babylonjs-serializers 8.46.2 → 8.47.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babylon.glTF2Serializer.js +1 -1
- package/babylon.glTF2Serializer.min.js +1 -1
- package/babylon.glTF2Serializer.min.js.map +1 -1
- package/babylonjs.serializers.d.ts +63 -1
- package/babylonjs.serializers.js +1 -1
- package/babylonjs.serializers.min.js +1 -1
- package/babylonjs.serializers.min.js.map +1 -1
- package/babylonjs.serializers.module.d.ts +138 -2
- package/package.json +4 -4
package/babylonjs.serializers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.d(o,{default:()=>Ht});var a={};n.r(a),n.d(a,{OBJExport:()=>g});var s={};n.r(s),n.d(s,{__IGLTFExporterExtension:()=>m});var i={};n.r(i),n.d(i,{GLTFData:()=>_});var u={};n.r(u),n.d(u,{GLTF2Export:()=>ue});var c={};n.r(c),n.d(c,{EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>mt,EXT_texture_webp:()=>xt,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Ve,KHR_materials_coat:()=>Ne,KHR_materials_diffuse_roughness:()=>ct,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_texture_basisu:()=>pt,KHR_texture_transform:()=>ht});var l={};n.r(l),n.d(l,{EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>mt,EXT_texture_webp:()=>xt,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Ve,KHR_materials_coat:()=>Ne,KHR_materials_diffuse_roughness:()=>ct,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_texture_basisu:()=>pt,KHR_texture_transform:()=>ht,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V});var h={};n.r(h),n.d(h,{STLExport:()=>_t});var f={};n.r(f),n.d(f,{USDZExportAsync:()=>Ft});var p={};n.r(p),n.d(p,{BVHExporter:()=>Bt});var d={};n.r(d),n.d(d,{BVHExporter:()=>Bt,EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>mt,EXT_texture_webp:()=>xt,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Ve,KHR_materials_coat:()=>Ne,KHR_materials_diffuse_roughness:()=>ct,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_texture_basisu:()=>pt,KHR_texture_transform:()=>ht,OBJExport:()=>g,STLExport:()=>_t,USDZExportAsync:()=>Ft,_ConvertToGLTFPBRMetallicRoughness:()=>S,_SolveMetallic:()=>V,__IGLTFExporterExtension:()=>m});var x=n(597),g=function(){function e(){}return e.OBJ=function(e,t,r,n){var o=[],a=1,s=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var i=0;i<e.length;i++){var u=e[i],c=u.name||"mesh".concat(i,"}");o.push("o ".concat(c));var l=null;if(n){var h=u.computeWorldMatrix(!0);l=new x.Matrix,h.invertToRef(l),u.bakeTransformIntoVertices(h)}if(t){var f=u.material;f&&o.push("usemtl "+f.id)}var p=u.geometry;if(p){var d=p.getVerticesData("position"),g=p.getVerticesData("normal"),m=p.getVerticesData("uv"),_=p.getIndices(),T=0,v=0;if(d&&_){for(var y=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*y+" "+d[b+1]+" "+d[b+2]),T++;if(null!=g)for(b=0;b<g.length;b+=3)o.push("vn "+g[b]*y+" "+g[b+1]+" "+g[b+2]);if(null!=m)for(b=0;b<m.length;b+=2)o.push("vt "+m[b]+" "+m[b+1]),v++;var M=["","",""],w=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===x.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=w[0],R=w[1];for(b=0;b<_.length;b+=3){var C=[String(_[b]+a),String(_[b+A]+a),String(_[b+R]+a)],E=[String(_[b]+s),String(_[b+A]+s),String(_[b+R]+s)],I=C,V=null!=m?E:M,S=null!=g?C:M;o.push("f "+I[0]+"/"+V[0]+"/"+S[0]+" "+I[1]+"/"+V[1]+"/"+S[1]+" "+I[2]+"/"+V[2]+"/"+S[2])}n&&l&&u.bakeTransformIntoVertices(l),a+=T,s+=v}else x.Tools.Warn("There are no position vertices or indices on the mesh!")}else x.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],r=e.material;return t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4)),r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e}(),m=0,_=function(){function e(){this.files={}}return Object.defineProperty(e.prototype,"glTFFiles",{get:function(){return this.files},enumerable:!1,configurable:!0}),e.prototype.downloadFiles=function(){for(var e in this.files){var t=this.files[e],r=new Blob([t],{type:(0,x.GetMimeType)(e)});x.Tools.Download(r,e)}},e}(),T=function(){return T=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},T.apply(this,arguments)};function v(e,t,r,n){return new(r||(r=Promise))((function(o,a){function s(e){try{u(n.next(e))}catch(e){a(e)}}function i(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,i)}u((n=n.apply(e,t||[])).next())}))}function y(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=i(0),s.throw=i(1),s.return=i(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function b(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var M=1e-6,w=new x.Color3(.04,.04,.04),A=1024,R=x.Color3.White(),C=x.Color3.BlackReadOnly;function E(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function I(e){return v(this,void 0,void 0,(function(){var t,r,n,o;return y(this,(function(a){switch(a.label){case 0:return(t=e.getInternalTexture())&&1===t.source?t.invertY?[2,null]:(r=t._buffer,o=e.mimeType,r?[3,2]:[4,x.Tools.LoadFileAsync(t.url)]):[2,null];case 1:return n=a.sent(),o=(0,x.GetMimeType)(t.url)||o,[3,10];case 2:return ArrayBuffer.isView(r)?(n=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,10]):[3,3];case 3:return r instanceof ArrayBuffer?(n=r,[3,10]):[3,4];case 4:return r instanceof Blob?[4,r.arrayBuffer()]:[3,6];case 5:return n=a.sent(),o=r.type||o,[3,10];case 6:return"string"!=typeof r?[3,8]:[4,x.Tools.LoadFileAsync(r)];case 7:return n=a.sent(),o=(0,x.GetMimeType)(r)||o,[3,10];case 8:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,x.Tools.LoadFileAsync(r.src)]:[3,10];case 9:n=a.sent(),o=(0,x.GetMimeType)(r.src)||o,a.label=10;case 10:return n&&E(o)?[2,new Blob([n],{type:o})]:[2,null]}}))}))}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 x.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=x.Scalar.Clamp(e.specularPower,0,A),o=(0,x.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:o}}function F(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 x.RawTexture.CreateRGBATexture(n,e,t,r)}function O(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.uniqueId))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c;return y(this,(function(l){switch(l.label){case 0:return r=S(e),n={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||x.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),t?(o=[],(a=e.diffuseTexture)&&o.push(this.exportTextureAsync(a).then((function(e){e&&(r.baseColorTexture=e)}))),(s=e.bumpTexture)&&o.push(this.exportTextureAsync(s).then((function(e){e&&(n.normalTexture=e,1!==s.level&&(n.normalTexture.scale=s.level))}))),(i=e.emissiveTexture)&&(n.emissiveFactor=[1,1,1],o.push(this.exportTextureAsync(i).then((function(e){e&&(n.emissiveTexture=e)})))),(u=e.ambientTexture)&&o.push(this.exportTextureAsync(u).then((function(e){if(e){var t={index:e.index};n.occlusionTexture=t}}))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===x.Constants.ALPHA_COMBINE?n.alphaMode="BLEND":x.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(C,M)&&(n.emissiveFactor=e.emissiveColor.asArray()),n.pbrMetallicRoughness=r,F(n,e),[4,this._finishMaterialAsync(n,e)];case 3:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s;return y(this,(function(i){switch(i.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(r=i.sent(),n=[],o=0,a=r;o<a.length;o++)s=a[o],n.push(this.exportTextureAsync(s));return[4,Promise.all(n)];case 2:return i.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return i.sent(),[2]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,a=e?e.getSize():{width:0,height:0},s=t?t.getSize():{width:0,height:0};return a.width<s.width?(n=e&&e instanceof x.Texture?x.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):B(s.width,s.height,r),o=t):a.width>s.width?(o=t&&t instanceof x.Texture?x.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):B(a.width,a.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h,f,p,d,g,m,_,T,v,b,w,A,C,E,I,V,S,F,B,P,N,U,L;return y(this,(function(y){switch(y.label){case 0:return n=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,y.sent()];case 2:return(o=e?e.getScene():t?t.getScene():null)?(a=this._resizeTexturesToSameDimensions(e,t,o),s=null===(L=a.texture1)||void 0===L?void 0:L.getSize(),i=void 0,u=void 0,c=s.width,l=s.height,[4,a.texture1.readPixels()]):[3,12];case 3:return h=y.sent(),[4,a.texture2.readPixels()];case 4:return f=y.sent(),h?(i=O(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return f?(u=O(f),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(p=u.byteLength,d=new Uint8Array(p),g=new Uint8Array(p),m=new x.Color3(0,0,0),_=0,T=0,F=0;F<l;++F)for(B=0;B<c;++B)v=4*(c*F+B),b=new x.Color3(i[v],i[v+1],i[v+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),w=new x.Color3(u[v],u[v+1],u[v+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(r.specularColor),A=u[v+3]*r.glossiness,C={diffuseColor:b,specularColor:w,glossiness:A},E=this._convertSpecularGlossinessToMetallicRoughness(C),m.r=Math.max(m.r,E.baseColor.r),m.g=Math.max(m.g,E.baseColor.g),m.b=Math.max(m.b,E.baseColor.b),_=Math.max(_,E.metallic),T=Math.max(T,E.roughness),g[v]=255*E.baseColor.r,g[v+1]=255*E.baseColor.g,g[v+2]=255*E.baseColor.b,g[v+3]=a.texture1.hasAlpha?255*i[v+3]:255,d[v]=0,d[v+1]=255*E.roughness,d[v+2]=255*E.metallic,d[v+3]=255;for(I={baseColor:m,metallic:_,roughness:T},V=!1,S=!1,F=0;F<l;++F)for(B=0;B<c;++B)g[P=4*(c*F+B)]/=I.baseColor.r>M?I.baseColor.r:1,g[P+1]/=I.baseColor.g>M?I.baseColor.g:1,g[P+2]/=I.baseColor.b>M?I.baseColor.b:1,N=x.Color3.FromInts(g[P],g[P+1],g[P+2]),U=N.toGammaSpace(o.getEngine().useExactSrgbConversions),g[P]=255*U.r,g[P+1]=255*U.g,g[P+2]=255*U.b,U.equalsWithEpsilon(R,M)||(S=!0),d[P+1]/=I.roughness>M?I.roughness:1,d[P+2]/=I.metallic>M?I.metallic:1,x.Color3.FromInts(255,d[P+1],d[P+2]).equalsWithEpsilon(R,M)||(V=!0);return V&&n.push((0,x.EncodeImageAsync)(d,c,l).then((function(e){I.metallicRoughnessTextureData=e}))),S&&n.push((0,x.EncodeImageAsync)(g,c,l).then((function(e){I.baseColorTextureData=e}))),[4,Promise.all(n).then((function(){return I}))];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),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,M)),s=e.specularColor.subtract(w.scale(1-o)).scale(1/Math.max(o,M)),i=x.Color3.Lerp(a,s,o*o);return{baseColor:i=i.clampToRef(0,1,i),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)},e.prototype._getMaxComponent=function(e){return Math.max(e.r,Math.max(e.g,e.b))},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n,o,a,s,i,u){return v(this,void 0,void 0,(function(){var c,l,h,f,p,d,g,m,_,T=this;return y(this,(function(b){switch(b.label){case 0:return c=[],l={baseColor:e,metallic:t,roughness:r},u&&(s instanceof x.OpenPBRMaterial?(s.geometryOpacityTexture?(h=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:0,f=s.geometryOpacityTexture&&s.geometryOpacityTexture.getInternalTexture()?s.geometryOpacityTexture.getInternalTexture().uniqueId:0,p=Number("".concat(h).concat(f)),(_=this._textureMap.get(p))?i.baseColorTexture=_:c.push((0,x.MergeTexturesAsync)("baseColorOpacityTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,2):(0,x.CreateConstantInput)(1),(0,x.CreateTextureInput)(s.geometryOpacityTexture,0)),s.getScene()).then((function(e){return v(T,void 0,void 0,(function(){var t;return y(this,(function(r){switch(r.label){case 0:return[4,this.exportTextureAsync(e,p)];case 1:return(t=r.sent())&&(i.baseColorTexture=t),[2]}}))}))})))):n&&c.push(this.exportTextureAsync(n).then((function(e){e&&(i.baseColorTexture=e)}))),s._useMetallicFromMetallicTextureBlue&&o?c.push(this.exportTextureAsync(o).then((function(e){e&&(i.metallicRoughnessTexture=e)}))):(a||o)&&(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,g=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,m=Number("".concat(d).concat(g)),(_=this._textureMap.get(m))?i.metallicRoughnessTexture=_:c.push((0,x.MergeTexturesAsync)("MetalRoughTexture",(0,x.CreateRGBAConfiguration)(s.ambientOcclusionTexture?(0,x.CreateTextureInput)(s.ambientOcclusionTexture,0):(0,x.CreateConstantInput)(1),a?(0,x.CreateTextureInput)(a,0):(0,x.CreateConstantInput)(1),o?(0,x.CreateTextureInput)(o,0):(0,x.CreateConstantInput)(1)),s.getScene()).then((function(e){return v(T,void 0,void 0,(function(){var t;return y(this,(function(r){switch(r.label){case 0:return[4,this.exportTextureAsync(e,m)];case 1:return(t=r.sent())&&(i.metallicRoughnessTexture=t),[2]}}))}))}))))):(n&&c.push(this.exportTextureAsync(n).then((function(e){e&&(i.baseColorTexture=e)}))),o&&c.push(this.exportTextureAsync(o).then((function(e){e&&(i.metallicRoughnessTexture=e)}))))),c.length>0?(this._exporter._materialNeedsUVsSet.add(s),[4,Promise.all(c)]):[3,2];case 1:b.sent(),b.label=2;case 2:return[2,l]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof x.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case x.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case x.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case x.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case x.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case x.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case x.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case x.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case x.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case x.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case x.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case x.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case x.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case x.Texture.WRAP_ADDRESSMODE:return 10497;case x.Texture.CLAMP_ADDRESSMODE:return 33071;case x.Texture.MIRROR_ADDRESSMODE:return 33648;default:return x.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l;return y(this,(function(h){switch(h.label){case 0:return n={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,a=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,!a||s?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(o||a)&&r?(this._exporter._materialNeedsUVsSet.add(e),i=this._exportTextureSampler(o||a),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,a,n)]):[3,8];case 3:return u=h.sent(),c=this._exporter._textures,u.baseColorTextureData?[4,this._exportImageAsync("baseColor".concat(c.length),u.baseColorTextureData)]:[3,5];case 4:l=h.sent(),t.baseColorTexture=this._exportTextureInfo(l,i,null==o?void 0:o.coordinatesIndex),h.label=5;case 5:return u.metallicRoughnessTextureData?[4,this._exportImageAsync("metallicRoughness".concat(c.length),u.metallicRoughnessTextureData)]:[3,7];case 6:l=h.sent(),t.metallicRoughnessTexture=this._exportTextureInfo(l,i,null==a?void 0:a.coordinatesIndex),h.label=7;case 7:return[2,u];case 8:return[2,this._convertSpecularGlossinessToMetallicRoughness(n)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c;return y(this,(function(l){switch(l.label){case 0:return r={},n={name:e.name},(o=e.isMetallicWorkflow())&&(a=e._albedoColor,s=e.alpha,a&&(r.baseColorFactor=[a.r,a.g,a.b,s])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,r,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,r,t)];case 3:u=l.sent(),l.label=4;case 4:return i=u,[4,this._setMetallicRoughnessPbrMaterialAsync(i,e,n,r,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(n,e)];case 6:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a,s,i,u,c,l=this;return y(this,(function(h){switch(h.label){case 0:return F(r,t),e.baseColor.equalsWithEpsilon(R,M)&&x.Scalar.WithinEpsilon(t.alpha,1,M)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||x.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),o?(a=[],(s=t instanceof x.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&a.push(this.exportTextureAsync(s).then((function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))}))),(i=t instanceof x.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&a.push(new Promise((function(e){return v(l,void 0,void 0,(function(){var r,o,a,s;return y(this,(function(u){switch(u.label){case 0:return t instanceof x.OpenPBRMaterial&&n.metallicRoughnessTexture?(r=this._exportTextureSampler(i),o=this._exporter._textures[n.metallicRoughnessTexture.index].source,a=this._exportTextureInfo(o,r,i.coordinatesIndex),this._textureMap.set(i.uniqueId,a),this._exporter._extensionsPostExportTextures("exporter",a,i),[2,e(a)]):[3,1];case 1:return s=e,[4,this.exportTextureAsync(i)];case 2:return[2,s.apply(void 0,[u.sent()])]}}))}))})).then((function(e){return v(l,void 0,void 0,(function(){var n;return y(this,(function(o){return e&&(n={index:e.index,texCoord:e.texCoord,extensions:e.extensions},r.occlusionTexture=n,t instanceof x.PBRBaseMaterial?n.strength=t._ambientTextureStrength:n.strength=t.ambientOcclusionTexture.level),[2]}))}))}))),(u=t instanceof x.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&a.push(this.exportTextureAsync(u).then((function(e){e&&(r.emissiveTexture=e)}))),a.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(a)]):[3,2]):[3,2];case 1:h.sent(),h.label=2;case 2:return(c=t instanceof x.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(C,M)||(r.emissiveFactor=c.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i;return y(this,(function(u){switch(u.label){case 0:return r={},n={name:e.name},o=e.baseColor,a=e.geometryOpacity,o&&(r.baseColorFactor=[o.r,o.g,o.b,a]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,r,t)];case 1:return s=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,n,r,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(n,e)];case 3:return u.sent(),(i=this._exporter._materials).push(n),[2,i.length-1]}}))}))},e.prototype.exportTextureAsync=function(e){return v(this,arguments,void 0,(function(e,t){var r,n,o;return void 0===t&&(t=null),y(this,(function(a){switch(a.label){case 0:return(r=this._textureMap.get(null!=t?t:e.uniqueId))?[2,r]:(n=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=a.sent(),r=this._exportTextureInfo(o,n,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,r),this._exporter._extensionsPostExportTextures("exporter",r,e),[2,r]}}))}))},e.prototype._exportTextureImageAsync=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,a,s=this;return y(this,(function(i){switch(i.label){case 0:return t=null!==(a=e.mimeType)&&void 0!==a?a:"none",r=this._internalTextureToImage,n=e.getInternalTexture().uniqueId,r[n]=r[n]||{},void 0===(o=r[n][t])&&(o=v(s,void 0,void 0,(function(){var r,n,o,a,s;return y(this,(function(i){switch(i.label){case 0:return[4,I(e)];case 1:return!(r=i.sent())||"none"!==t&&r.type!==t?[3,3]:[4,this._exportImageAsync(e.name,r)];case 2:case 6:return[2,i.sent()];case 3:return n="image/png","none"!==t&&(E(t)?n=t:(n="image/png",x.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG.")))),o=e.getSize(),[4,(0,x.GetTextureDataAsync)(e)];case 4:return a=i.sent(),[4,(0,x.EncodeImageAsync)(a,o.width,o.height,n)];case 5:return s=i.sent(),[4,this._exportImageAsync(e.name,s)]}}))})),r[n][t]=o),[4,o];case 1:return[2,i.sent()]}}))}))},e.prototype._exportImageAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u;return y(this,(function(c){switch(c.label){case 0:return r=this._exporter._images,this._exporter._shouldUseGlb?(n={name:e,mimeType:t.type,bufferView:void 0},[4,t.arrayBuffer()]):[3,2];case 1:return o=c.sent(),a=this._exporter._bufferManager.createBufferView(new Uint8Array(o)),this._exporter._bufferManager.setBufferView(n,a),[3,3];case 2:s=e.replace(/\.\/|\/|\.\\|\\/g,"_"),i=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(t.type),u=s+i,r.some((function(e){return e.uri===u}))&&(u="".concat(s,"_").concat(x.Tools.RandomId()).concat(i)),n={name:e,uri:u},this._exporter._imageData[u]=t,c.label=3;case 3:return r.push(n),[2,r.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=x.Matrix.Compose(new x.Vector3(-1,1,1),x.Quaternion.Identity(),x.Vector3.Zero());function U(e,t){if(!(e instanceof x.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(x.Matrix.IdentityReadOnly,x.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(N,x.TmpVectors.Matrix[0]).equalsWithEpsilon(x.Matrix.IdentityReadOnly,x.Epsilon))return!1;return!(e instanceof x.AbstractMesh&&e.geometry)}var L=x.Vector3.ZeroReadOnly,k=x.Quaternion.Identity(),K=x.Vector3.OneReadOnly,z=new x.Vector3(-1,1,1);function W(e,t){var r=e.byteOffset,n=e.byteStride,o=e.type,a=e.normalized,s=e.getSize(),i=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:s,type:o,count:i*s,normalized:a,totalVertices:i,kind:e.getKind()}}function D(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 q(e){switch(e){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:case x.VertexBuffer.ColorKind:case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:case x.VertexBuffer.MatricesWeightsKind:case x.VertexBuffer.MatricesWeightsExtraKind:case x.VertexBuffer.UVKind:case x.VertexBuffer.UV2Kind:case x.VertexBuffer.UV3Kind:case x.VertexBuffer.UV4Kind:case x.VertexBuffer.UV5Kind:case x.VertexBuffer.UV6Kind:return!0}return!1}function G(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function H(e){return e.x*=-1,e}function j(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),r=Math.abs(e.y);if(t>r){var n=Math.sign(e.x);e.x=t,e.y*=-n,e.z*=-n,e.w*=n}else n=Math.sign(e.y),e.x*=-n,e.y=r,e.z*=n,e.w*=-n}else{var o=Math.abs(e.z),a=Math.abs(e.w);o>a?(n=Math.sign(e.z),e.x*=-n,e.y*=n,e.z=o,e.w*=-n):(n=Math.sign(e.w),e.x*=n,e.y*=-n,e.z*=-n,e.w=a)}return e}function Q(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function X(e,t){var r=x.Vector3.FromArrayToRef(t.translation||[0,0,0],0,x.TmpVectors.Vector3[0]),n=x.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,x.TmpVectors.Quaternion[0]),o=x.Matrix.ComposeToRef(K,n,r,x.TmpVectors.Matrix[0]),a=x.Vector3.FromArrayToRef(e.translation||[0,0,0],0,x.TmpVectors.Vector3[2]),s=x.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,x.TmpVectors.Quaternion[1]),i=x.Matrix.ComposeToRef(K,s,a,x.TmpVectors.Matrix[1]);o.multiplyToRef(i,i),i.decompose(void 0,n,r),r.equalsWithEpsilon(L,x.Epsilon)?delete t.translation:t.translation=r.asArray(),n.equalsWithEpsilon(k,x.Epsilon)?delete t.rotation:t.rotation=n.asArray(),t.scale&&delete t.scale}function Y(e,t){if(!(t instanceof x.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var r=e.getScene(),n=e instanceof x.TargetCamera&&!r.useRightHandedSystem?z:K;return!!t.scaling.equalsWithEpsilon(n,x.Epsilon)||(x.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function Z(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],a=o[0],s=o[1],i=t[a];(Array.isArray(s)&&Array.isArray(i)&&J(s,i)||s===i)&&delete e[a]}return e}function J(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var $=new Map([[Int8Array,function(e,t,r){return e.setInt8(t,r)}],[Uint8Array,function(e,t,r){return e.setUint8(t,r)}],[Uint8ClampedArray,function(e,t,r){return e.setUint8(t,r)}],[Int16Array,function(e,t,r){return e.setInt16(t,r,!0)}],[Uint16Array,function(e,t,r){return e.setUint16(t,r,!0)}],[Int32Array,function(e,t,r){return e.setInt32(t,r,!0)}],[Uint32Array,function(e,t,r){return e.setUint32(t,r,!0)}],[Float32Array,function(e,t,r){return e.setFloat32(t,r,!0)}],[Float64Array,function(e,t,r){return e.setFloat64(t,r,!0)}]]),ee=function(){function e(e){this._data=new Uint8Array(e),this._dataView=new DataView(this._data.buffer),this._byteOffset=0}return e.prototype.writeTypedArray=function(e){this._checkGrowBuffer(e.byteLength);for(var t=$.get(e.constructor),r=0;r<e.length;r++)t(this._dataView,this._byteOffset,e[r]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var r=new Uint8Array(2*t);r.set(this._data),this._data=r,this._dataView=new DataView(this._data.buffer)}},e}();function te(e){return e%4==0?4:e%2==0?2:1}var re,ne=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach((function(e){t+=e.byteLength}));for(var r=new ee(t),n=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return te(t.byteLength)-te(e.byteLength)}));n<o.length;n++){var a=o[n];a.byteOffset=r.byteOffset,e.push(a);for(var s=e.length-1,i=0,u=this.getPropertiesWithBufferView(a);i<u.length;i++)u[i].bufferView=s;r.writeTypedArray(this._bufferViewToData.get(a)),this._bufferViewToData.delete(a)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,o,a,s){this._verifyBufferView(e);var i={bufferView:void 0,componentType:r,count:n,type:t,min:null==a?void 0:a.min,max:null==a?void 0:a.max,normalized:s,byteOffset:o};return this.setBufferView(i,e),this._accessorToBufferView.set(i,e),i},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var o=n[r];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(re||(re={}));var oe=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof x.TransformNode||e instanceof x.Camera||e instanceof x.Light)},e._CreateNodeAnimation=function(t,r,n,o,a){if(this._IsTransformable(t)){var s=[],i=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,o),h=l.interpolationType,f=l.shouldBakeAnimation;if(f?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,i,c,o):"LINEAR"===h||"STEP"===h?e._CreateLinearOrStepAnimation(t,r,n,s,i,o):"CUBICSPLINE"===h?e._CreateCubicSplineAnimation(t,r,n,s,i,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,i,c,o),s.length&&i.length)return{inputs:s,outputs:i,samplerInterpolation:h,inputsMin:f?c.min:x.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:f?c.max:x.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:x.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(x.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,o,a,s,i,u,c,l,h){var f;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var x=d[p];if(!h||h(x)){var g=e._DeduceAnimationInfo(x);g&&(f={name:x.name,samplers:[],channels:[]},e._AddAnimation("".concat(x.name),x.hasRunningRuntimeAnimations?r:f,t,x,g.dataAccessorType,g.animationChannelTargetPath,o,s,i,u,g.useQuaternion,c,l),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,a,s,i,u,c,l,h){var f;if(t instanceof x.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var g=0,m=p.getTarget(d).animations;g<m.length;g++){var _=m[g];if(!h||h(_)){for(var T=new x.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),v=[],y=_.getKeys(),b=0;b<y.length;++b)for(var M=y[b],w=0;w<p.numTargets;++w)w==d?v.push(M):v.push({frame:M.frame,value:0});T.setKeys(v,!0);var A=e._DeduceAnimationInfo(T);A&&(f={name:T.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:f,t,T,A.dataAccessorType,A.animationChannelTargetPath,o,s,i,u,A.useQuaternion,c,l,p.numTargets),f.samplers.length&&f.channels.length&&n.push(f))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,a,s,i,u,c){var l,h;if(t.animationGroups)for(var f=t.animationGroups,p=function(f){var p=new Map,g=new Map,m=new Set,_=f.to-f.from;h={name:f.name,channels:[],samplers:[]};for(var T=function(r){var _=f.targetedAnimations[r],T=_.target,v=_.animation;if(c&&!c(v))return"continue";var y=u.has(T);if(d._IsTransformable(T)||1===T.length&&d._IsTransformable(T[0])){if(M=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(T)?T:d._IsTransformable(T[0])?T[0]:null;b&&e._AddAnimation("".concat(v.name),h,b,v,M.dataAccessorType,M.animationChannelTargetPath,n,o,a,s,M.useQuaternion,i,y)}}else if(T instanceof x.MorphTarget||1===T.length&&T[0]instanceof x.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var w=T instanceof x.MorphTarget?T:T[0];if(w){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1}));if(A){var R=t.meshes.find((function(e){return e.morphTargetManager===A}));R&&(p.has(R)||p.set(R,new Map),null===(l=p.get(R))||void 0===l||l.set(w,v),m.add(R),g.set(R,v))}}}}},v=0;v<f.targetedAnimations.length;++v)T(v);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=g.get(t).getKeys(),d=l.length,m=0;m<d;++m)for(var T=0;T<r.numTargets;++T){var v=r.getTarget(T),y=p.get(t);if(y){var b=y.get(v);b?(u||(u=new x.Animation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,x.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[m])):c.push({frame:f.from+_/d*m,value:v.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c,!0);var M=e._DeduceAnimationInfo(u);M&&e._AddAnimation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),h,t,u,M.dataAccessorType,M.animationChannelTargetPath,n,o,a,s,M.useQuaternion,i,!1,null==r?void 0:r.numTargets)})),h.channels.length&&h.samplers.length&&r.push(h)},d=this,g=0,m=f;g<m.length;g++)p(m[g])},e._AddAnimation=function(t,r,n,o,a,s,i,u,c,l,h,f,p,d){var g,m,_,T,v,y,b=e._CreateNodeAnimation(n,o,s,h,f);if(b){if(d){for(var M=0,w=0,A=[];b.inputs.length>0;)w=b.inputs.shift(),M%d==0&&A.push(w),M++;b.inputs=A}var R=i.get(n),C=new Float32Array(b.inputs);g=u.createBufferView(C),m=u.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(m),_=l.length-1;var E=new x.Quaternion,I=new x.Vector3,V=new x.Vector3,S=n instanceof x.Camera,F=D(a),B=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var r=e;switch(s){case"translation":p&&(x.Vector3.FromArrayToRef(e,0,V),H(V),V.toArray(r));break;case"rotation":4===e.length?x.Quaternion.FromArrayToRef(e,0,E):(r=new Array(4),x.Vector3.FromArrayToRef(e,0,I),x.Quaternion.FromEulerVectorToRef(I,E)),p&&(j(E),S&&Q(E)),E.toArray(r)}B.set(r,t*F)})),g=u.createBufferView(B),m=u.createAccessor(g,a,5126,b.outputs.length),l.push(m),T=l.length-1,v={interpolation:b.samplerInterpolation,input:_,output:T},r.samplers.push(v),y={sampler:r.samplers.length-1,target:{node:R,path:s}},r.channels.push(y)}},e._CreateBakedAnimation=function(t,r,n,o,a,s,i,u,c,l,h){var f,p,d=x.Quaternion.Identity(),g=null,m=null,_=null,T=null,v=null,y=null;l.min=x.Tools.FloatRound(o/s);for(var b=r.getKeys(),M=0,w=b.length;M<w;++M){if(y=null,_=b[M],M+1<w)if(T=b[M+1],_.value.equals&&_.value.equals(T.value)||_.value===T.value){if(0!==M)continue;y=_.frame}else y=T.frame;else{if(v=b[M-1],_.value.equals&&_.value.equals(v.value)||_.value===v.value)continue;y=a}if(y)for(var A=_.frame;A<=y;A+=i)if((p=x.Tools.FloatRound(A/s))!==g){g=p,m=p;var R={key:0,repeatCount:0,loopMode:r.loopMode};f=r._interpolate(A,R),e._SetInterpolatedValue(t,f,p,r,n,d,u,c,h)}}m&&(l.max=m)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,a){var s=e._GetBasePositionRotationOrScale(r,o,a),i=n.targetProperty.split("."),u=i?i[1]:"",c=a?x.Quaternion.FromArray(s).normalize():x.Vector3.FromArray(s);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:x.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,a,s,i,u){var c;s.push(r),"weights"!==o?(n.dataType===x.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u)),"rotation"===o?(u?a=t:(c=t,x.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),i.push(a.asArray())):(c=t,i.push(c.asArray()))):i.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,o,a,s){for(var i=0,u=r.getKeys();i<u.length;i++){var c=u[i];o.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,a,n,t,s)}},e._CreateCubicSplineAnimation=function(t,r,n,o,a,s){r.getKeys().forEach((function(i){o.push(i.frame/r.framePerSecond),e._AddSplineTangent(re.INTANGENT,a,n,"CUBICSPLINE",i,s),e._AddKeyframeValue(i,r,a,n,t,s),e._AddSplineTangent(re.OUTTANGENT,a,n,"CUBICSPLINE",i,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var o=e.rotationQuaternion;n=(null!=o?o:x.Quaternion.Identity()).asArray()}else{var a=e.rotation;n=(null!=a?a:x.Vector3.Zero()).asArray()}else if("translation"===t){var s=e.position;n=(null!=s?s:x.Vector3.Zero()).asArray()}else{var i=e.scaling;n=(null!=i?i:x.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,o,a){var s,i=t.dataType;if(i===x.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=x.Vector3.FromArray(u);u=x.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(i===x.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(s=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,a)){if("rotation"===n){var l=a?s:x.Quaternion.RotationYawPitchRoll(s.y,s.x,s.z).normalize();r.push(l.asArray())}r.push(s.asArray())}}else i===x.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):x.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,a=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,i=e.length;s<i;++s)if((o=e[s]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",a=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&1===o.interpolation&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,r,n,o,a){var s,i=e===re.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(i)if(a)s=i.asArray();else{var u=i;s=x.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else s=[0,0,0,0];else s="weights"===r?i?[i]:[0]:i?i.asArray():[0,0,0];t.push(s)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}();function ae(e,t,r,n,o,a){var s={attributes:{},influence:e.influence,name:e.name},i=t.geometry;if(!i)return x.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),s;var u=a?-1:1,c=x.Vector3.Zero(),l=0;if(e.hasPositions){var h=e.getPositions(),f=i.getVerticesData(x.VertexBuffer.PositionKind);if(f){var p=new Float32Array(f.length),d=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];l=f.length/3;for(var m=0;m<l;++m){var _=x.Vector3.FromArray(f,3*m);x.Vector3.FromArray(h,3*m).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),g[0]=Math.max(g[0],c.x),d[1]=Math.min(d[1],c.y),g[1]=Math.max(g[1],c.y),d[2]=Math.min(d[2],c.z),g[2]=Math.max(g[2],c.z),p[3*m]=c.x,p[3*m+1]=c.y,p[3*m+2]=c.z}var T=r.createBufferView(p,12),v=r.createAccessor(T,"VEC3",5126,h.length/3,0,{min:d,max:g});o.push(v),s.attributes.POSITION=o.length-1}else x.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),b=i.getVerticesData(x.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(l=b.length/3,m=0;m<l;++m){var w=x.Vector3.FromArray(b,3*m).normalize();x.Vector3.FromArray(y,3*m).normalize().subtractToRef(w,c),M[3*m]=c.x*u,M[3*m+1]=c.y,M[3*m+2]=c.z}T=r.createBufferView(M,12),v=r.createAccessor(T,"VEC3",5126,y.length/3,0),o.push(v),s.attributes.NORMAL=o.length-1}else x.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),R=i.getVerticesData(x.VertexBuffer.TangentKind);if(R){l=R.length/4;var C=new Float32Array(3*l);for(m=0;m<l;++m){var E=x.Vector3.FromArray(R,4*m);G(E);var I=x.Vector3.FromArray(A,3*m);G(I),I.subtractToRef(E,c),C[3*m]=c.x*u,C[3*m+1]=c.y,C[3*m+2]=c.z}T=r.createBufferView(C,12),v=r.createAccessor(T,"VEC3",5126,l,0),o.push(v),s.attributes.TANGENT=o.length-1}else x.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),S=i.getVerticesData(x.VertexBuffer.ColorKind),F=i.getVertexBuffer(x.VertexBuffer.ColorKind);if(S&&F){var B=F.getSize();l=S.length/B;var O=new Float32Array(l*B);for(m=0;m<l;++m)if(3===B){var P=x.Vector3.FromArray(S,m*B);x.Vector3.FromArray(V,m*B).subtractToRef(P,c),O[3*m]=c.x,O[3*m+1]=c.y,O[3*m+2]=c.z}else if(4===B){var N=new x.Vector4;P=x.Vector4.FromArray(S,m*B),x.Vector4.FromArray(V,m*B).subtractToRef(P,N),O[4*m]=N.x,O[4*m+1]=N.y,O[4*m+2]=N.z,O[4*m+3]=N.w}else x.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));T=r.createBufferView(O,4*B),v=r.createAccessor(T,3===B?"VEC3":"VEC4",5126,l,0),o.push(v),s.attributes.COLOR_0=o.length-1}else x.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return s}var se=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,r,n,o){var a,s,i,u;return null===(u=null===(i=null===(s=null===(a=this._indicesAccessorMap.get(e))||void 0===a?void 0:a.get(t))||void 0===s?void 0:s.get(r))||void 0===i?void 0:i.get(n))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,r,n,o,a){var s=this._indicesAccessorMap.get(e);s||(s=new Map,this._indicesAccessorMap.set(e,s));var i=s.get(t);i||(i=new Map,s.set(t,i));var u=i.get(r);u||(u=new Map,i.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(o,a)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,o;return null===(o=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===o?void 0:o.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a)),a.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),ie=function(){function e(e,t){if(void 0===e&&(e=x.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(x.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new P(this),this._extensions={},this._bufferManager=new ne,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=T({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,r,n){var o=this;if(r>=t.length)return Promise.resolve(e);var a=n(t[r],e);return a?a.then((function(e){return v(o,void 0,void 0,(function(){var o;return y(this,(function(a){switch(a.label){case 0:return e?[4,this._ApplyExtension(e,t,r+1,n)]:[3,2];case 1:return o=a.sent(),[3,3];case 2:o=null,a.label=3;case 3:return[2,o]}}))}))})):this._ApplyExtension(e,t,r+1,n)},e.prototype._ApplyExtensions=function(t,r){for(var n=[],o=0,a=e._ExtensionNames;o<a.length;o++){var s=a[o];n.push(this._extensions[s])}return this._ApplyExtension(t,n,0,r)},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){var a=this;return this._ApplyExtensions(t,(function(t,s){return t.postExportNodeAsync&&t.postExportNodeAsync(e,s,r,n,o,a._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._ApplyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,r,n){return v(this,void 0,void 0,(function(){var o,a=this;return y(this,(function(s){switch(s.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map((function(e){return v(a,void 0,void 0,(function(){var a,s;return y(this,(function(i){switch(i.label){case 0:return(a=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,a.postExportMaterialAdditionalTexturesAsync(t,r,n)]:[3,2];case 1:s=i.sent(),o.push.apply(o,s),i.label=2;case 2:return[2]}}))}))})))];case 1:return s.sent(),[2,o]}}))}))},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var s=a[o],i=this._extensions[s];i.postExportTexture&&i.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.postExportMeshPrimitive&&a.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return v(this,void 0,void 0,(function(){var t,r,n,o;return y(this,(function(a){switch(a.label){case 0:t=0,r=e._ExtensionNames,a.label=1;case 1:return t<r.length?(n=r[t],(o=this._extensions[n]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:a.sent(),a.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.enabled&&t(a)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,o;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r,n){void 0===n&&(n=100),e.UnregisterExtension(t)&&x.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r;var o=null!=n?n:0;e._ExtensionOrders[t]=o;for(var a=e._ExtensionNames.length,s=0;s<e._ExtensionNames.length;s++){var i=e._ExtensionNames[s];if(o<e._ExtensionOrders[i]){a=s;break}}e._ExtensionNames.splice(a,0,t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._generateJSON=function(e,t,r){var n={byteLength:e};return n.byteLength&&(this._glTF.buffers=[n]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(n.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,a,s,i;return y(this,(function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength,e,!0),n=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",a=e+".bin",(s=new _).files[o]=r,s.files[a]=n,this._imageData)for(i in this._imageData)s.files[i]=this._imageData[i];return[2,s]}}))}))},e.prototype._generateBinaryAsync=function(){return v(this,void 0,void 0,(function(){return y(this,(function(e){switch(e.label){case 0:return[4,this._exportSceneAsync()];case 1:return e.sent(),[4,this._extensionsPreGenerateBinaryAsync()];case 2:return e.sent(),[2,this._bufferManager.generateBinary(this._bufferViews)]}}))}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype.generateGLBAsync=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,a,s,i,u,c,l,h,f,p,d;return y(this,(function(x){switch(x.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=x.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",o=r.length,"undefined"!=typeof TextEncoder&&(s=new TextEncoder,a=s.encode(r),o=a.length),i=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+i+t.byteLength+u,(l=new ee(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(o+i),l.writeUInt32(1313821514),a)l.writeTypedArray(a);else for(h="_".charCodeAt(0),p=0;p<o;++p)(f=r.charCodeAt(p))!=r.codePointAt(p)?l.writeUInt8(h):l.writeUInt8(f);for(p=0;p<i;++p)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),p=0;p<u;++p)l.writeUInt8(0);return(d=new _).files[n]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){var n;if(t.getPivotPoint().equalsWithEpsilon(L,x.Epsilon)||x.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(L,x.Epsilon)){var o=x.TmpVectors.Vector3[0].copyFrom(t.position);r&&H(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(K,x.Epsilon)||(e.scale=t.scaling.asArray());var a=(null===(n=t.rotationQuaternion)||void 0===n?void 0:n.clone())||x.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);a.equalsWithEpsilon(k,x.Epsilon)||(r&&j(a),e.rotation=a.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){var n=x.TmpVectors.Vector3[0],o=x.TmpVectors.Quaternion[0],a=t.getWorldMatrix();if(t.parent){var s=t.parent.getWorldMatrix().invertToRef(x.TmpVectors.Matrix[0]);a.multiplyToRef(s,x.TmpVectors.Matrix[1]).decompose(void 0,o,n)}else a.decompose(void 0,o,n);n.equalsWithEpsilon(L,x.Epsilon)||(r&&H(n),e.translation=n.asArray()),r&&j(o),this._babylonScene.useRightHandedSystem||Q(o),o.equalsWithEpsilon(k,x.Epsilon)||(e.rotation=o.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var r=t[e],n={type:r.mode===x.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(r.name&&(n.name=r.name),"perspective"===n.type)n.perspective={aspectRatio:r.getEngine().getAspectRatio(r),yfov:r.fovMode===x.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===n.type){var o=r.orthoLeft&&r.orthoRight?.5*(r.orthoRight-r.orthoLeft):.5*r.getEngine().getRenderWidth(),a=r.orthoBottom&&r.orthoTop?.5*(r.orthoTop-r.orthoBottom):.5*r.getEngine().getRenderHeight();n.orthographic={xmag:o,ymag:a,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,n)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var r=t[e],n=this._nodesCameraMap.get(r);if(void 0!==n){this._cameras.push(r);for(var o=0,a=n;o<a.length;o++)a[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var r=t[e];r.bones.length<=0||this._skinMap.set(r,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,r=function(r){if(r.bones.length<=0)return"continue";var o=n._skinMap.get(r);if(null==o)return"continue";for(var a={},s=-1,i=0;i<r.bones.length;++i){var u=r.bones[i];-1!==(h=null!==(t=u.getIndex())&&void 0!==t?t:i)&&(a[h]=u,h>s&&(s=h))}for(var c,l=[],h=0;h<=s;++h){var f=(u=a[h]).getTransformNode(),p=f?n._nodeMap.get(f):void 0;if(void 0!==p){o.joints.push(p);var d=u.getAbsoluteInverseBindMatrix().clone();e.has(f)&&(c=d,N.invertToRef(x.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(N,c)),l.push(d)}else x.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var g=n._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==g){var m=new Float32Array(16*l.length);l.forEach((function(e,t){m.set(e.m,16*t)}));var _=n._bufferManager.createBufferView(m);n._accessors.push(n._bufferManager.createAccessor(_,"MAT4",5126,l.length)),o.inverseBindMatrices=n._accessors.length-1,n._skins.push(o);for(var T=n._skins.length-1,v=0,y=g;v<y.length;v++)y[v].skin=T}},n=this,o=0,a=this._babylonScene.skeletons;o<a.length;o++)r(a[o])},e.prototype._exportSceneAsync=function(){return v(this,void 0,void 0,(function(){var e,t,r,n,o,a,s,i,u,c,l,h,f,p,d,x,g,m,_,T,v,b,M;return y(this,(function(y){switch(y.label){case 0:for(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),r=new Array,n=new Array,o=new Array,a=0,s=this._babylonScene.rootNodes;a<s.length;a++)i=s[a],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&U(i,this._babylonScene.useRightHandedSystem)?o.push.apply(o,i.getChildren()):this._babylonScene.useRightHandedSystem?r.push(i):n.push(i);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new se(!0,!1),l=(c=(v=e.nodes).push).apply,h=[v],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,h.concat([y.sent()])),f=new se(!1,!1),d=(p=(b=e.nodes).push).apply,x=[b],[4,this._exportNodesAsync(r,f)];case 2:return d.apply(p,x.concat([y.sent()])),g=new se(!1,!0),_=(m=(M=e.nodes).push).apply,T=[M],[4,this._exportNodesAsync(o,g)];case 3:return _.apply(m,T.concat([y.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(u.getNodesSet()),this._babylonScene.animationGroups.length&&oe._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,u.getNodesSet(),this._options.shouldExportAnimation),[2]}}))}))},e.prototype._shouldExportNode=function(e){var t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t},e.prototype._exportNodesAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a;return y(this,(function(s){switch(s.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,o=e,s.label=1;case 1:return n<o.length?(a=o[n],[4,this._exportNodeAsync(a,r,t)]):[3,4];case 2:s.sent(),s.label=3;case 3:return n++,[3,1];case 4:return[2,r]}}))}))},e.prototype._collectBuffers=function(e,t,r,n,o){if(this._shouldExportNode(e)&&e instanceof x.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var s in a)if(q(s)){var i=a[s];o.setHasVertexColorAlpha(i,e.hasVertexAlpha);var u=i._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(i)&&c.push(i);var l=r.get(i)||[];r.set(i,l),-1===l.indexOf(e)&&l.push(e)}var h=e.morphTargetManager;if(h)for(var f=0;f<h.numTargets;f++){var p=h.getTarget(f);l=n.get(p)||[],n.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,g=e.getChildren();d<g.length;d++){var m=g[d];this._collectBuffers(m,t,r,n,o)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,o=new Map,a=0,s=e;a<s.length;a++){var i=s[a];this._collectBuffers(i,r,n,o,t)}for(var u=Array.from(r.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var a=r.get(e);if(!a)return"continue";var s=a[0].byteStride;if(a.some((function(e){return e.byteStride!==s})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var i=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=n.get(e),r=W(e,t),o=r.byteOffset,a=r.byteStride,s=r.componentCount,u=r.type,c=r.count,h=r.normalized;switch(r.kind){case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:(0,x.EnumerateFloatValues)(i,o,a,s,u,c,h,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var r=1/t;e[0]*=r,e[1]*=r,e[2]*=r}}));break;case x.VertexBuffer.ColorKind:var f=t.filter((function(e){return e.material instanceof x.StandardMaterial||null==e.material})).length;if(0==f)break;if(f!=t.length){x.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==x.VertexBuffer.UNSIGNED_BYTE&&x.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var p=new x.Color3,d=new x.Color4,g=l._babylonScene.getEngine().useExactSrgbConversions;(0,x.EnumerateFloatValues)(i,o,a,s,u,c,h,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,g),p.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0))}))}},c=0,h=a;c<h.length;c++)u(F=h[c]);if(t.convertToRightHanded){for(var f=0,p=a;f<p.length;f++){var d=W(F=p[f],n.get(F)),g=d.byteOffset,m=d.byteStride,_=d.componentCount,T=d.type,v=d.count,y=d.normalized;switch(C=d.kind){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:(0,x.EnumerateFloatValues)(i,g,m,_,T,v,y,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,i)}var b=l._bufferManager.createBufferView(i,s);t.setVertexBufferView(e,b);for(var M=new Map,w=0,A=a;w<A.length;w++){var R=W(F=A[w],n.get(F)),C=R.kind,E=R.totalVertices;switch(C){case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:if(F.type==x.VertexBuffer.FLOAT){var I=F.getFloatData(E);null!==I&&M.set(F,I)}}}0!==M.size&&x.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var V=0,S=Array.from(M.keys());V<S.length;V++){var F=S[V],B=M.get(F);if(B){for(var O=B.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(B.length),N=0;N<B.length;N++)P[N]=B[N];var U=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,F,U)}}},l=this,h=0,f=u;h<f.length;h++)c(f[h]);for(var p=0,d=Array.from(o.keys());p<d.length;p++){var g=d[p],m=o.get(g);if(m)for(var _=ae(g,m[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),T=0,v=m;T<v.length;T++){var y=v[T];t.bindMorphDataToMesh(y,_)}}},e.prototype._exportNodeAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h=this;return y(this,(function(f){switch(f.label){case 0:return void 0!==(n=this._nodeMap.get(e))?(t.includes(n)||t.push(n),[2]):[4,this._createNodeAsync(e,r)];case 1:(o=f.sent())&&(n=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),a={name:"runtime animations",channels:[],samplers:[]},s=[],this._babylonScene.animationGroups.length||(oe._CreateMorphTargetAnimationFromMorphTargetAnimations(e,a,s,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&oe._CreateNodeAnimationFromNodeAnimations(e,a,s,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation)),a.channels.length&&a.samplers.length&&this._animations.push(a),s.forEach((function(e){e.channels.length&&e.samplers.length&&h._animations.push(e)}))),i=o?[]:t,u=0,c=e.getChildren(),f.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,i,r)]):[3,5];case 3:f.sent(),f.label=4;case 4:return u++,[3,2];case 5:return o&&i.length&&(o.children=i),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c,l,h,f,p;return y(this,(function(d){switch(d.label){case 0:return this._shouldExportNode(e)?(r={},e.name&&(r.name=e.name),e.metadata&&(n=this._options.metadataSelector(e.metadata))&&(r.extras=n),e instanceof x.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof x.AbstractMesh?(o=e instanceof x.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(a=r,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:a.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(s=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(s)&&this._nodesSkinMap.set(s,[]),null===(h=this._nodesSkinMap.get(s))||void 0===h||h.push(r)),d.label=3;case 3:if(e instanceof x.TargetCamera&&(i=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(i)&&this._nodesCameraMap.set(i,[]),this._setCameraTransformation(r,e,t.convertToRightHanded),null!==(u=e.parent)&&Y(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],X(r,l),null===(f=this._nodesCameraMap.get(i))||void 0===f||f.push(l),[2,null];null===(p=this._nodesCameraMap.get(i))||void 0===p||p.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,r]:(x.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,r,n,o,a,s,i,u){var c=null;u.mode=function(e){switch(e){case x.Material.TriangleFillMode:return 4;case x.Material.TriangleStripDrawMode:return 5;case x.Material.TriangleFanDrawMode:return 6;case x.Material.PointListDrawMode:case x.Material.PointFillMode:return 0;case x.Material.LineLoopDrawMode:return 2;case x.Material.LineListDrawMode:return 1;case x.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}(a);var l=s!==x.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case x.Material.TriangleFillMode:case x.Material.TriangleStripDrawMode:case x.Material.TriangleFanDrawMode:return!0}return!1}(a);if(l){if(a===x.Material.TriangleStripDrawMode||a===x.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");var h=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var f=0;f+2<n;f+=3)h[f]=e[r+f]+o,h[f+1]=e[r+f+2]+o,h[f+2]=e[r+f+1]+o;else for(f=0;f+2<n;f+=3)h[f]=f,h[f+1]=f+2,h[f+2]=f+1;c=h}else if(e&&0!==o){for(h=t?new Uint32Array(n):new Uint16Array(n),f=0;f<n;f++)h[f]=e[r+f]+o;c=h}else e&&(c=function(e,t,r,n){var o=e;return 0===t&&r===e.length||(o=Array.isArray(e)?e.slice(t,t+r):e.subarray(t,t+r)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?n?new Uint32Array(o):new Uint16Array(o):o}(e,r,n,t));if(c){var p=i.getIndicesAccessor(e,r,n,o,l);if(void 0===p){var d=this._bufferManager.createBufferView(c),g=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(d,"SCALAR",g,n,0)),p=this._accessors.length-1,i.setIndicesAccessor(e,r,n,o,l,p)}u.indices=p}},e.prototype._exportVertexBuffer=function(e,t,r,n,o,a){var s=e.getKind();if(q(s)&&(!s.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var i=o.getVertexAccessor(e,r,n);if(void 0===i){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=s===x.VertexBuffer.PositionKind?function(e,t,r,n){var o=t.byteOffset,a=t.byteStride,s=t.type,i=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,x.EnumerateFloatValues)(e,o+r*a,a,u,s,n*u,i,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,r,n):void 0,l=(s===x.VertexBuffer.MatricesIndicesKind||s===x.VertexBuffer.MatricesIndicesExtraKind)&&e.type===x.VertexBuffer.FLOAT,h=l?x.VertexBuffer.UNSIGNED_BYTE:e.type,f=l?void 0:e.normalized,p=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(p,function(e,t){if(e==x.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:return"VEC3";case x.VertexBuffer.TangentKind:case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:case x.VertexBuffer.MatricesWeightsKind:case x.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case x.VertexBuffer.UVKind:case x.VertexBuffer.UV2Kind:case x.VertexBuffer.UV3Kind:case x.VertexBuffer.UV4Kind:case x.VertexBuffer.UV5Kind:case x.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(s,o.hasVertexColorAlpha(e)),h,n,d,c,f)),i=this._accessors.length-1,o.setVertexAccessor(e,r,n,i)}a.attributes[function(e){switch(e){case x.VertexBuffer.PositionKind:return"POSITION";case x.VertexBuffer.NormalKind:return"NORMAL";case x.VertexBuffer.TangentKind:return"TANGENT";case x.VertexBuffer.ColorKind:return"COLOR_0";case x.VertexBuffer.UVKind:return"TEXCOORD_0";case x.VertexBuffer.UV2Kind:return"TEXCOORD_1";case x.VertexBuffer.UV3Kind:return"TEXCOORD_2";case x.VertexBuffer.UV4Kind:return"TEXCOORD_3";case x.VertexBuffer.UV5Kind:return"TEXCOORD_4";case x.VertexBuffer.UV6Kind:return"TEXCOORD_5";case x.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case x.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case x.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case x.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(s)]=i}},e.prototype._exportMaterialAsync=function(e,t,r,n){return v(this,void 0,void 0,(function(){var o,a;return y(this,(function(s){switch(s.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,8]:(a=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof x.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof x.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,a)]:[3,2]);case 1:return o=s.sent(),[3,7];case 2:return e instanceof x.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,a)]:[3,4];case 3:return o=s.sent(),[3,7];case 4:return e instanceof x.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,a)]:[3,6];case 5:return o=s.sent(),[3,7];case 6:return x.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,o),s.label=8;case 8:return n.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c,l,h,f,p,d,g,m,_,T,v,M,w,A,R,C,E,I,V,S,F,B,O,P,N,U,L;return y(this,(function(y){switch(y.label){case 0:if(void 0!==(r=t.getMesh(e)))return[2,r];if(n={primitives:[]},r=this._meshes.length,this._meshes.push(n),t.setMesh(e,r),o=e.isUnIndexed?null:e.getIndices(),a=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),s=t.getMorphTargetsFromMesh(e),i=e instanceof x.LinesMesh,u=e instanceof x.GreasedLineBaseMesh,c=e.subMeshes,!(a&&c&&c.length>0))return[3,7];l=0,h=c,y.label=1;case 1:return l<h.length?(f=h[l],p={attributes:{}},d=f.getMaterial()||this._babylonScene.defaultMaterial,u?(T={name:d.name},v=e,g=x.Color3.White(),m=null!==(P=null===(O=v.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(_=null!==(U=null===(N=v.greasedLineMaterial)||void 0===N?void 0:N.color)&&void 0!==U?U:g).equalsWithEpsilon(g,x.Epsilon)||m<1)&&(T.pbrMetallicRoughness={baseColorFactor:b(b([],_.asArray(),!0),[m],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return i?(T={name:d.name},(!(v=e).color.equalsWithEpsilon(x.Color3.White(),x.Epsilon)||v.alpha<1)&&(T.pbrMetallicRoughness={baseColorFactor:b(b([],v.color.asArray(),!0),[v.alpha],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,a,f,p)];case 4:y.sent(),y.label=5;case 5:for(M=i||u?x.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,w=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(w=w===x.Material.ClockWiseSideOrientation?x.Material.CounterClockWiseSideOrientation:x.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,x.AreIndices32Bits)(o,f.indexCount,f.indexStart,f.verticesStart):f.verticesCount>65535,o?f.indexStart:f.verticesStart,o?f.indexCount:f.verticesCount,-f.verticesStart,M,w,t,p),A=0,R=Object.values(a);A<R.length;A++)C=R[A],this._exportVertexBuffer(C,d,f.verticesStart,f.verticesCount,t,p);if(s)for(p.targets=[],E=0,I=s;E<I.length;E++)F=I[E],p.targets.push(F.attributes);n.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),y.label=6;case 6:return l++,[3,1];case 7:if(s)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],V=0,S=s;V<S.length;V++)F=S[V],n.weights.push(F.influence),n.extras.targetNames.push(F.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),ue=function(){function e(){}return e.GLTFAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o;return y(this,(function(a){switch(a.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(n=new ie(e,r)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.sent(),n.dispose(),[2,o]}}))}))},e.GLBAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o;return y(this,(function(a){switch(a.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(n=new ie(e,r)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.sent(),n.dispose(),[2,o]}}))}))},e}(),ce="EXT_mesh_gpu_instancing";function le(e,t){for(var r=new Float32Array(3*t),n=0;n<t;n++)r[3*n+0]=e[4*n+0],r[3*n+1]=e[4*n+1],r[3*n+2]=e[4*n+2];return r}var he=function(){function e(e){this.name=ce,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,r,n,o,a){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var s,i;if(t&&r instanceof x.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var u=x.Vector3.Zero(),c=x.Quaternion.Identity(),l=x.Vector3.One(),h=r.thinInstanceGetWorldMatrices(),f=x.TmpVectors.Vector3[2],p=x.TmpVectors.Quaternion[1],d=x.TmpVectors.Vector3[3],g=!1,m=!1,_=!1,T=new Float32Array(3*r.thinInstanceCount),v=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),b=0,M=0,w=h;M<w.length;M++)w[M].decompose(d,p,f),o&&(H(f),j(p)),T.set(f.asArray(),3*b),v.set(p.normalize().asArray(),4*b),y.set(d.asArray(),3*b),g=g||!f.equalsWithEpsilon(u),m=m||!p.equalsWithEpsilon(c),_=_||!d.equalsWithEpsilon(l),b++;var A={attributes:{}};g&&(A.attributes.TRANSLATION=e._buildAccessor(T,"VEC3",r.thinInstanceCount,a)),m&&(A.attributes.ROTATION=e._buildAccessor(v,"VEC4",r.thinInstanceCount,a)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,a));var R=null===(i=null===(s=r._userThinInstanceBuffersStorage)||void 0===s?void 0:s.data)||void 0===i?void 0:i.instanceColor;if(R){var C=r.thinInstanceCount;r.hasVertexAlpha&&R.length===4*C?(e._instanceColorWarned||(x.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),R=le(R,C)):R.length===4*C&&(R=le(R,C)),R.length===3*C&&(A.attributes._COLOR_0=e._buildAccessor(R,"VEC3",C,a))}t.extensions=t.extensions||{},t.extensions[ce]=A}n(t)}))];case 1:return[2,n.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,r,n){var o=n.createBufferView(e),a=n.createAccessor(o,t,5126,r);return this._exporter._accessors.push(a),this._exporter._accessors.length-1},e}();ie.RegisterExtension(ce,(function(e){return new he(e)}));var fe="KHR_draco_mesh_compression",pe=function(){function e(e){this.name=fe,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&x.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,r){var n=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],a=[],s=null;if(void 0!==e.indices){var i=r[e.indices],u=t.getBufferView(i);s=t.getData(u).slice(),o.push(u),a.push(i)}for(var c,l=[],h=0,f=Object.entries(e.attributes);h<f.length;h++){var p=f[h],d=p[0],g=(i=r[p[1]],u=t.getBufferView(i),D(i.type)),m=(0,x.GetTypedArrayData)(t.getData(u),g,i.componentType,i.byteOffset||0,u.byteStride||(0,x.GetTypeByteLength)(i.componentType)*g,i.count,!0);l.push({kind:d,dracoName:(c=d,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:D(i.type),data:m}),o.push(u),a.push(i)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},T=x.DracoEncoder.Default._encodeAsync(l,s,_).then((function(r){if(r){var s={bufferView:-1,attributes:r.attributeIds},i=t.createBufferView(r.data);t.setBufferView(s,i);for(var u=0,c=o;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var h=0,f=a;h<f.length;h++){var p=f[h];n._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[fe]=s}else x.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){x.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(T),this._wasUsed=!0}else x.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return v(this,void 0,void 0,(function(){var t=this;return y(this,(function(r){switch(r.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return r.sent(),this._bufferViewsUsed.forEach((function(r){e.getPropertiesWithBufferView(r).every((function(e){return t._accessorsUsed.has(e)}))&&e.removeBufferView(r)})),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}}))}))},e}();ie.RegisterExtension(fe,(function(e){return new pe(e)}));var de="KHR_lights_punctual",xe={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},ge={innerConeAngle:0,outerConeAngle:Math.PI/4},me=x.Vector3.Backward(),_e=function(){function e(e){this.name=de,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[de]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a=this;return y(this,(function(s){switch(s.label){case 0:return[4,new Promise((function(s){if(r instanceof x.Light){var i=r.getTypeID()==x.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==x.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==x.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(i&&r instanceof x.ShadowLight))return x.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(de)),void s(t);if(r.falloffType!==x.Light.FALLOFF_GLTF&&x.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(de," specification!")),!r.position.equalsToFloats(0,0,0)){var u=x.TmpVectors.Vector3[0].copyFrom(r.position);o&&H(u),t.translation=u.asArray()}if("point"!==i){var c=r.direction.normalizeToRef(x.TmpVectors.Vector3[0]);o&&H(c);var l=x.Quaternion.FromUnitVectorsToRef(me,c,x.TmpVectors.Quaternion[0]);x.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var h={type:i,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(Z(h,xe),"spot"===i){var f=r;h.spot={innerConeAngle:f.innerAngle/2,outerConeAngle:f.angle/2},Z(h.spot,ge)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(h);var p={light:a._lights.lights.length-1},d=r.parent;if(d&&Y(r,d)){var g=n.get(d);if(g){var m=a._exporter._nodes[g];return X(t,m),m.extensions||(m.extensions={}),m.extensions[de]=p,void s(null)}}t.extensions||(t.extensions={}),t.extensions[de]=p,s(t)}else s(t)}))];case 1:return[2,s.sent()]}}))}))},e}();ie.RegisterExtension(de,(function(e){return new _e(e)}));var Te="EXT_lights_area",ve={name:"",color:[1,1,1],intensity:1,size:1},ye={aspect:1},be=x.Vector3.Backward(),Me=function(){function e(e){this.name=Te,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[Te]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a=this;return y(this,(function(s){switch(s.label){case 0:return[4,new Promise((function(s){if(r instanceof x.Light){var i=r.getTypeID()==x.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!i)return x.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(Te)),void s(t);var u=r;if(u.falloffType!==x.Light.FALLOFF_GLTF&&x.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(Te," specification!")),!u.position.equalsToFloats(0,0,0)){var c=x.TmpVectors.Vector3[0].copyFrom(u.position);o&&H(c),t.translation=c.asArray()}var l=x.Vector3.Forward();o&&H(l);var h=x.Quaternion.FromUnitVectorsToRef(be,l,x.TmpVectors.Quaternion[0]);x.Quaternion.IsIdentity(h)||(t.rotation=h.asArray());var f={type:i,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};Z(f,ve),f.rect&&Z(f.rect,ye),a._lights||(a._lights={lights:[]}),a._lights.lights.push(f);var p={light:a._lights.lights.length-1},d=r.parent;if(d&&Y(u,d)){var g=n.get(d);if(g){var m=a._exporter._nodes[g];return X(t,m),m.extensions||(m.extensions={}),m.extensions[Te]=p,void s(null)}}t.extensions||(t.extensions={}),t.extensions[Te]=p,s(t)}else s(t)}))];case 1:return[2,s.sent()]}}))}))},e}();ie.RegisterExtension(Te,(function(e){return new Me(e)}));var we="KHR_materials_anisotropy";function Ae(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r||n?[4,(0,x.MergeTexturesAsync)("AnisotropyTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(0),r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}}))}))}var Re=function(){function e(e){this.name=we,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n;return y(this,(function(o){switch(o.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&e.push(r.anisotropy.texture),[2,e]):[3,5]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0?(t=function(e){var t=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoTangent";return"".concat(n,"_").concat(o)}(r),this._anisoTexturesMap[t]?(e.push(this._anisoTexturesMap[t]),[3,4]):[3,2]):[3,5];case 2:return[4,Ae(r)];case 3:(n=o.sent())&&(e.push(n),this._anisoTexturesMap[t]=n),o.label=4;case 4:return[2,e];case 5:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,s,i,u,c;if(r instanceof x.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var l=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture);null!==(T={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[we]=T}else if(r instanceof x.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){n._wasUsed=!0,t.extensions=t.extensions||{};var h=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(h=r.baseMetalnessTexture);var f=n._anisoTexturesMap[r.id];if(!h&&!f){var p=r.specularRoughness,d=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var g=(a=r.specularRoughness,c=(1-(s=r.specularRoughnessAnisotropy))*(u=(i=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-i)/Math.max(1-i,1e-4)),1)});p=g.newBaseRoughness,d=g.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=p);var m={anisotropyStrength:d,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[we]=m,e(t)}var _=f?n._exporter._materialExporter.getTextureInfo(f):null,T={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};r._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=n._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&n._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),n._exporter._materialNeedsUVsSet.add(r),t.extensions[we]=T}e(t)}))},e}();ie.RegisterExtension(we,(function(e){return new Re(e)}));var Ce="KHR_materials_clearcoat";function Ee(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("CoatTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useCoatRoughnessFromGreenChannel?1:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Ie(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var Ve=function(){function e(e){this.name=Ce,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o;return y(this,(function(a){switch(a.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.clearCoat.isEnabled?(r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),[2,e]):[3,5]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.coatWeight>0?(t=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):t=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):t=!0),t?(n=function(e){var t=e.coatWeightTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",n=e.coatRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoRoughness";return"".concat(r,"_").concat(o)}(r),this._cachedInternalTexturesMap[n]?[3,3]:[4,Ee(r)]):[3,4]):[3,5];case 2:(o=a.sent())&&(this._cachedInternalTexturesMap[n]=o),a.label=3;case 3:this._cachedInternalTexturesMap[n]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]))),a.label=4;case 4:return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),[2,e];case 5:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o,a=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);o=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&x.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&x.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture);null===(c={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ce]=c}else if(r instanceof x.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i=null,u=void 0;r.coatWeightTexture&&(i=n._mergedTexturesMap[r.coatWeightTexture.uniqueId],u=n._exporter._materialExporter.getTextureInfo(i));var c,l=null,h=void 0;r.coatRoughnessTexture&&(l=n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],h=n._exporter._materialExporter.getTextureInfo(l)),r.coatColorTexture&&x.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),s=n._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),null===(c={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=u?u:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=h?h:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ce]=c}e(t)}))},e}();ie.RegisterExtension(Ce,(function(e){return new Ve(e)}));var Se="KHR_materials_coat";function Fe(e){var t=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoTangent";return"".concat(n,"_").concat(o)}function Be(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r||n?[4,(0,x.MergeTexturesAsync)("AnisotropyTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(0),r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}}))}))}function Oe(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("CoatTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useCoatRoughnessFromGreenChannel?1:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Pe(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var Ne=function(){function e(e){this.name=Se,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o,a;return y(this,(function(s){switch(s.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.clearCoat.isEnabled?(r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),r.clearCoat.tintTexture&&e.push(r.clearCoat.tintTexture),[2,e]):[3,9]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.coatWeight>0?(t=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):t=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):t=!0),t?(o=function(e){var t=e.coatWeightTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",n=e.coatRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoRoughness";return"".concat(r,"_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,3]:[4,Oe(r)]):[3,4]):[3,9];case 2:(n=s.sent())&&(this._cachedInternalTexturesMap[o]=n),s.label=3;case 3:this._cachedInternalTexturesMap[o]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[o],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[o],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]))),s.label=4;case 4:return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatColorTexture&&e.push(r.coatColorTexture),r.coatRoughnessAnisotropy>0?(o=Fe(r),this._mergedTexturesMap[o]?(e.push(this._mergedTexturesMap[o]),[3,7]):[3,5]):[3,8];case 5:return[4,Be(r)];case 6:(a=s.sent())&&(e.push(a),this._mergedTexturesMap[o]=a),s.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,s,i,u,c;if(r instanceof x.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var l,h=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);l=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness);var f=void 0;r.clearCoat.isTintEnabled&&(f=n._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));var p=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),d=r.clearCoat.indexOfRefraction;null===(T={coatFactor:r.clearCoat.intensity,coatTexture:null!=h?h:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=l?l:void 0,coatNormalTexture:null!=p?p:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==d?d:void 0}).coatTexture&&null===T.coatRoughnessTexture&&null===T.coatRoughnessTexture&&null===T.coatColorTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Se]=T}else if(r instanceof x.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var g=null;h=void 0,r.coatWeightTexture&&(g=n._mergedTexturesMap[r.coatWeightTexture.uniqueId]?n._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,h=n._exporter._materialExporter.getTextureInfo(g));var m=null,_=void 0;r.coatRoughnessTexture&&(m=n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,_=n._exporter._materialExporter.getTextureInfo(m)),p=n._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),f=n._exporter._materialExporter.getTextureInfo(r.coatColorTexture),d=r.coatIor;var T,v=r.coatDarkening,y=r.coatRoughnessTexture,b=Fe(r),M=n._mergedTexturesMap[b],w=0,A=0,R=void 0;if(r.coatRoughnessAnisotropy>0){if(y||M){var C=M?n._exporter._materialExporter.getTextureInfo(M):null;w=r.coatRoughnessAnisotropy,A=r.geometryCoatTangentAngle,R=C||void 0}else{var E=r.coatRoughness,I=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var V=(a=r.coatRoughness,c=(1-(s=r.coatRoughnessAnisotropy))*(u=(i=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-i)/Math.max(1-i,1e-4)),1)});E=V.newBaseRoughness,I=V.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=E),w=I,A=r.geometryCoatTangentAngle+.5*Math.PI,R=void 0}r._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=n._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&n._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(T={coatFactor:r.coatWeight,coatTexture:null!=h?h:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=_?_:void 0,coatNormalTexture:null!=p?p:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==d?d:void 0,coatDarkeningFactor:1!==v?v:void 0,coatAnisotropyRotation:A,coatAnisotropyStrength:w,coatAnisotropyTexture:R}).coatTexture&&null===T.coatRoughnessTexture&&null===T.coatRoughnessTexture&&null===T.coatAnisotropyTexture&&null===T.coatColorTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Se]=T}e(t)}))},e}();ie.RegisterExtension(Se,(function(e){return new Ne(e)}));var Ue="KHR_materials_diffuse_transmission";function Le(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(x.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var ke=function(){function e(e){this.name=Ue,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var t,n;return y(this,(function(o){return t=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?((n=Le(e,r))&&t.push(n),r.subSurface.translucencyColorTexture&&t.push(r.subSurface.translucencyColorTexture),[2,t]):[2,t]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(o){var a,s;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,u=Le(e,r),c=0==i.translucencyIntensity?void 0:i.translucencyIntensity,l=null!==(a=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0,h=!i.translucencyColor||i.translucencyColor.equalsFloats(1,1,1)?void 0:i.translucencyColor.asArray(),f=null!==(s=n._exporter._materialExporter.getTextureInfo(i.translucencyColorTexture))&&void 0!==s?s:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:h,diffuseTransmissionColorTexture:f};(l||f)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Ue]=p}o(t)}))},e}();ie.RegisterExtension(Ue,(function(e){return new ke(e)}));var Ke="KHR_materials_dispersion",ze=function(){function e(){this.name=Ke,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ke]=o}e(t)}))},e}();ie.RegisterExtension(Ke,(function(){return new ze}));var We="KHR_materials_emissive_strength",De=function(){function e(){this.name=We,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(!(r instanceof x.PBRMaterial))return n(t);var o=r.emissiveColor.scale(r.emissiveIntensity),a=Math.max.apply(Math,o.asArray());if(a>1){t.emissiveFactor=o.scale(1/a).asArray(),e._wasUsed=!0;var s={emissiveStrength:a};t.extensions||(t.extensions={}),t.extensions[We]=s}else t.emissiveFactor=o.asArray();return n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(We,(function(){return new De}));var qe="KHR_materials_ior",Ge=function(){function e(){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[qe]=o}e(t)}))},e}();ie.RegisterExtension(qe,(function(e){return new Ge}));var He="KHR_materials_iridescence",je=function(){function e(e){this.name=He,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){if(e=[],r instanceof x.PBRBaseMaterial){if(r.iridescence.isEnabled)return r.iridescence.texture&&e.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&e.push(r.iridescence.thicknessTexture),[2,e]}else if(r instanceof x.OpenPBRMaterial&&r.thinFilmWeight>0)return r.thinFilmWeightTexture&&e.push(r.thinFilmWeightTexture),r.thinFilmThicknessTexture&&r.thinFilmThicknessTexture!==r.thinFilmWeightTexture&&e.push(r.thinFilmThicknessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),a=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture);null===(s={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=a?a:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=s}else if(r instanceof x.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s,i=n._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),u=n._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture);null===(s={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=i?i:void 0,iridescenceThicknessTexture:null!=u?u:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=s}e(t)}))},e}();ie.RegisterExtension(He,(function(e){return new je(e)}));var Qe="KHR_materials_sheen",Xe=function(){function e(e){this.name=Qe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){return y(this,(function(e){return r instanceof x.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[2,[r.sheen.texture]]:[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var o,a,s,i;if(r instanceof x.PBRMaterial){if(!r.sheen.isEnabled)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=r.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),t.extensions[Qe]=u}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(Qe,(function(e){return new Xe(e)}));var Ye="KHR_materials_fuzz";function Ze(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.fuzzColorTexture,n=e.fuzzRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("FuzzTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,1):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,2):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useFuzzRoughnessFromTextureAlpha?3:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Je(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var $e=function(){function e(e){this.name=Ye,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o;return y(this,(function(a){switch(a.label){case 0:return r instanceof x.OpenPBRMaterial?(e=[],r.fuzzWeight>0?(r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture),t=!1,r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):t=!0),r.fuzzColorTexture&&!t&&e.push(r.fuzzColorTexture),t?(n=function(e){var t=e.fuzzColorTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",n=e.fuzzRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(r,"_FuzzRoughness_").concat(o)}(r),this._cachedInternalTexturesMap[n]?[3,2]:[4,Ze(r)]):[3,3]):[3,3]):[3,4];case 1:(o=a.sent())&&(this._cachedInternalTexturesMap[n]=o),a.label=2;case 2:this._cachedInternalTexturesMap[n]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=Je(this._cachedInternalTexturesMap[n],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=Je(this._cachedInternalTexturesMap[n],r.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]))),a.label=3;case 3:return[2,e];case 4:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var o,a,s;if(r instanceof x.OpenPBRMaterial){if(0==r.fuzzWeight)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var i={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};r.fuzzWeightTexture&&(i.fuzzTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==o?o:void 0);var u=null;r.fuzzColorTexture&&(u=e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,i.fuzzColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0);var c=null;r.fuzzRoughnessTexture&&(c=e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,i.fuzzRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==s?s:void 0),null===i.fuzzColorTexture&&null===i.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),t.extensions[Ye]=i}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(Ye,(function(e){return new $e(e)}));var et="KHR_materials_specular",tt=function(){function e(e){this.name=et,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){return e=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.reflectanceTexture),[2,e]):[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,s,i,u;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(o=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,l=null!==(a=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,h={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:c,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:l};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[et]=h}else if(r instanceof x.OpenPBRMaterial){t.extensions=t.extensions||{};var f=null!==(s=n._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==s?s:void 0,p=null!==(i=n._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==i?i:void 0,d=1==r.specularWeight?void 0:r.specularWeight,g=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!p&&!f&&void 0===d&&void 0===g)return e(t);n._wasUsed=!0,(h={specularFactor:d,specularTexture:f,specularColorFactor:g,specularColorTexture:p,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=n._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(f||p)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[et]=h}e(t)}))},e}();ie.RegisterExtension(et,(function(e){return new tt(e)}));var rt="KHR_materials_transmission",nt=function(){function e(e){this.name=rt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){return e=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||this._hasTexturesExtension(e)},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.refractionIntensityTexture},e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s;return y(this,(function(i){switch(i.label){case 0:return r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(this._wasUsed=!0,n=r.subSurface,o=0===n.refractionIntensity?void 0:n.refractionIntensity,a={transmissionFactor:o},this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),n.refractionIntensityTexture?n.useGltfStyleTextures?[4,this._exporter._materialExporter.exportTextureAsync(n.refractionIntensityTexture)]:[3,2]:[3,3]):[3,4];case 1:return(s=i.sent())&&(a.transmissionTexture=s),[3,3];case 2:x.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported")),i.label=3;case 3:t.extensions||(t.extensions={}),t.extensions[rt]=a,i.label=4;case 4:return[2,t]}}))}))},e}();ie.RegisterExtension(rt,(function(e){return new nt(e)}));var ot="KHR_materials_unlit",at=function(){function e(){this.name=ot,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o=!1;r instanceof x.PBRMaterial?o=r.unlit:r instanceof x.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ot]={}),e(t)}))},e}();ie.RegisterExtension(ot,(function(){return new at}));var st="KHR_materials_volume",it=function(){function e(e){this.name=st,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){return e=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]):[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=x.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,s={thicknessFactor:0==a.maximumThickness?void 0:a.maximumThickness,thicknessTexture:null!==(o=n._exporter._materialExporter.getTextureInfo(a.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:a.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:a.tintColorAtDistance,attenuationColor:a.tintColor.equalsFloats(1,1,1)?void 0:a.tintColor.asArray()};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[st]=s}e(t)}))},e}();ie.RegisterExtension(st,(function(e){return new it(e)}));var ut="KHR_materials_diffuse_roughness",ct=function(){function e(e){this.name=ut,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){if(e=[],r instanceof x.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),[2,e]}else if(r instanceof x.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o=null,a=null;if(r instanceof x.PBRBaseMaterial?(o=r._baseDiffuseRoughness,a=r._baseDiffuseRoughnessTexture):r instanceof x.OpenPBRMaterial&&(o=r.baseDiffuseRoughness,a=r.baseDiffuseRoughnessTexture),o){n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(a),i={diffuseRoughnessFactor:o,diffuseRoughnessTexture:null!=s?s:void 0};null!==i.diffuseRoughnessTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[ut]=i,e(t)}else e(t)}))},e}();ie.RegisterExtension(ut,(function(e){return new ct(e)}));var lt="KHR_texture_transform",ht=function(){function e(){this.name=lt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,r){if(r.getScene()||x.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with rotation in the u or v axis is not supported in glTF.")),0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(lt,"."));x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(lt,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,o=e.vRotationCenter,a=e.uScale,s=e.vScale,i=e.wAng,u=Math.cos(i),c=Math.sin(i),l=n*a,h=o*s;return[t+(l*(1-u)+h*c),r+(h*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,o=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[lt]=n)}},e}();ie.RegisterExtension(lt,(function(){return new ht}));var ft="KHR_texture_basisu",pt=function(){function e(e){this.name=ft,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/ktx2"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[ft]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(ft,(function(e){return new pt(e)}));var dt="EXT_texture_webp",xt=function(){function e(e){this.name=dt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/webp"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[dt]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(dt,(function(e){return new xt(e)}));var gt="EXT_texture_avif",mt=function(){function e(e){this.name=gt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/avif"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[gt]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(gt,(function(e){return new mt(e)}));var _t=function(){function e(){}return e.CreateSTL=function(e,t,r,n,o,a,s,i){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===a&&(a=!1),void 0===s&&(s=!1),void 0===i&&(i=!1);var u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],o=[new x.Vector3(t[n[0]],t[n[0]+2],t[n[0]+1]),new x.Vector3(t[n[1]],t[n[1]+2],t[n[1]+1]),new x.Vector3(t[n[2]],t[n[2]+2],t[n[2]+1])],a=o[0].subtract(o[1]),s=o[2].subtract(o[1]);return{v:o,n:x.Vector3.Cross(s,a).normalize()}},c=function(e,t,r,n){return t=l(e,t,r.x,n),t=l(e,t,r.y,n),l(e,t,r.z,n)},l=function(e,t,r,n){return e.setFloat32(t,r,n),t+4},h=function(e){if(s){var t=e;e instanceof x.InstancedMesh&&(t=e.sourceMesh);var r=t.getVerticesData(x.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var n=x.Vector3.Zero(),o=void 0;for(o=0;o<r.length;o+=3)x.Vector3.TransformCoordinatesFromFloatsToRef(r[o],r[o+1],r[o+2],e.computeWorldMatrix(!0),n).toArray(r,o);return r}return e.getVerticesData(x.VertexBuffer.PositionKind)||[]};s&&(a=!0);var f="",p=0,d=0;if(n){for(var g=0;g<e.length;g++)p+=(v=(_=e[g]).getIndices())?v.length/3:0;var m=new ArrayBuffer(84+50*p);d+=80,(f=new DataView(m)).setUint32(d,p,o),d+=4}else i||(f="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!n&&i&&(f+="solid "+_.name+"\r\n"),!a&&_ instanceof x.Mesh&&_.bakeCurrentTransformIntoVertices();for(var T=h(_),v=_.getIndices()||[],y=0;y<v.length;y+=3){var b=u(v,T,y);n?(d=c(f,d,b.n,o),d=c(f,d,b.v[0],o),d=c(f,d,b.v[1],o),d=c(f,d,b.v[2],o),d+=2):(f+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",f+="\t\touter loop\r\n",f+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",f+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",f+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",f+="\t\tendloop\r\n",f+="\tendfacet\r\n")}!n&&i&&(f+="endsolid "+name+"\r\n")}if(n||i||(f+="endsolid stlmesh"),t){var M=document.createElement("a"),w=new Blob([f],{type:"application/octet-stream"});M.href=window.URL.createObjectURL(w),M.download=r+".stl",M.click()}return f},e}();function Tt(e,t,r,n){void 0===r&&(r=3),void 0===n&&(n=!1);for(var o=[],a=0;a<e.length/r;a++){var s=e[a*r]*(n?-1:1),i=e[a*r+1],u=e[a*r+2];o.push("(".concat(s.toPrecision(t.precision),", ").concat(i.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function vt(e,t){for(var r=[],n=0;n<e.length/2;n++){var o=e[2*n],a=e[2*n+1];r.push("(".concat(o.toPrecision(t.precision),", ").concat((1-a).toPrecision(t.precision),")"))}return r.join(", ")}function yt(e,t,r,n){var o=function(e,t,r,n){var o=e.getVerticesData(x.VertexBuffer.PositionKind),a=e.getVerticesData(x.VertexBuffer.NormalKind);if(o&&a)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(r,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,r=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(r/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,r=e.getIndices(),n=null!==(t=null==r?void 0:r.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==r)for(var a=0;a<n;a++)o.push(r[a]);else for(a=0;a<n;a++)o.push(a);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(Tt(a,t,void 0,n),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(Tt(o,t,void 0,n),"]\n ").concat(function(e,t){for(var r="",n=0;n<4;n++){var o=n>0?n:"",a=e.getVerticesData(x.VertexBuffer.UVKind+(o?o+1:""));a&&(r+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(vt(a,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var s=e.getVerticesData(x.VertexBuffer.ColorKind);return s&&(r+="\n\tcolor3f[] primvars:displayColor = [".concat(Tt(s,t,s.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),r}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t,r,n);return'\n def "Geometry"\n {\n '.concat(o,"\n }\n ")}function bt(e){var t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function Mt(e){var t=e.m;return"( ".concat(wt(t,0),", ").concat(wt(t,4),", ").concat(wt(t,8),", ").concat(wt(t,12)," )")}function wt(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function At(e,t){var r="Object_"+e.uniqueId,n=Mt(t);return'def Xform "'.concat(r,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(n,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Rt(e){switch(e){case x.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case x.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case x.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function Ct(e){return"(".concat(e.x,", ").concat(e.y,")")}function Et(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function It(e,t,r,n,o,a){var s=e.getInternalTexture().uniqueId+"_"+e.invertY;o[s]=e;var i=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new x.Vector2(e.uScale,e.vScale),c=new x.Vector2(e.uOffset,e.vOffset),l=e.wAng,h=Math.sin(l),f=Math.cos(l);return c.y=1-c.y-u.y,c.x+=h*u.x,c.y+=(1-f)*u.y,'\n def Shader "PrimvarReader_'.concat(r,'"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "').concat(i,'"\n float2 outputs:result\n }\n\n def Shader "Transform2d_').concat(r,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_').concat(t.uniqueId,"/PrimvarReader_").concat(r,".outputs:result>\n float inputs:rotation = ").concat((l*(180/Math.PI)).toFixed(a.precision),"\n float2 inputs:scale = ").concat(Ct(u),"\n float2 inputs:translation = ").concat(Ct(c),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(r,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(s,".png@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(t.uniqueId,"/Transform2d_").concat(r,".outputs:result>\n ").concat(n?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(n):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(Rt(e.wrapU),'"\n token inputs:wrapT = "').concat(Rt(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(t.needAlphaBlending()||t.needAlphaTesting()?"float outputs:a":"","\n }")}function Vt(e,t,r){var n="\t\t\t",o=[],a=[],s=function(e){var t,r,n={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof x.StandardMaterial?T(T({},n),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof x.PBRBaseMaterial?T(T({},n),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(t=e._roughness)&&void 0!==t?t:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(r=e._metallic)&&void 0!==r?r:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):n}(e),i=s.diffuseMap,u=s.diffuse,c=s.alphaCutOff,l=s.emissiveMap,h=s.emissive,f=s.normalMap,p=s.roughnessMap,d=s.roughnessChannel,g=s.roughness,m=s.metalnessMap,_=s.metalnessChannel,v=s.metalness,y=s.aoMap,b=s.aoMapChannel,M=s.aoMapIntensity,w=s.alphaMap,A=s.ior,R=s.clearCoatEnabled,C=s.clearCoat,E=s.clearCoatMap,I=s.clearCoatRoughness,V=s.clearCoatRoughnessMap;return null!==i?(o.push("".concat(n,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(n,"float inputs:opacityThreshold = ").concat(c))),a.push(It(i,e,"diffuse",u,t,r))):o.push("".concat(n,"color3f inputs:diffuseColor = ").concat(Et(u||x.Color3.White()))),null!==l?(o.push("".concat(n,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),a.push(It(l,e,"emissive",h,t,r))):h&&h.toLuminance()>0&&o.push("".concat(n,"color3f inputs:emissiveColor = ").concat(Et(h))),null!==f&&(o.push("".concat(n,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(f.uniqueId,"_normal.outputs:rgb>")),a.push(It(f,e,"normal",null,t,r))),null!==y&&(o.push("".concat(n,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(y.uniqueId,"_occlusion.outputs:").concat(b,">")),a.push(It(y,e,"occlusion",new x.Color3(M,M,M),t,r))),null!==p?(o.push("".concat(n,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_roughness.outputs:").concat(d,">")),a.push(It(p,e,"roughness",new x.Color3(g,g,g),t,r))):o.push("".concat(n,"float inputs:roughness = ").concat(g)),null!==m?(o.push("".concat(n,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(m.uniqueId,"_metallic.outputs:").concat(_,">")),a.push(It(m,e,"metallic",new x.Color3(v,v,v),t,r))):o.push("".concat(n,"float inputs:metallic = ").concat(v)),null!==w?(o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(w.uniqueId,"_opacity.outputs:r>")),o.push("".concat(n,"float inputs:opacityThreshold = 0.0001")),a.push(It(w,e,"opacity",null,t,r))):o.push("".concat(n,"float inputs:opacity = ").concat(e.alpha)),R&&(null!==E?(o.push("".concat(n,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(E.uniqueId,"_clearcoat.outputs:r>")),a.push(It(E,e,"clearcoat",new x.Color3(C,C,C),t,r))):o.push("".concat(n,"float inputs:clearcoat = ").concat(C)),null!==V?(o.push("".concat(n,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(V.uniqueId,"_clearcoatRoughness.outputs:g>")),a.push(It(V,e,"clearcoatRoughness",new x.Color3(I,I,I),t,r))):o.push("".concat(n,"float inputs:clearcoatRoughness = ").concat(I))),o.push("".concat(n,"float inputs:ior = ").concat(A)),'\n\tdef Material "Material_'.concat(e.uniqueId,'"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n').concat(o.join("\n"),"\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(a.join("\n"),"\n\n\t}\n")}function St(e){var t,r;e.computeWorldMatrix(!0);for(var n=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,a=null!==(r=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==r?r:e.sideOrientation,s=!o,i=e.parent;i;){if(U(i,o)&&null===i.parent){o||(n.multiplyToRef(i.getWorldMatrix().invert(),n),a=a===x.Material.ClockWiseSideOrientation?x.Material.CounterClockWiseSideOrientation:x.Material.ClockWiseSideOrientation),s=!1;break}i=i.parent}return n.determinant()<0&&x.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:n,windingOrder:a===x.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:s}}function Ft(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h,f,p,d,g,m,_,v,b,M,w,A,R,C,E,I,V,S,F,B,O,P,N,U;return y(this,(function(y){switch(y.label){case 0:return n=T({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},t),"undefined"!=typeof fflate?[3,2]:[4,x.Tools.LoadScriptAsync(n.fflateUrl)];case 1:y.sent(),y.label=2;case 2:for((o={})[n.modelFileName]=null,a='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',a+=function(e){var t=!0===e.includeAnchoringProperties?'\n\t\ttoken preliminary:anchoring:type = "'.concat(e.anchoringType,'"\n\t\ttoken preliminary:planeAnchoring:alignment = "').concat(e.planeAnchoringAlignment,'"'):"";return'def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {'.concat(t,"\n ")}(n),s={},i=0,u=e.meshes;i<u.length;i++)0!==(c=u[i]).getTotalVertices()&&(h=(l=c).geometry,(f=l.material)&&h&&(!r||r(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(f.getClassName())?(p="geometries/Geometry_"+h.uniqueId+".usda",d=St(l),g=d.matrix,m=d.windingOrder,_=d.convertToRightHanded,p in o||(v=yt(h,n,m,_),o[p]=bt(v)),f.uniqueId in s||(s[f.uniqueId]=f),a+=At(l,g)):x.Tools.Warn("USDZExportAsync does not support this material type: "+f.getClassName())));for(A in e.activeCamera&&n.exportCamera&&(a+=function(e,t){var r="Camera_"+e.uniqueId,n=Mt(x.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===x.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(n,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(t.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var o=e.getEngine().getAspectRatio(e),a=t.cameraSensorWidth||35;return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(n,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat focalLength = ").concat((a/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((a*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((a/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,n)),a+="\n }\n }",a+=function(e,t,r){var n=[];for(var o in e){var a=e[o];n.push(Vt(a,t,r))}return'\n def "Materials"\n{\n'.concat(n.join(""),"\n}\n\n")}(s,b={},n),a+="\n }",o[n.modelFileName]=fflate.strToU8(a),w=[],M=b)w.push(A);R=0,y.label=3;case 3:return R<w.length?(A=w[R])in M?(E=b[C=A],I=E.getSize(),[4,(0,x.GetTextureDataAsync)(E)]):[3,6]:[3,7];case 4:return V=y.sent(),[4,x.DumpTools.DumpDataAsync(I.width,I.height,V,"image/png",void 0,!1,!0)];case 5:S=y.sent(),o["textures/Texture_".concat(C,".png")]=new Uint8Array(S).slice(),y.label=6;case 6:return R++,[3,3];case 7:for(B in F=0,o)(O=o[B])&&(P=34+B.length,4!=(N=63&(F+=P))&&(U=new Uint8Array(64-N),o[B]=[O,{extra:{12345:U}}]),F=O.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var Bt=function(){function e(){}return e.Export=function(e,t,r){var n;if(void 0===t&&(t=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var o=t;t&&0!==t.length||(o=e.animations.map((function(e){return e.name})));for(var a=null,s=0,i=o;s<i.length;s++){var u=i[s],c=e.getAnimationRange(u);c&&(a=a?new x.AnimationRange("animation-range",Math.min(a.from,c.from),Math.max(a.to,c.to)):c)}if(!a&&(e.animations.length>0&&(a=e.getAnimationRange(e.animations[0].name)),!a))throw new Error("No animation range found in skeleton");for(var l=r||1/((null===(n=e.animations[0])||void 0===n?void 0:n.framePerSecond)||30),h=this._BuildBoneHierarchy(e,o),f=0,p=0,d=h;p<d.length;p++){var g=d[p];g.positionKeys.length>0&&(f=Math.max(f,g.positionKeys.length)),g.rotationKeys.length>0&&(f=Math.max(f,g.rotationKeys.length))}0===f&&(f=Math.floor((a.to-a.from)/l)+1);var m="";return m+="HIERARCHY\n",m+=this._ExportHierarchy(h,0),m+="MOTION\n",m+="Frames: ".concat(f,"\n"),(m+="Frame Time: ".concat(l.toFixed(6),"\n"))+this._ExportMotionData(h,f,0,o)},e._BuildBoneHierarchy=function(e,t){for(var r,n,o=new Map,a=[],s=0,i=e.bones;s<i.length;s++){var u={bone:h=i[s],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};o.set(h,u)}for(var c=0,l=e.bones;c<l.length;c++){var h=l[c];if(u=o.get(h),h.animations.length>0)for(var f=0,p=h.animations;f<p.length;f++){var d=p[f];t.includes(d.name)&&("position"===d.targetProperty?(u.hasPositionChannels=!0,(r=u.positionKeys).push.apply(r,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(n=u.rotationKeys).push.apply(n,d.getKeys())))}if(h.getParent()){var x=o.get(h.getParent());x&&x.children.push(u)}else a.push(u)}return a},e._ExportHierarchy=function(e,t){for(var r="",n=" ".repeat(t),o=0,a=e;o<a.length;o++){var s=a[o],i=s.bone;if(this._IsEndSite(s)){r+="".concat(n,"End Site\n"),r+="".concat(n,"{\n");var u=this._GetBoneOffset(i);r+="".concat(n," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),r+="".concat(n,"}\n")}else{r+="".concat(0===t?"ROOT":"".concat(n,"JOINT")," ").concat(i.name,"\n"),r+="".concat(n,"{\n"),u=this._GetBoneOffset(i),r+="".concat(n," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];s.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),s.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(r+="".concat(n," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),s.children.length>0&&(r+=this._ExportHierarchy(s.children,t+1)),r+="".concat(n,"}\n")}}return r},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return x.Vector3.Zero()}},e._ExportMotionData=function(e,t,r,n){for(var o="",a=0;a<t;a++){var s=[];this._CollectFrameValues(e,a+r,s,n),o+=s.map((function(e){return e.toFixed(6)})).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,r,n){for(var o=0,a=e;o<a.length;o++){var s=a[o];if(!this._IsEndSite(s)){if(s.hasPositionChannels){var i=this._GetPositionAtFrameIndex(s.positionKeys,t);r.push(i.x,i.y,i.z)}if(s.hasRotationChannels){var u=this._GetRotationAtFrameIndex(s.rotationKeys,t),c=this._QuaternionToEuler(u);r.push(c.z,c.x,c.y)}s.children.length>0&&this._CollectFrameValues(s.children,t,r,n)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?x.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?x.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new x.Matrix;e.toRotationMatrix(t);var r,n,o,a=t.m,s=Math.sqrt(a[0]*a[0]+a[1]*a[1]);return s>x.Epsilon?(r=Math.atan2(a[6],a[10]),n=Math.atan2(-a[2],s),o=Math.atan2(a[1],a[0])):(r=Math.atan2(-a[9],a[5]),n=Math.atan2(-a[2],s),o=0),new x.Vector3(x.Tools.ToDegrees(r),x.Tools.ToDegrees(n),x.Tools.ToDegrees(o))},e}(),Ot=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Ot)for(var Pt in p)Ot.BABYLON[Pt]=p[Pt];var Nt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Nt){Nt.BABYLON=Nt.BABYLON||{};var Ut=Nt.BABYLON;Ut.GLTF2=Ut.GLTF2||{},Ut.GLTF2.Exporter=Ut.GLTF2.Exporter||{},Ut.GLTF2.Exporter.Extensions=Ut.GLTF2.Exporter.Extensions||{};var Lt=[];for(var kt in s)Ut[kt]=s[kt],Lt.push(kt);for(var kt in i)Ut[kt]=i[kt],Lt.push(kt);for(var kt in u)Ut[kt]=u[kt],Lt.push(kt);for(var kt in c)Ut.GLTF2.Exporter.Extensions[kt]=c[kt],Lt.push(kt);for(var kt in l)Lt.indexOf(kt)>-1||(Ut.GLTF2.Exporter[kt]=l[kt])}var Kt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Kt)for(var zt in a)Kt.BABYLON[zt]=a[zt];var Wt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Wt)for(var Dt in h)Wt.BABYLON[Dt]=h[Dt];var qt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==qt)for(var Gt in f)qt.BABYLON[Gt]=f[Gt];const Ht=d;return o.default})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.d(o,{default:()=>Yt});var a={};n.r(a),n.d(a,{OBJExport:()=>g});var s={};n.r(s),n.d(s,{__IGLTFExporterExtension:()=>m});var i={};n.r(i),n.d(i,{GLTFData:()=>_});var u={};n.r(u),n.d(u,{GLTF2Export:()=>ue});var c={};n.r(c),n.d(c,{EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>yt,EXT_texture_webp:()=>Tt,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Se,KHR_materials_coat:()=>Ue,KHR_materials_diffuse_roughness:()=>ht,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_openpbr:()=>pt,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_materials_volume_scatter:()=>ct,KHR_texture_basisu:()=>mt,KHR_texture_transform:()=>xt});var l={};n.r(l),n.d(l,{EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>yt,EXT_texture_webp:()=>Tt,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Se,KHR_materials_coat:()=>Ue,KHR_materials_diffuse_roughness:()=>ht,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_openpbr:()=>pt,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_materials_volume_scatter:()=>ct,KHR_texture_basisu:()=>mt,KHR_texture_transform:()=>xt,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>S});var h={};n.r(h),n.d(h,{STLExport:()=>bt});var f={};n.r(f),n.d(f,{USDZExportAsync:()=>Ut});var p={};n.r(p),n.d(p,{BVHExporter:()=>Nt});var d={};n.r(d),n.d(d,{BVHExporter:()=>Nt,EXT_lights_area:()=>Me,EXT_mesh_gpu_instancing:()=>he,EXT_texture_avif:()=>yt,EXT_texture_webp:()=>Tt,GLTF2Export:()=>ue,GLTFData:()=>_,KHR_draco_mesh_compression:()=>pe,KHR_lights_punctual:()=>_e,KHR_materials_anisotropy:()=>Re,KHR_materials_clearcoat:()=>Se,KHR_materials_coat:()=>Ue,KHR_materials_diffuse_roughness:()=>ht,KHR_materials_diffuse_transmission:()=>ke,KHR_materials_dispersion:()=>ze,KHR_materials_emissive_strength:()=>De,KHR_materials_fuzz:()=>$e,KHR_materials_ior:()=>Ge,KHR_materials_iridescence:()=>je,KHR_materials_openpbr:()=>pt,KHR_materials_sheen:()=>Xe,KHR_materials_specular:()=>tt,KHR_materials_transmission:()=>nt,KHR_materials_unlit:()=>at,KHR_materials_volume:()=>it,KHR_materials_volume_scatter:()=>ct,KHR_texture_basisu:()=>mt,KHR_texture_transform:()=>xt,OBJExport:()=>g,STLExport:()=>bt,USDZExportAsync:()=>Ut,_ConvertToGLTFPBRMetallicRoughness:()=>V,_SolveMetallic:()=>S,__IGLTFExporterExtension:()=>m});var x=n(597),g=function(){function e(){}return e.OBJ=function(e,t,r,n){var o=[],a=1,s=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var i=0;i<e.length;i++){var u=e[i],c=u.name||"mesh".concat(i,"}");o.push("o ".concat(c));var l=null;if(n){var h=u.computeWorldMatrix(!0);l=new x.Matrix,h.invertToRef(l),u.bakeTransformIntoVertices(h)}if(t){var f=u.material;f&&o.push("usemtl "+f.id)}var p=u.geometry;if(p){var d=p.getVerticesData("position"),g=p.getVerticesData("normal"),m=p.getVerticesData("uv"),_=p.getIndices(),T=0,v=0;if(d&&_){for(var y=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*y+" "+d[b+1]+" "+d[b+2]),T++;if(null!=g)for(b=0;b<g.length;b+=3)o.push("vn "+g[b]*y+" "+g[b+1]+" "+g[b+2]);if(null!=m)for(b=0;b<m.length;b+=2)o.push("vt "+m[b]+" "+m[b+1]),v++;var M=["","",""],w=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===x.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=w[0],R=w[1];for(b=0;b<_.length;b+=3){var C=[String(_[b]+a),String(_[b+A]+a),String(_[b+R]+a)],E=[String(_[b]+s),String(_[b+A]+s),String(_[b+R]+s)],I=C,S=null!=m?E:M,V=null!=g?C:M;o.push("f "+I[0]+"/"+S[0]+"/"+V[0]+" "+I[1]+"/"+S[1]+"/"+V[1]+" "+I[2]+"/"+S[2]+"/"+V[2])}n&&l&&u.bakeTransformIntoVertices(l),a+=T,s+=v}else x.Tools.Warn("There are no position vertices or indices on the mesh!")}else x.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],r=e.material;return t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4)),r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e}(),m=0,_=function(){function e(){this.files={}}return Object.defineProperty(e.prototype,"glTFFiles",{get:function(){return this.files},enumerable:!1,configurable:!0}),e.prototype.downloadFiles=function(){for(var e in this.files){var t=this.files[e],r=new Blob([t],{type:(0,x.GetMimeType)(e)});x.Tools.Download(r,e)}},e}(),T=function(){return T=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},T.apply(this,arguments)};function v(e,t,r,n){return new(r||(r=Promise))((function(o,a){function s(e){try{u(n.next(e))}catch(e){a(e)}}function i(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,i)}u((n=n.apply(e,t||[])).next())}))}function y(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=i(0),s.throw=i(1),s.return=i(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function b(e,t,r){if(r||2===arguments.length)for(var n,o=0,a=t.length;o<a;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var M=1e-6,w=new x.Color3(.04,.04,.04),A=1024,R=x.Color3.White(),C=x.Color3.BlackReadOnly;function E(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function I(e){return v(this,void 0,void 0,(function(){var t,r,n,o;return y(this,(function(a){switch(a.label){case 0:if(!(t=e.getInternalTexture())||1!==t.source)return[2,null];if(t.invertY)return[2,null];r=t._buffer,o=e.mimeType,a.label=1;case 1:return a.trys.push([1,12,,13]),r?[3,3]:[4,x.Tools.LoadFileAsync(t.url)];case 2:return n=a.sent(),o=(0,x.GetMimeType)(t.url)||o,[3,11];case 3:return ArrayBuffer.isView(r)?(n=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,11]):[3,4];case 4:return r instanceof ArrayBuffer?(n=r,[3,11]):[3,5];case 5:return r instanceof Blob?[4,r.arrayBuffer()]:[3,7];case 6:return n=a.sent(),o=r.type||o,[3,11];case 7:return"string"!=typeof r?[3,9]:[4,x.Tools.LoadFileAsync(r)];case 8:return n=a.sent(),o=(0,x.GetMimeType)(r)||o,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,x.Tools.LoadFileAsync(r.src)]:[3,11];case 10:n=a.sent(),o=(0,x.GetMimeType)(r.src)||o,a.label=11;case 11:return[3,13];case 12:return a.sent(),[2,null];case 13:return n&&E(o)?[2,new Blob([n],{type:o})]:[2,null]}}))}))}function S(e,t,r){if(t<w.r)return 0;var n=w.r,o=e*r/(1-w.r)+t-2*w.r,a=o*o-4*n*(w.r-t);return x.Scalar.Clamp((-o+Math.sqrt(a))/(2*n),0,1)}function V(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=x.Scalar.Clamp(e.specularPower,0,A),o=(0,x.SpecularPowerToRoughness)(n);return{baseColorFactor:[t.r,t.g,t.b,r],metallicFactor:0,roughnessFactor:o}}function F(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 x.RawTexture.CreateRGBATexture(n,e,t,r)}function O(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.uniqueId))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c;return y(this,(function(l){switch(l.label){case 0:return r=V(e),n={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||x.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),t?(o=[],(a=e.diffuseTexture)&&o.push(this.exportTextureAsync(a).then((function(e){e&&(r.baseColorTexture=e)}))),(s=e.bumpTexture)&&o.push(this.exportTextureAsync(s).then((function(e){e&&(n.normalTexture=e,1!==s.level&&(n.normalTexture.scale=s.level))}))),(i=e.emissiveTexture)&&(n.emissiveFactor=[1,1,1],o.push(this.exportTextureAsync(i).then((function(e){e&&(n.emissiveTexture=e)})))),(u=e.ambientTexture)&&o.push(this.exportTextureAsync(u).then((function(e){if(e){var t={index:e.index};n.occlusionTexture=t}}))),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===x.Constants.ALPHA_COMBINE?n.alphaMode="BLEND":x.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(C,M)&&(n.emissiveFactor=e.emissiveColor.asArray()),n.pbrMetallicRoughness=r,F(n,e),[4,this._finishMaterialAsync(n,e)];case 3:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._finishMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s;return y(this,(function(i){switch(i.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(r=i.sent(),n=[],o=0,a=r;o<a.length;o++)s=a[o],n.push(this.exportTextureAsync(s));return[4,Promise.all(n)];case 2:return i.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return i.sent(),[2]}}))}))},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,a=e?e.getSize():{width:0,height:0},s=t?t.getSize():{width:0,height:0};return a.width<s.width?(n=e&&e instanceof x.Texture?x.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):B(s.width,s.height,r),o=t):a.width>s.width?(o=t&&t instanceof x.Texture?x.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):B(a.width,a.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h,f,p,d,g,m,_,T,v,b,w,A,C,E,I,S,V,F,B,P,U,N,L;return y(this,(function(y){switch(y.label){case 0:return n=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,y.sent()];case 2:return(o=e?e.getScene():t?t.getScene():null)?(a=this._resizeTexturesToSameDimensions(e,t,o),s=null===(L=a.texture1)||void 0===L?void 0:L.getSize(),i=void 0,u=void 0,c=s.width,l=s.height,[4,a.texture1.readPixels()]):[3,12];case 3:return h=y.sent(),[4,a.texture2.readPixels()];case 4:return f=y.sent(),h?(i=O(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return f?(u=O(f),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(p=u.byteLength,d=new Uint8Array(p),g=new Uint8Array(p),m=new x.Color3(0,0,0),_=0,T=0,F=0;F<l;++F)for(B=0;B<c;++B)v=4*(c*F+B),b=new x.Color3(i[v],i[v+1],i[v+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),w=new x.Color3(u[v],u[v+1],u[v+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(r.specularColor),A=u[v+3]*r.glossiness,C={diffuseColor:b,specularColor:w,glossiness:A},E=this._convertSpecularGlossinessToMetallicRoughness(C),m.r=Math.max(m.r,E.baseColor.r),m.g=Math.max(m.g,E.baseColor.g),m.b=Math.max(m.b,E.baseColor.b),_=Math.max(_,E.metallic),T=Math.max(T,E.roughness),g[v]=255*E.baseColor.r,g[v+1]=255*E.baseColor.g,g[v+2]=255*E.baseColor.b,g[v+3]=a.texture1.hasAlpha?255*i[v+3]:255,d[v]=0,d[v+1]=255*E.roughness,d[v+2]=255*E.metallic,d[v+3]=255;for(I={baseColor:m,metallic:_,roughness:T},S=!1,V=!1,F=0;F<l;++F)for(B=0;B<c;++B)g[P=4*(c*F+B)]/=I.baseColor.r>M?I.baseColor.r:1,g[P+1]/=I.baseColor.g>M?I.baseColor.g:1,g[P+2]/=I.baseColor.b>M?I.baseColor.b:1,U=x.Color3.FromInts(g[P],g[P+1],g[P+2]),N=U.toGammaSpace(o.getEngine().useExactSrgbConversions),g[P]=255*N.r,g[P+1]=255*N.g,g[P+2]=255*N.b,N.equalsWithEpsilon(R,M)||(V=!0),d[P+1]/=I.roughness>M?I.roughness:1,d[P+2]/=I.metallic>M?I.metallic:1,x.Color3.FromInts(255,d[P+1],d[P+2]).equalsWithEpsilon(R,M)||(S=!0);return S&&n.push((0,x.EncodeImageAsync)(d,c,l).then((function(e){I.metallicRoughnessTextureData=e}))),V&&n.push((0,x.EncodeImageAsync)(g,c,l).then((function(e){I.baseColorTextureData=e}))),[4,Promise.all(n).then((function(){return I}))];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),o=S(t,r,n),a=e.diffuseColor.scale(n/(1-w.r)/Math.max(1-o,M)),s=e.specularColor.subtract(w.scale(1-o)).scale(1/Math.max(o,M)),i=x.Color3.Lerp(a,s,o*o);return{baseColor:i=i.clampToRef(0,1,i),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)},e.prototype._getMaxComponent=function(e){return Math.max(e.r,Math.max(e.g,e.b))},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n,o,a,s,i,u){return v(this,void 0,void 0,(function(){var c,l,h,f,p,d,g,m,_,T=this;return y(this,(function(b){switch(b.label){case 0:return c=[],l={baseColor:e,metallic:t,roughness:r},u&&(s instanceof x.OpenPBRMaterial?(s.geometryOpacityTexture?(h=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:0,f=s.geometryOpacityTexture&&s.geometryOpacityTexture.getInternalTexture()?s.geometryOpacityTexture.getInternalTexture().uniqueId:0,p=Number("".concat(h).concat(f)),(_=this._textureMap.get(p))?i.baseColorTexture=_:c.push((0,x.MergeTexturesAsync)("baseColorOpacityTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,2):(0,x.CreateConstantInput)(1),(0,x.CreateTextureInput)(s.geometryOpacityTexture,0)),s.getScene()).then((function(e){return v(T,void 0,void 0,(function(){var t;return y(this,(function(r){switch(r.label){case 0:return[4,this.exportTextureAsync(e,p)];case 1:return(t=r.sent())&&(i.baseColorTexture=t),[2]}}))}))})))):n&&c.push(this.exportTextureAsync(n).then((function(e){e&&(i.baseColorTexture=e)}))),s._useMetallicFromMetallicTextureBlue&&o?c.push(this.exportTextureAsync(o).then((function(e){e&&(i.metallicRoughnessTexture=e)}))):(a||o)&&(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,g=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,m=Number("".concat(d).concat(g)),(_=this._textureMap.get(m))?i.metallicRoughnessTexture=_:c.push((0,x.MergeTexturesAsync)("MetalRoughTexture",(0,x.CreateRGBAConfiguration)(s.ambientOcclusionTexture?(0,x.CreateTextureInput)(s.ambientOcclusionTexture,0):(0,x.CreateConstantInput)(1),a?(0,x.CreateTextureInput)(a,0):(0,x.CreateConstantInput)(1),o?(0,x.CreateTextureInput)(o,0):(0,x.CreateConstantInput)(1)),s.getScene()).then((function(e){return v(T,void 0,void 0,(function(){var t;return y(this,(function(r){switch(r.label){case 0:return[4,this.exportTextureAsync(e,m)];case 1:return(t=r.sent())&&(i.metallicRoughnessTexture=t),[2]}}))}))}))))):(n&&c.push(this.exportTextureAsync(n).then((function(e){e&&(i.baseColorTexture=e)}))),o&&c.push(this.exportTextureAsync(o).then((function(e){e&&(i.metallicRoughnessTexture=e)}))))),c.length>0?(this._exporter._materialNeedsUVsSet.add(s),[4,Promise.all(c)]):[3,2];case 1:b.sent(),b.label=2;case 2:return[2,l]}}))}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof x.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case x.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case x.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case x.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case x.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case x.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case x.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case x.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case x.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case x.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case x.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case x.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case x.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case x.Texture.WRAP_ADDRESSMODE:return 10497;case x.Texture.CLAMP_ADDRESSMODE:return 33071;case x.Texture.MIRROR_ADDRESSMODE:return 33648;default:return x.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l;return y(this,(function(h){switch(h.label){case 0:return n={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,a=e._reflectivityTexture,s=e._useMicroSurfaceFromReflectivityMapAlpha,!a||s?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(o||a)&&r?(this._exporter._materialNeedsUVsSet.add(e),i=this._exportTextureSampler(o||a),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,a,n)]):[3,8];case 3:return u=h.sent(),c=this._exporter._textures,u.baseColorTextureData?[4,this._exportImageAsync("baseColor".concat(c.length),u.baseColorTextureData)]:[3,5];case 4:l=h.sent(),t.baseColorTexture=this._exportTextureInfo(l,i,null==o?void 0:o.coordinatesIndex),h.label=5;case 5:return u.metallicRoughnessTextureData?[4,this._exportImageAsync("metallicRoughness".concat(c.length),u.metallicRoughnessTextureData)]:[3,7];case 6:l=h.sent(),t.metallicRoughnessTexture=this._exportTextureInfo(l,i,null==a?void 0:a.coordinatesIndex),h.label=7;case 7:return[2,u];case 8:return[2,this._convertSpecularGlossinessToMetallicRoughness(n)]}}))}))},e.prototype.exportPBRMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c;return y(this,(function(l){switch(l.label){case 0:return r={},n={name:e.name},(o=e.isMetallicWorkflow())&&(a=e._albedoColor,s=e.alpha,a&&(r.baseColorFactor=[a.r,a.g,a.b,s])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,r,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,r,t)];case 3:u=l.sent(),l.label=4;case 4:return i=u,[4,this._setMetallicRoughnessPbrMaterialAsync(i,e,n,r,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(n,e)];case 6:return l.sent(),(c=this._exporter._materials).push(n),[2,c.length-1]}}))}))},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a,s,i,u,c,l=this;return y(this,(function(h){switch(h.label){case 0:return F(r,t),e.baseColor.equalsWithEpsilon(R,M)&&x.Scalar.WithinEpsilon(t.alpha,1,M)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||x.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),o?(a=[],(s=t instanceof x.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&a.push(this.exportTextureAsync(s).then((function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))}))),(i=t instanceof x.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&a.push(new Promise((function(e){return v(l,void 0,void 0,(function(){var r,o,a,s;return y(this,(function(u){switch(u.label){case 0:return t instanceof x.OpenPBRMaterial&&n.metallicRoughnessTexture?(r=this._exportTextureSampler(i),o=this._exporter._textures[n.metallicRoughnessTexture.index].source,a=this._exportTextureInfo(o,r,i.coordinatesIndex),this._textureMap.set(i.uniqueId,a),this._exporter._extensionsPostExportTextures("exporter",a,i),[2,e(a)]):[3,1];case 1:return s=e,[4,this.exportTextureAsync(i)];case 2:return[2,s.apply(void 0,[u.sent()])]}}))}))})).then((function(e){return v(l,void 0,void 0,(function(){var n;return y(this,(function(o){return e&&(n={index:e.index,texCoord:e.texCoord,extensions:e.extensions},r.occlusionTexture=n,t instanceof x.PBRBaseMaterial?n.strength=t._ambientTextureStrength:n.strength=t.ambientOcclusionTexture.level),[2]}))}))}))),(u=t instanceof x.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&a.push(this.exportTextureAsync(u).then((function(e){e&&(r.emissiveTexture=e)}))),a.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(a)]):[3,2]):[3,2];case 1:h.sent(),h.label=2;case 2:return(c=t instanceof x.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(C,M)||(r.emissiveFactor=c.asArray()),r.pbrMetallicRoughness=n,[2]}}))}))},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i;return y(this,(function(u){switch(u.label){case 0:return r={},n={name:e.name},o=e.baseColor,a=e.geometryOpacity,o&&(r.baseColorFactor=[o.r,o.g,o.b,a]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,r,t)];case 1:return s=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,n,r,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(n,e)];case 3:return u.sent(),(i=this._exporter._materials).push(n),[2,i.length-1]}}))}))},e.prototype.exportTextureAsync=function(e){return v(this,arguments,void 0,(function(e,t){var r,n,o;return void 0===t&&(t=null),y(this,(function(a){switch(a.label){case 0:return(r=this._textureMap.get(null!=t?t:e.uniqueId))?[2,r]:(n=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=a.sent(),r=this._exportTextureInfo(o,n,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,r),this._exporter._extensionsPostExportTextures("exporter",r,e),[2,r]}}))}))},e.prototype._exportTextureImageAsync=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,a,s=this;return y(this,(function(i){switch(i.label){case 0:return t=null!==(a=e.mimeType)&&void 0!==a?a:"none",r=this._internalTextureToImage,n=e.getInternalTexture().uniqueId,r[n]=r[n]||{},void 0===(o=r[n][t])&&(o=v(s,void 0,void 0,(function(){var r,n,o,a,s;return y(this,(function(i){switch(i.label){case 0:return[4,I(e)];case 1:return!(r=i.sent())||"none"!==t&&r.type!==t?[3,3]:[4,this._exportImageAsync(e.name,r)];case 2:case 6:return[2,i.sent()];case 3:return n="image/png","none"!==t&&(E(t)?n=t:(n="image/png",x.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG.")))),o=e.getSize(),[4,(0,x.GetTextureDataAsync)(e)];case 4:return a=i.sent(),[4,(0,x.EncodeImageAsync)(a,o.width,o.height,n)];case 5:return s=i.sent(),[4,this._exportImageAsync(e.name,s)]}}))})),r[n][t]=o),[4,o];case 1:return[2,i.sent()]}}))}))},e.prototype._exportImageAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u;return y(this,(function(c){switch(c.label){case 0:return r=this._exporter._images,this._exporter._shouldUseGlb?(n={name:e,mimeType:t.type,bufferView:void 0},[4,t.arrayBuffer()]):[3,2];case 1:return o=c.sent(),a=this._exporter._bufferManager.createBufferView(new Uint8Array(o)),this._exporter._bufferManager.setBufferView(n,a),[3,3];case 2:s=e.replace(/\.\/|\/|\.\\|\\/g,"_"),i=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(t.type),u=s+i,r.some((function(e){return e.uri===u}))&&(u="".concat(s,"_").concat(x.Tools.RandomId()).concat(i)),n={name:e,uri:u},this._exporter._imageData[u]=t,c.label=3;case 3:return r.push(n),[2,r.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}(),U=x.Matrix.Compose(new x.Vector3(-1,1,1),x.Quaternion.Identity(),x.Vector3.Zero());function N(e,t){if(!(e instanceof x.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(x.Matrix.IdentityReadOnly,x.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(U,x.TmpVectors.Matrix[0]).equalsWithEpsilon(x.Matrix.IdentityReadOnly,x.Epsilon))return!1;return!(e instanceof x.AbstractMesh&&e.geometry)}var L=x.Vector3.ZeroReadOnly,k=x.Quaternion.Identity(),K=x.Vector3.OneReadOnly,z=new x.Vector3(-1,1,1);function W(e,t){var r=e.byteOffset,n=e.byteStride,o=e.type,a=e.normalized,s=e.getSize(),i=t.reduce((function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e}),-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:s,type:o,count:i*s,normalized:a,totalVertices:i,kind:e.getKind()}}function D(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 q(e){switch(e){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:case x.VertexBuffer.ColorKind:case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:case x.VertexBuffer.MatricesWeightsKind:case x.VertexBuffer.MatricesWeightsExtraKind:case x.VertexBuffer.UVKind:case x.VertexBuffer.UV2Kind:case x.VertexBuffer.UV3Kind:case x.VertexBuffer.UV4Kind:case x.VertexBuffer.UV5Kind:case x.VertexBuffer.UV6Kind:return!0}return!1}function G(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function H(e){return e.x*=-1,e}function j(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),r=Math.abs(e.y);if(t>r){var n=Math.sign(e.x);e.x=t,e.y*=-n,e.z*=-n,e.w*=n}else n=Math.sign(e.y),e.x*=-n,e.y=r,e.z*=n,e.w*=-n}else{var o=Math.abs(e.z),a=Math.abs(e.w);o>a?(n=Math.sign(e.z),e.x*=-n,e.y*=n,e.z=o,e.w*=-n):(n=Math.sign(e.w),e.x*=n,e.y*=-n,e.z*=-n,e.w=a)}return e}function Q(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function X(e,t){var r=x.Vector3.FromArrayToRef(t.translation||[0,0,0],0,x.TmpVectors.Vector3[0]),n=x.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,x.TmpVectors.Quaternion[0]),o=x.Matrix.ComposeToRef(K,n,r,x.TmpVectors.Matrix[0]),a=x.Vector3.FromArrayToRef(e.translation||[0,0,0],0,x.TmpVectors.Vector3[2]),s=x.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,x.TmpVectors.Quaternion[1]),i=x.Matrix.ComposeToRef(K,s,a,x.TmpVectors.Matrix[1]);o.multiplyToRef(i,i),i.decompose(void 0,n,r),r.equalsWithEpsilon(L,x.Epsilon)?delete t.translation:t.translation=r.asArray(),n.equalsWithEpsilon(k,x.Epsilon)?delete t.rotation:t.rotation=n.asArray(),t.scale&&delete t.scale}function Y(e,t){if(!(t instanceof x.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var r=e.getScene(),n=e instanceof x.TargetCamera&&!r.useRightHandedSystem?z:K;return!!t.scaling.equalsWithEpsilon(n,x.Epsilon)||(x.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function Z(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],a=o[0],s=o[1],i=t[a];(Array.isArray(s)&&Array.isArray(i)&&J(s,i)||s===i)&&delete e[a]}return e}function J(e,t){return e.length===t.length&&e.every((function(e,r){return e===t[r]}))}var $=new Map([[Int8Array,function(e,t,r){return e.setInt8(t,r)}],[Uint8Array,function(e,t,r){return e.setUint8(t,r)}],[Uint8ClampedArray,function(e,t,r){return e.setUint8(t,r)}],[Int16Array,function(e,t,r){return e.setInt16(t,r,!0)}],[Uint16Array,function(e,t,r){return e.setUint16(t,r,!0)}],[Int32Array,function(e,t,r){return e.setInt32(t,r,!0)}],[Uint32Array,function(e,t,r){return e.setUint32(t,r,!0)}],[Float32Array,function(e,t,r){return e.setFloat32(t,r,!0)}],[Float64Array,function(e,t,r){return e.setFloat64(t,r,!0)}]]),ee=function(){function e(e){this._data=new Uint8Array(e),this._dataView=new DataView(this._data.buffer),this._byteOffset=0}return e.prototype.writeTypedArray=function(e){this._checkGrowBuffer(e.byteLength);for(var t=$.get(e.constructor),r=0;r<e.length;r++)t(this._dataView,this._byteOffset,e[r]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var r=new Uint8Array(2*t);r.set(this._data),this._data=r,this._dataView=new DataView(this._data.buffer)}},e}();function te(e){return e%4==0?4:e%2==0?2:1}var re,ne=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach((function(e){t+=e.byteLength}));for(var r=new ee(t),n=0,o=Array.from(this._bufferViewToData.keys()).sort((function(e,t){return te(t.byteLength)-te(e.byteLength)}));n<o.length;n++){var a=o[n];a.byteOffset=r.byteOffset,e.push(a);for(var s=e.length-1,i=0,u=this.getPropertiesWithBufferView(a);i<u.length;i++)u[i].bufferView=s;r.writeTypedArray(this._bufferViewToData.get(a)),this._bufferViewToData.delete(a)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,o,a,s){this._verifyBufferView(e);var i={bufferView:void 0,componentType:r,count:n,type:t,min:null==a?void 0:a.min,max:null==a?void 0:a.max,normalized:s,byteOffset:o};return this.setBufferView(i,e),this._accessorToBufferView.set(i,e),i},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var o=n[r];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))}))},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(re||(re={}));var oe=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof x.TransformNode||e instanceof x.Camera||e instanceof x.Light)},e._CreateNodeAnimation=function(t,r,n,o,a){if(this._IsTransformable(t)){var s=[],i=[],u=r.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,n,o),h=l.interpolationType,f=l.shouldBakeAnimation;if(f?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,i,c,o):"LINEAR"===h||"STEP"===h?e._CreateLinearOrStepAnimation(t,r,n,s,i,o):"CUBICSPLINE"===h?e._CreateCubicSplineAnimation(t,r,n,s,i,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,i,c,o),s.length&&i.length)return{inputs:s,outputs:i,samplerInterpolation:h,inputsMin:f?c.min:x.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:f?c.max:x.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:x.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(x.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,o,a,s,i,u,c,l,h){var f;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var x=d[p];if(!h||h(x)){var g=e._DeduceAnimationInfo(x);g&&(f={name:x.name,samplers:[],channels:[]},e._AddAnimation("".concat(x.name),x.hasRunningRuntimeAnimations?r:f,t,x,g.dataAccessorType,g.animationChannelTargetPath,o,s,i,u,g.useQuaternion,c,l),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,a,s,i,u,c,l,h){var f;if(t instanceof x.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var g=0,m=p.getTarget(d).animations;g<m.length;g++){var _=m[g];if(!h||h(_)){for(var T=new x.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),v=[],y=_.getKeys(),b=0;b<y.length;++b)for(var M=y[b],w=0;w<p.numTargets;++w)w==d?v.push(M):v.push({frame:M.frame,value:0});T.setKeys(v,!0);var A=e._DeduceAnimationInfo(T);A&&(f={name:T.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:f,t,T,A.dataAccessorType,A.animationChannelTargetPath,o,s,i,u,A.useQuaternion,c,l,p.numTargets),f.samplers.length&&f.channels.length&&n.push(f))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,a,s,i,u,c){var l,h;if(t.animationGroups)for(var f=t.animationGroups,p=function(f){var p=new Map,g=new Map,m=new Set,_=f.to-f.from;h={name:f.name,channels:[],samplers:[]};for(var T=function(r){var _=f.targetedAnimations[r],T=_.target,v=_.animation;if(c&&!c(v))return"continue";var y=u.has(T);if(d._IsTransformable(T)||1===T.length&&d._IsTransformable(T[0])){if(M=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(T)?T:d._IsTransformable(T[0])?T[0]:null;b&&e._AddAnimation("".concat(v.name),h,b,v,M.dataAccessorType,M.animationChannelTargetPath,n,o,a,s,M.useQuaternion,i,y)}}else if(T instanceof x.MorphTarget||1===T.length&&T[0]instanceof x.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var w=T instanceof x.MorphTarget?T:T[0];if(w){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1}));if(A){var R=t.meshes.find((function(e){return e.morphTargetManager===A}));R&&(p.has(R)||p.set(R,new Map),null===(l=p.get(R))||void 0===l||l.set(w,v),m.add(R),g.set(R,v))}}}}},v=0;v<f.targetedAnimations.length;++v)T(v);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],l=g.get(t).getKeys(),d=l.length,m=0;m<d;++m)for(var T=0;T<r.numTargets;++T){var v=r.getTarget(T),y=p.get(t);if(y){var b=y.get(v);b?(u||(u=new x.Animation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,x.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[m])):c.push({frame:f.from+_/d*m,value:v.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c,!0);var M=e._DeduceAnimationInfo(u);M&&e._AddAnimation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),h,t,u,M.dataAccessorType,M.animationChannelTargetPath,n,o,a,s,M.useQuaternion,i,!1,null==r?void 0:r.numTargets)})),h.channels.length&&h.samplers.length&&r.push(h)},d=this,g=0,m=f;g<m.length;g++)p(m[g])},e._AddAnimation=function(t,r,n,o,a,s,i,u,c,l,h,f,p,d){var g,m,_,T,v,y,b=e._CreateNodeAnimation(n,o,s,h,f);if(b){if(d){for(var M=0,w=0,A=[];b.inputs.length>0;)w=b.inputs.shift(),M%d==0&&A.push(w),M++;b.inputs=A}var R=i.get(n),C=new Float32Array(b.inputs);g=u.createBufferView(C),m=u.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(m),_=l.length-1;var E=new x.Quaternion,I=new x.Vector3,S=new x.Vector3,V=n instanceof x.Camera,F=D(a),B=new Float32Array(b.outputs.length*F);b.outputs.forEach((function(e,t){var r=e;switch(s){case"translation":p&&(x.Vector3.FromArrayToRef(e,0,S),H(S),S.toArray(r));break;case"rotation":4===e.length?x.Quaternion.FromArrayToRef(e,0,E):(r=new Array(4),x.Vector3.FromArrayToRef(e,0,I),x.Quaternion.FromEulerVectorToRef(I,E)),p&&(j(E),V&&Q(E)),E.toArray(r)}B.set(r,t*F)})),g=u.createBufferView(B),m=u.createAccessor(g,a,5126,b.outputs.length),l.push(m),T=l.length-1,v={interpolation:b.samplerInterpolation,input:_,output:T},r.samplers.push(v),y={sampler:r.samplers.length-1,target:{node:R,path:s}},r.channels.push(y)}},e._CreateBakedAnimation=function(t,r,n,o,a,s,i,u,c,l,h){var f,p,d=x.Quaternion.Identity(),g=null,m=null,_=null,T=null,v=null,y=null;l.min=x.Tools.FloatRound(o/s);for(var b=r.getKeys(),M=0,w=b.length;M<w;++M){if(y=null,_=b[M],M+1<w)if(T=b[M+1],_.value.equals&&_.value.equals(T.value)||_.value===T.value){if(0!==M)continue;y=_.frame}else y=T.frame;else{if(v=b[M-1],_.value.equals&&_.value.equals(v.value)||_.value===v.value)continue;y=a}if(y)for(var A=_.frame;A<=y;A+=i)if((p=x.Tools.FloatRound(A/s))!==g){g=p,m=p;var R={key:0,repeatCount:0,loopMode:r.loopMode};f=r._interpolate(A,R),e._SetInterpolatedValue(t,f,p,r,n,d,u,c,h)}}m&&(l.max=m)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,a){var s=e._GetBasePositionRotationOrScale(r,o,a),i=n.targetProperty.split("."),u=i?i[1]:"",c=a?x.Quaternion.FromArray(s).normalize():x.Vector3.FromArray(s);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:x.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,a,s,i,u){var c;s.push(r),"weights"!==o?(n.dataType===x.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u)),"rotation"===o?(u?a=t:(c=t,x.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),i.push(a.asArray())):(c=t,i.push(c.asArray()))):i.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,o,a,s){for(var i=0,u=r.getKeys();i<u.length;i++){var c=u[i];o.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,a,n,t,s)}},e._CreateCubicSplineAnimation=function(t,r,n,o,a,s){r.getKeys().forEach((function(i){o.push(i.frame/r.framePerSecond),e._AddSplineTangent(re.INTANGENT,a,n,"CUBICSPLINE",i,s),e._AddKeyframeValue(i,r,a,n,t,s),e._AddSplineTangent(re.OUTTANGENT,a,n,"CUBICSPLINE",i,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var o=e.rotationQuaternion;n=(null!=o?o:x.Quaternion.Identity()).asArray()}else{var a=e.rotation;n=(null!=a?a:x.Vector3.Zero()).asArray()}else if("translation"===t){var s=e.position;n=(null!=s?s:x.Vector3.Zero()).asArray()}else{var i=e.scaling;n=(null!=i?i:x.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,o,a){var s,i=t.dataType;if(i===x.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var c=x.Vector3.FromArray(u);u=x.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}r.push(u)}else if(i===x.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(s=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,a)){if("rotation"===n){var l=a?s:x.Quaternion.RotationYawPitchRoll(s.y,s.x,s.z).normalize();r.push(l.asArray())}r.push(s.asArray())}}else i===x.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):x.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,a=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,i=e.length;s<i;++s)if((o=e[s]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",a=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&1===o.interpolation&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,r,n,o,a){var s,i=e===re.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(i)if(a)s=i.asArray();else{var u=i;s=x.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else s=[0,0,0,0];else s="weights"===r?i?[i]:[0]:i?i.asArray():[0,0,0];t.push(s)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}();function ae(e,t,r,n,o,a){var s={attributes:{},influence:e.influence,name:e.name},i=t.geometry;if(!i)return x.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),s;var u=a?-1:1,c=x.Vector3.Zero(),l=0;if(e.hasPositions){var h=e.getPositions(),f=i.getVerticesData(x.VertexBuffer.PositionKind);if(f){var p=new Float32Array(f.length),d=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];l=f.length/3;for(var m=0;m<l;++m){var _=x.Vector3.FromArray(f,3*m);x.Vector3.FromArray(h,3*m).subtractToRef(_,c),c.x*=u,d[0]=Math.min(d[0],c.x),g[0]=Math.max(g[0],c.x),d[1]=Math.min(d[1],c.y),g[1]=Math.max(g[1],c.y),d[2]=Math.min(d[2],c.z),g[2]=Math.max(g[2],c.z),p[3*m]=c.x,p[3*m+1]=c.y,p[3*m+2]=c.z}var T=r.createBufferView(p,12),v=r.createAccessor(T,"VEC3",5126,h.length/3,0,{min:d,max:g});o.push(v),s.attributes.POSITION=o.length-1}else x.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),b=i.getVerticesData(x.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(l=b.length/3,m=0;m<l;++m){var w=x.Vector3.FromArray(b,3*m).normalize();x.Vector3.FromArray(y,3*m).normalize().subtractToRef(w,c),M[3*m]=c.x*u,M[3*m+1]=c.y,M[3*m+2]=c.z}T=r.createBufferView(M,12),v=r.createAccessor(T,"VEC3",5126,y.length/3,0),o.push(v),s.attributes.NORMAL=o.length-1}else x.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),R=i.getVerticesData(x.VertexBuffer.TangentKind);if(R){l=R.length/4;var C=new Float32Array(3*l);for(m=0;m<l;++m){var E=x.Vector3.FromArray(R,4*m);G(E);var I=x.Vector3.FromArray(A,3*m);G(I),I.subtractToRef(E,c),C[3*m]=c.x*u,C[3*m+1]=c.y,C[3*m+2]=c.z}T=r.createBufferView(C,12),v=r.createAccessor(T,"VEC3",5126,l,0),o.push(v),s.attributes.TANGENT=o.length-1}else x.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),V=i.getVerticesData(x.VertexBuffer.ColorKind),F=i.getVertexBuffer(x.VertexBuffer.ColorKind);if(V&&F){var B=F.getSize();l=V.length/B;var O=new Float32Array(l*B);for(m=0;m<l;++m)if(3===B){var P=x.Vector3.FromArray(V,m*B);x.Vector3.FromArray(S,m*B).subtractToRef(P,c),O[3*m]=c.x,O[3*m+1]=c.y,O[3*m+2]=c.z}else if(4===B){var U=new x.Vector4;P=x.Vector4.FromArray(V,m*B),x.Vector4.FromArray(S,m*B).subtractToRef(P,U),O[4*m]=U.x,O[4*m+1]=U.y,O[4*m+2]=U.z,O[4*m+3]=U.w}else x.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));T=r.createBufferView(O,4*B),v=r.createAccessor(T,3===B?"VEC3":"VEC4",5126,l,0),o.push(v),s.attributes.COLOR_0=o.length-1}else x.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return s}var se=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,r,n,o){var a,s,i,u;return null===(u=null===(i=null===(s=null===(a=this._indicesAccessorMap.get(e))||void 0===a?void 0:a.get(t))||void 0===s?void 0:s.get(r))||void 0===i?void 0:i.get(n))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,r,n,o,a){var s=this._indicesAccessorMap.get(e);s||(s=new Map,this._indicesAccessorMap.set(e,s));var i=s.get(t);i||(i=new Map,s.set(t,i));var u=i.get(r);u||(u=new Map,i.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(o,a)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,o;return null===(o=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===o?void 0:o.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a)),a.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),ie=function(){function e(e,t){if(void 0===e&&(e=x.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(x.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new P(this),this._extensions={},this._bufferManager=new ne,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=T({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,r,n){var o=this;if(r>=t.length)return Promise.resolve(e);var a=n(t[r],e);return a?a.then((function(e){return v(o,void 0,void 0,(function(){var o;return y(this,(function(a){switch(a.label){case 0:return e?[4,this._ApplyExtension(e,t,r+1,n)]:[3,2];case 1:return o=a.sent(),[3,3];case 2:o=null,a.label=3;case 3:return[2,o]}}))}))})):this._ApplyExtension(e,t,r+1,n)},e.prototype._ApplyExtensions=function(t,r){for(var n=[],o=0,a=e._ExtensionNames;o<a.length;o++){var s=a[o];n.push(this._extensions[s])}return this._ApplyExtension(t,n,0,r)},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){var a=this;return this._ApplyExtensions(t,(function(t,s){return t.postExportNodeAsync&&t.postExportNodeAsync(e,s,r,n,o,a._bufferManager)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._ApplyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,r,n){return v(this,void 0,void 0,(function(){var o,a=this;return y(this,(function(s){switch(s.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map((function(e){return v(a,void 0,void 0,(function(){var a,s;return y(this,(function(i){switch(i.label){case 0:return(a=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,a.postExportMaterialAdditionalTexturesAsync(t,r,n)]:[3,2];case 1:s=i.sent(),o.push.apply(o,s),i.label=2;case 2:return[2]}}))}))})))];case 1:return s.sent(),[2,o]}}))}))},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var s=a[o],i=this._extensions[s];i.postExportTexture&&i.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.postExportMeshPrimitive&&a.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return v(this,void 0,void 0,(function(){var t,r,n,o;return y(this,(function(a){switch(a.label){case 0:t=0,r=e._ExtensionNames,a.label=1;case 1:return t<r.length?(n=r[t],(o=this._extensions[n]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:a.sent(),a.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];a.enabled&&t(a)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){var r,n,o;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r,n){void 0===n&&(n=100),e.UnregisterExtension(t)&&x.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r;var o=null!=n?n:0;e._ExtensionOrders[t]=o;for(var a=e._ExtensionNames.length,s=0;s<e._ExtensionNames.length;s++){var i=e._ExtensionNames[s];if(o<e._ExtensionOrders[i]){a=s;break}}e._ExtensionNames.splice(a,0,t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._generateJSON=function(e,t,r){var n={byteLength:e};return n.byteLength&&(this._glTF.buffers=[n]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(n.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,a,s,i;return y(this,(function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength,e,!0),n=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",a=e+".bin",(s=new _).files[o]=r,s.files[a]=n,this._imageData)for(i in this._imageData)s.files[i]=this._imageData[i];return[2,s]}}))}))},e.prototype._generateBinaryAsync=function(){return v(this,void 0,void 0,(function(){return y(this,(function(e){switch(e.label){case 0:return[4,this._exportSceneAsync()];case 1:return e.sent(),[4,this._extensionsPreGenerateBinaryAsync()];case 2:return e.sent(),[2,this._bufferManager.generateBinary(this._bufferViews)]}}))}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype.generateGLBAsync=function(e){return v(this,void 0,void 0,(function(){var t,r,n,o,a,s,i,u,c,l,h,f,p,d;return y(this,(function(x){switch(x.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=x.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),n=e+".glb",o=r.length,"undefined"!=typeof TextEncoder&&(s=new TextEncoder,a=s.encode(r),o=a.length),i=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+i+t.byteLength+u,(l=new ee(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(o+i),l.writeUInt32(1313821514),a)l.writeTypedArray(a);else for(h="_".charCodeAt(0),p=0;p<o;++p)(f=r.charCodeAt(p))!=r.codePointAt(p)?l.writeUInt8(h):l.writeUInt8(f);for(p=0;p<i;++p)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),p=0;p<u;++p)l.writeUInt8(0);return(d=new _).files[n]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}}))}))},e.prototype._setNodeTransformation=function(e,t,r){var n;if(t.getPivotPoint().equalsWithEpsilon(L,x.Epsilon)||x.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(L,x.Epsilon)){var o=x.TmpVectors.Vector3[0].copyFrom(t.position);r&&H(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(K,x.Epsilon)||(e.scale=t.scaling.asArray());var a=(null===(n=t.rotationQuaternion)||void 0===n?void 0:n.clone())||x.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);a.equalsWithEpsilon(k,x.Epsilon)||(r&&j(a),e.rotation=a.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){var n=x.TmpVectors.Vector3[0],o=x.TmpVectors.Quaternion[0],a=t.getWorldMatrix();if(t.parent){var s=t.parent.getWorldMatrix().invertToRef(x.TmpVectors.Matrix[0]);a.multiplyToRef(s,x.TmpVectors.Matrix[1]).decompose(void 0,o,n)}else a.decompose(void 0,o,n);n.equalsWithEpsilon(L,x.Epsilon)||(r&&H(n),e.translation=n.asArray()),r&&j(o),this._babylonScene.useRightHandedSystem||Q(o),o.equalsWithEpsilon(k,x.Epsilon)||(e.rotation=o.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var r=t[e],n={type:r.mode===x.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(r.name&&(n.name=r.name),"perspective"===n.type)n.perspective={aspectRatio:r.getEngine().getAspectRatio(r),yfov:r.fovMode===x.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===n.type){var o=r.orthoLeft&&r.orthoRight?.5*(r.orthoRight-r.orthoLeft):.5*r.getEngine().getRenderWidth(),a=r.orthoBottom&&r.orthoTop?.5*(r.orthoTop-r.orthoBottom):.5*r.getEngine().getRenderHeight();n.orthographic={xmag:o,ymag:a,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,n)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var r=t[e],n=this._nodesCameraMap.get(r);if(void 0!==n){this._cameras.push(r);for(var o=0,a=n;o<a.length;o++)a[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var r=t[e];r.bones.length<=0||this._skinMap.set(r,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,r=function(r){if(r.bones.length<=0)return"continue";var o=n._skinMap.get(r);if(null==o)return"continue";for(var a={},s=-1,i=0;i<r.bones.length;++i){var u=r.bones[i];-1!==(h=null!==(t=u.getIndex())&&void 0!==t?t:i)&&(a[h]=u,h>s&&(s=h))}for(var c,l=[],h=0;h<=s;++h){var f=(u=a[h]).getTransformNode(),p=f?n._nodeMap.get(f):void 0;if(void 0!==p){o.joints.push(p);var d=u.getAbsoluteInverseBindMatrix().clone();e.has(f)&&(c=d,U.invertToRef(x.TmpVectors.Matrix[0]).multiplyToRef(c,c).multiplyToRef(U,c)),l.push(d)}else x.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var g=n._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==g){var m=new Float32Array(16*l.length);l.forEach((function(e,t){m.set(e.m,16*t)}));var _=n._bufferManager.createBufferView(m);n._accessors.push(n._bufferManager.createAccessor(_,"MAT4",5126,l.length)),o.inverseBindMatrices=n._accessors.length-1,n._skins.push(o);for(var T=n._skins.length-1,v=0,y=g;v<y.length;v++)y[v].skin=T}},n=this,o=0,a=this._babylonScene.skeletons;o<a.length;o++)r(a[o])},e.prototype._exportSceneAsync=function(){return v(this,void 0,void 0,(function(){var e,t,r,n,o,a,s,i,u,c,l,h,f,p,d,x,g,m,_,T,v,b,M;return y(this,(function(y){switch(y.label){case 0:for(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),r=new Array,n=new Array,o=new Array,a=0,s=this._babylonScene.rootNodes;a<s.length;a++)i=s[a],this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&N(i,this._babylonScene.useRightHandedSystem)?o.push.apply(o,i.getChildren()):this._babylonScene.useRightHandedSystem?r.push(i):n.push(i);return this._listAvailableCameras(),this._listAvailableSkeletons(),u=new se(!0,!1),l=(c=(v=e.nodes).push).apply,h=[v],[4,this._exportNodesAsync(n,u)];case 1:return l.apply(c,h.concat([y.sent()])),f=new se(!1,!1),d=(p=(b=e.nodes).push).apply,x=[b],[4,this._exportNodesAsync(r,f)];case 2:return d.apply(p,x.concat([y.sent()])),g=new se(!1,!0),_=(m=(M=e.nodes).push).apply,T=[M],[4,this._exportNodesAsync(o,g)];case 3:return _.apply(m,T.concat([y.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(u.getNodesSet()),this._babylonScene.animationGroups.length&&oe._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,u.getNodesSet(),this._options.shouldExportAnimation),[2]}}))}))},e.prototype._shouldExportNode=function(e){var t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t},e.prototype._exportNodesAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a;return y(this,(function(s){switch(s.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,o=e,s.label=1;case 1:return n<o.length?(a=o[n],[4,this._exportNodeAsync(a,r,t)]):[3,4];case 2:s.sent(),s.label=3;case 3:return n++,[3,1];case 4:return[2,r]}}))}))},e.prototype._collectBuffers=function(e,t,r,n,o){if(this._shouldExportNode(e)&&e instanceof x.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var s in a)if(q(s)){var i=a[s];o.setHasVertexColorAlpha(i,e.hasVertexAlpha);var u=i._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(i)&&c.push(i);var l=r.get(i)||[];r.set(i,l),-1===l.indexOf(e)&&l.push(e)}var h=e.morphTargetManager;if(h)for(var f=0;f<h.numTargets;f++){var p=h.getTarget(f);l=n.get(p)||[],n.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,g=e.getChildren();d<g.length;d++){var m=g[d];this._collectBuffers(m,t,r,n,o)}},e.prototype._exportBuffers=function(e,t){for(var r=new Map,n=new Map,o=new Map,a=0,s=e;a<s.length;a++){var i=s[a];this._collectBuffers(i,r,n,o,t)}for(var u=Array.from(r.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var a=r.get(e);if(!a)return"continue";var s=a[0].byteStride;if(a.some((function(e){return e.byteStride!==s})))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var i=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=n.get(e),r=W(e,t),o=r.byteOffset,a=r.byteStride,s=r.componentCount,u=r.type,c=r.count,h=r.normalized;switch(r.kind){case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:(0,x.EnumerateFloatValues)(i,o,a,s,u,c,h,(function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var r=1/t;e[0]*=r,e[1]*=r,e[2]*=r}}));break;case x.VertexBuffer.ColorKind:var f=t.filter((function(e){return e.material instanceof x.StandardMaterial||null==e.material})).length;if(0==f)break;if(f!=t.length){x.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==x.VertexBuffer.UNSIGNED_BYTE&&x.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var p=new x.Color3,d=new x.Color4,g=l._babylonScene.getEngine().useExactSrgbConversions;(0,x.EnumerateFloatValues)(i,o,a,s,u,c,h,(function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,g),p.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0))}))}},c=0,h=a;c<h.length;c++)u(F=h[c]);if(t.convertToRightHanded){for(var f=0,p=a;f<p.length;f++){var d=W(F=p[f],n.get(F)),g=d.byteOffset,m=d.byteStride,_=d.componentCount,T=d.type,v=d.count,y=d.normalized;switch(C=d.kind){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:case x.VertexBuffer.TangentKind:(0,x.EnumerateFloatValues)(i,g,m,_,T,v,y,(function(e){e[0]=-e[0]}))}}t.convertedToRightHandedBuffers.set(e,i)}var b=l._bufferManager.createBufferView(i,s);t.setVertexBufferView(e,b);for(var M=new Map,w=0,A=a;w<A.length;w++){var R=W(F=A[w],n.get(F)),C=R.kind,E=R.totalVertices;switch(C){case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:if(F.type==x.VertexBuffer.FLOAT){var I=F.getFloatData(E);null!==I&&M.set(F,I)}}}0!==M.size&&x.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var S=0,V=Array.from(M.keys());S<V.length;S++){var F=V[S],B=M.get(F);if(B){for(var O=B.some((function(e){return e>=256})),P=new(O?Uint16Array:Uint8Array)(B.length),U=0;U<B.length;U++)P[U]=B[U];var N=l._bufferManager.createBufferView(P,4*(O?2:1));t.setRemappedBufferView(e,F,N)}}},l=this,h=0,f=u;h<f.length;h++)c(f[h]);for(var p=0,d=Array.from(o.keys());p<d.length;p++){var g=d[p],m=o.get(g);if(m)for(var _=ae(g,m[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),T=0,v=m;T<v.length;T++){var y=v[T];t.bindMorphDataToMesh(y,_)}}},e.prototype._exportNodeAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h=this;return y(this,(function(f){switch(f.label){case 0:return void 0!==(n=this._nodeMap.get(e))?(t.includes(n)||t.push(n),[2]):[4,this._createNodeAsync(e,r)];case 1:(o=f.sent())&&(n=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),a={name:"runtime animations",channels:[],samplers:[]},s=[],this._babylonScene.animationGroups.length||(oe._CreateMorphTargetAnimationFromMorphTargetAnimations(e,a,s,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&oe._CreateNodeAnimationFromNodeAnimations(e,a,s,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation)),a.channels.length&&a.samplers.length&&this._animations.push(a),s.forEach((function(e){e.channels.length&&e.samplers.length&&h._animations.push(e)}))),i=o?[]:t,u=0,c=e.getChildren(),f.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,i,r)]):[3,5];case 3:f.sent(),f.label=4;case 4:return u++,[3,2];case 5:return o&&i.length&&(o.children=i),[2]}}))}))},e.prototype._createNodeAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c,l,h,f,p;return y(this,(function(d){switch(d.label){case 0:return this._shouldExportNode(e)?(r={},e.name&&(r.name=e.name),e.metadata&&(n=this._options.metadataSelector(e.metadata))&&(r.extras=n),e instanceof x.TransformNode?(this._setNodeTransformation(r,e,t.convertToRightHanded),e instanceof x.AbstractMesh?(o=e instanceof x.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(a=r,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:a.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(s=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(s)&&this._nodesSkinMap.set(s,[]),null===(h=this._nodesSkinMap.get(s))||void 0===h||h.push(r)),d.label=3;case 3:if(e instanceof x.TargetCamera&&(i=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(i)&&this._nodesCameraMap.set(i,[]),this._setCameraTransformation(r,e,t.convertToRightHanded),null!==(u=e.parent)&&Y(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],X(r,l),null===(f=this._nodesCameraMap.get(i))||void 0===f||f.push(l),[2,null];null===(p=this._nodesCameraMap.get(i))||void 0===p||p.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,r]:(x.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}}))}))},e.prototype._exportIndices=function(e,t,r,n,o,a,s,i,u){var c=null;u.mode=function(e){switch(e){case x.Material.TriangleFillMode:return 4;case x.Material.TriangleStripDrawMode:return 5;case x.Material.TriangleFanDrawMode:return 6;case x.Material.PointListDrawMode:case x.Material.PointFillMode:return 0;case x.Material.LineLoopDrawMode:return 2;case x.Material.LineListDrawMode:return 1;case x.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}(a);var l=s!==x.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case x.Material.TriangleFillMode:case x.Material.TriangleStripDrawMode:case x.Material.TriangleFanDrawMode:return!0}return!1}(a);if(l){if(a===x.Material.TriangleStripDrawMode||a===x.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");var h=t?new Uint32Array(n):new Uint16Array(n);if(e)for(var f=0;f+2<n;f+=3)h[f]=e[r+f]+o,h[f+1]=e[r+f+2]+o,h[f+2]=e[r+f+1]+o;else for(f=0;f+2<n;f+=3)h[f]=f,h[f+1]=f+2,h[f+2]=f+1;c=h}else if(e&&0!==o){for(h=t?new Uint32Array(n):new Uint16Array(n),f=0;f<n;f++)h[f]=e[r+f]+o;c=h}else e&&(c=function(e,t,r,n){var o=e;return 0===t&&r===e.length||(o=Array.isArray(e)?e.slice(t,t+r):e.subarray(t,t+r)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?n?new Uint32Array(o):new Uint16Array(o):o}(e,r,n,t));if(c){var p=i.getIndicesAccessor(e,r,n,o,l);if(void 0===p){var d=this._bufferManager.createBufferView(c),g=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(d,"SCALAR",g,n,0)),p=this._accessors.length-1,i.setIndicesAccessor(e,r,n,o,l,p)}u.indices=p}},e.prototype._exportVertexBuffer=function(e,t,r,n,o,a){var s=e.getKind();if(q(s)&&(!s.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var i=o.getVertexAccessor(e,r,n);if(void 0===i){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=s===x.VertexBuffer.PositionKind?function(e,t,r,n){var o=t.byteOffset,a=t.byteStride,s=t.type,i=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,x.EnumerateFloatValues)(e,o+r*a,a,u,s,n*u,i,(function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])})),{min:c,max:l}}(u,e,r,n):void 0,l=(s===x.VertexBuffer.MatricesIndicesKind||s===x.VertexBuffer.MatricesIndicesExtraKind)&&e.type===x.VertexBuffer.FLOAT,h=l?x.VertexBuffer.UNSIGNED_BYTE:e.type,f=l?void 0:e.normalized,p=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(p,function(e,t){if(e==x.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case x.VertexBuffer.PositionKind:case x.VertexBuffer.NormalKind:return"VEC3";case x.VertexBuffer.TangentKind:case x.VertexBuffer.MatricesIndicesKind:case x.VertexBuffer.MatricesIndicesExtraKind:case x.VertexBuffer.MatricesWeightsKind:case x.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case x.VertexBuffer.UVKind:case x.VertexBuffer.UV2Kind:case x.VertexBuffer.UV3Kind:case x.VertexBuffer.UV4Kind:case x.VertexBuffer.UV5Kind:case x.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(s,o.hasVertexColorAlpha(e)),h,n,d,c,f)),i=this._accessors.length-1,o.setVertexAccessor(e,r,n,i)}a.attributes[function(e){switch(e){case x.VertexBuffer.PositionKind:return"POSITION";case x.VertexBuffer.NormalKind:return"NORMAL";case x.VertexBuffer.TangentKind:return"TANGENT";case x.VertexBuffer.ColorKind:return"COLOR_0";case x.VertexBuffer.UVKind:return"TEXCOORD_0";case x.VertexBuffer.UV2Kind:return"TEXCOORD_1";case x.VertexBuffer.UV3Kind:return"TEXCOORD_2";case x.VertexBuffer.UV4Kind:return"TEXCOORD_3";case x.VertexBuffer.UV5Kind:return"TEXCOORD_4";case x.VertexBuffer.UV6Kind:return"TEXCOORD_5";case x.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case x.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case x.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case x.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(s)]=i}},e.prototype._exportMaterialAsync=function(e,t,r,n){return v(this,void 0,void 0,(function(){var o,a;return y(this,(function(s){switch(s.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,8]:(a=t&&Object.keys(t).some((function(e){return e.startsWith("uv")})),(e=e instanceof x.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof x.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,a)]:[3,2]);case 1:return o=s.sent(),[3,7];case 2:return e instanceof x.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,a)]:[3,4];case 3:return o=s.sent(),[3,7];case 4:return e instanceof x.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,a)]:[3,6];case 5:return o=s.sent(),[3,7];case 6:return x.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,o),s.label=8;case 8:return n.material=o,[2]}}))}))},e.prototype._exportMeshAsync=function(e,t){return v(this,void 0,void 0,(function(){var r,n,o,a,s,i,u,c,l,h,f,p,d,g,m,_,T,v,M,w,A,R,C,E,I,S,V,F,B,O,P,U,N,L;return y(this,(function(y){switch(y.label){case 0:if(void 0!==(r=t.getMesh(e)))return[2,r];if(n={primitives:[]},r=this._meshes.length,this._meshes.push(n),t.setMesh(e,r),o=e.isUnIndexed?null:e.getIndices(),a=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),s=t.getMorphTargetsFromMesh(e),i=e instanceof x.LinesMesh,u=e instanceof x.GreasedLineBaseMesh,c=e.subMeshes,!(a&&c&&c.length>0))return[3,7];l=0,h=c,y.label=1;case 1:return l<h.length?(f=h[l],p={attributes:{}},d=f.getMaterial()||this._babylonScene.defaultMaterial,u?(T={name:d.name},v=e,g=x.Color3.White(),m=null!==(P=null===(O=v.material)||void 0===O?void 0:O.alpha)&&void 0!==P?P:1,(!(_=null!==(N=null===(U=v.greasedLineMaterial)||void 0===U?void 0:U.color)&&void 0!==N?N:g).equalsWithEpsilon(g,x.Epsilon)||m<1)&&(T.pbrMetallicRoughness={baseColorFactor:b(b([],_.asArray(),!0),[m],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return i?(T={name:d.name},(!(v=e).color.equalsWithEpsilon(x.Color3.White(),x.Epsilon)||v.alpha<1)&&(T.pbrMetallicRoughness={baseColorFactor:b(b([],v.color.asArray(),!0),[v.alpha],!1)}),this._materials.push(T),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,a,f,p)];case 4:y.sent(),y.label=5;case 5:for(M=i||u?x.Material.LineListDrawMode:null!==(L=e.overrideRenderingFillMode)&&void 0!==L?L:d.fillMode,w=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(w=w===x.Material.ClockWiseSideOrientation?x.Material.CounterClockWiseSideOrientation:x.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,x.AreIndices32Bits)(o,f.indexCount,f.indexStart,f.verticesStart):f.verticesCount>65535,o?f.indexStart:f.verticesStart,o?f.indexCount:f.verticesCount,-f.verticesStart,M,w,t,p),A=0,R=Object.values(a);A<R.length;A++)C=R[A],this._exportVertexBuffer(C,d,f.verticesStart,f.verticesCount,t,p);if(s)for(p.targets=[],E=0,I=s;E<I.length;E++)F=I[E],p.targets.push(F.attributes);n.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),y.label=6;case 6:return l++,[3,1];case 7:if(s)for(n.weights=[],n.extras||(n.extras={}),n.extras.targetNames=[],S=0,V=s;S<V.length;S++)F=V[S],n.weights.push(F.influence),n.extras.targetNames.push(F.name);return[2,r]}}))}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),ue=function(){function e(){}return e.GLTFAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o;return y(this,(function(a){switch(a.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(n=new ie(e,r)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.sent(),n.dispose(),[2,o]}}))}))},e.GLBAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o;return y(this,(function(a){switch(a.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:a.sent(),a.label=2;case 2:return[4,(n=new ie(e,r)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=a.sent(),n.dispose(),[2,o]}}))}))},e}(),ce="EXT_mesh_gpu_instancing";function le(e,t){for(var r=new Float32Array(3*t),n=0;n<t;n++)r[3*n+0]=e[4*n+0],r[3*n+1]=e[4*n+1],r[3*n+2]=e[4*n+2];return r}var he=function(){function e(e){this.name=ce,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,r,n,o,a){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var s,i;if(t&&r instanceof x.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var u=x.Vector3.Zero(),c=x.Quaternion.Identity(),l=x.Vector3.One(),h=r.thinInstanceGetWorldMatrices(),f=x.TmpVectors.Vector3[2],p=x.TmpVectors.Quaternion[1],d=x.TmpVectors.Vector3[3],g=!1,m=!1,_=!1,T=new Float32Array(3*r.thinInstanceCount),v=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),b=0,M=0,w=h;M<w.length;M++)w[M].decompose(d,p,f),o&&(H(f),j(p)),T.set(f.asArray(),3*b),v.set(p.normalize().asArray(),4*b),y.set(d.asArray(),3*b),g=g||!f.equalsWithEpsilon(u),m=m||!p.equalsWithEpsilon(c),_=_||!d.equalsWithEpsilon(l),b++;var A={attributes:{}};g&&(A.attributes.TRANSLATION=e._buildAccessor(T,"VEC3",r.thinInstanceCount,a)),m&&(A.attributes.ROTATION=e._buildAccessor(v,"VEC4",r.thinInstanceCount,a)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,a));var R=null===(i=null===(s=r._userThinInstanceBuffersStorage)||void 0===s?void 0:s.data)||void 0===i?void 0:i.instanceColor;if(R){var C=r.thinInstanceCount;r.hasVertexAlpha&&R.length===4*C?(e._instanceColorWarned||(x.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),R=le(R,C)):R.length===4*C&&(R=le(R,C)),R.length===3*C&&(A.attributes._COLOR_0=e._buildAccessor(R,"VEC3",C,a))}t.extensions=t.extensions||{},t.extensions[ce]=A}n(t)}))];case 1:return[2,n.sent()]}}))}))},e.prototype._buildAccessor=function(e,t,r,n){var o=n.createBufferView(e),a=n.createAccessor(o,t,5126,r);return this._exporter._accessors.push(a),this._exporter._accessors.length-1},e}();ie.RegisterExtension(ce,(function(e){return new he(e)}));var fe="KHR_draco_mesh_compression",pe=function(){function e(e){this.name=fe,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&x.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,r){var n=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],a=[],s=null;if(void 0!==e.indices){var i=r[e.indices],u=t.getBufferView(i);s=t.getData(u).slice(),o.push(u),a.push(i)}for(var c,l=[],h=0,f=Object.entries(e.attributes);h<f.length;h++){var p=f[h],d=p[0],g=(i=r[p[1]],u=t.getBufferView(i),D(i.type)),m=(0,x.GetTypedArrayData)(t.getData(u),g,i.componentType,i.byteOffset||0,u.byteStride||(0,x.GetTypeByteLength)(i.componentType)*g,i.count,!0);l.push({kind:d,dracoName:(c=d,"POSITION"===c?"POSITION":"NORMAL"===c?"NORMAL":c.startsWith("COLOR")?"COLOR":c.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"),size:D(i.type),data:m}),o.push(u),a.push(i)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},T=x.DracoEncoder.Default._encodeAsync(l,s,_).then((function(r){if(r){var s={bufferView:-1,attributes:r.attributeIds},i=t.createBufferView(r.data);t.setBufferView(s,i);for(var u=0,c=o;u<c.length;u++){var l=c[u];n._bufferViewsUsed.add(l)}for(var h=0,f=a;h<f.length;h++){var p=f[h];n._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[fe]=s}else x.Logger.Error("Draco encoding failed for primitive.")})).catch((function(e){x.Logger.Error("Draco encoding failed for primitive: "+e)}));this._encodePromises.push(T),this._wasUsed=!0}else x.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return v(this,void 0,void 0,(function(){var t=this;return y(this,(function(r){switch(r.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return r.sent(),this._bufferViewsUsed.forEach((function(r){e.getPropertiesWithBufferView(r).every((function(e){return t._accessorsUsed.has(e)}))&&e.removeBufferView(r)})),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}}))}))},e}();ie.RegisterExtension(fe,(function(e){return new pe(e)}));var de="KHR_lights_punctual",xe={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},ge={innerConeAngle:0,outerConeAngle:Math.PI/4},me=x.Vector3.Backward(),_e=function(){function e(e){this.name=de,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[de]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a=this;return y(this,(function(s){switch(s.label){case 0:return[4,new Promise((function(s){if(r instanceof x.Light){var i=r.getTypeID()==x.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==x.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==x.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(i&&r instanceof x.ShadowLight))return x.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(de)),void s(t);if(r.falloffType!==x.Light.FALLOFF_GLTF&&x.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(de," specification!")),!r.position.equalsToFloats(0,0,0)){var u=x.TmpVectors.Vector3[0].copyFrom(r.position);o&&H(u),t.translation=u.asArray()}if("point"!==i){var c=r.direction.normalizeToRef(x.TmpVectors.Vector3[0]);o&&H(c);var l=x.Quaternion.FromUnitVectorsToRef(me,c,x.TmpVectors.Quaternion[0]);x.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var h={type:i,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(Z(h,xe),"spot"===i){var f=r;h.spot={innerConeAngle:f.innerAngle/2,outerConeAngle:f.angle/2},Z(h.spot,ge)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(h);var p={light:a._lights.lights.length-1},d=r.parent;if(d&&Y(r,d)){var g=n.get(d);if(g){var m=a._exporter._nodes[g];return X(t,m),m.extensions||(m.extensions={}),m.extensions[de]=p,void s(null)}}t.extensions||(t.extensions={}),t.extensions[de]=p,s(t)}else s(t)}))];case 1:return[2,s.sent()]}}))}))},e}();ie.RegisterExtension(de,(function(e){return new _e(e)}));var Te="EXT_lights_area",ve={name:"",color:[1,1,1],intensity:1,size:1},ye={aspect:1},be=x.Vector3.Backward(),Me=function(){function e(e){this.name=Te,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[Te]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n,o){return v(this,void 0,void 0,(function(){var a=this;return y(this,(function(s){switch(s.label){case 0:return[4,new Promise((function(s){if(r instanceof x.Light){var i=r.getTypeID()==x.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!i)return x.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(Te)),void s(t);var u=r;if(u.falloffType!==x.Light.FALLOFF_GLTF&&x.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(Te," specification!")),!u.position.equalsToFloats(0,0,0)){var c=x.TmpVectors.Vector3[0].copyFrom(u.position);o&&H(c),t.translation=c.asArray()}var l=x.Vector3.Forward();o&&H(l);var h=x.Quaternion.FromUnitVectorsToRef(be,l,x.TmpVectors.Quaternion[0]);x.Quaternion.IsIdentity(h)||(t.rotation=h.asArray());var f={type:i,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};Z(f,ve),f.rect&&Z(f.rect,ye),a._lights||(a._lights={lights:[]}),a._lights.lights.push(f);var p={light:a._lights.lights.length-1},d=r.parent;if(d&&Y(u,d)){var g=n.get(d);if(g){var m=a._exporter._nodes[g];return X(t,m),m.extensions||(m.extensions={}),m.extensions[Te]=p,void s(null)}}t.extensions||(t.extensions={}),t.extensions[Te]=p,s(t)}else s(t)}))];case 1:return[2,s.sent()]}}))}))},e}();ie.RegisterExtension(Te,(function(e){return new Me(e)}));var we="KHR_materials_anisotropy";function Ae(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r||n?[4,(0,x.MergeTexturesAsync)("AnisotropyTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(0),r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}}))}))}var Re=function(){function e(e){this.name=we,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n;return y(this,(function(o){switch(o.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&e.push(r.anisotropy.texture),[2,e]):[3,5]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0?(t=function(e){var t=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoTangent";return"".concat(n,"_").concat(o)}(r),this._anisoTexturesMap[t]?(e.push(this._anisoTexturesMap[t]),[3,4]):[3,2]):[3,5];case 2:return[4,Ae(r)];case 3:(n=o.sent())&&(e.push(n),this._anisoTexturesMap[t]=n),o.label=4;case 4:return[2,e];case 5:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,s,i,u,c;if(r instanceof x.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var l=n._exporter._materialExporter.getTextureInfo(r.anisotropy.texture);null!==(T={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[we]=T}else if(r instanceof x.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){n._wasUsed=!0,t.extensions=t.extensions||{};var h=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(h=r.baseMetalnessTexture);var f=n._anisoTexturesMap[r.id];if(!h&&!f){var p=r.specularRoughness,d=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var g=(a=r.specularRoughness,c=(1-(s=r.specularRoughnessAnisotropy))*(u=(i=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-i)/Math.max(1-i,1e-4)),1)});p=g.newBaseRoughness,d=g.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=p);var m={anisotropyStrength:d,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[we]=m,e(t)}var _=f?n._exporter._materialExporter.getTextureInfo(f):null,T={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};r._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=n._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&n._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),n._exporter._materialNeedsUVsSet.add(r),t.extensions[we]=T}e(t)}))},e}();ie.RegisterExtension(we,(function(e){return new Re(e)}));var Ce="KHR_materials_clearcoat";function Ee(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("CoatTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useCoatRoughnessFromGreenChannel?1:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Ie(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var Se=function(){function e(e){this.name=Ce,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o;return y(this,(function(a){switch(a.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.clearCoat.isEnabled?(r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),[2,e]):[3,5]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.coatWeight>0?(t=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):t=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):t=!0),t?(n=function(e){var t=e.coatWeightTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",n=e.coatRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoRoughness";return"".concat(r,"_").concat(o)}(r),this._cachedInternalTexturesMap[n]?[3,3]:[4,Ee(r)]):[3,4]):[3,5];case 2:(o=a.sent())&&(this._cachedInternalTexturesMap[n]=o),a.label=3;case 3:this._cachedInternalTexturesMap[n]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[n],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]))),a.label=4;case 4:return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),[2,e];case 5:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o,a=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);o=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&x.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&x.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var s=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture);null===(c={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ce]=c}else if(r instanceof x.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i=null,u=void 0;r.coatWeightTexture&&(i=n._mergedTexturesMap[r.coatWeightTexture.uniqueId],u=n._exporter._materialExporter.getTextureInfo(i));var c,l=null,h=void 0;r.coatRoughnessTexture&&(l=n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],h=n._exporter._materialExporter.getTextureInfo(l)),r.coatColorTexture&&x.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),s=n._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),null===(c={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=u?u:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=h?h:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ce]=c}e(t)}))},e}();ie.RegisterExtension(Ce,(function(e){return new Se(e)}));var Ve="KHR_materials_coat";function Fe(e){var t=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoTangent";return"".concat(n,"_").concat(o)}function Be(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r||n?[4,(0,x.MergeTexturesAsync)("AnisotropyTexture",(0,x.CreateRGBAConfiguration)(n?(0,x.CreateTextureInput)(n,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,1):(0,x.CreateConstantInput)(0),r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}}))}))}function Oe(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("CoatTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useCoatRoughnessFromGreenChannel?1:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Pe(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var Ue=function(){function e(e){this.name=Ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o,a;return y(this,(function(s){switch(s.label){case 0:return e=[],r instanceof x.PBRBaseMaterial?r.clearCoat.isEnabled?(r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),r.clearCoat.tintTexture&&e.push(r.clearCoat.tintTexture),[2,e]):[3,9]:[3,1];case 1:return r instanceof x.OpenPBRMaterial&&r.coatWeight>0?(t=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):t=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):t=!0),t?(o=function(e){var t=e.coatWeightTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",n=e.coatRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoRoughness";return"".concat(r,"_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,3]:[4,Oe(r)]):[3,4]):[3,9];case 2:(n=s.sent())&&(this._cachedInternalTexturesMap[o]=n),s.label=3;case 3:this._cachedInternalTexturesMap[o]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[o],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[o],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]))),s.label=4;case 4:return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatColorTexture&&e.push(r.coatColorTexture),r.coatRoughnessAnisotropy>0?(o=Fe(r),this._mergedTexturesMap[o]?(e.push(this._mergedTexturesMap[o]),[3,7]):[3,5]):[3,8];case 5:return[4,Be(r)];case 6:(a=s.sent())&&(e.push(a),this._mergedTexturesMap[o]=a),s.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,s,i,u,c;if(r instanceof x.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var l,h=n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);l=r.clearCoat.useRoughnessFromMainTexture?n._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):n._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness);var f=void 0;r.clearCoat.isTintEnabled&&(f=n._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));var p=n._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),d=r.clearCoat.indexOfRefraction;null===(T={coatFactor:r.clearCoat.intensity,coatTexture:null!=h?h:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=l?l:void 0,coatNormalTexture:null!=p?p:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==d?d:void 0}).coatTexture&&null===T.coatRoughnessTexture&&null===T.coatRoughnessTexture&&null===T.coatColorTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ve]=T}else if(r instanceof x.OpenPBRMaterial){if(0==r.coatWeight)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var g=null;h=void 0,r.coatWeightTexture&&(g=n._mergedTexturesMap[r.coatWeightTexture.uniqueId]?n._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,h=n._exporter._materialExporter.getTextureInfo(g));var m=null,_=void 0;r.coatRoughnessTexture&&(m=n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?n._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,_=n._exporter._materialExporter.getTextureInfo(m)),p=n._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),f=n._exporter._materialExporter.getTextureInfo(r.coatColorTexture),d=r.coatIor;var T,v=r.coatDarkening,y=r.coatRoughnessTexture,b=Fe(r),M=n._mergedTexturesMap[b],w=0,A=0,R=void 0;if(r.coatRoughnessAnisotropy>0){if(y||M){var C=M?n._exporter._materialExporter.getTextureInfo(M):null;w=r.coatRoughnessAnisotropy,A=r.geometryCoatTangentAngle,R=C||void 0}else{var E=r.coatRoughness,I=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var S=(a=r.coatRoughness,c=(1-(s=r.coatRoughnessAnisotropy))*(u=(i=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-i)/Math.max(1-i,1e-4)),1)});E=S.newBaseRoughness,I=S.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=E),w=I,A=r.geometryCoatTangentAngle+.5*Math.PI,R=void 0}r._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=n._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&n._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(T={coatFactor:r.coatWeight,coatTexture:null!=h?h:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=_?_:void 0,coatNormalTexture:null!=p?p:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==d?d:void 0,coatDarkeningFactor:1!==v?v:void 0,coatAnisotropyRotation:A,coatAnisotropyStrength:w,coatAnisotropyTexture:R}).coatTexture&&null===T.coatRoughnessTexture&&null===T.coatRoughnessTexture&&null===T.coatAnisotropyTexture&&null===T.coatColorTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[Ve]=T}e(t)}))},e}();ie.RegisterExtension(Ve,(function(e){return new Ue(e)}));var Ne="KHR_materials_diffuse_transmission";function Le(e,t){var r=t.subSurface,n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(x.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):n}var ke=function(){function e(e){this.name=Ne,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var t,n;return y(this,(function(o){return t=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?((n=Le(e,r))&&t.push(n),r.subSurface.translucencyColorTexture&&t.push(r.subSurface.translucencyColorTexture),[2,t]):[2,t]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(o){var a,s;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,u=Le(e,r),c=0==i.translucencyIntensity?void 0:i.translucencyIntensity,l=null!==(a=n._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0,h=!i.translucencyColor||i.translucencyColor.equalsFloats(1,1,1)?void 0:i.translucencyColor.asArray(),f=null!==(s=n._exporter._materialExporter.getTextureInfo(i.translucencyColorTexture))&&void 0!==s?s:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:h,diffuseTransmissionColorTexture:f};(l||f)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[Ne]=p}o(t)}))},e}();ie.RegisterExtension(Ne,(function(e){return new ke(e)}));var Ke="KHR_materials_dispersion",ze=function(){function e(){this.name=Ke,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Ke]=o}e(t)}))},e}();ie.RegisterExtension(Ke,(function(){return new ze}));var We="KHR_materials_emissive_strength",De=function(){function e(){this.name=We,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){if(!(r instanceof x.PBRMaterial))return n(t);var o=r.emissiveColor.scale(r.emissiveIntensity),a=Math.max.apply(Math,o.asArray());if(a>1){t.emissiveFactor=o.scale(1/a).asArray(),e._wasUsed=!0;var s={emissiveStrength:a};t.extensions||(t.extensions={}),t.extensions[We]=s}else t.emissiveFactor=o.asArray();return n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(We,(function(){return new De}));var qe="KHR_materials_ior",Ge=function(){function e(){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[qe]=o}e(t)}))},e}();ie.RegisterExtension(qe,(function(e){return new Ge}));var He="KHR_materials_iridescence",je=function(){function e(e){this.name=He,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){if(e=[],r instanceof x.PBRBaseMaterial){if(r.iridescence.isEnabled)return r.iridescence.texture&&e.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&e.push(r.iridescence.thicknessTexture),[2,e]}else if(r instanceof x.OpenPBRMaterial&&r.thinFilmWeight>0)return r.thinFilmWeightTexture&&e.push(r.thinFilmWeightTexture),r.thinFilmThicknessTexture&&r.thinFilmThicknessTexture!==r.thinFilmWeightTexture&&e.push(r.thinFilmThicknessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var o=n._exporter._materialExporter.getTextureInfo(r.iridescence.texture),a=n._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture);null===(s={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=a?a:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=s}else if(r instanceof x.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var s,i=n._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),u=n._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture);null===(s={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=i?i:void 0,iridescenceThicknessTexture:null!=u?u:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||n._exporter._materialNeedsUVsSet.add(r),t.extensions[He]=s}e(t)}))},e}();ie.RegisterExtension(He,(function(e){return new je(e)}));var Qe="KHR_materials_sheen",Xe=function(){function e(e){this.name=Qe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){return y(this,(function(e){return r instanceof x.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[2,[r.sheen.texture]]:[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var o,a,s,i;if(r instanceof x.PBRMaterial){if(!r.sheen.isEnabled)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=r.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(u.sheenColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),t.extensions[Qe]=u}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(Qe,(function(e){return new Xe(e)}));var Ye="KHR_materials_fuzz";function Ze(e){return v(this,void 0,void 0,(function(){var t,r,n;return y(this,(function(o){switch(o.label){case 0:return t=e.getScene(),r=e.fuzzColorTexture,n=e.fuzzRoughnessTexture,r||n?[4,(0,x.MergeTexturesAsync)("FuzzTexture",(0,x.CreateRGBAConfiguration)(r?(0,x.CreateTextureInput)(r,0):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,1):(0,x.CreateConstantInput)(1),r?(0,x.CreateTextureInput)(r,2):(0,x.CreateConstantInput)(1),n?(0,x.CreateTextureInput)(n,e._useFuzzRoughnessFromTextureAlpha?3:0):(0,x.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}}))}))}function Je(e,t){var r=new x.Texture(t.name,t.getScene());return r._texture=e,r.coordinatesIndex=t.coordinatesIndex,t instanceof x.Texture&&(r.uOffset=t.uOffset,r.vOffset=t.vOffset,r.uScale=t.uScale,r.vScale=t.vScale,r.wAng=t.wAng),r.wrapU=t.wrapU,r.wrapV=t.wrapV,r}var $e=function(){function e(e){this.name=Ye,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,o=Object.keys(this._cachedInternalTexturesMap);n<o.length;n++)r=o[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e,t,n,o;return y(this,(function(a){switch(a.label){case 0:return r instanceof x.OpenPBRMaterial?(e=[],r.fuzzWeight>0?(r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture),t=!1,r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):t=!0),r.fuzzColorTexture&&!t&&e.push(r.fuzzColorTexture),t?(n=function(e){var t=e.fuzzColorTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",n=e.fuzzRoughnessTexture,o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(r,"_FuzzRoughness_").concat(o)}(r),this._cachedInternalTexturesMap[n]?[3,2]:[4,Ze(r)]):[3,3]):[3,3]):[3,4];case 1:(o=a.sent())&&(this._cachedInternalTexturesMap[n]=o),a.label=2;case 2:this._cachedInternalTexturesMap[n]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=Je(this._cachedInternalTexturesMap[n],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=Je(this._cachedInternalTexturesMap[n],r.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]))),a.label=3;case 3:return[2,e];case 4:return[2,[]]}}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e=this;return y(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){var o,a,s;if(r instanceof x.OpenPBRMaterial){if(0==r.fuzzWeight)return void n(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var i={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};r.fuzzWeightTexture&&(i.fuzzTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==o?o:void 0);var u=null;r.fuzzColorTexture&&(u=e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,i.fuzzColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(u))&&void 0!==a?a:void 0);var c=null;r.fuzzRoughnessTexture&&(c=e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,i.fuzzRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==s?s:void 0),null===i.fuzzColorTexture&&null===i.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),t.extensions[Ye]=i}n(t)}))];case 1:return[2,n.sent()]}}))}))},e}();ie.RegisterExtension(Ye,(function(e){return new $e(e)}));var et="KHR_materials_specular",tt=function(){function e(e){this.name=et,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){return e=[],r instanceof x.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.reflectanceTexture),[2,e]):[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a,s,i,u;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(o=n._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,l=null!==(a=n._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,h={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:c,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:l};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[et]=h}else if(r instanceof x.OpenPBRMaterial){t.extensions=t.extensions||{};var f=null!==(s=n._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==s?s:void 0,p=null!==(i=n._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==i?i:void 0,d=1==r.specularWeight?void 0:r.specularWeight,g=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!p&&!f&&void 0===d&&void 0===g)return e(t);n._wasUsed=!0,(h={specularFactor:d,specularTexture:f,specularColorFactor:g,specularColorTexture:p,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=n._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===n._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&n._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(f||p)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[et]=h}e(t)}))},e}();ie.RegisterExtension(et,(function(e){return new tt(e)}));var rt="KHR_materials_transmission",nt=function(){function e(e){this.name=rt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){if(e=[],r instanceof x.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.refractionIntensityTexture&&r.subSurface.useGltfStyleTextures&&e.push(r.subSurface.refractionIntensityTexture),[2,e]}else r instanceof x.OpenPBRMaterial&&r.transmissionWeight>0&&r.transmissionWeightTexture&&e.push(r.transmissionWeightTexture);return[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){if(e instanceof x.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0;if(e instanceof x.PBRMaterial&&!e.unlit){var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||null!=t.refractionIntensityTexture&&t.useGltfStyleTextures}return!1},e.prototype.postExportMaterialAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s;return y(this,(function(i){return this._isExtensionEnabled(r)?(r instanceof x.PBRMaterial?(this._wasUsed=!0,n=r.subSurface,o=0===n.refractionIntensity?void 0:n.refractionIntensity,a={transmissionFactor:o},n.refractionIntensityTexture&&(n.useGltfStyleTextures?(this._exporter._materialNeedsUVsSet.add(r),(s=this._exporter._materialExporter.getTextureInfo(n.refractionIntensityTexture))&&(a.transmissionTexture=s)):x.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported"))),t.extensions||(t.extensions={}),t.extensions[rt]=a):r instanceof x.OpenPBRMaterial&&(this._wasUsed=!0,o=r.transmissionWeight,a={transmissionFactor:o},r.transmissionWeightTexture&&(this._exporter._materialNeedsUVsSet.add(r),(s=this._exporter._materialExporter.getTextureInfo(r.transmissionWeightTexture))&&(a.transmissionTexture=s)),1===o&&t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=void 0),t.extensions||(t.extensions={}),t.extensions[rt]=a),[2,t]):[2,t]}))}))},e}();ie.RegisterExtension(rt,(function(e){return new nt(e)}));var ot="KHR_materials_unlit",at=function(){function e(){this.name=ot,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o=!1;r instanceof x.PBRMaterial?o=r.unlit:r instanceof x.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ot]={}),e(t)}))},e}();ie.RegisterExtension(ot,(function(){return new at}));var st="KHR_materials_volume",it=function(){function e(e){this.name=st,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){if(e=[],r instanceof x.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]}else r instanceof x.OpenPBRMaterial&&r.transmissionWeight>0&&r.geometryThicknessTexture&&e.push(r.geometryThicknessTexture);return[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=x.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o,a;if(r instanceof x.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var s=r.subSurface,i={thicknessFactor:0==s.maximumThickness?void 0:s.maximumThickness,thicknessTexture:null!==(o=n._exporter._materialExporter.getTextureInfo(s.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:s.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:s.tintColorAtDistance,attenuationColor:s.tintColor.equalsFloats(1,1,1)?void 0:s.tintColor.asArray()};n._hasTexturesExtension(r)&&n._exporter._materialNeedsUVsSet.add(r),t.extensions=t.extensions||{},t.extensions[st]=i}else r instanceof x.OpenPBRMaterial&&r.transmissionWeight>0&&(n._wasUsed=!0,i={thicknessFactor:r.geometryThickness,thicknessTexture:null!==(a=n._exporter._materialExporter.getTextureInfo(r.geometryThicknessTexture))&&void 0!==a?a:void 0,attenuationDistance:r.transmissionDepth,attenuationColor:r.transmissionColor.equalsFloats(1,1,1)?void 0:r.transmissionColor.asArray()},t.extensions=t.extensions||{},t.extensions[st]=i);e(t)}))},e}();ie.RegisterExtension(st,(function(e){return new it(e)}));var ut="KHR_materials_volume_scatter",ct=function(){function e(e){this.name=ut,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){return e=[],r instanceof x.OpenPBRMaterial&&r.transmissionWeight>0&&r.transmissionScatterTexture&&e.push(r.transmissionScatterTexture),[2,e]}))}))},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&0!=e.transmissionWeight&&!e.transmissionScatter.equals(x.Color3.Black())},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof x.OpenPBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o=1/r.transmissionDepth,a=new x.Vector3(-Math.log(r.transmissionColor.r)*o,-Math.log(r.transmissionColor.g)*o,-Math.log(r.transmissionColor.b)*o),s=new x.Vector3(r.transmissionScatter.r*o,r.transmissionScatter.g*o,r.transmissionScatter.b*o),i=a.subtract(s),u=Math.min(i.x,i.y,i.z);u<0&&(i.subtractInPlace(new x.Vector3(u,u,u)),a.copyFrom(i).addInPlace(s));var c={multiscatterColor:(p=new x.Vector3(s.x/a.x,s.y/a.y,s.z/a.z),d=new x.Vector3(Math.sqrt(1-p.x),Math.sqrt(1-p.y),Math.sqrt(1-p.z)),g=new x.Vector3(1,1,1),m=g.subtract(d),_=g.subtract(new x.Vector3(.139,.139,.139).multiplyInPlace(d)),T=g.add(new x.Vector3(1.17,1.17,1.17).multiplyInPlace(d)),m.multiplyInPlace(_).divideInPlace(T)).asArray(),scatterAnisotropy:r.transmissionScatterAnisotropy};if(r.transmissionScatterTexture){n._exporter._materialNeedsUVsSet.add(r);var l=n._exporter._materialExporter.getTextureInfo(r.transmissionScatterTexture);l&&(c.multiscatterColorTexture=l)}if(t.extensions=t.extensions||{},t.extensions[ut]=c,t.extensions.KHR_materials_volume){var h=t.extensions.KHR_materials_volume,f=Math.max(a.x,a.y,a.z);h.attenuationDistance=1/Math.max(f,1e-4),h.attenuationColor=new x.Color3(Math.exp(-a.x*h.attenuationDistance),Math.exp(-a.y*h.attenuationDistance),Math.exp(-a.z*h.attenuationDistance)).asArray()}}var p,d,g,m,_,T;e(t)}))},e}();ie.RegisterExtension(ut,(function(e){return new ct(e)}),101);var lt="KHR_materials_diffuse_roughness",ht=function(){function e(e){this.name=lt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,r){return v(this,void 0,void 0,(function(){var e;return y(this,(function(t){if(e=[],r instanceof x.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),[2,e]}else if(r instanceof x.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),[2,e];return[2,[]]}))}))},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var o=null,a=null;if(r instanceof x.PBRBaseMaterial?(o=r._baseDiffuseRoughness,a=r._baseDiffuseRoughnessTexture):r instanceof x.OpenPBRMaterial&&(o=r.baseDiffuseRoughness,a=r.baseDiffuseRoughnessTexture),o){n._wasUsed=!0,t.extensions=t.extensions||{};var s=n._exporter._materialExporter.getTextureInfo(a),i={diffuseRoughnessFactor:o,diffuseRoughnessTexture:null!=s?s:void 0};null!==i.diffuseRoughnessTexture&&n._exporter._materialNeedsUVsSet.add(r),t.extensions[lt]=i,e(t)}else e(t)}))},e}();ie.RegisterExtension(lt,(function(e){return new ht(e)}));var ft="KHR_materials_openpbr",pt=function(){function e(){this.name=ft,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){r instanceof x.OpenPBRMaterial&&(n._wasUsed=!0,t.extensions=t.extensions||{},t.extensions[ft]={}),e(t)}))},e}();ie.RegisterExtension(ft,(function(e){return new pt}));var dt="KHR_texture_transform",xt=function(){function e(){this.name=dt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,r){if(r.getScene()||x.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with rotation in the u or v axis is not supported in glTF.")),0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(dt,"."));x.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(dt,".")),n.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,o=e.vRotationCenter,a=e.uScale,s=e.vScale,i=e.wAng,u=Math.cos(i),c=Math.sin(i),l=n*a,h=o*s;return[t+(l*(1-u)+h*c),r+(h*(1-u)-l*c)]}(r)}n.rotation=-r.wAng,o=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[dt]=n)}},e}();ie.RegisterExtension(dt,(function(){return new xt}));var gt="KHR_texture_basisu",mt=function(){function e(e){this.name=gt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/ktx2"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[gt]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(gt,(function(e){return new mt(e)}));var _t="EXT_texture_webp",Tt=function(){function e(e){this.name=_t,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/webp"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[_t]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(_t,(function(e){return new Tt(e)}));var vt="EXT_texture_avif",yt=function(){function e(e){this.name=vt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var r=this._exporter._textures[t.index],n=r.source;if(void 0!==n){var o=this._exporter._images[n];"image/avif"===(o.mimeType||(0,x.GetMimeType)(o.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[vt]={source:n},this._wasUsed=!0)}},e}();ie.RegisterExtension(vt,(function(e){return new yt(e)}));var bt=function(){function e(){}return e.CreateSTL=function(e,t,r,n,o,a,s,i){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===a&&(a=!1),void 0===s&&(s=!1),void 0===i&&(i=!1);var u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],o=[new x.Vector3(t[n[0]],t[n[0]+2],t[n[0]+1]),new x.Vector3(t[n[1]],t[n[1]+2],t[n[1]+1]),new x.Vector3(t[n[2]],t[n[2]+2],t[n[2]+1])],a=o[0].subtract(o[1]),s=o[2].subtract(o[1]);return{v:o,n:x.Vector3.Cross(s,a).normalize()}},c=function(e,t,r,n){return t=l(e,t,r.x,n),t=l(e,t,r.y,n),l(e,t,r.z,n)},l=function(e,t,r,n){return e.setFloat32(t,r,n),t+4},h=function(e){if(s){var t=e;e instanceof x.InstancedMesh&&(t=e.sourceMesh);var r=t.getVerticesData(x.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var n=x.Vector3.Zero(),o=void 0;for(o=0;o<r.length;o+=3)x.Vector3.TransformCoordinatesFromFloatsToRef(r[o],r[o+1],r[o+2],e.computeWorldMatrix(!0),n).toArray(r,o);return r}return e.getVerticesData(x.VertexBuffer.PositionKind)||[]};s&&(a=!0);var f="",p=0,d=0;if(n){for(var g=0;g<e.length;g++)p+=(v=(_=e[g]).getIndices())?v.length/3:0;var m=new ArrayBuffer(84+50*p);d+=80,(f=new DataView(m)).setUint32(d,p,o),d+=4}else i||(f="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!n&&i&&(f+="solid "+_.name+"\r\n"),!a&&_ instanceof x.Mesh&&_.bakeCurrentTransformIntoVertices();for(var T=h(_),v=_.getIndices()||[],y=0;y<v.length;y+=3){var b=u(v,T,y);n?(d=c(f,d,b.n,o),d=c(f,d,b.v[0],o),d=c(f,d,b.v[1],o),d=c(f,d,b.v[2],o),d+=2):(f+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",f+="\t\touter loop\r\n",f+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",f+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",f+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",f+="\t\tendloop\r\n",f+="\tendfacet\r\n")}!n&&i&&(f+="endsolid "+name+"\r\n")}if(n||i||(f+="endsolid stlmesh"),t){var M=document.createElement("a"),w=new Blob([f],{type:"application/octet-stream"});M.href=window.URL.createObjectURL(w),M.download=r+".stl",M.click()}return f},e}();function Mt(e,t,r,n){void 0===r&&(r=3),void 0===n&&(n=!1);for(var o=[],a=0;a<e.length/r;a++){var s=e[a*r]*(n?-1:1),i=e[a*r+1],u=e[a*r+2];o.push("(".concat(s.toPrecision(t.precision),", ").concat(i.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function wt(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 At(e,t,r,n){var o=function(e,t,r,n){var o=e.getVerticesData(x.VertexBuffer.PositionKind),a=e.getVerticesData(x.VertexBuffer.NormalKind);if(o&&a)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(r,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,r=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(r/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,r=e.getIndices(),n=null!==(t=null==r?void 0:r.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==r)for(var a=0;a<n;a++)o.push(r[a]);else for(a=0;a<n;a++)o.push(a);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(Mt(a,t,void 0,n),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(Mt(o,t,void 0,n),"]\n ").concat(function(e,t){for(var r="",n=0;n<4;n++){var o=n>0?n:"",a=e.getVerticesData(x.VertexBuffer.UVKind+(o?o+1:""));a&&(r+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(wt(a,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var s=e.getVerticesData(x.VertexBuffer.ColorKind);return s&&(r+="\n\tcolor3f[] primvars:displayColor = [".concat(Mt(s,t,s.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),r}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t,r,n);return'\n def "Geometry"\n {\n '.concat(o,"\n }\n ")}function Rt(e){var t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function Ct(e){var t=e.m;return"( ".concat(Et(t,0),", ").concat(Et(t,4),", ").concat(Et(t,8),", ").concat(Et(t,12)," )")}function Et(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function It(e,t){var r="Object_"+e.uniqueId,n=Ct(t);return'def Xform "'.concat(r,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(n,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function St(e){switch(e){case x.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case x.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case x.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function Vt(e){return"(".concat(e.x,", ").concat(e.y,")")}function Ft(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function Bt(e,t,r,n,o,a){var s=e.getInternalTexture().uniqueId+"_"+e.invertY;o[s]=e;var i=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new x.Vector2(e.uScale,e.vScale),c=new x.Vector2(e.uOffset,e.vOffset),l=e.wAng,h=Math.sin(l),f=Math.cos(l);return c.y=1-c.y-u.y,c.x+=h*u.x,c.y+=(1-f)*u.y,'\n def Shader "PrimvarReader_'.concat(r,'"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "').concat(i,'"\n float2 outputs:result\n }\n\n def Shader "Transform2d_').concat(r,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_').concat(t.uniqueId,"/PrimvarReader_").concat(r,".outputs:result>\n float inputs:rotation = ").concat((l*(180/Math.PI)).toFixed(a.precision),"\n float2 inputs:scale = ").concat(Vt(u),"\n float2 inputs:translation = ").concat(Vt(c),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(r,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(s,".png@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(t.uniqueId,"/Transform2d_").concat(r,".outputs:result>\n ").concat(n?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(n):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(St(e.wrapU),'"\n token inputs:wrapT = "').concat(St(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(t.needAlphaBlending()||t.needAlphaTesting()?"float outputs:a":"","\n }")}function Ot(e,t,r){var n="\t\t\t",o=[],a=[],s=function(e){var t,r,n={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof x.StandardMaterial?T(T({},n),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof x.PBRBaseMaterial?T(T({},n),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(t=e._roughness)&&void 0!==t?t:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(r=e._metallic)&&void 0!==r?r:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):n}(e),i=s.diffuseMap,u=s.diffuse,c=s.alphaCutOff,l=s.emissiveMap,h=s.emissive,f=s.normalMap,p=s.roughnessMap,d=s.roughnessChannel,g=s.roughness,m=s.metalnessMap,_=s.metalnessChannel,v=s.metalness,y=s.aoMap,b=s.aoMapChannel,M=s.aoMapIntensity,w=s.alphaMap,A=s.ior,R=s.clearCoatEnabled,C=s.clearCoat,E=s.clearCoatMap,I=s.clearCoatRoughness,S=s.clearCoatRoughnessMap;return null!==i?(o.push("".concat(n,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(i.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(n,"float inputs:opacityThreshold = ").concat(c))),a.push(Bt(i,e,"diffuse",u,t,r))):o.push("".concat(n,"color3f inputs:diffuseColor = ").concat(Ft(u||x.Color3.White()))),null!==l?(o.push("".concat(n,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),a.push(Bt(l,e,"emissive",h,t,r))):h&&h.toLuminance()>0&&o.push("".concat(n,"color3f inputs:emissiveColor = ").concat(Ft(h))),null!==f&&(o.push("".concat(n,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(f.uniqueId,"_normal.outputs:rgb>")),a.push(Bt(f,e,"normal",null,t,r))),null!==y&&(o.push("".concat(n,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(y.uniqueId,"_occlusion.outputs:").concat(b,">")),a.push(Bt(y,e,"occlusion",new x.Color3(M,M,M),t,r))),null!==p?(o.push("".concat(n,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_roughness.outputs:").concat(d,">")),a.push(Bt(p,e,"roughness",new x.Color3(g,g,g),t,r))):o.push("".concat(n,"float inputs:roughness = ").concat(g)),null!==m?(o.push("".concat(n,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(m.uniqueId,"_metallic.outputs:").concat(_,">")),a.push(Bt(m,e,"metallic",new x.Color3(v,v,v),t,r))):o.push("".concat(n,"float inputs:metallic = ").concat(v)),null!==w?(o.push("".concat(n,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(w.uniqueId,"_opacity.outputs:r>")),o.push("".concat(n,"float inputs:opacityThreshold = 0.0001")),a.push(Bt(w,e,"opacity",null,t,r))):o.push("".concat(n,"float inputs:opacity = ").concat(e.alpha)),R&&(null!==E?(o.push("".concat(n,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(E.uniqueId,"_clearcoat.outputs:r>")),a.push(Bt(E,e,"clearcoat",new x.Color3(C,C,C),t,r))):o.push("".concat(n,"float inputs:clearcoat = ").concat(C)),null!==S?(o.push("".concat(n,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(S.uniqueId,"_clearcoatRoughness.outputs:g>")),a.push(Bt(S,e,"clearcoatRoughness",new x.Color3(I,I,I),t,r))):o.push("".concat(n,"float inputs:clearcoatRoughness = ").concat(I))),o.push("".concat(n,"float inputs:ior = ").concat(A)),'\n\tdef Material "Material_'.concat(e.uniqueId,'"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n').concat(o.join("\n"),"\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(a.join("\n"),"\n\n\t}\n")}function Pt(e){var t,r;e.computeWorldMatrix(!0);for(var n=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,a=null!==(r=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==r?r:e.sideOrientation,s=!o,i=e.parent;i;){if(N(i,o)&&null===i.parent){o||(n.multiplyToRef(i.getWorldMatrix().invert(),n),a=a===x.Material.ClockWiseSideOrientation?x.Material.CounterClockWiseSideOrientation:x.Material.ClockWiseSideOrientation),s=!1;break}i=i.parent}return n.determinant()<0&&x.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:n,windingOrder:a===x.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:s}}function Ut(e,t,r){return v(this,void 0,void 0,(function(){var n,o,a,s,i,u,c,l,h,f,p,d,g,m,_,v,b,M,w,A,R,C,E,I,S,V,F,B,O,P,U,N;return y(this,(function(y){switch(y.label){case 0:return n=T({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},t),"undefined"!=typeof fflate?[3,2]:[4,x.Tools.LoadScriptAsync(n.fflateUrl)];case 1:y.sent(),y.label=2;case 2:for((o={})[n.modelFileName]=null,a='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',a+=function(e){var t=!0===e.includeAnchoringProperties?'\n\t\ttoken preliminary:anchoring:type = "'.concat(e.anchoringType,'"\n\t\ttoken preliminary:planeAnchoring:alignment = "').concat(e.planeAnchoringAlignment,'"'):"";return'def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {'.concat(t,"\n ")}(n),s={},i=0,u=e.meshes;i<u.length;i++)0!==(c=u[i]).getTotalVertices()&&(h=(l=c).geometry,(f=l.material)&&h&&(!r||r(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(f.getClassName())?(p="geometries/Geometry_"+h.uniqueId+".usda",d=Pt(l),g=d.matrix,m=d.windingOrder,_=d.convertToRightHanded,p in o||(v=At(h,n,m,_),o[p]=Rt(v)),f.uniqueId in s||(s[f.uniqueId]=f),a+=It(l,g)):x.Tools.Warn("USDZExportAsync does not support this material type: "+f.getClassName())));for(A in e.activeCamera&&n.exportCamera&&(a+=function(e,t){var r="Camera_"+e.uniqueId,n=Ct(x.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===x.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(n,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(t.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var o=e.getEngine().getAspectRatio(e),a=t.cameraSensorWidth||35;return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(n,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat focalLength = ").concat((a/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((a*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((a/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,n)),a+="\n }\n }",a+=function(e,t,r){var n=[];for(var o in e){var a=e[o];n.push(Ot(a,t,r))}return'\n def "Materials"\n{\n'.concat(n.join(""),"\n}\n\n")}(s,b={},n),a+="\n }",o[n.modelFileName]=fflate.strToU8(a),w=[],M=b)w.push(A);R=0,y.label=3;case 3:return R<w.length?(A=w[R])in M?(E=b[C=A],I=E.getSize(),[4,(0,x.GetTextureDataAsync)(E)]):[3,6]:[3,7];case 4:return S=y.sent(),[4,x.DumpTools.DumpDataAsync(I.width,I.height,S,"image/png",void 0,!1,!0)];case 5:V=y.sent(),o["textures/Texture_".concat(C,".png")]=new Uint8Array(V).slice(),y.label=6;case 6:return R++,[3,3];case 7:for(B in F=0,o)(O=o[B])&&(P=34+B.length,4!=(U=63&(F+=P))&&(N=new Uint8Array(64-U),o[B]=[O,{extra:{12345:N}}]),F=O.length);return[2,fflate.zipSync(o,{level:0})]}}))}))}var Nt=function(){function e(){}return e.Export=function(e,t,r){var n;if(void 0===t&&(t=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var o=t;t&&0!==t.length||(o=e.animations.map((function(e){return e.name})));for(var a=null,s=0,i=o;s<i.length;s++){var u=i[s],c=e.getAnimationRange(u);c&&(a=a?new x.AnimationRange("animation-range",Math.min(a.from,c.from),Math.max(a.to,c.to)):c)}if(!a&&(e.animations.length>0&&(a=e.getAnimationRange(e.animations[0].name)),!a))throw new Error("No animation range found in skeleton");for(var l=r||1/((null===(n=e.animations[0])||void 0===n?void 0:n.framePerSecond)||30),h=this._BuildBoneHierarchy(e,o),f=0,p=0,d=h;p<d.length;p++){var g=d[p];g.positionKeys.length>0&&(f=Math.max(f,g.positionKeys.length)),g.rotationKeys.length>0&&(f=Math.max(f,g.rotationKeys.length))}0===f&&(f=Math.floor((a.to-a.from)/l)+1);var m="";return m+="HIERARCHY\n",m+=this._ExportHierarchy(h,0),m+="MOTION\n",m+="Frames: ".concat(f,"\n"),(m+="Frame Time: ".concat(l.toFixed(6),"\n"))+this._ExportMotionData(h,f,0,o)},e._BuildBoneHierarchy=function(e,t){for(var r,n,o=new Map,a=[],s=0,i=e.bones;s<i.length;s++){var u={bone:h=i[s],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};o.set(h,u)}for(var c=0,l=e.bones;c<l.length;c++){var h=l[c];if(u=o.get(h),h.animations.length>0)for(var f=0,p=h.animations;f<p.length;f++){var d=p[f];t.includes(d.name)&&("position"===d.targetProperty?(u.hasPositionChannels=!0,(r=u.positionKeys).push.apply(r,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(n=u.rotationKeys).push.apply(n,d.getKeys())))}if(h.getParent()){var x=o.get(h.getParent());x&&x.children.push(u)}else a.push(u)}return a},e._ExportHierarchy=function(e,t){for(var r="",n=" ".repeat(t),o=0,a=e;o<a.length;o++){var s=a[o],i=s.bone;if(this._IsEndSite(s)){r+="".concat(n,"End Site\n"),r+="".concat(n,"{\n");var u=this._GetBoneOffset(i);r+="".concat(n," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),r+="".concat(n,"}\n")}else{r+="".concat(0===t?"ROOT":"".concat(n,"JOINT")," ").concat(i.name,"\n"),r+="".concat(n,"{\n"),u=this._GetBoneOffset(i),r+="".concat(n," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];s.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),s.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(r+="".concat(n," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),s.children.length>0&&(r+=this._ExportHierarchy(s.children,t+1)),r+="".concat(n,"}\n")}}return r},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return x.Vector3.Zero()}},e._ExportMotionData=function(e,t,r,n){for(var o="",a=0;a<t;a++){var s=[];this._CollectFrameValues(e,a+r,s,n),o+=s.map((function(e){return e.toFixed(6)})).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,r,n){for(var o=0,a=e;o<a.length;o++){var s=a[o];if(!this._IsEndSite(s)){if(s.hasPositionChannels){var i=this._GetPositionAtFrameIndex(s.positionKeys,t);r.push(i.x,i.y,i.z)}if(s.hasRotationChannels){var u=this._GetRotationAtFrameIndex(s.rotationKeys,t),c=this._QuaternionToEuler(u);r.push(c.z,c.x,c.y)}s.children.length>0&&this._CollectFrameValues(s.children,t,r,n)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?x.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?x.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new x.Matrix;e.toRotationMatrix(t);var r,n,o,a=t.m,s=Math.sqrt(a[0]*a[0]+a[1]*a[1]);return s>x.Epsilon?(r=Math.atan2(a[6],a[10]),n=Math.atan2(-a[2],s),o=Math.atan2(a[1],a[0])):(r=Math.atan2(-a[9],a[5]),n=Math.atan2(-a[2],s),o=0),new x.Vector3(x.Tools.ToDegrees(r),x.Tools.ToDegrees(n),x.Tools.ToDegrees(o))},e}(),Lt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Lt)for(var kt in p)Lt.BABYLON[kt]=p[kt];var Kt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Kt){Kt.BABYLON=Kt.BABYLON||{};var zt=Kt.BABYLON;zt.GLTF2=zt.GLTF2||{},zt.GLTF2.Exporter=zt.GLTF2.Exporter||{},zt.GLTF2.Exporter.Extensions=zt.GLTF2.Exporter.Extensions||{};var Wt=[];for(var Dt in s)zt[Dt]=s[Dt],Wt.push(Dt);for(var Dt in i)zt[Dt]=i[Dt],Wt.push(Dt);for(var Dt in u)zt[Dt]=u[Dt],Wt.push(Dt);for(var Dt in c)zt.GLTF2.Exporter.Extensions[Dt]=c[Dt],Wt.push(Dt);for(var Dt in l)Wt.indexOf(Dt)>-1||(zt.GLTF2.Exporter[Dt]=l[Dt])}var qt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==qt)for(var Gt in a)qt.BABYLON[Gt]=a[Gt];var Ht=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Ht)for(var jt in h)Ht.BABYLON[jt]=h[jt];var Qt=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Qt)for(var Xt in f)Qt.BABYLON[Xt]=f[Xt];const Yt=d;return o.default})()));
|
|
2
2
|
//# sourceMappingURL=babylonjs.serializers.min.js.map
|