babylonjs-serializers 9.5.0 → 9.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babylon.glTF2Serializer.min.js +1 -1
- package/babylon.glTF2Serializer.min.js.map +1 -1
- package/babylon.objSerializer.min.js +1 -1
- package/babylon.objSerializer.min.js.map +1 -1
- package/babylon.stlSerializer.min.js +1 -1
- package/babylon.stlSerializer.min.js.map +1 -1
- package/babylon.threemfSerializer.min.js +1 -1
- package/babylon.threemfSerializer.min.js.map +1 -1
- package/babylon.usdzSerializer.min.js +1 -1
- package/babylon.usdzSerializer.min.js.map +1 -1
- package/babylonjs.serializers.js +1 -1
- package/babylonjs.serializers.js.map +1 -1
- package/babylonjs.serializers.min.js +1 -1
- package/babylonjs.serializers.min.js.map +1 -1
- package/package.json +4 -3
- package/rollup.config.umd.mjs +2 -0
- package/src/3mf.ts +2 -3
- package/src/USDZ.ts +2 -3
- package/src/glTF2.ts +2 -3
- package/src/index.ts +2 -3
- package/src/obj.ts +2 -3
- package/src/stl.ts +2 -3
- package/webpack.config.js +0 -25
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";var n=function(){function e(){}return e.OBJ=function(e,n,r,o){var i=[],a=1,s=1;n&&(r||(r="mat"),i.push("mtllib "+r+".mtl"));for(var u=0;u<e.length;u++){var c=e[u],l=c.name||"mesh".concat(u,"}");i.push("o ".concat(l));var h=null;if(o){var f=c.computeWorldMatrix(!0);h=new t.Matrix,f.invertToRef(h),c.bakeTransformIntoVertices(f)}if(n){var p=c.material;p&&i.push("usemtl "+p.id)}var d=c.geometry;if(d){var m=d.getVerticesData("position"),g=d.getVerticesData("normal"),x=d.getVerticesData("uv"),_=d.getIndices(),v=0,T=0;if(m&&_){for(var y=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<m.length;b+=3)i.push("v "+m[b]*y+" "+m[b+1]+" "+m[b+2]),v++;if(null!=g)for(b=0;b<g.length;b+=3)i.push("vn "+g[b]*y+" "+g[b+1]+" "+g[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)i.push("vt "+x[b]+" "+x[b+1]),T++;var M=["","",""],w=(c.material||c.getScene().defaultMaterial)._getEffectiveOrientation(c)===t.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=w[0],C=w[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+a),String(_[b+A]+a),String(_[b+C]+a)],E=[String(_[b]+s),String(_[b+A]+s),String(_[b+C]+s)],I=R,S=null!=x?E:M,V=null!=g?R:M;i.push("f "+I[0]+"/"+S[0]+"/"+V[0]+" "+I[1]+"/"+S[1]+"/"+V[1]+" "+I[2]+"/"+S[2]+"/"+V[2])}o&&h&&c.bakeTransformIntoVertices(h),a+=v,s+=T}else t.Tools.Warn("There are no position vertices or indices on the mesh!")}else t.Tools.Warn("No geometry is present on the mesh")}return i.join("\n")},e.MTL=function(e){var t=[],n=e.material;return t.push("newmtl mat1"),t.push(" Ns "+n.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+n.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+n.ambientColor.r.toFixed(4)+" "+n.ambientColor.g.toFixed(4)+" "+n.ambientColor.b.toFixed(4)),t.push(" Kd "+n.diffuseColor.r.toFixed(4)+" "+n.diffuseColor.g.toFixed(4)+" "+n.diffuseColor.b.toFixed(4)),t.push(" Ks "+n.specularColor.r.toFixed(4)+" "+n.specularColor.g.toFixed(4)+" "+n.specularColor.b.toFixed(4)),t.push(" Ke "+n.emissiveColor.r.toFixed(4)+" "+n.emissiveColor.g.toFixed(4)+" "+n.emissiveColor.b.toFixed(4)),n.ambientTexture&&t.push(" map_Ka "+n.ambientTexture.name),n.diffuseTexture&&t.push(" map_Kd "+n.diffuseTexture.name),n.specularTexture&&t.push(" map_Ks "+n.specularTexture.name),n.bumpTexture&&t.push(" map_bump -imfchan z "+n.bumpTexture.name),n.opacityTexture&&t.push(" map_d "+n.opacityTexture.name),t.join("\n")},e}(),r={__proto__:null,OBJExport:n},o={__proto__:null,__IGLTFExporterExtension:0},i=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 n=this.files[e],r=new Blob([n],{type:t.GetMimeType(e)});t.Tools.Download(r,e)}},e}(),a={__proto__:null,GLTFData:i},s=function(e,t){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},s(e,t)};function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var c=function(){return c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};function l(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function h(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}u((r=r.apply(e,t||[])).next())})}function f(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function p(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var d=1e-6,m=new t.Color3(.04,.04,.04),g=t.Color3.White(),x=t.Color3.BlackReadOnly;function _(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function v(e){return h(this,void 0,void 0,function(){var n,r,o,i;return f(this,function(a){switch(a.label){case 0:if(!(n=e.getInternalTexture())||1!==n.source)return[2,null];if(n.invertY)return[2,null];r=n._buffer,i=e.mimeType,a.label=1;case 1:return a.trys.push([1,12,,13]),r?[3,3]:[4,t.Tools.LoadFileAsync(n.url)];case 2:return o=a.sent(),i=t.GetMimeType(n.url)||i,[3,11];case 3:return ArrayBuffer.isView(r)?(o=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,11]):[3,4];case 4:return r instanceof ArrayBuffer?(o=r,[3,11]):[3,5];case 5:return r instanceof Blob?[4,r.arrayBuffer()]:[3,7];case 6:return o=a.sent(),i=r.type||i,[3,11];case 7:return"string"!=typeof r?[3,9]:[4,t.Tools.LoadFileAsync(r)];case 8:return o=a.sent(),i=t.GetMimeType(r)||i,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,t.Tools.LoadFileAsync(r.src)]:[3,11];case 10:o=a.sent(),i=t.GetMimeType(r.src)||i,a.label=11;case 11:return[3,13];case 12:return a.sent(),[2,null];case 13:return o&&_(i)?[2,new Blob([o],{type:i})]:[2,null]}})})}function T(e,n,r){if(n<m.r)return 0;var o=m.r,i=e*r/(1-m.r)+n-2*m.r,a=i*i-4*o*(m.r-n);return t.Scalar.Clamp((-i+Math.sqrt(a))/(2*o),0,1)}function y(e){var n=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,o=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(o);return{baseColorFactor:[n.r,n.g,n.b,r],metallicFactor:0,roughnessFactor:i}}function b(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function M(e,n,r){for(var o=new Uint8Array(e*n*4),i=0;i<o.length;i+=4)o[i]=o[i+1]=o[i+2]=o[i+3]=255;return t.RawTexture.CreateRGBATexture(o,e,n,r)}function w(e){if(e instanceof Uint8Array){for(var t=e.length,n=new Float32Array(e.length),r=0;r<t;++r)n[r]=e[r]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var A=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,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l;return f(this,function(h){switch(h.label){case 0:return r=y(e),o={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||t.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),o.doubleSided=!0),n?(i=[],(a=e.diffuseTexture)&&i.push(this.exportTextureAsync(a).then(function(e){e&&(r.baseColorTexture=e)})),(s=e.bumpTexture)&&i.push(this.exportTextureAsync(s).then(function(e){e&&(o.normalTexture=e,1!==s.level&&(o.normalTexture.scale=s.level))})),(u=e.emissiveTexture)&&(o.emissiveFactor=[1,1,1],i.push(this.exportTextureAsync(u).then(function(e){e&&(o.emissiveTexture=e)}))),(c=e.ambientTexture)&&i.push(this.exportTextureAsync(c).then(function(e){if(e){var t={index:e.index};o.occlusionTexture=t}})),i.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(i)]):[3,2]):[3,2];case 1:h.sent(),h.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===t.Constants.ALPHA_COMBINE?o.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(x,d)&&(o.emissiveFactor=e.emissiveColor.asArray()),o.pbrMetallicRoughness=r,b(o,e),[4,this._finishMaterialAsync(o,e)];case 3:return h.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}})})},e.prototype._finishMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a;return f(this,function(s){switch(s.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(n=s.sent(),r=[],o=0,i=n;o<i.length;o++)a=i[o],r.push(this.exportTextureAsync(a));return[4,Promise.all(r)];case 2:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return s.sent(),[2]}})})},e.prototype._resizeTexturesToSameDimensions=function(e,n,r){var o,i,a=e?e.getSize():{width:0,height:0},s=n?n.getSize():{width:0,height:0};return a.width<s.width?(o=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):M(s.width,s.height,r),i=n):a.width>s.width?(i=n&&n instanceof t.Texture?t.TextureTools.CreateResizedCopy(n,a.width,a.height,!0):M(a.width,a.height,r),o=e):(o=e,i=n),{texture1:o,texture2:i}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,c,l,h,p,m,x,_,v,T,y,b,M,A,C,R,E,I,S,V,F,B,O,N,P,U,k;return f(this,function(f){switch(f.label){case 0:return o=new Array,e||n?[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,f.sent()];case 2:return(i=e?e.getScene():n?n.getScene():null)?(a=this._resizeTexturesToSameDimensions(e,n,i),s=null===(k=a.texture1)||void 0===k?void 0:k.getSize(),u=void 0,c=void 0,l=s.width,h=s.height,[4,a.texture1.readPixels()]):[3,12];case 3:return p=f.sent(),[4,a.texture2.readPixels()];case 4:return m=f.sent(),p?(u=w(p),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return m?(c=w(m),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(x=c.byteLength,_=new Uint8Array(x),v=new Uint8Array(x),T=new t.Color3(0,0,0),y=0,b=0,B=0;B<h;++B)for(O=0;O<l;++O)M=4*(l*B+O),A=new t.Color3(u[M],u[M+1],u[M+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),C=new t.Color3(c[M],c[M+1],c[M+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.specularColor),R=c[M+3]*r.glossiness,E={diffuseColor:A,specularColor:C,glossiness:R},I=this._convertSpecularGlossinessToMetallicRoughness(E),T.r=Math.max(T.r,I.baseColor.r),T.g=Math.max(T.g,I.baseColor.g),T.b=Math.max(T.b,I.baseColor.b),y=Math.max(y,I.metallic),b=Math.max(b,I.roughness),v[M]=255*I.baseColor.r,v[M+1]=255*I.baseColor.g,v[M+2]=255*I.baseColor.b,v[M+3]=a.texture1.hasAlpha?255*u[M+3]:255,_[M]=0,_[M+1]=255*I.roughness,_[M+2]=255*I.metallic,_[M+3]=255;for(S={baseColor:T,metallic:y,roughness:b},V=!1,F=!1,B=0;B<h;++B)for(O=0;O<l;++O)v[N=4*(l*B+O)]/=S.baseColor.r>d?S.baseColor.r:1,v[N+1]/=S.baseColor.g>d?S.baseColor.g:1,v[N+2]/=S.baseColor.b>d?S.baseColor.b:1,P=t.Color3.FromInts(v[N],v[N+1],v[N+2]),U=P.toGammaSpace(i.getEngine().useExactSrgbConversions),v[N]=255*U.r,v[N+1]=255*U.g,v[N+2]=255*U.b,U.equalsWithEpsilon(g,d)||(F=!0),_[N+1]/=S.roughness>d?S.roughness:1,_[N+2]/=S.metallic>d?S.metallic:1,t.Color3.FromInts(255,_[N+1],_[N+2]).equalsWithEpsilon(g,d)||(V=!0);return V&&o.push(t.EncodeImageAsync(_,l,h).then(function(e){S.metallicRoughnessTextureData=e})),F&&o.push(t.EncodeImageAsync(v,l,h).then(function(e){S.baseColorTextureData=e})),[4,Promise.all(o).then(function(){return S})];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}})})},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var n=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),o=1-this._getMaxComponent(e.specularColor),i=T(n,r,o),a=e.diffuseColor.scale(o/(1-m.r)/Math.max(1-i,d)),s=e.specularColor.subtract(m.scale(1-i)).scale(1/Math.max(i,d)),u=t.Color3.Lerp(a,s,i*i);return{baseColor:u=u.clampToRef(0,1,u),metallic:i,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,n,r,o,i,a,s,u,c){return h(this,void 0,void 0,function(){var l,p,d,m,g,x,_,v,T,y=this;return f(this,function(b){switch(b.label){case 0:return l=[],p={baseColor:e,metallic:n,roughness:r},c&&(s instanceof t.OpenPBRMaterial?(s.geometryOpacityTexture?(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,m=s.geometryOpacityTexture&&s.geometryOpacityTexture.getInternalTexture()?s.geometryOpacityTexture.getInternalTexture().uniqueId:0,g=Number("".concat(d).concat(m)),(T=this._textureMap.get(g))?u.baseColorTexture=T:l.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(1),o?t.CreateTextureInput(o,2):t.CreateConstantInput(1),t.CreateTextureInput(s.geometryOpacityTexture,0)),s.getScene()).then(function(e){return h(y,void 0,void 0,function(){var t;return f(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,g)];case 1:return(t=n.sent())&&(u.baseColorTexture=t),[2]}})})}))):o&&l.push(this.exportTextureAsync(o).then(function(e){e&&(u.baseColorTexture=e)})),s._useMetallicFromMetallicTextureBlue&&i?l.push(this.exportTextureAsync(i).then(function(e){e&&(u.metallicRoughnessTexture=e)})):(a||i)&&(x=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,_=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,v=Number("".concat(x).concat(_)),(T=this._textureMap.get(v))?u.metallicRoughnessTexture=T:l.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(s.ambientOcclusionTexture?t.CreateTextureInput(s.ambientOcclusionTexture,0):t.CreateConstantInput(1),a?t.CreateTextureInput(a,0):t.CreateConstantInput(1),i?t.CreateTextureInput(i,0):t.CreateConstantInput(1)),s.getScene()).then(function(e){return h(y,void 0,void 0,function(){var t;return f(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,v)];case 1:return(t=n.sent())&&(u.metallicRoughnessTexture=t),[2]}})})})))):(o&&l.push(this.exportTextureAsync(o).then(function(e){e&&(u.baseColorTexture=e)})),i&&l.push(this.exportTextureAsync(i).then(function(e){e&&(u.metallicRoughnessTexture=e)})))),l.length>0?(this._exporter._materialNeedsUVsSet.add(s),[4,Promise.all(l)]):[3,2];case 1:b.sent(),b.label=2;case 2:return[2,p]}})})},e.prototype._getTextureSampler=function(e){var n={};if(!(e&&e instanceof t.Texture))return n;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(n.wrapS=r);var o=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==o&&(n.wrapT=o),e.samplingMode){case t.Texture.LINEAR_LINEAR:n.magFilter=9729,n.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:n.magFilter=9729,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:n.magFilter=9728,n.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:n.magFilter=9728,n.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:n.magFilter=9728,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:n.magFilter=9728,n.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:n.magFilter=9729,n.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:n.magFilter=9729,n.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:n.magFilter=9728,n.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:n.magFilter=9729,n.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:n.magFilter=9729,n.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:n.magFilter=9728,n.minFilter=9984}return n},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case t.Texture.WRAP_ADDRESSMODE:return 10497;case t.Texture.CLAMP_ADDRESSMODE:return 33071;case t.Texture.MIRROR_ADDRESSMODE:return 33648;default:return t.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l;return f(this,function(h){switch(h.label){case 0:return r={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,i=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!i||a?[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||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),s=this._exportTextureSampler(o||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,i,r)]):[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,s,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,s,null==i?void 0:i.coordinatesIndex),h.label=7;case 7:return[2,u];case 8:return[2,this._convertSpecularGlossinessToMetallicRoughness(r)]}})})},e.prototype.exportPBRMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return f(this,function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(i=e._albedoColor,a=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,a])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,n,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t)];case 3:u=l.sent(),l.label=4;case 4:return s=u,[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,r,n,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(r,e)];case 6:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}})})},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a,s,u,c,l,p=this;return f(this,function(m){switch(m.label){case 0:return b(r,n),e.baseColor.equalsWithEpsilon(g,d)&&t.Scalar.WithinEpsilon(n.alpha,1,d)||(o.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,n.alpha]),null!=e.metallic&&1!==e.metallic&&(o.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(o.roughnessFactor=e.roughness),null==n.backFaceCulling||n.backFaceCulling||(n._twoSidedLighting||t.Tools.Warn(n.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),i?(a=[],(s=n instanceof t.PBRBaseMaterial?n._bumpTexture:n.geometryNormalTexture)&&a.push(this.exportTextureAsync(s).then(function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))})),(u=n instanceof t.PBRBaseMaterial?n._ambientTexture:n.ambientOcclusionTexture)&&a.push(new Promise(function(e){return h(p,void 0,void 0,function(){var r,i,a,s;return f(this,function(c){switch(c.label){case 0:return n instanceof t.OpenPBRMaterial&&o.metallicRoughnessTexture?(r=this._exportTextureSampler(u),i=this._exporter._textures[o.metallicRoughnessTexture.index].source,a=this._exportTextureInfo(i,r,u.coordinatesIndex),this._textureMap.set(u.uniqueId,a),this._exporter._extensionsPostExportTextures("exporter",a,u),[2,e(a)]):[3,1];case 1:return s=e,[4,this.exportTextureAsync(u)];case 2:return[2,s.apply(void 0,[c.sent()])]}})})}).then(function(e){return h(p,void 0,void 0,function(){var o;return f(this,function(i){return e&&(o={index:e.index,texCoord:e.texCoord,extensions:e.extensions},r.occlusionTexture=o,n instanceof t.PBRBaseMaterial?o.strength=n._ambientTextureStrength:o.strength=n.ambientOcclusionTexture.level),[2]})})})),(c=n instanceof t.PBRBaseMaterial?n._emissiveTexture:n.emissionColorTexture)&&a.push(this.exportTextureAsync(c).then(function(e){e&&(r.emissiveTexture=e)})),a.length>0?(this._exporter._materialNeedsUVsSet.add(n),[4,Promise.all(a)]):[3,2]):[3,2];case 1:m.sent(),m.label=2;case 2:return(l=n instanceof t.PBRBaseMaterial?n._emissiveColor:n.emissionColor).equalsWithEpsilon(x,d)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=o,[2]}})})},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a,s;return f(this,function(u){switch(u.label){case 0:return n={},r={name:e.name},o=e.baseColor,i=e.geometryOpacity,o&&(n.baseColorFactor=[o.r,o.g,o.b,i]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t)];case 1:return a=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(a,e,r,n,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(r,e)];case 3:return u.sent(),(s=this._exporter._materials).push(r),[2,s.length-1]}})})},e.prototype.exportTextureAsync=function(e){return h(this,arguments,void 0,function(e,t){var n,r,o;return void 0===t&&(t=null),f(this,function(i){switch(i.label){case 0:return(n=this._textureMap.get(null!=t?t:e.uniqueId))?[2,n]:(r=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=i.sent(),n=this._exportTextureInfo(o,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,n),this._exporter._extensionsPostExportTextures("exporter",n,e),[2,n]}})})},e.prototype._exportTextureImageAsync=function(e){return h(this,void 0,void 0,function(){var n,r,o,i,a,s=this;return f(this,function(u){switch(u.label){case 0:return n=null!==(a=e.mimeType)&&void 0!==a?a:"none",r=this._internalTextureToImage,o=e.getInternalTexture().uniqueId,r[o]=r[o]||{},void 0===(i=r[o][n])&&(i=h(s,void 0,void 0,function(){var r,o,i,a,s;return f(this,function(u){switch(u.label){case 0:return[4,v(e)];case 1:return!(r=u.sent())||"none"!==n&&r.type!==n?[3,3]:[4,this._exportImageAsync(e.name,r)];case 2:case 6:return[2,u.sent()];case 3:return o="image/png","none"!==n&&(_(n)?o=n:(o="image/png",t.Tools.Warn("Unsupported media type: ".concat(n,". Exporting texture as PNG.")))),i=e.getSize(),[4,t.GetTextureDataAsync(e)];case 4:return a=u.sent(),[4,t.EncodeImageAsync(a,i.width,i.height,o)];case 5:return s=u.sent(),[4,this._exportImageAsync(e.name,s)]}})}),r[o][n]=i),[4,i];case 1:return[2,u.sent()]}})})},e.prototype._exportImageAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c;return f(this,function(l){switch(l.label){case 0:return r=this._exporter._images,this._exporter._shouldUseGlb?(o={name:e,mimeType:n.type,bufferView:void 0},[4,n.arrayBuffer()]):[3,2];case 1:return i=l.sent(),a=this._exporter._bufferManager.createBufferView(new Uint8Array(i)),this._exporter._bufferManager.setBufferView(o,a),[3,3];case 2:s=e.replace(/\.\/|\/|\.\\|\\/g,"_"),u=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"}}(n.type),c=s+u,r.some(function(e){return e.uri===c})&&(c="".concat(s,"_").concat(t.Tools.RandomId()).concat(u)),o={name:e,uri:c},this._exporter._imageData[c]=n,l.label=3;case 3:return r.push(o),[2,r.length-1]}})})},e.prototype._exportTextureInfo=function(e,t,n){var r=this._exporter._textures,o=r.findIndex(function(n){return n.sampler==t&&n.source===e});-1===o&&(o=r.length,r.push({source:e,sampler:t}));var i={index:o};return n&&(i.texCoord=n),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),n=this._exporter._samplers,r=n.findIndex(function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT});return-1!==r?r:(n.push(t),n.length-1)},e}(),C=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function R(e,n){if(!(e instanceof t.TransformNode))return!1;if(n){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(C,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}var E=t.Vector3.ZeroReadOnly,I=t.Quaternion.Identity(),S=t.Vector3.OneReadOnly,V=new t.Vector3(-1,1,1);function F(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,i=e.normalized,a=e.getSize(),s=t.reduce(function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e},-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:a,type:o,count:s*a,normalized:i,totalVertices:s,kind:e.getKind()}}function B(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 O(e){return e.some(function(e){return e>=256})}function N(e){switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:case t.VertexBuffer.ColorKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return!0}return!1}function P(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 U(e){return e.x*=-1,e}function k(e){return C.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(C,e),e}function L(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){var r=Math.sign(e.x);e.x=t,e.y*=-r,e.z*=-r,e.w*=r}else r=Math.sign(e.y),e.x*=-r,e.y=n,e.z*=r,e.w*=-r}else{var o=Math.abs(e.z),i=Math.abs(e.w);o>i?(r=Math.sign(e.z),e.x*=-r,e.y*=r,e.z=o,e.w*=-r):(r=Math.sign(e.w),e.x*=r,e.y*=-r,e.z*=-r,e.w=i)}return e}function W(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function D(e,n){var r=t.Vector3.FromArrayToRef(n.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),o=t.Quaternion.FromArrayToRef(n.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(S,o,r,t.TmpVectors.Matrix[0]),a=t.Vector3.FromArrayToRef(e.translation||[0,0,0],0,t.TmpVectors.Vector3[2]),s=t.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[1]),u=t.Matrix.ComposeToRef(S,s,a,t.TmpVectors.Matrix[1]);i.multiplyToRef(u,u),u.decompose(void 0,o,r),r.equalsWithEpsilon(E,t.Epsilon)?delete n.translation:n.translation=r.asArray(),o.equalsWithEpsilon(I,t.Epsilon)?delete n.rotation:n.rotation=o.asArray(),n.scale&&delete n.scale}function z(e,n){if(!(n instanceof t.TransformNode))return!1;if(1!==n.getChildren().length||0!==e.getChildren().length||e.parent!==n)return!1;var r=e.getScene(),o=e instanceof t.TargetCamera&&!r.useRightHandedSystem?V:S;return!!n.scaling.equalsWithEpsilon(o,t.Epsilon)||(t.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(n.name," with modified scaling.")),!1)}function K(e,t){for(var n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],a=o[1],s=t[i];(Array.isArray(a)&&Array.isArray(s)&&G(a,s)||a===s)&&delete e[i]}return e}function G(e,t){return e.length===t.length&&e.every(function(e,n){return e===t[n]})}var q=new Map([[Int8Array,function(e,t,n){return e.setInt8(t,n)}],[Uint8Array,function(e,t,n){return e.setUint8(t,n)}],[Uint8ClampedArray,function(e,t,n){return e.setUint8(t,n)}],[Int16Array,function(e,t,n){return e.setInt16(t,n,!0)}],[Uint16Array,function(e,t,n){return e.setUint16(t,n,!0)}],[Int32Array,function(e,t,n){return e.setInt32(t,n,!0)}],[Uint32Array,function(e,t,n){return e.setUint32(t,n,!0)}],[Float32Array,function(e,t,n){return e.setFloat32(t,n,!0)}],[Float64Array,function(e,t,n){return e.setFloat64(t,n,!0)}]]),H=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=q.get(e.constructor),n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var n=new Uint8Array(2*t);n.set(this._data),this._data=n,this._dataView=new DataView(this._data.buffer)}},e}();function j(e){return e%4==0?4:e%2==0?2:1}var X,Q=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach(function(e){t+=e.byteLength});for(var n=new H(t),r=0,o=Array.from(this._bufferViewToData.keys()).sort(function(e,t){return j(t.byteLength)-j(e.byteLength)});r<o.length;r++){var i=o[r];i.byteOffset=n.byteOffset,e.push(i);for(var a=e.length-1,s=0,u=this.getPropertiesWithBufferView(i);s<u.length;s++)u[s].bufferView=a;n.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return n.getOutputData()},e.prototype.createBufferView=function(e,t){var n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n},e.prototype.createAccessor=function(e,t,n,r,o,i,a){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:a,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,n=0,r=this.getPropertiesWithBufferView(e);n<r.length;n++){var o=r[n];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach(function(n,r){n===e&&(void 0!==r.byteOffset&&delete r.byteOffset,t._accessorToBufferView.delete(r))})},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(X||(X={}));var Z=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof t.TransformNode||e instanceof t.Camera||e instanceof t.Light)},e._CreateNodeAnimation=function(n,r,o,i,a){if(this._IsTransformable(n)){var s=[],u=[],c=r.getKeys(),l=e._CalculateMinMaxKeyFrames(c),h=e._DeduceInterpolation(c,o,i),f=h.interpolationType,p=h.shouldBakeAnimation;if(p?e._CreateBakedAnimation(n,r,o,l.min,l.max,r.framePerSecond,a,s,u,l,i):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(n,r,o,s,u,i):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(n,r,o,s,u,i):e._CreateBakedAnimation(n,r,o,l.min,l.max,r.framePerSecond,a,s,u,l,i),s.length&&u.length)return{inputs:s,outputs:u,samplerInterpolation:f,inputsMin:p?l.min:t.Tools.FloatRound(l.min/r.framePerSecond),inputsMax:p?l.max:t.Tools.FloatRound(l.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var n=null,r="VEC3",o=!1,i=e.targetProperty.split(".");switch(i[0]){case"scaling":n="scale";break;case"position":n="translation";break;case"rotation":r="VEC4",n="rotation";break;case"rotationQuaternion":r="VEC4",o=!0,n="rotation";break;case"influence":r="SCALAR",n="weights";break;default:t.Tools.Error("Unsupported animatable property ".concat(i[0]))}return n?{animationChannelTargetPath:n,dataAccessorType:r,useQuaternion:o}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,i,a,s,u,c,l,h){var f;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!h||h(m)){var g=e._DeduceAnimationInfo(m);g&&(f={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?n:f,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,g.useQuaternion,c,l),f.samplers.length&&f.channels.length&&r.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(n,r,o,i,a,s,u,c,l,h,f){var p;if(n instanceof t.Mesh){var d=n.morphTargetManager;if(d)for(var m=0;m<d.numTargets;++m)for(var g=0,x=d.getTarget(m).animations;g<x.length;g++){var _=x[g];if(!f||f(_)){for(var v=new t.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),T=[],y=_.getKeys(),b=0;b<y.length;++b)for(var M=y[b],w=0;w<d.numTargets;++w)w==m?T.push(M):T.push({frame:M.frame,value:0});v.setKeys(T,!0);var A=e._DeduceAnimationInfo(v);A&&(p={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:p,n,v,A.dataAccessorType,A.animationChannelTargetPath,i,s,u,c,A.useQuaternion,l,h,d.numTargets),p.samplers.length&&p.channels.length&&o.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(n,r,o,i,a,s,u,c,l){var h,f;if(n.animationGroups)for(var p=n.animationGroups,d=function(p){var d=new Map,g=new Map,x=new Set,_=p.to-p.from;f={name:p.name,channels:[],samplers:[]};for(var v=function(r){var _=p.targetedAnimations[r],v=_.target,T=_.animation;if(l&&!l(T))return"continue";var y=c.has(v);if(m._IsTransformable(v)||1===v.length&&m._IsTransformable(v[0])){if(M=e._DeduceAnimationInfo(_.animation)){var b=m._IsTransformable(v)?v:m._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(T.name),f,b,T,M.dataAccessorType,M.animationChannelTargetPath,o,i,a,s,M.useQuaternion,u,y)}}else if(v instanceof t.MorphTarget||1===v.length&&v[0]instanceof t.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var w=v instanceof t.MorphTarget?v:v[0];if(w){var A=n.morphTargetManagers.find(function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1});if(A){var C=n.meshes.find(function(e){return e.morphTargetManager===A});C&&(d.has(C)||d.set(C,new Map),null===(h=d.get(C))||void 0===h||h.set(w,T),x.add(C),g.set(C,T))}}}}},T=0;T<p.targetedAnimations.length;++T)v(T);x.forEach(function(n){for(var r=n.morphTargetManager,c=null,l=[],h=g.get(n).getKeys(),m=h.length,x=0;x<m;++x)for(var v=0;v<r.numTargets;++v){var T=r.getTarget(v),y=d.get(n);if(y){var b=y.get(T);b?(c||(c=new t.Animation("".concat(p.name,"_").concat(n.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[x])):l.push({frame:p.from+_/m*x,value:T.influence,inTangent:h[0].inTangent?0:void 0,outTangent:h[0].outTangent?0:void 0})}}c.setKeys(l,!0);var M=e._DeduceAnimationInfo(c);M&&e._AddAnimation("".concat(p.name,"_").concat(n.name,"_MorphWeightAnimation"),f,n,c,M.dataAccessorType,M.animationChannelTargetPath,o,i,a,s,M.useQuaternion,u,!1,null==r?void 0:r.numTargets)}),f.channels.length&&f.samplers.length&&r.push(f)},m=this,g=0,x=p;g<x.length;g++)d(x[g])},e._AddAnimation=function(n,r,o,i,a,s,u,c,l,h,f,p,d,m){var g,x,_,v,T,y,b=e._CreateNodeAnimation(o,i,s,f,p);if(b){if(m){for(var M=0,w=void 0,A=[];b.inputs.length>0;)w=b.inputs.shift(),M%m==0&&A.push(w),M++;b.inputs=A}var C=u.get(o),R=new Float32Array(b.inputs);g=c.createBufferView(R),x=c.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),h.push(x),_=h.length-1;var E=new t.Quaternion,I=new t.Vector3,S=new t.Vector3,V=o instanceof t.Camera,F=B(a),O=new Float32Array(b.outputs.length*F);b.outputs.forEach(function(e,n){var r=e;switch(s){case"translation":d&&(t.Vector3.FromArrayToRef(e,0,S),U(S),S.toArray(r));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,E):(r=new Array(4),t.Vector3.FromArrayToRef(e,0,I),t.Quaternion.FromEulerVectorToRef(I,E)),d&&(L(E),V&&W(E)),E.toArray(r)}O.set(r,n*F)}),g=c.createBufferView(O),x=c.createAccessor(g,a,5126,b.outputs.length),h.push(x),v=h.length-1,T={interpolation:b.samplerInterpolation,input:_,output:v},r.samplers.push(T),y={sampler:r.samplers.length-1,target:{node:C,path:s}},r.channels.push(y)}},e._CreateBakedAnimation=function(n,r,o,i,a,s,u,c,l,h,f){var p,d,m,g,x,_,v=t.Quaternion.Identity(),T=null,y=null;h.min=t.Tools.FloatRound(i/s);for(var b=r.getKeys(),M=0,w=b.length;M<w;++M){if(m=b[M],M+1<w)if(g=b[M+1],m.value.equals&&m.value.equals(g.value)||m.value===g.value){if(0!==M)continue;_=m.frame}else _=g.frame;else{if(x=b[M-1],m.value.equals&&m.value.equals(x.value)||m.value===x.value)continue;_=a}if(_)for(var A=m.frame;A<=_;A+=u)if((d=t.Tools.FloatRound(A/s))!==T){T=d,y=d;var C={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(A,C),e._SetInterpolatedValue(n,p,d,r,o,v,c,l,f)}}y&&(h.max=y)},e._ConvertFactorToVector3OrQuaternion=function(n,r,o,i,a){var s=e._GetBasePositionRotationOrScale(r,i,a),u=o.targetProperty.split("."),c=u?u[1]:"",l=a?t.Quaternion.FromArray(s).normalize():t.Vector3.FromArray(s);switch(c){case"x":case"y":case"z":l[c]=n;break;case"w":l.w=n;break;default:t.Tools.Error('glTFAnimation: Unsupported component name "'.concat(c,'"!'))}return l},e._SetInterpolatedValue=function(e,n,r,o,i,a,s,u,c){var l;s.push(r),"weights"!==i?(o.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(n=this._ConvertFactorToVector3OrQuaternion(n,e,o,i,c)),"rotation"===i?(c?a=n:(l=n,t.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,a)),u.push(a.asArray())):(l=n,u.push(l.asArray()))):u.push([n])},e._CreateLinearOrStepAnimation=function(t,n,r,o,i,a){for(var s=0,u=n.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/n.framePerSecond),e._AddKeyframeValue(c,n,i,r,t,a)}},e._CreateCubicSplineAnimation=function(t,n,r,o,i,a){n.getKeys().forEach(function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(X.INTANGENT,i,r,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,n,i,r,t,a),e._AddSplineTangent(X.OUTTANGENT,i,r,"CUBICSPLINE",s,a)})},e._GetBasePositionRotationOrScale=function(e,n,r){var o;if("rotation"===n)if(r){var i=e.rotationQuaternion;o=(null!=i?i:t.Quaternion.Identity()).asArray()}else{var a=e.rotation;o=(null!=a?a:t.Vector3.Zero()).asArray()}else if("translation"===n){var s=e.position;o=(null!=s?s:t.Vector3.Zero()).asArray()}else{var u=e.scaling;o=(null!=u?u:t.Vector3.One()).asArray()}return o},e._AddKeyframeValue=function(e,n,r,o,i,a){var s,u=n.dataType;if(u===t.Animation.ANIMATIONTYPE_VECTOR3){var c=e.value.asArray();if("rotation"===o){var l=t.Vector3.FromArray(c);c=t.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}r.push(c)}else if(u===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===o)r.push([e.value]);else if(s=this._ConvertFactorToVector3OrQuaternion(e.value,i,n,o,a)){if("rotation"===o){var h=a?s:t.Quaternion.RotationYawPitchRoll(s.y,s.x,s.z).normalize();r.push(h.asArray())}r.push(s.asArray())}}else u===t.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,n,r,o,i,a){var s,u=e===X.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===o){if("rotation"===r)if(u)if(a)s=u.asArray();else{var c=u;s=t.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}else s=[0,0,0,0];else s="weights"===r?u?[u]:[0]:u?u.asArray():[0,0,0];n.push(s)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,n=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)}),{min:t,max:n}},e}();function Y(e,n,r,o,i,a){var s={attributes:{},influence:e.influence,name:e.name},u=n.geometry;if(!u)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),s;var c,l=a?-1:1,h=t.Vector3.Zero();if(e.hasPositions){var f=e.getPositions(),p=u.getVerticesData(t.VertexBuffer.PositionKind);if(p){var d=new Float32Array(p.length),m=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];c=p.length/3;for(var x=0;x<c;++x){var _=t.Vector3.FromArray(p,3*x);t.Vector3.FromArray(f,3*x).subtractToRef(_,h),h.x*=l,m[0]=Math.min(m[0],h.x),g[0]=Math.max(g[0],h.x),m[1]=Math.min(m[1],h.y),g[1]=Math.max(g[1],h.y),m[2]=Math.min(m[2],h.z),g[2]=Math.max(g[2],h.z),d[3*x]=h.x,d[3*x+1]=h.y,d[3*x+2]=h.z}var v=r.createBufferView(d,12),T=r.createAccessor(v,"VEC3",5126,f.length/3,0,{min:m,max:g});i.push(T),s.attributes.POSITION=i.length-1}else t.Tools.Warn("Morph target positions for mesh ".concat(n.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),b=u.getVerticesData(t.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(c=b.length/3,x=0;x<c;++x){var w=t.Vector3.FromArray(b,3*x).normalize();t.Vector3.FromArray(y,3*x).normalize().subtractToRef(w,h),M[3*x]=h.x*l,M[3*x+1]=h.y,M[3*x+2]=h.z}v=r.createBufferView(M,12),T=r.createAccessor(v,"VEC3",5126,y.length/3,0),i.push(T),s.attributes.NORMAL=i.length-1}else t.Tools.Warn("Morph target normals for mesh ".concat(n.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),C=u.getVerticesData(t.VertexBuffer.TangentKind);if(C){c=C.length/4;var R=new Float32Array(3*c);for(x=0;x<c;++x){var E=t.Vector3.FromArray(C,4*x);P(E);var I=t.Vector3.FromArray(A,3*x);P(I),I.subtractToRef(E,h),R[3*x]=h.x*l,R[3*x+1]=h.y,R[3*x+2]=h.z}v=r.createBufferView(R,12),T=r.createAccessor(v,"VEC3",5126,c,0),i.push(T),s.attributes.TANGENT=i.length-1}else t.Tools.Warn("Morph target tangents for mesh ".concat(n.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),V=u.getVerticesData(t.VertexBuffer.ColorKind),F=u.getVertexBuffer(t.VertexBuffer.ColorKind);if(V&&F){var B=F.getSize();c=V.length/B;var O=new Float32Array(c*B);for(x=0;x<c;++x)if(3===B){var N=t.Vector3.FromArray(V,x*B);t.Vector3.FromArray(S,x*B).subtractToRef(N,h),O[3*x]=h.x,O[3*x+1]=h.y,O[3*x+2]=h.z}else if(4===B){var U=new t.Vector4;N=t.Vector4.FromArray(V,x*B),t.Vector4.FromArray(S,x*B).subtractToRef(N,U),O[4*x]=U.x,O[4*x+1]=U.y,O[4*x+2]=U.z,O[4*x+3]=U.w}else t.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));v=r.createBufferView(O,4*B),T=r.createAccessor(v,3===B?"VEC3":"VEC4",5126,c,0),i.push(T),s.attributes.COLOR_0=i.length-1}else t.Tools.Warn("Morph target colors for mesh ".concat(n.name," were not exported. Mesh does not have colors vertex data"))}return s}var J=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,n,r,o){var i,a,s,u;return null===(u=null===(s=null===(a=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===a?void 0:a.get(n))||void 0===s?void 0:s.get(r))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,n,r,o,i){var a=this._indicesAccessorMap.get(e);a||(a=new Map,this._indicesAccessorMap.set(e,a));var s=a.get(t);s||(s=new Map,a.set(t,s));var u=s.get(n);u||(u=new Map,s.set(n,u));var c=u.get(r);c||(c=new Map,u.set(r,c)),c.set(o,i)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)},e.prototype.getRemappedBufferView=function(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)},e.prototype.getVertexAccessor=function(e,t,n){var r,o;return null===(o=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.get(n)},e.prototype.setVertexAccessor=function(e,t,n,r){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.set(t,i)),i.set(n,r)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),$=function(){function e(e,n){if(void 0===e&&(e=t.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(t.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 A(this),this._extensions={},this._bufferManager=new Q,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=c({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"},n),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,n,r){var o=this;if(n>=t.length)return Promise.resolve(e);var i=r(t[n],e);return i?i.then(function(e){return h(o,void 0,void 0,function(){var o;return f(this,function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=i.sent(),[3,3];case 2:o=null,i.label=3;case 3:return[2,o]}})})}):this._ApplyExtension(e,t,n+1,r)},e.prototype._ApplyExtensions=function(t,n){for(var r=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];r.push(this._extensions[a])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var i=this;return this._ApplyExtensions(t,function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,n,r,o,i._bufferManager)})},e.prototype._extensionsPostExportMaterialAsync=function(e,t,n){return this._ApplyExtensions(t,function(t,r){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,n)})},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,n,r){return h(this,void 0,void 0,function(){var o,i=this;return f(this,function(a){switch(a.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map(function(e){return h(i,void 0,void 0,function(){var i,a;return f(this,function(s){switch(s.label){case 0:return(i=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,i.postExportMaterialAdditionalTexturesAsync(t,n,r)]:[3,2];case 1:a=s.sent(),o.push.apply(o,a),s.label=2;case 2:return[2]}})})}))];case 1:return a.sent(),[2,o]}})})},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,n,r)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return h(this,void 0,void 0,function(){var t,n,r,o;return f(this,function(i){switch(i.label){case 0:t=0,n=e._ExtensionNames,i.label=1;case 1:return t<n.length?(r=n[t],(o=this._extensions[r]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}})})},e.prototype._forEachExtensions=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions(function(t){var n,r,o;t.wasUsed&&((n=e._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((r=e._glTF).extensionsRequired||(r.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())})},e.prototype._loadExtensions=function(){for(var t=0,n=e._ExtensionNames;t<n.length;t++){var r=n[t],o=e._ExtensionFactories[r](this);this._extensions[r]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(n,r,o){void 0===o&&(o=100),e.UnregisterExtension(n)&&t.Tools.Warn("Extension with the name ".concat(n," already exists")),e._ExtensionFactories[n]=r;var i=null!=o?o:0;e._ExtensionOrders[n]=i;for(var a=e._ExtensionNames.length,s=0;s<e._ExtensionNames.length;s++){var u=e._ExtensionNames[s];if(i<e._ExtensionOrders[u]){a=s;break}}e._ExtensionNames.splice(a,0,n)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[t];var n=e._ExtensionNames.indexOf(t);return-1!==n&&e._ExtensionNames.splice(n,1),!0},e.prototype._generateJSON=function(e,t,n){var r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(r.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return h(this,void 0,void 0,function(){var t,n,r,o,a,s,u;return f(this,function(c){switch(c.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=c.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength,e,!0),r=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",a=e+".bin",(s=new i).files[o]=n,s.files[a]=r,this._imageData)for(u in this._imageData)s.files[u]=this._imageData[u];return[2,s]}})})},e.prototype._generateBinaryAsync=function(){return h(this,void 0,void 0,function(){return f(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 h(this,void 0,void 0,function(){var t,n,r,o,a,s,u,c,l,h,p,d,m,g;return f(this,function(f){switch(f.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=f.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(s=new TextEncoder,a=s.encode(n),o=a.length),u=this._getPadding(o),c=this._getPadding(t.byteLength),l=28+o+u+t.byteLength+c,(h=new H(l)).writeUInt32(1179937895),h.writeUInt32(2),h.writeUInt32(l),h.writeUInt32(o+u),h.writeUInt32(1313821514),a)h.writeTypedArray(a);else for(p="_".charCodeAt(0),m=0;m<o;++m)(d=n.charCodeAt(m))!=n.codePointAt(m)?h.writeUInt8(p):h.writeUInt8(d);for(m=0;m<u;++m)h.writeUInt8(32);for(h.writeUInt32(t.byteLength+c),h.writeUInt32(5130562),h.writeTypedArray(t),m=0;m<c;++m)h.writeUInt8(0);return(g=new i).files[r]=new Blob([h.getOutputData()],{type:"application/octet-stream"}),[2,g]}})})},e.prototype._setNodeTransformation=function(e,n,r){var o;if(n.getPivotPoint().equalsWithEpsilon(E,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!n.position.equalsWithEpsilon(E,t.Epsilon)){var i=t.TmpVectors.Vector3[0].copyFrom(n.position);r&&U(i),e.translation=i.asArray()}n.scaling.equalsWithEpsilon(S,t.Epsilon)||(e.scale=n.scaling.asArray());var a=(null===(o=n.rotationQuaternion)||void 0===o?void 0:o.clone())||t.Quaternion.FromEulerAngles(n.rotation.x,n.rotation.y,n.rotation.z);a.equalsWithEpsilon(I,t.Epsilon)||(r&&L(a),e.rotation=a.normalize().asArray())},e.prototype._setCameraTransformation=function(e,n,r){var o=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],a=n.getWorldMatrix();if(n.parent){var s=n.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);a.multiplyToRef(s,t.TmpVectors.Matrix[1]).decompose(void 0,i,o)}else a.decompose(void 0,i,o);o.equalsWithEpsilon(E,t.Epsilon)||(r&&U(o),e.translation=o.asArray()),r&&L(i),this._babylonScene.useRightHandedSystem||W(i),i.equalsWithEpsilon(I,t.Epsilon)||(e.rotation=i.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,n=this._babylonScene.cameras;e<n.length;e++){var r=n[e],o={type:r.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(r.name&&(o.name=r.name),"perspective"===o.type)o.perspective={aspectRatio:r.getEngine().getAspectRatio(r),yfov:r.fovMode===t.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===o.type){var i=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();o.orthographic={xmag:i,ymag:a,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,o)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var n=t[e],r=this._nodesCameraMap.get(n);if(void 0!==r){this._cameras.push(n);for(var o=0,i=r;o<i.length;o++)i[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var n=t[e];n.bones.length<=0||this._skinMap.set(n,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var n,r=function(r){if(r.bones.length<=0)return"continue";var i=o._skinMap.get(r);if(null==i)return"continue";for(var a={},s=-1,u=0;u<r.bones.length;++u){var c=r.bones[u];-1!==(h=null!==(n=c.getIndex())&&void 0!==n?n:u)&&(a[h]=c,h>s&&(s=h))}for(var l=[],h=0;h<=s;++h){var f=(c=a[h]).getTransformNode(),p=f?o._nodeMap.get(f):void 0;if(void 0!==p){i.joints.push(p);var d=c.getAbsoluteInverseBindMatrix().clone();e.has(f)&&k(d),l.push(d)}else t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var m=o._nodesSkinMap.get(i);if(i.joints.length>0&&void 0!==m){var g=new Float32Array(16*l.length);l.forEach(function(e,t){g.set(e.m,16*t)});var x=o._bufferManager.createBufferView(g);o._accessors.push(o._bufferManager.createAccessor(x,"MAT4",5126,l.length)),i.inverseBindMatrices=o._accessors.length-1,o._skins.push(i);for(var _=o._skins.length-1,v=0,T=m;v<T.length;v++)T[v].skin=_}},o=this,i=0,a=this._babylonScene.skeletons;i<a.length;i++)r(a[i])},e.prototype._exportSceneAsync=function(){return h(this,void 0,void 0,function(){var e,n,r,o,i,a,s,u,c,l,h,p,d,m,g,x,_,v,T,y,b,M,w,A,C,E,I,S,V,F,B,O,N;return f(this,function(f){switch(f.label){case 0:if(e={nodes:[]},this._babylonScene.metadata&&(n=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=n),r=new Array,o=new Array,i=new Array,this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(s=0,u=this._babylonScene.animationGroups;s<u.length;s++)for(c=u[s],l=0,h=c.targetedAnimations;l<h.length;l++)p=h[l],(d=p.target)instanceof t.TransformNode&&!d.parent&&(null!=a?a:a=new Set).add(d);for(m=0,g=this._babylonScene.rootNodes;m<g.length;m++)x=g[m],_=x.animations,v=!!_&&_.length>0||(null==a?void 0:a.has(x)),this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&R(x,this._babylonScene.useRightHandedSystem)&&!v?i.push.apply(i,x.getChildren()):this._babylonScene.useRightHandedSystem?r.push(x):o.push(x);return this._listAvailableCameras(),this._listAvailableSkeletons(),T=new J(!0,!1),b=(y=(B=e.nodes).push).apply,M=[B],[4,this._exportNodesAsync(o,T)];case 1:return b.apply(y,M.concat([f.sent()])),w=new J(!1,!1),C=(A=(O=e.nodes).push).apply,E=[O],[4,this._exportNodesAsync(r,w)];case 2:return C.apply(A,E.concat([f.sent()])),I=new J(!1,!0),V=(S=(N=e.nodes).push).apply,F=[N],[4,this._exportNodesAsync(i,I)];case 3:return V.apply(S,F.concat([f.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(T.getNodesSet()),this._babylonScene.animationGroups.length&&Z._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,T.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 h(this,void 0,void 0,function(){var n,r,o,i;return f(this,function(a){switch(a.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,a.label=1;case 1:return r<o.length?(i=o[r],[4,this._exportNodeAsync(i,n,t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return r++,[3,1];case 4:return[2,n]}})})},e.prototype._collectBuffers=function(e,n,r,o,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var s in a)if(N(s)){var u=a[s];i.setHasVertexColorAlpha(u,e.hasVertexAlpha);var c=u._buffer,l=n.get(c)||[];n.set(c,l),-1===l.indexOf(u)&&l.push(u);var h=r.get(u)||[];r.set(u,h),-1===h.indexOf(e)&&h.push(e)}var f=e.morphTargetManager;if(f)for(var p=0;p<f.numTargets;p++){var d=f.getTarget(p);h=o.get(d)||[],o.set(d,h),-1===h.indexOf(e)&&h.push(e)}}for(var m=0,g=e.getChildren();m<g.length;m++){var x=g[m];this._collectBuffers(x,n,r,o,i)}},e.prototype._exportBuffers=function(e,n){for(var r=new Map,o=new Map,i=new Map,a=0,s=e;a<s.length;a++){var u=s[a];this._collectBuffers(u,r,o,i,n)}for(var c=Array.from(r.keys()),l=function(e){var i=e.getData();if(!i)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 u=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)}(i).slice(),c=function(e){var n=o.get(e),r=F(e,n),i=r.byteOffset,a=r.byteStride,s=r.componentCount,c=r.type,l=r.count,f=r.normalized;switch(r.kind){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,i,a,s,c,l,f,function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}});break;case t.VertexBuffer.ColorKind:var p=n.filter(function(e){return e.material instanceof t.StandardMaterial||null==e.material}).length;if(0==p)break;if(p!=n.length){t.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}c==t.VertexBuffer.UNSIGNED_BYTE&&t.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var d=new t.Color3,m=new t.Color4,g=h._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(u,i,a,s,c,l,f,function(e){3===e.length?(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0)):(m.fromArray(e,0),m.toLinearSpaceToRef(m,g),m.toArray(e,0))})}},l=0,f=a;l<f.length;l++)c(B=f[l]);if(n.convertToRightHanded){for(var p=0,d=a;p<d.length;p++){var m=F(B=d[p],o.get(B)),g=m.byteOffset,x=m.byteStride,_=m.componentCount,v=m.type,T=m.count,y=m.normalized;switch(R=m.kind){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,g,x,_,v,T,y,function(e){e[0]=-e[0]})}}n.convertedToRightHandedBuffers.set(e,u)}var b=h._bufferManager.createBufferView(u,s);n.setVertexBufferView(e,b);for(var M=new Map,w=0,A=a;w<A.length;w++){var C=F(B=A[w],o.get(B)),R=C.kind,E=C.totalVertices;switch(R){case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:if(B.type==t.VertexBuffer.FLOAT){var I=B.getFloatData(E);null!==I&&M.set(B,I)}}}0!==M.size&&t.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 B=V[S],N=M.get(B);if(N){for(var P=O(N),U=new(P?Uint16Array:Uint8Array)(N.length),k=0;k<N.length;k++)U[k]=N[k];var L=h._bufferManager.createBufferView(U,4*(P?2:1));n.setRemappedBufferView(e,B,L)}}},h=this,f=0,p=c;f<p.length;f++)l(p[f]);for(var d=0,m=Array.from(i.keys());d<m.length;d++){var g=m[d],x=i.get(g);if(x)for(var _=Y(g,x[0],this._bufferManager,this._bufferViews,this._accessors,n.convertToRightHanded),v=0,T=x;v<T.length;v++){var y=T[v];n.bindMorphDataToMesh(y,_)}}},e.prototype._exportNodeAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h=this;return f(this,function(f){switch(f.label){case 0:return void 0!==(r=this._nodeMap.get(e))?(t.includes(r)||t.push(r),[2]):[4,this._createNodeAsync(e,n)];case 1:(o=f.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),i={name:"runtime animations",channels:[],samplers:[]},a=[],this._babylonScene.animationGroups.length||(Z._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&Z._CreateNodeAnimationFromNodeAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),a.forEach(function(e){e.channels.length&&e.samplers.length&&h._animations.push(e)})),s=o?[]:t,u=0,c=e.getChildren(),f.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:f.sent(),f.label=4;case 4:return u++,[3,2];case 5:return o&&s.length&&(o.children=s),[2]}})})},e.prototype._createNodeAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,p,d,m;return f(this,function(f){switch(f.label){case 0:return this._shouldExportNode(e)?(r={},e.name&&(r.name=e.name),e.metadata&&(o=this._options.metadataSelector(e.metadata))&&(r.extras=o),e instanceof t.TransformNode?(this._setNodeTransformation(r,e,n.convertToRightHanded),e instanceof t.AbstractMesh?(i=e instanceof t.InstancedMesh?e.sourceMesh:e).subMeshes&&i.subMeshes.length>0?(a=r,[4,this._exportMeshAsync(i,n)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:a.mesh=f.sent(),f.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===(p=this._nodesSkinMap.get(s))||void 0===p||p.push(r)),f.label=3;case 3:if(e instanceof t.TargetCamera&&(u=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(u)&&this._nodesCameraMap.set(u,[]),this._setCameraTransformation(r,e,n.convertToRightHanded),null!==(c=e.parent)&&z(e,c)&&void 0!==(l=this._nodeMap.get(c)))return h=this._nodes[l],D(r,h),null===(d=this._nodesCameraMap.get(u))||void 0===d||d.push(h),[2,null];null===(m=this._nodesCameraMap.get(u))||void 0===m||m.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,n.convertToRightHanded)];case 4:return f.sent()?[2,r]:(t.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}})})},e.prototype._exportIndices=function(e,n,r,o,i,a,s,u,c){var l=null;c.mode=function(e){switch(e){case t.Material.TriangleFillMode:return 4;case t.Material.TriangleStripDrawMode:return 5;case t.Material.TriangleFanDrawMode:return 6;case t.Material.PointListDrawMode:case t.Material.PointFillMode:return 0;case t.Material.LineLoopDrawMode:return 2;case t.Material.LineListDrawMode:return 1;case t.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}(a);var h=s!==t.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case t.Material.TriangleFillMode:case t.Material.TriangleStripDrawMode:case t.Material.TriangleFanDrawMode:return!0}return!1}(a);if(h){if(a===t.Material.TriangleStripDrawMode||a===t.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");var f=n?new Uint32Array(o):new Uint16Array(o);if(e)for(var p=0;p+2<o;p+=3)f[p]=e[r+p]+i,f[p+1]=e[r+p+2]+i,f[p+2]=e[r+p+1]+i;else for(p=0;p+2<o;p+=3)f[p]=p,f[p+1]=p+2,f[p+2]=p+1;l=f}else if(e&&0!==i){for(f=n?new Uint32Array(o):new Uint16Array(o),p=0;p<o;p++)f[p]=e[r+p]+i;l=f}else e&&(l=function(e,t,n,r){var o=e;return 0===t&&n===e.length||(o=Array.isArray(e)?e.slice(t,t+n):e.subarray(t,t+n)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?r?new Uint32Array(o):new Uint16Array(o):o}(e,r,o,n));if(l){var d=u.getIndicesAccessor(e,r,o,i,h);if(void 0===d){var m=this._bufferManager.createBufferView(l),g=n?5125:5123;this._accessors.push(this._bufferManager.createAccessor(m,"SCALAR",g,o,0)),d=this._accessors.length-1,u.setIndicesAccessor(e,r,o,i,h,d)}c.indices=d}},e.prototype._exportVertexBuffer=function(e,n,r,o,i,a){var s=e.getKind();if(N(s)&&(!s.startsWith("uv")||this._options.exportUnusedUVs||n&&this._materialNeedsUVsSet.has(n))){var u=i.getVertexAccessor(e,r,o);if(void 0===u){var c=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),l=s===t.VertexBuffer.PositionKind?function(e,n,r,o){var i=n.byteOffset,a=n.byteStride,s=n.type,u=n.normalized,c=n.getSize(),l=new Array(c).fill(1/0),h=new Array(c).fill(-1/0);return t.EnumerateFloatValues(e,i+r*a,a,c,s,o*c,u,function(e){for(var t=0;t<c;t++)l[t]=Math.min(l[t],e[t]),h[t]=Math.max(h[t],e[t])}),{min:l,max:h}}(c,e,r,o):void 0,h=(s===t.VertexBuffer.MatricesIndicesKind||s===t.VertexBuffer.MatricesIndicesExtraKind)&&e.type===t.VertexBuffer.FLOAT,f=h?t.VertexBuffer.UNSIGNED_BYTE:e.type,p=h?void 0:e.normalized,d=h?i.getRemappedBufferView(e._buffer,e):i.getVertexBufferView(e._buffer),m=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,n){if(e==t.VertexBuffer.ColorKind)return n?"VEC4":"VEC3";switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:return"VEC3";case t.VertexBuffer.TangentKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(s,i.hasVertexColorAlpha(e)),f,o,m,l,p)),u=this._accessors.length-1,i.setVertexAccessor(e,r,o,u)}a.attributes[function(e){switch(e){case t.VertexBuffer.PositionKind:return"POSITION";case t.VertexBuffer.NormalKind:return"NORMAL";case t.VertexBuffer.TangentKind:return"TANGENT";case t.VertexBuffer.ColorKind:return"COLOR_0";case t.VertexBuffer.UVKind:return"TEXCOORD_0";case t.VertexBuffer.UV2Kind:return"TEXCOORD_1";case t.VertexBuffer.UV3Kind:return"TEXCOORD_2";case t.VertexBuffer.UV4Kind:return"TEXCOORD_3";case t.VertexBuffer.UV5Kind:return"TEXCOORD_4";case t.VertexBuffer.UV6Kind:return"TEXCOORD_5";case t.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case t.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case t.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case t.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(s)]=u}},e.prototype._exportMaterialAsync=function(e,n,r,o){return h(this,void 0,void 0,function(){var i,a;return f(this,function(s){switch(s.label){case 0:return void 0!==(i=this._materialMap.get(e))?[3,8]:(a=n&&Object.keys(n).some(function(e){return e.startsWith("uv")}),(e=e instanceof t.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof t.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,a)]:[3,2]);case 1:return i=s.sent(),[3,7];case 2:return e instanceof t.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,a)]:[3,4];case 3:return i=s.sent(),[3,7];case 4:return e instanceof t.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,a)]:[3,6];case 5:return i=s.sent(),[3,7];case 6:return t.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,i),s.label=8;case 8:return o.material=i,[2]}})})},e.prototype._exportMeshAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,d,m,g,x,_,v,T,y,b,M,w,A,C,R,E,I,S,V,F,B,O,N,P,U,k;return f(this,function(f){switch(f.label){case 0:if(void 0!==(r=n.getMesh(e)))return[2,r];if(o={primitives:[]},r=this._meshes.length,this._meshes.push(o),n.setMesh(e,r),i=e.isUnIndexed?null:e.getIndices(),a=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),s=n.getMorphTargetsFromMesh(e),u=e instanceof t.LinesMesh,c=e instanceof t.GreasedLineBaseMesh,l=e.subMeshes,!(a&&l&&l.length>0))return[3,7];h=0,d=l,f.label=1;case 1:return h<d.length?(m=d[h],g={attributes:{}},x=m.getMaterial()||this._babylonScene.defaultMaterial,c?(y={name:x.name},b=e,_=t.Color3.White(),v=null!==(N=null===(O=b.material)||void 0===O?void 0:O.alpha)&&void 0!==N?N:1,(!(T=null!==(U=null===(P=b.greasedLineMaterial)||void 0===P?void 0:P.color)&&void 0!==U?U:_).equalsWithEpsilon(_,t.Epsilon)||v<1)&&(y.pbrMetallicRoughness={baseColorFactor:p(p([],T.asArray(),!0),[v],!1)}),this._materials.push(y),g.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return u?(y={name:x.name},(!(b=e).color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||b.alpha<1)&&(y.pbrMetallicRoughness={baseColorFactor:p(p([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(y),g.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(x,a,m,g)];case 4:f.sent(),f.label=5;case 5:for(M=u||c?t.Material.LineListDrawMode:null!==(k=e.overrideRenderingFillMode)&&void 0!==k?k:x.fillMode,w=x._getEffectiveOrientation(e),n.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(w=w===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(i,i?t.AreIndices32Bits(i,m.indexCount,m.indexStart,m.verticesStart):m.verticesCount>65535,i?m.indexStart:m.verticesStart,i?m.indexCount:m.verticesCount,-m.verticesStart,M,w,n,g),A=0,C=Object.values(a);A<C.length;A++)R=C[A],this._exportVertexBuffer(R,x,m.verticesStart,m.verticesCount,n,g);if(s)for(g.targets=[],E=0,I=s;E<I.length;E++)F=I[E],g.targets.push(F.attributes);o.primitives.push(g),this._extensionsPostExportMeshPrimitive(g),f.label=6;case 6:return h++,[3,1];case 7:if(s)for(o.weights=[],o.extras||(o.extras={}),o.extras.targetNames=[],S=0,V=s;S<V.length;S++)F=V[S],o.weights.push(F.influence),o.extras.targetNames.push(F.name);return[2,r]}})})},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),ee=function(){function e(){}return e.GLTFAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o;return f(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new $(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e.GLBAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o;return f(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new $(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e}(),te={__proto__:null,GLTF2Export:ee},ne="EXT_mesh_gpu_instancing";function re(e,t){for(var n=new Float32Array(3*t),r=0;r<t;r++)n[3*r+0]=e[4*r+0],n[3*r+1]=e[4*r+1],n[3*r+2]=e[4*r+2];return n}var oe=function(){function e(e){this.name=ne,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,n,r,o,i,a){return h(this,void 0,void 0,function(){var e=this;return f(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var s,u;if(n&&r instanceof t.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var c=t.Vector3.Zero(),l=t.Quaternion.Identity(),h=t.Vector3.One(),f=r.thinInstanceGetWorldMatrices(),p=t.TmpVectors.Vector3[2],d=t.TmpVectors.Quaternion[1],m=t.TmpVectors.Vector3[3],g=!1,x=!1,_=!1,v=new Float32Array(3*r.thinInstanceCount),T=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),b=0,M=0,w=f;M<w.length;M++)w[M].decompose(m,d,p),i&&(U(p),L(d)),v.set(p.asArray(),3*b),T.set(d.normalize().asArray(),4*b),y.set(m.asArray(),3*b),g=g||!p.equalsWithEpsilon(c),x=x||!d.equalsWithEpsilon(l),_=_||!m.equalsWithEpsilon(h),b++;var A={attributes:{}};g&&(A.attributes.TRANSLATION=e._buildAccessor(v,"VEC3",r.thinInstanceCount,a)),x&&(A.attributes.ROTATION=e._buildAccessor(T,"VEC4",r.thinInstanceCount,a)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,a));var C=null===(u=null===(s=r._userThinInstanceBuffersStorage)||void 0===s?void 0:s.data)||void 0===u?void 0:u.instanceColor;if(C){var R=r.thinInstanceCount;r.hasVertexAlpha&&C.length===4*R?(e._instanceColorWarned||(t.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),C=re(C,R)):C.length===4*R&&(C=re(C,R)),C.length===3*R&&(A.attributes._COLOR_0=e._buildAccessor(C,"VEC3",R,a))}n.extensions=n.extensions||{},n.extensions[ne]=A}o(n)})];case 1:return[2,o.sent()]}})})},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),i=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();$.RegisterExtension(ne,function(e){return new oe(e)});var ie="KHR_draco_mesh_compression";function ae(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}var se=function(){function e(e){this.name=ie,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&t.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,n,r){var o=this;if(this.enabled)if(4===e.mode||5===e.mode){var i=[],a=[],s=null;if(void 0!==e.indices){var u=r[e.indices],c=n.getBufferView(u);s=n.getData(c).slice(),i.push(c),a.push(u)}for(var l=[],h=0,f=Object.entries(e.attributes);h<f.length;h++){var p=f[h],d=p[0],m=(u=r[p[1]],c=n.getBufferView(u),B(u.type)),g=t.GetTypedArrayData(n.getData(c),m,u.componentType,u.byteOffset||0,c.byteStride||t.GetTypeByteLength(u.componentType)*m,u.count,!0);l.push({kind:d,dracoName:ae(d),size:B(u.type),data:g}),i.push(c),a.push(u)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},_=t.DracoEncoder.Default._encodeAsync(l,s,x).then(function(t){var r={bufferView:-1,attributes:t.attributeIds},s=n.createBufferView(t.data);n.setBufferView(r,s);for(var u=0,c=i;u<c.length;u++){var l=c[u];o._bufferViewsUsed.add(l)}for(var h=0,f=a;h<f.length;h++){var p=f[h];o._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[ie]=r}).catch(function(e){t.Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. "+e.message)});this._encodePromises.push(_),this._wasUsed=!0}else t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return h(this,void 0,void 0,function(){var t=this;return f(this,function(n){switch(n.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return n.sent(),this._bufferViewsUsed.forEach(function(n){e.getPropertiesWithBufferView(n).every(function(e){return t._accessorsUsed.has(e)})&&e.removeBufferView(n)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}})})},e}();$.RegisterExtension(ie,function(e){return new se(e)});var ue="KHR_lights_punctual",ce={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},le={innerConeAngle:0,outerConeAngle:Math.PI/4},he=t.Vector3.Backward(),fe=function(){function e(e){this.name=ue,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[ue]=this._lights},e.prototype.postExportNodeAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a=this;return f(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){if(r instanceof t.Light){var u=r.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(u&&r instanceof t.ShadowLight))return t.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ue)),void s(n);if(r.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(ue," specification!")),!r.position.equalsToFloats(0,0,0)){var c=t.TmpVectors.Vector3[0].copyFrom(r.position);i&&U(c),n.translation=c.asArray()}if("point"!==u){var l=r.direction.normalizeToRef(t.TmpVectors.Vector3[0]);i&&U(l);var h=t.Quaternion.FromUnitVectorsToRef(he,l,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(h)||(n.rotation=h.asArray())}var f={type:u,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(K(f,ce),"spot"===u){var p=r;f.spot={innerConeAngle:p.innerAngle/2,outerConeAngle:p.angle/2},K(f.spot,le)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(f);var d={light:a._lights.lights.length-1},m=r.parent;if(m&&z(r,m)){var g=o.get(m);if(g){var x=a._exporter._nodes[g];return D(n,x),x.extensions||(x.extensions={}),x.extensions[ue]=d,void s(null)}}n.extensions||(n.extensions={}),n.extensions[ue]=d,s(n)}else s(n)})];case 1:return[2,s.sent()]}})})},e}();$.RegisterExtension(ue,function(e){return new fe(e)});var pe="EXT_lights_area",de={name:"",color:[1,1,1],intensity:1,size:1},me={aspect:1},ge=t.Vector3.Backward(),xe=function(){function e(e){this.name=pe,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[pe]=this._lights},e.prototype.postExportNodeAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a=this;return f(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){if(r instanceof t.Light){var u=r.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!u)return t.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(pe)),void s(n);var c=r;if(c.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(pe," specification!")),!c.position.equalsToFloats(0,0,0)){var l=t.TmpVectors.Vector3[0].copyFrom(c.position);i&&U(l),n.translation=l.asArray()}var h=t.Vector3.Forward();i&&U(h);var f=t.Quaternion.FromUnitVectorsToRef(ge,h,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(f)||(n.rotation=f.asArray());var p={type:u,name:c.name,color:c.diffuse.asArray(),intensity:c.intensity,size:c.height,rect:{aspect:c.width/c.height}};K(p,de),p.rect&&K(p.rect,me),a._lights||(a._lights={lights:[]}),a._lights.lights.push(p);var d={light:a._lights.lights.length-1},m=r.parent;if(m&&z(c,m)){var g=o.get(m);if(g){var x=a._exporter._nodes[g];return D(n,x),x.extensions||(x.extensions={}),x.extensions[pe]=d,void s(null)}}n.extensions||(n.extensions={}),n.extensions[pe]=d,s(n)}else s(n)})];case 1:return[2,s.sent()]}})})},e}();$.RegisterExtension(pe,function(e){return new xe(e)});var _e="KHR_materials_anisotropy";function ve(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.specularRoughnessAnisotropyTexture,o=e.geometryTangentTexture,r||o?[4,t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent()]}})})}var Te=function(){function e(e){this.name=_e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o;return f(this,function(i){switch(i.label){case 0:return e=[],r instanceof t.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 t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0?(n=function(e){var t=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}(r),this._anisoTexturesMap[n]?(e.push(this._anisoTexturesMap[n]),[3,4]):[3,2]):[3,5];case 2:return[4,ve(r)];case 3:(o=i.sent())&&(e.push(o),this._anisoTexturesMap[n]=o),i.label=4;case 4:return[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c,l;if(r instanceof t.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var h=o._exporter._materialExporter.getTextureInfo(r.anisotropy.texture);null!==(v={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=h?h:void 0}).anisotropyTexture&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[_e]=v}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){o._wasUsed=!0,n.extensions=n.extensions||{};var f=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(f=r.baseMetalnessTexture);var p=o._anisoTexturesMap[r.id];if(!f&&!p){var d=r.specularRoughness,m=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var g=(a=r.specularRoughness,l=(1-(s=r.specularRoughnessAnisotropy))*(c=(u=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(l),newAnisotropyStrength:Math.min(Math.sqrt((c-u)/Math.max(1-u,1e-4)),1)});d=g.newBaseRoughness,m=g.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=d);var x={anisotropyStrength:m,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return n.extensions[_e]=x,e(n)}var _=p?o._exporter._materialExporter.getTextureInfo(p):null,v={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};r._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(i=o._exporter._glTF).extensionsUsed||(i.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&o._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),o._exporter._materialNeedsUVsSet.add(r),n.extensions[_e]=v}e(n)})},e}();$.RegisterExtension(_e,function(e){return new Te(e)});var ye="KHR_materials_clearcoat";function be(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatWeightTexture,o=e.coatRoughnessTexture,r||o?[4,t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function Me(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var we=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 n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i;return f(this,function(a){switch(a.label){case 0:return e=[],r instanceof t.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 t.OpenPBRMaterial&&r.coatWeight>0?(n=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):n=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):n=!0),n?(o=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,3]:[4,be(r)]):[3,4]):[3,5];case 2:(i=a.sent())&&(this._cachedInternalTexturesMap[o]=i),a.label=3;case 3:this._cachedInternalTexturesMap[o]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Me(this._cachedInternalTexturesMap[o],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Me(this._cachedInternalTexturesMap[o],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,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var i,a=o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);i=r.clearCoat.useRoughnessFromMainTexture?o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):o._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&t.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var s=o._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture);null===(l={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[ye]=l}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var u=void 0,c=void 0;r.coatWeightTexture&&(u=o._mergedTexturesMap[r.coatWeightTexture.uniqueId],c=o._exporter._materialExporter.getTextureInfo(u));var l,h=void 0,f=void 0;r.coatRoughnessTexture&&(h=o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],f=o._exporter._materialExporter.getTextureInfo(h)),r.coatColorTexture&&t.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),s=o._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),null===(l={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=c?c:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=f?f:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[ye]=l}e(n)})},e}();$.RegisterExtension(ye,function(e){return new we(e)});var Ae="KHR_materials_coat";function Ce(e){var t=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}function Re(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatRoughnessAnisotropyTexture,o=e.geometryCoatTangentTexture,r||o?[4,t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent()]}})})}function Ee(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatWeightTexture,o=e.coatRoughnessTexture,r||o?[4,t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function Ie(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var Se=function(){function e(e){this.name=Ae,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 n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i,a;return f(this,function(s){switch(s.label){case 0:return e=[],r instanceof t.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 t.OpenPBRMaterial&&r.coatWeight>0?(n=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):n=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):n=!0),n?(i=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(r),this._cachedInternalTexturesMap[i]?[3,3]:[4,Ee(r)]):[3,4]):[3,9];case 2:(o=s.sent())&&(this._cachedInternalTexturesMap[i]=o),s.label=3;case 3:this._cachedInternalTexturesMap[i]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[i],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[i],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?(i=Ce(r),this._mergedTexturesMap[i]?(e.push(this._mergedTexturesMap[i]),[3,7]):[3,5]):[3,8];case 5:return[4,Re(r)];case 6:(a=s.sent())&&(e.push(a),this._mergedTexturesMap[i]=a),s.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c,l;if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var h,f=o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);h=r.clearCoat.useRoughnessFromMainTexture?o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):o._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness);var p=void 0;r.clearCoat.isTintEnabled&&(p=o._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));var d=o._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),m=r.clearCoat.indexOfRefraction;null===(v={coatFactor:r.clearCoat.intensity,coatTexture:null!=f?f:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=h?h:void 0,coatNormalTexture:null!=d?d:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=p?p:void 0,coatIor:1.5!==m?m:void 0}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatColorTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[Ae]=v}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var g=void 0;f=void 0,r.coatWeightTexture&&(g=o._mergedTexturesMap[r.coatWeightTexture.uniqueId]?o._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,f=o._exporter._materialExporter.getTextureInfo(g));var x=void 0,_=void 0;r.coatRoughnessTexture&&(x=o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,_=o._exporter._materialExporter.getTextureInfo(x)),d=o._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),p=o._exporter._materialExporter.getTextureInfo(r.coatColorTexture),m=r.coatIor;var v,T=r.coatDarkening,y=r.coatRoughnessTexture,b=Ce(r),M=o._mergedTexturesMap[b],w=0,A=0,C=void 0;if(r.coatRoughnessAnisotropy>0){if(y||M){var R=M?o._exporter._materialExporter.getTextureInfo(M):null;w=r.coatRoughnessAnisotropy,A=r.geometryCoatTangentAngle,C=R||void 0}else{var E=r.coatRoughness,I=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var S=(a=r.coatRoughness,l=(1-(s=r.coatRoughnessAnisotropy))*(c=(u=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(l),newAnisotropyStrength:Math.min(Math.sqrt((c-u)/Math.max(1-u,1e-4)),1)});E=S.newBaseRoughness,I=S.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=E),w=I,A=r.geometryCoatTangentAngle+.5*Math.PI,C=void 0}r._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(i=o._exporter._glTF).extensionsUsed||(i.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&o._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(v={coatFactor:r.coatWeight,coatTexture:null!=f?f:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=_?_:void 0,coatNormalTexture:null!=d?d:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=p?p:void 0,coatIor:1.5!==m?m:void 0,coatDarkeningFactor:1!==T?T:void 0,coatAnisotropyRotation:A,coatAnisotropyStrength:w,coatAnisotropyTexture:C}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatAnisotropyTexture&&null===v.coatColorTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[Ae]=v}e(n)})},e}();$.RegisterExtension(Ae,function(e){return new Se(e)});var Ve="KHR_materials_diffuse_transmission";function Fe(e,n){var r=n.subSurface,o=null;return r.translucencyIntensityTexture?o=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(o=r.thicknessTexture),o&&!r.useGltfStyleTextures?(t.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(n.name),1),null):o}var Be=function(){function e(e){this.name=Ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var n,o;return f(this,function(i){return n=[],r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)?((o=Fe(e,r))&&n.push(o),r.subSurface.translucencyColorTexture&&n.push(r.subSurface.translucencyColorTexture),[2,n]):[2,n]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(i){var a,s;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var u=r.subSurface,c=Fe(e,r),l=0==u.translucencyIntensity?void 0:u.translucencyIntensity,h=null!==(a=o._exporter._materialExporter.getTextureInfo(c))&&void 0!==a?a:void 0,f=!u.translucencyColor||u.translucencyColor.equalsFloats(1,1,1)?void 0:u.translucencyColor.asArray(),p=null!==(s=o._exporter._materialExporter.getTextureInfo(u.translucencyColorTexture))&&void 0!==s?s:void 0,d={diffuseTransmissionFactor:l,diffuseTransmissionTexture:h,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:p};(h||p)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions=n.extensions||{},n.extensions[Ve]=d}i(n)})},e}();$.RegisterExtension(Ve,function(e){return new Be(e)});var Oe="KHR_materials_dispersion",Ne=function(){function e(){this.name=Oe,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,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i={dispersion:r.subSurface.dispersion};n.extensions=n.extensions||{},n.extensions[Oe]=i}e(n)})},e}();$.RegisterExtension(Oe,function(){return new Ne});var Pe="KHR_materials_emissive_strength",Ue=function(){function e(){this.name=Pe,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,n,r){return h(this,void 0,void 0,function(){var e=this;return f(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){if(!(r instanceof t.PBRMaterial))return o(n);var i=r.emissiveColor.scale(r.emissiveIntensity),a=Math.max.apply(Math,i.asArray());if(a>1){n.emissiveFactor=i.scale(1/a).asArray(),e._wasUsed=!0;var s={emissiveStrength:a};n.extensions||(n.extensions={}),n.extensions[Pe]=s}else n.emissiveFactor=i.asArray();return o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(Pe,function(){return new Ue});var ke="KHR_materials_ior",Le=function(){function e(){this.name=ke,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(e instanceof t.OpenPBRMaterial?1.5!=e.specularIor:e instanceof t.PBRMaterial&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction)},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i={ior:r.indexOfRefraction};n.extensions=n.extensions||{},n.extensions[ke]=i}else r instanceof t.OpenPBRMaterial&&o._isExtensionEnabled(r)&&(o._wasUsed=!0,i={ior:r.specularIor},n.extensions=n.extensions||{},n.extensions[ke]=i);e(n)})},e}();$.RegisterExtension(ke,function(e){return new Le});var We="KHR_materials_iridescence",De=function(){function e(e){this.name=We,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){if(e=[],r instanceof t.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 t.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,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var i=o._exporter._materialExporter.getTextureInfo(r.iridescence.texture),a=o._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!=i?i:void 0,iridescenceThicknessTexture:null!=a?a:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[We]=s}else if(r instanceof t.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var s,u=o._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),c=o._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture);null===(s={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=u?u:void 0,iridescenceThicknessTexture:null!=c?c:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[We]=s}e(n)})},e}();$.RegisterExtension(We,function(e){return new De(e)});var ze="KHR_materials_sheen",Ke=function(){function e(e){this.name=ze,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){return f(this,function(e){return r instanceof t.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[2,[r.sheen.texture]]:[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e=this;return f(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var i,a,s,u;if(r instanceof t.PBRMaterial){if(!r.sheen.isEnabled)return void o(n);e._wasUsed=!0,null==n.extensions&&(n.extensions={});var c={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=r.sheen.roughness)&&void 0!==i?i:0};null===c.sheenColorTexture&&null===c.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(c.sheenColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?c.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(c.sheenRoughnessTexture=null!==(u=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==u?u:void 0),n.extensions[ze]=c}o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(ze,function(e){return new Ke(e)});var Ge="KHR_materials_fuzz";function qe(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.fuzzColorTexture,o=e.fuzzRoughnessTexture,r||o?[4,t.MergeTexturesAsync("FuzzTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(1),r?t.CreateTextureInput(r,2):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function He(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var je=function(){function e(e){this.name=Ge,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 n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i;return f(this,function(a){switch(a.label){case 0:return r instanceof t.OpenPBRMaterial?(e=[],r.fuzzWeight>0?(r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture),n=!1,r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):n=!0),r.fuzzColorTexture&&!n&&e.push(r.fuzzColorTexture),n?(o=function(e){var t=e.fuzzColorTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",r=e.fuzzRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(n,"_FuzzRoughness_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,2]:[4,qe(r)]):[3,3]):[3,3]):[3,4];case 1:(i=a.sent())&&(this._cachedInternalTexturesMap[o]=i),a.label=2;case 2:this._cachedInternalTexturesMap[o]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=He(this._cachedInternalTexturesMap[o],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=He(this._cachedInternalTexturesMap[o],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,n,r){return h(this,void 0,void 0,function(){var e=this;return f(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var i,a,s;if(r instanceof t.OpenPBRMaterial){if(0==r.fuzzWeight)return void o(n);e._wasUsed=!0,null==n.extensions&&(n.extensions={});var u={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};r.fuzzWeightTexture&&(u.fuzzTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==i?i:void 0);var c=void 0;r.fuzzColorTexture&&(c=e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,u.fuzzColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==a?a:void 0);var l=void 0;r.fuzzRoughnessTexture&&(l=e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,u.fuzzRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(l))&&void 0!==s?s:void 0),null===u.fuzzColorTexture&&null===u.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),n.extensions[Ge]=u}o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(Ge,function(e){return new je(e)});var Xe="KHR_materials_specular",Qe=function(){function e(e){this.name=Xe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){return e=[],r instanceof t.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,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0,n.extensions=n.extensions||{};var l=null!==(i=o._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==i?i:void 0,h=null!==(a=o._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,f={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:l,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:h};o._hasTexturesExtension(r)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[Xe]=f}else if(r instanceof t.OpenPBRMaterial){n.extensions=n.extensions||{};var p=null!==(s=o._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==s?s:void 0,d=null!==(u=o._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==u?u:void 0,m=1==r.specularWeight?void 0:r.specularWeight,g=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!d&&!p&&void 0===m&&void 0===g)return e(n);o._wasUsed=!0,(f={specularFactor:m,specularTexture:p,specularColorFactor:g,specularColorTexture:d,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(c=o._exporter._glTF).extensionsUsed||(c.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&o._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(p||d)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[Xe]=f}e(n)})},e}();$.RegisterExtension(Xe,function(e){return new Qe(e)});var Ze="KHR_materials_transmission",Ye=function(){function e(e){this.name=Ze,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){if(e=[],r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.refractionIntensityTexture&&r.subSurface.useGltfStyleTextures&&e.push(r.subSurface.refractionIntensityTexture),[2,e]}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionWeightTexture&&(e.push(r.transmissionWeightTexture),r.transmissionColorTexture&&e.push(r.transmissionColorTexture)),r.subsurfaceWeight>0&&r.subsurfaceWeightTexture&&e.push(r.subsurfaceWeightTexture));return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e instanceof t.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0||e.subsurfaceWeight>0;if(e instanceof t.PBRMaterial&&!e.unlit){var n=e.subSurface;return n.isRefractionEnabled&&null!=n.refractionIntensity&&0!=n.refractionIntensity||null!=n.refractionIntensityTexture&&n.useGltfStyleTextures}return!1},e.prototype.postExportMaterialAsync=function(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,c,l;return f(this,function(h){return this._isExtensionEnabled(r)?(r instanceof t.PBRMaterial?(this._wasUsed=!0,o=r.subSurface,a=0===o.refractionIntensity?void 0:o.refractionIntensity,s={transmissionFactor:a},o.refractionIntensityTexture&&(o.useGltfStyleTextures?(this._exporter._materialNeedsUVsSet.add(r),(u=this._exporter._materialExporter.getTextureInfo(o.refractionIntensityTexture))&&(s.transmissionTexture=u)):t.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported"))),n.extensions||(n.extensions={}),n.extensions[Ze]=s):r instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,i=(1-r.transmissionWeight)*r.subsurfaceWeight,a=i+r.transmissionWeight,s={transmissionFactor:a},r.transmissionWeightTexture?(this._exporter._materialNeedsUVsSet.add(r),(u=this._exporter._materialExporter.getTextureInfo(r.transmissionWeightTexture))&&(s.transmissionTexture=u)):r.subsurfaceWeightTexture&&(this._exporter._materialNeedsUVsSet.add(r),(c=this._exporter._materialExporter.getTextureInfo(r.subsurfaceWeightTexture))&&(s.transmissionTexture=c)),0!=r.transmissionDepth||r.transmissionColor.equals(t.Color3.White())&&!r.transmissionColorTexture||n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor||(n.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),n.pbrMetallicRoughness.baseColorFactor[0]*=r.transmissionColor.r,n.pbrMetallicRoughness.baseColorFactor[1]*=r.transmissionColor.g,n.pbrMetallicRoughness.baseColorFactor[2]*=r.transmissionColor.b,r.transmissionColorTexture&&!n.pbrMetallicRoughness.baseColorTexture&&(l=this._exporter._materialExporter.getTextureInfo(r.transmissionColorTexture))&&(n.pbrMetallicRoughness.baseColorTexture=l,this._exporter._materialNeedsUVsSet.add(r))),n.extensions||(n.extensions={}),n.extensions[Ze]=s),[2,n]):[2,n]})})},e}();$.RegisterExtension(Ze,function(e){return new Ye(e)});var Je="KHR_materials_unlit",$e=function(){function e(){this.name=Je,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,n,r){var o=this;return new Promise(function(e){var i=!1;r instanceof t.PBRMaterial?i=r.unlit:r instanceof t.StandardMaterial&&(i=r.disableLighting),i&&(o._wasUsed=!0,null==n.extensions&&(n.extensions={}),n.extensions[Je]={}),e(n)})},e}();$.RegisterExtension(Je,function(){return new $e});var et="KHR_materials_volume",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,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){if(e=[],r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0||r.subsurfaceWeight>0)&&r.geometryThicknessTexture&&e.push(r.geometryThicknessTexture);return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var n=e.subSurface;return!(!n.isRefractionEnabled&&!n.isTranslucencyEnabled)&&(null!=n.maximumThickness&&0!=n.maximumThickness||null!=n.tintColorAtDistance&&n.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=n.tintColor&&n.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var s=r.subSurface,u={thicknessFactor:f=0==s.maximumThickness?void 0:s.maximumThickness,thicknessTexture:h=null!==(i=o._exporter._materialExporter.getTextureInfo(s.thicknessTexture))&&void 0!==i?i:void 0,attenuationDistance:s.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:s.tintColorAtDistance,attenuationColor:V=s.tintColor.equalsFloats(1,1,1)?void 0:s.tintColor.asArray()};o._hasTexturesExtension(r)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions=n.extensions||{},n.extensions[et]=u}else if(r instanceof t.OpenPBRMaterial){var c=r.transmissionWeight>0&&!r.geometryThinWalled,l=r.subsurfaceWeight>0&&!r.geometryThinWalled;if(c||l){o._wasUsed=!0;var h,f=r.geometryThickness;(h=null!==(a=o._exporter._materialExporter.getTextureInfo(r.geometryThicknessTexture))&&void 0!==a?a:void 0)&&o._exporter._materialNeedsUVsSet.add(r);var p=void 0,d=t.Color3.White().asArray();if(c&&r.transmissionDepth>0){var m=1/r.transmissionDepth,g=new t.Vector3(-Math.log(r.transmissionColor.r)*m,-Math.log(r.transmissionColor.g)*m,-Math.log(r.transmissionColor.b)*m),x=new t.Vector3(r.transmissionScatter.r*m,r.transmissionScatter.g*m,r.transmissionScatter.b*m),_=g.subtract(x),v=Math.min(_.x,_.y,_.z);v<0&&(_.x=_.x-v,_.y=_.y-v,_.z=_.z-v),g=_.add(x),p=1/Math.max(g.x,g.y,g.z),d[0]=Math.exp(-g.x*p),d[1]=Math.exp(-g.y*p),d[2]=Math.exp(-g.z*p)}else p=Number.MAX_VALUE,d[0]=1,d[1]=1,d[2]=1;var T=1,y=t.Color3.White().asArray();if(l){var b=r.subsurfaceRadius,M=r.subsurfaceRadiusScale,w=new t.Vector3(M.r,M.g,M.b).multiplyByFloats(b,b,b),A=new t.Vector3(1/Math.max(w.x,1e-6),1/Math.max(w.y,1e-6),1/Math.max(w.z,1e-6));T=1/Math.max(A.x,A.y,A.z),y[0]=Math.exp(-A.x*T),y[1]=Math.exp(-A.y*T),y[2]=Math.exp(-A.z*T)}var C=(1-r.transmissionWeight)*r.subsurfaceWeight,R=C+r.transmissionWeight,E=1/Math.max(R,1e-6),I=r.transmissionWeight*E,S=C*E,V=d.map(function(e,t){return e*I+y[t]*S});u={thicknessFactor:f,thicknessTexture:h,attenuationDistance:p*I+T*S,attenuationColor:V},n.extensions=n.extensions||{},n.extensions[et]=u}}e(n)})},e}();$.RegisterExtension(et,function(e){return new tt(e)});var nt="KHR_materials_volume_scatter",rt=function(){function e(e){this.name=nt,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,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){return e=[],r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionScatterTexture&&e.push(r.transmissionScatterTexture),r.subsurfaceWeight>0&&r.subsurfaceColorTexture&&e.push(r.subsurfaceColorTexture)),[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var n=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),r=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!n&&!r)},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.OpenPBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i=t.Vector3.Zero(),a=0;if(r.transmissionWeight>0)x=new t.Vector3(r.transmissionScatter.r,r.transmissionScatter.g,r.transmissionScatter.b),_=new t.Vector3(Math.sqrt(1-x.x),Math.sqrt(1-x.y),Math.sqrt(1-x.z)),T=(v=new t.Vector3(1,1,1)).subtract(_),y=v.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(_)),b=v.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(_)),i=T.multiplyInPlace(y).divideInPlace(b),a=r.transmissionScatterAnisotropy;var s=t.Vector3.Zero(),u=0;r.subsurfaceWeight>0&&(s.set(r.subsurfaceColor.r,r.subsurfaceColor.g,r.subsurfaceColor.b),u=r.subsurfaceScatterAnisotropy);var c=(1-r.transmissionWeight)*r.subsurfaceWeight,l=c+r.transmissionWeight,h=1/Math.max(l,1e-6),f=r.transmissionWeight*h,p=c*h,d={multiscatterColorFactor:i.multiplyByFloats(f,f,f).addInPlace(s.multiplyByFloats(p,p,p)).asArray(),scatterAnisotropy:a*f+u*p};if(r.subsurfaceWeight>0&&r.subsurfaceColorTexture){o._exporter._materialNeedsUVsSet.add(r);var m=o._exporter._materialExporter.getTextureInfo(r.subsurfaceColorTexture);m&&(d.multiscatterColorTexture=m)}else if(r.transmissionWeight>0&&r.transmissionScatterTexture){o._exporter._materialNeedsUVsSet.add(r);var g=o._exporter._materialExporter.getTextureInfo(r.transmissionScatterTexture);g&&(d.multiscatterColorTexture=g)}n.extensions=n.extensions||{},n.extensions[nt]=d}var x,_,v,T,y,b;e(n)})},e}();$.RegisterExtension(nt,function(e){return new rt(e)},101);var ot="KHR_materials_diffuse_roughness",it=function(){function e(e){this.name=ot,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,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){if(e=[],r instanceof t.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),[2,e]}else if(r instanceof t.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i=null,a=null;if(r instanceof t.PBRBaseMaterial?(i=r._baseDiffuseRoughness,a=r._baseDiffuseRoughnessTexture):r instanceof t.OpenPBRMaterial&&(i=r.baseDiffuseRoughness,a=r.baseDiffuseRoughnessTexture),i){o._wasUsed=!0,n.extensions=n.extensions||{};var s=o._exporter._materialExporter.getTextureInfo(a),u={diffuseRoughnessFactor:i,diffuseRoughnessTexture:null!=s?s:void 0};null!==u.diffuseRoughnessTexture&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[ot]=u,e(n)}else e(n)})},e}();$.RegisterExtension(ot,function(e){return new it(e)});var at="KHR_materials_openpbr",st=function(){function e(){this.name=at,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,n,r){var o=this;return new Promise(function(e){r instanceof t.OpenPBRMaterial&&(o._wasUsed=!0,n.extensions=n.extensions||{},n.extensions[at]={}),e(n)})},e}();$.RegisterExtension(at,function(e){return new st});var ut="KHR_texture_transform",ct=function(){function e(){this.name=ut,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,n,r){if(r.getScene()||t.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(t.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 o={},i=!1;if(0===r.uOffset&&0===r.vOffset||(o.offset=[r.uOffset,r.vOffset],i=!0),1===r.uScale&&1===r.vScale||(o.scale=[r.uScale,r.vScale],i=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void t.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(ut,"."));t.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(ut,".")),o.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,a=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*i,h=o*a;return[t+(l*(1-u)+h*c),n+(h*(1-u)-l*c)]}(r)}o.rotation=-r.wAng,i=!0}0!==r.coordinatesIndex&&(o.texCoord=r.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,n.extensions||(n.extensions={}),n.extensions[ut]=o)}},e}();$.RegisterExtension(ut,function(){return new ct});var lt="KHR_texture_basisu",ht=function(){function e(e){this.name=lt,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,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[lt]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(lt,function(e){return new ht(e)});var ft="EXT_texture_webp",pt=function(){function e(e){this.name=ft,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[ft]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(ft,function(e){return new pt(e)});var dt="EXT_texture_avif",mt=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,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[dt]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(dt,function(e){return new mt(e)});var gt={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:oe,EXT_texture_avif:mt,EXT_texture_webp:pt,KHR_draco_mesh_compression:se,KHR_lights_punctual:fe,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:we,KHR_materials_coat:Se,KHR_materials_diffuse_roughness:it,KHR_materials_diffuse_transmission:Be,KHR_materials_dispersion:Ne,KHR_materials_emissive_strength:Ue,KHR_materials_fuzz:je,KHR_materials_ior:Le,KHR_materials_iridescence:De,KHR_materials_openpbr:st,KHR_materials_sheen:Ke,KHR_materials_specular:Qe,KHR_materials_transmission:Ye,KHR_materials_unlit:$e,KHR_materials_volume:tt,KHR_materials_volume_scatter:rt,KHR_texture_basisu:ht,KHR_texture_transform:ct},xt={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:oe,EXT_texture_avif:mt,EXT_texture_webp:pt,GLTF2Export:ee,GLTFData:i,KHR_draco_mesh_compression:se,KHR_lights_punctual:fe,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:we,KHR_materials_coat:Se,KHR_materials_diffuse_roughness:it,KHR_materials_diffuse_transmission:Be,KHR_materials_dispersion:Ne,KHR_materials_emissive_strength:Ue,KHR_materials_fuzz:je,KHR_materials_ior:Le,KHR_materials_iridescence:De,KHR_materials_openpbr:st,KHR_materials_sheen:Ke,KHR_materials_specular:Qe,KHR_materials_transmission:Ye,KHR_materials_unlit:$e,KHR_materials_volume:tt,KHR_materials_volume_scatter:rt,KHR_texture_basisu:ht,KHR_texture_transform:ct,_ConvertToGLTFPBRMetallicRoughness:y,_SolveMetallic:T},_t=function(){function e(){}return e.CreateSTL=function(e,n,r,o,i,a,s,u){void 0===n&&(n=!0),void 0===r&&(r="stlmesh"),void 0===o&&(o=!1),void 0===i&&(i=!0),void 0===a&&(a=!1),void 0===s&&(s=!1),void 0===u&&(u=!1);var c=function(e,n,r){var o=[3*e[r],3*e[r+1],3*e[r+2]],i=[new t.Vector3(n[o[0]],n[o[0]+2],n[o[0]+1]),new t.Vector3(n[o[1]],n[o[1]+2],n[o[1]+1]),new t.Vector3(n[o[2]],n[o[2]+2],n[o[2]+1])],a=i[0].subtract(i[1]),s=i[2].subtract(i[1]);return{v:i,n:t.Vector3.Cross(s,a).normalize()}},l=function(e,t,n,r){return t=h(e,t,n.x,r),t=h(e,t,n.y,r),h(e,t,n.z,r)},h=function(e,t,n,r){return e.setFloat32(t,n,r),t+4},f=function(e){if(s){var n=e;e instanceof t.InstancedMesh&&(n=e.sourceMesh);var r=n.getVerticesData(t.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var o=t.Vector3.Zero(),i=void 0;for(i=0;i<r.length;i+=3)t.Vector3.TransformCoordinatesFromFloatsToRef(r[i],r[i+1],r[i+2],e.computeWorldMatrix(!0),o).toArray(r,i);return r}return e.getVerticesData(t.VertexBuffer.PositionKind)||[]};s&&(a=!0);var p="",d=0,m=0;if(o){for(var g=0;g<e.length;g++)d+=(T=(_=e[g]).getIndices())?T.length/3:0;var x=new ArrayBuffer(84+50*d);m+=80,(p=new DataView(x)).setUint32(m,d,i),m+=4}else u||(p="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!o&&u&&(p+="solid "+_.name+"\r\n"),!a&&_ instanceof t.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=f(_),T=_.getIndices()||[],y=0;y<T.length;y+=3){var b=c(T,v,y);o?(m=l(p,m,b.n,i),m=l(p,m,b.v[0],i),m=l(p,m,b.v[1],i),m=l(p,m,b.v[2],i),m+=2):(p+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",p+="\t\touter loop\r\n",p+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",p+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",p+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",p+="\t\tendloop\r\n",p+="\tendfacet\r\n")}!o&&u&&(p+="endsolid "+name+"\r\n")}if(o||u||(p+="endsolid stlmesh"),n){var M=document.createElement("a"),w=new Blob([p],{type:"application/octet-stream"});M.href=window.URL.createObjectURL(w),M.download=r+".stl",M.click()}return p},e}(),vt={__proto__:null,STLExport:_t};function Tt(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],i=0;i<e.length/n;i++){var a=e[i*n]*(r?-1:1),s=e[i*n+1],u=e[i*n+2];o.push("(".concat(a.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function yt(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],i=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-i).toPrecision(t.precision),")"))}return n.join(", ")}function bt(e,n,r,o){var i=function(e,n,r,o){var i=e.getVerticesData(t.VertexBuffer.PositionKind),a=e.getVerticesData(t.VertexBuffer.NormalKind);if(i&&a)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(r,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,n=e.getIndices(),r=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==n)for(var i=0;i<r;i++)o.push(n[i]);else for(i=0;i<r;i++)o.push(i);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(Tt(a,n,void 0,o),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(Tt(i,n,void 0,o),"]\n ").concat(function(e,n){for(var r="",o=0;o<4;o++){var i=o>0?o:"",a=e.getVerticesData(t.VertexBuffer.UVKind+(i?i+1:""));a&&(r+="\n\t\ttexCoord2f[] primvars:st".concat(i," = [").concat(yt(a,n),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var s=e.getVerticesData(t.VertexBuffer.ColorKind);return s&&(r+="\n\tcolor3f[] primvars:displayColor = [".concat(Tt(s,n,s.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),r}(e,n),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,n,r,o);return'\n def "Geometry"\n {\n '.concat(i,"\n }\n ")}function Mt(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 wt(e){var t=e.m;return"( ".concat(At(t,0),", ").concat(At(t,4),", ").concat(At(t,8),", ").concat(At(t,12)," )")}function At(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function Ct(e,t){var n="Object_"+e.uniqueId,r=wt(t);return'def Xform "'.concat(n,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(r,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Rt(e){switch(e){case t.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case t.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case t.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function Et(e){return"(".concat(e.x,", ").concat(e.y,")")}function It(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function St(e,n,r,o,i,a){var s,u,c=e.getInternalTexture().uniqueId+"_"+e.invertY,l="image/jpeg"===(e.mimeType||t.GetMimeType(null!==(u=null===(s=e.getInternalTexture())||void 0===s?void 0:s.url)&&void 0!==u?u:""))?"jpg":"png";i[c]={texture:e,ext:l};var h=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",f=new t.Vector2(e.uScale,e.vScale),p=new t.Vector2(e.uOffset,e.vOffset),d=e.wAng,m=Math.sin(d),g=Math.cos(d);return p.y=1-p.y-f.y,p.x+=m*f.x,p.y+=(1-g)*f.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(h,'"\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(n.uniqueId,"/PrimvarReader_").concat(r,".outputs:result>\n float inputs:rotation = ").concat((d*(180/Math.PI)).toFixed(a.precision),"\n float2 inputs:scale = ").concat(Et(f),"\n float2 inputs:translation = ").concat(Et(p),'\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(c,".").concat(l,"@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(n.uniqueId,"/Transform2d_").concat(r,".outputs:result>\n ").concat(o?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(o):"",'\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(n.needAlphaBlending()||n.needAlphaTesting()?"float outputs:a":"","\n }")}function Vt(e,n,r){var o="\t\t\t",i=[],a=[],s=function(e){var n,r,o={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 t.StandardMaterial?c(c({},o),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof t.PBRBaseMaterial?c(c({},o),{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!==(n=e._roughness)&&void 0!==n?n: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}):o}(e),u=s.diffuseMap,l=s.diffuse,h=s.alphaCutOff,f=s.emissiveMap,p=s.emissive,d=s.normalMap,m=s.roughnessMap,g=s.roughnessChannel,x=s.roughness,_=s.metalnessMap,v=s.metalnessChannel,T=s.metalness,y=s.aoMap,b=s.aoMapChannel,M=s.aoMapIntensity,w=s.alphaMap,A=s.ior,C=s.clearCoatEnabled,R=s.clearCoat,E=s.clearCoatMap,I=s.clearCoatRoughness,S=s.clearCoatRoughnessMap;return null!==u?(i.push("".concat(o,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:a>")),i.push("".concat(o,"float inputs:opacityThreshold = ").concat(h))),a.push(St(u,e,"diffuse",l,n,r))):i.push("".concat(o,"color3f inputs:diffuseColor = ").concat(It(l||t.Color3.White()))),null!==f?(i.push("".concat(o,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(f.uniqueId,"_emissive.outputs:rgb>")),a.push(St(f,e,"emissive",p,n,r))):p&&p.toLuminance()>0&&i.push("".concat(o,"color3f inputs:emissiveColor = ").concat(It(p))),null!==d&&(i.push("".concat(o,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(d.uniqueId,"_normal.outputs:rgb>")),a.push(St(d,e,"normal",null,n,r))),null!==y&&(i.push("".concat(o,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(y.uniqueId,"_occlusion.outputs:").concat(b,">")),a.push(St(y,e,"occlusion",new t.Color3(M,M,M),n,r))),null!==m?(i.push("".concat(o,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(m.uniqueId,"_roughness.outputs:").concat(g,">")),a.push(St(m,e,"roughness",new t.Color3(x,x,x),n,r))):i.push("".concat(o,"float inputs:roughness = ").concat(x)),null!==_?(i.push("".concat(o,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(_.uniqueId,"_metallic.outputs:").concat(v,">")),a.push(St(_,e,"metallic",new t.Color3(T,T,T),n,r))):i.push("".concat(o,"float inputs:metallic = ").concat(T)),null!==w?(i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(w.uniqueId,"_opacity.outputs:r>")),i.push("".concat(o,"float inputs:opacityThreshold = 0.0001")),a.push(St(w,e,"opacity",null,n,r))):i.push("".concat(o,"float inputs:opacity = ").concat(e.alpha)),C&&(null!==E?(i.push("".concat(o,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(E.uniqueId,"_clearcoat.outputs:r>")),a.push(St(E,e,"clearcoat",new t.Color3(R,R,R),n,r))):i.push("".concat(o,"float inputs:clearcoat = ").concat(R)),null!==S?(i.push("".concat(o,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(S.uniqueId,"_clearcoatRoughness.outputs:g>")),a.push(St(S,e,"clearcoatRoughness",new t.Color3(I,I,I),n,r))):i.push("".concat(o,"float inputs:clearcoatRoughness = ").concat(I))),i.push("".concat(o,"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(i.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 Ft(e){var n,r;e.computeWorldMatrix(!0);for(var o=e.getWorldMatrix().clone(),i=e.getScene().useRightHandedSystem,a=null!==(r=null===(n=e.material)||void 0===n?void 0:n._getEffectiveOrientation(e))&&void 0!==r?r:e.sideOrientation,s=!i,u=e.parent;u;){if(R(u,i)&&null===u.parent){i||(o.multiplyToRef(u.getWorldMatrix().invert(),o),a=a===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),s=!1;break}u=u.parent}return o.determinant()<0&&t.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:o,windingOrder:a===t.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:s}}function Bt(e){return h(this,void 0,void 0,function(){var n,r,o,i,a;return f(this,function(s){switch(s.label){case 0:if(!(n=e.getInternalTexture())||1!==n.source)return[2,null];r=n._buffer,i=e.mimeType,s.label=1;case 1:return s.trys.push([1,12,,13]),r?[3,3]:[4,t.Tools.LoadFileAsync(n.url)];case 2:return o=s.sent(),i=t.GetMimeType(n.url)||i,[3,11];case 3:return ArrayBuffer.isView(r)?(o=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,11]):[3,4];case 4:return r instanceof ArrayBuffer?(o=r,[3,11]):[3,5];case 5:return r instanceof Blob?[4,r.arrayBuffer()]:[3,7];case 6:return o=s.sent(),i=r.type||i,[3,11];case 7:return"string"!=typeof r?[3,9]:[4,t.Tools.LoadFileAsync(r)];case 8:return o=s.sent(),i=t.GetMimeType(r)||i,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,t.Tools.LoadFileAsync(r.src)]:[3,11];case 10:o=s.sent(),i=t.GetMimeType(r.src)||i,s.label=11;case 11:return[3,13];case 12:return s.sent(),[2,null];case 13:return o&&!i&&n.url&&(a=n.url.match(/^data:([^;,]+)/),i=a?a[1]:t.GetMimeType(n.url)),o&&i?[2,{data:o,mimeType:i}]:[2,null]}})})}function Ot(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,l,h,p,d,m,g,x,_,v,T,y,b,M,w,A,C,R,E,I,S,V,F,B,O,N,P,U,k,L,W;return f(this,function(f){switch(f.label){case 0:return o=c({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},n),"undefined"!=typeof fflate?[3,2]:[4,t.Tools.LoadScriptAsync(o.fflateUrl)];case 1:f.sent(),f.label=2;case 2:for((i={})[o.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 ")}(o),s={},u=0,l=e.meshes;u<l.length;u++)0!==(h=l[u]).getTotalVertices()&&(d=(p=h).geometry,(m=p.material)&&d&&(!r||r(p))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(m.getClassName())?(g="geometries/Geometry_"+d.uniqueId+".usda",x=Ft(p),_=x.matrix,v=x.windingOrder,T=x.convertToRightHanded,g in i||(y=bt(d,o,v,T),i[g]=Mt(y)),m.uniqueId in s||(s[m.uniqueId]=m),a+=Ct(p,_)):t.Tools.Warn("USDZExportAsync does not support this material type: "+m.getClassName())));for(A in e.activeCamera&&o.exportCamera&&(a+=function(e,n){var r="Camera_"+e.uniqueId,o=wt(t.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===t.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(o,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(n.precision),", ").concat(e.maxZ.toPrecision(n.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(n.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(n.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var i=e.getEngine().getAspectRatio(e),a=n.cameraSensorWidth||35;return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(o,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(n.precision),", ").concat(e.maxZ.toPrecision(n.precision),")\n\t\t\tfloat focalLength = ").concat((a/(2*Math.tan(.5*e.fov))).toPrecision(n.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((a*i).toPrecision(n.precision),"\n\t\t\tfloat verticalAperture = ").concat((a/i).toPrecision(n.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,o)),a+="\n }\n }",a+=function(e,t,n){var r=[];for(var o in e){var i=e[o];r.push(Vt(i,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(s,b={},o),a+="\n }",i[o.modelFileName]=fflate.strToU8(a),w=[],M=b)w.push(A);C=0,f.label=3;case 3:return C<w.length?(A=w[C])in M?(E=b[R=A],I=E.texture,S=E.ext,[4,Bt(I)]):[3,8]:[3,9];case 4:return(V=f.sent())?(i["textures/Texture_".concat(R,".").concat(S)]=new Uint8Array(V.data),[3,8]):[3,5];case 5:return F=I.getSize(),[4,t.GetTextureDataAsync(I)];case 6:return B=f.sent(),[4,t.DumpTools.DumpDataAsync(F.width,F.height,B,"image/png",void 0,!1,!0)];case 7:O=f.sent(),i["textures/Texture_".concat(R,".").concat(S)]=new Uint8Array(O).slice(),f.label=8;case 8:return C++,[3,3];case 9:for(P in N=0,i)(U=i[P])&&(k=34+P.length,4!=(L=63&(N+=k))&&(W=new Uint8Array(64-L),i[P]=[U,{extra:{12345:W}}]),N=U.length);return[2,fflate.zipSync(i,{level:0})]}})})}var Nt={__proto__:null,USDZExportAsync:Ot},Pt=function(){function e(){}return e.Export=function(e,n,r){var o;if(void 0===n&&(n=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var i=n;n&&0!==n.length||(i=e.animations.map(function(e){return e.name}));for(var a=null,s=0,u=i;s<u.length;s++){var c=u[s],l=e.getAnimationRange(c);l&&(a=a?new t.AnimationRange("animation-range",Math.min(a.from,l.from),Math.max(a.to,l.to)):l)}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 h=r||1/((null===(o=e.animations[0])||void 0===o?void 0:o.framePerSecond)||30),f=this._BuildBoneHierarchy(e,i),p=0,d=0,m=f;d<m.length;d++){var g=m[d];g.positionKeys.length>0&&(p=Math.max(p,g.positionKeys.length)),g.rotationKeys.length>0&&(p=Math.max(p,g.rotationKeys.length))}0===p&&(p=Math.floor((a.to-a.from)/h)+1);var x="";return x+="HIERARCHY\n",x+=this._ExportHierarchy(f,0),x+="MOTION\n",x+="Frames: ".concat(p,"\n"),(x+="Frame Time: ".concat(h.toFixed(6),"\n"))+this._ExportMotionData(f,p,0,i)},e._BuildBoneHierarchy=function(e,t){for(var n,r,o=new Map,i=[],a=0,s=e.bones;a<s.length;a++){var u={bone:h=s[a],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,(n=u.positionKeys).push.apply(n,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(r=u.rotationKeys).push.apply(r,d.getKeys())))}if(h.getParent()){var m=o.get(h.getParent());m&&m.children.push(u)}else i.push(u)}return i},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,i=e;o<i.length;o++){var a=i[o],s=a.bone;if(this._IsEndSite(a)){n+="".concat(r,"End Site\n"),n+="".concat(r,"{\n");var u=this._GetBoneOffset(s);n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),n+="".concat(r,"}\n")}else{n+="".concat(0===t?"ROOT":"".concat(r,"JOINT")," ").concat(s.name,"\n"),n+="".concat(r,"{\n"),u=this._GetBoneOffset(s),n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];a.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),a.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),a.children.length>0&&(n+=this._ExportHierarchy(a.children,t+1)),n+="".concat(r,"}\n")}}return n},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return t.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",i=0;i<t;i++){var a=[];this._CollectFrameValues(e,i+n,a,r),o+=a.map(function(e){return e.toFixed(6)}).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,i=e;o<i.length;o++){var a=i[o];if(!this._IsEndSite(a)){if(a.hasPositionChannels){var s=this._GetPositionAtFrameIndex(a.positionKeys,t);n.push(s.x,s.y,s.z)}if(a.hasRotationChannels){var u=this._GetRotationAtFrameIndex(a.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}a.children.length>0&&this._CollectFrameValues(a.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,n){return 0===e.length?t.Vector3.Zero():e[Math.max(0,Math.min(n,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,n){return 0===e.length?t.Quaternion.Identity():e[Math.max(0,Math.min(n,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var n=new t.Matrix;e.toRotationMatrix(n);var r,o,i,a=n.m,s=Math.sqrt(a[0]*a[0]+a[1]*a[1]);return s>t.Epsilon?(r=Math.atan2(a[6],a[10]),o=Math.atan2(-a[2],s),i=Math.atan2(a[1],a[0])):(r=Math.atan2(-a[9],a[5]),o=Math.atan2(-a[2],s),i=0),new t.Vector3(t.Tools.ToDegrees(r),t.Tools.ToDegrees(o),t.Tools.ToDegrees(i))},e}(),Ut={__proto__:null,BVHExporter:Pt};function kt(e){return"string"==typeof(null==e?void 0:e.name)}var Lt=Symbol("__xml:meta$__"),Wt=Symbol("__xml:name$__");function Dt(e,t){var n,r=e.constructor;(null!==(n=r[Lt])&&void 0!==n?n:r[Lt]=[]).push(t)}function zt(e){return function(t){t[Wt]=e}}function Kt(){return function(e,t){return Dt(e,{kind:"none",prop:t,ignore:!0})}}function Gt(e){return function(t,n){return Dt(t,c({kind:"attr",prop:n},e))}}function qt(e){return function(t,n){return Dt(t,c({kind:"elem",prop:n},e))}}function Ht(e){var t,n;return null!==(n=null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Lt])&&void 0!==n?n:[]}function jt(e){var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Wt])||void 0}function Xt(e){return/^[A-Za-z_][A-Za-z0-9._-]*$/.test(e)}function Qt(e){if(kt(e))return e;var t=(null!=e?e:"").trim();if(!t)return{name:""};var n=t.indexOf(":");if(-1===n)return{name:t};if(-1!==t.indexOf(":",n+1))return{name:t};var r=t.slice(0,n),o=t.slice(n+1);return Xt(r)&&Xt(o)?{ns:r,name:o}:{name:t}}function Zt(e,t){return t?"".concat(t,":").concat(e):e}var Yt=Object.freeze({eps:1e-6,maxDecimalsCap:15,trimTrailingZeros:!0,allowScientific:!1,snapNearZero:!0}),Jt=Object.freeze({number:Yt});function $t(e){var t,n,r,o,i,a,s=null!==(t=null==e?void 0:e.eps)&&void 0!==t?t:Yt.eps;return{eps:s,maxDecimalsCap:null!==(n=null==e?void 0:e.maxDecimalsCap)&&void 0!==n?n:Yt.maxDecimalsCap,trimTrailingZeros:null!==(r=null==e?void 0:e.trimTrailingZeros)&&void 0!==r?r:Yt.trimTrailingZeros,fixedDecimals:null==e?void 0:e.fixedDecimals,allowScientific:null!==(o=null==e?void 0:e.allowScientific)&&void 0!==o?o:Yt.allowScientific,snapNearZero:null!==(i=null==e?void 0:e.snapNearZero)&&void 0!==i?i:Yt.snapNearZero,zeroThreshold:null!==(a=null==e?void 0:e.zeroThreshold)&&void 0!==a?a:s,perAttributeEps:null==e?void 0:e.perAttributeEps}}function en(e){return{number:$t(null==e?void 0:e.number)}}var tn=function(){function e(e){if(this.o=e,this._o=e.number,!Number.isFinite(this._o.eps)||this._o.eps<=0)throw new Error("opts.eps must be a finite, positive number")}return e.prototype.toString=function(e){var t,n,r,o;if(!Number.isFinite(e))throw new Error("Cannot format non-finite number: ".concat(e));var i,a=this._o,s=this._clampInt(null!==(t=a.maxDecimalsCap)&&void 0!==t?t:15,0,20),u=null===(n=a.trimTrailingZeros)||void 0===n||n,c=null===(r=a.snapNearZero)||void 0===r||r,l=null!==(o=a.zeroThreshold)&&void 0!==o?o:a.eps,h=1/a.eps,f=Math.round(e*h)/h;if(Object.is(f,-0)&&(f=0),c&&Math.abs(f)<=l&&(f=0),i=void 0!==a.fixedDecimals?this._clampInt(a.fixedDecimals,0,s):this._clampInt(Math.ceil(-Math.log10(a.eps)),0,s),a.allowScientific,0===i)return String(Math.trunc(f));var p=f.toFixed(i);if(u&&void 0===a.fixedDecimals&&(p=p.replace(/(\.\d*?[1-9])0+$/,"$1").replace(/\.0+$/,"").replace(/\.$/,"")),/[eE]/.test(p))throw new Error("Scientific notation not allowed in XML output: ".concat(p));return p},e.prototype._clampInt=function(e,t,n){return Number.isFinite(e)?(e=Math.trunc(e),Math.max(t,Math.min(n,e))):t},e}();function nn(e){return e instanceof Date}function rn(e){return"string"==typeof e}function on(e){return"number"==typeof e}function an(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||nn(e)}function sn(e){return"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||nn(e)}var un,cn=function(){function e(e,t){this._ns=new Map,this._prefixCount=0,this._builder=e,this._format=en(t),this._nFmt=new tn(this._format)}return e.prototype.withNamespace=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=0,r=e;n<r.length;n++){var o=r[n];this._assignNamespace(o)}return this},e.prototype.serialize=function(e,t){if(!(t=null!=t?t:jt(e)))throw new Error("can not find name for given object");var n=Qt(t);n.ns&&this._assignNamespace(n.ns,"xmlns"),this._gatherNamespaces(e,new WeakSet);for(var r=this._builder.ele(null,n.name),o=0,i=Array.from(this._ns.entries());o<i.length;o++){var a=i[o],s=a[0],u=a[1];r.att("xmlns",u,s)}this._writeObjectContent(r,e,(new WeakSet).add(e)),this._builder.end()},e.prototype._writeObject=function(e,t,n){if(!n.has(t))if(n.add(t),Array.isArray(t))for(var r=0,o=t;r<o.length;r++){var i=o[r];sn(i)||(rn(i)?this._builder.text(i):this._writeObject(e,i,n))}else{var a=jt(t);if(a){var s=Qt(a),u=this._getPrefix(s),c=Zt(s.name,u);e.ele(null,c),this._writeObjectContent(e,t,n),this._builder.end()}}},e.prototype._getPrefix=function(e){if(e.ns){var t=this._ns.get(e.ns.toLowerCase());if("xmlns"!==t)return t}},e.prototype._writeObjectContent=function(e,t,n){for(var r,o,i,a=null!==(r=Ht(t))&&void 0!==r?r:[],s=new Map,u=0,c=a;u<c.length;u++){var l=c[u],h=null!==(o=s.get(l.prop))&&void 0!==o?o:[];h.push(l),s.set(l.prop,h)}for(var f=Object.keys(t).sort(function(e,t){var n,r,o=(null!==(n=s.get(e))&&void 0!==n?n:[]).some(function(e){return"attr"===e.kind}),i=(null!==(r=s.get(t))&&void 0!==r?r:[]).some(function(e){return"attr"===e.kind});return o===i?0:o?-1:1}),p=0,d=f;p<d.length;p++){var m=d[p],g=t[m];if(null!=g){var x=s.get(m);if(x){var _=x.some(function(e){return!0===e.ignore||"none"===e.kind});if(_)continue;for(var v=0,T=x;v<T.length;v++){var y=null!==(i=(l=T[v]).name)&&void 0!==i?i:l.prop.toLowerCase();if(y&&"attr"===l.kind){var b=null;if(on(g)&&this._nFmt&&(b=this._nFmt.toString(g)),l.formatter&&(b=new l.formatter(this._format).toString(g)),b=null!=b?b:g.toString()){var M=Qt(y),w=this._getPrefix(M),A=Zt(M.name,w);e.att(null,A,b)}}}}else sn(g)||(rn(g)?this._builder.text(g):this._writeObject(e,g,n))}}},e.prototype._gatherNamespaces=function(e,t){var n,r;if(!t.has(e))if(t.add(e),Array.isArray(e))for(var o=0,i=e;o<i.length;o++){var a=i[o];an(a)||this._gatherNamespaces(a,t)}else{var s=jt(e);s&&this._assignNamespace(s);for(var u=null!==(n=Ht(e))&&void 0!==n?n:[],c=new Map,l=0,h=u;l<h.length;l++){var f=h[l],p=null!==(r=c.get(f.prop))&&void 0!==r?r:[];p.push(f),c.set(f.prop,p)}for(var d=[],m=0,g=Object.keys(e);m<g.length;m++){var x=g[m],_=e[x];if(null!=_){var v=c.get(x);if(v){var T=v.some(function(e){return!0===e.ignore||"none"===e.kind});if(T)continue;for(var y=0,b=v;y<b.length;y++)(f=b[y]).name&&this._assignNamespace(f.name)}d.push(_)}}for(var M=0,w=d;M<w.length;M++){var A=w[M];an(A)||this._gatherNamespaces(A,t)}}},e.prototype._assignNamespace=function(e,t){var n=Qt(e);if(null==n?void 0:n.ns){var r=n.ns.toLowerCase();this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r))}else"xmlns"===t&&(r=n.name.toLowerCase(),this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r)))},e.prototype._buildNsPrefix=function(e){var t,n=!1;do{t="ns".concat(this._prefixCount++);for(var r=0,o=Array.from(this._ns.values());r<o.length;r++)if(o[r]===t){n=!0;break}}while(n);return t},e}(),ln=function(){function e(){}return e.OpenTag="<",e.CloseTag=">",e.Slash="/",e.Question="?",e.Quote='"',e.Equal="=",e.Space=" ",e.Semicolon=":",e.Dec="<?xml",e.Xml="xml",e.Xmlns="xmlns",e.Xsi="xsi",e.VersionKeyword="version",e.EncodingKeyword="encoding",e.StandaloneKeyword="standalone",e}();!function(e){e[e.Declaration=0]="Declaration",e[e.Tag=1]="Tag",e[e.Attribute=2]="Attribute",e[e.Text=3]="Text"}(un||(un={}));var hn,fn,pn=function(){function e(e){this._ctxStack=[],this._d=0,this._w=e}return e.prototype.dec=function(e,t,n){return this._w.write(ln.Dec),this._writeAttStr(ln.VersionKeyword,e),t&&this._writeAttStr(ln.EncodingKeyword,t),void 0!==n&&this._writeAttStr(ln.StandaloneKeyword,n?"yes":"no"),this._w.write(ln.Question,ln.CloseTag),this},e.prototype.att=function(e,t,n){var r=this._peekContext();if(!r)throw new Error("att() without open element");if(r.closed)throw new Error("att() after start tag closed for <".concat(r.name,">"));if(this._isXmlnsDecl(e,t)){if(t===ln.Xmlns)r.defaultNs=n,this._registerNamespace(r,"",n),this._writeAttStr(ln.Xmlns,n);else if(e)this._registerNamespace(r,t,n),this._writeAttStr("".concat(e,":").concat(t),n);else{var o=t.slice(6);this._registerNamespace(r,o,n),this._writeAttStr(t,n)}return r.lastToken=un.Attribute,this}var i=t;if(e){var a=this._ensurePrefixDeclared(r,e);i="".concat(a,":").concat(t)}return r.lastToken=un.Attribute,this._writeAttStr(i,n),this},e.prototype.ele=function(e,t){var n,r=this._peekContext();r&&this._closeOpenTagIfNeeded(r);var o=t;if(e){var i=null!==(n=this._lookupPrefix(e))&&void 0!==n?n:e;o="".concat(i,":").concat(t)}return this._pushContext(o,++this._d),this._w.write(ln.OpenTag,o),this},e.prototype.text=function(e){var t=this._peekContext();if(!t)throw new Error("text() without open element");return this._closeOpenTagIfNeeded(t),t.lastToken=un.Text,this._w.write(this._escText(e)),this},e.prototype.end=function(){var e=this._popContext();return e&&(this._d--,e.closed?this._w.write(ln.OpenTag,ln.Slash,e.name,ln.CloseTag):this._w.write(ln.Slash,ln.CloseTag)),this},e.prototype._pushContext=function(t,n){var r=new e.Context(t,n);return this._ctxStack.push(r),r},e.prototype._popContext=function(){return this._ctxStack.pop()},e.prototype._peekContext=function(){return this._ctxStack[this._ctxStack.length-1]},Object.defineProperty(e.prototype,"_contextDepth",{get:function(){return this._ctxStack.length},enumerable:!1,configurable:!0}),e.prototype._writeAttStr=function(e,t){this._w.write(ln.Space,e,ln.Equal,ln.Quote,this._escAttr(t),ln.Quote)},e.prototype._lookupPrefix=function(e){var t,n=this._ctxStack.length-1;if(n>=0)do{var r=null===(t=this._ctxStack[n--].ns2prefix)||void 0===t?void 0:t.get(e);if(r)return r}while(n>=0)},e.prototype._escText=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")},e.prototype._escAttr=function(e){return this._escText(e).replace(/"/g,""").replace(/'/g,"'")},e.prototype._isXmlnsDecl=function(e,t){if(e)return e===ln.Xmlns;var n=t.length,r=ln.Xmlns.length;return n>=r&&t.startsWith(ln.Xmlns)&&(t.length==r||t[r]==ln.Semicolon)},e.prototype._registerNamespace=function(e,t,n){if(t===ln.Xml||t===ln.Xmlns)throw new Error("reserved prefix '".concat(t,"'"));var r=e.prefix2ns.get(t);if(r&&r!==n)throw new Error("prefix '".concat(t,"' already bound to a different namespace"));e.ns2prefix.get(n)||e.ns2prefix.set(n,t),e.prefix2ns.set(t,n)},e.prototype._allocPrefix=function(e){for(var t=1;;){var n="ns".concat(t++);if(!e.prefix2ns.has(n))return n}},e.prototype._ensurePrefixDeclared=function(e,t){var n=this._lookupPrefix(t);if(n)return n;if(e.closed)throw new Error("can not declare namespace after start tag closed for <".concat(e.name,">"));var r=this._allocPrefix(e);return this._writeAttStr("".concat(ln.Xmlns,":").concat(r),t),this._registerNamespace(e,r,t),r},e.prototype._closeOpenTagIfNeeded=function(e){e.closed||(this._w.write(ln.CloseTag),e.closed=!0)},e.Context=function(e,t){this.name="",this.closed=!1,this.lastToken=null,this.ns2prefix=new Map,this.prefix2ns=new Map,this.defaultNs=null,this.name=e,this.depth=t},e}(),dn=function(){function e(){this.count=0,this._chunks=[]}return e.prototype.write=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)return this;var n=e.join("");return this._chunks.push(n),this.count+=n.length,this},e.prototype.toString=function(){return this._chunks.join("")},e.prototype.clear=function(){this._chunks=[],this.count=0},e}(),mn=function(){function e(e,t){void 0===t&&(t={}),this._sink=e,this._opts=t,this.count=0,this._encoder=new TextEncoder,this._pending="",this._pendingChars=0}return e.prototype.write=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(0===t.length)return this;var r=t.join("");if(0===r.length)return this;this._pending+=r,this._pendingChars+=r.length;var o=null!==(e=this._opts.flushChars)&&void 0!==e?e:65536;return this._pendingChars>=o&&this.flush(),this},e.prototype.flush=function(){if(0===this._pendingChars)return this;var e=this._encoder.encode(this._pending);return this._sink.push(e),this.count+=e.length,this._pending="",this._pendingChars=0,this},e.prototype.finish=function(){this.flush(),this._sink.push(new Uint8Array(0),!0)},e.prototype.clear=function(){this._pending="",this._pendingChars=0,this.count=0},e}(),gn="http://schemas.microsoft.com/3dmanufacturing/core/2015/02",xn="http://schemas.microsoft.com/3dmanufacturing/trianglesets/2021/07";!function(e){e.micron="micron",e.millimeter="millimeter",e.centimeter="centimeter",e.inch="inch",e.foot="foot",e.meter="meter"}(hn||(hn={})),function(e){e.model="model",e.solidsupport="solidsupport",e.support="support",e.surface="surface",e.other="other"}(fn||(fn={}));var _n,vn="http://schemas.openxmlformats.org/package/2006/content-types",Tn="http://schemas.openxmlformats.org/package/2006/relationships";!function(e){e.Relationships="application/vnd.openxmlformats-package.relationships+xml",e.Model="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",e.Materials="application/vnd.ms-package.3dmanufacturing-material+xml",e.Colors="application/vnd.ms-package.3dmanufacturing-colors+xml",e.Texture="application/vnd.ms-package.3dmanufacturing-texture+xml",e.Texture2D="application/vnd.ms-package.3dmanufacturing-texture2d+xml",e.Production="application/vnd.ms-package.3dmanufacturing-production+xml",e.Slice="application/vnd.ms-package.3dmanufacturing-slice+xml",e.BeamLattice="application/vnd.ms-package.3dmanufacturing-beamlattice+xml",e.SecureContent="application/vnd.ms-package.3dmanufacturing-securecontent+xml",e.Png="image/png",e.Jpeg="image/jpeg",e.Tiff="image/tiff",e.Xml="application/xml"}(_n||(_n={}));var yn="_rels/",bn="3D/",Mn="3dmodel.model",wn=".rels",An="[Content_Types].xml",Cn=function(){function e(){}return e.IsKnown=function(t){return e.Known.has(t)},e.IsThreeDimModel=function(t){return t===e.ThreeDimModel},e.ThreeDimModel="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel",e.Thumbnail="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",e.PrintTicket="http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket",e.MustPreserve="http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve",e.Known=new Set([e.ThreeDimModel,e.Thumbnail,e.PrintTicket,e.MustPreserve]),e}(),Rn=function(){function e(){this.items=[]}return l([zt({ns:vn,name:"Types"})],e)}(),En=function(){function e(e,t){this.ext=e,this.ct=t}return l([Gt({name:{ns:vn,name:"Extension"}})],e.prototype,"ext",void 0),l([Gt({name:{ns:vn,name:"ContentType"}})],e.prototype,"ct",void 0),l([zt({ns:vn,name:"Default"})],e)}(),In=function(){function e(){this.items=[]}return l([zt({ns:Tn,name:"Relationships"})],e)}(),Sn=function(){function e(e,t,n){this.id=e,this.type=t,this.target=n}return l([Gt({name:"Id"})],e.prototype,"id",void 0),l([Gt({name:"Type"})],e.prototype,"type",void 0),l([Gt({name:"Target"})],e.prototype,"target",void 0),l([zt({ns:Tn,name:"Relationship"})],e)}(),Vn=function(e,t,n){this.contentTypes=e,this.relationships=t,this.model=n},Fn=function(){function e(e){this.values=e}return e.Zero=function(){return new e([0,0,0,0,0,0,0,0,0,0,0,0])},e.prototype.toString=function(){return this.values.join(" ")},e}(),Bn=function(){function e(e){this.o=e,this._f=new tn(e)}return e.prototype.toString=function(e){var t=this;return e.values.map(function(e){return t._f.toString(e)}).join(" ")},e}(),On=function(){function e(){this.unit=hn.millimeter}return e.KnownMeta=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate","Application"],l([Gt({name:"unit"})],e.prototype,"unit",void 0),l([Gt({name:"requiredextensions"})],e.prototype,"requiredextensions",void 0),l([Gt({name:"recommendedextensions"})],e.prototype,"recommendedextensions",void 0),l([zt({ns:gn,name:"model"})],e)}(),Nn=function(){function e(e,t,n,r){this.name=e,this.value=t,this.preserve=n,this.type=r}return l([Gt({name:"name"})],e.prototype,"name",void 0),l([Gt({name:"preserve"})],e.prototype,"preserve",void 0),l([Gt({name:"type"})],e.prototype,"type",void 0),l([zt({ns:gn,name:"meta"})],e)}(),Pn=function(){function e(){this.metadata=[]}return l([zt({ns:gn,name:"metadatagroup"})],e)}(),Un=function(){function e(){this.object=[]}return l([zt({ns:gn,name:"resources"})],e)}(),kn=function(){function e(e,t){void 0===t&&(t=fn.model),this.id=e,this.type=t}return l([Gt({name:"id"})],e.prototype,"id",void 0),l([Gt({name:"type"})],e.prototype,"type",void 0),l([Gt({name:"thumbnail"})],e.prototype,"thumbnail",void 0),l([Gt({name:"partnumber"})],e.prototype,"partnumber",void 0),l([Gt({name:"name"})],e.prototype,"name",void 0),l([Gt({name:"pid"})],e.prototype,"pid",void 0),l([Gt({name:"pindex"})],e.prototype,"pindex",void 0),l([zt({ns:gn,name:"object"})],e)}(),Ln=function(){function e(e,t){this.vertices=null!=e?e:new Wn,this.triangles=null!=t?t:new zn}return l([zt({ns:gn,name:"mesh"})],e)}(),Wn=function(){function e(){this.vertex=[]}return l([zt({ns:gn,name:"vertices"})],e)}(),Dn=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=0),void 0===n&&(n=0),this.x=e,this.y=t,this.z=n}return l([Gt({name:"x"})],e.prototype,"x",void 0),l([Gt({name:"y"})],e.prototype,"y",void 0),l([Gt({name:"z"})],e.prototype,"z",void 0),l([zt({ns:gn,name:"vertex"})],e)}(),zn=function(){function e(){this.triangle=[]}return l([zt({ns:gn,name:"triangles"})],e)}(),Kn=function(){function e(e,t,n){this.v1=e,this.v2=t,this.v3=n}return l([Gt({name:"v1"})],e.prototype,"v1",void 0),l([Gt({name:"v2"})],e.prototype,"v2",void 0),l([Gt({name:"v3"})],e.prototype,"v3",void 0),l([Gt({name:"p1"})],e.prototype,"p1",void 0),l([Gt({name:"p2"})],e.prototype,"p2",void 0),l([Gt({name:"p3"})],e.prototype,"p3",void 0),l([Gt({name:"pid"})],e.prototype,"pid",void 0),l([zt({ns:gn,name:"triangle"})],e)}(),Gn=function(){function e(){this.component=[]}return l([zt({ns:gn,name:"components"})],e)}(),qn=function(){function e(e,t){this.objectid=e,this.transform=t}return l([Gt({name:"objectid"})],e.prototype,"objectid",void 0),l([Gt({name:"transform",formatter:Bn})],e.prototype,"transform",void 0),l([zt({ns:gn,name:"component"})],e)}(),Hn=function(){function e(e){this.base=[],this.id=e}return l([Gt({name:"id"})],e.prototype,"id",void 0),l([zt({ns:gn,name:"basematerials"})],e)}(),jn=function(){function e(e,t){this.name=e,this.displaycolor=t}return l([Gt({name:"name"})],e.prototype,"name",void 0),l([Gt({name:"displaycolor"})],e.prototype,"displaycolor",void 0),l([zt({ns:gn,name:"base"})],e)}(),Xn=function(){function e(){this.item=[]}return l([zt({ns:gn,name:"build"})],e)}(),Qn=function(){function e(e,t,n){this.objectid=e,this.transform=t,this.partnumber=n}return l([Gt({name:"objectid"})],e.prototype,"objectid",void 0),l([Gt({name:"transform",formatter:Bn})],e.prototype,"transform",void 0),l([Gt({name:"partnumber"})],e.prototype,"partnumber",void 0),l([zt({ns:gn,name:"item"})],e)}(),Zn=function(){function e(e,t){this._object=new kn(e,t)}return e.prototype.withName=function(e){return this._object.name=e,this},e.prototype.withThumbnail=function(e){return this._object.thumbnail=e,this},e.prototype.withProperty=function(e,t){return void 0===t&&(t=0),this._object.pid=e,this._object.id=t,this},e.prototype.build=function(){return this._object},e.prototype.reset=function(e,t){this._object=new kn(e,t)},e}(),Yn=function(e){function t(t,n){void 0===n&&(n=fn.model);var r=e.call(this,t,n)||this;return r._object.content=new Gn,r}return u(t,e),t.prototype.withComponent=function(e,t){return this._object.content.component.push(new qn(e,t)),this},t}(Zn),Jn=function(e){function t(t){return e.call(this,t,fn.model)||this}return u(t,e),t.prototype.withPostProcessHandlers=function(e,t){return this._vh=e,this._th=t,this},t.prototype.withData=function(e){return this._object.content=this._buildMesh(e),this},t.prototype.withMaterial=function(e,t){return this._object.pid=e,this._object.pindex=t,this},t.prototype._buildMesh=function(e){var t=this._buildVertices(e.positions),n=this._buildTriangle(e.indices);return new Ln(t,n)},t.prototype._buildVertices=function(e){var t=new Wn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Dn(r,o,i);this._vh&&(a=this._vh(a)),t.vertex.push(a)}return t},t.prototype._buildTriangle=function(e){var t=new zn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Kn(r,o,i);this._th&&(a=this._th(a)),t.triangle.push(a)}return t},t}(Zn),$n=function(){function e(e){this._m=new Hn(e)}return e.prototype.withColor=function(e,t){var n;this._m.base=null!==(n=this._m.base)&&void 0!==n?n:[];var r=this._m.base.find(function(t){return t.name.toLowerCase()===e.toLowerCase()});return r?(r.displaycolor=this._rgbaToHex(t),this):(r=new jn(e,this._rgbaToHex(t)),this._m.base.push(r),this)},e.prototype.build=function(){return this._m},e.prototype._rgbaToHex=function(e){var t=function(e){return Math.round(Math.min(255,Math.max(0,255*Math.pow(e,1/2.2))))},n=t(e.r).toString(16).padStart(2,"0").toUpperCase(),r=t(e.g).toString(16).padStart(2,"0").toUpperCase(),o=t(e.b).toString(16).padStart(2,"0").toUpperCase();if("number"==typeof e.a){var i=Math.round(Math.min(255,Math.max(0,255*e.a))).toString(16).padStart(2,"0").toUpperCase();return"#".concat(n).concat(r).concat(o).concat(i)}return"#".concat(n).concat(r).concat(o)},e}(),er=function(){function e(){this._model=new On,this._objects=new Map}return e.prototype.withMetaData=function(e,t,n,r){return this._model.metadata||(this._model.metadata=new Array),this._model.metadata.push(new Nn(e,t,n,r)),this},e.prototype.withMaterial=function(e){var t,n;return e instanceof $n&&(e=e.build()),e&&(this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.basematerials=null!==(n=this._model.resources.basematerials)&&void 0!==n?n:[],this._model.resources.basematerials.push(e)),this},e.prototype.withMesh=function(e){var t;return e instanceof Jn&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.object.push(e),this},e.prototype.withComponents=function(e){var t;return e instanceof Yn&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.object.push(e),this},e.prototype.withBuild=function(e,t,n){var r,o;return this._model.build=null!==(r=this._model.build)&&void 0!==r?r:new Xn,null===(o=this._model.build.item)||void 0===o||o.push(new Qn(e,t,n)),this},e.prototype.withUnit=function(e){return this._model.unit=e,this},e.prototype.reset=function(){return this._model=new On,this._objects=new Map,this},e.prototype.build=function(){var e,t,n,r;if(!(null===(t=null===(e=this._model.resources)||void 0===e?void 0:e.object)||void 0===t?void 0:t.length))throw new Error("Invalid state: resources MUST be defined ");if(!(null===(r=null===(n=this._model.build)||void 0===n?void 0:n.item)||void 0===r?void 0:r.length))throw new Error("Invalid state: Build MUST be defined ");return this._model},e.KnownMetaSet=new Set(On.KnownMeta.map(function(e){return e.toLowerCase()})),e}(),tr=function(){function e(){}return e.prototype.withContentType=function(e){this._cts||(this._cts=new Rn);var t=this._cts.items;return t.some(function(t){return t.ext===e.ext&&t.ct===e.ct})||t.push(e),this},e.prototype.withRelationship=function(e){this._rs||(this._rs=new In);var t=this._rs.items;return t.some(function(t){return t.id===e.id})||t.push(e),this.withContentType(new En("rels",_n.Relationships)),this},e.prototype.withModel=function(e){return e instanceof er&&(e=e.build()),this._m=e,this.withContentType(new En("model",_n.Model)),this},e.prototype.build=function(){if(!this._m)throw new Error("Invalid state: you Must provide at least a model.");var e="".concat(bn).concat(Mn);if(!this._rs){var t="/".concat(e);this.withRelationship(new Sn("rel".concat(0),Cn.ThreeDimModel,t))}return new Vn(this._cts,this._rs,this._m)},e}(),nr=function(){function e(e){this._o=e}return Object.defineProperty(e.prototype,"options",{get:function(){return this._o},enumerable:!1,configurable:!0}),e.prototype.serializeAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u;return f(this,function(c){switch(c.label){case 0:return[4,this.ensureZipLibReadyAsync()];case 1:if(!(n=c.sent()))return[2];if(r=n.Zip,o=n.ZipDeflate,!r||!o)throw new Error("fflate Zip / ZipDeflate not available");return i=function(e){return{push:function(t,n){return e.push(t,n)}}},a=function(e,t,n){var r=new o(t,{level:6});e.add(r);var a=i(r),s=new mn(a),u=new pn(s).dec("1.0","UTF-8");new cn(u).serialize(n),s.finish()},(s=this.toDocument.apply(this,t))?(u=new r(e),a(u,An,s.contentTypes),a(u,"".concat(yn).concat(wn),s.relationships),a(u,"".concat(bn).concat(Mn),s.model),u.end(),[2]):[2]}})})},e.prototype.toDocument=function(){for(var e,t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o=(new er).withUnit(null!==(t=null===(e=this._o)||void 0===e?void 0:e.unit)&&void 0!==t?t:hn.millimeter);if(this.options.metadata)for(var i in this.options.metadata)o.withMetaData(i,this.options.metadata[i]);return(new tr).withModel(this.toModel.apply(this,p([o],n,!1))).build()},e}(),rr=function(){function e(){}return e.SerializeToMemoryAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return f(this,function(l){switch(l.label){case 0:return n=new Array,r=0,o=function(e,t,o){n.push(t),r+=t.length},[4,e.serializeAsync.apply(e,p([o],t,!1))];case 1:if(l.sent(),!r)return[2,void 0];for(i=new Uint8Array(r),a=0,s=0,u=n;s<u.length;s++)c=u[s],i.set(c,a),a+=c.length;return[2,i]}})})},e}(),or=function(){function e(){}return e.FFLATEUrl="https://unpkg.com/fflate@0.8.2",e}(),ir=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=Number.MIN_SAFE_INTEGER),void 0===n&&(n=1),this._from=e,this._to=t,this._step=n,this._i=e}return e.prototype.next=function(){if(this._i<this._to)throw new Error("ST_ResourceID out of bound");var e=this._i;return this._i+=this._step,e},e.prototype.reset=function(){return this._i=this._from,this},e}(),ar=function(e){function n(t){return void 0===t&&(t={}),e.call(this,c(c({},n.DefaultOptions),t))||this}return u(n,e),n.prototype.toModel=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];n=n.filter(function(e){return e instanceof t.Mesh||e instanceof t.InstancedMesh});for(var o=new ir,i=e,a=new Map,s=this.options.exportInstances?[]:null,u=0;u<n.length;u++){var c=n[u];if(c instanceof t.InstancedMesh)null==s||s.push(c);else{var l=c.name||"mesh".concat(u),h=c.getWorldMatrix(),f=this._handleBabylonTo3mfMatrixTransformToRef(h,Fn.Zero());if(void 0!==(A=c.subMeshes))for(var p=1==A.length,d=0;d<A.length;d++){var m=A[d],g=this._extractSubMesh(c,m);if(g){var x=p?"".concat(l):"".concat(l,"_").concat(d),_=new Jn(o.next()).withData(g).withName(x).build();i.withMesh(_),i.withBuild(_.id,f),a.set(m,_)}}}}if(s&&s.length)for(var v=this._groupBy(s,function(e){return e.sourceMesh}),T=0,y=Array.from(v.entries());T<y.length;T++){var b=y[T],M=b[0],w=b[1];if(w&&w.length)for(u=0;u<w.length;u++){h=w[u].getWorldMatrix();var A=M.subMeshes;for(d=0;d<A.length;d++){m=A[d];var C=a.get(m);C&&i.withBuild(C.id,this._handleBabylonTo3mfMatrixTransformToRef(h,Fn.Zero()))}}}return i.build()},n.prototype.ensureZipLibReadyAsync=function(){return h(this,void 0,void 0,function(){var e=this;return f(this,function(n){switch(n.label){case 0:return this._fflateReadyPromise?[4,this._fflateReadyPromise]:[3,2];case 1:case 3:return[2,n.sent()];case 2:return this._fflateReadyPromise=h(e,void 0,void 0,function(){var e;return f(this,function(n){switch(n.label){case 0:return(e=globalThis).fflate?[3,2]:[4,t.Tools.LoadScriptAsync(or.FFLATEUrl)];case 1:n.sent(),n.label=2;case 2:return[2,e.fflate]}})}),[4,this._fflateReadyPromise]}})})},n.prototype._extractSubMesh=function(e,t){var r=e.getIndices();if(r){var o=e.getVerticesData(n._PositionKind);if(o){if(0==t.indexStart&&t.indexCount==r.length)return{positions:o,indices:r};for(var i=t.indexStart,a=new Map,s=[],u=new Uint32Array(t.indexCount),c=0;c<t.indexCount;c++){var l=r[i+c],h=a.get(l);if(void 0===h){h=a.size,a.set(l,h);var f=3*l;s.push(o[f],o[f+1],o[f+2])}u[c]=h}return{positions:new Float32Array(s),indices:u}}}},n.prototype._groupBy=function(e,t){for(var n=new Map,r=0,o=e;r<o.length;r++){var i=o[r],a=t(i),s=n.get(a);s?s.push(i):n.set(a,[i])}return n},n.prototype._handleBabylonTo3mfMatrixTransformToRef=function(e,r){var o=e.multiplyToRef(n._R_BJS_TO_3MF,t.Matrix.Zero()).m;return r.values=[o[0],o[1],o[2],o[4],o[5],o[6],o[8],o[9],o[10],o[12],o[13],o[14]],r},n.DefaultOptions={unit:hn.meter,exportInstances:!1},n._PositionKind="position",n._R_BJS_TO_3MF=t.Matrix.RotationX(Math.PI/2).multiply(t.Matrix.Scaling(1,-1,1)),n}(nr),sr={__proto__:null,AbstractThreeMfSerializer:nr,ContentTypeFileName:An,DefaultXmlSerializerFormatOptions:Jt,DefaultXmlSerializerNumberOptions:Yt,GetXmlFieldMeta:Ht,GetXmlName:jt,IsQualifiedName:kt,Known3mfRelationshipTypes:Cn,get KnownI3mfContentType(){return _n},Matrix3d:Fn,MatrixFormatter:Bn,ModelFileName:Mn,NumberFormatter:tn,Object3dDirName:bn,OpenXmlContentTypesNamespace:vn,OpenXmlRelationshipsNamespace:Tn,RelationshipDirName:yn,RelationshipFileName:wn,ResolveFormatOptions:en,ResolveNumberOptions:$t,get ST_ObjectType(){return fn},get ST_Unit(){return hn},StringXmlWriter:dn,ThreeDimModelNamespace:gn,ThreeMf:rr,ThreeMfBase:jn,ThreeMfBaseMaterials:Hn,ThreeMfBuild:Xn,ThreeMfComponent:qn,ThreeMfComponents:Gn,ThreeMfComponentsBuilder:Yn,ThreeMfContentType:En,ThreeMfContentTypes:Rn,ThreeMfDocument:Vn,ThreeMfDocumentBuilder:tr,ThreeMfItem:Qn,ThreeMfMaterialBuilder:$n,ThreeMfMesh:Ln,ThreeMfMeshBuilder:Jn,ThreeMfMeta:Nn,ThreeMfMetadataGroup:Pn,ThreeMfModel:On,ThreeMfModelBuilder:er,ThreeMfObject:kn,ThreeMfObjectBuilder:Zn,ThreeMfRelationship:Sn,ThreeMfRelationships:In,ThreeMfResources:Un,ThreeMfSerializer:ar,ThreeMfSerializerGlobalConfiguration:or,ThreeMfTriangle:Kn,ThreeMfTriangles:zn,ThreeMfVertex:Dn,ThreeMfVertices:Wn,ToQualifiedString:Zt,get TokenType(){return un},TriangleSetsNamespace:xn,Utf8XmlWriterToBytes:mn,XmlAttr:Gt,XmlBuilder:pn,XmlElem:qt,XmlIgnore:Kt,XmlName:zt,XmlNameToParts:Qt,XmlSerializer:cn},ur="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==ur)for(var cr in Ut)ur.BABYLON[cr]=Ut[cr];var lr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==lr){lr.BABYLON=lr.BABYLON||{};var hr=lr.BABYLON;hr.GLTF2=hr.GLTF2||{},hr.GLTF2.Exporter=hr.GLTF2.Exporter||{},hr.GLTF2.Exporter.Extensions=hr.GLTF2.Exporter.Extensions||{};var fr=[];for(var pr in o)hr[pr]=o[pr],fr.push(pr);for(var pr in a)hr[pr]=a[pr],fr.push(pr);for(var pr in te)hr[pr]=te[pr],fr.push(pr);for(var pr in gt)hr.GLTF2.Exporter.Extensions[pr]=gt[pr],fr.push(pr);for(var pr in xt)fr.indexOf(pr)>-1||(hr.GLTF2.Exporter[pr]=xt[pr])}var dr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==dr)for(var mr in r)dr.BABYLON[mr]=r[mr];var gr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==gr)for(var xr in vt)gr.BABYLON[xr]=vt[xr];var _r="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==_r)for(var vr in Nt)_r.BABYLON[vr]=Nt[vr];var Tr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Tr){var yr=[];for(var br in sr)yr.indexOf(br)>-1||(Tr.BABYLON[br]=sr[br],yr.push(br))}var Mr={__proto__:null,AbstractThreeMfSerializer:nr,BVHExporter:Pt,ContentTypeFileName:An,DefaultXmlSerializerFormatOptions:Jt,DefaultXmlSerializerNumberOptions:Yt,EXT_lights_area:xe,EXT_mesh_gpu_instancing:oe,EXT_texture_avif:mt,EXT_texture_webp:pt,GLTF2Export:ee,GLTFData:i,GetXmlFieldMeta:Ht,GetXmlName:jt,IsQualifiedName:kt,KHR_draco_mesh_compression:se,KHR_lights_punctual:fe,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:we,KHR_materials_coat:Se,KHR_materials_diffuse_roughness:it,KHR_materials_diffuse_transmission:Be,KHR_materials_dispersion:Ne,KHR_materials_emissive_strength:Ue,KHR_materials_fuzz:je,KHR_materials_ior:Le,KHR_materials_iridescence:De,KHR_materials_openpbr:st,KHR_materials_sheen:Ke,KHR_materials_specular:Qe,KHR_materials_transmission:Ye,KHR_materials_unlit:$e,KHR_materials_volume:tt,KHR_materials_volume_scatter:rt,KHR_texture_basisu:ht,KHR_texture_transform:ct,Known3mfRelationshipTypes:Cn,get KnownI3mfContentType(){return _n},Matrix3d:Fn,MatrixFormatter:Bn,ModelFileName:Mn,NumberFormatter:tn,OBJExport:n,Object3dDirName:bn,OpenXmlContentTypesNamespace:vn,OpenXmlRelationshipsNamespace:Tn,RelationshipDirName:yn,RelationshipFileName:wn,ResolveFormatOptions:en,ResolveNumberOptions:$t,STLExport:_t,get ST_ObjectType(){return fn},get ST_Unit(){return hn},StringXmlWriter:dn,ThreeDimModelNamespace:gn,ThreeMf:rr,ThreeMfBase:jn,ThreeMfBaseMaterials:Hn,ThreeMfBuild:Xn,ThreeMfComponent:qn,ThreeMfComponents:Gn,ThreeMfComponentsBuilder:Yn,ThreeMfContentType:En,ThreeMfContentTypes:Rn,ThreeMfDocument:Vn,ThreeMfDocumentBuilder:tr,ThreeMfItem:Qn,ThreeMfMaterialBuilder:$n,ThreeMfMesh:Ln,ThreeMfMeshBuilder:Jn,ThreeMfMeta:Nn,ThreeMfMetadataGroup:Pn,ThreeMfModel:On,ThreeMfModelBuilder:er,ThreeMfObject:kn,ThreeMfObjectBuilder:Zn,ThreeMfRelationship:Sn,ThreeMfRelationships:In,ThreeMfResources:Un,ThreeMfSerializer:ar,ThreeMfSerializerGlobalConfiguration:or,ThreeMfTriangle:Kn,ThreeMfTriangles:zn,ThreeMfVertex:Dn,ThreeMfVertices:Wn,ToQualifiedString:Zt,get TokenType(){return un},TriangleSetsNamespace:xn,USDZExportAsync:Ot,Utf8XmlWriterToBytes:mn,XmlAttr:Gt,XmlBuilder:pn,XmlElem:qt,XmlIgnore:Kt,XmlName:zt,XmlNameToParts:Qt,XmlSerializer:cn,_ConvertToGLTFPBRMetallicRoughness:y,_SolveMetallic:T,__IGLTFExporterExtension:0};e.default=Mr,e.serializers=Mr,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";var n=function(){function e(){}return e.OBJ=function(e,n,r,o){var i=[],a=1,s=1;n&&(r||(r="mat"),i.push("mtllib "+r+".mtl"));for(var u=0;u<e.length;u++){var c=e[u],l=c.name||"mesh".concat(u,"}");i.push("o ".concat(l));var h=null;if(o){var p=c.computeWorldMatrix(!0);h=new t.Matrix,p.invertToRef(h),c.bakeTransformIntoVertices(p)}if(n){var f=c.material;f&&i.push("usemtl "+f.id)}var d=c.geometry;if(d){var m=d.getVerticesData("position"),g=d.getVerticesData("normal"),x=d.getVerticesData("uv"),_=d.getIndices(),v=0,T=0;if(m&&_){for(var y=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<m.length;b+=3)i.push("v "+m[b]*y+" "+m[b+1]+" "+m[b+2]),v++;if(null!=g)for(b=0;b<g.length;b+=3)i.push("vn "+g[b]*y+" "+g[b+1]+" "+g[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)i.push("vt "+x[b]+" "+x[b+1]),T++;var M=["","",""],w=(c.material||c.getScene().defaultMaterial)._getEffectiveOrientation(c)===t.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=w[0],C=w[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+a),String(_[b+A]+a),String(_[b+C]+a)],E=[String(_[b]+s),String(_[b+A]+s),String(_[b+C]+s)],I=R,S=null!=x?E:M,V=null!=g?R:M;i.push("f "+I[0]+"/"+S[0]+"/"+V[0]+" "+I[1]+"/"+S[1]+"/"+V[1]+" "+I[2]+"/"+S[2]+"/"+V[2])}o&&h&&c.bakeTransformIntoVertices(h),a+=v,s+=T}else t.Tools.Warn("There are no position vertices or indices on the mesh!")}else t.Tools.Warn("No geometry is present on the mesh")}return i.join("\n")},e.MTL=function(e){var t=[],n=e.material;return t.push("newmtl mat1"),t.push(" Ns "+n.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+n.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+n.ambientColor.r.toFixed(4)+" "+n.ambientColor.g.toFixed(4)+" "+n.ambientColor.b.toFixed(4)),t.push(" Kd "+n.diffuseColor.r.toFixed(4)+" "+n.diffuseColor.g.toFixed(4)+" "+n.diffuseColor.b.toFixed(4)),t.push(" Ks "+n.specularColor.r.toFixed(4)+" "+n.specularColor.g.toFixed(4)+" "+n.specularColor.b.toFixed(4)),t.push(" Ke "+n.emissiveColor.r.toFixed(4)+" "+n.emissiveColor.g.toFixed(4)+" "+n.emissiveColor.b.toFixed(4)),n.ambientTexture&&t.push(" map_Ka "+n.ambientTexture.name),n.diffuseTexture&&t.push(" map_Kd "+n.diffuseTexture.name),n.specularTexture&&t.push(" map_Ks "+n.specularTexture.name),n.bumpTexture&&t.push(" map_bump -imfchan z "+n.bumpTexture.name),n.opacityTexture&&t.push(" map_d "+n.opacityTexture.name),t.join("\n")},e}(),r={__proto__:null,OBJExport:n},o={__proto__:null,__IGLTFExporterExtension:0},i=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 n=this.files[e],r=new Blob([n],{type:t.GetMimeType(e)});t.Tools.Download(r,e)}},e}(),a={__proto__:null,GLTFData:i},s=function(e,t){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},s(e,t)};function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var c=function(){return c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};function l(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function h(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}u((r=r.apply(e,t||[])).next())})}function p(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function f(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var d=1e-6,m=new t.Color3(.04,.04,.04),g=t.Color3.White(),x=t.Color3.BlackReadOnly;function _(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function v(e){return h(this,void 0,void 0,function(){var n,r,o,i,a,s;return p(this,function(u){switch(u.label){case 0:if(!(n=e.getInternalTexture())||1!==n.source)return[2,null];if(n.invertY&&!((null===(s=e.getScene())||void 0===s?void 0:s.getEngine())instanceof t.NullEngine))return[2,null];r=n._buffer,i=e.mimeType,u.label=1;case 1:return u.trys.push([1,12,,13]),r?[3,3]:[4,t.Tools.LoadFileAsync(n.url)];case 2:return o=u.sent(),i=t.GetMimeType(n.url)||i,[3,11];case 3:return ArrayBuffer.isView(r)?(o=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,11]):[3,4];case 4:return r instanceof ArrayBuffer?(o=r,[3,11]):[3,5];case 5:return r instanceof Blob?[4,r.arrayBuffer()]:[3,7];case 6:return o=u.sent(),i=r.type||i,[3,11];case 7:return"string"!=typeof r?[3,9]:[4,t.Tools.LoadFileAsync(r)];case 8:return o=u.sent(),i=t.GetMimeType(r)||i,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,t.Tools.LoadFileAsync(r.src)]:[3,11];case 10:o=u.sent(),i=t.GetMimeType(r.src)||i,u.label=11;case 11:return[3,13];case 12:return u.sent(),[2,null];case 13:return o&&!i&&n.url&&(a=n.url.match(/^data:([^;,]+)/),i=a?a[1]:t.GetMimeType(n.url)),o&&_(i)?[2,new Blob([o],{type:i})]:[2,null]}})})}function T(e,n,r){if(n<m.r)return 0;var o=m.r,i=e*r/(1-m.r)+n-2*m.r,a=i*i-4*o*(m.r-n);return t.Scalar.Clamp((-i+Math.sqrt(a))/(2*o),0,1)}function y(e){var n=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,o=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(o);return{baseColorFactor:[n.r,n.g,n.b,r],metallicFactor:0,roughnessFactor:i}}function b(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function M(e,n,r){for(var o=new Uint8Array(e*n*4),i=0;i<o.length;i+=4)o[i]=o[i+1]=o[i+2]=o[i+3]=255;return t.RawTexture.CreateRGBATexture(o,e,n,r)}function w(e){if(e instanceof Uint8Array){for(var t=e.length,n=new Float32Array(e.length),r=0;r<t;++r)n[r]=e[r]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var A=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,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l;return p(this,function(h){switch(h.label){case 0:return r=y(e),o={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||t.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),o.doubleSided=!0),n?(i=[],(a=e.diffuseTexture)&&i.push(this.exportTextureAsync(a).then(function(e){e&&(r.baseColorTexture=e)})),(s=e.bumpTexture)&&i.push(this.exportTextureAsync(s).then(function(e){e&&(o.normalTexture=e,1!==s.level&&(o.normalTexture.scale=s.level))})),(u=e.emissiveTexture)&&(o.emissiveFactor=[1,1,1],i.push(this.exportTextureAsync(u).then(function(e){e&&(o.emissiveTexture=e)}))),(c=e.ambientTexture)&&i.push(this.exportTextureAsync(c).then(function(e){if(e){var t={index:e.index};o.occlusionTexture=t}})),i.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(i)]):[3,2]):[3,2];case 1:h.sent(),h.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===t.Constants.ALPHA_COMBINE?o.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(x,d)&&(o.emissiveFactor=e.emissiveColor.asArray()),o.pbrMetallicRoughness=r,b(o,e),[4,this._finishMaterialAsync(o,e)];case 3:return h.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}})})},e.prototype._finishMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a;return p(this,function(s){switch(s.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(n=s.sent(),r=[],o=0,i=n;o<i.length;o++)a=i[o],r.push(this.exportTextureAsync(a));return[4,Promise.all(r)];case 2:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return s.sent(),[2]}})})},e.prototype._resizeTexturesToSameDimensions=function(e,n,r){var o,i,a=e?e.getSize():{width:0,height:0},s=n?n.getSize():{width:0,height:0};return a.width<s.width?(o=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):M(s.width,s.height,r),i=n):a.width>s.width?(i=n&&n instanceof t.Texture?t.TextureTools.CreateResizedCopy(n,a.width,a.height,!0):M(a.width,a.height,r),o=e):(o=e,i=n),{texture1:o,texture2:i}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,c,l,h,f,m,x,_,v,T,y,b,M,A,C,R,E,I,S,V,F,B,O,N,P,U,k;return p(this,function(p){switch(p.label){case 0:return o=new Array,e||n?[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,p.sent()];case 2:return(i=e?e.getScene():n?n.getScene():null)?(a=this._resizeTexturesToSameDimensions(e,n,i),s=null===(k=a.texture1)||void 0===k?void 0:k.getSize(),u=void 0,c=void 0,l=s.width,h=s.height,[4,a.texture1.readPixels()]):[3,12];case 3:return f=p.sent(),[4,a.texture2.readPixels()];case 4:return m=p.sent(),f?(u=w(f),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return m?(c=w(m),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(x=c.byteLength,_=new Uint8Array(x),v=new Uint8Array(x),T=new t.Color3(0,0,0),y=0,b=0,B=0;B<h;++B)for(O=0;O<l;++O)M=4*(l*B+O),A=new t.Color3(u[M],u[M+1],u[M+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),C=new t.Color3(c[M],c[M+1],c[M+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.specularColor),R=c[M+3]*r.glossiness,E={diffuseColor:A,specularColor:C,glossiness:R},I=this._convertSpecularGlossinessToMetallicRoughness(E),T.r=Math.max(T.r,I.baseColor.r),T.g=Math.max(T.g,I.baseColor.g),T.b=Math.max(T.b,I.baseColor.b),y=Math.max(y,I.metallic),b=Math.max(b,I.roughness),v[M]=255*I.baseColor.r,v[M+1]=255*I.baseColor.g,v[M+2]=255*I.baseColor.b,v[M+3]=a.texture1.hasAlpha?255*u[M+3]:255,_[M]=0,_[M+1]=255*I.roughness,_[M+2]=255*I.metallic,_[M+3]=255;for(S={baseColor:T,metallic:y,roughness:b},V=!1,F=!1,B=0;B<h;++B)for(O=0;O<l;++O)v[N=4*(l*B+O)]/=S.baseColor.r>d?S.baseColor.r:1,v[N+1]/=S.baseColor.g>d?S.baseColor.g:1,v[N+2]/=S.baseColor.b>d?S.baseColor.b:1,P=t.Color3.FromInts(v[N],v[N+1],v[N+2]),U=P.toGammaSpace(i.getEngine().useExactSrgbConversions),v[N]=255*U.r,v[N+1]=255*U.g,v[N+2]=255*U.b,U.equalsWithEpsilon(g,d)||(F=!0),_[N+1]/=S.roughness>d?S.roughness:1,_[N+2]/=S.metallic>d?S.metallic:1,t.Color3.FromInts(255,_[N+1],_[N+2]).equalsWithEpsilon(g,d)||(V=!0);return V&&o.push(t.EncodeImageAsync(_,l,h).then(function(e){S.metallicRoughnessTextureData=e})),F&&o.push(t.EncodeImageAsync(v,l,h).then(function(e){S.baseColorTextureData=e})),[4,Promise.all(o).then(function(){return S})];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}})})},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var n=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),o=1-this._getMaxComponent(e.specularColor),i=T(n,r,o),a=e.diffuseColor.scale(o/(1-m.r)/Math.max(1-i,d)),s=e.specularColor.subtract(m.scale(1-i)).scale(1/Math.max(i,d)),u=t.Color3.Lerp(a,s,i*i);return{baseColor:u=u.clampToRef(0,1,u),metallic:i,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,n,r,o,i,a,s,u,c){return h(this,void 0,void 0,function(){var l,f,d,m,g,x,_,v,T,y=this;return p(this,function(b){switch(b.label){case 0:return l=[],f={baseColor:e,metallic:n,roughness:r},c&&(s instanceof t.OpenPBRMaterial?(s.geometryOpacityTexture?(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,m=s.geometryOpacityTexture&&s.geometryOpacityTexture.getInternalTexture()?s.geometryOpacityTexture.getInternalTexture().uniqueId:0,g=Number("".concat(d).concat(m)),(T=this._textureMap.get(g))?u.baseColorTexture=T:l.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(1),o?t.CreateTextureInput(o,2):t.CreateConstantInput(1),t.CreateTextureInput(s.geometryOpacityTexture,0)),s.getScene()).then(function(e){return h(y,void 0,void 0,function(){var t;return p(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,g)];case 1:return(t=n.sent())&&(u.baseColorTexture=t),[2]}})})}))):o&&l.push(this.exportTextureAsync(o).then(function(e){e&&(u.baseColorTexture=e)})),s._useMetallicFromMetallicTextureBlue&&i?l.push(this.exportTextureAsync(i).then(function(e){e&&(u.metallicRoughnessTexture=e)})):(a||i)&&(x=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,_=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,v=Number("".concat(x).concat(_)),(T=this._textureMap.get(v))?u.metallicRoughnessTexture=T:l.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(s.ambientOcclusionTexture?t.CreateTextureInput(s.ambientOcclusionTexture,0):t.CreateConstantInput(1),a?t.CreateTextureInput(a,0):t.CreateConstantInput(1),i?t.CreateTextureInput(i,0):t.CreateConstantInput(1)),s.getScene()).then(function(e){return h(y,void 0,void 0,function(){var t;return p(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,v)];case 1:return(t=n.sent())&&(u.metallicRoughnessTexture=t),[2]}})})})))):(o&&l.push(this.exportTextureAsync(o).then(function(e){e&&(u.baseColorTexture=e)})),i&&l.push(this.exportTextureAsync(i).then(function(e){e&&(u.metallicRoughnessTexture=e)})))),l.length>0?(this._exporter._materialNeedsUVsSet.add(s),[4,Promise.all(l)]):[3,2];case 1:b.sent(),b.label=2;case 2:return[2,f]}})})},e.prototype._getTextureSampler=function(e){var n={};if(!(e&&e instanceof t.Texture))return n;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(n.wrapS=r);var o=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==o&&(n.wrapT=o),e.samplingMode){case t.Texture.LINEAR_LINEAR:n.magFilter=9729,n.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:n.magFilter=9729,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:n.magFilter=9728,n.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:n.magFilter=9728,n.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:n.magFilter=9728,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:n.magFilter=9728,n.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:n.magFilter=9729,n.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:n.magFilter=9729,n.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:n.magFilter=9728,n.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:n.magFilter=9729,n.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:n.magFilter=9729,n.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:n.magFilter=9728,n.minFilter=9984}return n},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case t.Texture.WRAP_ADDRESSMODE:return 10497;case t.Texture.CLAMP_ADDRESSMODE:return 33071;case t.Texture.MIRROR_ADDRESSMODE:return 33648;default:return t.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l;return p(this,function(h){switch(h.label){case 0:return r={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,i=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!i||a?[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||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),s=this._exportTextureSampler(o||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,i,r)]):[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,s,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,s,null==i?void 0:i.coordinatesIndex),h.label=7;case 7:return[2,u];case 8:return[2,this._convertSpecularGlossinessToMetallicRoughness(r)]}})})},e.prototype.exportPBRMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return p(this,function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(i=e._albedoColor,a=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,a])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,n,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t)];case 3:u=l.sent(),l.label=4;case 4:return s=u,[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,r,n,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(r,e)];case 6:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}})})},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a,s,u,c,l,f=this;return p(this,function(m){switch(m.label){case 0:return b(r,n),e.baseColor.equalsWithEpsilon(g,d)&&t.Scalar.WithinEpsilon(n.alpha,1,d)||(o.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,n.alpha]),null!=e.metallic&&1!==e.metallic&&(o.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(o.roughnessFactor=e.roughness),null==n.backFaceCulling||n.backFaceCulling||(n._twoSidedLighting||t.Tools.Warn(n.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),i?(a=[],(s=n instanceof t.PBRBaseMaterial?n._bumpTexture:n.geometryNormalTexture)&&a.push(this.exportTextureAsync(s).then(function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))})),(u=n instanceof t.PBRBaseMaterial?n._ambientTexture:n.ambientOcclusionTexture)&&a.push(new Promise(function(e){return h(f,void 0,void 0,function(){var r,i,a,s;return p(this,function(c){switch(c.label){case 0:return n instanceof t.OpenPBRMaterial&&o.metallicRoughnessTexture?(r=this._exportTextureSampler(u),i=this._exporter._textures[o.metallicRoughnessTexture.index].source,a=this._exportTextureInfo(i,r,u.coordinatesIndex),this._textureMap.set(u.uniqueId,a),this._exporter._extensionsPostExportTextures("exporter",a,u),[2,e(a)]):[3,1];case 1:return s=e,[4,this.exportTextureAsync(u)];case 2:return[2,s.apply(void 0,[c.sent()])]}})})}).then(function(e){return h(f,void 0,void 0,function(){var o;return p(this,function(i){return e&&(o={index:e.index,texCoord:e.texCoord,extensions:e.extensions},r.occlusionTexture=o,n instanceof t.PBRBaseMaterial?o.strength=n._ambientTextureStrength:o.strength=n.ambientOcclusionTexture.level),[2]})})})),(c=n instanceof t.PBRBaseMaterial?n._emissiveTexture:n.emissionColorTexture)&&a.push(this.exportTextureAsync(c).then(function(e){e&&(r.emissiveTexture=e)})),a.length>0?(this._exporter._materialNeedsUVsSet.add(n),[4,Promise.all(a)]):[3,2]):[3,2];case 1:m.sent(),m.label=2;case 2:return(l=n instanceof t.PBRBaseMaterial?n._emissiveColor:n.emissionColor).equalsWithEpsilon(x,d)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=o,[2]}})})},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a,s;return p(this,function(u){switch(u.label){case 0:return n={},r={name:e.name},o=e.baseColor,i=e.geometryOpacity,o&&(n.baseColorFactor=[o.r,o.g,o.b,i]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t)];case 1:return a=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(a,e,r,n,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(r,e)];case 3:return u.sent(),(s=this._exporter._materials).push(r),[2,s.length-1]}})})},e.prototype.exportTextureAsync=function(e){return h(this,arguments,void 0,function(e,t){var n,r,o;return void 0===t&&(t=null),p(this,function(i){switch(i.label){case 0:return(n=this._textureMap.get(null!=t?t:e.uniqueId))?[2,n]:(r=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=i.sent(),n=this._exportTextureInfo(o,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,n),this._exporter._extensionsPostExportTextures("exporter",n,e),[2,n]}})})},e.prototype._exportTextureImageAsync=function(e){return h(this,void 0,void 0,function(){var n,r,o,i,a,s=this;return p(this,function(u){switch(u.label){case 0:return n=null!==(a=e.mimeType)&&void 0!==a?a:"none",r=this._internalTextureToImage,o=e.getInternalTexture().uniqueId,r[o]=r[o]||{},void 0===(i=r[o][n])&&(i=h(s,void 0,void 0,function(){var r,o,i,a,s;return p(this,function(u){switch(u.label){case 0:return[4,v(e)];case 1:return!(r=u.sent())||"none"!==n&&r.type!==n?[3,3]:[4,this._exportImageAsync(e.name,r)];case 2:case 6:return[2,u.sent()];case 3:return o="image/png","none"!==n&&(_(n)?o=n:(o="image/png",t.Tools.Warn("Unsupported media type: ".concat(n,". Exporting texture as PNG.")))),i=e.getSize(),[4,t.GetTextureDataAsync(e)];case 4:return a=u.sent(),[4,t.EncodeImageAsync(a,i.width,i.height,o)];case 5:return s=u.sent(),[4,this._exportImageAsync(e.name,s)]}})}),r[o][n]=i),[4,i];case 1:return[2,u.sent()]}})})},e.prototype._exportImageAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c;return p(this,function(l){switch(l.label){case 0:return r=this._exporter._images,this._exporter._shouldUseGlb?(o={name:e,mimeType:n.type,bufferView:void 0},[4,n.arrayBuffer()]):[3,2];case 1:return i=l.sent(),a=this._exporter._bufferManager.createBufferView(new Uint8Array(i)),this._exporter._bufferManager.setBufferView(o,a),[3,3];case 2:s=e.replace(/\.\/|\/|\.\\|\\/g,"_"),u=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"}}(n.type),c=s+u,r.some(function(e){return e.uri===c})&&(c="".concat(s,"_").concat(t.Tools.RandomId()).concat(u)),o={name:e,uri:c},this._exporter._imageData[c]=n,l.label=3;case 3:return r.push(o),[2,r.length-1]}})})},e.prototype._exportTextureInfo=function(e,t,n){var r=this._exporter._textures,o=r.findIndex(function(n){return n.sampler==t&&n.source===e});-1===o&&(o=r.length,r.push({source:e,sampler:t}));var i={index:o};return n&&(i.texCoord=n),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),n=this._exporter._samplers,r=n.findIndex(function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT});return-1!==r?r:(n.push(t),n.length-1)},e}(),C=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function R(e,n){if(!(e instanceof t.TransformNode))return!1;if(n){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(C,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}var E=t.Vector3.ZeroReadOnly,I=t.Quaternion.Identity(),S=t.Vector3.OneReadOnly,V=new t.Vector3(-1,1,1);function F(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,i=e.normalized,a=e.getSize(),s=t.reduce(function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e},-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:a,type:o,count:s*a,normalized:i,totalVertices:s,kind:e.getKind()}}function B(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 O(e){return e.some(function(e){return e>=256})}function N(e){switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:case t.VertexBuffer.ColorKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return!0}return!1}function P(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 U(e){return e.x*=-1,e}function k(e){return C.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(C,e),e}function L(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){var r=Math.sign(e.x);e.x=t,e.y*=-r,e.z*=-r,e.w*=r}else r=Math.sign(e.y),e.x*=-r,e.y=n,e.z*=r,e.w*=-r}else{var o=Math.abs(e.z),i=Math.abs(e.w);o>i?(r=Math.sign(e.z),e.x*=-r,e.y*=r,e.z=o,e.w*=-r):(r=Math.sign(e.w),e.x*=r,e.y*=-r,e.z*=-r,e.w=i)}return e}function W(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function D(e,n){var r=t.Vector3.FromArrayToRef(n.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),o=t.Quaternion.FromArrayToRef(n.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(S,o,r,t.TmpVectors.Matrix[0]),a=t.Vector3.FromArrayToRef(e.translation||[0,0,0],0,t.TmpVectors.Vector3[2]),s=t.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[1]),u=t.Matrix.ComposeToRef(S,s,a,t.TmpVectors.Matrix[1]);i.multiplyToRef(u,u),u.decompose(void 0,o,r),r.equalsWithEpsilon(E,t.Epsilon)?delete n.translation:n.translation=r.asArray(),o.equalsWithEpsilon(I,t.Epsilon)?delete n.rotation:n.rotation=o.asArray(),n.scale&&delete n.scale}function z(e,n){if(!(n instanceof t.TransformNode))return!1;if(1!==n.getChildren().length||0!==e.getChildren().length||e.parent!==n)return!1;var r=e.getScene(),o=e instanceof t.TargetCamera&&!r.useRightHandedSystem?V:S;return!!n.scaling.equalsWithEpsilon(o,t.Epsilon)||(t.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(n.name," with modified scaling.")),!1)}function K(e,t){for(var n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],a=o[1],s=t[i];(Array.isArray(a)&&Array.isArray(s)&&G(a,s)||a===s)&&delete e[i]}return e}function G(e,t){return e.length===t.length&&e.every(function(e,n){return e===t[n]})}var q=new Map([[Int8Array,function(e,t,n){return e.setInt8(t,n)}],[Uint8Array,function(e,t,n){return e.setUint8(t,n)}],[Uint8ClampedArray,function(e,t,n){return e.setUint8(t,n)}],[Int16Array,function(e,t,n){return e.setInt16(t,n,!0)}],[Uint16Array,function(e,t,n){return e.setUint16(t,n,!0)}],[Int32Array,function(e,t,n){return e.setInt32(t,n,!0)}],[Uint32Array,function(e,t,n){return e.setUint32(t,n,!0)}],[Float32Array,function(e,t,n){return e.setFloat32(t,n,!0)}],[Float64Array,function(e,t,n){return e.setFloat64(t,n,!0)}]]),H=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=q.get(e.constructor),n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var n=new Uint8Array(2*t);n.set(this._data),this._data=n,this._dataView=new DataView(this._data.buffer)}},e}();function j(e){return e%4==0?4:e%2==0?2:1}var X,Q=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach(function(e){t+=e.byteLength});for(var n=new H(t),r=0,o=Array.from(this._bufferViewToData.keys()).sort(function(e,t){return j(t.byteLength)-j(e.byteLength)});r<o.length;r++){var i=o[r];i.byteOffset=n.byteOffset,e.push(i);for(var a=e.length-1,s=0,u=this.getPropertiesWithBufferView(i);s<u.length;s++)u[s].bufferView=a;n.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return n.getOutputData()},e.prototype.createBufferView=function(e,t){var n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n},e.prototype.createAccessor=function(e,t,n,r,o,i,a){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:a,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,n=0,r=this.getPropertiesWithBufferView(e);n<r.length;n++){var o=r[n];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach(function(n,r){n===e&&(void 0!==r.byteOffset&&delete r.byteOffset,t._accessorToBufferView.delete(r))})},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(X||(X={}));var Z=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof t.TransformNode||e instanceof t.Camera||e instanceof t.Light)},e._CreateNodeAnimation=function(n,r,o,i,a){if(this._IsTransformable(n)){var s=[],u=[],c=r.getKeys(),l=e._CalculateMinMaxKeyFrames(c),h=e._DeduceInterpolation(c,o,i),p=h.interpolationType,f=h.shouldBakeAnimation;if(f?e._CreateBakedAnimation(n,r,o,l.min,l.max,r.framePerSecond,a,s,u,l,i):"LINEAR"===p||"STEP"===p?e._CreateLinearOrStepAnimation(n,r,o,s,u,i):"CUBICSPLINE"===p?e._CreateCubicSplineAnimation(n,r,o,s,u,i):e._CreateBakedAnimation(n,r,o,l.min,l.max,r.framePerSecond,a,s,u,l,i),s.length&&u.length)return{inputs:s,outputs:u,samplerInterpolation:p,inputsMin:f?l.min:t.Tools.FloatRound(l.min/r.framePerSecond),inputsMax:f?l.max:t.Tools.FloatRound(l.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var n=null,r="VEC3",o=!1,i=e.targetProperty.split(".");switch(i[0]){case"scaling":n="scale";break;case"position":n="translation";break;case"rotation":r="VEC4",n="rotation";break;case"rotationQuaternion":r="VEC4",o=!0,n="rotation";break;case"influence":r="SCALAR",n="weights";break;default:t.Tools.Error("Unsupported animatable property ".concat(i[0]))}return n?{animationChannelTargetPath:n,dataAccessorType:r,useQuaternion:o}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,i,a,s,u,c,l,h){var p;if(e._IsTransformable(t)&&t.animations)for(var f=0,d=t.animations;f<d.length;f++){var m=d[f];if(!h||h(m)){var g=e._DeduceAnimationInfo(m);g&&(p={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?n:p,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,g.useQuaternion,c,l),p.samplers.length&&p.channels.length&&r.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(n,r,o,i,a,s,u,c,l,h,p){var f;if(n instanceof t.Mesh){var d=n.morphTargetManager;if(d)for(var m=0;m<d.numTargets;++m)for(var g=0,x=d.getTarget(m).animations;g<x.length;g++){var _=x[g];if(!p||p(_)){for(var v=new t.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),T=[],y=_.getKeys(),b=0;b<y.length;++b)for(var M=y[b],w=0;w<d.numTargets;++w)w==m?T.push(M):T.push({frame:M.frame,value:0});v.setKeys(T,!0);var A=e._DeduceAnimationInfo(v);A&&(f={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:f,n,v,A.dataAccessorType,A.animationChannelTargetPath,i,s,u,c,A.useQuaternion,l,h,d.numTargets),f.samplers.length&&f.channels.length&&o.push(f))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(n,r,o,i,a,s,u,c,l){var h,p;if(n.animationGroups)for(var f=n.animationGroups,d=function(f){var d=new Map,g=new Map,x=new Set,_=f.to-f.from;p={name:f.name,channels:[],samplers:[]};for(var v=function(r){var _=f.targetedAnimations[r],v=_.target,T=_.animation;if(l&&!l(T))return"continue";var y=c.has(v);if(m._IsTransformable(v)||1===v.length&&m._IsTransformable(v[0])){if(M=e._DeduceAnimationInfo(_.animation)){var b=m._IsTransformable(v)?v:m._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(T.name),p,b,T,M.dataAccessorType,M.animationChannelTargetPath,o,i,a,s,M.useQuaternion,u,y)}}else if(v instanceof t.MorphTarget||1===v.length&&v[0]instanceof t.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var w=v instanceof t.MorphTarget?v:v[0];if(w){var A=n.morphTargetManagers.find(function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1});if(A){var C=n.meshes.find(function(e){return e.morphTargetManager===A});C&&(d.has(C)||d.set(C,new Map),null===(h=d.get(C))||void 0===h||h.set(w,T),x.add(C),g.set(C,T))}}}}},T=0;T<f.targetedAnimations.length;++T)v(T);x.forEach(function(n){for(var r=n.morphTargetManager,c=null,l=[],h=g.get(n).getKeys(),m=h.length,x=0;x<m;++x)for(var v=0;v<r.numTargets;++v){var T=r.getTarget(v),y=d.get(n);if(y){var b=y.get(T);b?(c||(c=new t.Animation("".concat(f.name,"_").concat(n.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[x])):l.push({frame:f.from+_/m*x,value:T.influence,inTangent:h[0].inTangent?0:void 0,outTangent:h[0].outTangent?0:void 0})}}c.setKeys(l,!0);var M=e._DeduceAnimationInfo(c);M&&e._AddAnimation("".concat(f.name,"_").concat(n.name,"_MorphWeightAnimation"),p,n,c,M.dataAccessorType,M.animationChannelTargetPath,o,i,a,s,M.useQuaternion,u,!1,null==r?void 0:r.numTargets)}),p.channels.length&&p.samplers.length&&r.push(p)},m=this,g=0,x=f;g<x.length;g++)d(x[g])},e._AddAnimation=function(n,r,o,i,a,s,u,c,l,h,p,f,d,m){var g,x,_,v,T,y,b=e._CreateNodeAnimation(o,i,s,p,f);if(b){if(m){for(var M=0,w=void 0,A=[];b.inputs.length>0;)w=b.inputs.shift(),M%m==0&&A.push(w),M++;b.inputs=A}var C=u.get(o),R=new Float32Array(b.inputs);g=c.createBufferView(R),x=c.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),h.push(x),_=h.length-1;var E=new t.Quaternion,I=new t.Vector3,S=new t.Vector3,V=o instanceof t.Camera,F=B(a),O=new Float32Array(b.outputs.length*F);b.outputs.forEach(function(e,n){var r=e;switch(s){case"translation":d&&(t.Vector3.FromArrayToRef(e,0,S),U(S),S.toArray(r));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,E):(r=new Array(4),t.Vector3.FromArrayToRef(e,0,I),t.Quaternion.FromEulerVectorToRef(I,E)),d&&(L(E),V&&W(E)),E.toArray(r)}O.set(r,n*F)}),g=c.createBufferView(O),x=c.createAccessor(g,a,5126,b.outputs.length),h.push(x),v=h.length-1,T={interpolation:b.samplerInterpolation,input:_,output:v},r.samplers.push(T),y={sampler:r.samplers.length-1,target:{node:C,path:s}},r.channels.push(y)}},e._CreateBakedAnimation=function(n,r,o,i,a,s,u,c,l,h,p){var f,d,m,g,x,_,v=t.Quaternion.Identity(),T=null,y=null;h.min=t.Tools.FloatRound(i/s);for(var b=r.getKeys(),M=0,w=b.length;M<w;++M){if(m=b[M],M+1<w)if(g=b[M+1],m.value.equals&&m.value.equals(g.value)||m.value===g.value){if(0!==M)continue;_=m.frame}else _=g.frame;else{if(x=b[M-1],m.value.equals&&m.value.equals(x.value)||m.value===x.value)continue;_=a}if(_)for(var A=m.frame;A<=_;A+=u)if((d=t.Tools.FloatRound(A/s))!==T){T=d,y=d;var C={key:0,repeatCount:0,loopMode:r.loopMode};f=r._interpolate(A,C),e._SetInterpolatedValue(n,f,d,r,o,v,c,l,p)}}y&&(h.max=y)},e._ConvertFactorToVector3OrQuaternion=function(n,r,o,i,a){var s=e._GetBasePositionRotationOrScale(r,i,a),u=o.targetProperty.split("."),c=u?u[1]:"",l=a?t.Quaternion.FromArray(s).normalize():t.Vector3.FromArray(s);switch(c){case"x":case"y":case"z":l[c]=n;break;case"w":l.w=n;break;default:t.Tools.Error('glTFAnimation: Unsupported component name "'.concat(c,'"!'))}return l},e._SetInterpolatedValue=function(e,n,r,o,i,a,s,u,c){var l;s.push(r),"weights"!==i?(o.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(n=this._ConvertFactorToVector3OrQuaternion(n,e,o,i,c)),"rotation"===i?(c?a=n:(l=n,t.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,a)),u.push(a.asArray())):(l=n,u.push(l.asArray()))):u.push([n])},e._CreateLinearOrStepAnimation=function(t,n,r,o,i,a){for(var s=0,u=n.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/n.framePerSecond),e._AddKeyframeValue(c,n,i,r,t,a)}},e._CreateCubicSplineAnimation=function(t,n,r,o,i,a){n.getKeys().forEach(function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(X.INTANGENT,i,r,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,n,i,r,t,a),e._AddSplineTangent(X.OUTTANGENT,i,r,"CUBICSPLINE",s,a)})},e._GetBasePositionRotationOrScale=function(e,n,r){var o;if("rotation"===n)if(r){var i=e.rotationQuaternion;o=(null!=i?i:t.Quaternion.Identity()).asArray()}else{var a=e.rotation;o=(null!=a?a:t.Vector3.Zero()).asArray()}else if("translation"===n){var s=e.position;o=(null!=s?s:t.Vector3.Zero()).asArray()}else{var u=e.scaling;o=(null!=u?u:t.Vector3.One()).asArray()}return o},e._AddKeyframeValue=function(e,n,r,o,i,a){var s,u=n.dataType;if(u===t.Animation.ANIMATIONTYPE_VECTOR3){var c=e.value.asArray();if("rotation"===o){var l=t.Vector3.FromArray(c);c=t.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}r.push(c)}else if(u===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===o)r.push([e.value]);else if(s=this._ConvertFactorToVector3OrQuaternion(e.value,i,n,o,a)){if("rotation"===o){var h=a?s:t.Quaternion.RotationYawPitchRoll(s.y,s.x,s.z).normalize();r.push(h.asArray())}r.push(s.asArray())}}else u===t.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,n,r,o,i,a){var s,u=e===X.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===o){if("rotation"===r)if(u)if(a)s=u.asArray();else{var c=u;s=t.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}else s=[0,0,0,0];else s="weights"===r?u?[u]:[0]:u?u.asArray():[0,0,0];n.push(s)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,n=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)}),{min:t,max:n}},e}();function Y(e,n,r,o,i,a){var s={attributes:{},influence:e.influence,name:e.name},u=n.geometry;if(!u)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),s;var c,l=a?-1:1,h=t.Vector3.Zero();if(e.hasPositions){var p=e.getPositions(),f=u.getVerticesData(t.VertexBuffer.PositionKind);if(f){var d=new Float32Array(f.length),m=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];c=f.length/3;for(var x=0;x<c;++x){var _=t.Vector3.FromArray(f,3*x);t.Vector3.FromArray(p,3*x).subtractToRef(_,h),h.x*=l,m[0]=Math.min(m[0],h.x),g[0]=Math.max(g[0],h.x),m[1]=Math.min(m[1],h.y),g[1]=Math.max(g[1],h.y),m[2]=Math.min(m[2],h.z),g[2]=Math.max(g[2],h.z),d[3*x]=h.x,d[3*x+1]=h.y,d[3*x+2]=h.z}var v=r.createBufferView(d,12),T=r.createAccessor(v,"VEC3",5126,p.length/3,0,{min:m,max:g});i.push(T),s.attributes.POSITION=i.length-1}else t.Tools.Warn("Morph target positions for mesh ".concat(n.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),b=u.getVerticesData(t.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(c=b.length/3,x=0;x<c;++x){var w=t.Vector3.FromArray(b,3*x).normalize();t.Vector3.FromArray(y,3*x).normalize().subtractToRef(w,h),M[3*x]=h.x*l,M[3*x+1]=h.y,M[3*x+2]=h.z}v=r.createBufferView(M,12),T=r.createAccessor(v,"VEC3",5126,y.length/3,0),i.push(T),s.attributes.NORMAL=i.length-1}else t.Tools.Warn("Morph target normals for mesh ".concat(n.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),C=u.getVerticesData(t.VertexBuffer.TangentKind);if(C){c=C.length/4;var R=new Float32Array(3*c);for(x=0;x<c;++x){var E=t.Vector3.FromArray(C,4*x);P(E);var I=t.Vector3.FromArray(A,3*x);P(I),I.subtractToRef(E,h),R[3*x]=h.x*l,R[3*x+1]=h.y,R[3*x+2]=h.z}v=r.createBufferView(R,12),T=r.createAccessor(v,"VEC3",5126,c,0),i.push(T),s.attributes.TANGENT=i.length-1}else t.Tools.Warn("Morph target tangents for mesh ".concat(n.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),V=u.getVerticesData(t.VertexBuffer.ColorKind),F=u.getVertexBuffer(t.VertexBuffer.ColorKind);if(V&&F){var B=F.getSize();c=V.length/B;var O=new Float32Array(c*B);for(x=0;x<c;++x)if(3===B){var N=t.Vector3.FromArray(V,x*B);t.Vector3.FromArray(S,x*B).subtractToRef(N,h),O[3*x]=h.x,O[3*x+1]=h.y,O[3*x+2]=h.z}else if(4===B){var U=new t.Vector4;N=t.Vector4.FromArray(V,x*B),t.Vector4.FromArray(S,x*B).subtractToRef(N,U),O[4*x]=U.x,O[4*x+1]=U.y,O[4*x+2]=U.z,O[4*x+3]=U.w}else t.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));v=r.createBufferView(O,4*B),T=r.createAccessor(v,3===B?"VEC3":"VEC4",5126,c,0),i.push(T),s.attributes.COLOR_0=i.length-1}else t.Tools.Warn("Morph target colors for mesh ".concat(n.name," were not exported. Mesh does not have colors vertex data"))}return s}var J=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,n,r,o){var i,a,s,u;return null===(u=null===(s=null===(a=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===a?void 0:a.get(n))||void 0===s?void 0:s.get(r))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,n,r,o,i){var a=this._indicesAccessorMap.get(e);a||(a=new Map,this._indicesAccessorMap.set(e,a));var s=a.get(t);s||(s=new Map,a.set(t,s));var u=s.get(n);u||(u=new Map,s.set(n,u));var c=u.get(r);c||(c=new Map,u.set(r,c)),c.set(o,i)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)},e.prototype.getRemappedBufferView=function(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)},e.prototype.getVertexAccessor=function(e,t,n){var r,o;return null===(o=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.get(n)},e.prototype.setVertexAccessor=function(e,t,n,r){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.set(t,i)),i.set(n,r)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),$=function(){function e(e,n){if(void 0===e&&(e=t.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(t.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 A(this),this._extensions={},this._bufferManager=new Q,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=c({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"},n),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,n,r){var o=this;if(n>=t.length)return Promise.resolve(e);var i=r(t[n],e);return i?i.then(function(e){return h(o,void 0,void 0,function(){var o;return p(this,function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=i.sent(),[3,3];case 2:o=null,i.label=3;case 3:return[2,o]}})})}):this._ApplyExtension(e,t,n+1,r)},e.prototype._ApplyExtensions=function(t,n){for(var r=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];r.push(this._extensions[a])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var i=this;return this._ApplyExtensions(t,function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,n,r,o,i._bufferManager)})},e.prototype._extensionsPostExportMaterialAsync=function(e,t,n){return this._ApplyExtensions(t,function(t,r){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,n)})},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,n,r){return h(this,void 0,void 0,function(){var o,i=this;return p(this,function(a){switch(a.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map(function(e){return h(i,void 0,void 0,function(){var i,a;return p(this,function(s){switch(s.label){case 0:return(i=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,i.postExportMaterialAdditionalTexturesAsync(t,n,r)]:[3,2];case 1:a=s.sent(),o.push.apply(o,a),s.label=2;case 2:return[2]}})})}))];case 1:return a.sent(),[2,o]}})})},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,n,r)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return h(this,void 0,void 0,function(){var t,n,r,o;return p(this,function(i){switch(i.label){case 0:t=0,n=e._ExtensionNames,i.label=1;case 1:return t<n.length?(r=n[t],(o=this._extensions[r]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}})})},e.prototype._forEachExtensions=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions(function(t){var n,r,o;t.wasUsed&&((n=e._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((r=e._glTF).extensionsRequired||(r.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())})},e.prototype._loadExtensions=function(){for(var t=0,n=e._ExtensionNames;t<n.length;t++){var r=n[t],o=e._ExtensionFactories[r](this);this._extensions[r]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(n,r,o){void 0===o&&(o=100),e.UnregisterExtension(n)&&t.Tools.Warn("Extension with the name ".concat(n," already exists")),e._ExtensionFactories[n]=r;var i=null!=o?o:0;e._ExtensionOrders[n]=i;for(var a=e._ExtensionNames.length,s=0;s<e._ExtensionNames.length;s++){var u=e._ExtensionNames[s];if(i<e._ExtensionOrders[u]){a=s;break}}e._ExtensionNames.splice(a,0,n)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[t];var n=e._ExtensionNames.indexOf(t);return-1!==n&&e._ExtensionNames.splice(n,1),!0},e.prototype._generateJSON=function(e,t,n){var r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(r.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return h(this,void 0,void 0,function(){var t,n,r,o,a,s,u;return p(this,function(c){switch(c.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=c.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength,e,!0),r=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",a=e+".bin",(s=new i).files[o]=n,s.files[a]=r,this._imageData)for(u in this._imageData)s.files[u]=this._imageData[u];return[2,s]}})})},e.prototype._generateBinaryAsync=function(){return h(this,void 0,void 0,function(){return p(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 h(this,void 0,void 0,function(){var t,n,r,o,a,s,u,c,l,h,f,d,m,g;return p(this,function(p){switch(p.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=p.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(s=new TextEncoder,a=s.encode(n),o=a.length),u=this._getPadding(o),c=this._getPadding(t.byteLength),l=28+o+u+t.byteLength+c,(h=new H(l)).writeUInt32(1179937895),h.writeUInt32(2),h.writeUInt32(l),h.writeUInt32(o+u),h.writeUInt32(1313821514),a)h.writeTypedArray(a);else for(f="_".charCodeAt(0),m=0;m<o;++m)(d=n.charCodeAt(m))!=n.codePointAt(m)?h.writeUInt8(f):h.writeUInt8(d);for(m=0;m<u;++m)h.writeUInt8(32);for(h.writeUInt32(t.byteLength+c),h.writeUInt32(5130562),h.writeTypedArray(t),m=0;m<c;++m)h.writeUInt8(0);return(g=new i).files[r]=new Blob([h.getOutputData()],{type:"application/octet-stream"}),[2,g]}})})},e.prototype._setNodeTransformation=function(e,n,r){var o;if(n.getPivotPoint().equalsWithEpsilon(E,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!n.position.equalsWithEpsilon(E,t.Epsilon)){var i=t.TmpVectors.Vector3[0].copyFrom(n.position);r&&U(i),e.translation=i.asArray()}n.scaling.equalsWithEpsilon(S,t.Epsilon)||(e.scale=n.scaling.asArray());var a=(null===(o=n.rotationQuaternion)||void 0===o?void 0:o.clone())||t.Quaternion.FromEulerAngles(n.rotation.x,n.rotation.y,n.rotation.z);a.equalsWithEpsilon(I,t.Epsilon)||(r&&L(a),e.rotation=a.normalize().asArray())},e.prototype._setCameraTransformation=function(e,n,r){var o=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],a=n.getWorldMatrix();if(n.parent){var s=n.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);a.multiplyToRef(s,t.TmpVectors.Matrix[1]).decompose(void 0,i,o)}else a.decompose(void 0,i,o);o.equalsWithEpsilon(E,t.Epsilon)||(r&&U(o),e.translation=o.asArray()),r&&L(i),this._babylonScene.useRightHandedSystem||W(i),i.equalsWithEpsilon(I,t.Epsilon)||(e.rotation=i.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,n=this._babylonScene.cameras;e<n.length;e++){var r=n[e],o={type:r.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(r.name&&(o.name=r.name),"perspective"===o.type)o.perspective={aspectRatio:r.getEngine().getAspectRatio(r),yfov:r.fovMode===t.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===o.type){var i=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();o.orthographic={xmag:i,ymag:a,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,o)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var n=t[e],r=this._nodesCameraMap.get(n);if(void 0!==r){this._cameras.push(n);for(var o=0,i=r;o<i.length;o++)i[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var n=t[e];n.bones.length<=0||this._skinMap.set(n,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var n,r=function(r){if(r.bones.length<=0)return"continue";var i=o._skinMap.get(r);if(null==i)return"continue";for(var a={},s=-1,u=0;u<r.bones.length;++u){var c=r.bones[u];-1!==(h=null!==(n=c.getIndex())&&void 0!==n?n:u)&&(a[h]=c,h>s&&(s=h))}for(var l=[],h=0;h<=s;++h){var p=(c=a[h]).getTransformNode(),f=p?o._nodeMap.get(p):void 0;if(void 0!==f){i.joints.push(f);var d=c.getAbsoluteInverseBindMatrix().clone();e.has(p)&&k(d),l.push(d)}else t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var m=o._nodesSkinMap.get(i);if(i.joints.length>0&&void 0!==m){var g=new Float32Array(16*l.length);l.forEach(function(e,t){g.set(e.m,16*t)});var x=o._bufferManager.createBufferView(g);o._accessors.push(o._bufferManager.createAccessor(x,"MAT4",5126,l.length)),i.inverseBindMatrices=o._accessors.length-1,o._skins.push(i);for(var _=o._skins.length-1,v=0,T=m;v<T.length;v++)T[v].skin=_}},o=this,i=0,a=this._babylonScene.skeletons;i<a.length;i++)r(a[i])},e.prototype._exportSceneAsync=function(){return h(this,void 0,void 0,function(){var e,n,r,o,i,a,s,u,c,l,h,f,d,m,g,x,_,v,T,y,b,M,w,A,C,E,I,S,V,F,B,O,N;return p(this,function(p){switch(p.label){case 0:if(e={nodes:[]},this._babylonScene.metadata&&(n=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=n),r=new Array,o=new Array,i=new Array,this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(s=0,u=this._babylonScene.animationGroups;s<u.length;s++)for(c=u[s],l=0,h=c.targetedAnimations;l<h.length;l++)f=h[l],(d=f.target)instanceof t.TransformNode&&!d.parent&&(null!=a?a:a=new Set).add(d);for(m=0,g=this._babylonScene.rootNodes;m<g.length;m++)x=g[m],_=x.animations,v=!!_&&_.length>0||(null==a?void 0:a.has(x)),this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&R(x,this._babylonScene.useRightHandedSystem)&&!v?i.push.apply(i,x.getChildren()):this._babylonScene.useRightHandedSystem?r.push(x):o.push(x);return this._listAvailableCameras(),this._listAvailableSkeletons(),T=new J(!0,!1),b=(y=(B=e.nodes).push).apply,M=[B],[4,this._exportNodesAsync(o,T)];case 1:return b.apply(y,M.concat([p.sent()])),w=new J(!1,!1),C=(A=(O=e.nodes).push).apply,E=[O],[4,this._exportNodesAsync(r,w)];case 2:return C.apply(A,E.concat([p.sent()])),I=new J(!1,!0),V=(S=(N=e.nodes).push).apply,F=[N],[4,this._exportNodesAsync(i,I)];case 3:return V.apply(S,F.concat([p.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(T.getNodesSet()),this._babylonScene.animationGroups.length&&Z._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,T.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 h(this,void 0,void 0,function(){var n,r,o,i;return p(this,function(a){switch(a.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,a.label=1;case 1:return r<o.length?(i=o[r],[4,this._exportNodeAsync(i,n,t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return r++,[3,1];case 4:return[2,n]}})})},e.prototype._collectBuffers=function(e,n,r,o,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var s in a)if(N(s)){var u=a[s];i.setHasVertexColorAlpha(u,e.hasVertexAlpha);var c=u._buffer,l=n.get(c)||[];n.set(c,l),-1===l.indexOf(u)&&l.push(u);var h=r.get(u)||[];r.set(u,h),-1===h.indexOf(e)&&h.push(e)}var p=e.morphTargetManager;if(p)for(var f=0;f<p.numTargets;f++){var d=p.getTarget(f);h=o.get(d)||[],o.set(d,h),-1===h.indexOf(e)&&h.push(e)}}for(var m=0,g=e.getChildren();m<g.length;m++){var x=g[m];this._collectBuffers(x,n,r,o,i)}},e.prototype._exportBuffers=function(e,n){for(var r=new Map,o=new Map,i=new Map,a=0,s=e;a<s.length;a++){var u=s[a];this._collectBuffers(u,r,o,i,n)}for(var c=Array.from(r.keys()),l=function(e){var i=e.getData();if(!i)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 u=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)}(i).slice(),c=function(e){var n=o.get(e),r=F(e,n),i=r.byteOffset,a=r.byteStride,s=r.componentCount,c=r.type,l=r.count,p=r.normalized;switch(r.kind){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,i,a,s,c,l,p,function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}});break;case t.VertexBuffer.ColorKind:var f=n.filter(function(e){return e.material instanceof t.StandardMaterial||null==e.material}).length;if(0==f)break;if(f!=n.length){t.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}c==t.VertexBuffer.UNSIGNED_BYTE&&t.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var d=new t.Color3,m=new t.Color4,g=h._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(u,i,a,s,c,l,p,function(e){3===e.length?(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0)):(m.fromArray(e,0),m.toLinearSpaceToRef(m,g),m.toArray(e,0))})}},l=0,p=a;l<p.length;l++)c(B=p[l]);if(n.convertToRightHanded){for(var f=0,d=a;f<d.length;f++){var m=F(B=d[f],o.get(B)),g=m.byteOffset,x=m.byteStride,_=m.componentCount,v=m.type,T=m.count,y=m.normalized;switch(R=m.kind){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,g,x,_,v,T,y,function(e){e[0]=-e[0]})}}n.convertedToRightHandedBuffers.set(e,u)}var b=h._bufferManager.createBufferView(u,s);n.setVertexBufferView(e,b);for(var M=new Map,w=0,A=a;w<A.length;w++){var C=F(B=A[w],o.get(B)),R=C.kind,E=C.totalVertices;switch(R){case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:if(B.type==t.VertexBuffer.FLOAT){var I=B.getFloatData(E);null!==I&&M.set(B,I)}}}0!==M.size&&t.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 B=V[S],N=M.get(B);if(N){for(var P=O(N),U=new(P?Uint16Array:Uint8Array)(N.length),k=0;k<N.length;k++)U[k]=N[k];var L=h._bufferManager.createBufferView(U,4*(P?2:1));n.setRemappedBufferView(e,B,L)}}},h=this,p=0,f=c;p<f.length;p++)l(f[p]);for(var d=0,m=Array.from(i.keys());d<m.length;d++){var g=m[d],x=i.get(g);if(x)for(var _=Y(g,x[0],this._bufferManager,this._bufferViews,this._accessors,n.convertToRightHanded),v=0,T=x;v<T.length;v++){var y=T[v];n.bindMorphDataToMesh(y,_)}}},e.prototype._exportNodeAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h=this;return p(this,function(p){switch(p.label){case 0:return void 0!==(r=this._nodeMap.get(e))?(t.includes(r)||t.push(r),[2]):[4,this._createNodeAsync(e,n)];case 1:(o=p.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),i={name:"runtime animations",channels:[],samplers:[]},a=[],this._babylonScene.animationGroups.length||(Z._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&Z._CreateNodeAnimationFromNodeAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),a.forEach(function(e){e.channels.length&&e.samplers.length&&h._animations.push(e)})),s=o?[]:t,u=0,c=e.getChildren(),p.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:p.sent(),p.label=4;case 4:return u++,[3,2];case 5:return o&&s.length&&(o.children=s),[2]}})})},e.prototype._createNodeAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,f,d,m;return p(this,function(p){switch(p.label){case 0:return this._shouldExportNode(e)?(r={},e.name&&(r.name=e.name),e.metadata&&(o=this._options.metadataSelector(e.metadata))&&(r.extras=o),e instanceof t.TransformNode?(this._setNodeTransformation(r,e,n.convertToRightHanded),e instanceof t.AbstractMesh?(i=e instanceof t.InstancedMesh?e.sourceMesh:e).subMeshes&&i.subMeshes.length>0?(a=r,[4,this._exportMeshAsync(i,n)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:a.mesh=p.sent(),p.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===(f=this._nodesSkinMap.get(s))||void 0===f||f.push(r)),p.label=3;case 3:if(e instanceof t.TargetCamera&&(u=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(u)&&this._nodesCameraMap.set(u,[]),this._setCameraTransformation(r,e,n.convertToRightHanded),null!==(c=e.parent)&&z(e,c)&&void 0!==(l=this._nodeMap.get(c)))return h=this._nodes[l],D(r,h),null===(d=this._nodesCameraMap.get(u))||void 0===d||d.push(h),[2,null];null===(m=this._nodesCameraMap.get(u))||void 0===m||m.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,n.convertToRightHanded)];case 4:return p.sent()?[2,r]:(t.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}})})},e.prototype._exportIndices=function(e,n,r,o,i,a,s,u,c){var l=null;c.mode=function(e){switch(e){case t.Material.TriangleFillMode:return 4;case t.Material.TriangleStripDrawMode:return 5;case t.Material.TriangleFanDrawMode:return 6;case t.Material.PointListDrawMode:case t.Material.PointFillMode:return 0;case t.Material.LineLoopDrawMode:return 2;case t.Material.LineListDrawMode:return 1;case t.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}(a);var h=s!==t.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case t.Material.TriangleFillMode:case t.Material.TriangleStripDrawMode:case t.Material.TriangleFanDrawMode:return!0}return!1}(a);if(h){if(a===t.Material.TriangleStripDrawMode||a===t.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");var p=n?new Uint32Array(o):new Uint16Array(o);if(e)for(var f=0;f+2<o;f+=3)p[f]=e[r+f]+i,p[f+1]=e[r+f+2]+i,p[f+2]=e[r+f+1]+i;else for(f=0;f+2<o;f+=3)p[f]=f,p[f+1]=f+2,p[f+2]=f+1;l=p}else if(e&&0!==i){for(p=n?new Uint32Array(o):new Uint16Array(o),f=0;f<o;f++)p[f]=e[r+f]+i;l=p}else e&&(l=function(e,t,n,r){var o=e;return 0===t&&n===e.length||(o=Array.isArray(e)?e.slice(t,t+n):e.subarray(t,t+n)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?r?new Uint32Array(o):new Uint16Array(o):o}(e,r,o,n));if(l){var d=u.getIndicesAccessor(e,r,o,i,h);if(void 0===d){var m=this._bufferManager.createBufferView(l),g=n?5125:5123;this._accessors.push(this._bufferManager.createAccessor(m,"SCALAR",g,o,0)),d=this._accessors.length-1,u.setIndicesAccessor(e,r,o,i,h,d)}c.indices=d}},e.prototype._exportVertexBuffer=function(e,n,r,o,i,a){var s=e.getKind();if(N(s)&&(!s.startsWith("uv")||this._options.exportUnusedUVs||n&&this._materialNeedsUVsSet.has(n))){var u=i.getVertexAccessor(e,r,o);if(void 0===u){var c=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),l=s===t.VertexBuffer.PositionKind?function(e,n,r,o){var i=n.byteOffset,a=n.byteStride,s=n.type,u=n.normalized,c=n.getSize(),l=new Array(c).fill(1/0),h=new Array(c).fill(-1/0);return t.EnumerateFloatValues(e,i+r*a,a,c,s,o*c,u,function(e){for(var t=0;t<c;t++)l[t]=Math.min(l[t],e[t]),h[t]=Math.max(h[t],e[t])}),{min:l,max:h}}(c,e,r,o):void 0,h=(s===t.VertexBuffer.MatricesIndicesKind||s===t.VertexBuffer.MatricesIndicesExtraKind)&&e.type===t.VertexBuffer.FLOAT,p=h?t.VertexBuffer.UNSIGNED_BYTE:e.type,f=h?void 0:e.normalized,d=h?i.getRemappedBufferView(e._buffer,e):i.getVertexBufferView(e._buffer),m=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,n){if(e==t.VertexBuffer.ColorKind)return n?"VEC4":"VEC3";switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:return"VEC3";case t.VertexBuffer.TangentKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(s,i.hasVertexColorAlpha(e)),p,o,m,l,f)),u=this._accessors.length-1,i.setVertexAccessor(e,r,o,u)}a.attributes[function(e){switch(e){case t.VertexBuffer.PositionKind:return"POSITION";case t.VertexBuffer.NormalKind:return"NORMAL";case t.VertexBuffer.TangentKind:return"TANGENT";case t.VertexBuffer.ColorKind:return"COLOR_0";case t.VertexBuffer.UVKind:return"TEXCOORD_0";case t.VertexBuffer.UV2Kind:return"TEXCOORD_1";case t.VertexBuffer.UV3Kind:return"TEXCOORD_2";case t.VertexBuffer.UV4Kind:return"TEXCOORD_3";case t.VertexBuffer.UV5Kind:return"TEXCOORD_4";case t.VertexBuffer.UV6Kind:return"TEXCOORD_5";case t.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case t.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case t.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case t.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(s)]=u}},e.prototype._exportMaterialAsync=function(e,n,r,o){return h(this,void 0,void 0,function(){var i,a;return p(this,function(s){switch(s.label){case 0:return void 0!==(i=this._materialMap.get(e))?[3,8]:(a=n&&Object.keys(n).some(function(e){return e.startsWith("uv")}),(e=e instanceof t.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof t.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,a)]:[3,2]);case 1:return i=s.sent(),[3,7];case 2:return e instanceof t.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,a)]:[3,4];case 3:return i=s.sent(),[3,7];case 4:return e instanceof t.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,a)]:[3,6];case 5:return i=s.sent(),[3,7];case 6:return t.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,i),s.label=8;case 8:return o.material=i,[2]}})})},e.prototype._exportMeshAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,d,m,g,x,_,v,T,y,b,M,w,A,C,R,E,I,S,V,F,B,O,N,P,U,k;return p(this,function(p){switch(p.label){case 0:if(void 0!==(r=n.getMesh(e)))return[2,r];if(o={primitives:[]},r=this._meshes.length,this._meshes.push(o),n.setMesh(e,r),i=e.isUnIndexed?null:e.getIndices(),a=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),s=n.getMorphTargetsFromMesh(e),u=e instanceof t.LinesMesh,c=e instanceof t.GreasedLineBaseMesh,l=e.subMeshes,!(a&&l&&l.length>0))return[3,7];h=0,d=l,p.label=1;case 1:return h<d.length?(m=d[h],g={attributes:{}},x=m.getMaterial()||this._babylonScene.defaultMaterial,c?(y={name:x.name},b=e,_=t.Color3.White(),v=null!==(N=null===(O=b.material)||void 0===O?void 0:O.alpha)&&void 0!==N?N:1,(!(T=null!==(U=null===(P=b.greasedLineMaterial)||void 0===P?void 0:P.color)&&void 0!==U?U:_).equalsWithEpsilon(_,t.Epsilon)||v<1)&&(y.pbrMetallicRoughness={baseColorFactor:f(f([],T.asArray(),!0),[v],!1)}),this._materials.push(y),g.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return u?(y={name:x.name},(!(b=e).color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||b.alpha<1)&&(y.pbrMetallicRoughness={baseColorFactor:f(f([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(y),g.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(x,a,m,g)];case 4:p.sent(),p.label=5;case 5:for(M=u||c?t.Material.LineListDrawMode:null!==(k=e.overrideRenderingFillMode)&&void 0!==k?k:x.fillMode,w=x._getEffectiveOrientation(e),n.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(w=w===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(i,i?t.AreIndices32Bits(i,m.indexCount,m.indexStart,m.verticesStart):m.verticesCount>65535,i?m.indexStart:m.verticesStart,i?m.indexCount:m.verticesCount,-m.verticesStart,M,w,n,g),A=0,C=Object.values(a);A<C.length;A++)R=C[A],this._exportVertexBuffer(R,x,m.verticesStart,m.verticesCount,n,g);if(s)for(g.targets=[],E=0,I=s;E<I.length;E++)F=I[E],g.targets.push(F.attributes);o.primitives.push(g),this._extensionsPostExportMeshPrimitive(g),p.label=6;case 6:return h++,[3,1];case 7:if(s)for(o.weights=[],o.extras||(o.extras={}),o.extras.targetNames=[],S=0,V=s;S<V.length;S++)F=V[S],o.weights.push(F.influence),o.extras.targetNames.push(F.name);return[2,r]}})})},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),ee=function(){function e(){}return e.GLTFAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o;return p(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new $(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e.GLBAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o;return p(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new $(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e}(),te={__proto__:null,GLTF2Export:ee},ne="EXT_mesh_gpu_instancing";function re(e,t){for(var n=new Float32Array(3*t),r=0;r<t;r++)n[3*r+0]=e[4*r+0],n[3*r+1]=e[4*r+1],n[3*r+2]=e[4*r+2];return n}var oe=function(){function e(e){this.name=ne,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,n,r,o,i,a){return h(this,void 0,void 0,function(){var e=this;return p(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var s,u;if(n&&r instanceof t.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var c=t.Vector3.Zero(),l=t.Quaternion.Identity(),h=t.Vector3.One(),p=r.thinInstanceGetWorldMatrices(),f=t.TmpVectors.Vector3[2],d=t.TmpVectors.Quaternion[1],m=t.TmpVectors.Vector3[3],g=!1,x=!1,_=!1,v=new Float32Array(3*r.thinInstanceCount),T=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),b=0,M=0,w=p;M<w.length;M++)w[M].decompose(m,d,f),i&&(U(f),L(d)),v.set(f.asArray(),3*b),T.set(d.normalize().asArray(),4*b),y.set(m.asArray(),3*b),g=g||!f.equalsWithEpsilon(c),x=x||!d.equalsWithEpsilon(l),_=_||!m.equalsWithEpsilon(h),b++;var A={attributes:{}};g&&(A.attributes.TRANSLATION=e._buildAccessor(v,"VEC3",r.thinInstanceCount,a)),x&&(A.attributes.ROTATION=e._buildAccessor(T,"VEC4",r.thinInstanceCount,a)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,a));var C=null===(u=null===(s=r._userThinInstanceBuffersStorage)||void 0===s?void 0:s.data)||void 0===u?void 0:u.instanceColor;if(C){var R=r.thinInstanceCount;r.hasVertexAlpha&&C.length===4*R?(e._instanceColorWarned||(t.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),C=re(C,R)):C.length===4*R&&(C=re(C,R)),C.length===3*R&&(A.attributes._COLOR_0=e._buildAccessor(C,"VEC3",R,a))}n.extensions=n.extensions||{},n.extensions[ne]=A}o(n)})];case 1:return[2,o.sent()]}})})},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),i=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();$.RegisterExtension(ne,function(e){return new oe(e)});var ie="KHR_draco_mesh_compression";function ae(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}var se=function(){function e(e){this.name=ie,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&t.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,n,r){var o=this;if(this.enabled)if(4===e.mode||5===e.mode){var i=[],a=[],s=null;if(void 0!==e.indices){var u=r[e.indices],c=n.getBufferView(u);s=n.getData(c).slice(),i.push(c),a.push(u)}for(var l=[],h=0,p=Object.entries(e.attributes);h<p.length;h++){var f=p[h],d=f[0],m=(u=r[f[1]],c=n.getBufferView(u),B(u.type)),g=t.GetTypedArrayData(n.getData(c),m,u.componentType,u.byteOffset||0,c.byteStride||t.GetTypeByteLength(u.componentType)*m,u.count,!0);l.push({kind:d,dracoName:ae(d),size:B(u.type),data:g}),i.push(c),a.push(u)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},_=t.DracoEncoder.Default._encodeAsync(l,s,x).then(function(t){var r={bufferView:-1,attributes:t.attributeIds},s=n.createBufferView(t.data);n.setBufferView(r,s);for(var u=0,c=i;u<c.length;u++){var l=c[u];o._bufferViewsUsed.add(l)}for(var h=0,p=a;h<p.length;h++){var f=p[h];o._accessorsUsed.add(f)}e.extensions||(e.extensions={}),e.extensions[ie]=r}).catch(function(e){t.Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. "+e.message)});this._encodePromises.push(_),this._wasUsed=!0}else t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return h(this,void 0,void 0,function(){var t=this;return p(this,function(n){switch(n.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return n.sent(),this._bufferViewsUsed.forEach(function(n){e.getPropertiesWithBufferView(n).every(function(e){return t._accessorsUsed.has(e)})&&e.removeBufferView(n)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}})})},e}();$.RegisterExtension(ie,function(e){return new se(e)});var ue="KHR_lights_punctual",ce={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},le={innerConeAngle:0,outerConeAngle:Math.PI/4},he=t.Vector3.Backward(),pe=function(){function e(e){this.name=ue,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[ue]=this._lights},e.prototype.postExportNodeAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a=this;return p(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){if(r instanceof t.Light){var u=r.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(u&&r instanceof t.ShadowLight))return t.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ue)),void s(n);if(r.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(ue," specification!")),!r.position.equalsToFloats(0,0,0)){var c=t.TmpVectors.Vector3[0].copyFrom(r.position);i&&U(c),n.translation=c.asArray()}if("point"!==u){var l=r.direction.normalizeToRef(t.TmpVectors.Vector3[0]);i&&U(l);var h=t.Quaternion.FromUnitVectorsToRef(he,l,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(h)||(n.rotation=h.asArray())}var p={type:u,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(K(p,ce),"spot"===u){var f=r;p.spot={innerConeAngle:f.innerAngle/2,outerConeAngle:f.angle/2},K(p.spot,le)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(p);var d={light:a._lights.lights.length-1},m=r.parent;if(m&&z(r,m)){var g=o.get(m);if(g){var x=a._exporter._nodes[g];return D(n,x),x.extensions||(x.extensions={}),x.extensions[ue]=d,void s(null)}}n.extensions||(n.extensions={}),n.extensions[ue]=d,s(n)}else s(n)})];case 1:return[2,s.sent()]}})})},e}();$.RegisterExtension(ue,function(e){return new pe(e)});var fe="EXT_lights_area",de={name:"",color:[1,1,1],intensity:1,size:1},me={aspect:1},ge=t.Vector3.Backward(),xe=function(){function e(e){this.name=fe,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[fe]=this._lights},e.prototype.postExportNodeAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a=this;return p(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){if(r instanceof t.Light){var u=r.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!u)return t.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(fe)),void s(n);var c=r;if(c.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(fe," specification!")),!c.position.equalsToFloats(0,0,0)){var l=t.TmpVectors.Vector3[0].copyFrom(c.position);i&&U(l),n.translation=l.asArray()}var h=t.Vector3.Forward();i&&U(h);var p=t.Quaternion.FromUnitVectorsToRef(ge,h,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(p)||(n.rotation=p.asArray());var f={type:u,name:c.name,color:c.diffuse.asArray(),intensity:c.intensity,size:c.height,rect:{aspect:c.width/c.height}};K(f,de),f.rect&&K(f.rect,me),a._lights||(a._lights={lights:[]}),a._lights.lights.push(f);var d={light:a._lights.lights.length-1},m=r.parent;if(m&&z(c,m)){var g=o.get(m);if(g){var x=a._exporter._nodes[g];return D(n,x),x.extensions||(x.extensions={}),x.extensions[fe]=d,void s(null)}}n.extensions||(n.extensions={}),n.extensions[fe]=d,s(n)}else s(n)})];case 1:return[2,s.sent()]}})})},e}();$.RegisterExtension(fe,function(e){return new xe(e)});var _e="KHR_materials_anisotropy";function ve(e){return h(this,void 0,void 0,function(){var n,r,o;return p(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.specularRoughnessAnisotropyTexture,o=e.geometryTangentTexture,r||o?[4,t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent()]}})})}var Te=function(){function e(e){this.name=_e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o;return p(this,function(i){switch(i.label){case 0:return e=[],r instanceof t.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 t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0?(n=function(e){var t=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}(r),this._anisoTexturesMap[n]?(e.push(this._anisoTexturesMap[n]),[3,4]):[3,2]):[3,5];case 2:return[4,ve(r)];case 3:(o=i.sent())&&(e.push(o),this._anisoTexturesMap[n]=o),i.label=4;case 4:return[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c,l;if(r instanceof t.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var h=o._exporter._materialExporter.getTextureInfo(r.anisotropy.texture);null!==(v={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=h?h:void 0}).anisotropyTexture&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[_e]=v}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){o._wasUsed=!0,n.extensions=n.extensions||{};var p=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(p=r.baseMetalnessTexture);var f=o._anisoTexturesMap[r.id];if(!p&&!f){var d=r.specularRoughness,m=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var g=(a=r.specularRoughness,l=(1-(s=r.specularRoughnessAnisotropy))*(c=(u=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(l),newAnisotropyStrength:Math.min(Math.sqrt((c-u)/Math.max(1-u,1e-4)),1)});d=g.newBaseRoughness,m=g.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=d);var x={anisotropyStrength:m,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return n.extensions[_e]=x,e(n)}var _=f?o._exporter._materialExporter.getTextureInfo(f):null,v={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};r._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(i=o._exporter._glTF).extensionsUsed||(i.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&o._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),o._exporter._materialNeedsUVsSet.add(r),n.extensions[_e]=v}e(n)})},e}();$.RegisterExtension(_e,function(e){return new Te(e)});var ye="KHR_materials_clearcoat";function be(e){return h(this,void 0,void 0,function(){var n,r,o;return p(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatWeightTexture,o=e.coatRoughnessTexture,r||o?[4,t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function Me(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var we=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 n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i;return p(this,function(a){switch(a.label){case 0:return e=[],r instanceof t.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 t.OpenPBRMaterial&&r.coatWeight>0?(n=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):n=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):n=!0),n?(o=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,3]:[4,be(r)]):[3,4]):[3,5];case 2:(i=a.sent())&&(this._cachedInternalTexturesMap[o]=i),a.label=3;case 3:this._cachedInternalTexturesMap[o]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Me(this._cachedInternalTexturesMap[o],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Me(this._cachedInternalTexturesMap[o],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,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var i,a=o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);i=r.clearCoat.useRoughnessFromMainTexture?o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):o._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&t.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var s=o._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture);null===(l={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[ye]=l}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var u=void 0,c=void 0;r.coatWeightTexture&&(u=o._mergedTexturesMap[r.coatWeightTexture.uniqueId],c=o._exporter._materialExporter.getTextureInfo(u));var l,h=void 0,p=void 0;r.coatRoughnessTexture&&(h=o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],p=o._exporter._materialExporter.getTextureInfo(h)),r.coatColorTexture&&t.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),s=o._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),null===(l={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=c?c:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=p?p:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[ye]=l}e(n)})},e}();$.RegisterExtension(ye,function(e){return new we(e)});var Ae="KHR_materials_coat";function Ce(e){var t=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}function Re(e){return h(this,void 0,void 0,function(){var n,r,o;return p(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatRoughnessAnisotropyTexture,o=e.geometryCoatTangentTexture,r||o?[4,t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent()]}})})}function Ee(e){return h(this,void 0,void 0,function(){var n,r,o;return p(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatWeightTexture,o=e.coatRoughnessTexture,r||o?[4,t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function Ie(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var Se=function(){function e(e){this.name=Ae,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 n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i,a;return p(this,function(s){switch(s.label){case 0:return e=[],r instanceof t.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 t.OpenPBRMaterial&&r.coatWeight>0?(n=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):n=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):n=!0),n?(i=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(r),this._cachedInternalTexturesMap[i]?[3,3]:[4,Ee(r)]):[3,4]):[3,9];case 2:(o=s.sent())&&(this._cachedInternalTexturesMap[i]=o),s.label=3;case 3:this._cachedInternalTexturesMap[i]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[i],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[i],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?(i=Ce(r),this._mergedTexturesMap[i]?(e.push(this._mergedTexturesMap[i]),[3,7]):[3,5]):[3,8];case 5:return[4,Re(r)];case 6:(a=s.sent())&&(e.push(a),this._mergedTexturesMap[i]=a),s.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c,l;if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var h,p=o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);h=r.clearCoat.useRoughnessFromMainTexture?o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):o._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness);var f=void 0;r.clearCoat.isTintEnabled&&(f=o._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));var d=o._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),m=r.clearCoat.indexOfRefraction;null===(v={coatFactor:r.clearCoat.intensity,coatTexture:null!=p?p:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=h?h:void 0,coatNormalTexture:null!=d?d:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==m?m:void 0}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatColorTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[Ae]=v}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var g=void 0;p=void 0,r.coatWeightTexture&&(g=o._mergedTexturesMap[r.coatWeightTexture.uniqueId]?o._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,p=o._exporter._materialExporter.getTextureInfo(g));var x=void 0,_=void 0;r.coatRoughnessTexture&&(x=o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,_=o._exporter._materialExporter.getTextureInfo(x)),d=o._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),f=o._exporter._materialExporter.getTextureInfo(r.coatColorTexture),m=r.coatIor;var v,T=r.coatDarkening,y=r.coatRoughnessTexture,b=Ce(r),M=o._mergedTexturesMap[b],w=0,A=0,C=void 0;if(r.coatRoughnessAnisotropy>0){if(y||M){var R=M?o._exporter._materialExporter.getTextureInfo(M):null;w=r.coatRoughnessAnisotropy,A=r.geometryCoatTangentAngle,C=R||void 0}else{var E=r.coatRoughness,I=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var S=(a=r.coatRoughness,l=(1-(s=r.coatRoughnessAnisotropy))*(c=(u=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(l),newAnisotropyStrength:Math.min(Math.sqrt((c-u)/Math.max(1-u,1e-4)),1)});E=S.newBaseRoughness,I=S.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=E),w=I,A=r.geometryCoatTangentAngle+.5*Math.PI,C=void 0}r._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(i=o._exporter._glTF).extensionsUsed||(i.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&o._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(v={coatFactor:r.coatWeight,coatTexture:null!=p?p:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=_?_:void 0,coatNormalTexture:null!=d?d:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==m?m:void 0,coatDarkeningFactor:1!==T?T:void 0,coatAnisotropyRotation:A,coatAnisotropyStrength:w,coatAnisotropyTexture:C}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatAnisotropyTexture&&null===v.coatColorTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[Ae]=v}e(n)})},e}();$.RegisterExtension(Ae,function(e){return new Se(e)});var Ve="KHR_materials_diffuse_transmission";function Fe(e,n){var r=n.subSurface,o=null;return r.translucencyIntensityTexture?o=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(o=r.thicknessTexture),o&&!r.useGltfStyleTextures?(t.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(n.name),1),null):o}var Be=function(){function e(e){this.name=Ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var n,o;return p(this,function(i){return n=[],r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)?((o=Fe(e,r))&&n.push(o),r.subSurface.translucencyColorTexture&&n.push(r.subSurface.translucencyColorTexture),[2,n]):[2,n]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(i){var a,s;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var u=r.subSurface,c=Fe(e,r),l=0==u.translucencyIntensity?void 0:u.translucencyIntensity,h=null!==(a=o._exporter._materialExporter.getTextureInfo(c))&&void 0!==a?a:void 0,p=!u.translucencyColor||u.translucencyColor.equalsFloats(1,1,1)?void 0:u.translucencyColor.asArray(),f=null!==(s=o._exporter._materialExporter.getTextureInfo(u.translucencyColorTexture))&&void 0!==s?s:void 0,d={diffuseTransmissionFactor:l,diffuseTransmissionTexture:h,diffuseTransmissionColorFactor:p,diffuseTransmissionColorTexture:f};(h||f)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions=n.extensions||{},n.extensions[Ve]=d}i(n)})},e}();$.RegisterExtension(Ve,function(e){return new Be(e)});var Oe="KHR_materials_dispersion",Ne=function(){function e(){this.name=Oe,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,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i={dispersion:r.subSurface.dispersion};n.extensions=n.extensions||{},n.extensions[Oe]=i}e(n)})},e}();$.RegisterExtension(Oe,function(){return new Ne});var Pe="KHR_materials_emissive_strength",Ue=function(){function e(){this.name=Pe,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,n,r){return h(this,void 0,void 0,function(){var e=this;return p(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){if(!(r instanceof t.PBRMaterial))return o(n);var i=r.emissiveColor.scale(r.emissiveIntensity),a=Math.max.apply(Math,i.asArray());if(a>1){n.emissiveFactor=i.scale(1/a).asArray(),e._wasUsed=!0;var s={emissiveStrength:a};n.extensions||(n.extensions={}),n.extensions[Pe]=s}else n.emissiveFactor=i.asArray();return o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(Pe,function(){return new Ue});var ke="KHR_materials_ior",Le=function(){function e(){this.name=ke,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(e instanceof t.OpenPBRMaterial?1.5!=e.specularIor:e instanceof t.PBRMaterial&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction)},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i={ior:r.indexOfRefraction};n.extensions=n.extensions||{},n.extensions[ke]=i}else r instanceof t.OpenPBRMaterial&&o._isExtensionEnabled(r)&&(o._wasUsed=!0,i={ior:r.specularIor},n.extensions=n.extensions||{},n.extensions[ke]=i);e(n)})},e}();$.RegisterExtension(ke,function(e){return new Le});var We="KHR_materials_iridescence",De=function(){function e(e){this.name=We,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return p(this,function(n){if(e=[],r instanceof t.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 t.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,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var i=o._exporter._materialExporter.getTextureInfo(r.iridescence.texture),a=o._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!=i?i:void 0,iridescenceThicknessTexture:null!=a?a:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[We]=s}else if(r instanceof t.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var s,u=o._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),c=o._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture);null===(s={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=u?u:void 0,iridescenceThicknessTexture:null!=c?c:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[We]=s}e(n)})},e}();$.RegisterExtension(We,function(e){return new De(e)});var ze="KHR_materials_sheen",Ke=function(){function e(e){this.name=ze,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){return p(this,function(e){return r instanceof t.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[2,[r.sheen.texture]]:[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e=this;return p(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var i,a,s,u;if(r instanceof t.PBRMaterial){if(!r.sheen.isEnabled)return void o(n);e._wasUsed=!0,null==n.extensions&&(n.extensions={});var c={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=r.sheen.roughness)&&void 0!==i?i:0};null===c.sheenColorTexture&&null===c.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(c.sheenColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?c.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(c.sheenRoughnessTexture=null!==(u=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==u?u:void 0),n.extensions[ze]=c}o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(ze,function(e){return new Ke(e)});var Ge="KHR_materials_fuzz";function qe(e){return h(this,void 0,void 0,function(){var n,r,o;return p(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.fuzzColorTexture,o=e.fuzzRoughnessTexture,r||o?[4,t.MergeTexturesAsync("FuzzTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(1),r?t.CreateTextureInput(r,2):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function He(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var je=function(){function e(e){this.name=Ge,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 n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i;return p(this,function(a){switch(a.label){case 0:return r instanceof t.OpenPBRMaterial?(e=[],r.fuzzWeight>0?(r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture),n=!1,r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):n=!0),r.fuzzColorTexture&&!n&&e.push(r.fuzzColorTexture),n?(o=function(e){var t=e.fuzzColorTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",r=e.fuzzRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(n,"_FuzzRoughness_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,2]:[4,qe(r)]):[3,3]):[3,3]):[3,4];case 1:(i=a.sent())&&(this._cachedInternalTexturesMap[o]=i),a.label=2;case 2:this._cachedInternalTexturesMap[o]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=He(this._cachedInternalTexturesMap[o],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=He(this._cachedInternalTexturesMap[o],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,n,r){return h(this,void 0,void 0,function(){var e=this;return p(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var i,a,s;if(r instanceof t.OpenPBRMaterial){if(0==r.fuzzWeight)return void o(n);e._wasUsed=!0,null==n.extensions&&(n.extensions={});var u={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};r.fuzzWeightTexture&&(u.fuzzTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==i?i:void 0);var c=void 0;r.fuzzColorTexture&&(c=e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,u.fuzzColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==a?a:void 0);var l=void 0;r.fuzzRoughnessTexture&&(l=e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,u.fuzzRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(l))&&void 0!==s?s:void 0),null===u.fuzzColorTexture&&null===u.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),n.extensions[Ge]=u}o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(Ge,function(e){return new je(e)});var Xe="KHR_materials_specular",Qe=function(){function e(e){this.name=Xe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return p(this,function(n){return e=[],r instanceof t.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,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0,n.extensions=n.extensions||{};var l=null!==(i=o._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==i?i:void 0,h=null!==(a=o._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,p={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:l,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:h};o._hasTexturesExtension(r)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[Xe]=p}else if(r instanceof t.OpenPBRMaterial){n.extensions=n.extensions||{};var f=null!==(s=o._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==s?s:void 0,d=null!==(u=o._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==u?u:void 0,m=1==r.specularWeight?void 0:r.specularWeight,g=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!d&&!f&&void 0===m&&void 0===g)return e(n);o._wasUsed=!0,(p={specularFactor:m,specularTexture:f,specularColorFactor:g,specularColorTexture:d,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(c=o._exporter._glTF).extensionsUsed||(c.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&o._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(f||d)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[Xe]=p}e(n)})},e}();$.RegisterExtension(Xe,function(e){return new Qe(e)});var Ze="KHR_materials_transmission",Ye=function(){function e(e){this.name=Ze,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return p(this,function(n){if(e=[],r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.refractionIntensityTexture&&r.subSurface.useGltfStyleTextures&&e.push(r.subSurface.refractionIntensityTexture),[2,e]}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionWeightTexture&&(e.push(r.transmissionWeightTexture),r.transmissionColorTexture&&e.push(r.transmissionColorTexture)),r.subsurfaceWeight>0&&r.subsurfaceWeightTexture&&e.push(r.subsurfaceWeightTexture));return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e instanceof t.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0||e.subsurfaceWeight>0;if(e instanceof t.PBRMaterial&&!e.unlit){var n=e.subSurface;return n.isRefractionEnabled&&null!=n.refractionIntensity&&0!=n.refractionIntensity||null!=n.refractionIntensityTexture&&n.useGltfStyleTextures}return!1},e.prototype.postExportMaterialAsync=function(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,c,l;return p(this,function(h){return this._isExtensionEnabled(r)?(r instanceof t.PBRMaterial?(this._wasUsed=!0,o=r.subSurface,a=0===o.refractionIntensity?void 0:o.refractionIntensity,s={transmissionFactor:a},o.refractionIntensityTexture&&(o.useGltfStyleTextures?(this._exporter._materialNeedsUVsSet.add(r),(u=this._exporter._materialExporter.getTextureInfo(o.refractionIntensityTexture))&&(s.transmissionTexture=u)):t.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported"))),n.extensions||(n.extensions={}),n.extensions[Ze]=s):r instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,i=(1-r.transmissionWeight)*r.subsurfaceWeight,a=i+r.transmissionWeight,s={transmissionFactor:a},r.transmissionWeightTexture?(this._exporter._materialNeedsUVsSet.add(r),(u=this._exporter._materialExporter.getTextureInfo(r.transmissionWeightTexture))&&(s.transmissionTexture=u)):r.subsurfaceWeightTexture&&(this._exporter._materialNeedsUVsSet.add(r),(c=this._exporter._materialExporter.getTextureInfo(r.subsurfaceWeightTexture))&&(s.transmissionTexture=c)),0!=r.transmissionDepth||r.transmissionColor.equals(t.Color3.White())&&!r.transmissionColorTexture||n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor||(n.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),n.pbrMetallicRoughness.baseColorFactor[0]*=r.transmissionColor.r,n.pbrMetallicRoughness.baseColorFactor[1]*=r.transmissionColor.g,n.pbrMetallicRoughness.baseColorFactor[2]*=r.transmissionColor.b,r.transmissionColorTexture&&!n.pbrMetallicRoughness.baseColorTexture&&(l=this._exporter._materialExporter.getTextureInfo(r.transmissionColorTexture))&&(n.pbrMetallicRoughness.baseColorTexture=l,this._exporter._materialNeedsUVsSet.add(r))),n.extensions||(n.extensions={}),n.extensions[Ze]=s),[2,n]):[2,n]})})},e}();$.RegisterExtension(Ze,function(e){return new Ye(e)});var Je="KHR_materials_unlit",$e=function(){function e(){this.name=Je,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,n,r){var o=this;return new Promise(function(e){var i=!1;r instanceof t.PBRMaterial?i=r.unlit:r instanceof t.StandardMaterial&&(i=r.disableLighting),i&&(o._wasUsed=!0,null==n.extensions&&(n.extensions={}),n.extensions[Je]={}),e(n)})},e}();$.RegisterExtension(Je,function(){return new $e});var et="KHR_materials_volume",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,n,r){return h(this,void 0,void 0,function(){var e;return p(this,function(n){if(e=[],r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0||r.subsurfaceWeight>0)&&r.geometryThicknessTexture&&e.push(r.geometryThicknessTexture);return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var n=e.subSurface;return!(!n.isRefractionEnabled&&!n.isTranslucencyEnabled)&&(null!=n.maximumThickness&&0!=n.maximumThickness||null!=n.tintColorAtDistance&&n.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=n.tintColor&&n.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var s=r.subSurface,u={thicknessFactor:p=0==s.maximumThickness?void 0:s.maximumThickness,thicknessTexture:h=null!==(i=o._exporter._materialExporter.getTextureInfo(s.thicknessTexture))&&void 0!==i?i:void 0,attenuationDistance:s.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:s.tintColorAtDistance,attenuationColor:V=s.tintColor.equalsFloats(1,1,1)?void 0:s.tintColor.asArray()};o._hasTexturesExtension(r)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions=n.extensions||{},n.extensions[et]=u}else if(r instanceof t.OpenPBRMaterial){var c=r.transmissionWeight>0&&!r.geometryThinWalled,l=r.subsurfaceWeight>0&&!r.geometryThinWalled;if(c||l){o._wasUsed=!0;var h,p=r.geometryThickness;(h=null!==(a=o._exporter._materialExporter.getTextureInfo(r.geometryThicknessTexture))&&void 0!==a?a:void 0)&&o._exporter._materialNeedsUVsSet.add(r);var f=void 0,d=t.Color3.White().asArray();if(c&&r.transmissionDepth>0){var m=1/r.transmissionDepth,g=new t.Vector3(-Math.log(r.transmissionColor.r)*m,-Math.log(r.transmissionColor.g)*m,-Math.log(r.transmissionColor.b)*m),x=new t.Vector3(r.transmissionScatter.r*m,r.transmissionScatter.g*m,r.transmissionScatter.b*m),_=g.subtract(x),v=Math.min(_.x,_.y,_.z);v<0&&(_.x=_.x-v,_.y=_.y-v,_.z=_.z-v),g=_.add(x),f=1/Math.max(g.x,g.y,g.z),d[0]=Math.exp(-g.x*f),d[1]=Math.exp(-g.y*f),d[2]=Math.exp(-g.z*f)}else f=Number.MAX_VALUE,d[0]=1,d[1]=1,d[2]=1;var T=1,y=t.Color3.White().asArray();if(l){var b=r.subsurfaceRadius,M=r.subsurfaceRadiusScale,w=new t.Vector3(M.r,M.g,M.b).multiplyByFloats(b,b,b),A=new t.Vector3(1/Math.max(w.x,1e-6),1/Math.max(w.y,1e-6),1/Math.max(w.z,1e-6));T=1/Math.max(A.x,A.y,A.z),y[0]=Math.exp(-A.x*T),y[1]=Math.exp(-A.y*T),y[2]=Math.exp(-A.z*T)}var C=(1-r.transmissionWeight)*r.subsurfaceWeight,R=C+r.transmissionWeight,E=1/Math.max(R,1e-6),I=r.transmissionWeight*E,S=C*E,V=d.map(function(e,t){return e*I+y[t]*S});u={thicknessFactor:p,thicknessTexture:h,attenuationDistance:f*I+T*S,attenuationColor:V},n.extensions=n.extensions||{},n.extensions[et]=u}}e(n)})},e}();$.RegisterExtension(et,function(e){return new tt(e)});var nt="KHR_materials_volume_scatter",rt=function(){function e(e){this.name=nt,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,n,r){return h(this,void 0,void 0,function(){var e;return p(this,function(n){return e=[],r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionScatterTexture&&e.push(r.transmissionScatterTexture),r.subsurfaceWeight>0&&r.subsurfaceColorTexture&&e.push(r.subsurfaceColorTexture)),[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var n=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),r=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!n&&!r)},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.OpenPBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i=t.Vector3.Zero(),a=0;if(r.transmissionWeight>0)x=new t.Vector3(r.transmissionScatter.r,r.transmissionScatter.g,r.transmissionScatter.b),_=new t.Vector3(Math.sqrt(1-x.x),Math.sqrt(1-x.y),Math.sqrt(1-x.z)),T=(v=new t.Vector3(1,1,1)).subtract(_),y=v.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(_)),b=v.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(_)),i=T.multiplyInPlace(y).divideInPlace(b),a=r.transmissionScatterAnisotropy;var s=t.Vector3.Zero(),u=0;r.subsurfaceWeight>0&&(s.set(r.subsurfaceColor.r,r.subsurfaceColor.g,r.subsurfaceColor.b),u=r.subsurfaceScatterAnisotropy);var c=(1-r.transmissionWeight)*r.subsurfaceWeight,l=c+r.transmissionWeight,h=1/Math.max(l,1e-6),p=r.transmissionWeight*h,f=c*h,d={multiscatterColorFactor:i.multiplyByFloats(p,p,p).addInPlace(s.multiplyByFloats(f,f,f)).asArray(),scatterAnisotropy:a*p+u*f};if(r.subsurfaceWeight>0&&r.subsurfaceColorTexture){o._exporter._materialNeedsUVsSet.add(r);var m=o._exporter._materialExporter.getTextureInfo(r.subsurfaceColorTexture);m&&(d.multiscatterColorTexture=m)}else if(r.transmissionWeight>0&&r.transmissionScatterTexture){o._exporter._materialNeedsUVsSet.add(r);var g=o._exporter._materialExporter.getTextureInfo(r.transmissionScatterTexture);g&&(d.multiscatterColorTexture=g)}n.extensions=n.extensions||{},n.extensions[nt]=d}var x,_,v,T,y,b;e(n)})},e}();$.RegisterExtension(nt,function(e){return new rt(e)},101);var ot="KHR_materials_diffuse_roughness",it=function(){function e(e){this.name=ot,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,n,r){return h(this,void 0,void 0,function(){var e;return p(this,function(n){if(e=[],r instanceof t.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),[2,e]}else if(r instanceof t.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i=null,a=null;if(r instanceof t.PBRBaseMaterial?(i=r._baseDiffuseRoughness,a=r._baseDiffuseRoughnessTexture):r instanceof t.OpenPBRMaterial&&(i=r.baseDiffuseRoughness,a=r.baseDiffuseRoughnessTexture),i){o._wasUsed=!0,n.extensions=n.extensions||{};var s=o._exporter._materialExporter.getTextureInfo(a),u={diffuseRoughnessFactor:i,diffuseRoughnessTexture:null!=s?s:void 0};null!==u.diffuseRoughnessTexture&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[ot]=u,e(n)}else e(n)})},e}();$.RegisterExtension(ot,function(e){return new it(e)});var at="KHR_materials_openpbr",st=function(){function e(){this.name=at,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,n,r){var o=this;return new Promise(function(e){r instanceof t.OpenPBRMaterial&&(o._wasUsed=!0,n.extensions=n.extensions||{},n.extensions[at]={}),e(n)})},e}();$.RegisterExtension(at,function(e){return new st});var ut="KHR_texture_transform",ct=function(){function e(){this.name=ut,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,n,r){if(r.getScene()||t.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(t.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 o={},i=!1;if(0===r.uOffset&&0===r.vOffset||(o.offset=[r.uOffset,r.vOffset],i=!0),1===r.uScale&&1===r.vScale||(o.scale=[r.uScale,r.vScale],i=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void t.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(ut,"."));t.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(ut,".")),o.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,a=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*i,h=o*a;return[t+(l*(1-u)+h*c),n+(h*(1-u)-l*c)]}(r)}o.rotation=-r.wAng,i=!0}0!==r.coordinatesIndex&&(o.texCoord=r.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,n.extensions||(n.extensions={}),n.extensions[ut]=o)}},e}();$.RegisterExtension(ut,function(){return new ct});var lt="KHR_texture_basisu",ht=function(){function e(e){this.name=lt,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,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[lt]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(lt,function(e){return new ht(e)});var pt="EXT_texture_webp",ft=function(){function e(e){this.name=pt,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,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[pt]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(pt,function(e){return new ft(e)});var dt="EXT_texture_avif",mt=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,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[dt]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(dt,function(e){return new mt(e)});var gt={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:oe,EXT_texture_avif:mt,EXT_texture_webp:ft,KHR_draco_mesh_compression:se,KHR_lights_punctual:pe,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:we,KHR_materials_coat:Se,KHR_materials_diffuse_roughness:it,KHR_materials_diffuse_transmission:Be,KHR_materials_dispersion:Ne,KHR_materials_emissive_strength:Ue,KHR_materials_fuzz:je,KHR_materials_ior:Le,KHR_materials_iridescence:De,KHR_materials_openpbr:st,KHR_materials_sheen:Ke,KHR_materials_specular:Qe,KHR_materials_transmission:Ye,KHR_materials_unlit:$e,KHR_materials_volume:tt,KHR_materials_volume_scatter:rt,KHR_texture_basisu:ht,KHR_texture_transform:ct},xt={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:oe,EXT_texture_avif:mt,EXT_texture_webp:ft,GLTF2Export:ee,GLTFData:i,KHR_draco_mesh_compression:se,KHR_lights_punctual:pe,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:we,KHR_materials_coat:Se,KHR_materials_diffuse_roughness:it,KHR_materials_diffuse_transmission:Be,KHR_materials_dispersion:Ne,KHR_materials_emissive_strength:Ue,KHR_materials_fuzz:je,KHR_materials_ior:Le,KHR_materials_iridescence:De,KHR_materials_openpbr:st,KHR_materials_sheen:Ke,KHR_materials_specular:Qe,KHR_materials_transmission:Ye,KHR_materials_unlit:$e,KHR_materials_volume:tt,KHR_materials_volume_scatter:rt,KHR_texture_basisu:ht,KHR_texture_transform:ct,_ConvertToGLTFPBRMetallicRoughness:y,_SolveMetallic:T},_t=function(){function e(){}return e.CreateSTL=function(e,n,r,o,i,a,s,u){void 0===n&&(n=!0),void 0===r&&(r="stlmesh"),void 0===o&&(o=!1),void 0===i&&(i=!0),void 0===a&&(a=!1),void 0===s&&(s=!1),void 0===u&&(u=!1);var c=function(e,n,r){var o=[3*e[r],3*e[r+1],3*e[r+2]],i=[new t.Vector3(n[o[0]],n[o[0]+2],n[o[0]+1]),new t.Vector3(n[o[1]],n[o[1]+2],n[o[1]+1]),new t.Vector3(n[o[2]],n[o[2]+2],n[o[2]+1])],a=i[0].subtract(i[1]),s=i[2].subtract(i[1]);return{v:i,n:t.Vector3.Cross(s,a).normalize()}},l=function(e,t,n,r){return t=h(e,t,n.x,r),t=h(e,t,n.y,r),h(e,t,n.z,r)},h=function(e,t,n,r){return e.setFloat32(t,n,r),t+4},p=function(e){if(s){var n=e;e instanceof t.InstancedMesh&&(n=e.sourceMesh);var r=n.getVerticesData(t.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var o=t.Vector3.Zero(),i=void 0;for(i=0;i<r.length;i+=3)t.Vector3.TransformCoordinatesFromFloatsToRef(r[i],r[i+1],r[i+2],e.computeWorldMatrix(!0),o).toArray(r,i);return r}return e.getVerticesData(t.VertexBuffer.PositionKind)||[]};s&&(a=!0);var f="",d=0,m=0;if(o){for(var g=0;g<e.length;g++)d+=(T=(_=e[g]).getIndices())?T.length/3:0;var x=new ArrayBuffer(84+50*d);m+=80,(f=new DataView(x)).setUint32(m,d,i),m+=4}else u||(f="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!o&&u&&(f+="solid "+_.name+"\r\n"),!a&&_ instanceof t.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=p(_),T=_.getIndices()||[],y=0;y<T.length;y+=3){var b=c(T,v,y);o?(m=l(f,m,b.n,i),m=l(f,m,b.v[0],i),m=l(f,m,b.v[1],i),m=l(f,m,b.v[2],i),m+=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")}!o&&u&&(f+="endsolid "+name+"\r\n")}if(o||u||(f+="endsolid stlmesh"),n){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}(),vt={__proto__:null,STLExport:_t};function Tt(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],i=0;i<e.length/n;i++){var a=e[i*n]*(r?-1:1),s=e[i*n+1],u=e[i*n+2];o.push("(".concat(a.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function yt(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],i=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-i).toPrecision(t.precision),")"))}return n.join(", ")}function bt(e,n,r,o){var i=function(e,n,r,o){var i=e.getVerticesData(t.VertexBuffer.PositionKind),a=e.getVerticesData(t.VertexBuffer.NormalKind);if(i&&a)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(r,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,n=e.getIndices(),r=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==n)for(var i=0;i<r;i++)o.push(n[i]);else for(i=0;i<r;i++)o.push(i);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(Tt(a,n,void 0,o),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(Tt(i,n,void 0,o),"]\n ").concat(function(e,n){for(var r="",o=0;o<4;o++){var i=o>0?o:"",a=e.getVerticesData(t.VertexBuffer.UVKind+(i?i+1:""));a&&(r+="\n\t\ttexCoord2f[] primvars:st".concat(i," = [").concat(yt(a,n),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var s=e.getVerticesData(t.VertexBuffer.ColorKind);return s&&(r+="\n\tcolor3f[] primvars:displayColor = [".concat(Tt(s,n,s.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),r}(e,n),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,n,r,o);return'\n def "Geometry"\n {\n '.concat(i,"\n }\n ")}function Mt(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 wt(e){var t=e.m;return"( ".concat(At(t,0),", ").concat(At(t,4),", ").concat(At(t,8),", ").concat(At(t,12)," )")}function At(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function Ct(e,t){var n="Object_"+e.uniqueId,r=wt(t);return'def Xform "'.concat(n,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(r,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Rt(e){switch(e){case t.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case t.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case t.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function Et(e){return"(".concat(e.x,", ").concat(e.y,")")}function It(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function St(e,n,r,o,i,a){var s,u,c=e.getInternalTexture().uniqueId+"_"+e.invertY,l="image/jpeg"===(e.mimeType||t.GetMimeType(null!==(u=null===(s=e.getInternalTexture())||void 0===s?void 0:s.url)&&void 0!==u?u:""))?"jpg":"png";i[c]={texture:e,ext:l};var h=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",p=new t.Vector2(e.uScale,e.vScale),f=new t.Vector2(e.uOffset,e.vOffset),d=e.wAng,m=Math.sin(d),g=Math.cos(d);return f.y=1-f.y-p.y,f.x+=m*p.x,f.y+=(1-g)*p.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(h,'"\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(n.uniqueId,"/PrimvarReader_").concat(r,".outputs:result>\n float inputs:rotation = ").concat((d*(180/Math.PI)).toFixed(a.precision),"\n float2 inputs:scale = ").concat(Et(p),"\n float2 inputs:translation = ").concat(Et(f),'\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(c,".").concat(l,"@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(n.uniqueId,"/Transform2d_").concat(r,".outputs:result>\n ").concat(o?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(o):"",'\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(n.needAlphaBlending()||n.needAlphaTesting()?"float outputs:a":"","\n }")}function Vt(e,n,r){var o="\t\t\t",i=[],a=[],s=function(e){var n,r,o={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 t.StandardMaterial?c(c({},o),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof t.PBRBaseMaterial?c(c({},o),{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!==(n=e._roughness)&&void 0!==n?n: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}):o}(e),u=s.diffuseMap,l=s.diffuse,h=s.alphaCutOff,p=s.emissiveMap,f=s.emissive,d=s.normalMap,m=s.roughnessMap,g=s.roughnessChannel,x=s.roughness,_=s.metalnessMap,v=s.metalnessChannel,T=s.metalness,y=s.aoMap,b=s.aoMapChannel,M=s.aoMapIntensity,w=s.alphaMap,A=s.ior,C=s.clearCoatEnabled,R=s.clearCoat,E=s.clearCoatMap,I=s.clearCoatRoughness,S=s.clearCoatRoughnessMap;return null!==u?(i.push("".concat(o,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:a>")),i.push("".concat(o,"float inputs:opacityThreshold = ").concat(h))),a.push(St(u,e,"diffuse",l,n,r))):i.push("".concat(o,"color3f inputs:diffuseColor = ").concat(It(l||t.Color3.White()))),null!==p?(i.push("".concat(o,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_emissive.outputs:rgb>")),a.push(St(p,e,"emissive",f,n,r))):f&&f.toLuminance()>0&&i.push("".concat(o,"color3f inputs:emissiveColor = ").concat(It(f))),null!==d&&(i.push("".concat(o,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(d.uniqueId,"_normal.outputs:rgb>")),a.push(St(d,e,"normal",null,n,r))),null!==y&&(i.push("".concat(o,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(y.uniqueId,"_occlusion.outputs:").concat(b,">")),a.push(St(y,e,"occlusion",new t.Color3(M,M,M),n,r))),null!==m?(i.push("".concat(o,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(m.uniqueId,"_roughness.outputs:").concat(g,">")),a.push(St(m,e,"roughness",new t.Color3(x,x,x),n,r))):i.push("".concat(o,"float inputs:roughness = ").concat(x)),null!==_?(i.push("".concat(o,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(_.uniqueId,"_metallic.outputs:").concat(v,">")),a.push(St(_,e,"metallic",new t.Color3(T,T,T),n,r))):i.push("".concat(o,"float inputs:metallic = ").concat(T)),null!==w?(i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(w.uniqueId,"_opacity.outputs:r>")),i.push("".concat(o,"float inputs:opacityThreshold = 0.0001")),a.push(St(w,e,"opacity",null,n,r))):i.push("".concat(o,"float inputs:opacity = ").concat(e.alpha)),C&&(null!==E?(i.push("".concat(o,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(E.uniqueId,"_clearcoat.outputs:r>")),a.push(St(E,e,"clearcoat",new t.Color3(R,R,R),n,r))):i.push("".concat(o,"float inputs:clearcoat = ").concat(R)),null!==S?(i.push("".concat(o,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(S.uniqueId,"_clearcoatRoughness.outputs:g>")),a.push(St(S,e,"clearcoatRoughness",new t.Color3(I,I,I),n,r))):i.push("".concat(o,"float inputs:clearcoatRoughness = ").concat(I))),i.push("".concat(o,"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(i.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 Ft(e){var n,r;e.computeWorldMatrix(!0);for(var o=e.getWorldMatrix().clone(),i=e.getScene().useRightHandedSystem,a=null!==(r=null===(n=e.material)||void 0===n?void 0:n._getEffectiveOrientation(e))&&void 0!==r?r:e.sideOrientation,s=!i,u=e.parent;u;){if(R(u,i)&&null===u.parent){i||(o.multiplyToRef(u.getWorldMatrix().invert(),o),a=a===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),s=!1;break}u=u.parent}return o.determinant()<0&&t.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:o,windingOrder:a===t.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:s}}function Bt(e){return h(this,void 0,void 0,function(){var n,r,o,i,a;return p(this,function(s){switch(s.label){case 0:if(!(n=e.getInternalTexture())||1!==n.source)return[2,null];r=n._buffer,i=e.mimeType,s.label=1;case 1:return s.trys.push([1,12,,13]),r?[3,3]:[4,t.Tools.LoadFileAsync(n.url)];case 2:return o=s.sent(),i=t.GetMimeType(n.url)||i,[3,11];case 3:return ArrayBuffer.isView(r)?(o=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,11]):[3,4];case 4:return r instanceof ArrayBuffer?(o=r,[3,11]):[3,5];case 5:return r instanceof Blob?[4,r.arrayBuffer()]:[3,7];case 6:return o=s.sent(),i=r.type||i,[3,11];case 7:return"string"!=typeof r?[3,9]:[4,t.Tools.LoadFileAsync(r)];case 8:return o=s.sent(),i=t.GetMimeType(r)||i,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,t.Tools.LoadFileAsync(r.src)]:[3,11];case 10:o=s.sent(),i=t.GetMimeType(r.src)||i,s.label=11;case 11:return[3,13];case 12:return s.sent(),[2,null];case 13:return o&&!i&&n.url&&(a=n.url.match(/^data:([^;,]+)/),i=a?a[1]:t.GetMimeType(n.url)),o&&i?[2,{data:o,mimeType:i}]:[2,null]}})})}function Ot(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,l,h,f,d,m,g,x,_,v,T,y,b,M,w,A,C,R,E,I,S,V,F,B,O,N,P,U,k,L,W;return p(this,function(p){switch(p.label){case 0:return o=c({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},n),"undefined"!=typeof fflate?[3,2]:[4,t.Tools.LoadScriptAsync(o.fflateUrl)];case 1:p.sent(),p.label=2;case 2:for((i={})[o.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 ")}(o),s={},u=0,l=e.meshes;u<l.length;u++)0!==(h=l[u]).getTotalVertices()&&(d=(f=h).geometry,(m=f.material)&&d&&(!r||r(f))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(m.getClassName())?(g="geometries/Geometry_"+d.uniqueId+".usda",x=Ft(f),_=x.matrix,v=x.windingOrder,T=x.convertToRightHanded,g in i||(y=bt(d,o,v,T),i[g]=Mt(y)),m.uniqueId in s||(s[m.uniqueId]=m),a+=Ct(f,_)):t.Tools.Warn("USDZExportAsync does not support this material type: "+m.getClassName())));for(A in e.activeCamera&&o.exportCamera&&(a+=function(e,n){var r="Camera_"+e.uniqueId,o=wt(t.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===t.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(o,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(n.precision),", ").concat(e.maxZ.toPrecision(n.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(n.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(n.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var i=e.getEngine().getAspectRatio(e),a=n.cameraSensorWidth||35;return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(o,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(n.precision),", ").concat(e.maxZ.toPrecision(n.precision),")\n\t\t\tfloat focalLength = ").concat((a/(2*Math.tan(.5*e.fov))).toPrecision(n.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((a*i).toPrecision(n.precision),"\n\t\t\tfloat verticalAperture = ").concat((a/i).toPrecision(n.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,o)),a+="\n }\n }",a+=function(e,t,n){var r=[];for(var o in e){var i=e[o];r.push(Vt(i,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(s,b={},o),a+="\n }",i[o.modelFileName]=fflate.strToU8(a),w=[],M=b)w.push(A);C=0,p.label=3;case 3:return C<w.length?(A=w[C])in M?(E=b[R=A],I=E.texture,S=E.ext,[4,Bt(I)]):[3,8]:[3,9];case 4:return(V=p.sent())?(i["textures/Texture_".concat(R,".").concat(S)]=new Uint8Array(V.data),[3,8]):[3,5];case 5:return F=I.getSize(),[4,t.GetTextureDataAsync(I)];case 6:return B=p.sent(),[4,t.DumpTools.DumpDataAsync(F.width,F.height,B,"image/png",void 0,!1,!0)];case 7:O=p.sent(),i["textures/Texture_".concat(R,".").concat(S)]=new Uint8Array(O).slice(),p.label=8;case 8:return C++,[3,3];case 9:for(P in N=0,i)(U=i[P])&&(k=34+P.length,4!=(L=63&(N+=k))&&(W=new Uint8Array(64-L),i[P]=[U,{extra:{12345:W}}]),N=U.length);return[2,fflate.zipSync(i,{level:0})]}})})}var Nt={__proto__:null,USDZExportAsync:Ot},Pt=function(){function e(){}return e.Export=function(e,n,r){var o;if(void 0===n&&(n=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var i=n;n&&0!==n.length||(i=e.animations.map(function(e){return e.name}));for(var a=null,s=0,u=i;s<u.length;s++){var c=u[s],l=e.getAnimationRange(c);l&&(a=a?new t.AnimationRange("animation-range",Math.min(a.from,l.from),Math.max(a.to,l.to)):l)}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 h=r||1/((null===(o=e.animations[0])||void 0===o?void 0:o.framePerSecond)||30),p=this._BuildBoneHierarchy(e,i),f=0,d=0,m=p;d<m.length;d++){var g=m[d];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)/h)+1);var x="";return x+="HIERARCHY\n",x+=this._ExportHierarchy(p,0),x+="MOTION\n",x+="Frames: ".concat(f,"\n"),(x+="Frame Time: ".concat(h.toFixed(6),"\n"))+this._ExportMotionData(p,f,0,i)},e._BuildBoneHierarchy=function(e,t){for(var n,r,o=new Map,i=[],a=0,s=e.bones;a<s.length;a++){var u={bone:h=s[a],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 p=0,f=h.animations;p<f.length;p++){var d=f[p];t.includes(d.name)&&("position"===d.targetProperty?(u.hasPositionChannels=!0,(n=u.positionKeys).push.apply(n,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(r=u.rotationKeys).push.apply(r,d.getKeys())))}if(h.getParent()){var m=o.get(h.getParent());m&&m.children.push(u)}else i.push(u)}return i},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,i=e;o<i.length;o++){var a=i[o],s=a.bone;if(this._IsEndSite(a)){n+="".concat(r,"End Site\n"),n+="".concat(r,"{\n");var u=this._GetBoneOffset(s);n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),n+="".concat(r,"}\n")}else{n+="".concat(0===t?"ROOT":"".concat(r,"JOINT")," ").concat(s.name,"\n"),n+="".concat(r,"{\n"),u=this._GetBoneOffset(s),n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];a.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),a.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),a.children.length>0&&(n+=this._ExportHierarchy(a.children,t+1)),n+="".concat(r,"}\n")}}return n},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return t.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",i=0;i<t;i++){var a=[];this._CollectFrameValues(e,i+n,a,r),o+=a.map(function(e){return e.toFixed(6)}).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,i=e;o<i.length;o++){var a=i[o];if(!this._IsEndSite(a)){if(a.hasPositionChannels){var s=this._GetPositionAtFrameIndex(a.positionKeys,t);n.push(s.x,s.y,s.z)}if(a.hasRotationChannels){var u=this._GetRotationAtFrameIndex(a.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}a.children.length>0&&this._CollectFrameValues(a.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,n){return 0===e.length?t.Vector3.Zero():e[Math.max(0,Math.min(n,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,n){return 0===e.length?t.Quaternion.Identity():e[Math.max(0,Math.min(n,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var n=new t.Matrix;e.toRotationMatrix(n);var r,o,i,a=n.m,s=Math.sqrt(a[0]*a[0]+a[1]*a[1]);return s>t.Epsilon?(r=Math.atan2(a[6],a[10]),o=Math.atan2(-a[2],s),i=Math.atan2(a[1],a[0])):(r=Math.atan2(-a[9],a[5]),o=Math.atan2(-a[2],s),i=0),new t.Vector3(t.Tools.ToDegrees(r),t.Tools.ToDegrees(o),t.Tools.ToDegrees(i))},e}(),Ut={__proto__:null,BVHExporter:Pt};function kt(e){return"string"==typeof(null==e?void 0:e.name)}var Lt=Symbol("__xml:meta$__"),Wt=Symbol("__xml:name$__");function Dt(e,t){var n,r=e.constructor;(null!==(n=r[Lt])&&void 0!==n?n:r[Lt]=[]).push(t)}function zt(e){return function(t){t[Wt]=e}}function Kt(){return function(e,t){return Dt(e,{kind:"none",prop:t,ignore:!0})}}function Gt(e){return function(t,n){return Dt(t,c({kind:"attr",prop:n},e))}}function qt(e){return function(t,n){return Dt(t,c({kind:"elem",prop:n},e))}}function Ht(e){var t,n;return null!==(n=null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Lt])&&void 0!==n?n:[]}function jt(e){var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Wt])||void 0}function Xt(e){return/^[A-Za-z_][A-Za-z0-9._-]*$/.test(e)}function Qt(e){if(kt(e))return e;var t=(null!=e?e:"").trim();if(!t)return{name:""};var n=t.indexOf(":");if(-1===n)return{name:t};if(-1!==t.indexOf(":",n+1))return{name:t};var r=t.slice(0,n),o=t.slice(n+1);return Xt(r)&&Xt(o)?{ns:r,name:o}:{name:t}}function Zt(e,t){return t?"".concat(t,":").concat(e):e}var Yt=Object.freeze({eps:1e-6,maxDecimalsCap:15,trimTrailingZeros:!0,allowScientific:!1,snapNearZero:!0}),Jt=Object.freeze({number:Yt});function $t(e){var t,n,r,o,i,a,s=null!==(t=null==e?void 0:e.eps)&&void 0!==t?t:Yt.eps;return{eps:s,maxDecimalsCap:null!==(n=null==e?void 0:e.maxDecimalsCap)&&void 0!==n?n:Yt.maxDecimalsCap,trimTrailingZeros:null!==(r=null==e?void 0:e.trimTrailingZeros)&&void 0!==r?r:Yt.trimTrailingZeros,fixedDecimals:null==e?void 0:e.fixedDecimals,allowScientific:null!==(o=null==e?void 0:e.allowScientific)&&void 0!==o?o:Yt.allowScientific,snapNearZero:null!==(i=null==e?void 0:e.snapNearZero)&&void 0!==i?i:Yt.snapNearZero,zeroThreshold:null!==(a=null==e?void 0:e.zeroThreshold)&&void 0!==a?a:s,perAttributeEps:null==e?void 0:e.perAttributeEps}}function en(e){return{number:$t(null==e?void 0:e.number)}}var tn=function(){function e(e){if(this.o=e,this._o=e.number,!Number.isFinite(this._o.eps)||this._o.eps<=0)throw new Error("opts.eps must be a finite, positive number")}return e.prototype.toString=function(e){var t,n,r,o;if(!Number.isFinite(e))throw new Error("Cannot format non-finite number: ".concat(e));var i,a=this._o,s=this._clampInt(null!==(t=a.maxDecimalsCap)&&void 0!==t?t:15,0,20),u=null===(n=a.trimTrailingZeros)||void 0===n||n,c=null===(r=a.snapNearZero)||void 0===r||r,l=null!==(o=a.zeroThreshold)&&void 0!==o?o:a.eps,h=1/a.eps,p=Math.round(e*h)/h;if(Object.is(p,-0)&&(p=0),c&&Math.abs(p)<=l&&(p=0),i=void 0!==a.fixedDecimals?this._clampInt(a.fixedDecimals,0,s):this._clampInt(Math.ceil(-Math.log10(a.eps)),0,s),a.allowScientific,0===i)return String(Math.trunc(p));var f=p.toFixed(i);if(u&&void 0===a.fixedDecimals&&(f=f.replace(/(\.\d*?[1-9])0+$/,"$1").replace(/\.0+$/,"").replace(/\.$/,"")),/[eE]/.test(f))throw new Error("Scientific notation not allowed in XML output: ".concat(f));return f},e.prototype._clampInt=function(e,t,n){return Number.isFinite(e)?(e=Math.trunc(e),Math.max(t,Math.min(n,e))):t},e}();function nn(e){return e instanceof Date}function rn(e){return"string"==typeof e}function on(e){return"number"==typeof e}function an(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||nn(e)}function sn(e){return"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||nn(e)}var un,cn=function(){function e(e,t){this._ns=new Map,this._prefixCount=0,this._builder=e,this._format=en(t),this._nFmt=new tn(this._format)}return e.prototype.withNamespace=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=0,r=e;n<r.length;n++){var o=r[n];this._assignNamespace(o)}return this},e.prototype.serialize=function(e,t){if(!(t=null!=t?t:jt(e)))throw new Error("can not find name for given object");var n=Qt(t);n.ns&&this._assignNamespace(n.ns,"xmlns"),this._gatherNamespaces(e,new WeakSet);for(var r=this._builder.ele(null,n.name),o=0,i=Array.from(this._ns.entries());o<i.length;o++){var a=i[o],s=a[0],u=a[1];r.att("xmlns",u,s)}this._writeObjectContent(r,e,(new WeakSet).add(e)),this._builder.end()},e.prototype._writeObject=function(e,t,n){if(!n.has(t))if(n.add(t),Array.isArray(t))for(var r=0,o=t;r<o.length;r++){var i=o[r];sn(i)||(rn(i)?this._builder.text(i):this._writeObject(e,i,n))}else{var a=jt(t);if(a){var s=Qt(a),u=this._getPrefix(s),c=Zt(s.name,u);e.ele(null,c),this._writeObjectContent(e,t,n),this._builder.end()}}},e.prototype._getPrefix=function(e){if(e.ns){var t=this._ns.get(e.ns.toLowerCase());if("xmlns"!==t)return t}},e.prototype._writeObjectContent=function(e,t,n){for(var r,o,i,a=null!==(r=Ht(t))&&void 0!==r?r:[],s=new Map,u=0,c=a;u<c.length;u++){var l=c[u],h=null!==(o=s.get(l.prop))&&void 0!==o?o:[];h.push(l),s.set(l.prop,h)}for(var p=Object.keys(t).sort(function(e,t){var n,r,o=(null!==(n=s.get(e))&&void 0!==n?n:[]).some(function(e){return"attr"===e.kind}),i=(null!==(r=s.get(t))&&void 0!==r?r:[]).some(function(e){return"attr"===e.kind});return o===i?0:o?-1:1}),f=0,d=p;f<d.length;f++){var m=d[f],g=t[m];if(null!=g){var x=s.get(m);if(x){var _=x.some(function(e){return!0===e.ignore||"none"===e.kind});if(_)continue;for(var v=0,T=x;v<T.length;v++){var y=null!==(i=(l=T[v]).name)&&void 0!==i?i:l.prop.toLowerCase();if(y&&"attr"===l.kind){var b=null;if(on(g)&&this._nFmt&&(b=this._nFmt.toString(g)),l.formatter&&(b=new l.formatter(this._format).toString(g)),b=null!=b?b:g.toString()){var M=Qt(y),w=this._getPrefix(M),A=Zt(M.name,w);e.att(null,A,b)}}}}else sn(g)||(rn(g)?this._builder.text(g):this._writeObject(e,g,n))}}},e.prototype._gatherNamespaces=function(e,t){var n,r;if(!t.has(e))if(t.add(e),Array.isArray(e))for(var o=0,i=e;o<i.length;o++){var a=i[o];an(a)||this._gatherNamespaces(a,t)}else{var s=jt(e);s&&this._assignNamespace(s);for(var u=null!==(n=Ht(e))&&void 0!==n?n:[],c=new Map,l=0,h=u;l<h.length;l++){var p=h[l],f=null!==(r=c.get(p.prop))&&void 0!==r?r:[];f.push(p),c.set(p.prop,f)}for(var d=[],m=0,g=Object.keys(e);m<g.length;m++){var x=g[m],_=e[x];if(null!=_){var v=c.get(x);if(v){var T=v.some(function(e){return!0===e.ignore||"none"===e.kind});if(T)continue;for(var y=0,b=v;y<b.length;y++)(p=b[y]).name&&this._assignNamespace(p.name)}d.push(_)}}for(var M=0,w=d;M<w.length;M++){var A=w[M];an(A)||this._gatherNamespaces(A,t)}}},e.prototype._assignNamespace=function(e,t){var n=Qt(e);if(null==n?void 0:n.ns){var r=n.ns.toLowerCase();this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r))}else"xmlns"===t&&(r=n.name.toLowerCase(),this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r)))},e.prototype._buildNsPrefix=function(e){var t,n=!1;do{t="ns".concat(this._prefixCount++);for(var r=0,o=Array.from(this._ns.values());r<o.length;r++)if(o[r]===t){n=!0;break}}while(n);return t},e}(),ln=function(){function e(){}return e.OpenTag="<",e.CloseTag=">",e.Slash="/",e.Question="?",e.Quote='"',e.Equal="=",e.Space=" ",e.Semicolon=":",e.Dec="<?xml",e.Xml="xml",e.Xmlns="xmlns",e.Xsi="xsi",e.VersionKeyword="version",e.EncodingKeyword="encoding",e.StandaloneKeyword="standalone",e}();e.TokenType=void 0,(un=e.TokenType||(e.TokenType={}))[un.Declaration=0]="Declaration",un[un.Tag=1]="Tag",un[un.Attribute=2]="Attribute",un[un.Text=3]="Text";var hn,pn,fn=function(){function t(e){this._ctxStack=[],this._d=0,this._w=e}return t.prototype.dec=function(e,t,n){return this._w.write(ln.Dec),this._writeAttStr(ln.VersionKeyword,e),t&&this._writeAttStr(ln.EncodingKeyword,t),void 0!==n&&this._writeAttStr(ln.StandaloneKeyword,n?"yes":"no"),this._w.write(ln.Question,ln.CloseTag),this},t.prototype.att=function(t,n,r){var o=this._peekContext();if(!o)throw new Error("att() without open element");if(o.closed)throw new Error("att() after start tag closed for <".concat(o.name,">"));if(this._isXmlnsDecl(t,n)){if(n===ln.Xmlns)o.defaultNs=r,this._registerNamespace(o,"",r),this._writeAttStr(ln.Xmlns,r);else if(t)this._registerNamespace(o,n,r),this._writeAttStr("".concat(t,":").concat(n),r);else{var i=n.slice(6);this._registerNamespace(o,i,r),this._writeAttStr(n,r)}return o.lastToken=e.TokenType.Attribute,this}var a=n;if(t){var s=this._ensurePrefixDeclared(o,t);a="".concat(s,":").concat(n)}return o.lastToken=e.TokenType.Attribute,this._writeAttStr(a,r),this},t.prototype.ele=function(e,t){var n,r=this._peekContext();r&&this._closeOpenTagIfNeeded(r);var o=t;if(e){var i=null!==(n=this._lookupPrefix(e))&&void 0!==n?n:e;o="".concat(i,":").concat(t)}return this._pushContext(o,++this._d),this._w.write(ln.OpenTag,o),this},t.prototype.text=function(t){var n=this._peekContext();if(!n)throw new Error("text() without open element");return this._closeOpenTagIfNeeded(n),n.lastToken=e.TokenType.Text,this._w.write(this._escText(t)),this},t.prototype.end=function(){var e=this._popContext();return e&&(this._d--,e.closed?this._w.write(ln.OpenTag,ln.Slash,e.name,ln.CloseTag):this._w.write(ln.Slash,ln.CloseTag)),this},t.prototype._pushContext=function(e,n){var r=new t.Context(e,n);return this._ctxStack.push(r),r},t.prototype._popContext=function(){return this._ctxStack.pop()},t.prototype._peekContext=function(){return this._ctxStack[this._ctxStack.length-1]},Object.defineProperty(t.prototype,"_contextDepth",{get:function(){return this._ctxStack.length},enumerable:!1,configurable:!0}),t.prototype._writeAttStr=function(e,t){this._w.write(ln.Space,e,ln.Equal,ln.Quote,this._escAttr(t),ln.Quote)},t.prototype._lookupPrefix=function(e){var t,n=this._ctxStack.length-1;if(n>=0)do{var r=null===(t=this._ctxStack[n--].ns2prefix)||void 0===t?void 0:t.get(e);if(r)return r}while(n>=0)},t.prototype._escText=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")},t.prototype._escAttr=function(e){return this._escText(e).replace(/"/g,""").replace(/'/g,"'")},t.prototype._isXmlnsDecl=function(e,t){if(e)return e===ln.Xmlns;var n=t.length,r=ln.Xmlns.length;return n>=r&&t.startsWith(ln.Xmlns)&&(t.length==r||t[r]==ln.Semicolon)},t.prototype._registerNamespace=function(e,t,n){if(t===ln.Xml||t===ln.Xmlns)throw new Error("reserved prefix '".concat(t,"'"));var r=e.prefix2ns.get(t);if(r&&r!==n)throw new Error("prefix '".concat(t,"' already bound to a different namespace"));e.ns2prefix.get(n)||e.ns2prefix.set(n,t),e.prefix2ns.set(t,n)},t.prototype._allocPrefix=function(e){for(var t=1;;){var n="ns".concat(t++);if(!e.prefix2ns.has(n))return n}},t.prototype._ensurePrefixDeclared=function(e,t){var n=this._lookupPrefix(t);if(n)return n;if(e.closed)throw new Error("can not declare namespace after start tag closed for <".concat(e.name,">"));var r=this._allocPrefix(e);return this._writeAttStr("".concat(ln.Xmlns,":").concat(r),t),this._registerNamespace(e,r,t),r},t.prototype._closeOpenTagIfNeeded=function(e){e.closed||(this._w.write(ln.CloseTag),e.closed=!0)},t.Context=function(e,t){this.name="",this.closed=!1,this.lastToken=null,this.ns2prefix=new Map,this.prefix2ns=new Map,this.defaultNs=null,this.name=e,this.depth=t},t}(),dn=function(){function e(){this.count=0,this._chunks=[]}return e.prototype.write=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)return this;var n=e.join("");return this._chunks.push(n),this.count+=n.length,this},e.prototype.toString=function(){return this._chunks.join("")},e.prototype.clear=function(){this._chunks=[],this.count=0},e}(),mn=function(){function e(e,t){void 0===t&&(t={}),this._sink=e,this._opts=t,this.count=0,this._encoder=new TextEncoder,this._pending="",this._pendingChars=0}return e.prototype.write=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(0===t.length)return this;var r=t.join("");if(0===r.length)return this;this._pending+=r,this._pendingChars+=r.length;var o=null!==(e=this._opts.flushChars)&&void 0!==e?e:65536;return this._pendingChars>=o&&this.flush(),this},e.prototype.flush=function(){if(0===this._pendingChars)return this;var e=this._encoder.encode(this._pending);return this._sink.push(e),this.count+=e.length,this._pending="",this._pendingChars=0,this},e.prototype.finish=function(){this.flush(),this._sink.push(new Uint8Array(0),!0)},e.prototype.clear=function(){this._pending="",this._pendingChars=0,this.count=0},e}(),gn="http://schemas.microsoft.com/3dmanufacturing/core/2015/02",xn="http://schemas.microsoft.com/3dmanufacturing/trianglesets/2021/07";e.ST_Unit=void 0,(hn=e.ST_Unit||(e.ST_Unit={})).micron="micron",hn.millimeter="millimeter",hn.centimeter="centimeter",hn.inch="inch",hn.foot="foot",hn.meter="meter",e.ST_ObjectType=void 0,(pn=e.ST_ObjectType||(e.ST_ObjectType={})).model="model",pn.solidsupport="solidsupport",pn.support="support",pn.surface="surface",pn.other="other";var _n,vn="http://schemas.openxmlformats.org/package/2006/content-types",Tn="http://schemas.openxmlformats.org/package/2006/relationships";e.KnownI3mfContentType=void 0,(_n=e.KnownI3mfContentType||(e.KnownI3mfContentType={})).Relationships="application/vnd.openxmlformats-package.relationships+xml",_n.Model="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",_n.Materials="application/vnd.ms-package.3dmanufacturing-material+xml",_n.Colors="application/vnd.ms-package.3dmanufacturing-colors+xml",_n.Texture="application/vnd.ms-package.3dmanufacturing-texture+xml",_n.Texture2D="application/vnd.ms-package.3dmanufacturing-texture2d+xml",_n.Production="application/vnd.ms-package.3dmanufacturing-production+xml",_n.Slice="application/vnd.ms-package.3dmanufacturing-slice+xml",_n.BeamLattice="application/vnd.ms-package.3dmanufacturing-beamlattice+xml",_n.SecureContent="application/vnd.ms-package.3dmanufacturing-securecontent+xml",_n.Png="image/png",_n.Jpeg="image/jpeg",_n.Tiff="image/tiff",_n.Xml="application/xml";var yn="_rels/",bn="3D/",Mn="3dmodel.model",wn=".rels",An="[Content_Types].xml",Cn=function(){function e(){}return e.IsKnown=function(t){return e.Known.has(t)},e.IsThreeDimModel=function(t){return t===e.ThreeDimModel},e.ThreeDimModel="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel",e.Thumbnail="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",e.PrintTicket="http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket",e.MustPreserve="http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve",e.Known=new Set([e.ThreeDimModel,e.Thumbnail,e.PrintTicket,e.MustPreserve]),e}(),Rn=function(){function e(){this.items=[]}return l([zt({ns:vn,name:"Types"})],e)}(),En=function(){function e(e,t){this.ext=e,this.ct=t}return l([Gt({name:{ns:vn,name:"Extension"}})],e.prototype,"ext",void 0),l([Gt({name:{ns:vn,name:"ContentType"}})],e.prototype,"ct",void 0),l([zt({ns:vn,name:"Default"})],e)}(),In=function(){function e(){this.items=[]}return l([zt({ns:Tn,name:"Relationships"})],e)}(),Sn=function(){function e(e,t,n){this.id=e,this.type=t,this.target=n}return l([Gt({name:"Id"})],e.prototype,"id",void 0),l([Gt({name:"Type"})],e.prototype,"type",void 0),l([Gt({name:"Target"})],e.prototype,"target",void 0),l([zt({ns:Tn,name:"Relationship"})],e)}(),Vn=function(e,t,n){this.contentTypes=e,this.relationships=t,this.model=n},Fn=function(){function e(e){this.values=e}return e.Zero=function(){return new e([0,0,0,0,0,0,0,0,0,0,0,0])},e.prototype.toString=function(){return this.values.join(" ")},e}(),Bn=function(){function e(e){this.o=e,this._f=new tn(e)}return e.prototype.toString=function(e){var t=this;return e.values.map(function(e){return t._f.toString(e)}).join(" ")},e}(),On=function(){function t(){this.unit=e.ST_Unit.millimeter}return t.KnownMeta=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate","Application"],l([Gt({name:"unit"})],t.prototype,"unit",void 0),l([Gt({name:"requiredextensions"})],t.prototype,"requiredextensions",void 0),l([Gt({name:"recommendedextensions"})],t.prototype,"recommendedextensions",void 0),l([zt({ns:gn,name:"model"})],t)}(),Nn=function(){function e(e,t,n,r){this.name=e,this.value=t,this.preserve=n,this.type=r}return l([Gt({name:"name"})],e.prototype,"name",void 0),l([Gt({name:"preserve"})],e.prototype,"preserve",void 0),l([Gt({name:"type"})],e.prototype,"type",void 0),l([zt({ns:gn,name:"meta"})],e)}(),Pn=function(){function e(){this.metadata=[]}return l([zt({ns:gn,name:"metadatagroup"})],e)}(),Un=function(){function e(){this.object=[]}return l([zt({ns:gn,name:"resources"})],e)}(),kn=function(){function t(t,n){void 0===n&&(n=e.ST_ObjectType.model),this.id=t,this.type=n}return l([Gt({name:"id"})],t.prototype,"id",void 0),l([Gt({name:"type"})],t.prototype,"type",void 0),l([Gt({name:"thumbnail"})],t.prototype,"thumbnail",void 0),l([Gt({name:"partnumber"})],t.prototype,"partnumber",void 0),l([Gt({name:"name"})],t.prototype,"name",void 0),l([Gt({name:"pid"})],t.prototype,"pid",void 0),l([Gt({name:"pindex"})],t.prototype,"pindex",void 0),l([zt({ns:gn,name:"object"})],t)}(),Ln=function(){function e(e,t){this.vertices=null!=e?e:new Wn,this.triangles=null!=t?t:new zn}return l([zt({ns:gn,name:"mesh"})],e)}(),Wn=function(){function e(){this.vertex=[]}return l([zt({ns:gn,name:"vertices"})],e)}(),Dn=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=0),void 0===n&&(n=0),this.x=e,this.y=t,this.z=n}return l([Gt({name:"x"})],e.prototype,"x",void 0),l([Gt({name:"y"})],e.prototype,"y",void 0),l([Gt({name:"z"})],e.prototype,"z",void 0),l([zt({ns:gn,name:"vertex"})],e)}(),zn=function(){function e(){this.triangle=[]}return l([zt({ns:gn,name:"triangles"})],e)}(),Kn=function(){function e(e,t,n){this.v1=e,this.v2=t,this.v3=n}return l([Gt({name:"v1"})],e.prototype,"v1",void 0),l([Gt({name:"v2"})],e.prototype,"v2",void 0),l([Gt({name:"v3"})],e.prototype,"v3",void 0),l([Gt({name:"p1"})],e.prototype,"p1",void 0),l([Gt({name:"p2"})],e.prototype,"p2",void 0),l([Gt({name:"p3"})],e.prototype,"p3",void 0),l([Gt({name:"pid"})],e.prototype,"pid",void 0),l([zt({ns:gn,name:"triangle"})],e)}(),Gn=function(){function e(){this.component=[]}return l([zt({ns:gn,name:"components"})],e)}(),qn=function(){function e(e,t){this.objectid=e,this.transform=t}return l([Gt({name:"objectid"})],e.prototype,"objectid",void 0),l([Gt({name:"transform",formatter:Bn})],e.prototype,"transform",void 0),l([zt({ns:gn,name:"component"})],e)}(),Hn=function(){function e(e){this.base=[],this.id=e}return l([Gt({name:"id"})],e.prototype,"id",void 0),l([zt({ns:gn,name:"basematerials"})],e)}(),jn=function(){function e(e,t){this.name=e,this.displaycolor=t}return l([Gt({name:"name"})],e.prototype,"name",void 0),l([Gt({name:"displaycolor"})],e.prototype,"displaycolor",void 0),l([zt({ns:gn,name:"base"})],e)}(),Xn=function(){function e(){this.item=[]}return l([zt({ns:gn,name:"build"})],e)}(),Qn=function(){function e(e,t,n){this.objectid=e,this.transform=t,this.partnumber=n}return l([Gt({name:"objectid"})],e.prototype,"objectid",void 0),l([Gt({name:"transform",formatter:Bn})],e.prototype,"transform",void 0),l([Gt({name:"partnumber"})],e.prototype,"partnumber",void 0),l([zt({ns:gn,name:"item"})],e)}(),Zn=function(){function e(e,t){this._object=new kn(e,t)}return e.prototype.withName=function(e){return this._object.name=e,this},e.prototype.withThumbnail=function(e){return this._object.thumbnail=e,this},e.prototype.withProperty=function(e,t){return void 0===t&&(t=0),this._object.pid=e,this._object.id=t,this},e.prototype.build=function(){return this._object},e.prototype.reset=function(e,t){this._object=new kn(e,t)},e}(),Yn=function(t){function n(n,r){void 0===r&&(r=e.ST_ObjectType.model);var o=t.call(this,n,r)||this;return o._object.content=new Gn,o}return u(n,t),n.prototype.withComponent=function(e,t){return this._object.content.component.push(new qn(e,t)),this},n}(Zn),Jn=function(t){function n(n){return t.call(this,n,e.ST_ObjectType.model)||this}return u(n,t),n.prototype.withPostProcessHandlers=function(e,t){return this._vh=e,this._th=t,this},n.prototype.withData=function(e){return this._object.content=this._buildMesh(e),this},n.prototype.withMaterial=function(e,t){return this._object.pid=e,this._object.pindex=t,this},n.prototype._buildMesh=function(e){var t=this._buildVertices(e.positions),n=this._buildTriangle(e.indices);return new Ln(t,n)},n.prototype._buildVertices=function(e){var t=new Wn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Dn(r,o,i);this._vh&&(a=this._vh(a)),t.vertex.push(a)}return t},n.prototype._buildTriangle=function(e){var t=new zn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Kn(r,o,i);this._th&&(a=this._th(a)),t.triangle.push(a)}return t},n}(Zn),$n=function(){function e(e){this._m=new Hn(e)}return e.prototype.withColor=function(e,t){var n;this._m.base=null!==(n=this._m.base)&&void 0!==n?n:[];var r=this._m.base.find(function(t){return t.name.toLowerCase()===e.toLowerCase()});return r?(r.displaycolor=this._rgbaToHex(t),this):(r=new jn(e,this._rgbaToHex(t)),this._m.base.push(r),this)},e.prototype.build=function(){return this._m},e.prototype._rgbaToHex=function(e){var t=function(e){return Math.round(Math.min(255,Math.max(0,255*Math.pow(e,1/2.2))))},n=t(e.r).toString(16).padStart(2,"0").toUpperCase(),r=t(e.g).toString(16).padStart(2,"0").toUpperCase(),o=t(e.b).toString(16).padStart(2,"0").toUpperCase();if("number"==typeof e.a){var i=Math.round(Math.min(255,Math.max(0,255*e.a))).toString(16).padStart(2,"0").toUpperCase();return"#".concat(n).concat(r).concat(o).concat(i)}return"#".concat(n).concat(r).concat(o)},e}(),er=function(){function e(){this._model=new On,this._objects=new Map}return e.prototype.withMetaData=function(e,t,n,r){return this._model.metadata||(this._model.metadata=new Array),this._model.metadata.push(new Nn(e,t,n,r)),this},e.prototype.withMaterial=function(e){var t,n;return e instanceof $n&&(e=e.build()),e&&(this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.basematerials=null!==(n=this._model.resources.basematerials)&&void 0!==n?n:[],this._model.resources.basematerials.push(e)),this},e.prototype.withMesh=function(e){var t;return e instanceof Jn&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.object.push(e),this},e.prototype.withComponents=function(e){var t;return e instanceof Yn&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.object.push(e),this},e.prototype.withBuild=function(e,t,n){var r,o;return this._model.build=null!==(r=this._model.build)&&void 0!==r?r:new Xn,null===(o=this._model.build.item)||void 0===o||o.push(new Qn(e,t,n)),this},e.prototype.withUnit=function(e){return this._model.unit=e,this},e.prototype.reset=function(){return this._model=new On,this._objects=new Map,this},e.prototype.build=function(){var e,t,n,r;if(!(null===(t=null===(e=this._model.resources)||void 0===e?void 0:e.object)||void 0===t?void 0:t.length))throw new Error("Invalid state: resources MUST be defined ");if(!(null===(r=null===(n=this._model.build)||void 0===n?void 0:n.item)||void 0===r?void 0:r.length))throw new Error("Invalid state: Build MUST be defined ");return this._model},e.KnownMetaSet=new Set(On.KnownMeta.map(function(e){return e.toLowerCase()})),e}(),tr=function(){function t(){}return t.prototype.withContentType=function(e){this._cts||(this._cts=new Rn);var t=this._cts.items;return t.some(function(t){return t.ext===e.ext&&t.ct===e.ct})||t.push(e),this},t.prototype.withRelationship=function(t){this._rs||(this._rs=new In);var n=this._rs.items;return n.some(function(e){return e.id===t.id})||n.push(t),this.withContentType(new En("rels",e.KnownI3mfContentType.Relationships)),this},t.prototype.withModel=function(t){return t instanceof er&&(t=t.build()),this._m=t,this.withContentType(new En("model",e.KnownI3mfContentType.Model)),this},t.prototype.build=function(){if(!this._m)throw new Error("Invalid state: you Must provide at least a model.");var e="".concat(bn).concat(Mn);if(!this._rs){var t="/".concat(e);this.withRelationship(new Sn("rel".concat(0),Cn.ThreeDimModel,t))}return new Vn(this._cts,this._rs,this._m)},t}(),nr=function(){function t(e){this._o=e}return Object.defineProperty(t.prototype,"options",{get:function(){return this._o},enumerable:!1,configurable:!0}),t.prototype.serializeAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u;return p(this,function(c){switch(c.label){case 0:return[4,this.ensureZipLibReadyAsync()];case 1:if(!(n=c.sent()))return[2];if(r=n.Zip,o=n.ZipDeflate,!r||!o)throw new Error("fflate Zip / ZipDeflate not available");return i=function(e){return{push:function(t,n){return e.push(t,n)}}},a=function(e,t,n){var r=new o(t,{level:6});e.add(r);var a=i(r),s=new mn(a),u=new fn(s).dec("1.0","UTF-8");new cn(u).serialize(n),s.finish()},(s=this.toDocument.apply(this,t))?(u=new r(e),a(u,An,s.contentTypes),a(u,"".concat(yn).concat(wn),s.relationships),a(u,"".concat(bn).concat(Mn),s.model),u.end(),[2]):[2]}})})},t.prototype.toDocument=function(){for(var t,n,r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];var i=(new er).withUnit(null!==(n=null===(t=this._o)||void 0===t?void 0:t.unit)&&void 0!==n?n:e.ST_Unit.millimeter);if(this.options.metadata)for(var a in this.options.metadata)i.withMetaData(a,this.options.metadata[a]);return(new tr).withModel(this.toModel.apply(this,f([i],r,!1))).build()},t}(),rr=function(){function e(){}return e.SerializeToMemoryAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return p(this,function(l){switch(l.label){case 0:return n=new Array,r=0,o=function(e,t,o){n.push(t),r+=t.length},[4,e.serializeAsync.apply(e,f([o],t,!1))];case 1:if(l.sent(),!r)return[2,void 0];for(i=new Uint8Array(r),a=0,s=0,u=n;s<u.length;s++)c=u[s],i.set(c,a),a+=c.length;return[2,i]}})})},e}(),or=function(){function e(){}return e.FFLATEUrl="https://unpkg.com/fflate@0.8.2",e}(),ir=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=Number.MIN_SAFE_INTEGER),void 0===n&&(n=1),this._from=e,this._to=t,this._step=n,this._i=e}return e.prototype.next=function(){if(this._i<this._to)throw new Error("ST_ResourceID out of bound");var e=this._i;return this._i+=this._step,e},e.prototype.reset=function(){return this._i=this._from,this},e}(),ar=function(n){function r(e){return void 0===e&&(e={}),n.call(this,c(c({},r.DefaultOptions),e))||this}return u(r,n),r.prototype.toModel=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];n=n.filter(function(e){return e instanceof t.Mesh||e instanceof t.InstancedMesh});for(var o=new ir,i=e,a=new Map,s=this.options.exportInstances?[]:null,u=0;u<n.length;u++){var c=n[u];if(c instanceof t.InstancedMesh)null==s||s.push(c);else{var l=c.name||"mesh".concat(u),h=c.getWorldMatrix(),p=this._handleBabylonTo3mfMatrixTransformToRef(h,Fn.Zero());if(void 0!==(A=c.subMeshes))for(var f=1==A.length,d=0;d<A.length;d++){var m=A[d],g=this._extractSubMesh(c,m);if(g){var x=f?"".concat(l):"".concat(l,"_").concat(d),_=new Jn(o.next()).withData(g).withName(x).build();i.withMesh(_),i.withBuild(_.id,p),a.set(m,_)}}}}if(s&&s.length)for(var v=this._groupBy(s,function(e){return e.sourceMesh}),T=0,y=Array.from(v.entries());T<y.length;T++){var b=y[T],M=b[0],w=b[1];if(w&&w.length)for(u=0;u<w.length;u++){h=w[u].getWorldMatrix();var A=M.subMeshes;for(d=0;d<A.length;d++){m=A[d];var C=a.get(m);C&&i.withBuild(C.id,this._handleBabylonTo3mfMatrixTransformToRef(h,Fn.Zero()))}}}return i.build()},r.prototype.ensureZipLibReadyAsync=function(){return h(this,void 0,void 0,function(){var e=this;return p(this,function(n){switch(n.label){case 0:return this._fflateReadyPromise?[4,this._fflateReadyPromise]:[3,2];case 1:case 3:return[2,n.sent()];case 2:return this._fflateReadyPromise=h(e,void 0,void 0,function(){var e;return p(this,function(n){switch(n.label){case 0:return(e=globalThis).fflate?[3,2]:[4,t.Tools.LoadScriptAsync(or.FFLATEUrl)];case 1:n.sent(),n.label=2;case 2:return[2,e.fflate]}})}),[4,this._fflateReadyPromise]}})})},r.prototype._extractSubMesh=function(e,t){var n=e.getIndices();if(n){var o=e.getVerticesData(r._PositionKind);if(o){if(0==t.indexStart&&t.indexCount==n.length)return{positions:o,indices:n};for(var i=t.indexStart,a=new Map,s=[],u=new Uint32Array(t.indexCount),c=0;c<t.indexCount;c++){var l=n[i+c],h=a.get(l);if(void 0===h){h=a.size,a.set(l,h);var p=3*l;s.push(o[p],o[p+1],o[p+2])}u[c]=h}return{positions:new Float32Array(s),indices:u}}}},r.prototype._groupBy=function(e,t){for(var n=new Map,r=0,o=e;r<o.length;r++){var i=o[r],a=t(i),s=n.get(a);s?s.push(i):n.set(a,[i])}return n},r.prototype._handleBabylonTo3mfMatrixTransformToRef=function(e,n){var o=e.multiplyToRef(r._R_BJS_TO_3MF,t.Matrix.Zero()).m;return n.values=[o[0],o[1],o[2],o[4],o[5],o[6],o[8],o[9],o[10],o[12],o[13],o[14]],n},r.DefaultOptions={unit:e.ST_Unit.meter,exportInstances:!1},r._PositionKind="position",r._R_BJS_TO_3MF=t.Matrix.RotationX(Math.PI/2).multiply(t.Matrix.Scaling(1,-1,1)),r}(nr),sr={__proto__:null,AbstractThreeMfSerializer:nr,ContentTypeFileName:An,DefaultXmlSerializerFormatOptions:Jt,DefaultXmlSerializerNumberOptions:Yt,GetXmlFieldMeta:Ht,GetXmlName:jt,IsQualifiedName:kt,Known3mfRelationshipTypes:Cn,get KnownI3mfContentType(){return e.KnownI3mfContentType},Matrix3d:Fn,MatrixFormatter:Bn,ModelFileName:Mn,NumberFormatter:tn,Object3dDirName:bn,OpenXmlContentTypesNamespace:vn,OpenXmlRelationshipsNamespace:Tn,RelationshipDirName:yn,RelationshipFileName:wn,ResolveFormatOptions:en,ResolveNumberOptions:$t,get ST_ObjectType(){return e.ST_ObjectType},get ST_Unit(){return e.ST_Unit},StringXmlWriter:dn,ThreeDimModelNamespace:gn,ThreeMf:rr,ThreeMfBase:jn,ThreeMfBaseMaterials:Hn,ThreeMfBuild:Xn,ThreeMfComponent:qn,ThreeMfComponents:Gn,ThreeMfComponentsBuilder:Yn,ThreeMfContentType:En,ThreeMfContentTypes:Rn,ThreeMfDocument:Vn,ThreeMfDocumentBuilder:tr,ThreeMfItem:Qn,ThreeMfMaterialBuilder:$n,ThreeMfMesh:Ln,ThreeMfMeshBuilder:Jn,ThreeMfMeta:Nn,ThreeMfMetadataGroup:Pn,ThreeMfModel:On,ThreeMfModelBuilder:er,ThreeMfObject:kn,ThreeMfObjectBuilder:Zn,ThreeMfRelationship:Sn,ThreeMfRelationships:In,ThreeMfResources:Un,ThreeMfSerializer:ar,ThreeMfSerializerGlobalConfiguration:or,ThreeMfTriangle:Kn,ThreeMfTriangles:zn,ThreeMfVertex:Dn,ThreeMfVertices:Wn,ToQualifiedString:Zt,get TokenType(){return e.TokenType},TriangleSetsNamespace:xn,Utf8XmlWriterToBytes:mn,XmlAttr:Gt,XmlBuilder:fn,XmlElem:qt,XmlIgnore:Kt,XmlName:zt,XmlNameToParts:Qt,XmlSerializer:cn},ur="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==ur)for(var cr in Ut)ur.BABYLON[cr]=Ut[cr];var lr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==lr){lr.BABYLON=lr.BABYLON||{};var hr=lr.BABYLON;hr.GLTF2=hr.GLTF2||{},hr.GLTF2.Exporter=hr.GLTF2.Exporter||{},hr.GLTF2.Exporter.Extensions=hr.GLTF2.Exporter.Extensions||{};var pr=[];for(var fr in o)hr[fr]=o[fr],pr.push(fr);for(var fr in a)hr[fr]=a[fr],pr.push(fr);for(var fr in te)hr[fr]=te[fr],pr.push(fr);for(var fr in gt)hr.GLTF2.Exporter.Extensions[fr]=gt[fr],pr.push(fr);for(var fr in xt)pr.indexOf(fr)>-1||(hr.GLTF2.Exporter[fr]=xt[fr])}var dr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==dr)for(var mr in r)dr.BABYLON[mr]=r[mr];var gr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==gr)for(var xr in vt)gr.BABYLON[xr]=vt[xr];var _r="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==_r)for(var vr in Nt)_r.BABYLON[vr]=Nt[vr];var Tr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Tr){var yr=[];for(var br in sr)yr.indexOf(br)>-1||(Tr.BABYLON[br]=sr[br],yr.push(br))}e.AbstractThreeMfSerializer=nr,e.BVHExporter=Pt,e.ContentTypeFileName=An,e.DefaultXmlSerializerFormatOptions=Jt,e.DefaultXmlSerializerNumberOptions=Yt,e.EXT_lights_area=xe,e.EXT_mesh_gpu_instancing=oe,e.EXT_texture_avif=mt,e.EXT_texture_webp=ft,e.GLTF2Export=ee,e.GLTFData=i,e.GetXmlFieldMeta=Ht,e.GetXmlName=jt,e.IsQualifiedName=kt,e.KHR_draco_mesh_compression=se,e.KHR_lights_punctual=pe,e.KHR_materials_anisotropy=Te,e.KHR_materials_clearcoat=we,e.KHR_materials_coat=Se,e.KHR_materials_diffuse_roughness=it,e.KHR_materials_diffuse_transmission=Be,e.KHR_materials_dispersion=Ne,e.KHR_materials_emissive_strength=Ue,e.KHR_materials_fuzz=je,e.KHR_materials_ior=Le,e.KHR_materials_iridescence=De,e.KHR_materials_openpbr=st,e.KHR_materials_sheen=Ke,e.KHR_materials_specular=Qe,e.KHR_materials_transmission=Ye,e.KHR_materials_unlit=$e,e.KHR_materials_volume=tt,e.KHR_materials_volume_scatter=rt,e.KHR_texture_basisu=ht,e.KHR_texture_transform=ct,e.Known3mfRelationshipTypes=Cn,e.Matrix3d=Fn,e.MatrixFormatter=Bn,e.ModelFileName=Mn,e.NumberFormatter=tn,e.OBJExport=n,e.Object3dDirName=bn,e.OpenXmlContentTypesNamespace=vn,e.OpenXmlRelationshipsNamespace=Tn,e.RelationshipDirName=yn,e.RelationshipFileName=wn,e.ResolveFormatOptions=en,e.ResolveNumberOptions=$t,e.STLExport=_t,e.StringXmlWriter=dn,e.ThreeDimModelNamespace=gn,e.ThreeMf=rr,e.ThreeMfBase=jn,e.ThreeMfBaseMaterials=Hn,e.ThreeMfBuild=Xn,e.ThreeMfComponent=qn,e.ThreeMfComponents=Gn,e.ThreeMfComponentsBuilder=Yn,e.ThreeMfContentType=En,e.ThreeMfContentTypes=Rn,e.ThreeMfDocument=Vn,e.ThreeMfDocumentBuilder=tr,e.ThreeMfItem=Qn,e.ThreeMfMaterialBuilder=$n,e.ThreeMfMesh=Ln,e.ThreeMfMeshBuilder=Jn,e.ThreeMfMeta=Nn,e.ThreeMfMetadataGroup=Pn,e.ThreeMfModel=On,e.ThreeMfModelBuilder=er,e.ThreeMfObject=kn,e.ThreeMfObjectBuilder=Zn,e.ThreeMfRelationship=Sn,e.ThreeMfRelationships=In,e.ThreeMfResources=Un,e.ThreeMfSerializer=ar,e.ThreeMfSerializerGlobalConfiguration=or,e.ThreeMfTriangle=Kn,e.ThreeMfTriangles=zn,e.ThreeMfVertex=Dn,e.ThreeMfVertices=Wn,e.ToQualifiedString=Zt,e.TriangleSetsNamespace=xn,e.USDZExportAsync=Ot,e.Utf8XmlWriterToBytes=mn,e.XmlAttr=Gt,e.XmlBuilder=fn,e.XmlElem=qt,e.XmlIgnore=Kt,e.XmlName=zt,e.XmlNameToParts=Qt,e.XmlSerializer=cn,e._ConvertToGLTFPBRMetallicRoughness=y,e._SolveMetallic=T,e.__IGLTFExporterExtension=0});
|
|
2
2
|
//# sourceMappingURL=babylonjs.serializers.min.js.map
|