babylonjs-serializers 9.14.0 → 9.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babylon.glTF2Serializer.js +1 -1
- package/babylon.glTF2Serializer.js.map +1 -1
- package/babylon.glTF2Serializer.min.js +1 -1
- package/babylon.glTF2Serializer.min.js.map +1 -1
- package/babylon.objSerializer.js +1 -1
- package/babylon.objSerializer.js.map +1 -1
- package/babylon.objSerializer.min.js +1 -1
- package/babylon.objSerializer.min.js.map +1 -1
- package/babylon.stlSerializer.js +1 -1
- package/babylon.stlSerializer.js.map +1 -1
- package/babylon.stlSerializer.min.js +1 -1
- package/babylon.stlSerializer.min.js.map +1 -1
- package/babylon.threemfSerializer.js +1 -1
- package/babylon.threemfSerializer.js.map +1 -1
- package/babylon.threemfSerializer.min.js +1 -1
- package/babylon.threemfSerializer.min.js.map +1 -1
- package/babylon.usdzSerializer.js +1 -1
- package/babylon.usdzSerializer.js.map +1 -1
- package/babylon.usdzSerializer.min.js +1 -1
- package/babylon.usdzSerializer.min.js.map +1 -1
- package/babylonjs.serializers.d.ts +52 -11
- 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/babylonjs.serializers.module.d.ts +104 -22
- package/package.json +3 -3
- package/tsconfig.build.json +1 -2
|
@@ -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 r={__proto__:null,__IGLTFExporterExtension:0},n=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 r=this.files[e],n=new Blob([r],{type:t.GetMimeType(e)});t.Tools.Download(n,e)}},e}(),s={__proto__:null,GLTFData:n},i=function(){return i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var s in t=arguments[r])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e},i.apply(this,arguments)};function o(e,t,r,n){return new(r||(r=Promise))(function(s,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,a)}u((n=n.apply(e,t||[])).next())})}function a(e,t){var r,n,s,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(i=0)),i;)try{if(r=1,n&&(s=2&a[0]?n.return:a[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;switch(n=0,s&&(a=[2&a[0],s.value]),a[0]){case 0:case 1:s=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!((s=(s=i.trys).length>0&&s[s.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!s||a[1]>s[0]&&a[1]<s[3])){i.label=a[1];break}if(6===a[0]&&i.label<s[1]){i.label=s[1],s=a;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(a);break}s[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=s=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function u(e,t,r){if(r||2===arguments.length)for(var n,s=0,i=t.length;s<i;s++)!n&&s in t||(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}function c(e){return o(this,void 0,void 0,function(){var r,n,s,i,o,u;return a(this,function(a){switch(a.label){case 0:if(!(r=e.getInternalTexture())||1!==r.source)return[2,null];if(r.invertY&&!((null===(u=e.getScene())||void 0===u?void 0:u.getEngine())instanceof t.NullEngine))return[2,null];n=r._buffer,i=e.mimeType,a.label=1;case 1:return a.trys.push([1,12,,13]),n?[3,3]:[4,t.Tools.LoadFileAsync(r.url)];case 2:return s=a.sent(),i=t.GetMimeType(r.url)||i,[3,11];case 3:return ArrayBuffer.isView(n)?(s=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),[3,11]):[3,4];case 4:return n instanceof ArrayBuffer?(s=n,[3,11]):[3,5];case 5:return n instanceof Blob?[4,n.arrayBuffer()]:[3,7];case 6:return s=a.sent(),i=n.type||i,[3,11];case 7:return"string"!=typeof n?[3,9]:[4,t.Tools.LoadFileAsync(n)];case 8:return s=a.sent(),i=t.GetMimeType(n)||i,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement?[4,t.Tools.LoadFileAsync(n.src)]:[3,11];case 10:s=a.sent(),i=t.GetMimeType(n.src)||i,a.label=11;case 11:return[3,13];case 12:return a.sent(),[2,null];case 13:return s&&!i&&r.url&&(o=r.url.match(/^data:([^;,]+)/),i=o?o[1]:t.GetMimeType(r.url)),s&&i?[2,{data:s,mimeType:i}]:[2,null]}})})}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var l=1e-6,h=new t.Color3(.04,.04,.04),f=t.Color3.White(),p=t.Color3.BlackReadOnly;function d(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function x(e,r,n){if(r<h.r)return 0;var s=h.r,i=e*n/(1-h.r)+r-2*h.r,o=i*i-4*s*(h.r-r);return t.Scalar.Clamp((-i+Math.sqrt(o))/(2*s),0,1)}function g(e){var r=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),n=e.alpha,s=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(s);return{baseColorFactor:[r.r,r.g,r.b,n],metallicFactor:0,roughnessFactor:i}}function _(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function m(e,r,n){for(var s=new Uint8Array(e*r*4),i=0;i<s.length;i+=4)s[i]=s[i+1]=s[i+2]=s[i+3]=255;return t.RawTexture.CreateRGBATexture(s,e,r,n)}function T(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var y=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,r){return o(this,void 0,void 0,function(){var n,s,i,o,u,c,h,f;return a(this,function(a){switch(a.label){case 0:return n=g(e),s={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."),s.doubleSided=!0),r?(i=[],(o=e.diffuseTexture)&&i.push(this.exportTextureAsync(o).then(function(e){e&&(n.baseColorTexture=e)})),(u=e.bumpTexture)&&i.push(this.exportTextureAsync(u).then(function(e){e&&(s.normalTexture=e,1!==u.level&&(s.normalTexture.scale=u.level))})),(c=e.emissiveTexture)&&(s.emissiveFactor=[1,1,1],i.push(this.exportTextureAsync(c).then(function(e){e&&(s.emissiveTexture=e)}))),(h=e.ambientTexture)&&i.push(this.exportTextureAsync(h).then(function(e){if(e){var t={index:e.index};s.occlusionTexture=t}})),i.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(i)]):[3,2]):[3,2];case 1:a.sent(),a.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===t.Constants.ALPHA_COMBINE?s.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(p,l)&&(s.emissiveFactor=e.emissiveColor.asArray()),s.pbrMetallicRoughness=n,_(s,e),[4,this._finishMaterialAsync(s,e)];case 3:return a.sent(),(f=this._exporter._materials).push(s),[2,f.length-1]}})})},e.prototype._finishMaterialAsync=function(e,t){return o(this,void 0,void 0,function(){var r,n,s,i,o;return a(this,function(a){switch(a.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(r=a.sent(),n=[],s=0,i=r;s<i.length;s++)o=i[s],n.push(this.exportTextureAsync(o));return[4,Promise.all(n)];case 2:return a.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return a.sent(),[2]}})})},e.prototype._resizeTexturesToSameDimensions=function(e,r,n){var s,i,o=e?e.getSize():{width:0,height:0},a=r?r.getSize():{width:0,height:0};return o.width<a.width?(s=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,a.width,a.height,!0):m(a.width,a.height,n),i=r):o.width>a.width?(i=r&&r instanceof t.Texture?t.TextureTools.CreateResizedCopy(r,o.width,o.height,!0):m(o.width,o.height,n),s=e):(s=e,i=r),{texture1:s,texture2:i}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,r,n){return o(this,void 0,void 0,function(){var s,i,o,u,c,h,p,d,x,g,_,m,y,v,b,R,M,w,A,E,C,I,V,S,F,B,N,O,U,P,K;return a(this,function(a){switch(a.label){case 0:return s=new Array,e||r?[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,a.sent()];case 2:return(i=e?e.getScene():r?r.getScene():null)?(o=this._resizeTexturesToSameDimensions(e,r,i),u=null===(K=o.texture1)||void 0===K?void 0:K.getSize(),c=void 0,h=void 0,p=u.width,d=u.height,[4,o.texture1.readPixels()]):[3,12];case 3:return x=a.sent(),[4,o.texture2.readPixels()];case 4:return g=a.sent(),x?(c=T(x),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return g?(h=T(g),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(_=h.byteLength,m=new Uint8Array(_),y=new Uint8Array(_),v=new t.Color3(0,0,0),b=0,R=0,B=0;B<d;++B)for(N=0;N<p;++N)M=4*(p*B+N),w=new t.Color3(c[M],c[M+1],c[M+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),A=new t.Color3(h[M],h[M+1],h[M+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(n.specularColor),E=h[M+3]*n.glossiness,C={diffuseColor:w,specularColor:A,glossiness:E},I=this._convertSpecularGlossinessToMetallicRoughness(C),v.r=Math.max(v.r,I.baseColor.r),v.g=Math.max(v.g,I.baseColor.g),v.b=Math.max(v.b,I.baseColor.b),b=Math.max(b,I.metallic),R=Math.max(R,I.roughness),y[M]=255*I.baseColor.r,y[M+1]=255*I.baseColor.g,y[M+2]=255*I.baseColor.b,y[M+3]=o.texture1.hasAlpha?255*c[M+3]:255,m[M]=0,m[M+1]=255*I.roughness,m[M+2]=255*I.metallic,m[M+3]=255;for(V={baseColor:v,metallic:b,roughness:R},S=!1,F=!1,B=0;B<d;++B)for(N=0;N<p;++N)y[O=4*(p*B+N)]/=V.baseColor.r>l?V.baseColor.r:1,y[O+1]/=V.baseColor.g>l?V.baseColor.g:1,y[O+2]/=V.baseColor.b>l?V.baseColor.b:1,U=t.Color3.FromInts(y[O],y[O+1],y[O+2]),P=U.toGammaSpace(i.getEngine().useExactSrgbConversions),y[O]=255*P.r,y[O+1]=255*P.g,y[O+2]=255*P.b,P.equalsWithEpsilon(f,l)||(F=!0),m[O+1]/=V.roughness>l?V.roughness:1,m[O+2]/=V.metallic>l?V.metallic:1,t.Color3.FromInts(255,m[O+1],m[O+2]).equalsWithEpsilon(f,l)||(S=!0);return S&&s.push(t.EncodeImageAsync(m,p,d).then(function(e){V.metallicRoughnessTextureData=e})),F&&s.push(t.EncodeImageAsync(y,p,d).then(function(e){V.baseColorTextureData=e})),[4,Promise.all(s).then(function(){return V})];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}})})},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var r=this._getPerceivedBrightness(e.diffuseColor),n=this._getPerceivedBrightness(e.specularColor),s=1-this._getMaxComponent(e.specularColor),i=x(r,n,s),o=e.diffuseColor.scale(s/(1-h.r)/Math.max(1-i,l)),a=e.specularColor.subtract(h.scale(1-i)).scale(1/Math.max(i,l)),u=t.Color3.Lerp(o,a,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,r,n,s,i,u,c,l,h){return o(this,void 0,void 0,function(){var f,p,d,x,g,_,m,T,y,v=this;return a(this,function(b){switch(b.label){case 0:return f=[],p={baseColor:e,metallic:r,roughness:n},h&&(c instanceof t.OpenPBRMaterial?(c.geometryOpacityTexture?(d=s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:0,x=c.geometryOpacityTexture&&c.geometryOpacityTexture.getInternalTexture()?c.geometryOpacityTexture.getInternalTexture().uniqueId:0,g=Number("".concat(d).concat(x)),(y=this._textureMap.get(g))?l.baseColorTexture=y:f.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),s?t.CreateTextureInput(s,1):t.CreateConstantInput(1),s?t.CreateTextureInput(s,2):t.CreateConstantInput(1),t.CreateTextureInput(c.geometryOpacityTexture,0)),c.getScene()).then(function(e){return o(v,void 0,void 0,function(){var t;return a(this,function(r){switch(r.label){case 0:return[4,this.exportTextureAsync(e,g)];case 1:return(t=r.sent())&&(l.baseColorTexture=t),[2]}})})}))):s&&f.push(this.exportTextureAsync(s).then(function(e){e&&(l.baseColorTexture=e)})),c._useMetallicFromMetallicTextureBlue&&i?f.push(this.exportTextureAsync(i).then(function(e){e&&(l.metallicRoughnessTexture=e)})):(u||i)&&(_=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,m=u&&u.getInternalTexture()?u.getInternalTexture().uniqueId:0,T=Number("".concat(_).concat(m)),(y=this._textureMap.get(T))?l.metallicRoughnessTexture=y:f.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(c.ambientOcclusionTexture?t.CreateTextureInput(c.ambientOcclusionTexture,0):t.CreateConstantInput(1),u?t.CreateTextureInput(u,0):t.CreateConstantInput(1),i?t.CreateTextureInput(i,0):t.CreateConstantInput(1)),c.getScene()).then(function(e){return o(v,void 0,void 0,function(){var t;return a(this,function(r){switch(r.label){case 0:return[4,this.exportTextureAsync(e,T)];case 1:return(t=r.sent())&&(l.metallicRoughnessTexture=t),[2]}})})})))):(s&&f.push(this.exportTextureAsync(s).then(function(e){e&&(l.baseColorTexture=e)})),i&&f.push(this.exportTextureAsync(i).then(function(e){e&&(l.metallicRoughnessTexture=e)})))),f.length>0?(this._exporter._materialNeedsUVsSet.add(c),[4,Promise.all(f)]):[3,2];case 1:b.sent(),b.label=2;case 2:return[2,p]}})})},e.prototype._getTextureSampler=function(e){var r={};if(!(e&&e instanceof t.Texture))return r;var n=this._getGLTFTextureWrapMode(e.wrapU);10497!==n&&(r.wrapS=n);var s=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==s&&(r.wrapT=s),e.samplingMode){case t.Texture.LINEAR_LINEAR:r.magFilter=9729,r.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:r.magFilter=9729,r.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:r.magFilter=9728,r.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:r.magFilter=9728,r.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:r.magFilter=9728,r.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:r.magFilter=9728,r.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:r.magFilter=9729,r.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:r.magFilter=9729,r.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:r.magFilter=9728,r.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:r.magFilter=9729,r.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:r.magFilter=9729,r.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:r.magFilter=9728,r.minFilter=9984}return r},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,r){return o(this,void 0,void 0,function(){var n,s,i,o,u,c,l,h;return a(this,function(a){switch(a.label){case 0:return n={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},s=e._albedoTexture,i=e._reflectivityTexture,o=e._useMicroSurfaceFromReflectivityMapAlpha,!i||o?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,a.sent()];case 2:return(s||i)&&r?(this._exporter._materialNeedsUVsSet.add(e),u=this._exportTextureSampler(s||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(s,i,n)]):[3,8];case 3:return c=a.sent(),l=this._exporter._textures,c.baseColorTextureData?[4,this._exportImageAsync("baseColor".concat(l.length),c.baseColorTextureData)]:[3,5];case 4:h=a.sent(),t.baseColorTexture=this._exportTextureInfo(h,u,null==s?void 0:s.coordinatesIndex),a.label=5;case 5:return c.metallicRoughnessTextureData?[4,this._exportImageAsync("metallicRoughness".concat(l.length),c.metallicRoughnessTextureData)]:[3,7];case 6:h=a.sent(),t.metallicRoughnessTexture=this._exportTextureInfo(h,u,null==i?void 0:i.coordinatesIndex),a.label=7;case 7:return[2,c];case 8:return[2,this._convertSpecularGlossinessToMetallicRoughness(n)]}})})},e.prototype.exportPBRMaterialAsync=function(e,t){return o(this,void 0,void 0,function(){var r,n,s,i,o,u,c,l;return a(this,function(a){switch(a.label){case 0:return r={},n={name:e.name},(s=e.isMetallicWorkflow())&&(i=e._albedoColor,o=e.alpha,i&&(r.baseColorFactor=[i.r,i.g,i.b,o])),s?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,r,t)]:[3,2];case 1:return c=a.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,r,t)];case 3:c=a.sent(),a.label=4;case 4:return u=c,[4,this._setMetallicRoughnessPbrMaterialAsync(u,e,n,r,t)];case 5:return a.sent(),[4,this._finishMaterialAsync(n,e)];case 6:return a.sent(),(l=this._exporter._materials).push(n),[2,l.length-1]}})})},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,r,n,s,i){return o(this,void 0,void 0,function(){var u,c,h,d,x,g=this;return a(this,function(m){switch(m.label){case 0:return _(n,r),e.baseColor.equalsWithEpsilon(f,l)&&t.Scalar.WithinEpsilon(r.alpha,1,l)||(s.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,r.alpha]),null!=e.metallic&&1!==e.metallic&&(s.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(s.roughnessFactor=e.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||t.Tools.Warn(r.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),i?(u=[],(c=r instanceof t.PBRBaseMaterial?r._bumpTexture:r.geometryNormalTexture)&&u.push(this.exportTextureAsync(c).then(function(e){e&&(n.normalTexture=e,1!==c.level&&(n.normalTexture.scale=c.level))})),(h=r instanceof t.PBRBaseMaterial?r._ambientTexture:r.ambientOcclusionTexture)&&u.push(new Promise(function(e){return o(g,void 0,void 0,function(){var n,i,o,u;return a(this,function(a){switch(a.label){case 0:return r instanceof t.OpenPBRMaterial&&s.metallicRoughnessTexture?(n=this._exportTextureSampler(h),i=this._exporter._textures[s.metallicRoughnessTexture.index].source,o=this._exportTextureInfo(i,n,h.coordinatesIndex),this._textureMap.set(h.uniqueId,o),this._exporter._extensionsPostExportTextures("exporter",o,h),[2,e(o)]):[3,1];case 1:return u=e,[4,this.exportTextureAsync(h)];case 2:return[2,u.apply(void 0,[a.sent()])]}})})}).then(function(e){return o(g,void 0,void 0,function(){var s;return a(this,function(i){return e&&(s={index:e.index,texCoord:e.texCoord,extensions:e.extensions},n.occlusionTexture=s,r instanceof t.PBRBaseMaterial?s.strength=r._ambientTextureStrength:s.strength=r.ambientOcclusionTexture.level),[2]})})})),(d=r instanceof t.PBRBaseMaterial?r._emissiveTexture:r.emissionColorTexture)&&u.push(this.exportTextureAsync(d).then(function(e){e&&(n.emissiveTexture=e)})),u.length>0?(this._exporter._materialNeedsUVsSet.add(r),[4,Promise.all(u)]):[3,2]):[3,2];case 1:m.sent(),m.label=2;case 2:return(x=r instanceof t.PBRBaseMaterial?r._emissiveColor:r.emissionColor).equalsWithEpsilon(p,l)||(n.emissiveFactor=x.asArray()),n.pbrMetallicRoughness=s,[2]}})})},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return o(this,void 0,void 0,function(){var r,n,s,i,o,u;return a(this,function(a){switch(a.label){case 0:return r={},n={name:e.name},s=e.baseColor,i=e.geometryOpacity,s&&(r.baseColorFactor=[s.r,s.g,s.b,i]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,r,t)];case 1:return o=a.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(o,e,n,r,t)];case 2:return a.sent(),[4,this._finishMaterialAsync(n,e)];case 3:return a.sent(),(u=this._exporter._materials).push(n),[2,u.length-1]}})})},e.prototype.exportTextureAsync=function(e){return o(this,arguments,void 0,function(e,t){var r,n,s;return void 0===t&&(t=null),a(this,function(i){switch(i.label){case 0:return(r=this._textureMap.get(null!=t?t:e.uniqueId))?[2,r]:(n=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return s=i.sent(),r=this._exportTextureInfo(s,n,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,r),this._exporter._extensionsPostExportTextures("exporter",r,e),[2,r]}})})},e.prototype._exportTextureImageAsync=function(e){return o(this,void 0,void 0,function(){var r,n,s,i,u,l=this;return a(this,function(h){switch(h.label){case 0:return r=null!==(u=e.mimeType)&&void 0!==u?u:"none",n=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,n[s]=n[s]||{},void 0===(i=n[s][r])&&(i=o(l,void 0,void 0,function(){var n,s,i,o,u;return a(this,function(a){switch(a.label){case 0:return[4,c(e)];case 1:return!(n=a.sent())||!d(n.mimeType)||"none"!==r&&n.mimeType!==r?[3,3]:[4,this._exportImageAsync(e.name,new Blob([n.data],{type:n.mimeType}))];case 2:case 6:return[2,a.sent()];case 3:return s="image/png","none"!==r&&(d(r)?s=r:(s="image/png",t.Tools.Warn("Unsupported media type: ".concat(r,". Exporting texture as PNG.")))),i=e.getSize(),[4,t.GetTextureDataAsync(e)];case 4:return o=a.sent(),[4,t.EncodeImageAsync(o,i.width,i.height,s)];case 5:return u=a.sent(),[4,this._exportImageAsync(e.name,u)]}})}),n[s][r]=i),[4,i];case 1:return[2,h.sent()]}})})},e.prototype._exportImageAsync=function(e,r){return o(this,void 0,void 0,function(){var n,s,i,o,u,c,l;return a(this,function(a){switch(a.label){case 0:return n=this._exporter._images,this._exporter._shouldUseGlb?(s={name:e,mimeType:r.type,bufferView:void 0},[4,r.arrayBuffer()]):[3,2];case 1:return i=a.sent(),o=this._exporter._bufferManager.createBufferView(new Uint8Array(i)),this._exporter._bufferManager.setBufferView(s,o),[3,3];case 2:u=e.replace(/\.\/|\/|\.\\|\\/g,"_"),c=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"}}(r.type),l=u+c,n.some(function(e){return e.uri===l})&&(l="".concat(u,"_").concat(t.Tools.RandomId()).concat(c)),s={name:e,uri:l},this._exporter._imageData[l]=r,a.label=3;case 3:return n.push(s),[2,n.length-1]}})})},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,s=n.findIndex(function(r){return r.sampler==t&&r.source===e});-1===s&&(s=n.length,n.push({source:e,sampler:t}));var i={index:s};return r&&(i.texCoord=r),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex(function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT});return-1!==n?n:(r.push(t),r.length-1)},e}(),v=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function b(e,r){if(!(e instanceof t.TransformNode))return!1;if(r){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(v,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}var R=t.Vector3.ZeroReadOnly,M=t.Quaternion.Identity(),w=t.Vector3.OneReadOnly,A=new t.Vector3(-1,1,1);function E(e,t){var r=e.byteOffset,n=e.byteStride,s=e.type,i=e.normalized,o=e.getSize(),a=t.reduce(function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e},-Number.MAX_VALUE);return{byteOffset:r,byteStride:n,componentCount:o,type:s,count:a*o,normalized:i,totalVertices:a,kind:e.getKind()}}function C(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 I(e){return e.some(function(e){return e>=256})}function V(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 S(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 F(e){return e.x*=-1,e}function B(e){return v.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(v,e),e}function N(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),r=Math.abs(e.y);if(t>r){var n=Math.sign(e.x);e.x=t,e.y*=-n,e.z*=-n,e.w*=n}else n=Math.sign(e.y),e.x*=-n,e.y=r,e.z*=n,e.w*=-n}else{var s=Math.abs(e.z),i=Math.abs(e.w);s>i?(n=Math.sign(e.z),e.x*=-n,e.y*=n,e.z=s,e.w*=-n):(n=Math.sign(e.w),e.x*=n,e.y*=-n,e.z*=-n,e.w=i)}return e}function O(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function U(e,r){var n=t.Vector3.FromArrayToRef(r.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),s=t.Quaternion.FromArrayToRef(r.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(w,s,n,t.TmpVectors.Matrix[0]),o=t.Vector3.FromArrayToRef(e.translation||[0,0,0],0,t.TmpVectors.Vector3[2]),a=t.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[1]),u=t.Matrix.ComposeToRef(w,a,o,t.TmpVectors.Matrix[1]);i.multiplyToRef(u,u),u.decompose(void 0,s,n),n.equalsWithEpsilon(R,t.Epsilon)?delete r.translation:r.translation=n.asArray(),s.equalsWithEpsilon(M,t.Epsilon)?delete r.rotation:r.rotation=s.asArray(),r.scale&&delete r.scale}function P(e,r){if(!(r instanceof t.TransformNode))return!1;if(1!==r.getChildren().length||0!==e.getChildren().length||e.parent!==r)return!1;var n=e.getScene(),s=e instanceof t.TargetCamera&&!n.useRightHandedSystem?A:w;return!!r.scaling.equalsWithEpsilon(s,t.Epsilon)||(t.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(r.name," with modified scaling.")),!1)}function K(e,t){for(var r=0,n=Object.entries(e);r<n.length;r++){var s=n[r],i=s[0],o=s[1],a=t[i];(Array.isArray(o)&&Array.isArray(a)&&W(o,a)||o===a)&&delete e[i]}return e}function W(e,t){return e.length===t.length&&e.every(function(e,r){return e===t[r]})}var H=new Map([[Int8Array,function(e,t,r){return e.setInt8(t,r)}],[Uint8Array,function(e,t,r){return e.setUint8(t,r)}],[Uint8ClampedArray,function(e,t,r){return e.setUint8(t,r)}],[Int16Array,function(e,t,r){return e.setInt16(t,r,!0)}],[Uint16Array,function(e,t,r){return e.setUint16(t,r,!0)}],[Int32Array,function(e,t,r){return e.setInt32(t,r,!0)}],[Uint32Array,function(e,t,r){return e.setUint32(t,r,!0)}],[Float32Array,function(e,t,r){return e.setFloat32(t,r,!0)}],[Float64Array,function(e,t,r){return e.setFloat64(t,r,!0)}]]),L=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=H.get(e.constructor),r=0;r<e.length;r++)t(this._dataView,this._byteOffset,e[r]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var r=new Uint8Array(2*t);r.set(this._data),this._data=r,this._dataView=new DataView(this._data.buffer)}},e}();function z(e){return e%4==0?4:e%2==0?2:1}var k,G=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach(function(e){t+=e.byteLength});for(var r=new L(t),n=0,s=Array.from(this._bufferViewToData.keys()).sort(function(e,t){return z(t.byteLength)-z(e.byteLength)});n<s.length;n++){var i=s[n];i.byteOffset=r.byteOffset,e.push(i);for(var o=e.length-1,a=0,u=this.getPropertiesWithBufferView(i);a<u.length;a++)u[a].bufferView=o;r.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return r.getOutputData()},e.prototype.createBufferView=function(e,t){var r={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(r,e),r},e.prototype.createAccessor=function(e,t,r,n,s,i,o){this._verifyBufferView(e);var a={bufferView:void 0,componentType:r,count:n,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,byteOffset:s};return this.setBufferView(a,e),this._accessorToBufferView.set(a,e),a},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,r=0,n=this.getPropertiesWithBufferView(e);r<n.length;r++){var s=n[r];void 0!==s.bufferView&&delete s.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach(function(r,n){r===e&&(void 0!==n.byteOffset&&delete n.byteOffset,t._accessorToBufferView.delete(n))})},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(k||(k={}));var D=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(r,n,s,i,o){if(this._IsTransformable(r)){var a=[],u=[],c=n.getKeys(),l=e._CalculateMinMaxKeyFrames(c),h=e._DeduceInterpolation(c,s,i),f=h.interpolationType,p=h.shouldBakeAnimation;if(p?e._CreateBakedAnimation(r,n,s,l.min,l.max,n.framePerSecond,o,a,u,l,i):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(r,n,s,a,u,i):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(r,n,s,a,u,i):e._CreateBakedAnimation(r,n,s,l.min,l.max,n.framePerSecond,o,a,u,l,i),a.length&&u.length)return{inputs:a,outputs:u,samplerInterpolation:f,inputsMin:p?l.min:t.Tools.FloatRound(l.min/n.framePerSecond),inputsMax:p?l.max:t.Tools.FloatRound(l.max/n.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var r=null,n="VEC3",s=!1,i=e.targetProperty.split(".");switch(i[0]){case"scaling":r="scale";break;case"position":r="translation";break;case"rotation":n="VEC4",r="rotation";break;case"rotationQuaternion":n="VEC4",s=!0,r="rotation";break;case"influence":n="SCALAR",r="weights";break;default:t.Tools.Error("Unsupported animatable property ".concat(i[0]))}return r?{animationChannelTargetPath:r,dataAccessorType:n,useQuaternion:s}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,s,i,o,a,u,c,l,h){var f;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var x=d[p];if(!h||h(x)){var g=e._DeduceAnimationInfo(x);g&&(f={name:x.name,samplers:[],channels:[]},e._AddAnimation("".concat(x.name),x.hasRunningRuntimeAnimations?r:f,t,x,g.dataAccessorType,g.animationChannelTargetPath,s,o,a,u,g.useQuaternion,c,l),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(r,n,s,i,o,a,u,c,l,h,f){var p;if(r instanceof t.Mesh){var d=r.morphTargetManager;if(d)for(var x=0;x<d.numTargets;++x)for(var g=0,_=d.getTarget(x).animations;g<_.length;g++){var m=_[g];if(!f||f(m)){for(var T=new t.Animation("".concat(m.name),"influence",m.framePerSecond,m.dataType,m.loopMode,m.enableBlending),y=[],v=m.getKeys(),b=0;b<v.length;++b)for(var R=v[b],M=0;M<d.numTargets;++M)M==x?y.push(R):y.push({frame:R.frame,value:0});T.setKeys(y,!0);var w=e._DeduceAnimationInfo(T);w&&(p={name:T.name,samplers:[],channels:[]},e._AddAnimation(m.name,m.hasRunningRuntimeAnimations?n:p,r,T,w.dataAccessorType,w.animationChannelTargetPath,i,a,u,c,w.useQuaternion,l,h,d.numTargets),p.samplers.length&&p.channels.length&&s.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(r,n,s,i,o,a,u,c,l){var h,f;if(r.animationGroups)for(var p=r.animationGroups,d=function(p){var d=new Map,g=new Map,_=new Set,m=p.to-p.from;f={name:p.name,channels:[],samplers:[]};for(var T=function(n){var m=p.targetedAnimations[n],T=m.target,y=m.animation;if(l&&!l(y))return"continue";var v=c.has(T);if(x._IsTransformable(T)||1===T.length&&x._IsTransformable(T[0])){if(R=e._DeduceAnimationInfo(m.animation)){var b=x._IsTransformable(T)?T:x._IsTransformable(T[0])?T[0]:null;b&&e._AddAnimation("".concat(y.name),f,b,y,R.dataAccessorType,R.animationChannelTargetPath,s,i,o,a,R.useQuaternion,u,v)}}else if(T instanceof t.MorphTarget||1===T.length&&T[0]instanceof t.MorphTarget){var R;if(R=e._DeduceAnimationInfo(m.animation)){var M=T instanceof t.MorphTarget?T:T[0];if(M){var w=r.morphTargetManagers.find(function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===M)return!0;return!1});if(w){var A=r.meshes.find(function(e){return e.morphTargetManager===w});A&&(d.has(A)||d.set(A,new Map),null===(h=d.get(A))||void 0===h||h.set(M,y),_.add(A),g.set(A,y))}}}}},y=0;y<p.targetedAnimations.length;++y)T(y);_.forEach(function(r){for(var n=r.morphTargetManager,c=null,l=[],h=g.get(r).getKeys(),x=h.length,_=0;_<x;++_)for(var T=0;T<n.numTargets;++T){var y=n.getTarget(T),v=d.get(r);if(v){var b=v.get(y);b?(c||(c=new t.Animation("".concat(p.name,"_").concat(r.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[_])):l.push({frame:p.from+m/x*_,value:y.influence,inTangent:h[0].inTangent?0:void 0,outTangent:h[0].outTangent?0:void 0})}}c.setKeys(l,!0);var R=e._DeduceAnimationInfo(c);R&&e._AddAnimation("".concat(p.name,"_").concat(r.name,"_MorphWeightAnimation"),f,r,c,R.dataAccessorType,R.animationChannelTargetPath,s,i,o,a,R.useQuaternion,u,!1,null==n?void 0:n.numTargets)}),f.channels.length&&f.samplers.length&&n.push(f)},x=this,g=0,_=p;g<_.length;g++)d(_[g])},e._AddAnimation=function(r,n,s,i,o,a,u,c,l,h,f,p,d,x){var g,_,m,T,y,v,b=e._CreateNodeAnimation(s,i,a,f,p);if(b){if(x){for(var R=0,M=void 0,w=[];b.inputs.length>0;)M=b.inputs.shift(),R%x==0&&w.push(M),R++;b.inputs=w}var A=u.get(s),E=new Float32Array(b.inputs);g=c.createBufferView(E),_=c.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),h.push(_),m=h.length-1;var I=new t.Quaternion,V=new t.Vector3,S=new t.Vector3,B=s instanceof t.Camera,U=C(o),P=new Float32Array(b.outputs.length*U);b.outputs.forEach(function(e,r){var n=e;switch(a){case"translation":d&&(t.Vector3.FromArrayToRef(e,0,S),F(S),S.toArray(n));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,I):(n=new Array(4),t.Vector3.FromArrayToRef(e,0,V),t.Quaternion.FromEulerVectorToRef(V,I)),d&&(N(I),B&&O(I)),I.toArray(n)}P.set(n,r*U)}),g=c.createBufferView(P),_=c.createAccessor(g,o,5126,b.outputs.length),h.push(_),T=h.length-1,y={interpolation:b.samplerInterpolation,input:m,output:T},n.samplers.push(y),v={sampler:n.samplers.length-1,target:{node:A,path:a}},n.channels.push(v)}},e._CreateBakedAnimation=function(r,n,s,i,o,a,u,c,l,h,f){var p,d,x,g,_,m,T=t.Quaternion.Identity(),y=null,v=null;h.min=t.Tools.FloatRound(i/a);for(var b=n.getKeys(),R=0,M=b.length;R<M;++R){if(x=b[R],R+1<M)if(g=b[R+1],x.value.equals&&x.value.equals(g.value)||x.value===g.value){if(0!==R)continue;m=x.frame}else m=g.frame;else{if(_=b[R-1],x.value.equals&&x.value.equals(_.value)||x.value===_.value)continue;m=o}if(m)for(var w=x.frame;w<=m;w+=u)if((d=t.Tools.FloatRound(w/a))!==y){y=d,v=d;var A={key:0,repeatCount:0,loopMode:n.loopMode};p=n._interpolate(w,A),e._SetInterpolatedValue(r,p,d,n,s,T,c,l,f)}}v&&(h.max=v)},e._ConvertFactorToVector3OrQuaternion=function(r,n,s,i,o){var a=e._GetBasePositionRotationOrScale(n,i,o),u=s.targetProperty.split("."),c=u?u[1]:"",l=o?t.Quaternion.FromArray(a).normalize():t.Vector3.FromArray(a);switch(c){case"x":case"y":case"z":l[c]=r;break;case"w":l.w=r;break;default:t.Tools.Error('glTFAnimation: Unsupported component name "'.concat(c,'"!'))}return l},e._SetInterpolatedValue=function(e,r,n,s,i,o,a,u,c){var l;a.push(n),"weights"!==i?(s.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(r=this._ConvertFactorToVector3OrQuaternion(r,e,s,i,c)),"rotation"===i?(c?o=r:(l=r,t.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,o)),u.push(o.asArray())):(l=r,u.push(l.asArray()))):u.push([r])},e._CreateLinearOrStepAnimation=function(t,r,n,s,i,o){for(var a=0,u=r.getKeys();a<u.length;a++){var c=u[a];s.push(c.frame/r.framePerSecond),e._AddKeyframeValue(c,r,i,n,t,o)}},e._CreateCubicSplineAnimation=function(t,r,n,s,i,o){r.getKeys().forEach(function(a){s.push(a.frame/r.framePerSecond),e._AddSplineTangent(k.INTANGENT,i,n,"CUBICSPLINE",a,o),e._AddKeyframeValue(a,r,i,n,t,o),e._AddSplineTangent(k.OUTTANGENT,i,n,"CUBICSPLINE",a,o)})},e._GetBasePositionRotationOrScale=function(e,r,n){var s;if("rotation"===r)if(n){var i=e.rotationQuaternion;s=(null!=i?i:t.Quaternion.Identity()).asArray()}else{var o=e.rotation;s=(null!=o?o:t.Vector3.Zero()).asArray()}else if("translation"===r){var a=e.position;s=(null!=a?a:t.Vector3.Zero()).asArray()}else{var u=e.scaling;s=(null!=u?u:t.Vector3.One()).asArray()}return s},e._AddKeyframeValue=function(e,r,n,s,i,o){var a,u=r.dataType;if(u===t.Animation.ANIMATIONTYPE_VECTOR3){var c=e.value.asArray();if("rotation"===s){var l=t.Vector3.FromArray(c);c=t.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}n.push(c)}else if(u===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===s)n.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,i,r,s,o)){if("rotation"===s){var h=o?a:t.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();n.push(h.asArray())}n.push(a.asArray())}}else u===t.Animation.ANIMATIONTYPE_QUATERNION?n.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,s,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var o=0,a=e.length;o<a;++o)if((s=e[o]).inTangent||s.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||s.interpolation&&1===s.interpolation&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=s.interpolation&&1===s.interpolation?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,r,n,s,i,o){var a,u=e===k.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===s){if("rotation"===n)if(u)if(o)a=u.asArray();else{var c=u;a=t.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}else a=[0,0,0,0];else a="weights"===n?u?[u]:[0]:u?u.asArray():[0,0,0];r.push(a)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)}),{min:t,max:r}},e}();function q(e,r,n,s,i,o){var a={attributes:{},influence:e.influence,name:e.name},u=r.geometry;if(!u)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;var c,l=o?-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),x=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];c=p.length/3;for(var _=0;_<c;++_){var m=t.Vector3.FromArray(p,3*_);t.Vector3.FromArray(f,3*_).subtractToRef(m,h),h.x*=l,x[0]=Math.min(x[0],h.x),g[0]=Math.max(g[0],h.x),x[1]=Math.min(x[1],h.y),g[1]=Math.max(g[1],h.y),x[2]=Math.min(x[2],h.z),g[2]=Math.max(g[2],h.z),d[3*_]=h.x,d[3*_+1]=h.y,d[3*_+2]=h.z}var T=n.createBufferView(d,12),y=n.createAccessor(T,"VEC3",5126,f.length/3,0,{min:x,max:g});i.push(y),a.attributes.POSITION=i.length-1}else t.Tools.Warn("Morph target positions for mesh ".concat(r.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var v=e.getNormals(),b=u.getVerticesData(t.VertexBuffer.NormalKind);if(b){var R=new Float32Array(b.length);for(c=b.length/3,_=0;_<c;++_){var M=t.Vector3.FromArray(b,3*_).normalize();t.Vector3.FromArray(v,3*_).normalize().subtractToRef(M,h),R[3*_]=h.x*l,R[3*_+1]=h.y,R[3*_+2]=h.z}T=n.createBufferView(R,12),y=n.createAccessor(T,"VEC3",5126,v.length/3,0),i.push(y),a.attributes.NORMAL=i.length-1}else t.Tools.Warn("Morph target normals for mesh ".concat(r.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var w=e.getTangents(),A=u.getVerticesData(t.VertexBuffer.TangentKind);if(A){c=A.length/4;var E=new Float32Array(3*c);for(_=0;_<c;++_){var C=t.Vector3.FromArray(A,4*_);S(C);var I=t.Vector3.FromArray(w,3*_);S(I),I.subtractToRef(C,h),E[3*_]=h.x*l,E[3*_+1]=h.y,E[3*_+2]=h.z}T=n.createBufferView(E,12),y=n.createAccessor(T,"VEC3",5126,c,0),i.push(y),a.attributes.TANGENT=i.length-1}else t.Tools.Warn("Morph target tangents for mesh ".concat(r.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var V=e.getColors(),F=u.getVerticesData(t.VertexBuffer.ColorKind),B=u.getVertexBuffer(t.VertexBuffer.ColorKind);if(F&&B){var N=B.getSize();c=F.length/N;var O=new Float32Array(c*N);for(_=0;_<c;++_)if(3===N){var U=t.Vector3.FromArray(F,_*N);t.Vector3.FromArray(V,_*N).subtractToRef(U,h),O[3*_]=h.x,O[3*_+1]=h.y,O[3*_+2]=h.z}else if(4===N){var P=new t.Vector4;U=t.Vector4.FromArray(F,_*N),t.Vector4.FromArray(V,_*N).subtractToRef(U,P),O[4*_]=P.x,O[4*_+1]=P.y,O[4*_+2]=P.z,O[4*_+3]=P.w}else t.Tools.Warn("Unsupported number of components for color attribute: ".concat(N));T=n.createBufferView(O,4*N),y=n.createAccessor(T,3===N?"VEC3":"VEC4",5126,c,0),i.push(y),a.attributes.COLOR_0=i.length-1}else t.Tools.Warn("Morph target colors for mesh ".concat(r.name," were not exported. Mesh does not have colors vertex data"))}return a}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,r,n,s){var i,o,a,u;return null===(u=null===(a=null===(o=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===o?void 0:o.get(r))||void 0===a?void 0:a.get(n))||void 0===u?void 0:u.get(s)},e.prototype.setIndicesAccessor=function(e,t,r,n,s,i){var o=this._indicesAccessorMap.get(e);o||(o=new Map,this._indicesAccessorMap.set(e,o));var a=o.get(t);a||(a=new Map,o.set(t,a));var u=a.get(r);u||(u=new Map,a.set(r,u));var c=u.get(n);c||(c=new Map,u.set(n,c)),c.set(s,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,r){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,r)},e.prototype.getRemappedBufferView=function(e,t){var r;return null===(r=this._remappedBufferView.get(e))||void 0===r?void 0:r.get(t)},e.prototype.getVertexAccessor=function(e,t,r){var n,s;return null===(s=null===(n=this._vertexAccessorMap.get(e))||void 0===n?void 0:n.get(t))||void 0===s?void 0:s.get(r)},e.prototype.setVertexAccessor=function(e,t,r,n){var s=this._vertexAccessorMap.get(e);s||(s=new Map,this._vertexAccessorMap.set(e,s));var i=s.get(t);i||(i=new Map,s.set(t,i)),i.set(r,n)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var r=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,r),-1===r.indexOf(t)&&r.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),X=function(){function e(e,r){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 y(this),this._extensions={},this._bufferManager=new G,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=i({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"},r),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,r,n){var s=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then(function(e){return o(s,void 0,void 0,function(){var s;return a(this,function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,r+1,n)]:[3,2];case 1:return s=i.sent(),[3,3];case 2:s=null,i.label=3;case 3:return[2,s]}})})}):this._ApplyExtension(e,t,r+1,n)},e.prototype._ApplyExtensions=function(t,r){for(var n=[],s=0,i=e._ExtensionNames;s<i.length;s++){var o=i[s];n.push(this._extensions[o])}return this._ApplyExtension(t,n,0,r)},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,s){var i=this;return this._ApplyExtensions(t,function(t,o){return t.postExportNodeAsync&&t.postExportNodeAsync(e,o,r,n,s,i._bufferManager)})},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._ApplyExtensions(t,function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)})},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,r,n){return o(this,void 0,void 0,function(){var s,i=this;return a(this,function(u){switch(u.label){case 0:return s=[],[4,Promise.all(e._ExtensionNames.map(function(e){return o(i,void 0,void 0,function(){var i,o;return a(this,function(a){switch(a.label){case 0:return(i=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,i.postExportMaterialAdditionalTexturesAsync(t,r,n)]:[3,2];case 1:o=a.sent(),s.push.apply(s,o),a.label=2;case 2:return[2]}})})}))];case 1:return u.sent(),[2,s]}})})},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var s=0,i=e._ExtensionNames;s<i.length;s++){var o=i[s],a=this._extensions[o];a.postExportTexture&&a.postExportTexture(t,r,n)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var s=n[r],i=this._extensions[s];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return o(this,void 0,void 0,function(){var t,r,n,s;return a(this,function(i){switch(i.label){case 0:t=0,r=e._ExtensionNames,i.label=1;case 1:return t<r.length?(n=r[t],(s=this._extensions[n]).preGenerateBinaryAsync?[4,s.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 r=0,n=e._ExtensionNames;r<n.length;r++){var s=n[r],i=this._extensions[s];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions(function(t){var r,n,s;t.wasUsed&&((r=e._glTF).extensionsUsed||(r.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((n=e._glTF).extensionsRequired||(n.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(s=e._glTF).extensions||(s.extensions={}),t.onExporting&&t.onExporting())})},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],s=e._ExtensionFactories[n](this);this._extensions[n]=s}},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(r,n,s){void 0===s&&(s=100),e.UnregisterExtension(r)&&t.Tools.Warn("Extension with the name ".concat(r," already exists")),e._ExtensionFactories[r]=n;var i=null!=s?s:0;e._ExtensionOrders[r]=i;for(var o=e._ExtensionNames.length,a=0;a<e._ExtensionNames.length;a++){var u=e._ExtensionNames[a];if(i<e._ExtensionOrders[u]){o=a;break}}e._ExtensionNames.splice(o,0,r)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._generateJSON=function(e,t,r){var n={byteLength:e};return n.byteLength&&(this._glTF.buffers=[n]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(n.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return o(this,void 0,void 0,function(){var t,r,s,i,o,u,c;return a(this,function(a){switch(a.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=a.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength,e,!0),s=new Blob([t],{type:"application/octet-stream"}),i=e+".gltf",o=e+".bin",(u=new n).files[i]=r,u.files[o]=s,this._imageData)for(c in this._imageData)u.files[c]=this._imageData[c];return[2,u]}})})},e.prototype._generateBinaryAsync=function(){return o(this,void 0,void 0,function(){return a(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 o(this,void 0,void 0,function(){var t,r,s,i,o,u,c,l,h,f,p,d,x,g;return a(this,function(a){switch(a.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=a.sent(),this._extensionsOnExporting(),r=this._generateJSON(t.byteLength),s=e+".glb",i=r.length,"undefined"!=typeof TextEncoder&&(u=new TextEncoder,o=u.encode(r),i=o.length),c=this._getPadding(i),l=this._getPadding(t.byteLength),h=28+i+c+t.byteLength+l,(f=new L(h)).writeUInt32(1179937895),f.writeUInt32(2),f.writeUInt32(h),f.writeUInt32(i+c),f.writeUInt32(1313821514),o)f.writeTypedArray(o);else for(p="_".charCodeAt(0),x=0;x<i;++x)(d=r.charCodeAt(x))!=r.codePointAt(x)?f.writeUInt8(p):f.writeUInt8(d);for(x=0;x<c;++x)f.writeUInt8(32);for(f.writeUInt32(t.byteLength+l),f.writeUInt32(5130562),f.writeTypedArray(t),x=0;x<l;++x)f.writeUInt8(0);return(g=new n).files[s]=new Blob([f.getOutputData()],{type:"application/octet-stream"}),[2,g]}})})},e.prototype._setNodeTransformation=function(e,r,n){var s;if(r.getPivotPoint().equalsWithEpsilon(R,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!r.position.equalsWithEpsilon(R,t.Epsilon)){var i=t.TmpVectors.Vector3[0].copyFrom(r.position);n&&F(i),e.translation=i.asArray()}r.scaling.equalsWithEpsilon(w,t.Epsilon)||(e.scale=r.scaling.asArray());var o=(null===(s=r.rotationQuaternion)||void 0===s?void 0:s.clone())||t.Quaternion.FromEulerAngles(r.rotation.x,r.rotation.y,r.rotation.z);o.equalsWithEpsilon(M,t.Epsilon)||(n&&N(o),e.rotation=o.normalize().asArray())},e.prototype._setCameraTransformation=function(e,r,n){var s=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],o=r.getWorldMatrix();if(r.parent){var a=r.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);o.multiplyToRef(a,t.TmpVectors.Matrix[1]).decompose(void 0,i,s)}else o.decompose(void 0,i,s);s.equalsWithEpsilon(R,t.Epsilon)||(n&&F(s),e.translation=s.asArray()),n&&N(i),this._babylonScene.useRightHandedSystem||O(i),i.equalsWithEpsilon(M,t.Epsilon)||(e.rotation=i.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,r=this._babylonScene.cameras;e<r.length;e++){var n=r[e],s={type:n.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(n.name&&(s.name=n.name),"perspective"===s.type)s.perspective={aspectRatio:n.getEngine().getAspectRatio(n),yfov:n.fovMode===t.Camera.FOVMODE_VERTICAL_FIXED?n.fov:n.fov*n.getEngine().getAspectRatio(n),znear:n.minZ,zfar:n.maxZ};else if("orthographic"===s.type){var i=n.orthoLeft&&n.orthoRight?.5*(n.orthoRight-n.orthoLeft):.5*n.getEngine().getRenderWidth(),o=n.orthoBottom&&n.orthoTop?.5*(n.orthoTop-n.orthoBottom):.5*n.getEngine().getRenderHeight();s.orthographic={xmag:i,ymag:o,znear:n.minZ,zfar:n.maxZ}}this._camerasMap.set(n,s)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var r=t[e],n=this._nodesCameraMap.get(r);if(void 0!==n){this._cameras.push(r);for(var s=0,i=n;s<i.length;s++)i[s].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var r=t[e];r.bones.length<=0||this._skinMap.set(r,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var r,n=function(n){if(n.bones.length<=0)return"continue";var i=s._skinMap.get(n);if(null==i)return"continue";for(var o={},a=-1,u=0;u<n.bones.length;++u){var c=n.bones[u];-1!==(h=null!==(r=c.getIndex())&&void 0!==r?r:u)&&(o[h]=c,h>a&&(a=h))}for(var l=[],h=0;h<=a;++h){var f=(c=o[h]).getTransformNode(),p=f?s._nodeMap.get(f):void 0;if(void 0!==p){i.joints.push(p);var d=c.getAbsoluteInverseBindMatrix().clone();e.has(f)&&B(d),l.push(d)}else t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var x=s._nodesSkinMap.get(i);if(i.joints.length>0&&void 0!==x){var g=new Float32Array(16*l.length);l.forEach(function(e,t){g.set(e.m,16*t)});var _=s._bufferManager.createBufferView(g);s._accessors.push(s._bufferManager.createAccessor(_,"MAT4",5126,l.length)),i.inverseBindMatrices=s._accessors.length-1,s._skins.push(i);for(var m=s._skins.length-1,T=0,y=x;T<y.length;T++)y[T].skin=m}},s=this,i=0,o=this._babylonScene.skeletons;i<o.length;i++)n(o[i])},e.prototype._exportSceneAsync=function(){return o(this,void 0,void 0,function(){var e,r,n,s,i,o,u,c,l,h,f,p,d,x,g,_,m,T,y,v,R,M,w,A,E,C,I,V,S,F,B,N,O;return a(this,function(a){switch(a.label){case 0:if(e={nodes:[]},this._babylonScene.metadata&&(r=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=r),n=new Array,s=new Array,i=new Array,this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(u=0,c=this._babylonScene.animationGroups;u<c.length;u++)for(l=c[u],h=0,f=l.targetedAnimations;h<f.length;h++)p=f[h],(d=p.target)instanceof t.TransformNode&&!d.parent&&(null!=o?o:o=new Set).add(d);for(x=0,g=this._babylonScene.rootNodes;x<g.length;x++)_=g[x],m=_.animations,T=!!m&&m.length>0||(null==o?void 0:o.has(_)),this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&b(_,this._babylonScene.useRightHandedSystem)&&!T?i.push.apply(i,_.getChildren()):this._babylonScene.useRightHandedSystem?n.push(_):s.push(_);return this._listAvailableCameras(),this._listAvailableSkeletons(),y=new j(!0,!1),R=(v=(B=e.nodes).push).apply,M=[B],[4,this._exportNodesAsync(s,y)];case 1:return R.apply(v,M.concat([a.sent()])),w=new j(!1,!1),E=(A=(N=e.nodes).push).apply,C=[N],[4,this._exportNodesAsync(n,w)];case 2:return E.apply(A,C.concat([a.sent()])),I=new j(!1,!0),S=(V=(O=e.nodes).push).apply,F=[O],[4,this._exportNodesAsync(i,I)];case 3:return S.apply(V,F.concat([a.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(y.getNodesSet()),this._babylonScene.animationGroups.length&&D._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,y.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 o(this,void 0,void 0,function(){var r,n,s,i;return a(this,function(o){switch(o.label){case 0:r=new Array,this._exportBuffers(e,t),n=0,s=e,o.label=1;case 1:return n<s.length?(i=s[n],[4,this._exportNodeAsync(i,r,t)]):[3,4];case 2:o.sent(),o.label=3;case 3:return n++,[3,1];case 4:return[2,r]}})})},e.prototype._collectBuffers=function(e,r,n,s,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){var o=e.geometry.getVertexBuffers();if(o)for(var a in o)if(V(a)){var u=o[a];i.setHasVertexColorAlpha(u,e.hasVertexAlpha);var c=u._buffer,l=r.get(c)||[];r.set(c,l),-1===l.indexOf(u)&&l.push(u);var h=n.get(u)||[];n.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=s.get(d)||[],s.set(d,h),-1===h.indexOf(e)&&h.push(e)}}for(var x=0,g=e.getChildren();x<g.length;x++){var _=g[x];this._collectBuffers(_,r,n,s,i)}},e.prototype._exportBuffers=function(e,r){for(var n=new Map,s=new Map,i=new Map,o=0,a=e;o<a.length;o++){var u=a[o];this._collectBuffers(u,n,s,i,r)}for(var c=Array.from(n.keys()),l=function(e){var i=e.getData();if(!i)throw new Error("Buffer data is not available");var o=n.get(e);if(!o)return"continue";var a=o[0].byteStride;if(o.some(function(e){return e.byteStride!==a}))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var 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 r=s.get(e),n=E(e,r),i=n.byteOffset,o=n.byteStride,a=n.componentCount,c=n.type,l=n.count,f=n.normalized;switch(n.kind){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,i,o,a,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 r=1/t;e[0]*=r,e[1]*=r,e[2]*=r}});break;case t.VertexBuffer.ColorKind:var p=r.filter(function(e){return e.material instanceof t.StandardMaterial||null==e.material}).length;if(0==p)break;if(p!=r.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,x=new t.Color4,g=h._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(u,i,o,a,c,l,f,function(e){3===e.length?(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0)):(x.fromArray(e,0),x.toLinearSpaceToRef(x,g),x.toArray(e,0))})}},l=0,f=o;l<f.length;l++)c(N=f[l]);if(r.convertToRightHanded){for(var p=0,d=o;p<d.length;p++){var x=E(N=d[p],s.get(N)),g=x.byteOffset,_=x.byteStride,m=x.componentCount,T=x.type,y=x.count,v=x.normalized;switch(C=x.kind){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,g,_,m,T,y,v,function(e){e[0]=-e[0]})}}r.convertedToRightHandedBuffers.set(e,u)}var b=h._bufferManager.createBufferView(u,a);r.setVertexBufferView(e,b);for(var R=new Map,M=0,w=o;M<w.length;M++){var A=E(N=w[M],s.get(N)),C=A.kind,V=A.totalVertices;switch(C){case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:if(N.type==t.VertexBuffer.FLOAT){var S=N.getFloatData(V);null!==S&&R.set(N,S)}}}0!==R.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 F=0,B=Array.from(R.keys());F<B.length;F++){var N=B[F],O=R.get(N);if(O){for(var U=I(O),P=new(U?Uint16Array:Uint8Array)(O.length),K=0;K<O.length;K++)P[K]=O[K];var W=h._bufferManager.createBufferView(P,4*(U?2:1));r.setRemappedBufferView(e,N,W)}}},h=this,f=0,p=c;f<p.length;f++)l(p[f]);for(var d=0,x=Array.from(i.keys());d<x.length;d++){var g=x[d],_=i.get(g);if(_)for(var m=q(g,_[0],this._bufferManager,this._bufferViews,this._accessors,r.convertToRightHanded),T=0,y=_;T<y.length;T++){var v=y[T];r.bindMorphDataToMesh(v,m)}}},e.prototype._exportNodeAsync=function(e,t,r){return o(this,void 0,void 0,function(){var n,s,i,o,u,c,l,h,f=this;return a(this,function(a){switch(a.label){case 0:return void 0!==(n=this._nodeMap.get(e))?(t.includes(n)||t.push(n),[2]):[4,this._createNodeAsync(e,r)];case 1:(s=a.sent())&&(n=this._nodes.length,this._nodes.push(s),this._nodeMap.set(e,n),r.pushExportedNode(e),t.push(n),i={name:"runtime animations",channels:[],samplers:[]},o=[],this._babylonScene.animationGroups.length||(D._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&D._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,r.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),o.forEach(function(e){e.channels.length&&e.samplers.length&&f._animations.push(e)})),u=s?[]:t,c=0,l=e.getChildren(),a.label=2;case 2:return c<l.length?(h=l[c],[4,this._exportNodeAsync(h,u,r)]):[3,5];case 3:a.sent(),a.label=4;case 4:return c++,[3,2];case 5:return s&&u.length&&(s.children=u),[2]}})})},e.prototype._createNodeAsync=function(e,r){return o(this,void 0,void 0,function(){var n,s,i,o,u,c,l,h,f,p,d,x;return a(this,function(a){switch(a.label){case 0:return this._shouldExportNode(e)?(n={},e.name&&(n.name=e.name),e.metadata&&(s=this._options.metadataSelector(e.metadata))&&(n.extras=s),e instanceof t.TransformNode?(this._setNodeTransformation(n,e,r.convertToRightHanded),e instanceof t.AbstractMesh?(i=e instanceof t.InstancedMesh?e.sourceMesh:e).subMeshes&&i.subMeshes.length>0?(o=n,[4,this._exportMeshAsync(i,r)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:o.mesh=a.sent(),a.label=2;case 2:e.skeleton&&void 0!==(u=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(u)&&this._nodesSkinMap.set(u,[]),null===(p=this._nodesSkinMap.get(u))||void 0===p||p.push(n)),a.label=3;case 3:if(e instanceof t.TargetCamera&&(c=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(c)&&this._nodesCameraMap.set(c,[]),this._setCameraTransformation(n,e,r.convertToRightHanded),null!==(l=e.parent)&&P(e,l)&&void 0!==(h=this._nodeMap.get(l)))return f=this._nodes[h],U(n,f),null===(d=this._nodesCameraMap.get(c))||void 0===d||d.push(f),[2,null];null===(x=this._nodesCameraMap.get(c))||void 0===x||x.push(n)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",n,e,this._nodeMap,r.convertToRightHanded)];case 4:return a.sent()?[2,n]:(t.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}})})},e.prototype._exportIndices=function(e,r,n,s,i,o,a,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))}(o);var h=a!==t.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case t.Material.TriangleFillMode:case t.Material.TriangleStripDrawMode:case t.Material.TriangleFanDrawMode:return!0}return!1}(o);if(h){if(o===t.Material.TriangleStripDrawMode||o===t.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");var f=r?new Uint32Array(s):new Uint16Array(s);if(e)for(var p=0;p+2<s;p+=3)f[p]=e[n+p]+i,f[p+1]=e[n+p+2]+i,f[p+2]=e[n+p+1]+i;else for(p=0;p+2<s;p+=3)f[p]=p,f[p+1]=p+2,f[p+2]=p+1;l=f}else if(e&&0!==i){for(f=r?new Uint32Array(s):new Uint16Array(s),p=0;p<s;p++)f[p]=e[n+p]+i;l=f}else e&&(l=function(e,t,r,n){var s=e;return 0===t&&r===e.length||(s=Array.isArray(e)?e.slice(t,t+r):e.subarray(t,t+r)),s instanceof Int32Array?new Uint32Array(s.buffer,s.byteOffset,s.length):Array.isArray(s)?n?new Uint32Array(s):new Uint16Array(s):s}(e,n,s,r));if(l){var d=u.getIndicesAccessor(e,n,s,i,h);if(void 0===d){var x=this._bufferManager.createBufferView(l),g=r?5125:5123;this._accessors.push(this._bufferManager.createAccessor(x,"SCALAR",g,s,0)),d=this._accessors.length-1,u.setIndicesAccessor(e,n,s,i,h,d)}c.indices=d}},e.prototype._exportVertexBuffer=function(e,r,n,s,i,o){var a=e.getKind();if(V(a)&&(!a.startsWith("uv")||this._options.exportUnusedUVs||r&&this._materialNeedsUVsSet.has(r))){var u=i.getVertexAccessor(e,n,s);if(void 0===u){var c=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),l=a===t.VertexBuffer.PositionKind?function(e,r,n,s){var i=r.byteOffset,o=r.byteStride,a=r.type,u=r.normalized,c=r.getSize(),l=new Array(c).fill(1/0),h=new Array(c).fill(-1/0);return t.EnumerateFloatValues(e,i+n*o,o,c,a,s*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,n,s):void 0,h=(a===t.VertexBuffer.MatricesIndicesKind||a===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),x=e.byteOffset+n*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,r){if(e==t.VertexBuffer.ColorKind)return r?"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))}(a,i.hasVertexColorAlpha(e)),f,s,x,l,p)),u=this._accessors.length-1,i.setVertexAccessor(e,n,s,u)}o.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))}(a)]=u}},e.prototype._exportMaterialAsync=function(e,r,n,s){return o(this,void 0,void 0,function(){var i,o;return a(this,function(a){switch(a.label){case 0:return void 0!==(i=this._materialMap.get(e))?[3,8]:(o=r&&Object.keys(r).some(function(e){return e.startsWith("uv")}),(e=e instanceof t.MultiMaterial?e.subMaterials[n.materialIndex]:e)instanceof t.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,o)]:[3,2]);case 1:return i=a.sent(),[3,7];case 2:return e instanceof t.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,o)]:[3,4];case 3:return i=a.sent(),[3,7];case 4:return e instanceof t.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,o)]:[3,6];case 5:return i=a.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),a.label=8;case 8:return s.material=i,[2]}})})},e.prototype._exportMeshAsync=function(e,r){return o(this,void 0,void 0,function(){var n,s,i,o,c,l,h,f,p,d,x,g,_,m,T,y,v,b,R,M,w,A,E,C,I,V,S,F,B,N,O,U,P,K;return a(this,function(a){switch(a.label){case 0:if(void 0!==(n=r.getMesh(e)))return[2,n];if(s={primitives:[]},n=this._meshes.length,this._meshes.push(s),r.setMesh(e,n),i=e.isUnIndexed?null:e.getIndices(),o=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),c=r.getMorphTargetsFromMesh(e),l=e instanceof t.LinesMesh,h=e instanceof t.GreasedLineBaseMesh,f=e.subMeshes,!(o&&f&&f.length>0))return[3,7];p=0,d=f,a.label=1;case 1:return p<d.length?(x=d[p],g={attributes:{}},_=x.getMaterial()||this._babylonScene.defaultMaterial,h?(v={name:_.name},b=e,m=t.Color3.White(),T=null!==(O=null===(N=b.material)||void 0===N?void 0:N.alpha)&&void 0!==O?O:1,(!(y=null!==(P=null===(U=b.greasedLineMaterial)||void 0===U?void 0:U.color)&&void 0!==P?P:m).equalsWithEpsilon(m,t.Epsilon)||T<1)&&(v.pbrMetallicRoughness={baseColorFactor:u(u([],y.asArray(),!0),[T],!1)}),this._materials.push(v),g.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return l?(v={name:_.name},(!(b=e).color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||b.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:u(u([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(v),g.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(_,o,x,g)];case 4:a.sent(),a.label=5;case 5:for(R=l||h?t.Material.LineListDrawMode:null!==(K=e.overrideRenderingFillMode)&&void 0!==K?K:_.fillMode,M=_._getEffectiveOrientation(e),r.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(M=M===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(i,i?t.AreIndices32Bits(i,x.indexCount,x.indexStart,x.verticesStart):x.verticesCount>65535,i?x.indexStart:x.verticesStart,i?x.indexCount:x.verticesCount,-x.verticesStart,R,M,r,g),w=0,A=Object.values(o);w<A.length;w++)E=A[w],this._exportVertexBuffer(E,_,x.verticesStart,x.verticesCount,r,g);if(c)for(g.targets=[],C=0,I=c;C<I.length;C++)F=I[C],g.targets.push(F.attributes);s.primitives.push(g),this._extensionsPostExportMeshPrimitive(g),a.label=6;case 6:return p++,[3,1];case 7:if(c)for(s.weights=[],s.extras||(s.extras={}),s.extras.targetNames=[],V=0,S=c;V<S.length;V++)F=S[V],s.weights.push(F.influence),s.extras.targetNames.push(F.name);return[2,n]}})})},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),Q=function(){function e(){}return e.GLTFAsync=function(e,t,r){return o(this,void 0,void 0,function(){var n,s;return a(this,function(i){switch(i.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(n=new X(e,r)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=i.sent(),n.dispose(),[2,s]}})})},e.GLBAsync=function(e,t,r){return o(this,void 0,void 0,function(){var n,s;return a(this,function(i){switch(i.label){case 0:return r&&r.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(n=new X(e,r)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return s=i.sent(),n.dispose(),[2,s]}})})},e}(),Y={__proto__:null,GLTF2Export:Q},Z="EXT_mesh_gpu_instancing";function J(e,t){for(var r=new Float32Array(3*t),n=0;n<t;n++)r[3*n+0]=e[4*n+0],r[3*n+1]=e[4*n+1],r[3*n+2]=e[4*n+2];return r}var $=function(){function e(e){this.name=Z,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,r,n,s,i,u){return o(this,void 0,void 0,function(){var e=this;return a(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){var o,a;if(r&&n instanceof t.Mesh&&n.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var c=t.Vector3.Zero(),l=t.Quaternion.Identity(),h=t.Vector3.One(),f=n.thinInstanceGetWorldMatrices(),p=t.TmpVectors.Vector3[2],d=t.TmpVectors.Quaternion[1],x=t.TmpVectors.Vector3[3],g=!1,_=!1,m=!1,T=new Float32Array(3*n.thinInstanceCount),y=new Float32Array(4*n.thinInstanceCount),v=new Float32Array(3*n.thinInstanceCount),b=0,R=0,M=f;R<M.length;R++)M[R].decompose(x,d,p),i&&(F(p),N(d)),T.set(p.asArray(),3*b),y.set(d.normalize().asArray(),4*b),v.set(x.asArray(),3*b),g=g||!p.equalsWithEpsilon(c),_=_||!d.equalsWithEpsilon(l),m=m||!x.equalsWithEpsilon(h),b++;var w={attributes:{}};g&&(w.attributes.TRANSLATION=e._buildAccessor(T,"VEC3",n.thinInstanceCount,u)),_&&(w.attributes.ROTATION=e._buildAccessor(y,"VEC4",n.thinInstanceCount,u)),m&&(w.attributes.SCALE=e._buildAccessor(v,"VEC3",n.thinInstanceCount,u));var A=null===(a=null===(o=n._userThinInstanceBuffersStorage)||void 0===o?void 0:o.data)||void 0===a?void 0:a.instanceColor;if(A){var E=n.thinInstanceCount;n.hasVertexAlpha&&A.length===4*E?(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),A=J(A,E)):A.length===4*E&&(A=J(A,E)),A.length===3*E&&(w.attributes._COLOR_0=e._buildAccessor(A,"VEC3",E,u))}r.extensions=r.extensions||{},r.extensions[Z]=w}s(r)})];case 1:return[2,s.sent()]}})})},e.prototype._buildAccessor=function(e,t,r,n){var s=n.createBufferView(e),i=n.createAccessor(s,t,5126,r);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}(),ee=!1;function te(){ee||(ee=!0,X.RegisterExtension(Z,function(e){return new $(e)}))}te();var re="KHR_draco_mesh_compression";function ne(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=re,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,r,n){var s=this;if(this.enabled)if(4===e.mode||5===e.mode){var i=[],o=[],a=null;if(void 0!==e.indices){var u=n[e.indices],c=r.getBufferView(u);a=r.getData(c).slice(),i.push(c),o.push(u)}for(var l=[],h=0,f=Object.entries(e.attributes);h<f.length;h++){var p=f[h],d=p[0],x=(u=n[p[1]],c=r.getBufferView(u),C(u.type)),g=t.GetTypedArrayData(r.getData(c),x,u.componentType,u.byteOffset||0,c.byteStride||t.GetTypeByteLength(u.componentType)*x,u.count,!0);l.push({kind:d,dracoName:ne(d),size:C(u.type),data:g}),i.push(c),o.push(u)}var _={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},m=t.DracoEncoder.Default._encodeAsync(l,a,_).then(function(t){var n={bufferView:-1,attributes:t.attributeIds},a=r.createBufferView(t.data);r.setBufferView(n,a);for(var u=0,c=i;u<c.length;u++){var l=c[u];s._bufferViewsUsed.add(l)}for(var h=0,f=o;h<f.length;h++){var p=f[h];s._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[re]=n}).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(m),this._wasUsed=!0}else t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return o(this,void 0,void 0,function(){var t=this;return a(this,function(r){switch(r.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return r.sent(),this._bufferViewsUsed.forEach(function(r){e.getPropertiesWithBufferView(r).every(function(e){return t._accessorsUsed.has(e)})&&e.removeBufferView(r)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}})})},e}(),ie=!1;function oe(){ie||(ie=!0,X.RegisterExtension(re,function(e){return new se(e)}))}oe();var ae="KHR_lights_punctual",ue={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},ce={innerConeAngle:0,outerConeAngle:Math.PI/4},le=t.Vector3.Backward(),he=function(){function e(e){this.name=ae,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[ae]=this._lights},e.prototype.postExportNodeAsync=function(e,r,n,s,i){return o(this,void 0,void 0,function(){var o=this;return a(this,function(a){switch(a.label){case 0:return[4,new Promise(function(a){if(n instanceof t.Light){var u=n.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":n.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":n.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(u&&n instanceof t.ShadowLight))return t.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(ae)),void a(r);if(n.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(ae," specification!")),!n.position.equalsToFloats(0,0,0)){var c=t.TmpVectors.Vector3[0].copyFrom(n.position);i&&F(c),r.translation=c.asArray()}if("point"!==u){var l=n.direction.normalizeToRef(t.TmpVectors.Vector3[0]);i&&F(l);var h=t.Quaternion.FromUnitVectorsToRef(le,l,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(h)||(r.rotation=h.asArray())}var f={type:u,name:n.name,color:n.diffuse.asArray(),intensity:n.intensity,range:n.range};if(K(f,ue),"spot"===u){var p=n;f.spot={innerConeAngle:p.innerAngle/2,outerConeAngle:p.angle/2},K(f.spot,ce)}o._lights||(o._lights={lights:[]}),o._lights.lights.push(f);var d={light:o._lights.lights.length-1},x=n.parent;if(x&&P(n,x)){var g=s.get(x);if(g){var _=o._exporter._nodes[g];return U(r,_),_.extensions||(_.extensions={}),_.extensions[ae]=d,void a(null)}}r.extensions||(r.extensions={}),r.extensions[ae]=d,a(r)}else a(r)})];case 1:return[2,a.sent()]}})})},e}(),fe=!1;function pe(){fe||(fe=!0,X.RegisterExtension(ae,function(e){return new he(e)}))}pe();var de="EXT_lights_area",xe={name:"",color:[1,1,1],intensity:1,size:1},ge={aspect:1},_e=t.Vector3.Backward(),me=function(){function e(e){this.name=de,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[de]=this._lights},e.prototype.postExportNodeAsync=function(e,r,n,s,i){return o(this,void 0,void 0,function(){var o=this;return a(this,function(a){switch(a.label){case 0:return[4,new Promise(function(a){if(n instanceof t.Light){var u=n.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!u)return t.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(de)),void a(r);var c=n;if(c.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(de," specification!")),!c.position.equalsToFloats(0,0,0)){var l=t.TmpVectors.Vector3[0].copyFrom(c.position);i&&F(l),r.translation=l.asArray()}var h=t.Vector3.Forward();i&&F(h);var f=t.Quaternion.FromUnitVectorsToRef(_e,h,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(f)||(r.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,xe),p.rect&&K(p.rect,ge),o._lights||(o._lights={lights:[]}),o._lights.lights.push(p);var d={light:o._lights.lights.length-1},x=n.parent;if(x&&P(c,x)){var g=s.get(x);if(g){var _=o._exporter._nodes[g];return U(r,_),_.extensions||(_.extensions={}),_.extensions[de]=d,void a(null)}}r.extensions||(r.extensions={}),r.extensions[de]=d,a(r)}else a(r)})];case 1:return[2,a.sent()]}})})},e}(),Te=!1;function ye(){Te||(Te=!0,X.RegisterExtension(de,function(e){return new me(e)}))}ye();var ve="KHR_materials_anisotropy";function be(e){return o(this,void 0,void 0,function(){var r,n,s;return a(this,function(i){switch(i.label){case 0:return r=e.getScene(),n=e.specularRoughnessAnisotropyTexture,s=e.geometryTangentTexture,n||s?[4,t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),s?t.CreateTextureInput(s,1):t.CreateConstantInput(0),n?t.CreateTextureInput(n,0):t.CreateConstantInput(1)),r)]:[2,null];case 1:return[2,i.sent()]}})})}var Re=function(){function e(e){this.name=ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,r,n){return o(this,void 0,void 0,function(){var e,r,s;return a(this,function(i){switch(i.label){case 0:return e=[],n instanceof t.PBRBaseMaterial?n.anisotropy.isEnabled&&!n.anisotropy.legacy?(n.anisotropy.texture&&e.push(n.anisotropy.texture),[2,e]):[3,5]:[3,1];case 1:return n instanceof t.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0?(r=function(e){var t=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",s=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoTangent";return"".concat(n,"_").concat(s)}(n),this._anisoTexturesMap[r]?(e.push(this._anisoTexturesMap[r]),[3,4]):[3,2]):[3,5];case 2:return[4,be(n)];case 3:(s=i.sent())&&(e.push(s),this._anisoTexturesMap[r]=s),i.label=4;case 4:return[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){var i,o,a,u,c,l;if(n instanceof t.PBRBaseMaterial){if(!n.anisotropy.isEnabled||n.anisotropy.legacy)return void e(r);s._wasUsed=!0,r.extensions=r.extensions||{};var h=s._exporter._materialExporter.getTextureInfo(n.anisotropy.texture);null!==(T={anisotropyStrength:n.anisotropy.intensity,anisotropyRotation:n.anisotropy.angle,anisotropyTexture:null!=h?h:void 0}).anisotropyTexture&&s._exporter._materialNeedsUVsSet.add(n),r.extensions[ve]=T}else if(n instanceof t.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0){s._wasUsed=!0,r.extensions=r.extensions||{};var f=n.specularRoughnessTexture;n._useRoughnessFromMetallicTextureGreen&&(f=n.baseMetalnessTexture);var p=s._anisoTexturesMap[n.id];if(!f&&!p){var d=n.specularRoughness,x=n.specularRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var g=(o=n.specularRoughness,l=(1-(a=n.specularRoughnessAnisotropy))*(c=(u=o*o)*Math.sqrt(2/(1+(1-a)*(1-a)))),{newBaseRoughness:Math.sqrt(l),newAnisotropyStrength:Math.min(Math.sqrt((c-u)/Math.max(1-u,1e-4)),1)});d=g.newBaseRoughness,x=g.newAnisotropyStrength}r.pbrMetallicRoughness&&(r.pbrMetallicRoughness.roughnessFactor=d);var _={anisotropyStrength:x,anisotropyRotation:n.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return r.extensions[ve]=_,e(r)}var m=p?s._exporter._materialExporter.getTextureInfo(p):null,T={anisotropyStrength:n.specularRoughnessAnisotropy,anisotropyRotation:n.geometryTangentAngle,anisotropyTexture:m||void 0,extensions:{}};n._useGltfStyleAnisotropy||(r.extensions.KHR_materials_openpbr={},(i=s._exporter._glTF).extensionsUsed||(i.extensionsUsed=[]),-1===s._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&s._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),s._exporter._materialNeedsUVsSet.add(n),r.extensions[ve]=T}e(r)})},e}(),Me=!1;function we(){Me||(Me=!0,X.RegisterExtension(ve,function(e){return new Re(e)}))}we();var Ae="KHR_materials_clearcoat";function Ee(e){return o(this,void 0,void 0,function(){var r,n,s;return a(this,function(i){switch(i.label){case 0:return r=e.getScene(),n=e.coatWeightTexture,s=e.coatRoughnessTexture,n||s?[4,t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),s?t.CreateTextureInput(s,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),r)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function Ce(e,r){var n=new t.Texture(r.name,r.getScene());return n._texture=e,n.coordinatesIndex=r.coordinatesIndex,r instanceof t.Texture&&(n.uOffset=r.uOffset,n.vOffset=r.vOffset,n.uScale=r.uScale,n.vScale=r.vScale,n.wAng=r.wAng),n.wrapU=r.wrapU,n.wrapV=r.wrapV,n}var Ie=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 r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,s=Object.keys(this._cachedInternalTexturesMap);n<s.length;n++)r=s[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,r,n){return o(this,void 0,void 0,function(){var e,r,s,i;return a(this,function(o){switch(o.label){case 0:return e=[],n instanceof t.PBRBaseMaterial?n.clearCoat.isEnabled?(n.clearCoat.texture&&e.push(n.clearCoat.texture),!n.clearCoat.useRoughnessFromMainTexture&&n.clearCoat.textureRoughness&&e.push(n.clearCoat.textureRoughness),n.clearCoat.bumpTexture&&e.push(n.clearCoat.bumpTexture),[2,e]):[3,5]:[3,1];case 1:return n instanceof t.OpenPBRMaterial&&n.coatWeight>0?(r=!1,n.coatWeightTexture?n.coatRoughnessTexture?n._useCoatRoughnessFromGreenChannel&&n.coatWeightTexture.getInternalTexture()===n.coatRoughnessTexture.getInternalTexture()?(e.push(n.coatWeightTexture),e.push(n.coatRoughnessTexture)):r=!0:e.push(n.coatWeightTexture):n.coatRoughnessTexture&&(n._useCoatRoughnessFromGreenChannel?e.push(n.coatRoughnessTexture):r=!0),r?(s=function(e){var t=e.coatWeightTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",n=e.coatRoughnessTexture,s=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoRoughness";return"".concat(r,"_").concat(s)}(n),this._cachedInternalTexturesMap[s]?[3,3]:[4,Ee(n)]):[3,4]):[3,5];case 2:(i=o.sent())&&(this._cachedInternalTexturesMap[s]=i),o.label=3;case 3:this._cachedInternalTexturesMap[s]&&(n.coatWeightTexture&&(this._mergedTexturesMap[n.coatWeightTexture.uniqueId]=Ce(this._cachedInternalTexturesMap[s],n.coatWeightTexture),e.push(this._mergedTexturesMap[n.coatWeightTexture.uniqueId])),n.coatRoughnessTexture&&(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]=Ce(this._cachedInternalTexturesMap[s],n.coatRoughnessTexture),e.push(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]))),o.label=4;case 4:return n.geometryCoatNormalTexture&&e.push(n.geometryCoatNormalTexture),[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){if(n instanceof t.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(r);s._wasUsed=!0,r.extensions=r.extensions||{};var i,o=s._exporter._materialExporter.getTextureInfo(n.clearCoat.texture);i=n.clearCoat.useRoughnessFromMainTexture?s._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):s._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness),n.clearCoat.isTintEnabled&&t.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),n.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(n.name));var a=s._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture);null===(l={clearcoatFactor:n.clearCoat.intensity,clearcoatTexture:null!=o?o:void 0,clearcoatRoughnessFactor:n.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=a?a:void 0}).clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||s._exporter._materialNeedsUVsSet.add(n),r.extensions[Ae]=l}else if(n instanceof t.OpenPBRMaterial){if(0==n.coatWeight)return void e(r);s._wasUsed=!0,r.extensions=r.extensions||{};var u=void 0,c=void 0;n.coatWeightTexture&&(u=s._mergedTexturesMap[n.coatWeightTexture.uniqueId],c=s._exporter._materialExporter.getTextureInfo(u));var l,h=void 0,f=void 0;n.coatRoughnessTexture&&(h=s._mergedTexturesMap[n.coatRoughnessTexture.uniqueId],f=s._exporter._materialExporter.getTextureInfo(h)),n.coatColorTexture&&t.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),a=s._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),null===(l={clearcoatFactor:n.coatWeight,clearcoatTexture:null!=c?c:void 0,clearcoatRoughnessFactor:n.coatRoughness,clearcoatRoughnessTexture:null!=f?f:void 0,clearcoatNormalTexture:null!=a?a:void 0}).clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||s._exporter._materialNeedsUVsSet.add(n),r.extensions[Ae]=l}e(r)})},e}(),Ve=!1;function Se(){Ve||(Ve=!0,X.RegisterExtension(Ae,function(e){return new Ie(e)}))}Se();var Fe="KHR_materials_coat";function Be(e){var t=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",s=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoTangent";return"".concat(n,"_").concat(s)}function Ne(e){return o(this,void 0,void 0,function(){var r,n,s;return a(this,function(i){switch(i.label){case 0:return r=e.getScene(),n=e.coatRoughnessAnisotropyTexture,s=e.geometryCoatTangentTexture,n||s?[4,t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(s?t.CreateTextureInput(s,0):t.CreateConstantInput(1),s?t.CreateTextureInput(s,1):t.CreateConstantInput(0),n?t.CreateTextureInput(n,0):t.CreateConstantInput(1)),r)]:[2,null];case 1:return[2,i.sent()]}})})}function Oe(e){return o(this,void 0,void 0,function(){var r,n,s;return a(this,function(i){switch(i.label){case 0:return r=e.getScene(),n=e.coatWeightTexture,s=e.coatRoughnessTexture,n||s?[4,t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),s?t.CreateTextureInput(s,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),r)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function Ue(e,r){var n=new t.Texture(r.name,r.getScene());return n._texture=e,n.coordinatesIndex=r.coordinatesIndex,r instanceof t.Texture&&(n.uOffset=r.uOffset,n.vOffset=r.vOffset,n.uScale=r.uScale,n.vScale=r.vScale,n.wAng=r.wAng),n.wrapU=r.wrapU,n.wrapV=r.wrapV,n}var Pe=function(){function e(e){this.name=Fe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,s=Object.keys(this._cachedInternalTexturesMap);n<s.length;n++)r=s[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,r,n){return o(this,void 0,void 0,function(){var e,r,s,i,o;return a(this,function(a){switch(a.label){case 0:return e=[],n instanceof t.PBRBaseMaterial?n.clearCoat.isEnabled?(n.clearCoat.texture&&e.push(n.clearCoat.texture),!n.clearCoat.useRoughnessFromMainTexture&&n.clearCoat.textureRoughness&&e.push(n.clearCoat.textureRoughness),n.clearCoat.bumpTexture&&e.push(n.clearCoat.bumpTexture),n.clearCoat.tintTexture&&e.push(n.clearCoat.tintTexture),[2,e]):[3,9]:[3,1];case 1:return n instanceof t.OpenPBRMaterial&&n.coatWeight>0?(r=!1,n.coatWeightTexture?n.coatRoughnessTexture?n._useCoatRoughnessFromGreenChannel&&n.coatWeightTexture.getInternalTexture()===n.coatRoughnessTexture.getInternalTexture()?(e.push(n.coatWeightTexture),e.push(n.coatRoughnessTexture)):r=!0:e.push(n.coatWeightTexture):n.coatRoughnessTexture&&(n._useCoatRoughnessFromGreenChannel?e.push(n.coatRoughnessTexture):r=!0),r?(i=function(e){var t=e.coatWeightTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",n=e.coatRoughnessTexture,s=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoRoughness";return"".concat(r,"_").concat(s)}(n),this._cachedInternalTexturesMap[i]?[3,3]:[4,Oe(n)]):[3,4]):[3,9];case 2:(s=a.sent())&&(this._cachedInternalTexturesMap[i]=s),a.label=3;case 3:this._cachedInternalTexturesMap[i]&&(n.coatWeightTexture&&(this._mergedTexturesMap[n.coatWeightTexture.uniqueId]=Ue(this._cachedInternalTexturesMap[i],n.coatWeightTexture),e.push(this._mergedTexturesMap[n.coatWeightTexture.uniqueId])),n.coatRoughnessTexture&&(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]=Ue(this._cachedInternalTexturesMap[i],n.coatRoughnessTexture),e.push(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]))),a.label=4;case 4:return n.geometryCoatNormalTexture&&e.push(n.geometryCoatNormalTexture),n.coatColorTexture&&e.push(n.coatColorTexture),n.coatRoughnessAnisotropy>0?(i=Be(n),this._mergedTexturesMap[i]?(e.push(this._mergedTexturesMap[i]),[3,7]):[3,5]):[3,8];case 5:return[4,Ne(n)];case 6:(o=a.sent())&&(e.push(o),this._mergedTexturesMap[i]=o),a.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){var i,o,a,u,c,l;if(n instanceof t.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(r);s._wasUsed=!0,r.extensions=r.extensions||{};var h,f=s._exporter._materialExporter.getTextureInfo(n.clearCoat.texture);h=n.clearCoat.useRoughnessFromMainTexture?s._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):s._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness);var p=void 0;n.clearCoat.isTintEnabled&&(p=s._exporter._materialExporter.getTextureInfo(n.clearCoat.tintTexture));var d=s._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture),x=n.clearCoat.indexOfRefraction;null===(T={coatFactor:n.clearCoat.intensity,coatTexture:null!=f?f:void 0,coatRoughnessFactor:n.clearCoat.roughness,coatRoughnessTexture:null!=h?h:void 0,coatNormalTexture:null!=d?d:void 0,coatColorFactor:n.clearCoat.tintColor.asArray(),coatColorTexture:null!=p?p:void 0,coatIor:1.5!==x?x:void 0}).coatTexture&&null===T.coatRoughnessTexture&&null===T.coatRoughnessTexture&&null===T.coatColorTexture||s._exporter._materialNeedsUVsSet.add(n),r.extensions[Fe]=T}else if(n instanceof t.OpenPBRMaterial){if(0==n.coatWeight)return void e(r);s._wasUsed=!0,r.extensions=r.extensions||{};var g=void 0;f=void 0,n.coatWeightTexture&&(g=s._mergedTexturesMap[n.coatWeightTexture.uniqueId]?s._mergedTexturesMap[n.coatWeightTexture.uniqueId]:n.coatWeightTexture,f=s._exporter._materialExporter.getTextureInfo(g));var _=void 0,m=void 0;n.coatRoughnessTexture&&(_=s._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]?s._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]:n.coatRoughnessTexture,m=s._exporter._materialExporter.getTextureInfo(_)),d=s._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),p=s._exporter._materialExporter.getTextureInfo(n.coatColorTexture),x=n.coatIor;var T,y=n.coatDarkening,v=n.coatRoughnessTexture,b=Be(n),R=s._mergedTexturesMap[b],M=0,w=0,A=void 0;if(n.coatRoughnessAnisotropy>0){if(v||R){var E=R?s._exporter._materialExporter.getTextureInfo(R):null;M=n.coatRoughnessAnisotropy,w=n.geometryCoatTangentAngle,A=E||void 0}else{var C=n.coatRoughness,I=n.coatRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var V=(o=n.coatRoughness,l=(1-(a=n.coatRoughnessAnisotropy))*(c=(u=o*o)*Math.sqrt(2/(1+(1-a)*(1-a)))),{newBaseRoughness:Math.sqrt(l),newAnisotropyStrength:Math.min(Math.sqrt((c-u)/Math.max(1-u,1e-4)),1)});C=V.newBaseRoughness,I=V.newAnisotropyStrength}r.pbrMetallicRoughness&&(r.pbrMetallicRoughness.roughnessFactor=C),M=I,w=n.geometryCoatTangentAngle+.5*Math.PI,A=void 0}n._useGltfStyleAnisotropy||(r.extensions.KHR_materials_openpbr={},(i=s._exporter._glTF).extensionsUsed||(i.extensionsUsed=[]),-1===s._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&s._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(T={coatFactor:n.coatWeight,coatTexture:null!=f?f:void 0,coatRoughnessFactor:n.coatRoughness,coatRoughnessTexture:null!=m?m:void 0,coatNormalTexture:null!=d?d:void 0,coatColorFactor:n.coatColor.asArray(),coatColorTexture:null!=p?p:void 0,coatIor:1.5!==x?x:void 0,coatDarkeningFactor:1!==y?y:void 0,coatAnisotropyRotation:w,coatAnisotropyStrength:M,coatAnisotropyTexture:A}).coatTexture&&null===T.coatRoughnessTexture&&null===T.coatRoughnessTexture&&null===T.coatAnisotropyTexture&&null===T.coatColorTexture||s._exporter._materialNeedsUVsSet.add(n),r.extensions[Fe]=T}e(r)})},e}(),Ke=!1;function We(){Ke||(Ke=!0,X.RegisterExtension(Fe,function(e){return new Pe(e)}))}We();var He="KHR_materials_diffuse_transmission";function Le(e,r){var n=r.subSurface,s=null;return n.translucencyIntensityTexture?s=n.translucencyIntensityTexture:n.thicknessTexture&&n.useMaskFromThicknessTexture&&(s=n.thicknessTexture),s&&!n.useGltfStyleTextures?(t.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(r.name),1),null):s}var ze=function(){function e(e){this.name=He,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,r,n){return o(this,void 0,void 0,function(){var r,s;return a(this,function(i){return r=[],n instanceof t.PBRMaterial&&this._isExtensionEnabled(n)?((s=Le(e,n))&&r.push(s),n.subSurface.translucencyColorTexture&&r.push(n.subSurface.translucencyColorTexture),[2,r]):[2,r]})})},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,r,n){var s=this;return new Promise(function(i){var o,a;if(n instanceof t.PBRMaterial&&s._isExtensionEnabled(n)){s._wasUsed=!0;var u=n.subSurface,c=Le(e,n),l=0==u.translucencyIntensity?void 0:u.translucencyIntensity,h=null!==(o=s._exporter._materialExporter.getTextureInfo(c))&&void 0!==o?o:void 0,f=!u.translucencyColor||u.translucencyColor.equalsFloats(1,1,1)?void 0:u.translucencyColor.asArray(),p=null!==(a=s._exporter._materialExporter.getTextureInfo(u.translucencyColorTexture))&&void 0!==a?a:void 0,d={diffuseTransmissionFactor:l,diffuseTransmissionTexture:h,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:p};(h||p)&&s._exporter._materialNeedsUVsSet.add(n),r.extensions=r.extensions||{},r.extensions[He]=d}i(r)})},e}(),ke=!1;function Ge(){ke||(ke=!0,X.RegisterExtension(He,function(e){return new ze(e)}))}Ge();var De="KHR_materials_dispersion",qe=function(){function e(){this.name=De,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){if(n instanceof t.PBRMaterial&&s._isExtensionEnabled(n)){s._wasUsed=!0;var i={dispersion:n.subSurface.dispersion};r.extensions=r.extensions||{},r.extensions[De]=i}e(r)})},e}(),je=!1;function Xe(){je||(je=!0,X.RegisterExtension(De,function(){return new qe}))}Xe();var Qe="KHR_materials_emissive_strength",Ye=function(){function e(){this.name=Qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,r,n){return o(this,void 0,void 0,function(){var e=this;return a(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){if(!(n instanceof t.PBRMaterial))return s(r);var i=n.emissiveColor.scale(n.emissiveIntensity),o=Math.max.apply(Math,i.asArray());if(o>1){r.emissiveFactor=i.scale(1/o).asArray(),e._wasUsed=!0;var a={emissiveStrength:o};r.extensions||(r.extensions={}),r.extensions[Qe]=a}else r.emissiveFactor=i.asArray();return s(r)})];case 1:return[2,s.sent()]}})})},e}(),Ze=!1;function Je(){Ze||(Ze=!0,X.RegisterExtension(Qe,function(){return new Ye}))}Je();var $e="KHR_materials_ior",et=function(){function e(){this.name=$e,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,r,n){var s=this;return new Promise(function(e){if(n instanceof t.PBRMaterial&&s._isExtensionEnabled(n)){s._wasUsed=!0;var i={ior:n.indexOfRefraction};r.extensions=r.extensions||{},r.extensions[$e]=i}else n instanceof t.OpenPBRMaterial&&s._isExtensionEnabled(n)&&(s._wasUsed=!0,i={ior:n.specularIor},r.extensions=r.extensions||{},r.extensions[$e]=i);e(r)})},e}(),tt=!1;function rt(){tt||(tt=!0,X.RegisterExtension($e,function(){return new et}))}rt();var nt="KHR_materials_iridescence",st=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,r,n){return o(this,void 0,void 0,function(){var e;return a(this,function(r){if(e=[],n instanceof t.PBRBaseMaterial){if(n.iridescence.isEnabled)return n.iridescence.texture&&e.push(n.iridescence.texture),n.iridescence.thicknessTexture&&n.iridescence.thicknessTexture!==n.iridescence.texture&&e.push(n.iridescence.thicknessTexture),[2,e]}else if(n instanceof t.OpenPBRMaterial&&n.thinFilmWeight>0)return n.thinFilmWeightTexture&&e.push(n.thinFilmWeightTexture),n.thinFilmThicknessTexture&&n.thinFilmThicknessTexture!==n.thinFilmWeightTexture&&e.push(n.thinFilmThicknessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){if(n instanceof t.PBRBaseMaterial){if(!n.iridescence.isEnabled)return void e(r);s._wasUsed=!0,r.extensions=r.extensions||{};var i=s._exporter._materialExporter.getTextureInfo(n.iridescence.texture),o=s._exporter._materialExporter.getTextureInfo(n.iridescence.thicknessTexture);null===(a={iridescenceFactor:n.iridescence.intensity,iridescenceIor:n.iridescence.indexOfRefraction,iridescenceThicknessMinimum:n.iridescence.minimumThickness,iridescenceThicknessMaximum:n.iridescence.maximumThickness,iridescenceTexture:null!=i?i:void 0,iridescenceThicknessTexture:null!=o?o:void 0}).iridescenceTexture&&null===a.iridescenceThicknessTexture||s._exporter._materialNeedsUVsSet.add(n),r.extensions[nt]=a}else if(n instanceof t.OpenPBRMaterial){if(n.thinFilmWeight<=0)return void e(r);s._wasUsed=!0,r.extensions=r.extensions||{};var a,u=s._exporter._materialExporter.getTextureInfo(n.thinFilmWeightTexture),c=s._exporter._materialExporter.getTextureInfo(n.thinFilmThicknessTexture);null===(a={iridescenceFactor:n.thinFilmWeight,iridescenceIor:n.thinFilmIor,iridescenceThicknessMinimum:1e3*n.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*n.thinFilmThickness,iridescenceTexture:null!=u?u:void 0,iridescenceThicknessTexture:null!=c?c:void 0}).iridescenceTexture&&null===a.iridescenceThicknessTexture||s._exporter._materialNeedsUVsSet.add(n),r.extensions[nt]=a}e(r)})},e}(),it=!1;function ot(){it||(it=!0,X.RegisterExtension(nt,function(e){return new st(e)}))}ot();var at="KHR_materials_sheen",ut=function(){function e(e){this.name=at,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,r,n){return o(this,void 0,void 0,function(){return a(this,function(e){return n instanceof t.PBRMaterial&&n.sheen.isEnabled&&n.sheen.texture?[2,[n.sheen.texture]]:[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,r,n){return o(this,void 0,void 0,function(){var e=this;return a(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){var i,o,a,u;if(n instanceof t.PBRMaterial){if(!n.sheen.isEnabled)return void s(r);e._wasUsed=!0,null==r.extensions&&(r.extensions={});var c={sheenColorFactor:n.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=n.sheen.roughness)&&void 0!==i?i:0};null===c.sheenColorTexture&&null===c.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),n.sheen.texture&&(c.sheenColorTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==o?o:void 0),n.sheen.textureRoughness&&!n.sheen.useRoughnessFromMainTexture?c.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(n.sheen.textureRoughness))&&void 0!==a?a:void 0:n.sheen.texture&&n.sheen.useRoughnessFromMainTexture&&(c.sheenRoughnessTexture=null!==(u=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==u?u:void 0),r.extensions[at]=c}s(r)})];case 1:return[2,s.sent()]}})})},e}(),ct=!1;function lt(){ct||(ct=!0,X.RegisterExtension(at,function(e){return new ut(e)}))}lt();var ht="KHR_materials_fuzz";function ft(e){return o(this,void 0,void 0,function(){var r,n,s;return a(this,function(i){switch(i.label){case 0:return r=e.getScene(),n=e.fuzzColorTexture,s=e.fuzzRoughnessTexture,n||s?[4,t.MergeTexturesAsync("FuzzTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(1),n?t.CreateTextureInput(n,2):t.CreateConstantInput(1),s?t.CreateTextureInput(s,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),r)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function pt(e,r){var n=new t.Texture(r.name,r.getScene());return n._texture=e,n.coordinatesIndex=r.coordinatesIndex,r instanceof t.Texture&&(n.uOffset=r.uOffset,n.vOffset=r.vOffset,n.uScale=r.uScale,n.vScale=r.vScale,n.wAng=r.wAng),n.wrapU=r.wrapU,n.wrapV=r.wrapV,n}var dt=function(){function e(e){this.name=ht,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var r=t[e];this._mergedTexturesMap[r].dispose()}this._mergedTexturesMap={};for(var n=0,s=Object.keys(this._cachedInternalTexturesMap);n<s.length;n++)r=s[n],this._cachedInternalTexturesMap[r].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,r,n){return o(this,void 0,void 0,function(){var e,r,s,i;return a(this,function(o){switch(o.label){case 0:return n instanceof t.OpenPBRMaterial?(e=[],n.fuzzWeight>0?(n.fuzzWeightTexture&&e.push(n.fuzzWeightTexture),r=!1,n.fuzzRoughnessTexture&&(n._useFuzzRoughnessFromTextureAlpha?e.push(n.fuzzRoughnessTexture):r=!0),n.fuzzColorTexture&&!r&&e.push(n.fuzzColorTexture),r?(s=function(e){var t=e.fuzzColorTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",n=e.fuzzRoughnessTexture,s=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(r,"_FuzzRoughness_").concat(s)}(n),this._cachedInternalTexturesMap[s]?[3,2]:[4,ft(n)]):[3,3]):[3,3]):[3,4];case 1:(i=o.sent())&&(this._cachedInternalTexturesMap[s]=i),o.label=2;case 2:this._cachedInternalTexturesMap[s]&&(n.fuzzColorTexture&&(this._mergedTexturesMap[n.fuzzColorTexture.uniqueId]=pt(this._cachedInternalTexturesMap[s],n.fuzzColorTexture),e.push(this._mergedTexturesMap[n.fuzzColorTexture.uniqueId])),n.fuzzRoughnessTexture&&(this._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]=pt(this._cachedInternalTexturesMap[s],n.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]))),o.label=3;case 3:return[2,e];case 4:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,r,n){return o(this,void 0,void 0,function(){var e=this;return a(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){var i,o,a;if(n instanceof t.OpenPBRMaterial){if(0==n.fuzzWeight)return void s(r);e._wasUsed=!0,null==r.extensions&&(r.extensions={});var u={fuzzFactor:n.fuzzWeight,fuzzColorFactor:n.fuzzColor.asArray(),fuzzRoughnessFactor:n.fuzzRoughness};n.fuzzWeightTexture&&(u.fuzzTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(n.fuzzWeightTexture))&&void 0!==i?i:void 0);var c=void 0;n.fuzzColorTexture&&(c=e._mergedTexturesMap[n.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[n.fuzzColorTexture.uniqueId]:n.fuzzColorTexture,u.fuzzColorTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==o?o:void 0);var l=void 0;n.fuzzRoughnessTexture&&(l=e._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]:n.fuzzRoughnessTexture,u.fuzzRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(l))&&void 0!==a?a:void 0),null===u.fuzzColorTexture&&null===u.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),r.extensions[ht]=u}s(r)})];case 1:return[2,s.sent()]}})})},e}(),xt=!1;function gt(){xt||(xt=!0,X.RegisterExtension(ht,function(e){return new dt(e)}))}gt();var _t="KHR_materials_specular",mt=function(){function e(e){this.name=_t,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,r,n){return o(this,void 0,void 0,function(){var e;return a(this,function(r){return e=[],n instanceof t.PBRMaterial&&this._isExtensionEnabled(n)?(n.metallicReflectanceTexture&&e.push(n.metallicReflectanceTexture),n.reflectanceTexture&&e.push(n.reflectanceTexture),[2,e]):[2,e]})})},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){var i,o,a,u,c;if(n instanceof t.PBRMaterial&&s._isExtensionEnabled(n)){s._wasUsed=!0,r.extensions=r.extensions||{};var l=null!==(i=s._exporter._materialExporter.getTextureInfo(n.metallicReflectanceTexture))&&void 0!==i?i:void 0,h=null!==(o=s._exporter._materialExporter.getTextureInfo(n.reflectanceTexture))&&void 0!==o?o:void 0,f={specularFactor:1==n.metallicF0Factor?void 0:n.metallicF0Factor,specularTexture:l,specularColorFactor:n.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:n.metallicReflectanceColor.asArray(),specularColorTexture:h};s._hasTexturesExtension(n)&&s._exporter._materialNeedsUVsSet.add(n),r.extensions[_t]=f}else if(n instanceof t.OpenPBRMaterial){r.extensions=r.extensions||{};var p=null!==(a=s._exporter._materialExporter.getTextureInfo(n.specularWeightTexture))&&void 0!==a?a:void 0,d=null!==(u=s._exporter._materialExporter.getTextureInfo(n.specularColorTexture))&&void 0!==u?u:void 0,x=1==n.specularWeight?void 0:n.specularWeight,g=n.specularColor.equalsFloats(1,1,1)?void 0:n.specularColor.asArray();if(!d&&!p&&void 0===x&&void 0===g)return e(r);s._wasUsed=!0,(f={specularFactor:x,specularTexture:p,specularColorFactor:g,specularColorTexture:d,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(c=s._exporter._glTF).extensionsUsed||(c.extensionsUsed=[]),-1===s._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&s._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(p||d)&&s._exporter._materialNeedsUVsSet.add(n),r.extensions[_t]=f}e(r)})},e}(),Tt=!1;function yt(){Tt||(Tt=!0,X.RegisterExtension(_t,function(e){return new mt(e)}))}yt();var vt="KHR_materials_transmission",bt=function(){function e(e){this.name=vt,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,r,n){return o(this,void 0,void 0,function(){var e;return a(this,function(r){if(e=[],n instanceof t.PBRMaterial){if(this._isExtensionEnabled(n))return n.subSurface.refractionIntensityTexture&&n.subSurface.useGltfStyleTextures&&e.push(n.subSurface.refractionIntensityTexture),[2,e]}else n instanceof t.OpenPBRMaterial&&(n.transmissionWeight>0&&n.transmissionWeightTexture&&(e.push(n.transmissionWeightTexture),n.transmissionColorTexture&&e.push(n.transmissionColorTexture)),n.subsurfaceWeight>0&&n.subsurfaceWeightTexture&&e.push(n.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 r=e.subSurface;return r.isRefractionEnabled&&null!=r.refractionIntensity&&0!=r.refractionIntensity||null!=r.refractionIntensityTexture&&r.useGltfStyleTextures}return!1},e.prototype.postExportMaterialAsync=function(e,r,n){return o(this,void 0,void 0,function(){var s,i,o,u,c,l,h;return a(this,function(a){return this._isExtensionEnabled(n)?(n instanceof t.PBRMaterial?(this._wasUsed=!0,s=n.subSurface,o=0===s.refractionIntensity?void 0:s.refractionIntensity,u={transmissionFactor:o},s.refractionIntensityTexture&&(s.useGltfStyleTextures?(this._exporter._materialNeedsUVsSet.add(n),(c=this._exporter._materialExporter.getTextureInfo(s.refractionIntensityTexture))&&(u.transmissionTexture=c)):t.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported"))),r.extensions||(r.extensions={}),r.extensions[vt]=u):n instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,i=(1-n.transmissionWeight)*n.subsurfaceWeight,o=i+n.transmissionWeight,u={transmissionFactor:o},n.transmissionWeightTexture?(this._exporter._materialNeedsUVsSet.add(n),(c=this._exporter._materialExporter.getTextureInfo(n.transmissionWeightTexture))&&(u.transmissionTexture=c)):n.subsurfaceWeightTexture&&(this._exporter._materialNeedsUVsSet.add(n),(l=this._exporter._materialExporter.getTextureInfo(n.subsurfaceWeightTexture))&&(u.transmissionTexture=l)),0!=n.transmissionDepth||n.transmissionColor.equals(t.Color3.White())&&!n.transmissionColorTexture||r.pbrMetallicRoughness&&(r.pbrMetallicRoughness.baseColorFactor||(r.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),r.pbrMetallicRoughness.baseColorFactor[0]*=n.transmissionColor.r,r.pbrMetallicRoughness.baseColorFactor[1]*=n.transmissionColor.g,r.pbrMetallicRoughness.baseColorFactor[2]*=n.transmissionColor.b,n.transmissionColorTexture&&!r.pbrMetallicRoughness.baseColorTexture&&(h=this._exporter._materialExporter.getTextureInfo(n.transmissionColorTexture))&&(r.pbrMetallicRoughness.baseColorTexture=h,this._exporter._materialNeedsUVsSet.add(n))),r.extensions||(r.extensions={}),r.extensions[vt]=u),[2,r]):[2,r]})})},e}(),Rt=!1;function Mt(){Rt||(Rt=!0,X.RegisterExtension(vt,function(e){return new bt(e)}))}Mt();var wt="KHR_materials_unlit",At=function(){function e(){this.name=wt,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,r,n){var s=this;return new Promise(function(e){var i=!1;n instanceof t.PBRMaterial?i=n.unlit:n instanceof t.StandardMaterial&&(i=n.disableLighting),i&&(s._wasUsed=!0,null==r.extensions&&(r.extensions={}),r.extensions[wt]={}),e(r)})},e}(),Et=!1;function Ct(){Et||(Et=!0,X.RegisterExtension(wt,function(){return new At}))}Ct();var It="KHR_materials_volume",Vt=function(){function e(e){this.name=It,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,r,n){return o(this,void 0,void 0,function(){var e;return a(this,function(r){if(e=[],n instanceof t.PBRMaterial){if(this._isExtensionEnabled(n))return n.subSurface.thicknessTexture&&e.push(n.subSurface.thicknessTexture),[2,e]}else n instanceof t.OpenPBRMaterial&&(n.transmissionWeight>0||n.subsurfaceWeight>0)&&n.geometryThicknessTexture&&e.push(n.geometryThicknessTexture);return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var r=e.subSurface;return!(!r.isRefractionEnabled&&!r.isTranslucencyEnabled)&&(null!=r.maximumThickness&&0!=r.maximumThickness||null!=r.tintColorAtDistance&&r.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=r.tintColor&&r.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){var i,o;if(n instanceof t.PBRMaterial&&s._isExtensionEnabled(n)){s._wasUsed=!0;var a=n.subSurface,u={thicknessFactor:f=0==a.maximumThickness?void 0:a.maximumThickness,thicknessTexture:h=null!==(i=s._exporter._materialExporter.getTextureInfo(a.thicknessTexture))&&void 0!==i?i:void 0,attenuationDistance:a.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:a.tintColorAtDistance,attenuationColor:S=a.tintColor.equalsFloats(1,1,1)?void 0:a.tintColor.asArray()};s._hasTexturesExtension(n)&&s._exporter._materialNeedsUVsSet.add(n),r.extensions=r.extensions||{},r.extensions[It]=u}else if(n instanceof t.OpenPBRMaterial){var c=n.transmissionWeight>0&&!n.geometryThinWalled,l=n.subsurfaceWeight>0&&!n.geometryThinWalled;if(c||l){s._wasUsed=!0;var h,f=n.geometryThickness;(h=null!==(o=s._exporter._materialExporter.getTextureInfo(n.geometryThicknessTexture))&&void 0!==o?o:void 0)&&s._exporter._materialNeedsUVsSet.add(n);var p=void 0,d=t.Color3.White().asArray();if(c&&n.transmissionDepth>0){var x=1/n.transmissionDepth,g=new t.Vector3(-Math.log(n.transmissionColor.r)*x,-Math.log(n.transmissionColor.g)*x,-Math.log(n.transmissionColor.b)*x),_=new t.Vector3(n.transmissionScatter.r*x,n.transmissionScatter.g*x,n.transmissionScatter.b*x),m=g.subtract(_),T=Math.min(m.x,m.y,m.z);T<0&&(m.x=m.x-T,m.y=m.y-T,m.z=m.z-T),g=m.add(_),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 y=1,v=t.Color3.White().asArray();if(l){var b=n.subsurfaceRadius,R=n.subsurfaceRadiusScale,M=new t.Vector3(R.r,R.g,R.b).multiplyByFloats(b,b,b),w=new t.Vector3(1/Math.max(M.x,1e-6),1/Math.max(M.y,1e-6),1/Math.max(M.z,1e-6));y=1/Math.max(w.x,w.y,w.z),v[0]=Math.exp(-w.x*y),v[1]=Math.exp(-w.y*y),v[2]=Math.exp(-w.z*y)}var A=(1-n.transmissionWeight)*n.subsurfaceWeight,E=A+n.transmissionWeight,C=1/Math.max(E,1e-6),I=n.transmissionWeight*C,V=A*C,S=d.map(function(e,t){return e*I+v[t]*V});u={thicknessFactor:f,thicknessTexture:h,attenuationDistance:p*I+y*V,attenuationColor:S},r.extensions=r.extensions||{},r.extensions[It]=u}}e(r)})},e}(),St=!1;function Ft(){St||(St=!0,X.RegisterExtension(It,function(e){return new Vt(e)}))}Ft();var Bt="KHR_materials_volume_scatter",Nt=function(){function e(e){this.name=Bt,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,r,n){return o(this,void 0,void 0,function(){var e;return a(this,function(r){return e=[],n instanceof t.OpenPBRMaterial&&(n.transmissionWeight>0&&n.transmissionScatterTexture&&e.push(n.transmissionScatterTexture),n.subsurfaceWeight>0&&n.subsurfaceColorTexture&&e.push(n.subsurfaceColorTexture)),[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var r=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),n=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!r&&!n)},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){if(n instanceof t.OpenPBRMaterial&&s._isExtensionEnabled(n)){s._wasUsed=!0;var i=t.Vector3.Zero(),o=0;if(n.transmissionWeight>0)_=new t.Vector3(n.transmissionScatter.r,n.transmissionScatter.g,n.transmissionScatter.b),m=new t.Vector3(Math.sqrt(1-_.x),Math.sqrt(1-_.y),Math.sqrt(1-_.z)),y=(T=new t.Vector3(1,1,1)).subtract(m),v=T.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(m)),b=T.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(m)),i=y.multiplyInPlace(v).divideInPlace(b),o=n.transmissionScatterAnisotropy;var a=t.Vector3.Zero(),u=0;n.subsurfaceWeight>0&&(a.set(n.subsurfaceColor.r,n.subsurfaceColor.g,n.subsurfaceColor.b),u=n.subsurfaceScatterAnisotropy);var c=(1-n.transmissionWeight)*n.subsurfaceWeight,l=c+n.transmissionWeight,h=1/Math.max(l,1e-6),f=n.transmissionWeight*h,p=c*h,d={multiscatterColorFactor:i.multiplyByFloats(f,f,f).addInPlace(a.multiplyByFloats(p,p,p)).asArray(),scatterAnisotropy:o*f+u*p};if(n.subsurfaceWeight>0&&n.subsurfaceColorTexture){s._exporter._materialNeedsUVsSet.add(n);var x=s._exporter._materialExporter.getTextureInfo(n.subsurfaceColorTexture);x&&(d.multiscatterColorTexture=x)}else if(n.transmissionWeight>0&&n.transmissionScatterTexture){s._exporter._materialNeedsUVsSet.add(n);var g=s._exporter._materialExporter.getTextureInfo(n.transmissionScatterTexture);g&&(d.multiscatterColorTexture=g)}r.extensions=r.extensions||{},r.extensions[Bt]=d}var _,m,T,y,v,b;e(r)})},e}(),Ot=!1;function Ut(){Ot||(Ot=!0,X.RegisterExtension(Bt,function(e){return new Nt(e)},101))}Ut();var Pt="KHR_materials_diffuse_roughness",Kt=function(){function e(e){this.name=Pt,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,r,n){return o(this,void 0,void 0,function(){var e;return a(this,function(r){if(e=[],n instanceof t.PBRBaseMaterial){if(n._baseDiffuseRoughness)return n._baseDiffuseRoughnessTexture&&e.push(n._baseDiffuseRoughnessTexture),[2,e]}else if(n instanceof t.OpenPBRMaterial&&n.baseDiffuseRoughness)return n.baseDiffuseRoughnessTexture&&e.push(n.baseDiffuseRoughnessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){var i=null,o=null;if(n instanceof t.PBRBaseMaterial?(i=n._baseDiffuseRoughness,o=n._baseDiffuseRoughnessTexture):n instanceof t.OpenPBRMaterial&&(i=n.baseDiffuseRoughness,o=n.baseDiffuseRoughnessTexture),i){s._wasUsed=!0,r.extensions=r.extensions||{};var a=s._exporter._materialExporter.getTextureInfo(o),u={diffuseRoughnessFactor:i,diffuseRoughnessTexture:null!=a?a:void 0};null!==u.diffuseRoughnessTexture&&s._exporter._materialNeedsUVsSet.add(n),r.extensions[Pt]=u,e(r)}else e(r)})},e}(),Wt=!1;function Ht(){Wt||(Wt=!0,X.RegisterExtension(Pt,function(e){return new Kt(e)}))}Ht();var Lt="KHR_materials_openpbr",zt=function(){function e(){this.name=Lt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,r,n){var s=this;return new Promise(function(e){n instanceof t.OpenPBRMaterial&&(s._wasUsed=!0,r.extensions=r.extensions||{},r.extensions[Lt]={}),e(r)})},e}(),kt=!1;function Gt(){kt||(kt=!0,X.RegisterExtension(Lt,function(){return new zt}))}Gt();var Dt="KHR_texture_transform",qt=function(){function e(){this.name=Dt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,r,n){if(n.getScene()||t.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(n.name,"!")),0===n.uAng&&0===n.vAng||(t.Tools.Warn("".concat(e,": Texture ").concat(n.name," with rotation in the u or v axis is not supported in glTF.")),0===n.uRotationCenter&&0===n.vRotationCenter)){var s={},i=!1;if(0===n.uOffset&&0===n.vOffset||(s.offset=[n.uOffset,n.vOffset],i=!0),1===n.uScale&&1===n.vScale||(s.scale=[n.uScale,n.vScale],i=!0),0!==n.wAng){if(0!==n.uRotationCenter||0!==n.vRotationCenter){if(n.homogeneousRotationInUVTransform&&n.uScale!==n.vScale)return void t.Tools.Warn("".concat(e,": Texture ").concat(n.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(Dt,"."));t.Tools.Warn("".concat(e,": Texture ").concat(n.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(Dt,".")),s.offset=function(e){var t=e.uOffset,r=e.vOffset,n=e.uRotationCenter,s=e.vRotationCenter,i=e.uScale,o=e.vScale,a=e.wAng,u=Math.cos(a),c=Math.sin(a),l=n*i,h=s*o;return[t+(l*(1-u)+h*c),r+(h*(1-u)-l*c)]}(n)}s.rotation=-n.wAng,i=!0}0!==n.coordinatesIndex&&(s.texCoord=n.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,r.extensions||(r.extensions={}),r.extensions[Dt]=s)}},e}(),jt=!1;function Xt(){jt||(jt=!0,X.RegisterExtension(Dt,function(){return new qt}))}Xt();var Qt="KHR_texture_basisu",Yt=function(){function e(e){this.name=Qt,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,r){var n=this._exporter._textures[r.index],s=n.source;if(void 0!==s){var i=this._exporter._images[s];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Qt]={source:s},this._wasUsed=!0)}},e}(),Zt=!1;function Jt(){Zt||(Zt=!0,X.RegisterExtension(Qt,function(e){return new Yt(e)}))}Jt();var $t="EXT_texture_webp",er=function(){function e(e){this.name=$t,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,r){var n=this._exporter._textures[r.index],s=n.source;if(void 0!==s){var i=this._exporter._images[s];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[$t]={source:s},this._wasUsed=!0)}},e}(),tr=!1;function rr(){tr||(tr=!0,X.RegisterExtension($t,function(e){return new er(e)}))}rr();var nr="EXT_texture_avif",sr=function(){function e(e){this.name=nr,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,r){var n=this._exporter._textures[r.index],s=n.source;if(void 0!==s){var i=this._exporter._images[s];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[nr]={source:s},this._wasUsed=!0)}},e}(),ir=!1;function or(){ir||(ir=!0,X.RegisterExtension(nr,function(e){return new sr(e)}))}or();var ar={__proto__:null,EXT_lights_area:me,EXT_mesh_gpu_instancing:$,EXT_texture_avif:sr,EXT_texture_webp:er,KHR_draco_mesh_compression:se,KHR_lights_punctual:he,KHR_materials_anisotropy:Re,KHR_materials_clearcoat:Ie,KHR_materials_coat:Pe,KHR_materials_diffuse_roughness:Kt,KHR_materials_diffuse_transmission:ze,KHR_materials_dispersion:qe,KHR_materials_emissive_strength:Ye,KHR_materials_fuzz:dt,KHR_materials_ior:et,KHR_materials_iridescence:st,KHR_materials_openpbr:zt,KHR_materials_sheen:ut,KHR_materials_specular:mt,KHR_materials_transmission:bt,KHR_materials_unlit:At,KHR_materials_volume:Vt,KHR_materials_volume_scatter:Nt,KHR_texture_basisu:Yt,KHR_texture_transform:qt,RegisterEXT_lights_area:ye,RegisterEXT_mesh_gpu_instancing:te,RegisterEXT_texture_avif:or,RegisterEXT_texture_webp:rr,RegisterKHR_draco_mesh_compression:oe,RegisterKHR_lights_punctual:pe,RegisterKHR_materials_anisotropy:we,RegisterKHR_materials_clearcoat:Se,RegisterKHR_materials_coat:We,RegisterKHR_materials_diffuse_roughness:Ht,RegisterKHR_materials_diffuse_transmission:Ge,RegisterKHR_materials_dispersion:Xe,RegisterKHR_materials_emissive_strength:Je,RegisterKHR_materials_fuzz:gt,RegisterKHR_materials_ior:rt,RegisterKHR_materials_iridescence:ot,RegisterKHR_materials_openpbr:Gt,RegisterKHR_materials_sheen:lt,RegisterKHR_materials_specular:yt,RegisterKHR_materials_transmission:Mt,RegisterKHR_materials_unlit:Ct,RegisterKHR_materials_volume:Ft,RegisterKHR_materials_volume_scatter:Ut,RegisterKHR_texture_basisu:Jt,RegisterKHR_texture_transform:Xt},ur={__proto__:null,EXT_lights_area:me,EXT_mesh_gpu_instancing:$,EXT_texture_avif:sr,EXT_texture_webp:er,GLTF2Export:Q,GLTFData:n,KHR_draco_mesh_compression:se,KHR_lights_punctual:he,KHR_materials_anisotropy:Re,KHR_materials_clearcoat:Ie,KHR_materials_coat:Pe,KHR_materials_diffuse_roughness:Kt,KHR_materials_diffuse_transmission:ze,KHR_materials_dispersion:qe,KHR_materials_emissive_strength:Ye,KHR_materials_fuzz:dt,KHR_materials_ior:et,KHR_materials_iridescence:st,KHR_materials_openpbr:zt,KHR_materials_sheen:ut,KHR_materials_specular:mt,KHR_materials_transmission:bt,KHR_materials_unlit:At,KHR_materials_volume:Vt,KHR_materials_volume_scatter:Nt,KHR_texture_basisu:Yt,KHR_texture_transform:qt,RegisterEXT_lights_area:ye,RegisterEXT_mesh_gpu_instancing:te,RegisterEXT_texture_avif:or,RegisterEXT_texture_webp:rr,RegisterKHR_draco_mesh_compression:oe,RegisterKHR_lights_punctual:pe,RegisterKHR_materials_anisotropy:we,RegisterKHR_materials_clearcoat:Se,RegisterKHR_materials_coat:We,RegisterKHR_materials_diffuse_roughness:Ht,RegisterKHR_materials_diffuse_transmission:Ge,RegisterKHR_materials_dispersion:Xe,RegisterKHR_materials_emissive_strength:Je,RegisterKHR_materials_fuzz:gt,RegisterKHR_materials_ior:rt,RegisterKHR_materials_iridescence:ot,RegisterKHR_materials_openpbr:Gt,RegisterKHR_materials_sheen:lt,RegisterKHR_materials_specular:yt,RegisterKHR_materials_transmission:Mt,RegisterKHR_materials_unlit:Ct,RegisterKHR_materials_volume:Ft,RegisterKHR_materials_volume_scatter:Ut,RegisterKHR_texture_basisu:Jt,RegisterKHR_texture_transform:Xt,_ConvertToGLTFPBRMetallicRoughness:g,_SolveMetallic:x},cr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==cr){cr.BABYLON=cr.BABYLON||{};var lr=cr.BABYLON;lr.GLTF2=lr.GLTF2||{},lr.GLTF2.Exporter=lr.GLTF2.Exporter||{},lr.GLTF2.Exporter.Extensions=lr.GLTF2.Exporter.Extensions||{};var hr=[];for(var fr in r)lr[fr]=r[fr],hr.push(fr);for(var fr in s)lr[fr]=s[fr],hr.push(fr);for(var fr in Y)lr[fr]=Y[fr],hr.push(fr);for(var fr in ar)lr.GLTF2.Exporter.Extensions[fr]=ar[fr],hr.push(fr);for(var fr in ur)hr.indexOf(fr)>-1||(lr.GLTF2.Exporter[fr]=ur[fr])}e.EXT_lights_area=me,e.EXT_mesh_gpu_instancing=$,e.EXT_texture_avif=sr,e.EXT_texture_webp=er,e.GLTF2Export=Q,e.GLTFData=n,e.KHR_draco_mesh_compression=se,e.KHR_lights_punctual=he,e.KHR_materials_anisotropy=Re,e.KHR_materials_clearcoat=Ie,e.KHR_materials_coat=Pe,e.KHR_materials_diffuse_roughness=Kt,e.KHR_materials_diffuse_transmission=ze,e.KHR_materials_dispersion=qe,e.KHR_materials_emissive_strength=Ye,e.KHR_materials_fuzz=dt,e.KHR_materials_ior=et,e.KHR_materials_iridescence=st,e.KHR_materials_openpbr=zt,e.KHR_materials_sheen=ut,e.KHR_materials_specular=mt,e.KHR_materials_transmission=bt,e.KHR_materials_unlit=At,e.KHR_materials_volume=Vt,e.KHR_materials_volume_scatter=Nt,e.KHR_texture_basisu=Yt,e.KHR_texture_transform=qt,e.RegisterEXT_lights_area=ye,e.RegisterEXT_mesh_gpu_instancing=te,e.RegisterEXT_texture_avif=or,e.RegisterEXT_texture_webp=rr,e.RegisterKHR_draco_mesh_compression=oe,e.RegisterKHR_lights_punctual=pe,e.RegisterKHR_materials_anisotropy=we,e.RegisterKHR_materials_clearcoat=Se,e.RegisterKHR_materials_coat=We,e.RegisterKHR_materials_diffuse_roughness=Ht,e.RegisterKHR_materials_diffuse_transmission=Ge,e.RegisterKHR_materials_dispersion=Xe,e.RegisterKHR_materials_emissive_strength=Je,e.RegisterKHR_materials_fuzz=gt,e.RegisterKHR_materials_ior=rt,e.RegisterKHR_materials_iridescence=ot,e.RegisterKHR_materials_openpbr=Gt,e.RegisterKHR_materials_sheen=lt,e.RegisterKHR_materials_specular=yt,e.RegisterKHR_materials_transmission=Mt,e.RegisterKHR_materials_unlit=Ct,e.RegisterKHR_materials_volume=Ft,e.RegisterKHR_materials_volume_scatter=Ut,e.RegisterKHR_texture_basisu=Jt,e.RegisterKHR_texture_transform=Xt,e._ConvertToGLTFPBRMetallicRoughness=g,e._SolveMetallic=x,e.__IGLTFExporterExtension=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 s={__proto__:null,__IGLTFExporterExtension:0};class r{constructor(){this.files={}}get glTFFiles(){return this.files}downloadFiles(){for(const e in this.files){const s=this.files[e],r=new Blob([s],{type:t.GetMimeType(e)});t.Tools.Download(r,e)}}}var n={__proto__:null,GLTFData:r};function i(e,t,s,r){return new(s||(s=Promise))(function(n,i){function o(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(o,a)}u((r=r.apply(e,t||[])).next())})}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;const o=1e-6,a=new t.Color3(.04,.04,.04),u=t.Color3.White(),l=t.Color3.BlackReadOnly;function c(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function h(e,s,r){if(s<a.r)return 0;const n=a.r,i=e*r/(1-a.r)+s-2*a.r,o=i*i-4*n*(a.r-s);return t.Scalar.Clamp((-i+Math.sqrt(o))/(2*n),0,1)}function f(e){const s=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,n=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(n);return{baseColorFactor:[s.r,s.g,s.b,r],metallicFactor:0,roughnessFactor:i}}function d(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function p(e,s,r){const n=new Uint8Array(e*s*4);for(let e=0;e<n.length;e+=4)n[e]=n[e+1]=n[e+2]=n[e+3]=255;return t.RawTexture.CreateRGBATexture(n,e,s,r)}function x(e){if(e instanceof Uint8Array){const t=e.length,s=new Float32Array(e.length);for(let r=0;r<t;++r)s[r]=e[r]/255;return s}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}class _{constructor(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}getTextureInfo(e){var t;return e&&null!==(t=this._textureMap.get(e.uniqueId))&&void 0!==t?t:null}exportStandardMaterialAsync(e,s){return i(this,void 0,void 0,function*(){const r=f(e),n={name:e.name};if(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."),n.doubleSided=!0),s){const t=[],s=e.diffuseTexture;s&&t.push(this.exportTextureAsync(s).then(e=>{e&&(r.baseColorTexture=e)}));const i=e.bumpTexture;i&&t.push(this.exportTextureAsync(i).then(e=>{e&&(n.normalTexture=e,1!==i.level&&(n.normalTexture.scale=i.level))}));const o=e.emissiveTexture;o&&(n.emissiveFactor=[1,1,1],t.push(this.exportTextureAsync(o).then(e=>{e&&(n.emissiveTexture=e)})));const a=e.ambientTexture;a&&t.push(this.exportTextureAsync(a).then(e=>{if(e){const t={index:e.index};n.occlusionTexture=t}})),t.length>0&&(this._exporter._materialNeedsUVsSet.add(e),yield Promise.all(t))}(e.alpha<1||e.opacityTexture)&&(e.alphaMode===t.Constants.ALPHA_COMBINE?n.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(l,o)&&(n.emissiveFactor=e.emissiveColor.asArray()),n.pbrMetallicRoughness=r,d(n,e),yield this._finishMaterialAsync(n,e);const i=this._exporter._materials;return i.push(n),i.length-1})}_finishMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s=yield this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t),r=[];for(const e of s)r.push(this.exportTextureAsync(e));yield Promise.all(r),yield this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)})}_resizeTexturesToSameDimensions(e,s,r){const n=e?e.getSize():{width:0,height:0},i=s?s.getSize():{width:0,height:0};let o,a;return n.width<i.width?(o=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):p(i.width,i.height,r),a=s):n.width>i.width?(a=s&&s instanceof t.Texture?t.TextureTools.CreateResizedCopy(s,n.width,n.height,!0):p(n.width,n.height,r),o=e):(o=e,a=s),{texture1:o,texture2:a}}_convertSpecularGlossinessTexturesToMetallicRoughnessAsync(e,s,r){return i(this,void 0,void 0,function*(){var n;const i=new Array;if(!e&&!s)return yield Promise.reject("diffuse and specular glossiness textures are not defined!");const a=e?e.getScene():s?s.getScene():null;if(a){const l=this._resizeTexturesToSameDimensions(e,s,a),c=null===(n=l.texture1)||void 0===n?void 0:n.getSize();let h,f;const d=c.width,p=c.height,_=yield l.texture1.readPixels(),g=yield l.texture2.readPixels();if(!_)return yield Promise.reject("Failed to retrieve pixels from diffuse texture!");if(h=x(_),!g)return yield Promise.reject("Failed to retrieve pixels from specular glossiness texture!");f=x(g);const m=f.byteLength,T=new Uint8Array(m),y=new Uint8Array(m),R=4,M=new t.Color3(0,0,0);let A=0,b=0;for(let e=0;e<p;++e)for(let s=0;s<d;++s){const n=(d*e+s)*R,i={diffuseColor:new t.Color3(h[n],h[n+1],h[n+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),specularColor:new t.Color3(f[n],f[n+1],f[n+2]).toLinearSpace(a.getEngine().useExactSrgbConversions).multiply(r.specularColor),glossiness:f[n+3]*r.glossiness},o=this._convertSpecularGlossinessToMetallicRoughness(i);M.r=Math.max(M.r,o.baseColor.r),M.g=Math.max(M.g,o.baseColor.g),M.b=Math.max(M.b,o.baseColor.b),A=Math.max(A,o.metallic),b=Math.max(b,o.roughness),y[n]=255*o.baseColor.r,y[n+1]=255*o.baseColor.g,y[n+2]=255*o.baseColor.b,y[n+3]=l.texture1.hasAlpha?255*h[n+3]:255,T[n]=0,T[n+1]=255*o.roughness,T[n+2]=255*o.metallic,T[n+3]=255}const w={baseColor:M,metallic:A,roughness:b};let E=!1,v=!1;for(let e=0;e<p;++e)for(let s=0;s<d;++s){const r=(d*e+s)*R;y[r]/=w.baseColor.r>o?w.baseColor.r:1,y[r+1]/=w.baseColor.g>o?w.baseColor.g:1,y[r+2]/=w.baseColor.b>o?w.baseColor.b:1;const n=t.Color3.FromInts(y[r],y[r+1],y[r+2]).toGammaSpace(a.getEngine().useExactSrgbConversions);y[r]=255*n.r,y[r+1]=255*n.g,y[r+2]=255*n.b,n.equalsWithEpsilon(u,o)||(v=!0),T[r+1]/=w.roughness>o?w.roughness:1,T[r+2]/=w.metallic>o?w.metallic:1,t.Color3.FromInts(255,T[r+1],T[r+2]).equalsWithEpsilon(u,o)||(E=!0)}return E&&i.push(t.EncodeImageAsync(T,d,p).then(e=>{w.metallicRoughnessTextureData=e})),v&&i.push(t.EncodeImageAsync(y,d,p).then(e=>{w.baseColorTextureData=e})),yield Promise.all(i).then(()=>w)}return yield Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")})}_convertSpecularGlossinessToMetallicRoughness(e){const s=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),i=h(s,r,n),u=e.diffuseColor.scale(n/(1-a.r)/Math.max(1-i,o)),l=e.specularColor.subtract(a.scale(1-i)).scale(1/Math.max(i,o));let c=t.Color3.Lerp(u,l,i*i);return c=c.clampToRef(0,1,c),{baseColor:c,metallic:i,roughness:1-e.glossiness}}_getPerceivedBrightness(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)}_getMaxComponent(e){return Math.max(e.r,Math.max(e.g,e.b))}_convertMetalRoughFactorsToMetallicRoughnessAsync(e,s,r,n,o,a,u,l,c){return i(this,void 0,void 0,function*(){const h=[],f={baseColor:e,metallic:s,roughness:r};if(c)if(u instanceof t.OpenPBRMaterial){if(u.geometryOpacityTexture){const e=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:0,s=u.geometryOpacityTexture&&u.geometryOpacityTexture.getInternalTexture()?u.geometryOpacityTexture.getInternalTexture().uniqueId:0,r=Number(`${e}${s}`),o=this._textureMap.get(r);o?l.baseColorTexture=o:h.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(1),n?t.CreateTextureInput(n,2):t.CreateConstantInput(1),t.CreateTextureInput(u.geometryOpacityTexture,0)),u.getScene()).then(e=>i(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,r);t&&(l.baseColorTexture=t)})))}else n&&h.push(this.exportTextureAsync(n).then(e=>{e&&(l.baseColorTexture=e)}));if(u._useMetallicFromMetallicTextureBlue&&o)h.push(this.exportTextureAsync(o).then(e=>{e&&(l.metallicRoughnessTexture=e)}));else if(a||o){const e=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,s=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,r=Number(`${e}${s}`),n=this._textureMap.get(r);n?l.metallicRoughnessTexture=n:h.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(u.ambientOcclusionTexture?t.CreateTextureInput(u.ambientOcclusionTexture,0):t.CreateConstantInput(1),a?t.CreateTextureInput(a,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,0):t.CreateConstantInput(1)),u.getScene()).then(e=>i(this,void 0,void 0,function*(){const t=yield this.exportTextureAsync(e,r);t&&(l.metallicRoughnessTexture=t)})))}}else n&&h.push(this.exportTextureAsync(n).then(e=>{e&&(l.baseColorTexture=e)})),o&&h.push(this.exportTextureAsync(o).then(e=>{e&&(l.metallicRoughnessTexture=e)}));return h.length>0&&(this._exporter._materialNeedsUVsSet.add(u),yield Promise.all(h)),f})}_getTextureSampler(e){const s={};if(!(e&&e instanceof t.Texture))return s;const r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(s.wrapS=r);const n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(s.wrapT=n),e.samplingMode){case t.Texture.LINEAR_LINEAR:s.magFilter=9729,s.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:s.magFilter=9729,s.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:s.magFilter=9728,s.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:s.magFilter=9728,s.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:s.magFilter=9728,s.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:s.magFilter=9728,s.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:s.magFilter=9729,s.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:s.magFilter=9729,s.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:s.magFilter=9728,s.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:s.magFilter=9729,s.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:s.magFilter=9729,s.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:s.magFilter=9728,s.minFilter=9984}return s}_getGLTFTextureWrapMode(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 ${e}!`),10497}}_convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,s){return i(this,void 0,void 0,function*(){const r={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},n=e._albedoTexture,i=e._reflectivityTexture,o=e._useMicroSurfaceFromReflectivityMapAlpha;if(i&&!o)return yield Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");if((n||i)&&s){this._exporter._materialNeedsUVsSet.add(e);const s=this._exportTextureSampler(n||i),o=yield this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(n,i,r),a=this._exporter._textures;if(o.baseColorTextureData){const e=yield this._exportImageAsync(`baseColor${a.length}`,o.baseColorTextureData);t.baseColorTexture=this._exportTextureInfo(e,s,null==n?void 0:n.coordinatesIndex)}if(o.metallicRoughnessTextureData){const e=yield this._exportImageAsync(`metallicRoughness${a.length}`,o.metallicRoughnessTextureData);t.metallicRoughnessTexture=this._exportTextureInfo(e,s,null==i?void 0:i.coordinatesIndex)}return o}return this._convertSpecularGlossinessToMetallicRoughness(r)})}exportPBRMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s={},r={name:e.name},n=e.isMetallicWorkflow();if(n){const t=e._albedoColor,r=e.alpha;t&&(s.baseColorFactor=[t.r,t.g,t.b,r])}const i=n?yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,s,t):yield this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,s,t);yield this._setMetallicRoughnessPbrMaterialAsync(i,e,r,s,t),yield this._finishMaterialAsync(r,e);const o=this._exporter._materials;return o.push(r),o.length-1})}_setMetallicRoughnessPbrMaterialAsync(e,s,r,n,a){return i(this,void 0,void 0,function*(){if(d(r,s),e.baseColor.equalsWithEpsilon(u,o)&&t.Scalar.WithinEpsilon(s.alpha,1,o)||(n.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,s.alpha]),null!=e.metallic&&1!==e.metallic&&(n.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(n.roughnessFactor=e.roughness),null==s.backFaceCulling||s.backFaceCulling||(s._twoSidedLighting||t.Tools.Warn(s.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),a){const e=[],o=s instanceof t.PBRBaseMaterial?s._bumpTexture:s.geometryNormalTexture;o&&e.push(this.exportTextureAsync(o).then(e=>{e&&(r.normalTexture=e,1!==o.level&&(r.normalTexture.scale=o.level))}));const a=s instanceof t.PBRBaseMaterial?s._ambientTexture:s.ambientOcclusionTexture;a&&e.push(new Promise(e=>i(this,void 0,void 0,function*(){if(s instanceof t.OpenPBRMaterial&&n.metallicRoughnessTexture){const t=this._exportTextureSampler(a),s=this._exporter._textures[n.metallicRoughnessTexture.index].source,r=this._exportTextureInfo(s,t,a.coordinatesIndex);return this._textureMap.set(a.uniqueId,r),this._exporter._extensionsPostExportTextures("exporter",r,a),e(r)}return e(yield this.exportTextureAsync(a))})).then(e=>i(this,void 0,void 0,function*(){if(e){const n={index:e.index,texCoord:e.texCoord,extensions:e.extensions};r.occlusionTexture=n,s instanceof t.PBRBaseMaterial?n.strength=s._ambientTextureStrength:n.strength=s.ambientOcclusionTexture.level}})));const u=s instanceof t.PBRBaseMaterial?s._emissiveTexture:s.emissionColorTexture;u&&e.push(this.exportTextureAsync(u).then(e=>{e&&(r.emissiveTexture=e)})),e.length>0&&(this._exporter._materialNeedsUVsSet.add(s),yield Promise.all(e))}const c=s instanceof t.PBRBaseMaterial?s._emissiveColor:s.emissionColor;c.equalsWithEpsilon(l,o)||(r.emissiveFactor=c.asArray()),r.pbrMetallicRoughness=n})}exportOpenPBRMaterialAsync(e,t){return i(this,void 0,void 0,function*(){const s={},r={name:e.name},n=e.baseColor,i=e.geometryOpacity;n&&(s.baseColorFactor=[n.r,n.g,n.b,i]);const o=yield this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,s,t);yield this._setMetallicRoughnessPbrMaterialAsync(o,e,r,s,t),yield this._finishMaterialAsync(r,e);const a=this._exporter._materials;return a.push(r),a.length-1})}exportTextureAsync(e){return i(this,arguments,void 0,function*(e,t=null){let s=this._textureMap.get(null!=t?t:e.uniqueId);if(s)return s;const r=this._exportTextureSampler(e),n=yield this._exportTextureImageAsync(e);return s=this._exportTextureInfo(n,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,s),this._exporter._extensionsPostExportTextures("exporter",s,e),s})}_exportTextureImageAsync(e){return i(this,void 0,void 0,function*(){var s;const r=null!==(s=e.mimeType)&&void 0!==s?s:"none",n=this._internalTextureToImage,o=e.getInternalTexture().uniqueId;n[o]=n[o]||{};let a=n[o][r];return void 0===a&&(a=(()=>i(this,void 0,void 0,function*(){const s=yield function(e){return i(this,void 0,void 0,function*(){var s;const r=e.getInternalTexture();if(!r||1!==r.source)return null;if(r.invertY&&!((null===(s=e.getScene())||void 0===s?void 0:s.getEngine())instanceof t.NullEngine))return null;const n=r._buffer;let i,o=e.mimeType;try{n?ArrayBuffer.isView(n)?i=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n instanceof ArrayBuffer?i=n:n instanceof Blob?(i=yield n.arrayBuffer(),o=n.type||o):"string"==typeof n?(i=yield t.Tools.LoadFileAsync(n),o=t.GetMimeType(n)||o):"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement&&(i=yield t.Tools.LoadFileAsync(n.src),o=t.GetMimeType(n.src)||o):(i=yield t.Tools.LoadFileAsync(r.url),o=t.GetMimeType(r.url)||o)}catch(e){return null}if(i&&!o&&r.url){const e=r.url.match(/^data:([^;,]+)/);o=e?e[1]:t.GetMimeType(r.url)}return i&&o?{data:i,mimeType:o}:null})}(e);if(s&&c(s.mimeType)&&("none"===r||s.mimeType===r))return yield this._exportImageAsync(e.name,new Blob([s.data],{type:s.mimeType}));let n="image/png";"none"!==r&&(c(r)?n=r:(n="image/png",t.Tools.Warn(`Unsupported media type: ${r}. Exporting texture as PNG.`)));const o=e.getSize(),a=yield t.GetTextureDataAsync(e),u=yield t.EncodeImageAsync(a,o.width,o.height,n);return yield this._exportImageAsync(e.name,u)}))(),n[o][r]=a),yield a})}_exportImageAsync(e,s){return i(this,void 0,void 0,function*(){const r=this._exporter._images;let n;if(this._exporter._shouldUseGlb){n={name:e,mimeType:s.type,bufferView:void 0};const t=yield s.arrayBuffer(),r=this._exporter._bufferManager.createBufferView(new Uint8Array(t));this._exporter._bufferManager.setBufferView(n,r)}else{const i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),o=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"}}(s.type);let a=i+o;r.some(e=>e.uri===a)&&(a=`${i}_${t.Tools.RandomId()}${o}`),n={name:e,uri:a},this._exporter._imageData[a]=s}return r.push(n),r.length-1})}_exportTextureInfo(e,t,s){const r=this._exporter._textures;let n=r.findIndex(s=>s.sampler==t&&s.source===e);-1===n&&(n=r.length,r.push({source:e,sampler:t}));const i={index:n};return s&&(i.texCoord=s),i}_exportTextureSampler(e){const t=this._getTextureSampler(e),s=this._exporter._samplers,r=s.findIndex(e=>e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT);return-1!==r?r:(s.push(t),s.length-1)}}const g=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function m(e,s){if(!(e instanceof t.TransformNode))return!1;if(s){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(g,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}const T=t.Vector3.ZeroReadOnly,y=t.Quaternion.Identity(),R=t.Vector3.OneReadOnly,M=new t.Vector3(-1,1,1);function A(e,t){const{byteOffset:s,byteStride:r,type:n,normalized:i}=e,o=e.getSize(),a=t.reduce((e,t)=>t.getTotalVertices()>e?t.getTotalVertices():e,-Number.MAX_VALUE);return{byteOffset:s,byteStride:r,componentCount:o,type:n,count:a*o,normalized:i,totalVertices:a,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 w(e){return e.some(e=>e>=256)}function E(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 v(e){const 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 C(e){return e.x*=-1,e}function I(e){return g.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(g,e),e}function V(e){if(e.x*e.x+e.y*e.y>.5){const t=Math.abs(e.x),s=Math.abs(e.y);if(t>s){const s=Math.sign(e.x);e.x=t,e.y*=-s,e.z*=-s,e.w*=s}else{const t=Math.sign(e.y);e.x*=-t,e.y=s,e.z*=t,e.w*=-t}}else{const t=Math.abs(e.z),s=Math.abs(e.w);if(t>s){const s=Math.sign(e.z);e.x*=-s,e.y*=s,e.z=t,e.w*=-s}else{const t=Math.sign(e.w);e.x*=t,e.y*=-t,e.z*=-t,e.w=s}}return e}function S(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function F(e,s){const r=t.Vector3.FromArrayToRef(s.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),n=t.Quaternion.FromArrayToRef(s.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(R,n,r,t.TmpVectors.Matrix[0]),o=t.Vector3.FromArrayToRef(e.translation||[0,0,0],0,t.TmpVectors.Vector3[2]),a=t.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[1]),u=t.Matrix.ComposeToRef(R,a,o,t.TmpVectors.Matrix[1]);i.multiplyToRef(u,u),u.decompose(void 0,n,r),r.equalsWithEpsilon(T,t.Epsilon)?delete s.translation:s.translation=r.asArray(),n.equalsWithEpsilon(y,t.Epsilon)?delete s.rotation:s.rotation=n.asArray(),s.scale&&delete s.scale}function B(e,s){if(!(s instanceof t.TransformNode))return!1;if(1!==s.getChildren().length||0!==e.getChildren().length||e.parent!==s)return!1;const r=e.getScene(),n=e instanceof t.TargetCamera&&!r.useRightHandedSystem?M:R;return!!s.scaling.equalsWithEpsilon(n,t.Epsilon)||(t.Logger.Warn(`Cannot collapse node ${e.name} into parent node ${s.name} with modified scaling.`),!1)}function N(e){if(e instanceof Array){const 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)}function U(e,t){for(const[s,r]of Object.entries(e)){const n=t[s];(Array.isArray(r)&&Array.isArray(n)&&O(r,n)||r===n)&&delete e[s]}return e}function O(e,t){return e.length===t.length&&e.every((e,s)=>e===t[s])}const K=new Map([[Int8Array,(e,t,s)=>e.setInt8(t,s)],[Uint8Array,(e,t,s)=>e.setUint8(t,s)],[Uint8ClampedArray,(e,t,s)=>e.setUint8(t,s)],[Int16Array,(e,t,s)=>e.setInt16(t,s,!0)],[Uint16Array,(e,t,s)=>e.setUint16(t,s,!0)],[Int32Array,(e,t,s)=>e.setInt32(t,s,!0)],[Uint32Array,(e,t,s)=>e.setUint32(t,s,!0)],[Float32Array,(e,t,s)=>e.setFloat32(t,s,!0)],[Float64Array,(e,t,s)=>e.setFloat64(t,s,!0)]]);class P{writeTypedArray(e){this._checkGrowBuffer(e.byteLength);const t=K.get(e.constructor);for(let s=0;s<e.length;s++)t(this._dataView,this._byteOffset,e[s]),this._byteOffset+=e.BYTES_PER_ELEMENT}constructor(e){this._data=new Uint8Array(e),this._dataView=new DataView(this._data.buffer),this._byteOffset=0}get byteOffset(){return this._byteOffset}getOutputData(){return new Uint8Array(this._data.buffer,0,this._byteOffset)}writeUInt8(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++}writeInt8(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++}writeInt16(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2}writeUInt16(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2}writeInt32(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4}writeUInt32(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4}writeFloat32(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4}writeFloat64(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8}_checkGrowBuffer(e){const t=this.byteOffset+e;if(t>this._data.byteLength){const e=new Uint8Array(2*t);e.set(this._data),this._data=e,this._dataView=new DataView(this._data.buffer)}}}function W(e){return e%4==0?4:e%2==0?2:1}class H{constructor(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}generateBinary(e){let t=0;this._bufferViewToData.forEach(e=>{t+=e.byteLength});const s=new P(t),r=Array.from(this._bufferViewToData.keys()).sort((e,t)=>W(t.byteLength)-W(e.byteLength));for(const t of r){t.byteOffset=s.byteOffset,e.push(t);const r=e.length-1,n=this.getPropertiesWithBufferView(t);for(const e of n)e.bufferView=r;s.writeTypedArray(this._bufferViewToData.get(t)),this._bufferViewToData.delete(t)}return s.getOutputData()}createBufferView(e,t){const s={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(s,e),s}createAccessor(e,t,s,r,n,i,o){this._verifyBufferView(e);const a={bufferView:void 0,componentType:s,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:o,byteOffset:n};return this.setBufferView(a,e),this._accessorToBufferView.set(a,e),a}setBufferView(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)}removeBufferView(e){const t=this.getPropertiesWithBufferView(e);for(const e of t)void 0!==e.bufferView&&delete e.bufferView;this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach((t,s)=>{t===e&&(void 0!==s.byteOffset&&delete s.byteOffset,this._accessorToBufferView.delete(s))})}getBufferView(e){const t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t}getPropertiesWithBufferView(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)}getData(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)}_verifyBufferView(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error(`BufferView ${e} not found in BufferManager.`)}}var L;!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(L||(L={}));class z{static _IsTransformable(e){return e&&(e instanceof t.TransformNode||e instanceof t.Camera||e instanceof t.Light)}static _CreateNodeAnimation(e,s,r,n,i){if(this._IsTransformable(e)){const o=[],a=[],u=s.getKeys(),l=z._CalculateMinMaxKeyFrames(u),c=z._DeduceInterpolation(u,r,n),h=c.interpolationType,f=c.shouldBakeAnimation;if(f?z._CreateBakedAnimation(e,s,r,l.min,l.max,s.framePerSecond,i,o,a,l,n):"LINEAR"===h||"STEP"===h?z._CreateLinearOrStepAnimation(e,s,r,o,a,n):"CUBICSPLINE"===h?z._CreateCubicSplineAnimation(e,s,r,o,a,n):z._CreateBakedAnimation(e,s,r,l.min,l.max,s.framePerSecond,i,o,a,l,n),o.length&&a.length)return{inputs:o,outputs:a,samplerInterpolation:h,inputsMin:f?l.min:t.Tools.FloatRound(l.min/s.framePerSecond),inputsMax:f?l.max:t.Tools.FloatRound(l.max/s.framePerSecond)}}return null}static _DeduceAnimationInfo(e){let s=null,r="VEC3",n=!1;const i=e.targetProperty.split(".");switch(i[0]){case"scaling":s="scale";break;case"position":s="translation";break;case"rotation":r="VEC4",s="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,s="rotation";break;case"influence":r="SCALAR",s="weights";break;default:t.Tools.Error(`Unsupported animatable property ${i[0]}`)}return s?{animationChannelTargetPath:s,dataAccessorType:r,useQuaternion:n}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)}static _CreateNodeAnimationFromNodeAnimations(e,t,s,r,n,i,o,a,u,l,c){let h;if(z._IsTransformable(e)&&e.animations)for(const n of e.animations){if(c&&!c(n))continue;const f=z._DeduceAnimationInfo(n);f&&(h={name:n.name,samplers:[],channels:[]},z._AddAnimation(`${n.name}`,n.hasRunningRuntimeAnimations?t:h,e,n,f.dataAccessorType,f.animationChannelTargetPath,r,i,o,a,f.useQuaternion,u,l),h.samplers.length&&h.channels.length&&s.push(h))}}static _CreateMorphTargetAnimationFromMorphTargetAnimations(e,s,r,n,i,o,a,u,l,c,h){let f;if(e instanceof t.Mesh){const i=e.morphTargetManager;if(i)for(let d=0;d<i.numTargets;++d){const p=i.getTarget(d);for(const x of p.animations){if(h&&!h(x))continue;const p=new t.Animation(`${x.name}`,"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),_=[],g=x.getKeys();for(let e=0;e<g.length;++e){const t=g[e];for(let e=0;e<i.numTargets;++e)e==d?_.push(t):_.push({frame:t.frame,value:0})}p.setKeys(_,!0);const m=z._DeduceAnimationInfo(p);m&&(f={name:p.name,samplers:[],channels:[]},z._AddAnimation(x.name,x.hasRunningRuntimeAnimations?s:f,e,p,m.dataAccessorType,m.animationChannelTargetPath,n,o,a,u,m.useQuaternion,l,c,i.numTargets),f.samplers.length&&f.channels.length&&r.push(f))}}}}static _CreateNodeAndMorphAnimationFromAnimationGroups(e,s,r,n,i,o,a,u,l){var c;let h;if(e.animationGroups){const f=e.animationGroups;for(const d of f){const f=new Map,p=new Map,x=new Set,_=d.to-d.from;h={name:d.name,channels:[],samplers:[]};for(let s=0;s<d.targetedAnimations.length;++s){const _=d.targetedAnimations[s],g=_.target,m=_.animation;if(l&&!l(m))continue;const T=u.has(g);if(this._IsTransformable(g)||1===g.length&&this._IsTransformable(g[0])){const e=z._DeduceAnimationInfo(_.animation);if(e){const t=this._IsTransformable(g)?g:this._IsTransformable(g[0])?g[0]:null;t&&z._AddAnimation(`${m.name}`,h,t,m,e.dataAccessorType,e.animationChannelTargetPath,r,n,i,o,e.useQuaternion,a,T)}}else if((g instanceof t.MorphTarget||1===g.length&&g[0]instanceof t.MorphTarget)&&z._DeduceAnimationInfo(_.animation)){const s=g instanceof t.MorphTarget?g:g[0];if(s){const t=e.morphTargetManagers.find(e=>{for(let t=0;t<e.numTargets;++t)if(e.getTarget(t)===s)return!0;return!1});if(t){const r=e.meshes.find(e=>e.morphTargetManager===t);r&&(f.has(r)||f.set(r,new Map),null===(c=f.get(r))||void 0===c||c.set(s,m),x.add(r),p.set(r,m))}}}}x.forEach(e=>{const s=e.morphTargetManager;let u=null;const l=[],c=p.get(e).getKeys(),x=c.length;for(let r=0;r<x;++r)for(let n=0;n<s.numTargets;++n){const i=s.getTarget(n),o=f.get(e);if(o){const s=o.get(i);s?(u||(u=new t.Animation(`${d.name}_${e.name}_MorphWeightAnimation`,"influence",s.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,s.loopMode,s.enableBlending)),l.push(s.getKeys()[r])):l.push({frame:d.from+_/x*r,value:i.influence,inTangent:c[0].inTangent?0:void 0,outTangent:c[0].outTangent?0:void 0})}}u.setKeys(l,!0);const g=z._DeduceAnimationInfo(u);g&&z._AddAnimation(`${d.name}_${e.name}_MorphWeightAnimation`,h,e,u,g.dataAccessorType,g.animationChannelTargetPath,r,n,i,o,g.useQuaternion,a,!1,null==s?void 0:s.numTargets)}),h.channels.length&&h.samplers.length&&s.push(h)}}}static _AddAnimation(e,s,r,n,i,o,a,u,l,c,h,f,d,p){const x=z._CreateNodeAnimation(r,n,o,h,f);let _,g,m,T,y,R;if(x){if(p){let e,t=0;const s=[];for(;x.inputs.length>0;)e=x.inputs.shift(),t%p==0&&s.push(e),t++;x.inputs=s}const e=a.get(r),n=new Float32Array(x.inputs);_=u.createBufferView(n),g=u.createAccessor(_,"SCALAR",5126,x.inputs.length,void 0,{min:[x.inputsMin],max:[x.inputsMax]}),c.push(g),m=c.length-1;const l=new t.Quaternion,h=new t.Vector3,f=new t.Vector3,M=r instanceof t.Camera,A=b(i),w=new Float32Array(x.outputs.length*A);x.outputs.forEach(function(e,s){let r=e;switch(o){case"translation":d&&(t.Vector3.FromArrayToRef(e,0,f),C(f),f.toArray(r));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,l):(r=new Array(4),t.Vector3.FromArrayToRef(e,0,h),t.Quaternion.FromEulerVectorToRef(h,l)),d&&(V(l),M&&S(l)),l.toArray(r)}w.set(r,s*A)}),_=u.createBufferView(w),g=u.createAccessor(_,i,5126,x.outputs.length),c.push(g),T=c.length-1,y={interpolation:x.samplerInterpolation,input:m,output:T},s.samplers.push(y),R={sampler:s.samplers.length-1,target:{node:e,path:o}},s.channels.push(R)}}static _CreateBakedAnimation(e,s,r,n,i,o,a,u,l,c,h){let f;const d=t.Quaternion.Identity();let p,x,_,g,m,T=null,y=null;c.min=t.Tools.FloatRound(n/o);const R=s.getKeys();for(let n=0,c=R.length;n<c;++n){if(x=R[n],n+1<c)if(_=R[n+1],x.value.equals&&x.value.equals(_.value)||x.value===_.value){if(0!==n)continue;m=x.frame}else m=_.frame;else{if(g=R[n-1],x.value.equals&&x.value.equals(g.value)||x.value===g.value)continue;m=i}if(m)for(let n=x.frame;n<=m;n+=a){if(p=t.Tools.FloatRound(n/o),p===T)continue;T=p,y=p;const i={key:0,repeatCount:0,loopMode:s.loopMode};f=s._interpolate(n,i),z._SetInterpolatedValue(e,f,p,s,r,d,u,l,h)}}y&&(c.max=y)}static _ConvertFactorToVector3OrQuaternion(e,s,r,n,i){const o=z._GetBasePositionRotationOrScale(s,n,i),a=r.targetProperty.split("."),u=a?a[1]:"",l=i?t.Quaternion.FromArray(o).normalize():t.Vector3.FromArray(o);switch(u){case"x":case"y":case"z":l[u]=e;break;case"w":l.w=e;break;default:t.Tools.Error(`glTFAnimation: Unsupported component name "${u}"!`)}return l}static _SetInterpolatedValue(e,s,r,n,i,o,a,u,l){let c;a.push(r),"weights"!==i?(n.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(s=this._ConvertFactorToVector3OrQuaternion(s,e,n,i,l)),"rotation"===i?(l?o=s:(c=s,t.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,o)),u.push(o.asArray())):(c=s,u.push(c.asArray()))):u.push([s])}static _CreateLinearOrStepAnimation(e,t,s,r,n,i){for(const o of t.getKeys())r.push(o.frame/t.framePerSecond),z._AddKeyframeValue(o,t,n,s,e,i)}static _CreateCubicSplineAnimation(e,t,s,r,n,i){t.getKeys().forEach(function(o){r.push(o.frame/t.framePerSecond),z._AddSplineTangent(L.INTANGENT,n,s,"CUBICSPLINE",o,i),z._AddKeyframeValue(o,t,n,s,e,i),z._AddSplineTangent(L.OUTTANGENT,n,s,"CUBICSPLINE",o,i)})}static _GetBasePositionRotationOrScale(e,s,r){let n;if("rotation"===s)if(r){const s=e.rotationQuaternion;n=(null!=s?s:t.Quaternion.Identity()).asArray()}else{const s=e.rotation;n=(null!=s?s:t.Vector3.Zero()).asArray()}else if("translation"===s){const s=e.position;n=(null!=s?s:t.Vector3.Zero()).asArray()}else{const s=e.scaling;n=(null!=s?s:t.Vector3.One()).asArray()}return n}static _AddKeyframeValue(e,s,r,n,i,o){let a;const u=s.dataType;if(u===t.Animation.ANIMATIONTYPE_VECTOR3){let s=e.value.asArray();if("rotation"===n){const e=t.Vector3.FromArray(s);s=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}r.push(s)}else if(u===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,i,s,n,o),a){if("rotation"===n){const e=o?a:t.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();r.push(e.asArray())}r.push(a.asArray())}}else u===t.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")}static _DeduceInterpolation(e,t,s){let r,n,i=!1;if("rotation"===t&&!s)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(let t=0,s=e.length;t<s;++t)if(n=e[t],n.inTangent||n.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||n.interpolation&&1===n.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=n.interpolation&&1===n.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}}static _AddSplineTangent(e,s,r,n,i,o){let a;const u=e===L.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(u)if(o)a=u.asArray();else{const e=u;a=t.Quaternion.RotationYawPitchRoll(e.y,e.x,e.z).asArray()}else a=[0,0,0,0];else a="weights"===r?u?[u]:[0]:u?u.asArray():[0,0,0];s.push(a)}}static _CalculateMinMaxKeyFrames(e){let t=1/0,s=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),s=Math.max(s,e.frame)}),{min:t,max:s}}}function k(e,s,r,n,i,o){const a={attributes:{},influence:e.influence,name:e.name},u=s.geometry;if(!u)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;const l=o?-1:1,c=t.Vector3.Zero();let h,f;if(e.hasPositions){const n=e.getPositions(),o=u.getVerticesData(t.VertexBuffer.PositionKind);if(o){const e=new Float32Array(o.length),s=[1/0,1/0,1/0],u=[-1/0,-1/0,-1/0];f=o.length/3,h=0;for(let r=h;r<f;++r){const i=t.Vector3.FromArray(o,3*r);t.Vector3.FromArray(n,3*r).subtractToRef(i,c),c.x*=l,s[0]=Math.min(s[0],c.x),u[0]=Math.max(u[0],c.x),s[1]=Math.min(s[1],c.y),u[1]=Math.max(u[1],c.y),s[2]=Math.min(s[2],c.z),u[2]=Math.max(u[2],c.z),e[3*r]=c.x,e[3*r+1]=c.y,e[3*r+2]=c.z}const d=r.createBufferView(e,12),p=r.createAccessor(d,"VEC3",5126,n.length/3,0,{min:s,max:u});i.push(p),a.attributes.POSITION=i.length-1}else t.Tools.Warn(`Morph target positions for mesh ${s.name} were not exported. Mesh does not have position vertex data`)}if(e.hasNormals){const n=e.getNormals(),o=u.getVerticesData(t.VertexBuffer.NormalKind);if(o){const e=new Float32Array(o.length);f=o.length/3,h=0;for(let s=h;s<f;++s){const r=t.Vector3.FromArray(o,3*s).normalize();t.Vector3.FromArray(n,3*s).normalize().subtractToRef(r,c),e[3*s]=c.x*l,e[3*s+1]=c.y,e[3*s+2]=c.z}const s=r.createBufferView(e,12),u=r.createAccessor(s,"VEC3",5126,n.length/3,0);i.push(u),a.attributes.NORMAL=i.length-1}else t.Tools.Warn(`Morph target normals for mesh ${s.name} were not exported. Mesh does not have normals vertex data`)}if(e.hasTangents){const n=e.getTangents(),o=u.getVerticesData(t.VertexBuffer.TangentKind);if(o){f=o.length/4;const e=new Float32Array(3*f);h=0;for(let s=h;s<f;++s){const r=t.Vector3.FromArray(o,4*s);v(r);const i=t.Vector3.FromArray(n,3*s);v(i),i.subtractToRef(r,c),e[3*s]=c.x*l,e[3*s+1]=c.y,e[3*s+2]=c.z}const s=r.createBufferView(e,12),u=r.createAccessor(s,"VEC3",5126,f,0);i.push(u),a.attributes.TANGENT=i.length-1}else t.Tools.Warn(`Morph target tangents for mesh ${s.name} were not exported. Mesh does not have tangents vertex data`)}if(e.hasColors){const n=e.getColors(),o=u.getVerticesData(t.VertexBuffer.ColorKind),l=u.getVertexBuffer(t.VertexBuffer.ColorKind);if(o&&l){const e=l.getSize();f=o.length/e;const s=new Float32Array(f*e);h=0;for(let r=h;r<f;++r)if(3===e){const i=t.Vector3.FromArray(o,r*e);t.Vector3.FromArray(n,r*e).subtractToRef(i,c),s[3*r]=c.x,s[3*r+1]=c.y,s[3*r+2]=c.z}else if(4===e){const i=new t.Vector4,a=t.Vector4.FromArray(o,r*e);t.Vector4.FromArray(n,r*e).subtractToRef(a,i),s[4*r]=i.x,s[4*r+1]=i.y,s[4*r+2]=i.z,s[4*r+3]=i.w}else t.Tools.Warn(`Unsupported number of components for color attribute: ${e}`);const u=r.createBufferView(s,4*e),d=r.createAccessor(u,3===e?"VEC3":"VEC4",5126,f,0);i.push(d),a.attributes.COLOR_0=i.length-1}else t.Tools.Warn(`Morph target colors for mesh ${s.name} were not exported. Mesh does not have colors vertex data`)}return a}class G{constructor(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}getIndicesAccessor(e,t,s,r,n){var i,o,a,u;return null===(u=null===(a=null===(o=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===o?void 0:o.get(s))||void 0===a?void 0:a.get(r))||void 0===u?void 0:u.get(n)}setIndicesAccessor(e,t,s,r,n,i){let o=this._indicesAccessorMap.get(e);o||(o=new Map,this._indicesAccessorMap.set(e,o));let a=o.get(t);a||(a=new Map,o.set(t,a));let u=a.get(s);u||(u=new Map,a.set(s,u));let l=u.get(r);l||(l=new Map,u.set(r,l)),l.set(n,i)}pushExportedNode(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)}getNodesSet(){return this._exportedNodes}getVertexBufferView(e){return this._vertexBufferViewMap.get(e)}setVertexBufferView(e,t){this._vertexBufferViewMap.set(e,t)}setRemappedBufferView(e,t,s){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,s)}getRemappedBufferView(e,t){var s;return null===(s=this._remappedBufferView.get(e))||void 0===s?void 0:s.get(t)}getVertexAccessor(e,t,s){var r,n;return null===(n=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===n?void 0:n.get(s)}setVertexAccessor(e,t,s,r){let n=this._vertexAccessorMap.get(e);n||(n=new Map,this._vertexAccessorMap.set(e,n));let i=n.get(t);i||(i=new Map,n.set(t,i)),i.set(s,r)}hasVertexColorAlpha(e){return this._vertexMapColorAlpha.get(e)||!1}setHasVertexColorAlpha(e,t){return this._vertexMapColorAlpha.set(e,t)}getMesh(e){return this._meshMap.get(e)}setMesh(e,t){this._meshMap.set(e,t)}bindMorphDataToMesh(e,t){const s=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,s),-1===s.indexOf(t)&&s.push(t)}getMorphTargetsFromMesh(e){return this._meshMorphTargetMap.get(e)}}class D{_ApplyExtension(e,t,s,r){if(s>=t.length)return Promise.resolve(e);const n=r(t[s],e);return n?n.then(e=>i(this,void 0,void 0,function*(){return e?yield this._ApplyExtension(e,t,s+1,r):null})):this._ApplyExtension(e,t,s+1,r)}_ApplyExtensions(e,t){const s=[];for(const e of D._ExtensionNames)s.push(this._extensions[e]);return this._ApplyExtension(e,s,0,t)}_extensionsPostExportNodeAsync(e,t,s,r,n){return this._ApplyExtensions(t,(t,i)=>t.postExportNodeAsync&&t.postExportNodeAsync(e,i,s,r,n,this._bufferManager))}_extensionsPostExportMaterialAsync(e,t,s){return this._ApplyExtensions(t,(t,r)=>t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,s))}_extensionsPostExportMaterialAdditionalTexturesAsync(e,t,s){return i(this,void 0,void 0,function*(){const r=[];return yield Promise.all(D._ExtensionNames.map(n=>i(this,void 0,void 0,function*(){const i=this._extensions[n];if(i.postExportMaterialAdditionalTexturesAsync){const n=yield i.postExportMaterialAdditionalTexturesAsync(e,t,s);r.push(...n)}}))),r})}_extensionsPostExportTextures(e,t,s){for(const r of D._ExtensionNames){const n=this._extensions[r];n.postExportTexture&&n.postExportTexture(e,t,s)}}_extensionsPostExportMeshPrimitive(e){for(const t of D._ExtensionNames){const s=this._extensions[t];s.postExportMeshPrimitive&&s.postExportMeshPrimitive(e,this._bufferManager,this._accessors)}}_extensionsPreGenerateBinaryAsync(){return i(this,void 0,void 0,function*(){for(const e of D._ExtensionNames){const t=this._extensions[e];t.preGenerateBinaryAsync&&(yield t.preGenerateBinaryAsync(this._bufferManager))}})}_forEachExtensions(e){for(const t of D._ExtensionNames){const s=this._extensions[t];s.enabled&&e(s)}}_extensionsOnExporting(){this._forEachExtensions(e=>{var t,s,r;e.wasUsed&&((t=this._glTF).extensionsUsed||(t.extensionsUsed=[]),-1===this._glTF.extensionsUsed.indexOf(e.name)&&this._glTF.extensionsUsed.push(e.name),e.required&&((s=this._glTF).extensionsRequired||(s.extensionsRequired=[]),-1===this._glTF.extensionsRequired.indexOf(e.name)&&this._glTF.extensionsRequired.push(e.name)),(r=this._glTF).extensions||(r.extensions={}),e.onExporting&&e.onExporting())})}_loadExtensions(){for(const e of D._ExtensionNames){const t=D._ExtensionFactories[e](this);this._extensions[e]=t}}constructor(e=t.EngineStore.LastCreatedScene,s){if(this._glTF={asset:{generator:`Babylon.js v${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 _(this),this._extensions={},this._bufferManager=new H,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=Object.assign({shouldExportNode:()=>!0,shouldExportAnimation:()=>!0,metadataSelector: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"},s),this._loadExtensions()}dispose(){for(const e in this._extensions)this._extensions[e].dispose()}get options(){return this._options}static RegisterExtension(e,s,r=100){D.UnregisterExtension(e)&&t.Tools.Warn(`Extension with the name ${e} already exists`),D._ExtensionFactories[e]=s;const n=null!=r?r:0;D._ExtensionOrders[e]=n;let i=D._ExtensionNames.length;for(let e=0;e<D._ExtensionNames.length;e++){const t=D._ExtensionNames[e];if(n<D._ExtensionOrders[t]){i=e;break}}D._ExtensionNames.splice(i,0,e)}static UnregisterExtension(e){if(!D._ExtensionFactories[e])return!1;delete D._ExtensionFactories[e],delete D._ExtensionOrders[e];const t=D._ExtensionNames.indexOf(e);return-1!==t&&D._ExtensionNames.splice(t,1),!0}_generateJSON(e,t,s){const 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"),s?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)}generateGLTFAsync(e){return i(this,void 0,void 0,function*(){const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const s=this._generateJSON(t.byteLength,e,!0),n=new Blob([t],{type:"application/octet-stream"}),i=e+".gltf",o=e+".bin",a=new r;if(a.files[i]=s,a.files[o]=n,this._imageData)for(const e in this._imageData)a.files[e]=this._imageData[e];return a})}_generateBinaryAsync(){return i(this,void 0,void 0,function*(){return yield this._exportSceneAsync(),yield this._extensionsPreGenerateBinaryAsync(),this._bufferManager.generateBinary(this._bufferViews)})}_getPadding(e){const t=e%4;return 0===t?t:4-t}generateGLBAsync(e){return i(this,void 0,void 0,function*(){this._shouldUseGlb=!0;const t=yield this._generateBinaryAsync();this._extensionsOnExporting();const s=this._generateJSON(t.byteLength),n=e+".glb";let i,o=s.length;"undefined"!=typeof TextEncoder&&(i=(new TextEncoder).encode(s),o=i.length);const a=this._getPadding(o),u=this._getPadding(t.byteLength),l=28+o+a+t.byteLength+u,c=new P(l);if(c.writeUInt32(1179937895),c.writeUInt32(2),c.writeUInt32(l),c.writeUInt32(o+a),c.writeUInt32(1313821514),i)c.writeTypedArray(i);else{const e="_".charCodeAt(0);for(let t=0;t<o;++t){const r=s.charCodeAt(t);r!=s.codePointAt(t)?c.writeUInt8(e):c.writeUInt8(r)}}for(let e=0;e<a;++e)c.writeUInt8(32);c.writeUInt32(t.byteLength+u),c.writeUInt32(5130562),c.writeTypedArray(t);for(let e=0;e<u;++e)c.writeUInt8(0);const h=new r;return h.files[n]=new Blob([c.getOutputData()],{type:"application/octet-stream"}),h})}_setNodeTransformation(e,s,r){var n;if(s.getPivotPoint().equalsWithEpsilon(T,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!s.position.equalsWithEpsilon(T,t.Epsilon)){const n=t.TmpVectors.Vector3[0].copyFrom(s.position);r&&C(n),e.translation=n.asArray()}s.scaling.equalsWithEpsilon(R,t.Epsilon)||(e.scale=s.scaling.asArray());const i=(null===(n=s.rotationQuaternion)||void 0===n?void 0:n.clone())||t.Quaternion.FromEulerAngles(s.rotation.x,s.rotation.y,s.rotation.z);i.equalsWithEpsilon(y,t.Epsilon)||(r&&V(i),e.rotation=i.normalize().asArray())}_setCameraTransformation(e,s,r){const n=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],o=s.getWorldMatrix();if(s.parent){const e=s.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);o.multiplyToRef(e,t.TmpVectors.Matrix[1]).decompose(void 0,i,n)}else o.decompose(void 0,i,n);n.equalsWithEpsilon(T,t.Epsilon)||(r&&C(n),e.translation=n.asArray()),r&&V(i),this._babylonScene.useRightHandedSystem||S(i),i.equalsWithEpsilon(y,t.Epsilon)||(e.rotation=i.asArray())}_listAvailableCameras(){for(const e of this._babylonScene.cameras){const s={type:e.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(s.name=e.name),"perspective"===s.type)s.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===t.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===s.type){const t=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),r=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();s.orthographic={xmag:t,ymag:r,znear:e.minZ,zfar:e.maxZ}}this._camerasMap.set(e,s)}}_exportAndAssignCameras(){const e=Array.from(this._camerasMap.values());for(const t of e){const e=this._nodesCameraMap.get(t);if(void 0!==e){this._cameras.push(t);for(const t of e)t.camera=this._cameras.length-1}}}_listAvailableSkeletons(){for(const e of this._babylonScene.skeletons){if(e.bones.length<=0)continue;const t={joints:[]};this._skinMap.set(e,t)}}_exportAndAssignSkeletons(e){var s;for(const r of this._babylonScene.skeletons){if(r.bones.length<=0)continue;const n=this._skinMap.get(r);if(null==n)continue;const i={};let o=-1;for(let e=0;e<r.bones.length;++e){const t=r.bones[e],n=null!==(s=t.getIndex())&&void 0!==s?s:e;-1!==n&&(i[n]=t,n>o&&(o=n))}const a=[];for(let s=0;s<=o;++s){const r=i[s],o=r.getTransformNode(),u=o?this._nodeMap.get(o):void 0;if(void 0===u){t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.");continue}n.joints.push(u);const l=r.getAbsoluteInverseBindMatrix().clone();e.has(o)&&I(l),a.push(l)}const u=this._nodesSkinMap.get(n);if(n.joints.length>0&&void 0!==u){const e=new Float32Array(16*a.length);a.forEach((t,s)=>{e.set(t.m,16*s)});const t=this._bufferManager.createBufferView(e);this._accessors.push(this._bufferManager.createAccessor(t,"MAT4",5126,a.length)),n.inverseBindMatrices=this._accessors.length-1,this._skins.push(n);const s=this._skins.length-1;for(const e of u)e.skin=s}}}_exportSceneAsync(){return i(this,void 0,void 0,function*(){const e={nodes:[]};if(this._babylonScene.metadata){const t=this._options.metadataSelector(this._babylonScene.metadata);t&&(e.extras=t)}const s=new Array,r=new Array,n=new Array;let i;if(this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(const e of this._babylonScene.animationGroups)for(const s of e.targetedAnimations){const e=s.target;e instanceof t.TransformNode&&!e.parent&&(null!=i?i:i=new Set).add(e)}for(const e of this._babylonScene.rootNodes){const t=e.animations,o=!!t&&t.length>0||(null==i?void 0:i.has(e));this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&m(e,this._babylonScene.useRightHandedSystem)&&!o?n.push(...e.getChildren()):this._babylonScene.useRightHandedSystem?s.push(e):r.push(e)}this._listAvailableCameras(),this._listAvailableSkeletons();const o=new G(!0,!1);e.nodes.push(...yield this._exportNodesAsync(r,o));const a=new G(!1,!1);e.nodes.push(...yield this._exportNodesAsync(s,a));const u=new G(!1,!0);e.nodes.push(...yield this._exportNodesAsync(n,u)),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(o.getNodesSet()),this._babylonScene.animationGroups.length&&z._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,o.getNodesSet(),this._options.shouldExportAnimation)})}_shouldExportNode(e){let t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t}_exportNodesAsync(e,t){return i(this,void 0,void 0,function*(){const s=new Array;this._exportBuffers(e,t);for(const r of e)yield this._exportNodeAsync(r,s,t);return s})}_collectBuffers(e,s,r,n,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){const t=e.geometry.getVertexBuffers();if(t)for(const n in t){if(!E(n))continue;const o=t[n];i.setHasVertexColorAlpha(o,e.hasVertexAlpha);const a=o._buffer,u=s.get(a)||[];s.set(a,u),-1===u.indexOf(o)&&u.push(o);const l=r.get(o)||[];r.set(o,l),-1===l.indexOf(e)&&l.push(e)}const o=e.morphTargetManager;if(o)for(let t=0;t<o.numTargets;t++){const s=o.getTarget(t),r=n.get(s)||[];n.set(s,r),-1===r.indexOf(e)&&r.push(e)}}for(const t of e.getChildren())this._collectBuffers(t,s,r,n,i)}_exportBuffers(e,s){const r=new Map,n=new Map,i=new Map;for(const t of e)this._collectBuffers(t,r,n,i,s);const o=Array.from(r.keys());for(const e of o){const i=e.getData();if(!i)throw new Error("Buffer data is not available");const o=r.get(e);if(!o)continue;const a=o[0].byteStride;if(o.some(e=>e.byteStride!==a))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");const u=N(i).slice();for(const e of o){const s=n.get(e),{byteOffset:r,byteStride:i,componentCount:o,type:a,count:l,normalized:c,kind:h}=A(e,s);switch(h){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{const t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){const s=1/t;e[0]*=s,e[1]*=s,e[2]*=s}});break;case t.VertexBuffer.ColorKind:{const e=s.filter(e=>e.material instanceof t.StandardMaterial||null==e.material).length;if(0==e)break;if(e!=s.length){t.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}a==t.VertexBuffer.UNSIGNED_BYTE&&t.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");const n=new t.Color3,h=new t.Color4,f=this._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{3===e.length?(n.fromArray(e,0),n.toLinearSpaceToRef(n,f),n.toArray(e,0)):(h.fromArray(e,0),h.toLinearSpaceToRef(h,f),h.toArray(e,0))})}}}if(s.convertToRightHanded){for(const e of o){const s=n.get(e),{byteOffset:r,byteStride:i,componentCount:o,type:a,count:l,normalized:c,kind:h}=A(e,s);switch(h){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,r,i,o,a,l,c,e=>{e[0]=-e[0]})}}s.convertedToRightHandedBuffers.set(e,u)}const l=this._bufferManager.createBufferView(u,a);s.setVertexBufferView(e,l);const c=new Map;for(const e of o){const s=n.get(e),{kind:r,totalVertices:i}=A(e,s);switch(r){case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:if(e.type==t.VertexBuffer.FLOAT){const t=e.getFloatData(i);null!==t&&c.set(e,t)}}}0!==c.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.");const h=Array.from(c.keys());for(const t of h){const r=c.get(t);if(!r)continue;const n=w(r),i=new(n?Uint16Array:Uint8Array)(r.length);for(let e=0;e<r.length;e++)i[e]=r[e];const o=this._bufferManager.createBufferView(i,4*(n?2:1));s.setRemappedBufferView(e,t,o)}}const a=Array.from(i.keys());for(const e of a){const t=i.get(e);if(!t)continue;const r=k(e,t[0],this._bufferManager,this._bufferViews,this._accessors,s.convertToRightHanded);for(const e of t)s.bindMorphDataToMesh(e,r)}}_exportNodeAsync(e,t,s){return i(this,void 0,void 0,function*(){let r=this._nodeMap.get(e);if(void 0!==r)return void(t.includes(r)||t.push(r));const n=yield this._createNodeAsync(e,s);if(n){r=this._nodes.length,this._nodes.push(n),this._nodeMap.set(e,r),s.pushExportedNode(e),t.push(r);const i={name:"runtime animations",channels:[],samplers:[]},o=[];this._babylonScene.animationGroups.length||(z._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,s.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&z._CreateNodeAnimationFromNodeAnimations(e,i,o,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,s.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),o.forEach(e=>{e.channels.length&&e.samplers.length&&this._animations.push(e)})}const i=n?[]:t;for(const t of e.getChildren())yield this._exportNodeAsync(t,i,s);n&&i.length&&(n.children=i)})}_createNodeAsync(e,s){return i(this,void 0,void 0,function*(){var r,n,i;if(!this._shouldExportNode(e))return null;const o={};if(e.name&&(o.name=e.name),e.metadata){const t=this._options.metadataSelector(e.metadata);t&&(o.extras=t)}if(e instanceof t.TransformNode&&(this._setNodeTransformation(o,e,s.convertToRightHanded),e instanceof t.AbstractMesh)){const n=e instanceof t.InstancedMesh?e.sourceMesh:e;if(n.subMeshes&&n.subMeshes.length>0&&(o.mesh=yield this._exportMeshAsync(n,s)),e.skeleton){const t=this._skinMap.get(e.skeleton);void 0!==t&&(void 0===this._nodesSkinMap.get(t)&&this._nodesSkinMap.set(t,[]),null===(r=this._nodesSkinMap.get(t))||void 0===r||r.push(o))}}if(e instanceof t.TargetCamera){const t=this._camerasMap.get(e);if(t){void 0===this._nodesCameraMap.get(t)&&this._nodesCameraMap.set(t,[]),this._setCameraTransformation(o,e,s.convertToRightHanded);const r=e.parent;if(null!==r&&B(e,r)){const e=this._nodeMap.get(r);if(void 0!==e){const s=this._nodes[e];return F(o,s),null===(n=this._nodesCameraMap.get(t))||void 0===n||n.push(s),null}}null===(i=this._nodesCameraMap.get(t))||void 0===i||i.push(o)}}return(yield this._extensionsPostExportNodeAsync("exportNodeAsync",o,e,this._nodeMap,s.convertToRightHanded))?o:(t.Logger.Warn(`Not exporting node ${e.name}`),null)})}_exportIndices(e,s,r,n,i,o,a,u,l){let c=null;l.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: ${e}`)}(o);const h=a!==t.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case t.Material.TriangleFillMode:case t.Material.TriangleStripDrawMode:case t.Material.TriangleFanDrawMode:return!0}return!1}(o);if(h){if(o===t.Material.TriangleStripDrawMode||o===t.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");const a=s?new Uint32Array(n):new Uint16Array(n);if(e)for(let t=0;t+2<n;t+=3)a[t]=e[r+t]+i,a[t+1]=e[r+t+2]+i,a[t+2]=e[r+t+1]+i;else for(let e=0;e+2<n;e+=3)a[e]=e,a[e+1]=e+2,a[e+2]=e+1;c=a}else if(e&&0!==i){const t=s?new Uint32Array(n):new Uint16Array(n);for(let s=0;s<n;s++)t[s]=e[r+s]+i;c=t}else e&&(c=function(e,t,s,r){let n=e;return 0===t&&s===e.length||(n=Array.isArray(e)?e.slice(t,t+s):e.subarray(t,t+s)),n instanceof Int32Array?new Uint32Array(n.buffer,n.byteOffset,n.length):Array.isArray(n)?r?new Uint32Array(n):new Uint16Array(n):n}(e,r,n,s));if(c){let t=u.getIndicesAccessor(e,r,n,i,h);if(void 0===t){const o=this._bufferManager.createBufferView(c),a=s?5125:5123;this._accessors.push(this._bufferManager.createAccessor(o,"SCALAR",a,n,0)),t=this._accessors.length-1,u.setIndicesAccessor(e,r,n,i,h,t)}l.indices=t}}_exportVertexBuffer(e,s,r,n,i,o){const a=e.getKind();if(!E(a))return;if(a.startsWith("uv")&&!this._options.exportUnusedUVs&&(!s||!this._materialNeedsUVsSet.has(s)))return;let u=i.getVertexAccessor(e,r,n);if(void 0===u){const s=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),o=a===t.VertexBuffer.PositionKind?function(e,s,r,n){const{byteOffset:i,byteStride:o,type:a,normalized:u}=s,l=s.getSize(),c=new Array(l).fill(1/0),h=new Array(l).fill(-1/0);return t.EnumerateFloatValues(e,i+r*o,o,l,a,n*l,u,e=>{for(let t=0;t<l;t++)c[t]=Math.min(c[t],e[t]),h[t]=Math.max(h[t],e[t])}),{min:c,max:h}}(s,e,r,n):void 0,l=(a===t.VertexBuffer.MatricesIndicesKind||a===t.VertexBuffer.MatricesIndicesExtraKind)&&e.type===t.VertexBuffer.FLOAT,c=l?t.VertexBuffer.UNSIGNED_BYTE:e.type,h=l?void 0:e.normalized,f=l?i.getRemappedBufferView(e._buffer,e):i.getVertexBufferView(e._buffer),d=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(f,function(e,s){if(e==t.VertexBuffer.ColorKind)return s?"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 ${e}`)}(a,i.hasVertexColorAlpha(e)),c,n,d,o,h)),u=this._accessors.length-1,i.setVertexAccessor(e,r,n,u)}o.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: ${e}`)}(a)]=u}_exportMaterialAsync(e,s,r,n){return i(this,void 0,void 0,function*(){let i=this._materialMap.get(e);if(void 0===i){const n=s&&Object.keys(s).some(e=>e.startsWith("uv"));if((e=e instanceof t.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof t.PBRBaseMaterial)i=yield this._materialExporter.exportPBRMaterialAsync(e,n);else if(e instanceof t.StandardMaterial)i=yield this._materialExporter.exportStandardMaterialAsync(e,n);else{if(!(e instanceof t.OpenPBRMaterial))return void t.Logger.Warn(`Unsupported material '${e.name}' with type ${e.getClassName()}`);i=yield this._materialExporter.exportOpenPBRMaterialAsync(e,n)}this._materialMap.set(e,i)}n.material=i})}_exportMeshAsync(e,s){return i(this,void 0,void 0,function*(){var r,n,i,o,a,u;let l=s.getMesh(e);if(void 0!==l)return l;const c={primitives:[]};l=this._meshes.length,this._meshes.push(c),s.setMesh(e,l);const h=e.isUnIndexed?null:e.getIndices(),f=null===(r=e.geometry)||void 0===r?void 0:r.getVertexBuffers(),d=s.getMorphTargetsFromMesh(e),p=e instanceof t.LinesMesh,x=e instanceof t.GreasedLineBaseMesh,_=e.subMeshes;if(f&&_&&_.length>0)for(const r of _){const l={attributes:{}},_=r.getMaterial()||this._babylonScene.defaultMaterial;if(x){const s={name:_.name},r=e,u=t.Color3.White(),c=null!==(i=null===(n=r.material)||void 0===n?void 0:n.alpha)&&void 0!==i?i:1,h=null!==(a=null===(o=r.greasedLineMaterial)||void 0===o?void 0:o.color)&&void 0!==a?a:u;(!h.equalsWithEpsilon(u,t.Epsilon)||c<1)&&(s.pbrMetallicRoughness={baseColorFactor:[...h.asArray(),c]}),this._materials.push(s),l.material=this._materials.length-1}else if(p){const s={name:_.name},r=e;(!r.color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||r.alpha<1)&&(s.pbrMetallicRoughness={baseColorFactor:[...r.color.asArray(),r.alpha]}),this._materials.push(s),l.material=this._materials.length-1}else yield this._exportMaterialAsync(_,f,r,l);const g=p||x?t.Material.LineListDrawMode:null!==(u=e.overrideRenderingFillMode)&&void 0!==u?u:_.fillMode;let m=_._getEffectiveOrientation(e);s.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(m=m===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(h,h?t.AreIndices32Bits(h,r.indexCount,r.indexStart,r.verticesStart):r.verticesCount>65535,h?r.indexStart:r.verticesStart,h?r.indexCount:r.verticesCount,-r.verticesStart,g,m,s,l);for(const e of Object.values(f))this._exportVertexBuffer(e,_,r.verticesStart,r.verticesCount,s,l);if(d){l.targets=[];for(const e of d)l.targets.push(e.attributes)}c.primitives.push(l),this._extensionsPostExportMeshPrimitive(l)}if(d){c.weights=[],c.extras||(c.extras={}),c.extras.targetNames=[];for(const e of d)c.weights.push(e.influence),c.extras.targetNames.push(e.name)}return l})}}D._ExtensionNames=new Array,D._ExtensionFactories={},D._ExtensionOrders={};class q{static GLTFAsync(e,t,s){return i(this,void 0,void 0,function*(){s&&s.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const r=new D(e,s),n=yield r.generateGLTFAsync(t.replace(/\.[^/.]+$/,""));return r.dispose(),n})}static GLBAsync(e,t,s){return i(this,void 0,void 0,function*(){s&&s.exportWithoutWaitingForScene||(yield e.whenReadyAsync());const r=new D(e,s),n=yield r.generateGLBAsync(t.replace(/\.[^/.]+$/,""));return r.dispose(),n})}}var $={__proto__:null,GLTF2Export:q};const X="EXT_mesh_gpu_instancing";function Q(e,t){const s=new Float32Array(3*t);for(let r=0;r<t;r++)s[3*r+0]=e[4*r+0],s[3*r+1]=e[4*r+1],s[3*r+2]=e[4*r+2];return s}class j{constructor(e){this.name=X,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportNodeAsync(e,s,r,n,o,a){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i;if(s&&r instanceof t.Mesh&&r.hasThinInstances&&this._exporter){this._wasUsed=!0;const e=t.Vector3.Zero(),u=t.Quaternion.Identity(),l=t.Vector3.One(),c=r.thinInstanceGetWorldMatrices(),h=t.TmpVectors.Vector3[2],f=t.TmpVectors.Quaternion[1],d=t.TmpVectors.Vector3[3];let p=!1,x=!1,_=!1;const g=new Float32Array(3*r.thinInstanceCount),m=new Float32Array(4*r.thinInstanceCount),T=new Float32Array(3*r.thinInstanceCount);let y=0;for(const t of c)t.decompose(d,f,h),o&&(C(h),V(f)),g.set(h.asArray(),3*y),m.set(f.normalize().asArray(),4*y),T.set(d.asArray(),3*y),p=p||!h.equalsWithEpsilon(e),x=x||!f.equalsWithEpsilon(u),_=_||!d.equalsWithEpsilon(l),y++;const R={attributes:{}};p&&(R.attributes.TRANSLATION=this._buildAccessor(g,"VEC3",r.thinInstanceCount,a)),x&&(R.attributes.ROTATION=this._buildAccessor(m,"VEC4",r.thinInstanceCount,a)),_&&(R.attributes.SCALE=this._buildAccessor(T,"VEC3",r.thinInstanceCount,a));let M=null===(i=null===(n=r._userThinInstanceBuffersStorage)||void 0===n?void 0:n.data)||void 0===i?void 0:i.instanceColor;if(M){const e=r.thinInstanceCount,s="VEC3";r.hasVertexAlpha&&M.length===4*e?(this._instanceColorWarned||(t.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),this._instanceColorWarned=!0),M=Q(M,e)):M.length===4*e&&(M=Q(M,e)),M.length===3*e&&(R.attributes._COLOR_0=this._buildAccessor(M,s,e,a))}s.extensions=s.extensions||{},s.extensions[X]=R}e(s)})})}_buildAccessor(e,t,s,r){const n=r.createBufferView(e),i=r.createAccessor(n,t,5126,s);return this._exporter._accessors.push(i),this._exporter._accessors.length-1}}let Y=!1;function Z(){Y||(Y=!0,D.RegisterExtension(X,e=>new j(e)))}Z();const J="KHR_draco_mesh_compression";function ee(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}class te{get wasUsed(){return this._wasUsed}constructor(e){this.name=J,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}dispose(){}postExportMeshPrimitive(e,s,r){if(!this.enabled)return;if(4!==e.mode&&5!==e.mode)return void t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".");const n=[],i=[];let o=null;if(void 0!==e.indices){const t=r[e.indices],a=s.getBufferView(t);o=s.getData(a).slice(),n.push(a),i.push(t)}const a=[];for(const[o,u]of Object.entries(e.attributes)){const e=r[u],l=s.getBufferView(e),c=b(e.type),h=t.GetTypedArrayData(s.getData(l),c,e.componentType,e.byteOffset||0,l.byteStride||t.GetTypeByteLength(e.componentType)*c,e.count,!0);a.push({kind:o,dracoName:ee(o),size:b(e.type),data:h}),n.push(l),i.push(e)}const u={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},l=t.DracoEncoder.Default._encodeAsync(a,o,u).then(t=>{const r={bufferView:-1,attributes:t.attributeIds},o=s.createBufferView(t.data);s.setBufferView(r,o);for(const e of n)this._bufferViewsUsed.add(e);for(const e of i)this._accessorsUsed.add(e);e.extensions||(e.extensions={}),e.extensions[J]=r}).catch(e=>{t.Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. "+e.message)});this._encodePromises.push(l),this._wasUsed=!0}preGenerateBinaryAsync(e){return i(this,void 0,void 0,function*(){this.enabled&&(yield Promise.all(this._encodePromises),this._bufferViewsUsed.forEach(t=>{e.getPropertiesWithBufferView(t).every(e=>this._accessorsUsed.has(e))&&e.removeBufferView(t)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear())})}}let se=!1;function re(){se||(se=!0,D.RegisterExtension(J,e=>new te(e)))}re();const ne="KHR_lights_punctual",ie={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},oe={innerConeAngle:0,outerConeAngle:Math.PI/4},ae=t.Vector3.Backward();class ue{constructor(e){this.name=ne,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[ne]=this._lights}postExportNodeAsync(e,s,r,n,o){return i(this,void 0,void 0,function*(){return yield new Promise(i=>{if(!(r instanceof t.Light))return void i(s);const a=r.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(a&&r instanceof t.ShadowLight))return t.Logger.Warn(`${e}: Light ${r.name} is not supported in ${ne}`),void i(s);if(r.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${r.name} does not match the ${ne} specification!`),!r.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(r.position);o&&C(e),s.translation=e.asArray()}if("point"!==a){const e=r.direction.normalizeToRef(t.TmpVectors.Vector3[0]);o&&C(e);const n=t.Quaternion.FromUnitVectorsToRef(ae,e,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(n)||(s.rotation=n.asArray())}const u={type:a,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(U(u,ie),"spot"===a){const e=r;u.spot={innerConeAngle:e.innerAngle/2,outerConeAngle:e.angle/2},U(u.spot,oe)}this._lights||(this._lights={lights:[]}),this._lights.lights.push(u);const l={light:this._lights.lights.length-1},c=r.parent;if(c&&B(r,c)){const e=n.get(c);if(e){const t=this._exporter._nodes[e];return F(s,t),t.extensions||(t.extensions={}),t.extensions[ne]=l,void i(null)}}s.extensions||(s.extensions={}),s.extensions[ne]=l,i(s)})})}}let le=!1;function ce(){le||(le=!0,D.RegisterExtension(ne,e=>new ue(e)))}ce();const he="EXT_lights_area",fe={name:"",color:[1,1,1],intensity:1,size:1},de={aspect:1},pe=t.Vector3.Backward();class xe{constructor(e){this.name=he,this.enabled=!0,this.required=!1,this._exporter=e}dispose(){this._lights=null}get wasUsed(){return!!this._lights}onExporting(){this._exporter._glTF.extensions[he]=this._lights}postExportNodeAsync(e,s,r,n,o){return i(this,void 0,void 0,function*(){return yield new Promise(i=>{if(!(r instanceof t.Light))return void i(s);const a=r.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!a)return t.Logger.Warn(`${e}: Light ${r.name} is not supported in ${he}`),void i(s);const u=r;if(u.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn(`${e}: Light falloff for ${r.name} does not match the ${he} specification!`),!u.position.equalsToFloats(0,0,0)){const e=t.TmpVectors.Vector3[0].copyFrom(u.position);o&&C(e),s.translation=e.asArray()}const l=t.Vector3.Forward();o&&C(l);const c=t.Quaternion.FromUnitVectorsToRef(pe,l,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(c)||(s.rotation=c.asArray());const h={type:a,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};U(h,fe),h.rect&&U(h.rect,de),this._lights||(this._lights={lights:[]}),this._lights.lights.push(h);const f={light:this._lights.lights.length-1},d=r.parent;if(d&&B(u,d)){const e=n.get(d);if(e){const t=this._exporter._nodes[e];return F(s,t),t.extensions||(t.extensions={}),t.extensions[he]=f,void i(null)}}s.extensions||(s.extensions={}),s.extensions[he]=f,i(s)})})}}let _e=!1;function ge(){_e||(_e=!0,D.RegisterExtension(he,e=>new xe(e)))}ge();const me="KHR_materials_anisotropy";class Te{constructor(e){this.name=me,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.anisotropy.isEnabled&&!r.anisotropy.legacy)return r.anisotropy.texture&&e.push(r.anisotropy.texture),e}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){const s=function(e){const t=e.specularRoughnessAnisotropyTexture,s=e.geometryTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoTangent"}`}(r);if(this._anisoTexturesMap[s])e.push(this._anisoTexturesMap[s]);else{const n=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture;return r||n?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),s):null})}(r);n&&(e.push(n),this._anisoTexturesMap[s]=n)}return e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n;if(r instanceof t.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.anisotropy.texture),n={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=t?t:void 0};null!==n.anisotropyTexture&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[me]=n}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){this._wasUsed=!0,s.extensions=s.extensions||{};let t=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(t=r.baseMetalnessTexture);const i=this._anisoTexturesMap[r.id];if(!t&&!i){let t=r.specularRoughness,n=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){const e=function(e,t){const s=e*e,r=s*Math.sqrt(2/(1+(1-t)*(1-t))),n=(1-t)*r;return{newBaseRoughness:Math.sqrt(n),newAnisotropyStrength:Math.min(Math.sqrt((r-s)/Math.max(1-s,1e-4)),1)}}(r.specularRoughness,r.specularRoughnessAnisotropy);t=e.newBaseRoughness,n=e.newAnisotropyStrength}s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.roughnessFactor=t);const i={anisotropyStrength:n,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return s.extensions[me]=i,e(s)}const o=i?this._exporter._materialExporter.getTextureInfo(i):null,a={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:o||void 0,extensions:{}};r._useGltfStyleAnisotropy||(s.extensions.KHR_materials_openpbr={},(n=this._exporter._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),this._exporter._materialNeedsUVsSet.add(r),s.extensions[me]=a}e(s)})}}let ye=!1;function Re(){ye||(ye=!0,D.RegisterExtension(me,e=>new Te(e)))}Re();const Me="KHR_materials_clearcoat";function Ae(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class be{constructor(e){this.name=Me,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.clearCoat.isEnabled)return 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),e}else if(r instanceof t.OpenPBRMaterial&&r.coatWeight>0){let s=!1;if(r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):s=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):s=!0),s){const s=function(e){const t=e.coatWeightTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture;return`${s}_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture;return r||n?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ae(this._cachedInternalTexturesMap[s],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ae(this._cachedInternalTexturesMap[s],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId])))}return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const n=this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);let i;i=r.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${r.name}`),r.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${r.name}`);const o=this._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=n?n:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=o?o:void 0};null===a.clearcoatTexture&&null===a.clearcoatRoughnessTexture&&null===a.clearcoatRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[Me]=a}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(s);let n,i,o,a;this._wasUsed=!0,s.extensions=s.extensions||{},r.coatWeightTexture&&(n=this._mergedTexturesMap[r.coatWeightTexture.uniqueId],i=this._exporter._materialExporter.getTextureInfo(n)),r.coatRoughnessTexture&&(o=this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],a=this._exporter._materialExporter.getTextureInfo(o)),r.coatColorTexture&&t.Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${r.name}`);const u=this._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),l={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=a?a:void 0,clearcoatNormalTexture:null!=u?u:void 0};null===l.clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[Me]=l}e(s)})}}let we=!1;function Ee(){we||(we=!0,D.RegisterExtension(Me,e=>new be(e)))}Ee();const ve="KHR_materials_coat";function Ce(e){const t=e.coatRoughnessAnisotropyTexture,s=e.geometryCoatTangentTexture;return`${t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength"}_${s&&s.getInternalTexture()?s.getInternalTexture().uniqueId:"NoTangent"}`}function Ie(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class Ve{constructor(e){this.name=ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r.clearCoat.isEnabled)return 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),e}else if(r instanceof t.OpenPBRMaterial&&r.coatWeight>0){let s=!1;if(r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):s=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):s=!0),s){const s=function(e){const t=e.coatWeightTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture;return`${s}_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatWeightTexture,n=e.coatRoughnessTexture;return r||n?(yield t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[s],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[s],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId])))}if(r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatColorTexture&&e.push(r.coatColorTexture),r.coatRoughnessAnisotropy>0){const s=Ce(r);if(this._mergedTexturesMap[s])e.push(this._mergedTexturesMap[s]);else{const n=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture;return r||n?yield t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(n?t.CreateTextureInput(n,0):t.CreateConstantInput(1),n?t.CreateTextureInput(n,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),s):null})}(r);n&&(e.push(n),this._mergedTexturesMap[s]=n)}return e}return e}return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n;if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);let n,i;n=r.clearCoat.useRoughnessFromMainTexture?this._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):this._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&(i=this._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));const o=this._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),a=r.clearCoat.indexOfRefraction,u={coatFactor:r.clearCoat.intensity,coatTexture:null!=t?t:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=n?n:void 0,coatNormalTexture:null!=o?o:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=i?i:void 0,coatIor:1.5!==a?a:void 0};null===u.coatTexture&&null===u.coatRoughnessTexture&&null===u.coatRoughnessTexture&&null===u.coatColorTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[ve]=u}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(s);let t,i,o,a;this._wasUsed=!0,s.extensions=s.extensions||{},r.coatWeightTexture&&(t=this._mergedTexturesMap[r.coatWeightTexture.uniqueId]?this._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,i=this._exporter._materialExporter.getTextureInfo(t)),r.coatRoughnessTexture&&(o=this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,a=this._exporter._materialExporter.getTextureInfo(o));const u=this._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),l=this._exporter._materialExporter.getTextureInfo(r.coatColorTexture),c=r.coatIor,h=r.coatDarkening,f=r.coatRoughnessTexture,d=Ce(r),p=this._mergedTexturesMap[d];let x,_=0,g=0;if(r.coatRoughnessAnisotropy>0){if(f||p){const e=p?this._exporter._materialExporter.getTextureInfo(p):null;_=r.coatRoughnessAnisotropy,g=r.geometryCoatTangentAngle,x=e||void 0}else{let e=r.coatRoughness,t=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){const s=function(e,t){const s=e*e,r=s*Math.sqrt(2/(1+(1-t)*(1-t))),n=(1-t)*r;return{newBaseRoughness:Math.sqrt(n),newAnisotropyStrength:Math.min(Math.sqrt((r-s)/Math.max(1-s,1e-4)),1)}}(r.coatRoughness,r.coatRoughnessAnisotropy);e=s.newBaseRoughness,t=s.newAnisotropyStrength}s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.roughnessFactor=e),_=t,g=r.geometryCoatTangentAngle+.5*Math.PI,x=void 0}r._useGltfStyleAnisotropy||(s.extensions.KHR_materials_openpbr={},(n=this._exporter._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}const m={coatFactor:r.coatWeight,coatTexture:null!=i?i:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=a?a:void 0,coatNormalTexture:null!=u?u:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=l?l:void 0,coatIor:1.5!==c?c:void 0,coatDarkeningFactor:1!==h?h:void 0,coatAnisotropyRotation:g,coatAnisotropyStrength:_,coatAnisotropyTexture:x};null===m.coatTexture&&null===m.coatRoughnessTexture&&null===m.coatRoughnessTexture&&null===m.coatAnisotropyTexture&&null===m.coatColorTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[ve]=m}e(s)})}}let Se=!1;function Fe(){Se||(Se=!0,D.RegisterExtension(ve,e=>new Ve(e)))}Fe();const Be="KHR_materials_diffuse_transmission";function Ne(e,s){const r=s.subSurface;let n=null;return r.translucencyIntensityTexture?n=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(n=r.thicknessTexture),n&&!r.useGltfStyleTextures?(t.Logger.Warn(`${e}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${s.name}`,1),null):n}class Ue{constructor(e){this.name=Be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const s=[];if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){const t=Ne(e,r);return t&&s.push(t),r.subSurface.translucencyColorTexture&&s.push(r.subSurface.translucencyColorTexture),s}return s})}_isExtensionEnabled(e){if(e.unlit)return!1;const t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness}postExportMaterialAsync(e,s,r){return new Promise(n=>{var i,o;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const t=r.subSurface,n=Ne(e,r),a=0==t.translucencyIntensity?void 0:t.translucencyIntensity,u=null!==(i=this._exporter._materialExporter.getTextureInfo(n))&&void 0!==i?i:void 0,l=!t.translucencyColor||t.translucencyColor.equalsFloats(1,1,1)?void 0:t.translucencyColor.asArray(),c=null!==(o=this._exporter._materialExporter.getTextureInfo(t.translucencyColorTexture))&&void 0!==o?o:void 0,h={diffuseTransmissionFactor:a,diffuseTransmissionTexture:u,diffuseTransmissionColorFactor:l,diffuseTransmissionColorTexture:c};(u||c)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions=s.extensions||{},s.extensions[Be]=h}n(s)})}}let Oe=!1;function Ke(){Oe||(Oe=!0,D.RegisterExtension(Be,e=>new Ue(e)))}Ke();const Pe="KHR_materials_dispersion";class We{constructor(){this.name=Pe,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}_isExtensionEnabled(e){if(e.unlit)return!1;const t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={dispersion:r.subSurface.dispersion};s.extensions=s.extensions||{},s.extensions[Pe]=e}e(s)})}}let He=!1;function Le(){He||(He=!0,D.RegisterExtension(Pe,()=>new We))}Le();const ze="KHR_materials_emissive_strength";class ke{constructor(){this.name=ze,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{if(!(r instanceof t.PBRMaterial))return e(s);const n=r.emissiveColor.scale(r.emissiveIntensity),i=Math.max(...n.asArray());if(i>1){s.emissiveFactor=n.scale(1/i).asArray(),this._wasUsed=!0;const e={emissiveStrength:i};s.extensions||(s.extensions={}),s.extensions[ze]=e}else s.emissiveFactor=n.asArray();return e(s)})})}}let Ge=!1;function De(){Ge||(Ge=!0,D.RegisterExtension(ze,()=>new ke))}De();const qe="KHR_materials_ior";class $e{constructor(){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}_isExtensionEnabled(e){return!e.unlit&&(e instanceof t.OpenPBRMaterial?1.5!=e.specularIor:e instanceof t.PBRMaterial&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction)}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={ior:r.indexOfRefraction};s.extensions=s.extensions||{},s.extensions[qe]=e}else if(r instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e={ior:r.specularIor};s.extensions=s.extensions||{},s.extensions[qe]=e}e(s)})}}let Xe=!1;function Qe(){Xe||(Xe=!0,D.RegisterExtension(qe,()=>new $e))}Qe();const je="KHR_materials_iridescence";class Ye{constructor(e){this.name=je,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(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),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),e;return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.iridescence.texture),n=this._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture),i={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=n?n:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[je]=i}else if(r instanceof t.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const t=this._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),n=this._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture),i={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=t?t:void 0,iridescenceThicknessTexture:null!=n?n:void 0};null===i.iridescenceTexture&&null===i.iridescenceThicknessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[je]=i}e(s)})}}let Ze=!1;function Je(){Ze||(Ze=!0,D.RegisterExtension(je,e=>new Ye(e)))}Je();const et="KHR_materials_sheen";class tt{constructor(e){this.name=et,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){return r instanceof t.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]})}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i,o,a;if(r instanceof t.PBRMaterial){if(!r.sheen.isEnabled)return void e(s);this._wasUsed=!0,null==s.extensions&&(s.extensions={});const t={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(n=r.sheen.roughness)&&void 0!==n?n:0};null===t.sheenColorTexture&&null===t.sheenRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(t.sheenColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?t.sheenRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(t.sheenRoughnessTexture=null!==(a=this._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),s.extensions[et]=t}e(s)})})}}let st=!1;function rt(){st||(st=!0,D.RegisterExtension(et,e=>new tt(e)))}rt();const nt="KHR_materials_fuzz";function it(e,s){const r=new t.Texture(s.name,s.getScene());return r._texture=e,r.coordinatesIndex=s.coordinatesIndex,s instanceof t.Texture&&(r.uOffset=s.uOffset,r.vOffset=s.vOffset,r.uScale=s.uScale,r.vScale=s.vScale,r.wAng=s.wAng),r.wrapU=s.wrapU,r.wrapV=s.wrapV,r}class ot{constructor(e){this.name=nt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}dispose(){for(const e of Object.keys(this._mergedTexturesMap))this._mergedTexturesMap[e].dispose();this._mergedTexturesMap={};for(const e of Object.keys(this._cachedInternalTexturesMap))this._cachedInternalTexturesMap[e].dispose();this._cachedInternalTexturesMap={}}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){if(r instanceof t.OpenPBRMaterial){const e=[];if(r.fuzzWeight>0){r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture);let s=!1;if(r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):s=!0),r.fuzzColorTexture&&!s&&e.push(r.fuzzColorTexture),s){const s=function(e){const t=e.fuzzColorTexture,s=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",r=e.fuzzRoughnessTexture;return`FuzzColor_${s}_FuzzRoughness_${r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoFuzzRoughness"}`}(r);if(!this._cachedInternalTexturesMap[s]){const e=yield function(e){return i(this,void 0,void 0,function*(){const s=e.getScene(),r=e.fuzzColorTexture,n=e.fuzzRoughnessTexture;return r||n?(yield 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),n?t.CreateTextureInput(n,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),s)).getInternalTexture():null})}(r);e&&(this._cachedInternalTexturesMap[s]=e)}this._cachedInternalTexturesMap[s]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=it(this._cachedInternalTexturesMap[s],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=it(this._cachedInternalTexturesMap[s],r.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId])))}}return e}return[]})}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){return yield new Promise(e=>{var n,i,o;if(r instanceof t.OpenPBRMaterial){if(0==r.fuzzWeight)return void e(s);this._wasUsed=!0,null==s.extensions&&(s.extensions={});const t={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};let a,u;r.fuzzWeightTexture&&(t.fuzzTexture=null!==(n=this._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==n?n:void 0),r.fuzzColorTexture&&(a=this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,t.fuzzColorTexture=null!==(i=this._exporter._materialExporter.getTextureInfo(a))&&void 0!==i?i:void 0),r.fuzzRoughnessTexture&&(u=this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,t.fuzzRoughnessTexture=null!==(o=this._exporter._materialExporter.getTextureInfo(u))&&void 0!==o?o:void 0),null===t.fuzzColorTexture&&null===t.fuzzRoughnessTexture||this._exporter._materialNeedsUVsSet.add(r),s.extensions[nt]=t}e(s)})})}}let at=!1;function ut(){at||(at=!0,D.RegisterExtension(nt,e=>new ot(e)))}ut();const lt="KHR_materials_specular";class ct{constructor(e){this.name=lt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];return r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.reflectanceTexture),e):e})}_isExtensionEnabled(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))}_hasTexturesExtension(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n,i,o,a,u;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0,s.extensions=s.extensions||{};const e=null!==(n=this._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==n?n:void 0,t=null!==(i=this._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==i?i:void 0,o={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:e,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:t};this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[lt]=o}else if(r instanceof t.OpenPBRMaterial){s.extensions=s.extensions||{};const t=null!==(o=this._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==o?o:void 0,n=null!==(a=this._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==a?a:void 0,i=1==r.specularWeight?void 0:r.specularWeight,l=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!n&&!t&&void 0===i&&void 0===l)return e(s);this._wasUsed=!0;const c={specularEdgeColorEnabled:!0},h={specularFactor:i,specularTexture:t,specularColorFactor:l,specularColorTexture:n,extensions:{}};h.extensions.EXT_materials_specular_edge_color=c,(u=this._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&this._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(t||n)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[lt]=h}e(s)})}}let ht=!1;function ft(){ht||(ht=!0,D.RegisterExtension(lt,e=>new ct(e)))}ft();const dt="KHR_materials_transmission";class pt{constructor(e){this.name=dt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.refractionIntensityTexture&&r.subSurface.useGltfStyleTextures&&e.push(r.subSurface.refractionIntensityTexture),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 e})}_isExtensionEnabled(e){if(e instanceof t.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0||e.subsurfaceWeight>0;if(e instanceof t.PBRMaterial&&!e.unlit){const t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||null!=t.refractionIntensityTexture&&t.useGltfStyleTextures}return!1}postExportMaterialAsync(e,s,r){return i(this,void 0,void 0,function*(){if(!this._isExtensionEnabled(r))return s;if(r instanceof t.PBRMaterial){this._wasUsed=!0;const n=r.subSurface,i={transmissionFactor:0===n.refractionIntensity?void 0:n.refractionIntensity};if(n.refractionIntensityTexture)if(n.useGltfStyleTextures){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(n.refractionIntensityTexture);e&&(i.transmissionTexture=e)}else t.Logger.Warn(`${e}: Exporting a subsurface refraction intensity texture without \`useGltfStyleTextures\` is not supported`);s.extensions||(s.extensions={}),s.extensions[dt]=i}else if(r instanceof t.OpenPBRMaterial){this._wasUsed=!0;const e={transmissionFactor:(1-r.transmissionWeight)*r.subsurfaceWeight+r.transmissionWeight};if(r.transmissionWeightTexture){this._exporter._materialNeedsUVsSet.add(r);const t=this._exporter._materialExporter.getTextureInfo(r.transmissionWeightTexture);t&&(e.transmissionTexture=t)}else if(r.subsurfaceWeightTexture){this._exporter._materialNeedsUVsSet.add(r);const t=this._exporter._materialExporter.getTextureInfo(r.subsurfaceWeightTexture);t&&(e.transmissionTexture=t)}if(0==r.transmissionDepth&&(!r.transmissionColor.equals(t.Color3.White())||r.transmissionColorTexture)&&s.pbrMetallicRoughness&&(s.pbrMetallicRoughness.baseColorFactor||(s.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),s.pbrMetallicRoughness.baseColorFactor[0]*=r.transmissionColor.r,s.pbrMetallicRoughness.baseColorFactor[1]*=r.transmissionColor.g,s.pbrMetallicRoughness.baseColorFactor[2]*=r.transmissionColor.b,r.transmissionColorTexture&&!s.pbrMetallicRoughness.baseColorTexture)){const e=this._exporter._materialExporter.getTextureInfo(r.transmissionColorTexture);e&&(s.pbrMetallicRoughness.baseColorTexture=e,this._exporter._materialNeedsUVsSet.add(r))}s.extensions||(s.extensions={}),s.extensions[dt]=e}return s})}}let xt=!1;function _t(){xt||(xt=!0,D.RegisterExtension(dt,e=>new pt(e)))}_t();const gt="KHR_materials_unlit";class mt{constructor(){this.name=gt,this.enabled=!0,this.required=!1,this._wasUsed=!1}get wasUsed(){return this._wasUsed}dispose(){}postExportMaterialAsync(e,s,r){return new Promise(e=>{let n=!1;r instanceof t.PBRMaterial?n=r.unlit:r instanceof t.StandardMaterial&&(n=r.disableLighting),n&&(this._wasUsed=!0,null==s.extensions&&(s.extensions={}),s.extensions[gt]={}),e(s)})}}let Tt=!1;function yt(){Tt||(Tt=!0,D.RegisterExtension(gt,()=>new mt))}yt();const Rt="KHR_materials_volume";class Mt{constructor(e){this.name=Rt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),e}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0||r.subsurfaceWeight>0)&&r.geometryThicknessTexture&&e.push(r.geometryThicknessTexture);return e})}_isExtensionEnabled(e){if(e.unlit)return!1;const s=e.subSurface;return!(!s.isRefractionEnabled&&!s.isTranslucencyEnabled)&&(null!=s.maximumThickness&&0!=s.maximumThickness||null!=s.tintColorAtDistance&&s.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=s.tintColor&&s.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))}_hasTexturesExtension(e){return null!=e.subSurface.thicknessTexture}postExportMaterialAsync(e,s,r){return new Promise(e=>{var n,i;if(r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;const e=r.subSurface,t={thicknessFactor:0==e.maximumThickness?void 0:e.maximumThickness,thicknessTexture:null!==(n=this._exporter._materialExporter.getTextureInfo(e.thicknessTexture))&&void 0!==n?n:void 0,attenuationDistance:e.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:e.tintColorAtDistance,attenuationColor:e.tintColor.equalsFloats(1,1,1)?void 0:e.tintColor.asArray()};this._hasTexturesExtension(r)&&this._exporter._materialNeedsUVsSet.add(r),s.extensions=s.extensions||{},s.extensions[Rt]=t}else if(r instanceof t.OpenPBRMaterial){const e=r.transmissionWeight>0&&!r.geometryThinWalled,n=r.subsurfaceWeight>0&&!r.geometryThinWalled;if(e||n){this._wasUsed=!0;const o=r.geometryThickness,a=null!==(i=this._exporter._materialExporter.getTextureInfo(r.geometryThicknessTexture))&&void 0!==i?i:void 0;let u;a&&this._exporter._materialNeedsUVsSet.add(r);const l=t.Color3.White().asArray();if(e&&r.transmissionDepth>0){const e=1/r.transmissionDepth;let s=new t.Vector3(-Math.log(r.transmissionColor.r)*e,-Math.log(r.transmissionColor.g)*e,-Math.log(r.transmissionColor.b)*e);const n=new t.Vector3(r.transmissionScatter.r*e,r.transmissionScatter.g*e,r.transmissionScatter.b*e),i=s.subtract(n),o=Math.min(i.x,i.y,i.z);o<0&&(i.x=i.x-o,i.y=i.y-o,i.z=i.z-o),s=i.add(n),u=1/Math.max(s.x,s.y,s.z),l[0]=Math.exp(-s.x*u),l[1]=Math.exp(-s.y*u),l[2]=Math.exp(-s.z*u)}else u=Number.MAX_VALUE,l[0]=1,l[1]=1,l[2]=1;let c=1;const h=t.Color3.White().asArray();if(n){const e=r.subsurfaceRadius,s=r.subsurfaceRadiusScale,n=new t.Vector3(s.r,s.g,s.b).multiplyByFloats(e,e,e),i=new t.Vector3(1/Math.max(n.x,1e-6),1/Math.max(n.y,1e-6),1/Math.max(n.z,1e-6));c=1/Math.max(i.x,i.y,i.z),h[0]=Math.exp(-i.x*c),h[1]=Math.exp(-i.y*c),h[2]=Math.exp(-i.z*c)}const f=(1-r.transmissionWeight)*r.subsurfaceWeight,d=f+r.transmissionWeight,p=1/Math.max(d,1e-6),x=r.transmissionWeight*p,_=f*p,g=l.map((e,t)=>e*x+h[t]*_),m={thicknessFactor:o,thicknessTexture:a,attenuationDistance:u*x+c*_,attenuationColor:g};s.extensions=s.extensions||{},s.extensions[Rt]=m}}e(s)})}}let At=!1;function bt(){At||(At=!0,D.RegisterExtension(Rt,e=>new Mt(e)))}bt();const wt="KHR_materials_volume_scatter";class Et{constructor(e){this.name=wt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];return r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionScatterTexture&&e.push(r.transmissionScatterTexture),r.subsurfaceWeight>0&&r.subsurfaceColorTexture&&e.push(r.subsurfaceColorTexture)),e})}_isExtensionEnabled(e){if(e.unlit)return!1;const s=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),r=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!s&&!r)}postExportMaterialAsync(e,s,r){return new Promise(e=>{if(r instanceof t.OpenPBRMaterial&&this._isExtensionEnabled(r)){this._wasUsed=!0;let e=t.Vector3.Zero(),n=0;r.transmissionWeight>0&&(e=function(e){const s=new t.Vector3(Math.sqrt(1-e.x),Math.sqrt(1-e.y),Math.sqrt(1-e.z)),r=new t.Vector3(1,1,1),n=r.subtract(s),i=r.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(s)),o=r.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(s));return n.multiplyInPlace(i).divideInPlace(o)}(new t.Vector3(r.transmissionScatter.r,r.transmissionScatter.g,r.transmissionScatter.b)),n=r.transmissionScatterAnisotropy);const i=t.Vector3.Zero();let o=0;r.subsurfaceWeight>0&&(i.set(r.subsurfaceColor.r,r.subsurfaceColor.g,r.subsurfaceColor.b),o=r.subsurfaceScatterAnisotropy);const a=(1-r.transmissionWeight)*r.subsurfaceWeight,u=a+r.transmissionWeight,l=1/Math.max(u,1e-6),c=r.transmissionWeight*l,h=a*l,f={multiscatterColorFactor:e.multiplyByFloats(c,c,c).addInPlace(i.multiplyByFloats(h,h,h)).asArray(),scatterAnisotropy:n*c+o*h};if(r.subsurfaceWeight>0&&r.subsurfaceColorTexture){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(r.subsurfaceColorTexture);e&&(f.multiscatterColorTexture=e)}else if(r.transmissionWeight>0&&r.transmissionScatterTexture){this._exporter._materialNeedsUVsSet.add(r);const e=this._exporter._materialExporter.getTextureInfo(r.transmissionScatterTexture);e&&(f.multiscatterColorTexture=e)}s.extensions=s.extensions||{},s.extensions[wt]=f}e(s)})}}let vt=!1;function Ct(){vt||(vt=!0,D.RegisterExtension(wt,e=>new Et(e),101))}Ct();const It="KHR_materials_diffuse_roughness";class Vt{constructor(e){this.name=It,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAdditionalTexturesAsync(e,s,r){return i(this,void 0,void 0,function*(){const e=[];if(r instanceof t.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),e}else if(r instanceof t.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),e;return[]})}postExportMaterialAsync(e,s,r){return new Promise(e=>{let n=null,i=null;if(r instanceof t.PBRBaseMaterial?(n=r._baseDiffuseRoughness,i=r._baseDiffuseRoughnessTexture):r instanceof t.OpenPBRMaterial&&(n=r.baseDiffuseRoughness,i=r.baseDiffuseRoughnessTexture),!n)return void e(s);this._wasUsed=!0,s.extensions=s.extensions||{};const o=this._exporter._materialExporter.getTextureInfo(i),a={diffuseRoughnessFactor:n,diffuseRoughnessTexture:null!=o?o:void 0};null!==a.diffuseRoughnessTexture&&this._exporter._materialNeedsUVsSet.add(r),s.extensions[It]=a,e(s)})}}let St=!1;function Ft(){St||(St=!0,D.RegisterExtension(It,e=>new Vt(e)))}Ft();const Bt="KHR_materials_openpbr";class Nt{constructor(){this.name=Bt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportMaterialAsync(e,s,r){return new Promise(e=>{r instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,s.extensions=s.extensions||{},s.extensions[Bt]={}),e(s)})}}let Ut=!1;function Ot(){Ut||(Ut=!0,D.RegisterExtension(Bt,()=>new Nt))}Ot();const Kt="KHR_texture_transform";class Pt{constructor(){this.name=Kt,this.enabled=!0,this.required=!1,this._wasUsed=!1}dispose(){}get wasUsed(){return this._wasUsed}postExportTexture(e,s,r){if(r.getScene()||t.Tools.Warn(`${e}: "scene" is not defined for Babylon texture ${r.name}!`),(0!==r.uAng||0!==r.vAng)&&(t.Tools.Warn(`${e}: Texture ${r.name} with rotation in the u or v axis is not supported in glTF.`),0!==r.uRotationCenter||0!==r.vRotationCenter))return;const n={};let i=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],i=!0),1===r.uScale&&1===r.vScale||(n.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(`${e}: Texture ${r.name} with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ${Kt}.`);t.Tools.Warn(`${e}: Texture ${r.name} with non-origin rotation center will be exported using an adjusted offset with ${Kt}.`),n.offset=function(e){const{uOffset:t,vOffset:s,uRotationCenter:r,vRotationCenter:n,uScale:i,vScale:o,wAng:a}=e,u=Math.cos(a),l=Math.sin(a),c=r*i,h=n*o;return[t+(c*(1-u)+h*l),s+(h*(1-u)-c*l)]}(r)}n.rotation=-r.wAng,i=!0}0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,s.extensions||(s.extensions={}),s.extensions[Kt]=n)}}let Wt=!1;function Ht(){Wt||(Wt=!0,D.RegisterExtension(Kt,()=>new Pt))}Ht();const Lt="KHR_texture_basisu";class zt{get wasUsed(){return this._wasUsed}constructor(e){this.name=Lt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Lt]={source:n},this._wasUsed=!0)}}let kt=!1;function Gt(){kt||(kt=!0,D.RegisterExtension(Lt,e=>new zt(e)))}Gt();const Dt="EXT_texture_webp";class qt{get wasUsed(){return this._wasUsed}constructor(e){this.name=Dt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Dt]={source:n},this._wasUsed=!0)}}let $t=!1;function Xt(){$t||($t=!0,D.RegisterExtension(Dt,e=>new qt(e)))}Xt();const Qt="EXT_texture_avif";class jt{get wasUsed(){return this._wasUsed}constructor(e){this.name=Qt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}dispose(){}postExportTexture(e,s){const r=this._exporter._textures[s.index],n=r.source;if(void 0===n)return;const i=this._exporter._images[n];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[Qt]={source:n},this._wasUsed=!0)}}let Yt=!1;function Zt(){Yt||(Yt=!0,D.RegisterExtension(Qt,e=>new jt(e)))}Zt();var Jt={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:j,EXT_texture_avif:jt,EXT_texture_webp:qt,KHR_draco_mesh_compression:te,KHR_lights_punctual:ue,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:be,KHR_materials_coat:Ve,KHR_materials_diffuse_roughness:Vt,KHR_materials_diffuse_transmission:Ue,KHR_materials_dispersion:We,KHR_materials_emissive_strength:ke,KHR_materials_fuzz:ot,KHR_materials_ior:$e,KHR_materials_iridescence:Ye,KHR_materials_openpbr:Nt,KHR_materials_sheen:tt,KHR_materials_specular:ct,KHR_materials_transmission:pt,KHR_materials_unlit:mt,KHR_materials_volume:Mt,KHR_materials_volume_scatter:Et,KHR_texture_basisu:zt,KHR_texture_transform:Pt,RegisterEXT_lights_area:ge,RegisterEXT_mesh_gpu_instancing:Z,RegisterEXT_texture_avif:Zt,RegisterEXT_texture_webp:Xt,RegisterKHR_draco_mesh_compression:re,RegisterKHR_lights_punctual:ce,RegisterKHR_materials_anisotropy:Re,RegisterKHR_materials_clearcoat:Ee,RegisterKHR_materials_coat:Fe,RegisterKHR_materials_diffuse_roughness:Ft,RegisterKHR_materials_diffuse_transmission:Ke,RegisterKHR_materials_dispersion:Le,RegisterKHR_materials_emissive_strength:De,RegisterKHR_materials_fuzz:ut,RegisterKHR_materials_ior:Qe,RegisterKHR_materials_iridescence:Je,RegisterKHR_materials_openpbr:Ot,RegisterKHR_materials_sheen:rt,RegisterKHR_materials_specular:ft,RegisterKHR_materials_transmission:_t,RegisterKHR_materials_unlit:yt,RegisterKHR_materials_volume:bt,RegisterKHR_materials_volume_scatter:Ct,RegisterKHR_texture_basisu:Gt,RegisterKHR_texture_transform:Ht},es={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:j,EXT_texture_avif:jt,EXT_texture_webp:qt,GLTF2Export:q,GLTFData:r,KHR_draco_mesh_compression:te,KHR_lights_punctual:ue,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:be,KHR_materials_coat:Ve,KHR_materials_diffuse_roughness:Vt,KHR_materials_diffuse_transmission:Ue,KHR_materials_dispersion:We,KHR_materials_emissive_strength:ke,KHR_materials_fuzz:ot,KHR_materials_ior:$e,KHR_materials_iridescence:Ye,KHR_materials_openpbr:Nt,KHR_materials_sheen:tt,KHR_materials_specular:ct,KHR_materials_transmission:pt,KHR_materials_unlit:mt,KHR_materials_volume:Mt,KHR_materials_volume_scatter:Et,KHR_texture_basisu:zt,KHR_texture_transform:Pt,RegisterEXT_lights_area:ge,RegisterEXT_mesh_gpu_instancing:Z,RegisterEXT_texture_avif:Zt,RegisterEXT_texture_webp:Xt,RegisterKHR_draco_mesh_compression:re,RegisterKHR_lights_punctual:ce,RegisterKHR_materials_anisotropy:Re,RegisterKHR_materials_clearcoat:Ee,RegisterKHR_materials_coat:Fe,RegisterKHR_materials_diffuse_roughness:Ft,RegisterKHR_materials_diffuse_transmission:Ke,RegisterKHR_materials_dispersion:Le,RegisterKHR_materials_emissive_strength:De,RegisterKHR_materials_fuzz:ut,RegisterKHR_materials_ior:Qe,RegisterKHR_materials_iridescence:Je,RegisterKHR_materials_openpbr:Ot,RegisterKHR_materials_sheen:rt,RegisterKHR_materials_specular:ft,RegisterKHR_materials_transmission:_t,RegisterKHR_materials_unlit:yt,RegisterKHR_materials_volume:bt,RegisterKHR_materials_volume_scatter:Ct,RegisterKHR_texture_basisu:Gt,RegisterKHR_texture_transform:Ht,_ConvertToGLTFPBRMetallicRoughness:f,_SolveMetallic:h};const ts="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==ts){ts.BABYLON=ts.BABYLON||{};const e=ts.BABYLON;e.GLTF2=e.GLTF2||{},e.GLTF2.Exporter=e.GLTF2.Exporter||{},e.GLTF2.Exporter.Extensions=e.GLTF2.Exporter.Extensions||{};const t=[];for(const r in s)e[r]=s[r],t.push(r);for(const s in n)e[s]=n[s],t.push(s);for(const s in $)e[s]=$[s],t.push(s);for(const s in Jt)e.GLTF2.Exporter.Extensions[s]=Jt[s],t.push(s);for(const s in es)t.indexOf(s)>-1||(e.GLTF2.Exporter[s]=es[s])}e.EXT_lights_area=xe,e.EXT_mesh_gpu_instancing=j,e.EXT_texture_avif=jt,e.EXT_texture_webp=qt,e.GLTF2Export=q,e.GLTFData=r,e.KHR_draco_mesh_compression=te,e.KHR_lights_punctual=ue,e.KHR_materials_anisotropy=Te,e.KHR_materials_clearcoat=be,e.KHR_materials_coat=Ve,e.KHR_materials_diffuse_roughness=Vt,e.KHR_materials_diffuse_transmission=Ue,e.KHR_materials_dispersion=We,e.KHR_materials_emissive_strength=ke,e.KHR_materials_fuzz=ot,e.KHR_materials_ior=$e,e.KHR_materials_iridescence=Ye,e.KHR_materials_openpbr=Nt,e.KHR_materials_sheen=tt,e.KHR_materials_specular=ct,e.KHR_materials_transmission=pt,e.KHR_materials_unlit=mt,e.KHR_materials_volume=Mt,e.KHR_materials_volume_scatter=Et,e.KHR_texture_basisu=zt,e.KHR_texture_transform=Pt,e.RegisterEXT_lights_area=ge,e.RegisterEXT_mesh_gpu_instancing=Z,e.RegisterEXT_texture_avif=Zt,e.RegisterEXT_texture_webp=Xt,e.RegisterKHR_draco_mesh_compression=re,e.RegisterKHR_lights_punctual=ce,e.RegisterKHR_materials_anisotropy=Re,e.RegisterKHR_materials_clearcoat=Ee,e.RegisterKHR_materials_coat=Fe,e.RegisterKHR_materials_diffuse_roughness=Ft,e.RegisterKHR_materials_diffuse_transmission=Ke,e.RegisterKHR_materials_dispersion=Le,e.RegisterKHR_materials_emissive_strength=De,e.RegisterKHR_materials_fuzz=ut,e.RegisterKHR_materials_ior=Qe,e.RegisterKHR_materials_iridescence=Je,e.RegisterKHR_materials_openpbr=Ot,e.RegisterKHR_materials_sheen=rt,e.RegisterKHR_materials_specular=ft,e.RegisterKHR_materials_transmission=_t,e.RegisterKHR_materials_unlit=yt,e.RegisterKHR_materials_volume=bt,e.RegisterKHR_materials_volume_scatter=Ct,e.RegisterKHR_texture_basisu=Gt,e.RegisterKHR_texture_transform=Ht,e._ConvertToGLTFPBRMetallicRoughness=f,e._SolveMetallic=h,e.__IGLTFExporterExtension=0});
|
|
2
2
|
//# sourceMappingURL=babylon.glTF2Serializer.min.js.map
|