babylonjs-serializers 9.1.0 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/babylonjs.serializers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,e=>(()=>{"use strict";var t={597(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};r.d(o,{default:()=>Ir});var i={};r.r(i),r.d(i,{OBJExport:()=>x});var a={};r.r(a),r.d(a,{__IGLTFExporterExtension:()=>_});var s={};r.r(s),r.d(s,{GLTFData:()=>v});var u={};r.r(u),r.d(u,{GLTF2Export:()=>de});var c={};r.r(c),r.d(c,{EXT_lights_area:()=>Se,EXT_mesh_gpu_instancing:()=>xe,EXT_texture_avif:()=>Et,EXT_texture_webp:()=>Rt,KHR_draco_mesh_compression:()=>Te,KHR_lights_punctual:()=>Ae,KHR_materials_anisotropy:()=>Oe,KHR_materials_clearcoat:()=>Ue,KHR_materials_coat:()=>We,KHR_materials_diffuse_roughness:()=>_t,KHR_materials_diffuse_transmission:()=>He,KHR_materials_dispersion:()=>Xe,KHR_materials_emissive_strength:()=>Ze,KHR_materials_fuzz:()=>at,KHR_materials_ior:()=>Je,KHR_materials_iridescence:()=>et,KHR_materials_openpbr:()=>Tt,KHR_materials_sheen:()=>nt,KHR_materials_specular:()=>ut,KHR_materials_transmission:()=>lt,KHR_materials_unlit:()=>pt,KHR_materials_volume:()=>dt,KHR_materials_volume_scatter:()=>gt,KHR_texture_basisu:()=>wt,KHR_texture_transform:()=>bt});var l={};r.r(l),r.d(l,{EXT_lights_area:()=>Se,EXT_mesh_gpu_instancing:()=>xe,EXT_texture_avif:()=>Et,EXT_texture_webp:()=>Rt,GLTF2Export:()=>de,GLTFData:()=>v,KHR_draco_mesh_compression:()=>Te,KHR_lights_punctual:()=>Ae,KHR_materials_anisotropy:()=>Oe,KHR_materials_clearcoat:()=>Ue,KHR_materials_coat:()=>We,KHR_materials_diffuse_roughness:()=>_t,KHR_materials_diffuse_transmission:()=>He,KHR_materials_dispersion:()=>Xe,KHR_materials_emissive_strength:()=>Ze,KHR_materials_fuzz:()=>at,KHR_materials_ior:()=>Je,KHR_materials_iridescence:()=>et,KHR_materials_openpbr:()=>Tt,KHR_materials_sheen:()=>nt,KHR_materials_specular:()=>ut,KHR_materials_transmission:()=>lt,KHR_materials_unlit:()=>pt,KHR_materials_volume:()=>dt,KHR_materials_volume_scatter:()=>gt,KHR_texture_basisu:()=>wt,KHR_texture_transform:()=>bt,_ConvertToGLTFPBRMetallicRoughness:()=>N,_SolveMetallic:()=>B});var h={};r.r(h),r.d(h,{STLExport:()=>It});var p={};r.r(p),r.d(p,{USDZExportAsync:()=>Wt});var f={};r.r(f),r.d(f,{BVHExporter:()=>qt});var d={};r.r(d),r.d(d,{AbstractThreeMfSerializer:()=>cr,ContentTypeFileName:()=>Fn,DefaultXmlSerializerFormatOptions:()=>an,DefaultXmlSerializerNumberOptions:()=>on,GetXmlFieldMeta:()=>$t,GetXmlName:()=>en,IsQualifiedName:()=>Gt,Known3mfRelationshipTypes:()=>On,KnownI3mfContentType:()=>An,Matrix3d:()=>Dn,MatrixFormatter:()=>Ln,ModelFileName:()=>Sn,NumberFormatter:()=>cn,Object3dDirName:()=>In,OpenXmlContentTypesNamespace:()=>Rn,OpenXmlRelationshipsNamespace:()=>Cn,RelationshipDirName:()=>En,RelationshipFileName:()=>Vn,ResolveFormatOptions:()=>un,ResolveNumberOptions:()=>sn,ST_ObjectType:()=>vn,ST_Unit:()=>_n,StringXmlWriter:()=>yn,ThreeDimModelNamespace:()=>Mn,ThreeMf:()=>lr,ThreeMfBase:()=>er,ThreeMfBaseMaterials:()=>$n,ThreeMfBuild:()=>tr,ThreeMfComponent:()=>Jn,ThreeMfComponents:()=>Yn,ThreeMfComponentsBuilder:()=>or,ThreeMfContentType:()=>Nn,ThreeMfContentTypes:()=>Bn,ThreeMfDocument:()=>kn,ThreeMfDocumentBuilder:()=>ur,ThreeMfItem:()=>nr,ThreeMfMaterialBuilder:()=>ar,ThreeMfMesh:()=>Hn,ThreeMfMeshBuilder:()=>ir,ThreeMfMeta:()=>Kn,ThreeMfMetadataGroup:()=>Wn,ThreeMfModel:()=>zn,ThreeMfModelBuilder:()=>sr,ThreeMfObject:()=>Gn,ThreeMfObjectBuilder:()=>rr,ThreeMfRelationship:()=>Un,ThreeMfRelationships:()=>Pn,ThreeMfResources:()=>qn,ThreeMfSerializer:()=>fr,ThreeMfSerializerGlobalConfiguration:()=>hr,ThreeMfTriangle:()=>Zn,ThreeMfTriangles:()=>Qn,ThreeMfVertex:()=>Xn,ThreeMfVertices:()=>jn,ToQualifiedString:()=>rn,TokenType:()=>mn,TriangleSetsNamespace:()=>wn,Utf8XmlWriterToBytes:()=>bn,XmlAttr:()=>Yt,XmlBuilder:()=>Tn,XmlElem:()=>Jt,XmlIgnore:()=>Zt,XmlName:()=>Qt,XmlNameToParts:()=>nn,XmlSerializer:()=>gn});var m={};r.r(m),r.d(m,{AbstractThreeMfSerializer:()=>cr,BVHExporter:()=>qt,ContentTypeFileName:()=>Fn,DefaultXmlSerializerFormatOptions:()=>an,DefaultXmlSerializerNumberOptions:()=>on,EXT_lights_area:()=>Se,EXT_mesh_gpu_instancing:()=>xe,EXT_texture_avif:()=>Et,EXT_texture_webp:()=>Rt,GLTF2Export:()=>de,GLTFData:()=>v,GetXmlFieldMeta:()=>$t,GetXmlName:()=>en,IsQualifiedName:()=>Gt,KHR_draco_mesh_compression:()=>Te,KHR_lights_punctual:()=>Ae,KHR_materials_anisotropy:()=>Oe,KHR_materials_clearcoat:()=>Ue,KHR_materials_coat:()=>We,KHR_materials_diffuse_roughness:()=>_t,KHR_materials_diffuse_transmission:()=>He,KHR_materials_dispersion:()=>Xe,KHR_materials_emissive_strength:()=>Ze,KHR_materials_fuzz:()=>at,KHR_materials_ior:()=>Je,KHR_materials_iridescence:()=>et,KHR_materials_openpbr:()=>Tt,KHR_materials_sheen:()=>nt,KHR_materials_specular:()=>ut,KHR_materials_transmission:()=>lt,KHR_materials_unlit:()=>pt,KHR_materials_volume:()=>dt,KHR_materials_volume_scatter:()=>gt,KHR_texture_basisu:()=>wt,KHR_texture_transform:()=>bt,Known3mfRelationshipTypes:()=>On,KnownI3mfContentType:()=>An,Matrix3d:()=>Dn,MatrixFormatter:()=>Ln,ModelFileName:()=>Sn,NumberFormatter:()=>cn,OBJExport:()=>x,Object3dDirName:()=>In,OpenXmlContentTypesNamespace:()=>Rn,OpenXmlRelationshipsNamespace:()=>Cn,RelationshipDirName:()=>En,RelationshipFileName:()=>Vn,ResolveFormatOptions:()=>un,ResolveNumberOptions:()=>sn,STLExport:()=>It,ST_ObjectType:()=>vn,ST_Unit:()=>_n,StringXmlWriter:()=>yn,ThreeDimModelNamespace:()=>Mn,ThreeMf:()=>lr,ThreeMfBase:()=>er,ThreeMfBaseMaterials:()=>$n,ThreeMfBuild:()=>tr,ThreeMfComponent:()=>Jn,ThreeMfComponents:()=>Yn,ThreeMfComponentsBuilder:()=>or,ThreeMfContentType:()=>Nn,ThreeMfContentTypes:()=>Bn,ThreeMfDocument:()=>kn,ThreeMfDocumentBuilder:()=>ur,ThreeMfItem:()=>nr,ThreeMfMaterialBuilder:()=>ar,ThreeMfMesh:()=>Hn,ThreeMfMeshBuilder:()=>ir,ThreeMfMeta:()=>Kn,ThreeMfMetadataGroup:()=>Wn,ThreeMfModel:()=>zn,ThreeMfModelBuilder:()=>sr,ThreeMfObject:()=>Gn,ThreeMfObjectBuilder:()=>rr,ThreeMfRelationship:()=>Un,ThreeMfRelationships:()=>Pn,ThreeMfResources:()=>qn,ThreeMfSerializer:()=>fr,ThreeMfSerializerGlobalConfiguration:()=>hr,ThreeMfTriangle:()=>Zn,ThreeMfTriangles:()=>Qn,ThreeMfVertex:()=>Xn,ThreeMfVertices:()=>jn,ToQualifiedString:()=>rn,TokenType:()=>mn,TriangleSetsNamespace:()=>wn,USDZExportAsync:()=>Wt,Utf8XmlWriterToBytes:()=>bn,XmlAttr:()=>Yt,XmlBuilder:()=>Tn,XmlElem:()=>Jt,XmlIgnore:()=>Zt,XmlName:()=>Qt,XmlNameToParts:()=>nn,XmlSerializer:()=>gn,_ConvertToGLTFPBRMetallicRoughness:()=>N,_SolveMetallic:()=>B,__IGLTFExporterExtension:()=>_});var g=r(597),x=function(){function e(){}return e.OBJ=function(e,t,n,r){var o=[],i=1,a=1;t&&(n||(n="mat"),o.push("mtllib "+n+".mtl"));for(var s=0;s<e.length;s++){var u=e[s],c=u.name||"mesh".concat(s,"}");o.push("o ".concat(c));var l=null;if(r){var h=u.computeWorldMatrix(!0);l=new g.Matrix,h.invertToRef(l),u.bakeTransformIntoVertices(h)}if(t){var p=u.material;p&&o.push("usemtl "+p.id)}var f=u.geometry;if(f){var d=f.getVerticesData("position"),m=f.getVerticesData("normal"),x=f.getVerticesData("uv"),_=f.getIndices(),v=0,T=0;if(d&&_){for(var y=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*y+" "+d[b+1]+" "+d[b+2]),v++;if(null!=m)for(b=0;b<m.length;b+=3)o.push("vn "+m[b]*y+" "+m[b+1]+" "+m[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),T++;var M=["","",""],w=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===g.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=w[0],R=w[1];for(b=0;b<_.length;b+=3){var C=[String(_[b]+i),String(_[b+A]+i),String(_[b+R]+i)],E=[String(_[b]+a),String(_[b+A]+a),String(_[b+R]+a)],I=C,S=null!=x?E:M,V=null!=m?C:M;o.push("f "+I[0]+"/"+S[0]+"/"+V[0]+" "+I[1]+"/"+S[1]+"/"+V[1]+" "+I[2]+"/"+S[2]+"/"+V[2])}r&&l&&u.bakeTransformIntoVertices(l),i+=v,a+=T}else g.Tools.Warn("There are no position vertices or indices on the mesh!")}else g.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],n=e.material;return t.push("newmtl mat1"),t.push(" Ns "+n.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+n.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+n.ambientColor.r.toFixed(4)+" "+n.ambientColor.g.toFixed(4)+" "+n.ambientColor.b.toFixed(4)),t.push(" Kd "+n.diffuseColor.r.toFixed(4)+" "+n.diffuseColor.g.toFixed(4)+" "+n.diffuseColor.b.toFixed(4)),t.push(" Ks "+n.specularColor.r.toFixed(4)+" "+n.specularColor.g.toFixed(4)+" "+n.specularColor.b.toFixed(4)),t.push(" Ke "+n.emissiveColor.r.toFixed(4)+" "+n.emissiveColor.g.toFixed(4)+" "+n.emissiveColor.b.toFixed(4)),n.ambientTexture&&t.push(" map_Ka "+n.ambientTexture.name),n.diffuseTexture&&t.push(" map_Kd "+n.diffuseTexture.name),n.specularTexture&&t.push(" map_Ks "+n.specularTexture.name),n.bumpTexture&&t.push(" map_bump -imfchan z "+n.bumpTexture.name),n.opacityTexture&&t.push(" map_d "+n.opacityTexture.name),t.join("\n")},e}(),_=0,v=function(){function e(){this.files={}}return Object.defineProperty(e.prototype,"glTFFiles",{get:function(){return this.files},enumerable:!1,configurable:!0}),e.prototype.downloadFiles=function(){for(var e in this.files){var t=this.files[e],n=new Blob([t],{type:(0,g.GetMimeType)(e)});g.Tools.Download(n,e)}},e}(),T=function(e,t){return T=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},T(e,t)};function y(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}T(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var b=function(){return b=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},b.apply(this,arguments)};function M(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function w(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}u((r=r.apply(e,t||[])).next())})}function A(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function R(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var C=1e-6,E=new g.Color3(.04,.04,.04),I=1024,S=g.Color3.White(),V=g.Color3.BlackReadOnly;function F(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function O(e){return w(this,void 0,void 0,function(){var t,n,r,o;return A(this,function(i){switch(i.label){case 0:if(!(t=e.getInternalTexture())||1!==t.source)return[2,null];if(t.invertY)return[2,null];n=t._buffer,o=e.mimeType,i.label=1;case 1:return i.trys.push([1,12,,13]),n?[3,3]:[4,g.Tools.LoadFileAsync(t.url)];case 2:return r=i.sent(),o=(0,g.GetMimeType)(t.url)||o,[3,11];case 3:return ArrayBuffer.isView(n)?(r=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),[3,11]):[3,4];case 4:return n instanceof ArrayBuffer?(r=n,[3,11]):[3,5];case 5:return n instanceof Blob?[4,n.arrayBuffer()]:[3,7];case 6:return r=i.sent(),o=n.type||o,[3,11];case 7:return"string"!=typeof n?[3,9]:[4,g.Tools.LoadFileAsync(n)];case 8:return r=i.sent(),o=(0,g.GetMimeType)(n)||o,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement?[4,g.Tools.LoadFileAsync(n.src)]:[3,11];case 10:r=i.sent(),o=(0,g.GetMimeType)(n.src)||o,i.label=11;case 11:return[3,13];case 12:return i.sent(),[2,null];case 13:return r&&F(o)?[2,new Blob([r],{type:o})]:[2,null]}})})}function B(e,t,n){if(t<E.r)return 0;var r=E.r,o=e*n/(1-E.r)+t-2*E.r,i=o*o-4*r*(E.r-t);return g.Scalar.Clamp((-o+Math.sqrt(i))/(2*r),0,1)}function N(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),n=e.alpha,r=g.Scalar.Clamp(e.specularPower,0,I),o=(0,g.SpecularPowerToRoughness)(r);return{baseColorFactor:[t.r,t.g,t.b,n],metallicFactor:0,roughnessFactor:o}}function P(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function U(e,t,n){for(var r=new Uint8Array(e*t*4),o=0;o<r.length;o+=4)r[o]=r[o+1]=r[o+2]=r[o+3]=255;return g.RawTexture.CreateRGBATexture(r,e,t,n)}function k(e){if(e instanceof Uint8Array){for(var t=e.length,n=new Float32Array(e.length),r=0;r<t;++r)n[r]=e[r]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var D=function(){function e(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}return e.prototype.getTextureInfo=function(e){var t;return e&&null!==(t=this._textureMap.get(e.uniqueId))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return A(this,function(l){switch(l.label){case 0:return n=N(e),r={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||g.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),t?(o=[],(i=e.diffuseTexture)&&o.push(this.exportTextureAsync(i).then(function(e){e&&(n.baseColorTexture=e)})),(a=e.bumpTexture)&&o.push(this.exportTextureAsync(a).then(function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))})),(s=e.emissiveTexture)&&(r.emissiveFactor=[1,1,1],o.push(this.exportTextureAsync(s).then(function(e){e&&(r.emissiveTexture=e)}))),(u=e.ambientTexture)&&o.push(this.exportTextureAsync(u).then(function(e){if(e){var t={index:e.index};r.occlusionTexture=t}})),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===g.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":g.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(V,C)&&(r.emissiveFactor=e.emissiveColor.asArray()),r.pbrMetallicRoughness=n,P(r,e),[4,this._finishMaterialAsync(r,e)];case 3:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}})})},e.prototype._finishMaterialAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a;return A(this,function(s){switch(s.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(n=s.sent(),r=[],o=0,i=n;o<i.length;o++)a=i[o],r.push(this.exportTextureAsync(a));return[4,Promise.all(r)];case 2:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return s.sent(),[2]}})})},e.prototype._resizeTexturesToSameDimensions=function(e,t,n){var r,o,i=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return i.width<a.width?(r=e&&e instanceof g.Texture?g.TextureTools.CreateResizedCopy(e,a.width,a.height,!0):U(a.width,a.height,n),o=t):i.width>a.width?(o=t&&t instanceof g.Texture?g.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):U(i.width,i.height,n),r=e):(r=e,o=t),{texture1:r,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,p,f,d,m,x,_,v,T,y,b,M,w,R,E,I,V,F,O,B,N,P,U;return A(this,function(A){switch(A.label){case 0:return r=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,A.sent()];case 2:return(o=e?e.getScene():t?t.getScene():null)?(i=this._resizeTexturesToSameDimensions(e,t,o),a=null===(U=i.texture1)||void 0===U?void 0:U.getSize(),s=void 0,u=void 0,c=a.width,l=a.height,[4,i.texture1.readPixels()]):[3,12];case 3:return h=A.sent(),[4,i.texture2.readPixels()];case 4:return p=A.sent(),h?(s=k(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return p?(u=k(p),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(f=u.byteLength,d=new Uint8Array(f),m=new Uint8Array(f),x=new g.Color3(0,0,0),_=0,v=0,F=0;F<l;++F)for(O=0;O<c;++O)T=4*(c*F+O),y=new g.Color3(s[T],s[T+1],s[T+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),b=new g.Color3(u[T],u[T+1],u[T+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(n.specularColor),M=u[T+3]*n.glossiness,w={diffuseColor:y,specularColor:b,glossiness:M},R=this._convertSpecularGlossinessToMetallicRoughness(w),x.r=Math.max(x.r,R.baseColor.r),x.g=Math.max(x.g,R.baseColor.g),x.b=Math.max(x.b,R.baseColor.b),_=Math.max(_,R.metallic),v=Math.max(v,R.roughness),m[T]=255*R.baseColor.r,m[T+1]=255*R.baseColor.g,m[T+2]=255*R.baseColor.b,m[T+3]=i.texture1.hasAlpha?255*s[T+3]:255,d[T]=0,d[T+1]=255*R.roughness,d[T+2]=255*R.metallic,d[T+3]=255;for(E={baseColor:x,metallic:_,roughness:v},I=!1,V=!1,F=0;F<l;++F)for(O=0;O<c;++O)m[B=4*(c*F+O)]/=E.baseColor.r>C?E.baseColor.r:1,m[B+1]/=E.baseColor.g>C?E.baseColor.g:1,m[B+2]/=E.baseColor.b>C?E.baseColor.b:1,N=g.Color3.FromInts(m[B],m[B+1],m[B+2]),P=N.toGammaSpace(o.getEngine().useExactSrgbConversions),m[B]=255*P.r,m[B+1]=255*P.g,m[B+2]=255*P.b,P.equalsWithEpsilon(S,C)||(V=!0),d[B+1]/=E.roughness>C?E.roughness:1,d[B+2]/=E.metallic>C?E.metallic:1,g.Color3.FromInts(255,d[B+1],d[B+2]).equalsWithEpsilon(S,C)||(I=!0);return I&&r.push((0,g.EncodeImageAsync)(d,c,l).then(function(e){E.metallicRoughnessTextureData=e})),V&&r.push((0,g.EncodeImageAsync)(m,c,l).then(function(e){E.baseColorTextureData=e})),[4,Promise.all(r).then(function(){return E})];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}})})},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),n=this._getPerceivedBrightness(e.specularColor),r=1-this._getMaxComponent(e.specularColor),o=B(t,n,r),i=e.diffuseColor.scale(r/(1-E.r)/Math.max(1-o,C)),a=e.specularColor.subtract(E.scale(1-o)).scale(1/Math.max(o,C)),s=g.Color3.Lerp(i,a,o*o);return{baseColor:s=s.clampToRef(0,1,s),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)},e.prototype._getMaxComponent=function(e){return Math.max(e.r,Math.max(e.g,e.b))},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,n,r,o,i,a,s,u){return w(this,void 0,void 0,function(){var c,l,h,p,f,d,m,x,_,v=this;return A(this,function(T){switch(T.label){case 0:return c=[],l={baseColor:e,metallic:t,roughness:n},u&&(a instanceof g.OpenPBRMaterial?(a.geometryOpacityTexture?(h=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:0,p=a.geometryOpacityTexture&&a.geometryOpacityTexture.getInternalTexture()?a.geometryOpacityTexture.getInternalTexture().uniqueId:0,f=Number("".concat(h).concat(p)),(_=this._textureMap.get(f))?s.baseColorTexture=_:c.push((0,g.MergeTexturesAsync)("baseColorOpacityTexture",(0,g.CreateRGBAConfiguration)(r?(0,g.CreateTextureInput)(r,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,1):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,2):(0,g.CreateConstantInput)(1),(0,g.CreateTextureInput)(a.geometryOpacityTexture,0)),a.getScene()).then(function(e){return w(v,void 0,void 0,function(){var t;return A(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,f)];case 1:return(t=n.sent())&&(s.baseColorTexture=t),[2]}})})}))):r&&c.push(this.exportTextureAsync(r).then(function(e){e&&(s.baseColorTexture=e)})),a._useMetallicFromMetallicTextureBlue&&o?c.push(this.exportTextureAsync(o).then(function(e){e&&(s.metallicRoughnessTexture=e)})):(i||o)&&(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,m=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,x=Number("".concat(d).concat(m)),(_=this._textureMap.get(x))?s.metallicRoughnessTexture=_:c.push((0,g.MergeTexturesAsync)("MetalRoughTexture",(0,g.CreateRGBAConfiguration)(a.ambientOcclusionTexture?(0,g.CreateTextureInput)(a.ambientOcclusionTexture,0):(0,g.CreateConstantInput)(1),i?(0,g.CreateTextureInput)(i,0):(0,g.CreateConstantInput)(1),o?(0,g.CreateTextureInput)(o,0):(0,g.CreateConstantInput)(1)),a.getScene()).then(function(e){return w(v,void 0,void 0,function(){var t;return A(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,x)];case 1:return(t=n.sent())&&(s.metallicRoughnessTexture=t),[2]}})})})))):(r&&c.push(this.exportTextureAsync(r).then(function(e){e&&(s.baseColorTexture=e)})),o&&c.push(this.exportTextureAsync(o).then(function(e){e&&(s.metallicRoughnessTexture=e)})))),c.length>0?(this._exporter._materialNeedsUVsSet.add(a),[4,Promise.all(c)]):[3,2];case 1:T.sent(),T.label=2;case 2:return[2,l]}})})},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof g.Texture))return t;var n=this._getGLTFTextureWrapMode(e.wrapU);10497!==n&&(t.wrapS=n);var r=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==r&&(t.wrapT=r),e.samplingMode){case g.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case g.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case g.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case g.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case g.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case g.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case g.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case g.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case g.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case g.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case g.Texture.WRAP_ADDRESSMODE:return 10497;case g.Texture.CLAMP_ADDRESSMODE:return 33071;case g.Texture.MIRROR_ADDRESSMODE:return 33648;default:return g.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l;return A(this,function(h){switch(h.label){case 0:return r={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,i=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!i||a?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(o||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),s=this._exportTextureSampler(o||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,i,r)]):[3,8];case 3:return u=h.sent(),c=this._exporter._textures,u.baseColorTextureData?[4,this._exportImageAsync("baseColor".concat(c.length),u.baseColorTextureData)]:[3,5];case 4:l=h.sent(),t.baseColorTexture=this._exportTextureInfo(l,s,null==o?void 0:o.coordinatesIndex),h.label=5;case 5:return u.metallicRoughnessTextureData?[4,this._exportImageAsync("metallicRoughness".concat(c.length),u.metallicRoughnessTextureData)]:[3,7];case 6:l=h.sent(),t.metallicRoughnessTexture=this._exportTextureInfo(l,s,null==i?void 0:i.coordinatesIndex),h.label=7;case 7:return[2,u];case 8:return[2,this._convertSpecularGlossinessToMetallicRoughness(r)]}})})},e.prototype.exportPBRMaterialAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return A(this,function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(i=e._albedoColor,a=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,a])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,n,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t)];case 3:u=l.sent(),l.label=4;case 4:return s=u,[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,r,n,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(r,e)];case 6:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}})})},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,n,r,o){return w(this,void 0,void 0,function(){var i,a,s,u,c,l=this;return A(this,function(h){switch(h.label){case 0:return P(n,t),e.baseColor.equalsWithEpsilon(S,C)&&g.Scalar.WithinEpsilon(t.alpha,1,C)||(r.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(r.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(r.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||g.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o?(i=[],(a=t instanceof g.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&i.push(this.exportTextureAsync(a).then(function(e){e&&(n.normalTexture=e,1!==a.level&&(n.normalTexture.scale=a.level))})),(s=t instanceof g.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&i.push(new Promise(function(e){return w(l,void 0,void 0,function(){var n,o,i,a;return A(this,function(u){switch(u.label){case 0:return t instanceof g.OpenPBRMaterial&&r.metallicRoughnessTexture?(n=this._exportTextureSampler(s),o=this._exporter._textures[r.metallicRoughnessTexture.index].source,i=this._exportTextureInfo(o,n,s.coordinatesIndex),this._textureMap.set(s.uniqueId,i),this._exporter._extensionsPostExportTextures("exporter",i,s),[2,e(i)]):[3,1];case 1:return a=e,[4,this.exportTextureAsync(s)];case 2:return[2,a.apply(void 0,[u.sent()])]}})})}).then(function(e){return w(l,void 0,void 0,function(){var r;return A(this,function(o){return e&&(r={index:e.index,texCoord:e.texCoord,extensions:e.extensions},n.occlusionTexture=r,t instanceof g.PBRBaseMaterial?r.strength=t._ambientTextureStrength:r.strength=t.ambientOcclusionTexture.level),[2]})})})),(u=t instanceof g.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&i.push(this.exportTextureAsync(u).then(function(e){e&&(n.emissiveTexture=e)})),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:h.sent(),h.label=2;case 2:return(c=t instanceof g.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(V,C)||(n.emissiveFactor=c.asArray()),n.pbrMetallicRoughness=r,[2]}})})},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s;return A(this,function(u){switch(u.label){case 0:return n={},r={name:e.name},o=e.baseColor,i=e.geometryOpacity,o&&(n.baseColorFactor=[o.r,o.g,o.b,i]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t)];case 1:return a=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(a,e,r,n,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(r,e)];case 3:return u.sent(),(s=this._exporter._materials).push(r),[2,s.length-1]}})})},e.prototype.exportTextureAsync=function(e){return w(this,arguments,void 0,function(e,t){var n,r,o;return void 0===t&&(t=null),A(this,function(i){switch(i.label){case 0:return(n=this._textureMap.get(null!=t?t:e.uniqueId))?[2,n]:(r=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=i.sent(),n=this._exportTextureInfo(o,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,n),this._exporter._extensionsPostExportTextures("exporter",n,e),[2,n]}})})},e.prototype._exportTextureImageAsync=function(e){return w(this,void 0,void 0,function(){var t,n,r,o,i,a=this;return A(this,function(s){switch(s.label){case 0:return t=null!==(i=e.mimeType)&&void 0!==i?i:"none",n=this._internalTextureToImage,r=e.getInternalTexture().uniqueId,n[r]=n[r]||{},void 0===(o=n[r][t])&&(o=w(a,void 0,void 0,function(){var n,r,o,i,a;return A(this,function(s){switch(s.label){case 0:return[4,O(e)];case 1:return!(n=s.sent())||"none"!==t&&n.type!==t?[3,3]:[4,this._exportImageAsync(e.name,n)];case 2:case 6:return[2,s.sent()];case 3:return r="image/png","none"!==t&&(F(t)?r=t:(r="image/png",g.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG.")))),o=e.getSize(),[4,(0,g.GetTextureDataAsync)(e)];case 4:return i=s.sent(),[4,(0,g.EncodeImageAsync)(i,o.width,o.height,r)];case 5:return a=s.sent(),[4,this._exportImageAsync(e.name,a)]}})}),n[r][t]=o),[4,o];case 1:return[2,s.sent()]}})})},e.prototype._exportImageAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u;return A(this,function(c){switch(c.label){case 0:return n=this._exporter._images,this._exporter._shouldUseGlb?(r={name:e,mimeType:t.type,bufferView:void 0},[4,t.arrayBuffer()]):[3,2];case 1:return o=c.sent(),i=this._exporter._bufferManager.createBufferView(new Uint8Array(o)),this._exporter._bufferManager.setBufferView(r,i),[3,3];case 2:a=e.replace(/\.\/|\/|\.\\|\\/g,"_"),s=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(t.type),u=a+s,n.some(function(e){return e.uri===u})&&(u="".concat(a,"_").concat(g.Tools.RandomId()).concat(s)),r={name:e,uri:u},this._exporter._imageData[u]=t,c.label=3;case 3:return n.push(r),[2,n.length-1]}})})},e.prototype._exportTextureInfo=function(e,t,n){var r=this._exporter._textures,o=r.findIndex(function(n){return n.sampler==t&&n.source===e});-1===o&&(o=r.length,r.push({source:e,sampler:t}));var i={index:o};return n&&(i.texCoord=n),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),n=this._exporter._samplers,r=n.findIndex(function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT});return-1!==r?r:(n.push(t),n.length-1)},e}(),L=g.Matrix.Compose(new g.Vector3(-1,1,1),g.Quaternion.Identity(),g.Vector3.Zero());function z(e,t){if(!(e instanceof g.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(L,g.TmpVectors.Matrix[0]).equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1;return!(e instanceof g.AbstractMesh&&e.geometry)}var K=g.Vector3.ZeroReadOnly,W=g.Quaternion.Identity(),q=g.Vector3.OneReadOnly,G=new g.Vector3(-1,1,1);function H(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,i=e.normalized,a=e.getSize(),s=t.reduce(function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e},-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:a,type:o,count:s*a,normalized:i,totalVertices:s,kind:e.getKind()}}function j(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 X(e){return e.some(function(e){return e>=256})}function Q(e){switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:case g.VertexBuffer.ColorKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return!0}return!1}function Z(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 Y(e){return e.x*=-1,e}function J(e){return L.invertToRef(g.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(L,e),e}function $(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){var r=Math.sign(e.x);e.x=t,e.y*=-r,e.z*=-r,e.w*=r}else r=Math.sign(e.y),e.x*=-r,e.y=n,e.z*=r,e.w*=-r}else{var o=Math.abs(e.z),i=Math.abs(e.w);o>i?(r=Math.sign(e.z),e.x*=-r,e.y*=r,e.z=o,e.w*=-r):(r=Math.sign(e.w),e.x*=r,e.y*=-r,e.z*=-r,e.w=i)}return e}function ee(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function te(e,t){var n=g.Vector3.FromArrayToRef(t.translation||[0,0,0],0,g.TmpVectors.Vector3[0]),r=g.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[0]),o=g.Matrix.ComposeToRef(q,r,n,g.TmpVectors.Matrix[0]),i=g.Vector3.FromArrayToRef(e.translation||[0,0,0],0,g.TmpVectors.Vector3[2]),a=g.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[1]),s=g.Matrix.ComposeToRef(q,a,i,g.TmpVectors.Matrix[1]);o.multiplyToRef(s,s),s.decompose(void 0,r,n),n.equalsWithEpsilon(K,g.Epsilon)?delete t.translation:t.translation=n.asArray(),r.equalsWithEpsilon(W,g.Epsilon)?delete t.rotation:t.rotation=r.asArray(),t.scale&&delete t.scale}function ne(e,t){if(!(t instanceof g.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var n=e.getScene(),r=e instanceof g.TargetCamera&&!n.useRightHandedSystem?G:q;return!!t.scaling.equalsWithEpsilon(r,g.Epsilon)||(g.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function re(e,t){for(var n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],a=o[1],s=t[i];(Array.isArray(a)&&Array.isArray(s)&&oe(a,s)||a===s)&&delete e[i]}return e}function oe(e,t){return e.length===t.length&&e.every(function(e,n){return e===t[n]})}var ie=new Map([[Int8Array,function(e,t,n){return e.setInt8(t,n)}],[Uint8Array,function(e,t,n){return e.setUint8(t,n)}],[Uint8ClampedArray,function(e,t,n){return e.setUint8(t,n)}],[Int16Array,function(e,t,n){return e.setInt16(t,n,!0)}],[Uint16Array,function(e,t,n){return e.setUint16(t,n,!0)}],[Int32Array,function(e,t,n){return e.setInt32(t,n,!0)}],[Uint32Array,function(e,t,n){return e.setUint32(t,n,!0)}],[Float32Array,function(e,t,n){return e.setFloat32(t,n,!0)}],[Float64Array,function(e,t,n){return e.setFloat64(t,n,!0)}]]),ae=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=ie.get(e.constructor),n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var n=new Uint8Array(2*t);n.set(this._data),this._data=n,this._dataView=new DataView(this._data.buffer)}},e}();function se(e){return e%4==0?4:e%2==0?2:1}var ue,ce=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach(function(e){t+=e.byteLength});for(var n=new ae(t),r=0,o=Array.from(this._bufferViewToData.keys()).sort(function(e,t){return se(t.byteLength)-se(e.byteLength)});r<o.length;r++){var i=o[r];i.byteOffset=n.byteOffset,e.push(i);for(var a=e.length-1,s=0,u=this.getPropertiesWithBufferView(i);s<u.length;s++)u[s].bufferView=a;n.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return n.getOutputData()},e.prototype.createBufferView=function(e,t){var n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n},e.prototype.createAccessor=function(e,t,n,r,o,i,a){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:a,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,n=0,r=this.getPropertiesWithBufferView(e);n<r.length;n++){var o=r[n];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach(function(n,r){n===e&&(void 0!==r.byteOffset&&delete r.byteOffset,t._accessorToBufferView.delete(r))})},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(ue||(ue={}));var le=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof g.TransformNode||e instanceof g.Camera||e instanceof g.Light)},e._CreateNodeAnimation=function(t,n,r,o,i){if(this._IsTransformable(t)){var a=[],s=[],u=n.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,r,o),h=l.interpolationType,p=l.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o):"LINEAR"===h||"STEP"===h?e._CreateLinearOrStepAnimation(t,n,r,a,s,o):"CUBICSPLINE"===h?e._CreateCubicSplineAnimation(t,n,r,a,s,o):e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o),a.length&&s.length)return{inputs:a,outputs:s,samplerInterpolation:h,inputsMin:p?c.min:g.Tools.FloatRound(c.min/n.framePerSecond),inputsMax:p?c.max:g.Tools.FloatRound(c.max/n.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,n="VEC3",r=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":n="VEC4",t="rotation";break;case"rotationQuaternion":n="VEC4",r=!0,t="rotation";break;case"influence":n="SCALAR",t="weights";break;default:g.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:n,useQuaternion:r}:(g.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,i,a,s,u,c,l,h){var p;if(e._IsTransformable(t)&&t.animations)for(var f=0,d=t.animations;f<d.length;f++){var m=d[f];if(!h||h(m)){var g=e._DeduceAnimationInfo(m);g&&(p={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?n:p,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,g.useQuaternion,c,l),p.samplers.length&&p.channels.length&&r.push(p))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,n,r,o,i,a,s,u,c,l,h){var p;if(t instanceof g.Mesh){var f=t.morphTargetManager;if(f)for(var d=0;d<f.numTargets;++d)for(var m=0,x=f.getTarget(d).animations;m<x.length;m++){var _=x[m];if(!h||h(_)){for(var v=new g.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),T=[],y=_.getKeys(),b=0;b<y.length;++b)for(var M=y[b],w=0;w<f.numTargets;++w)w==d?T.push(M):T.push({frame:M.frame,value:0});v.setKeys(T,!0);var A=e._DeduceAnimationInfo(v);A&&(p={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?n:p,t,v,A.dataAccessorType,A.animationChannelTargetPath,o,a,s,u,A.useQuaternion,c,l,f.numTargets),p.samplers.length&&p.channels.length&&r.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,n,r,o,i,a,s,u,c){var l,h;if(t.animationGroups)for(var p=t.animationGroups,f=function(p){var f=new Map,m=new Map,x=new Set,_=p.to-p.from;h={name:p.name,channels:[],samplers:[]};for(var v=function(n){var _=p.targetedAnimations[n],v=_.target,T=_.animation;if(c&&!c(T))return"continue";var y=u.has(v);if(d._IsTransformable(v)||1===v.length&&d._IsTransformable(v[0])){if(M=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(v)?v:d._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(T.name),h,b,T,M.dataAccessorType,M.animationChannelTargetPath,r,o,i,a,M.useQuaternion,s,y)}}else if(v instanceof g.MorphTarget||1===v.length&&v[0]instanceof g.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var w=v instanceof g.MorphTarget?v:v[0];if(w){var A=t.morphTargetManagers.find(function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1});if(A){var R=t.meshes.find(function(e){return e.morphTargetManager===A});R&&(f.has(R)||f.set(R,new Map),null===(l=f.get(R))||void 0===l||l.set(w,T),x.add(R),m.set(R,T))}}}}},T=0;T<p.targetedAnimations.length;++T)v(T);x.forEach(function(t){for(var n=t.morphTargetManager,u=null,c=[],l=m.get(t).getKeys(),d=l.length,x=0;x<d;++x)for(var v=0;v<n.numTargets;++v){var T=n.getTarget(v),y=f.get(t);if(y){var b=y.get(T);b?(u||(u=new g.Animation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,g.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:p.from+_/d*x,value:T.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c,!0);var M=e._DeduceAnimationInfo(u);M&&e._AddAnimation("".concat(p.name,"_").concat(t.name,"_MorphWeightAnimation"),h,t,u,M.dataAccessorType,M.animationChannelTargetPath,r,o,i,a,M.useQuaternion,s,!1,null==n?void 0:n.numTargets)}),h.channels.length&&h.samplers.length&&n.push(h)},d=this,m=0,x=p;m<x.length;m++)f(x[m])},e._AddAnimation=function(t,n,r,o,i,a,s,u,c,l,h,p,f,d){var m,x,_,v,T,y,b=e._CreateNodeAnimation(r,o,a,h,p);if(b){if(d){for(var M=0,w=void 0,A=[];b.inputs.length>0;)w=b.inputs.shift(),M%d==0&&A.push(w),M++;b.inputs=A}var R=s.get(r),C=new Float32Array(b.inputs);m=u.createBufferView(C),x=u.createAccessor(m,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var E=new g.Quaternion,I=new g.Vector3,S=new g.Vector3,V=r instanceof g.Camera,F=j(i),O=new Float32Array(b.outputs.length*F);b.outputs.forEach(function(e,t){var n=e;switch(a){case"translation":f&&(g.Vector3.FromArrayToRef(e,0,S),Y(S),S.toArray(n));break;case"rotation":4===e.length?g.Quaternion.FromArrayToRef(e,0,E):(n=new Array(4),g.Vector3.FromArrayToRef(e,0,I),g.Quaternion.FromEulerVectorToRef(I,E)),f&&($(E),V&&ee(E)),E.toArray(n)}O.set(n,t*F)}),m=u.createBufferView(O),x=u.createAccessor(m,i,5126,b.outputs.length),l.push(x),v=l.length-1,T={interpolation:b.samplerInterpolation,input:_,output:v},n.samplers.push(T),y={sampler:n.samplers.length-1,target:{node:R,path:a}},n.channels.push(y)}},e._CreateBakedAnimation=function(t,n,r,o,i,a,s,u,c,l,h){var p,f,d,m,x,_,v=g.Quaternion.Identity(),T=null,y=null;l.min=g.Tools.FloatRound(o/a);for(var b=n.getKeys(),M=0,w=b.length;M<w;++M){if(d=b[M],M+1<w)if(m=b[M+1],d.value.equals&&d.value.equals(m.value)||d.value===m.value){if(0!==M)continue;_=d.frame}else _=m.frame;else{if(x=b[M-1],d.value.equals&&d.value.equals(x.value)||d.value===x.value)continue;_=i}if(_)for(var A=d.frame;A<=_;A+=s)if((f=g.Tools.FloatRound(A/a))!==T){T=f,y=f;var R={key:0,repeatCount:0,loopMode:n.loopMode};p=n._interpolate(A,R),e._SetInterpolatedValue(t,p,f,n,r,v,u,c,h)}}y&&(l.max=y)},e._ConvertFactorToVector3OrQuaternion=function(t,n,r,o,i){var a=e._GetBasePositionRotationOrScale(n,o,i),s=r.targetProperty.split("."),u=s?s[1]:"",c=i?g.Quaternion.FromArray(a).normalize():g.Vector3.FromArray(a);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:g.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,n,r,o,i,a,s,u){var c;a.push(n),"weights"!==o?(r.dataType===g.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,r,o,u)),"rotation"===o?(u?i=t:(c=t,g.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),s.push(i.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,n,r,o,i,a){for(var s=0,u=n.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/n.framePerSecond),e._AddKeyframeValue(c,n,i,r,t,a)}},e._CreateCubicSplineAnimation=function(t,n,r,o,i,a){n.getKeys().forEach(function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(ue.INTANGENT,i,r,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,n,i,r,t,a),e._AddSplineTangent(ue.OUTTANGENT,i,r,"CUBICSPLINE",s,a)})},e._GetBasePositionRotationOrScale=function(e,t,n){var r;if("rotation"===t)if(n){var o=e.rotationQuaternion;r=(null!=o?o:g.Quaternion.Identity()).asArray()}else{var i=e.rotation;r=(null!=i?i:g.Vector3.Zero()).asArray()}else if("translation"===t){var a=e.position;r=(null!=a?a:g.Vector3.Zero()).asArray()}else{var s=e.scaling;r=(null!=s?s:g.Vector3.One()).asArray()}return r},e._AddKeyframeValue=function(e,t,n,r,o,i){var a,s=t.dataType;if(s===g.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===r){var c=g.Vector3.FromArray(u);u=g.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}n.push(u)}else if(s===g.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)n.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,r,i)){if("rotation"===r){var l=i?a:g.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();n.push(l.asArray())}n.push(a.asArray())}}else s===g.Animation.ANIMATIONTYPE_QUATERNION?n.push(e.value.normalize().asArray()):g.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,n,r,o,i){var a,s=e===ue.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===r){if("rotation"===n)if(s)if(i)a=s.asArray();else{var u=s;a=g.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else a=[0,0,0,0];else a="weights"===n?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(a)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,n=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)}),{min:t,max:n}},e}();function he(e,t,n,r,o,i){var a={attributes:{},influence:e.influence,name:e.name},s=t.geometry;if(!s)return g.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;var u,c=i?-1:1,l=g.Vector3.Zero();if(e.hasPositions){var h=e.getPositions(),p=s.getVerticesData(g.VertexBuffer.PositionKind);if(p){var f=new Float32Array(p.length),d=[1/0,1/0,1/0],m=[-1/0,-1/0,-1/0];u=p.length/3;for(var x=0;x<u;++x){var _=g.Vector3.FromArray(p,3*x);g.Vector3.FromArray(h,3*x).subtractToRef(_,l),l.x*=c,d[0]=Math.min(d[0],l.x),m[0]=Math.max(m[0],l.x),d[1]=Math.min(d[1],l.y),m[1]=Math.max(m[1],l.y),d[2]=Math.min(d[2],l.z),m[2]=Math.max(m[2],l.z),f[3*x]=l.x,f[3*x+1]=l.y,f[3*x+2]=l.z}var v=n.createBufferView(f,12),T=n.createAccessor(v,"VEC3",5126,h.length/3,0,{min:d,max:m});o.push(T),a.attributes.POSITION=o.length-1}else g.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),b=s.getVerticesData(g.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(u=b.length/3,x=0;x<u;++x){var w=g.Vector3.FromArray(b,3*x).normalize();g.Vector3.FromArray(y,3*x).normalize().subtractToRef(w,l),M[3*x]=l.x*c,M[3*x+1]=l.y,M[3*x+2]=l.z}v=n.createBufferView(M,12),T=n.createAccessor(v,"VEC3",5126,y.length/3,0),o.push(T),a.attributes.NORMAL=o.length-1}else g.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),R=s.getVerticesData(g.VertexBuffer.TangentKind);if(R){u=R.length/4;var C=new Float32Array(3*u);for(x=0;x<u;++x){var E=g.Vector3.FromArray(R,4*x);Z(E);var I=g.Vector3.FromArray(A,3*x);Z(I),I.subtractToRef(E,l),C[3*x]=l.x*c,C[3*x+1]=l.y,C[3*x+2]=l.z}v=n.createBufferView(C,12),T=n.createAccessor(v,"VEC3",5126,u,0),o.push(T),a.attributes.TANGENT=o.length-1}else g.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),V=s.getVerticesData(g.VertexBuffer.ColorKind),F=s.getVertexBuffer(g.VertexBuffer.ColorKind);if(V&&F){var O=F.getSize();u=V.length/O;var B=new Float32Array(u*O);for(x=0;x<u;++x)if(3===O){var N=g.Vector3.FromArray(V,x*O);g.Vector3.FromArray(S,x*O).subtractToRef(N,l),B[3*x]=l.x,B[3*x+1]=l.y,B[3*x+2]=l.z}else if(4===O){var P=new g.Vector4;N=g.Vector4.FromArray(V,x*O),g.Vector4.FromArray(S,x*O).subtractToRef(N,P),B[4*x]=P.x,B[4*x+1]=P.y,B[4*x+2]=P.z,B[4*x+3]=P.w}else g.Tools.Warn("Unsupported number of components for color attribute: ".concat(O));v=n.createBufferView(B,4*O),T=n.createAccessor(v,3===O?"VEC3":"VEC4",5126,u,0),o.push(T),a.attributes.COLOR_0=o.length-1}else g.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return a}var pe=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,n,r,o){var i,a,s,u;return null===(u=null===(s=null===(a=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===a?void 0:a.get(n))||void 0===s?void 0:s.get(r))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,n,r,o,i){var a=this._indicesAccessorMap.get(e);a||(a=new Map,this._indicesAccessorMap.set(e,a));var s=a.get(t);s||(s=new Map,a.set(t,s));var u=s.get(n);u||(u=new Map,s.set(n,u));var c=u.get(r);c||(c=new Map,u.set(r,c)),c.set(o,i)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)},e.prototype.getRemappedBufferView=function(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)},e.prototype.getVertexAccessor=function(e,t,n){var r,o;return null===(o=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.get(n)},e.prototype.setVertexAccessor=function(e,t,n,r){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.set(t,i)),i.set(n,r)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),fe=function(){function e(e,t){if(void 0===e&&(e=g.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(g.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new D(this),this._extensions={},this._bufferManager=new ce,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=b({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,n,r){var o=this;if(n>=t.length)return Promise.resolve(e);var i=r(t[n],e);return i?i.then(function(e){return w(o,void 0,void 0,function(){var o;return A(this,function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=i.sent(),[3,3];case 2:o=null,i.label=3;case 3:return[2,o]}})})}):this._ApplyExtension(e,t,n+1,r)},e.prototype._ApplyExtensions=function(t,n){for(var r=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];r.push(this._extensions[a])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var i=this;return this._ApplyExtensions(t,function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,n,r,o,i._bufferManager)})},e.prototype._extensionsPostExportMaterialAsync=function(e,t,n){return this._ApplyExtensions(t,function(t,r){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,n)})},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,n,r){return w(this,void 0,void 0,function(){var o,i=this;return A(this,function(a){switch(a.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map(function(e){return w(i,void 0,void 0,function(){var i,a;return A(this,function(s){switch(s.label){case 0:return(i=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,i.postExportMaterialAdditionalTexturesAsync(t,n,r)]:[3,2];case 1:a=s.sent(),o.push.apply(o,a),s.label=2;case 2:return[2]}})})}))];case 1:return a.sent(),[2,o]}})})},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,n,r)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return w(this,void 0,void 0,function(){var t,n,r,o;return A(this,function(i){switch(i.label){case 0:t=0,n=e._ExtensionNames,i.label=1;case 1:return t<n.length?(r=n[t],(o=this._extensions[r]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}})})},e.prototype._forEachExtensions=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions(function(t){var n,r,o;t.wasUsed&&((n=e._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((r=e._glTF).extensionsRequired||(r.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())})},e.prototype._loadExtensions=function(){for(var t=0,n=e._ExtensionNames;t<n.length;t++){var r=n[t],o=e._ExtensionFactories[r](this);this._extensions[r]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,n,r){void 0===r&&(r=100),e.UnregisterExtension(t)&&g.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=n;var o=null!=r?r:0;e._ExtensionOrders[t]=o;for(var i=e._ExtensionNames.length,a=0;a<e._ExtensionNames.length;a++){var s=e._ExtensionNames[a];if(o<e._ExtensionOrders[s]){i=a;break}}e._ExtensionNames.splice(i,0,t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[t];var n=e._ExtensionNames.indexOf(t);return-1!==n&&e._ExtensionNames.splice(n,1),!0},e.prototype._generateJSON=function(e,t,n){var r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(r.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return w(this,void 0,void 0,function(){var t,n,r,o,i,a,s;return A(this,function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength,e,!0),r=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",i=e+".bin",(a=new v).files[o]=n,a.files[i]=r,this._imageData)for(s in this._imageData)a.files[s]=this._imageData[s];return[2,a]}})})},e.prototype._generateBinaryAsync=function(){return w(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 w(this,void 0,void 0,function(){var t,n,r,o,i,a,s,u,c,l,h,p,f,d;return A(this,function(m){switch(m.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=m.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(a=new TextEncoder,i=a.encode(n),o=i.length),s=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+s+t.byteLength+u,(l=new ae(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(o+s),l.writeUInt32(1313821514),i)l.writeTypedArray(i);else for(h="_".charCodeAt(0),f=0;f<o;++f)(p=n.charCodeAt(f))!=n.codePointAt(f)?l.writeUInt8(h):l.writeUInt8(p);for(f=0;f<s;++f)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),f=0;f<u;++f)l.writeUInt8(0);return(d=new v).files[r]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}})})},e.prototype._setNodeTransformation=function(e,t,n){var r;if(t.getPivotPoint().equalsWithEpsilon(K,g.Epsilon)||g.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(K,g.Epsilon)){var o=g.TmpVectors.Vector3[0].copyFrom(t.position);n&&Y(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(q,g.Epsilon)||(e.scale=t.scaling.asArray());var i=(null===(r=t.rotationQuaternion)||void 0===r?void 0:r.clone())||g.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);i.equalsWithEpsilon(W,g.Epsilon)||(n&&$(i),e.rotation=i.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,n){var r=g.TmpVectors.Vector3[0],o=g.TmpVectors.Quaternion[0],i=t.getWorldMatrix();if(t.parent){var a=t.parent.getWorldMatrix().invertToRef(g.TmpVectors.Matrix[0]);i.multiplyToRef(a,g.TmpVectors.Matrix[1]).decompose(void 0,o,r)}else i.decompose(void 0,o,r);r.equalsWithEpsilon(K,g.Epsilon)||(n&&Y(r),e.translation=r.asArray()),n&&$(o),this._babylonScene.useRightHandedSystem||ee(o),o.equalsWithEpsilon(W,g.Epsilon)||(e.rotation=o.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var n=t[e],r={type:n.mode===g.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(n.name&&(r.name=n.name),"perspective"===r.type)r.perspective={aspectRatio:n.getEngine().getAspectRatio(n),yfov:n.fovMode===g.Camera.FOVMODE_VERTICAL_FIXED?n.fov:n.fov*n.getEngine().getAspectRatio(n),znear:n.minZ,zfar:n.maxZ};else if("orthographic"===r.type){var o=n.orthoLeft&&n.orthoRight?.5*(n.orthoRight-n.orthoLeft):.5*n.getEngine().getRenderWidth(),i=n.orthoBottom&&n.orthoTop?.5*(n.orthoTop-n.orthoBottom):.5*n.getEngine().getRenderHeight();r.orthographic={xmag:o,ymag:i,znear:n.minZ,zfar:n.maxZ}}this._camerasMap.set(n,r)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var n=t[e],r=this._nodesCameraMap.get(n);if(void 0!==r){this._cameras.push(n);for(var o=0,i=r;o<i.length;o++)i[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var n=t[e];n.bones.length<=0||this._skinMap.set(n,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,n=function(n){if(n.bones.length<=0)return"continue";var o=r._skinMap.get(n);if(null==o)return"continue";for(var i={},a=-1,s=0;s<n.bones.length;++s){var u=n.bones[s];-1!==(l=null!==(t=u.getIndex())&&void 0!==t?t:s)&&(i[l]=u,l>a&&(a=l))}for(var c=[],l=0;l<=a;++l){var h=(u=i[l]).getTransformNode(),p=h?r._nodeMap.get(h):void 0;if(void 0!==p){o.joints.push(p);var f=u.getAbsoluteInverseBindMatrix().clone();e.has(h)&&J(f),c.push(f)}else g.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var d=r._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==d){var m=new Float32Array(16*c.length);c.forEach(function(e,t){m.set(e.m,16*t)});var x=r._bufferManager.createBufferView(m);r._accessors.push(r._bufferManager.createAccessor(x,"MAT4",5126,c.length)),o.inverseBindMatrices=r._accessors.length-1,r._skins.push(o);for(var _=r._skins.length-1,v=0,T=d;v<T.length;v++)T[v].skin=_}},r=this,o=0,i=this._babylonScene.skeletons;o<i.length;o++)n(i[o])},e.prototype._exportSceneAsync=function(){return w(this,void 0,void 0,function(){var e,t,n,r,o,i,a,s,u,c,l,h,p,f,d,m,x,_,v,T,y,b,M,w,R,C,E,I,S,V,F,O,B;return A(this,function(A){switch(A.label){case 0:if(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),n=new Array,r=new Array,o=new Array,this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(a=0,s=this._babylonScene.animationGroups;a<s.length;a++)for(u=s[a],c=0,l=u.targetedAnimations;c<l.length;c++)h=l[c],(p=h.target)instanceof g.TransformNode&&!p.parent&&(null!=i?i:i=new Set).add(p);for(f=0,d=this._babylonScene.rootNodes;f<d.length;f++)m=d[f],x=m.animations,_=!!x&&x.length>0||(null==i?void 0:i.has(m)),this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&z(m,this._babylonScene.useRightHandedSystem)&&!_?o.push.apply(o,m.getChildren()):this._babylonScene.useRightHandedSystem?n.push(m):r.push(m);return this._listAvailableCameras(),this._listAvailableSkeletons(),v=new pe(!0,!1),y=(T=(F=e.nodes).push).apply,b=[F],[4,this._exportNodesAsync(r,v)];case 1:return y.apply(T,b.concat([A.sent()])),M=new pe(!1,!1),R=(w=(O=e.nodes).push).apply,C=[O],[4,this._exportNodesAsync(n,M)];case 2:return R.apply(w,C.concat([A.sent()])),E=new pe(!1,!0),S=(I=(B=e.nodes).push).apply,V=[B],[4,this._exportNodesAsync(o,E)];case 3:return S.apply(I,V.concat([A.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(v.getNodesSet()),this._babylonScene.animationGroups.length&&le._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,v.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 w(this,void 0,void 0,function(){var n,r,o,i;return A(this,function(a){switch(a.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,a.label=1;case 1:return r<o.length?(i=o[r],[4,this._exportNodeAsync(i,n,t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return r++,[3,1];case 4:return[2,n]}})})},e.prototype._collectBuffers=function(e,t,n,r,o){if(this._shouldExportNode(e)&&e instanceof g.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var a in i)if(Q(a)){var s=i[a];o.setHasVertexColorAlpha(s,e.hasVertexAlpha);var u=s._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(s)&&c.push(s);var l=n.get(s)||[];n.set(s,l),-1===l.indexOf(e)&&l.push(e)}var h=e.morphTargetManager;if(h)for(var p=0;p<h.numTargets;p++){var f=h.getTarget(p);l=r.get(f)||[],r.set(f,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,m=e.getChildren();d<m.length;d++){var x=m[d];this._collectBuffers(x,t,n,r,o)}},e.prototype._exportBuffers=function(e,t){for(var n=new Map,r=new Map,o=new Map,i=0,a=e;i<a.length;i++){var s=a[i];this._collectBuffers(s,n,r,o,t)}for(var u=Array.from(n.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var i=n.get(e);if(!i)return"continue";var a=i[0].byteStride;if(i.some(function(e){return e.byteStride!==a}))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var s=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=r.get(e),n=H(e,t),o=n.byteOffset,i=n.byteStride,a=n.componentCount,u=n.type,c=n.count,h=n.normalized;switch(n.kind){case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,o,i,a,u,c,h,function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}});break;case g.VertexBuffer.ColorKind:var p=t.filter(function(e){return e.material instanceof g.StandardMaterial||null==e.material}).length;if(0==p)break;if(p!=t.length){g.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==g.VertexBuffer.UNSIGNED_BYTE&&g.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var f=new g.Color3,d=new g.Color4,m=l._babylonScene.getEngine().useExactSrgbConversions;(0,g.EnumerateFloatValues)(s,o,i,a,u,c,h,function(e){3===e.length?(f.fromArray(e,0),f.toLinearSpaceToRef(f,m),f.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,m),d.toArray(e,0))})}},c=0,h=i;c<h.length;c++)u(F=h[c]);if(t.convertToRightHanded){for(var p=0,f=i;p<f.length;p++){var d=H(F=f[p],r.get(F)),m=d.byteOffset,x=d.byteStride,_=d.componentCount,v=d.type,T=d.count,y=d.normalized;switch(C=d.kind){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,m,x,_,v,T,y,function(e){e[0]=-e[0]})}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,a);t.setVertexBufferView(e,b);for(var M=new Map,w=0,A=i;w<A.length;w++){var R=H(F=A[w],r.get(F)),C=R.kind,E=R.totalVertices;switch(C){case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:if(F.type==g.VertexBuffer.FLOAT){var I=F.getFloatData(E);null!==I&&M.set(F,I)}}}0!==M.size&&g.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var S=0,V=Array.from(M.keys());S<V.length;S++){var F=V[S],O=M.get(F);if(O){for(var B=X(O),N=new(B?Uint16Array:Uint8Array)(O.length),P=0;P<O.length;P++)N[P]=O[P];var U=l._bufferManager.createBufferView(N,4*(B?2:1));t.setRemappedBufferView(e,F,U)}}},l=this,h=0,p=u;h<p.length;h++)c(p[h]);for(var f=0,d=Array.from(o.keys());f<d.length;f++){var m=d[f],x=o.get(m);if(x)for(var _=he(m,x[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),v=0,T=x;v<T.length;v++){var y=T[v];t.bindMorphDataToMesh(y,_)}}},e.prototype._exportNodeAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h=this;return A(this,function(p){switch(p.label){case 0:return void 0!==(r=this._nodeMap.get(e))?(t.includes(r)||t.push(r),[2]):[4,this._createNodeAsync(e,n)];case 1:(o=p.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),i={name:"runtime animations",channels:[],samplers:[]},a=[],this._babylonScene.animationGroups.length||(le._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&le._CreateNodeAnimationFromNodeAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),a.forEach(function(e){e.channels.length&&e.samplers.length&&h._animations.push(e)})),s=o?[]:t,u=0,c=e.getChildren(),p.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:p.sent(),p.label=4;case 4:return u++,[3,2];case 5:return o&&s.length&&(o.children=s),[2]}})})},e.prototype._createNodeAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c,l,h,p,f;return A(this,function(d){switch(d.label){case 0:return this._shouldExportNode(e)?(n={},e.name&&(n.name=e.name),e.metadata&&(r=this._options.metadataSelector(e.metadata))&&(n.extras=r),e instanceof g.TransformNode?(this._setNodeTransformation(n,e,t.convertToRightHanded),e instanceof g.AbstractMesh?(o=e instanceof g.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(i=n,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(a=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(a)&&this._nodesSkinMap.set(a,[]),null===(h=this._nodesSkinMap.get(a))||void 0===h||h.push(n)),d.label=3;case 3:if(e instanceof g.TargetCamera&&(s=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(s)&&this._nodesCameraMap.set(s,[]),this._setCameraTransformation(n,e,t.convertToRightHanded),null!==(u=e.parent)&&ne(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],te(n,l),null===(p=this._nodesCameraMap.get(s))||void 0===p||p.push(l),[2,null];null===(f=this._nodesCameraMap.get(s))||void 0===f||f.push(n)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",n,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,n]:(g.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}})})},e.prototype._exportIndices=function(e,t,n,r,o,i,a,s,u){var c=null;u.mode=function(e){switch(e){case g.Material.TriangleFillMode:return 4;case g.Material.TriangleStripDrawMode:return 5;case g.Material.TriangleFanDrawMode:return 6;case g.Material.PointListDrawMode:case g.Material.PointFillMode:return 0;case g.Material.LineLoopDrawMode:return 2;case g.Material.LineListDrawMode:return 1;case g.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}(i);var l=a!==g.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case g.Material.TriangleFillMode:case g.Material.TriangleStripDrawMode:case g.Material.TriangleFanDrawMode:return!0}return!1}(i);if(l){if(i===g.Material.TriangleStripDrawMode||i===g.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");var h=t?new Uint32Array(r):new Uint16Array(r);if(e)for(var p=0;p+2<r;p+=3)h[p]=e[n+p]+o,h[p+1]=e[n+p+2]+o,h[p+2]=e[n+p+1]+o;else for(p=0;p+2<r;p+=3)h[p]=p,h[p+1]=p+2,h[p+2]=p+1;c=h}else if(e&&0!==o){for(h=t?new Uint32Array(r):new Uint16Array(r),p=0;p<r;p++)h[p]=e[n+p]+o;c=h}else e&&(c=function(e,t,n,r){var o=e;return 0===t&&n===e.length||(o=Array.isArray(e)?e.slice(t,t+n):e.subarray(t,t+n)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?r?new Uint32Array(o):new Uint16Array(o):o}(e,n,r,t));if(c){var f=s.getIndicesAccessor(e,n,r,o,l);if(void 0===f){var d=this._bufferManager.createBufferView(c),m=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(d,"SCALAR",m,r,0)),f=this._accessors.length-1,s.setIndicesAccessor(e,n,r,o,l,f)}u.indices=f}},e.prototype._exportVertexBuffer=function(e,t,n,r,o,i){var a=e.getKind();if(Q(a)&&(!a.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var s=o.getVertexAccessor(e,n,r);if(void 0===s){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=a===g.VertexBuffer.PositionKind?function(e,t,n,r){var o=t.byteOffset,i=t.byteStride,a=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,g.EnumerateFloatValues)(e,o+n*i,i,u,a,r*u,s,function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])}),{min:c,max:l}}(u,e,n,r):void 0,l=(a===g.VertexBuffer.MatricesIndicesKind||a===g.VertexBuffer.MatricesIndicesExtraKind)&&e.type===g.VertexBuffer.FLOAT,h=l?g.VertexBuffer.UNSIGNED_BYTE:e.type,p=l?void 0:e.normalized,f=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+n*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(f,function(e,t){if(e==g.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:return"VEC3";case g.VertexBuffer.TangentKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(a,o.hasVertexColorAlpha(e)),h,r,d,c,p)),s=this._accessors.length-1,o.setVertexAccessor(e,n,r,s)}i.attributes[function(e){switch(e){case g.VertexBuffer.PositionKind:return"POSITION";case g.VertexBuffer.NormalKind:return"NORMAL";case g.VertexBuffer.TangentKind:return"TANGENT";case g.VertexBuffer.ColorKind:return"COLOR_0";case g.VertexBuffer.UVKind:return"TEXCOORD_0";case g.VertexBuffer.UV2Kind:return"TEXCOORD_1";case g.VertexBuffer.UV3Kind:return"TEXCOORD_2";case g.VertexBuffer.UV4Kind:return"TEXCOORD_3";case g.VertexBuffer.UV5Kind:return"TEXCOORD_4";case g.VertexBuffer.UV6Kind:return"TEXCOORD_5";case g.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case g.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case g.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case g.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(a)]=s}},e.prototype._exportMaterialAsync=function(e,t,n,r){return w(this,void 0,void 0,function(){var o,i;return A(this,function(a){switch(a.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,8]:(i=t&&Object.keys(t).some(function(e){return e.startsWith("uv")}),(e=e instanceof g.MultiMaterial?e.subMaterials[n.materialIndex]:e)instanceof g.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,i)]:[3,2]);case 1:return o=a.sent(),[3,7];case 2:return e instanceof g.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,i)]:[3,4];case 3:return o=a.sent(),[3,7];case 4:return e instanceof g.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,i)]:[3,6];case 5:return o=a.sent(),[3,7];case 6:return g.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,o),a.label=8;case 8:return r.material=o,[2]}})})},e.prototype._exportMeshAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c,l,h,p,f,d,m,x,_,v,T,y,b,M,w,C,E,I,S,V,F,O,B,N,P,U,k;return A(this,function(A){switch(A.label){case 0:if(void 0!==(n=t.getMesh(e)))return[2,n];if(r={primitives:[]},n=this._meshes.length,this._meshes.push(r),t.setMesh(e,n),o=e.isUnIndexed?null:e.getIndices(),i=null===(O=e.geometry)||void 0===O?void 0:O.getVertexBuffers(),a=t.getMorphTargetsFromMesh(e),s=e instanceof g.LinesMesh,u=e instanceof g.GreasedLineBaseMesh,c=e.subMeshes,!(i&&c&&c.length>0))return[3,7];l=0,h=c,A.label=1;case 1:return l<h.length?(p=h[l],f={attributes:{}},d=p.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:d.name},T=e,m=g.Color3.White(),x=null!==(N=null===(B=T.material)||void 0===B?void 0:B.alpha)&&void 0!==N?N:1,(!(_=null!==(U=null===(P=T.greasedLineMaterial)||void 0===P?void 0:P.color)&&void 0!==U?U:m).equalsWithEpsilon(m,g.Epsilon)||x<1)&&(v.pbrMetallicRoughness={baseColorFactor:R(R([],_.asArray(),!0),[x],!1)}),this._materials.push(v),f.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return s?(v={name:d.name},(!(T=e).color.equalsWithEpsilon(g.Color3.White(),g.Epsilon)||T.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:R(R([],T.color.asArray(),!0),[T.alpha],!1)}),this._materials.push(v),f.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,i,p,f)];case 4:A.sent(),A.label=5;case 5:for(y=s||u?g.Material.LineListDrawMode:null!==(k=e.overrideRenderingFillMode)&&void 0!==k?k:d.fillMode,b=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(b=b===g.Material.ClockWiseSideOrientation?g.Material.CounterClockWiseSideOrientation:g.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,g.AreIndices32Bits)(o,p.indexCount,p.indexStart,p.verticesStart):p.verticesCount>65535,o?p.indexStart:p.verticesStart,o?p.indexCount:p.verticesCount,-p.verticesStart,y,b,t,f),M=0,w=Object.values(i);M<w.length;M++)C=w[M],this._exportVertexBuffer(C,d,p.verticesStart,p.verticesCount,t,f);if(a)for(f.targets=[],E=0,I=a;E<I.length;E++)F=I[E],f.targets.push(F.attributes);r.primitives.push(f),this._extensionsPostExportMeshPrimitive(f),A.label=6;case 6:return l++,[3,1];case 7:if(a)for(r.weights=[],r.extras||(r.extras={}),r.extras.targetNames=[],S=0,V=a;S<V.length;S++)F=V[S],r.weights.push(F.influence),r.extras.targetNames.push(F.name);return[2,n]}})})},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),de=function(){function e(){}return e.GLTFAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o;return A(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new fe(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e.GLBAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o;return A(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new fe(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e}(),me="EXT_mesh_gpu_instancing";function ge(e,t){for(var n=new Float32Array(3*t),r=0;r<t;r++)n[3*r+0]=e[4*r+0],n[3*r+1]=e[4*r+1],n[3*r+2]=e[4*r+2];return n}var xe=function(){function e(e){this.name=me,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,n,r,o,i){return w(this,void 0,void 0,function(){var e=this;return A(this,function(r){switch(r.label){case 0:return[4,new Promise(function(r){var a,s;if(t&&n instanceof g.Mesh&&n.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var u=g.Vector3.Zero(),c=g.Quaternion.Identity(),l=g.Vector3.One(),h=n.thinInstanceGetWorldMatrices(),p=g.TmpVectors.Vector3[2],f=g.TmpVectors.Quaternion[1],d=g.TmpVectors.Vector3[3],m=!1,x=!1,_=!1,v=new Float32Array(3*n.thinInstanceCount),T=new Float32Array(4*n.thinInstanceCount),y=new Float32Array(3*n.thinInstanceCount),b=0,M=0,w=h;M<w.length;M++)w[M].decompose(d,f,p),o&&(Y(p),$(f)),v.set(p.asArray(),3*b),T.set(f.normalize().asArray(),4*b),y.set(d.asArray(),3*b),m=m||!p.equalsWithEpsilon(u),x=x||!f.equalsWithEpsilon(c),_=_||!d.equalsWithEpsilon(l),b++;var A={attributes:{}};m&&(A.attributes.TRANSLATION=e._buildAccessor(v,"VEC3",n.thinInstanceCount,i)),x&&(A.attributes.ROTATION=e._buildAccessor(T,"VEC4",n.thinInstanceCount,i)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",n.thinInstanceCount,i));var R=null===(s=null===(a=n._userThinInstanceBuffersStorage)||void 0===a?void 0:a.data)||void 0===s?void 0:s.instanceColor;if(R){var C=n.thinInstanceCount;n.hasVertexAlpha&&R.length===4*C?(e._instanceColorWarned||(g.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),R=ge(R,C)):R.length===4*C&&(R=ge(R,C)),R.length===3*C&&(A.attributes._COLOR_0=e._buildAccessor(R,"VEC3",C,i))}t.extensions=t.extensions||{},t.extensions[me]=A}r(t)})];case 1:return[2,r.sent()]}})})},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),i=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();fe.RegisterExtension(me,function(e){return new xe(e)});var _e="KHR_draco_mesh_compression";function ve(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}var Te=function(){function e(e){this.name=_e,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&g.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,n){var r=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],i=[],a=null;if(void 0!==e.indices){var s=n[e.indices],u=t.getBufferView(s);a=t.getData(u).slice(),o.push(u),i.push(s)}for(var c=[],l=0,h=Object.entries(e.attributes);l<h.length;l++){var p=h[l],f=p[0],d=(s=n[p[1]],u=t.getBufferView(s),j(s.type)),m=(0,g.GetTypedArrayData)(t.getData(u),d,s.componentType,s.byteOffset||0,u.byteStride||(0,g.GetTypeByteLength)(s.componentType)*d,s.count,!0);c.push({kind:f,dracoName:ve(f),size:j(s.type),data:m}),o.push(u),i.push(s)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},_=g.DracoEncoder.Default._encodeAsync(c,a,x).then(function(n){var a={bufferView:-1,attributes:n.attributeIds},s=t.createBufferView(n.data);t.setBufferView(a,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];r._bufferViewsUsed.add(l)}for(var h=0,p=i;h<p.length;h++){var f=p[h];r._accessorsUsed.add(f)}e.extensions||(e.extensions={}),e.extensions[_e]=a}).catch(function(e){g.Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. "+e.message)});this._encodePromises.push(_),this._wasUsed=!0}else g.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return w(this,void 0,void 0,function(){var t=this;return A(this,function(n){switch(n.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return n.sent(),this._bufferViewsUsed.forEach(function(n){e.getPropertiesWithBufferView(n).every(function(e){return t._accessorsUsed.has(e)})&&e.removeBufferView(n)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}})})},e}();fe.RegisterExtension(_e,function(e){return new Te(e)});var ye="KHR_lights_punctual",be={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},Me={innerConeAngle:0,outerConeAngle:Math.PI/4},we=g.Vector3.Backward(),Ae=function(){function e(e){this.name=ye,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[ye]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return w(this,void 0,void 0,function(){var i=this;return A(this,function(a){switch(a.label){case 0:return[4,new Promise(function(a){if(n instanceof g.Light){var s=n.getTypeID()==g.Light.LIGHTTYPEID_POINTLIGHT?"point":n.getTypeID()==g.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":n.getTypeID()==g.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(s&&n instanceof g.ShadowLight))return g.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(ye)),void a(t);if(n.falloffType!==g.Light.FALLOFF_GLTF&&g.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(ye," specification!")),!n.position.equalsToFloats(0,0,0)){var u=g.TmpVectors.Vector3[0].copyFrom(n.position);o&&Y(u),t.translation=u.asArray()}if("point"!==s){var c=n.direction.normalizeToRef(g.TmpVectors.Vector3[0]);o&&Y(c);var l=g.Quaternion.FromUnitVectorsToRef(we,c,g.TmpVectors.Quaternion[0]);g.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var h={type:s,name:n.name,color:n.diffuse.asArray(),intensity:n.intensity,range:n.range};if(re(h,be),"spot"===s){var p=n;h.spot={innerConeAngle:p.innerAngle/2,outerConeAngle:p.angle/2},re(h.spot,Me)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(h);var f={light:i._lights.lights.length-1},d=n.parent;if(d&&ne(n,d)){var m=r.get(d);if(m){var x=i._exporter._nodes[m];return te(t,x),x.extensions||(x.extensions={}),x.extensions[ye]=f,void a(null)}}t.extensions||(t.extensions={}),t.extensions[ye]=f,a(t)}else a(t)})];case 1:return[2,a.sent()]}})})},e}();fe.RegisterExtension(ye,function(e){return new Ae(e)});var Re="EXT_lights_area",Ce={name:"",color:[1,1,1],intensity:1,size:1},Ee={aspect:1},Ie=g.Vector3.Backward(),Se=function(){function e(e){this.name=Re,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[Re]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return w(this,void 0,void 0,function(){var i=this;return A(this,function(a){switch(a.label){case 0:return[4,new Promise(function(a){if(n instanceof g.Light){var s=n.getTypeID()==g.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!s)return g.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(Re)),void a(t);var u=n;if(u.falloffType!==g.Light.FALLOFF_GLTF&&g.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(Re," specification!")),!u.position.equalsToFloats(0,0,0)){var c=g.TmpVectors.Vector3[0].copyFrom(u.position);o&&Y(c),t.translation=c.asArray()}var l=g.Vector3.Forward();o&&Y(l);var h=g.Quaternion.FromUnitVectorsToRef(Ie,l,g.TmpVectors.Quaternion[0]);g.Quaternion.IsIdentity(h)||(t.rotation=h.asArray());var p={type:s,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};re(p,Ce),p.rect&&re(p.rect,Ee),i._lights||(i._lights={lights:[]}),i._lights.lights.push(p);var f={light:i._lights.lights.length-1},d=n.parent;if(d&&ne(u,d)){var m=r.get(d);if(m){var x=i._exporter._nodes[m];return te(t,x),x.extensions||(x.extensions={}),x.extensions[Re]=f,void a(null)}}t.extensions||(t.extensions={}),t.extensions[Re]=f,a(t)}else a(t)})];case 1:return[2,a.sent()]}})})},e}();fe.RegisterExtension(Re,function(e){return new Se(e)});var Ve="KHR_materials_anisotropy";function Fe(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n||r?[4,(0,g.MergeTexturesAsync)("AnisotropyTexture",(0,g.CreateRGBAConfiguration)(r?(0,g.CreateTextureInput)(r,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,1):(0,g.CreateConstantInput)(0),n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}})})}var Oe=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,t,n){return w(this,void 0,void 0,function(){var e,t,r;return A(this,function(o){switch(o.label){case 0:return e=[],n instanceof g.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 g.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0?(t=function(e){var t=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}(n),this._anisoTexturesMap[t]?(e.push(this._anisoTexturesMap[t]),[3,4]):[3,2]):[3,5];case 2:return[4,Fe(n)];case 3:(r=o.sent())&&(e.push(r),this._anisoTexturesMap[t]=r),o.label=4;case 4:return[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o,i,a,s,u,c;if(n instanceof g.PBRBaseMaterial){if(!n.anisotropy.isEnabled||n.anisotropy.legacy)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var l=r._exporter._materialExporter.getTextureInfo(n.anisotropy.texture);null!==(v={anisotropyStrength:n.anisotropy.intensity,anisotropyRotation:n.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[Ve]=v}else if(n instanceof g.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0){r._wasUsed=!0,t.extensions=t.extensions||{};var h=n.specularRoughnessTexture;n._useRoughnessFromMetallicTextureGreen&&(h=n.baseMetalnessTexture);var p=r._anisoTexturesMap[n.id];if(!h&&!p){var f=n.specularRoughness,d=n.specularRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var m=(i=n.specularRoughness,c=(1-(a=n.specularRoughnessAnisotropy))*(u=(s=i*i)*Math.sqrt(2/(1+(1-a)*(1-a)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});f=m.newBaseRoughness,d=m.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=f);var x={anisotropyStrength:d,anisotropyRotation:n.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[Ve]=x,e(t)}var _=p?r._exporter._materialExporter.getTextureInfo(p):null,v={anisotropyStrength:n.specularRoughnessAnisotropy,anisotropyRotation:n.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};n._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=r._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&r._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),r._exporter._materialNeedsUVsSet.add(n),t.extensions[Ve]=v}e(t)})},e}();fe.RegisterExtension(Ve,function(e){return new Oe(e)});var Be="KHR_materials_clearcoat";function Ne(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.coatWeightTexture,r=e.coatRoughnessTexture,n||r?[4,(0,g.MergeTexturesAsync)("CoatTexture",(0,g.CreateRGBAConfiguration)(n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,e._useCoatRoughnessFromGreenChannel?1:0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}})})}function Pe(e,t){var n=new g.Texture(t.name,t.getScene());return n._texture=e,n.coordinatesIndex=t.coordinatesIndex,t instanceof g.Texture&&(n.uOffset=t.uOffset,n.vOffset=t.vOffset,n.uScale=t.uScale,n.vScale=t.vScale,n.wAng=t.wAng),n.wrapU=t.wrapU,n.wrapV=t.wrapV,n}var Ue=function(){function e(e){this.name=Be,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e,t,r,o;return A(this,function(i){switch(i.label){case 0:return e=[],n instanceof g.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 g.OpenPBRMaterial&&n.coatWeight>0?(t=!1,n.coatWeightTexture?n.coatRoughnessTexture?n._useCoatRoughnessFromGreenChannel&&n.coatWeightTexture.getInternalTexture()===n.coatRoughnessTexture.getInternalTexture()?(e.push(n.coatWeightTexture),e.push(n.coatRoughnessTexture)):t=!0:e.push(n.coatWeightTexture):n.coatRoughnessTexture&&(n._useCoatRoughnessFromGreenChannel?e.push(n.coatRoughnessTexture):t=!0),t?(r=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(n),this._cachedInternalTexturesMap[r]?[3,3]:[4,Ne(n)]):[3,4]):[3,5];case 2:(o=i.sent())&&(this._cachedInternalTexturesMap[r]=o),i.label=3;case 3:this._cachedInternalTexturesMap[r]&&(n.coatWeightTexture&&(this._mergedTexturesMap[n.coatWeightTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[r],n.coatWeightTexture),e.push(this._mergedTexturesMap[n.coatWeightTexture.uniqueId])),n.coatRoughnessTexture&&(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[r],n.coatRoughnessTexture),e.push(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]))),i.label=4;case 4:return n.geometryCoatNormalTexture&&e.push(n.geometryCoatNormalTexture),[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o,i=r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture);o=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness),n.clearCoat.isTintEnabled&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),n.clearCoat.remapF0OnInterfaceChange&&g.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(n.name));var a=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture);null===(c={clearcoatFactor:n.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:n.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=a?a:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Be]=c}else if(n instanceof g.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var s=void 0,u=void 0;n.coatWeightTexture&&(s=r._mergedTexturesMap[n.coatWeightTexture.uniqueId],u=r._exporter._materialExporter.getTextureInfo(s));var c,l=void 0,h=void 0;n.coatRoughnessTexture&&(l=r._mergedTexturesMap[n.coatRoughnessTexture.uniqueId],h=r._exporter._materialExporter.getTextureInfo(l)),n.coatColorTexture&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),a=r._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),null===(c={clearcoatFactor:n.coatWeight,clearcoatTexture:null!=u?u:void 0,clearcoatRoughnessFactor:n.coatRoughness,clearcoatRoughnessTexture:null!=h?h:void 0,clearcoatNormalTexture:null!=a?a:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Be]=c}e(t)})},e}();fe.RegisterExtension(Be,function(e){return new Ue(e)});var ke="KHR_materials_coat";function De(e){var t=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}function Le(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n||r?[4,(0,g.MergeTexturesAsync)("AnisotropyTexture",(0,g.CreateRGBAConfiguration)(r?(0,g.CreateTextureInput)(r,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,1):(0,g.CreateConstantInput)(0),n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}})})}function ze(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.coatWeightTexture,r=e.coatRoughnessTexture,n||r?[4,(0,g.MergeTexturesAsync)("CoatTexture",(0,g.CreateRGBAConfiguration)(n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,e._useCoatRoughnessFromGreenChannel?1:0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}})})}function Ke(e,t){var n=new g.Texture(t.name,t.getScene());return n._texture=e,n.coordinatesIndex=t.coordinatesIndex,t instanceof g.Texture&&(n.uOffset=t.uOffset,n.vOffset=t.vOffset,n.uScale=t.uScale,n.vScale=t.vScale,n.wAng=t.wAng),n.wrapU=t.wrapU,n.wrapV=t.wrapV,n}var We=function(){function e(e){this.name=ke,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e,t,r,o,i;return A(this,function(a){switch(a.label){case 0:return e=[],n instanceof g.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 g.OpenPBRMaterial&&n.coatWeight>0?(t=!1,n.coatWeightTexture?n.coatRoughnessTexture?n._useCoatRoughnessFromGreenChannel&&n.coatWeightTexture.getInternalTexture()===n.coatRoughnessTexture.getInternalTexture()?(e.push(n.coatWeightTexture),e.push(n.coatRoughnessTexture)):t=!0:e.push(n.coatWeightTexture):n.coatRoughnessTexture&&(n._useCoatRoughnessFromGreenChannel?e.push(n.coatRoughnessTexture):t=!0),t?(o=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(n),this._cachedInternalTexturesMap[o]?[3,3]:[4,ze(n)]):[3,4]):[3,9];case 2:(r=a.sent())&&(this._cachedInternalTexturesMap[o]=r),a.label=3;case 3:this._cachedInternalTexturesMap[o]&&(n.coatWeightTexture&&(this._mergedTexturesMap[n.coatWeightTexture.uniqueId]=Ke(this._cachedInternalTexturesMap[o],n.coatWeightTexture),e.push(this._mergedTexturesMap[n.coatWeightTexture.uniqueId])),n.coatRoughnessTexture&&(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]=Ke(this._cachedInternalTexturesMap[o],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?(o=De(n),this._mergedTexturesMap[o]?(e.push(this._mergedTexturesMap[o]),[3,7]):[3,5]):[3,8];case 5:return[4,Le(n)];case 6:(i=a.sent())&&(e.push(i),this._mergedTexturesMap[o]=i),a.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o,i,a,s,u,c;if(n instanceof g.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var l,h=r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture);l=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness);var p=void 0;n.clearCoat.isTintEnabled&&(p=r._exporter._materialExporter.getTextureInfo(n.clearCoat.tintTexture));var f=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture),d=n.clearCoat.indexOfRefraction;null===(v={coatFactor:n.clearCoat.intensity,coatTexture:null!=h?h:void 0,coatRoughnessFactor:n.clearCoat.roughness,coatRoughnessTexture:null!=l?l:void 0,coatNormalTexture:null!=f?f:void 0,coatColorFactor:n.clearCoat.tintColor.asArray(),coatColorTexture:null!=p?p:void 0,coatIor:1.5!==d?d:void 0}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatColorTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[ke]=v}else if(n instanceof g.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var m=void 0;h=void 0,n.coatWeightTexture&&(m=r._mergedTexturesMap[n.coatWeightTexture.uniqueId]?r._mergedTexturesMap[n.coatWeightTexture.uniqueId]:n.coatWeightTexture,h=r._exporter._materialExporter.getTextureInfo(m));var x=void 0,_=void 0;n.coatRoughnessTexture&&(x=r._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]?r._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]:n.coatRoughnessTexture,_=r._exporter._materialExporter.getTextureInfo(x)),f=r._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),p=r._exporter._materialExporter.getTextureInfo(n.coatColorTexture),d=n.coatIor;var v,T=n.coatDarkening,y=n.coatRoughnessTexture,b=De(n),M=r._mergedTexturesMap[b],w=0,A=0,R=void 0;if(n.coatRoughnessAnisotropy>0){if(y||M){var C=M?r._exporter._materialExporter.getTextureInfo(M):null;w=n.coatRoughnessAnisotropy,A=n.geometryCoatTangentAngle,R=C||void 0}else{var E=n.coatRoughness,I=n.coatRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var S=(i=n.coatRoughness,c=(1-(a=n.coatRoughnessAnisotropy))*(u=(s=i*i)*Math.sqrt(2/(1+(1-a)*(1-a)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});E=S.newBaseRoughness,I=S.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=E),w=I,A=n.geometryCoatTangentAngle+.5*Math.PI,R=void 0}n._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=r._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&r._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(v={coatFactor:n.coatWeight,coatTexture:null!=h?h:void 0,coatRoughnessFactor:n.coatRoughness,coatRoughnessTexture:null!=_?_:void 0,coatNormalTexture:null!=f?f:void 0,coatColorFactor:n.coatColor.asArray(),coatColorTexture:null!=p?p:void 0,coatIor:1.5!==d?d:void 0,coatDarkeningFactor:1!==T?T:void 0,coatAnisotropyRotation:A,coatAnisotropyStrength:w,coatAnisotropyTexture:R}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatAnisotropyTexture&&null===v.coatColorTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[ke]=v}e(t)})},e}();fe.RegisterExtension(ke,function(e){return new We(e)});var qe="KHR_materials_diffuse_transmission";function Ge(e,t){var n=t.subSurface,r=null;return n.translucencyIntensityTexture?r=n.translucencyIntensityTexture:n.thicknessTexture&&n.useMaskFromThicknessTexture&&(r=n.thicknessTexture),r&&!n.useGltfStyleTextures?(g.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):r}var He=function(){function e(e){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var t,r;return A(this,function(o){return t=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?((r=Ge(e,n))&&t.push(r),n.subSurface.translucencyColorTexture&&t.push(n.subSurface.translucencyColorTexture),[2,t]):[2,t]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(o){var i,a;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var s=n.subSurface,u=Ge(e,n),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(i=r._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0,h=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),p=null!==(a=r._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==a?a:void 0,f={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:h,diffuseTransmissionColorTexture:p};(l||p)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[qe]=f}o(t)})},e}();fe.RegisterExtension(qe,function(e){return new He(e)});var je="KHR_materials_dispersion",Xe=function(){function e(){this.name=je,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={dispersion:n.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[je]=o}e(t)})},e}();fe.RegisterExtension(je,function(){return new Xe});var Qe="KHR_materials_emissive_strength",Ze=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,t,n){return w(this,void 0,void 0,function(){var e=this;return A(this,function(r){switch(r.label){case 0:return[4,new Promise(function(r){if(!(n instanceof g.PBRMaterial))return r(t);var o=n.emissiveColor.scale(n.emissiveIntensity),i=Math.max.apply(Math,o.asArray());if(i>1){t.emissiveFactor=o.scale(1/i).asArray(),e._wasUsed=!0;var a={emissiveStrength:i};t.extensions||(t.extensions={}),t.extensions[Qe]=a}else t.emissiveFactor=o.asArray();return r(t)})];case 1:return[2,r.sent()]}})})},e}();fe.RegisterExtension(Qe,function(){return new Ze});var Ye="KHR_materials_ior",Je=function(){function e(){this.name=Ye,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={ior:n.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[Ye]=o}e(t)})},e}();fe.RegisterExtension(Ye,function(e){return new Je});var $e="KHR_materials_iridescence",et=function(){function e(e){this.name=$e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){if(e=[],n instanceof g.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 g.OpenPBRMaterial&&n.thinFilmWeight>0)return n.thinFilmWeightTexture&&e.push(n.thinFilmWeightTexture),n.thinFilmThicknessTexture&&n.thinFilmThicknessTexture!==n.thinFilmWeightTexture&&e.push(n.thinFilmThicknessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.PBRBaseMaterial){if(!n.iridescence.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.iridescence.texture),i=r._exporter._materialExporter.getTextureInfo(n.iridescence.thicknessTexture);null===(a={iridescenceFactor:n.iridescence.intensity,iridescenceIor:n.iridescence.indexOfRefraction,iridescenceThicknessMinimum:n.iridescence.minimumThickness,iridescenceThicknessMaximum:n.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0}).iridescenceTexture&&null===a.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[$e]=a}else if(n instanceof g.OpenPBRMaterial){if(n.thinFilmWeight<=0)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var a,s=r._exporter._materialExporter.getTextureInfo(n.thinFilmWeightTexture),u=r._exporter._materialExporter.getTextureInfo(n.thinFilmThicknessTexture);null===(a={iridescenceFactor:n.thinFilmWeight,iridescenceIor:n.thinFilmIor,iridescenceThicknessMinimum:1e3*n.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*n.thinFilmThickness,iridescenceTexture:null!=s?s:void 0,iridescenceThicknessTexture:null!=u?u:void 0}).iridescenceTexture&&null===a.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[$e]=a}e(t)})},e}();fe.RegisterExtension($e,function(e){return new et(e)});var tt="KHR_materials_sheen",nt=function(){function e(e){this.name=tt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){return A(this,function(e){return n instanceof g.PBRMaterial&&n.sheen.isEnabled&&n.sheen.texture?[2,[n.sheen.texture]]:[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e=this;return A(this,function(r){switch(r.label){case 0:return[4,new Promise(function(r){var o,i,a,s;if(n instanceof g.PBRMaterial){if(!n.sheen.isEnabled)return void r(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:n.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=n.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),n.sheen.texture&&(u.sheenColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==i?i:void 0),n.sheen.textureRoughness&&!n.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(n.sheen.textureRoughness))&&void 0!==a?a:void 0:n.sheen.texture&&n.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==s?s:void 0),t.extensions[tt]=u}r(t)})];case 1:return[2,r.sent()]}})})},e}();fe.RegisterExtension(tt,function(e){return new nt(e)});var rt="KHR_materials_fuzz";function ot(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.fuzzColorTexture,r=e.fuzzRoughnessTexture,n||r?[4,(0,g.MergeTexturesAsync)("FuzzTexture",(0,g.CreateRGBAConfiguration)(n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1),n?(0,g.CreateTextureInput)(n,1):(0,g.CreateConstantInput)(1),n?(0,g.CreateTextureInput)(n,2):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,e._useFuzzRoughnessFromTextureAlpha?3:0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}})})}function it(e,t){var n=new g.Texture(t.name,t.getScene());return n._texture=e,n.coordinatesIndex=t.coordinatesIndex,t instanceof g.Texture&&(n.uOffset=t.uOffset,n.vOffset=t.vOffset,n.uScale=t.uScale,n.vScale=t.vScale,n.wAng=t.wAng),n.wrapU=t.wrapU,n.wrapV=t.wrapV,n}var at=function(){function e(e){this.name=rt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e,t,r,o;return A(this,function(i){switch(i.label){case 0:return n instanceof g.OpenPBRMaterial?(e=[],n.fuzzWeight>0?(n.fuzzWeightTexture&&e.push(n.fuzzWeightTexture),t=!1,n.fuzzRoughnessTexture&&(n._useFuzzRoughnessFromTextureAlpha?e.push(n.fuzzRoughnessTexture):t=!0),n.fuzzColorTexture&&!t&&e.push(n.fuzzColorTexture),t?(r=function(e){var t=e.fuzzColorTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",r=e.fuzzRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(n,"_FuzzRoughness_").concat(o)}(n),this._cachedInternalTexturesMap[r]?[3,2]:[4,ot(n)]):[3,3]):[3,3]):[3,4];case 1:(o=i.sent())&&(this._cachedInternalTexturesMap[r]=o),i.label=2;case 2:this._cachedInternalTexturesMap[r]&&(n.fuzzColorTexture&&(this._mergedTexturesMap[n.fuzzColorTexture.uniqueId]=it(this._cachedInternalTexturesMap[r],n.fuzzColorTexture),e.push(this._mergedTexturesMap[n.fuzzColorTexture.uniqueId])),n.fuzzRoughnessTexture&&(this._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]=it(this._cachedInternalTexturesMap[r],n.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]))),i.label=3;case 3:return[2,e];case 4:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e=this;return A(this,function(r){switch(r.label){case 0:return[4,new Promise(function(r){var o,i,a;if(n instanceof g.OpenPBRMaterial){if(0==n.fuzzWeight)return void r(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var s={fuzzFactor:n.fuzzWeight,fuzzColorFactor:n.fuzzColor.asArray(),fuzzRoughnessFactor:n.fuzzRoughness};n.fuzzWeightTexture&&(s.fuzzTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(n.fuzzWeightTexture))&&void 0!==o?o:void 0);var u=void 0;n.fuzzColorTexture&&(u=e._mergedTexturesMap[n.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[n.fuzzColorTexture.uniqueId]:n.fuzzColorTexture,s.fuzzColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0);var c=void 0;n.fuzzRoughnessTexture&&(c=e._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]:n.fuzzRoughnessTexture,s.fuzzRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==a?a:void 0),null===s.fuzzColorTexture&&null===s.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),t.extensions[rt]=s}r(t)})];case 1:return[2,r.sent()]}})})},e}();fe.RegisterExtension(rt,function(e){return new at(e)});var st="KHR_materials_specular",ut=function(){function e(e){this.name=st,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){return e=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(n.metallicReflectanceTexture&&e.push(n.metallicReflectanceTexture),n.reflectanceTexture&&e.push(n.reflectanceTexture),[2,e]):[2,e]})})},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o,i,a,s,u;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(o=r._exporter._materialExporter.getTextureInfo(n.metallicReflectanceTexture))&&void 0!==o?o:void 0,l=null!==(i=r._exporter._materialExporter.getTextureInfo(n.reflectanceTexture))&&void 0!==i?i:void 0,h={specularFactor:1==n.metallicF0Factor?void 0:n.metallicF0Factor,specularTexture:c,specularColorFactor:n.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:n.metallicReflectanceColor.asArray(),specularColorTexture:l};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[st]=h}else if(n instanceof g.OpenPBRMaterial){t.extensions=t.extensions||{};var p=null!==(a=r._exporter._materialExporter.getTextureInfo(n.specularWeightTexture))&&void 0!==a?a:void 0,f=null!==(s=r._exporter._materialExporter.getTextureInfo(n.specularColorTexture))&&void 0!==s?s:void 0,d=1==n.specularWeight?void 0:n.specularWeight,m=n.specularColor.equalsFloats(1,1,1)?void 0:n.specularColor.asArray();if(!f&&!p&&void 0===d&&void 0===m)return e(t);r._wasUsed=!0,(h={specularFactor:d,specularTexture:p,specularColorFactor:m,specularColorTexture:f,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=r._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&r._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(p||f)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[st]=h}e(t)})},e}();fe.RegisterExtension(st,function(e){return new ut(e)});var ct="KHR_materials_transmission",lt=function(){function e(e){this.name=ct,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){if(e=[],n instanceof g.PBRMaterial){if(this._isExtensionEnabled(n))return n.subSurface.refractionIntensityTexture&&n.subSurface.useGltfStyleTextures&&e.push(n.subSurface.refractionIntensityTexture),[2,e]}else n instanceof g.OpenPBRMaterial&&n.transmissionWeight>0&&n.transmissionWeightTexture&&e.push(n.transmissionWeightTexture);return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e instanceof g.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0;if(e instanceof g.PBRMaterial&&!e.unlit){var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||null!=t.refractionIntensityTexture&&t.useGltfStyleTextures}return!1},e.prototype.postExportMaterialAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a;return A(this,function(s){return this._isExtensionEnabled(n)?(n instanceof g.PBRMaterial?(this._wasUsed=!0,r=n.subSurface,o=0===r.refractionIntensity?void 0:r.refractionIntensity,i={transmissionFactor:o},r.refractionIntensityTexture&&(r.useGltfStyleTextures?(this._exporter._materialNeedsUVsSet.add(n),(a=this._exporter._materialExporter.getTextureInfo(r.refractionIntensityTexture))&&(i.transmissionTexture=a)):g.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported"))),t.extensions||(t.extensions={}),t.extensions[ct]=i):n instanceof g.OpenPBRMaterial&&(this._wasUsed=!0,o=n.transmissionWeight,i={transmissionFactor:o},n.transmissionWeightTexture&&(this._exporter._materialNeedsUVsSet.add(n),(a=this._exporter._materialExporter.getTextureInfo(n.transmissionWeightTexture))&&(i.transmissionTexture=a)),1===o&&t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=void 0),t.extensions||(t.extensions={}),t.extensions[ct]=i),[2,t]):[2,t]})})},e}();fe.RegisterExtension(ct,function(e){return new lt(e)});var ht="KHR_materials_unlit",pt=function(){function e(){this.name=ht,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o=!1;n instanceof g.PBRMaterial?o=n.unlit:n instanceof g.StandardMaterial&&(o=n.disableLighting),o&&(r._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ht]={}),e(t)})},e}();fe.RegisterExtension(ht,function(){return new pt});var ft="KHR_materials_volume",dt=function(){function e(e){this.name=ft,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){if(e=[],n instanceof g.PBRMaterial){if(this._isExtensionEnabled(n))return n.subSurface.thicknessTexture&&e.push(n.subSurface.thicknessTexture),[2,e]}else n instanceof g.OpenPBRMaterial&&n.transmissionWeight>0&&n.geometryThicknessTexture&&e.push(n.geometryThicknessTexture);return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=g.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o,i;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var a=n.subSurface,s={thicknessFactor:0==a.maximumThickness?void 0:a.maximumThickness,thicknessTexture:null!==(o=r._exporter._materialExporter.getTextureInfo(a.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:a.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:a.tintColorAtDistance,attenuationColor:a.tintColor.equalsFloats(1,1,1)?void 0:a.tintColor.asArray()};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[ft]=s}else n instanceof g.OpenPBRMaterial&&n.transmissionWeight>0&&(r._wasUsed=!0,s={thicknessFactor:n.geometryThickness,thicknessTexture:null!==(i=r._exporter._materialExporter.getTextureInfo(n.geometryThicknessTexture))&&void 0!==i?i:void 0,attenuationDistance:n.transmissionDepth,attenuationColor:n.transmissionColor.equalsFloats(1,1,1)?void 0:n.transmissionColor.asArray()},t.extensions=t.extensions||{},t.extensions[ft]=s);e(t)})},e}();fe.RegisterExtension(ft,function(e){return new dt(e)});var mt="KHR_materials_volume_scatter",gt=function(){function e(e){this.name=mt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){return e=[],n instanceof g.OpenPBRMaterial&&n.transmissionWeight>0&&n.transmissionScatterTexture&&e.push(n.transmissionScatterTexture),[2,e]})})},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&0!=e.transmissionWeight&&!e.transmissionScatter.equals(g.Color3.Black())},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.OpenPBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o=1/n.transmissionDepth,i=new g.Vector3(-Math.log(n.transmissionColor.r)*o,-Math.log(n.transmissionColor.g)*o,-Math.log(n.transmissionColor.b)*o),a=new g.Vector3(n.transmissionScatter.r*o,n.transmissionScatter.g*o,n.transmissionScatter.b*o),s=i.subtract(a),u=Math.min(s.x,s.y,s.z);u<0&&(s.subtractInPlace(new g.Vector3(u,u,u)),i.copyFrom(s).addInPlace(a));var c={multiscatterColor:(f=new g.Vector3(a.x/i.x,a.y/i.y,a.z/i.z),d=new g.Vector3(Math.sqrt(1-f.x),Math.sqrt(1-f.y),Math.sqrt(1-f.z)),m=new g.Vector3(1,1,1),x=m.subtract(d),_=m.subtract(new g.Vector3(.139,.139,.139).multiplyInPlace(d)),v=m.add(new g.Vector3(1.17,1.17,1.17).multiplyInPlace(d)),x.multiplyInPlace(_).divideInPlace(v)).asArray(),scatterAnisotropy:n.transmissionScatterAnisotropy};if(n.transmissionScatterTexture){r._exporter._materialNeedsUVsSet.add(n);var l=r._exporter._materialExporter.getTextureInfo(n.transmissionScatterTexture);l&&(c.multiscatterColorTexture=l)}if(t.extensions=t.extensions||{},t.extensions[mt]=c,t.extensions.KHR_materials_volume){var h=t.extensions.KHR_materials_volume,p=Math.max(i.x,i.y,i.z);h.attenuationDistance=1/Math.max(p,1e-4),h.attenuationColor=new g.Color3(Math.exp(-i.x*h.attenuationDistance),Math.exp(-i.y*h.attenuationDistance),Math.exp(-i.z*h.attenuationDistance)).asArray()}}var f,d,m,x,_,v;e(t)})},e}();fe.RegisterExtension(mt,function(e){return new gt(e)},101);var xt="KHR_materials_diffuse_roughness",_t=function(){function e(e){this.name=xt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){if(e=[],n instanceof g.PBRBaseMaterial){if(n._baseDiffuseRoughness)return n._baseDiffuseRoughnessTexture&&e.push(n._baseDiffuseRoughnessTexture),[2,e]}else if(n instanceof g.OpenPBRMaterial&&n.baseDiffuseRoughness)return n.baseDiffuseRoughnessTexture&&e.push(n.baseDiffuseRoughnessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o=null,i=null;if(n instanceof g.PBRBaseMaterial?(o=n._baseDiffuseRoughness,i=n._baseDiffuseRoughnessTexture):n instanceof g.OpenPBRMaterial&&(o=n.baseDiffuseRoughness,i=n.baseDiffuseRoughnessTexture),o){r._wasUsed=!0,t.extensions=t.extensions||{};var a=r._exporter._materialExporter.getTextureInfo(i),s={diffuseRoughnessFactor:o,diffuseRoughnessTexture:null!=a?a:void 0};null!==s.diffuseRoughnessTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[xt]=s,e(t)}else e(t)})},e}();fe.RegisterExtension(xt,function(e){return new _t(e)});var vt="KHR_materials_openpbr",Tt=function(){function e(){this.name=vt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){n instanceof g.OpenPBRMaterial&&(r._wasUsed=!0,t.extensions=t.extensions||{},t.extensions[vt]={}),e(t)})},e}();fe.RegisterExtension(vt,function(e){return new Tt});var yt="KHR_texture_transform",bt=function(){function e(){this.name=yt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,n){if(n.getScene()||g.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(n.name,"!")),0===n.uAng&&0===n.vAng||(g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with rotation in the u or v axis is not supported in glTF.")),0===n.uRotationCenter&&0===n.vRotationCenter)){var r={},o=!1;if(0===n.uOffset&&0===n.vOffset||(r.offset=[n.uOffset,n.vOffset],o=!0),1===n.uScale&&1===n.vScale||(r.scale=[n.uScale,n.vScale],o=!0),0!==n.wAng){if(0!==n.uRotationCenter||0!==n.vRotationCenter){if(n.homogeneousRotationInUVTransform&&n.uScale!==n.vScale)return void g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(yt,"."));g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(yt,".")),r.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,a=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*i,h=o*a;return[t+(l*(1-u)+h*c),n+(h*(1-u)-l*c)]}(n)}r.rotation=-n.wAng,o=!0}0!==n.coordinatesIndex&&(r.texCoord=n.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[yt]=r)}},e}();fe.RegisterExtension(yt,function(){return new bt});var Mt="KHR_texture_basisu",wt=function(){function e(e){this.name=Mt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/ktx2"===(o.mimeType||(0,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Mt]={source:r},this._wasUsed=!0)}},e}();fe.RegisterExtension(Mt,function(e){return new wt(e)});var At="EXT_texture_webp",Rt=function(){function e(e){this.name=At,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/webp"===(o.mimeType||(0,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[At]={source:r},this._wasUsed=!0)}},e}();fe.RegisterExtension(At,function(e){return new Rt(e)});var Ct="EXT_texture_avif",Et=function(){function e(e){this.name=Ct,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/avif"===(o.mimeType||(0,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Ct]={source:r},this._wasUsed=!0)}},e}();fe.RegisterExtension(Ct,function(e){return new Et(e)});var It=function(){function e(){}return e.CreateSTL=function(e,t,n,r,o,i,a,s){void 0===t&&(t=!0),void 0===n&&(n="stlmesh"),void 0===r&&(r=!1),void 0===o&&(o=!0),void 0===i&&(i=!1),void 0===a&&(a=!1),void 0===s&&(s=!1);var u=function(e,t,n){var r=[3*e[n],3*e[n+1],3*e[n+2]],o=[new g.Vector3(t[r[0]],t[r[0]+2],t[r[0]+1]),new g.Vector3(t[r[1]],t[r[1]+2],t[r[1]+1]),new g.Vector3(t[r[2]],t[r[2]+2],t[r[2]+1])],i=o[0].subtract(o[1]),a=o[2].subtract(o[1]);return{v:o,n:g.Vector3.Cross(a,i).normalize()}},c=function(e,t,n,r){return t=l(e,t,n.x,r),t=l(e,t,n.y,r),l(e,t,n.z,r)},l=function(e,t,n,r){return e.setFloat32(t,n,r),t+4},h=function(e){if(a){var t=e;e instanceof g.InstancedMesh&&(t=e.sourceMesh);var n=t.getVerticesData(g.VertexBuffer.PositionKind,!0,!0);if(!n)return[];var r=g.Vector3.Zero(),o=void 0;for(o=0;o<n.length;o+=3)g.Vector3.TransformCoordinatesFromFloatsToRef(n[o],n[o+1],n[o+2],e.computeWorldMatrix(!0),r).toArray(n,o);return n}return e.getVerticesData(g.VertexBuffer.PositionKind)||[]};a&&(i=!0);var p="",f=0,d=0;if(r){for(var m=0;m<e.length;m++)f+=(T=(_=e[m]).getIndices())?T.length/3:0;var x=new ArrayBuffer(84+50*f);d+=80,(p=new DataView(x)).setUint32(d,f,o),d+=4}else s||(p="solid stlmesh\r\n");for(m=0;m<e.length;m++){var _=e[m];!r&&s&&(p+="solid "+_.name+"\r\n"),!i&&_ instanceof g.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=h(_),T=_.getIndices()||[],y=0;y<T.length;y+=3){var b=u(T,v,y);r?(d=c(p,d,b.n,o),d=c(p,d,b.v[0],o),d=c(p,d,b.v[1],o),d=c(p,d,b.v[2],o),d+=2):(p+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",p+="\t\touter loop\r\n",p+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",p+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",p+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",p+="\t\tendloop\r\n",p+="\tendfacet\r\n")}!r&&s&&(p+="endsolid "+name+"\r\n")}if(r||s||(p+="endsolid stlmesh"),t){var M=document.createElement("a"),w=new Blob([p],{type:"application/octet-stream"});M.href=window.URL.createObjectURL(w),M.download=n+".stl",M.click()}return p},e}();function St(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],i=0;i<e.length/n;i++){var a=e[i*n]*(r?-1:1),s=e[i*n+1],u=e[i*n+2];o.push("(".concat(a.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function Vt(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],i=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-i).toPrecision(t.precision),")"))}return n.join(", ")}function Ft(e,t,n,r){var o=function(e,t,n,r){var o=e.getVerticesData(g.VertexBuffer.PositionKind),i=e.getVerticesData(g.VertexBuffer.NormalKind);if(o&&i)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(n,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,n=e.getIndices(),r=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==n)for(var i=0;i<r;i++)o.push(n[i]);else for(i=0;i<r;i++)o.push(i);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(St(i,t,void 0,r),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(St(o,t,void 0,r),"]\n ").concat(function(e,t){for(var n="",r=0;r<4;r++){var o=r>0?r:"",i=e.getVerticesData(g.VertexBuffer.UVKind+(o?o+1:""));i&&(n+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(Vt(i,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var a=e.getVerticesData(g.VertexBuffer.ColorKind);return a&&(n+="\n\tcolor3f[] primvars:displayColor = [".concat(St(a,t,a.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),n}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t,n,r);return'\n def "Geometry"\n {\n '.concat(o,"\n }\n ")}function Ot(e){var t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function Bt(e){var t=e.m;return"( ".concat(Nt(t,0),", ").concat(Nt(t,4),", ").concat(Nt(t,8),", ").concat(Nt(t,12)," )")}function Nt(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function Pt(e,t){var n="Object_"+e.uniqueId,r=Bt(t);return'def Xform "'.concat(n,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(r,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Ut(e){switch(e){case g.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case g.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case g.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function kt(e){return"(".concat(e.x,", ").concat(e.y,")")}function Dt(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function Lt(e,t,n,r,o,i){var a=e.getInternalTexture().uniqueId+"_"+e.invertY;o[a]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new g.Vector2(e.uScale,e.vScale),c=new g.Vector2(e.uOffset,e.vOffset),l=e.wAng,h=Math.sin(l),p=Math.cos(l);return c.y=1-c.y-u.y,c.x+=h*u.x,c.y+=(1-p)*u.y,'\n def Shader "PrimvarReader_'.concat(n,'"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "').concat(s,'"\n float2 outputs:result\n }\n\n def Shader "Transform2d_').concat(n,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_').concat(t.uniqueId,"/PrimvarReader_").concat(n,".outputs:result>\n float inputs:rotation = ").concat((l*(180/Math.PI)).toFixed(i.precision),"\n float2 inputs:scale = ").concat(kt(u),"\n float2 inputs:translation = ").concat(kt(c),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(n,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(a,".png@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(t.uniqueId,"/Transform2d_").concat(n,".outputs:result>\n ").concat(r?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(r):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(Ut(e.wrapU),'"\n token inputs:wrapT = "').concat(Ut(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(t.needAlphaBlending()||t.needAlphaTesting()?"float outputs:a":"","\n }")}function zt(e,t,n){var r="\t\t\t",o=[],i=[],a=function(e){var t,n,r={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof g.StandardMaterial?b(b({},r),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof g.PBRBaseMaterial?b(b({},r),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(t=e._roughness)&&void 0!==t?t:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(n=e._metallic)&&void 0!==n?n:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):r}(e),s=a.diffuseMap,u=a.diffuse,c=a.alphaCutOff,l=a.emissiveMap,h=a.emissive,p=a.normalMap,f=a.roughnessMap,d=a.roughnessChannel,m=a.roughness,x=a.metalnessMap,_=a.metalnessChannel,v=a.metalness,T=a.aoMap,y=a.aoMapChannel,M=a.aoMapIntensity,w=a.alphaMap,A=a.ior,R=a.clearCoatEnabled,C=a.clearCoat,E=a.clearCoatMap,I=a.clearCoatRoughness,S=a.clearCoatRoughnessMap;return null!==s?(o.push("".concat(r,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(r,"float inputs:opacityThreshold = ").concat(c))),i.push(Lt(s,e,"diffuse",u,t,n))):o.push("".concat(r,"color3f inputs:diffuseColor = ").concat(Dt(u||g.Color3.White()))),null!==l?(o.push("".concat(r,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),i.push(Lt(l,e,"emissive",h,t,n))):h&&h.toLuminance()>0&&o.push("".concat(r,"color3f inputs:emissiveColor = ").concat(Dt(h))),null!==p&&(o.push("".concat(r,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_normal.outputs:rgb>")),i.push(Lt(p,e,"normal",null,t,n))),null!==T&&(o.push("".concat(r,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(T.uniqueId,"_occlusion.outputs:").concat(y,">")),i.push(Lt(T,e,"occlusion",new g.Color3(M,M,M),t,n))),null!==f?(o.push("".concat(r,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(f.uniqueId,"_roughness.outputs:").concat(d,">")),i.push(Lt(f,e,"roughness",new g.Color3(m,m,m),t,n))):o.push("".concat(r,"float inputs:roughness = ").concat(m)),null!==x?(o.push("".concat(r,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(x.uniqueId,"_metallic.outputs:").concat(_,">")),i.push(Lt(x,e,"metallic",new g.Color3(v,v,v),t,n))):o.push("".concat(r,"float inputs:metallic = ").concat(v)),null!==w?(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(w.uniqueId,"_opacity.outputs:r>")),o.push("".concat(r,"float inputs:opacityThreshold = 0.0001")),i.push(Lt(w,e,"opacity",null,t,n))):o.push("".concat(r,"float inputs:opacity = ").concat(e.alpha)),R&&(null!==E?(o.push("".concat(r,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(E.uniqueId,"_clearcoat.outputs:r>")),i.push(Lt(E,e,"clearcoat",new g.Color3(C,C,C),t,n))):o.push("".concat(r,"float inputs:clearcoat = ").concat(C)),null!==S?(o.push("".concat(r,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(S.uniqueId,"_clearcoatRoughness.outputs:g>")),i.push(Lt(S,e,"clearcoatRoughness",new g.Color3(I,I,I),t,n))):o.push("".concat(r,"float inputs:clearcoatRoughness = ").concat(I))),o.push("".concat(r,"float inputs:ior = ").concat(A)),'\n\tdef Material "Material_'.concat(e.uniqueId,'"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n').concat(o.join("\n"),"\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(i.join("\n"),"\n\n\t}\n")}function Kt(e){var t,n;e.computeWorldMatrix(!0);for(var r=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,i=null!==(n=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==n?n:e.sideOrientation,a=!o,s=e.parent;s;){if(z(s,o)&&null===s.parent){o||(r.multiplyToRef(s.getWorldMatrix().invert(),r),i=i===g.Material.ClockWiseSideOrientation?g.Material.CounterClockWiseSideOrientation:g.Material.ClockWiseSideOrientation),a=!1;break}s=s.parent}return r.determinant()<0&&g.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:r,windingOrder:i===g.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:a}}function Wt(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,p,f,d,m,x,_,v,T,y,M,w,R,C,E,I,S,V,F,O,B,N,P,U;return A(this,function(A){switch(A.label){case 0:return r=b({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},t),"undefined"!=typeof fflate?[3,2]:[4,g.Tools.LoadScriptAsync(r.fflateUrl)];case 1:A.sent(),A.label=2;case 2:for((o={})[r.modelFileName]=null,i='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',i+=function(e){var t=!0===e.includeAnchoringProperties?'\n\t\ttoken preliminary:anchoring:type = "'.concat(e.anchoringType,'"\n\t\ttoken preliminary:planeAnchoring:alignment = "').concat(e.planeAnchoringAlignment,'"'):"";return'def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {'.concat(t,"\n ")}(r),a={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(h=(l=c).geometry,(p=l.material)&&h&&(!n||n(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(p.getClassName())?(f="geometries/Geometry_"+h.uniqueId+".usda",d=Kt(l),m=d.matrix,x=d.windingOrder,_=d.convertToRightHanded,f in o||(v=Ft(h,r,x,_),o[f]=Ot(v)),p.uniqueId in a||(a[p.uniqueId]=p),i+=Pt(l,m)):g.Tools.Warn("USDZExportAsync does not support this material type: "+p.getClassName())));for(w in e.activeCamera&&r.exportCamera&&(i+=function(e,t){var n="Camera_"+e.uniqueId,r=Bt(g.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===g.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(t.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var o=e.getEngine().getAspectRatio(e),i=t.cameraSensorWidth||35;return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat focalLength = ").concat((i/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((i*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((i/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,r)),i+="\n }\n }",i+=function(e,t,n){var r=[];for(var o in e){var i=e[o];r.push(zt(i,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(a,T={},r),i+="\n }",o[r.modelFileName]=fflate.strToU8(i),M=[],y=T)M.push(w);R=0,A.label=3;case 3:return R<M.length?(w=M[R])in y?(E=T[C=w],I=E.getSize(),[4,(0,g.GetTextureDataAsync)(E)]):[3,6]:[3,7];case 4:return S=A.sent(),[4,g.DumpTools.DumpDataAsync(I.width,I.height,S,"image/png",void 0,!1,!0)];case 5:V=A.sent(),o["textures/Texture_".concat(C,".png")]=new Uint8Array(V).slice(),A.label=6;case 6:return R++,[3,3];case 7:for(O in F=0,o)(B=o[O])&&(N=34+O.length,4!=(P=63&(F+=N))&&(U=new Uint8Array(64-P),o[O]=[B,{extra:{12345:U}}]),F=B.length);return[2,fflate.zipSync(o,{level:0})]}})})}var qt=function(){function e(){}return e.Export=function(e,t,n){var r;if(void 0===t&&(t=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var o=t;t&&0!==t.length||(o=e.animations.map(function(e){return e.name}));for(var i=null,a=0,s=o;a<s.length;a++){var u=s[a],c=e.getAnimationRange(u);c&&(i=i?new g.AnimationRange("animation-range",Math.min(i.from,c.from),Math.max(i.to,c.to)):c)}if(!i&&(e.animations.length>0&&(i=e.getAnimationRange(e.animations[0].name)),!i))throw new Error("No animation range found in skeleton");for(var l=n||1/((null===(r=e.animations[0])||void 0===r?void 0:r.framePerSecond)||30),h=this._BuildBoneHierarchy(e,o),p=0,f=0,d=h;f<d.length;f++){var m=d[f];m.positionKeys.length>0&&(p=Math.max(p,m.positionKeys.length)),m.rotationKeys.length>0&&(p=Math.max(p,m.rotationKeys.length))}0===p&&(p=Math.floor((i.to-i.from)/l)+1);var x="";return x+="HIERARCHY\n",x+=this._ExportHierarchy(h,0),x+="MOTION\n",x+="Frames: ".concat(p,"\n"),(x+="Frame Time: ".concat(l.toFixed(6),"\n"))+this._ExportMotionData(h,p,0,o)},e._BuildBoneHierarchy=function(e,t){for(var n,r,o=new Map,i=[],a=0,s=e.bones;a<s.length;a++){var u={bone:h=s[a],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};o.set(h,u)}for(var c=0,l=e.bones;c<l.length;c++){var h=l[c];if(u=o.get(h),h.animations.length>0)for(var p=0,f=h.animations;p<f.length;p++){var d=f[p];t.includes(d.name)&&("position"===d.targetProperty?(u.hasPositionChannels=!0,(n=u.positionKeys).push.apply(n,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(r=u.rotationKeys).push.apply(r,d.getKeys())))}if(h.getParent()){var m=o.get(h.getParent());m&&m.children.push(u)}else i.push(u)}return i},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,i=e;o<i.length;o++){var a=i[o],s=a.bone;if(this._IsEndSite(a)){n+="".concat(r,"End Site\n"),n+="".concat(r,"{\n");var u=this._GetBoneOffset(s);n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),n+="".concat(r,"}\n")}else{n+="".concat(0===t?"ROOT":"".concat(r,"JOINT")," ").concat(s.name,"\n"),n+="".concat(r,"{\n"),u=this._GetBoneOffset(s),n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];a.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),a.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),a.children.length>0&&(n+=this._ExportHierarchy(a.children,t+1)),n+="".concat(r,"}\n")}}return n},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return g.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",i=0;i<t;i++){var a=[];this._CollectFrameValues(e,i+n,a,r),o+=a.map(function(e){return e.toFixed(6)}).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,i=e;o<i.length;o++){var a=i[o];if(!this._IsEndSite(a)){if(a.hasPositionChannels){var s=this._GetPositionAtFrameIndex(a.positionKeys,t);n.push(s.x,s.y,s.z)}if(a.hasRotationChannels){var u=this._GetRotationAtFrameIndex(a.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}a.children.length>0&&this._CollectFrameValues(a.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?g.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?g.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new g.Matrix;e.toRotationMatrix(t);var n,r,o,i=t.m,a=Math.sqrt(i[0]*i[0]+i[1]*i[1]);return a>g.Epsilon?(n=Math.atan2(i[6],i[10]),r=Math.atan2(-i[2],a),o=Math.atan2(i[1],i[0])):(n=Math.atan2(-i[9],i[5]),r=Math.atan2(-i[2],a),o=0),new g.Vector3(g.Tools.ToDegrees(n),g.Tools.ToDegrees(r),g.Tools.ToDegrees(o))},e}();function Gt(e){return"string"==typeof(null==e?void 0:e.name)}var Ht=Symbol("__xml:meta$__"),jt=Symbol("__xml:name$__");function Xt(e,t){var n,r=e.constructor;(null!==(n=r[Ht])&&void 0!==n?n:r[Ht]=[]).push(t)}function Qt(e){return function(t){t[jt]=e}}function Zt(){return function(e,t){return Xt(e,{kind:"none",prop:t,ignore:!0})}}function Yt(e){return function(t,n){return Xt(t,b({kind:"attr",prop:n},e))}}function Jt(e){return function(t,n){return Xt(t,b({kind:"elem",prop:n},e))}}function $t(e){var t,n;return null!==(n=null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Ht])&&void 0!==n?n:[]}function en(e){var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[jt])||void 0}function tn(e){return/^[A-Za-z_][A-Za-z0-9._-]*$/.test(e)}function nn(e){if(Gt(e))return e;var t=(null!=e?e:"").trim();if(!t)return{name:""};var n=t.indexOf(":");if(-1===n)return{name:t};if(-1!==t.indexOf(":",n+1))return{name:t};var r=t.slice(0,n),o=t.slice(n+1);return tn(r)&&tn(o)?{ns:r,name:o}:{name:t}}function rn(e,t){return t?"".concat(t,":").concat(e):e}var on=Object.freeze({eps:1e-6,maxDecimalsCap:15,trimTrailingZeros:!0,allowScientific:!1,snapNearZero:!0}),an=Object.freeze({number:on});function sn(e){var t,n,r,o,i,a,s=null!==(t=null==e?void 0:e.eps)&&void 0!==t?t:on.eps;return{eps:s,maxDecimalsCap:null!==(n=null==e?void 0:e.maxDecimalsCap)&&void 0!==n?n:on.maxDecimalsCap,trimTrailingZeros:null!==(r=null==e?void 0:e.trimTrailingZeros)&&void 0!==r?r:on.trimTrailingZeros,fixedDecimals:null==e?void 0:e.fixedDecimals,allowScientific:null!==(o=null==e?void 0:e.allowScientific)&&void 0!==o?o:on.allowScientific,snapNearZero:null!==(i=null==e?void 0:e.snapNearZero)&&void 0!==i?i:on.snapNearZero,zeroThreshold:null!==(a=null==e?void 0:e.zeroThreshold)&&void 0!==a?a:s,perAttributeEps:null==e?void 0:e.perAttributeEps}}function un(e){return{number:sn(null==e?void 0:e.number)}}var cn=function(){function e(e){if(this.o=e,this._o=e.number,!Number.isFinite(this._o.eps)||this._o.eps<=0)throw new Error("opts.eps must be a finite, positive number")}return e.prototype.toString=function(e){var t,n,r,o;if(!Number.isFinite(e))throw new Error("Cannot format non-finite number: ".concat(e));var i,a=this._o,s=this._clampInt(null!==(t=a.maxDecimalsCap)&&void 0!==t?t:15,0,20),u=null===(n=a.trimTrailingZeros)||void 0===n||n,c=null===(r=a.snapNearZero)||void 0===r||r,l=null!==(o=a.zeroThreshold)&&void 0!==o?o:a.eps,h=1/a.eps,p=Math.round(e*h)/h;if(Object.is(p,-0)&&(p=0),c&&Math.abs(p)<=l&&(p=0),i=void 0!==a.fixedDecimals?this._clampInt(a.fixedDecimals,0,s):this._clampInt(Math.ceil(-Math.log10(a.eps)),0,s),a.allowScientific,0===i)return String(Math.trunc(p));var f=p.toFixed(i);if(u&&void 0===a.fixedDecimals&&(f=f.replace(/(\.\d*?[1-9])0+$/,"$1").replace(/\.0+$/,"").replace(/\.$/,"")),/[eE]/.test(f))throw new Error("Scientific notation not allowed in XML output: ".concat(f));return f},e.prototype._clampInt=function(e,t,n){return Number.isFinite(e)?(e=Math.trunc(e),Math.max(t,Math.min(n,e))):t},e}();function ln(e){return e instanceof Date}function hn(e){return"string"==typeof e}function pn(e){return"number"==typeof e}function fn(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||ln(e)}function dn(e){return"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||ln(e)}var mn,gn=function(){function e(e,t){this._ns=new Map,this._prefixCount=0,this._builder=e,this._format=un(t),this._nFmt=new cn(this._format)}return e.prototype.withNamespace=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=0,r=e;n<r.length;n++){var o=r[n];this._assignNamespace(o)}return this},e.prototype.serialize=function(e,t){if(!(t=null!=t?t:en(e)))throw new Error("can not find name for given object");var n=nn(t);n.ns&&this._assignNamespace(n.ns,"xmlns"),this._gatherNamespaces(e,new WeakSet);for(var r=this._builder.ele(null,n.name),o=0,i=Array.from(this._ns.entries());o<i.length;o++){var a=i[o],s=a[0],u=a[1];r.att("xmlns",u,s)}this._writeObjectContent(r,e,(new WeakSet).add(e)),this._builder.end()},e.prototype._writeObject=function(e,t,n){if(!n.has(t))if(n.add(t),Array.isArray(t))for(var r=0,o=t;r<o.length;r++){var i=o[r];dn(i)||(hn(i)?this._builder.text(i):this._writeObject(e,i,n))}else{var a=en(t);if(a){var s=nn(a),u=this._getPrefix(s),c=rn(s.name,u);e.ele(null,c),this._writeObjectContent(e,t,n),this._builder.end()}}},e.prototype._getPrefix=function(e){if(e.ns){var t=this._ns.get(e.ns.toLowerCase());if("xmlns"!==t)return t}},e.prototype._writeObjectContent=function(e,t,n){for(var r,o,i,a=null!==(r=$t(t))&&void 0!==r?r:[],s=new Map,u=0,c=a;u<c.length;u++){var l=c[u],h=null!==(o=s.get(l.prop))&&void 0!==o?o:[];h.push(l),s.set(l.prop,h)}for(var p=Object.keys(t).sort(function(e,t){var n,r,o=(null!==(n=s.get(e))&&void 0!==n?n:[]).some(function(e){return"attr"===e.kind}),i=(null!==(r=s.get(t))&&void 0!==r?r:[]).some(function(e){return"attr"===e.kind});return o===i?0:o?-1:1}),f=0,d=p;f<d.length;f++){var m=d[f],g=t[m];if(null!=g){var x=s.get(m);if(x){var _=x.some(function(e){return!0===e.ignore||"none"===e.kind});if(_)continue;for(var v=0,T=x;v<T.length;v++){var y=null!==(i=(l=T[v]).name)&&void 0!==i?i:l.prop.toLowerCase();if(y&&"attr"===l.kind){var b=null;if(pn(g)&&this._nFmt&&(b=this._nFmt.toString(g)),l.formatter&&(b=new l.formatter(this._format).toString(g)),b=null!=b?b:g.toString()){var M=nn(y),w=this._getPrefix(M),A=rn(M.name,w);e.att(null,A,b)}}}}else dn(g)||(hn(g)?this._builder.text(g):this._writeObject(e,g,n))}}},e.prototype._gatherNamespaces=function(e,t){var n,r;if(!t.has(e))if(t.add(e),Array.isArray(e))for(var o=0,i=e;o<i.length;o++){var a=i[o];fn(a)||this._gatherNamespaces(a,t)}else{var s=en(e);s&&this._assignNamespace(s);for(var u=null!==(n=$t(e))&&void 0!==n?n:[],c=new Map,l=0,h=u;l<h.length;l++){var p=h[l],f=null!==(r=c.get(p.prop))&&void 0!==r?r:[];f.push(p),c.set(p.prop,f)}for(var d=[],m=0,g=Object.keys(e);m<g.length;m++){var x=g[m],_=e[x];if(null!=_){var v=c.get(x);if(v){var T=v.some(function(e){return!0===e.ignore||"none"===e.kind});if(T)continue;for(var y=0,b=v;y<b.length;y++)(p=b[y]).name&&this._assignNamespace(p.name)}d.push(_)}}for(var M=0,w=d;M<w.length;M++){var A=w[M];fn(A)||this._gatherNamespaces(A,t)}}},e.prototype._assignNamespace=function(e,t){var n=nn(e);if(null==n?void 0:n.ns){var r=n.ns.toLowerCase();this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r))}else"xmlns"===t&&(r=n.name.toLowerCase(),this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r)))},e.prototype._buildNsPrefix=function(e){var t,n=!1;do{t="ns".concat(this._prefixCount++);for(var r=0,o=Array.from(this._ns.values());r<o.length;r++)if(o[r]===t){n=!0;break}}while(n);return t},e}(),xn=function(){function e(){}return e.OpenTag="<",e.CloseTag=">",e.Slash="/",e.Question="?",e.Quote='"',e.Equal="=",e.Space=" ",e.Semicolon=":",e.Dec="<?xml",e.Xml="xml",e.Xmlns="xmlns",e.Xsi="xsi",e.VersionKeyword="version",e.EncodingKeyword="encoding",e.StandaloneKeyword="standalone",e}();!function(e){e[e.Declaration=0]="Declaration",e[e.Tag=1]="Tag",e[e.Attribute=2]="Attribute",e[e.Text=3]="Text"}(mn||(mn={}));var _n,vn,Tn=function(){function e(e){this._ctxStack=[],this._d=0,this._w=e}return e.prototype.dec=function(e,t,n){return this._w.write(xn.Dec),this._writeAttStr(xn.VersionKeyword,e),t&&this._writeAttStr(xn.EncodingKeyword,t),void 0!==n&&this._writeAttStr(xn.StandaloneKeyword,n?"yes":"no"),this._w.write(xn.Question,xn.CloseTag),this},e.prototype.att=function(e,t,n){var r=this._peekContext();if(!r)throw new Error("att() without open element");if(r.closed)throw new Error("att() after start tag closed for <".concat(r.name,">"));if(this._isXmlnsDecl(e,t)){if(t===xn.Xmlns)r.defaultNs=n,this._registerNamespace(r,"",n),this._writeAttStr(xn.Xmlns,n);else if(e)this._registerNamespace(r,t,n),this._writeAttStr("".concat(e,":").concat(t),n);else{var o=t.slice(6);this._registerNamespace(r,o,n),this._writeAttStr(t,n)}return r.lastToken=mn.Attribute,this}var i=t;if(e){var a=this._ensurePrefixDeclared(r,e);i="".concat(a,":").concat(t)}return r.lastToken=mn.Attribute,this._writeAttStr(i,n),this},e.prototype.ele=function(e,t){var n,r=this._peekContext();r&&this._closeOpenTagIfNeeded(r);var o=t;if(e){var i=null!==(n=this._lookupPrefix(e))&&void 0!==n?n:e;o="".concat(i,":").concat(t)}return this._pushContext(o,++this._d),this._w.write(xn.OpenTag,o),this},e.prototype.text=function(e){var t=this._peekContext();if(!t)throw new Error("text() without open element");return this._closeOpenTagIfNeeded(t),t.lastToken=mn.Text,this._w.write(this._escText(e)),this},e.prototype.end=function(){var e=this._popContext();return e&&(this._d--,e.closed?this._w.write(xn.OpenTag,xn.Slash,e.name,xn.CloseTag):this._w.write(xn.Slash,xn.CloseTag)),this},e.prototype._pushContext=function(t,n){var r=new e.Context(t,n);return this._ctxStack.push(r),r},e.prototype._popContext=function(){return this._ctxStack.pop()},e.prototype._peekContext=function(){return this._ctxStack[this._ctxStack.length-1]},Object.defineProperty(e.prototype,"_contextDepth",{get:function(){return this._ctxStack.length},enumerable:!1,configurable:!0}),e.prototype._writeAttStr=function(e,t){this._w.write(xn.Space,e,xn.Equal,xn.Quote,this._escAttr(t),xn.Quote)},e.prototype._lookupPrefix=function(e){var t,n=this._ctxStack.length-1;if(n>=0)do{var r=null===(t=this._ctxStack[n--].ns2prefix)||void 0===t?void 0:t.get(e);if(r)return r}while(n>=0)},e.prototype._escText=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")},e.prototype._escAttr=function(e){return this._escText(e).replace(/"/g,""").replace(/'/g,"'")},e.prototype._isXmlnsDecl=function(e,t){if(e)return e===xn.Xmlns;var n=t.length,r=xn.Xmlns.length;return n>=r&&t.startsWith(xn.Xmlns)&&(t.length==r||t[r]==xn.Semicolon)},e.prototype._registerNamespace=function(e,t,n){if(t===xn.Xml||t===xn.Xmlns)throw new Error("reserved prefix '".concat(t,"'"));var r=e.prefix2ns.get(t);if(r&&r!==n)throw new Error("prefix '".concat(t,"' already bound to a different namespace"));e.ns2prefix.get(n)||e.ns2prefix.set(n,t),e.prefix2ns.set(t,n)},e.prototype._allocPrefix=function(e){for(var t=1;;){var n="ns".concat(t++);if(!e.prefix2ns.has(n))return n}},e.prototype._ensurePrefixDeclared=function(e,t){var n=this._lookupPrefix(t);if(n)return n;if(e.closed)throw new Error("can not declare namespace after start tag closed for <".concat(e.name,">"));var r=this._allocPrefix(e);return this._writeAttStr("".concat(xn.Xmlns,":").concat(r),t),this._registerNamespace(e,r,t),r},e.prototype._closeOpenTagIfNeeded=function(e){e.closed||(this._w.write(xn.CloseTag),e.closed=!0)},e.Context=function(e,t){this.name="",this.closed=!1,this.lastToken=null,this.ns2prefix=new Map,this.prefix2ns=new Map,this.defaultNs=null,this.name=e,this.depth=t},e}(),yn=function(){function e(){this.count=0,this._chunks=[]}return e.prototype.write=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)return this;var n=e.join("");return this._chunks.push(n),this.count+=n.length,this},e.prototype.toString=function(){return this._chunks.join("")},e.prototype.clear=function(){this._chunks=[],this.count=0},e}(),bn=function(){function e(e,t){void 0===t&&(t={}),this._sink=e,this._opts=t,this.count=0,this._encoder=new TextEncoder,this._pending="",this._pendingChars=0}return e.prototype.write=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(0===t.length)return this;var r=t.join("");if(0===r.length)return this;this._pending+=r,this._pendingChars+=r.length;var o=null!==(e=this._opts.flushChars)&&void 0!==e?e:65536;return this._pendingChars>=o&&this.flush(),this},e.prototype.flush=function(){if(0===this._pendingChars)return this;var e=this._encoder.encode(this._pending);return this._sink.push(e),this.count+=e.length,this._pending="",this._pendingChars=0,this},e.prototype.finish=function(){this.flush(),this._sink.push(new Uint8Array(0),!0)},e.prototype.clear=function(){this._pending="",this._pendingChars=0,this.count=0},e}(),Mn="http://schemas.microsoft.com/3dmanufacturing/core/2015/02",wn="http://schemas.microsoft.com/3dmanufacturing/trianglesets/2021/07";!function(e){e.micron="micron",e.millimeter="millimeter",e.centimeter="centimeter",e.inch="inch",e.foot="foot",e.meter="meter"}(_n||(_n={})),function(e){e.model="model",e.solidsupport="solidsupport",e.support="support",e.surface="surface",e.other="other"}(vn||(vn={}));var An,Rn="http://schemas.openxmlformats.org/package/2006/content-types",Cn="http://schemas.openxmlformats.org/package/2006/relationships";!function(e){e.Relationships="application/vnd.openxmlformats-package.relationships+xml",e.Model="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",e.Materials="application/vnd.ms-package.3dmanufacturing-material+xml",e.Colors="application/vnd.ms-package.3dmanufacturing-colors+xml",e.Texture="application/vnd.ms-package.3dmanufacturing-texture+xml",e.Texture2D="application/vnd.ms-package.3dmanufacturing-texture2d+xml",e.Production="application/vnd.ms-package.3dmanufacturing-production+xml",e.Slice="application/vnd.ms-package.3dmanufacturing-slice+xml",e.BeamLattice="application/vnd.ms-package.3dmanufacturing-beamlattice+xml",e.SecureContent="application/vnd.ms-package.3dmanufacturing-securecontent+xml",e.Png="image/png",e.Jpeg="image/jpeg",e.Tiff="image/tiff",e.Xml="application/xml"}(An||(An={}));var En="_rels/",In="3D/",Sn="3dmodel.model",Vn=".rels",Fn="[Content_Types].xml",On=function(){function e(){}return e.IsKnown=function(t){return e.Known.has(t)},e.IsThreeDimModel=function(t){return t===e.ThreeDimModel},e.ThreeDimModel="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel",e.Thumbnail="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",e.PrintTicket="http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket",e.MustPreserve="http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve",e.Known=new Set([e.ThreeDimModel,e.Thumbnail,e.PrintTicket,e.MustPreserve]),e}(),Bn=function(){function e(){this.items=[]}return M([Qt({ns:Rn,name:"Types"})],e)}(),Nn=function(){function e(e,t){this.ext=e,this.ct=t}return M([Yt({name:{ns:Rn,name:"Extension"}})],e.prototype,"ext",void 0),M([Yt({name:{ns:Rn,name:"ContentType"}})],e.prototype,"ct",void 0),M([Qt({ns:Rn,name:"Default"})],e)}(),Pn=function(){function e(){this.items=[]}return M([Qt({ns:Cn,name:"Relationships"})],e)}(),Un=function(){function e(e,t,n){this.id=e,this.type=t,this.target=n}return M([Yt({name:"Id"})],e.prototype,"id",void 0),M([Yt({name:"Type"})],e.prototype,"type",void 0),M([Yt({name:"Target"})],e.prototype,"target",void 0),M([Qt({ns:Cn,name:"Relationship"})],e)}(),kn=function(e,t,n){this.contentTypes=e,this.relationships=t,this.model=n},Dn=function(){function e(e){this.values=e}return e.Zero=function(){return new e([0,0,0,0,0,0,0,0,0,0,0,0])},e.prototype.toString=function(){return this.values.join(" ")},e}(),Ln=function(){function e(e){this.o=e,this._f=new cn(e)}return e.prototype.toString=function(e){var t=this;return e.values.map(function(e){return t._f.toString(e)}).join(" ")},e}(),zn=function(){function e(){this.unit=_n.millimeter}return e.KnownMeta=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate","Application"],M([Yt({name:"unit"})],e.prototype,"unit",void 0),M([Yt({name:"requiredextensions"})],e.prototype,"requiredextensions",void 0),M([Yt({name:"recommendedextensions"})],e.prototype,"recommendedextensions",void 0),M([Qt({ns:Mn,name:"model"})],e)}(),Kn=function(){function e(e,t,n,r){this.name=e,this.value=t,this.preserve=n,this.type=r}return M([Yt({name:"name"})],e.prototype,"name",void 0),M([Yt({name:"preserve"})],e.prototype,"preserve",void 0),M([Yt({name:"type"})],e.prototype,"type",void 0),M([Qt({ns:Mn,name:"meta"})],e)}(),Wn=function(){function e(){this.metadata=[]}return M([Qt({ns:Mn,name:"metadatagroup"})],e)}(),qn=function(){function e(){this.object=[]}return M([Qt({ns:Mn,name:"resources"})],e)}(),Gn=function(){function e(e,t){void 0===t&&(t=vn.model),this.id=e,this.type=t}return M([Yt({name:"id"})],e.prototype,"id",void 0),M([Yt({name:"type"})],e.prototype,"type",void 0),M([Yt({name:"thumbnail"})],e.prototype,"thumbnail",void 0),M([Yt({name:"partnumber"})],e.prototype,"partnumber",void 0),M([Yt({name:"name"})],e.prototype,"name",void 0),M([Yt({name:"pid"})],e.prototype,"pid",void 0),M([Yt({name:"pindex"})],e.prototype,"pindex",void 0),M([Qt({ns:Mn,name:"object"})],e)}(),Hn=function(){function e(e,t){this.vertices=null!=e?e:new jn,this.triangles=null!=t?t:new Qn}return M([Qt({ns:Mn,name:"mesh"})],e)}(),jn=function(){function e(){this.vertex=[]}return M([Qt({ns:Mn,name:"vertices"})],e)}(),Xn=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=0),void 0===n&&(n=0),this.x=e,this.y=t,this.z=n}return M([Yt({name:"x"})],e.prototype,"x",void 0),M([Yt({name:"y"})],e.prototype,"y",void 0),M([Yt({name:"z"})],e.prototype,"z",void 0),M([Qt({ns:Mn,name:"vertex"})],e)}(),Qn=function(){function e(){this.triangle=[]}return M([Qt({ns:Mn,name:"triangles"})],e)}(),Zn=function(){function e(e,t,n){this.v1=e,this.v2=t,this.v3=n}return M([Yt({name:"v1"})],e.prototype,"v1",void 0),M([Yt({name:"v2"})],e.prototype,"v2",void 0),M([Yt({name:"v3"})],e.prototype,"v3",void 0),M([Yt({name:"p1"})],e.prototype,"p1",void 0),M([Yt({name:"p2"})],e.prototype,"p2",void 0),M([Yt({name:"p3"})],e.prototype,"p3",void 0),M([Yt({name:"pid"})],e.prototype,"pid",void 0),M([Qt({ns:Mn,name:"triangle"})],e)}(),Yn=function(){function e(){this.component=[]}return M([Qt({ns:Mn,name:"components"})],e)}(),Jn=function(){function e(e,t){this.objectid=e,this.transform=t}return M([Yt({name:"objectid"})],e.prototype,"objectid",void 0),M([Yt({name:"transform",formatter:Ln})],e.prototype,"transform",void 0),M([Qt({ns:Mn,name:"component"})],e)}(),$n=function(){function e(e){this.base=[],this.id=e}return M([Yt({name:"id"})],e.prototype,"id",void 0),M([Qt({ns:Mn,name:"basematerials"})],e)}(),er=function(){function e(e,t){this.name=e,this.displaycolor=t}return M([Yt({name:"name"})],e.prototype,"name",void 0),M([Yt({name:"displaycolor"})],e.prototype,"displaycolor",void 0),M([Qt({ns:Mn,name:"base"})],e)}(),tr=function(){function e(){this.item=[]}return M([Qt({ns:Mn,name:"build"})],e)}(),nr=function(){function e(e,t,n){this.objectid=e,this.transform=t,this.partnumber=n}return M([Yt({name:"objectid"})],e.prototype,"objectid",void 0),M([Yt({name:"transform",formatter:Ln})],e.prototype,"transform",void 0),M([Yt({name:"partnumber"})],e.prototype,"partnumber",void 0),M([Qt({ns:Mn,name:"item"})],e)}(),rr=function(){function e(e,t){this._object=new Gn(e,t)}return e.prototype.withName=function(e){return this._object.name=e,this},e.prototype.withThumbnail=function(e){return this._object.thumbnail=e,this},e.prototype.withProperty=function(e,t){return void 0===t&&(t=0),this._object.pid=e,this._object.id=t,this},e.prototype.build=function(){return this._object},e.prototype.reset=function(e,t){this._object=new Gn(e,t)},e}(),or=function(e){function t(t,n){void 0===n&&(n=vn.model);var r=e.call(this,t,n)||this;return r._object.content=new Yn,r}return y(t,e),t.prototype.withComponent=function(e,t){return this._object.content.component.push(new Jn(e,t)),this},t}(rr),ir=function(e){function t(t){return e.call(this,t,vn.model)||this}return y(t,e),t.prototype.withPostProcessHandlers=function(e,t){return this._vh=e,this._th=t,this},t.prototype.withData=function(e){return this._object.content=this._buildMesh(e),this},t.prototype.withMaterial=function(e,t){return this._object.pid=e,this._object.pindex=t,this},t.prototype._buildMesh=function(e){var t=this._buildVertices(e.positions),n=this._buildTriangle(e.indices);return new Hn(t,n)},t.prototype._buildVertices=function(e){var t=new jn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Xn(r,o,i);this._vh&&(a=this._vh(a)),t.vertex.push(a)}return t},t.prototype._buildTriangle=function(e){var t=new Qn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Zn(r,o,i);this._th&&(a=this._th(a)),t.triangle.push(a)}return t},t}(rr),ar=function(){function e(e){this._m=new $n(e)}return e.prototype.withColor=function(e,t){var n;this._m.base=null!==(n=this._m.base)&&void 0!==n?n:[];var r=this._m.base.find(function(t){return t.name.toLowerCase()===e.toLowerCase()});return r?(r.displaycolor=this._rgbaToHex(t),this):(r=new er(e,this._rgbaToHex(t)),this._m.base.push(r),this)},e.prototype.build=function(){return this._m},e.prototype._rgbaToHex=function(e){var t=function(e){return Math.round(Math.min(255,Math.max(0,255*Math.pow(e,1/2.2))))},n=t(e.r).toString(16).padStart(2,"0").toUpperCase(),r=t(e.g).toString(16).padStart(2,"0").toUpperCase(),o=t(e.b).toString(16).padStart(2,"0").toUpperCase();if("number"==typeof e.a){var i=Math.round(Math.min(255,Math.max(0,255*e.a))).toString(16).padStart(2,"0").toUpperCase();return"#".concat(n).concat(r).concat(o).concat(i)}return"#".concat(n).concat(r).concat(o)},e}(),sr=function(){function e(){this._model=new zn,this._objects=new Map}return e.prototype.withMetaData=function(e,t,n,r){return this._model.metadata||(this._model.metadata=new Array),this._model.metadata.push(new Kn(e,t,n,r)),this},e.prototype.withMaterial=function(e){var t,n;return e instanceof ar&&(e=e.build()),e&&(this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new qn,this._model.resources.basematerials=null!==(n=this._model.resources.basematerials)&&void 0!==n?n:[],this._model.resources.basematerials.push(e)),this},e.prototype.withMesh=function(e){var t;return e instanceof ir&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new qn,this._model.resources.object.push(e),this},e.prototype.withComponents=function(e){var t;return e instanceof or&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new qn,this._model.resources.object.push(e),this},e.prototype.withBuild=function(e,t,n){var r,o;return this._model.build=null!==(r=this._model.build)&&void 0!==r?r:new tr,null===(o=this._model.build.item)||void 0===o||o.push(new nr(e,t,n)),this},e.prototype.withUnit=function(e){return this._model.unit=e,this},e.prototype.reset=function(){return this._model=new zn,this._objects=new Map,this},e.prototype.build=function(){var e,t,n,r;if(!(null===(t=null===(e=this._model.resources)||void 0===e?void 0:e.object)||void 0===t?void 0:t.length))throw new Error("Invalid state: resources MUST be defined ");if(!(null===(r=null===(n=this._model.build)||void 0===n?void 0:n.item)||void 0===r?void 0:r.length))throw new Error("Invalid state: Build MUST be defined ");return this._model},e.KnownMetaSet=new Set(zn.KnownMeta.map(function(e){return e.toLowerCase()})),e}(),ur=function(){function e(){}return e.prototype.withContentType=function(e){this._cts||(this._cts=new Bn);var t=this._cts.items;return t.some(function(t){return t.ext===e.ext&&t.ct===e.ct})||t.push(e),this},e.prototype.withRelationship=function(e){this._rs||(this._rs=new Pn);var t=this._rs.items;return t.some(function(t){return t.id===e.id})||t.push(e),this.withContentType(new Nn("rels",An.Relationships)),this},e.prototype.withModel=function(e){return e instanceof sr&&(e=e.build()),this._m=e,this.withContentType(new Nn("model",An.Model)),this},e.prototype.build=function(){if(!this._m)throw new Error("Invalid state: you Must provide at least a model.");var e="".concat(In).concat(Sn);if(!this._rs){var t="/".concat(e);this.withRelationship(new Un("rel".concat(0),On.ThreeDimModel,t))}return new kn(this._cts,this._rs,this._m)},e}(),cr=function(){function e(e){this._o=e}return Object.defineProperty(e.prototype,"options",{get:function(){return this._o},enumerable:!1,configurable:!0}),e.prototype.serializeAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u;return A(this,function(c){switch(c.label){case 0:return[4,this.ensureZipLibReadyAsync()];case 1:if(!(n=c.sent()))return[2];if(r=n.Zip,o=n.ZipDeflate,!r||!o)throw new Error("fflate Zip / ZipDeflate not available");return i=function(e){return{push:function(t,n){return e.push(t,n)}}},a=function(e,t,n){var r=new o(t,{level:6});e.add(r);var a=i(r),s=new bn(a),u=new Tn(s).dec("1.0","UTF-8");new gn(u).serialize(n),s.finish()},(s=this.toDocument.apply(this,t))?(u=new r(e),a(u,Fn,s.contentTypes),a(u,"".concat(En).concat(Vn),s.relationships),a(u,"".concat(In).concat(Sn),s.model),u.end(),[2]):[2]}})})},e.prototype.toDocument=function(){for(var e,t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o=(new sr).withUnit(null!==(t=null===(e=this._o)||void 0===e?void 0:e.unit)&&void 0!==t?t:_n.millimeter);if(this.options.metadata)for(var i in this.options.metadata)o.withMetaData(i,this.options.metadata[i]);return(new ur).withModel(this.toModel.apply(this,R([o],n,!1))).build()},e}(),lr=function(){function e(){}return e.SerializeToMemoryAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return A(this,function(l){switch(l.label){case 0:return n=new Array,r=0,o=function(e,t,o){n.push(t),r+=t.length},[4,e.serializeAsync.apply(e,R([o],t,!1))];case 1:if(l.sent(),!r)return[2,void 0];for(i=new Uint8Array(r),a=0,s=0,u=n;s<u.length;s++)c=u[s],i.set(c,a),a+=c.length;return[2,i]}})})},e}(),hr=function(){function e(){}return e.FFLATEUrl="https://unpkg.com/fflate@0.8.2",e}(),pr=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=Number.MIN_SAFE_INTEGER),void 0===n&&(n=1),this._from=e,this._to=t,this._step=n,this._i=e}return e.prototype.next=function(){if(this._i<this._to)throw new Error("ST_ResourceID out of bound");var e=this._i;return this._i+=this._step,e},e.prototype.reset=function(){return this._i=this._from,this},e}(),fr=function(e){function t(n){return void 0===n&&(n={}),e.call(this,b(b({},t.DefaultOptions),n))||this}return y(t,e),t.prototype.toModel=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];t=t.filter(function(e){return e instanceof g.Mesh||e instanceof g.InstancedMesh});for(var r=new pr,o=e,i=new Map,a=this.options.exportInstances?[]:null,s=0;s<t.length;s++){var u=t[s];if(u instanceof g.InstancedMesh)null==a||a.push(u);else{var c=u.name||"mesh".concat(s),l=u.getWorldMatrix(),h=this._handleBabylonTo3mfMatrixTransformToRef(l,Dn.Zero());if(void 0!==(A=u.subMeshes))for(var p=1==A.length,f=0;f<A.length;f++){var d=A[f],m=this._extractSubMesh(u,d);if(m){var x=p?"".concat(c):"".concat(c,"_").concat(f),_=new ir(r.next()).withData(m).withName(x).build();o.withMesh(_),o.withBuild(_.id,h),i.set(d,_)}}}}if(a&&a.length)for(var v=this._groupBy(a,function(e){return e.sourceMesh}),T=0,y=Array.from(v.entries());T<y.length;T++){var b=y[T],M=b[0],w=b[1];if(w&&w.length)for(s=0;s<w.length;s++){l=w[s].getWorldMatrix();var A=M.subMeshes;for(f=0;f<A.length;f++){d=A[f];var R=i.get(d);R&&o.withBuild(R.id,this._handleBabylonTo3mfMatrixTransformToRef(l,Dn.Zero()))}}}return o.build()},t.prototype.ensureZipLibReadyAsync=function(){return w(this,void 0,void 0,function(){var e=this;return A(this,function(t){switch(t.label){case 0:return this._fflateReadyPromise?[4,this._fflateReadyPromise]:[3,2];case 1:case 3:return[2,t.sent()];case 2:return this._fflateReadyPromise=w(e,void 0,void 0,function(){var e;return A(this,function(t){switch(t.label){case 0:return(e=globalThis).fflate?[3,2]:[4,g.Tools.LoadScriptAsync(hr.FFLATEUrl)];case 1:t.sent(),t.label=2;case 2:return[2,e.fflate]}})}),[4,this._fflateReadyPromise]}})})},t.prototype._extractSubMesh=function(e,n){var r=e.getIndices();if(r){var o=e.getVerticesData(t._PositionKind);if(o){if(0==n.indexStart&&n.indexCount==r.length)return{positions:o,indices:r};for(var i=n.indexStart,a=new Map,s=[],u=new Uint32Array(n.indexCount),c=0;c<n.indexCount;c++){var l=r[i+c],h=a.get(l);if(void 0===h){h=a.size,a.set(l,h);var p=3*l;s.push(o[p],o[p+1],o[p+2])}u[c]=h}return{positions:new Float32Array(s),indices:u}}}},t.prototype._groupBy=function(e,t){for(var n=new Map,r=0,o=e;r<o.length;r++){var i=o[r],a=t(i),s=n.get(a);s?s.push(i):n.set(a,[i])}return n},t.prototype._handleBabylonTo3mfMatrixTransformToRef=function(e,n){var r=e.multiplyToRef(t._R_BJS_TO_3MF,g.Matrix.Zero()).m;return n.values=[r[0],r[1],r[2],r[4],r[5],r[6],r[8],r[9],r[10],r[12],r[13],r[14]],n},t.DefaultOptions={unit:_n.meter,exportInstances:!1},t._PositionKind="position",t._R_BJS_TO_3MF=g.Matrix.RotationX(Math.PI/2).multiply(g.Matrix.Scaling(1,-1,1)),t}(cr),dr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==dr)for(var mr in f)dr.BABYLON[mr]=f[mr];var gr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==gr){gr.BABYLON=gr.BABYLON||{};var xr=gr.BABYLON;xr.GLTF2=xr.GLTF2||{},xr.GLTF2.Exporter=xr.GLTF2.Exporter||{},xr.GLTF2.Exporter.Extensions=xr.GLTF2.Exporter.Extensions||{};var _r=[];for(var vr in a)xr[vr]=a[vr],_r.push(vr);for(var vr in s)xr[vr]=s[vr],_r.push(vr);for(var vr in u)xr[vr]=u[vr],_r.push(vr);for(var vr in c)xr.GLTF2.Exporter.Extensions[vr]=c[vr],_r.push(vr);for(var vr in l)_r.indexOf(vr)>-1||(xr.GLTF2.Exporter[vr]=l[vr])}var Tr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Tr)for(var yr in i)Tr.BABYLON[yr]=i[yr];var br=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==br)for(var Mr in h)br.BABYLON[Mr]=h[Mr];var wr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==wr)for(var Ar in p)wr.BABYLON[Ar]=p[Ar];var Rr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Rr){var Cr=[];for(var Er in d)Cr.indexOf(Er)>-1||(Rr.BABYLON[Er]=d[Er],Cr.push(Er))}const Ir=m;return o.default})());
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,e=>(()=>{"use strict";var t={597(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};r.d(o,{default:()=>Ir});var i={};r.r(i),r.d(i,{OBJExport:()=>x});var a={};r.r(a),r.d(a,{__IGLTFExporterExtension:()=>_});var s={};r.r(s),r.d(s,{GLTFData:()=>v});var u={};r.r(u),r.d(u,{GLTF2Export:()=>de});var c={};r.r(c),r.d(c,{EXT_lights_area:()=>Se,EXT_mesh_gpu_instancing:()=>xe,EXT_texture_avif:()=>Et,EXT_texture_webp:()=>Ct,KHR_draco_mesh_compression:()=>Te,KHR_lights_punctual:()=>Ae,KHR_materials_anisotropy:()=>Be,KHR_materials_clearcoat:()=>Ue,KHR_materials_coat:()=>Ke,KHR_materials_diffuse_roughness:()=>_t,KHR_materials_diffuse_transmission:()=>je,KHR_materials_dispersion:()=>Xe,KHR_materials_emissive_strength:()=>Ze,KHR_materials_fuzz:()=>at,KHR_materials_ior:()=>Je,KHR_materials_iridescence:()=>et,KHR_materials_openpbr:()=>Tt,KHR_materials_sheen:()=>nt,KHR_materials_specular:()=>ut,KHR_materials_transmission:()=>lt,KHR_materials_unlit:()=>ft,KHR_materials_volume:()=>dt,KHR_materials_volume_scatter:()=>gt,KHR_texture_basisu:()=>wt,KHR_texture_transform:()=>bt});var l={};r.r(l),r.d(l,{EXT_lights_area:()=>Se,EXT_mesh_gpu_instancing:()=>xe,EXT_texture_avif:()=>Et,EXT_texture_webp:()=>Ct,GLTF2Export:()=>de,GLTFData:()=>v,KHR_draco_mesh_compression:()=>Te,KHR_lights_punctual:()=>Ae,KHR_materials_anisotropy:()=>Be,KHR_materials_clearcoat:()=>Ue,KHR_materials_coat:()=>Ke,KHR_materials_diffuse_roughness:()=>_t,KHR_materials_diffuse_transmission:()=>je,KHR_materials_dispersion:()=>Xe,KHR_materials_emissive_strength:()=>Ze,KHR_materials_fuzz:()=>at,KHR_materials_ior:()=>Je,KHR_materials_iridescence:()=>et,KHR_materials_openpbr:()=>Tt,KHR_materials_sheen:()=>nt,KHR_materials_specular:()=>ut,KHR_materials_transmission:()=>lt,KHR_materials_unlit:()=>ft,KHR_materials_volume:()=>dt,KHR_materials_volume_scatter:()=>gt,KHR_texture_basisu:()=>wt,KHR_texture_transform:()=>bt,_ConvertToGLTFPBRMetallicRoughness:()=>N,_SolveMetallic:()=>O});var h={};r.r(h),r.d(h,{STLExport:()=>It});var f={};r.r(f),r.d(f,{USDZExportAsync:()=>Kt});var p={};r.r(p),r.d(p,{BVHExporter:()=>qt});var d={};r.r(d),r.d(d,{AbstractThreeMfSerializer:()=>cr,ContentTypeFileName:()=>Fn,DefaultXmlSerializerFormatOptions:()=>an,DefaultXmlSerializerNumberOptions:()=>on,GetXmlFieldMeta:()=>$t,GetXmlName:()=>en,IsQualifiedName:()=>Gt,Known3mfRelationshipTypes:()=>Bn,KnownI3mfContentType:()=>An,Matrix3d:()=>Wn,MatrixFormatter:()=>Dn,ModelFileName:()=>Sn,NumberFormatter:()=>cn,Object3dDirName:()=>In,OpenXmlContentTypesNamespace:()=>Cn,OpenXmlRelationshipsNamespace:()=>Rn,RelationshipDirName:()=>En,RelationshipFileName:()=>Vn,ResolveFormatOptions:()=>un,ResolveNumberOptions:()=>sn,ST_ObjectType:()=>vn,ST_Unit:()=>_n,StringXmlWriter:()=>yn,ThreeDimModelNamespace:()=>Mn,ThreeMf:()=>lr,ThreeMfBase:()=>er,ThreeMfBaseMaterials:()=>$n,ThreeMfBuild:()=>tr,ThreeMfComponent:()=>Jn,ThreeMfComponents:()=>Yn,ThreeMfComponentsBuilder:()=>or,ThreeMfContentType:()=>Nn,ThreeMfContentTypes:()=>On,ThreeMfDocument:()=>kn,ThreeMfDocumentBuilder:()=>ur,ThreeMfItem:()=>nr,ThreeMfMaterialBuilder:()=>ar,ThreeMfMesh:()=>jn,ThreeMfMeshBuilder:()=>ir,ThreeMfMeta:()=>Ln,ThreeMfMetadataGroup:()=>Kn,ThreeMfModel:()=>zn,ThreeMfModelBuilder:()=>sr,ThreeMfObject:()=>Gn,ThreeMfObjectBuilder:()=>rr,ThreeMfRelationship:()=>Un,ThreeMfRelationships:()=>Pn,ThreeMfResources:()=>qn,ThreeMfSerializer:()=>pr,ThreeMfSerializerGlobalConfiguration:()=>hr,ThreeMfTriangle:()=>Zn,ThreeMfTriangles:()=>Qn,ThreeMfVertex:()=>Xn,ThreeMfVertices:()=>Hn,ToQualifiedString:()=>rn,TokenType:()=>mn,TriangleSetsNamespace:()=>wn,Utf8XmlWriterToBytes:()=>bn,XmlAttr:()=>Yt,XmlBuilder:()=>Tn,XmlElem:()=>Jt,XmlIgnore:()=>Zt,XmlName:()=>Qt,XmlNameToParts:()=>nn,XmlSerializer:()=>gn});var m={};r.r(m),r.d(m,{AbstractThreeMfSerializer:()=>cr,BVHExporter:()=>qt,ContentTypeFileName:()=>Fn,DefaultXmlSerializerFormatOptions:()=>an,DefaultXmlSerializerNumberOptions:()=>on,EXT_lights_area:()=>Se,EXT_mesh_gpu_instancing:()=>xe,EXT_texture_avif:()=>Et,EXT_texture_webp:()=>Ct,GLTF2Export:()=>de,GLTFData:()=>v,GetXmlFieldMeta:()=>$t,GetXmlName:()=>en,IsQualifiedName:()=>Gt,KHR_draco_mesh_compression:()=>Te,KHR_lights_punctual:()=>Ae,KHR_materials_anisotropy:()=>Be,KHR_materials_clearcoat:()=>Ue,KHR_materials_coat:()=>Ke,KHR_materials_diffuse_roughness:()=>_t,KHR_materials_diffuse_transmission:()=>je,KHR_materials_dispersion:()=>Xe,KHR_materials_emissive_strength:()=>Ze,KHR_materials_fuzz:()=>at,KHR_materials_ior:()=>Je,KHR_materials_iridescence:()=>et,KHR_materials_openpbr:()=>Tt,KHR_materials_sheen:()=>nt,KHR_materials_specular:()=>ut,KHR_materials_transmission:()=>lt,KHR_materials_unlit:()=>ft,KHR_materials_volume:()=>dt,KHR_materials_volume_scatter:()=>gt,KHR_texture_basisu:()=>wt,KHR_texture_transform:()=>bt,Known3mfRelationshipTypes:()=>Bn,KnownI3mfContentType:()=>An,Matrix3d:()=>Wn,MatrixFormatter:()=>Dn,ModelFileName:()=>Sn,NumberFormatter:()=>cn,OBJExport:()=>x,Object3dDirName:()=>In,OpenXmlContentTypesNamespace:()=>Cn,OpenXmlRelationshipsNamespace:()=>Rn,RelationshipDirName:()=>En,RelationshipFileName:()=>Vn,ResolveFormatOptions:()=>un,ResolveNumberOptions:()=>sn,STLExport:()=>It,ST_ObjectType:()=>vn,ST_Unit:()=>_n,StringXmlWriter:()=>yn,ThreeDimModelNamespace:()=>Mn,ThreeMf:()=>lr,ThreeMfBase:()=>er,ThreeMfBaseMaterials:()=>$n,ThreeMfBuild:()=>tr,ThreeMfComponent:()=>Jn,ThreeMfComponents:()=>Yn,ThreeMfComponentsBuilder:()=>or,ThreeMfContentType:()=>Nn,ThreeMfContentTypes:()=>On,ThreeMfDocument:()=>kn,ThreeMfDocumentBuilder:()=>ur,ThreeMfItem:()=>nr,ThreeMfMaterialBuilder:()=>ar,ThreeMfMesh:()=>jn,ThreeMfMeshBuilder:()=>ir,ThreeMfMeta:()=>Ln,ThreeMfMetadataGroup:()=>Kn,ThreeMfModel:()=>zn,ThreeMfModelBuilder:()=>sr,ThreeMfObject:()=>Gn,ThreeMfObjectBuilder:()=>rr,ThreeMfRelationship:()=>Un,ThreeMfRelationships:()=>Pn,ThreeMfResources:()=>qn,ThreeMfSerializer:()=>pr,ThreeMfSerializerGlobalConfiguration:()=>hr,ThreeMfTriangle:()=>Zn,ThreeMfTriangles:()=>Qn,ThreeMfVertex:()=>Xn,ThreeMfVertices:()=>Hn,ToQualifiedString:()=>rn,TokenType:()=>mn,TriangleSetsNamespace:()=>wn,USDZExportAsync:()=>Kt,Utf8XmlWriterToBytes:()=>bn,XmlAttr:()=>Yt,XmlBuilder:()=>Tn,XmlElem:()=>Jt,XmlIgnore:()=>Zt,XmlName:()=>Qt,XmlNameToParts:()=>nn,XmlSerializer:()=>gn,_ConvertToGLTFPBRMetallicRoughness:()=>N,_SolveMetallic:()=>O,__IGLTFExporterExtension:()=>_});var g=r(597),x=function(){function e(){}return e.OBJ=function(e,t,n,r){var o=[],i=1,a=1;t&&(n||(n="mat"),o.push("mtllib "+n+".mtl"));for(var s=0;s<e.length;s++){var u=e[s],c=u.name||"mesh".concat(s,"}");o.push("o ".concat(c));var l=null;if(r){var h=u.computeWorldMatrix(!0);l=new g.Matrix,h.invertToRef(l),u.bakeTransformIntoVertices(h)}if(t){var f=u.material;f&&o.push("usemtl "+f.id)}var p=u.geometry;if(p){var d=p.getVerticesData("position"),m=p.getVerticesData("normal"),x=p.getVerticesData("uv"),_=p.getIndices(),v=0,T=0;if(d&&_){for(var y=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<d.length;b+=3)o.push("v "+d[b]*y+" "+d[b+1]+" "+d[b+2]),v++;if(null!=m)for(b=0;b<m.length;b+=3)o.push("vn "+m[b]*y+" "+m[b+1]+" "+m[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)o.push("vt "+x[b]+" "+x[b+1]),T++;var M=["","",""],w=(u.material||u.getScene().defaultMaterial)._getEffectiveOrientation(u)===g.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=w[0],C=w[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+i),String(_[b+A]+i),String(_[b+C]+i)],E=[String(_[b]+a),String(_[b+A]+a),String(_[b+C]+a)],I=R,S=null!=x?E:M,V=null!=m?R:M;o.push("f "+I[0]+"/"+S[0]+"/"+V[0]+" "+I[1]+"/"+S[1]+"/"+V[1]+" "+I[2]+"/"+S[2]+"/"+V[2])}r&&l&&u.bakeTransformIntoVertices(l),i+=v,a+=T}else g.Tools.Warn("There are no position vertices or indices on the mesh!")}else g.Tools.Warn("No geometry is present on the mesh")}return o.join("\n")},e.MTL=function(e){var t=[],n=e.material;return t.push("newmtl mat1"),t.push(" Ns "+n.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+n.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+n.ambientColor.r.toFixed(4)+" "+n.ambientColor.g.toFixed(4)+" "+n.ambientColor.b.toFixed(4)),t.push(" Kd "+n.diffuseColor.r.toFixed(4)+" "+n.diffuseColor.g.toFixed(4)+" "+n.diffuseColor.b.toFixed(4)),t.push(" Ks "+n.specularColor.r.toFixed(4)+" "+n.specularColor.g.toFixed(4)+" "+n.specularColor.b.toFixed(4)),t.push(" Ke "+n.emissiveColor.r.toFixed(4)+" "+n.emissiveColor.g.toFixed(4)+" "+n.emissiveColor.b.toFixed(4)),n.ambientTexture&&t.push(" map_Ka "+n.ambientTexture.name),n.diffuseTexture&&t.push(" map_Kd "+n.diffuseTexture.name),n.specularTexture&&t.push(" map_Ks "+n.specularTexture.name),n.bumpTexture&&t.push(" map_bump -imfchan z "+n.bumpTexture.name),n.opacityTexture&&t.push(" map_d "+n.opacityTexture.name),t.join("\n")},e}(),_=0,v=function(){function e(){this.files={}}return Object.defineProperty(e.prototype,"glTFFiles",{get:function(){return this.files},enumerable:!1,configurable:!0}),e.prototype.downloadFiles=function(){for(var e in this.files){var t=this.files[e],n=new Blob([t],{type:(0,g.GetMimeType)(e)});g.Tools.Download(n,e)}},e}(),T=function(e,t){return T=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},T(e,t)};function y(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}T(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var b=function(){return b=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},b.apply(this,arguments)};function M(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function w(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}u((r=r.apply(e,t||[])).next())})}function A(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function C(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var R=1e-6,E=new g.Color3(.04,.04,.04),I=1024,S=g.Color3.White(),V=g.Color3.BlackReadOnly;function F(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function B(e){return w(this,void 0,void 0,function(){var t,n,r,o;return A(this,function(i){switch(i.label){case 0:if(!(t=e.getInternalTexture())||1!==t.source)return[2,null];if(t.invertY)return[2,null];n=t._buffer,o=e.mimeType,i.label=1;case 1:return i.trys.push([1,12,,13]),n?[3,3]:[4,g.Tools.LoadFileAsync(t.url)];case 2:return r=i.sent(),o=(0,g.GetMimeType)(t.url)||o,[3,11];case 3:return ArrayBuffer.isView(n)?(r=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),[3,11]):[3,4];case 4:return n instanceof ArrayBuffer?(r=n,[3,11]):[3,5];case 5:return n instanceof Blob?[4,n.arrayBuffer()]:[3,7];case 6:return r=i.sent(),o=n.type||o,[3,11];case 7:return"string"!=typeof n?[3,9]:[4,g.Tools.LoadFileAsync(n)];case 8:return r=i.sent(),o=(0,g.GetMimeType)(n)||o,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&n instanceof HTMLImageElement?[4,g.Tools.LoadFileAsync(n.src)]:[3,11];case 10:r=i.sent(),o=(0,g.GetMimeType)(n.src)||o,i.label=11;case 11:return[3,13];case 12:return i.sent(),[2,null];case 13:return r&&F(o)?[2,new Blob([r],{type:o})]:[2,null]}})})}function O(e,t,n){if(t<E.r)return 0;var r=E.r,o=e*n/(1-E.r)+t-2*E.r,i=o*o-4*r*(E.r-t);return g.Scalar.Clamp((-o+Math.sqrt(i))/(2*r),0,1)}function N(e){var t=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),n=e.alpha,r=g.Scalar.Clamp(e.specularPower,0,I),o=(0,g.SpecularPowerToRoughness)(r);return{baseColorFactor:[t.r,t.g,t.b,n],metallicFactor:0,roughnessFactor:o}}function P(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function U(e,t,n){for(var r=new Uint8Array(e*t*4),o=0;o<r.length;o+=4)r[o]=r[o+1]=r[o+2]=r[o+3]=255;return g.RawTexture.CreateRGBATexture(r,e,t,n)}function k(e){if(e instanceof Uint8Array){for(var t=e.length,n=new Float32Array(e.length),r=0;r<t;++r)n[r]=e[r]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var W=function(){function e(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}return e.prototype.getTextureInfo=function(e){var t;return e&&null!==(t=this._textureMap.get(e.uniqueId))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return A(this,function(l){switch(l.label){case 0:return n=N(e),r={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||g.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),t?(o=[],(i=e.diffuseTexture)&&o.push(this.exportTextureAsync(i).then(function(e){e&&(n.baseColorTexture=e)})),(a=e.bumpTexture)&&o.push(this.exportTextureAsync(a).then(function(e){e&&(r.normalTexture=e,1!==a.level&&(r.normalTexture.scale=a.level))})),(s=e.emissiveTexture)&&(r.emissiveFactor=[1,1,1],o.push(this.exportTextureAsync(s).then(function(e){e&&(r.emissiveTexture=e)}))),(u=e.ambientTexture)&&o.push(this.exportTextureAsync(u).then(function(e){if(e){var t={index:e.index};r.occlusionTexture=t}})),o.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(o)]):[3,2]):[3,2];case 1:l.sent(),l.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===g.Constants.ALPHA_COMBINE?r.alphaMode="BLEND":g.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(V,R)&&(r.emissiveFactor=e.emissiveColor.asArray()),r.pbrMetallicRoughness=n,P(r,e),[4,this._finishMaterialAsync(r,e)];case 3:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}})})},e.prototype._finishMaterialAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a;return A(this,function(s){switch(s.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(n=s.sent(),r=[],o=0,i=n;o<i.length;o++)a=i[o],r.push(this.exportTextureAsync(a));return[4,Promise.all(r)];case 2:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return s.sent(),[2]}})})},e.prototype._resizeTexturesToSameDimensions=function(e,t,n){var r,o,i=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return i.width<a.width?(r=e&&e instanceof g.Texture?g.TextureTools.CreateResizedCopy(e,a.width,a.height,!0):U(a.width,a.height,n),o=t):i.width>a.width?(o=t&&t instanceof g.Texture?g.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):U(i.width,i.height,n),r=e):(r=e,o=t),{texture1:r,texture2:o}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,f,p,d,m,x,_,v,T,y,b,M,w,C,E,I,V,F,B,O,N,P,U;return A(this,function(A){switch(A.label){case 0:return r=new Array,e||t?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,A.sent()];case 2:return(o=e?e.getScene():t?t.getScene():null)?(i=this._resizeTexturesToSameDimensions(e,t,o),a=null===(U=i.texture1)||void 0===U?void 0:U.getSize(),s=void 0,u=void 0,c=a.width,l=a.height,[4,i.texture1.readPixels()]):[3,12];case 3:return h=A.sent(),[4,i.texture2.readPixels()];case 4:return f=A.sent(),h?(s=k(h),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return f?(u=k(f),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(p=u.byteLength,d=new Uint8Array(p),m=new Uint8Array(p),x=new g.Color3(0,0,0),_=0,v=0,F=0;F<l;++F)for(B=0;B<c;++B)T=4*(c*F+B),y=new g.Color3(s[T],s[T+1],s[T+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),b=new g.Color3(u[T],u[T+1],u[T+2]).toLinearSpace(o.getEngine().useExactSrgbConversions).multiply(n.specularColor),M=u[T+3]*n.glossiness,w={diffuseColor:y,specularColor:b,glossiness:M},C=this._convertSpecularGlossinessToMetallicRoughness(w),x.r=Math.max(x.r,C.baseColor.r),x.g=Math.max(x.g,C.baseColor.g),x.b=Math.max(x.b,C.baseColor.b),_=Math.max(_,C.metallic),v=Math.max(v,C.roughness),m[T]=255*C.baseColor.r,m[T+1]=255*C.baseColor.g,m[T+2]=255*C.baseColor.b,m[T+3]=i.texture1.hasAlpha?255*s[T+3]:255,d[T]=0,d[T+1]=255*C.roughness,d[T+2]=255*C.metallic,d[T+3]=255;for(E={baseColor:x,metallic:_,roughness:v},I=!1,V=!1,F=0;F<l;++F)for(B=0;B<c;++B)m[O=4*(c*F+B)]/=E.baseColor.r>R?E.baseColor.r:1,m[O+1]/=E.baseColor.g>R?E.baseColor.g:1,m[O+2]/=E.baseColor.b>R?E.baseColor.b:1,N=g.Color3.FromInts(m[O],m[O+1],m[O+2]),P=N.toGammaSpace(o.getEngine().useExactSrgbConversions),m[O]=255*P.r,m[O+1]=255*P.g,m[O+2]=255*P.b,P.equalsWithEpsilon(S,R)||(V=!0),d[O+1]/=E.roughness>R?E.roughness:1,d[O+2]/=E.metallic>R?E.metallic:1,g.Color3.FromInts(255,d[O+1],d[O+2]).equalsWithEpsilon(S,R)||(I=!0);return I&&r.push((0,g.EncodeImageAsync)(d,c,l).then(function(e){E.metallicRoughnessTextureData=e})),V&&r.push((0,g.EncodeImageAsync)(m,c,l).then(function(e){E.baseColorTextureData=e})),[4,Promise.all(r).then(function(){return E})];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}})})},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),n=this._getPerceivedBrightness(e.specularColor),r=1-this._getMaxComponent(e.specularColor),o=O(t,n,r),i=e.diffuseColor.scale(r/(1-E.r)/Math.max(1-o,R)),a=e.specularColor.subtract(E.scale(1-o)).scale(1/Math.max(o,R)),s=g.Color3.Lerp(i,a,o*o);return{baseColor:s=s.clampToRef(0,1,s),metallic:o,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)},e.prototype._getMaxComponent=function(e){return Math.max(e.r,Math.max(e.g,e.b))},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,n,r,o,i,a,s,u){return w(this,void 0,void 0,function(){var c,l,h,f,p,d,m,x,_,v=this;return A(this,function(T){switch(T.label){case 0:return c=[],l={baseColor:e,metallic:t,roughness:n},u&&(a instanceof g.OpenPBRMaterial?(a.geometryOpacityTexture?(h=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:0,f=a.geometryOpacityTexture&&a.geometryOpacityTexture.getInternalTexture()?a.geometryOpacityTexture.getInternalTexture().uniqueId:0,p=Number("".concat(h).concat(f)),(_=this._textureMap.get(p))?s.baseColorTexture=_:c.push((0,g.MergeTexturesAsync)("baseColorOpacityTexture",(0,g.CreateRGBAConfiguration)(r?(0,g.CreateTextureInput)(r,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,1):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,2):(0,g.CreateConstantInput)(1),(0,g.CreateTextureInput)(a.geometryOpacityTexture,0)),a.getScene()).then(function(e){return w(v,void 0,void 0,function(){var t;return A(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,p)];case 1:return(t=n.sent())&&(s.baseColorTexture=t),[2]}})})}))):r&&c.push(this.exportTextureAsync(r).then(function(e){e&&(s.baseColorTexture=e)})),a._useMetallicFromMetallicTextureBlue&&o?c.push(this.exportTextureAsync(o).then(function(e){e&&(s.metallicRoughnessTexture=e)})):(i||o)&&(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,m=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,x=Number("".concat(d).concat(m)),(_=this._textureMap.get(x))?s.metallicRoughnessTexture=_:c.push((0,g.MergeTexturesAsync)("MetalRoughTexture",(0,g.CreateRGBAConfiguration)(a.ambientOcclusionTexture?(0,g.CreateTextureInput)(a.ambientOcclusionTexture,0):(0,g.CreateConstantInput)(1),i?(0,g.CreateTextureInput)(i,0):(0,g.CreateConstantInput)(1),o?(0,g.CreateTextureInput)(o,0):(0,g.CreateConstantInput)(1)),a.getScene()).then(function(e){return w(v,void 0,void 0,function(){var t;return A(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,x)];case 1:return(t=n.sent())&&(s.metallicRoughnessTexture=t),[2]}})})})))):(r&&c.push(this.exportTextureAsync(r).then(function(e){e&&(s.baseColorTexture=e)})),o&&c.push(this.exportTextureAsync(o).then(function(e){e&&(s.metallicRoughnessTexture=e)})))),c.length>0?(this._exporter._materialNeedsUVsSet.add(a),[4,Promise.all(c)]):[3,2];case 1:T.sent(),T.label=2;case 2:return[2,l]}})})},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof g.Texture))return t;var n=this._getGLTFTextureWrapMode(e.wrapU);10497!==n&&(t.wrapS=n);var r=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==r&&(t.wrapT=r),e.samplingMode){case g.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case g.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case g.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case g.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case g.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case g.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case g.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case g.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case g.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case g.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case g.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case g.Texture.WRAP_ADDRESSMODE:return 10497;case g.Texture.CLAMP_ADDRESSMODE:return 33071;case g.Texture.MIRROR_ADDRESSMODE:return 33648;default:return g.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l;return A(this,function(h){switch(h.label){case 0:return r={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,i=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!i||a?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(o||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),s=this._exportTextureSampler(o||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,i,r)]):[3,8];case 3:return u=h.sent(),c=this._exporter._textures,u.baseColorTextureData?[4,this._exportImageAsync("baseColor".concat(c.length),u.baseColorTextureData)]:[3,5];case 4:l=h.sent(),t.baseColorTexture=this._exportTextureInfo(l,s,null==o?void 0:o.coordinatesIndex),h.label=5;case 5:return u.metallicRoughnessTextureData?[4,this._exportImageAsync("metallicRoughness".concat(c.length),u.metallicRoughnessTextureData)]:[3,7];case 6:l=h.sent(),t.metallicRoughnessTexture=this._exportTextureInfo(l,s,null==i?void 0:i.coordinatesIndex),h.label=7;case 7:return[2,u];case 8:return[2,this._convertSpecularGlossinessToMetallicRoughness(r)]}})})},e.prototype.exportPBRMaterialAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return A(this,function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(i=e._albedoColor,a=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,a])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,n,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t)];case 3:u=l.sent(),l.label=4;case 4:return s=u,[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,r,n,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(r,e)];case 6:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}})})},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,t,n,r,o){return w(this,void 0,void 0,function(){var i,a,s,u,c,l=this;return A(this,function(h){switch(h.label){case 0:return P(n,t),e.baseColor.equalsWithEpsilon(S,R)&&g.Scalar.WithinEpsilon(t.alpha,1,R)||(r.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,t.alpha]),null!=e.metallic&&1!==e.metallic&&(r.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(r.roughnessFactor=e.roughness),null==t.backFaceCulling||t.backFaceCulling||(t._twoSidedLighting||g.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o?(i=[],(a=t instanceof g.PBRBaseMaterial?t._bumpTexture:t.geometryNormalTexture)&&i.push(this.exportTextureAsync(a).then(function(e){e&&(n.normalTexture=e,1!==a.level&&(n.normalTexture.scale=a.level))})),(s=t instanceof g.PBRBaseMaterial?t._ambientTexture:t.ambientOcclusionTexture)&&i.push(new Promise(function(e){return w(l,void 0,void 0,function(){var n,o,i,a;return A(this,function(u){switch(u.label){case 0:return t instanceof g.OpenPBRMaterial&&r.metallicRoughnessTexture?(n=this._exportTextureSampler(s),o=this._exporter._textures[r.metallicRoughnessTexture.index].source,i=this._exportTextureInfo(o,n,s.coordinatesIndex),this._textureMap.set(s.uniqueId,i),this._exporter._extensionsPostExportTextures("exporter",i,s),[2,e(i)]):[3,1];case 1:return a=e,[4,this.exportTextureAsync(s)];case 2:return[2,a.apply(void 0,[u.sent()])]}})})}).then(function(e){return w(l,void 0,void 0,function(){var r;return A(this,function(o){return e&&(r={index:e.index,texCoord:e.texCoord,extensions:e.extensions},n.occlusionTexture=r,t instanceof g.PBRBaseMaterial?r.strength=t._ambientTextureStrength:r.strength=t.ambientOcclusionTexture.level),[2]})})})),(u=t instanceof g.PBRBaseMaterial?t._emissiveTexture:t.emissionColorTexture)&&i.push(this.exportTextureAsync(u).then(function(e){e&&(n.emissiveTexture=e)})),i.length>0?(this._exporter._materialNeedsUVsSet.add(t),[4,Promise.all(i)]):[3,2]):[3,2];case 1:h.sent(),h.label=2;case 2:return(c=t instanceof g.PBRBaseMaterial?t._emissiveColor:t.emissionColor).equalsWithEpsilon(V,R)||(n.emissiveFactor=c.asArray()),n.pbrMetallicRoughness=r,[2]}})})},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s;return A(this,function(u){switch(u.label){case 0:return n={},r={name:e.name},o=e.baseColor,i=e.geometryOpacity,o&&(n.baseColorFactor=[o.r,o.g,o.b,i]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t)];case 1:return a=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(a,e,r,n,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(r,e)];case 3:return u.sent(),(s=this._exporter._materials).push(r),[2,s.length-1]}})})},e.prototype.exportTextureAsync=function(e){return w(this,arguments,void 0,function(e,t){var n,r,o;return void 0===t&&(t=null),A(this,function(i){switch(i.label){case 0:return(n=this._textureMap.get(null!=t?t:e.uniqueId))?[2,n]:(r=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=i.sent(),n=this._exportTextureInfo(o,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,n),this._exporter._extensionsPostExportTextures("exporter",n,e),[2,n]}})})},e.prototype._exportTextureImageAsync=function(e){return w(this,void 0,void 0,function(){var t,n,r,o,i,a=this;return A(this,function(s){switch(s.label){case 0:return t=null!==(i=e.mimeType)&&void 0!==i?i:"none",n=this._internalTextureToImage,r=e.getInternalTexture().uniqueId,n[r]=n[r]||{},void 0===(o=n[r][t])&&(o=w(a,void 0,void 0,function(){var n,r,o,i,a;return A(this,function(s){switch(s.label){case 0:return[4,B(e)];case 1:return!(n=s.sent())||"none"!==t&&n.type!==t?[3,3]:[4,this._exportImageAsync(e.name,n)];case 2:case 6:return[2,s.sent()];case 3:return r="image/png","none"!==t&&(F(t)?r=t:(r="image/png",g.Tools.Warn("Unsupported media type: ".concat(t,". Exporting texture as PNG.")))),o=e.getSize(),[4,(0,g.GetTextureDataAsync)(e)];case 4:return i=s.sent(),[4,(0,g.EncodeImageAsync)(i,o.width,o.height,r)];case 5:return a=s.sent(),[4,this._exportImageAsync(e.name,a)]}})}),n[r][t]=o),[4,o];case 1:return[2,s.sent()]}})})},e.prototype._exportImageAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u;return A(this,function(c){switch(c.label){case 0:return n=this._exporter._images,this._exporter._shouldUseGlb?(r={name:e,mimeType:t.type,bufferView:void 0},[4,t.arrayBuffer()]):[3,2];case 1:return o=c.sent(),i=this._exporter._bufferManager.createBufferView(new Uint8Array(o)),this._exporter._bufferManager.setBufferView(r,i),[3,3];case 2:a=e.replace(/\.\/|\/|\.\\|\\/g,"_"),s=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(t.type),u=a+s,n.some(function(e){return e.uri===u})&&(u="".concat(a,"_").concat(g.Tools.RandomId()).concat(s)),r={name:e,uri:u},this._exporter._imageData[u]=t,c.label=3;case 3:return n.push(r),[2,n.length-1]}})})},e.prototype._exportTextureInfo=function(e,t,n){var r=this._exporter._textures,o=r.findIndex(function(n){return n.sampler==t&&n.source===e});-1===o&&(o=r.length,r.push({source:e,sampler:t}));var i={index:o};return n&&(i.texCoord=n),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),n=this._exporter._samplers,r=n.findIndex(function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT});return-1!==r?r:(n.push(t),n.length-1)},e}(),D=g.Matrix.Compose(new g.Vector3(-1,1,1),g.Quaternion.Identity(),g.Vector3.Zero());function z(e,t){if(!(e instanceof g.TransformNode))return!1;if(t){if(!e.getWorldMatrix().equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(D,g.TmpVectors.Matrix[0]).equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1;return!(e instanceof g.AbstractMesh&&e.geometry)}var L=g.Vector3.ZeroReadOnly,K=g.Quaternion.Identity(),q=g.Vector3.OneReadOnly,G=new g.Vector3(-1,1,1);function j(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,i=e.normalized,a=e.getSize(),s=t.reduce(function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e},-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:a,type:o,count:s*a,normalized:i,totalVertices:s,kind:e.getKind()}}function H(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 X(e){return e.some(function(e){return e>=256})}function Q(e){switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:case g.VertexBuffer.ColorKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return!0}return!1}function Z(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 Y(e){return e.x*=-1,e}function J(e){return D.invertToRef(g.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(D,e),e}function $(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){var r=Math.sign(e.x);e.x=t,e.y*=-r,e.z*=-r,e.w*=r}else r=Math.sign(e.y),e.x*=-r,e.y=n,e.z*=r,e.w*=-r}else{var o=Math.abs(e.z),i=Math.abs(e.w);o>i?(r=Math.sign(e.z),e.x*=-r,e.y*=r,e.z=o,e.w*=-r):(r=Math.sign(e.w),e.x*=r,e.y*=-r,e.z*=-r,e.w=i)}return e}function ee(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function te(e,t){var n=g.Vector3.FromArrayToRef(t.translation||[0,0,0],0,g.TmpVectors.Vector3[0]),r=g.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[0]),o=g.Matrix.ComposeToRef(q,r,n,g.TmpVectors.Matrix[0]),i=g.Vector3.FromArrayToRef(e.translation||[0,0,0],0,g.TmpVectors.Vector3[2]),a=g.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,g.TmpVectors.Quaternion[1]),s=g.Matrix.ComposeToRef(q,a,i,g.TmpVectors.Matrix[1]);o.multiplyToRef(s,s),s.decompose(void 0,r,n),n.equalsWithEpsilon(L,g.Epsilon)?delete t.translation:t.translation=n.asArray(),r.equalsWithEpsilon(K,g.Epsilon)?delete t.rotation:t.rotation=r.asArray(),t.scale&&delete t.scale}function ne(e,t){if(!(t instanceof g.TransformNode))return!1;if(1!==t.getChildren().length||0!==e.getChildren().length||e.parent!==t)return!1;var n=e.getScene(),r=e instanceof g.TargetCamera&&!n.useRightHandedSystem?G:q;return!!t.scaling.equalsWithEpsilon(r,g.Epsilon)||(g.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(t.name," with modified scaling.")),!1)}function re(e,t){for(var n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],a=o[1],s=t[i];(Array.isArray(a)&&Array.isArray(s)&&oe(a,s)||a===s)&&delete e[i]}return e}function oe(e,t){return e.length===t.length&&e.every(function(e,n){return e===t[n]})}var ie=new Map([[Int8Array,function(e,t,n){return e.setInt8(t,n)}],[Uint8Array,function(e,t,n){return e.setUint8(t,n)}],[Uint8ClampedArray,function(e,t,n){return e.setUint8(t,n)}],[Int16Array,function(e,t,n){return e.setInt16(t,n,!0)}],[Uint16Array,function(e,t,n){return e.setUint16(t,n,!0)}],[Int32Array,function(e,t,n){return e.setInt32(t,n,!0)}],[Uint32Array,function(e,t,n){return e.setUint32(t,n,!0)}],[Float32Array,function(e,t,n){return e.setFloat32(t,n,!0)}],[Float64Array,function(e,t,n){return e.setFloat64(t,n,!0)}]]),ae=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=ie.get(e.constructor),n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var n=new Uint8Array(2*t);n.set(this._data),this._data=n,this._dataView=new DataView(this._data.buffer)}},e}();function se(e){return e%4==0?4:e%2==0?2:1}var ue,ce=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach(function(e){t+=e.byteLength});for(var n=new ae(t),r=0,o=Array.from(this._bufferViewToData.keys()).sort(function(e,t){return se(t.byteLength)-se(e.byteLength)});r<o.length;r++){var i=o[r];i.byteOffset=n.byteOffset,e.push(i);for(var a=e.length-1,s=0,u=this.getPropertiesWithBufferView(i);s<u.length;s++)u[s].bufferView=a;n.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return n.getOutputData()},e.prototype.createBufferView=function(e,t){var n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n},e.prototype.createAccessor=function(e,t,n,r,o,i,a){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:a,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,n=0,r=this.getPropertiesWithBufferView(e);n<r.length;n++){var o=r[n];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach(function(n,r){n===e&&(void 0!==r.byteOffset&&delete r.byteOffset,t._accessorToBufferView.delete(r))})},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(ue||(ue={}));var le=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof g.TransformNode||e instanceof g.Camera||e instanceof g.Light)},e._CreateNodeAnimation=function(t,n,r,o,i){if(this._IsTransformable(t)){var a=[],s=[],u=n.getKeys(),c=e._CalculateMinMaxKeyFrames(u),l=e._DeduceInterpolation(u,r,o),h=l.interpolationType,f=l.shouldBakeAnimation;if(f?e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o):"LINEAR"===h||"STEP"===h?e._CreateLinearOrStepAnimation(t,n,r,a,s,o):"CUBICSPLINE"===h?e._CreateCubicSplineAnimation(t,n,r,a,s,o):e._CreateBakedAnimation(t,n,r,c.min,c.max,n.framePerSecond,i,a,s,c,o),a.length&&s.length)return{inputs:a,outputs:s,samplerInterpolation:h,inputsMin:f?c.min:g.Tools.FloatRound(c.min/n.framePerSecond),inputsMax:f?c.max:g.Tools.FloatRound(c.max/n.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,n="VEC3",r=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":n="VEC4",t="rotation";break;case"rotationQuaternion":n="VEC4",r=!0,t="rotation";break;case"influence":n="SCALAR",t="weights";break;default:g.Tools.Error("Unsupported animatable property ".concat(o[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:n,useQuaternion:r}:(g.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,i,a,s,u,c,l,h){var f;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!h||h(m)){var g=e._DeduceAnimationInfo(m);g&&(f={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?n:f,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,g.useQuaternion,c,l),f.samplers.length&&f.channels.length&&r.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,n,r,o,i,a,s,u,c,l,h){var f;if(t instanceof g.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var m=0,x=p.getTarget(d).animations;m<x.length;m++){var _=x[m];if(!h||h(_)){for(var v=new g.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),T=[],y=_.getKeys(),b=0;b<y.length;++b)for(var M=y[b],w=0;w<p.numTargets;++w)w==d?T.push(M):T.push({frame:M.frame,value:0});v.setKeys(T,!0);var A=e._DeduceAnimationInfo(v);A&&(f={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?n:f,t,v,A.dataAccessorType,A.animationChannelTargetPath,o,a,s,u,A.useQuaternion,c,l,p.numTargets),f.samplers.length&&f.channels.length&&r.push(f))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,n,r,o,i,a,s,u,c){var l,h;if(t.animationGroups)for(var f=t.animationGroups,p=function(f){var p=new Map,m=new Map,x=new Set,_=f.to-f.from;h={name:f.name,channels:[],samplers:[]};for(var v=function(n){var _=f.targetedAnimations[n],v=_.target,T=_.animation;if(c&&!c(T))return"continue";var y=u.has(v);if(d._IsTransformable(v)||1===v.length&&d._IsTransformable(v[0])){if(M=e._DeduceAnimationInfo(_.animation)){var b=d._IsTransformable(v)?v:d._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(T.name),h,b,T,M.dataAccessorType,M.animationChannelTargetPath,r,o,i,a,M.useQuaternion,s,y)}}else if(v instanceof g.MorphTarget||1===v.length&&v[0]instanceof g.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var w=v instanceof g.MorphTarget?v:v[0];if(w){var A=t.morphTargetManagers.find(function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1});if(A){var C=t.meshes.find(function(e){return e.morphTargetManager===A});C&&(p.has(C)||p.set(C,new Map),null===(l=p.get(C))||void 0===l||l.set(w,T),x.add(C),m.set(C,T))}}}}},T=0;T<f.targetedAnimations.length;++T)v(T);x.forEach(function(t){for(var n=t.morphTargetManager,u=null,c=[],l=m.get(t).getKeys(),d=l.length,x=0;x<d;++x)for(var v=0;v<n.numTargets;++v){var T=n.getTarget(v),y=p.get(t);if(y){var b=y.get(T);b?(u||(u=new g.Animation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,g.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:f.from+_/d*x,value:T.influence,inTangent:l[0].inTangent?0:void 0,outTangent:l[0].outTangent?0:void 0})}}u.setKeys(c,!0);var M=e._DeduceAnimationInfo(u);M&&e._AddAnimation("".concat(f.name,"_").concat(t.name,"_MorphWeightAnimation"),h,t,u,M.dataAccessorType,M.animationChannelTargetPath,r,o,i,a,M.useQuaternion,s,!1,null==n?void 0:n.numTargets)}),h.channels.length&&h.samplers.length&&n.push(h)},d=this,m=0,x=f;m<x.length;m++)p(x[m])},e._AddAnimation=function(t,n,r,o,i,a,s,u,c,l,h,f,p,d){var m,x,_,v,T,y,b=e._CreateNodeAnimation(r,o,a,h,f);if(b){if(d){for(var M=0,w=void 0,A=[];b.inputs.length>0;)w=b.inputs.shift(),M%d==0&&A.push(w),M++;b.inputs=A}var C=s.get(r),R=new Float32Array(b.inputs);m=u.createBufferView(R),x=u.createAccessor(m,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),l.push(x),_=l.length-1;var E=new g.Quaternion,I=new g.Vector3,S=new g.Vector3,V=r instanceof g.Camera,F=H(i),B=new Float32Array(b.outputs.length*F);b.outputs.forEach(function(e,t){var n=e;switch(a){case"translation":p&&(g.Vector3.FromArrayToRef(e,0,S),Y(S),S.toArray(n));break;case"rotation":4===e.length?g.Quaternion.FromArrayToRef(e,0,E):(n=new Array(4),g.Vector3.FromArrayToRef(e,0,I),g.Quaternion.FromEulerVectorToRef(I,E)),p&&($(E),V&&ee(E)),E.toArray(n)}B.set(n,t*F)}),m=u.createBufferView(B),x=u.createAccessor(m,i,5126,b.outputs.length),l.push(x),v=l.length-1,T={interpolation:b.samplerInterpolation,input:_,output:v},n.samplers.push(T),y={sampler:n.samplers.length-1,target:{node:C,path:a}},n.channels.push(y)}},e._CreateBakedAnimation=function(t,n,r,o,i,a,s,u,c,l,h){var f,p,d,m,x,_,v=g.Quaternion.Identity(),T=null,y=null;l.min=g.Tools.FloatRound(o/a);for(var b=n.getKeys(),M=0,w=b.length;M<w;++M){if(d=b[M],M+1<w)if(m=b[M+1],d.value.equals&&d.value.equals(m.value)||d.value===m.value){if(0!==M)continue;_=d.frame}else _=m.frame;else{if(x=b[M-1],d.value.equals&&d.value.equals(x.value)||d.value===x.value)continue;_=i}if(_)for(var A=d.frame;A<=_;A+=s)if((p=g.Tools.FloatRound(A/a))!==T){T=p,y=p;var C={key:0,repeatCount:0,loopMode:n.loopMode};f=n._interpolate(A,C),e._SetInterpolatedValue(t,f,p,n,r,v,u,c,h)}}y&&(l.max=y)},e._ConvertFactorToVector3OrQuaternion=function(t,n,r,o,i){var a=e._GetBasePositionRotationOrScale(n,o,i),s=r.targetProperty.split("."),u=s?s[1]:"",c=i?g.Quaternion.FromArray(a).normalize():g.Vector3.FromArray(a);switch(u){case"x":case"y":case"z":c[u]=t;break;case"w":c.w=t;break;default:g.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return c},e._SetInterpolatedValue=function(e,t,n,r,o,i,a,s,u){var c;a.push(n),"weights"!==o?(r.dataType===g.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,r,o,u)),"rotation"===o?(u?i=t:(c=t,g.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),s.push(i.asArray())):(c=t,s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,n,r,o,i,a){for(var s=0,u=n.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/n.framePerSecond),e._AddKeyframeValue(c,n,i,r,t,a)}},e._CreateCubicSplineAnimation=function(t,n,r,o,i,a){n.getKeys().forEach(function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(ue.INTANGENT,i,r,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,n,i,r,t,a),e._AddSplineTangent(ue.OUTTANGENT,i,r,"CUBICSPLINE",s,a)})},e._GetBasePositionRotationOrScale=function(e,t,n){var r;if("rotation"===t)if(n){var o=e.rotationQuaternion;r=(null!=o?o:g.Quaternion.Identity()).asArray()}else{var i=e.rotation;r=(null!=i?i:g.Vector3.Zero()).asArray()}else if("translation"===t){var a=e.position;r=(null!=a?a:g.Vector3.Zero()).asArray()}else{var s=e.scaling;r=(null!=s?s:g.Vector3.One()).asArray()}return r},e._AddKeyframeValue=function(e,t,n,r,o,i){var a,s=t.dataType;if(s===g.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===r){var c=g.Vector3.FromArray(u);u=g.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}n.push(u)}else if(s===g.Animation.ANIMATIONTYPE_FLOAT){if("weights"===r)n.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,r,i)){if("rotation"===r){var l=i?a:g.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();n.push(l.asArray())}n.push(a.asArray())}}else s===g.Animation.ANIMATIONTYPE_QUATERNION?n.push(e.value.normalize().asArray()):g.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,n,r,o,i){var a,s=e===ue.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===r){if("rotation"===n)if(s)if(i)a=s.asArray();else{var u=s;a=g.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else a=[0,0,0,0];else a="weights"===n?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(a)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,n=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)}),{min:t,max:n}},e}();function he(e,t,n,r,o,i){var a={attributes:{},influence:e.influence,name:e.name},s=t.geometry;if(!s)return g.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),a;var u,c=i?-1:1,l=g.Vector3.Zero();if(e.hasPositions){var h=e.getPositions(),f=s.getVerticesData(g.VertexBuffer.PositionKind);if(f){var p=new Float32Array(f.length),d=[1/0,1/0,1/0],m=[-1/0,-1/0,-1/0];u=f.length/3;for(var x=0;x<u;++x){var _=g.Vector3.FromArray(f,3*x);g.Vector3.FromArray(h,3*x).subtractToRef(_,l),l.x*=c,d[0]=Math.min(d[0],l.x),m[0]=Math.max(m[0],l.x),d[1]=Math.min(d[1],l.y),m[1]=Math.max(m[1],l.y),d[2]=Math.min(d[2],l.z),m[2]=Math.max(m[2],l.z),p[3*x]=l.x,p[3*x+1]=l.y,p[3*x+2]=l.z}var v=n.createBufferView(p,12),T=n.createAccessor(v,"VEC3",5126,h.length/3,0,{min:d,max:m});o.push(T),a.attributes.POSITION=o.length-1}else g.Tools.Warn("Morph target positions for mesh ".concat(t.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),b=s.getVerticesData(g.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(u=b.length/3,x=0;x<u;++x){var w=g.Vector3.FromArray(b,3*x).normalize();g.Vector3.FromArray(y,3*x).normalize().subtractToRef(w,l),M[3*x]=l.x*c,M[3*x+1]=l.y,M[3*x+2]=l.z}v=n.createBufferView(M,12),T=n.createAccessor(v,"VEC3",5126,y.length/3,0),o.push(T),a.attributes.NORMAL=o.length-1}else g.Tools.Warn("Morph target normals for mesh ".concat(t.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),C=s.getVerticesData(g.VertexBuffer.TangentKind);if(C){u=C.length/4;var R=new Float32Array(3*u);for(x=0;x<u;++x){var E=g.Vector3.FromArray(C,4*x);Z(E);var I=g.Vector3.FromArray(A,3*x);Z(I),I.subtractToRef(E,l),R[3*x]=l.x*c,R[3*x+1]=l.y,R[3*x+2]=l.z}v=n.createBufferView(R,12),T=n.createAccessor(v,"VEC3",5126,u,0),o.push(T),a.attributes.TANGENT=o.length-1}else g.Tools.Warn("Morph target tangents for mesh ".concat(t.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),V=s.getVerticesData(g.VertexBuffer.ColorKind),F=s.getVertexBuffer(g.VertexBuffer.ColorKind);if(V&&F){var B=F.getSize();u=V.length/B;var O=new Float32Array(u*B);for(x=0;x<u;++x)if(3===B){var N=g.Vector3.FromArray(V,x*B);g.Vector3.FromArray(S,x*B).subtractToRef(N,l),O[3*x]=l.x,O[3*x+1]=l.y,O[3*x+2]=l.z}else if(4===B){var P=new g.Vector4;N=g.Vector4.FromArray(V,x*B),g.Vector4.FromArray(S,x*B).subtractToRef(N,P),O[4*x]=P.x,O[4*x+1]=P.y,O[4*x+2]=P.z,O[4*x+3]=P.w}else g.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));v=n.createBufferView(O,4*B),T=n.createAccessor(v,3===B?"VEC3":"VEC4",5126,u,0),o.push(T),a.attributes.COLOR_0=o.length-1}else g.Tools.Warn("Morph target colors for mesh ".concat(t.name," were not exported. Mesh does not have colors vertex data"))}return a}var fe=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,n,r,o){var i,a,s,u;return null===(u=null===(s=null===(a=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===a?void 0:a.get(n))||void 0===s?void 0:s.get(r))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,n,r,o,i){var a=this._indicesAccessorMap.get(e);a||(a=new Map,this._indicesAccessorMap.set(e,a));var s=a.get(t);s||(s=new Map,a.set(t,s));var u=s.get(n);u||(u=new Map,s.set(n,u));var c=u.get(r);c||(c=new Map,u.set(r,c)),c.set(o,i)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)},e.prototype.getRemappedBufferView=function(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)},e.prototype.getVertexAccessor=function(e,t,n){var r,o;return null===(o=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.get(n)},e.prototype.setVertexAccessor=function(e,t,n,r){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.set(t,i)),i.set(n,r)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),pe=function(){function e(e,t){if(void 0===e&&(e=g.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(g.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new W(this),this._extensions={},this._bufferManager=new ce,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=b({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},t),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,n,r){var o=this;if(n>=t.length)return Promise.resolve(e);var i=r(t[n],e);return i?i.then(function(e){return w(o,void 0,void 0,function(){var o;return A(this,function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=i.sent(),[3,3];case 2:o=null,i.label=3;case 3:return[2,o]}})})}):this._ApplyExtension(e,t,n+1,r)},e.prototype._ApplyExtensions=function(t,n){for(var r=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];r.push(this._extensions[a])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var i=this;return this._ApplyExtensions(t,function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,n,r,o,i._bufferManager)})},e.prototype._extensionsPostExportMaterialAsync=function(e,t,n){return this._ApplyExtensions(t,function(t,r){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,n)})},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,n,r){return w(this,void 0,void 0,function(){var o,i=this;return A(this,function(a){switch(a.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map(function(e){return w(i,void 0,void 0,function(){var i,a;return A(this,function(s){switch(s.label){case 0:return(i=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,i.postExportMaterialAdditionalTexturesAsync(t,n,r)]:[3,2];case 1:a=s.sent(),o.push.apply(o,a),s.label=2;case 2:return[2]}})})}))];case 1:return a.sent(),[2,o]}})})},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,n,r)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return w(this,void 0,void 0,function(){var t,n,r,o;return A(this,function(i){switch(i.label){case 0:t=0,n=e._ExtensionNames,i.label=1;case 1:return t<n.length?(r=n[t],(o=this._extensions[r]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}})})},e.prototype._forEachExtensions=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions(function(t){var n,r,o;t.wasUsed&&((n=e._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((r=e._glTF).extensionsRequired||(r.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())})},e.prototype._loadExtensions=function(){for(var t=0,n=e._ExtensionNames;t<n.length;t++){var r=n[t],o=e._ExtensionFactories[r](this);this._extensions[r]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,n,r){void 0===r&&(r=100),e.UnregisterExtension(t)&&g.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=n;var o=null!=r?r:0;e._ExtensionOrders[t]=o;for(var i=e._ExtensionNames.length,a=0;a<e._ExtensionNames.length;a++){var s=e._ExtensionNames[a];if(o<e._ExtensionOrders[s]){i=a;break}}e._ExtensionNames.splice(i,0,t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[t];var n=e._ExtensionNames.indexOf(t);return-1!==n&&e._ExtensionNames.splice(n,1),!0},e.prototype._generateJSON=function(e,t,n){var r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(r.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return w(this,void 0,void 0,function(){var t,n,r,o,i,a,s;return A(this,function(u){switch(u.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=u.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength,e,!0),r=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",i=e+".bin",(a=new v).files[o]=n,a.files[i]=r,this._imageData)for(s in this._imageData)a.files[s]=this._imageData[s];return[2,a]}})})},e.prototype._generateBinaryAsync=function(){return w(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 w(this,void 0,void 0,function(){var t,n,r,o,i,a,s,u,c,l,h,f,p,d;return A(this,function(m){switch(m.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=m.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(a=new TextEncoder,i=a.encode(n),o=i.length),s=this._getPadding(o),u=this._getPadding(t.byteLength),c=28+o+s+t.byteLength+u,(l=new ae(c)).writeUInt32(1179937895),l.writeUInt32(2),l.writeUInt32(c),l.writeUInt32(o+s),l.writeUInt32(1313821514),i)l.writeTypedArray(i);else for(h="_".charCodeAt(0),p=0;p<o;++p)(f=n.charCodeAt(p))!=n.codePointAt(p)?l.writeUInt8(h):l.writeUInt8(f);for(p=0;p<s;++p)l.writeUInt8(32);for(l.writeUInt32(t.byteLength+u),l.writeUInt32(5130562),l.writeTypedArray(t),p=0;p<u;++p)l.writeUInt8(0);return(d=new v).files[r]=new Blob([l.getOutputData()],{type:"application/octet-stream"}),[2,d]}})})},e.prototype._setNodeTransformation=function(e,t,n){var r;if(t.getPivotPoint().equalsWithEpsilon(L,g.Epsilon)||g.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(L,g.Epsilon)){var o=g.TmpVectors.Vector3[0].copyFrom(t.position);n&&Y(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(q,g.Epsilon)||(e.scale=t.scaling.asArray());var i=(null===(r=t.rotationQuaternion)||void 0===r?void 0:r.clone())||g.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);i.equalsWithEpsilon(K,g.Epsilon)||(n&&$(i),e.rotation=i.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,n){var r=g.TmpVectors.Vector3[0],o=g.TmpVectors.Quaternion[0],i=t.getWorldMatrix();if(t.parent){var a=t.parent.getWorldMatrix().invertToRef(g.TmpVectors.Matrix[0]);i.multiplyToRef(a,g.TmpVectors.Matrix[1]).decompose(void 0,o,r)}else i.decompose(void 0,o,r);r.equalsWithEpsilon(L,g.Epsilon)||(n&&Y(r),e.translation=r.asArray()),n&&$(o),this._babylonScene.useRightHandedSystem||ee(o),o.equalsWithEpsilon(K,g.Epsilon)||(e.rotation=o.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,t=this._babylonScene.cameras;e<t.length;e++){var n=t[e],r={type:n.mode===g.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(n.name&&(r.name=n.name),"perspective"===r.type)r.perspective={aspectRatio:n.getEngine().getAspectRatio(n),yfov:n.fovMode===g.Camera.FOVMODE_VERTICAL_FIXED?n.fov:n.fov*n.getEngine().getAspectRatio(n),znear:n.minZ,zfar:n.maxZ};else if("orthographic"===r.type){var o=n.orthoLeft&&n.orthoRight?.5*(n.orthoRight-n.orthoLeft):.5*n.getEngine().getRenderWidth(),i=n.orthoBottom&&n.orthoTop?.5*(n.orthoTop-n.orthoBottom):.5*n.getEngine().getRenderHeight();r.orthographic={xmag:o,ymag:i,znear:n.minZ,zfar:n.maxZ}}this._camerasMap.set(n,r)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var n=t[e],r=this._nodesCameraMap.get(n);if(void 0!==r){this._cameras.push(n);for(var o=0,i=r;o<i.length;o++)i[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var n=t[e];n.bones.length<=0||this._skinMap.set(n,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var t,n=function(n){if(n.bones.length<=0)return"continue";var o=r._skinMap.get(n);if(null==o)return"continue";for(var i={},a=-1,s=0;s<n.bones.length;++s){var u=n.bones[s];-1!==(l=null!==(t=u.getIndex())&&void 0!==t?t:s)&&(i[l]=u,l>a&&(a=l))}for(var c=[],l=0;l<=a;++l){var h=(u=i[l]).getTransformNode(),f=h?r._nodeMap.get(h):void 0;if(void 0!==f){o.joints.push(f);var p=u.getAbsoluteInverseBindMatrix().clone();e.has(h)&&J(p),c.push(p)}else g.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var d=r._nodesSkinMap.get(o);if(o.joints.length>0&&void 0!==d){var m=new Float32Array(16*c.length);c.forEach(function(e,t){m.set(e.m,16*t)});var x=r._bufferManager.createBufferView(m);r._accessors.push(r._bufferManager.createAccessor(x,"MAT4",5126,c.length)),o.inverseBindMatrices=r._accessors.length-1,r._skins.push(o);for(var _=r._skins.length-1,v=0,T=d;v<T.length;v++)T[v].skin=_}},r=this,o=0,i=this._babylonScene.skeletons;o<i.length;o++)n(i[o])},e.prototype._exportSceneAsync=function(){return w(this,void 0,void 0,function(){var e,t,n,r,o,i,a,s,u,c,l,h,f,p,d,m,x,_,v,T,y,b,M,w,C,R,E,I,S,V,F,B,O;return A(this,function(A){switch(A.label){case 0:if(e={nodes:[]},this._babylonScene.metadata&&(t=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=t),n=new Array,r=new Array,o=new Array,this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(a=0,s=this._babylonScene.animationGroups;a<s.length;a++)for(u=s[a],c=0,l=u.targetedAnimations;c<l.length;c++)h=l[c],(f=h.target)instanceof g.TransformNode&&!f.parent&&(null!=i?i:i=new Set).add(f);for(p=0,d=this._babylonScene.rootNodes;p<d.length;p++)m=d[p],x=m.animations,_=!!x&&x.length>0||(null==i?void 0:i.has(m)),this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&z(m,this._babylonScene.useRightHandedSystem)&&!_?o.push.apply(o,m.getChildren()):this._babylonScene.useRightHandedSystem?n.push(m):r.push(m);return this._listAvailableCameras(),this._listAvailableSkeletons(),v=new fe(!0,!1),y=(T=(F=e.nodes).push).apply,b=[F],[4,this._exportNodesAsync(r,v)];case 1:return y.apply(T,b.concat([A.sent()])),M=new fe(!1,!1),C=(w=(B=e.nodes).push).apply,R=[B],[4,this._exportNodesAsync(n,M)];case 2:return C.apply(w,R.concat([A.sent()])),E=new fe(!1,!0),S=(I=(O=e.nodes).push).apply,V=[O],[4,this._exportNodesAsync(o,E)];case 3:return S.apply(I,V.concat([A.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(v.getNodesSet()),this._babylonScene.animationGroups.length&&le._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,v.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 w(this,void 0,void 0,function(){var n,r,o,i;return A(this,function(a){switch(a.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,a.label=1;case 1:return r<o.length?(i=o[r],[4,this._exportNodeAsync(i,n,t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return r++,[3,1];case 4:return[2,n]}})})},e.prototype._collectBuffers=function(e,t,n,r,o){if(this._shouldExportNode(e)&&e instanceof g.AbstractMesh&&e.geometry){var i=e.geometry.getVertexBuffers();if(i)for(var a in i)if(Q(a)){var s=i[a];o.setHasVertexColorAlpha(s,e.hasVertexAlpha);var u=s._buffer,c=t.get(u)||[];t.set(u,c),-1===c.indexOf(s)&&c.push(s);var l=n.get(s)||[];n.set(s,l),-1===l.indexOf(e)&&l.push(e)}var h=e.morphTargetManager;if(h)for(var f=0;f<h.numTargets;f++){var p=h.getTarget(f);l=r.get(p)||[],r.set(p,l),-1===l.indexOf(e)&&l.push(e)}}for(var d=0,m=e.getChildren();d<m.length;d++){var x=m[d];this._collectBuffers(x,t,n,r,o)}},e.prototype._exportBuffers=function(e,t){for(var n=new Map,r=new Map,o=new Map,i=0,a=e;i<a.length;i++){var s=a[i];this._collectBuffers(s,n,r,o,t)}for(var u=Array.from(n.keys()),c=function(e){var o=e.getData();if(!o)throw new Error("Buffer data is not available");var i=n.get(e);if(!i)return"continue";var a=i[0].byteStride;if(i.some(function(e){return e.byteStride!==a}))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var s=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(o).slice(),u=function(e){var t=r.get(e),n=j(e,t),o=n.byteOffset,i=n.byteStride,a=n.componentCount,u=n.type,c=n.count,h=n.normalized;switch(n.kind){case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,o,i,a,u,c,h,function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}});break;case g.VertexBuffer.ColorKind:var f=t.filter(function(e){return e.material instanceof g.StandardMaterial||null==e.material}).length;if(0==f)break;if(f!=t.length){g.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}u==g.VertexBuffer.UNSIGNED_BYTE&&g.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var p=new g.Color3,d=new g.Color4,m=l._babylonScene.getEngine().useExactSrgbConversions;(0,g.EnumerateFloatValues)(s,o,i,a,u,c,h,function(e){3===e.length?(p.fromArray(e,0),p.toLinearSpaceToRef(p,m),p.toArray(e,0)):(d.fromArray(e,0),d.toLinearSpaceToRef(d,m),d.toArray(e,0))})}},c=0,h=i;c<h.length;c++)u(F=h[c]);if(t.convertToRightHanded){for(var f=0,p=i;f<p.length;f++){var d=j(F=p[f],r.get(F)),m=d.byteOffset,x=d.byteStride,_=d.componentCount,v=d.type,T=d.count,y=d.normalized;switch(R=d.kind){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:case g.VertexBuffer.TangentKind:(0,g.EnumerateFloatValues)(s,m,x,_,v,T,y,function(e){e[0]=-e[0]})}}t.convertedToRightHandedBuffers.set(e,s)}var b=l._bufferManager.createBufferView(s,a);t.setVertexBufferView(e,b);for(var M=new Map,w=0,A=i;w<A.length;w++){var C=j(F=A[w],r.get(F)),R=C.kind,E=C.totalVertices;switch(R){case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:if(F.type==g.VertexBuffer.FLOAT){var I=F.getFloatData(E);null!==I&&M.set(F,I)}}}0!==M.size&&g.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var S=0,V=Array.from(M.keys());S<V.length;S++){var F=V[S],B=M.get(F);if(B){for(var O=X(B),N=new(O?Uint16Array:Uint8Array)(B.length),P=0;P<B.length;P++)N[P]=B[P];var U=l._bufferManager.createBufferView(N,4*(O?2:1));t.setRemappedBufferView(e,F,U)}}},l=this,h=0,f=u;h<f.length;h++)c(f[h]);for(var p=0,d=Array.from(o.keys());p<d.length;p++){var m=d[p],x=o.get(m);if(x)for(var _=he(m,x[0],this._bufferManager,this._bufferViews,this._accessors,t.convertToRightHanded),v=0,T=x;v<T.length;v++){var y=T[v];t.bindMorphDataToMesh(y,_)}}},e.prototype._exportNodeAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h=this;return A(this,function(f){switch(f.label){case 0:return void 0!==(r=this._nodeMap.get(e))?(t.includes(r)||t.push(r),[2]):[4,this._createNodeAsync(e,n)];case 1:(o=f.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),i={name:"runtime animations",channels:[],samplers:[]},a=[],this._babylonScene.animationGroups.length||(le._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&le._CreateNodeAnimationFromNodeAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),a.forEach(function(e){e.channels.length&&e.samplers.length&&h._animations.push(e)})),s=o?[]:t,u=0,c=e.getChildren(),f.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:f.sent(),f.label=4;case 4:return u++,[3,2];case 5:return o&&s.length&&(o.children=s),[2]}})})},e.prototype._createNodeAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c,l,h,f,p;return A(this,function(d){switch(d.label){case 0:return this._shouldExportNode(e)?(n={},e.name&&(n.name=e.name),e.metadata&&(r=this._options.metadataSelector(e.metadata))&&(n.extras=r),e instanceof g.TransformNode?(this._setNodeTransformation(n,e,t.convertToRightHanded),e instanceof g.AbstractMesh?(o=e instanceof g.InstancedMesh?e.sourceMesh:e).subMeshes&&o.subMeshes.length>0?(i=n,[4,this._exportMeshAsync(o,t)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:i.mesh=d.sent(),d.label=2;case 2:e.skeleton&&void 0!==(a=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(a)&&this._nodesSkinMap.set(a,[]),null===(h=this._nodesSkinMap.get(a))||void 0===h||h.push(n)),d.label=3;case 3:if(e instanceof g.TargetCamera&&(s=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(s)&&this._nodesCameraMap.set(s,[]),this._setCameraTransformation(n,e,t.convertToRightHanded),null!==(u=e.parent)&&ne(e,u)&&void 0!==(c=this._nodeMap.get(u)))return l=this._nodes[c],te(n,l),null===(f=this._nodesCameraMap.get(s))||void 0===f||f.push(l),[2,null];null===(p=this._nodesCameraMap.get(s))||void 0===p||p.push(n)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",n,e,this._nodeMap,t.convertToRightHanded)];case 4:return d.sent()?[2,n]:(g.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}})})},e.prototype._exportIndices=function(e,t,n,r,o,i,a,s,u){var c=null;u.mode=function(e){switch(e){case g.Material.TriangleFillMode:return 4;case g.Material.TriangleStripDrawMode:return 5;case g.Material.TriangleFanDrawMode:return 6;case g.Material.PointListDrawMode:case g.Material.PointFillMode:return 0;case g.Material.LineLoopDrawMode:return 2;case g.Material.LineListDrawMode:return 1;case g.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}(i);var l=a!==g.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case g.Material.TriangleFillMode:case g.Material.TriangleStripDrawMode:case g.Material.TriangleFanDrawMode:return!0}return!1}(i);if(l){if(i===g.Material.TriangleStripDrawMode||i===g.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");var h=t?new Uint32Array(r):new Uint16Array(r);if(e)for(var f=0;f+2<r;f+=3)h[f]=e[n+f]+o,h[f+1]=e[n+f+2]+o,h[f+2]=e[n+f+1]+o;else for(f=0;f+2<r;f+=3)h[f]=f,h[f+1]=f+2,h[f+2]=f+1;c=h}else if(e&&0!==o){for(h=t?new Uint32Array(r):new Uint16Array(r),f=0;f<r;f++)h[f]=e[n+f]+o;c=h}else e&&(c=function(e,t,n,r){var o=e;return 0===t&&n===e.length||(o=Array.isArray(e)?e.slice(t,t+n):e.subarray(t,t+n)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?r?new Uint32Array(o):new Uint16Array(o):o}(e,n,r,t));if(c){var p=s.getIndicesAccessor(e,n,r,o,l);if(void 0===p){var d=this._bufferManager.createBufferView(c),m=t?5125:5123;this._accessors.push(this._bufferManager.createAccessor(d,"SCALAR",m,r,0)),p=this._accessors.length-1,s.setIndicesAccessor(e,n,r,o,l,p)}u.indices=p}},e.prototype._exportVertexBuffer=function(e,t,n,r,o,i){var a=e.getKind();if(Q(a)&&(!a.startsWith("uv")||this._options.exportUnusedUVs||t&&this._materialNeedsUVsSet.has(t))){var s=o.getVertexAccessor(e,n,r);if(void 0===s){var u=o.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),c=a===g.VertexBuffer.PositionKind?function(e,t,n,r){var o=t.byteOffset,i=t.byteStride,a=t.type,s=t.normalized,u=t.getSize(),c=new Array(u).fill(1/0),l=new Array(u).fill(-1/0);return(0,g.EnumerateFloatValues)(e,o+n*i,i,u,a,r*u,s,function(e){for(var t=0;t<u;t++)c[t]=Math.min(c[t],e[t]),l[t]=Math.max(l[t],e[t])}),{min:c,max:l}}(u,e,n,r):void 0,l=(a===g.VertexBuffer.MatricesIndicesKind||a===g.VertexBuffer.MatricesIndicesExtraKind)&&e.type===g.VertexBuffer.FLOAT,h=l?g.VertexBuffer.UNSIGNED_BYTE:e.type,f=l?void 0:e.normalized,p=l?o.getRemappedBufferView(e._buffer,e):o.getVertexBufferView(e._buffer),d=e.byteOffset+n*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(p,function(e,t){if(e==g.VertexBuffer.ColorKind)return t?"VEC4":"VEC3";switch(e){case g.VertexBuffer.PositionKind:case g.VertexBuffer.NormalKind:return"VEC3";case g.VertexBuffer.TangentKind:case g.VertexBuffer.MatricesIndicesKind:case g.VertexBuffer.MatricesIndicesExtraKind:case g.VertexBuffer.MatricesWeightsKind:case g.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case g.VertexBuffer.UVKind:case g.VertexBuffer.UV2Kind:case g.VertexBuffer.UV3Kind:case g.VertexBuffer.UV4Kind:case g.VertexBuffer.UV5Kind:case g.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(a,o.hasVertexColorAlpha(e)),h,r,d,c,f)),s=this._accessors.length-1,o.setVertexAccessor(e,n,r,s)}i.attributes[function(e){switch(e){case g.VertexBuffer.PositionKind:return"POSITION";case g.VertexBuffer.NormalKind:return"NORMAL";case g.VertexBuffer.TangentKind:return"TANGENT";case g.VertexBuffer.ColorKind:return"COLOR_0";case g.VertexBuffer.UVKind:return"TEXCOORD_0";case g.VertexBuffer.UV2Kind:return"TEXCOORD_1";case g.VertexBuffer.UV3Kind:return"TEXCOORD_2";case g.VertexBuffer.UV4Kind:return"TEXCOORD_3";case g.VertexBuffer.UV5Kind:return"TEXCOORD_4";case g.VertexBuffer.UV6Kind:return"TEXCOORD_5";case g.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case g.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case g.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case g.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(a)]=s}},e.prototype._exportMaterialAsync=function(e,t,n,r){return w(this,void 0,void 0,function(){var o,i;return A(this,function(a){switch(a.label){case 0:return void 0!==(o=this._materialMap.get(e))?[3,8]:(i=t&&Object.keys(t).some(function(e){return e.startsWith("uv")}),(e=e instanceof g.MultiMaterial?e.subMaterials[n.materialIndex]:e)instanceof g.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,i)]:[3,2]);case 1:return o=a.sent(),[3,7];case 2:return e instanceof g.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,i)]:[3,4];case 3:return o=a.sent(),[3,7];case 4:return e instanceof g.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,i)]:[3,6];case 5:return o=a.sent(),[3,7];case 6:return g.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,o),a.label=8;case 8:return r.material=o,[2]}})})},e.prototype._exportMeshAsync=function(e,t){return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c,l,h,f,p,d,m,x,_,v,T,y,b,M,w,R,E,I,S,V,F,B,O,N,P,U,k;return A(this,function(A){switch(A.label){case 0:if(void 0!==(n=t.getMesh(e)))return[2,n];if(r={primitives:[]},n=this._meshes.length,this._meshes.push(r),t.setMesh(e,n),o=e.isUnIndexed?null:e.getIndices(),i=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),a=t.getMorphTargetsFromMesh(e),s=e instanceof g.LinesMesh,u=e instanceof g.GreasedLineBaseMesh,c=e.subMeshes,!(i&&c&&c.length>0))return[3,7];l=0,h=c,A.label=1;case 1:return l<h.length?(f=h[l],p={attributes:{}},d=f.getMaterial()||this._babylonScene.defaultMaterial,u?(v={name:d.name},T=e,m=g.Color3.White(),x=null!==(N=null===(O=T.material)||void 0===O?void 0:O.alpha)&&void 0!==N?N:1,(!(_=null!==(U=null===(P=T.greasedLineMaterial)||void 0===P?void 0:P.color)&&void 0!==U?U:m).equalsWithEpsilon(m,g.Epsilon)||x<1)&&(v.pbrMetallicRoughness={baseColorFactor:C(C([],_.asArray(),!0),[x],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return s?(v={name:d.name},(!(T=e).color.equalsWithEpsilon(g.Color3.White(),g.Epsilon)||T.alpha<1)&&(v.pbrMetallicRoughness={baseColorFactor:C(C([],T.color.asArray(),!0),[T.alpha],!1)}),this._materials.push(v),p.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(d,i,f,p)];case 4:A.sent(),A.label=5;case 5:for(y=s||u?g.Material.LineListDrawMode:null!==(k=e.overrideRenderingFillMode)&&void 0!==k?k:d.fillMode,b=d._getEffectiveOrientation(e),t.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(b=b===g.Material.ClockWiseSideOrientation?g.Material.CounterClockWiseSideOrientation:g.Material.ClockWiseSideOrientation),this._exportIndices(o,o?(0,g.AreIndices32Bits)(o,f.indexCount,f.indexStart,f.verticesStart):f.verticesCount>65535,o?f.indexStart:f.verticesStart,o?f.indexCount:f.verticesCount,-f.verticesStart,y,b,t,p),M=0,w=Object.values(i);M<w.length;M++)R=w[M],this._exportVertexBuffer(R,d,f.verticesStart,f.verticesCount,t,p);if(a)for(p.targets=[],E=0,I=a;E<I.length;E++)F=I[E],p.targets.push(F.attributes);r.primitives.push(p),this._extensionsPostExportMeshPrimitive(p),A.label=6;case 6:return l++,[3,1];case 7:if(a)for(r.weights=[],r.extras||(r.extras={}),r.extras.targetNames=[],S=0,V=a;S<V.length;S++)F=V[S],r.weights.push(F.influence),r.extras.targetNames.push(F.name);return[2,n]}})})},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),de=function(){function e(){}return e.GLTFAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o;return A(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new pe(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e.GLBAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o;return A(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new pe(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e}(),me="EXT_mesh_gpu_instancing";function ge(e,t){for(var n=new Float32Array(3*t),r=0;r<t;r++)n[3*r+0]=e[4*r+0],n[3*r+1]=e[4*r+1],n[3*r+2]=e[4*r+2];return n}var xe=function(){function e(e){this.name=me,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,t,n,r,o,i){return w(this,void 0,void 0,function(){var e=this;return A(this,function(r){switch(r.label){case 0:return[4,new Promise(function(r){var a,s;if(t&&n instanceof g.Mesh&&n.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var u=g.Vector3.Zero(),c=g.Quaternion.Identity(),l=g.Vector3.One(),h=n.thinInstanceGetWorldMatrices(),f=g.TmpVectors.Vector3[2],p=g.TmpVectors.Quaternion[1],d=g.TmpVectors.Vector3[3],m=!1,x=!1,_=!1,v=new Float32Array(3*n.thinInstanceCount),T=new Float32Array(4*n.thinInstanceCount),y=new Float32Array(3*n.thinInstanceCount),b=0,M=0,w=h;M<w.length;M++)w[M].decompose(d,p,f),o&&(Y(f),$(p)),v.set(f.asArray(),3*b),T.set(p.normalize().asArray(),4*b),y.set(d.asArray(),3*b),m=m||!f.equalsWithEpsilon(u),x=x||!p.equalsWithEpsilon(c),_=_||!d.equalsWithEpsilon(l),b++;var A={attributes:{}};m&&(A.attributes.TRANSLATION=e._buildAccessor(v,"VEC3",n.thinInstanceCount,i)),x&&(A.attributes.ROTATION=e._buildAccessor(T,"VEC4",n.thinInstanceCount,i)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",n.thinInstanceCount,i));var C=null===(s=null===(a=n._userThinInstanceBuffersStorage)||void 0===a?void 0:a.data)||void 0===s?void 0:s.instanceColor;if(C){var R=n.thinInstanceCount;n.hasVertexAlpha&&C.length===4*R?(e._instanceColorWarned||(g.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),C=ge(C,R)):C.length===4*R&&(C=ge(C,R)),C.length===3*R&&(A.attributes._COLOR_0=e._buildAccessor(C,"VEC3",R,i))}t.extensions=t.extensions||{},t.extensions[me]=A}r(t)})];case 1:return[2,r.sent()]}})})},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),i=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();pe.RegisterExtension(me,function(e){return new xe(e)});var _e="KHR_draco_mesh_compression";function ve(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}var Te=function(){function e(e){this.name=_e,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&g.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,t,n){var r=this;if(this.enabled)if(4===e.mode||5===e.mode){var o=[],i=[],a=null;if(void 0!==e.indices){var s=n[e.indices],u=t.getBufferView(s);a=t.getData(u).slice(),o.push(u),i.push(s)}for(var c=[],l=0,h=Object.entries(e.attributes);l<h.length;l++){var f=h[l],p=f[0],d=(s=n[f[1]],u=t.getBufferView(s),H(s.type)),m=(0,g.GetTypedArrayData)(t.getData(u),d,s.componentType,s.byteOffset||0,u.byteStride||(0,g.GetTypeByteLength)(s.componentType)*d,s.count,!0);c.push({kind:p,dracoName:ve(p),size:H(s.type),data:m}),o.push(u),i.push(s)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},_=g.DracoEncoder.Default._encodeAsync(c,a,x).then(function(n){var a={bufferView:-1,attributes:n.attributeIds},s=t.createBufferView(n.data);t.setBufferView(a,s);for(var u=0,c=o;u<c.length;u++){var l=c[u];r._bufferViewsUsed.add(l)}for(var h=0,f=i;h<f.length;h++){var p=f[h];r._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[_e]=a}).catch(function(e){g.Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. "+e.message)});this._encodePromises.push(_),this._wasUsed=!0}else g.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return w(this,void 0,void 0,function(){var t=this;return A(this,function(n){switch(n.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return n.sent(),this._bufferViewsUsed.forEach(function(n){e.getPropertiesWithBufferView(n).every(function(e){return t._accessorsUsed.has(e)})&&e.removeBufferView(n)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}})})},e}();pe.RegisterExtension(_e,function(e){return new Te(e)});var ye="KHR_lights_punctual",be={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},Me={innerConeAngle:0,outerConeAngle:Math.PI/4},we=g.Vector3.Backward(),Ae=function(){function e(e){this.name=ye,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[ye]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return w(this,void 0,void 0,function(){var i=this;return A(this,function(a){switch(a.label){case 0:return[4,new Promise(function(a){if(n instanceof g.Light){var s=n.getTypeID()==g.Light.LIGHTTYPEID_POINTLIGHT?"point":n.getTypeID()==g.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":n.getTypeID()==g.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(s&&n instanceof g.ShadowLight))return g.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(ye)),void a(t);if(n.falloffType!==g.Light.FALLOFF_GLTF&&g.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(ye," specification!")),!n.position.equalsToFloats(0,0,0)){var u=g.TmpVectors.Vector3[0].copyFrom(n.position);o&&Y(u),t.translation=u.asArray()}if("point"!==s){var c=n.direction.normalizeToRef(g.TmpVectors.Vector3[0]);o&&Y(c);var l=g.Quaternion.FromUnitVectorsToRef(we,c,g.TmpVectors.Quaternion[0]);g.Quaternion.IsIdentity(l)||(t.rotation=l.asArray())}var h={type:s,name:n.name,color:n.diffuse.asArray(),intensity:n.intensity,range:n.range};if(re(h,be),"spot"===s){var f=n;h.spot={innerConeAngle:f.innerAngle/2,outerConeAngle:f.angle/2},re(h.spot,Me)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(h);var p={light:i._lights.lights.length-1},d=n.parent;if(d&&ne(n,d)){var m=r.get(d);if(m){var x=i._exporter._nodes[m];return te(t,x),x.extensions||(x.extensions={}),x.extensions[ye]=p,void a(null)}}t.extensions||(t.extensions={}),t.extensions[ye]=p,a(t)}else a(t)})];case 1:return[2,a.sent()]}})})},e}();pe.RegisterExtension(ye,function(e){return new Ae(e)});var Ce="EXT_lights_area",Re={name:"",color:[1,1,1],intensity:1,size:1},Ee={aspect:1},Ie=g.Vector3.Backward(),Se=function(){function e(e){this.name=Ce,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[Ce]=this._lights},e.prototype.postExportNodeAsync=function(e,t,n,r,o){return w(this,void 0,void 0,function(){var i=this;return A(this,function(a){switch(a.label){case 0:return[4,new Promise(function(a){if(n instanceof g.Light){var s=n.getTypeID()==g.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!s)return g.Logger.Warn("".concat(e,": Light ").concat(n.name," is not supported in ").concat(Ce)),void a(t);var u=n;if(u.falloffType!==g.Light.FALLOFF_GLTF&&g.Logger.Warn("".concat(e,": Light falloff for ").concat(n.name," does not match the ").concat(Ce," specification!")),!u.position.equalsToFloats(0,0,0)){var c=g.TmpVectors.Vector3[0].copyFrom(u.position);o&&Y(c),t.translation=c.asArray()}var l=g.Vector3.Forward();o&&Y(l);var h=g.Quaternion.FromUnitVectorsToRef(Ie,l,g.TmpVectors.Quaternion[0]);g.Quaternion.IsIdentity(h)||(t.rotation=h.asArray());var f={type:s,name:u.name,color:u.diffuse.asArray(),intensity:u.intensity,size:u.height,rect:{aspect:u.width/u.height}};re(f,Re),f.rect&&re(f.rect,Ee),i._lights||(i._lights={lights:[]}),i._lights.lights.push(f);var p={light:i._lights.lights.length-1},d=n.parent;if(d&&ne(u,d)){var m=r.get(d);if(m){var x=i._exporter._nodes[m];return te(t,x),x.extensions||(x.extensions={}),x.extensions[Ce]=p,void a(null)}}t.extensions||(t.extensions={}),t.extensions[Ce]=p,a(t)}else a(t)})];case 1:return[2,a.sent()]}})})},e}();pe.RegisterExtension(Ce,function(e){return new Se(e)});var Ve="KHR_materials_anisotropy";function Fe(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.specularRoughnessAnisotropyTexture,r=e.geometryTangentTexture,n||r?[4,(0,g.MergeTexturesAsync)("AnisotropyTexture",(0,g.CreateRGBAConfiguration)(r?(0,g.CreateTextureInput)(r,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,1):(0,g.CreateConstantInput)(0),n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}})})}var Be=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,t,n){return w(this,void 0,void 0,function(){var e,t,r;return A(this,function(o){switch(o.label){case 0:return e=[],n instanceof g.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 g.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0?(t=function(e){var t=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}(n),this._anisoTexturesMap[t]?(e.push(this._anisoTexturesMap[t]),[3,4]):[3,2]):[3,5];case 2:return[4,Fe(n)];case 3:(r=o.sent())&&(e.push(r),this._anisoTexturesMap[t]=r),o.label=4;case 4:return[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o,i,a,s,u,c;if(n instanceof g.PBRBaseMaterial){if(!n.anisotropy.isEnabled||n.anisotropy.legacy)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var l=r._exporter._materialExporter.getTextureInfo(n.anisotropy.texture);null!==(v={anisotropyStrength:n.anisotropy.intensity,anisotropyRotation:n.anisotropy.angle,anisotropyTexture:null!=l?l:void 0}).anisotropyTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[Ve]=v}else if(n instanceof g.OpenPBRMaterial&&n.specularRoughnessAnisotropy>0){r._wasUsed=!0,t.extensions=t.extensions||{};var h=n.specularRoughnessTexture;n._useRoughnessFromMetallicTextureGreen&&(h=n.baseMetalnessTexture);var f=r._anisoTexturesMap[n.id];if(!h&&!f){var p=n.specularRoughness,d=n.specularRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var m=(i=n.specularRoughness,c=(1-(a=n.specularRoughnessAnisotropy))*(u=(s=i*i)*Math.sqrt(2/(1+(1-a)*(1-a)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});p=m.newBaseRoughness,d=m.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=p);var x={anisotropyStrength:d,anisotropyRotation:n.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return t.extensions[Ve]=x,e(t)}var _=f?r._exporter._materialExporter.getTextureInfo(f):null,v={anisotropyStrength:n.specularRoughnessAnisotropy,anisotropyRotation:n.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};n._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=r._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&r._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),r._exporter._materialNeedsUVsSet.add(n),t.extensions[Ve]=v}e(t)})},e}();pe.RegisterExtension(Ve,function(e){return new Be(e)});var Oe="KHR_materials_clearcoat";function Ne(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.coatWeightTexture,r=e.coatRoughnessTexture,n||r?[4,(0,g.MergeTexturesAsync)("CoatTexture",(0,g.CreateRGBAConfiguration)(n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,e._useCoatRoughnessFromGreenChannel?1:0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}})})}function Pe(e,t){var n=new g.Texture(t.name,t.getScene());return n._texture=e,n.coordinatesIndex=t.coordinatesIndex,t instanceof g.Texture&&(n.uOffset=t.uOffset,n.vOffset=t.vOffset,n.uScale=t.uScale,n.vScale=t.vScale,n.wAng=t.wAng),n.wrapU=t.wrapU,n.wrapV=t.wrapV,n}var Ue=function(){function e(e){this.name=Oe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e,t,r,o;return A(this,function(i){switch(i.label){case 0:return e=[],n instanceof g.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 g.OpenPBRMaterial&&n.coatWeight>0?(t=!1,n.coatWeightTexture?n.coatRoughnessTexture?n._useCoatRoughnessFromGreenChannel&&n.coatWeightTexture.getInternalTexture()===n.coatRoughnessTexture.getInternalTexture()?(e.push(n.coatWeightTexture),e.push(n.coatRoughnessTexture)):t=!0:e.push(n.coatWeightTexture):n.coatRoughnessTexture&&(n._useCoatRoughnessFromGreenChannel?e.push(n.coatRoughnessTexture):t=!0),t?(r=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(n),this._cachedInternalTexturesMap[r]?[3,3]:[4,Ne(n)]):[3,4]):[3,5];case 2:(o=i.sent())&&(this._cachedInternalTexturesMap[r]=o),i.label=3;case 3:this._cachedInternalTexturesMap[r]&&(n.coatWeightTexture&&(this._mergedTexturesMap[n.coatWeightTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[r],n.coatWeightTexture),e.push(this._mergedTexturesMap[n.coatWeightTexture.uniqueId])),n.coatRoughnessTexture&&(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]=Pe(this._cachedInternalTexturesMap[r],n.coatRoughnessTexture),e.push(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]))),i.label=4;case 4:return n.geometryCoatNormalTexture&&e.push(n.geometryCoatNormalTexture),[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o,i=r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture);o=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness),n.clearCoat.isTintEnabled&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),n.clearCoat.remapF0OnInterfaceChange&&g.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(n.name));var a=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture);null===(c={clearcoatFactor:n.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:n.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=a?a:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Oe]=c}else if(n instanceof g.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var s=void 0,u=void 0;n.coatWeightTexture&&(s=r._mergedTexturesMap[n.coatWeightTexture.uniqueId],u=r._exporter._materialExporter.getTextureInfo(s));var c,l=void 0,h=void 0;n.coatRoughnessTexture&&(l=r._mergedTexturesMap[n.coatRoughnessTexture.uniqueId],h=r._exporter._materialExporter.getTextureInfo(l)),n.coatColorTexture&&g.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(n.name)),a=r._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),null===(c={clearcoatFactor:n.coatWeight,clearcoatTexture:null!=u?u:void 0,clearcoatRoughnessFactor:n.coatRoughness,clearcoatRoughnessTexture:null!=h?h:void 0,clearcoatNormalTexture:null!=a?a:void 0}).clearcoatTexture&&null===c.clearcoatRoughnessTexture&&null===c.clearcoatRoughnessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[Oe]=c}e(t)})},e}();pe.RegisterExtension(Oe,function(e){return new Ue(e)});var ke="KHR_materials_coat";function We(e){var t=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}function De(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.coatRoughnessAnisotropyTexture,r=e.geometryCoatTangentTexture,n||r?[4,(0,g.MergeTexturesAsync)("AnisotropyTexture",(0,g.CreateRGBAConfiguration)(r?(0,g.CreateTextureInput)(r,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,1):(0,g.CreateConstantInput)(0),n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent()]}})})}function ze(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.coatWeightTexture,r=e.coatRoughnessTexture,n||r?[4,(0,g.MergeTexturesAsync)("CoatTexture",(0,g.CreateRGBAConfiguration)(n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,e._useCoatRoughnessFromGreenChannel?1:0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}})})}function Le(e,t){var n=new g.Texture(t.name,t.getScene());return n._texture=e,n.coordinatesIndex=t.coordinatesIndex,t instanceof g.Texture&&(n.uOffset=t.uOffset,n.vOffset=t.vOffset,n.uScale=t.uScale,n.vScale=t.vScale,n.wAng=t.wAng),n.wrapU=t.wrapU,n.wrapV=t.wrapV,n}var Ke=function(){function e(e){this.name=ke,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e,t,r,o,i;return A(this,function(a){switch(a.label){case 0:return e=[],n instanceof g.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 g.OpenPBRMaterial&&n.coatWeight>0?(t=!1,n.coatWeightTexture?n.coatRoughnessTexture?n._useCoatRoughnessFromGreenChannel&&n.coatWeightTexture.getInternalTexture()===n.coatRoughnessTexture.getInternalTexture()?(e.push(n.coatWeightTexture),e.push(n.coatRoughnessTexture)):t=!0:e.push(n.coatWeightTexture):n.coatRoughnessTexture&&(n._useCoatRoughnessFromGreenChannel?e.push(n.coatRoughnessTexture):t=!0),t?(o=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(n),this._cachedInternalTexturesMap[o]?[3,3]:[4,ze(n)]):[3,4]):[3,9];case 2:(r=a.sent())&&(this._cachedInternalTexturesMap[o]=r),a.label=3;case 3:this._cachedInternalTexturesMap[o]&&(n.coatWeightTexture&&(this._mergedTexturesMap[n.coatWeightTexture.uniqueId]=Le(this._cachedInternalTexturesMap[o],n.coatWeightTexture),e.push(this._mergedTexturesMap[n.coatWeightTexture.uniqueId])),n.coatRoughnessTexture&&(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]=Le(this._cachedInternalTexturesMap[o],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?(o=We(n),this._mergedTexturesMap[o]?(e.push(this._mergedTexturesMap[o]),[3,7]):[3,5]):[3,8];case 5:return[4,De(n)];case 6:(i=a.sent())&&(e.push(i),this._mergedTexturesMap[o]=i),a.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o,i,a,s,u,c;if(n instanceof g.PBRBaseMaterial){if(!n.clearCoat.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var l,h=r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture);l=n.clearCoat.useRoughnessFromMainTexture?r._exporter._materialExporter.getTextureInfo(n.clearCoat.texture):r._exporter._materialExporter.getTextureInfo(n.clearCoat.textureRoughness);var f=void 0;n.clearCoat.isTintEnabled&&(f=r._exporter._materialExporter.getTextureInfo(n.clearCoat.tintTexture));var p=r._exporter._materialExporter.getTextureInfo(n.clearCoat.bumpTexture),d=n.clearCoat.indexOfRefraction;null===(v={coatFactor:n.clearCoat.intensity,coatTexture:null!=h?h:void 0,coatRoughnessFactor:n.clearCoat.roughness,coatRoughnessTexture:null!=l?l:void 0,coatNormalTexture:null!=p?p:void 0,coatColorFactor:n.clearCoat.tintColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==d?d:void 0}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatColorTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[ke]=v}else if(n instanceof g.OpenPBRMaterial){if(0==n.coatWeight)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var m=void 0;h=void 0,n.coatWeightTexture&&(m=r._mergedTexturesMap[n.coatWeightTexture.uniqueId]?r._mergedTexturesMap[n.coatWeightTexture.uniqueId]:n.coatWeightTexture,h=r._exporter._materialExporter.getTextureInfo(m));var x=void 0,_=void 0;n.coatRoughnessTexture&&(x=r._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]?r._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]:n.coatRoughnessTexture,_=r._exporter._materialExporter.getTextureInfo(x)),p=r._exporter._materialExporter.getTextureInfo(n.geometryCoatNormalTexture),f=r._exporter._materialExporter.getTextureInfo(n.coatColorTexture),d=n.coatIor;var v,T=n.coatDarkening,y=n.coatRoughnessTexture,b=We(n),M=r._mergedTexturesMap[b],w=0,A=0,C=void 0;if(n.coatRoughnessAnisotropy>0){if(y||M){var R=M?r._exporter._materialExporter.getTextureInfo(M):null;w=n.coatRoughnessAnisotropy,A=n.geometryCoatTangentAngle,C=R||void 0}else{var E=n.coatRoughness,I=n.coatRoughnessAnisotropy;if(!n._useGltfStyleAnisotropy){var S=(i=n.coatRoughness,c=(1-(a=n.coatRoughnessAnisotropy))*(u=(s=i*i)*Math.sqrt(2/(1+(1-a)*(1-a)))),{newBaseRoughness:Math.sqrt(c),newAnisotropyStrength:Math.min(Math.sqrt((u-s)/Math.max(1-s,1e-4)),1)});E=S.newBaseRoughness,I=S.newAnisotropyStrength}t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=E),w=I,A=n.geometryCoatTangentAngle+.5*Math.PI,C=void 0}n._useGltfStyleAnisotropy||(t.extensions.KHR_materials_openpbr={},(o=r._exporter._glTF).extensionsUsed||(o.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&r._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(v={coatFactor:n.coatWeight,coatTexture:null!=h?h:void 0,coatRoughnessFactor:n.coatRoughness,coatRoughnessTexture:null!=_?_:void 0,coatNormalTexture:null!=p?p:void 0,coatColorFactor:n.coatColor.asArray(),coatColorTexture:null!=f?f:void 0,coatIor:1.5!==d?d:void 0,coatDarkeningFactor:1!==T?T:void 0,coatAnisotropyRotation:A,coatAnisotropyStrength:w,coatAnisotropyTexture:C}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatAnisotropyTexture&&null===v.coatColorTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[ke]=v}e(t)})},e}();pe.RegisterExtension(ke,function(e){return new Ke(e)});var qe="KHR_materials_diffuse_transmission";function Ge(e,t){var n=t.subSurface,r=null;return n.translucencyIntensityTexture?r=n.translucencyIntensityTexture:n.thicknessTexture&&n.useMaskFromThicknessTexture&&(r=n.thicknessTexture),r&&!n.useGltfStyleTextures?(g.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(t.name),1),null):r}var je=function(){function e(e){this.name=qe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var t,r;return A(this,function(o){return t=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?((r=Ge(e,n))&&t.push(r),n.subSurface.translucencyColorTexture&&t.push(n.subSurface.translucencyColorTexture),[2,t]):[2,t]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(o){var i,a;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var s=n.subSurface,u=Ge(e,n),c=0==s.translucencyIntensity?void 0:s.translucencyIntensity,l=null!==(i=r._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0,h=!s.translucencyColor||s.translucencyColor.equalsFloats(1,1,1)?void 0:s.translucencyColor.asArray(),f=null!==(a=r._exporter._materialExporter.getTextureInfo(s.translucencyColorTexture))&&void 0!==a?a:void 0,p={diffuseTransmissionFactor:c,diffuseTransmissionTexture:l,diffuseTransmissionColorFactor:h,diffuseTransmissionColorTexture:f};(l||f)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[qe]=p}o(t)})},e}();pe.RegisterExtension(qe,function(e){return new je(e)});var He="KHR_materials_dispersion",Xe=function(){function e(){this.name=He,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={dispersion:n.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[He]=o}e(t)})},e}();pe.RegisterExtension(He,function(){return new Xe});var Qe="KHR_materials_emissive_strength",Ze=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,t,n){return w(this,void 0,void 0,function(){var e=this;return A(this,function(r){switch(r.label){case 0:return[4,new Promise(function(r){if(!(n instanceof g.PBRMaterial))return r(t);var o=n.emissiveColor.scale(n.emissiveIntensity),i=Math.max.apply(Math,o.asArray());if(i>1){t.emissiveFactor=o.scale(1/i).asArray(),e._wasUsed=!0;var a={emissiveStrength:i};t.extensions||(t.extensions={}),t.extensions[Qe]=a}else t.emissiveFactor=o.asArray();return r(t)})];case 1:return[2,r.sent()]}})})},e}();pe.RegisterExtension(Qe,function(){return new Ze});var Ye="KHR_materials_ior",Je=function(){function e(){this.name=Ye,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o={ior:n.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[Ye]=o}e(t)})},e}();pe.RegisterExtension(Ye,function(e){return new Je});var $e="KHR_materials_iridescence",et=function(){function e(e){this.name=$e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){if(e=[],n instanceof g.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 g.OpenPBRMaterial&&n.thinFilmWeight>0)return n.thinFilmWeightTexture&&e.push(n.thinFilmWeightTexture),n.thinFilmThicknessTexture&&n.thinFilmThicknessTexture!==n.thinFilmWeightTexture&&e.push(n.thinFilmThicknessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.PBRBaseMaterial){if(!n.iridescence.isEnabled)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var o=r._exporter._materialExporter.getTextureInfo(n.iridescence.texture),i=r._exporter._materialExporter.getTextureInfo(n.iridescence.thicknessTexture);null===(a={iridescenceFactor:n.iridescence.intensity,iridescenceIor:n.iridescence.indexOfRefraction,iridescenceThicknessMinimum:n.iridescence.minimumThickness,iridescenceThicknessMaximum:n.iridescence.maximumThickness,iridescenceTexture:null!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0}).iridescenceTexture&&null===a.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[$e]=a}else if(n instanceof g.OpenPBRMaterial){if(n.thinFilmWeight<=0)return void e(t);r._wasUsed=!0,t.extensions=t.extensions||{};var a,s=r._exporter._materialExporter.getTextureInfo(n.thinFilmWeightTexture),u=r._exporter._materialExporter.getTextureInfo(n.thinFilmThicknessTexture);null===(a={iridescenceFactor:n.thinFilmWeight,iridescenceIor:n.thinFilmIor,iridescenceThicknessMinimum:1e3*n.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*n.thinFilmThickness,iridescenceTexture:null!=s?s:void 0,iridescenceThicknessTexture:null!=u?u:void 0}).iridescenceTexture&&null===a.iridescenceThicknessTexture||r._exporter._materialNeedsUVsSet.add(n),t.extensions[$e]=a}e(t)})},e}();pe.RegisterExtension($e,function(e){return new et(e)});var tt="KHR_materials_sheen",nt=function(){function e(e){this.name=tt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){return A(this,function(e){return n instanceof g.PBRMaterial&&n.sheen.isEnabled&&n.sheen.texture?[2,[n.sheen.texture]]:[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e=this;return A(this,function(r){switch(r.label){case 0:return[4,new Promise(function(r){var o,i,a,s;if(n instanceof g.PBRMaterial){if(!n.sheen.isEnabled)return void r(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:n.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=n.sheen.roughness)&&void 0!==o?o:0};null===u.sheenColorTexture&&null===u.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),n.sheen.texture&&(u.sheenColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==i?i:void 0),n.sheen.textureRoughness&&!n.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(n.sheen.textureRoughness))&&void 0!==a?a:void 0:n.sheen.texture&&n.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(n.sheen.texture))&&void 0!==s?s:void 0),t.extensions[tt]=u}r(t)})];case 1:return[2,r.sent()]}})})},e}();pe.RegisterExtension(tt,function(e){return new nt(e)});var rt="KHR_materials_fuzz";function ot(e){return w(this,void 0,void 0,function(){var t,n,r;return A(this,function(o){switch(o.label){case 0:return t=e.getScene(),n=e.fuzzColorTexture,r=e.fuzzRoughnessTexture,n||r?[4,(0,g.MergeTexturesAsync)("FuzzTexture",(0,g.CreateRGBAConfiguration)(n?(0,g.CreateTextureInput)(n,0):(0,g.CreateConstantInput)(1),n?(0,g.CreateTextureInput)(n,1):(0,g.CreateConstantInput)(1),n?(0,g.CreateTextureInput)(n,2):(0,g.CreateConstantInput)(1),r?(0,g.CreateTextureInput)(r,e._useFuzzRoughnessFromTextureAlpha?3:0):(0,g.CreateConstantInput)(1)),t)]:[2,null];case 1:return[2,o.sent().getInternalTexture()]}})})}function it(e,t){var n=new g.Texture(t.name,t.getScene());return n._texture=e,n.coordinatesIndex=t.coordinatesIndex,t instanceof g.Texture&&(n.uOffset=t.uOffset,n.vOffset=t.vOffset,n.uScale=t.uScale,n.vScale=t.vScale,n.wAng=t.wAng),n.wrapU=t.wrapU,n.wrapV=t.wrapV,n}var at=function(){function e(e){this.name=rt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e,t,r,o;return A(this,function(i){switch(i.label){case 0:return n instanceof g.OpenPBRMaterial?(e=[],n.fuzzWeight>0?(n.fuzzWeightTexture&&e.push(n.fuzzWeightTexture),t=!1,n.fuzzRoughnessTexture&&(n._useFuzzRoughnessFromTextureAlpha?e.push(n.fuzzRoughnessTexture):t=!0),n.fuzzColorTexture&&!t&&e.push(n.fuzzColorTexture),t?(r=function(e){var t=e.fuzzColorTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",r=e.fuzzRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(n,"_FuzzRoughness_").concat(o)}(n),this._cachedInternalTexturesMap[r]?[3,2]:[4,ot(n)]):[3,3]):[3,3]):[3,4];case 1:(o=i.sent())&&(this._cachedInternalTexturesMap[r]=o),i.label=2;case 2:this._cachedInternalTexturesMap[r]&&(n.fuzzColorTexture&&(this._mergedTexturesMap[n.fuzzColorTexture.uniqueId]=it(this._cachedInternalTexturesMap[r],n.fuzzColorTexture),e.push(this._mergedTexturesMap[n.fuzzColorTexture.uniqueId])),n.fuzzRoughnessTexture&&(this._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]=it(this._cachedInternalTexturesMap[r],n.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]))),i.label=3;case 3:return[2,e];case 4:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e=this;return A(this,function(r){switch(r.label){case 0:return[4,new Promise(function(r){var o,i,a;if(n instanceof g.OpenPBRMaterial){if(0==n.fuzzWeight)return void r(t);e._wasUsed=!0,null==t.extensions&&(t.extensions={});var s={fuzzFactor:n.fuzzWeight,fuzzColorFactor:n.fuzzColor.asArray(),fuzzRoughnessFactor:n.fuzzRoughness};n.fuzzWeightTexture&&(s.fuzzTexture=null!==(o=e._exporter._materialExporter.getTextureInfo(n.fuzzWeightTexture))&&void 0!==o?o:void 0);var u=void 0;n.fuzzColorTexture&&(u=e._mergedTexturesMap[n.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[n.fuzzColorTexture.uniqueId]:n.fuzzColorTexture,s.fuzzColorTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(u))&&void 0!==i?i:void 0);var c=void 0;n.fuzzRoughnessTexture&&(c=e._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[n.fuzzRoughnessTexture.uniqueId]:n.fuzzRoughnessTexture,s.fuzzRoughnessTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==a?a:void 0),null===s.fuzzColorTexture&&null===s.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(n),t.extensions[rt]=s}r(t)})];case 1:return[2,r.sent()]}})})},e}();pe.RegisterExtension(rt,function(e){return new at(e)});var st="KHR_materials_specular",ut=function(){function e(e){this.name=st,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){return e=[],n instanceof g.PBRMaterial&&this._isExtensionEnabled(n)?(n.metallicReflectanceTexture&&e.push(n.metallicReflectanceTexture),n.reflectanceTexture&&e.push(n.reflectanceTexture),[2,e]):[2,e]})})},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o,i,a,s,u;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0,t.extensions=t.extensions||{};var c=null!==(o=r._exporter._materialExporter.getTextureInfo(n.metallicReflectanceTexture))&&void 0!==o?o:void 0,l=null!==(i=r._exporter._materialExporter.getTextureInfo(n.reflectanceTexture))&&void 0!==i?i:void 0,h={specularFactor:1==n.metallicF0Factor?void 0:n.metallicF0Factor,specularTexture:c,specularColorFactor:n.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:n.metallicReflectanceColor.asArray(),specularColorTexture:l};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[st]=h}else if(n instanceof g.OpenPBRMaterial){t.extensions=t.extensions||{};var f=null!==(a=r._exporter._materialExporter.getTextureInfo(n.specularWeightTexture))&&void 0!==a?a:void 0,p=null!==(s=r._exporter._materialExporter.getTextureInfo(n.specularColorTexture))&&void 0!==s?s:void 0,d=1==n.specularWeight?void 0:n.specularWeight,m=n.specularColor.equalsFloats(1,1,1)?void 0:n.specularColor.asArray();if(!p&&!f&&void 0===d&&void 0===m)return e(t);r._wasUsed=!0,(h={specularFactor:d,specularTexture:f,specularColorFactor:m,specularColorTexture:p,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(u=r._exporter._glTF).extensionsUsed||(u.extensionsUsed=[]),-1===r._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&r._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(f||p)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[st]=h}e(t)})},e}();pe.RegisterExtension(st,function(e){return new ut(e)});var ct="KHR_materials_transmission",lt=function(){function e(e){this.name=ct,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){if(e=[],n instanceof g.PBRMaterial){if(this._isExtensionEnabled(n))return n.subSurface.refractionIntensityTexture&&n.subSurface.useGltfStyleTextures&&e.push(n.subSurface.refractionIntensityTexture),[2,e]}else n instanceof g.OpenPBRMaterial&&(n.transmissionWeight>0&&n.transmissionWeightTexture&&e.push(n.transmissionWeightTexture),n.subsurfaceWeight>0&&n.subsurfaceWeightTexture&&e.push(n.subsurfaceWeightTexture));return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e instanceof g.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0||e.subsurfaceWeight>0;if(e instanceof g.PBRMaterial&&!e.unlit){var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||null!=t.refractionIntensityTexture&&t.useGltfStyleTextures}return!1},e.prototype.postExportMaterialAsync=function(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u;return A(this,function(c){return this._isExtensionEnabled(n)?(n instanceof g.PBRMaterial?(this._wasUsed=!0,r=n.subSurface,i=0===r.refractionIntensity?void 0:r.refractionIntensity,a={transmissionFactor:i},r.refractionIntensityTexture&&(r.useGltfStyleTextures?(this._exporter._materialNeedsUVsSet.add(n),(s=this._exporter._materialExporter.getTextureInfo(r.refractionIntensityTexture))&&(a.transmissionTexture=s)):g.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported"))),t.extensions||(t.extensions={}),t.extensions[ct]=a):n instanceof g.OpenPBRMaterial&&(this._wasUsed=!0,o=(1-n.transmissionWeight)*n.subsurfaceWeight,i=o+n.transmissionWeight,a={transmissionFactor:i},n.transmissionWeightTexture?(this._exporter._materialNeedsUVsSet.add(n),(s=this._exporter._materialExporter.getTextureInfo(n.transmissionWeightTexture))&&(a.transmissionTexture=s)):n.subsurfaceWeightTexture&&(this._exporter._materialNeedsUVsSet.add(n),(u=this._exporter._materialExporter.getTextureInfo(n.subsurfaceWeightTexture))&&(a.transmissionTexture=u)),1===i&&t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=void 0),t.extensions||(t.extensions={}),t.extensions[ct]=a),[2,t]):[2,t]})})},e}();pe.RegisterExtension(ct,function(e){return new lt(e)});var ht="KHR_materials_unlit",ft=function(){function e(){this.name=ht,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o=!1;n instanceof g.PBRMaterial?o=n.unlit:n instanceof g.StandardMaterial&&(o=n.disableLighting),o&&(r._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[ht]={}),e(t)})},e}();pe.RegisterExtension(ht,function(){return new ft});var pt="KHR_materials_volume",dt=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,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){if(e=[],n instanceof g.PBRMaterial){if(this._isExtensionEnabled(n))return n.subSurface.thicknessTexture&&e.push(n.subSurface.thicknessTexture),[2,e]}else n instanceof g.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 t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isTranslucencyEnabled)&&(null!=t.maximumThickness&&0!=t.maximumThickness||null!=t.tintColorAtDistance&&t.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=t.tintColor&&t.tintColor!=g.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o,i;if(n instanceof g.PBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var a=n.subSurface,s={thicknessFactor:h=0==a.maximumThickness?void 0:a.maximumThickness,thicknessTexture:l=null!==(o=r._exporter._materialExporter.getTextureInfo(a.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:a.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:a.tintColorAtDistance,attenuationColor:V=a.tintColor.equalsFloats(1,1,1)?void 0:a.tintColor.asArray()};r._hasTexturesExtension(n)&&r._exporter._materialNeedsUVsSet.add(n),t.extensions=t.extensions||{},t.extensions[pt]=s}else if(n instanceof g.OpenPBRMaterial){var u=n.transmissionWeight>0&&!n.geometryThinWalled&&n.transmissionDepth>0,c=n.subsurfaceWeight>0&&!n.geometryThinWalled;if(u||c){r._wasUsed=!0;var l,h=n.geometryThickness;(l=null!==(i=r._exporter._materialExporter.getTextureInfo(n.geometryThicknessTexture))&&void 0!==i?i:void 0)&&r._exporter._materialNeedsUVsSet.add(n);var f=1,p=g.Color3.White().asArray();if(u){var d=1/n.transmissionDepth,m=new g.Vector3(-Math.log(n.transmissionColor.r)*d,-Math.log(n.transmissionColor.g)*d,-Math.log(n.transmissionColor.b)*d),x=new g.Vector3(n.transmissionScatter.r*d,n.transmissionScatter.g*d,n.transmissionScatter.b*d),_=m.subtract(x),v=Math.min(_.x,_.y,_.z);v<0&&(_.x=_.x-v,_.y=_.y-v,_.z=_.z-v),m=_.add(x),f=1/Math.max(m.x,m.y,m.z),p[0]=Math.exp(-m.x*f),p[1]=Math.exp(-m.y*f),p[2]=Math.exp(-m.z*f)}var T=1,y=g.Color3.White().asArray();if(c){var b=n.subsurfaceRadius,M=n.subsurfaceRadiusScale,w=new g.Vector3(M.r,M.g,M.b).multiplyByFloats(b,b,b),A=new g.Vector3(1/Math.max(w.x,1e-6),1/Math.max(w.y,1e-6),1/Math.max(w.z,1e-6));T=1/Math.max(A.x,A.y,A.z),y[0]=Math.exp(-A.x*T),y[1]=Math.exp(-A.y*T),y[2]=Math.exp(-A.z*T)}var C=(1-n.transmissionWeight)*n.subsurfaceWeight,R=C+n.transmissionWeight,E=1/Math.max(R,1e-6),I=n.transmissionWeight*E,S=C*E,V=p.map(function(e,t){return e*I+y[t]*S});s={thicknessFactor:h,thicknessTexture:l,attenuationDistance:f*I+T*S,attenuationColor:V},t.extensions=t.extensions||{},t.extensions[pt]=s}}e(t)})},e}();pe.RegisterExtension(pt,function(e){return new dt(e)});var mt="KHR_materials_volume_scatter",gt=function(){function e(e){this.name=mt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){return e=[],n instanceof g.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 t=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(g.Color3.Black()),n=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!t&&!n)},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){if(n instanceof g.OpenPBRMaterial&&r._isExtensionEnabled(n)){r._wasUsed=!0;var o=g.Vector3.Zero(),i=0;if(n.transmissionWeight>0){var a=1/n.transmissionDepth,s=new g.Vector3(-Math.log(n.transmissionColor.r)*a,-Math.log(n.transmissionColor.g)*a,-Math.log(n.transmissionColor.b)*a),u=new g.Vector3(n.transmissionScatter.r*a,n.transmissionScatter.g*a,n.transmissionScatter.b*a),c=s.subtract(u),l=Math.min(c.x,c.y,c.z);l<0&&(c.x=c.x-l,c.y=c.y-l,c.z=c.z-l),s=c.add(u),b=new g.Vector3(u.x/Math.max(s.x,1e-6),u.y/Math.max(s.y,1e-6),u.z/Math.max(s.z,1e-6)),M=new g.Vector3(Math.sqrt(1-b.x),Math.sqrt(1-b.y),Math.sqrt(1-b.z)),A=(w=new g.Vector3(1,1,1)).subtract(M),C=w.subtract(new g.Vector3(.139,.139,.139).multiplyInPlace(M)),R=w.add(new g.Vector3(1.17,1.17,1.17).multiplyInPlace(M)),o=A.multiplyInPlace(C).divideInPlace(R),i=n.transmissionScatterAnisotropy}var h=g.Vector3.Zero(),f=0;n.subsurfaceWeight>0&&(h.set(n.subsurfaceColor.r,n.subsurfaceColor.g,n.subsurfaceColor.b),f=n.subsurfaceScatterAnisotropy);var p=(1-n.transmissionWeight)*n.subsurfaceWeight,d=p+n.transmissionWeight,m=1/Math.max(d,1e-6),x=n.transmissionWeight*m,_=p*m,v={multiscatterColorFactor:o.multiplyByFloats(x,x,x).addInPlace(h.multiplyByFloats(_,_,_)).asArray(),scatterAnisotropy:i*x+f*_};if(n.subsurfaceWeight>0&&n.subsurfaceColorTexture){r._exporter._materialNeedsUVsSet.add(n);var T=r._exporter._materialExporter.getTextureInfo(n.subsurfaceColorTexture);T&&(v.multiscatterColorTexture=T)}else if(n.transmissionWeight>0&&n.transmissionScatterTexture){r._exporter._materialNeedsUVsSet.add(n);var y=r._exporter._materialExporter.getTextureInfo(n.transmissionScatterTexture);y&&(v.multiscatterColorTexture=y)}t.extensions=t.extensions||{},t.extensions[mt]=v}var b,M,w,A,C,R;e(t)})},e}();pe.RegisterExtension(mt,function(e){return new gt(e)},101);var xt="KHR_materials_diffuse_roughness",_t=function(){function e(e){this.name=xt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,t,n){return w(this,void 0,void 0,function(){var e;return A(this,function(t){if(e=[],n instanceof g.PBRBaseMaterial){if(n._baseDiffuseRoughness)return n._baseDiffuseRoughnessTexture&&e.push(n._baseDiffuseRoughnessTexture),[2,e]}else if(n instanceof g.OpenPBRMaterial&&n.baseDiffuseRoughness)return n.baseDiffuseRoughnessTexture&&e.push(n.baseDiffuseRoughnessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){var o=null,i=null;if(n instanceof g.PBRBaseMaterial?(o=n._baseDiffuseRoughness,i=n._baseDiffuseRoughnessTexture):n instanceof g.OpenPBRMaterial&&(o=n.baseDiffuseRoughness,i=n.baseDiffuseRoughnessTexture),o){r._wasUsed=!0,t.extensions=t.extensions||{};var a=r._exporter._materialExporter.getTextureInfo(i),s={diffuseRoughnessFactor:o,diffuseRoughnessTexture:null!=a?a:void 0};null!==s.diffuseRoughnessTexture&&r._exporter._materialNeedsUVsSet.add(n),t.extensions[xt]=s,e(t)}else e(t)})},e}();pe.RegisterExtension(xt,function(e){return new _t(e)});var vt="KHR_materials_openpbr",Tt=function(){function e(){this.name=vt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,n){var r=this;return new Promise(function(e){n instanceof g.OpenPBRMaterial&&(r._wasUsed=!0,t.extensions=t.extensions||{},t.extensions[vt]={}),e(t)})},e}();pe.RegisterExtension(vt,function(e){return new Tt});var yt="KHR_texture_transform",bt=function(){function e(){this.name=yt,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,n){if(n.getScene()||g.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(n.name,"!")),0===n.uAng&&0===n.vAng||(g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with rotation in the u or v axis is not supported in glTF.")),0===n.uRotationCenter&&0===n.vRotationCenter)){var r={},o=!1;if(0===n.uOffset&&0===n.vOffset||(r.offset=[n.uOffset,n.vOffset],o=!0),1===n.uScale&&1===n.vScale||(r.scale=[n.uScale,n.vScale],o=!0),0!==n.wAng){if(0!==n.uRotationCenter||0!==n.vRotationCenter){if(n.homogeneousRotationInUVTransform&&n.uScale!==n.vScale)return void g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(yt,"."));g.Tools.Warn("".concat(e,": Texture ").concat(n.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(yt,".")),r.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,a=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*i,h=o*a;return[t+(l*(1-u)+h*c),n+(h*(1-u)-l*c)]}(n)}r.rotation=-n.wAng,o=!0}0!==n.coordinatesIndex&&(r.texCoord=n.coordinatesIndex,o=!0),o&&(this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[yt]=r)}},e}();pe.RegisterExtension(yt,function(){return new bt});var Mt="KHR_texture_basisu",wt=function(){function e(e){this.name=Mt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/ktx2"===(o.mimeType||(0,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Mt]={source:r},this._wasUsed=!0)}},e}();pe.RegisterExtension(Mt,function(e){return new wt(e)});var At="EXT_texture_webp",Ct=function(){function e(e){this.name=At,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/webp"===(o.mimeType||(0,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[At]={source:r},this._wasUsed=!0)}},e}();pe.RegisterExtension(At,function(e){return new Ct(e)});var Rt="EXT_texture_avif",Et=function(){function e(e){this.name=Rt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,t){var n=this._exporter._textures[t.index],r=n.source;if(void 0!==r){var o=this._exporter._images[r];"image/avif"===(o.mimeType||(0,g.GetMimeType)(o.uri))&&(n.source=void 0,n.extensions||(n.extensions={}),n.extensions[Rt]={source:r},this._wasUsed=!0)}},e}();pe.RegisterExtension(Rt,function(e){return new Et(e)});var It=function(){function e(){}return e.CreateSTL=function(e,t,n,r,o,i,a,s){void 0===t&&(t=!0),void 0===n&&(n="stlmesh"),void 0===r&&(r=!1),void 0===o&&(o=!0),void 0===i&&(i=!1),void 0===a&&(a=!1),void 0===s&&(s=!1);var u=function(e,t,n){var r=[3*e[n],3*e[n+1],3*e[n+2]],o=[new g.Vector3(t[r[0]],t[r[0]+2],t[r[0]+1]),new g.Vector3(t[r[1]],t[r[1]+2],t[r[1]+1]),new g.Vector3(t[r[2]],t[r[2]+2],t[r[2]+1])],i=o[0].subtract(o[1]),a=o[2].subtract(o[1]);return{v:o,n:g.Vector3.Cross(a,i).normalize()}},c=function(e,t,n,r){return t=l(e,t,n.x,r),t=l(e,t,n.y,r),l(e,t,n.z,r)},l=function(e,t,n,r){return e.setFloat32(t,n,r),t+4},h=function(e){if(a){var t=e;e instanceof g.InstancedMesh&&(t=e.sourceMesh);var n=t.getVerticesData(g.VertexBuffer.PositionKind,!0,!0);if(!n)return[];var r=g.Vector3.Zero(),o=void 0;for(o=0;o<n.length;o+=3)g.Vector3.TransformCoordinatesFromFloatsToRef(n[o],n[o+1],n[o+2],e.computeWorldMatrix(!0),r).toArray(n,o);return n}return e.getVerticesData(g.VertexBuffer.PositionKind)||[]};a&&(i=!0);var f="",p=0,d=0;if(r){for(var m=0;m<e.length;m++)p+=(T=(_=e[m]).getIndices())?T.length/3:0;var x=new ArrayBuffer(84+50*p);d+=80,(f=new DataView(x)).setUint32(d,p,o),d+=4}else s||(f="solid stlmesh\r\n");for(m=0;m<e.length;m++){var _=e[m];!r&&s&&(f+="solid "+_.name+"\r\n"),!i&&_ instanceof g.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=h(_),T=_.getIndices()||[],y=0;y<T.length;y+=3){var b=u(T,v,y);r?(d=c(f,d,b.n,o),d=c(f,d,b.v[0],o),d=c(f,d,b.v[1],o),d=c(f,d,b.v[2],o),d+=2):(f+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",f+="\t\touter loop\r\n",f+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",f+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",f+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",f+="\t\tendloop\r\n",f+="\tendfacet\r\n")}!r&&s&&(f+="endsolid "+name+"\r\n")}if(r||s||(f+="endsolid stlmesh"),t){var M=document.createElement("a"),w=new Blob([f],{type:"application/octet-stream"});M.href=window.URL.createObjectURL(w),M.download=n+".stl",M.click()}return f},e}();function St(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],i=0;i<e.length/n;i++){var a=e[i*n]*(r?-1:1),s=e[i*n+1],u=e[i*n+2];o.push("(".concat(a.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function Vt(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],i=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-i).toPrecision(t.precision),")"))}return n.join(", ")}function Ft(e,t,n,r){var o=function(e,t,n,r){var o=e.getVerticesData(g.VertexBuffer.PositionKind),i=e.getVerticesData(g.VertexBuffer.NormalKind);if(o&&i)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(n,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,n=e.getIndices(),r=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==n)for(var i=0;i<r;i++)o.push(n[i]);else for(i=0;i<r;i++)o.push(i);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(St(i,t,void 0,r),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(St(o,t,void 0,r),"]\n ").concat(function(e,t){for(var n="",r=0;r<4;r++){var o=r>0?r:"",i=e.getVerticesData(g.VertexBuffer.UVKind+(o?o+1:""));i&&(n+="\n\t\ttexCoord2f[] primvars:st".concat(o," = [").concat(Vt(i,t),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var a=e.getVerticesData(g.VertexBuffer.ColorKind);return a&&(n+="\n\tcolor3f[] primvars:displayColor = [".concat(St(a,t,a.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),n}(e,t),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,t,n,r);return'\n def "Geometry"\n {\n '.concat(o,"\n }\n ")}function Bt(e){var t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function Ot(e){var t=e.m;return"( ".concat(Nt(t,0),", ").concat(Nt(t,4),", ").concat(Nt(t,8),", ").concat(Nt(t,12)," )")}function Nt(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function Pt(e,t){var n="Object_"+e.uniqueId,r=Ot(t);return'def Xform "'.concat(n,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(r,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Ut(e){switch(e){case g.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case g.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case g.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function kt(e){return"(".concat(e.x,", ").concat(e.y,")")}function Wt(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function Dt(e,t,n,r,o,i){var a=e.getInternalTexture().uniqueId+"_"+e.invertY;o[a]=e;var s=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",u=new g.Vector2(e.uScale,e.vScale),c=new g.Vector2(e.uOffset,e.vOffset),l=e.wAng,h=Math.sin(l),f=Math.cos(l);return c.y=1-c.y-u.y,c.x+=h*u.x,c.y+=(1-f)*u.y,'\n def Shader "PrimvarReader_'.concat(n,'"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "').concat(s,'"\n float2 outputs:result\n }\n\n def Shader "Transform2d_').concat(n,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_').concat(t.uniqueId,"/PrimvarReader_").concat(n,".outputs:result>\n float inputs:rotation = ").concat((l*(180/Math.PI)).toFixed(i.precision),"\n float2 inputs:scale = ").concat(kt(u),"\n float2 inputs:translation = ").concat(kt(c),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(n,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(a,".png@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(t.uniqueId,"/Transform2d_").concat(n,".outputs:result>\n ").concat(r?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(r):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(Ut(e.wrapU),'"\n token inputs:wrapT = "').concat(Ut(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(t.needAlphaBlending()||t.needAlphaTesting()?"float outputs:a":"","\n }")}function zt(e,t,n){var r="\t\t\t",o=[],i=[],a=function(e){var t,n,r={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof g.StandardMaterial?b(b({},r),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof g.PBRBaseMaterial?b(b({},r),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(t=e._roughness)&&void 0!==t?t:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(n=e._metallic)&&void 0!==n?n:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):r}(e),s=a.diffuseMap,u=a.diffuse,c=a.alphaCutOff,l=a.emissiveMap,h=a.emissive,f=a.normalMap,p=a.roughnessMap,d=a.roughnessChannel,m=a.roughness,x=a.metalnessMap,_=a.metalnessChannel,v=a.metalness,T=a.aoMap,y=a.aoMapChannel,M=a.aoMapIntensity,w=a.alphaMap,A=a.ior,C=a.clearCoatEnabled,R=a.clearCoat,E=a.clearCoatMap,I=a.clearCoatRoughness,S=a.clearCoatRoughnessMap;return null!==s?(o.push("".concat(r,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(s.uniqueId,"_diffuse.outputs:a>")),o.push("".concat(r,"float inputs:opacityThreshold = ").concat(c))),i.push(Dt(s,e,"diffuse",u,t,n))):o.push("".concat(r,"color3f inputs:diffuseColor = ").concat(Wt(u||g.Color3.White()))),null!==l?(o.push("".concat(r,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(l.uniqueId,"_emissive.outputs:rgb>")),i.push(Dt(l,e,"emissive",h,t,n))):h&&h.toLuminance()>0&&o.push("".concat(r,"color3f inputs:emissiveColor = ").concat(Wt(h))),null!==f&&(o.push("".concat(r,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(f.uniqueId,"_normal.outputs:rgb>")),i.push(Dt(f,e,"normal",null,t,n))),null!==T&&(o.push("".concat(r,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(T.uniqueId,"_occlusion.outputs:").concat(y,">")),i.push(Dt(T,e,"occlusion",new g.Color3(M,M,M),t,n))),null!==p?(o.push("".concat(r,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(p.uniqueId,"_roughness.outputs:").concat(d,">")),i.push(Dt(p,e,"roughness",new g.Color3(m,m,m),t,n))):o.push("".concat(r,"float inputs:roughness = ").concat(m)),null!==x?(o.push("".concat(r,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(x.uniqueId,"_metallic.outputs:").concat(_,">")),i.push(Dt(x,e,"metallic",new g.Color3(v,v,v),t,n))):o.push("".concat(r,"float inputs:metallic = ").concat(v)),null!==w?(o.push("".concat(r,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(w.uniqueId,"_opacity.outputs:r>")),o.push("".concat(r,"float inputs:opacityThreshold = 0.0001")),i.push(Dt(w,e,"opacity",null,t,n))):o.push("".concat(r,"float inputs:opacity = ").concat(e.alpha)),C&&(null!==E?(o.push("".concat(r,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(E.uniqueId,"_clearcoat.outputs:r>")),i.push(Dt(E,e,"clearcoat",new g.Color3(R,R,R),t,n))):o.push("".concat(r,"float inputs:clearcoat = ").concat(R)),null!==S?(o.push("".concat(r,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(S.uniqueId,"_clearcoatRoughness.outputs:g>")),i.push(Dt(S,e,"clearcoatRoughness",new g.Color3(I,I,I),t,n))):o.push("".concat(r,"float inputs:clearcoatRoughness = ").concat(I))),o.push("".concat(r,"float inputs:ior = ").concat(A)),'\n\tdef Material "Material_'.concat(e.uniqueId,'"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n').concat(o.join("\n"),"\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(i.join("\n"),"\n\n\t}\n")}function Lt(e){var t,n;e.computeWorldMatrix(!0);for(var r=e.getWorldMatrix().clone(),o=e.getScene().useRightHandedSystem,i=null!==(n=null===(t=e.material)||void 0===t?void 0:t._getEffectiveOrientation(e))&&void 0!==n?n:e.sideOrientation,a=!o,s=e.parent;s;){if(z(s,o)&&null===s.parent){o||(r.multiplyToRef(s.getWorldMatrix().invert(),r),i=i===g.Material.ClockWiseSideOrientation?g.Material.CounterClockWiseSideOrientation:g.Material.ClockWiseSideOrientation),a=!1;break}s=s.parent}return r.determinant()<0&&g.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:r,windingOrder:i===g.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:a}}function Kt(e,t,n){return w(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,f,p,d,m,x,_,v,T,y,M,w,C,R,E,I,S,V,F,B,O,N,P,U;return A(this,function(A){switch(A.label){case 0:return r=b({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},t),"undefined"!=typeof fflate?[3,2]:[4,g.Tools.LoadScriptAsync(r.fflateUrl)];case 1:A.sent(),A.label=2;case 2:for((o={})[r.modelFileName]=null,i='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',i+=function(e){var t=!0===e.includeAnchoringProperties?'\n\t\ttoken preliminary:anchoring:type = "'.concat(e.anchoringType,'"\n\t\ttoken preliminary:planeAnchoring:alignment = "').concat(e.planeAnchoringAlignment,'"'):"";return'def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {'.concat(t,"\n ")}(r),a={},s=0,u=e.meshes;s<u.length;s++)0!==(c=u[s]).getTotalVertices()&&(h=(l=c).geometry,(f=l.material)&&h&&(!n||n(l))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(f.getClassName())?(p="geometries/Geometry_"+h.uniqueId+".usda",d=Lt(l),m=d.matrix,x=d.windingOrder,_=d.convertToRightHanded,p in o||(v=Ft(h,r,x,_),o[p]=Bt(v)),f.uniqueId in a||(a[f.uniqueId]=f),i+=Pt(l,m)):g.Tools.Warn("USDZExportAsync does not support this material type: "+f.getClassName())));for(w in e.activeCamera&&r.exportCamera&&(i+=function(e,t){var n="Camera_"+e.uniqueId,r=Ot(g.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===g.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(t.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var o=e.getEngine().getAspectRatio(e),i=t.cameraSensorWidth||35;return'def Camera "'.concat(n,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(r,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(t.precision),", ").concat(e.maxZ.toPrecision(t.precision),")\n\t\t\tfloat focalLength = ").concat((i/(2*Math.tan(.5*e.fov))).toPrecision(t.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((i*o).toPrecision(t.precision),"\n\t\t\tfloat verticalAperture = ").concat((i/o).toPrecision(t.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,r)),i+="\n }\n }",i+=function(e,t,n){var r=[];for(var o in e){var i=e[o];r.push(zt(i,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(a,T={},r),i+="\n }",o[r.modelFileName]=fflate.strToU8(i),M=[],y=T)M.push(w);C=0,A.label=3;case 3:return C<M.length?(w=M[C])in y?(E=T[R=w],I=E.getSize(),[4,(0,g.GetTextureDataAsync)(E)]):[3,6]:[3,7];case 4:return S=A.sent(),[4,g.DumpTools.DumpDataAsync(I.width,I.height,S,"image/png",void 0,!1,!0)];case 5:V=A.sent(),o["textures/Texture_".concat(R,".png")]=new Uint8Array(V).slice(),A.label=6;case 6:return C++,[3,3];case 7:for(B in F=0,o)(O=o[B])&&(N=34+B.length,4!=(P=63&(F+=N))&&(U=new Uint8Array(64-P),o[B]=[O,{extra:{12345:U}}]),F=O.length);return[2,fflate.zipSync(o,{level:0})]}})})}var qt=function(){function e(){}return e.Export=function(e,t,n){var r;if(void 0===t&&(t=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var o=t;t&&0!==t.length||(o=e.animations.map(function(e){return e.name}));for(var i=null,a=0,s=o;a<s.length;a++){var u=s[a],c=e.getAnimationRange(u);c&&(i=i?new g.AnimationRange("animation-range",Math.min(i.from,c.from),Math.max(i.to,c.to)):c)}if(!i&&(e.animations.length>0&&(i=e.getAnimationRange(e.animations[0].name)),!i))throw new Error("No animation range found in skeleton");for(var l=n||1/((null===(r=e.animations[0])||void 0===r?void 0:r.framePerSecond)||30),h=this._BuildBoneHierarchy(e,o),f=0,p=0,d=h;p<d.length;p++){var m=d[p];m.positionKeys.length>0&&(f=Math.max(f,m.positionKeys.length)),m.rotationKeys.length>0&&(f=Math.max(f,m.rotationKeys.length))}0===f&&(f=Math.floor((i.to-i.from)/l)+1);var x="";return x+="HIERARCHY\n",x+=this._ExportHierarchy(h,0),x+="MOTION\n",x+="Frames: ".concat(f,"\n"),(x+="Frame Time: ".concat(l.toFixed(6),"\n"))+this._ExportMotionData(h,f,0,o)},e._BuildBoneHierarchy=function(e,t){for(var n,r,o=new Map,i=[],a=0,s=e.bones;a<s.length;a++){var u={bone:h=s[a],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};o.set(h,u)}for(var c=0,l=e.bones;c<l.length;c++){var h=l[c];if(u=o.get(h),h.animations.length>0)for(var f=0,p=h.animations;f<p.length;f++){var d=p[f];t.includes(d.name)&&("position"===d.targetProperty?(u.hasPositionChannels=!0,(n=u.positionKeys).push.apply(n,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(r=u.rotationKeys).push.apply(r,d.getKeys())))}if(h.getParent()){var m=o.get(h.getParent());m&&m.children.push(u)}else i.push(u)}return i},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,i=e;o<i.length;o++){var a=i[o],s=a.bone;if(this._IsEndSite(a)){n+="".concat(r,"End Site\n"),n+="".concat(r,"{\n");var u=this._GetBoneOffset(s);n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),n+="".concat(r,"}\n")}else{n+="".concat(0===t?"ROOT":"".concat(r,"JOINT")," ").concat(s.name,"\n"),n+="".concat(r,"{\n"),u=this._GetBoneOffset(s),n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];a.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),a.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),a.children.length>0&&(n+=this._ExportHierarchy(a.children,t+1)),n+="".concat(r,"}\n")}}return n},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return g.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",i=0;i<t;i++){var a=[];this._CollectFrameValues(e,i+n,a,r),o+=a.map(function(e){return e.toFixed(6)}).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,i=e;o<i.length;o++){var a=i[o];if(!this._IsEndSite(a)){if(a.hasPositionChannels){var s=this._GetPositionAtFrameIndex(a.positionKeys,t);n.push(s.x,s.y,s.z)}if(a.hasRotationChannels){var u=this._GetRotationAtFrameIndex(a.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}a.children.length>0&&this._CollectFrameValues(a.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,t){return 0===e.length?g.Vector3.Zero():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,t){return 0===e.length?g.Quaternion.Identity():e[Math.max(0,Math.min(t,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var t=new g.Matrix;e.toRotationMatrix(t);var n,r,o,i=t.m,a=Math.sqrt(i[0]*i[0]+i[1]*i[1]);return a>g.Epsilon?(n=Math.atan2(i[6],i[10]),r=Math.atan2(-i[2],a),o=Math.atan2(i[1],i[0])):(n=Math.atan2(-i[9],i[5]),r=Math.atan2(-i[2],a),o=0),new g.Vector3(g.Tools.ToDegrees(n),g.Tools.ToDegrees(r),g.Tools.ToDegrees(o))},e}();function Gt(e){return"string"==typeof(null==e?void 0:e.name)}var jt=Symbol("__xml:meta$__"),Ht=Symbol("__xml:name$__");function Xt(e,t){var n,r=e.constructor;(null!==(n=r[jt])&&void 0!==n?n:r[jt]=[]).push(t)}function Qt(e){return function(t){t[Ht]=e}}function Zt(){return function(e,t){return Xt(e,{kind:"none",prop:t,ignore:!0})}}function Yt(e){return function(t,n){return Xt(t,b({kind:"attr",prop:n},e))}}function Jt(e){return function(t,n){return Xt(t,b({kind:"elem",prop:n},e))}}function $t(e){var t,n;return null!==(n=null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[jt])&&void 0!==n?n:[]}function en(e){var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Ht])||void 0}function tn(e){return/^[A-Za-z_][A-Za-z0-9._-]*$/.test(e)}function nn(e){if(Gt(e))return e;var t=(null!=e?e:"").trim();if(!t)return{name:""};var n=t.indexOf(":");if(-1===n)return{name:t};if(-1!==t.indexOf(":",n+1))return{name:t};var r=t.slice(0,n),o=t.slice(n+1);return tn(r)&&tn(o)?{ns:r,name:o}:{name:t}}function rn(e,t){return t?"".concat(t,":").concat(e):e}var on=Object.freeze({eps:1e-6,maxDecimalsCap:15,trimTrailingZeros:!0,allowScientific:!1,snapNearZero:!0}),an=Object.freeze({number:on});function sn(e){var t,n,r,o,i,a,s=null!==(t=null==e?void 0:e.eps)&&void 0!==t?t:on.eps;return{eps:s,maxDecimalsCap:null!==(n=null==e?void 0:e.maxDecimalsCap)&&void 0!==n?n:on.maxDecimalsCap,trimTrailingZeros:null!==(r=null==e?void 0:e.trimTrailingZeros)&&void 0!==r?r:on.trimTrailingZeros,fixedDecimals:null==e?void 0:e.fixedDecimals,allowScientific:null!==(o=null==e?void 0:e.allowScientific)&&void 0!==o?o:on.allowScientific,snapNearZero:null!==(i=null==e?void 0:e.snapNearZero)&&void 0!==i?i:on.snapNearZero,zeroThreshold:null!==(a=null==e?void 0:e.zeroThreshold)&&void 0!==a?a:s,perAttributeEps:null==e?void 0:e.perAttributeEps}}function un(e){return{number:sn(null==e?void 0:e.number)}}var cn=function(){function e(e){if(this.o=e,this._o=e.number,!Number.isFinite(this._o.eps)||this._o.eps<=0)throw new Error("opts.eps must be a finite, positive number")}return e.prototype.toString=function(e){var t,n,r,o;if(!Number.isFinite(e))throw new Error("Cannot format non-finite number: ".concat(e));var i,a=this._o,s=this._clampInt(null!==(t=a.maxDecimalsCap)&&void 0!==t?t:15,0,20),u=null===(n=a.trimTrailingZeros)||void 0===n||n,c=null===(r=a.snapNearZero)||void 0===r||r,l=null!==(o=a.zeroThreshold)&&void 0!==o?o:a.eps,h=1/a.eps,f=Math.round(e*h)/h;if(Object.is(f,-0)&&(f=0),c&&Math.abs(f)<=l&&(f=0),i=void 0!==a.fixedDecimals?this._clampInt(a.fixedDecimals,0,s):this._clampInt(Math.ceil(-Math.log10(a.eps)),0,s),a.allowScientific,0===i)return String(Math.trunc(f));var p=f.toFixed(i);if(u&&void 0===a.fixedDecimals&&(p=p.replace(/(\.\d*?[1-9])0+$/,"$1").replace(/\.0+$/,"").replace(/\.$/,"")),/[eE]/.test(p))throw new Error("Scientific notation not allowed in XML output: ".concat(p));return p},e.prototype._clampInt=function(e,t,n){return Number.isFinite(e)?(e=Math.trunc(e),Math.max(t,Math.min(n,e))):t},e}();function ln(e){return e instanceof Date}function hn(e){return"string"==typeof e}function fn(e){return"number"==typeof e}function pn(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||ln(e)}function dn(e){return"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||ln(e)}var mn,gn=function(){function e(e,t){this._ns=new Map,this._prefixCount=0,this._builder=e,this._format=un(t),this._nFmt=new cn(this._format)}return e.prototype.withNamespace=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=0,r=e;n<r.length;n++){var o=r[n];this._assignNamespace(o)}return this},e.prototype.serialize=function(e,t){if(!(t=null!=t?t:en(e)))throw new Error("can not find name for given object");var n=nn(t);n.ns&&this._assignNamespace(n.ns,"xmlns"),this._gatherNamespaces(e,new WeakSet);for(var r=this._builder.ele(null,n.name),o=0,i=Array.from(this._ns.entries());o<i.length;o++){var a=i[o],s=a[0],u=a[1];r.att("xmlns",u,s)}this._writeObjectContent(r,e,(new WeakSet).add(e)),this._builder.end()},e.prototype._writeObject=function(e,t,n){if(!n.has(t))if(n.add(t),Array.isArray(t))for(var r=0,o=t;r<o.length;r++){var i=o[r];dn(i)||(hn(i)?this._builder.text(i):this._writeObject(e,i,n))}else{var a=en(t);if(a){var s=nn(a),u=this._getPrefix(s),c=rn(s.name,u);e.ele(null,c),this._writeObjectContent(e,t,n),this._builder.end()}}},e.prototype._getPrefix=function(e){if(e.ns){var t=this._ns.get(e.ns.toLowerCase());if("xmlns"!==t)return t}},e.prototype._writeObjectContent=function(e,t,n){for(var r,o,i,a=null!==(r=$t(t))&&void 0!==r?r:[],s=new Map,u=0,c=a;u<c.length;u++){var l=c[u],h=null!==(o=s.get(l.prop))&&void 0!==o?o:[];h.push(l),s.set(l.prop,h)}for(var f=Object.keys(t).sort(function(e,t){var n,r,o=(null!==(n=s.get(e))&&void 0!==n?n:[]).some(function(e){return"attr"===e.kind}),i=(null!==(r=s.get(t))&&void 0!==r?r:[]).some(function(e){return"attr"===e.kind});return o===i?0:o?-1:1}),p=0,d=f;p<d.length;p++){var m=d[p],g=t[m];if(null!=g){var x=s.get(m);if(x){var _=x.some(function(e){return!0===e.ignore||"none"===e.kind});if(_)continue;for(var v=0,T=x;v<T.length;v++){var y=null!==(i=(l=T[v]).name)&&void 0!==i?i:l.prop.toLowerCase();if(y&&"attr"===l.kind){var b=null;if(fn(g)&&this._nFmt&&(b=this._nFmt.toString(g)),l.formatter&&(b=new l.formatter(this._format).toString(g)),b=null!=b?b:g.toString()){var M=nn(y),w=this._getPrefix(M),A=rn(M.name,w);e.att(null,A,b)}}}}else dn(g)||(hn(g)?this._builder.text(g):this._writeObject(e,g,n))}}},e.prototype._gatherNamespaces=function(e,t){var n,r;if(!t.has(e))if(t.add(e),Array.isArray(e))for(var o=0,i=e;o<i.length;o++){var a=i[o];pn(a)||this._gatherNamespaces(a,t)}else{var s=en(e);s&&this._assignNamespace(s);for(var u=null!==(n=$t(e))&&void 0!==n?n:[],c=new Map,l=0,h=u;l<h.length;l++){var f=h[l],p=null!==(r=c.get(f.prop))&&void 0!==r?r:[];p.push(f),c.set(f.prop,p)}for(var d=[],m=0,g=Object.keys(e);m<g.length;m++){var x=g[m],_=e[x];if(null!=_){var v=c.get(x);if(v){var T=v.some(function(e){return!0===e.ignore||"none"===e.kind});if(T)continue;for(var y=0,b=v;y<b.length;y++)(f=b[y]).name&&this._assignNamespace(f.name)}d.push(_)}}for(var M=0,w=d;M<w.length;M++){var A=w[M];pn(A)||this._gatherNamespaces(A,t)}}},e.prototype._assignNamespace=function(e,t){var n=nn(e);if(null==n?void 0:n.ns){var r=n.ns.toLowerCase();this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r))}else"xmlns"===t&&(r=n.name.toLowerCase(),this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r)))},e.prototype._buildNsPrefix=function(e){var t,n=!1;do{t="ns".concat(this._prefixCount++);for(var r=0,o=Array.from(this._ns.values());r<o.length;r++)if(o[r]===t){n=!0;break}}while(n);return t},e}(),xn=function(){function e(){}return e.OpenTag="<",e.CloseTag=">",e.Slash="/",e.Question="?",e.Quote='"',e.Equal="=",e.Space=" ",e.Semicolon=":",e.Dec="<?xml",e.Xml="xml",e.Xmlns="xmlns",e.Xsi="xsi",e.VersionKeyword="version",e.EncodingKeyword="encoding",e.StandaloneKeyword="standalone",e}();!function(e){e[e.Declaration=0]="Declaration",e[e.Tag=1]="Tag",e[e.Attribute=2]="Attribute",e[e.Text=3]="Text"}(mn||(mn={}));var _n,vn,Tn=function(){function e(e){this._ctxStack=[],this._d=0,this._w=e}return e.prototype.dec=function(e,t,n){return this._w.write(xn.Dec),this._writeAttStr(xn.VersionKeyword,e),t&&this._writeAttStr(xn.EncodingKeyword,t),void 0!==n&&this._writeAttStr(xn.StandaloneKeyword,n?"yes":"no"),this._w.write(xn.Question,xn.CloseTag),this},e.prototype.att=function(e,t,n){var r=this._peekContext();if(!r)throw new Error("att() without open element");if(r.closed)throw new Error("att() after start tag closed for <".concat(r.name,">"));if(this._isXmlnsDecl(e,t)){if(t===xn.Xmlns)r.defaultNs=n,this._registerNamespace(r,"",n),this._writeAttStr(xn.Xmlns,n);else if(e)this._registerNamespace(r,t,n),this._writeAttStr("".concat(e,":").concat(t),n);else{var o=t.slice(6);this._registerNamespace(r,o,n),this._writeAttStr(t,n)}return r.lastToken=mn.Attribute,this}var i=t;if(e){var a=this._ensurePrefixDeclared(r,e);i="".concat(a,":").concat(t)}return r.lastToken=mn.Attribute,this._writeAttStr(i,n),this},e.prototype.ele=function(e,t){var n,r=this._peekContext();r&&this._closeOpenTagIfNeeded(r);var o=t;if(e){var i=null!==(n=this._lookupPrefix(e))&&void 0!==n?n:e;o="".concat(i,":").concat(t)}return this._pushContext(o,++this._d),this._w.write(xn.OpenTag,o),this},e.prototype.text=function(e){var t=this._peekContext();if(!t)throw new Error("text() without open element");return this._closeOpenTagIfNeeded(t),t.lastToken=mn.Text,this._w.write(this._escText(e)),this},e.prototype.end=function(){var e=this._popContext();return e&&(this._d--,e.closed?this._w.write(xn.OpenTag,xn.Slash,e.name,xn.CloseTag):this._w.write(xn.Slash,xn.CloseTag)),this},e.prototype._pushContext=function(t,n){var r=new e.Context(t,n);return this._ctxStack.push(r),r},e.prototype._popContext=function(){return this._ctxStack.pop()},e.prototype._peekContext=function(){return this._ctxStack[this._ctxStack.length-1]},Object.defineProperty(e.prototype,"_contextDepth",{get:function(){return this._ctxStack.length},enumerable:!1,configurable:!0}),e.prototype._writeAttStr=function(e,t){this._w.write(xn.Space,e,xn.Equal,xn.Quote,this._escAttr(t),xn.Quote)},e.prototype._lookupPrefix=function(e){var t,n=this._ctxStack.length-1;if(n>=0)do{var r=null===(t=this._ctxStack[n--].ns2prefix)||void 0===t?void 0:t.get(e);if(r)return r}while(n>=0)},e.prototype._escText=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")},e.prototype._escAttr=function(e){return this._escText(e).replace(/"/g,""").replace(/'/g,"'")},e.prototype._isXmlnsDecl=function(e,t){if(e)return e===xn.Xmlns;var n=t.length,r=xn.Xmlns.length;return n>=r&&t.startsWith(xn.Xmlns)&&(t.length==r||t[r]==xn.Semicolon)},e.prototype._registerNamespace=function(e,t,n){if(t===xn.Xml||t===xn.Xmlns)throw new Error("reserved prefix '".concat(t,"'"));var r=e.prefix2ns.get(t);if(r&&r!==n)throw new Error("prefix '".concat(t,"' already bound to a different namespace"));e.ns2prefix.get(n)||e.ns2prefix.set(n,t),e.prefix2ns.set(t,n)},e.prototype._allocPrefix=function(e){for(var t=1;;){var n="ns".concat(t++);if(!e.prefix2ns.has(n))return n}},e.prototype._ensurePrefixDeclared=function(e,t){var n=this._lookupPrefix(t);if(n)return n;if(e.closed)throw new Error("can not declare namespace after start tag closed for <".concat(e.name,">"));var r=this._allocPrefix(e);return this._writeAttStr("".concat(xn.Xmlns,":").concat(r),t),this._registerNamespace(e,r,t),r},e.prototype._closeOpenTagIfNeeded=function(e){e.closed||(this._w.write(xn.CloseTag),e.closed=!0)},e.Context=function(e,t){this.name="",this.closed=!1,this.lastToken=null,this.ns2prefix=new Map,this.prefix2ns=new Map,this.defaultNs=null,this.name=e,this.depth=t},e}(),yn=function(){function e(){this.count=0,this._chunks=[]}return e.prototype.write=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)return this;var n=e.join("");return this._chunks.push(n),this.count+=n.length,this},e.prototype.toString=function(){return this._chunks.join("")},e.prototype.clear=function(){this._chunks=[],this.count=0},e}(),bn=function(){function e(e,t){void 0===t&&(t={}),this._sink=e,this._opts=t,this.count=0,this._encoder=new TextEncoder,this._pending="",this._pendingChars=0}return e.prototype.write=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(0===t.length)return this;var r=t.join("");if(0===r.length)return this;this._pending+=r,this._pendingChars+=r.length;var o=null!==(e=this._opts.flushChars)&&void 0!==e?e:65536;return this._pendingChars>=o&&this.flush(),this},e.prototype.flush=function(){if(0===this._pendingChars)return this;var e=this._encoder.encode(this._pending);return this._sink.push(e),this.count+=e.length,this._pending="",this._pendingChars=0,this},e.prototype.finish=function(){this.flush(),this._sink.push(new Uint8Array(0),!0)},e.prototype.clear=function(){this._pending="",this._pendingChars=0,this.count=0},e}(),Mn="http://schemas.microsoft.com/3dmanufacturing/core/2015/02",wn="http://schemas.microsoft.com/3dmanufacturing/trianglesets/2021/07";!function(e){e.micron="micron",e.millimeter="millimeter",e.centimeter="centimeter",e.inch="inch",e.foot="foot",e.meter="meter"}(_n||(_n={})),function(e){e.model="model",e.solidsupport="solidsupport",e.support="support",e.surface="surface",e.other="other"}(vn||(vn={}));var An,Cn="http://schemas.openxmlformats.org/package/2006/content-types",Rn="http://schemas.openxmlformats.org/package/2006/relationships";!function(e){e.Relationships="application/vnd.openxmlformats-package.relationships+xml",e.Model="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",e.Materials="application/vnd.ms-package.3dmanufacturing-material+xml",e.Colors="application/vnd.ms-package.3dmanufacturing-colors+xml",e.Texture="application/vnd.ms-package.3dmanufacturing-texture+xml",e.Texture2D="application/vnd.ms-package.3dmanufacturing-texture2d+xml",e.Production="application/vnd.ms-package.3dmanufacturing-production+xml",e.Slice="application/vnd.ms-package.3dmanufacturing-slice+xml",e.BeamLattice="application/vnd.ms-package.3dmanufacturing-beamlattice+xml",e.SecureContent="application/vnd.ms-package.3dmanufacturing-securecontent+xml",e.Png="image/png",e.Jpeg="image/jpeg",e.Tiff="image/tiff",e.Xml="application/xml"}(An||(An={}));var En="_rels/",In="3D/",Sn="3dmodel.model",Vn=".rels",Fn="[Content_Types].xml",Bn=function(){function e(){}return e.IsKnown=function(t){return e.Known.has(t)},e.IsThreeDimModel=function(t){return t===e.ThreeDimModel},e.ThreeDimModel="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel",e.Thumbnail="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",e.PrintTicket="http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket",e.MustPreserve="http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve",e.Known=new Set([e.ThreeDimModel,e.Thumbnail,e.PrintTicket,e.MustPreserve]),e}(),On=function(){function e(){this.items=[]}return M([Qt({ns:Cn,name:"Types"})],e)}(),Nn=function(){function e(e,t){this.ext=e,this.ct=t}return M([Yt({name:{ns:Cn,name:"Extension"}})],e.prototype,"ext",void 0),M([Yt({name:{ns:Cn,name:"ContentType"}})],e.prototype,"ct",void 0),M([Qt({ns:Cn,name:"Default"})],e)}(),Pn=function(){function e(){this.items=[]}return M([Qt({ns:Rn,name:"Relationships"})],e)}(),Un=function(){function e(e,t,n){this.id=e,this.type=t,this.target=n}return M([Yt({name:"Id"})],e.prototype,"id",void 0),M([Yt({name:"Type"})],e.prototype,"type",void 0),M([Yt({name:"Target"})],e.prototype,"target",void 0),M([Qt({ns:Rn,name:"Relationship"})],e)}(),kn=function(e,t,n){this.contentTypes=e,this.relationships=t,this.model=n},Wn=function(){function e(e){this.values=e}return e.Zero=function(){return new e([0,0,0,0,0,0,0,0,0,0,0,0])},e.prototype.toString=function(){return this.values.join(" ")},e}(),Dn=function(){function e(e){this.o=e,this._f=new cn(e)}return e.prototype.toString=function(e){var t=this;return e.values.map(function(e){return t._f.toString(e)}).join(" ")},e}(),zn=function(){function e(){this.unit=_n.millimeter}return e.KnownMeta=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate","Application"],M([Yt({name:"unit"})],e.prototype,"unit",void 0),M([Yt({name:"requiredextensions"})],e.prototype,"requiredextensions",void 0),M([Yt({name:"recommendedextensions"})],e.prototype,"recommendedextensions",void 0),M([Qt({ns:Mn,name:"model"})],e)}(),Ln=function(){function e(e,t,n,r){this.name=e,this.value=t,this.preserve=n,this.type=r}return M([Yt({name:"name"})],e.prototype,"name",void 0),M([Yt({name:"preserve"})],e.prototype,"preserve",void 0),M([Yt({name:"type"})],e.prototype,"type",void 0),M([Qt({ns:Mn,name:"meta"})],e)}(),Kn=function(){function e(){this.metadata=[]}return M([Qt({ns:Mn,name:"metadatagroup"})],e)}(),qn=function(){function e(){this.object=[]}return M([Qt({ns:Mn,name:"resources"})],e)}(),Gn=function(){function e(e,t){void 0===t&&(t=vn.model),this.id=e,this.type=t}return M([Yt({name:"id"})],e.prototype,"id",void 0),M([Yt({name:"type"})],e.prototype,"type",void 0),M([Yt({name:"thumbnail"})],e.prototype,"thumbnail",void 0),M([Yt({name:"partnumber"})],e.prototype,"partnumber",void 0),M([Yt({name:"name"})],e.prototype,"name",void 0),M([Yt({name:"pid"})],e.prototype,"pid",void 0),M([Yt({name:"pindex"})],e.prototype,"pindex",void 0),M([Qt({ns:Mn,name:"object"})],e)}(),jn=function(){function e(e,t){this.vertices=null!=e?e:new Hn,this.triangles=null!=t?t:new Qn}return M([Qt({ns:Mn,name:"mesh"})],e)}(),Hn=function(){function e(){this.vertex=[]}return M([Qt({ns:Mn,name:"vertices"})],e)}(),Xn=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=0),void 0===n&&(n=0),this.x=e,this.y=t,this.z=n}return M([Yt({name:"x"})],e.prototype,"x",void 0),M([Yt({name:"y"})],e.prototype,"y",void 0),M([Yt({name:"z"})],e.prototype,"z",void 0),M([Qt({ns:Mn,name:"vertex"})],e)}(),Qn=function(){function e(){this.triangle=[]}return M([Qt({ns:Mn,name:"triangles"})],e)}(),Zn=function(){function e(e,t,n){this.v1=e,this.v2=t,this.v3=n}return M([Yt({name:"v1"})],e.prototype,"v1",void 0),M([Yt({name:"v2"})],e.prototype,"v2",void 0),M([Yt({name:"v3"})],e.prototype,"v3",void 0),M([Yt({name:"p1"})],e.prototype,"p1",void 0),M([Yt({name:"p2"})],e.prototype,"p2",void 0),M([Yt({name:"p3"})],e.prototype,"p3",void 0),M([Yt({name:"pid"})],e.prototype,"pid",void 0),M([Qt({ns:Mn,name:"triangle"})],e)}(),Yn=function(){function e(){this.component=[]}return M([Qt({ns:Mn,name:"components"})],e)}(),Jn=function(){function e(e,t){this.objectid=e,this.transform=t}return M([Yt({name:"objectid"})],e.prototype,"objectid",void 0),M([Yt({name:"transform",formatter:Dn})],e.prototype,"transform",void 0),M([Qt({ns:Mn,name:"component"})],e)}(),$n=function(){function e(e){this.base=[],this.id=e}return M([Yt({name:"id"})],e.prototype,"id",void 0),M([Qt({ns:Mn,name:"basematerials"})],e)}(),er=function(){function e(e,t){this.name=e,this.displaycolor=t}return M([Yt({name:"name"})],e.prototype,"name",void 0),M([Yt({name:"displaycolor"})],e.prototype,"displaycolor",void 0),M([Qt({ns:Mn,name:"base"})],e)}(),tr=function(){function e(){this.item=[]}return M([Qt({ns:Mn,name:"build"})],e)}(),nr=function(){function e(e,t,n){this.objectid=e,this.transform=t,this.partnumber=n}return M([Yt({name:"objectid"})],e.prototype,"objectid",void 0),M([Yt({name:"transform",formatter:Dn})],e.prototype,"transform",void 0),M([Yt({name:"partnumber"})],e.prototype,"partnumber",void 0),M([Qt({ns:Mn,name:"item"})],e)}(),rr=function(){function e(e,t){this._object=new Gn(e,t)}return e.prototype.withName=function(e){return this._object.name=e,this},e.prototype.withThumbnail=function(e){return this._object.thumbnail=e,this},e.prototype.withProperty=function(e,t){return void 0===t&&(t=0),this._object.pid=e,this._object.id=t,this},e.prototype.build=function(){return this._object},e.prototype.reset=function(e,t){this._object=new Gn(e,t)},e}(),or=function(e){function t(t,n){void 0===n&&(n=vn.model);var r=e.call(this,t,n)||this;return r._object.content=new Yn,r}return y(t,e),t.prototype.withComponent=function(e,t){return this._object.content.component.push(new Jn(e,t)),this},t}(rr),ir=function(e){function t(t){return e.call(this,t,vn.model)||this}return y(t,e),t.prototype.withPostProcessHandlers=function(e,t){return this._vh=e,this._th=t,this},t.prototype.withData=function(e){return this._object.content=this._buildMesh(e),this},t.prototype.withMaterial=function(e,t){return this._object.pid=e,this._object.pindex=t,this},t.prototype._buildMesh=function(e){var t=this._buildVertices(e.positions),n=this._buildTriangle(e.indices);return new jn(t,n)},t.prototype._buildVertices=function(e){var t=new Hn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Xn(r,o,i);this._vh&&(a=this._vh(a)),t.vertex.push(a)}return t},t.prototype._buildTriangle=function(e){var t=new Qn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Zn(r,o,i);this._th&&(a=this._th(a)),t.triangle.push(a)}return t},t}(rr),ar=function(){function e(e){this._m=new $n(e)}return e.prototype.withColor=function(e,t){var n;this._m.base=null!==(n=this._m.base)&&void 0!==n?n:[];var r=this._m.base.find(function(t){return t.name.toLowerCase()===e.toLowerCase()});return r?(r.displaycolor=this._rgbaToHex(t),this):(r=new er(e,this._rgbaToHex(t)),this._m.base.push(r),this)},e.prototype.build=function(){return this._m},e.prototype._rgbaToHex=function(e){var t=function(e){return Math.round(Math.min(255,Math.max(0,255*Math.pow(e,1/2.2))))},n=t(e.r).toString(16).padStart(2,"0").toUpperCase(),r=t(e.g).toString(16).padStart(2,"0").toUpperCase(),o=t(e.b).toString(16).padStart(2,"0").toUpperCase();if("number"==typeof e.a){var i=Math.round(Math.min(255,Math.max(0,255*e.a))).toString(16).padStart(2,"0").toUpperCase();return"#".concat(n).concat(r).concat(o).concat(i)}return"#".concat(n).concat(r).concat(o)},e}(),sr=function(){function e(){this._model=new zn,this._objects=new Map}return e.prototype.withMetaData=function(e,t,n,r){return this._model.metadata||(this._model.metadata=new Array),this._model.metadata.push(new Ln(e,t,n,r)),this},e.prototype.withMaterial=function(e){var t,n;return e instanceof ar&&(e=e.build()),e&&(this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new qn,this._model.resources.basematerials=null!==(n=this._model.resources.basematerials)&&void 0!==n?n:[],this._model.resources.basematerials.push(e)),this},e.prototype.withMesh=function(e){var t;return e instanceof ir&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new qn,this._model.resources.object.push(e),this},e.prototype.withComponents=function(e){var t;return e instanceof or&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new qn,this._model.resources.object.push(e),this},e.prototype.withBuild=function(e,t,n){var r,o;return this._model.build=null!==(r=this._model.build)&&void 0!==r?r:new tr,null===(o=this._model.build.item)||void 0===o||o.push(new nr(e,t,n)),this},e.prototype.withUnit=function(e){return this._model.unit=e,this},e.prototype.reset=function(){return this._model=new zn,this._objects=new Map,this},e.prototype.build=function(){var e,t,n,r;if(!(null===(t=null===(e=this._model.resources)||void 0===e?void 0:e.object)||void 0===t?void 0:t.length))throw new Error("Invalid state: resources MUST be defined ");if(!(null===(r=null===(n=this._model.build)||void 0===n?void 0:n.item)||void 0===r?void 0:r.length))throw new Error("Invalid state: Build MUST be defined ");return this._model},e.KnownMetaSet=new Set(zn.KnownMeta.map(function(e){return e.toLowerCase()})),e}(),ur=function(){function e(){}return e.prototype.withContentType=function(e){this._cts||(this._cts=new On);var t=this._cts.items;return t.some(function(t){return t.ext===e.ext&&t.ct===e.ct})||t.push(e),this},e.prototype.withRelationship=function(e){this._rs||(this._rs=new Pn);var t=this._rs.items;return t.some(function(t){return t.id===e.id})||t.push(e),this.withContentType(new Nn("rels",An.Relationships)),this},e.prototype.withModel=function(e){return e instanceof sr&&(e=e.build()),this._m=e,this.withContentType(new Nn("model",An.Model)),this},e.prototype.build=function(){if(!this._m)throw new Error("Invalid state: you Must provide at least a model.");var e="".concat(In).concat(Sn);if(!this._rs){var t="/".concat(e);this.withRelationship(new Un("rel".concat(0),Bn.ThreeDimModel,t))}return new kn(this._cts,this._rs,this._m)},e}(),cr=function(){function e(e){this._o=e}return Object.defineProperty(e.prototype,"options",{get:function(){return this._o},enumerable:!1,configurable:!0}),e.prototype.serializeAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u;return A(this,function(c){switch(c.label){case 0:return[4,this.ensureZipLibReadyAsync()];case 1:if(!(n=c.sent()))return[2];if(r=n.Zip,o=n.ZipDeflate,!r||!o)throw new Error("fflate Zip / ZipDeflate not available");return i=function(e){return{push:function(t,n){return e.push(t,n)}}},a=function(e,t,n){var r=new o(t,{level:6});e.add(r);var a=i(r),s=new bn(a),u=new Tn(s).dec("1.0","UTF-8");new gn(u).serialize(n),s.finish()},(s=this.toDocument.apply(this,t))?(u=new r(e),a(u,Fn,s.contentTypes),a(u,"".concat(En).concat(Vn),s.relationships),a(u,"".concat(In).concat(Sn),s.model),u.end(),[2]):[2]}})})},e.prototype.toDocument=function(){for(var e,t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o=(new sr).withUnit(null!==(t=null===(e=this._o)||void 0===e?void 0:e.unit)&&void 0!==t?t:_n.millimeter);if(this.options.metadata)for(var i in this.options.metadata)o.withMetaData(i,this.options.metadata[i]);return(new ur).withModel(this.toModel.apply(this,C([o],n,!1))).build()},e}(),lr=function(){function e(){}return e.SerializeToMemoryAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return w(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return A(this,function(l){switch(l.label){case 0:return n=new Array,r=0,o=function(e,t,o){n.push(t),r+=t.length},[4,e.serializeAsync.apply(e,C([o],t,!1))];case 1:if(l.sent(),!r)return[2,void 0];for(i=new Uint8Array(r),a=0,s=0,u=n;s<u.length;s++)c=u[s],i.set(c,a),a+=c.length;return[2,i]}})})},e}(),hr=function(){function e(){}return e.FFLATEUrl="https://unpkg.com/fflate@0.8.2",e}(),fr=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=Number.MIN_SAFE_INTEGER),void 0===n&&(n=1),this._from=e,this._to=t,this._step=n,this._i=e}return e.prototype.next=function(){if(this._i<this._to)throw new Error("ST_ResourceID out of bound");var e=this._i;return this._i+=this._step,e},e.prototype.reset=function(){return this._i=this._from,this},e}(),pr=function(e){function t(n){return void 0===n&&(n={}),e.call(this,b(b({},t.DefaultOptions),n))||this}return y(t,e),t.prototype.toModel=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];t=t.filter(function(e){return e instanceof g.Mesh||e instanceof g.InstancedMesh});for(var r=new fr,o=e,i=new Map,a=this.options.exportInstances?[]:null,s=0;s<t.length;s++){var u=t[s];if(u instanceof g.InstancedMesh)null==a||a.push(u);else{var c=u.name||"mesh".concat(s),l=u.getWorldMatrix(),h=this._handleBabylonTo3mfMatrixTransformToRef(l,Wn.Zero());if(void 0!==(A=u.subMeshes))for(var f=1==A.length,p=0;p<A.length;p++){var d=A[p],m=this._extractSubMesh(u,d);if(m){var x=f?"".concat(c):"".concat(c,"_").concat(p),_=new ir(r.next()).withData(m).withName(x).build();o.withMesh(_),o.withBuild(_.id,h),i.set(d,_)}}}}if(a&&a.length)for(var v=this._groupBy(a,function(e){return e.sourceMesh}),T=0,y=Array.from(v.entries());T<y.length;T++){var b=y[T],M=b[0],w=b[1];if(w&&w.length)for(s=0;s<w.length;s++){l=w[s].getWorldMatrix();var A=M.subMeshes;for(p=0;p<A.length;p++){d=A[p];var C=i.get(d);C&&o.withBuild(C.id,this._handleBabylonTo3mfMatrixTransformToRef(l,Wn.Zero()))}}}return o.build()},t.prototype.ensureZipLibReadyAsync=function(){return w(this,void 0,void 0,function(){var e=this;return A(this,function(t){switch(t.label){case 0:return this._fflateReadyPromise?[4,this._fflateReadyPromise]:[3,2];case 1:case 3:return[2,t.sent()];case 2:return this._fflateReadyPromise=w(e,void 0,void 0,function(){var e;return A(this,function(t){switch(t.label){case 0:return(e=globalThis).fflate?[3,2]:[4,g.Tools.LoadScriptAsync(hr.FFLATEUrl)];case 1:t.sent(),t.label=2;case 2:return[2,e.fflate]}})}),[4,this._fflateReadyPromise]}})})},t.prototype._extractSubMesh=function(e,n){var r=e.getIndices();if(r){var o=e.getVerticesData(t._PositionKind);if(o){if(0==n.indexStart&&n.indexCount==r.length)return{positions:o,indices:r};for(var i=n.indexStart,a=new Map,s=[],u=new Uint32Array(n.indexCount),c=0;c<n.indexCount;c++){var l=r[i+c],h=a.get(l);if(void 0===h){h=a.size,a.set(l,h);var f=3*l;s.push(o[f],o[f+1],o[f+2])}u[c]=h}return{positions:new Float32Array(s),indices:u}}}},t.prototype._groupBy=function(e,t){for(var n=new Map,r=0,o=e;r<o.length;r++){var i=o[r],a=t(i),s=n.get(a);s?s.push(i):n.set(a,[i])}return n},t.prototype._handleBabylonTo3mfMatrixTransformToRef=function(e,n){var r=e.multiplyToRef(t._R_BJS_TO_3MF,g.Matrix.Zero()).m;return n.values=[r[0],r[1],r[2],r[4],r[5],r[6],r[8],r[9],r[10],r[12],r[13],r[14]],n},t.DefaultOptions={unit:_n.meter,exportInstances:!1},t._PositionKind="position",t._R_BJS_TO_3MF=g.Matrix.RotationX(Math.PI/2).multiply(g.Matrix.Scaling(1,-1,1)),t}(cr),dr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==dr)for(var mr in p)dr.BABYLON[mr]=p[mr];var gr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==gr){gr.BABYLON=gr.BABYLON||{};var xr=gr.BABYLON;xr.GLTF2=xr.GLTF2||{},xr.GLTF2.Exporter=xr.GLTF2.Exporter||{},xr.GLTF2.Exporter.Extensions=xr.GLTF2.Exporter.Extensions||{};var _r=[];for(var vr in a)xr[vr]=a[vr],_r.push(vr);for(var vr in s)xr[vr]=s[vr],_r.push(vr);for(var vr in u)xr[vr]=u[vr],_r.push(vr);for(var vr in c)xr.GLTF2.Exporter.Extensions[vr]=c[vr],_r.push(vr);for(var vr in l)_r.indexOf(vr)>-1||(xr.GLTF2.Exporter[vr]=l[vr])}var Tr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Tr)for(var yr in i)Tr.BABYLON[yr]=i[yr];var br=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==br)for(var Mr in h)br.BABYLON[Mr]=h[Mr];var wr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==wr)for(var Ar in f)wr.BABYLON[Ar]=f[Ar];var Cr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Cr){var Rr=[];for(var Er in d)Rr.indexOf(Er)>-1||(Cr.BABYLON[Er]=d[Er],Rr.push(Er))}const Ir=m;return o.default})());
|
|
2
2
|
//# sourceMappingURL=babylonjs.serializers.min.js.map
|