babylonjs-serializers 8.34.0 → 8.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babylon.glTF2Serializer.js +1 -1
- package/babylon.glTF2Serializer.min.js +1 -1
- package/babylon.glTF2Serializer.min.js.map +1 -1
- package/babylonjs.serializers.d.ts +46 -75
- package/babylonjs.serializers.js +1 -1
- package/babylonjs.serializers.min.js +1 -1
- package/babylonjs.serializers.min.js.map +1 -1
- package/babylonjs.serializers.module.d.ts +101 -172
- package/package.json +3 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};r.d(o,{default:()=>Ht});var i={};r.r(i),r.d(i,{OBJExport:()=>g});var a={};r.r(a),r.d(a,{__IGLTFExporterExtension:()=>m});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_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>fe,EXT_texture_avif:()=>dt,EXT_texture_webp:()=>pt,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Ee,KHR_materials_clearcoat:()=>Ce,KHR_materials_clearcoat_anisotropy:()=>Ne,KHR_materials_clearcoat_color:()=>Oe,KHR_materials_clearcoat_darkening:()=>Ve,KHR_materials_clearcoat_ior:()=>Fe,KHR_materials_diffuse_roughness:()=>at,KHR_materials_diffuse_transmission:()=>Ke,KHR_materials_dispersion:()=>We,KHR_materials_emissive_strength:()=>Ge,KHR_materials_ior:()=>je,KHR_materials_iridescence:()=>Xe,KHR_materials_sheen:()=>Ye,KHR_materials_specular:()=>Je,KHR_materials_transmission:()=>et,KHR_materials_unlit:()=>nt,KHR_materials_volume:()=>ot,KHR_texture_basisu:()=>lt,KHR_texture_transform:()=>ut});var l={};r.r(l),r.d(l,{EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>fe,EXT_texture_avif:()=>dt,EXT_texture_webp:()=>pt,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Ee,KHR_materials_clearcoat:()=>Ce,KHR_materials_clearcoat_anisotropy:()=>Ne,KHR_materials_clearcoat_color:()=>Oe,KHR_materials_clearcoat_darkening:()=>Ve,KHR_materials_clearcoat_ior:()=>Fe,KHR_materials_diffuse_roughness:()=>at,KHR_materials_diffuse_transmission:()=>Ke,KHR_materials_dispersion:()=>We,KHR_materials_emissive_strength:()=>Ge,KHR_materials_ior:()=>je,KHR_materials_iridescence:()=>Xe,KHR_materials_sheen:()=>Ye,KHR_materials_specular:()=>Je,KHR_materials_transmission:()=>et,KHR_materials_unlit:()=>nt,KHR_materials_volume:()=>ot,KHR_texture_basisu:()=>lt,KHR_texture_transform:()=>ut,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>I});var f={};r.r(f),r.d(f,{STLExport:()=>xt});var p={};r.r(p),r.d(p,{USDZExportAsync:()=>It});var h={};r.r(h),r.d(h,{BVHExporter:()=>Vt});var d={};r.r(d),r.d(d,{BVHExporter:()=>Vt,EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>fe,EXT_texture_avif:()=>dt,EXT_texture_webp:()=>pt,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>he,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Ee,KHR_materials_clearcoat:()=>Ce,KHR_materials_clearcoat_anisotropy:()=>Ne,KHR_materials_clearcoat_color:()=>Oe,KHR_materials_clearcoat_darkening:()=>Ve,KHR_materials_clearcoat_ior:()=>Fe,KHR_materials_diffuse_roughness:()=>at,KHR_materials_diffuse_transmission:()=>Ke,KHR_materials_dispersion:()=>We,KHR_materials_emissive_strength:()=>Ge,KHR_materials_ior:()=>je,KHR_materials_iridescence:()=>Xe,KHR_materials_sheen:()=>Ye,KHR_materials_specular:()=>Je,KHR_materials_transmission:()=>et,KHR_materials_unlit:()=>nt,KHR_materials_volume:()=>ot,KHR_texture_basisu:()=>lt,KHR_texture_transform:()=>ut,OBJExport:()=>g,STLExport:()=>xt,USDZExportAsync:()=>It,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>I,__IGLTFExporterExtension:()=>m});var x=r(597),g=function(){function e(){}return e.OBJ=function(e,t,n,r){var o=[],i=1,a=1;t&&(n||(n="mat"),o.push("mtllib "+n+".mtl"));for(var s=0;s<e.length;s++){var u=e[s],c=u.name||"mesh".concat(s,"}");o.push("o ".concat(c));var l=null;if(r){var f=u.computeWorldMatrix(!0);l=new x.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"),g=h.getVerticesData("normal"),m=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!=g)for(b=0;b<g.length;b+=3)o.push("vn "+g[b]*T+" "+g[b+1]+" "+g[b+2]);if(null!=m)for(b=0;b<m.length;b+=2)o.push("vt "+m[b]+" "+m[b+1]),y++;var M=["","",""],A=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===x.Material.ClockWiseSideOrientation?[2,1]:[1,2],w=A[0],E=A[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+i),String(_[b+w]+i),String(_[b+E]+i)],C=[String(_[b]+a),String(_[b+w]+a),String(_[b+E]+a)],I=R,V=null!=m?C:M,S=null!=g?R:M;o.push("f "+I[0]+"/"+V[0]+"/"+S[0]+" "+I[1]+"/"+V[1]+"/"+S[1]+" "+I[2]+"/"+V[2]+"/"+S[2])}r&&l&&u.bakeTransformIntoVertices(l),i+=v,a+=y}else x.Tools.Warn("There are no position vertices or indices on the mesh!")}else x.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}(),m=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,x.GetMimeType)(e)});x.Tools.Download(n,e)}},e}(),v=function(){return v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},v.apply(this,arguments)};function y(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))}function T(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function b(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var M=1e-6,A=new x.Color3(.04,.04,.04),w=1024,E=x.Color3.White(),R=x.Color3.BlackReadOnly;function C(e){return y(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(i){switch(i.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(n=t._buffer,o=e.mimeType,n?[3,2]:[4,x.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return r=i.sent(),o=(0,x.GetMimeType)(t.url)||o,[3,10];case 2:return ArrayBuffer.isView(n)?(r=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),[3,10]):[3,3];case 3:return n instanceof ArrayBuffer?(r=n,[3,10]):[3,4];case 4:return n instanceof Blob?[4,n.arrayBuffer()]:[3,6];case 5:return r=i.sent(),o=n.type||o,[3,10];case 6:return"string"!=typeof n?[3,8]:[4,x.Tools.LoadFileAsync(n)];case 7:return r=i.sent(),o=(0,x.GetMimeType)(n)||o,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement?[4,x.Tools.LoadFileAsync(n.src)]:[3,10];case 9:r=i.sent(),o=(0,x.GetMimeType)(n.src)||o,i.label=10;case 10:return r&&o?[2,{data:r,mimeType:o}]:[2,null]}}))}))}function I(e,t,n){if(t<A.r)return 0;var r=A.r,o=e*n/(1-A.r)+t-2*A.r,i=o*o-4*r*(A.r-t);return x.Scalar.Clamp((-o+Math.sqrt(i))/(2*r),0,1)}function V(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),n=e.alpha,r=x.Scalar.Clamp(e.specularPower,0,w),o=(0,x.SpecularPowerToRoughness)(r);return{baseColorFactor:[t.r,t.g,t.b,n],metallicFactor:0,roughnessFactor:o}}function S(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function F(e,t,n){for(var r=new Uint8Array(e*t*4),o=0;o<r.length;o+=4)r[o]=r[o+1]=r[o+2]=r[o+3]=255;return x.RawTexture.CreateRGBATexture(r,e,t,n)}function B(e){if(e instanceof Uint8Array){for(var t=e.length,n=new Float32Array(e.length),r=0;r<t;++r)n[r]=e[r]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var O=function(){function e(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}return e.prototype.getTextureInfo=function(e){var t;return e&&null!==(t=this._textureMap.get(e.uniqueId))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n=V(e),r={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||x.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),t?(o=[],(i=e.diffuseTexture)&&o.push(this.exportTextureAsync(i).then((function(e){e&&(n.baseColorTexture=e)}))),(a=e.bumpTexture)&&o.push(this.exportTextureAsync(a).then((function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))}))),(s=e.emissiveTexture)&&(r.emissiveFactor=[1,1,1],o.push(this.exportTextureAsync(s).then((function(e){e&&(r.emissiveTexture=e)})))),(u=e.ambientTexture)&&o.push(this.exportTextureAsync(u).then((function(e){if(e){var t={index:e.index};r.occlusionTexture=t}}))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===x.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":x.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(R,M)&&(r.emissiveFactor=e.emissiveColor.asArray()),r.pbrMetallicRoughness=n,S(r,e),[4,this._finishMaterialAsync(r,e)];case 3:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(n=s.sent(),r=[],o=0,i=n;o<i.length;o++)a=i[o],r.push(this.exportTextureAsync(a));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,x.DumpTools.DumpDataAsync(t,n,e,r,void 0,!1,!0)];case 1:return[2,o.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,n){var r,o,i=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return i.width<a.width?(r=e&&e instanceof x.Texture?x.TextureTools.CreateResizedCopy(e,a.width,a.height,!0):F(a.width,a.height,n),o=t):i.width>a.width?(o=t&&t instanceof x.Texture?x.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):F(i.width,i.height,n),r=e):(r=e,o=t),{texture1:r,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){var o,i,a,s,u,c,l,f,p,h,d,g,m,_,v,y,b,A,w,R,C,I,V,S,F,O,P,U,N,L,k;return T(this,(function(T){switch(T.label){case 0:return o=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,T.sent()];case 2:return(i=e?e.getScene():t?t.getScene():null)?(a=this._resizeTexturesToSameDimensions(e,t,i),s=null===(k=a.texture1)||void 0===k?void 0:k.getSize(),u=void 0,c=void 0,l=s.width,f=s.height,[4,a.texture1.readPixels()]):[3,12];case 3:return p=T.sent(),[4,a.texture2.readPixels()];case 4:return h=T.sent(),p?(u=B(p),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return h?(c=B(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,g=new Uint8Array(d),m=new Uint8Array(d),_=new x.Color3(0,0,0),v=0,y=0,O=0;O<f;++O)for(P=0;P<l;++P)b=4*(l*O+P),A=new x.Color3(u[b],u[b+1],u[b+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),w=new x.Color3(c[b],c[b+1],c[b+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(n.specularColor),R=c[b+3]*n.glossiness,C={diffuseColor:A,specularColor:w,glossiness:R},I=this._convertSpecularGlossinessToMetallicRoughness(C),_.r=Math.max(_.r,I.baseColor.r),_.g=Math.max(_.g,I.baseColor.g),_.b=Math.max(_.b,I.baseColor.b),v=Math.max(v,I.metallic),y=Math.max(y,I.roughness),m[b]=255*I.baseColor.r,m[b+1]=255*I.baseColor.g,m[b+2]=255*I.baseColor.b,m[b+3]=a.texture1.hasAlpha?255*u[b+3]:255,g[b]=0,g[b+1]=255*I.roughness,g[b+2]=255*I.metallic,g[b+3]=255;for(V={baseColor:_,metallic:v,roughness:y},S=!1,F=!1,O=0;O<f;++O)for(P=0;P<l;++P)m[U=4*(l*O+P)]/=V.baseColor.r>M?V.baseColor.r:1,m[U+1]/=V.baseColor.g>M?V.baseColor.g:1,m[U+2]/=V.baseColor.b>M?V.baseColor.b:1,N=x.Color3.FromInts(m[U],m[U+1],m[U+2]),L=N.toGammaSpace(i.getEngine().useExactSrgbConversions),m[U]=255*L.r,m[U+1]=255*L.g,m[U+2]=255*L.b,L.equalsWithEpsilon(E,M)||(F=!0),g[U+1]/=V.roughness>M?V.roughness:1,g[U+2]/=V.metallic>M?V.metallic:1,x.Color3.FromInts(255,g[U+1],g[U+2]).equalsWithEpsilon(E,M)||(S=!0);return S&&o.push(this._getImageDataAsync(g,l,f,r).then((function(e){V.metallicRoughnessTextureData=e}))),F&&o.push(this._getImageDataAsync(m,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=I(t,n,r),i=e.diffuseColor.scale(r/(1-A.r)/Math.max(1-o,M)),a=e.specularColor.subtract(A.scale(1-o)).scale(1/Math.max(o,M)),s=x.Color3.Lerp(i,a,o*o);return{baseColor:s=s.clampToRef(0,1,s),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return 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,i,a,s,u){return y(this,void 0,void 0,(function(){var c,l,f,p,h,d,g,m,_,v=this;return T(this,(function(b){switch(b.label){case 0:return c=[],l={baseColor:e,metallic:t,roughness:n},u&&(a instanceof x.OpenPBRMaterial?(a.geometryOpacityTexture?(f=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:0,p=a.geometryOpacityTexture&&a.geometryOpacityTexture.getInternalTexture()?a.geometryOpacityTexture.getInternalTexture().uniqueId:0,h=Number("".concat(f).concat(p)),(_=this._textureMap.get(h))?s.baseColorTexture=_:c.push((0,x.MergeTexturesAsync)("baseColorOpacityTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,1):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,2):(0,x.CreateConstantInput)(1),(0,x.CreateTextureInput)(a.geometryOpacityTexture,0)),a.getScene()).then((function(e){return y(v,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,h)];case 1:return(t=n.sent())&&(s.baseColorTexture=t),[2]}}))}))})))):r&&c.push(this.exportTextureAsync(r).then((function(e){e&&(s.baseColorTexture=e)}))),a._useMetallicFromMetallicTextureBlue&&o?c.push(this.exportTextureAsync(o).then((function(e){e&&(s.metallicRoughnessTexture=e)}))):(i||o)&&(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,g=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,m=Number("".concat(d).concat(g)),(_=this._textureMap.get(m))?s.metallicRoughnessTexture=_:c.push((0,x.MergeTexturesAsync)("MetalRoughTexture",(0,x.CreateRGBAConfiguration)(a.ambientOcclusionTexture?(0,x.CreateTextureInput)(a.ambientOcclusionTexture,0):(0,x.CreateConstantInput)(1),i?(0,x.CreateTextureInput)(i,0):(0,x.CreateConstantInput)(1),o?(0,x.CreateTextureInput)(o,0):(0,x.CreateConstantInput)(1)),a.getScene()).then((function(e){return y(v,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,m)];case 1:return(t=n.sent())&&(s.metallicRoughnessTexture=t),[2]}}))}))}))))):(r&&c.push(this.exportTextureAsync(r).then((function(e){e&&(s.baseColorTexture=e)}))),o&&c.push(this.exportTextureAsync(o).then((function(e){e&&(s.metallicRoughnessTexture=e)}))))),c.length>0?(this._exporter._materialNeedsUVsSet.add(a),[4,Promise.all(c)]):[3,2];case 1:b.sent(),b.label=2;case 2:return[2,l]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof x.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 x.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case x.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case x.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case x.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case x.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case x.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case x.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case x.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case x.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case x.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case x.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case x.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case x.Texture.WRAP_ADDRESSMODE:return 10497;case x.Texture.CLAMP_ADDRESSMODE:return 33071;case x.Texture.MIRROR_ADDRESSMODE:return 33648;default:return x.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f;return T(this,(function(p){switch(p.label){case 0:return r="image/png",o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},i=e._albedoTexture,a=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,!a||s?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,p.sent()];case 2:return(i||a)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(i||a),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(i,a,o,r)]):[3,4];case 3:return c=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==i?void 0:i.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),r,c.metallicRoughnessTextureData),t.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==a?void 0:a.coordinatesIndex)),[2,c];case 4:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i,a,s,u,c;return T(this,(function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(i=e._albedoColor,a=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,a])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._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 i,a,s,u,c,l=this;return T(this,(function(f){switch(f.label){case 0:return S(n,t),e.baseColor.equalsWithEpsilon(E,M)&&x.Scalar.WithinEpsilon(t.alpha,1,M)||(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||x.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o?(i=[],(a=t instanceof x.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&i.push(this.exportTextureAsync(a).then((function(e){e&&(n.normalTexture=e,1!==a.level&&(n.normalTexture.scale=a.level))}))),(s=t instanceof x.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&i.push(new Promise((function(e){return y(l,void 0,void 0,(function(){var n,o,i,a;return T(this,(function(u){switch(u.label){case 0:return t instanceof x.OpenPBRMaterial&&r.metallicRoughnessTexture?(n=this._exportTextureSampler(s),o=this._exporter._textures[r.metallicRoughnessTexture.index].source,i=this._exportTextureInfo(o,n,s.coordinatesIndex),this._textureMap.set(s.uniqueId,i),this._exporter._extensionsPostExportTextures("exporter",i,s),[2,e(i)]):[3,1];case 1:return a=e,[4,this.exportTextureAsync(s)];case 2:return[2,a.apply(void 0,[u.sent()])]}}))}))})).then((function(e){return y(l,void 0,void 0,(function(){var r;return T(this,(function(o){return e&&(r={index:e.index,texCoord:e.texCoord,extensions:e.extensions},n.occlusionTexture=r,t instanceof x.PBRBaseMaterial?r.strength=t._ambientTextureStrength:r.strength=t.ambientOcclusionTexture.level),[2]}))}))}))),(u=t instanceof x.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&i.push(this.exportTextureAsync(u).then((function(e){e&&(n.emissiveTexture=e)}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(c=t instanceof x.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(R,M)||(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,i,a,s;return T(this,(function(u){switch(u.label){case 0:return n={},r={name:e.name},o=e.baseColor,i=e.geometryOpacity,o&&(n.baseColorFactor=[o.r,o.g,o.b,i]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t)];case 1:return a=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(a,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,arguments,void 0,(function(e,t){var n,r,o;return void 0===t&&(t=null),T(this,(function(i){switch(i.label){case 0:return(n=this._textureMap.get(null!=t?t:e.uniqueId))?[2,n]:(r=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=i.sent(),n=this._exportTextureInfo(o,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,n),this._exporter._extensionsPostExportTextures("exporter",n,e),[2,n]}}))}))},e.prototype._exportTextureImageAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r,o,i,a=this;return T(this,(function(s){switch(s.label){case 0:return t=null!==(i=e.mimeType)&&void 0!==i?i:"none",n=this._internalTextureToImage,r=e.getInternalTexture().uniqueId,n[r]=n[r]||{},void 0===(o=n[r][t])&&(o=y(a,void 0,void 0,(function(){var n,r,o,i,a;return T(this,(function(s){switch(s.label){case 0:return[4,C(e)];case 1:if((n=s.sent())&&("none"===t||n.mimeType===t))return[2,this._exportImage(e.name,n.mimeType,n.data)];if(r="image/png","none"!==t)switch(t){case"image/jpeg":case"image/png":case"image/webp":r=t;break;default:x.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG."))}return o=e.getSize(),[4,(0,x.GetTextureDataAsync)(e)];case 2:return i=s.sent(),[4,this._getImageDataAsync(i,o.width,o.height,r)];case 3:return a=s.sent(),[2,this._exportImage(e.name,r,a)]}}))})),n[r][t]=o),[4,o];case 1:return[2,s.sent()]}}))}))},e.prototype._exportImage=function(e,t,n){var r,o=this._exporter._images;if(this._exporter._shouldUseGlb){r={name:e,mimeType:t,bufferView:void 0};var i=this._exporter._bufferManager.createBufferView(new Uint8Array(n));this._exporter._bufferManager.setBufferView(r,i)}else{var a=e.replace(/\.\/|\/|\.\\|\\/g,"_"),s=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(t),u=a+s;o.some((function(e){return e.uri===u}))&&(u="".concat(a,"_").concat(x.Tools.RandomId()).concat(s)),r={name:e,uri:u},this._exporter._imageData[u]={data:n,mimeType:t}}return o.push(r),o.length-1},e.prototype._exportTextureInfo=function(e,t,n){var r=this._exporter._textures,o=r.findIndex((function(n){return n.sampler==t&&n.source===e}));-1===o&&(o=r.length,r.push({source:e,sampler:t}));var i={index:o};return n&&(i.texCoord=n),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),n=this._exporter._samplers,r=n.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==r?r:(n.push(t),n.length-1)},e}(),P=x.Matrix.Compose(new x.Vector3(-1,1,1),x.Quaternion.Identity(),x.Vector3.Zero());function U(e,t){if(!(e instanceof x.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(x.Matrix.IdentityReadOnly,x.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(P,x.TmpVectors.Matrix[0]).equalsWithEpsilon(x.Matrix.IdentityReadOnly,x.Epsilon))return!1;return!(e instanceof x.AbstractMesh&&e.geometry)}var N=x.Vector3.ZeroReadOnly,L=x.Quaternion.Identity(),k=x.Vector3.OneReadOnly,K=new x.Vector3(-1,1,1);function D(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,i=e.normalized,a=e.getSize(),s=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:a,type:o,count:s*a,normalized:i,totalVertices:s,kind:e.getKind()}}function W(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 H(e){switch(e){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:case x.VertexBuffer.ColorKind:case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:case x.VertexBuffer.MatricesWeightsKind:case x.VertexBuffer.MatricesWeightsExtraKind:case x.VertexBuffer.UVKind:case x.VertexBuffer.UV2Kind:case x.VertexBuffer.UV3Kind:case x.VertexBuffer.UV4Kind:case x.VertexBuffer.UV5Kind:case x.VertexBuffer.UV6Kind:return!0}return!1}function G(e){switch(e){case x.Material.TriangleFillMode:return 4;case x.Material.TriangleStripDrawMode:return 5;case x.Material.TriangleFanDrawMode:return 6;case x.Material.PointListDrawMode:case x.Material.PointFillMode:return 0;case x.Material.LineLoopDrawMode:return 2;case x.Material.LineListDrawMode:return 1;case x.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function q(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function j(e){return e.x*=-1,e}function z(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){var r=Math.sign(e.x);e.x=t,e.y*=-r,e.z*=-r,e.w*=r}else r=Math.sign(e.y),e.x*=-r,e.y=n,e.z*=r,e.w*=-r}else{var o=Math.abs(e.z),i=Math.abs(e.w);o>i?(r=Math.sign(e.z),e.x*=-r,e.y*=r,e.z=o,e.w*=-r):(r=Math.sign(e.w),e.x*=r,e.y*=-r,e.z*=-r,e.w=i)}return e}function X(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function Q(e,t){var n=x.Vector3.FromArrayToRef(t.translation||[0,0,0],0,x.TmpVectors.Vector3[0]),r=x.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,x.TmpVectors.Quaternion[0]),o=x.Matrix.ComposeToRef(k,r,n,x.TmpVectors.Matrix[0]),i=x.Vector3.FromArrayToRef(e.translation||[0,0,0],0,x.TmpVectors.Vector3[2]),a=x.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,x.TmpVectors.Quaternion[1]),s=x.Matrix.ComposeToRef(k,a,i,x.TmpVectors.Matrix[1]);o.multiplyToRef(s,s),s.decompose(void 0,r,n),n.equalsWithEpsilon(N,x.Epsilon)?delete t.translation:t.translation=n.asArray(),r.equalsWithEpsilon(L,x.Epsilon)?delete t.rotation:t.rotation=r.asArray(),t.scale&&delete t.scale}function Y(e,t){if(!(t instanceof x.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var n=e.getScene(),r=e instanceof x.TargetCamera&&!n.useRightHandedSystem?K:k;return!!t.scaling.equalsWithEpsilon(r,x.Epsilon)||(x.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function Z(e,t){for(var n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],a=o[1],s=t[i];(Array.isArray(a)&&Array.isArray(s)&&J(a,s)||a===s)&&delete e[i]}return e}function J(e,t){return e.length===t.length&&e.every((function(e,n){return e===t[n]}))}var $=new Map([[Int8Array,function(e,t,n){return e.setInt8(t,n)}],[Uint8Array,function(e,t,n){return e.setUint8(t,n)}],[Uint8ClampedArray,function(e,t,n){return e.setUint8(t,n)}],[Int16Array,function(e,t,n){return e.setInt16(t,n,!0)}],[Uint16Array,function(e,t,n){return e.setUint16(t,n,!0)}],[Int32Array,function(e,t,n){return e.setInt32(t,n,!0)}],[Uint32Array,function(e,t,n){return e.setUint32(t,n,!0)}],[Float32Array,function(e,t,n){return e.setFloat32(t,n,!0)}],[Float64Array,function(e,t,n){return e.setFloat64(t,n,!0)}]]),ee=function(){function e(e){this._data=new Uint8Array(e),this._dataView=new DataView(this._data.buffer),this._byteOffset=0}return e.prototype.writeTypedArray=function(e){this._checkGrowBuffer(e.byteLength);for(var t=$.get(e.constructor),n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var n=new Uint8Array(2*t);n.set(this._data),this._data=n,this._dataView=new DataView(this._data.buffer)}},e}();function te(e){return e%4==0?4:e%2==0?2:1}var ne,re=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach((function(e){t+=e.byteLength}));for(var n=new ee(t),r=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return te(t.byteLength)-te(e.byteLength)}));r<o.length;r++){var i=o[r];i.byteOffset=n.byteOffset,e.push(i);for(var a=e.length-1,s=0,u=this.getPropertiesWithBufferView(i);s<u.length;s++)u[s].bufferView=a;n.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return n.getOutputData()},e.prototype.createBufferView=function(e,t){var n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n},e.prototype.createAccessor=function(e,t,n,r,o,i,a){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:a,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,n=0,r=this.getPropertiesWithBufferView(e);n<r.length;n++){var o=r[n];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(n,r){n===e&&(void 0!==r.byteOffset&&delete r.byteOffset,t._accessorToBufferView.delete(r))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(ne||(ne={}));var oe=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof x.TransformNode||e instanceof x.Camera||e instanceof x.Light)},e._CreateNodeAnimation=function(t,n,r,o,i){if(this._IsTransformable(t)){var a=[],s=[],u=n.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,r,o),f=l.interpolationType,p=l.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,n,r,a,s,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,n,r,a,s,o):e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o),a.length&&s.length)return{inputs:a,outputs:s,samplerInterpolation:f,inputsMin:p?c.min:x.Tools.FloatRound(c.min/n.framePerSecond),inputsMax:p?c.max:x.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:x.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:n,useQuaternion:r}:(x.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,i,a,s,u,c,l,f){var p;if(e._IsTransformable(t)&&t.animations)for(var h=0,d=t.animations;h<d.length;h++){var x=d[h];if(!f||f(x)){var g=e._DeduceAnimationInfo(x);g&&(p={name:x.name,samplers:[],channels:[]},e._AddAnimation("".concat(x.name),x.hasRunningRuntimeAnimations?n:p,t,x,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,g.useQuaternion,c,l),p.samplers.length&&p.channels.length&&r.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,n,r,o,i,a,s,u,c,l,f){var p;if(t instanceof x.Mesh){var h=t.morphTargetManager;if(h)for(var d=0;d<h.numTargets;++d)for(var g=0,m=h.getTarget(d).animations;g<m.length;g++){var _=m[g];if(!f||f(_)){for(var v=new x.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),b=0;b<T.length;++b)for(var M=T[b],A=0;A<h.numTargets;++A)A==d?y.push(M):y.push({frame:M.frame,value:0});v.setKeys(y,!0);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,a,s,u,w.useQuaternion,c,l,h.numTargets),p.samplers.length&&p.channels.length&&r.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,n,r,o,i,a,s,u,c){var l,f;if(t.animationGroups)for(var p=t.animationGroups,h=function(p){var h=new Map,g=new Map,m=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(M=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,M.dataAccessorType,M.animationChannelTargetPath,r,o,i,a,M.useQuaternion,s,T)}}else if(v instanceof x.MorphTarget||1===v.length&&v[0]instanceof x.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var A=v instanceof x.MorphTarget?v:v[0];if(A){var w=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===A)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(A,y),m.add(E),g.set(E,y))}}}}},y=0;y<p.targetedAnimations.length;++y)v(y);m.forEach((function(t){for(var n=t.morphTargetManager,u=null,c=[],l=g.get(t).getKeys(),d=l.length,m=0;m<d;++m)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 x.Animation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,x.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[m])):c.push({frame:p.from+_/d*m,value:y.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c,!0);var M=e._DeduceAnimationInfo(u);M&&e._AddAnimation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,M.dataAccessorType,M.animationChannelTargetPath,r,o,i,a,M.useQuaternion,s,!1,null==n?void 0:n.numTargets)})),f.channels.length&&f.samplers.length&&n.push(f)},d=this,g=0,m=p;g<m.length;g++)h(m[g])},e._AddAnimation=function(t,n,r,o,i,a,s,u,c,l,f,p,h,d){var g,m,_,v,y,T,b=e._CreateNodeAnimation(r,o,a,f,p);if(b){if(d){for(var M=0,A=0,w=[];b.inputs.length>0;)A=b.inputs.shift(),M%d==0&&w.push(A),M++;b.inputs=w}var E=s.get(r),R=new Float32Array(b.inputs);g=u.createBufferView(R),m=u.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(m),_=l.length-1;var C=new x.Quaternion,I=new x.Vector3,V=new x.Vector3,S=r instanceof x.Camera,F=W(i),B=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var n=e;switch(a){case"translation":h&&(x.Vector3.FromArrayToRef(e,0,V),j(V),V.toArray(n));break;case"rotation":4===e.length?x.Quaternion.FromArrayToRef(e,0,C):(n=new Array(4),x.Vector3.FromArrayToRef(e,0,I),x.Quaternion.FromEulerVectorToRef(I,C)),h&&(z(C),S&&X(C)),C.toArray(n)}B.set(n,t*F)})),g=u.createBufferView(B),m=u.createAccessor(g,i,5126,b.outputs.length),l.push(m),v=l.length-1,y={interpolation:b.samplerInterpolation,input:_,output:v},n.samplers.push(y),T={sampler:n.samplers.length-1,target:{node:E,path:a}},n.channels.push(T)}},e._CreateBakedAnimation=function(t,n,r,o,i,a,s,u,c,l,f){var p,h,d=x.Quaternion.Identity(),g=null,m=null,_=null,v=null,y=null,T=null;l.min=x.Tools.FloatRound(o/a);for(var b=n.getKeys(),M=0,A=b.length;M<A;++M){if(T=null,_=b[M],M+1<A)if(v=b[M+1],_.value.equals&&_.value.equals(v.value)||_.value===v.value){if(0!==M)continue;T=_.frame}else T=v.frame;else{if(y=b[M-1],_.value.equals&&_.value.equals(y.value)||_.value===y.value)continue;T=i}if(T)for(var w=_.frame;w<=T;w+=s)if((h=x.Tools.FloatRound(w/a))!==g){g=h,m=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)}}m&&(l.max=m)},e._ConvertFactorToVector3OrQuaternion=function(t,n,r,o,i){var a=e._GetBasePositionRotationOrScale(n,o,i),s=r.targetProperty.split("."),u=s?s[1]:"",c=i?x.Quaternion.FromArray(a).normalize():x.Vector3.FromArray(a);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:x.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,n,r,o,i,a,s,u){var c;a.push(n),"weights"!==o?(r.dataType===x.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,r,o,u)),"rotation"===o?(u?i=t:(c=t,x.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),s.push(i.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,n,r,o,i,a){for(var s=0,u=n.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/n.framePerSecond),e._AddKeyframeValue(c,n,i,r,t,a)}},e._CreateCubicSplineAnimation=function(t,n,r,o,i,a){n.getKeys().forEach((function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(ne.INTANGENT,i,r,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,n,i,r,t,a),e._AddSplineTangent(ne.OUTTANGENT,i,r,"CUBICSPLINE",s,a)}))},e._GetBasePositionRotationOrScale=function(e,t,n){var r;if("rotation"===t)if(n){var o=e.rotationQuaternion;r=(null!=o?o:x.Quaternion.Identity()).asArray()}else{var i=e.rotation;r=(null!=i?i:x.Vector3.Zero()).asArray()}else if("translation"===t){var a=e.position;r=(null!=a?a:x.Vector3.Zero()).asArray()}else{var s=e.scaling;r=(null!=s?s:x.Vector3.One()).asArray()}return r},e._AddKeyframeValue=function(e,t,n,r,o,i){var a,s=t.dataType;if(s===x.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===r){var c=x.Vector3.FromArray(u);u=x.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}n.push(u)}else if(s===x.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)n.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,r,i)){if("rotation"===r){var l=i?a:x.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();n.push(l.asArray())}n.push(a.asArray())}}else s===x.Animation.ANIMATIONTYPE_QUATERNION?n.push(e.value.normalize().asArray()):x.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,n,r,o,i){var a,s=e===ne.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===r){if("rotation"===n)if(s)if(i)a=s.asArray();else{var u=s;a=x.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else a=[0,0,0,0];else a="weights"===n?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(a)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,n=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)})),{min:t,max:n}},e}();function ie(e,t,n,r,o,i){var a={attributes:{},influence:e.influence,name:e.name},s=t.geometry;if(!s)return x.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;var u=i?-1:1,c=x.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),p=s.getVerticesData(x.VertexBuffer.PositionKind);if(p){var h=new Float32Array(p.length),d=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];l=p.length/3;for(var m=0;m<l;++m){var _=x.Vector3.FromArray(p,3*m);x.Vector3.FromArray(f,3*m).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),g[0]=Math.max(g[0],c.x),d[1]=Math.min(d[1],c.y),g[1]=Math.max(g[1],c.y),d[2]=Math.min(d[2],c.z),g[2]=Math.max(g[2],c.z),h[3*m]=c.x,h[3*m+1]=c.y,h[3*m+2]=c.z}var v=n.createBufferView(h,12),y=n.createAccessor(v,"VEC3",5126,f.length/3,0,{min:d,max:g});o.push(y),a.attributes.POSITION=o.length-1}else x.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(x.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(l=b.length/3,m=0;m<l;++m){var A=x.Vector3.FromArray(b,3*m).normalize();x.Vector3.FromArray(T,3*m).normalize().subtractToRef(A,c),M[3*m]=c.x*u,M[3*m+1]=c.y,M[3*m+2]=c.z}v=n.createBufferView(M,12),y=n.createAccessor(v,"VEC3",5126,T.length/3,0),o.push(y),a.attributes.NORMAL=o.length-1}else x.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(x.VertexBuffer.TangentKind);if(E){l=E.length/4;var R=new Float32Array(3*l);for(m=0;m<l;++m){var C=x.Vector3.FromArray(E,4*m);q(C);var I=x.Vector3.FromArray(w,3*m);q(I),I.subtractToRef(C,c),R[3*m]=c.x*u,R[3*m+1]=c.y,R[3*m+2]=c.z}v=n.createBufferView(R,12),y=n.createAccessor(v,"VEC3",5126,l,0),o.push(y),a.attributes.TANGENT=o.length-1}else x.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),S=s.getVerticesData(x.VertexBuffer.ColorKind),F=s.getVertexBuffer(x.VertexBuffer.ColorKind);if(S&&F){var B=F.getSize();l=S.length/B;var O=new Float32Array(l*B);for(m=0;m<l;++m)if(3===B){var P=x.Vector3.FromArray(S,m*B);x.Vector3.FromArray(V,m*B).subtractToRef(P,c),O[3*m]=c.x,O[3*m+1]=c.y,O[3*m+2]=c.z}else if(4===B){var U=new x.Vector4;P=x.Vector4.FromArray(S,m*B),x.Vector4.FromArray(V,m*B).subtractToRef(P,U),O[4*m]=U.x,O[4*m+1]=U.y,O[4*m+2]=U.z,O[4*m+3]=U.w}else x.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));v=n.createBufferView(O,4*B),y=n.createAccessor(v,3===B?"VEC3":"VEC4",5126,l,0),o.push(y),a.attributes.COLOR_0=o.length-1}else x.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return a}var ae=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,n,r,o){var i,a,s,u;return null===(u=null===(s=null===(a=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===a?void 0:a.get(n))||void 0===s?void 0:s.get(r))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,n,r,o,i){var a=this._indicesAccessorMap.get(e);a||(a=new Map,this._indicesAccessorMap.set(e,a));var s=a.get(t);s||(s=new Map,a.set(t,s));var u=s.get(n);u||(u=new Map,s.set(n,u));var c=u.get(r);c||(c=new Map,u.set(r,c)),c.set(o,i)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)},e.prototype.getRemappedBufferView=function(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)},e.prototype.getVertexAccessor=function(e,t,n){var r,o;return null===(o=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.get(n)},e.prototype.setVertexAccessor=function(e,t,n,r){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.set(t,i)),i.set(n,r)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),se=function(){function e(e,t){if(void 0===e&&(e=x.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(x.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new O(this),this._extensions={},this._bufferManager=new re,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=v({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,n,r){var o=this;if(n>=t.length)return Promise.resolve(e);var i=r(t[n],e);return i?i.then((function(e){return y(o,void 0,void 0,(function(){var o;return T(this,(function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=i.sent(),[3,3];case 2:o=null,i.label=3;case 3:return[2,o]}}))}))})):this._ApplyExtension(e,t,n+1,r)},e.prototype._ApplyExtensions=function(t,n){for(var r=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];r.push(this._extensions[a])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var i=this;return this._ApplyExtensions(t,(function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,n,r,o,i._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,n){return this._ApplyExtensions(t,(function(t,r){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,n)}))},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,n,r){return y(this,void 0,void 0,(function(){var o,i=this;return T(this,(function(a){switch(a.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map((function(e){return y(i,void 0,void 0,(function(){var i,a;return T(this,(function(s){switch(s.label){case 0:return(i=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,i.postExportMaterialAdditionalTexturesAsync(t,n,r)]:[3,2];case 1:a=s.sent(),o.push.apply(o,a),s.label=2;case 2:return[2]}}))}))})))];case 1:return a.sent(),[2,o]}}))}))},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,n,r)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return y(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(i){switch(i.label){case 0:t=0,n=e._ExtensionNames,i.label=1;case 1:return t<n.length?(r=n[t],(o=this._extensions[r]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var n,r,o;t.wasUsed&&((n=e._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((r=e._glTF).extensionsRequired||(r.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,n=e._ExtensionNames;t<n.length;t++){var r=n[t],o=e._ExtensionFactories[r](this);this._extensions[r]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,n,r){void 0===r&&(r=100),e.UnregisterExtension(t)&&x.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 i=e._ExtensionNames.length,a=0;a<e._ExtensionNames.length;a++){var s=e._ExtensionNames[a];if(o<e._ExtensionOrders[s]){i=a;break}}e._ExtensionNames.splice(i,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,i,a,s;return T(this,(function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength,e,!0),r=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",i=e+".bin",(a=new _).files[o]=n,a.files[i]=r,this._imageData)for(s in this._imageData)a.files[s]=new Blob([this._imageData[s].data],{type:this._imageData[s].mimeType});return[2,a]}}))}))},e.prototype._generateBinaryAsync=function(){return y(this,void 0,void 0,(function(){return T(this,(function(e){switch(e.label){case 0:return[4,this._exportSceneAsync()];case 1:return e.sent(),[4,this._extensionsPreGenerateBinaryAsync()];case 2:return e.sent(),[2,this._bufferManager.generateBinary(this._bufferViews)]}}))}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype.generateGLBAsync=function(e){return y(this,void 0,void 0,(function(){var t,n,r,o,i,a,s,u,c,l,f,p,h,d;return T(this,(function(x){switch(x.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=x.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(a=new TextEncoder,i=a.encode(n),o=i.length),s=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+s+t.byteLength+u,(l=new ee(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(o+s),l.writeUInt32(1313821514),i)l.writeTypedArray(i);else for(f="_".charCodeAt(0),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,x.Epsilon)||x.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(N,x.Epsilon)){var o=x.TmpVectors.Vector3[0].copyFrom(t.position);n&&j(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(k,x.Epsilon)||(e.scale=t.scaling.asArray());var i=(null===(r=t.rotationQuaternion)||void 0===r?void 0:r.clone())||x.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);i.equalsWithEpsilon(L,x.Epsilon)||(n&&z(i),e.rotation=i.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,n){var r=x.TmpVectors.Vector3[0],o=x.TmpVectors.Quaternion[0],i=t.getWorldMatrix();if(t.parent){var a=t.parent.getWorldMatrix().invertToRef(x.TmpVectors.Matrix[0]);i.multiplyToRef(a,x.TmpVectors.Matrix[1]).decompose(void 0,o,r)}else i.decompose(void 0,o,r);r.equalsWithEpsilon(N,x.Epsilon)||(n&&j(r),e.translation=r.asArray()),n&&z(o),this._babylonScene.useRightHandedSystem||X(o),o.equalsWithEpsilon(L,x.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===x.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===x.Camera.FOVMODE_VERTICAL_FIXED?n.fov:n.fov*n.getEngine().getAspectRatio(n),znear:n.minZ,zfar:n.maxZ};else if("orthographic"===r.type){var o=n.orthoLeft&&n.orthoRight?.5*(n.orthoRight-n.orthoLeft):.5*n.getEngine().getRenderWidth(),i=n.orthoBottom&&n.orthoTop?.5*(n.orthoTop-n.orthoBottom):.5*n.getEngine().getRenderHeight();r.orthographic={xmag:o,ymag:i,znear:n.minZ,zfar:n.maxZ}}this._camerasMap.set(n,r)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var n=t[e],r=this._nodesCameraMap.get(n);if(void 0!==r){this._cameras.push(n);for(var o=0,i=r;o<i.length;o++)i[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var n=t[e];n.bones.length<=0||this._skinMap.set(n,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,n=function(n){if(n.bones.length<=0)return"continue";var o=r._skinMap.get(n);if(null==o)return"continue";for(var i={},a=-1,s=0;s<n.bones.length;++s){var u=n.bones[s];-1!==(f=null!==(t=u.getIndex())&&void 0!==t?t:s)&&(i[f]=u,f>a&&(a=f))}for(var c,l=[],f=0;f<=a;++f){var p=(u=i[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(x.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(P,c)),l.push(d)}else x.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var g=r._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==g){var m=new Float32Array(16*l.length);l.forEach((function(e,t){m.set(e.m,16*t)}));var _=r._bufferManager.createBufferView(m);r._accessors.push(r._bufferManager.createAccessor(_,"MAT4",5126,l.length)),o.inverseBindMatrices=r._accessors.length-1,r._skins.push(o);for(var v=r._skins.length-1,y=0,T=g;y<T.length;y++)T[y].skin=v}},r=this,o=0,i=this._babylonScene.skeletons;o<i.length;o++)n(i[o])},e.prototype._exportSceneAsync=function(){return y(this,void 0,void 0,(function(){var e,t,n,r,o,i,a,s,u,c,l,f,p,h,d,x,g,m,_,v,y,b,M;return T(this,(function(T){switch(T.label){case 0:for(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),n=new Array,r=new Array,o=new Array,i=0,a=this._babylonScene.rootNodes;i<a.length;i++)s=a[i],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&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 ae(!0,!1),l=(c=(y=e.nodes).push).apply,f=[y],[4,this._exportNodesAsync(r,u)];case 1:return l.apply(c,f.concat([T.sent()])),p=new ae(!1,!1),d=(h=(b=e.nodes).push).apply,x=[b],[4,this._exportNodesAsync(n,p)];case 2:return d.apply(h,x.concat([T.sent()])),g=new ae(!1,!0),_=(m=(M=e.nodes).push).apply,v=[M],[4,this._exportNodesAsync(o,g)];case 3:return _.apply(m,v.concat([T.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(u.getNodesSet()),this._babylonScene.animationGroups.length&&oe._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,u.getNodesSet(),this._options.shouldExportAnimation),[2]}}))}))},e.prototype._shouldExportNode=function(e){var t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t},e.prototype._exportNodesAsync=function(e,t){return y(this,void 0,void 0,(function(){var n,r,o,i;return T(this,(function(a){switch(a.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,a.label=1;case 1:return r<o.length?(i=o[r],[4,this._exportNodeAsync(i,n,t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return r++,[3,1];case 4:return[2,n]}}))}))},e.prototype._collectBuffers=function(e,t,n,r,o){if(this._shouldExportNode(e)&&e instanceof x.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var a in i)if(H(a)){var s=i[a];o.setHasVertexColorAlpha(s,e.hasVertexAlpha);var u=s._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(s)&&c.push(s);var l=n.get(s)||[];n.set(s,l),-1===l.indexOf(e)&&l.push(e)}var f=e.morphTargetManager;if(f)for(var 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,g=e.getChildren();d<g.length;d++){var m=g[d];this._collectBuffers(m,t,n,r,o)}},e.prototype._exportBuffers=function(e,t){for(var n=new Map,r=new Map,o=new Map,i=0,a=e;i<a.length;i++){var s=a[i];this._collectBuffers(s,n,r,o,t)}for(var u=Array.from(n.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var i=n.get(e);if(!i)return"continue";var a=i[0].byteStride;if(i.some((function(e){return e.byteStride!==a})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var s=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=r.get(e),n=D(e,t),o=n.byteOffset,i=n.byteStride,a=n.componentCount,u=n.type,c=n.count,f=n.normalized;switch(n.kind){case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:(0,x.EnumerateFloatValues)(s,o,i,a,u,c,f,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}}));break;case x.VertexBuffer.ColorKind:var p=t.filter((function(e){return e.material instanceof x.StandardMaterial||null==e.material})).length;if(0==p)break;if(p!=t.length){x.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==x.VertexBuffer.UNSIGNED_BYTE&&x.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var h=new x.Color3,d=new x.Color4,g=l._babylonScene.getEngine().useExactSrgbConversions;(0,x.EnumerateFloatValues)(s,o,i,a,u,c,f,(function(e){3===e.length?(h.fromArray(e,0),h.toLinearSpaceToRef(h,g),h.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0))}))}},c=0,f=i;c<f.length;c++)u(F=f[c]);if(t.convertToRightHanded){for(var p=0,h=i;p<h.length;p++){var d=D(F=h[p],r.get(F)),g=d.byteOffset,m=d.byteStride,_=d.componentCount,v=d.type,y=d.count,T=d.normalized;switch(R=d.kind){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:(0,x.EnumerateFloatValues)(s,g,m,_,v,y,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,a);t.setVertexBufferView(e,b);for(var M=new Map,A=0,w=i;A<w.length;A++){var E=D(F=w[A],r.get(F)),R=E.kind,C=E.totalVertices;switch(R){case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:if(F.type==x.VertexBuffer.FLOAT){var I=F.getFloatData(C);null!==I&&M.set(F,I)}}}0!==M.size&&x.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,S=Array.from(M.keys());V<S.length;V++){var F=S[V],B=M.get(F);if(B){for(var O=B.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(B.length),U=0;U<B.length;U++)P[U]=B[U];var N=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,F,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 g=d[h],m=o.get(g);if(m)for(var _=ie(g,m[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),v=0,y=m;v<y.length;v++){var T=y[v];t.bindMorphDataToMesh(T,_)}}},e.prototype._exportNodeAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f=this;return T(this,(function(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),i={name:"runtime animations",channels:[],samplers:[]},a=[],this._babylonScene.animationGroups.length||(oe._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&oe._CreateNodeAnimationFromNodeAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),a.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),s=o?[]:t,u=0,c=e.getChildren(),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,i,a,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 x.TransformNode?(this._setNodeTransformation(n,e,t.convertToRightHanded),e instanceof x.AbstractMesh?(o=e instanceof x.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(i=n,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(a=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(a)&&this._nodesSkinMap.set(a,[]),null===(f=this._nodesSkinMap.get(a))||void 0===f||f.push(n)),d.label=3;case 3:if(e instanceof x.TargetCamera&&(s=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(s)&&this._nodesCameraMap.set(s,[]),this._setCameraTransformation(n,e,t.convertToRightHanded),null!==(u=e.parent)&&Y(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],Q(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]:(x.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,n,r,o,i,a,s,u){var c=e;u.mode=G(i);var l=a!==x.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case x.Material.TriangleFillMode:case x.Material.TriangleStripDrawMode:case x.Material.TriangleFanDrawMode:return!0}return!1}(i);if(l){if(i===x.Material.TriangleStripDrawMode||i===x.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=G(i);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),g=this._bufferManager.createBufferView(d),m=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(g,"SCALAR",m,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,i){var a=e.getKind();if(H(a)&&(!a.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var s=o.getVertexAccessor(e,n,r);if(void 0===s){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=a===x.VertexBuffer.PositionKind?function(e,t,n,r){var o=t.byteOffset,i=t.byteStride,a=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,x.EnumerateFloatValues)(e,o+n*i,i,u,a,r*u,s,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,n,r):void 0,l=(a===x.VertexBuffer.MatricesIndicesKind||a===x.VertexBuffer.MatricesIndicesExtraKind)&&e.type===x.VertexBuffer.FLOAT,f=l?x.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==x.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:return"VEC3";case x.VertexBuffer.TangentKind:case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:case x.VertexBuffer.MatricesWeightsKind:case x.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case x.VertexBuffer.UVKind:case x.VertexBuffer.UV2Kind:case x.VertexBuffer.UV3Kind:case x.VertexBuffer.UV4Kind:case x.VertexBuffer.UV5Kind:case x.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(a,o.hasVertexColorAlpha(e)),f,r,d,c,p)),s=this._accessors.length-1,o.setVertexAccessor(e,n,r,s)}i.attributes[function(e){switch(e){case x.VertexBuffer.PositionKind:return"POSITION";case x.VertexBuffer.NormalKind:return"NORMAL";case x.VertexBuffer.TangentKind:return"TANGENT";case x.VertexBuffer.ColorKind:return"COLOR_0";case x.VertexBuffer.UVKind:return"TEXCOORD_0";case x.VertexBuffer.UV2Kind:return"TEXCOORD_1";case x.VertexBuffer.UV3Kind:return"TEXCOORD_2";case x.VertexBuffer.UV4Kind:return"TEXCOORD_3";case x.VertexBuffer.UV5Kind:return"TEXCOORD_4";case x.VertexBuffer.UV6Kind:return"TEXCOORD_5";case x.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case x.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case x.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case x.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(a)]=s}},e.prototype._exportMaterialAsync=function(e,t,n,r){return y(this,void 0,void 0,(function(){var o,i;return T(this,(function(a){switch(a.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,8]:(i=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof x.MultiMaterial?e.subMaterials[n.materialIndex]:e)instanceof x.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,i)]:[3,2]);case 1:return o=a.sent(),[3,7];case 2:return e instanceof x.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,i)]:[3,4];case 3:return o=a.sent(),[3,7];case 4:return e instanceof x.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,i)]:[3,6];case 5:return o=a.sent(),[3,7];case 6:return x.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,o),a.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,i,a,s,u,c,l,f,p,h,d,g,m,_,v,y,M,A,w,E,R,C,I,V,S,F,B,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(),i=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),a=t.getMorphTargetsFromMesh(e),s=e instanceof x.LinesMesh,u=e instanceof x.GreasedLineBaseMesh,c=e.subMeshes,!(i&&c&&c.length>0))return[3,7];l=0,f=c,T.label=1;case 1:return l<f.length?(p=f[l],h={attributes:{}},d=p.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:d.name},y=e,g=x.Color3.White(),m=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:g).equalsWithEpsilon(g,x.Epsilon)||m<1)&&(v.pbrMetallicRoughness={baseColorFactor:b(b([],_.asArray(),!0),[m],!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(x.Color3.White(),x.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,i,p,h)];case 4:T.sent(),T.label=5;case 5:for(M=s||u?x.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,A=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(A=A===x.Material.ClockWiseSideOrientation?x.Material.CounterClockWiseSideOrientation:x.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,x.AreIndices32Bits)(o,p.indexCount,p.indexStart,p.verticesStart):p.verticesCount>65535,o?p.indexStart:p.verticesStart,o?p.indexCount:p.verticesCount,-p.verticesStart,M,A,t,h),w=0,E=Object.values(i);w<E.length;w++)R=E[w],this._exportVertexBuffer(R,d,p.verticesStart,p.verticesCount,t,h);if(a)for(h.targets=[],C=0,I=a;C<I.length;C++)F=I[C],h.targets.push(F.attributes);r.primitives.push(h),this._extensionsPostExportMeshPrimitive(h),T.label=6;case 6:return l++,[3,1];case 7:if(a)for(r.weights=[],r.extras||(r.extras={}),r.extras.targetNames=[],V=0,S=a;V<S.length;V++)F=S[V],r.weights.push(F.influence),r.extras.targetNames.push(F.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(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new se(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}}))}))},e.GLBAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var r,o;return T(this,(function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new se(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}}))}))},e}(),ce="EXT_mesh_gpu_instancing";function le(e,t){for(var n=new Float32Array(3*t),r=0;r<t;r++)n[3*r+0]=e[4*r+0],n[3*r+1]=e[4*r+1],n[3*r+2]=e[4*r+2];return n}var fe=function(){function e(e){this.name=ce,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,n,r,o,i){return y(this,void 0,void 0,(function(){var e=this;return T(this,(function(r){switch(r.label){case 0:return[4,new Promise((function(r){var a,s;if(t&&n instanceof x.Mesh&&n.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var u=x.Vector3.Zero(),c=x.Quaternion.Identity(),l=x.Vector3.One(),f=n.thinInstanceGetWorldMatrices(),p=x.TmpVectors.Vector3[2],h=x.TmpVectors.Quaternion[1],d=x.TmpVectors.Vector3[3],g=!1,m=!1,_=!1,v=new Float32Array(3*n.thinInstanceCount),y=new Float32Array(4*n.thinInstanceCount),T=new Float32Array(3*n.thinInstanceCount),b=0,M=0,A=f;M<A.length;M++)A[M].decompose(d,h,p),o&&(j(p),z(h)),v.set(p.asArray(),3*b),y.set(h.normalize().asArray(),4*b),T.set(d.asArray(),3*b),g=g||!p.equalsWithEpsilon(u),m=m||!h.equalsWithEpsilon(c),_=_||!d.equalsWithEpsilon(l),b++;var w={attributes:{}};g&&(w.attributes.TRANSLATION=e._buildAccessor(v,"VEC3",n.thinInstanceCount,i)),m&&(w.attributes.ROTATION=e._buildAccessor(y,"VEC4",n.thinInstanceCount,i)),_&&(w.attributes.SCALE=e._buildAccessor(T,"VEC3",n.thinInstanceCount,i));var E=null===(s=null===(a=n._userThinInstanceBuffersStorage)||void 0===a?void 0:a.data)||void 0===s?void 0:s.instanceColor;if(E){var R=n.thinInstanceCount;n.hasVertexAlpha&&E.length===4*R?(e._instanceColorWarned||(x.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),E=le(E,R)):E.length===4*R&&(E=le(E,R)),E.length===3*R&&(w.attributes._COLOR_0=e._buildAccessor(E,"VEC3",R,i))}t.extensions=t.extensions||{},t.extensions[ce]=w}r(t)}))];case 1:return[2,r.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),i=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();se.RegisterExtension(ce,(function(e){return new fe(e)}));var pe="KHR_draco_mesh_compression",he=function(){function e(e){this.name=pe,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&x.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,n){var r=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],i=[],a=null;if(void 0!==e.indices){var s=n[e.indices],u=t.getBufferView(s);a=t.getData(u).slice(),o.push(u),i.push(s)}for(var c,l=[],f=0,p=Object.entries(e.attributes);f<p.length;f++){var h=p[f],d=h[0],g=(s=n[h[1]],u=t.getBufferView(s),W(s.type)),m=(0,x.GetTypedArrayData)(t.getData(u),g,s.componentType,s.byteOffset||0,u.byteStride||(0,x.GetTypeByteLength)(s.componentType)*g,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:W(s.type),data:m}),o.push(u),i.push(s)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},v=x.DracoEncoder.Default._encodeAsync(l,a,_).then((function(n){if(n){var a={bufferView:-1,attributes:n.attributeIds},s=t.createBufferView(n.data);t.setBufferView(a,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];r._bufferViewsUsed.add(l)}for(var f=0,p=i;f<p.length;f++){var h=p[f];r._accessorsUsed.add(h)}e.extensions||(e.extensions={}),e.extensions[pe]=a}else x.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){x.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(v),this._wasUsed=!0}else x.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(pe,(function(e){return new he(e)}));var de="KHR_lights_punctual",xe={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},ge={innerConeAngle:0,outerConeAngle:Math.PI/4},me=x.Vector3.Backward(),_e=function(){function e(e){this.name=de,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[de]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return y(this,void 0,void 0,(function(){var i=this;return T(this,(function(a){switch(a.label){case 0:return[4,new Promise((function(a){if(n instanceof x.Light){var s=n.getTypeID()==x.Light.LIGHTTYPEID_POINTLIGHT?"point":n.getTypeID()==x.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":n.getTypeID()==x.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(s&&n instanceof x.ShadowLight))return x.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(de)),void a(t);if(n.falloffType!==x.Light.FALLOFF_GLTF&&x.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(de," specification!")),!n.position.equalsToFloats(0,0,0)){var u=x.TmpVectors.Vector3[0].copyFrom(n.position);o&&j(u),t.translation=u.asArray()}if("point"!==s){var c=n.direction.normalizeToRef(x.TmpVectors.Vector3[0]);o&&j(c);var l=x.Quaternion.FromUnitVectorsToRef(me,c,x.TmpVectors.Quaternion[0]);x.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,xe),"spot"===s){var p=n;f.spot={innerConeAngle:p.innerAngle/2,outerConeAngle:p.angle/2},Z(f.spot,ge)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(f);var h={light:i._lights.lights.length-1},d=n.parent;if(d&&Y(n,d)){var g=r.get(d);if(g){var m=i._exporter._nodes[g];return Q(t,m),m.extensions||(m.extensions={}),m.extensions[de]=h,void a(null)}}t.extensions||(t.extensions={}),t.extensions[de]=h,a(t)}else a(t)}))];case 1:return[2,a.sent()]}}))}))},e}();se.RegisterExtension(de,(function(e){return new _e(e)}));var ve="EXT_lights_area",ye={name:"",color:[1,1,1],intensity:1,size:1},Te={aspect:1},be=x.Vector3.Backward(),Me=function(){function e(e){this.name=ve,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[ve]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return y(this,void 0,void 0,(function(){var i=this;return T(this,(function(a){switch(a.label){case 0:return[4,new Promise((function(a){if(n instanceof x.Light){var s=n.getTypeID()==x.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!s)return x.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(ve)),void a(t);var u=n;if(u.falloffType!==x.Light.FALLOFF_GLTF&&x.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(ve," specification!")),!u.position.equalsToFloats(0,0,0)){var c=x.TmpVectors.Vector3[0].copyFrom(u.position);o&&j(c),t.translation=c.asArray()}var l=x.Vector3.Forward();o&&j(l);var f=x.Quaternion.FromUnitVectorsToRef(be,l,x.TmpVectors.Quaternion[0]);x.Quaternion.IsIdentity(f)||(t.rotation=f.asArray());var p={type:s,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};Z(p,ye),p.rect&&Z(p.rect,Te),i._lights||(i._lights={lights:[]}),i._lights.lights.push(p);var h={light:i._lights.lights.length-1},d=n.parent;if(d&&Y(u,d)){var g=r.get(d);if(g){var m=i._exporter._nodes[g];return Q(t,m),m.extensions||(m.extensions={}),m.extensions[ve]=h,void a(null)}}t.extensions||(t.extensions={}),t.extensions[ve]=h,a(t)}else a(t)}))];case 1:return[2,a.sent()]}}))}))},e}();se.RegisterExtension(ve,(function(e){return new Me(e)}));var Ae="KHR_materials_anisotropy";function we(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=e.getScene(),n=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n||r?[4,(0,x.MergeTexturesAsync)("AnisotropyTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,1):(0,x.CreateConstantInput)(0),n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}}))}))}var Ee=function(){function e(e){this.name=Ae,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,r;return T(this,(function(o){switch(o.label){case 0:return e=[],n instanceof x.PBRBaseMaterial?n.anisotropy.isEnabled&&!n.anisotropy.legacy?(n.anisotropy.texture&&e.push(n.anisotropy.texture),[2,e]):[3,5]:[3,1];case 1:return n instanceof x.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0?(t=function(e){var t=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}(n),this._anisoTexturesMap[t]?(e.push(this._anisoTexturesMap[t]),[3,4]):[3,2]):[3,5];case 2:return[4,we(n)];case 3:(r=o.sent())&&(e.push(r),this._anisoTexturesMap[t]=r),o.label=4;case 4:return[2,e];case 5:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o,i,a,s,u,c;if(n instanceof x.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[Ae]=v}else if(n instanceof x.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 g=(i=n.specularRoughness,c=(1-(a=n.specularRoughnessAnisotropy))*(u=(s=i*i)*Math.sqrt(2/(1+(1-a)*(1-a)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});h=g.newBaseRoughness,d=g.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);var m={anisotropyStrength:d,anisotropyRotation:n.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[Ae]=m,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[Ae]=v}e(t)}))},e}();se.RegisterExtension(Ae,(function(e){return new Ee(e)}));var Re="KHR_materials_clearcoat",Ce=function(){function e(e){this.name=Re,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 x.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 x.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 x.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),i=void 0;i=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness),n.clearCoat.isTintEnabled&&x.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),n.clearCoat.remapF0OnInterfaceChange&&x.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(n.name));var a=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture);null===(s={clearcoatFactor:n.clearCoat.intensity,clearcoatTexture:null!=o?o:void 0,clearcoatRoughnessFactor:n.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=a?a:void 0}).clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Re]=s}else if(n instanceof x.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),i=void 0,i=n.useCoatRoughnessFromWeightTexture?r._exporter._materialExporter.getTextureInfo(n.coatWeightTexture):r._exporter._materialExporter.getTextureInfo(n.coatRoughnessTexture),n.coatColorTexture&&x.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),a=r._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),null===(s={clearcoatFactor:n.coatWeight,clearcoatTexture:null!=o?o:void 0,clearcoatRoughnessFactor:n.coatRoughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=a?a:void 0}).clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Re]=s}e(t)}))},e}();se.RegisterExtension(Re,(function(e){return new Ce(e)}));var Ie="KHR_materials_clearcoat_darkening",Ve=function(){function e(e){this.name=Ie,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){return e=[],n instanceof x.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,i=null;if(n instanceof x.OpenPBRMaterial&&(o=n.coatDarkening,i=n.coatDarkeningTexture),null===o||1===o&&null===i)return e(t);var a=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!a)return e(t);r._wasUsed=!0;var s=r._exporter._materialExporter.getTextureInfo(i),u={clearcoatDarkeningFactor:o,clearcoatDarkeningTexture:null!=s?s:void 0};return null!==u.clearcoatDarkeningTexture&&r._exporter._materialNeedsUVsSet.add(n),a.extensions=a.extensions||{},a.extensions[Ie]=u,e(t)}))},e}();se.RegisterExtension(Ie,(function(e){return new Ve(e)}),105);var Se="KHR_materials_clearcoat_ior",Fe=function(){function e(e){this.name=Se,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 x.OpenPBRMaterial?o=n.coatIor:n instanceof x.PBRMaterial&&(o=n.clearCoat.indexOfRefraction),null===o||1.5===o)return e(t);var i=t.extensions?t.extensions.KHR_materials_clearcoat:null;if(!i)return e(t);r._wasUsed=!0;var a={clearcoatIor:o};return r._exporter,i.extensions=i.extensions||{},i.extensions[Se]=a,e(t)}))},e}();se.RegisterExtension(Se,(function(e){return new Fe(e)}),105);var Be="KHR_materials_clearcoat_color",Oe=function(){function e(e){this.name=Be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return y(this,void 0,void 0,(function(){var e;return T(this,(function(t){if(e=[],n instanceof x.PBRBaseMaterial){if(n.clearCoat.isEnabled)return n.clearCoat.tintTexture&&e.push(n.clearCoat.tintTexture),[2,e]}else if(n instanceof x.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 x.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);if(r._wasUsed=!0,!(i=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);var o=r._exporter._materialExporter.getTextureInfo(n.clearCoat.tintTexture);null!==(a={clearcoatColorFactor:n.clearCoat.tintColor.asArray(),clearcoatColorTexture:null!=o?o:void 0}).clearcoatColorTexture&&r._exporter._materialNeedsUVsSet.add(n),i.extensions=i.extensions||{},i.extensions[Be]=a}else if(n instanceof x.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);var i,a;if(r._wasUsed=!0,!(i=t.extensions?t.extensions.KHR_materials_clearcoat:null))return void e(t);o=r._exporter._materialExporter.getTextureInfo(n.coatWeightTexture),null!==(a={clearcoatColorFactor:n.coatColor.asArray(),clearcoatColorTexture:null!=o?o:void 0}).clearcoatColorTexture&&r._exporter._materialNeedsUVsSet.add(n),i.extensions=i.extensions||{},i.extensions[Be]=a}e(t)}))},e}();se.RegisterExtension(Be,(function(e){return new Oe(e)}),105);var Pe="KHR_materials_clearcoat_anisotropy";function Ue(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=e.getScene(),n=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n||r?[4,(0,x.MergeTexturesAsync)("AnisotropyTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,1):(0,x.CreateConstantInput)(0),n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}}))}))}var Ne=function(){function e(e){this.name=Pe,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,r;return T(this,(function(o){switch(o.label){case 0:return e=[],n instanceof x.OpenPBRMaterial&&n.coatRoughnessAnisotropy>0?(t=function(e){var t=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}(n),this._anisoTexturesMap[t]?(e.push(this._anisoTexturesMap[t]),[3,3]):[3,1]):[3,4];case 1:return[4,Ue(n)];case 2:(r=o.sent())&&(e.push(r),this._anisoTexturesMap[t]=r),o.label=3;case 3:return[2,e];case 4:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){var o,i,a,s,u,c;if(n instanceof x.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 g=(i=n.coatRoughness,c=(1-(a=n.coatRoughnessAnisotropy))*(u=(s=i*i)*Math.sqrt(2/(1+(1-a)*(1-a)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});h=g.newBaseRoughness,d=g.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);var m={clearcoatAnisotropyStrength:d,clearcoatAnisotropyRotation:n.geometryCoatTangentAngle+.5*Math.PI,clearcoatAnisotropyTexture:void 0};return l.extensions=l.extensions||{},l.extensions[Pe]=m,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[Pe]=v}e(t)}))},e}();se.RegisterExtension(Pe,(function(e){return new Ne(e)}),105);var Le="KHR_materials_diffuse_transmission";function ke(e,t){var n=t.subSurface,r=null;return n.translucencyIntensityTexture?r=n.translucencyIntensityTexture:n.thicknessTexture&&n.useMaskFromThicknessTexture&&(r=n.thicknessTexture),r&&!n.useGltfStyleTextures?(x.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):r}var Ke=function(){function e(e){this.name=Le,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 x.PBRMaterial&&this._isExtensionEnabled(n)?((r=ke(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 i,a;if(n instanceof x.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var s=n.subSurface,u=ke(e,n),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(i=r._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0,f=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),p=null!==(a=r._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==a?a:void 0,h={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:p};(l||p)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[Le]=h}o(t)}))},e}();se.RegisterExtension(Le,(function(e){return new Ke(e)}));var De="KHR_materials_dispersion",We=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._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 x.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={dispersion:n.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[De]=o}e(t)}))},e}();se.RegisterExtension(De,(function(){return new We}));var He="KHR_materials_emissive_strength",Ge=function(){function e(){this.name=He,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 x.PBRMaterial))return r(t);var o=n.emissiveColor.scale(n.emissiveIntensity),i=Math.max.apply(Math,o.asArray());if(i>1){t.emissiveFactor=o.scale(1/i).asArray(),e._wasUsed=!0;var a={emissiveStrength:i};t.extensions||(t.extensions={}),t.extensions[He]=a}else t.emissiveFactor=o.asArray();return r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(He,(function(){return new Ge}));var qe="KHR_materials_ior",je=function(){function e(){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._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 x.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={ior:n.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[qe]=o}e(t)}))},e}();se.RegisterExtension(qe,(function(e){return new je}));var ze="KHR_materials_iridescence",Xe=function(){function e(e){this.name=ze,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 x.PBRBaseMaterial){if(n.iridescence.isEnabled)return n.iridescence.texture&&e.push(n.iridescence.texture),n.iridescence.thicknessTexture&&n.iridescence.thicknessTexture!==n.iridescence.texture&&e.push(n.iridescence.thicknessTexture),[2,e]}else if(n instanceof x.OpenPBRMaterial&&n.thinFilmWeight>0)return n.thinFilmWeightTexture&&e.push(n.thinFilmWeightTexture),n.thinFilmThicknessTexture&&n.thinFilmThicknessTexture!==n.thinFilmWeightTexture&&e.push(n.thinFilmThicknessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise((function(e){if(n instanceof x.PBRBaseMaterial){if(!n.iridescence.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.iridescence.texture),i=r._exporter._materialExporter.getTextureInfo(n.iridescence.thicknessTexture);null===(a={iridescenceFactor:n.iridescence.intensity,iridescenceIor:n.iridescence.indexOfRefraction,iridescenceThicknessMinimum:n.iridescence.minimumThickness,iridescenceThicknessMaximum:n.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0}).iridescenceTexture&&null===a.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[ze]=a}else if(n instanceof x.OpenPBRMaterial){if(n.thinFilmWeight<=0)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var a,s=r._exporter._materialExporter.getTextureInfo(n.thinFilmWeightTexture),u=r._exporter._materialExporter.getTextureInfo(n.thinFilmThicknessTexture);null===(a={iridescenceFactor:n.thinFilmWeight,iridescenceIor:n.thinFilmIor,iridescenceThicknessMinimum:1e3*n.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*n.thinFilmThickness,iridescenceTexture:null!=s?s:void 0,iridescenceThicknessTexture:null!=u?u:void 0}).iridescenceTexture&&null===a.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[ze]=a}e(t)}))},e}();se.RegisterExtension(ze,(function(e){return new Xe(e)}));var Qe="KHR_materials_sheen",Ye=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 x.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,i,a,s;if(n instanceof x.PBRMaterial){if(!n.sheen.isEnabled)return void r(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:n.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=n.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),n.sheen.texture&&(u.sheenColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==i?i:void 0),n.sheen.textureRoughness&&!n.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(n.sheen.textureRoughness))&&void 0!==a?a:void 0:n.sheen.texture&&n.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==s?s:void 0),t.extensions[Qe]=u}r(t)}))];case 1:return[2,r.sent()]}}))}))},e}();se.RegisterExtension(Qe,(function(e){return new Ye(e)}));var Ze="KHR_materials_specular",Je=function(){function e(e){this.name=Ze,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 x.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,i,a,s,u;if(n instanceof x.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!==(i=r._exporter._materialExporter.getTextureInfo(n.reflectanceTexture))&&void 0!==i?i: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[Ze]=f}else if(n instanceof x.OpenPBRMaterial){t.extensions=t.extensions||{};var p=null!==(a=r._exporter._materialExporter.getTextureInfo(n.specularWeightTexture))&&void 0!==a?a: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,g=n.specularColor.equalsFloats(1,1,1)?void 0:n.specularColor.asArray();if(!h&&!p&&void 0===d&&void 0===g)return e(t);r._wasUsed=!0,(f={specularFactor:d,specularTexture:p,specularColorFactor:g,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[Ze]=f}e(t)}))},e}();se.RegisterExtension(Ze,(function(e){return new Je(e)}));var $e="KHR_materials_transmission",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 x.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,i,a;return T(this,(function(s){switch(s.label){case 0:return n instanceof x.PBRMaterial&&this._isExtensionEnabled(n)?(this._wasUsed=!0,r=n.subSurface,o=0===r.refractionIntensity?void 0:r.refractionIntensity,i={transmissionFactor:o},this._hasTexturesExtension(n)&&this._exporter._materialNeedsUVsSet.add(n),r.refractionIntensityTexture?r.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(r.refractionIntensityTexture)]:[3,2]:[3,3]):[3,4];case 1:return(a=s.sent())&&(i.transmissionTexture=a),[3,3];case 2:x.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[$e]=i,s.label=4;case 4:return[2,t]}}))}))},e}();se.RegisterExtension($e,(function(e){return new et(e)}));var tt="KHR_materials_unlit",nt=function(){function e(){this.name=tt,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 x.PBRMaterial?o=n.unlit:n instanceof x.StandardMaterial&&(o=n.disableLighting),o&&(r._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[tt]={}),e(t)}))},e}();se.RegisterExtension(tt,(function(){return new nt}));var rt="KHR_materials_volume",ot=function(){function e(e){this.name=rt,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 x.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!=x.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 x.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var i=n.subSurface,a={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(o=r._exporter._materialExporter.getTextureInfo(i.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray()};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[rt]=a}e(t)}))},e}();se.RegisterExtension(rt,(function(e){return new ot(e)}));var it="KHR_materials_diffuse_roughness",at=function(){function e(e){this.name=it,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 x.PBRBaseMaterial){if(n._baseDiffuseRoughness)return n._baseDiffuseRoughnessTexture&&e.push(n._baseDiffuseRoughnessTexture),[2,e]}else if(n instanceof x.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,i=null;if(n instanceof x.PBRBaseMaterial?(o=n._baseDiffuseRoughness,i=n._baseDiffuseRoughnessTexture):n instanceof x.OpenPBRMaterial&&(o=n.baseDiffuseRoughness,i=n.baseDiffuseRoughnessTexture),o){r._wasUsed=!0,t.extensions=t.extensions||{};var a=r._exporter._materialExporter.getTextureInfo(i),s={diffuseRoughnessFactor:o,diffuseRoughnessTexture:null!=a?a:void 0};null!==s.diffuseRoughnessTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[it]=s,e(t)}else e(t)}))},e}();se.RegisterExtension(it,(function(e){return new at(e)}));var st="KHR_texture_transform",ut=function(){function e(){this.name=st,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()||x.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(n.name,"!")),0===n.uAng&&0===n.vAng||(x.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 x.Tools.Warn("".concat(e,": Texture ").concat(n.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(st,"."));x.Tools.Warn("".concat(e,": Texture ").concat(n.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(st,".")),r.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,a=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*i,f=o*a;return[t+(l*(1-u)+f*c),n+(f*(1-u)-l*c)]}(n)}r.rotation=-n.wAng,o=!0}0!==n.coordinatesIndex&&(r.texCoord=n.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[st]=r)}},e}();se.RegisterExtension(st,(function(){return new ut}));var ct="KHR_texture_basisu",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/ktx2"===(o.mimeType||(0,x.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="EXT_texture_webp",pt=function(){function e(e){this.name=ft,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,x.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[ft]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(ft,(function(e){return new pt(e)}));var ht="EXT_texture_avif",dt=function(){function e(e){this.name=ht,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,x.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[ht]={source:r},this._wasUsed=!0)}},e}();se.RegisterExtension(ht,(function(e){return new dt(e)}));var xt=function(){function e(){}return e.CreateSTL=function(e,t,n,r,o,i,a,s){void 0===t&&(t=!0),void 0===n&&(n="stlmesh"),void 0===r&&(r=!1),void 0===o&&(o=!0),void 0===i&&(i=!1),void 0===a&&(a=!1),void 0===s&&(s=!1);var u=function(e,t,n){var r=[3*e[n],3*e[n+1],3*e[n+2]],o=[new x.Vector3(t[r[0]],t[r[0]+2],t[r[0]+1]),new x.Vector3(t[r[1]],t[r[1]+2],t[r[1]+1]),new x.Vector3(t[r[2]],t[r[2]+2],t[r[2]+1])],i=o[0].subtract(o[1]),a=o[2].subtract(o[1]);return{v:o,n:x.Vector3.Cross(a,i).normalize()}},c=function(e,t,n,r){return t=l(e,t,n.x,r),t=l(e,t,n.y,r),l(e,t,n.z,r)},l=function(e,t,n,r){return e.setFloat32(t,n,r),t+4},f=function(e){if(a){var t=e;e instanceof x.InstancedMesh&&(t=e.sourceMesh);var n=t.getVerticesData(x.VertexBuffer.PositionKind,!0,!0);if(!n)return[];var r=x.Vector3.Zero(),o=void 0;for(o=0;o<n.length;o+=3)x.Vector3.TransformCoordinatesFromFloatsToRef(n[o],n[o+1],n[o+2],e.computeWorldMatrix(!0),r).toArray(n,o);return n}return e.getVerticesData(x.VertexBuffer.PositionKind)||[]};a&&(i=!0);var p="",h=0,d=0;if(r){for(var g=0;g<e.length;g++)h+=(y=(_=e[g]).getIndices())?y.length/3:0;var m=new ArrayBuffer(84+50*h);d+=80,(p=new DataView(m)).setUint32(d,h,o),d+=4}else s||(p="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!r&&s&&(p+="solid "+_.name+"\r\n"),!i&&_ instanceof x.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 M=document.createElement("a"),A=new Blob([p],{type:"application/octet-stream"});M.href=window.URL.createObjectURL(A),M.download=n+".stl",M.click()}return p},e}();function gt(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],i=0;i<e.length/n;i++){var a=e[i*n]*(r?-1:1),s=e[i*n+1],u=e[i*n+2];o.push("(".concat(a.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function mt(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],i=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-i).toPrecision(t.precision),")"))}return n.join(", ")}function _t(e,t,n,r){var o=function(e,t,n,r){var o=e.getVerticesData(x.VertexBuffer.PositionKind),i=e.getVerticesData(x.VertexBuffer.NormalKind);if(o&&i)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(n,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,n=e.getIndices(),r=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==n)for(var i=0;i<r;i++)o.push(n[i]);else for(i=0;i<r;i++)o.push(i);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(gt(i,t,void 0,r),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(gt(o,t,void 0,r),"]\n ").concat(function(e,t){for(var n="",r=0;r<4;r++){var o=r>0?r:"",i=e.getVerticesData(x.VertexBuffer.UVKind+(o?o+1:""));i&&(n+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(mt(i,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var a=e.getVerticesData(x.VertexBuffer.ColorKind);return a&&(n+="\n\tcolor3f[] primvars:displayColor = [".concat(gt(a,t,a.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),n}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t,n,r);return'\n def "Geometry"\n {\n '.concat(o,"\n }\n ")}function vt(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 yt(e){var t=e.m;return"( ".concat(Tt(t,0),", ").concat(Tt(t,4),", ").concat(Tt(t,8),", ").concat(Tt(t,12)," )")}function Tt(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function bt(e,t){var n="Object_"+e.uniqueId,r=yt(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 Mt(e){switch(e){case x.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case x.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case x.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function At(e){return"(".concat(e.x,", ").concat(e.y,")")}function wt(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function Et(e,t,n,r,o,i){var a=e.getInternalTexture().uniqueId+"_"+e.invertY;o[a]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new x.Vector2(e.uScale,e.vScale),c=new x.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(i.precision),"\n float2 inputs:scale = ").concat(At(u),"\n float2 inputs:translation = ").concat(At(c),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(n,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(a,".png@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(t.uniqueId,"/Transform2d_").concat(n,".outputs:result>\n ").concat(r?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(r):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(Mt(e.wrapU),'"\n token inputs:wrapT = "').concat(Mt(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 Rt(e,t,n){var r="\t\t\t",o=[],i=[],a=function(e){var t,n,r={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof x.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 x.PBRBaseMaterial?v(v({},r),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(t=e._roughness)&&void 0!==t?t:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(n=e._metallic)&&void 0!==n?n:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):r}(e),s=a.diffuseMap,u=a.diffuse,c=a.alphaCutOff,l=a.emissiveMap,f=a.emissive,p=a.normalMap,h=a.roughnessMap,d=a.roughnessChannel,g=a.roughness,m=a.metalnessMap,_=a.metalnessChannel,y=a.metalness,T=a.aoMap,b=a.aoMapChannel,M=a.aoMapIntensity,A=a.alphaMap,w=a.ior,E=a.clearCoatEnabled,R=a.clearCoat,C=a.clearCoatMap,I=a.clearCoatRoughness,V=a.clearCoatRoughnessMap;return null!==s?(o.push("".concat(r,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(r,"float inputs:opacityThreshold = ").concat(c))),i.push(Et(s,e,"diffuse",u,t,n))):o.push("".concat(r,"color3f inputs:diffuseColor = ").concat(wt(u||x.Color3.White()))),null!==l?(o.push("".concat(r,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),i.push(Et(l,e,"emissive",f,t,n))):f&&f.toLuminance()>0&&o.push("".concat(r,"color3f inputs:emissiveColor = ").concat(wt(f))),null!==p&&(o.push("".concat(r,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_normal.outputs:rgb>")),i.push(Et(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,">")),i.push(Et(T,e,"occlusion",new x.Color3(M,M,M),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,">")),i.push(Et(h,e,"roughness",new x.Color3(g,g,g),t,n))):o.push("".concat(r,"float inputs:roughness = ").concat(g)),null!==m?(o.push("".concat(r,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(m.uniqueId,"_metallic.outputs:").concat(_,">")),i.push(Et(m,e,"metallic",new x.Color3(y,y,y),t,n))):o.push("".concat(r,"float inputs:metallic = ").concat(y)),null!==A?(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(A.uniqueId,"_opacity.outputs:r>")),o.push("".concat(r,"float inputs:opacityThreshold = 0.0001")),i.push(Et(A,e,"opacity",null,t,n))):o.push("".concat(r,"float inputs:opacity = ").concat(e.alpha)),E&&(null!==C?(o.push("".concat(r,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(C.uniqueId,"_clearcoat.outputs:r>")),i.push(Et(C,e,"clearcoat",new x.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>")),i.push(Et(V,e,"clearcoatRoughness",new x.Color3(I,I,I),t,n))):o.push("".concat(r,"float inputs:clearcoatRoughness = ").concat(I))),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(i.join("\n"),"\n\n\t}\n")}function Ct(e){var t,n;e.computeWorldMatrix(!0);for(var r=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,i=null!==(n=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==n?n:e.sideOrientation,a=!o,s=e.parent;s;){if(U(s,o)&&null===s.parent){o||(r.multiplyToRef(s.getWorldMatrix().invert(),r),i=i===x.Material.ClockWiseSideOrientation?x.Material.CounterClockWiseSideOrientation:x.Material.ClockWiseSideOrientation),a=!1;break}s=s.parent}return r.determinant()<0&&x.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:r,windingOrder:i===x.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:a}}function It(e,t,n){return y(this,void 0,void 0,(function(){var r,o,i,a,s,u,c,l,f,p,h,d,g,m,_,y,b,M,A,w,E,R,C,I,V,S,F,B,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,x.Tools.LoadScriptAsync(r.fflateUrl)];case 1:T.sent(),T.label=2;case 2:for((o={})[r.modelFileName]=null,i='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',i+=function(e){var t=!0===e.includeAnchoringProperties?'\n\t\ttoken preliminary:anchoring:type = "'.concat(e.anchoringType,'"\n\t\ttoken preliminary:planeAnchoring:alignment = "').concat(e.planeAnchoringAlignment,'"'):"";return'def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {'.concat(t,"\n ")}(r),a={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(f=(l=c).geometry,(p=l.material)&&f&&(!n||n(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(p.getClassName())?(h="geometries/Geometry_"+f.uniqueId+".usda",d=Ct(l),g=d.matrix,m=d.windingOrder,_=d.convertToRightHanded,h in o||(y=_t(f,r,m,_),o[h]=vt(y)),p.uniqueId in a||(a[p.uniqueId]=p),i+=bt(l,g)):x.Tools.Warn("USDZExportAsync does not support this material type: "+p.getClassName())));for(w in e.activeCamera&&r.exportCamera&&(i+=function(e,t){var n="Camera_"+e.uniqueId,r=yt(x.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===x.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(t.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var o=e.getEngine().getAspectRatio(e),i=t.cameraSensorWidth||35;return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat focalLength = ").concat((i/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((i*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((i/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,r)),i+="\n }\n }",i+=function(e,t,n){var r=[];for(var o in e){var i=e[o];r.push(Rt(i,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(a,b={},r),i+="\n }",o[r.modelFileName]=fflate.strToU8(i),A=[],M=b)A.push(w);E=0,T.label=3;case 3:return E<A.length?(w=A[E])in M?(C=b[R=w],I=C.getSize(),[4,(0,x.GetTextureDataAsync)(C)]):[3,6]:[3,7];case 4:return V=T.sent(),[4,x.DumpTools.DumpDataAsync(I.width,I.height,V,"image/png",void 0,!1,!0)];case 5:S=T.sent(),o["textures/Texture_".concat(R,".png")]=new Uint8Array(S).slice(),T.label=6;case 6:return E++,[3,3];case 7:for(B in F=0,o)(O=o[B])&&(P=34+B.length,4!=(U=63&(F+=P))&&(N=new Uint8Array(64-U),o[B]=[O,{extra:{12345:N}}]),F=O.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var Vt=function(){function e(){}return e.Export=function(e,t,n){var r;if(void 0===t&&(t=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var o=t;t&&0!==t.length||(o=e.animations.map((function(e){return e.name})));for(var i=null,a=0,s=o;a<s.length;a++){var u=s[a],c=e.getAnimationRange(u);c&&(i=i?new x.AnimationRange("animation-range",Math.min(i.from,c.from),Math.max(i.to,c.to)):c)}if(!i&&(e.animations.length>0&&(i=e.getAnimationRange(e.animations[0].name)),!i))throw new Error("No animation range found in skeleton");for(var l=n||1/((null===(r=e.animations[0])||void 0===r?void 0:r.framePerSecond)||30),f=this._BuildBoneHierarchy(e,o),p=0,h=0,d=f;h<d.length;h++){var g=d[h];g.positionKeys.length>0&&(p=Math.max(p,g.positionKeys.length)),g.rotationKeys.length>0&&(p=Math.max(p,g.rotationKeys.length))}0===p&&(p=Math.floor((i.to-i.from)/l)+1);var m="";return m+="HIERARCHY\n",m+=this._ExportHierarchy(f,0),m+="MOTION\n",m+="Frames: ".concat(p,"\n"),(m+="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,i=[],a=0,s=e.bones;a<s.length;a++){var u={bone:f=s[a],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};o.set(f,u)}for(var c=0,l=e.bones;c<l.length;c++){var f=l[c];if(u=o.get(f),f.animations.length>0)for(var 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 x=o.get(f.getParent());x&&x.children.push(u)}else i.push(u)}return i},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,i=e;o<i.length;o++){var a=i[o],s=a.bone;if(this._IsEndSite(a)){n+="".concat(r,"End Site\n"),n+="".concat(r,"{\n");var u=this._GetBoneOffset(s);n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),n+="".concat(r,"}\n")}else{n+="".concat(0===t?"ROOT":"".concat(r,"JOINT")," ").concat(s.name,"\n"),n+="".concat(r,"{\n"),u=this._GetBoneOffset(s),n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];a.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),a.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),a.children.length>0&&(n+=this._ExportHierarchy(a.children,t+1)),n+="".concat(r,"}\n")}}return n},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return x.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",i=0;i<t;i++){var a=[];this._CollectFrameValues(e,i+n,a,r),o+=a.map((function(e){return e.toFixed(6)})).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,i=e;o<i.length;o++){var a=i[o];if(!this._IsEndSite(a)){if(a.hasPositionChannels){var s=this._GetPositionAtFrameIndex(a.positionKeys,t);n.push(s.x,s.y,s.z)}if(a.hasRotationChannels){var u=this._GetRotationAtFrameIndex(a.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}a.children.length>0&&this._CollectFrameValues(a.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?x.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?x.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new x.Matrix;e.toRotationMatrix(t);var n,r,o,i=t.m,a=Math.sqrt(i[0]*i[0]+i[1]*i[1]);return a>x.Epsilon?(n=Math.atan2(i[6],i[10]),r=Math.atan2(-i[2],a),o=Math.atan2(i[1],i[0])):(n=Math.atan2(-i[9],i[5]),r=Math.atan2(-i[2],a),o=0),new x.Vector3(x.Tools.ToDegrees(n),x.Tools.ToDegrees(r),x.Tools.ToDegrees(o))},e}(),St=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==St)for(var Ft in h)St.BABYLON[Ft]=h[Ft];var Bt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Bt){Bt.BABYLON=Bt.BABYLON||{};var Ot=Bt.BABYLON;Ot.GLTF2=Ot.GLTF2||{},Ot.GLTF2.Exporter=Ot.GLTF2.Exporter||{},Ot.GLTF2.Exporter.Extensions=Ot.GLTF2.Exporter.Extensions||{};var Pt=[];for(var Ut in a)Ot[Ut]=a[Ut],Pt.push(Ut);for(var Ut in s)Ot[Ut]=s[Ut],Pt.push(Ut);for(var Ut in u)Ot[Ut]=u[Ut],Pt.push(Ut);for(var Ut in c)Ot.GLTF2.Exporter.Extensions[Ut]=c[Ut],Pt.push(Ut);for(var Ut in l)Pt.indexOf(Ut)>-1||(Ot.GLTF2.Exporter[Ut]=l[Ut])}var Nt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Nt)for(var Lt in i)Nt.BABYLON[Lt]=i[Lt];var kt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==kt)for(var Kt in f)kt.BABYLON[Kt]=f[Kt];var Dt=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Dt)for(var Wt in p)Dt.BABYLON[Wt]=p[Wt];const Ht=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}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.d(o,{default:()=>Ht});var a={};n.r(a),n.d(a,{OBJExport:()=>g});var s={};n.r(s),n.d(s,{__IGLTFExporterExtension:()=>m});var i={};n.r(i),n.d(i,{GLTFData:()=>_});var u={};n.r(u),n.d(u,{GLTF2Export:()=>ue});var c={};n.r(c),n.d(c,{EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>mt,EXT_texture_webp:()=>xt,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Ve,KHR_materials_coat:()=>Ne,KHR_materials_diffuse_roughness:()=>ct,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_texture_basisu:()=>pt,KHR_texture_transform:()=>ht});var l={};n.r(l),n.d(l,{EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>mt,EXT_texture_webp:()=>xt,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Ve,KHR_materials_coat:()=>Ne,KHR_materials_diffuse_roughness:()=>ct,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_texture_basisu:()=>pt,KHR_texture_transform:()=>ht,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>I});var h={};n.r(h),n.d(h,{STLExport:()=>_t});var f={};n.r(f),n.d(f,{USDZExportAsync:()=>Ft});var p={};n.r(p),n.d(p,{BVHExporter:()=>Bt});var d={};n.r(d),n.d(d,{BVHExporter:()=>Bt,EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>mt,EXT_texture_webp:()=>xt,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Ve,KHR_materials_coat:()=>Ne,KHR_materials_diffuse_roughness:()=>ct,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_texture_basisu:()=>pt,KHR_texture_transform:()=>ht,OBJExport:()=>g,STLExport:()=>_t,USDZExportAsync:()=>Ft,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>I,__IGLTFExporterExtension:()=>m});var x=n(597),g=function(){function e(){}return e.OBJ=function(e,t,r,n){var o=[],a=1,s=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var i=0;i<e.length;i++){var u=e[i],c=u.name||"mesh".concat(i,"}");o.push("o ".concat(c));var l=null;if(n){var h=u.computeWorldMatrix(!0);l=new x.Matrix,h.invertToRef(l),u.bakeTransformIntoVertices(h)}if(t){var f=u.material;f&&o.push("usemtl "+f.id)}var p=u.geometry;if(p){var d=p.getVerticesData("position"),g=p.getVerticesData("normal"),m=p.getVerticesData("uv"),_=p.getIndices(),T=0,v=0;if(d&&_){for(var y=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*y+" "+d[b+1]+" "+d[b+2]),T++;if(null!=g)for(b=0;b<g.length;b+=3)o.push("vn "+g[b]*y+" "+g[b+1]+" "+g[b+2]);if(null!=m)for(b=0;b<m.length;b+=2)o.push("vt "+m[b]+" "+m[b+1]),v++;var M=["","",""],w=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===x.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=w[0],R=w[1];for(b=0;b<_.length;b+=3){var C=[String(_[b]+a),String(_[b+A]+a),String(_[b+R]+a)],E=[String(_[b]+s),String(_[b+A]+s),String(_[b+R]+s)],I=C,V=null!=m?E:M,S=null!=g?C:M;o.push("f "+I[0]+"/"+V[0]+"/"+S[0]+" "+I[1]+"/"+V[1]+"/"+S[1]+" "+I[2]+"/"+V[2]+"/"+S[2])}n&&l&&u.bakeTransformIntoVertices(l),a+=T,s+=v}else x.Tools.Warn("There are no position vertices or indices on the mesh!")}else x.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],r=e.material;return t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4)),r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e}(),m=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],r=new Blob([t],{type:(0,x.GetMimeType)(e)});x.Tools.Download(r,e)}},e}(),T=function(){return T=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},T.apply(this,arguments)};function v(e,t,r,n){return new(r||(r=Promise))((function(o,a){function s(e){try{u(n.next(e))}catch(e){a(e)}}function i(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,i)}u((n=n.apply(e,t||[])).next())}))}function y(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=i(0),s.throw=i(1),s.return=i(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function b(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var M=1e-6,w=new x.Color3(.04,.04,.04),A=1024,R=x.Color3.White(),C=x.Color3.BlackReadOnly;function E(e){return v(this,void 0,void 0,(function(){var t,r,n,o;return y(this,(function(a){switch(a.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(r=t._buffer,o=e.mimeType,r?[3,2]:[4,x.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return n=a.sent(),o=(0,x.GetMimeType)(t.url)||o,[3,10];case 2:return ArrayBuffer.isView(r)?(n=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,10]):[3,3];case 3:return r instanceof ArrayBuffer?(n=r,[3,10]):[3,4];case 4:return r instanceof Blob?[4,r.arrayBuffer()]:[3,6];case 5:return n=a.sent(),o=r.type||o,[3,10];case 6:return"string"!=typeof r?[3,8]:[4,x.Tools.LoadFileAsync(r)];case 7:return n=a.sent(),o=(0,x.GetMimeType)(r)||o,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,x.Tools.LoadFileAsync(r.src)]:[3,10];case 9:n=a.sent(),o=(0,x.GetMimeType)(r.src)||o,a.label=10;case 10:return n&&o?[2,{data:n,mimeType:o}]:[2,null]}}))}))}function I(e,t,r){if(t<w.r)return 0;var n=w.r,o=e*r/(1-w.r)+t-2*w.r,a=o*o-4*n*(w.r-t);return x.Scalar.Clamp((-o+Math.sqrt(a))/(2*n),0,1)}function V(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=x.Scalar.Clamp(e.specularPower,0,A),o=(0,x.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:o}}function S(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function F(e,t,r){for(var n=new Uint8Array(e*t*4),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return x.RawTexture.CreateRGBATexture(n,e,t,r)}function B(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var 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.uniqueId))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c;return y(this,(function(l){switch(l.label){case 0:return r=V(e),n={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||x.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),t?(o=[],(a=e.diffuseTexture)&&o.push(this.exportTextureAsync(a).then((function(e){e&&(r.baseColorTexture=e)}))),(s=e.bumpTexture)&&o.push(this.exportTextureAsync(s).then((function(e){e&&(n.normalTexture=e,1!==s.level&&(n.normalTexture.scale=s.level))}))),(i=e.emissiveTexture)&&(n.emissiveFactor=[1,1,1],o.push(this.exportTextureAsync(i).then((function(e){e&&(n.emissiveTexture=e)})))),(u=e.ambientTexture)&&o.push(this.exportTextureAsync(u).then((function(e){if(e){var t={index:e.index};n.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===x.Constants.ALPHA_COMBINE?n.alphaMode="BLEND":x.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(C,M)&&(n.emissiveFactor=e.emissiveColor.asArray()),n.pbrMetallicRoughness=r,S(n,e),[4,this._finishMaterialAsync(n,e)];case 3:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s;return y(this,(function(i){switch(i.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(r=i.sent(),n=[],o=0,a=r;o<a.length;o++)s=a[o],n.push(this.exportTextureAsync(s));return[4,Promise.all(n)];case 2:return i.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return i.sent(),[2]}}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return v(this,void 0,void 0,(function(){return y(this,(function(o){switch(o.label){case 0:return[4,x.DumpTools.DumpDataAsync(t,r,e,n,void 0,!1,!0)];case 1:return[2,o.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,a=e?e.getSize():{width:0,height:0},s=t?t.getSize():{width:0,height:0};return a.width<s.width?(n=e&&e instanceof x.Texture?x.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):F(s.width,s.height,r),o=t):a.width>s.width?(o=t&&t instanceof x.Texture?x.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):F(a.width,a.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return v(this,void 0,void 0,(function(){var o,a,s,i,u,c,l,h,f,p,d,g,m,_,T,v,b,w,A,C,E,I,V,S,F,O,P,N,U,L,k;return y(this,(function(y){switch(y.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,y.sent()];case 2:return(a=e?e.getScene():t?t.getScene():null)?(s=this._resizeTexturesToSameDimensions(e,t,a),i=null===(k=s.texture1)||void 0===k?void 0:k.getSize(),u=void 0,c=void 0,l=i.width,h=i.height,[4,s.texture1.readPixels()]):[3,12];case 3:return f=y.sent(),[4,s.texture2.readPixels()];case 4:return p=y.sent(),f?(u=B(f),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return p?(c=B(p),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(d=c.byteLength,g=new Uint8Array(d),m=new Uint8Array(d),_=new x.Color3(0,0,0),T=0,v=0,O=0;O<h;++O)for(P=0;P<l;++P)b=4*(l*O+P),w=new x.Color3(u[b],u[b+1],u[b+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),A=new x.Color3(c[b],c[b+1],c[b+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.specularColor),C=c[b+3]*r.glossiness,E={diffuseColor:w,specularColor:A,glossiness:C},I=this._convertSpecularGlossinessToMetallicRoughness(E),_.r=Math.max(_.r,I.baseColor.r),_.g=Math.max(_.g,I.baseColor.g),_.b=Math.max(_.b,I.baseColor.b),T=Math.max(T,I.metallic),v=Math.max(v,I.roughness),m[b]=255*I.baseColor.r,m[b+1]=255*I.baseColor.g,m[b+2]=255*I.baseColor.b,m[b+3]=s.texture1.hasAlpha?255*u[b+3]:255,g[b]=0,g[b+1]=255*I.roughness,g[b+2]=255*I.metallic,g[b+3]=255;for(V={baseColor:_,metallic:T,roughness:v},S=!1,F=!1,O=0;O<h;++O)for(P=0;P<l;++P)m[N=4*(l*O+P)]/=V.baseColor.r>M?V.baseColor.r:1,m[N+1]/=V.baseColor.g>M?V.baseColor.g:1,m[N+2]/=V.baseColor.b>M?V.baseColor.b:1,U=x.Color3.FromInts(m[N],m[N+1],m[N+2]),L=U.toGammaSpace(a.getEngine().useExactSrgbConversions),m[N]=255*L.r,m[N+1]=255*L.g,m[N+2]=255*L.b,L.equalsWithEpsilon(R,M)||(F=!0),g[N+1]/=V.roughness>M?V.roughness:1,g[N+2]/=V.metallic>M?V.metallic:1,x.Color3.FromInts(255,g[N+1],g[N+2]).equalsWithEpsilon(R,M)||(S=!0);return S&&o.push(this._getImageDataAsync(g,l,h,n).then((function(e){V.metallicRoughnessTextureData=e}))),F&&o.push(this._getImageDataAsync(m,l,h,n).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),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),o=I(t,r,n),a=e.diffuseColor.scale(n/(1-w.r)/Math.max(1-o,M)),s=e.specularColor.subtract(w.scale(1-o)).scale(1/Math.max(o,M)),i=x.Color3.Lerp(a,s,o*o);return{baseColor:i=i.clampToRef(0,1,i),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,r,n,o,a,s,i,u){return v(this,void 0,void 0,(function(){var c,l,h,f,p,d,g,m,_,T=this;return y(this,(function(b){switch(b.label){case 0:return c=[],l={baseColor:e,metallic:t,roughness:r},u&&(s instanceof x.OpenPBRMaterial?(s.geometryOpacityTexture?(h=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:0,f=s.geometryOpacityTexture&&s.geometryOpacityTexture.getInternalTexture()?s.geometryOpacityTexture.getInternalTexture().uniqueId:0,p=Number("".concat(h).concat(f)),(_=this._textureMap.get(p))?i.baseColorTexture=_:c.push((0,x.MergeTexturesAsync)("baseColorOpacityTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,2):(0,x.CreateConstantInput)(1),(0,x.CreateTextureInput)(s.geometryOpacityTexture,0)),s.getScene()).then((function(e){return v(T,void 0,void 0,(function(){var t;return y(this,(function(r){switch(r.label){case 0:return[4,this.exportTextureAsync(e,p)];case 1:return(t=r.sent())&&(i.baseColorTexture=t),[2]}}))}))})))):n&&c.push(this.exportTextureAsync(n).then((function(e){e&&(i.baseColorTexture=e)}))),s._useMetallicFromMetallicTextureBlue&&o?c.push(this.exportTextureAsync(o).then((function(e){e&&(i.metallicRoughnessTexture=e)}))):(a||o)&&(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,g=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,m=Number("".concat(d).concat(g)),(_=this._textureMap.get(m))?i.metallicRoughnessTexture=_:c.push((0,x.MergeTexturesAsync)("MetalRoughTexture",(0,x.CreateRGBAConfiguration)(s.ambientOcclusionTexture?(0,x.CreateTextureInput)(s.ambientOcclusionTexture,0):(0,x.CreateConstantInput)(1),a?(0,x.CreateTextureInput)(a,0):(0,x.CreateConstantInput)(1),o?(0,x.CreateTextureInput)(o,0):(0,x.CreateConstantInput)(1)),s.getScene()).then((function(e){return v(T,void 0,void 0,(function(){var t;return y(this,(function(r){switch(r.label){case 0:return[4,this.exportTextureAsync(e,m)];case 1:return(t=r.sent())&&(i.metallicRoughnessTexture=t),[2]}}))}))}))))):(n&&c.push(this.exportTextureAsync(n).then((function(e){e&&(i.baseColorTexture=e)}))),o&&c.push(this.exportTextureAsync(o).then((function(e){e&&(i.metallicRoughnessTexture=e)}))))),c.length>0?(this._exporter._materialNeedsUVsSet.add(s),[4,Promise.all(c)]):[3,2];case 1:b.sent(),b.label=2;case 2:return[2,l]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof x.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case x.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case x.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case x.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case x.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case x.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case x.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case x.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case x.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case x.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case x.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case x.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case x.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case x.Texture.WRAP_ADDRESSMODE:return 10497;case x.Texture.CLAMP_ADDRESSMODE:return 33071;case x.Texture.MIRROR_ADDRESSMODE:return 33648;default:return x.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h;return y(this,(function(f){switch(f.label){case 0:return n="image/png",o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},a=e._albedoTexture,s=e._reflectivityTexture,i=e._useMicroSurfaceFromReflectivityMapAlpha,!s||i?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,f.sent()];case 2:return(a||s)&&r?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(a||s),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,s,o,n)]):[3,4];case 3:return c=f.sent(),l=this._exporter._textures,c.baseColorTextureData&&(h=this._exportImage("baseColor".concat(l.length),n,c.baseColorTextureData),t.baseColorTexture=this._exportTextureInfo(h,u,null==a?void 0:a.coordinatesIndex)),c.metallicRoughnessTextureData&&(h=this._exportImage("metallicRoughness".concat(l.length),n,c.metallicRoughnessTextureData),t.metallicRoughnessTexture=this._exportTextureInfo(h,u,null==s?void 0:s.coordinatesIndex)),[2,c];case 4:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c;return y(this,(function(l){switch(l.label){case 0:return r={},n={name:e.name},(o=e.isMetallicWorkflow())&&(a=e._albedoColor,s=e.alpha,a&&(r.baseColorFactor=[a.r,a.g,a.b,s])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,r,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,r,t)];case 3:u=l.sent(),l.label=4;case 4:return i=u,[4,this._setMetallicRoughnessPbrMaterialAsync(i,e,n,r,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(n,e)];case 6:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a,s,i,u,c,l=this;return y(this,(function(h){switch(h.label){case 0:return S(r,t),e.baseColor.equalsWithEpsilon(R,M)&&x.Scalar.WithinEpsilon(t.alpha,1,M)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||x.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),o?(a=[],(s=t instanceof x.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&a.push(this.exportTextureAsync(s).then((function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))}))),(i=t instanceof x.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&a.push(new Promise((function(e){return v(l,void 0,void 0,(function(){var r,o,a,s;return y(this,(function(u){switch(u.label){case 0:return t instanceof x.OpenPBRMaterial&&n.metallicRoughnessTexture?(r=this._exportTextureSampler(i),o=this._exporter._textures[n.metallicRoughnessTexture.index].source,a=this._exportTextureInfo(o,r,i.coordinatesIndex),this._textureMap.set(i.uniqueId,a),this._exporter._extensionsPostExportTextures("exporter",a,i),[2,e(a)]):[3,1];case 1:return s=e,[4,this.exportTextureAsync(i)];case 2:return[2,s.apply(void 0,[u.sent()])]}}))}))})).then((function(e){return v(l,void 0,void 0,(function(){var n;return y(this,(function(o){return e&&(n={index:e.index,texCoord:e.texCoord,extensions:e.extensions},r.occlusionTexture=n,t instanceof x.PBRBaseMaterial?n.strength=t._ambientTextureStrength:n.strength=t.ambientOcclusionTexture.level),[2]}))}))}))),(u=t instanceof x.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&a.push(this.exportTextureAsync(u).then((function(e){e&&(r.emissiveTexture=e)}))),a.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(a)]):[3,2]):[3,2];case 1:h.sent(),h.label=2;case 2:return(c=t instanceof x.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(C,M)||(r.emissiveFactor=c.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i;return y(this,(function(u){switch(u.label){case 0:return r={},n={name:e.name},o=e.baseColor,a=e.geometryOpacity,o&&(r.baseColorFactor=[o.r,o.g,o.b,a]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,r,t)];case 1:return s=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,n,r,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(n,e)];case 3:return u.sent(),(i=this._exporter._materials).push(n),[2,i.length-1]}}))}))},e.prototype.exportTextureAsync=function(e){return v(this,arguments,void 0,(function(e,t){var r,n,o;return void 0===t&&(t=null),y(this,(function(a){switch(a.label){case 0:return(r=this._textureMap.get(null!=t?t:e.uniqueId))?[2,r]:(n=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=a.sent(),r=this._exportTextureInfo(o,n,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,r),this._exporter._extensionsPostExportTextures("exporter",r,e),[2,r]}}))}))},e.prototype._exportTextureImageAsync=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,a,s=this;return y(this,(function(i){switch(i.label){case 0:return t=null!==(a=e.mimeType)&&void 0!==a?a:"none",r=this._internalTextureToImage,n=e.getInternalTexture().uniqueId,r[n]=r[n]||{},void 0===(o=r[n][t])&&(o=v(s,void 0,void 0,(function(){var r,n,o,a,s;return y(this,(function(i){switch(i.label){case 0:return[4,E(e)];case 1:if((r=i.sent())&&("none"===t||r.mimeType===t))return[2,this._exportImage(e.name,r.mimeType,r.data)];if(n="image/png","none"!==t)switch(t){case"image/jpeg":case"image/png":case"image/webp":n=t;break;default:x.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG."))}return o=e.getSize(),[4,(0,x.GetTextureDataAsync)(e)];case 2:return a=i.sent(),[4,this._getImageDataAsync(a,o.width,o.height,n)];case 3:return s=i.sent(),[2,this._exportImage(e.name,n,s)]}}))})),r[n][t]=o),[4,o];case 1:return[2,i.sent()]}}))}))},e.prototype._exportImage=function(e,t,r){var n,o=this._exporter._images;if(this._exporter._shouldUseGlb){n={name:e,mimeType:t,bufferView:void 0};var a=this._exporter._bufferManager.createBufferView(new Uint8Array(r));this._exporter._bufferManager.setBufferView(n,a)}else{var s=e.replace(/\.\/|\/|\.\\|\\/g,"_"),i=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=s+i;o.some((function(e){return e.uri===u}))&&(u="".concat(s,"_").concat(x.Tools.RandomId()).concat(i)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return o.push(n),o.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,o=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===o&&(o=n.length,n.push({source:e,sampler:t}));var a={index:o};return r&&(a.texCoord=r),a},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e}(),P=x.Matrix.Compose(new x.Vector3(-1,1,1),x.Quaternion.Identity(),x.Vector3.Zero());function N(e,t){if(!(e instanceof x.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(x.Matrix.IdentityReadOnly,x.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(P,x.TmpVectors.Matrix[0]).equalsWithEpsilon(x.Matrix.IdentityReadOnly,x.Epsilon))return!1;return!(e instanceof x.AbstractMesh&&e.geometry)}var U=x.Vector3.ZeroReadOnly,L=x.Quaternion.Identity(),k=x.Vector3.OneReadOnly,K=new x.Vector3(-1,1,1);function z(e,t){var r=e.byteOffset,n=e.byteStride,o=e.type,a=e.normalized,s=e.getSize(),i=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:s,type:o,count:i*s,normalized:a,totalVertices:i,kind:e.getKind()}}function W(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 D(e){switch(e){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:case x.VertexBuffer.ColorKind:case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:case x.VertexBuffer.MatricesWeightsKind:case x.VertexBuffer.MatricesWeightsExtraKind:case x.VertexBuffer.UVKind:case x.VertexBuffer.UV2Kind:case x.VertexBuffer.UV3Kind:case x.VertexBuffer.UV4Kind:case x.VertexBuffer.UV5Kind:case x.VertexBuffer.UV6Kind:return!0}return!1}function q(e){switch(e){case x.Material.TriangleFillMode:return 4;case x.Material.TriangleStripDrawMode:return 5;case x.Material.TriangleFanDrawMode:return 6;case x.Material.PointListDrawMode:case x.Material.PointFillMode:return 0;case x.Material.LineLoopDrawMode:return 2;case x.Material.LineListDrawMode:return 1;case x.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function G(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function H(e){return e.x*=-1,e}function j(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),r=Math.abs(e.y);if(t>r){var n=Math.sign(e.x);e.x=t,e.y*=-n,e.z*=-n,e.w*=n}else n=Math.sign(e.y),e.x*=-n,e.y=r,e.z*=n,e.w*=-n}else{var o=Math.abs(e.z),a=Math.abs(e.w);o>a?(n=Math.sign(e.z),e.x*=-n,e.y*=n,e.z=o,e.w*=-n):(n=Math.sign(e.w),e.x*=n,e.y*=-n,e.z*=-n,e.w=a)}return e}function Q(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function X(e,t){var r=x.Vector3.FromArrayToRef(t.translation||[0,0,0],0,x.TmpVectors.Vector3[0]),n=x.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,x.TmpVectors.Quaternion[0]),o=x.Matrix.ComposeToRef(k,n,r,x.TmpVectors.Matrix[0]),a=x.Vector3.FromArrayToRef(e.translation||[0,0,0],0,x.TmpVectors.Vector3[2]),s=x.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,x.TmpVectors.Quaternion[1]),i=x.Matrix.ComposeToRef(k,s,a,x.TmpVectors.Matrix[1]);o.multiplyToRef(i,i),i.decompose(void 0,n,r),r.equalsWithEpsilon(U,x.Epsilon)?delete t.translation:t.translation=r.asArray(),n.equalsWithEpsilon(L,x.Epsilon)?delete t.rotation:t.rotation=n.asArray(),t.scale&&delete t.scale}function Y(e,t){if(!(t instanceof x.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var r=e.getScene(),n=e instanceof x.TargetCamera&&!r.useRightHandedSystem?K:k;return!!t.scaling.equalsWithEpsilon(n,x.Epsilon)||(x.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function Z(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],a=o[0],s=o[1],i=t[a];(Array.isArray(s)&&Array.isArray(i)&&J(s,i)||s===i)&&delete e[a]}return e}function J(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var $=new Map([[Int8Array,function(e,t,r){return e.setInt8(t,r)}],[Uint8Array,function(e,t,r){return e.setUint8(t,r)}],[Uint8ClampedArray,function(e,t,r){return e.setUint8(t,r)}],[Int16Array,function(e,t,r){return e.setInt16(t,r,!0)}],[Uint16Array,function(e,t,r){return e.setUint16(t,r,!0)}],[Int32Array,function(e,t,r){return e.setInt32(t,r,!0)}],[Uint32Array,function(e,t,r){return e.setUint32(t,r,!0)}],[Float32Array,function(e,t,r){return e.setFloat32(t,r,!0)}],[Float64Array,function(e,t,r){return e.setFloat64(t,r,!0)}]]),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),r=0;r<e.length;r++)t(this._dataView,this._byteOffset,e[r]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var r=new Uint8Array(2*t);r.set(this._data),this._data=r,this._dataView=new DataView(this._data.buffer)}},e}();function te(e){return e%4==0?4:e%2==0?2:1}var re,ne=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach((function(e){t+=e.byteLength}));for(var r=new ee(t),n=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return te(t.byteLength)-te(e.byteLength)}));n<o.length;n++){var a=o[n];a.byteOffset=r.byteOffset,e.push(a);for(var s=e.length-1,i=0,u=this.getPropertiesWithBufferView(a);i<u.length;i++)u[i].bufferView=s;r.writeTypedArray(this._bufferViewToData.get(a)),this._bufferViewToData.delete(a)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,o,a,s){this._verifyBufferView(e);var i={bufferView:void 0,componentType:r,count:n,type:t,min:null==a?void 0:a.min,max:null==a?void 0:a.max,normalized:s,byteOffset:o};return this.setBufferView(i,e),this._accessorToBufferView.set(i,e),i},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var o=n[r];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(re||(re={}));var oe=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof x.TransformNode||e instanceof x.Camera||e instanceof x.Light)},e._CreateNodeAnimation=function(t,r,n,o,a){if(this._IsTransformable(t)){var s=[],i=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,o),h=l.interpolationType,f=l.shouldBakeAnimation;if(f?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,i,c,o):"LINEAR"===h||"STEP"===h?e._CreateLinearOrStepAnimation(t,r,n,s,i,o):"CUBICSPLINE"===h?e._CreateCubicSplineAnimation(t,r,n,s,i,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,i,c,o),s.length&&i.length)return{inputs:s,outputs:i,samplerInterpolation:h,inputsMin:f?c.min:x.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:f?c.max:x.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:x.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(x.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,o,a,s,i,u,c,l,h){var f;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var x=d[p];if(!h||h(x)){var g=e._DeduceAnimationInfo(x);g&&(f={name:x.name,samplers:[],channels:[]},e._AddAnimation("".concat(x.name),x.hasRunningRuntimeAnimations?r:f,t,x,g.dataAccessorType,g.animationChannelTargetPath,o,s,i,u,g.useQuaternion,c,l),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,a,s,i,u,c,l,h){var f;if(t instanceof x.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var g=0,m=p.getTarget(d).animations;g<m.length;g++){var _=m[g];if(!h||h(_)){for(var T=new x.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),v=[],y=_.getKeys(),b=0;b<y.length;++b)for(var M=y[b],w=0;w<p.numTargets;++w)w==d?v.push(M):v.push({frame:M.frame,value:0});T.setKeys(v,!0);var A=e._DeduceAnimationInfo(T);A&&(f={name:T.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:f,t,T,A.dataAccessorType,A.animationChannelTargetPath,o,s,i,u,A.useQuaternion,c,l,p.numTargets),f.samplers.length&&f.channels.length&&n.push(f))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,a,s,i,u,c){var l,h;if(t.animationGroups)for(var f=t.animationGroups,p=function(f){var p=new Map,g=new Map,m=new Set,_=f.to-f.from;h={name:f.name,channels:[],samplers:[]};for(var T=function(r){var _=f.targetedAnimations[r],T=_.target,v=_.animation;if(c&&!c(v))return"continue";var y=u.has(T);if(d._IsTransformable(T)||1===T.length&&d._IsTransformable(T[0])){if(M=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(T)?T:d._IsTransformable(T[0])?T[0]:null;b&&e._AddAnimation("".concat(v.name),h,b,v,M.dataAccessorType,M.animationChannelTargetPath,n,o,a,s,M.useQuaternion,i,y)}}else if(T instanceof x.MorphTarget||1===T.length&&T[0]instanceof x.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var w=T instanceof x.MorphTarget?T:T[0];if(w){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1}));if(A){var R=t.meshes.find((function(e){return e.morphTargetManager===A}));R&&(p.has(R)||p.set(R,new Map),null===(l=p.get(R))||void 0===l||l.set(w,v),m.add(R),g.set(R,v))}}}}},v=0;v<f.targetedAnimations.length;++v)T(v);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=g.get(t).getKeys(),d=l.length,m=0;m<d;++m)for(var T=0;T<r.numTargets;++T){var v=r.getTarget(T),y=p.get(t);if(y){var b=y.get(v);b?(u||(u=new x.Animation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,x.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[m])):c.push({frame:f.from+_/d*m,value:v.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c,!0);var M=e._DeduceAnimationInfo(u);M&&e._AddAnimation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),h,t,u,M.dataAccessorType,M.animationChannelTargetPath,n,o,a,s,M.useQuaternion,i,!1,null==r?void 0:r.numTargets)})),h.channels.length&&h.samplers.length&&r.push(h)},d=this,g=0,m=f;g<m.length;g++)p(m[g])},e._AddAnimation=function(t,r,n,o,a,s,i,u,c,l,h,f,p,d){var g,m,_,T,v,y,b=e._CreateNodeAnimation(n,o,s,h,f);if(b){if(d){for(var M=0,w=0,A=[];b.inputs.length>0;)w=b.inputs.shift(),M%d==0&&A.push(w),M++;b.inputs=A}var R=i.get(n),C=new Float32Array(b.inputs);g=u.createBufferView(C),m=u.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(m),_=l.length-1;var E=new x.Quaternion,I=new x.Vector3,V=new x.Vector3,S=n instanceof x.Camera,F=W(a),B=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var r=e;switch(s){case"translation":p&&(x.Vector3.FromArrayToRef(e,0,V),H(V),V.toArray(r));break;case"rotation":4===e.length?x.Quaternion.FromArrayToRef(e,0,E):(r=new Array(4),x.Vector3.FromArrayToRef(e,0,I),x.Quaternion.FromEulerVectorToRef(I,E)),p&&(j(E),S&&Q(E)),E.toArray(r)}B.set(r,t*F)})),g=u.createBufferView(B),m=u.createAccessor(g,a,5126,b.outputs.length),l.push(m),T=l.length-1,v={interpolation:b.samplerInterpolation,input:_,output:T},r.samplers.push(v),y={sampler:r.samplers.length-1,target:{node:R,path:s}},r.channels.push(y)}},e._CreateBakedAnimation=function(t,r,n,o,a,s,i,u,c,l,h){var f,p,d=x.Quaternion.Identity(),g=null,m=null,_=null,T=null,v=null,y=null;l.min=x.Tools.FloatRound(o/s);for(var b=r.getKeys(),M=0,w=b.length;M<w;++M){if(y=null,_=b[M],M+1<w)if(T=b[M+1],_.value.equals&&_.value.equals(T.value)||_.value===T.value){if(0!==M)continue;y=_.frame}else y=T.frame;else{if(v=b[M-1],_.value.equals&&_.value.equals(v.value)||_.value===v.value)continue;y=a}if(y)for(var A=_.frame;A<=y;A+=i)if((p=x.Tools.FloatRound(A/s))!==g){g=p,m=p;var R={key:0,repeatCount:0,loopMode:r.loopMode};f=r._interpolate(A,R),e._SetInterpolatedValue(t,f,p,r,n,d,u,c,h)}}m&&(l.max=m)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,a){var s=e._GetBasePositionRotationOrScale(r,o,a),i=n.targetProperty.split("."),u=i?i[1]:"",c=a?x.Quaternion.FromArray(s).normalize():x.Vector3.FromArray(s);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:x.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,a,s,i,u){var c;s.push(r),"weights"!==o?(n.dataType===x.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u)),"rotation"===o?(u?a=t:(c=t,x.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),i.push(a.asArray())):(c=t,i.push(c.asArray()))):i.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,o,a,s){for(var i=0,u=r.getKeys();i<u.length;i++){var c=u[i];o.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,a,n,t,s)}},e._CreateCubicSplineAnimation=function(t,r,n,o,a,s){r.getKeys().forEach((function(i){o.push(i.frame/r.framePerSecond),e._AddSplineTangent(re.INTANGENT,a,n,"CUBICSPLINE",i,s),e._AddKeyframeValue(i,r,a,n,t,s),e._AddSplineTangent(re.OUTTANGENT,a,n,"CUBICSPLINE",i,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var o=e.rotationQuaternion;n=(null!=o?o:x.Quaternion.Identity()).asArray()}else{var a=e.rotation;n=(null!=a?a:x.Vector3.Zero()).asArray()}else if("translation"===t){var s=e.position;n=(null!=s?s:x.Vector3.Zero()).asArray()}else{var i=e.scaling;n=(null!=i?i:x.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,o,a){var s,i=t.dataType;if(i===x.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=x.Vector3.FromArray(u);u=x.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(i===x.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(s=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,a)){if("rotation"===n){var l=a?s:x.Quaternion.RotationYawPitchRoll(s.y,s.x,s.z).normalize();r.push(l.asArray())}r.push(s.asArray())}}else i===x.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):x.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,a=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,i=e.length;s<i;++s)if((o=e[s]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",a=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&1===o.interpolation&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,r,n,o,a){var s,i=e===re.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(i)if(a)s=i.asArray();else{var u=i;s=x.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else s=[0,0,0,0];else s="weights"===r?i?[i]:[0]:i?i.asArray():[0,0,0];t.push(s)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}();function ae(e,t,r,n,o,a){var s={attributes:{},influence:e.influence,name:e.name},i=t.geometry;if(!i)return x.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),s;var u=a?-1:1,c=x.Vector3.Zero(),l=0;if(e.hasPositions){var h=e.getPositions(),f=i.getVerticesData(x.VertexBuffer.PositionKind);if(f){var p=new Float32Array(f.length),d=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];l=f.length/3;for(var m=0;m<l;++m){var _=x.Vector3.FromArray(f,3*m);x.Vector3.FromArray(h,3*m).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),g[0]=Math.max(g[0],c.x),d[1]=Math.min(d[1],c.y),g[1]=Math.max(g[1],c.y),d[2]=Math.min(d[2],c.z),g[2]=Math.max(g[2],c.z),p[3*m]=c.x,p[3*m+1]=c.y,p[3*m+2]=c.z}var T=r.createBufferView(p,12),v=r.createAccessor(T,"VEC3",5126,h.length/3,0,{min:d,max:g});o.push(v),s.attributes.POSITION=o.length-1}else x.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),b=i.getVerticesData(x.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(l=b.length/3,m=0;m<l;++m){var w=x.Vector3.FromArray(b,3*m).normalize();x.Vector3.FromArray(y,3*m).normalize().subtractToRef(w,c),M[3*m]=c.x*u,M[3*m+1]=c.y,M[3*m+2]=c.z}T=r.createBufferView(M,12),v=r.createAccessor(T,"VEC3",5126,y.length/3,0),o.push(v),s.attributes.NORMAL=o.length-1}else x.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),R=i.getVerticesData(x.VertexBuffer.TangentKind);if(R){l=R.length/4;var C=new Float32Array(3*l);for(m=0;m<l;++m){var E=x.Vector3.FromArray(R,4*m);G(E);var I=x.Vector3.FromArray(A,3*m);G(I),I.subtractToRef(E,c),C[3*m]=c.x*u,C[3*m+1]=c.y,C[3*m+2]=c.z}T=r.createBufferView(C,12),v=r.createAccessor(T,"VEC3",5126,l,0),o.push(v),s.attributes.TANGENT=o.length-1}else x.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),S=i.getVerticesData(x.VertexBuffer.ColorKind),F=i.getVertexBuffer(x.VertexBuffer.ColorKind);if(S&&F){var B=F.getSize();l=S.length/B;var O=new Float32Array(l*B);for(m=0;m<l;++m)if(3===B){var P=x.Vector3.FromArray(S,m*B);x.Vector3.FromArray(V,m*B).subtractToRef(P,c),O[3*m]=c.x,O[3*m+1]=c.y,O[3*m+2]=c.z}else if(4===B){var N=new x.Vector4;P=x.Vector4.FromArray(S,m*B),x.Vector4.FromArray(V,m*B).subtractToRef(P,N),O[4*m]=N.x,O[4*m+1]=N.y,O[4*m+2]=N.z,O[4*m+3]=N.w}else x.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));T=r.createBufferView(O,4*B),v=r.createAccessor(T,3===B?"VEC3":"VEC4",5126,l,0),o.push(v),s.attributes.COLOR_0=o.length-1}else x.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return s}var se=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,r,n,o){var a,s,i,u;return null===(u=null===(i=null===(s=null===(a=this._indicesAccessorMap.get(e))||void 0===a?void 0:a.get(t))||void 0===s?void 0:s.get(r))||void 0===i?void 0:i.get(n))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,r,n,o,a){var s=this._indicesAccessorMap.get(e);s||(s=new Map,this._indicesAccessorMap.set(e,s));var i=s.get(t);i||(i=new Map,s.set(t,i));var u=i.get(r);u||(u=new Map,i.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(o,a)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,o;return null===(o=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===o?void 0:o.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a)),a.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),ie=function(){function e(e,t){if(void 0===e&&(e=x.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(x.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 ne,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=T({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,r,n){var o=this;if(r>=t.length)return Promise.resolve(e);var a=n(t[r],e);return a?a.then((function(e){return v(o,void 0,void 0,(function(){var o;return y(this,(function(a){switch(a.label){case 0:return e?[4,this._ApplyExtension(e,t,r+1,n)]:[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,r+1,n)},e.prototype._ApplyExtensions=function(t,r){for(var n=[],o=0,a=e._ExtensionNames;o<a.length;o++){var s=a[o];n.push(this._extensions[s])}return this._ApplyExtension(t,n,0,r)},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){var a=this;return this._ApplyExtensions(t,(function(t,s){return t.postExportNodeAsync&&t.postExportNodeAsync(e,s,r,n,o,a._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._ApplyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,r,n){return v(this,void 0,void 0,(function(){var o,a=this;return y(this,(function(s){switch(s.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map((function(e){return v(a,void 0,void 0,(function(){var a,s;return y(this,(function(i){switch(i.label){case 0:return(a=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,a.postExportMaterialAdditionalTexturesAsync(t,r,n)]:[3,2];case 1:s=i.sent(),o.push.apply(o,s),i.label=2;case 2:return[2]}}))}))})))];case 1:return s.sent(),[2,o]}}))}))},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var s=a[o],i=this._extensions[s];i.postExportTexture&&i.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.postExportMeshPrimitive&&a.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return v(this,void 0,void 0,(function(){var t,r,n,o;return y(this,(function(a){switch(a.label){case 0:t=0,r=e._ExtensionNames,a.label=1;case 1:return t<r.length?(n=r[t],(o=this._extensions[n]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:a.sent(),a.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.enabled&&t(a)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,o;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r,n){void 0===n&&(n=100),e.UnregisterExtension(t)&&x.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r;var o=null!=n?n:0;e._ExtensionOrders[t]=o;for(var a=e._ExtensionNames.length,s=0;s<e._ExtensionNames.length;s++){var i=e._ExtensionNames[s];if(o<e._ExtensionOrders[i]){a=s;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 r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._generateJSON=function(e,t,r){var n={byteLength:e};return n.byteLength&&(this._glTF.buffers=[n]),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||(n.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,a,s,i;return y(this,(function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength,e,!0),n=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",a=e+".bin",(s=new _).files[o]=r,s.files[a]=n,this._imageData)for(i in this._imageData)s.files[i]=new Blob([this._imageData[i].data],{type:this._imageData[i].mimeType});return[2,s]}}))}))},e.prototype._generateBinaryAsync=function(){return v(this,void 0,void 0,(function(){return y(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 v(this,void 0,void 0,(function(){var t,r,n,o,a,s,i,u,c,l,h,f,p,d;return y(this,(function(x){switch(x.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=x.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",o=r.length,"undefined"!=typeof TextEncoder&&(s=new TextEncoder,a=s.encode(r),o=a.length),i=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+i+t.byteLength+u,(l=new ee(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(o+i),l.writeUInt32(1313821514),a)l.writeTypedArray(a);else for(h="_".charCodeAt(0),p=0;p<o;++p)(f=r.charCodeAt(p))!=r.codePointAt(p)?l.writeUInt8(h):l.writeUInt8(f);for(p=0;p<i;++p)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),p=0;p<u;++p)l.writeUInt8(0);return(d=new _).files[n]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){var n;if(t.getPivotPoint().equalsWithEpsilon(U,x.Epsilon)||x.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(U,x.Epsilon)){var o=x.TmpVectors.Vector3[0].copyFrom(t.position);r&&H(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(k,x.Epsilon)||(e.scale=t.scaling.asArray());var a=(null===(n=t.rotationQuaternion)||void 0===n?void 0:n.clone())||x.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);a.equalsWithEpsilon(L,x.Epsilon)||(r&&j(a),e.rotation=a.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){var n=x.TmpVectors.Vector3[0],o=x.TmpVectors.Quaternion[0],a=t.getWorldMatrix();if(t.parent){var s=t.parent.getWorldMatrix().invertToRef(x.TmpVectors.Matrix[0]);a.multiplyToRef(s,x.TmpVectors.Matrix[1]).decompose(void 0,o,n)}else a.decompose(void 0,o,n);n.equalsWithEpsilon(U,x.Epsilon)||(r&&H(n),e.translation=n.asArray()),r&&j(o),this._babylonScene.useRightHandedSystem||Q(o),o.equalsWithEpsilon(L,x.Epsilon)||(e.rotation=o.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var r=t[e],n={type:r.mode===x.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(r.name&&(n.name=r.name),"perspective"===n.type)n.perspective={aspectRatio:r.getEngine().getAspectRatio(r),yfov:r.fovMode===x.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===n.type){var o=r.orthoLeft&&r.orthoRight?.5*(r.orthoRight-r.orthoLeft):.5*r.getEngine().getRenderWidth(),a=r.orthoBottom&&r.orthoTop?.5*(r.orthoTop-r.orthoBottom):.5*r.getEngine().getRenderHeight();n.orthographic={xmag:o,ymag:a,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,n)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var r=t[e],n=this._nodesCameraMap.get(r);if(void 0!==n){this._cameras.push(r);for(var o=0,a=n;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 r=t[e];r.bones.length<=0||this._skinMap.set(r,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,r=function(r){if(r.bones.length<=0)return"continue";var o=n._skinMap.get(r);if(null==o)return"continue";for(var a={},s=-1,i=0;i<r.bones.length;++i){var u=r.bones[i];-1!==(h=null!==(t=u.getIndex())&&void 0!==t?t:i)&&(a[h]=u,h>s&&(s=h))}for(var c,l=[],h=0;h<=s;++h){var f=(u=a[h]).getTransformNode(),p=f?n._nodeMap.get(f):void 0;if(void 0!==p){o.joints.push(p);var d=u.getAbsoluteInverseBindMatrix().clone();e.has(f)&&(c=d,P.invertToRef(x.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(P,c)),l.push(d)}else x.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var g=n._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==g){var m=new Float32Array(16*l.length);l.forEach((function(e,t){m.set(e.m,16*t)}));var _=n._bufferManager.createBufferView(m);n._accessors.push(n._bufferManager.createAccessor(_,"MAT4",5126,l.length)),o.inverseBindMatrices=n._accessors.length-1,n._skins.push(o);for(var T=n._skins.length-1,v=0,y=g;v<y.length;v++)y[v].skin=T}},n=this,o=0,a=this._babylonScene.skeletons;o<a.length;o++)r(a[o])},e.prototype._exportSceneAsync=function(){return v(this,void 0,void 0,(function(){var e,t,r,n,o,a,s,i,u,c,l,h,f,p,d,x,g,m,_,T,v,b,M;return y(this,(function(y){switch(y.label){case 0:for(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),r=new Array,n=new Array,o=new Array,a=0,s=this._babylonScene.rootNodes;a<s.length;a++)i=s[a],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&N(i,this._babylonScene.useRightHandedSystem)?o.push.apply(o,i.getChildren()):this._babylonScene.useRightHandedSystem?r.push(i):n.push(i);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new se(!0,!1),l=(c=(v=e.nodes).push).apply,h=[v],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,h.concat([y.sent()])),f=new se(!1,!1),d=(p=(b=e.nodes).push).apply,x=[b],[4,this._exportNodesAsync(r,f)];case 2:return d.apply(p,x.concat([y.sent()])),g=new se(!1,!0),_=(m=(M=e.nodes).push).apply,T=[M],[4,this._exportNodesAsync(o,g)];case 3:return _.apply(m,T.concat([y.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 v(this,void 0,void 0,(function(){var r,n,o,a;return y(this,(function(s){switch(s.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,o=e,s.label=1;case 1:return n<o.length?(a=o[n],[4,this._exportNodeAsync(a,r,t)]):[3,4];case 2:s.sent(),s.label=3;case 3:return n++,[3,1];case 4:return[2,r]}}))}))},e.prototype._collectBuffers=function(e,t,r,n,o){if(this._shouldExportNode(e)&&e instanceof x.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var s in a)if(D(s)){var i=a[s];o.setHasVertexColorAlpha(i,e.hasVertexAlpha);var u=i._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(i)&&c.push(i);var l=r.get(i)||[];r.set(i,l),-1===l.indexOf(e)&&l.push(e)}var h=e.morphTargetManager;if(h)for(var f=0;f<h.numTargets;f++){var p=h.getTarget(f);l=n.get(p)||[],n.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,g=e.getChildren();d<g.length;d++){var m=g[d];this._collectBuffers(m,t,r,n,o)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,o=new Map,a=0,s=e;a<s.length;a++){var i=s[a];this._collectBuffers(i,r,n,o,t)}for(var u=Array.from(r.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var a=r.get(e);if(!a)return"continue";var s=a[0].byteStride;if(a.some((function(e){return e.byteStride!==s})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var i=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=n.get(e),r=z(e,t),o=r.byteOffset,a=r.byteStride,s=r.componentCount,u=r.type,c=r.count,h=r.normalized;switch(r.kind){case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:(0,x.EnumerateFloatValues)(i,o,a,s,u,c,h,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var r=1/t;e[0]*=r,e[1]*=r,e[2]*=r}}));break;case x.VertexBuffer.ColorKind:var f=t.filter((function(e){return e.material instanceof x.StandardMaterial||null==e.material})).length;if(0==f)break;if(f!=t.length){x.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==x.VertexBuffer.UNSIGNED_BYTE&&x.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var p=new x.Color3,d=new x.Color4,g=l._babylonScene.getEngine().useExactSrgbConversions;(0,x.EnumerateFloatValues)(i,o,a,s,u,c,h,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,g),p.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0))}))}},c=0,h=a;c<h.length;c++)u(F=h[c]);if(t.convertToRightHanded){for(var f=0,p=a;f<p.length;f++){var d=z(F=p[f],n.get(F)),g=d.byteOffset,m=d.byteStride,_=d.componentCount,T=d.type,v=d.count,y=d.normalized;switch(C=d.kind){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:(0,x.EnumerateFloatValues)(i,g,m,_,T,v,y,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,i)}var b=l._bufferManager.createBufferView(i,s);t.setVertexBufferView(e,b);for(var M=new Map,w=0,A=a;w<A.length;w++){var R=z(F=A[w],n.get(F)),C=R.kind,E=R.totalVertices;switch(C){case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:if(F.type==x.VertexBuffer.FLOAT){var I=F.getFloatData(E);null!==I&&M.set(F,I)}}}0!==M.size&&x.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,S=Array.from(M.keys());V<S.length;V++){var F=S[V],B=M.get(F);if(B){for(var O=B.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(B.length),N=0;N<B.length;N++)P[N]=B[N];var U=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,F,U)}}},l=this,h=0,f=u;h<f.length;h++)c(f[h]);for(var p=0,d=Array.from(o.keys());p<d.length;p++){var g=d[p],m=o.get(g);if(m)for(var _=ae(g,m[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),T=0,v=m;T<v.length;T++){var y=v[T];t.bindMorphDataToMesh(y,_)}}},e.prototype._exportNodeAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h=this;return y(this,(function(f){switch(f.label){case 0:return void 0!==(n=this._nodeMap.get(e))?(t.includes(n)||t.push(n),[2]):[4,this._createNodeAsync(e,r)];case 1:(o=f.sent())&&(n=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),a={name:"runtime animations",channels:[],samplers:[]},s=[],this._babylonScene.animationGroups.length||(oe._CreateMorphTargetAnimationFromMorphTargetAnimations(e,a,s,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&oe._CreateNodeAnimationFromNodeAnimations(e,a,s,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation)),a.channels.length&&a.samplers.length&&this._animations.push(a),s.forEach((function(e){e.channels.length&&e.samplers.length&&h._animations.push(e)}))),i=o?[]:t,u=0,c=e.getChildren(),f.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,i,r)]):[3,5];case 3:f.sent(),f.label=4;case 4:return u++,[3,2];case 5:return o&&i.length&&(o.children=i),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c,l,h,f,p;return y(this,(function(d){switch(d.label){case 0:return this._shouldExportNode(e)?(r={},e.name&&(r.name=e.name),e.metadata&&(n=this._options.metadataSelector(e.metadata))&&(r.extras=n),e instanceof x.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof x.AbstractMesh?(o=e instanceof x.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(a=r,[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!==(s=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(s)&&this._nodesSkinMap.set(s,[]),null===(h=this._nodesSkinMap.get(s))||void 0===h||h.push(r)),d.label=3;case 3:if(e instanceof x.TargetCamera&&(i=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(i)&&this._nodesCameraMap.set(i,[]),this._setCameraTransformation(r,e,t.convertToRightHanded),null!==(u=e.parent)&&Y(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],X(r,l),null===(f=this._nodesCameraMap.get(i))||void 0===f||f.push(l),[2,null];null===(p=this._nodesCameraMap.get(i))||void 0===p||p.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,r]:(x.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,r,n,o,a,s,i,u){var c=e;u.mode=q(a);var l=s!==x.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case x.Material.TriangleFillMode:case x.Material.TriangleStripDrawMode:case x.Material.TriangleFanDrawMode:return!0}return!1}(a);if(l){if(a===x.Material.TriangleStripDrawMode||a===x.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=q(a);var h=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var f=0;f+2<n;f+=3)h[f]=e[r+f]+o,h[f+1]=e[r+f+2]+o,h[f+2]=e[r+f+1]+o;else for(f=0;f+2<n;f+=3)h[f]=f,h[f+1]=f+2,h[f+2]=f+1;c=h}else if(e&&0!==o){for(h=t?new Uint32Array(n):new Uint16Array(n),f=0;f<n;f++)h[f]=e[r+f]+o;c=h}if(c){var p=i.getIndicesAccessor(e,r,n,o,l);if(void 0===p){var d=function(e,t,r,n){var o=e;return 0===t&&r===e.length||(o=Array.isArray(e)?e.slice(t,t+r):e.subarray(t,t+r)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?n?new Uint32Array(o):new Uint16Array(o):o}(c,r,n,t),g=this._bufferManager.createBufferView(d),m=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(g,"SCALAR",m,n,0)),p=this._accessors.length-1,i.setIndicesAccessor(e,r,n,o,l,p)}u.indices=p}},e.prototype._exportVertexBuffer=function(e,t,r,n,o,a){var s=e.getKind();if(D(s)&&(!s.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var i=o.getVertexAccessor(e,r,n);if(void 0===i){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=s===x.VertexBuffer.PositionKind?function(e,t,r,n){var o=t.byteOffset,a=t.byteStride,s=t.type,i=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,x.EnumerateFloatValues)(e,o+r*a,a,u,s,n*u,i,(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,r,n):void 0,l=(s===x.VertexBuffer.MatricesIndicesKind||s===x.VertexBuffer.MatricesIndicesExtraKind)&&e.type===x.VertexBuffer.FLOAT,h=l?x.VertexBuffer.UNSIGNED_BYTE:e.type,f=l?void 0:e.normalized,p=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(p,function(e,t){if(e==x.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:return"VEC3";case x.VertexBuffer.TangentKind:case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:case x.VertexBuffer.MatricesWeightsKind:case x.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case x.VertexBuffer.UVKind:case x.VertexBuffer.UV2Kind:case x.VertexBuffer.UV3Kind:case x.VertexBuffer.UV4Kind:case x.VertexBuffer.UV5Kind:case x.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(s,o.hasVertexColorAlpha(e)),h,n,d,c,f)),i=this._accessors.length-1,o.setVertexAccessor(e,r,n,i)}a.attributes[function(e){switch(e){case x.VertexBuffer.PositionKind:return"POSITION";case x.VertexBuffer.NormalKind:return"NORMAL";case x.VertexBuffer.TangentKind:return"TANGENT";case x.VertexBuffer.ColorKind:return"COLOR_0";case x.VertexBuffer.UVKind:return"TEXCOORD_0";case x.VertexBuffer.UV2Kind:return"TEXCOORD_1";case x.VertexBuffer.UV3Kind:return"TEXCOORD_2";case x.VertexBuffer.UV4Kind:return"TEXCOORD_3";case x.VertexBuffer.UV5Kind:return"TEXCOORD_4";case x.VertexBuffer.UV6Kind:return"TEXCOORD_5";case x.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case x.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case x.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case x.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(s)]=i}},e.prototype._exportMaterialAsync=function(e,t,r,n){return v(this,void 0,void 0,(function(){var o,a;return y(this,(function(s){switch(s.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 x.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof x.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,a)]:[3,2]);case 1:return o=s.sent(),[3,7];case 2:return e instanceof x.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,a)]:[3,4];case 3:return o=s.sent(),[3,7];case 4:return e instanceof x.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,a)]:[3,6];case 5:return o=s.sent(),[3,7];case 6:return x.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,o),s.label=8;case 8:return n.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c,l,h,f,p,d,g,m,_,T,v,M,w,A,R,C,E,I,V,S,F,B,O,P,N,U,L;return y(this,(function(y){switch(y.label){case 0:if(void 0!==(r=t.getMesh(e)))return[2,r];if(n={primitives:[]},r=this._meshes.length,this._meshes.push(n),t.setMesh(e,r),o=e.isUnIndexed?null:e.getIndices(),a=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),s=t.getMorphTargetsFromMesh(e),i=e instanceof x.LinesMesh,u=e instanceof x.GreasedLineBaseMesh,c=e.subMeshes,!(a&&c&&c.length>0))return[3,7];l=0,h=c,y.label=1;case 1:return l<h.length?(f=h[l],p={attributes:{}},d=f.getMaterial()||this._babylonScene.defaultMaterial,u?(T={name:d.name},v=e,g=x.Color3.White(),m=null!==(P=null===(O=v.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(_=null!==(U=null===(N=v.greasedLineMaterial)||void 0===N?void 0:N.color)&&void 0!==U?U:g).equalsWithEpsilon(g,x.Epsilon)||m<1)&&(T.pbrMetallicRoughness={baseColorFactor:b(b([],_.asArray(),!0),[m],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return i?(T={name:d.name},(!(v=e).color.equalsWithEpsilon(x.Color3.White(),x.Epsilon)||v.alpha<1)&&(T.pbrMetallicRoughness={baseColorFactor:b(b([],v.color.asArray(),!0),[v.alpha],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,a,f,p)];case 4:y.sent(),y.label=5;case 5:for(M=i||u?x.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,w=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(w=w===x.Material.ClockWiseSideOrientation?x.Material.CounterClockWiseSideOrientation:x.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,x.AreIndices32Bits)(o,f.indexCount,f.indexStart,f.verticesStart):f.verticesCount>65535,o?f.indexStart:f.verticesStart,o?f.indexCount:f.verticesCount,-f.verticesStart,M,w,t,p),A=0,R=Object.values(a);A<R.length;A++)C=R[A],this._exportVertexBuffer(C,d,f.verticesStart,f.verticesCount,t,p);if(s)for(p.targets=[],E=0,I=s;E<I.length;E++)F=I[E],p.targets.push(F.attributes);n.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),y.label=6;case 6:return l++,[3,1];case 7:if(s)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],V=0,S=s;V<S.length;V++)F=S[V],n.weights.push(F.influence),n.extras.targetNames.push(F.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),ue=function(){function e(){}return e.GLTFAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o;return y(this,(function(a){switch(a.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(n=new ie(e,r)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.sent(),n.dispose(),[2,o]}}))}))},e.GLBAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o;return y(this,(function(a){switch(a.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(n=new ie(e,r)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.sent(),n.dispose(),[2,o]}}))}))},e}(),ce="EXT_mesh_gpu_instancing";function le(e,t){for(var r=new Float32Array(3*t),n=0;n<t;n++)r[3*n+0]=e[4*n+0],r[3*n+1]=e[4*n+1],r[3*n+2]=e[4*n+2];return r}var he=function(){function e(e){this.name=ce,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,r,n,o,a){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var s,i;if(t&&r instanceof x.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var u=x.Vector3.Zero(),c=x.Quaternion.Identity(),l=x.Vector3.One(),h=r.thinInstanceGetWorldMatrices(),f=x.TmpVectors.Vector3[2],p=x.TmpVectors.Quaternion[1],d=x.TmpVectors.Vector3[3],g=!1,m=!1,_=!1,T=new Float32Array(3*r.thinInstanceCount),v=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),b=0,M=0,w=h;M<w.length;M++)w[M].decompose(d,p,f),o&&(H(f),j(p)),T.set(f.asArray(),3*b),v.set(p.normalize().asArray(),4*b),y.set(d.asArray(),3*b),g=g||!f.equalsWithEpsilon(u),m=m||!p.equalsWithEpsilon(c),_=_||!d.equalsWithEpsilon(l),b++;var A={attributes:{}};g&&(A.attributes.TRANSLATION=e._buildAccessor(T,"VEC3",r.thinInstanceCount,a)),m&&(A.attributes.ROTATION=e._buildAccessor(v,"VEC4",r.thinInstanceCount,a)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,a));var R=null===(i=null===(s=r._userThinInstanceBuffersStorage)||void 0===s?void 0:s.data)||void 0===i?void 0:i.instanceColor;if(R){var C=r.thinInstanceCount;r.hasVertexAlpha&&R.length===4*C?(e._instanceColorWarned||(x.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),R=le(R,C)):R.length===4*C&&(R=le(R,C)),R.length===3*C&&(A.attributes._COLOR_0=e._buildAccessor(R,"VEC3",C,a))}t.extensions=t.extensions||{},t.extensions[ce]=A}n(t)}))];case 1:return[2,n.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,r,n){var o=n.createBufferView(e),a=n.createAccessor(o,t,5126,r);return this._exporter._accessors.push(a),this._exporter._accessors.length-1},e}();ie.RegisterExtension(ce,(function(e){return new he(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&&x.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,r){var n=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],a=[],s=null;if(void 0!==e.indices){var i=r[e.indices],u=t.getBufferView(i);s=t.getData(u).slice(),o.push(u),a.push(i)}for(var c,l=[],h=0,f=Object.entries(e.attributes);h<f.length;h++){var p=f[h],d=p[0],g=(i=r[p[1]],u=t.getBufferView(i),W(i.type)),m=(0,x.GetTypedArrayData)(t.getData(u),g,i.componentType,i.byteOffset||0,u.byteStride||(0,x.GetTypeByteLength)(i.componentType)*g,i.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:W(i.type),data:m}),o.push(u),a.push(i)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},T=x.DracoEncoder.Default._encodeAsync(l,s,_).then((function(r){if(r){var s={bufferView:-1,attributes:r.attributeIds},i=t.createBufferView(r.data);t.setBufferView(s,i);for(var u=0,c=o;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var h=0,f=a;h<f.length;h++){var p=f[h];n._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[fe]=s}else x.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){x.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(T),this._wasUsed=!0}else x.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return v(this,void 0,void 0,(function(){var t=this;return y(this,(function(r){switch(r.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return r.sent(),this._bufferViewsUsed.forEach((function(r){e.getPropertiesWithBufferView(r).every((function(e){return t._accessorsUsed.has(e)}))&&e.removeBufferView(r)})),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}}))}))},e}();ie.RegisterExtension(fe,(function(e){return new pe(e)}));var de="KHR_lights_punctual",xe={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},ge={innerConeAngle:0,outerConeAngle:Math.PI/4},me=x.Vector3.Backward(),_e=function(){function e(e){this.name=de,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[de]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a=this;return y(this,(function(s){switch(s.label){case 0:return[4,new Promise((function(s){if(r instanceof x.Light){var i=r.getTypeID()==x.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==x.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==x.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(i&&r instanceof x.ShadowLight))return x.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(de)),void s(t);if(r.falloffType!==x.Light.FALLOFF_GLTF&&x.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(de," specification!")),!r.position.equalsToFloats(0,0,0)){var u=x.TmpVectors.Vector3[0].copyFrom(r.position);o&&H(u),t.translation=u.asArray()}if("point"!==i){var c=r.direction.normalizeToRef(x.TmpVectors.Vector3[0]);o&&H(c);var l=x.Quaternion.FromUnitVectorsToRef(me,c,x.TmpVectors.Quaternion[0]);x.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var h={type:i,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(Z(h,xe),"spot"===i){var f=r;h.spot={innerConeAngle:f.innerAngle/2,outerConeAngle:f.angle/2},Z(h.spot,ge)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(h);var p={light:a._lights.lights.length-1},d=r.parent;if(d&&Y(r,d)){var g=n.get(d);if(g){var m=a._exporter._nodes[g];return X(t,m),m.extensions||(m.extensions={}),m.extensions[de]=p,void s(null)}}t.extensions||(t.extensions={}),t.extensions[de]=p,s(t)}else s(t)}))];case 1:return[2,s.sent()]}}))}))},e}();ie.RegisterExtension(de,(function(e){return new _e(e)}));var Te="EXT_lights_area",ve={name:"",color:[1,1,1],intensity:1,size:1},ye={aspect:1},be=x.Vector3.Backward(),Me=function(){function e(e){this.name=Te,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[Te]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a=this;return y(this,(function(s){switch(s.label){case 0:return[4,new Promise((function(s){if(r instanceof x.Light){var i=r.getTypeID()==x.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!i)return x.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(Te)),void s(t);var u=r;if(u.falloffType!==x.Light.FALLOFF_GLTF&&x.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(Te," specification!")),!u.position.equalsToFloats(0,0,0)){var c=x.TmpVectors.Vector3[0].copyFrom(u.position);o&&H(c),t.translation=c.asArray()}var l=x.Vector3.Forward();o&&H(l);var h=x.Quaternion.FromUnitVectorsToRef(be,l,x.TmpVectors.Quaternion[0]);x.Quaternion.IsIdentity(h)||(t.rotation=h.asArray());var f={type:i,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};Z(f,ve),f.rect&&Z(f.rect,ye),a._lights||(a._lights={lights:[]}),a._lights.lights.push(f);var p={light:a._lights.lights.length-1},d=r.parent;if(d&&Y(u,d)){var g=n.get(d);if(g){var m=a._exporter._nodes[g];return X(t,m),m.extensions||(m.extensions={}),m.extensions[Te]=p,void s(null)}}t.extensions||(t.extensions={}),t.extensions[Te]=p,s(t)}else s(t)}))];case 1:return[2,s.sent()]}}))}))},e}();ie.RegisterExtension(Te,(function(e){return new Me(e)}));var we="KHR_materials_anisotropy";function Ae(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r||n?[4,(0,x.MergeTexturesAsync)("AnisotropyTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(0),r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}}))}))}var Re=function(){function e(e){this.name=we,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,r){return v(this,void 0,void 0,(function(){var e,t,n;return y(this,(function(o){switch(o.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&e.push(r.anisotropy.texture),[2,e]):[3,5]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0?(t=function(e){var t=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoTangent";return"".concat(n,"_").concat(o)}(r),this._anisoTexturesMap[t]?(e.push(this._anisoTexturesMap[t]),[3,4]):[3,2]):[3,5];case 2:return[4,Ae(r)];case 3:(n=o.sent())&&(e.push(n),this._anisoTexturesMap[t]=n),o.label=4;case 4:return[2,e];case 5:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,s,i,u,c;if(r instanceof x.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var l=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture);null!==(T={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[we]=T}else if(r instanceof x.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){n._wasUsed=!0,t.extensions=t.extensions||{};var h=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(h=r.baseMetalnessTexture);var f=n._anisoTexturesMap[r.id];if(!h&&!f){var p=r.specularRoughness,d=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var g=(a=r.specularRoughness,c=(1-(s=r.specularRoughnessAnisotropy))*(u=(i=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-i)/Math.max(1-i,1e-4)),1)});p=g.newBaseRoughness,d=g.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=p);var m={anisotropyStrength:d,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[we]=m,e(t)}var _=f?n._exporter._materialExporter.getTextureInfo(f):null,T={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};r._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=n._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&n._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),n._exporter._materialNeedsUVsSet.add(r),t.extensions[we]=T}e(t)}))},e}();ie.RegisterExtension(we,(function(e){return new Re(e)}));var Ce="KHR_materials_clearcoat";function Ee(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("CoatTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useCoatRoughnessFromGreenChannel?1:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Ie(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var Ve=function(){function e(e){this.name=Ce,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o;return y(this,(function(a){switch(a.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.clearCoat.isEnabled?(r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),[2,e]):[3,5]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.coatWeight>0?(t=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):t=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):t=!0),t?(n=function(e){var t=e.coatWeightTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",n=e.coatRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoRoughness";return"".concat(r,"_").concat(o)}(r),this._cachedInternalTexturesMap[n]?[3,3]:[4,Ee(r)]):[3,4]):[3,5];case 2:(o=a.sent())&&(this._cachedInternalTexturesMap[n]=o),a.label=3;case 3:this._cachedInternalTexturesMap[n]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]))),a.label=4;case 4:return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),[2,e];case 5:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o,a=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);o=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&x.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&x.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture);null===(c={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ce]=c}else if(r instanceof x.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i=null,u=void 0;r.coatWeightTexture&&(i=n._mergedTexturesMap[r.coatWeightTexture.uniqueId],u=n._exporter._materialExporter.getTextureInfo(i));var c,l=null,h=void 0;r.coatRoughnessTexture&&(l=n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],h=n._exporter._materialExporter.getTextureInfo(l)),r.coatColorTexture&&x.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),s=n._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),null===(c={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=u?u:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=h?h:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ce]=c}e(t)}))},e}();ie.RegisterExtension(Ce,(function(e){return new Ve(e)}));var Se="KHR_materials_coat";function Fe(e){var t=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoTangent";return"".concat(n,"_").concat(o)}function Be(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r||n?[4,(0,x.MergeTexturesAsync)("AnisotropyTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(0),r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}}))}))}function Oe(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("CoatTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useCoatRoughnessFromGreenChannel?1:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Pe(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var Ne=function(){function e(e){this.name=Se,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o,a;return y(this,(function(s){switch(s.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.clearCoat.isEnabled?(r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),r.clearCoat.tintTexture&&e.push(r.clearCoat.tintTexture),[2,e]):[3,9]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.coatWeight>0?(t=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):t=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):t=!0),t?(o=function(e){var t=e.coatWeightTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",n=e.coatRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoRoughness";return"".concat(r,"_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,3]:[4,Oe(r)]):[3,4]):[3,9];case 2:(n=s.sent())&&(this._cachedInternalTexturesMap[o]=n),s.label=3;case 3:this._cachedInternalTexturesMap[o]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[o],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[o],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]))),s.label=4;case 4:return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatColorTexture&&e.push(r.coatColorTexture),r.coatRoughnessAnisotropy>0?(o=Fe(r),this._mergedTexturesMap[o]?(e.push(this._mergedTexturesMap[o]),[3,7]):[3,5]):[3,8];case 5:return[4,Be(r)];case 6:(a=s.sent())&&(e.push(a),this._mergedTexturesMap[o]=a),s.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,s,i,u,c;if(r instanceof x.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var l,h=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);l=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness);var f=void 0;r.clearCoat.isTintEnabled&&(f=n._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));var p=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),d=r.clearCoat.indexOfRefraction;null===(T={coatFactor:r.clearCoat.intensity,coatTexture:null!=h?h:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=l?l:void 0,coatNormalTexture:null!=p?p:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==d?d:void 0}).coatTexture&&null===T.coatRoughnessTexture&&null===T.coatRoughnessTexture&&null===T.coatColorTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Se]=T}else if(r instanceof x.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var g=null;h=void 0,r.coatWeightTexture&&(g=n._mergedTexturesMap[r.coatWeightTexture.uniqueId]?n._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,h=n._exporter._materialExporter.getTextureInfo(g));var m=null,_=void 0;r.coatRoughnessTexture&&(m=n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,_=n._exporter._materialExporter.getTextureInfo(m)),p=n._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),f=n._exporter._materialExporter.getTextureInfo(r.coatColorTexture),d=r.coatIor;var T,v=r.coatDarkening,y=r.coatRoughnessTexture,b=Fe(r),M=n._mergedTexturesMap[b],w=0,A=0,R=void 0;if(r.coatRoughnessAnisotropy>0){if(y||M){var C=M?n._exporter._materialExporter.getTextureInfo(M):null;w=r.coatRoughnessAnisotropy,A=r.geometryCoatTangentAngle,R=C||void 0}else{var E=r.coatRoughness,I=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var V=(a=r.coatRoughness,c=(1-(s=r.coatRoughnessAnisotropy))*(u=(i=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-i)/Math.max(1-i,1e-4)),1)});E=V.newBaseRoughness,I=V.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=E),w=I,A=r.geometryCoatTangentAngle+.5*Math.PI,R=void 0}r._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=n._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&n._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(T={coatFactor:r.coatWeight,coatTexture:null!=h?h:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=_?_:void 0,coatNormalTexture:null!=p?p:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==d?d:void 0,coatDarkeningFactor:1!==v?v:void 0,coatAnisotropyRotation:A,coatAnisotropyStrength:w,coatAnisotropyTexture:R}).coatTexture&&null===T.coatRoughnessTexture&&null===T.coatRoughnessTexture&&null===T.coatAnisotropyTexture&&null===T.coatColorTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Se]=T}e(t)}))},e}();ie.RegisterExtension(Se,(function(e){return new Ne(e)}));var Ue="KHR_materials_diffuse_transmission";function Le(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(x.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var ke=function(){function e(e){this.name=Ue,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var t,n;return y(this,(function(o){return t=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?((n=Le(e,r))&&t.push(n),r.subSurface.translucencyColorTexture&&t.push(r.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,r){var n=this;return new Promise((function(o){var a,s;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,u=Le(e,r),c=0==i.translucencyIntensity?void 0:i.translucencyIntensity,l=null!==(a=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0,h=!i.translucencyColor||i.translucencyColor.equalsFloats(1,1,1)?void 0:i.translucencyColor.asArray(),f=null!==(s=n._exporter._materialExporter.getTextureInfo(i.translucencyColorTexture))&&void 0!==s?s:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:h,diffuseTransmissionColorTexture:f};(l||f)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Ue]=p}o(t)}))},e}();ie.RegisterExtension(Ue,(function(e){return new ke(e)}));var Ke="KHR_materials_dispersion",ze=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){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ke]=o}e(t)}))},e}();ie.RegisterExtension(Ke,(function(){return new ze}));var We="KHR_materials_emissive_strength",De=function(){function e(){this.name=We,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(!(r instanceof x.PBRMaterial))return n(t);var o=r.emissiveColor.scale(r.emissiveIntensity),a=Math.max.apply(Math,o.asArray());if(a>1){t.emissiveFactor=o.scale(1/a).asArray(),e._wasUsed=!0;var s={emissiveStrength:a};t.extensions||(t.extensions={}),t.extensions[We]=s}else t.emissiveFactor=o.asArray();return n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(We,(function(){return new De}));var qe="KHR_materials_ior",Ge=function(){function e(){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[qe]=o}e(t)}))},e}();ie.RegisterExtension(qe,(function(e){return new Ge}));var He="KHR_materials_iridescence",je=function(){function e(e){this.name=He,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,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){if(e=[],r instanceof x.PBRBaseMaterial){if(r.iridescence.isEnabled)return r.iridescence.texture&&e.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&e.push(r.iridescence.thicknessTexture),[2,e]}else if(r instanceof x.OpenPBRMaterial&&r.thinFilmWeight>0)return r.thinFilmWeightTexture&&e.push(r.thinFilmWeightTexture),r.thinFilmThicknessTexture&&r.thinFilmThicknessTexture!==r.thinFilmWeightTexture&&e.push(r.thinFilmThicknessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),a=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture);null===(s={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=a?a:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=s}else if(r instanceof x.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s,i=n._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),u=n._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture);null===(s={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=i?i:void 0,iridescenceThicknessTexture:null!=u?u:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=s}e(t)}))},e}();ie.RegisterExtension(He,(function(e){return new je(e)}));var Qe="KHR_materials_sheen",Xe=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,r){return v(this,void 0,void 0,(function(){return y(this,(function(e){return r instanceof x.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[2,[r.sheen.texture]]:[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var o,a,s,i;if(r instanceof x.PBRMaterial){if(!r.sheen.isEnabled)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=r.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),t.extensions[Qe]=u}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(Qe,(function(e){return new Xe(e)}));var Ye="KHR_materials_fuzz";function Ze(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.fuzzColorTexture,n=e.fuzzRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("FuzzTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,1):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,2):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useFuzzRoughnessFromTextureAlpha?3:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Je(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var $e=function(){function e(e){this.name=Ye,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o;return y(this,(function(a){switch(a.label){case 0:return r instanceof x.OpenPBRMaterial?(e=[],r.fuzzWeight>0?(r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture),t=!1,r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):t=!0),r.fuzzColorTexture&&!t&&e.push(r.fuzzColorTexture),t?(n=function(e){var t=e.fuzzColorTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",n=e.fuzzRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(r,"_FuzzRoughness_").concat(o)}(r),this._cachedInternalTexturesMap[n]?[3,2]:[4,Ze(r)]):[3,3]):[3,3]):[3,4];case 1:(o=a.sent())&&(this._cachedInternalTexturesMap[n]=o),a.label=2;case 2:this._cachedInternalTexturesMap[n]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=Je(this._cachedInternalTexturesMap[n],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=Je(this._cachedInternalTexturesMap[n],r.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]))),a.label=3;case 3:return[2,e];case 4:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var o,a,s;if(r instanceof x.OpenPBRMaterial){if(0==r.fuzzWeight)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var i={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};r.fuzzWeightTexture&&(i.fuzzTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==o?o:void 0);var u=null;r.fuzzColorTexture&&(u=e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,i.fuzzColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0);var c=null;r.fuzzRoughnessTexture&&(c=e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,i.fuzzRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==s?s:void 0),null===i.fuzzColorTexture&&null===i.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),t.extensions[Ye]=i}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(Ye,(function(e){return new $e(e)}));var et="KHR_materials_specular",tt=function(){function e(e){this.name=et,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,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){return e=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.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,r){var n=this;return new Promise((function(e){var o,a,s,i,u;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(o=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,l=null!==(a=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,h={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:c,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:l};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[et]=h}else if(r instanceof x.OpenPBRMaterial){t.extensions=t.extensions||{};var f=null!==(s=n._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==s?s:void 0,p=null!==(i=n._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==i?i:void 0,d=1==r.specularWeight?void 0:r.specularWeight,g=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!p&&!f&&void 0===d&&void 0===g)return e(t);n._wasUsed=!0,(h={specularFactor:d,specularTexture:f,specularColorFactor:g,specularColorTexture:p,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=n._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(f||p)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[et]=h}e(t)}))},e}();ie.RegisterExtension(et,(function(e){return new tt(e)}));var rt="KHR_materials_transmission",nt=function(){function e(e){this.name=rt,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,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){return e=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&e.push(r.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,r){return v(this,void 0,void 0,(function(){var n,o,a,s;return y(this,(function(i){switch(i.label){case 0:return r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(this._wasUsed=!0,n=r.subSurface,o=0===n.refractionIntensity?void 0:n.refractionIntensity,a={transmissionFactor:o},this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),n.refractionIntensityTexture?n.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(n.refractionIntensityTexture)]:[3,2]:[3,3]):[3,4];case 1:return(s=i.sent())&&(a.transmissionTexture=s),[3,3];case 2:x.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported")),i.label=3;case 3:t.extensions||(t.extensions={}),t.extensions[rt]=a,i.label=4;case 4:return[2,t]}}))}))},e}();ie.RegisterExtension(rt,(function(e){return new nt(e)}));var ot="KHR_materials_unlit",at=function(){function e(){this.name=ot,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o=!1;r instanceof x.PBRMaterial?o=r.unlit:r instanceof x.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ot]={}),e(t)}))},e}();ie.RegisterExtension(ot,(function(){return new at}));var st="KHR_materials_volume",it=function(){function e(e){this.name=st,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,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){return e=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&e.push(r.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!=x.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,s={thicknessFactor:0==a.maximumThickness?void 0:a.maximumThickness,thicknessTexture:null!==(o=n._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()};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[st]=s}e(t)}))},e}();ie.RegisterExtension(st,(function(e){return new it(e)}));var ut="KHR_materials_diffuse_roughness",ct=function(){function e(e){this.name=ut,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,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){if(e=[],r instanceof x.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),[2,e]}else if(r instanceof x.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o=null,a=null;if(r instanceof x.PBRBaseMaterial?(o=r._baseDiffuseRoughness,a=r._baseDiffuseRoughnessTexture):r instanceof x.OpenPBRMaterial&&(o=r.baseDiffuseRoughness,a=r.baseDiffuseRoughnessTexture),o){n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(a),i={diffuseRoughnessFactor:o,diffuseRoughnessTexture:null!=s?s:void 0};null!==i.diffuseRoughnessTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[ut]=i,e(t)}else e(t)}))},e}();ie.RegisterExtension(ut,(function(e){return new ct(e)}));var lt="KHR_texture_transform",ht=function(){function e(){this.name=lt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,r){if(r.getScene()||x.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with rotation in the u or v axis is not supported in glTF.")),0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(lt,"."));x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(lt,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,o=e.vRotationCenter,a=e.uScale,s=e.vScale,i=e.wAng,u=Math.cos(i),c=Math.sin(i),l=n*a,h=o*s;return[t+(l*(1-u)+h*c),r+(h*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,o=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[lt]=n)}},e}();ie.RegisterExtension(lt,(function(){return new ht}));var ft="KHR_texture_basisu",pt=function(){function e(e){this.name=ft,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 r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/ktx2"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[ft]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(ft,(function(e){return new pt(e)}));var dt="EXT_texture_webp",xt=function(){function e(e){this.name=dt,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 r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/webp"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[dt]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(dt,(function(e){return new xt(e)}));var gt="EXT_texture_avif",mt=function(){function e(e){this.name=gt,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 r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/avif"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[gt]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(gt,(function(e){return new mt(e)}));var _t=function(){function e(){}return e.CreateSTL=function(e,t,r,n,o,a,s,i){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===a&&(a=!1),void 0===s&&(s=!1),void 0===i&&(i=!1);var u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],o=[new x.Vector3(t[n[0]],t[n[0]+2],t[n[0]+1]),new x.Vector3(t[n[1]],t[n[1]+2],t[n[1]+1]),new x.Vector3(t[n[2]],t[n[2]+2],t[n[2]+1])],a=o[0].subtract(o[1]),s=o[2].subtract(o[1]);return{v:o,n:x.Vector3.Cross(s,a).normalize()}},c=function(e,t,r,n){return t=l(e,t,r.x,n),t=l(e,t,r.y,n),l(e,t,r.z,n)},l=function(e,t,r,n){return e.setFloat32(t,r,n),t+4},h=function(e){if(s){var t=e;e instanceof x.InstancedMesh&&(t=e.sourceMesh);var r=t.getVerticesData(x.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var n=x.Vector3.Zero(),o=void 0;for(o=0;o<r.length;o+=3)x.Vector3.TransformCoordinatesFromFloatsToRef(r[o],r[o+1],r[o+2],e.computeWorldMatrix(!0),n).toArray(r,o);return r}return e.getVerticesData(x.VertexBuffer.PositionKind)||[]};s&&(a=!0);var f="",p=0,d=0;if(n){for(var g=0;g<e.length;g++)p+=(v=(_=e[g]).getIndices())?v.length/3:0;var m=new ArrayBuffer(84+50*p);d+=80,(f=new DataView(m)).setUint32(d,p,o),d+=4}else i||(f="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!n&&i&&(f+="solid "+_.name+"\r\n"),!a&&_ instanceof x.Mesh&&_.bakeCurrentTransformIntoVertices();for(var T=h(_),v=_.getIndices()||[],y=0;y<v.length;y+=3){var b=u(v,T,y);n?(d=c(f,d,b.n,o),d=c(f,d,b.v[0],o),d=c(f,d,b.v[1],o),d=c(f,d,b.v[2],o),d+=2):(f+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",f+="\t\touter loop\r\n",f+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",f+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",f+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",f+="\t\tendloop\r\n",f+="\tendfacet\r\n")}!n&&i&&(f+="endsolid "+name+"\r\n")}if(n||i||(f+="endsolid stlmesh"),t){var M=document.createElement("a"),w=new Blob([f],{type:"application/octet-stream"});M.href=window.URL.createObjectURL(w),M.download=r+".stl",M.click()}return f},e}();function Tt(e,t,r,n){void 0===r&&(r=3),void 0===n&&(n=!1);for(var o=[],a=0;a<e.length/r;a++){var s=e[a*r]*(n?-1:1),i=e[a*r+1],u=e[a*r+2];o.push("(".concat(s.toPrecision(t.precision),", ").concat(i.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function vt(e,t){for(var r=[],n=0;n<e.length/2;n++){var o=e[2*n],a=e[2*n+1];r.push("(".concat(o.toPrecision(t.precision),", ").concat((1-a).toPrecision(t.precision),")"))}return r.join(", ")}function yt(e,t,r,n){var o=function(e,t,r,n){var o=e.getVerticesData(x.VertexBuffer.PositionKind),a=e.getVerticesData(x.VertexBuffer.NormalKind);if(o&&a)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(r,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,r=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(r/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,r=e.getIndices(),n=null!==(t=null==r?void 0:r.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==r)for(var a=0;a<n;a++)o.push(r[a]);else for(a=0;a<n;a++)o.push(a);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(Tt(a,t,void 0,n),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(Tt(o,t,void 0,n),"]\n ").concat(function(e,t){for(var r="",n=0;n<4;n++){var o=n>0?n:"",a=e.getVerticesData(x.VertexBuffer.UVKind+(o?o+1:""));a&&(r+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(vt(a,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var s=e.getVerticesData(x.VertexBuffer.ColorKind);return s&&(r+="\n\tcolor3f[] primvars:displayColor = [".concat(Tt(s,t,s.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),r}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t,r,n);return'\n def "Geometry"\n {\n '.concat(o,"\n }\n ")}function bt(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(wt(t,0),", ").concat(wt(t,4),", ").concat(wt(t,8),", ").concat(wt(t,12)," )")}function wt(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function At(e,t){var r="Object_"+e.uniqueId,n=Mt(t);return'def Xform "'.concat(r,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(n,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Rt(e){switch(e){case x.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case x.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case x.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function Ct(e){return"(".concat(e.x,", ").concat(e.y,")")}function Et(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function It(e,t,r,n,o,a){var s=e.getInternalTexture().uniqueId+"_"+e.invertY;o[s]=e;var i=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new x.Vector2(e.uScale,e.vScale),c=new x.Vector2(e.uOffset,e.vOffset),l=e.wAng,h=Math.sin(l),f=Math.cos(l);return c.y=1-c.y-u.y,c.x+=h*u.x,c.y+=(1-f)*u.y,'\n def Shader "PrimvarReader_'.concat(r,'"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "').concat(i,'"\n float2 outputs:result\n }\n\n def Shader "Transform2d_').concat(r,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_').concat(t.uniqueId,"/PrimvarReader_").concat(r,".outputs:result>\n float inputs:rotation = ").concat((l*(180/Math.PI)).toFixed(a.precision),"\n float2 inputs:scale = ").concat(Ct(u),"\n float2 inputs:translation = ").concat(Ct(c),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(r,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(s,".png@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(t.uniqueId,"/Transform2d_").concat(r,".outputs:result>\n ").concat(n?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(n):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(Rt(e.wrapU),'"\n token inputs:wrapT = "').concat(Rt(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 Vt(e,t,r){var n="\t\t\t",o=[],a=[],s=function(e){var t,r,n={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 x.StandardMaterial?T(T({},n),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof x.PBRBaseMaterial?T(T({},n),{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!==(r=e._metallic)&&void 0!==r?r: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}):n}(e),i=s.diffuseMap,u=s.diffuse,c=s.alphaCutOff,l=s.emissiveMap,h=s.emissive,f=s.normalMap,p=s.roughnessMap,d=s.roughnessChannel,g=s.roughness,m=s.metalnessMap,_=s.metalnessChannel,v=s.metalness,y=s.aoMap,b=s.aoMapChannel,M=s.aoMapIntensity,w=s.alphaMap,A=s.ior,R=s.clearCoatEnabled,C=s.clearCoat,E=s.clearCoatMap,I=s.clearCoatRoughness,V=s.clearCoatRoughnessMap;return null!==i?(o.push("".concat(n,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(n,"float inputs:opacityThreshold = ").concat(c))),a.push(It(i,e,"diffuse",u,t,r))):o.push("".concat(n,"color3f inputs:diffuseColor = ").concat(Et(u||x.Color3.White()))),null!==l?(o.push("".concat(n,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),a.push(It(l,e,"emissive",h,t,r))):h&&h.toLuminance()>0&&o.push("".concat(n,"color3f inputs:emissiveColor = ").concat(Et(h))),null!==f&&(o.push("".concat(n,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(f.uniqueId,"_normal.outputs:rgb>")),a.push(It(f,e,"normal",null,t,r))),null!==y&&(o.push("".concat(n,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(y.uniqueId,"_occlusion.outputs:").concat(b,">")),a.push(It(y,e,"occlusion",new x.Color3(M,M,M),t,r))),null!==p?(o.push("".concat(n,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_roughness.outputs:").concat(d,">")),a.push(It(p,e,"roughness",new x.Color3(g,g,g),t,r))):o.push("".concat(n,"float inputs:roughness = ").concat(g)),null!==m?(o.push("".concat(n,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(m.uniqueId,"_metallic.outputs:").concat(_,">")),a.push(It(m,e,"metallic",new x.Color3(v,v,v),t,r))):o.push("".concat(n,"float inputs:metallic = ").concat(v)),null!==w?(o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(w.uniqueId,"_opacity.outputs:r>")),o.push("".concat(n,"float inputs:opacityThreshold = 0.0001")),a.push(It(w,e,"opacity",null,t,r))):o.push("".concat(n,"float inputs:opacity = ").concat(e.alpha)),R&&(null!==E?(o.push("".concat(n,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(E.uniqueId,"_clearcoat.outputs:r>")),a.push(It(E,e,"clearcoat",new x.Color3(C,C,C),t,r))):o.push("".concat(n,"float inputs:clearcoat = ").concat(C)),null!==V?(o.push("".concat(n,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(V.uniqueId,"_clearcoatRoughness.outputs:g>")),a.push(It(V,e,"clearcoatRoughness",new x.Color3(I,I,I),t,r))):o.push("".concat(n,"float inputs:clearcoatRoughness = ").concat(I))),o.push("".concat(n,"float inputs:ior = ").concat(A)),'\n\tdef Material "Material_'.concat(e.uniqueId,'"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n').concat(o.join("\n"),"\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(a.join("\n"),"\n\n\t}\n")}function St(e){var t,r;e.computeWorldMatrix(!0);for(var n=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,a=null!==(r=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==r?r:e.sideOrientation,s=!o,i=e.parent;i;){if(N(i,o)&&null===i.parent){o||(n.multiplyToRef(i.getWorldMatrix().invert(),n),a=a===x.Material.ClockWiseSideOrientation?x.Material.CounterClockWiseSideOrientation:x.Material.ClockWiseSideOrientation),s=!1;break}i=i.parent}return n.determinant()<0&&x.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:n,windingOrder:a===x.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:s}}function Ft(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h,f,p,d,g,m,_,v,b,M,w,A,R,C,E,I,V,S,F,B,O,P,N,U;return y(this,(function(y){switch(y.label){case 0:return n=T({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,x.Tools.LoadScriptAsync(n.fflateUrl)];case 1:y.sent(),y.label=2;case 2:for((o={})[n.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 ")}(n),s={},i=0,u=e.meshes;i<u.length;i++)0!==(c=u[i]).getTotalVertices()&&(h=(l=c).geometry,(f=l.material)&&h&&(!r||r(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(f.getClassName())?(p="geometries/Geometry_"+h.uniqueId+".usda",d=St(l),g=d.matrix,m=d.windingOrder,_=d.convertToRightHanded,p in o||(v=yt(h,n,m,_),o[p]=bt(v)),f.uniqueId in s||(s[f.uniqueId]=f),a+=At(l,g)):x.Tools.Warn("USDZExportAsync does not support this material type: "+f.getClassName())));for(A in e.activeCamera&&n.exportCamera&&(a+=function(e,t){var r="Camera_"+e.uniqueId,n=Mt(x.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===x.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(n,'\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(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(n,'\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,n)),a+="\n }\n }",a+=function(e,t,r){var n=[];for(var o in e){var a=e[o];n.push(Vt(a,t,r))}return'\n def "Materials"\n{\n'.concat(n.join(""),"\n}\n\n")}(s,b={},n),a+="\n }",o[n.modelFileName]=fflate.strToU8(a),w=[],M=b)w.push(A);R=0,y.label=3;case 3:return R<w.length?(A=w[R])in M?(E=b[C=A],I=E.getSize(),[4,(0,x.GetTextureDataAsync)(E)]):[3,6]:[3,7];case 4:return V=y.sent(),[4,x.DumpTools.DumpDataAsync(I.width,I.height,V,"image/png",void 0,!1,!0)];case 5:S=y.sent(),o["textures/Texture_".concat(C,".png")]=new Uint8Array(S).slice(),y.label=6;case 6:return R++,[3,3];case 7:for(B in F=0,o)(O=o[B])&&(P=34+B.length,4!=(N=63&(F+=P))&&(U=new Uint8Array(64-N),o[B]=[O,{extra:{12345:U}}]),F=O.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var Bt=function(){function e(){}return e.Export=function(e,t,r){var n;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,s=0,i=o;s<i.length;s++){var u=i[s],c=e.getAnimationRange(u);c&&(a=a?new x.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=r||1/((null===(n=e.animations[0])||void 0===n?void 0:n.framePerSecond)||30),h=this._BuildBoneHierarchy(e,o),f=0,p=0,d=h;p<d.length;p++){var g=d[p];g.positionKeys.length>0&&(f=Math.max(f,g.positionKeys.length)),g.rotationKeys.length>0&&(f=Math.max(f,g.rotationKeys.length))}0===f&&(f=Math.floor((a.to-a.from)/l)+1);var m="";return m+="HIERARCHY\n",m+=this._ExportHierarchy(h,0),m+="MOTION\n",m+="Frames: ".concat(f,"\n"),(m+="Frame Time: ".concat(l.toFixed(6),"\n"))+this._ExportMotionData(h,f,0,o)},e._BuildBoneHierarchy=function(e,t){for(var r,n,o=new Map,a=[],s=0,i=e.bones;s<i.length;s++){var u={bone:h=i[s],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};o.set(h,u)}for(var c=0,l=e.bones;c<l.length;c++){var h=l[c];if(u=o.get(h),h.animations.length>0)for(var f=0,p=h.animations;f<p.length;f++){var d=p[f];t.includes(d.name)&&("position"===d.targetProperty?(u.hasPositionChannels=!0,(r=u.positionKeys).push.apply(r,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(n=u.rotationKeys).push.apply(n,d.getKeys())))}if(h.getParent()){var x=o.get(h.getParent());x&&x.children.push(u)}else a.push(u)}return a},e._ExportHierarchy=function(e,t){for(var r="",n=" ".repeat(t),o=0,a=e;o<a.length;o++){var s=a[o],i=s.bone;if(this._IsEndSite(s)){r+="".concat(n,"End Site\n"),r+="".concat(n,"{\n");var u=this._GetBoneOffset(i);r+="".concat(n," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),r+="".concat(n,"}\n")}else{r+="".concat(0===t?"ROOT":"".concat(n,"JOINT")," ").concat(i.name,"\n"),r+="".concat(n,"{\n"),u=this._GetBoneOffset(i),r+="".concat(n," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];s.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),s.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(r+="".concat(n," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),s.children.length>0&&(r+=this._ExportHierarchy(s.children,t+1)),r+="".concat(n,"}\n")}}return r},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 x.Vector3.Zero()}},e._ExportMotionData=function(e,t,r,n){for(var o="",a=0;a<t;a++){var s=[];this._CollectFrameValues(e,a+r,s,n),o+=s.map((function(e){return e.toFixed(6)})).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,r,n){for(var o=0,a=e;o<a.length;o++){var s=a[o];if(!this._IsEndSite(s)){if(s.hasPositionChannels){var i=this._GetPositionAtFrameIndex(s.positionKeys,t);r.push(i.x,i.y,i.z)}if(s.hasRotationChannels){var u=this._GetRotationAtFrameIndex(s.rotationKeys,t),c=this._QuaternionToEuler(u);r.push(c.z,c.x,c.y)}s.children.length>0&&this._CollectFrameValues(s.children,t,r,n)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?x.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?x.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new x.Matrix;e.toRotationMatrix(t);var r,n,o,a=t.m,s=Math.sqrt(a[0]*a[0]+a[1]*a[1]);return s>x.Epsilon?(r=Math.atan2(a[6],a[10]),n=Math.atan2(-a[2],s),o=Math.atan2(a[1],a[0])):(r=Math.atan2(-a[9],a[5]),n=Math.atan2(-a[2],s),o=0),new x.Vector3(x.Tools.ToDegrees(r),x.Tools.ToDegrees(n),x.Tools.ToDegrees(o))},e}(),Ot=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Ot)for(var Pt in p)Ot.BABYLON[Pt]=p[Pt];var Nt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Nt){Nt.BABYLON=Nt.BABYLON||{};var Ut=Nt.BABYLON;Ut.GLTF2=Ut.GLTF2||{},Ut.GLTF2.Exporter=Ut.GLTF2.Exporter||{},Ut.GLTF2.Exporter.Extensions=Ut.GLTF2.Exporter.Extensions||{};var Lt=[];for(var kt in s)Ut[kt]=s[kt],Lt.push(kt);for(var kt in i)Ut[kt]=i[kt],Lt.push(kt);for(var kt in u)Ut[kt]=u[kt],Lt.push(kt);for(var kt in c)Ut.GLTF2.Exporter.Extensions[kt]=c[kt],Lt.push(kt);for(var kt in l)Lt.indexOf(kt)>-1||(Ut.GLTF2.Exporter[kt]=l[kt])}var Kt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Kt)for(var zt in a)Kt.BABYLON[zt]=a[zt];var Wt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Wt)for(var Dt in h)Wt.BABYLON[Dt]=h[Dt];var qt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==qt)for(var Gt in f)qt.BABYLON[Gt]=f[Gt];const Ht=d;return o.default})()));
|
|
2
2
|
//# sourceMappingURL=babylonjs.serializers.min.js.map
|