babylonjs-serializers 8.2.0 → 8.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t,r,n={597:t=>{t.exports=e}},o={};function a(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,a),r.exports}r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,a.t=function(e,n){if(1&n&&(e=this(e)),8&n)return e;if("object"==typeof e&&e){if(4&n&&e.__esModule)return e;if(16&n&&"function"==typeof e.then)return e}var o=Object.create(null);a.r(o);var i={};t=t||[null,r({}),r([]),r(r)];for(var s=2&n&&e;"object"==typeof s&&!~t.indexOf(s);s=r(s))Object.getOwnPropertyNames(s).forEach((t=>i[t]=()=>e[t]));return i.default=()=>e,a.d(o,i),o},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};a.d(i,{default:()=>dt});var s={};a.r(s),a.d(s,{OBJExport:()=>x});var u={};a.r(u),a.d(u,{__IGLTFExporterExtension:()=>_});var c={};a.r(c),a.d(c,{GLTFData:()=>v});var l={};a.r(l),a.d(l,{GLTF2Export:()=>se});var f={};a.r(f),a.d(f,{EXT_mesh_gpu_instancing:()=>ce,KHR_draco_mesh_compression:()=>fe,KHR_lights_punctual:()=>ge,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>ye,KHR_materials_diffuse_transmission:()=>Ae,KHR_materials_dispersion:()=>we,KHR_materials_emissive_strength:()=>Re,KHR_materials_ior:()=>Ve,KHR_materials_iridescence:()=>Ie,KHR_materials_sheen:()=>Fe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Ue,KHR_materials_unlit:()=>ke,KHR_materials_volume:()=>Ke,KHR_texture_transform:()=>We});var p={};a.r(p),a.d(p,{EXT_mesh_gpu_instancing:()=>ce,GLTF2Export:()=>se,GLTFData:()=>v,KHR_draco_mesh_compression:()=>fe,KHR_lights_punctual:()=>ge,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>ye,KHR_materials_diffuse_transmission:()=>Ae,KHR_materials_dispersion:()=>we,KHR_materials_emissive_strength:()=>Re,KHR_materials_ior:()=>Ve,KHR_materials_iridescence:()=>Ie,KHR_materials_sheen:()=>Fe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Ue,KHR_materials_unlit:()=>ke,KHR_materials_volume:()=>Ke,KHR_texture_transform:()=>We,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V});var h={};a.r(h),a.d(h,{STLExport:()=>He});var d={};a.r(d),a.d(d,{USDZExportAsync:()=>nt});var m={};a.r(m),a.d(m,{EXT_mesh_gpu_instancing:()=>ce,GLTF2Export:()=>se,GLTFData:()=>v,KHR_draco_mesh_compression:()=>fe,KHR_lights_punctual:()=>ge,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>ye,KHR_materials_diffuse_transmission:()=>Ae,KHR_materials_dispersion:()=>we,KHR_materials_emissive_strength:()=>Re,KHR_materials_ior:()=>Ve,KHR_materials_iridescence:()=>Ie,KHR_materials_sheen:()=>Fe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Ue,KHR_materials_unlit:()=>ke,KHR_materials_volume:()=>Ke,KHR_texture_transform:()=>We,OBJExport:()=>x,STLExport:()=>He,USDZExportAsync:()=>nt,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V,__IGLTFExporterExtension:()=>_});var g=a(597),x=function(){function e(){}return e.OBJ=function(e,t,r,n){var o=[],a=1,i=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var s=0;s<e.length;s++){var u=e[s],c=u.name||"mesh".concat(s,"}");o.push("o ".concat(c));var l=null;if(n){var f=u.computeWorldMatrix(!0);l=new g.Matrix,f.invertToRef(l),u.bakeTransformIntoVertices(f)}if(t){var p=u.material;p&&o.push("usemtl "+p.id)}var h=u.geometry;if(h){var d=h.getVerticesData("position"),m=h.getVerticesData("normal"),x=h.getVerticesData("uv"),_=h.getIndices(),v=0,y=0;if(d&&_){for(var T=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*T+" "+d[b+1]+" "+d[b+2]),v++;if(null!=m)for(b=0;b<m.length;b+=3)o.push("vn "+m[b]*T+" "+m[b+1]+" "+m[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),y++;var A=["","",""],M=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===g.Material.ClockWiseSideOrientation?[2,1]:[1,2],w=M[0],E=M[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+a),String(_[b+w]+a),String(_[b+E]+a)],C=[String(_[b]+i),String(_[b+w]+i),String(_[b+E]+i)],V=R,S=null!=x?C:A,I=null!=m?R:A;o.push("f "+V[0]+"/"+S[0]+"/"+I[0]+" "+V[1]+"/"+S[1]+"/"+I[1]+" "+V[2]+"/"+S[2]+"/"+I[2])}n&&l&&u.bakeTransformIntoVertices(l),a+=v,i+=y}else g.Tools.Warn("There are no position vertices or indices on the mesh!")}else g.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],r=e.material;return t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4)),r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e}(),_=0,v=function(){function e(){this.files={}}return Object.defineProperty(e.prototype,"glTFFiles",{get:function(){return this.files},enumerable:!1,configurable:!0}),e.prototype.downloadFiles=function(){for(var e in this.files){var t=this.files[e],r=new Blob([t],{type:(0,g.GetMimeType)(e)});g.Tools.Download(r,e)}},e}(),y=function(){return y=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},y.apply(this,arguments)};function T(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function s(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function b(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function A(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var M=1e-6,w=new g.Color3(.04,.04,.04),E=1024,R=g.Color3.White(),C=g.Color3.Black();function V(e,t,r){if(t<w.r)return 0;var n=w.r,o=e*r/(1-w.r)+t-2*w.r,a=o*o-4*n*(w.r-t);return g.Scalar.Clamp((-o+Math.sqrt(a))/(2*n),0,1)}function S(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=g.Scalar.Clamp(e.specularPower,0,E),o=(0,g.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:o}}function I(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function B(e,t,r){for(var n=new Uint8Array(e*t*4),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return g.RawTexture.CreateRGBATexture(n,e,t,r)}function F(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var P=function(){function e(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}return e.prototype.getTextureInfo=function(e){var t;return e&&null!==(t=this._textureMap.get(e))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return n=S(e),o={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||g.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),o.doubleSided=!0),r?(a=[],(i=e.diffuseTexture)&&a.push(this.exportTextureAsync(i,t).then((function(e){e&&(n.baseColorTexture=e)}))),(s=e.bumpTexture)&&a.push(this.exportTextureAsync(s,t).then((function(e){e&&(o.normalTexture=e,1!==s.level&&(o.normalTexture.scale=s.level))}))),(u=e.emissiveTexture)&&(o.emissiveFactor=[1,1,1],a.push(this.exportTextureAsync(u,t).then((function(e){e&&(o.emissiveTexture=e)})))),(c=e.ambientTexture)&&a.push(this.exportTextureAsync(c,t).then((function(e){if(e){var t={index:e.index};o.occlusionTexture=t}}))),a.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(a)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===g.Constants.ALPHA_COMBINE?o.alphaMode="BLEND":g.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(C,M)&&(o.emissiveFactor=e.emissiveColor.asArray()),o.pbrMetallicRoughness=n,I(o,e),[4,this._finishMaterialAsync(o,e,t)];case 3:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s;return b(this,(function(u){switch(u.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),o=[],a=0,i=n;a<i.length;a++)s=i[a],o.push(this.exportTextureAsync(s,r));return[4,Promise.all(o)];case 1:return u.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 2:return u.sent(),[2]}}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,i,s,u,c;return b(this,(function(l){switch(l.label){case 0:return o=g.Constants.TEXTURETYPE_UNSIGNED_BYTE,i=this._exporter._babylonScene,s=i.getEngine(),u=s.createRawTexture(e,t,r,g.Constants.TEXTUREFORMAT_RGBA,!1,!0,g.Texture.NEAREST_SAMPLINGMODE,null,o),s.isWebGPU?[4,Promise.resolve().then(a.t.bind(a,597,23))]:[3,2];case 1:return l.sent(),[3,4];case 2:return[4,Promise.resolve().then(a.t.bind(a,597,23))];case 3:l.sent(),l.label=4;case 4:return[4,g.TextureTools.ApplyPostProcess("pass",u,i,o,g.Constants.TEXTURE_NEAREST_SAMPLINGMODE,g.Constants.TEXTUREFORMAT_RGBA)];case 5:return l.sent(),[4,s._readTexturePixels(u,t,r)];case 6:return c=l.sent(),[4,g.DumpTools.DumpDataAsync(t,r,c,n,void 0,!0,!0)];case 7:return[2,l.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,a=e?e.getSize():{width:0,height:0},i=t?t.getSize():{width:0,height:0};return a.width<i.width?(n=e&&e instanceof g.Texture?g.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):B(i.width,i.height,r),o=t):a.width>i.width?(o=t&&t instanceof g.Texture?g.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):B(a.width,a.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i,s,u,c,l,f,p,h,d,m,x,_,v,y,T,A,w,E,V,S,I,B,P,N,O,U,L,k,D;return b(this,(function(b){switch(b.label){case 0:return o=new Array,e||t?(a=e?e.getScene():t?t.getScene():null)?(i=this._resizeTexturesToSameDimensions(e,t,a),s=null===(D=i.texture1)||void 0===D?void 0:D.getSize(),u=void 0,c=void 0,l=s.width,f=s.height,[4,i.texture1.readPixels()]):[3,3]:[2,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:return p=b.sent(),[4,i.texture2.readPixels()];case 2:if(h=b.sent(),!p)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(u=F(p),!h)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(c=F(h),d=c.byteLength,m=new Uint8Array(d),x=new Uint8Array(d),_=C,v=0,y=0,N=0;N<f;++N)for(O=0;O<l;++O)T=4*(l*N+O),A=new g.Color3(u[T],u[T+1],u[T+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),w=new g.Color3(c[T],c[T+1],c[T+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.specularColor),E=c[T+3]*r.glossiness,V={diffuseColor:A,specularColor:w,glossiness:E},S=this._convertSpecularGlossinessToMetallicRoughness(V),_.r=Math.max(_.r,S.baseColor.r),_.g=Math.max(_.g,S.baseColor.g),_.b=Math.max(_.b,S.baseColor.b),v=Math.max(v,S.metallic),y=Math.max(y,S.roughness),x[T]=255*S.baseColor.r,x[T+1]=255*S.baseColor.g,x[T+2]=255*S.baseColor.b,x[T+3]=i.texture1.hasAlpha?255*u[T+3]:255,m[T]=0,m[T+1]=255*S.roughness,m[T+2]=255*S.metallic,m[T+3]=255;for(I={baseColor:_,metallic:v,roughness:y},B=!1,P=!1,N=0;N<f;++N)for(O=0;O<l;++O)x[U=4*(l*N+O)]/=I.baseColor.r>M?I.baseColor.r:1,x[U+1]/=I.baseColor.g>M?I.baseColor.g:1,x[U+2]/=I.baseColor.b>M?I.baseColor.b:1,L=g.Color3.FromInts(x[U],x[U+1],x[U+2]),k=L.toGammaSpace(a.getEngine().useExactSrgbConversions),x[U]=255*k.r,x[U+1]=255*k.g,x[U+2]=255*k.b,k.equalsWithEpsilon(R,M)||(P=!0),m[U+1]/=I.roughness>M?I.roughness:1,m[U+2]/=I.metallic>M?I.metallic:1,g.Color3.FromInts(255,m[U+1],m[U+2]).equalsWithEpsilon(R,M)||(B=!0);return B&&o.push(this._getImageDataAsync(m,l,f,n).then((function(e){I.metallicRoughnessTextureData=e}))),P&&o.push(this._getImageDataAsync(x,l,f,n).then((function(e){I.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return I}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),o=V(t,r,n),a=e.diffuseColor.scale(n/(1-w.r)/Math.max(1-o)),i=e.specularColor.subtract(w.scale(1-o)).scale(1/Math.max(o)),s=g.Color3.Lerp(a,i,o*o);return{baseColor:s=s.clampToRef(0,1,s),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i;return b(this,(function(s){switch(s.label){case 0:return o=[],a={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&(e._albedoTexture&&o.push(this.exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),(i=e._metallicTexture)&&o.push(this.exportTextureAsync(i,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2];case 1:s.sent(),s.label=2;case 2:return[2,a]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof g.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case g.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case g.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case g.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case g.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case g.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case g.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case g.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case g.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case g.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case g.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case g.Texture.WRAP_ADDRESSMODE:return 10497;case g.Texture.CLAMP_ADDRESSMODE:return 33071;case g.Texture.MIRROR_ADDRESSMODE:return 33648;default:return g.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i,s,u,c,l,f;return b(this,(function(p){switch(p.label){case 0:return o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},a=e._albedoTexture,i=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,i&&!s?[2,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")]:(a||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(a||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,i,o,t)]):[3,2];case 1:return c=p.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),t,c.baseColorTextureData),r.baseColorTexture=this._exportTextureInfo(f,u,null==a?void 0:a.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),t,c.metallicRoughnessTextureData),r.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),[2,c];case 2:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return n={},o={name:e.name},(a=e.isMetallicWorkflow())&&(i=e._albedoColor,s=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,s])),a?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,n,r)]:[3,2];case 1:return c=f.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,n,r)];case 3:c=f.sent(),f.label=4;case 4:return u=c,[4,this._setMetallicRoughnessPbrMaterialAsync(u,e,o,n,t,r)];case 5:return f.sent(),[4,this._finishMaterialAsync(o,e,t)];case 6:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,o,a){return T(this,void 0,void 0,(function(){var i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return I(r,t),e.baseColor.equalsWithEpsilon(R,M)&&g.Scalar.WithinEpsilon(t.alpha,1,M)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||g.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),a?(i=[],(s=t._bumpTexture)&&i.push(this.exportTextureAsync(s,o).then((function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))}))),(u=t._ambientTexture)&&i.push(this.exportTextureAsync(u,o).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n;var o=t._ambientTextureStrength;o&&(n.strength=o)}}))),(c=t._emissiveTexture)&&i.push(this.exportTextureAsync(c,o).then((function(e){e&&(r.emissiveTexture=e)}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(l=t._emissiveColor).equalsWithEpsilon(C,M)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype._getPixelsFromTexture=function(e){return e.textureType,g.Constants.TEXTURETYPE_UNSIGNED_BYTE,e.readPixels()},e.prototype.exportTextureAsync=function(e,t){return T(this,void 0,void 0,(function(){var r,n=this;return b(this,(function(o){return(r=this._exporter._extensionsPreExportTextureAsync("exporter",e,t))?[2,r.then((function(r){return r?n._exportTextureInfoAsync(r,t):n._exportTextureInfoAsync(e,t)}))]:[2,this._exportTextureInfoAsync(e,t)]}))}))},e.prototype._exportTextureInfoAsync=function(e,t){return T(this,void 0,void 0,(function(){var r,n,o,a,i,s,u,c,l,f=this;return b(this,(function(p){switch(p.label){case 0:return(r=this._textureMap.get(e))?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=p.sent()))return[2,null];if(o=this._exportTextureSampler(e),a=e.mimeType)switch(a){case"image/jpeg":case"image/png":case"image/webp":t=a;break;default:g.Tools.Warn("Unsupported media type: ".concat(a))}return i=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,i[s]||(i[s]={}),void 0===(u=i[s][t])&&(c=e.getSize(),u=T(f,void 0,void 0,(function(){var r;return b(this,(function(o){switch(o.label){case 0:return[4,this._getImageDataAsync(n,c.width,c.height,t)];case 1:return r=o.sent(),[2,this._exportImage(e.name,t,r)]}}))})),i[s][t]=u),l=this._exportTextureInfo,[4,u];case 2:r=l.apply(this,[p.sent(),o,e.coordinatesIndex]),this._textureMap.set(e,r),this._exporter._extensionsPostExportTextures("exporter",r,e),p.label=3;case 3:return[2,r]}}))}))},e.prototype._exportImage=function(e,t,r){var n,o=this._exporter._images;if(this._exporter._shouldUseGlb){n={name:e,mimeType:t,bufferView:void 0};var a=this._exporter._bufferManager.createBufferView(new Uint8Array(r));this._exporter._bufferManager.setBufferView(n,a)}else{var i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),s=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif"}}(t),u=i+s;o.some((function(e){return e.uri===u}))&&(u="".concat(i,"_").concat(g.Tools.RandomId()).concat(s)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return o.push(n),o.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,o=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===o&&(o=n.length,n.push({source:e,sampler:t}));var a={index:o};return r&&(a.texCoord=r),a},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e}(),N=g.Matrix.Compose(new g.Vector3(-1,1,1),g.Quaternion.Identity(),g.Vector3.Zero()),O=new g.Quaternion(0,1,0,0),U=1e-6,L=g.Vector3.Zero(),k=g.Vector3.One();function D(e,t){var r=e.byteOffset,n=e.byteStride,o=e.type,a=e.normalized,i=e.getSize(),s=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:i,type:o,count:s*i,normalized:a,totalVertices:s,kind:e.getKind()}}function K(e){switch(e){case"MAT2":case"VEC4":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3}}function G(e){switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:case g.VertexBuffer.ColorKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return!0}return!1}function W(e){switch(e){case g.Material.TriangleFillMode:return 4;case g.Material.TriangleStripDrawMode:return 5;case g.Material.TriangleFanDrawMode:return 6;case g.Material.PointListDrawMode:case g.Material.PointFillMode:return 0;case g.Material.LineLoopDrawMode:return 2;case g.Material.LineListDrawMode:return 1;case g.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function H(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 q(e){return e.x*=-1,e}function j(e){return e.x*=-1,e.y*=-1,e}function z(e){return e.multiplyInPlace(O)}function Q(e,t){return t instanceof g.TransformNode&&1==t.getChildren().length&&0==e.getChildren().length}function Y(e,t){if(!(e instanceof g.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(N,g.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof g.Mesh&&e.geometry||e instanceof g.InstancedMesh&&e.sourceMesh.geometry)}function X(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],a=o[0],i=o[1],s=t[a];(Array.isArray(i)&&Array.isArray(s)&&Z(i,s)||i===s)&&delete e[a]}return e}function Z(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var J=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)}]]),$=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=J.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 ee(e){return e%4==0?4:e%2==0?2:1}var te,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 r=new $(t),n=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return ee(t.byteLength)-ee(e.byteLength)}));n<o.length;n++){var a=o[n];a.byteOffset=r.byteOffset,e.push(a);for(var i=e.length-1,s=0,u=this.getPropertiesWithBufferView(a);s<u.length;s++)u[s].bufferView=i;r.writeTypedArray(this._bufferViewToData.get(a)),this._bufferViewToData.delete(a)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,o,a,i){this._verifyBufferView(e);var s={bufferView:void 0,componentType:r,count:n,type:t,min:null==a?void 0:a.min,max:null==a?void 0:a.max,normalized:i,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var o=n[r];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(te||(te={}));var ne=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof g.TransformNode||e instanceof g.Camera||e instanceof g.Light)},e._CreateNodeAnimation=function(t,r,n,o,a){if(this._IsTransformable(t)){var i=[],s=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,o),f=l.interpolationType,p=l.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,i,s,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,i,s,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,i,s,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,i,s,c,o),i.length&&s.length)return{inputs:i,outputs:s,samplerInterpolation:f,inputsMin:p?c.min:g.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:p?c.max:g.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:g.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(g.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,o,a,i,s,u,c,l,f){var p;if(e._IsTransformable(t)&&t.animations)for(var h=0,d=t.animations;h<d.length;h++){var m=d[h];if(!f||f(m)){var g=e._DeduceAnimationInfo(m);g&&(p={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?r:p,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,i,s,u,g.useQuaternion,c,l),p.samplers.length&&p.channels.length&&n.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,a,i,s,u,c,l,f){var p;if(t instanceof g.Mesh){var h=t.morphTargetManager;if(h)for(var d=0;d<h.numTargets;++d)for(var m=0,x=h.getTarget(d).animations;m<x.length;m++){var _=x[m];if(!f||f(_)){for(var v=new g.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),b=0;b<T.length;++b)for(var A=T[b],M=0;M<h.numTargets;++M)M==d?y.push(A):y.push({frame:A.frame,value:0});v.setKeys(y);var w=e._DeduceAnimationInfo(v);w&&(p={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:p,t,v,w.dataAccessorType,w.animationChannelTargetPath,o,i,s,u,w.useQuaternion,c,l,h.numTargets),p.samplers.length&&p.channels.length&&n.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,a,i,s,u,c){var l,f;if(t.animationGroups)for(var p=t.animationGroups,h=function(p){var h=new Map,m=new Map,x=new Set,_=p.to-p.from;f={name:p.name,channels:[],samplers:[]};for(var v=function(r){var _=p.targetedAnimations[r],v=_.target,y=_.animation;if(c&&!c(y))return"continue";var T=u.has(v);if(d._IsTransformable(v)||1===v.length&&d._IsTransformable(v[0])){if(A=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(v)?v:d._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(y.name),f,b,y,A.dataAccessorType,A.animationChannelTargetPath,n,o,a,i,A.useQuaternion,s,T)}}else if(v instanceof g.MorphTarget||1===v.length&&v[0]instanceof g.MorphTarget){var A;if(A=e._DeduceAnimationInfo(_.animation)){var M=v instanceof g.MorphTarget?v:v[0];if(M){var w=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===M)return!0;return!1}));if(w){var E=t.meshes.find((function(e){return e.morphTargetManager===w}));E&&(h.has(E)||h.set(E,new Map),null===(l=h.get(E))||void 0===l||l.set(M,y),x.add(E),m.set(E,y))}}}}},y=0;y<p.targetedAnimations.length;++y)v(y);x.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=m.get(t).getKeys(),d=l.length,x=0;x<d;++x)for(var v=0;v<r.numTargets;++v){var y=r.getTarget(v),T=h.get(t);if(T){var b=T.get(y);b?(u||(u=new g.Animation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,g.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:p.from+_/d*x,value:y.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,o,a,i,A.useQuaternion,s,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},d=this,m=0,x=p;m<x.length;m++)h(x[m])},e._AddAnimation=function(t,r,n,o,a,i,s,u,c,l,f,p,h,d){var m,x,_,v,y,T,b=e._CreateNodeAnimation(n,o,i,f,p);if(b){if(d){for(var A=0,M=0,w=[];b.inputs.length>0;)M=b.inputs.shift(),A%d==0&&w.push(M),A++;b.inputs=w}var E=s.get(n),R=new Float32Array(b.inputs);m=u.createBufferView(R),x=u.createAccessor(m,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var C=new g.Quaternion,V=new g.Vector3,S=new g.Vector3,I=n instanceof g.Camera,B=K(a),F=new Float32Array(b.outputs.length*B);b.outputs.forEach((function(e,t){var r=e;if(h)switch(i){case"translation":g.Vector3.FromArrayToRef(e,0,S),q(S),S.toArray(r);break;case"rotation":4===e.length?g.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),g.Vector3.FromArrayToRef(e,0,V),g.Quaternion.FromEulerVectorToRef(V,C)),I?z(C):g.Quaternion.IsIdentity(C)||j(C),C.toArray(r)}else"rotation"===i&&(4===e.length?g.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),g.Vector3.FromArrayToRef(e,0,V),g.Quaternion.FromEulerVectorToRef(V,C)),I&&z(C),C.toArray(r));F.set(r,t*B)})),m=u.createBufferView(F),x=u.createAccessor(m,a,5126,b.outputs.length),l.push(x),v=l.length-1,y={interpolation:b.samplerInterpolation,input:_,output:v},r.samplers.push(y),T={sampler:r.samplers.length-1,target:{node:E,path:i}},r.channels.push(T)}},e._CreateBakedAnimation=function(t,r,n,o,a,i,s,u,c,l,f){var p,h,d=g.Quaternion.Identity(),m=null,x=null,_=null,v=null,y=null,T=null;l.min=g.Tools.FloatRound(o/i);for(var b=r.getKeys(),A=0,M=b.length;A<M;++A){if(T=null,_=b[A],A+1<M)if(v=b[A+1],_.value.equals&&_.value.equals(v.value)||_.value===v.value){if(0!==A)continue;T=_.frame}else T=v.frame;else{if(y=b[A-1],_.value.equals&&_.value.equals(y.value)||_.value===y.value)continue;T=a}if(T)for(var w=_.frame;w<=T;w+=s)if((h=g.Tools.FloatRound(w/i))!==m){m=h,x=h;var E={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(w,E),e._SetInterpolatedValue(t,p,h,r,n,d,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,a){var i=e._GetBasePositionRotationOrScale(r,o,a),s=n.targetProperty.split("."),u=s?s[1]:"",c=a?g.Quaternion.FromArray(i).normalize():g.Vector3.FromArray(i);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:g.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,a,i,s,u){var c;i.push(r),"weights"!==o?(n.dataType===g.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u)),"rotation"===o?(u?a=t:(c=t,g.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),s.push(a.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,o,a,i){for(var s=0,u=r.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,a,n,t,i)}},e._CreateCubicSplineAnimation=function(t,r,n,o,a,i){r.getKeys().forEach((function(s){o.push(s.frame/r.framePerSecond),e._AddSplineTangent(te.INTANGENT,a,n,"CUBICSPLINE",s,i),e._AddKeyframeValue(s,r,a,n,t,i),e._AddSplineTangent(te.OUTTANGENT,a,n,"CUBICSPLINE",s,i)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var o=e.rotationQuaternion;n=(null!=o?o:g.Quaternion.Identity()).asArray()}else{var a=e.rotation;n=(null!=a?a:g.Vector3.Zero()).asArray()}else if("translation"===t){var i=e.position;n=(null!=i?i:g.Vector3.Zero()).asArray()}else{var s=e.scaling;n=(null!=s?s:g.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,o,a){var i,s=t.dataType;if(s===g.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=g.Vector3.FromArray(u);u=g.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(s===g.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(i=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,a)){if("rotation"===n){var l=a?i:g.Quaternion.RotationYawPitchRoll(i.y,i.x,i.z).normalize();r.push(l.asArray())}r.push(i.asArray())}}else s===g.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):g.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,a=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var i=0,s=e.length;i<s;++i)if((o=e[i]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",a=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&1===o.interpolation&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,r,n,o,a){var i,s=e===te.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(s)if(a)i=s.asArray();else{var u=s;i=g.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else i=[0,0,0,0];else i="weights"===r?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(i)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}();function oe(e,t,r,n,o,a){var i={attributes:{},influence:e.influence,name:e.name},s=a?-1:1,u=g.Vector3.Zero(),c=0;if(e.hasPositions){var l=e.getPositions(),f=t.getVerticesData(g.VertexBuffer.PositionKind,void 0,void 0,!0);if(f){var p=new Float32Array(f.length),h=[1/0,1/0,1/0],d=[-1/0,-1/0,-1/0];c=f.length/3;for(var m=0;m<c;++m){var x=g.Vector3.FromArray(f,3*m);g.Vector3.FromArray(l,3*m).subtractToRef(x,u),u.x*=s,h[0]=Math.min(h[0],u.x),d[0]=Math.max(d[0],u.x),h[1]=Math.min(h[1],u.y),d[1]=Math.max(d[1],u.y),h[2]=Math.min(h[2],u.z),d[2]=Math.max(d[2],u.z),p[3*m]=u.x,p[3*m+1]=u.y,p[3*m+2]=u.z}var _=r.createBufferView(p,12),v=r.createAccessor(_,"VEC3",5126,l.length/3,0,{min:h,max:d});o.push(v),i.attributes.POSITION=o.length-1}else g.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),T=t.getVerticesData(g.VertexBuffer.NormalKind,void 0,void 0,!0);if(T){var b=new Float32Array(T.length);for(c=T.length/3,m=0;m<c;++m){var A=g.Vector3.FromArray(T,3*m).normalize();g.Vector3.FromArray(y,3*m).normalize().subtractToRef(A,u),b[3*m]=u.x*s,b[3*m+1]=u.y,b[3*m+2]=u.z}_=r.createBufferView(b,12),v=r.createAccessor(_,"VEC3",5126,y.length/3,0),o.push(v),i.attributes.NORMAL=o.length-1}else g.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var M=e.getTangents(),w=t.getVerticesData(g.VertexBuffer.TangentKind,void 0,void 0,!0);if(w){c=w.length/4;var E=new Float32Array(3*c);for(m=0;m<c;++m){var R=g.Vector3.FromArray(w,4*m);H(R);var C=g.Vector3.FromArray(M,3*m);H(C),C.subtractToRef(R,u),E[3*m]=u.x*s,E[3*m+1]=u.y,E[3*m+2]=u.z}_=r.createBufferView(E,12),v=r.createAccessor(_,"VEC3",5126,c,0),o.push(v),i.attributes.TANGENT=o.length-1}else g.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),S=t.getVerticesData(g.VertexBuffer.ColorKind,void 0,void 0,!0),I=t.getVertexBuffer(g.VertexBuffer.ColorKind,!0);if(S&&I){var B=I.getSize();c=S.length/B;var F=new Float32Array(c*B);for(m=0;m<c;++m)if(3===B){var P=g.Vector3.FromArray(S,m*B);g.Vector3.FromArray(V,m*B).subtractToRef(P,u),F[3*m]=u.x,F[3*m+1]=u.y,F[3*m+2]=u.z}else if(4===B){var N=new g.Vector4;P=g.Vector4.FromArray(S,m*B),g.Vector4.FromArray(V,m*B).subtractToRef(P,N),F[4*m]=N.x,F[4*m+1]=N.y,F[4*m+2]=N.z,F[4*m+3]=N.w}else g.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));_=r.createBufferView(F,4*B),v=r.createAccessor(_,3===B?"VEC3":"VEC4",5126,c,0),o.push(v),i.attributes.COLOR_0=o.length-1}else g.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return i}var 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,r,n,o){var a,i,s,u;return null===(u=null===(s=null===(i=null===(a=this._indicesAccessorMap.get(e))||void 0===a?void 0:a.get(t))||void 0===i?void 0:i.get(r))||void 0===s?void 0:s.get(n))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,r,n,o,a){var i=this._indicesAccessorMap.get(e);i||(i=new Map,this._indicesAccessorMap.set(e,i));var s=i.get(t);s||(s=new Map,i.set(t,s));var u=s.get(r);u||(u=new Map,s.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(o,a)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,o;return null===(o=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===o?void 0:o.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a)),a.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),ie=function(){function e(e,t){if(void 0===e&&(e=g.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(g.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new P(this),this._extensions={},this._bufferManager=new 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=y({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 e?o._applyExtension(e,t,r+1,n):null})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o];n.push(this._extensions[i])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){var a=this;return this._applyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,r,n,o,a._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var o=[],a=0,i=e._ExtensionNames;a<i.length;a++){var s=i[a],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o],s=this._extensions[i];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.postExportMeshPrimitive&&a.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return T(this,void 0,void 0,(function(){var t,r,n,o;return b(this,(function(a){switch(a.label){case 0:t=0,r=e._ExtensionNames,a.label=1;case 1:return t<r.length?(n=r[t],(o=this._extensions[n]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:a.sent(),a.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.enabled&&t(a)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,o;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&g.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._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 T(this,void 0,void 0,(function(){var t,r,n,o,a,i,s;return b(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",(i=new v).files[o]=r,i.files[a]=n,this._imageData)for(s in this._imageData)i.files[s]=new Blob([this._imageData[s].data],{type:this._imageData[s].mimeType});return[2,i]}}))}))},e.prototype._generateBinaryAsync=function(){return T(this,void 0,void 0,(function(){return b(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 T(this,void 0,void 0,(function(){var t,r,n,o,a,i,s,u,c,l,f,p,h,d,m,g,x,_,y,T,A,M,w,E;return b(this,(function(b){switch(b.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=b.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",o=r.length,"undefined"!=typeof TextEncoder&&(i=new TextEncoder,a=i.encode(r),o=a.length),s=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+s+t.byteLength+u,l=new ArrayBuffer(12),(f=new DataView(l)).setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,c,!0),p=new ArrayBuffer(8+o+s),(h=new DataView(p)).setUint32(0,o+s,!0),h.setUint32(4,1313821514,!0),d=new Uint8Array(p,8),a)d.set(a);else for(m="_".charCodeAt(0),M=0;M<o;++M)(g=r.charCodeAt(M))!=r.codePointAt(M)?d[M]=m:d[M]=g;for(x=new Uint8Array(p,8+o),M=0;M<s;++M)x[M]=32;for(_=new ArrayBuffer(8),(y=new DataView(_)).setUint32(0,t.byteLength+u,!0),y.setUint32(4,5130562,!0),T=new ArrayBuffer(u),A=new Uint8Array(T),M=0;M<u;++M)A[M]=0;return w=new Blob([l,p,_,t,T],{type:"application/octet-stream"}),(E=new v).files[n]=w,[2,E]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){if(t.getPivotPoint().equalsToFloats(0,0,0)||g.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsToFloats(0,0,0)){var n=g.TmpVectors.Vector3[0].copyFrom(t.position);r&&q(n),e.translation=n.asArray()}t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var o=g.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&o.multiplyInPlace(t.rotationQuaternion),g.Quaternion.IsIdentity(o)||(r&&j(o),e.rotation=o.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r,n){var o=g.TmpVectors.Vector3[0],a=g.TmpVectors.Quaternion[0];if(null!==n){var i=g.Matrix.Invert(n.getWorldMatrix());t.getWorldMatrix().multiply(i).decompose(void 0,a,o)}else t.getWorldMatrix().decompose(void 0,a,o);o.equalsToFloats(0,0,0)||(e.translation=o.asArray()),g.Quaternion.IsIdentity(a)||(e.rotation=a.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===g.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===g.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(){for(var e,t=function(t){if(t.bones.length<=0)return"continue";var n=r._skinMap.get(t);if(null==n)return"continue";for(var o={},a=[],i=-1,s=0;s<t.bones.length;++s){var u=t.bones[s];-1!==(c=null!==(e=u.getIndex())&&void 0!==e?e:s)&&(o[c]=u,c>i&&(i=c))}for(var c=0;c<=i;++c){u=o[c],a.push(u.getAbsoluteInverseBindMatrix());var l=u.getTransformNode();if(null!==l){var f=r._nodeMap.get(l);l&&null!=f?n.joints.push(f):g.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}else g.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}var p=r._nodesSkinMap.get(n);if(n.joints.length>0&&void 0!==p){var h=64*a.length,d=new Float32Array(h/4);a.forEach((function(e,t){d.set(e.m,16*t)}));var m=r._bufferManager.createBufferView(d);r._accessors.push(r._bufferManager.createAccessor(m,"MAT4",5126,a.length)),n.inverseBindMatrices=r._accessors.length-1,r._skins.push(n);for(var x=0,_=p;x<_.length;x++)_[x].skin=r._skins.length-1}},r=this,n=0,o=this._babylonScene.skeletons;n<o.length;n++)t(o[n])},e.prototype._exportSceneAsync=function(){return T(this,void 0,void 0,(function(){var e,t,r,n,o,a,i,s,u,c,l,f,p,h,d,m,g,x,_,v,y,T,A;return b(this,(function(b){switch(b.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,i=this._babylonScene.rootNodes;a<i.length;a++)s=i[a],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&Y(s,this._babylonScene.useRightHandedSystem)?o.push.apply(o,s.getChildren()):this._babylonScene.useRightHandedSystem?r.push(s):n.push(s);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new ae(!0,!1),l=(c=(y=e.nodes).push).apply,f=[y],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,f.concat([b.sent()])),p=new ae(!1,!1),d=(h=(T=e.nodes).push).apply,m=[T],[4,this._exportNodesAsync(r,p)];case 2:return d.apply(h,m.concat([b.sent()])),g=new ae(!1,!0),_=(x=(A=e.nodes).push).apply,v=[A],[4,this._exportNodesAsync(o,g)];case 3:return _.apply(x,v.concat([b.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(),this._babylonScene.animationGroups.length&&ne._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 T(this,void 0,void 0,(function(){var r,n,o,a;return b(this,(function(i){switch(i.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,o=e,i.label=1;case 1:return n<o.length?(a=o[n],[4,this._exportNodeAsync(a,r,t)]):[3,4];case 2:i.sent(),i.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 g.Mesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var i in a)if(G(i)){var s=a[i];o.setHasVertexColorAlpha(s,e.hasVertexAlpha);var u=s._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(s)&&c.push(s);var l=r.get(s)||[];r.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=n.get(h)||[],n.set(h,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,m=e.getChildren();d<m.length;d++){var x=m[d];this._collectBuffers(x,t,r,n,o)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,o=new Map,a=0,i=e;a<i.length;a++){var s=i[a];this._collectBuffers(s,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 i=a[0].byteStride;if(a.some((function(e){return e.byteStride!==i})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var s=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=n.get(e),r=D(e,t),o=r.byteOffset,a=r.byteStride,i=r.componentCount,u=r.type,c=r.count,f=r.normalized;switch(r.kind){case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,o,a,i,u,c,f,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var r=1/t;e[0]*=r,e[1]*=r,e[2]*=r}}));break;case g.VertexBuffer.ColorKind:var p=t.filter((function(e){return e.material instanceof g.StandardMaterial||null==e.material})).length;if(0==p)break;if(p!=t.length){g.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==g.VertexBuffer.UNSIGNED_BYTE&&g.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var h=new g.Color3,d=new g.Color4,m=l._babylonScene.getEngine().useExactSrgbConversions;(0,g.EnumerateFloatValues)(s,o,a,i,u,c,f,(function(e){3===e.length?(h.fromArray(e,0),h.toLinearSpaceToRef(h,m),h.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,m),d.toArray(e,0))}))}},c=0,f=a;c<f.length;c++)u(B=f[c]);if(t.convertToRightHanded){for(var p=0,h=a;p<h.length;p++){var d=D(B=h[p],n.get(B)),m=d.byteOffset,x=d.byteStride,_=d.componentCount,v=d.type,y=d.count,T=d.normalized;switch(R=d.kind){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,m,x,_,v,y,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,i);t.setVertexBufferView(e,b);for(var A=new Map,M=0,w=a;M<w.length;M++){var E=D(B=w[M],n.get(B)),R=E.kind,C=E.totalVertices;switch(R){case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:if(B.type==g.VertexBuffer.FLOAT){var V=B.getFloatData(C);null!==V&&A.set(B,V)}}}0!==A.size&&g.Logger.Warn("Joints conversion needed: some joints are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var S=0,I=Array.from(A.keys());S<I.length;S++){var B=I[S],F=A.get(B);if(F){for(var P=F.some((function(e){return e>=256})),N=new(P?Uint16Array:Uint8Array)(F.length),O=0;O<F.length;O++)N[O]=F[O];var U=l._bufferManager.createBufferView(N,4*(P?2:1));t.setRemappedBufferView(e,B,U)}}},l=this,f=0,p=u;f<p.length;f++)c(p[f]);for(var h=0,d=Array.from(o.keys());h<d.length;h++){var m=d[h],x=o.get(m);if(x)for(var _=oe(m,x[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),v=0,y=x;v<y.length;v++){var T=y[v];t.bindMorphDataToMesh(T,_)}}},e.prototype._exportNodeAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l,f=this;return b(this,(function(p){switch(p.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=p.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:[]},i=[],this._babylonScene.animationGroups.length||(ne._CreateMorphTargetAnimationFromMorphTargetAnimations(e,a,i,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&ne._CreateNodeAnimationFromNodeAnimations(e,a,i,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),i.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),s=o?[]:t,u=0,c=e.getChildren(),p.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,r)]):[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 T(this,void 0,void 0,(function(){var r,n,o,a,i,s,u,c,l,f,p,h;return b(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 g.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof g.Mesh||e instanceof g.InstancedMesh?(o=e instanceof g.Mesh?e:e.sourceMesh).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!==(i=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(i)&&this._nodesSkinMap.set(i,[]),null===(f=this._nodesSkinMap.get(i))||void 0===f||f.push(r)),d.label=3;case 3:if(e instanceof g.Camera&&(s=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(s)&&this._nodesCameraMap.set(s,[]),u=e.parent,this._setCameraTransformation(r,e,t.convertToRightHanded,u),u&&Q(e,u)&&(c=this._nodeMap.get(u)))return l=this._nodes[c],null===(p=this._nodesCameraMap.get(s))||void 0===p||p.push(l),[2,null];t.convertToRightHanded&&(m=r,x=g.Vector3.FromArrayToRef(m.translation||[0,0,0],0,g.TmpVectors.Vector3[0]),_=g.Quaternion.FromArrayToRef(m.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[0]),x=q(x),_=j(_),x.equalsWithEpsilon(L,U)?delete m.translation:m.translation=x.asArray(),g.Quaternion.IsIdentity(_)?delete m.rotation:m.rotation=_.asArray(),function(e){var t=g.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[1]);O.multiplyToRef(t,t),e.rotation=t.asArray()}(r)),null===(h=this._nodesCameraMap.get(s))||void 0===h||h.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,r]:(g.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}var m,x,_}))}))},e.prototype._exportIndices=function(e,t,r,n,o,a,i,s,u){var c=e;u.mode=W(a);var l=i!==g.Material.CounterClockWiseSideOrientation,f=!s.wasAddedByNoopNode&&l,p=function(e){switch(e){case g.Material.TriangleFillMode:case g.Material.TriangleStripDrawMode:case g.Material.TriangleFanDrawMode:return!0}return!1}(a)&&f;if(p){if(a===g.Material.TriangleStripDrawMode||a===g.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=W(a);var h=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var d=0;d+2<n;d+=3)h[d]=e[r+d]+o,h[d+1]=e[r+d+2]+o,h[d+2]=e[r+d+1]+o;else for(d=0;d+2<n;d+=3)h[d]=d,h[d+1]=d+2,h[d+2]=d+1;c=h}else if(e&&0!==o){for(h=t?new Uint32Array(n):new Uint16Array(n),d=0;d<n;d++)h[d]=e[r+d]+o;c=h}if(c){var m=s.getIndicesAccessor(e,r,n,o,p);if(void 0===m){var x=function(e,t,r,n){if(e instanceof Uint16Array||e instanceof Uint32Array)return e;if(e instanceof Int32Array)return new Uint32Array(e.buffer,e.byteOffset,e.length);var o=e.slice(0,0+r);return n?new Uint32Array(o):new Uint16Array(o)}(c,0,n,t),_=this._bufferManager.createBufferView(x),v=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(_,"SCALAR",v,n,0)),m=this._accessors.length-1,s.setIndicesAccessor(e,r,n,o,p,m)}u.indices=m}},e.prototype._exportVertexBuffer=function(e,t,r,n,o,a){var i=e.getKind();if(G(i)&&(!i.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var s=o.getVertexAccessor(e,r,n);if(void 0===s){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=i===g.VertexBuffer.PositionKind?function(e,t,r,n){var o=t.byteOffset,a=t.byteStride,i=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,g.EnumerateFloatValues)(e,o+r*a,a,u,i,n*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,r,n):void 0,l=(i===g.VertexBuffer.MatricesIndicesKind||i===g.VertexBuffer.MatricesIndicesExtraKind)&&e.type===g.VertexBuffer.FLOAT,f=l?g.VertexBuffer.UNSIGNED_BYTE:e.type,p=l?void 0:e.normalized,h=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(h,function(e,t){if(e==g.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:return"VEC3";case g.VertexBuffer.TangentKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(i,o.hasVertexColorAlpha(e)),f,n,d,c,p)),s=this._accessors.length-1,o.setVertexAccessor(e,r,n,s)}a.attributes[function(e){switch(e){case g.VertexBuffer.PositionKind:return"POSITION";case g.VertexBuffer.NormalKind:return"NORMAL";case g.VertexBuffer.TangentKind:return"TANGENT";case g.VertexBuffer.ColorKind:return"COLOR_0";case g.VertexBuffer.UVKind:return"TEXCOORD_0";case g.VertexBuffer.UV2Kind:return"TEXCOORD_1";case g.VertexBuffer.UV3Kind:return"TEXCOORD_2";case g.VertexBuffer.UV4Kind:return"TEXCOORD_3";case g.VertexBuffer.UV5Kind:return"TEXCOORD_4";case g.VertexBuffer.UV6Kind:return"TEXCOORD_5";case g.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case g.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case g.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case g.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(i)]=s}},e.prototype._exportMaterialAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a;return b(this,(function(i){switch(i.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,6]:(a=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof g.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof g.PBRMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,"image/png",a)]:[3,2]);case 1:return o=i.sent(),[3,5];case 2:return e instanceof g.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,"image/png",a)]:[3,4];case 3:return o=i.sent(),[3,5];case 4:return g.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 5:this._materialMap.set(e,o),i.label=6;case 6:return n.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return T(this,void 0,void 0,(function(){var r,n,o,a,i,s,u,c,l,f,p,h,d,m,x,_,v,y,T,M,w,E,R,C,V,S,I,B,F,P,N,O,U,L;return b(this,(function(b){switch(b.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===(F=e.geometry)||void 0===F?void 0:F.getVertexBuffers(),i=t.getMorphTargetsFromMesh(e),s=e instanceof g.LinesMesh,u=e instanceof g.GreasedLineBaseMesh,c=e.subMeshes,!(a&&c&&c.length>0))return[3,7];l=0,f=c,b.label=1;case 1:return l<f.length?(p=f[l],h={attributes:{}},d=p.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:d.name},y=e,m=g.Color3.White(),x=null!==(N=null===(P=y.material)||void 0===P?void 0:P.alpha)&&void 0!==N?N:1,(!(_=null!==(U=null===(O=y.greasedLineMaterial)||void 0===O?void 0:O.color)&&void 0!==U?U:m).equals(m)||x<1)&&(v.pbrMetallicRoughness={baseColorFactor:A(A([],_.asArray(),!0),[x],!1)}),this._materials.push(v),h.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return s?(v={name:d.name},(!(y=e).color.equals(g.Color3.White())||y.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:A(A([],y.color.asArray(),!0),[y.alpha],!1)}),this._materials.push(v),h.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,a,p,h)];case 4:b.sent(),b.label=5;case 5:for(T=s||u?g.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,M=d._getEffectiveOrientation(e),this._exportIndices(o,o?(0,g.AreIndices32Bits)(o,p.indexCount,p.indexStart,p.verticesStart):p.verticesCount>65535,o?p.indexStart:p.verticesStart,o?p.indexCount:p.verticesCount,-p.verticesStart,T,M,t,h),w=0,E=Object.values(a);w<E.length;w++)R=E[w],this._exportVertexBuffer(R,d,p.verticesStart,p.verticesCount,t,h);if(i)for(h.targets=[],C=0,V=i;C<V.length;C++)B=V[C],h.targets.push(B.attributes);n.primitives.push(h),this._extensionsPostExportMeshPrimitive(h),b.label=6;case 6:return l++,[3,1];case 7:if(i)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],S=0,I=i;S<I.length;S++)B=I[S],n.weights.push(B.influence),n.extras.targetNames.push(B.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),se=function(){function e(){}return e.GLTFAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o;return b(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 T(this,void 0,void 0,(function(){var n,o;return b(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}(),ue="EXT_mesh_gpu_instancing",ce=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.postExportNodeAsync=function(e,t,r,n,o,a){var i=this;return new Promise((function(e){if(t&&r instanceof g.Mesh&&r.hasThinInstances&&i._exporter){i._wasUsed=!0;for(var n=g.Vector3.Zero(),s=g.Quaternion.Identity(),u=g.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),l=g.TmpVectors.Vector3[2],f=g.TmpVectors.Quaternion[1],p=g.TmpVectors.Vector3[3],h=!1,d=!1,m=!1,x=new Float32Array(3*r.thinInstanceCount),_=new Float32Array(4*r.thinInstanceCount),v=new Float32Array(3*r.thinInstanceCount),y=0,T=0,b=c;T<b.length;T++)b[T].decompose(p,f,l),o&&(q(l),j(f)),x.set(l.asArray(),3*y),_.set(f.normalize().asArray(),4*y),v.set(p.asArray(),3*y),h=h||!l.equalsWithEpsilon(n),d=d||!f.equalsWithEpsilon(s),m=m||!p.equalsWithEpsilon(u),y++;var A={attributes:{}};h&&(A.attributes.TRANSLATION=i._buildAccessor(x,"VEC3",r.thinInstanceCount,a)),d&&(A.attributes.ROTATION=i._buildAccessor(_,"VEC4",r.thinInstanceCount,a)),m&&(A.attributes.SCALE=i._buildAccessor(v,"VEC3",r.thinInstanceCount,a)),t.extensions=t.extensions||{},t.extensions[ue]=A}e(t)}))},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(ue,(function(e){return new ce(e)}));var le="KHR_draco_mesh_compression",fe=function(){function e(e){this.name=le,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&g.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,r){var n=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],a=[],i=null;if(void 0!==e.indices){var s=r[e.indices],u=t.getBufferView(s);i=t.getData(u).slice(),o.push(u),a.push(s)}for(var c,l=[],f=0,p=Object.entries(e.attributes);f<p.length;f++){var h=p[f],d=h[0],m=(s=r[h[1]],u=t.getBufferView(s),K(s.type)),x=(0,g.GetTypedArrayData)(t.getData(u),m,s.componentType,s.byteOffset||0,u.byteStride||(0,g.GetTypeByteLength)(s.componentType)*m,s.normalized||!1,s.count,!0);l.push({kind:d,dracoName:(c=d,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:K(s.type),data:x}),o.push(u),a.push(s)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},v=g.DracoEncoder.Default._encodeAsync(l,i,_).then((function(r){if(r){var i={bufferView:-1,attributes:r.attributeIDs},s=t.createBufferView(r.data);t.setBufferView(i,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var f=0,p=a;f<p.length;f++){var h=p[f];n._accessorsUsed.add(h)}e.extensions||(e.extensions={}),e.extensions[le]=i}else g.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){g.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(v),this._wasUsed=!0}else g.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return T(this,void 0,void 0,(function(){var t=this;return b(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(le,(function(e){return new fe(e)}));var pe="KHR_lights_punctual",he={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},de={innerConeAngle:0,outerConeAngle:Math.PI/4},me=g.Vector3.Backward(),ge=function(){function e(e){this.name=pe,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[pe]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,o){var a=this;return new Promise((function(i){if(r instanceof g.ShadowLight){var s=r.getTypeID()==g.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==g.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==g.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!s)return g.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(pe)),void i(t);if(r.falloffType!==g.Light.FALLOFF_GLTF&&g.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(pe," specification!")),!r.position.equalsToFloats(0,0,0)){var u=g.TmpVectors.Vector3[0].copyFrom(r.position);o&&q(u),t.translation=u.asArray()}if("point"!==s){var c=r.direction.normalizeToRef(g.TmpVectors.Vector3[0]);o&&q(c);var l=Math.acos(g.Vector3.Dot(me,c)),f=g.Vector3.Cross(me,c),p=g.Quaternion.RotationAxisToRef(f,l,g.TmpVectors.Quaternion[0]);g.Quaternion.IsIdentity(p)||(t.rotation=p.asArray())}var h={type:s,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(X(h,he),"spot"===s){var d=r;h.spot={innerConeAngle:d.innerAngle/2,outerConeAngle:d.angle/2},X(h.spot,de)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(h);var m={light:a._lights.lights.length-1},x=r.parent;if(x&&Q(r,x)){var _=n.get(x);if(_){var v=a._exporter._nodes[_];return function(e,t){var r=g.Vector3.FromArrayToRef(t.translation||[0,0,0],0,g.TmpVectors.Vector3[0]),n=g.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[0]),o=g.Vector3.FromArrayToRef(t.scale||[1,1,1],0,g.TmpVectors.Vector3[1]),a=g.Matrix.ComposeToRef(o,n,r,g.TmpVectors.Matrix[0]),i=g.Vector3.FromArrayToRef(e.translation||[0,0,0],0,g.TmpVectors.Vector3[2]),s=g.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[1]),u=g.Vector3.FromArrayToRef(e.scale||[1,1,1],0,g.TmpVectors.Vector3[1]),c=g.Matrix.ComposeToRef(u,s,i,g.TmpVectors.Matrix[1]);a.multiplyToRef(c,c),c.decompose(o,n,r),r.equalsWithEpsilon(L,U)?delete t.translation:t.translation=r.asArray(),g.Quaternion.IsIdentity(n)?delete t.rotation:t.rotation=n.asArray(),o.equalsWithEpsilon(k,U)?delete t.scale:t.scale=o.asArray()}(t,v),v.extensions||(v.extensions={}),v.extensions[pe]=m,void i(null)}}t.extensions||(t.extensions={}),t.extensions[pe]=m,i(t)}else i(t)}))},e}();ie.RegisterExtension(pe,(function(e){return new ge(e)}));var xe="KHR_materials_anisotropy",_e=function(){function e(e){this.name=xe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRBaseMaterial&&r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&n.push(r.anisotropy.texture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof g.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),a={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=o?o:void 0};null!==a.anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[xe]=a}e(t)}))},e}();ie.RegisterExtension(xe,(function(e){return new _e(e)}));var ve="KHR_materials_clearcoat",ye=function(){function e(e){this.name=ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRBaseMaterial&&r.clearCoat.isEnabled?(r.clearCoat.texture&&n.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&n.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&n.push(r.clearCoat.bumpTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof g.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&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&g.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var i=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),s={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=i?i:void 0};null===s.clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[ve]=s}e(t)}))},e}();ie.RegisterExtension(ve,(function(e){return new ye(e)}));var Te="KHR_materials_diffuse_transmission";function be(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(g.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var Ae=function(){function e(e){this.name=Te,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];if(r instanceof g.PBRMaterial&&this._isExtensionEnabled(r)){var o=be(e,r);return o&&n.push(o),r.subSurface.translucencyColorTexture&&n.push(r.subSurface.translucencyColorTexture),n}return n},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,i;if(r instanceof g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var s=r.subSurface,u=be(e,r),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(a=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0,f=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),p=null!==(i=n._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==i?i:void 0,h={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:p};(l||p)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Te]=h}o(t)}))},e}();ie.RegisterExtension(Te,(function(e){return new Ae(e)}));var Me="KHR_materials_dispersion",we=function(){function e(){this.name=Me,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 g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Me]=o}e(t)}))},e}();ie.RegisterExtension(Me,(function(){return new we}));var Ee="KHR_materials_emissive_strength",Re=function(){function e(){this.name=Ee,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){var n=this;return new Promise((function(e){if(!(r instanceof g.PBRMaterial))return e(t);var o=r.emissiveColor.asArray(),a=Math.max.apply(Math,o);if(a>1){n._wasUsed=!0,t.extensions||(t.extensions={});var i={emissiveStrength:a},s=r.emissiveColor.scale(1/i.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[Ee]=i}return e(t)}))},e}();ie.RegisterExtension(Ee,(function(e){return new Re}));var Ce="KHR_materials_ior",Ve=function(){function e(){this.name=Ce,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 g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[Ce]=o}e(t)}))},e}();ie.RegisterExtension(Ce,(function(e){return new Ve}));var Se="KHR_materials_iridescence",Ie=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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRBaseMaterial&&r.iridescence.isEnabled?(r.iridescence.texture&&n.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&n.push(r.iridescence.thicknessTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof g.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),i={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};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Se]=i}e(t)}))},e}();ie.RegisterExtension(Se,(function(e){return new Ie(e)}));var Be="KHR_materials_sheen",Fe=function(){function e(e){this.name=Be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof g.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,i,s;if(r instanceof g.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._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||n._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(a=n._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(i=n._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==i?i:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=n._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==s?s:void 0),t.extensions[Be]=u}e(t)}))},e}();ie.RegisterExtension(Be,(function(e){return new Fe(e)}));var Pe="KHR_materials_specular",Ne=function(){function e(e){this.name=Pe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&n.push(r.metallicReflectanceTexture),r.reflectanceTexture&&n.push(r.reflectanceTexture),n):n},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;if(r instanceof g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var i=null!==(o=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,s=null!==(a=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,u={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:i,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:s};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[Pe]=u}e(t)}))},e}();ie.RegisterExtension(Pe,(function(e){return new Ne(e)}));var Oe="KHR_materials_transmission",Ue=function(){function e(e){this.name=Oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},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 T(this,void 0,void 0,(function(){var n,o,a,i;return b(this,(function(s){switch(s.label){case 0:return r instanceof g.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,"image/png")]:[3,2]:[3,3]):[3,4];case 1:return(i=s.sent())&&(a.transmissionTexture=i),[3,3];case 2:g.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported")),s.label=3;case 3:t.extensions||(t.extensions={}),t.extensions[Oe]=a,s.label=4;case 4:return[2,t]}}))}))},e}();ie.RegisterExtension(Oe,(function(e){return new Ue(e)}));var Le="KHR_materials_unlit",ke=function(){function e(){this.name=Le,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 g.PBRMaterial?o=r.unlit:r instanceof g.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[Le]={}),e(t)}))},e}();ie.RegisterExtension(Le,(function(){return new ke}));var De="KHR_materials_volume",Ke=function(){function e(e){this.name=De,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=g.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o;if(r instanceof g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,i={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[De]=i}e(t)}))},e}();ie.RegisterExtension(De,(function(e){return new Ke(e)}));var Ge="KHR_texture_transform",We=function(){function e(){this.name=Ge,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()||g.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(g.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 g.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Ge,"."));g.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Ge,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,o=e.vRotationCenter,a=e.uScale,i=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=n*a,f=o*i;return[t+(l*(1-u)+f*c),r+(f*(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[Ge]=n)}},e}();ie.RegisterExtension(Ge,(function(){return new We}));var He=function(){function e(){}return e.CreateSTL=function(e,t,r,n,o,a,i,s){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===i&&(i=!1),void 0===s&&(s=!1);var u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],o=[new g.Vector3(t[n[0]],t[n[0]+2],t[n[0]+1]),new g.Vector3(t[n[1]],t[n[1]+2],t[n[1]+1]),new g.Vector3(t[n[2]],t[n[2]+2],t[n[2]+1])],a=o[0].subtract(o[1]),i=o[2].subtract(o[1]);return{v:o,n:g.Vector3.Cross(i,a).normalize()}},c=function(e,t,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},f=function(e){if(i){var t=e;e instanceof g.InstancedMesh&&(t=e.sourceMesh);var r=t.getVerticesData(g.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var n=g.Vector3.Zero(),o=void 0;for(o=0;o<r.length;o+=3)g.Vector3.TransformCoordinatesFromFloatsToRef(r[o],r[o+1],r[o+2],e.computeWorldMatrix(!0),n).toArray(r,o);return r}return e.getVerticesData(g.VertexBuffer.PositionKind)||[]};i&&(a=!0);var p="",h=0,d=0;if(n){for(var m=0;m<e.length;m++)h+=(y=(_=e[m]).getIndices())?y.length/3:0;var x=new ArrayBuffer(84+50*h);d+=80,(p=new DataView(x)).setUint32(d,h,o),d+=4}else s||(p="solid stlmesh\r\n");for(m=0;m<e.length;m++){var _=e[m];!n&&s&&(p+="solid "+_.name+"\r\n"),!a&&_ instanceof g.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=f(_),y=_.getIndices()||[],T=0;T<y.length;T+=3){var b=u(y,v,T);n?(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")}!n&&s&&(p+="endsolid "+name+"\r\n")}if(n||s||(p+="endsolid stlmesh"),t){var A=document.createElement("a"),M=new Blob([p],{type:"application/octet-stream"});A.href=window.URL.createObjectURL(M),A.download=r+".stl",A.click()}return p},e}();function qe(e,t,r){void 0===r&&(r=3);for(var n=[],o=0;o<e.length/r;o++){var a=e[o*r],i=e[o*r+1],s=e[o*r+2];n.push("(".concat(a.toPrecision(t.precision),", ").concat(i.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),")"))}return n.join(", ")}function je(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 ze(e,t){var r=function(e,t){var r=e.getVerticesData(g.VertexBuffer.PositionKind),n=e.getVerticesData(g.VertexBuffer.PositionKind);if(r&&n)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\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=e.getIndices(),r=[];if(null!==t)for(var n=0;n<t.length;n++)r.push(t[n]);else{var o=e.getTotalVertices();for(n=0;n<o;n++)r.push(n)}return r.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(qe(n,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(qe(r,t),"]\n ").concat(function(e,t){for(var r="",n=0;n<4;n++){var o=n>0?n:"",a=e.getVerticesData(g.VertexBuffer.UVKind+(o||""));a&&(r+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(je(a,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var i=e.getVerticesData(g.VertexBuffer.ColorKind);return i&&(r+="\n\tcolor3f[] primvars:displayColor = [".concat(qe(i,t,i.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),r}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t);return'\n def "Geometry"\n {\n '.concat(r,"\n }\n ")}function Qe(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 Ye(e){var t=e.m;return"( ".concat(Xe(t,0),", ").concat(Xe(t,4),", ").concat(Xe(t,8),", ").concat(Xe(t,12)," )")}function Xe(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function Ze(e){var t="Object_"+e.uniqueId,r=e.getWorldMatrix().clone();r.determinant()<0&&r.multiplyToRef(g.Matrix.Scaling(-1,1,1),r);var n=Ye(r);return'def Xform "'.concat(t,'" (\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 = </Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Je(e){switch(e){case g.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case g.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case g.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function $e(e){return"(".concat(e.x,", ").concat(e.y,")")}function et(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function tt(e,t,r,n,o,a){var i=e.getInternalTexture().uniqueId+"_"+e.invertY;o[i]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new g.Vector2(e.uScale,e.vScale),c=new g.Vector2(e.uOffset,e.vOffset),l=e.wAng,f=Math.sin(l),p=Math.cos(l);return c.y=1-c.y-u.y,c.x+=f*u.x,c.y+=(1-p)*u.y,'\n def Shader "PrimvarReader_'.concat(r,'"\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(r,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </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($e(u),"\n float2 inputs:translation = ").concat($e(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(i,".png@\n float2 inputs:st.connect = </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?"raw":"sRGB",'"\n token inputs:wrapS = "').concat(Je(e.wrapU),'"\n token inputs:wrapT = "').concat(Je(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(t.needAlphaBlending()?"float outputs:a":"","\n }")}function rt(e,t,r){var n="\t\t\t",o=[],a=[],i=function(e){switch(e.getClassName()){case"StandardMaterial":return{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughnessMap:null,normalMap:null,metalnessMap:null,roughness:1,metalness:0,aoMap:null,aoMapIntensity:0,alphaMap:e.opacityTexture,ior:1};case"PBRMaterial":return{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:e.roughness||1,metalnessMap:e.metallicTexture,metalnessChannel:e.useMetallnessFromMetallicTextureBlue?"b":"r",metalness:e.metallic||0,aoMap:e.ambientTexture,aoMapChannel:e.useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e.ambientTextureStrength,alphaMap:e.opacityTexture,ior:e.indexOfRefraction};case"PBRMetallicRoughnessMaterial":return{diffuseMap:e.baseTexture,diffuse:e.baseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,normalMap:e.normalTexture,roughnessMap:e.metallicTexture,roughnessChannel:e.useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:e.roughness||1,metalnessMap:e.metallicTexture,metalnessChannel:e.useMetallnessFromMetallicTextureBlue?"b":"r",metalness:e.metallic||0,aoMap:e.ambientTexture,aoMapChannel:e.useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e.ambientTextureStrength,alphaMap:e.opacityTexture,ior:e.indexOfRefraction};default:return{diffuseMap:null,diffuse:null,emissiveMap:null,emissemissiveiveColor:null,normalMap:null,roughnessMap:null,metalnessMap:null,alphaCutOff:0,roughness:0,metalness:0,aoMap:null,aoMapIntensity:0,alphaMap:null,ior:1}}}(e),s=i.diffuseMap,u=i.diffuse,c=i.alphaCutOff,l=i.emissiveMap,f=i.emissive,p=i.normalMap,h=i.roughnessMap,d=i.roughnessChannel,m=i.roughness,x=i.metalnessMap,_=i.metalnessChannel,v=i.metalness,y=i.aoMap,T=i.aoMapChannel,b=i.aoMapIntensity,A=i.alphaMap,M=i.ior;return null!==s?(o.push("".concat(n,"color3f inputs:diffuseColor.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(n,"float inputs:opacity.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(n,"float inputs:opacity.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(n,"float inputs:opacityThreshold = ").concat(c))),a.push(tt(s,e,"diffuse",u,t,r))):o.push("".concat(n,"color3f inputs:diffuseColor = ").concat(et(u||g.Color3.White()))),null!==l?(o.push("".concat(n,"color3f inputs:emissiveColor.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),a.push(tt(l,e,"emissive",f,t,r))):f&&f.toLuminance()>0&&o.push("".concat(n,"color3f inputs:emissiveColor = ").concat(et(f))),null!==p&&(o.push("".concat(n,"normal3f inputs:normal.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_normal.outputs:rgb>")),a.push(tt(p,e,"normal",null,t,r))),null!==y&&(o.push("".concat(n,"float inputs:occlusion.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(y.uniqueId,"_occlusion.outputs:").concat(T,">")),a.push(tt(y,e,"occlusion",new g.Color3(b,b,b),t,r))),null!==h?(o.push("".concat(n,"float inputs:roughness.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(h.uniqueId,"_roughness.outputs:").concat(d,">")),a.push(tt(h,e,"roughness",new g.Color3(m,m,m),t,r))):o.push("".concat(n,"float inputs:roughness = ").concat(m)),null!==x?(o.push("".concat(n,"float inputs:metallic.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(x.uniqueId,"_metallic.outputs:").concat(_,">")),a.push(tt(x,e,"metallic",new g.Color3(v,v,v),t,r))):o.push("".concat(n,"float inputs:metallic = ").concat(v)),null!==A?(o.push("".concat(n,"float inputs:opacity.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(A.uniqueId,"_opacity.outputs:r>")),o.push("".concat(n,"float inputs:opacityThreshold = 0.0001")),a.push(tt(A,e,"opacity",null,t,r))):o.push("".concat(n,"float inputs:opacity = ").concat(e.alpha)),o.push("".concat(n,"float inputs:ior = ").concat(M)),'\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 = </Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(a.join("\n"),"\n\n\t}\n")}function nt(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l,f,p,h,d,m,x,_,v,T,A,M,w,E,R,C,V,S,I,B,F;return b(this,(function(b){switch(b.label){case 0:return n=y({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},t),"undefined"!=typeof fflate?[3,2]:[4,g.Tools.LoadScriptAsync(n.fflateUrl)];case 1:b.sent(),b.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),i={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(f=(l=c).geometry,(p=l.material)&&f&&(!r||r(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(p.getClassName())?((h="geometries/Geometry_"+f.uniqueId+".usda")in o||(d=ze(f,n),o[h]=Qe(d)),p.uniqueId in i||(i[p.uniqueId]=p),a+=Ze(l)):g.Tools.Warn("USDZExportAsync does not support this material type: "+p.getClassName())));for(v in e.activeCamera&&n.exportCamera&&(a+=function(e,t){var r="Camera_"+e.uniqueId,n=Ye(g.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===g.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 }\n }",a+=function(e,t,r){var n=[];for(var o in e){var a=e[o];n.push(rt(a,t,r))}return'\n def "Materials"\n{\n'.concat(n.join(""),"\n}\n\n")}(i,m={},n),o[n.modelFileName]=fflate.strToU8(a),_=[],x=m)_.push(v);T=0,b.label=3;case 3:return T<_.length?(v=_[T])in x?(M=m[A=v],w=M.getSize(),[4,M.readPixels()]):[3,6]:[3,7];case 4:if(!(E=b.sent()))throw new Error("Texture data is not available");return[4,g.DumpTools.DumpDataAsync(w.width,w.height,E,"image/png",void 0,!1,!0)];case 5:R=b.sent(),o["textures/Texture_".concat(A,".png")]=new Uint8Array(R).slice(),b.label=6;case 6:return T++,[3,3];case 7:for(V in C=0,o)(S=o[V])&&(I=34+V.length,4!=(B=63&(C+=I))&&(F=new Uint8Array(64-B),o[V]=[S,{extra:{12345:F}}]),C=S.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var ot=void 0!==a.g?a.g:"undefined"!=typeof window?window:void 0;if(void 0!==ot){ot.BABYLON=ot.BABYLON||{};var at=ot.BABYLON;at.GLTF2=at.GLTF2||{},at.GLTF2.Exporter=at.GLTF2.Exporter||{},at.GLTF2.Exporter.Extensions=at.GLTF2.Exporter.Extensions||{};var it=[];for(var st in u)at[st]=u[st],it.push(st);for(var st in c)at[st]=c[st],it.push(st);for(var st in l)at[st]=l[st],it.push(st);for(var st in f)at.GLTF2.Exporter.Extensions[st]=f[st],it.push(st);for(var st in p)it.indexOf(st)>-1||(at.GLTF2.Exporter[st]=p[st])}var ut=void 0!==a.g?a.g:"undefined"!=typeof window?window:void 0;if(void 0!==ut)for(var ct in s)ut.BABYLON[ct]=s[ct];var lt=void 0!==a.g?a.g:"undefined"!=typeof window?window:void 0;if(void 0!==lt)for(var ft in h)lt.BABYLON[ft]=h[ft];var pt=void 0!==a.g?a.g:"undefined"!=typeof window?window:void 0;if(void 0!==pt)for(var ht in d)pt.BABYLON[ht]=d[ht];const dt=m;return i.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,r,n={597:t=>{t.exports=e}},o={};function a(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,a),r.exports}r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,a.t=function(e,n){if(1&n&&(e=this(e)),8&n)return e;if("object"==typeof e&&e){if(4&n&&e.__esModule)return e;if(16&n&&"function"==typeof e.then)return e}var o=Object.create(null);a.r(o);var i={};t=t||[null,r({}),r([]),r(r)];for(var s=2&n&&e;"object"==typeof s&&!~t.indexOf(s);s=r(s))Object.getOwnPropertyNames(s).forEach((t=>i[t]=()=>e[t]));return i.default=()=>e,a.d(o,i),o},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};a.d(i,{default:()=>dt});var s={};a.r(s),a.d(s,{OBJExport:()=>x});var u={};a.r(u),a.d(u,{__IGLTFExporterExtension:()=>_});var c={};a.r(c),a.d(c,{GLTFData:()=>y});var l={};a.r(l),a.d(l,{GLTF2Export:()=>se});var f={};a.r(f),a.d(f,{EXT_mesh_gpu_instancing:()=>ce,KHR_draco_mesh_compression:()=>fe,KHR_lights_punctual:()=>ge,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>ve,KHR_materials_diffuse_transmission:()=>Ae,KHR_materials_dispersion:()=>we,KHR_materials_emissive_strength:()=>Re,KHR_materials_ior:()=>Ve,KHR_materials_iridescence:()=>Ie,KHR_materials_sheen:()=>Fe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Ue,KHR_materials_unlit:()=>ke,KHR_materials_volume:()=>Ke,KHR_texture_transform:()=>We});var p={};a.r(p),a.d(p,{EXT_mesh_gpu_instancing:()=>ce,GLTF2Export:()=>se,GLTFData:()=>y,KHR_draco_mesh_compression:()=>fe,KHR_lights_punctual:()=>ge,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>ve,KHR_materials_diffuse_transmission:()=>Ae,KHR_materials_dispersion:()=>we,KHR_materials_emissive_strength:()=>Re,KHR_materials_ior:()=>Ve,KHR_materials_iridescence:()=>Ie,KHR_materials_sheen:()=>Fe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Ue,KHR_materials_unlit:()=>ke,KHR_materials_volume:()=>Ke,KHR_texture_transform:()=>We,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V});var h={};a.r(h),a.d(h,{STLExport:()=>He});var d={};a.r(d),a.d(d,{USDZExportAsync:()=>nt});var m={};a.r(m),a.d(m,{EXT_mesh_gpu_instancing:()=>ce,GLTF2Export:()=>se,GLTFData:()=>y,KHR_draco_mesh_compression:()=>fe,KHR_lights_punctual:()=>ge,KHR_materials_anisotropy:()=>_e,KHR_materials_clearcoat:()=>ve,KHR_materials_diffuse_transmission:()=>Ae,KHR_materials_dispersion:()=>we,KHR_materials_emissive_strength:()=>Re,KHR_materials_ior:()=>Ve,KHR_materials_iridescence:()=>Ie,KHR_materials_sheen:()=>Fe,KHR_materials_specular:()=>Ne,KHR_materials_transmission:()=>Ue,KHR_materials_unlit:()=>ke,KHR_materials_volume:()=>Ke,KHR_texture_transform:()=>We,OBJExport:()=>x,STLExport:()=>He,USDZExportAsync:()=>nt,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V,__IGLTFExporterExtension:()=>_});var g=a(597),x=function(){function e(){}return e.OBJ=function(e,t,r,n){var o=[],a=1,i=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var s=0;s<e.length;s++){var u=e[s],c=u.name||"mesh".concat(s,"}");o.push("o ".concat(c));var l=null;if(n){var f=u.computeWorldMatrix(!0);l=new g.Matrix,f.invertToRef(l),u.bakeTransformIntoVertices(f)}if(t){var p=u.material;p&&o.push("usemtl "+p.id)}var h=u.geometry;if(h){var d=h.getVerticesData("position"),m=h.getVerticesData("normal"),x=h.getVerticesData("uv"),_=h.getIndices(),y=0,v=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]),y++;if(null!=m)for(b=0;b<m.length;b+=3)o.push("vn "+m[b]*T+" "+m[b+1]+" "+m[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),v++;var A=["","",""],M=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===g.Material.ClockWiseSideOrientation?[2,1]:[1,2],w=M[0],E=M[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+a),String(_[b+w]+a),String(_[b+E]+a)],C=[String(_[b]+i),String(_[b+w]+i),String(_[b+E]+i)],V=R,S=null!=x?C:A,I=null!=m?R:A;o.push("f "+V[0]+"/"+S[0]+"/"+I[0]+" "+V[1]+"/"+S[1]+"/"+I[1]+" "+V[2]+"/"+S[2]+"/"+I[2])}n&&l&&u.bakeTransformIntoVertices(l),a+=y,i+=v}else g.Tools.Warn("There are no position vertices or indices on the mesh!")}else g.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],r=e.material;return t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4)),r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e}(),_=0,y=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,g.GetMimeType)(e)});g.Tools.Download(r,e)}},e}(),v=function(){return v=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},v.apply(this,arguments)};function T(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function s(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function b(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function A(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var M=1e-6,w=new g.Color3(.04,.04,.04),E=1024,R=g.Color3.White(),C=g.Color3.Black();function V(e,t,r){if(t<w.r)return 0;var n=w.r,o=e*r/(1-w.r)+t-2*w.r,a=o*o-4*n*(w.r-t);return g.Scalar.Clamp((-o+Math.sqrt(a))/(2*n),0,1)}function S(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=g.Scalar.Clamp(e.specularPower,0,E),o=(0,g.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:o}}function I(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function B(e,t,r){for(var n=new Uint8Array(e*t*4),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return g.RawTexture.CreateRGBATexture(n,e,t,r)}function F(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var P=function(){function e(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}return e.prototype.getTextureInfo=function(e){var t;return e&&null!==(t=this._textureMap.get(e))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return n=S(e),o={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||g.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),o.doubleSided=!0),r?(a=[],(i=e.diffuseTexture)&&a.push(this.exportTextureAsync(i,t).then((function(e){e&&(n.baseColorTexture=e)}))),(s=e.bumpTexture)&&a.push(this.exportTextureAsync(s,t).then((function(e){e&&(o.normalTexture=e,1!==s.level&&(o.normalTexture.scale=s.level))}))),(u=e.emissiveTexture)&&(o.emissiveFactor=[1,1,1],a.push(this.exportTextureAsync(u,t).then((function(e){e&&(o.emissiveTexture=e)})))),(c=e.ambientTexture)&&a.push(this.exportTextureAsync(c,t).then((function(e){if(e){var t={index:e.index};o.occlusionTexture=t}}))),a.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(a)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===g.Constants.ALPHA_COMBINE?o.alphaMode="BLEND":g.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(C,M)&&(o.emissiveFactor=e.emissiveColor.asArray()),o.pbrMetallicRoughness=n,I(o,e),[4,this._finishMaterialAsync(o,e,t)];case 3:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s;return b(this,(function(u){switch(u.label){case 0:for(n=this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",e,t),o=[],a=0,i=n;a<i.length;a++)s=i[a],o.push(this.exportTextureAsync(s,r));return[4,Promise.all(o)];case 1:return u.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 2:return u.sent(),[2]}}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,i,s,u,c;return b(this,(function(l){switch(l.label){case 0:return o=g.Constants.TEXTURETYPE_UNSIGNED_BYTE,i=this._exporter._babylonScene,s=i.getEngine(),u=s.createRawTexture(e,t,r,g.Constants.TEXTUREFORMAT_RGBA,!1,!0,g.Texture.NEAREST_SAMPLINGMODE,null,o),s.isWebGPU?[4,Promise.resolve().then(a.t.bind(a,597,23))]:[3,2];case 1:return l.sent(),[3,4];case 2:return[4,Promise.resolve().then(a.t.bind(a,597,23))];case 3:l.sent(),l.label=4;case 4:return[4,g.TextureTools.ApplyPostProcess("pass",u,i,o,g.Constants.TEXTURE_NEAREST_SAMPLINGMODE,g.Constants.TEXTUREFORMAT_RGBA)];case 5:return l.sent(),[4,s._readTexturePixels(u,t,r)];case 6:return c=l.sent(),[4,g.DumpTools.DumpDataAsync(t,r,c,n,void 0,!0,!0)];case 7:return[2,l.sent()]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,a=e?e.getSize():{width:0,height:0},i=t?t.getSize():{width:0,height:0};return a.width<i.width?(n=e&&e instanceof g.Texture?g.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):B(i.width,i.height,r),o=t):a.width>i.width?(o=t&&t instanceof g.Texture?g.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):B(a.width,a.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i,s,u,c,l,f,p,h,d,m,x,_,y,v,T,A,w,E,V,S,I,B,P,N,O,U,L,k,D;return b(this,(function(b){switch(b.label){case 0:return o=new Array,e||t?(a=e?e.getScene():t?t.getScene():null)?(i=this._resizeTexturesToSameDimensions(e,t,a),s=null===(D=i.texture1)||void 0===D?void 0:D.getSize(),u=void 0,c=void 0,l=s.width,f=s.height,[4,i.texture1.readPixels()]):[3,3]:[2,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:return p=b.sent(),[4,i.texture2.readPixels()];case 2:if(h=b.sent(),!p)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(u=F(p),!h)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(c=F(h),d=c.byteLength,m=new Uint8Array(d),x=new Uint8Array(d),_=C,y=0,v=0,N=0;N<f;++N)for(O=0;O<l;++O)T=4*(l*N+O),A=new g.Color3(u[T],u[T+1],u[T+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),w=new g.Color3(c[T],c[T+1],c[T+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.specularColor),E=c[T+3]*r.glossiness,V={diffuseColor:A,specularColor:w,glossiness:E},S=this._convertSpecularGlossinessToMetallicRoughness(V),_.r=Math.max(_.r,S.baseColor.r),_.g=Math.max(_.g,S.baseColor.g),_.b=Math.max(_.b,S.baseColor.b),y=Math.max(y,S.metallic),v=Math.max(v,S.roughness),x[T]=255*S.baseColor.r,x[T+1]=255*S.baseColor.g,x[T+2]=255*S.baseColor.b,x[T+3]=i.texture1.hasAlpha?255*u[T+3]:255,m[T]=0,m[T+1]=255*S.roughness,m[T+2]=255*S.metallic,m[T+3]=255;for(I={baseColor:_,metallic:y,roughness:v},B=!1,P=!1,N=0;N<f;++N)for(O=0;O<l;++O)x[U=4*(l*N+O)]/=I.baseColor.r>M?I.baseColor.r:1,x[U+1]/=I.baseColor.g>M?I.baseColor.g:1,x[U+2]/=I.baseColor.b>M?I.baseColor.b:1,L=g.Color3.FromInts(x[U],x[U+1],x[U+2]),k=L.toGammaSpace(a.getEngine().useExactSrgbConversions),x[U]=255*k.r,x[U+1]=255*k.g,x[U+2]=255*k.b,k.equalsWithEpsilon(R,M)||(P=!0),m[U+1]/=I.roughness>M?I.roughness:1,m[U+2]/=I.metallic>M?I.metallic:1,g.Color3.FromInts(255,m[U+1],m[U+2]).equalsWithEpsilon(R,M)||(B=!0);return B&&o.push(this._getImageDataAsync(m,l,f,n).then((function(e){I.metallicRoughnessTextureData=e}))),P&&o.push(this._getImageDataAsync(x,l,f,n).then((function(e){I.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return I}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),o=V(t,r,n),a=e.diffuseColor.scale(n/(1-w.r)/Math.max(1-o)),i=e.specularColor.subtract(w.scale(1-o)).scale(1/Math.max(o)),s=g.Color3.Lerp(a,i,o*o);return{baseColor:s=s.clampToRef(0,1,s),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i;return b(this,(function(s){switch(s.label){case 0:return o=[],a={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness},n&&(e._albedoTexture&&o.push(this.exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),(i=e._metallicTexture)&&o.push(this.exportTextureAsync(i,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2];case 1:s.sent(),s.label=2;case 2:return[2,a]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof g.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case g.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case g.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case g.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case g.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case g.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case g.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case g.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case g.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case g.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case g.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case g.Texture.WRAP_ADDRESSMODE:return 10497;case g.Texture.CLAMP_ADDRESSMODE:return 33071;case g.Texture.MIRROR_ADDRESSMODE:return 33648;default:return g.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a,i,s,u,c,l,f;return b(this,(function(p){switch(p.label){case 0:return o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},a=e._albedoTexture,i=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,i&&!s?[2,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")]:(a||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(a||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,i,o,t)]):[3,2];case 1:return c=p.sent(),l=this._exporter._textures,c.baseColorTextureData&&(f=this._exportImage("baseColor".concat(l.length),t,c.baseColorTextureData),r.baseColorTexture=this._exportTextureInfo(f,u,null==a?void 0:a.coordinatesIndex)),c.metallicRoughnessTextureData&&(f=this._exportImage("metallicRoughness".concat(l.length),t,c.metallicRoughnessTextureData),r.metallicRoughnessTexture=this._exportTextureInfo(f,u,null==i?void 0:i.coordinatesIndex)),[2,c];case 2:return[2,this._convertSpecularGlossinessToMetallicRoughness(o)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return n={},o={name:e.name},(a=e.isMetallicWorkflow())&&(i=e._albedoColor,s=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,s])),a?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,n,r)]:[3,2];case 1:return c=f.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,n,r)];case 3:c=f.sent(),f.label=4;case 4:return u=c,[4,this._setMetallicRoughnessPbrMaterialAsync(u,e,o,n,t,r)];case 5:return f.sent(),[4,this._finishMaterialAsync(o,e,t)];case 6:return f.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,o,a){return T(this,void 0,void 0,(function(){var i,s,u,c,l;return b(this,(function(f){switch(f.label){case 0:return I(r,t),e.baseColor.equalsWithEpsilon(R,M)&&g.Scalar.WithinEpsilon(t.alpha,1,M)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||g.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),a?(i=[],(s=t._bumpTexture)&&i.push(this.exportTextureAsync(s,o).then((function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))}))),(u=t._ambientTexture)&&i.push(this.exportTextureAsync(u,o).then((function(e){if(e){var n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n;var o=t._ambientTextureStrength;o&&(n.strength=o)}}))),(c=t._emissiveTexture)&&i.push(this.exportTextureAsync(c,o).then((function(e){e&&(r.emissiveTexture=e)}))),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:f.sent(),f.label=2;case 2:return(l=t._emissiveColor).equalsWithEpsilon(C,M)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype._getPixelsFromTexture=function(e){return e.textureType,g.Constants.TEXTURETYPE_UNSIGNED_BYTE,e.readPixels()},e.prototype.exportTextureAsync=function(e,t){return T(this,void 0,void 0,(function(){var r,n=this;return b(this,(function(o){return(r=this._exporter._extensionsPreExportTextureAsync("exporter",e,t))?[2,r.then((function(r){return r?n._exportTextureInfoAsync(r,t):n._exportTextureInfoAsync(e,t)}))]:[2,this._exportTextureInfoAsync(e,t)]}))}))},e.prototype._exportTextureInfoAsync=function(e,t){return T(this,void 0,void 0,(function(){var r,n,o,a,i,s,u,c,l,f=this;return b(this,(function(p){switch(p.label){case 0:return(r=this._textureMap.get(e))?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=p.sent()))return[2,null];if(o=this._exportTextureSampler(e),a=e.mimeType)switch(a){case"image/jpeg":case"image/png":case"image/webp":t=a;break;default:g.Tools.Warn("Unsupported media type: ".concat(a))}return i=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,i[s]||(i[s]={}),void 0===(u=i[s][t])&&(c=e.getSize(),u=T(f,void 0,void 0,(function(){var r;return b(this,(function(o){switch(o.label){case 0:return[4,this._getImageDataAsync(n,c.width,c.height,t)];case 1:return r=o.sent(),[2,this._exportImage(e.name,t,r)]}}))})),i[s][t]=u),l=this._exportTextureInfo,[4,u];case 2:r=l.apply(this,[p.sent(),o,e.coordinatesIndex]),this._textureMap.set(e,r),this._exporter._extensionsPostExportTextures("exporter",r,e),p.label=3;case 3:return[2,r]}}))}))},e.prototype._exportImage=function(e,t,r){var n,o=this._exporter._images;if(this._exporter._shouldUseGlb){n={name:e,mimeType:t,bufferView:void 0};var a=this._exporter._bufferManager.createBufferView(new Uint8Array(r));this._exporter._bufferManager.setBufferView(n,a)}else{var i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),s=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif"}}(t),u=i+s;o.some((function(e){return e.uri===u}))&&(u="".concat(i,"_").concat(g.Tools.RandomId()).concat(s)),n={name:e,uri:u},this._exporter._imageData[u]={data:r,mimeType:t}}return o.push(n),o.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,o=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===o&&(o=n.length,n.push({source:e,sampler:t}));var a={index:o};return r&&(a.texCoord=r),a},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e}(),N=g.Matrix.Compose(new g.Vector3(-1,1,1),g.Quaternion.Identity(),g.Vector3.Zero()),O=new g.Quaternion(0,1,0,0),U=1e-6,L=g.Vector3.Zero(),k=g.Vector3.One();function D(e,t){var r=e.byteOffset,n=e.byteStride,o=e.type,a=e.normalized,i=e.getSize(),s=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:i,type:o,count:s*i,normalized:a,totalVertices:s,kind:e.getKind()}}function K(e){switch(e){case"MAT2":case"VEC4":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3}}function G(e){switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:case g.VertexBuffer.ColorKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return!0}return!1}function W(e){switch(e){case g.Material.TriangleFillMode:return 4;case g.Material.TriangleStripDrawMode:return 5;case g.Material.TriangleFanDrawMode:return 6;case g.Material.PointListDrawMode:case g.Material.PointFillMode:return 0;case g.Material.LineLoopDrawMode:return 2;case g.Material.LineListDrawMode:return 1;case g.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}function H(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 q(e){return e.x*=-1,e}function j(e){return e.x*=-1,e.y*=-1,e}function z(e){return e.multiplyInPlace(O)}function Q(e,t){return t instanceof g.TransformNode&&1==t.getChildren().length&&0==e.getChildren().length}function Y(e,t){if(!(e instanceof g.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(N,g.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof g.AbstractMesh&&e.geometry)}function X(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],a=o[0],i=o[1],s=t[a];(Array.isArray(i)&&Array.isArray(s)&&Z(i,s)||i===s)&&delete e[a]}return e}function Z(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var J=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)}]]),$=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=J.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 ee(e){return e%4==0?4:e%2==0?2:1}var te,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 r=new $(t),n=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return ee(t.byteLength)-ee(e.byteLength)}));n<o.length;n++){var a=o[n];a.byteOffset=r.byteOffset,e.push(a);for(var i=e.length-1,s=0,u=this.getPropertiesWithBufferView(a);s<u.length;s++)u[s].bufferView=i;r.writeTypedArray(this._bufferViewToData.get(a)),this._bufferViewToData.delete(a)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,o,a,i){this._verifyBufferView(e);var s={bufferView:void 0,componentType:r,count:n,type:t,min:null==a?void 0:a.min,max:null==a?void 0:a.max,normalized:i,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var o=n[r];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(te||(te={}));var ne=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof g.TransformNode||e instanceof g.Camera||e instanceof g.Light)},e._CreateNodeAnimation=function(t,r,n,o,a){if(this._IsTransformable(t)){var i=[],s=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,o),f=l.interpolationType,p=l.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,i,s,c,o):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(t,r,n,i,s,o):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(t,r,n,i,s,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,i,s,c,o),i.length&&s.length)return{inputs:i,outputs:s,samplerInterpolation:f,inputsMin:p?c.min:g.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:p?c.max:g.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:g.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(g.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,o,a,i,s,u,c,l,f){var p;if(e._IsTransformable(t)&&t.animations)for(var h=0,d=t.animations;h<d.length;h++){var m=d[h];if(!f||f(m)){var g=e._DeduceAnimationInfo(m);g&&(p={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?r:p,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,i,s,u,g.useQuaternion,c,l),p.samplers.length&&p.channels.length&&n.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,a,i,s,u,c,l,f){var p;if(t instanceof g.Mesh){var h=t.morphTargetManager;if(h)for(var d=0;d<h.numTargets;++d)for(var m=0,x=h.getTarget(d).animations;m<x.length;m++){var _=x[m];if(!f||f(_)){for(var y=new g.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),v=[],T=_.getKeys(),b=0;b<T.length;++b)for(var A=T[b],M=0;M<h.numTargets;++M)M==d?v.push(A):v.push({frame:A.frame,value:0});y.setKeys(v);var w=e._DeduceAnimationInfo(y);w&&(p={name:y.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:p,t,y,w.dataAccessorType,w.animationChannelTargetPath,o,i,s,u,w.useQuaternion,c,l,h.numTargets),p.samplers.length&&p.channels.length&&n.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,a,i,s,u,c){var l,f;if(t.animationGroups)for(var p=t.animationGroups,h=function(p){var h=new Map,m=new Map,x=new Set,_=p.to-p.from;f={name:p.name,channels:[],samplers:[]};for(var y=function(r){var _=p.targetedAnimations[r],y=_.target,v=_.animation;if(c&&!c(v))return"continue";var T=u.has(y);if(d._IsTransformable(y)||1===y.length&&d._IsTransformable(y[0])){if(A=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(y)?y:d._IsTransformable(y[0])?y[0]:null;b&&e._AddAnimation("".concat(v.name),f,b,v,A.dataAccessorType,A.animationChannelTargetPath,n,o,a,i,A.useQuaternion,s,T)}}else if(y instanceof g.MorphTarget||1===y.length&&y[0]instanceof g.MorphTarget){var A;if(A=e._DeduceAnimationInfo(_.animation)){var M=y instanceof g.MorphTarget?y:y[0];if(M){var w=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===M)return!0;return!1}));if(w){var E=t.meshes.find((function(e){return e.morphTargetManager===w}));E&&(h.has(E)||h.set(E,new Map),null===(l=h.get(E))||void 0===l||l.set(M,v),x.add(E),m.set(E,v))}}}}},v=0;v<p.targetedAnimations.length;++v)y(v);x.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=m.get(t).getKeys(),d=l.length,x=0;x<d;++x)for(var y=0;y<r.numTargets;++y){var v=r.getTarget(y),T=h.get(t);if(T){var b=T.get(v);b?(u||(u=new g.Animation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,g.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:p.from+_/d*x,value:v.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),f,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,o,a,i,A.useQuaternion,s,!1,null==r?void 0:r.numTargets)})),f.channels.length&&f.samplers.length&&r.push(f)},d=this,m=0,x=p;m<x.length;m++)h(x[m])},e._AddAnimation=function(t,r,n,o,a,i,s,u,c,l,f,p,h,d){var m,x,_,y,v,T,b=e._CreateNodeAnimation(n,o,i,f,p);if(b){if(d){for(var A=0,M=0,w=[];b.inputs.length>0;)M=b.inputs.shift(),A%d==0&&w.push(M),A++;b.inputs=w}var E=s.get(n),R=new Float32Array(b.inputs);m=u.createBufferView(R),x=u.createAccessor(m,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var C=new g.Quaternion,V=new g.Vector3,S=new g.Vector3,I=n instanceof g.Camera,B=K(a),F=new Float32Array(b.outputs.length*B);b.outputs.forEach((function(e,t){var r=e;if(h)switch(i){case"translation":g.Vector3.FromArrayToRef(e,0,S),q(S),S.toArray(r);break;case"rotation":4===e.length?g.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),g.Vector3.FromArrayToRef(e,0,V),g.Quaternion.FromEulerVectorToRef(V,C)),I?z(C):g.Quaternion.IsIdentity(C)||j(C),C.toArray(r)}else"rotation"===i&&(4===e.length?g.Quaternion.FromArrayToRef(e,0,C):(r=new Array(4),g.Vector3.FromArrayToRef(e,0,V),g.Quaternion.FromEulerVectorToRef(V,C)),I&&z(C),C.toArray(r));F.set(r,t*B)})),m=u.createBufferView(F),x=u.createAccessor(m,a,5126,b.outputs.length),l.push(x),y=l.length-1,v={interpolation:b.samplerInterpolation,input:_,output:y},r.samplers.push(v),T={sampler:r.samplers.length-1,target:{node:E,path:i}},r.channels.push(T)}},e._CreateBakedAnimation=function(t,r,n,o,a,i,s,u,c,l,f){var p,h,d=g.Quaternion.Identity(),m=null,x=null,_=null,y=null,v=null,T=null;l.min=g.Tools.FloatRound(o/i);for(var b=r.getKeys(),A=0,M=b.length;A<M;++A){if(T=null,_=b[A],A+1<M)if(y=b[A+1],_.value.equals&&_.value.equals(y.value)||_.value===y.value){if(0!==A)continue;T=_.frame}else T=y.frame;else{if(v=b[A-1],_.value.equals&&_.value.equals(v.value)||_.value===v.value)continue;T=a}if(T)for(var w=_.frame;w<=T;w+=s)if((h=g.Tools.FloatRound(w/i))!==m){m=h,x=h;var E={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(w,E),e._SetInterpolatedValue(t,p,h,r,n,d,u,c,f)}}x&&(l.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,a){var i=e._GetBasePositionRotationOrScale(r,o,a),s=n.targetProperty.split("."),u=s?s[1]:"",c=a?g.Quaternion.FromArray(i).normalize():g.Vector3.FromArray(i);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:g.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,a,i,s,u){var c;i.push(r),"weights"!==o?(n.dataType===g.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u)),"rotation"===o?(u?a=t:(c=t,g.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),s.push(a.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,o,a,i){for(var s=0,u=r.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,a,n,t,i)}},e._CreateCubicSplineAnimation=function(t,r,n,o,a,i){r.getKeys().forEach((function(s){o.push(s.frame/r.framePerSecond),e._AddSplineTangent(te.INTANGENT,a,n,"CUBICSPLINE",s,i),e._AddKeyframeValue(s,r,a,n,t,i),e._AddSplineTangent(te.OUTTANGENT,a,n,"CUBICSPLINE",s,i)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var o=e.rotationQuaternion;n=(null!=o?o:g.Quaternion.Identity()).asArray()}else{var a=e.rotation;n=(null!=a?a:g.Vector3.Zero()).asArray()}else if("translation"===t){var i=e.position;n=(null!=i?i:g.Vector3.Zero()).asArray()}else{var s=e.scaling;n=(null!=s?s:g.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,o,a){var i,s=t.dataType;if(s===g.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=g.Vector3.FromArray(u);u=g.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(s===g.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(i=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,a)){if("rotation"===n){var l=a?i:g.Quaternion.RotationYawPitchRoll(i.y,i.x,i.z).normalize();r.push(l.asArray())}r.push(i.asArray())}}else s===g.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):g.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,a=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var i=0,s=e.length;i<s;++i)if((o=e[i]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",a=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&1===o.interpolation&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,r,n,o,a){var i,s=e===te.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(s)if(a)i=s.asArray();else{var u=s;i=g.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else i=[0,0,0,0];else i="weights"===r?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(i)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}();function oe(e,t,r,n,o,a){var i={attributes:{},influence:e.influence,name:e.name},s=t.geometry;if(!s)return g.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),i;var u=a?-1:1,c=g.Vector3.Zero(),l=0;if(e.hasPositions){var f=e.getPositions(),p=s.getVerticesData(g.VertexBuffer.PositionKind);if(p){var h=new Float32Array(p.length),d=[1/0,1/0,1/0],m=[-1/0,-1/0,-1/0];l=p.length/3;for(var x=0;x<l;++x){var _=g.Vector3.FromArray(p,3*x);g.Vector3.FromArray(f,3*x).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),m[0]=Math.max(m[0],c.x),d[1]=Math.min(d[1],c.y),m[1]=Math.max(m[1],c.y),d[2]=Math.min(d[2],c.z),m[2]=Math.max(m[2],c.z),h[3*x]=c.x,h[3*x+1]=c.y,h[3*x+2]=c.z}var y=r.createBufferView(h,12),v=r.createAccessor(y,"VEC3",5126,f.length/3,0,{min:d,max:m});o.push(v),i.attributes.POSITION=o.length-1}else g.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var T=e.getNormals(),b=s.getVerticesData(g.VertexBuffer.NormalKind);if(b){var A=new Float32Array(b.length);for(l=b.length/3,x=0;x<l;++x){var M=g.Vector3.FromArray(b,3*x).normalize();g.Vector3.FromArray(T,3*x).normalize().subtractToRef(M,c),A[3*x]=c.x*u,A[3*x+1]=c.y,A[3*x+2]=c.z}y=r.createBufferView(A,12),v=r.createAccessor(y,"VEC3",5126,T.length/3,0),o.push(v),i.attributes.NORMAL=o.length-1}else g.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var w=e.getTangents(),E=s.getVerticesData(g.VertexBuffer.TangentKind);if(E){l=E.length/4;var R=new Float32Array(3*l);for(x=0;x<l;++x){var C=g.Vector3.FromArray(E,4*x);H(C);var V=g.Vector3.FromArray(w,3*x);H(V),V.subtractToRef(C,c),R[3*x]=c.x*u,R[3*x+1]=c.y,R[3*x+2]=c.z}y=r.createBufferView(R,12),v=r.createAccessor(y,"VEC3",5126,l,0),o.push(v),i.attributes.TANGENT=o.length-1}else g.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),I=s.getVerticesData(g.VertexBuffer.ColorKind),B=s.getVertexBuffer(g.VertexBuffer.ColorKind);if(I&&B){var F=B.getSize();l=I.length/F;var P=new Float32Array(l*F);for(x=0;x<l;++x)if(3===F){var N=g.Vector3.FromArray(I,x*F);g.Vector3.FromArray(S,x*F).subtractToRef(N,c),P[3*x]=c.x,P[3*x+1]=c.y,P[3*x+2]=c.z}else if(4===F){var O=new g.Vector4;N=g.Vector4.FromArray(I,x*F),g.Vector4.FromArray(S,x*F).subtractToRef(N,O),P[4*x]=O.x,P[4*x+1]=O.y,P[4*x+2]=O.z,P[4*x+3]=O.w}else g.Tools.Warn("Unsupported number of components for color attribute: ".concat(F));y=r.createBufferView(P,4*F),v=r.createAccessor(y,3===F?"VEC3":"VEC4",5126,l,0),o.push(v),i.attributes.COLOR_0=o.length-1}else g.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return i}var 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,r,n,o){var a,i,s,u;return null===(u=null===(s=null===(i=null===(a=this._indicesAccessorMap.get(e))||void 0===a?void 0:a.get(t))||void 0===i?void 0:i.get(r))||void 0===s?void 0:s.get(n))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,r,n,o,a){var i=this._indicesAccessorMap.get(e);i||(i=new Map,this._indicesAccessorMap.set(e,i));var s=i.get(t);s||(s=new Map,i.set(t,s));var u=s.get(r);u||(u=new Map,s.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(o,a)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,o;return null===(o=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===o?void 0:o.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a)),a.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),ie=function(){function e(e,t){if(void 0===e&&(e=g.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(g.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new P(this),this._extensions={},this._bufferManager=new 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,r,n){var o=this;if(r>=t.length)return Promise.resolve(e);var a=n(t[r],e);return a?a.then((function(e){return e?o._applyExtension(e,t,r+1,n):null})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o];n.push(this._extensions[i])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){var a=this;return this._applyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,r,n,o,a._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var o=[],a=0,i=e._ExtensionNames;a<i.length;a++){var s=i[a],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o],s=this._extensions[i];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.postExportMeshPrimitive&&a.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return T(this,void 0,void 0,(function(){var t,r,n,o;return b(this,(function(a){switch(a.label){case 0:t=0,r=e._ExtensionNames,a.label=1;case 1:return t<r.length?(n=r[t],(o=this._extensions[n]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:a.sent(),a.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.enabled&&t(a)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,o;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&g.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._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 T(this,void 0,void 0,(function(){var t,r,n,o,a,i,s;return b(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",(i=new y).files[o]=r,i.files[a]=n,this._imageData)for(s in this._imageData)i.files[s]=new Blob([this._imageData[s].data],{type:this._imageData[s].mimeType});return[2,i]}}))}))},e.prototype._generateBinaryAsync=function(){return T(this,void 0,void 0,(function(){return b(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 T(this,void 0,void 0,(function(){var t,r,n,o,a,i,s,u,c,l,f,p,h,d,m,g,x,_,v,T,A,M,w,E;return b(this,(function(b){switch(b.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=b.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",o=r.length,"undefined"!=typeof TextEncoder&&(i=new TextEncoder,a=i.encode(r),o=a.length),s=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+s+t.byteLength+u,l=new ArrayBuffer(12),(f=new DataView(l)).setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,c,!0),p=new ArrayBuffer(8+o+s),(h=new DataView(p)).setUint32(0,o+s,!0),h.setUint32(4,1313821514,!0),d=new Uint8Array(p,8),a)d.set(a);else for(m="_".charCodeAt(0),M=0;M<o;++M)(g=r.charCodeAt(M))!=r.codePointAt(M)?d[M]=m:d[M]=g;for(x=new Uint8Array(p,8+o),M=0;M<s;++M)x[M]=32;for(_=new ArrayBuffer(8),(v=new DataView(_)).setUint32(0,t.byteLength+u,!0),v.setUint32(4,5130562,!0),T=new ArrayBuffer(u),A=new Uint8Array(T),M=0;M<u;++M)A[M]=0;return w=new Blob([l,p,_,t,T],{type:"application/octet-stream"}),(E=new y).files[n]=w,[2,E]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){if(t.getPivotPoint().equalsToFloats(0,0,0)||g.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsToFloats(0,0,0)){var n=g.TmpVectors.Vector3[0].copyFrom(t.position);r&&q(n),e.translation=n.asArray()}t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var o=g.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&o.multiplyInPlace(t.rotationQuaternion),g.Quaternion.IsIdentity(o)||(r&&j(o),e.rotation=o.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r,n){var o=g.TmpVectors.Vector3[0],a=g.TmpVectors.Quaternion[0];if(null!==n){var i=g.Matrix.Invert(n.getWorldMatrix());t.getWorldMatrix().multiply(i).decompose(void 0,a,o)}else t.getWorldMatrix().decompose(void 0,a,o);o.equalsToFloats(0,0,0)||(e.translation=o.asArray()),g.Quaternion.IsIdentity(a)||(e.rotation=a.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===g.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===g.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(){for(var e,t=function(t){if(t.bones.length<=0)return"continue";var n=r._skinMap.get(t);if(null==n)return"continue";for(var o={},a=[],i=-1,s=0;s<t.bones.length;++s){var u=t.bones[s];-1!==(c=null!==(e=u.getIndex())&&void 0!==e?e:s)&&(o[c]=u,c>i&&(i=c))}for(var c=0;c<=i;++c){u=o[c],a.push(u.getAbsoluteInverseBindMatrix());var l=u.getTransformNode();if(null!==l){var f=r._nodeMap.get(l);l&&null!=f?n.joints.push(f):g.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}else g.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}var p=r._nodesSkinMap.get(n);if(n.joints.length>0&&void 0!==p){var h=64*a.length,d=new Float32Array(h/4);a.forEach((function(e,t){d.set(e.m,16*t)}));var m=r._bufferManager.createBufferView(d);r._accessors.push(r._bufferManager.createAccessor(m,"MAT4",5126,a.length)),n.inverseBindMatrices=r._accessors.length-1,r._skins.push(n);for(var x=0,_=p;x<_.length;x++)_[x].skin=r._skins.length-1}},r=this,n=0,o=this._babylonScene.skeletons;n<o.length;n++)t(o[n])},e.prototype._exportSceneAsync=function(){return T(this,void 0,void 0,(function(){var e,t,r,n,o,a,i,s,u,c,l,f,p,h,d,m,g,x,_,y,v,T,A;return b(this,(function(b){switch(b.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,i=this._babylonScene.rootNodes;a<i.length;a++)s=i[a],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&Y(s,this._babylonScene.useRightHandedSystem)?o.push.apply(o,s.getChildren()):this._babylonScene.useRightHandedSystem?r.push(s):n.push(s);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new ae(!0,!1),l=(c=(v=e.nodes).push).apply,f=[v],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,f.concat([b.sent()])),p=new ae(!1,!1),d=(h=(T=e.nodes).push).apply,m=[T],[4,this._exportNodesAsync(r,p)];case 2:return d.apply(h,m.concat([b.sent()])),g=new ae(!1,!0),_=(x=(A=e.nodes).push).apply,y=[A],[4,this._exportNodesAsync(o,g)];case 3:return _.apply(x,y.concat([b.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(),this._babylonScene.animationGroups.length&&ne._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 T(this,void 0,void 0,(function(){var r,n,o,a;return b(this,(function(i){switch(i.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,o=e,i.label=1;case 1:return n<o.length?(a=o[n],[4,this._exportNodeAsync(a,r,t)]):[3,4];case 2:i.sent(),i.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 g.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var i in a)if(G(i)){var s=a[i];o.setHasVertexColorAlpha(s,e.hasVertexAlpha);var u=s._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(s)&&c.push(s);var l=r.get(s)||[];r.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=n.get(h)||[],n.set(h,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,m=e.getChildren();d<m.length;d++){var x=m[d];this._collectBuffers(x,t,r,n,o)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,o=new Map,a=0,i=e;a<i.length;a++){var s=i[a];this._collectBuffers(s,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 i=a[0].byteStride;if(a.some((function(e){return e.byteStride!==i})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var s=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=n.get(e),r=D(e,t),o=r.byteOffset,a=r.byteStride,i=r.componentCount,u=r.type,c=r.count,f=r.normalized;switch(r.kind){case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,o,a,i,u,c,f,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var r=1/t;e[0]*=r,e[1]*=r,e[2]*=r}}));break;case g.VertexBuffer.ColorKind:var p=t.filter((function(e){return e.material instanceof g.StandardMaterial||null==e.material})).length;if(0==p)break;if(p!=t.length){g.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==g.VertexBuffer.UNSIGNED_BYTE&&g.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var h=new g.Color3,d=new g.Color4,m=l._babylonScene.getEngine().useExactSrgbConversions;(0,g.EnumerateFloatValues)(s,o,a,i,u,c,f,(function(e){3===e.length?(h.fromArray(e,0),h.toLinearSpaceToRef(h,m),h.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,m),d.toArray(e,0))}))}},c=0,f=a;c<f.length;c++)u(B=f[c]);if(t.convertToRightHanded){for(var p=0,h=a;p<h.length;p++){var d=D(B=h[p],n.get(B)),m=d.byteOffset,x=d.byteStride,_=d.componentCount,y=d.type,v=d.count,T=d.normalized;switch(R=d.kind){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,m,x,_,y,v,T,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,i);t.setVertexBufferView(e,b);for(var A=new Map,M=0,w=a;M<w.length;M++){var E=D(B=w[M],n.get(B)),R=E.kind,C=E.totalVertices;switch(R){case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:if(B.type==g.VertexBuffer.FLOAT){var V=B.getFloatData(C);null!==V&&A.set(B,V)}}}0!==A.size&&g.Logger.Warn("Joints conversion needed: some joints are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var S=0,I=Array.from(A.keys());S<I.length;S++){var B=I[S],F=A.get(B);if(F){for(var P=F.some((function(e){return e>=256})),N=new(P?Uint16Array:Uint8Array)(F.length),O=0;O<F.length;O++)N[O]=F[O];var U=l._bufferManager.createBufferView(N,4*(P?2:1));t.setRemappedBufferView(e,B,U)}}},l=this,f=0,p=u;f<p.length;f++)c(p[f]);for(var h=0,d=Array.from(o.keys());h<d.length;h++){var m=d[h],x=o.get(m);if(x)for(var _=oe(m,x[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),y=0,v=x;y<v.length;y++){var T=v[y];t.bindMorphDataToMesh(T,_)}}},e.prototype._exportNodeAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l,f=this;return b(this,(function(p){switch(p.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=p.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:[]},i=[],this._babylonScene.animationGroups.length||(ne._CreateMorphTargetAnimationFromMorphTargetAnimations(e,a,i,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&ne._CreateNodeAnimationFromNodeAnimations(e,a,i,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),i.forEach((function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)}))),s=o?[]:t,u=0,c=e.getChildren(),p.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,r)]):[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 T(this,void 0,void 0,(function(){var r,n,o,a,i,s,u,c,l,f,p,h;return b(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 g.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof g.AbstractMesh?(o=e instanceof g.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!==(i=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(i)&&this._nodesSkinMap.set(i,[]),null===(f=this._nodesSkinMap.get(i))||void 0===f||f.push(r)),d.label=3;case 3:if(e instanceof g.Camera&&(s=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(s)&&this._nodesCameraMap.set(s,[]),u=e.parent,this._setCameraTransformation(r,e,t.convertToRightHanded,u),u&&Q(e,u)&&(c=this._nodeMap.get(u)))return l=this._nodes[c],null===(p=this._nodesCameraMap.get(s))||void 0===p||p.push(l),[2,null];t.convertToRightHanded&&(m=r,x=g.Vector3.FromArrayToRef(m.translation||[0,0,0],0,g.TmpVectors.Vector3[0]),_=g.Quaternion.FromArrayToRef(m.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[0]),x=q(x),_=j(_),x.equalsWithEpsilon(L,U)?delete m.translation:m.translation=x.asArray(),g.Quaternion.IsIdentity(_)?delete m.rotation:m.rotation=_.asArray(),function(e){var t=g.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[1]);O.multiplyToRef(t,t),e.rotation=t.asArray()}(r)),null===(h=this._nodesCameraMap.get(s))||void 0===h||h.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,r]:(g.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}var m,x,_}))}))},e.prototype._exportIndices=function(e,t,r,n,o,a,i,s,u){var c=e;u.mode=W(a);var l=i!==g.Material.CounterClockWiseSideOrientation,f=!s.wasAddedByNoopNode&&l,p=function(e){switch(e){case g.Material.TriangleFillMode:case g.Material.TriangleStripDrawMode:case g.Material.TriangleFanDrawMode:return!0}return!1}(a)&&f;if(p){if(a===g.Material.TriangleStripDrawMode||a===g.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");u.mode=W(a);var h=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var d=0;d+2<n;d+=3)h[d]=e[r+d]+o,h[d+1]=e[r+d+2]+o,h[d+2]=e[r+d+1]+o;else for(d=0;d+2<n;d+=3)h[d]=d,h[d+1]=d+2,h[d+2]=d+1;c=h}else if(e&&0!==o){for(h=t?new Uint32Array(n):new Uint16Array(n),d=0;d<n;d++)h[d]=e[r+d]+o;c=h}if(c){var m=s.getIndicesAccessor(e,r,n,o,p);if(void 0===m){var x=function(e,t,r,n){if(e instanceof Uint16Array||e instanceof Uint32Array)return e;if(e instanceof Int32Array)return new Uint32Array(e.buffer,e.byteOffset,e.length);var o=e.slice(0,0+r);return n?new Uint32Array(o):new Uint16Array(o)}(c,0,n,t),_=this._bufferManager.createBufferView(x),y=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(_,"SCALAR",y,n,0)),m=this._accessors.length-1,s.setIndicesAccessor(e,r,n,o,p,m)}u.indices=m}},e.prototype._exportVertexBuffer=function(e,t,r,n,o,a){var i=e.getKind();if(G(i)&&(!i.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var s=o.getVertexAccessor(e,r,n);if(void 0===s){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=i===g.VertexBuffer.PositionKind?function(e,t,r,n){var o=t.byteOffset,a=t.byteStride,i=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,g.EnumerateFloatValues)(e,o+r*a,a,u,i,n*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,r,n):void 0,l=(i===g.VertexBuffer.MatricesIndicesKind||i===g.VertexBuffer.MatricesIndicesExtraKind)&&e.type===g.VertexBuffer.FLOAT,f=l?g.VertexBuffer.UNSIGNED_BYTE:e.type,p=l?void 0:e.normalized,h=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(h,function(e,t){if(e==g.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:return"VEC3";case g.VertexBuffer.TangentKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(i,o.hasVertexColorAlpha(e)),f,n,d,c,p)),s=this._accessors.length-1,o.setVertexAccessor(e,r,n,s)}a.attributes[function(e){switch(e){case g.VertexBuffer.PositionKind:return"POSITION";case g.VertexBuffer.NormalKind:return"NORMAL";case g.VertexBuffer.TangentKind:return"TANGENT";case g.VertexBuffer.ColorKind:return"COLOR_0";case g.VertexBuffer.UVKind:return"TEXCOORD_0";case g.VertexBuffer.UV2Kind:return"TEXCOORD_1";case g.VertexBuffer.UV3Kind:return"TEXCOORD_2";case g.VertexBuffer.UV4Kind:return"TEXCOORD_3";case g.VertexBuffer.UV5Kind:return"TEXCOORD_4";case g.VertexBuffer.UV6Kind:return"TEXCOORD_5";case g.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case g.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case g.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case g.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(i)]=s}},e.prototype._exportMaterialAsync=function(e,t,r,n){return T(this,void 0,void 0,(function(){var o,a;return b(this,(function(i){switch(i.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,6]:(a=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof g.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof g.PBRMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,"image/png",a)]:[3,2]);case 1:return o=i.sent(),[3,5];case 2:return e instanceof g.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,"image/png",a)]:[3,4];case 3:return o=i.sent(),[3,5];case 4:return g.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 5:this._materialMap.set(e,o),i.label=6;case 6:return n.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return T(this,void 0,void 0,(function(){var r,n,o,a,i,s,u,c,l,f,p,h,d,m,x,_,y,v,T,M,w,E,R,C,V,S,I,B,F,P,N,O,U,L;return b(this,(function(b){switch(b.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===(F=e.geometry)||void 0===F?void 0:F.getVertexBuffers(),i=t.getMorphTargetsFromMesh(e),s=e instanceof g.LinesMesh,u=e instanceof g.GreasedLineBaseMesh,c=e.subMeshes,!(a&&c&&c.length>0))return[3,7];l=0,f=c,b.label=1;case 1:return l<f.length?(p=f[l],h={attributes:{}},d=p.getMaterial()||this._babylonScene.defaultMaterial,u?(y={name:d.name},v=e,m=g.Color3.White(),x=null!==(N=null===(P=v.material)||void 0===P?void 0:P.alpha)&&void 0!==N?N:1,(!(_=null!==(U=null===(O=v.greasedLineMaterial)||void 0===O?void 0:O.color)&&void 0!==U?U:m).equals(m)||x<1)&&(y.pbrMetallicRoughness={baseColorFactor:A(A([],_.asArray(),!0),[x],!1)}),this._materials.push(y),h.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return s?(y={name:d.name},(!(v=e).color.equals(g.Color3.White())||v.alpha<1)&&(y.pbrMetallicRoughness={baseColorFactor:A(A([],v.color.asArray(),!0),[v.alpha],!1)}),this._materials.push(y),h.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,a,p,h)];case 4:b.sent(),b.label=5;case 5:for(T=s||u?g.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,M=d._getEffectiveOrientation(e),this._exportIndices(o,o?(0,g.AreIndices32Bits)(o,p.indexCount,p.indexStart,p.verticesStart):p.verticesCount>65535,o?p.indexStart:p.verticesStart,o?p.indexCount:p.verticesCount,-p.verticesStart,T,M,t,h),w=0,E=Object.values(a);w<E.length;w++)R=E[w],this._exportVertexBuffer(R,d,p.verticesStart,p.verticesCount,t,h);if(i)for(h.targets=[],C=0,V=i;C<V.length;C++)B=V[C],h.targets.push(B.attributes);n.primitives.push(h),this._extensionsPostExportMeshPrimitive(h),b.label=6;case 6:return l++,[3,1];case 7:if(i)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],S=0,I=i;S<I.length;S++)B=I[S],n.weights.push(B.influence),n.extras.targetNames.push(B.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),se=function(){function e(){}return e.GLTFAsync=function(e,t,r){return T(this,void 0,void 0,(function(){var n,o;return b(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 T(this,void 0,void 0,(function(){var n,o;return b(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}(),ue="EXT_mesh_gpu_instancing",ce=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.postExportNodeAsync=function(e,t,r,n,o,a){var i=this;return new Promise((function(e){if(t&&r instanceof g.Mesh&&r.hasThinInstances&&i._exporter){i._wasUsed=!0;for(var n=g.Vector3.Zero(),s=g.Quaternion.Identity(),u=g.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),l=g.TmpVectors.Vector3[2],f=g.TmpVectors.Quaternion[1],p=g.TmpVectors.Vector3[3],h=!1,d=!1,m=!1,x=new Float32Array(3*r.thinInstanceCount),_=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),v=0,T=0,b=c;T<b.length;T++)b[T].decompose(p,f,l),o&&(q(l),j(f)),x.set(l.asArray(),3*v),_.set(f.normalize().asArray(),4*v),y.set(p.asArray(),3*v),h=h||!l.equalsWithEpsilon(n),d=d||!f.equalsWithEpsilon(s),m=m||!p.equalsWithEpsilon(u),v++;var A={attributes:{}};h&&(A.attributes.TRANSLATION=i._buildAccessor(x,"VEC3",r.thinInstanceCount,a)),d&&(A.attributes.ROTATION=i._buildAccessor(_,"VEC4",r.thinInstanceCount,a)),m&&(A.attributes.SCALE=i._buildAccessor(y,"VEC3",r.thinInstanceCount,a)),t.extensions=t.extensions||{},t.extensions[ue]=A}e(t)}))},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(ue,(function(e){return new ce(e)}));var le="KHR_draco_mesh_compression",fe=function(){function e(e){this.name=le,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&g.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,r){var n=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],a=[],i=null;if(void 0!==e.indices){var s=r[e.indices],u=t.getBufferView(s);i=t.getData(u).slice(),o.push(u),a.push(s)}for(var c,l=[],f=0,p=Object.entries(e.attributes);f<p.length;f++){var h=p[f],d=h[0],m=(s=r[h[1]],u=t.getBufferView(s),K(s.type)),x=(0,g.GetTypedArrayData)(t.getData(u),m,s.componentType,s.byteOffset||0,u.byteStride||(0,g.GetTypeByteLength)(s.componentType)*m,s.normalized||!1,s.count,!0);l.push({kind:d,dracoName:(c=d,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:K(s.type),data:x}),o.push(u),a.push(s)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},y=g.DracoEncoder.Default._encodeAsync(l,i,_).then((function(r){if(r){var i={bufferView:-1,attributes:r.attributeIDs},s=t.createBufferView(r.data);t.setBufferView(i,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var f=0,p=a;f<p.length;f++){var h=p[f];n._accessorsUsed.add(h)}e.extensions||(e.extensions={}),e.extensions[le]=i}else g.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){g.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(y),this._wasUsed=!0}else g.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return T(this,void 0,void 0,(function(){var t=this;return b(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(le,(function(e){return new fe(e)}));var pe="KHR_lights_punctual",he={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},de={innerConeAngle:0,outerConeAngle:Math.PI/4},me=g.Vector3.Backward(),ge=function(){function e(e){this.name=pe,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[pe]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,o){var a=this;return new Promise((function(i){if(r instanceof g.ShadowLight){var s=r.getTypeID()==g.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==g.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==g.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!s)return g.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(pe)),void i(t);if(r.falloffType!==g.Light.FALLOFF_GLTF&&g.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(pe," specification!")),!r.position.equalsToFloats(0,0,0)){var u=g.TmpVectors.Vector3[0].copyFrom(r.position);o&&q(u),t.translation=u.asArray()}if("point"!==s){var c=r.direction.normalizeToRef(g.TmpVectors.Vector3[0]);o&&q(c);var l=Math.acos(g.Vector3.Dot(me,c)),f=g.Vector3.Cross(me,c),p=g.Quaternion.RotationAxisToRef(f,l,g.TmpVectors.Quaternion[0]);g.Quaternion.IsIdentity(p)||(t.rotation=p.asArray())}var h={type:s,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(X(h,he),"spot"===s){var d=r;h.spot={innerConeAngle:d.innerAngle/2,outerConeAngle:d.angle/2},X(h.spot,de)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(h);var m={light:a._lights.lights.length-1},x=r.parent;if(x&&Q(r,x)){var _=n.get(x);if(_){var y=a._exporter._nodes[_];return function(e,t){var r=g.Vector3.FromArrayToRef(t.translation||[0,0,0],0,g.TmpVectors.Vector3[0]),n=g.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[0]),o=g.Vector3.FromArrayToRef(t.scale||[1,1,1],0,g.TmpVectors.Vector3[1]),a=g.Matrix.ComposeToRef(o,n,r,g.TmpVectors.Matrix[0]),i=g.Vector3.FromArrayToRef(e.translation||[0,0,0],0,g.TmpVectors.Vector3[2]),s=g.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[1]),u=g.Vector3.FromArrayToRef(e.scale||[1,1,1],0,g.TmpVectors.Vector3[1]),c=g.Matrix.ComposeToRef(u,s,i,g.TmpVectors.Matrix[1]);a.multiplyToRef(c,c),c.decompose(o,n,r),r.equalsWithEpsilon(L,U)?delete t.translation:t.translation=r.asArray(),g.Quaternion.IsIdentity(n)?delete t.rotation:t.rotation=n.asArray(),o.equalsWithEpsilon(k,U)?delete t.scale:t.scale=o.asArray()}(t,y),y.extensions||(y.extensions={}),y.extensions[pe]=m,void i(null)}}t.extensions||(t.extensions={}),t.extensions[pe]=m,i(t)}else i(t)}))},e}();ie.RegisterExtension(pe,(function(e){return new ge(e)}));var xe="KHR_materials_anisotropy",_e=function(){function e(e){this.name=xe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRBaseMaterial&&r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&n.push(r.anisotropy.texture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof g.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),a={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=o?o:void 0};null!==a.anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[xe]=a}e(t)}))},e}();ie.RegisterExtension(xe,(function(e){return new _e(e)}));var ye="KHR_materials_clearcoat",ve=function(){function e(e){this.name=ye,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRBaseMaterial&&r.clearCoat.isEnabled?(r.clearCoat.texture&&n.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&n.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&n.push(r.clearCoat.bumpTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof g.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&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&g.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var i=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),s={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=i?i:void 0};null===s.clearcoatTexture&&null===s.clearcoatRoughnessTexture&&null===s.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[ye]=s}e(t)}))},e}();ie.RegisterExtension(ye,(function(e){return new ve(e)}));var Te="KHR_materials_diffuse_transmission";function be(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(g.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var Ae=function(){function e(e){this.name=Te,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];if(r instanceof g.PBRMaterial&&this._isExtensionEnabled(r)){var o=be(e,r);return o&&n.push(o),r.subSurface.translucencyColorTexture&&n.push(r.subSurface.translucencyColorTexture),n}return n},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,i;if(r instanceof g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var s=r.subSurface,u=be(e,r),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(a=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0,f=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),p=null!==(i=n._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==i?i:void 0,h={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:p};(l||p)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Te]=h}o(t)}))},e}();ie.RegisterExtension(Te,(function(e){return new Ae(e)}));var Me="KHR_materials_dispersion",we=function(){function e(){this.name=Me,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 g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Me]=o}e(t)}))},e}();ie.RegisterExtension(Me,(function(){return new we}));var Ee="KHR_materials_emissive_strength",Re=function(){function e(){this.name=Ee,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){var n=this;return new Promise((function(e){if(!(r instanceof g.PBRMaterial))return e(t);var o=r.emissiveColor.asArray(),a=Math.max.apply(Math,o);if(a>1){n._wasUsed=!0,t.extensions||(t.extensions={});var i={emissiveStrength:a},s=r.emissiveColor.scale(1/i.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[Ee]=i}return e(t)}))},e}();ie.RegisterExtension(Ee,(function(e){return new Re}));var Ce="KHR_materials_ior",Ve=function(){function e(){this.name=Ce,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 g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[Ce]=o}e(t)}))},e}();ie.RegisterExtension(Ce,(function(e){return new Ve}));var Se="KHR_materials_iridescence",Ie=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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRBaseMaterial&&r.iridescence.isEnabled?(r.iridescence.texture&&n.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&n.push(r.iridescence.thicknessTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof g.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),i={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};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Se]=i}e(t)}))},e}();ie.RegisterExtension(Se,(function(e){return new Ie(e)}));var Be="KHR_materials_sheen",Fe=function(){function e(e){this.name=Be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof g.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,i,s;if(r instanceof g.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._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||n._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(a=n._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(i=n._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==i?i:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=n._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==s?s:void 0),t.extensions[Be]=u}e(t)}))},e}();ie.RegisterExtension(Be,(function(e){return new Fe(e)}));var Pe="KHR_materials_specular",Ne=function(){function e(e){this.name=Pe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&n.push(r.metallicReflectanceTexture),r.reflectanceTexture&&n.push(r.reflectanceTexture),n):n},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;if(r instanceof g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var i=null!==(o=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,s=null!==(a=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,u={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:i,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:s};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[Pe]=u}e(t)}))},e}();ie.RegisterExtension(Pe,(function(e){return new Ne(e)}));var Oe="KHR_materials_transmission",Ue=function(){function e(e){this.name=Oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},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 T(this,void 0,void 0,(function(){var n,o,a,i;return b(this,(function(s){switch(s.label){case 0:return r instanceof g.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,"image/png")]:[3,2]:[3,3]):[3,4];case 1:return(i=s.sent())&&(a.transmissionTexture=i),[3,3];case 2:g.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported")),s.label=3;case 3:t.extensions||(t.extensions={}),t.extensions[Oe]=a,s.label=4;case 4:return[2,t]}}))}))},e}();ie.RegisterExtension(Oe,(function(e){return new Ue(e)}));var Le="KHR_materials_unlit",ke=function(){function e(){this.name=Le,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 g.PBRMaterial?o=r.unlit:r instanceof g.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[Le]={}),e(t)}))},e}();ie.RegisterExtension(Le,(function(){return new ke}));var De="KHR_materials_volume",Ke=function(){function e(e){this.name=De,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof g.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=g.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o;if(r instanceof g.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,i={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[De]=i}e(t)}))},e}();ie.RegisterExtension(De,(function(e){return new Ke(e)}));var Ge="KHR_texture_transform",We=function(){function e(){this.name=Ge,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()||g.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(g.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 g.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Ge,"."));g.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Ge,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,o=e.vRotationCenter,a=e.uScale,i=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=n*a,f=o*i;return[t+(l*(1-u)+f*c),r+(f*(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[Ge]=n)}},e}();ie.RegisterExtension(Ge,(function(){return new We}));var He=function(){function e(){}return e.CreateSTL=function(e,t,r,n,o,a,i,s){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===i&&(i=!1),void 0===s&&(s=!1);var u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],o=[new g.Vector3(t[n[0]],t[n[0]+2],t[n[0]+1]),new g.Vector3(t[n[1]],t[n[1]+2],t[n[1]+1]),new g.Vector3(t[n[2]],t[n[2]+2],t[n[2]+1])],a=o[0].subtract(o[1]),i=o[2].subtract(o[1]);return{v:o,n:g.Vector3.Cross(i,a).normalize()}},c=function(e,t,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},f=function(e){if(i){var t=e;e instanceof g.InstancedMesh&&(t=e.sourceMesh);var r=t.getVerticesData(g.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var n=g.Vector3.Zero(),o=void 0;for(o=0;o<r.length;o+=3)g.Vector3.TransformCoordinatesFromFloatsToRef(r[o],r[o+1],r[o+2],e.computeWorldMatrix(!0),n).toArray(r,o);return r}return e.getVerticesData(g.VertexBuffer.PositionKind)||[]};i&&(a=!0);var p="",h=0,d=0;if(n){for(var m=0;m<e.length;m++)h+=(v=(_=e[m]).getIndices())?v.length/3:0;var x=new ArrayBuffer(84+50*h);d+=80,(p=new DataView(x)).setUint32(d,h,o),d+=4}else s||(p="solid stlmesh\r\n");for(m=0;m<e.length;m++){var _=e[m];!n&&s&&(p+="solid "+_.name+"\r\n"),!a&&_ instanceof g.Mesh&&_.bakeCurrentTransformIntoVertices();for(var y=f(_),v=_.getIndices()||[],T=0;T<v.length;T+=3){var b=u(v,y,T);n?(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")}!n&&s&&(p+="endsolid "+name+"\r\n")}if(n||s||(p+="endsolid stlmesh"),t){var A=document.createElement("a"),M=new Blob([p],{type:"application/octet-stream"});A.href=window.URL.createObjectURL(M),A.download=r+".stl",A.click()}return p},e}();function qe(e,t,r){void 0===r&&(r=3);for(var n=[],o=0;o<e.length/r;o++){var a=e[o*r],i=e[o*r+1],s=e[o*r+2];n.push("(".concat(a.toPrecision(t.precision),", ").concat(i.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),")"))}return n.join(", ")}function je(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 ze(e,t){var r=function(e,t){var r=e.getVerticesData(g.VertexBuffer.PositionKind),n=e.getVerticesData(g.VertexBuffer.PositionKind);if(r&&n)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\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=e.getIndices(),r=[];if(null!==t)for(var n=0;n<t.length;n++)r.push(t[n]);else{var o=e.getTotalVertices();for(n=0;n<o;n++)r.push(n)}return r.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(qe(n,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(qe(r,t),"]\n ").concat(function(e,t){for(var r="",n=0;n<4;n++){var o=n>0?n:"",a=e.getVerticesData(g.VertexBuffer.UVKind+(o||""));a&&(r+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(je(a,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var i=e.getVerticesData(g.VertexBuffer.ColorKind);return i&&(r+="\n\tcolor3f[] primvars:displayColor = [".concat(qe(i,t,i.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),r}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t);return'\n def "Geometry"\n {\n '.concat(r,"\n }\n ")}function Qe(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 Ye(e){var t=e.m;return"( ".concat(Xe(t,0),", ").concat(Xe(t,4),", ").concat(Xe(t,8),", ").concat(Xe(t,12)," )")}function Xe(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function Ze(e){var t="Object_"+e.uniqueId,r=e.getWorldMatrix().clone();r.determinant()<0&&r.multiplyToRef(g.Matrix.Scaling(-1,1,1),r);var n=Ye(r);return'def Xform "'.concat(t,'" (\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 = </Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Je(e){switch(e){case g.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case g.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case g.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function $e(e){return"(".concat(e.x,", ").concat(e.y,")")}function et(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function tt(e,t,r,n,o,a){var i=e.getInternalTexture().uniqueId+"_"+e.invertY;o[i]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new g.Vector2(e.uScale,e.vScale),c=new g.Vector2(e.uOffset,e.vOffset),l=e.wAng,f=Math.sin(l),p=Math.cos(l);return c.y=1-c.y-u.y,c.x+=f*u.x,c.y+=(1-p)*u.y,'\n def Shader "PrimvarReader_'.concat(r,'"\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(r,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </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($e(u),"\n float2 inputs:translation = ").concat($e(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(i,".png@\n float2 inputs:st.connect = </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?"raw":"sRGB",'"\n token inputs:wrapS = "').concat(Je(e.wrapU),'"\n token inputs:wrapT = "').concat(Je(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(t.needAlphaBlending()?"float outputs:a":"","\n }")}function rt(e,t,r){var n="\t\t\t",o=[],a=[],i=function(e){switch(e.getClassName()){case"StandardMaterial":return{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughnessMap:null,normalMap:null,metalnessMap:null,roughness:1,metalness:0,aoMap:null,aoMapIntensity:0,alphaMap:e.opacityTexture,ior:1};case"PBRMaterial":return{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:e.roughness||1,metalnessMap:e.metallicTexture,metalnessChannel:e.useMetallnessFromMetallicTextureBlue?"b":"r",metalness:e.metallic||0,aoMap:e.ambientTexture,aoMapChannel:e.useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e.ambientTextureStrength,alphaMap:e.opacityTexture,ior:e.indexOfRefraction};case"PBRMetallicRoughnessMaterial":return{diffuseMap:e.baseTexture,diffuse:e.baseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,normalMap:e.normalTexture,roughnessMap:e.metallicTexture,roughnessChannel:e.useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:e.roughness||1,metalnessMap:e.metallicTexture,metalnessChannel:e.useMetallnessFromMetallicTextureBlue?"b":"r",metalness:e.metallic||0,aoMap:e.ambientTexture,aoMapChannel:e.useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e.ambientTextureStrength,alphaMap:e.opacityTexture,ior:e.indexOfRefraction};default:return{diffuseMap:null,diffuse:null,emissiveMap:null,emissemissiveiveColor:null,normalMap:null,roughnessMap:null,metalnessMap:null,alphaCutOff:0,roughness:0,metalness:0,aoMap:null,aoMapIntensity:0,alphaMap:null,ior:1}}}(e),s=i.diffuseMap,u=i.diffuse,c=i.alphaCutOff,l=i.emissiveMap,f=i.emissive,p=i.normalMap,h=i.roughnessMap,d=i.roughnessChannel,m=i.roughness,x=i.metalnessMap,_=i.metalnessChannel,y=i.metalness,v=i.aoMap,T=i.aoMapChannel,b=i.aoMapIntensity,A=i.alphaMap,M=i.ior;return null!==s?(o.push("".concat(n,"color3f inputs:diffuseColor.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(n,"float inputs:opacity.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(n,"float inputs:opacity.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(n,"float inputs:opacityThreshold = ").concat(c))),a.push(tt(s,e,"diffuse",u,t,r))):o.push("".concat(n,"color3f inputs:diffuseColor = ").concat(et(u||g.Color3.White()))),null!==l?(o.push("".concat(n,"color3f inputs:emissiveColor.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),a.push(tt(l,e,"emissive",f,t,r))):f&&f.toLuminance()>0&&o.push("".concat(n,"color3f inputs:emissiveColor = ").concat(et(f))),null!==p&&(o.push("".concat(n,"normal3f inputs:normal.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_normal.outputs:rgb>")),a.push(tt(p,e,"normal",null,t,r))),null!==v&&(o.push("".concat(n,"float inputs:occlusion.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(v.uniqueId,"_occlusion.outputs:").concat(T,">")),a.push(tt(v,e,"occlusion",new g.Color3(b,b,b),t,r))),null!==h?(o.push("".concat(n,"float inputs:roughness.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(h.uniqueId,"_roughness.outputs:").concat(d,">")),a.push(tt(h,e,"roughness",new g.Color3(m,m,m),t,r))):o.push("".concat(n,"float inputs:roughness = ").concat(m)),null!==x?(o.push("".concat(n,"float inputs:metallic.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(x.uniqueId,"_metallic.outputs:").concat(_,">")),a.push(tt(x,e,"metallic",new g.Color3(y,y,y),t,r))):o.push("".concat(n,"float inputs:metallic = ").concat(y)),null!==A?(o.push("".concat(n,"float inputs:opacity.connect = </Materials/Material_").concat(e.uniqueId,"/Texture_").concat(A.uniqueId,"_opacity.outputs:r>")),o.push("".concat(n,"float inputs:opacityThreshold = 0.0001")),a.push(tt(A,e,"opacity",null,t,r))):o.push("".concat(n,"float inputs:opacity = ").concat(e.alpha)),o.push("".concat(n,"float inputs:ior = ").concat(M)),'\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 = </Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(a.join("\n"),"\n\n\t}\n")}function nt(e,t,r){return T(this,void 0,void 0,(function(){var n,o,a,i,s,u,c,l,f,p,h,d,m,x,_,y,T,A,M,w,E,R,C,V,S,I,B,F;return b(this,(function(b){switch(b.label){case 0:return n=v({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},t),"undefined"!=typeof fflate?[3,2]:[4,g.Tools.LoadScriptAsync(n.fflateUrl)];case 1:b.sent(),b.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),i={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(f=(l=c).geometry,(p=l.material)&&f&&(!r||r(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(p.getClassName())?((h="geometries/Geometry_"+f.uniqueId+".usda")in o||(d=ze(f,n),o[h]=Qe(d)),p.uniqueId in i||(i[p.uniqueId]=p),a+=Ze(l)):g.Tools.Warn("USDZExportAsync does not support this material type: "+p.getClassName())));for(y in e.activeCamera&&n.exportCamera&&(a+=function(e,t){var r="Camera_"+e.uniqueId,n=Ye(g.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===g.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 }\n }",a+=function(e,t,r){var n=[];for(var o in e){var a=e[o];n.push(rt(a,t,r))}return'\n def "Materials"\n{\n'.concat(n.join(""),"\n}\n\n")}(i,m={},n),o[n.modelFileName]=fflate.strToU8(a),_=[],x=m)_.push(y);T=0,b.label=3;case 3:return T<_.length?(y=_[T])in x?(M=m[A=y],w=M.getSize(),[4,M.readPixels()]):[3,6]:[3,7];case 4:if(!(E=b.sent()))throw new Error("Texture data is not available");return[4,g.DumpTools.DumpDataAsync(w.width,w.height,E,"image/png",void 0,!1,!0)];case 5:R=b.sent(),o["textures/Texture_".concat(A,".png")]=new Uint8Array(R).slice(),b.label=6;case 6:return T++,[3,3];case 7:for(V in C=0,o)(S=o[V])&&(I=34+V.length,4!=(B=63&(C+=I))&&(F=new Uint8Array(64-B),o[V]=[S,{extra:{12345:F}}]),C=S.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var ot=void 0!==a.g?a.g:"undefined"!=typeof window?window:void 0;if(void 0!==ot){ot.BABYLON=ot.BABYLON||{};var at=ot.BABYLON;at.GLTF2=at.GLTF2||{},at.GLTF2.Exporter=at.GLTF2.Exporter||{},at.GLTF2.Exporter.Extensions=at.GLTF2.Exporter.Extensions||{};var it=[];for(var st in u)at[st]=u[st],it.push(st);for(var st in c)at[st]=c[st],it.push(st);for(var st in l)at[st]=l[st],it.push(st);for(var st in f)at.GLTF2.Exporter.Extensions[st]=f[st],it.push(st);for(var st in p)it.indexOf(st)>-1||(at.GLTF2.Exporter[st]=p[st])}var ut=void 0!==a.g?a.g:"undefined"!=typeof window?window:void 0;if(void 0!==ut)for(var ct in s)ut.BABYLON[ct]=s[ct];var lt=void 0!==a.g?a.g:"undefined"!=typeof window?window:void 0;if(void 0!==lt)for(var ft in h)lt.BABYLON[ft]=h[ft];var pt=void 0!==a.g?a.g:"undefined"!=typeof window?window:void 0;if(void 0!==pt)for(var ht in d)pt.BABYLON[ht]=d[ht];const dt=m;return i.default})()));
2
2
  //# sourceMappingURL=babylonjs.serializers.min.js.map