babylonjs-serializers 9.4.0 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babylon.glTF2Serializer.min.js +2 -2
- package/babylon.glTF2Serializer.min.js.map +1 -1
- package/babylon.objSerializer.min.js +2 -2
- package/babylon.objSerializer.min.js.map +1 -1
- package/babylon.stlSerializer.min.js +2 -2
- package/babylon.stlSerializer.min.js.map +1 -1
- package/babylon.threemfSerializer.min.js +2 -2
- package/babylon.threemfSerializer.min.js.map +1 -1
- package/babylon.usdzSerializer.min.js +2 -2
- package/babylon.usdzSerializer.min.js.map +1 -1
- package/babylonjs.serializers.js +2 -2
- package/babylonjs.serializers.js.map +1 -0
- package/babylonjs.serializers.min.js +2 -2
- package/babylonjs.serializers.min.js.map +1 -1
- package/package.json +6 -11
- package/rollup.config.umd.mjs +25 -0
- package/babylon.glTF2Serializer.js +0 -2
- package/babylon.objSerializer.js +0 -2
- package/babylon.stlSerializer.js +0 -2
- package/babylon.threemfSerializer.js +0 -2
- package/babylon.usdzSerializer.js +0 -2
|
@@ -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:()=>Sr});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:()=>Gt});var p={};r.r(p),r.d(p,{BVHExporter:()=>qt});var d={};r.r(d),r.d(d,{AbstractThreeMfSerializer:()=>lr,ContentTypeFileName:()=>Bn,DefaultXmlSerializerFormatOptions:()=>sn,DefaultXmlSerializerNumberOptions:()=>an,GetXmlFieldMeta:()=>en,GetXmlName:()=>tn,IsQualifiedName:()=>jt,Known3mfRelationshipTypes:()=>On,KnownI3mfContentType:()=>Cn,Matrix3d:()=>Wn,MatrixFormatter:()=>Dn,ModelFileName:()=>Vn,NumberFormatter:()=>ln,Object3dDirName:()=>Sn,OpenXmlContentTypesNamespace:()=>Rn,OpenXmlRelationshipsNamespace:()=>En,RelationshipDirName:()=>In,RelationshipFileName:()=>Fn,ResolveFormatOptions:()=>cn,ResolveNumberOptions:()=>un,ST_ObjectType:()=>Tn,ST_Unit:()=>vn,StringXmlWriter:()=>bn,ThreeDimModelNamespace:()=>wn,ThreeMf:()=>hr,ThreeMfBase:()=>tr,ThreeMfBaseMaterials:()=>er,ThreeMfBuild:()=>nr,ThreeMfComponent:()=>$n,ThreeMfComponents:()=>Jn,ThreeMfComponentsBuilder:()=>ir,ThreeMfContentType:()=>Pn,ThreeMfContentTypes:()=>Nn,ThreeMfDocument:()=>Ln,ThreeMfDocumentBuilder:()=>cr,ThreeMfItem:()=>rr,ThreeMfMaterialBuilder:()=>sr,ThreeMfMesh:()=>Hn,ThreeMfMeshBuilder:()=>ar,ThreeMfMeta:()=>Kn,ThreeMfMetadataGroup:()=>Gn,ThreeMfModel:()=>zn,ThreeMfModelBuilder:()=>ur,ThreeMfObject:()=>jn,ThreeMfObjectBuilder:()=>or,ThreeMfRelationship:()=>kn,ThreeMfRelationships:()=>Un,ThreeMfResources:()=>qn,ThreeMfSerializer:()=>dr,ThreeMfSerializerGlobalConfiguration:()=>fr,ThreeMfTriangle:()=>Yn,ThreeMfTriangles:()=>Zn,ThreeMfVertex:()=>Qn,ThreeMfVertices:()=>Xn,ToQualifiedString:()=>on,TokenType:()=>gn,TriangleSetsNamespace:()=>An,Utf8XmlWriterToBytes:()=>Mn,XmlAttr:()=>Jt,XmlBuilder:()=>yn,XmlElem:()=>$t,XmlIgnore:()=>Yt,XmlName:()=>Zt,XmlNameToParts:()=>rn,XmlSerializer:()=>xn});var m={};r.r(m),r.d(m,{AbstractThreeMfSerializer:()=>lr,BVHExporter:()=>qt,ContentTypeFileName:()=>Bn,DefaultXmlSerializerFormatOptions:()=>sn,DefaultXmlSerializerNumberOptions:()=>an,EXT_lights_area:()=>Se,EXT_mesh_gpu_instancing:()=>xe,EXT_texture_avif:()=>Et,EXT_texture_webp:()=>Ct,GLTF2Export:()=>de,GLTFData:()=>v,GetXmlFieldMeta:()=>en,GetXmlName:()=>tn,IsQualifiedName:()=>jt,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:()=>On,KnownI3mfContentType:()=>Cn,Matrix3d:()=>Wn,MatrixFormatter:()=>Dn,ModelFileName:()=>Vn,NumberFormatter:()=>ln,OBJExport:()=>x,Object3dDirName:()=>Sn,OpenXmlContentTypesNamespace:()=>Rn,OpenXmlRelationshipsNamespace:()=>En,RelationshipDirName:()=>In,RelationshipFileName:()=>Fn,ResolveFormatOptions:()=>cn,ResolveNumberOptions:()=>un,STLExport:()=>It,ST_ObjectType:()=>Tn,ST_Unit:()=>vn,StringXmlWriter:()=>bn,ThreeDimModelNamespace:()=>wn,ThreeMf:()=>hr,ThreeMfBase:()=>tr,ThreeMfBaseMaterials:()=>er,ThreeMfBuild:()=>nr,ThreeMfComponent:()=>$n,ThreeMfComponents:()=>Jn,ThreeMfComponentsBuilder:()=>ir,ThreeMfContentType:()=>Pn,ThreeMfContentTypes:()=>Nn,ThreeMfDocument:()=>Ln,ThreeMfDocumentBuilder:()=>cr,ThreeMfItem:()=>rr,ThreeMfMaterialBuilder:()=>sr,ThreeMfMesh:()=>Hn,ThreeMfMeshBuilder:()=>ar,ThreeMfMeta:()=>Kn,ThreeMfMetadataGroup:()=>Gn,ThreeMfModel:()=>zn,ThreeMfModelBuilder:()=>ur,ThreeMfObject:()=>jn,ThreeMfObjectBuilder:()=>or,ThreeMfRelationship:()=>kn,ThreeMfRelationships:()=>Un,ThreeMfResources:()=>qn,ThreeMfSerializer:()=>dr,ThreeMfSerializerGlobalConfiguration:()=>fr,ThreeMfTriangle:()=>Yn,ThreeMfTriangles:()=>Zn,ThreeMfVertex:()=>Qn,ThreeMfVertices:()=>Xn,ToQualifiedString:()=>on,TokenType:()=>gn,TriangleSetsNamespace:()=>An,USDZExportAsync:()=>Gt,Utf8XmlWriterToBytes:()=>Mn,XmlAttr:()=>Jt,XmlBuilder:()=>yn,XmlElem:()=>$t,XmlIgnore:()=>Yt,XmlName:()=>Zt,XmlNameToParts:()=>rn,XmlSerializer:()=>xn,_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 L=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}(),W=g.Matrix.Compose(new g.Vector3(-1,1,1),g.Quaternion.Identity(),g.Vector3.Zero());function D(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(W,g.TmpVectors.Matrix[0]).equalsWithEpsilon(g.Matrix.IdentityReadOnly,g.Epsilon))return!1;return!(e instanceof g.AbstractMesh&&e.geometry)}var z=g.Vector3.ZeroReadOnly,K=g.Quaternion.Identity(),G=g.Vector3.OneReadOnly,q=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 W.invertToRef(g.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(W,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(G,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(G,a,i,g.TmpVectors.Matrix[1]);o.multiplyToRef(s,s),s.decompose(void 0,r,n),n.equalsWithEpsilon(z,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?q:G;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 L(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(z,g.Epsilon)||g.Tools.Warn("Pivot points are not supported in the glTF serializer"),!t.position.equalsWithEpsilon(z,g.Epsilon)){var o=g.TmpVectors.Vector3[0].copyFrom(t.position);n&&Y(o),e.translation=o.asArray()}t.scaling.equalsWithEpsilon(G,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(z,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&&D(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 Le(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 We(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 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.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 ze(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,De(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]=ze(this._cachedInternalTexturesMap[o],n.coatWeightTexture),e.push(this._mergedTexturesMap[n.coatWeightTexture.uniqueId])),n.coatRoughnessTexture&&(this._mergedTexturesMap[n.coatRoughnessTexture.uniqueId]=ze(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=Le(n),this._mergedTexturesMap[o]?(e.push(this._mergedTexturesMap[o]),[3,7]):[3,5]):[3,8];case 5:return[4,We(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=Le(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 Ge="KHR_materials_diffuse_transmission";function qe(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=Ge,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=qe(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=qe(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[Ge]=p}o(t)})},e}();pe.RegisterExtension(Ge,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 Lt(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function Wt(e,t,n,r,o,i){var a,s,u=e.getInternalTexture().uniqueId+"_"+e.invertY,c="image/jpeg"===(e.mimeType||(0,g.GetMimeType)(null!==(s=null===(a=e.getInternalTexture())||void 0===a?void 0:a.url)&&void 0!==s?s:""))?"jpg":"png";o[u]={texture:e,ext:c};var l=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",h=new g.Vector2(e.uScale,e.vScale),f=new g.Vector2(e.uOffset,e.vOffset),p=e.wAng,d=Math.sin(p),m=Math.cos(p);return f.y=1-f.y-h.y,f.x+=d*h.x,f.y+=(1-m)*h.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(l,'"\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((p*(180/Math.PI)).toFixed(i.precision),"\n float2 inputs:scale = ").concat(kt(h),"\n float2 inputs:translation = ").concat(kt(f),'\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(u,".").concat(c,"@\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 Dt(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(Wt(s,e,"diffuse",u,t,n))):o.push("".concat(r,"color3f inputs:diffuseColor = ").concat(Lt(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(Wt(l,e,"emissive",h,t,n))):h&&h.toLuminance()>0&&o.push("".concat(r,"color3f inputs:emissiveColor = ").concat(Lt(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(Wt(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(Wt(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(Wt(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(Wt(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(Wt(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(Wt(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(Wt(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 zt(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(D(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){return w(this,void 0,void 0,function(){var t,n,r,o,i;return A(this,function(a){switch(a.label){case 0:if(!(t=e.getInternalTexture())||1!==t.source)return[2,null];n=t._buffer,o=e.mimeType,a.label=1;case 1:return a.trys.push([1,12,,13]),n?[3,3]:[4,g.Tools.LoadFileAsync(t.url)];case 2:return r=a.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=a.sent(),o=n.type||o,[3,11];case 7:return"string"!=typeof n?[3,9]:[4,g.Tools.LoadFileAsync(n)];case 8:return r=a.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=a.sent(),o=(0,g.GetMimeType)(n.src)||o,a.label=11;case 11:return[3,13];case 12:return a.sent(),[2,null];case 13:return r&&!o&&t.url&&(i=t.url.match(/^data:([^;,]+)/),o=i?i[1]:(0,g.GetMimeType)(t.url)),r&&o?[2,{data:r,mimeType:o}]:[2,null]}})})}function Gt(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,k,L,W;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=zt(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(Dt(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.texture,S=E.ext,[4,Kt(I)]):[3,8]:[3,9];case 4:return(V=A.sent())?(o["textures/Texture_".concat(R,".").concat(S)]=new Uint8Array(V.data),[3,8]):[3,5];case 5:return F=I.getSize(),[4,(0,g.GetTextureDataAsync)(I)];case 6:return B=A.sent(),[4,g.DumpTools.DumpDataAsync(F.width,F.height,B,"image/png",void 0,!1,!0)];case 7:O=A.sent(),o["textures/Texture_".concat(R,".").concat(S)]=new Uint8Array(O).slice(),A.label=8;case 8:return C++,[3,3];case 9:for(P in N=0,o)(U=o[P])&&(k=34+P.length,4!=(L=63&(N+=k))&&(W=new Uint8Array(64-L),o[P]=[U,{extra:{12345:W}}]),N=U.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 jt(e){return"string"==typeof(null==e?void 0:e.name)}var Ht=Symbol("__xml:meta$__"),Xt=Symbol("__xml:name$__");function Qt(e,t){var n,r=e.constructor;(null!==(n=r[Ht])&&void 0!==n?n:r[Ht]=[]).push(t)}function Zt(e){return function(t){t[Xt]=e}}function Yt(){return function(e,t){return Qt(e,{kind:"none",prop:t,ignore:!0})}}function Jt(e){return function(t,n){return Qt(t,b({kind:"attr",prop:n},e))}}function $t(e){return function(t,n){return Qt(t,b({kind:"elem",prop:n},e))}}function en(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 tn(e){var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Xt])||void 0}function nn(e){return/^[A-Za-z_][A-Za-z0-9._-]*$/.test(e)}function rn(e){if(jt(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 nn(r)&&nn(o)?{ns:r,name:o}:{name:t}}function on(e,t){return t?"".concat(t,":").concat(e):e}var an=Object.freeze({eps:1e-6,maxDecimalsCap:15,trimTrailingZeros:!0,allowScientific:!1,snapNearZero:!0}),sn=Object.freeze({number:an});function un(e){var t,n,r,o,i,a,s=null!==(t=null==e?void 0:e.eps)&&void 0!==t?t:an.eps;return{eps:s,maxDecimalsCap:null!==(n=null==e?void 0:e.maxDecimalsCap)&&void 0!==n?n:an.maxDecimalsCap,trimTrailingZeros:null!==(r=null==e?void 0:e.trimTrailingZeros)&&void 0!==r?r:an.trimTrailingZeros,fixedDecimals:null==e?void 0:e.fixedDecimals,allowScientific:null!==(o=null==e?void 0:e.allowScientific)&&void 0!==o?o:an.allowScientific,snapNearZero:null!==(i=null==e?void 0:e.snapNearZero)&&void 0!==i?i:an.snapNearZero,zeroThreshold:null!==(a=null==e?void 0:e.zeroThreshold)&&void 0!==a?a:s,perAttributeEps:null==e?void 0:e.perAttributeEps}}function cn(e){return{number:un(null==e?void 0:e.number)}}var ln=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 hn(e){return e instanceof Date}function fn(e){return"string"==typeof e}function pn(e){return"number"==typeof e}function dn(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||hn(e)}function mn(e){return"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||hn(e)}var gn,xn=function(){function e(e,t){this._ns=new Map,this._prefixCount=0,this._builder=e,this._format=cn(t),this._nFmt=new ln(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:tn(e)))throw new Error("can not find name for given object");var n=rn(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];mn(i)||(fn(i)?this._builder.text(i):this._writeObject(e,i,n))}else{var a=tn(t);if(a){var s=rn(a),u=this._getPrefix(s),c=on(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=en(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(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=rn(y),w=this._getPrefix(M),A=on(M.name,w);e.att(null,A,b)}}}}else mn(g)||(fn(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];dn(a)||this._gatherNamespaces(a,t)}else{var s=tn(e);s&&this._assignNamespace(s);for(var u=null!==(n=en(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];dn(A)||this._gatherNamespaces(A,t)}}},e.prototype._assignNamespace=function(e,t){var n=rn(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}(),_n=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"}(gn||(gn={}));var vn,Tn,yn=function(){function e(e){this._ctxStack=[],this._d=0,this._w=e}return e.prototype.dec=function(e,t,n){return this._w.write(_n.Dec),this._writeAttStr(_n.VersionKeyword,e),t&&this._writeAttStr(_n.EncodingKeyword,t),void 0!==n&&this._writeAttStr(_n.StandaloneKeyword,n?"yes":"no"),this._w.write(_n.Question,_n.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===_n.Xmlns)r.defaultNs=n,this._registerNamespace(r,"",n),this._writeAttStr(_n.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=gn.Attribute,this}var i=t;if(e){var a=this._ensurePrefixDeclared(r,e);i="".concat(a,":").concat(t)}return r.lastToken=gn.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(_n.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=gn.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(_n.OpenTag,_n.Slash,e.name,_n.CloseTag):this._w.write(_n.Slash,_n.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(_n.Space,e,_n.Equal,_n.Quote,this._escAttr(t),_n.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===_n.Xmlns;var n=t.length,r=_n.Xmlns.length;return n>=r&&t.startsWith(_n.Xmlns)&&(t.length==r||t[r]==_n.Semicolon)},e.prototype._registerNamespace=function(e,t,n){if(t===_n.Xml||t===_n.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(_n.Xmlns,":").concat(r),t),this._registerNamespace(e,r,t),r},e.prototype._closeOpenTagIfNeeded=function(e){e.closed||(this._w.write(_n.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}(),bn=function(){function e(){this.count=0,this._chunks=[]}return e.prototype.write=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)return this;var n=e.join("");return this._chunks.push(n),this.count+=n.length,this},e.prototype.toString=function(){return this._chunks.join("")},e.prototype.clear=function(){this._chunks=[],this.count=0},e}(),Mn=function(){function e(e,t){void 0===t&&(t={}),this._sink=e,this._opts=t,this.count=0,this._encoder=new TextEncoder,this._pending="",this._pendingChars=0}return e.prototype.write=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(0===t.length)return this;var r=t.join("");if(0===r.length)return this;this._pending+=r,this._pendingChars+=r.length;var o=null!==(e=this._opts.flushChars)&&void 0!==e?e:65536;return this._pendingChars>=o&&this.flush(),this},e.prototype.flush=function(){if(0===this._pendingChars)return this;var e=this._encoder.encode(this._pending);return this._sink.push(e),this.count+=e.length,this._pending="",this._pendingChars=0,this},e.prototype.finish=function(){this.flush(),this._sink.push(new Uint8Array(0),!0)},e.prototype.clear=function(){this._pending="",this._pendingChars=0,this.count=0},e}(),wn="http://schemas.microsoft.com/3dmanufacturing/core/2015/02",An="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"}(vn||(vn={})),function(e){e.model="model",e.solidsupport="solidsupport",e.support="support",e.surface="surface",e.other="other"}(Tn||(Tn={}));var Cn,Rn="http://schemas.openxmlformats.org/package/2006/content-types",En="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"}(Cn||(Cn={}));var In="_rels/",Sn="3D/",Vn="3dmodel.model",Fn=".rels",Bn="[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}(),Nn=function(){function e(){this.items=[]}return M([Zt({ns:Rn,name:"Types"})],e)}(),Pn=function(){function e(e,t){this.ext=e,this.ct=t}return M([Jt({name:{ns:Rn,name:"Extension"}})],e.prototype,"ext",void 0),M([Jt({name:{ns:Rn,name:"ContentType"}})],e.prototype,"ct",void 0),M([Zt({ns:Rn,name:"Default"})],e)}(),Un=function(){function e(){this.items=[]}return M([Zt({ns:En,name:"Relationships"})],e)}(),kn=function(){function e(e,t,n){this.id=e,this.type=t,this.target=n}return M([Jt({name:"Id"})],e.prototype,"id",void 0),M([Jt({name:"Type"})],e.prototype,"type",void 0),M([Jt({name:"Target"})],e.prototype,"target",void 0),M([Zt({ns:En,name:"Relationship"})],e)}(),Ln=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 ln(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=vn.millimeter}return e.KnownMeta=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate","Application"],M([Jt({name:"unit"})],e.prototype,"unit",void 0),M([Jt({name:"requiredextensions"})],e.prototype,"requiredextensions",void 0),M([Jt({name:"recommendedextensions"})],e.prototype,"recommendedextensions",void 0),M([Zt({ns:wn,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([Jt({name:"name"})],e.prototype,"name",void 0),M([Jt({name:"preserve"})],e.prototype,"preserve",void 0),M([Jt({name:"type"})],e.prototype,"type",void 0),M([Zt({ns:wn,name:"meta"})],e)}(),Gn=function(){function e(){this.metadata=[]}return M([Zt({ns:wn,name:"metadatagroup"})],e)}(),qn=function(){function e(){this.object=[]}return M([Zt({ns:wn,name:"resources"})],e)}(),jn=function(){function e(e,t){void 0===t&&(t=Tn.model),this.id=e,this.type=t}return M([Jt({name:"id"})],e.prototype,"id",void 0),M([Jt({name:"type"})],e.prototype,"type",void 0),M([Jt({name:"thumbnail"})],e.prototype,"thumbnail",void 0),M([Jt({name:"partnumber"})],e.prototype,"partnumber",void 0),M([Jt({name:"name"})],e.prototype,"name",void 0),M([Jt({name:"pid"})],e.prototype,"pid",void 0),M([Jt({name:"pindex"})],e.prototype,"pindex",void 0),M([Zt({ns:wn,name:"object"})],e)}(),Hn=function(){function e(e,t){this.vertices=null!=e?e:new Xn,this.triangles=null!=t?t:new Zn}return M([Zt({ns:wn,name:"mesh"})],e)}(),Xn=function(){function e(){this.vertex=[]}return M([Zt({ns:wn,name:"vertices"})],e)}(),Qn=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([Jt({name:"x"})],e.prototype,"x",void 0),M([Jt({name:"y"})],e.prototype,"y",void 0),M([Jt({name:"z"})],e.prototype,"z",void 0),M([Zt({ns:wn,name:"vertex"})],e)}(),Zn=function(){function e(){this.triangle=[]}return M([Zt({ns:wn,name:"triangles"})],e)}(),Yn=function(){function e(e,t,n){this.v1=e,this.v2=t,this.v3=n}return M([Jt({name:"v1"})],e.prototype,"v1",void 0),M([Jt({name:"v2"})],e.prototype,"v2",void 0),M([Jt({name:"v3"})],e.prototype,"v3",void 0),M([Jt({name:"p1"})],e.prototype,"p1",void 0),M([Jt({name:"p2"})],e.prototype,"p2",void 0),M([Jt({name:"p3"})],e.prototype,"p3",void 0),M([Jt({name:"pid"})],e.prototype,"pid",void 0),M([Zt({ns:wn,name:"triangle"})],e)}(),Jn=function(){function e(){this.component=[]}return M([Zt({ns:wn,name:"components"})],e)}(),$n=function(){function e(e,t){this.objectid=e,this.transform=t}return M([Jt({name:"objectid"})],e.prototype,"objectid",void 0),M([Jt({name:"transform",formatter:Dn})],e.prototype,"transform",void 0),M([Zt({ns:wn,name:"component"})],e)}(),er=function(){function e(e){this.base=[],this.id=e}return M([Jt({name:"id"})],e.prototype,"id",void 0),M([Zt({ns:wn,name:"basematerials"})],e)}(),tr=function(){function e(e,t){this.name=e,this.displaycolor=t}return M([Jt({name:"name"})],e.prototype,"name",void 0),M([Jt({name:"displaycolor"})],e.prototype,"displaycolor",void 0),M([Zt({ns:wn,name:"base"})],e)}(),nr=function(){function e(){this.item=[]}return M([Zt({ns:wn,name:"build"})],e)}(),rr=function(){function e(e,t,n){this.objectid=e,this.transform=t,this.partnumber=n}return M([Jt({name:"objectid"})],e.prototype,"objectid",void 0),M([Jt({name:"transform",formatter:Dn})],e.prototype,"transform",void 0),M([Jt({name:"partnumber"})],e.prototype,"partnumber",void 0),M([Zt({ns:wn,name:"item"})],e)}(),or=function(){function e(e,t){this._object=new jn(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 jn(e,t)},e}(),ir=function(e){function t(t,n){void 0===n&&(n=Tn.model);var r=e.call(this,t,n)||this;return r._object.content=new Jn,r}return y(t,e),t.prototype.withComponent=function(e,t){return this._object.content.component.push(new $n(e,t)),this},t}(or),ar=function(e){function t(t){return e.call(this,t,Tn.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 Xn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Qn(r,o,i);this._vh&&(a=this._vh(a)),t.vertex.push(a)}return t},t.prototype._buildTriangle=function(e){var t=new Zn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Yn(r,o,i);this._th&&(a=this._th(a)),t.triangle.push(a)}return t},t}(or),sr=function(){function e(e){this._m=new er(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 tr(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}(),ur=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 sr&&(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 ar&&(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 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.withBuild=function(e,t,n){var r,o;return this._model.build=null!==(r=this._model.build)&&void 0!==r?r:new nr,null===(o=this._model.build.item)||void 0===o||o.push(new rr(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}(),cr=function(){function e(){}return e.prototype.withContentType=function(e){this._cts||(this._cts=new Nn);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 Un);var t=this._rs.items;return t.some(function(t){return t.id===e.id})||t.push(e),this.withContentType(new Pn("rels",Cn.Relationships)),this},e.prototype.withModel=function(e){return e instanceof ur&&(e=e.build()),this._m=e,this.withContentType(new Pn("model",Cn.Model)),this},e.prototype.build=function(){if(!this._m)throw new Error("Invalid state: you Must provide at least a model.");var e="".concat(Sn).concat(Vn);if(!this._rs){var t="/".concat(e);this.withRelationship(new kn("rel".concat(0),On.ThreeDimModel,t))}return new Ln(this._cts,this._rs,this._m)},e}(),lr=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 Mn(a),u=new yn(s).dec("1.0","UTF-8");new xn(u).serialize(n),s.finish()},(s=this.toDocument.apply(this,t))?(u=new r(e),a(u,Bn,s.contentTypes),a(u,"".concat(In).concat(Fn),s.relationships),a(u,"".concat(Sn).concat(Vn),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 ur).withUnit(null!==(t=null===(e=this._o)||void 0===e?void 0:e.unit)&&void 0!==t?t:vn.millimeter);if(this.options.metadata)for(var i in this.options.metadata)o.withMetaData(i,this.options.metadata[i]);return(new cr).withModel(this.toModel.apply(this,C([o],n,!1))).build()},e}(),hr=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}(),fr=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}(),dr=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,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 ar(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(fr.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:vn.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}(lr),mr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==mr)for(var gr in p)mr.BABYLON[gr]=p[gr];var xr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==xr){xr.BABYLON=xr.BABYLON||{};var _r=xr.BABYLON;_r.GLTF2=_r.GLTF2||{},_r.GLTF2.Exporter=_r.GLTF2.Exporter||{},_r.GLTF2.Exporter.Extensions=_r.GLTF2.Exporter.Extensions||{};var vr=[];for(var Tr in a)_r[Tr]=a[Tr],vr.push(Tr);for(var Tr in s)_r[Tr]=s[Tr],vr.push(Tr);for(var Tr in u)_r[Tr]=u[Tr],vr.push(Tr);for(var Tr in c)_r.GLTF2.Exporter.Extensions[Tr]=c[Tr],vr.push(Tr);for(var Tr in l)vr.indexOf(Tr)>-1||(_r.GLTF2.Exporter[Tr]=l[Tr])}var yr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==yr)for(var br in i)yr.BABYLON[br]=i[br];var Mr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Mr)for(var wr in h)Mr.BABYLON[wr]=h[wr];var Ar=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Ar)for(var Cr in f)Ar.BABYLON[Cr]=f[Cr];var Rr=void 0!==r.g?r.g:"undefined"!=typeof window?window:void 0;if(void 0!==Rr){var Er=[];for(var Ir in d)Er.indexOf(Ir)>-1||(Rr.BABYLON[Ir]=d[Ir],Er.push(Ir))}const Sr=m;return o.default})());
|
|
2
|
-
//# sourceMappingURL=babylonjs.serializers.min.js.map
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";var n=function(){function e(){}return e.OBJ=function(e,n,r,o){var i=[],a=1,s=1;n&&(r||(r="mat"),i.push("mtllib "+r+".mtl"));for(var u=0;u<e.length;u++){var c=e[u],l=c.name||"mesh".concat(u,"}");i.push("o ".concat(l));var h=null;if(o){var f=c.computeWorldMatrix(!0);h=new t.Matrix,f.invertToRef(h),c.bakeTransformIntoVertices(f)}if(n){var p=c.material;p&&i.push("usemtl "+p.id)}var d=c.geometry;if(d){var m=d.getVerticesData("position"),g=d.getVerticesData("normal"),x=d.getVerticesData("uv"),_=d.getIndices(),v=0,T=0;if(m&&_){for(var y=e[0].getScene().useRightHandedSystem?1:-1,b=0;b<m.length;b+=3)i.push("v "+m[b]*y+" "+m[b+1]+" "+m[b+2]),v++;if(null!=g)for(b=0;b<g.length;b+=3)i.push("vn "+g[b]*y+" "+g[b+1]+" "+g[b+2]);if(null!=x)for(b=0;b<x.length;b+=2)i.push("vt "+x[b]+" "+x[b+1]),T++;var M=["","",""],w=(c.material||c.getScene().defaultMaterial)._getEffectiveOrientation(c)===t.Material.ClockWiseSideOrientation?[2,1]:[1,2],A=w[0],C=w[1];for(b=0;b<_.length;b+=3){var R=[String(_[b]+a),String(_[b+A]+a),String(_[b+C]+a)],E=[String(_[b]+s),String(_[b+A]+s),String(_[b+C]+s)],I=R,S=null!=x?E:M,V=null!=g?R:M;i.push("f "+I[0]+"/"+S[0]+"/"+V[0]+" "+I[1]+"/"+S[1]+"/"+V[1]+" "+I[2]+"/"+S[2]+"/"+V[2])}o&&h&&c.bakeTransformIntoVertices(h),a+=v,s+=T}else t.Tools.Warn("There are no position vertices or indices on the mesh!")}else t.Tools.Warn("No geometry is present on the mesh")}return i.join("\n")},e.MTL=function(e){var t=[],n=e.material;return t.push("newmtl mat1"),t.push(" Ns "+n.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+n.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+n.ambientColor.r.toFixed(4)+" "+n.ambientColor.g.toFixed(4)+" "+n.ambientColor.b.toFixed(4)),t.push(" Kd "+n.diffuseColor.r.toFixed(4)+" "+n.diffuseColor.g.toFixed(4)+" "+n.diffuseColor.b.toFixed(4)),t.push(" Ks "+n.specularColor.r.toFixed(4)+" "+n.specularColor.g.toFixed(4)+" "+n.specularColor.b.toFixed(4)),t.push(" Ke "+n.emissiveColor.r.toFixed(4)+" "+n.emissiveColor.g.toFixed(4)+" "+n.emissiveColor.b.toFixed(4)),n.ambientTexture&&t.push(" map_Ka "+n.ambientTexture.name),n.diffuseTexture&&t.push(" map_Kd "+n.diffuseTexture.name),n.specularTexture&&t.push(" map_Ks "+n.specularTexture.name),n.bumpTexture&&t.push(" map_bump -imfchan z "+n.bumpTexture.name),n.opacityTexture&&t.push(" map_d "+n.opacityTexture.name),t.join("\n")},e}(),r={__proto__:null,OBJExport:n},o={__proto__:null,__IGLTFExporterExtension:0},i=function(){function e(){this.files={}}return Object.defineProperty(e.prototype,"glTFFiles",{get:function(){return this.files},enumerable:!1,configurable:!0}),e.prototype.downloadFiles=function(){for(var e in this.files){var n=this.files[e],r=new Blob([n],{type:t.GetMimeType(e)});t.Tools.Download(r,e)}},e}(),a={__proto__:null,GLTFData:i},s=function(e,t){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},s(e,t)};function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var c=function(){return c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};function l(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function h(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}u((r=r.apply(e,t||[])).next())})}function f(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!((o=(o=i.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function p(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var d=1e-6,m=new t.Color3(.04,.04,.04),g=t.Color3.White(),x=t.Color3.BlackReadOnly;function _(e){switch(e){case"image/jpeg":case"image/png":case"image/webp":case"image/avif":case"image/ktx2":return!0;default:return!1}}function v(e){return h(this,void 0,void 0,function(){var n,r,o,i;return f(this,function(a){switch(a.label){case 0:if(!(n=e.getInternalTexture())||1!==n.source)return[2,null];if(n.invertY)return[2,null];r=n._buffer,i=e.mimeType,a.label=1;case 1:return a.trys.push([1,12,,13]),r?[3,3]:[4,t.Tools.LoadFileAsync(n.url)];case 2:return o=a.sent(),i=t.GetMimeType(n.url)||i,[3,11];case 3:return ArrayBuffer.isView(r)?(o=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,11]):[3,4];case 4:return r instanceof ArrayBuffer?(o=r,[3,11]):[3,5];case 5:return r instanceof Blob?[4,r.arrayBuffer()]:[3,7];case 6:return o=a.sent(),i=r.type||i,[3,11];case 7:return"string"!=typeof r?[3,9]:[4,t.Tools.LoadFileAsync(r)];case 8:return o=a.sent(),i=t.GetMimeType(r)||i,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,t.Tools.LoadFileAsync(r.src)]:[3,11];case 10:o=a.sent(),i=t.GetMimeType(r.src)||i,a.label=11;case 11:return[3,13];case 12:return a.sent(),[2,null];case 13:return o&&_(i)?[2,new Blob([o],{type:i})]:[2,null]}})})}function T(e,n,r){if(n<m.r)return 0;var o=m.r,i=e*r/(1-m.r)+n-2*m.r,a=i*i-4*o*(m.r-n);return t.Scalar.Clamp((-i+Math.sqrt(a))/(2*o),0,1)}function y(e){var n=e.diffuseColor.toLinearSpace(e.getScene().getEngine().useExactSrgbConversions).scale(.5),r=e.alpha,o=t.Scalar.Clamp(e.specularPower,0,1024),i=t.SpecularPowerToRoughness(o);return{baseColorFactor:[n.r,n.g,n.b,r],metallicFactor:0,roughnessFactor:i}}function b(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)}function M(e,n,r){for(var o=new Uint8Array(e*n*4),i=0;i<o.length;i+=4)o[i]=o[i+1]=o[i+2]=o[i+3]=255;return t.RawTexture.CreateRGBATexture(o,e,n,r)}function w(e){if(e instanceof Uint8Array){for(var t=e.length,n=new Float32Array(e.length),r=0;r<t;++r)n[r]=e[r]/255;return n}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")}var A=function(){function e(e){this._exporter=e,this._textureMap=new Map,this._internalTextureToImage={}}return e.prototype.getTextureInfo=function(e){var t;return e&&null!==(t=this._textureMap.get(e.uniqueId))&&void 0!==t?t:null},e.prototype.exportStandardMaterialAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l;return f(this,function(h){switch(h.label){case 0:return r=y(e),o={name:e.name},null==e.backFaceCulling||e.backFaceCulling||(e.twoSidedLighting||t.Tools.Warn(e.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),o.doubleSided=!0),n?(i=[],(a=e.diffuseTexture)&&i.push(this.exportTextureAsync(a).then(function(e){e&&(r.baseColorTexture=e)})),(s=e.bumpTexture)&&i.push(this.exportTextureAsync(s).then(function(e){e&&(o.normalTexture=e,1!==s.level&&(o.normalTexture.scale=s.level))})),(u=e.emissiveTexture)&&(o.emissiveFactor=[1,1,1],i.push(this.exportTextureAsync(u).then(function(e){e&&(o.emissiveTexture=e)}))),(c=e.ambientTexture)&&i.push(this.exportTextureAsync(c).then(function(e){if(e){var t={index:e.index};o.occlusionTexture=t}})),i.length>0?(this._exporter._materialNeedsUVsSet.add(e),[4,Promise.all(i)]):[3,2]):[3,2];case 1:h.sent(),h.label=2;case 2:return(e.alpha<1||e.opacityTexture)&&(e.alphaMode===t.Constants.ALPHA_COMBINE?o.alphaMode="BLEND":t.Tools.Warn(e.name+": glTF 2.0 does not support alpha mode: "+e.alphaMode.toString())),e.emissiveColor&&!e.emissiveColor.equalsWithEpsilon(x,d)&&(o.emissiveFactor=e.emissiveColor.asArray()),o.pbrMetallicRoughness=r,b(o,e),[4,this._finishMaterialAsync(o,e)];case 3:return h.sent(),(l=this._exporter._materials).push(o),[2,l.length-1]}})})},e.prototype._finishMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a;return f(this,function(s){switch(s.label){case 0:return[4,this._exporter._extensionsPostExportMaterialAdditionalTexturesAsync("exportMaterial",e,t)];case 1:for(n=s.sent(),r=[],o=0,i=n;o<i.length;o++)a=i[o],r.push(this.exportTextureAsync(a));return[4,Promise.all(r)];case 2:return s.sent(),[4,this._exporter._extensionsPostExportMaterialAsync("exportMaterial",e,t)];case 3:return s.sent(),[2]}})})},e.prototype._resizeTexturesToSameDimensions=function(e,n,r){var o,i,a=e?e.getSize():{width:0,height:0},s=n?n.getSize():{width:0,height:0};return a.width<s.width?(o=e&&e instanceof t.Texture?t.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):M(s.width,s.height,r),i=n):a.width>s.width?(i=n&&n instanceof t.Texture?t.TextureTools.CreateResizedCopy(n,a.width,a.height,!0):M(a.width,a.height,r),o=e):(o=e,i=n),{texture1:o,texture2:i}},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,c,l,h,p,m,x,_,v,T,y,b,M,A,C,R,E,I,S,V,F,B,O,N,P,U,k;return f(this,function(f){switch(f.label){case 0:return o=new Array,e||n?[3,2]:[4,Promise.reject("diffuse and specular glossiness textures are not defined!")];case 1:case 6:case 9:case 11:case 13:return[2,f.sent()];case 2:return(i=e?e.getScene():n?n.getScene():null)?(a=this._resizeTexturesToSameDimensions(e,n,i),s=null===(k=a.texture1)||void 0===k?void 0:k.getSize(),u=void 0,c=void 0,l=s.width,h=s.height,[4,a.texture1.readPixels()]):[3,12];case 3:return p=f.sent(),[4,a.texture2.readPixels()];case 4:return m=f.sent(),p?(u=w(p),[3,7]):[3,5];case 5:return[4,Promise.reject("Failed to retrieve pixels from diffuse texture!")];case 7:return m?(c=w(m),[3,10]):[3,8];case 8:return[4,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];case 10:for(x=c.byteLength,_=new Uint8Array(x),v=new Uint8Array(x),T=new t.Color3(0,0,0),y=0,b=0,B=0;B<h;++B)for(O=0;O<l;++O)M=4*(l*B+O),A=new t.Color3(u[M],u[M+1],u[M+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.diffuseColor),C=new t.Color3(c[M],c[M+1],c[M+2]).toLinearSpace(i.getEngine().useExactSrgbConversions).multiply(r.specularColor),R=c[M+3]*r.glossiness,E={diffuseColor:A,specularColor:C,glossiness:R},I=this._convertSpecularGlossinessToMetallicRoughness(E),T.r=Math.max(T.r,I.baseColor.r),T.g=Math.max(T.g,I.baseColor.g),T.b=Math.max(T.b,I.baseColor.b),y=Math.max(y,I.metallic),b=Math.max(b,I.roughness),v[M]=255*I.baseColor.r,v[M+1]=255*I.baseColor.g,v[M+2]=255*I.baseColor.b,v[M+3]=a.texture1.hasAlpha?255*u[M+3]:255,_[M]=0,_[M+1]=255*I.roughness,_[M+2]=255*I.metallic,_[M+3]=255;for(S={baseColor:T,metallic:y,roughness:b},V=!1,F=!1,B=0;B<h;++B)for(O=0;O<l;++O)v[N=4*(l*B+O)]/=S.baseColor.r>d?S.baseColor.r:1,v[N+1]/=S.baseColor.g>d?S.baseColor.g:1,v[N+2]/=S.baseColor.b>d?S.baseColor.b:1,P=t.Color3.FromInts(v[N],v[N+1],v[N+2]),U=P.toGammaSpace(i.getEngine().useExactSrgbConversions),v[N]=255*U.r,v[N+1]=255*U.g,v[N+2]=255*U.b,U.equalsWithEpsilon(g,d)||(F=!0),_[N+1]/=S.roughness>d?S.roughness:1,_[N+2]/=S.metallic>d?S.metallic:1,t.Color3.FromInts(255,_[N+1],_[N+2]).equalsWithEpsilon(g,d)||(V=!0);return V&&o.push(t.EncodeImageAsync(_,l,h).then(function(e){S.metallicRoughnessTextureData=e})),F&&o.push(t.EncodeImageAsync(v,l,h).then(function(e){S.baseColorTextureData=e})),[4,Promise.all(o).then(function(){return S})];case 12:return[4,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}})})},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var n=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),o=1-this._getMaxComponent(e.specularColor),i=T(n,r,o),a=e.diffuseColor.scale(o/(1-m.r)/Math.max(1-i,d)),s=e.specularColor.subtract(m.scale(1-i)).scale(1/Math.max(i,d)),u=t.Color3.Lerp(a,s,i*i);return{baseColor:u=u.clampToRef(0,1,u),metallic:i,roughness:1-e.glossiness}},e.prototype._getPerceivedBrightness=function(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)},e.prototype._getMaxComponent=function(e){return Math.max(e.r,Math.max(e.g,e.b))},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,n,r,o,i,a,s,u,c){return h(this,void 0,void 0,function(){var l,p,d,m,g,x,_,v,T,y=this;return f(this,function(b){switch(b.label){case 0:return l=[],p={baseColor:e,metallic:n,roughness:r},c&&(s instanceof t.OpenPBRMaterial?(s.geometryOpacityTexture?(d=o&&o.getInternalTexture()?o.getInternalTexture().uniqueId:0,m=s.geometryOpacityTexture&&s.geometryOpacityTexture.getInternalTexture()?s.geometryOpacityTexture.getInternalTexture().uniqueId:0,g=Number("".concat(d).concat(m)),(T=this._textureMap.get(g))?u.baseColorTexture=T:l.push(t.MergeTexturesAsync("baseColorOpacityTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(1),o?t.CreateTextureInput(o,2):t.CreateConstantInput(1),t.CreateTextureInput(s.geometryOpacityTexture,0)),s.getScene()).then(function(e){return h(y,void 0,void 0,function(){var t;return f(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,g)];case 1:return(t=n.sent())&&(u.baseColorTexture=t),[2]}})})}))):o&&l.push(this.exportTextureAsync(o).then(function(e){e&&(u.baseColorTexture=e)})),s._useMetallicFromMetallicTextureBlue&&i?l.push(this.exportTextureAsync(i).then(function(e){e&&(u.metallicRoughnessTexture=e)})):(a||i)&&(x=i&&i.getInternalTexture()?i.getInternalTexture().uniqueId:0,_=a&&a.getInternalTexture()?a.getInternalTexture().uniqueId:0,v=Number("".concat(x).concat(_)),(T=this._textureMap.get(v))?u.metallicRoughnessTexture=T:l.push(t.MergeTexturesAsync("MetalRoughTexture",t.CreateRGBAConfiguration(s.ambientOcclusionTexture?t.CreateTextureInput(s.ambientOcclusionTexture,0):t.CreateConstantInput(1),a?t.CreateTextureInput(a,0):t.CreateConstantInput(1),i?t.CreateTextureInput(i,0):t.CreateConstantInput(1)),s.getScene()).then(function(e){return h(y,void 0,void 0,function(){var t;return f(this,function(n){switch(n.label){case 0:return[4,this.exportTextureAsync(e,v)];case 1:return(t=n.sent())&&(u.metallicRoughnessTexture=t),[2]}})})})))):(o&&l.push(this.exportTextureAsync(o).then(function(e){e&&(u.baseColorTexture=e)})),i&&l.push(this.exportTextureAsync(i).then(function(e){e&&(u.metallicRoughnessTexture=e)})))),l.length>0?(this._exporter._materialNeedsUVsSet.add(s),[4,Promise.all(l)]):[3,2];case 1:b.sent(),b.label=2;case 2:return[2,p]}})})},e.prototype._getTextureSampler=function(e){var n={};if(!(e&&e instanceof t.Texture))return n;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(n.wrapS=r);var o=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==o&&(n.wrapT=o),e.samplingMode){case t.Texture.LINEAR_LINEAR:n.magFilter=9729,n.minFilter=9729;break;case t.Texture.LINEAR_NEAREST:n.magFilter=9729,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR:n.magFilter=9728,n.minFilter=9729;break;case t.Texture.NEAREST_LINEAR_MIPLINEAR:n.magFilter=9728,n.minFilter=9987;break;case t.Texture.NEAREST_NEAREST:n.magFilter=9728,n.minFilter=9728;break;case t.Texture.NEAREST_LINEAR_MIPNEAREST:n.magFilter=9728,n.minFilter=9985;break;case t.Texture.LINEAR_NEAREST_MIPNEAREST:n.magFilter=9729,n.minFilter=9984;break;case t.Texture.LINEAR_NEAREST_MIPLINEAR:n.magFilter=9729,n.minFilter=9986;break;case t.Texture.NEAREST_NEAREST_MIPLINEAR:n.magFilter=9728,n.minFilter=9986;break;case t.Texture.LINEAR_LINEAR_MIPLINEAR:n.magFilter=9729,n.minFilter=9987;break;case t.Texture.LINEAR_LINEAR_MIPNEAREST:n.magFilter=9729,n.minFilter=9985;break;case t.Texture.NEAREST_NEAREST_MIPNEAREST:n.magFilter=9728,n.minFilter=9984}return n},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case t.Texture.WRAP_ADDRESSMODE:return 10497;case t.Texture.CLAMP_ADDRESSMODE:return 33071;case t.Texture.MIRROR_ADDRESSMODE:return 33648;default:return t.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l;return f(this,function(h){switch(h.label){case 0:return r={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,i=e._reflectivityTexture,a=e._useMicroSurfaceFromReflectivityMapAlpha,!i||a?[3,2]:[4,Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported")];case 1:return[2,h.sent()];case 2:return(o||i)&&n?(this._exporter._materialNeedsUVsSet.add(e),s=this._exportTextureSampler(o||i),[4,this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,i,r)]):[3,8];case 3:return u=h.sent(),c=this._exporter._textures,u.baseColorTextureData?[4,this._exportImageAsync("baseColor".concat(c.length),u.baseColorTextureData)]:[3,5];case 4:l=h.sent(),t.baseColorTexture=this._exportTextureInfo(l,s,null==o?void 0:o.coordinatesIndex),h.label=5;case 5:return u.metallicRoughnessTextureData?[4,this._exportImageAsync("metallicRoughness".concat(c.length),u.metallicRoughnessTextureData)]:[3,7];case 6:l=h.sent(),t.metallicRoughnessTexture=this._exportTextureInfo(l,s,null==i?void 0:i.coordinatesIndex),h.label=7;case 7:return[2,u];case 8:return[2,this._convertSpecularGlossinessToMetallicRoughness(r)]}})})},e.prototype.exportPBRMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return f(this,function(l){switch(l.label){case 0:return n={},r={name:e.name},(o=e.isMetallicWorkflow())&&(i=e._albedoColor,a=e.alpha,i&&(n.baseColorFactor=[i.r,i.g,i.b,a])),o?[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e._albedoColor,e._metallic,e._roughness,e._albedoTexture,e._metallicTexture,e._metallicTexture,e,n,t)]:[3,2];case 1:return u=l.sent(),[3,4];case 2:return[4,this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,n,t)];case 3:u=l.sent(),l.label=4;case 4:return s=u,[4,this._setMetallicRoughnessPbrMaterialAsync(s,e,r,n,t)];case 5:return l.sent(),[4,this._finishMaterialAsync(r,e)];case 6:return l.sent(),(c=this._exporter._materials).push(r),[2,c.length-1]}})})},e.prototype._setMetallicRoughnessPbrMaterialAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a,s,u,c,l,p=this;return f(this,function(m){switch(m.label){case 0:return b(r,n),e.baseColor.equalsWithEpsilon(g,d)&&t.Scalar.WithinEpsilon(n.alpha,1,d)||(o.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,n.alpha]),null!=e.metallic&&1!==e.metallic&&(o.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(o.roughnessFactor=e.roughness),null==n.backFaceCulling||n.backFaceCulling||(n._twoSidedLighting||t.Tools.Warn(n.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),r.doubleSided=!0),i?(a=[],(s=n instanceof t.PBRBaseMaterial?n._bumpTexture:n.geometryNormalTexture)&&a.push(this.exportTextureAsync(s).then(function(e){e&&(r.normalTexture=e,1!==s.level&&(r.normalTexture.scale=s.level))})),(u=n instanceof t.PBRBaseMaterial?n._ambientTexture:n.ambientOcclusionTexture)&&a.push(new Promise(function(e){return h(p,void 0,void 0,function(){var r,i,a,s;return f(this,function(c){switch(c.label){case 0:return n instanceof t.OpenPBRMaterial&&o.metallicRoughnessTexture?(r=this._exportTextureSampler(u),i=this._exporter._textures[o.metallicRoughnessTexture.index].source,a=this._exportTextureInfo(i,r,u.coordinatesIndex),this._textureMap.set(u.uniqueId,a),this._exporter._extensionsPostExportTextures("exporter",a,u),[2,e(a)]):[3,1];case 1:return s=e,[4,this.exportTextureAsync(u)];case 2:return[2,s.apply(void 0,[c.sent()])]}})})}).then(function(e){return h(p,void 0,void 0,function(){var o;return f(this,function(i){return e&&(o={index:e.index,texCoord:e.texCoord,extensions:e.extensions},r.occlusionTexture=o,n instanceof t.PBRBaseMaterial?o.strength=n._ambientTextureStrength:o.strength=n.ambientOcclusionTexture.level),[2]})})})),(c=n instanceof t.PBRBaseMaterial?n._emissiveTexture:n.emissionColorTexture)&&a.push(this.exportTextureAsync(c).then(function(e){e&&(r.emissiveTexture=e)})),a.length>0?(this._exporter._materialNeedsUVsSet.add(n),[4,Promise.all(a)]):[3,2]):[3,2];case 1:m.sent(),m.label=2;case 2:return(l=n instanceof t.PBRBaseMaterial?n._emissiveColor:n.emissionColor).equalsWithEpsilon(x,d)||(r.emissiveFactor=l.asArray()),r.pbrMetallicRoughness=o,[2]}})})},e.prototype.exportOpenPBRMaterialAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i,a,s;return f(this,function(u){switch(u.label){case 0:return n={},r={name:e.name},o=e.baseColor,i=e.geometryOpacity,o&&(n.baseColorFactor=[o.r,o.g,o.b,i]),[4,this._convertMetalRoughFactorsToMetallicRoughnessAsync(e.baseColor,e.baseMetalness,e.specularRoughness,e.baseColorTexture,e.baseMetalnessTexture,e.specularRoughnessTexture,e,n,t)];case 1:return a=u.sent(),[4,this._setMetallicRoughnessPbrMaterialAsync(a,e,r,n,t)];case 2:return u.sent(),[4,this._finishMaterialAsync(r,e)];case 3:return u.sent(),(s=this._exporter._materials).push(r),[2,s.length-1]}})})},e.prototype.exportTextureAsync=function(e){return h(this,arguments,void 0,function(e,t){var n,r,o;return void 0===t&&(t=null),f(this,function(i){switch(i.label){case 0:return(n=this._textureMap.get(null!=t?t:e.uniqueId))?[2,n]:(r=this._exportTextureSampler(e),[4,this._exportTextureImageAsync(e)]);case 1:return o=i.sent(),n=this._exportTextureInfo(o,r,e.coordinatesIndex),this._textureMap.set(null!=t?t:e.uniqueId,n),this._exporter._extensionsPostExportTextures("exporter",n,e),[2,n]}})})},e.prototype._exportTextureImageAsync=function(e){return h(this,void 0,void 0,function(){var n,r,o,i,a,s=this;return f(this,function(u){switch(u.label){case 0:return n=null!==(a=e.mimeType)&&void 0!==a?a:"none",r=this._internalTextureToImage,o=e.getInternalTexture().uniqueId,r[o]=r[o]||{},void 0===(i=r[o][n])&&(i=h(s,void 0,void 0,function(){var r,o,i,a,s;return f(this,function(u){switch(u.label){case 0:return[4,v(e)];case 1:return!(r=u.sent())||"none"!==n&&r.type!==n?[3,3]:[4,this._exportImageAsync(e.name,r)];case 2:case 6:return[2,u.sent()];case 3:return o="image/png","none"!==n&&(_(n)?o=n:(o="image/png",t.Tools.Warn("Unsupported media type: ".concat(n,". Exporting texture as PNG.")))),i=e.getSize(),[4,t.GetTextureDataAsync(e)];case 4:return a=u.sent(),[4,t.EncodeImageAsync(a,i.width,i.height,o)];case 5:return s=u.sent(),[4,this._exportImageAsync(e.name,s)]}})}),r[o][n]=i),[4,i];case 1:return[2,u.sent()]}})})},e.prototype._exportImageAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c;return f(this,function(l){switch(l.label){case 0:return r=this._exporter._images,this._exporter._shouldUseGlb?(o={name:e,mimeType:n.type,bufferView:void 0},[4,n.arrayBuffer()]):[3,2];case 1:return i=l.sent(),a=this._exporter._bufferManager.createBufferView(new Uint8Array(i)),this._exporter._bufferManager.setBufferView(o,a),[3,3];case 2:s=e.replace(/\.\/|\/|\.\\|\\/g,"_"),u=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif";case"image/ktx2":return".ktx2"}}(n.type),c=s+u,r.some(function(e){return e.uri===c})&&(c="".concat(s,"_").concat(t.Tools.RandomId()).concat(u)),o={name:e,uri:c},this._exporter._imageData[c]=n,l.label=3;case 3:return r.push(o),[2,r.length-1]}})})},e.prototype._exportTextureInfo=function(e,t,n){var r=this._exporter._textures,o=r.findIndex(function(n){return n.sampler==t&&n.source===e});-1===o&&(o=r.length,r.push({source:e,sampler:t}));var i={index:o};return n&&(i.texCoord=n),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),n=this._exporter._samplers,r=n.findIndex(function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT});return-1!==r?r:(n.push(t),n.length-1)},e}(),C=t.Matrix.Compose(new t.Vector3(-1,1,1),t.Quaternion.Identity(),t.Vector3.Zero());function R(e,n){if(!(e instanceof t.TransformNode))return!1;if(n){if(!e.getWorldMatrix().equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1}else if(!e.getWorldMatrix().multiplyToRef(C,t.TmpVectors.Matrix[0]).equalsWithEpsilon(t.Matrix.IdentityReadOnly,t.Epsilon))return!1;return!(e instanceof t.AbstractMesh&&e.geometry)}var E=t.Vector3.ZeroReadOnly,I=t.Quaternion.Identity(),S=t.Vector3.OneReadOnly,V=new t.Vector3(-1,1,1);function F(e,t){var n=e.byteOffset,r=e.byteStride,o=e.type,i=e.normalized,a=e.getSize(),s=t.reduce(function(e,t){return t.getTotalVertices()>e?t.getTotalVertices():e},-Number.MAX_VALUE);return{byteOffset:n,byteStride:r,componentCount:a,type:o,count:s*a,normalized:i,totalVertices:s,kind:e.getKind()}}function B(e){switch(e){case"MAT2":case"VEC4":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3}}function O(e){return e.some(function(e){return e>=256})}function N(e){switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:case t.VertexBuffer.ColorKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return!0}return!1}function P(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)}function U(e){return e.x*=-1,e}function k(e){return C.invertToRef(t.TmpVectors.Matrix[0]).multiplyToRef(e,e).multiplyToRef(C,e),e}function L(e){if(e.x*e.x+e.y*e.y>.5){var t=Math.abs(e.x),n=Math.abs(e.y);if(t>n){var r=Math.sign(e.x);e.x=t,e.y*=-r,e.z*=-r,e.w*=r}else r=Math.sign(e.y),e.x*=-r,e.y=n,e.z*=r,e.w*=-r}else{var o=Math.abs(e.z),i=Math.abs(e.w);o>i?(r=Math.sign(e.z),e.x*=-r,e.y*=r,e.z=o,e.w*=-r):(r=Math.sign(e.w),e.x*=r,e.y*=-r,e.z*=-r,e.w=i)}return e}function W(e){e.copyFromFloats(-e.z,e.w,e.x,-e.y)}function D(e,n){var r=t.Vector3.FromArrayToRef(n.translation||[0,0,0],0,t.TmpVectors.Vector3[0]),o=t.Quaternion.FromArrayToRef(n.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[0]),i=t.Matrix.ComposeToRef(S,o,r,t.TmpVectors.Matrix[0]),a=t.Vector3.FromArrayToRef(e.translation||[0,0,0],0,t.TmpVectors.Vector3[2]),s=t.Quaternion.FromArrayToRef(e.rotation||[0,0,0,1],0,t.TmpVectors.Quaternion[1]),u=t.Matrix.ComposeToRef(S,s,a,t.TmpVectors.Matrix[1]);i.multiplyToRef(u,u),u.decompose(void 0,o,r),r.equalsWithEpsilon(E,t.Epsilon)?delete n.translation:n.translation=r.asArray(),o.equalsWithEpsilon(I,t.Epsilon)?delete n.rotation:n.rotation=o.asArray(),n.scale&&delete n.scale}function z(e,n){if(!(n instanceof t.TransformNode))return!1;if(1!==n.getChildren().length||0!==e.getChildren().length||e.parent!==n)return!1;var r=e.getScene(),o=e instanceof t.TargetCamera&&!r.useRightHandedSystem?V:S;return!!n.scaling.equalsWithEpsilon(o,t.Epsilon)||(t.Logger.Warn("Cannot collapse node ".concat(e.name," into parent node ").concat(n.name," with modified scaling.")),!1)}function K(e,t){for(var n=0,r=Object.entries(e);n<r.length;n++){var o=r[n],i=o[0],a=o[1],s=t[i];(Array.isArray(a)&&Array.isArray(s)&&G(a,s)||a===s)&&delete e[i]}return e}function G(e,t){return e.length===t.length&&e.every(function(e,n){return e===t[n]})}var q=new Map([[Int8Array,function(e,t,n){return e.setInt8(t,n)}],[Uint8Array,function(e,t,n){return e.setUint8(t,n)}],[Uint8ClampedArray,function(e,t,n){return e.setUint8(t,n)}],[Int16Array,function(e,t,n){return e.setInt16(t,n,!0)}],[Uint16Array,function(e,t,n){return e.setUint16(t,n,!0)}],[Int32Array,function(e,t,n){return e.setInt32(t,n,!0)}],[Uint32Array,function(e,t,n){return e.setUint32(t,n,!0)}],[Float32Array,function(e,t,n){return e.setFloat32(t,n,!0)}],[Float64Array,function(e,t,n){return e.setFloat64(t,n,!0)}]]),H=function(){function e(e){this._data=new Uint8Array(e),this._dataView=new DataView(this._data.buffer),this._byteOffset=0}return e.prototype.writeTypedArray=function(e){this._checkGrowBuffer(e.byteLength);for(var t=q.get(e.constructor),n=0;n<e.length;n++)t(this._dataView,this._byteOffset,e[n]),this._byteOffset+=e.BYTES_PER_ELEMENT},Object.defineProperty(e.prototype,"byteOffset",{get:function(){return this._byteOffset},enumerable:!1,configurable:!0}),e.prototype.getOutputData=function(){return new Uint8Array(this._data.buffer,0,this._byteOffset)},e.prototype.writeUInt8=function(e){this._checkGrowBuffer(1),this._dataView.setUint8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt8=function(e){this._checkGrowBuffer(1),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++},e.prototype.writeInt16=function(e){this._checkGrowBuffer(2),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeUInt16=function(e){this._checkGrowBuffer(2),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2},e.prototype.writeInt32=function(e){this._checkGrowBuffer(4),this._dataView.setInt32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeUInt32=function(e){this._checkGrowBuffer(4),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat32=function(e){this._checkGrowBuffer(4),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.writeFloat64=function(e){this._checkGrowBuffer(8),this._dataView.setFloat64(this._byteOffset,e,!0),this._byteOffset+=8},e.prototype._checkGrowBuffer=function(e){var t=this.byteOffset+e;if(t>this._data.byteLength){var n=new Uint8Array(2*t);n.set(this._data),this._data=n,this._dataView=new DataView(this._data.buffer)}},e}();function j(e){return e%4==0?4:e%2==0?2:1}var X,Q=function(){function e(){this._bufferViewToData=new Map,this._bufferViewToProperties=new Map,this._accessorToBufferView=new Map}return e.prototype.generateBinary=function(e){var t=0;this._bufferViewToData.forEach(function(e){t+=e.byteLength});for(var n=new H(t),r=0,o=Array.from(this._bufferViewToData.keys()).sort(function(e,t){return j(t.byteLength)-j(e.byteLength)});r<o.length;r++){var i=o[r];i.byteOffset=n.byteOffset,e.push(i);for(var a=e.length-1,s=0,u=this.getPropertiesWithBufferView(i);s<u.length;s++)u[s].bufferView=a;n.writeTypedArray(this._bufferViewToData.get(i)),this._bufferViewToData.delete(i)}return n.getOutputData()},e.prototype.createBufferView=function(e,t){var n={buffer:0,byteOffset:void 0,byteLength:e.byteLength,byteStride:t};return this._bufferViewToData.set(n,e),n},e.prototype.createAccessor=function(e,t,n,r,o,i,a){this._verifyBufferView(e);var s={bufferView:void 0,componentType:n,count:r,type:t,min:null==i?void 0:i.min,max:null==i?void 0:i.max,normalized:a,byteOffset:o};return this.setBufferView(s,e),this._accessorToBufferView.set(s,e),s},e.prototype.setBufferView=function(e,t){this._verifyBufferView(t),this.getPropertiesWithBufferView(t).push(e)},e.prototype.removeBufferView=function(e){for(var t=this,n=0,r=this.getPropertiesWithBufferView(e);n<r.length;n++){var o=r[n];void 0!==o.bufferView&&delete o.bufferView}this._bufferViewToData.delete(e),this._bufferViewToProperties.delete(e),this._accessorToBufferView.forEach(function(n,r){n===e&&(void 0!==r.byteOffset&&delete r.byteOffset,t._accessorToBufferView.delete(r))})},e.prototype.getBufferView=function(e){var t=this._accessorToBufferView.get(e);return this._verifyBufferView(t),t},e.prototype.getPropertiesWithBufferView=function(e){var t;return this._verifyBufferView(e),this._bufferViewToProperties.set(e,null!==(t=this._bufferViewToProperties.get(e))&&void 0!==t?t:[]),this._bufferViewToProperties.get(e)},e.prototype.getData=function(e){return this._verifyBufferView(e),this._bufferViewToData.get(e)},e.prototype._verifyBufferView=function(e){if(void 0===e||!this._bufferViewToData.has(e))throw new Error("BufferView ".concat(e," not found in BufferManager."))},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(X||(X={}));var Z=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof t.TransformNode||e instanceof t.Camera||e instanceof t.Light)},e._CreateNodeAnimation=function(n,r,o,i,a){if(this._IsTransformable(n)){var s=[],u=[],c=r.getKeys(),l=e._CalculateMinMaxKeyFrames(c),h=e._DeduceInterpolation(c,o,i),f=h.interpolationType,p=h.shouldBakeAnimation;if(p?e._CreateBakedAnimation(n,r,o,l.min,l.max,r.framePerSecond,a,s,u,l,i):"LINEAR"===f||"STEP"===f?e._CreateLinearOrStepAnimation(n,r,o,s,u,i):"CUBICSPLINE"===f?e._CreateCubicSplineAnimation(n,r,o,s,u,i):e._CreateBakedAnimation(n,r,o,l.min,l.max,r.framePerSecond,a,s,u,l,i),s.length&&u.length)return{inputs:s,outputs:u,samplerInterpolation:f,inputsMin:p?l.min:t.Tools.FloatRound(l.min/r.framePerSecond),inputsMax:p?l.max:t.Tools.FloatRound(l.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var n=null,r="VEC3",o=!1,i=e.targetProperty.split(".");switch(i[0]){case"scaling":n="scale";break;case"position":n="translation";break;case"rotation":r="VEC4",n="rotation";break;case"rotationQuaternion":r="VEC4",o=!0,n="rotation";break;case"influence":r="SCALAR",n="weights";break;default:t.Tools.Error("Unsupported animatable property ".concat(i[0]))}return n?{animationChannelTargetPath:n,dataAccessorType:r,useQuaternion:o}:(t.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,n,r,o,i,a,s,u,c,l,h){var f;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!h||h(m)){var g=e._DeduceAnimationInfo(m);g&&(f={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?n:f,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,g.useQuaternion,c,l),f.samplers.length&&f.channels.length&&r.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(n,r,o,i,a,s,u,c,l,h,f){var p;if(n instanceof t.Mesh){var d=n.morphTargetManager;if(d)for(var m=0;m<d.numTargets;++m)for(var g=0,x=d.getTarget(m).animations;g<x.length;g++){var _=x[g];if(!f||f(_)){for(var v=new t.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),T=[],y=_.getKeys(),b=0;b<y.length;++b)for(var M=y[b],w=0;w<d.numTargets;++w)w==m?T.push(M):T.push({frame:M.frame,value:0});v.setKeys(T,!0);var A=e._DeduceAnimationInfo(v);A&&(p={name:v.name,samplers:[],channels:[]},e._AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:p,n,v,A.dataAccessorType,A.animationChannelTargetPath,i,s,u,c,A.useQuaternion,l,h,d.numTargets),p.samplers.length&&p.channels.length&&o.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(n,r,o,i,a,s,u,c,l){var h,f;if(n.animationGroups)for(var p=n.animationGroups,d=function(p){var d=new Map,g=new Map,x=new Set,_=p.to-p.from;f={name:p.name,channels:[],samplers:[]};for(var v=function(r){var _=p.targetedAnimations[r],v=_.target,T=_.animation;if(l&&!l(T))return"continue";var y=c.has(v);if(m._IsTransformable(v)||1===v.length&&m._IsTransformable(v[0])){if(M=e._DeduceAnimationInfo(_.animation)){var b=m._IsTransformable(v)?v:m._IsTransformable(v[0])?v[0]:null;b&&e._AddAnimation("".concat(T.name),f,b,T,M.dataAccessorType,M.animationChannelTargetPath,o,i,a,s,M.useQuaternion,u,y)}}else if(v instanceof t.MorphTarget||1===v.length&&v[0]instanceof t.MorphTarget){var M;if(M=e._DeduceAnimationInfo(_.animation)){var w=v instanceof t.MorphTarget?v:v[0];if(w){var A=n.morphTargetManagers.find(function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===w)return!0;return!1});if(A){var C=n.meshes.find(function(e){return e.morphTargetManager===A});C&&(d.has(C)||d.set(C,new Map),null===(h=d.get(C))||void 0===h||h.set(w,T),x.add(C),g.set(C,T))}}}}},T=0;T<p.targetedAnimations.length;++T)v(T);x.forEach(function(n){for(var r=n.morphTargetManager,c=null,l=[],h=g.get(n).getKeys(),m=h.length,x=0;x<m;++x)for(var v=0;v<r.numTargets;++v){var T=r.getTarget(v),y=d.get(n);if(y){var b=y.get(T);b?(c||(c=new t.Animation("".concat(p.name,"_").concat(n.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,t.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[x])):l.push({frame:p.from+_/m*x,value:T.influence,inTangent:h[0].inTangent?0:void 0,outTangent:h[0].outTangent?0:void 0})}}c.setKeys(l,!0);var M=e._DeduceAnimationInfo(c);M&&e._AddAnimation("".concat(p.name,"_").concat(n.name,"_MorphWeightAnimation"),f,n,c,M.dataAccessorType,M.animationChannelTargetPath,o,i,a,s,M.useQuaternion,u,!1,null==r?void 0:r.numTargets)}),f.channels.length&&f.samplers.length&&r.push(f)},m=this,g=0,x=p;g<x.length;g++)d(x[g])},e._AddAnimation=function(n,r,o,i,a,s,u,c,l,h,f,p,d,m){var g,x,_,v,T,y,b=e._CreateNodeAnimation(o,i,s,f,p);if(b){if(m){for(var M=0,w=void 0,A=[];b.inputs.length>0;)w=b.inputs.shift(),M%m==0&&A.push(w),M++;b.inputs=A}var C=u.get(o),R=new Float32Array(b.inputs);g=c.createBufferView(R),x=c.createAccessor(g,"SCALAR",5126,b.inputs.length,void 0,{min:[b.inputsMin],max:[b.inputsMax]}),h.push(x),_=h.length-1;var E=new t.Quaternion,I=new t.Vector3,S=new t.Vector3,V=o instanceof t.Camera,F=B(a),O=new Float32Array(b.outputs.length*F);b.outputs.forEach(function(e,n){var r=e;switch(s){case"translation":d&&(t.Vector3.FromArrayToRef(e,0,S),U(S),S.toArray(r));break;case"rotation":4===e.length?t.Quaternion.FromArrayToRef(e,0,E):(r=new Array(4),t.Vector3.FromArrayToRef(e,0,I),t.Quaternion.FromEulerVectorToRef(I,E)),d&&(L(E),V&&W(E)),E.toArray(r)}O.set(r,n*F)}),g=c.createBufferView(O),x=c.createAccessor(g,a,5126,b.outputs.length),h.push(x),v=h.length-1,T={interpolation:b.samplerInterpolation,input:_,output:v},r.samplers.push(T),y={sampler:r.samplers.length-1,target:{node:C,path:s}},r.channels.push(y)}},e._CreateBakedAnimation=function(n,r,o,i,a,s,u,c,l,h,f){var p,d,m,g,x,_,v=t.Quaternion.Identity(),T=null,y=null;h.min=t.Tools.FloatRound(i/s);for(var b=r.getKeys(),M=0,w=b.length;M<w;++M){if(m=b[M],M+1<w)if(g=b[M+1],m.value.equals&&m.value.equals(g.value)||m.value===g.value){if(0!==M)continue;_=m.frame}else _=g.frame;else{if(x=b[M-1],m.value.equals&&m.value.equals(x.value)||m.value===x.value)continue;_=a}if(_)for(var A=m.frame;A<=_;A+=u)if((d=t.Tools.FloatRound(A/s))!==T){T=d,y=d;var C={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(A,C),e._SetInterpolatedValue(n,p,d,r,o,v,c,l,f)}}y&&(h.max=y)},e._ConvertFactorToVector3OrQuaternion=function(n,r,o,i,a){var s=e._GetBasePositionRotationOrScale(r,i,a),u=o.targetProperty.split("."),c=u?u[1]:"",l=a?t.Quaternion.FromArray(s).normalize():t.Vector3.FromArray(s);switch(c){case"x":case"y":case"z":l[c]=n;break;case"w":l.w=n;break;default:t.Tools.Error('glTFAnimation: Unsupported component name "'.concat(c,'"!'))}return l},e._SetInterpolatedValue=function(e,n,r,o,i,a,s,u,c){var l;s.push(r),"weights"!==i?(o.dataType===t.Animation.ANIMATIONTYPE_FLOAT&&(n=this._ConvertFactorToVector3OrQuaternion(n,e,o,i,c)),"rotation"===i?(c?a=n:(l=n,t.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,a)),u.push(a.asArray())):(l=n,u.push(l.asArray()))):u.push([n])},e._CreateLinearOrStepAnimation=function(t,n,r,o,i,a){for(var s=0,u=n.getKeys();s<u.length;s++){var c=u[s];o.push(c.frame/n.framePerSecond),e._AddKeyframeValue(c,n,i,r,t,a)}},e._CreateCubicSplineAnimation=function(t,n,r,o,i,a){n.getKeys().forEach(function(s){o.push(s.frame/n.framePerSecond),e._AddSplineTangent(X.INTANGENT,i,r,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,n,i,r,t,a),e._AddSplineTangent(X.OUTTANGENT,i,r,"CUBICSPLINE",s,a)})},e._GetBasePositionRotationOrScale=function(e,n,r){var o;if("rotation"===n)if(r){var i=e.rotationQuaternion;o=(null!=i?i:t.Quaternion.Identity()).asArray()}else{var a=e.rotation;o=(null!=a?a:t.Vector3.Zero()).asArray()}else if("translation"===n){var s=e.position;o=(null!=s?s:t.Vector3.Zero()).asArray()}else{var u=e.scaling;o=(null!=u?u:t.Vector3.One()).asArray()}return o},e._AddKeyframeValue=function(e,n,r,o,i,a){var s,u=n.dataType;if(u===t.Animation.ANIMATIONTYPE_VECTOR3){var c=e.value.asArray();if("rotation"===o){var l=t.Vector3.FromArray(c);c=t.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}r.push(c)}else if(u===t.Animation.ANIMATIONTYPE_FLOAT){if("weights"===o)r.push([e.value]);else if(s=this._ConvertFactorToVector3OrQuaternion(e.value,i,n,o,a)){if("rotation"===o){var h=a?s:t.Quaternion.RotationYawPitchRoll(s.y,s.x,s.z).normalize();r.push(h.asArray())}r.push(s.asArray())}}else u===t.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):t.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,n){var r,o,i=!1;if("rotation"===t&&!n)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(r){if("CUBICSPLINE"!==r){r="LINEAR",i=!0;break}}else r="CUBICSPLINE";else if(r){if("CUBICSPLINE"===r||o.interpolation&&1===o.interpolation&&"STEP"!==r){r="LINEAR",i=!0;break}}else r=o.interpolation&&1===o.interpolation?"STEP":"LINEAR";return r||(r="LINEAR"),{interpolationType:r,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,n,r,o,i,a){var s,u=e===X.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===o){if("rotation"===r)if(u)if(a)s=u.asArray();else{var c=u;s=t.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).asArray()}else s=[0,0,0,0];else s="weights"===r?u?[u]:[0]:u?u.asArray():[0,0,0];n.push(s)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,n=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),n=Math.max(n,e.frame)}),{min:t,max:n}},e}();function Y(e,n,r,o,i,a){var s={attributes:{},influence:e.influence,name:e.name},u=n.geometry;if(!u)return t.Tools.Warn("Attempted to export morph target data from a mesh without geometry. This should not happen."),s;var c,l=a?-1:1,h=t.Vector3.Zero();if(e.hasPositions){var f=e.getPositions(),p=u.getVerticesData(t.VertexBuffer.PositionKind);if(p){var d=new Float32Array(p.length),m=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0];c=p.length/3;for(var x=0;x<c;++x){var _=t.Vector3.FromArray(p,3*x);t.Vector3.FromArray(f,3*x).subtractToRef(_,h),h.x*=l,m[0]=Math.min(m[0],h.x),g[0]=Math.max(g[0],h.x),m[1]=Math.min(m[1],h.y),g[1]=Math.max(g[1],h.y),m[2]=Math.min(m[2],h.z),g[2]=Math.max(g[2],h.z),d[3*x]=h.x,d[3*x+1]=h.y,d[3*x+2]=h.z}var v=r.createBufferView(d,12),T=r.createAccessor(v,"VEC3",5126,f.length/3,0,{min:m,max:g});i.push(T),s.attributes.POSITION=i.length-1}else t.Tools.Warn("Morph target positions for mesh ".concat(n.name," were not exported. Mesh does not have position vertex data"))}if(e.hasNormals){var y=e.getNormals(),b=u.getVerticesData(t.VertexBuffer.NormalKind);if(b){var M=new Float32Array(b.length);for(c=b.length/3,x=0;x<c;++x){var w=t.Vector3.FromArray(b,3*x).normalize();t.Vector3.FromArray(y,3*x).normalize().subtractToRef(w,h),M[3*x]=h.x*l,M[3*x+1]=h.y,M[3*x+2]=h.z}v=r.createBufferView(M,12),T=r.createAccessor(v,"VEC3",5126,y.length/3,0),i.push(T),s.attributes.NORMAL=i.length-1}else t.Tools.Warn("Morph target normals for mesh ".concat(n.name," were not exported. Mesh does not have normals vertex data"))}if(e.hasTangents){var A=e.getTangents(),C=u.getVerticesData(t.VertexBuffer.TangentKind);if(C){c=C.length/4;var R=new Float32Array(3*c);for(x=0;x<c;++x){var E=t.Vector3.FromArray(C,4*x);P(E);var I=t.Vector3.FromArray(A,3*x);P(I),I.subtractToRef(E,h),R[3*x]=h.x*l,R[3*x+1]=h.y,R[3*x+2]=h.z}v=r.createBufferView(R,12),T=r.createAccessor(v,"VEC3",5126,c,0),i.push(T),s.attributes.TANGENT=i.length-1}else t.Tools.Warn("Morph target tangents for mesh ".concat(n.name," were not exported. Mesh does not have tangents vertex data"))}if(e.hasColors){var S=e.getColors(),V=u.getVerticesData(t.VertexBuffer.ColorKind),F=u.getVertexBuffer(t.VertexBuffer.ColorKind);if(V&&F){var B=F.getSize();c=V.length/B;var O=new Float32Array(c*B);for(x=0;x<c;++x)if(3===B){var N=t.Vector3.FromArray(V,x*B);t.Vector3.FromArray(S,x*B).subtractToRef(N,h),O[3*x]=h.x,O[3*x+1]=h.y,O[3*x+2]=h.z}else if(4===B){var U=new t.Vector4;N=t.Vector4.FromArray(V,x*B),t.Vector4.FromArray(S,x*B).subtractToRef(N,U),O[4*x]=U.x,O[4*x+1]=U.y,O[4*x+2]=U.z,O[4*x+3]=U.w}else t.Tools.Warn("Unsupported number of components for color attribute: ".concat(B));v=r.createBufferView(O,4*B),T=r.createAccessor(v,3===B?"VEC3":"VEC4",5126,c,0),i.push(T),s.attributes.COLOR_0=i.length-1}else t.Tools.Warn("Morph target colors for mesh ".concat(n.name," were not exported. Mesh does not have colors vertex data"))}return s}var J=function(){function e(e,t){this._indicesAccessorMap=new Map,this._vertexBufferViewMap=new Map,this._vertexAccessorMap=new Map,this._remappedBufferView=new Map,this._meshMorphTargetMap=new Map,this._vertexMapColorAlpha=new Map,this._exportedNodes=new Set,this._meshMap=new Map,this.convertedToRightHandedBuffers=new Map,this.convertToRightHanded=e,this.wasAddedByNoopNode=t}return e.prototype.getIndicesAccessor=function(e,t,n,r,o){var i,a,s,u;return null===(u=null===(s=null===(a=null===(i=this._indicesAccessorMap.get(e))||void 0===i?void 0:i.get(t))||void 0===a?void 0:a.get(n))||void 0===s?void 0:s.get(r))||void 0===u?void 0:u.get(o)},e.prototype.setIndicesAccessor=function(e,t,n,r,o,i){var a=this._indicesAccessorMap.get(e);a||(a=new Map,this._indicesAccessorMap.set(e,a));var s=a.get(t);s||(s=new Map,a.set(t,s));var u=s.get(n);u||(u=new Map,s.set(n,u));var c=u.get(r);c||(c=new Map,u.set(r,c)),c.set(o,i)},e.prototype.pushExportedNode=function(e){this._exportedNodes.has(e)||this._exportedNodes.add(e)},e.prototype.getNodesSet=function(){return this._exportedNodes},e.prototype.getVertexBufferView=function(e){return this._vertexBufferViewMap.get(e)},e.prototype.setVertexBufferView=function(e,t){this._vertexBufferViewMap.set(e,t)},e.prototype.setRemappedBufferView=function(e,t,n){this._remappedBufferView.set(e,new Map),this._remappedBufferView.get(e).set(t,n)},e.prototype.getRemappedBufferView=function(e,t){var n;return null===(n=this._remappedBufferView.get(e))||void 0===n?void 0:n.get(t)},e.prototype.getVertexAccessor=function(e,t,n){var r,o;return null===(o=null===(r=this._vertexAccessorMap.get(e))||void 0===r?void 0:r.get(t))||void 0===o?void 0:o.get(n)},e.prototype.setVertexAccessor=function(e,t,n,r){var o=this._vertexAccessorMap.get(e);o||(o=new Map,this._vertexAccessorMap.set(e,o));var i=o.get(t);i||(i=new Map,o.set(t,i)),i.set(n,r)},e.prototype.hasVertexColorAlpha=function(e){return this._vertexMapColorAlpha.get(e)||!1},e.prototype.setHasVertexColorAlpha=function(e,t){return this._vertexMapColorAlpha.set(e,t)},e.prototype.getMesh=function(e){return this._meshMap.get(e)},e.prototype.setMesh=function(e,t){this._meshMap.set(e,t)},e.prototype.bindMorphDataToMesh=function(e,t){var n=this._meshMorphTargetMap.get(e)||[];this._meshMorphTargetMap.set(e,n),-1===n.indexOf(t)&&n.push(t)},e.prototype.getMorphTargetsFromMesh=function(e){return this._meshMorphTargetMap.get(e)},e}(),$=function(){function e(e,n){if(void 0===e&&(e=t.EngineStore.LastCreatedScene),this._glTF={asset:{generator:"Babylon.js v".concat(t.Engine.Version),version:"2.0"}},this._animations=[],this._accessors=[],this._bufferViews=[],this._cameras=[],this._images=[],this._materials=[],this._meshes=[],this._nodes=[],this._samplers=[],this._scenes=[],this._skins=[],this._textures=[],this._imageData={},this._shouldUseGlb=!1,this._materialExporter=new A(this),this._extensions={},this._bufferManager=new Q,this._shouldExportNodeMap=new Map,this._nodeMap=new Map,this._materialMap=new Map,this._camerasMap=new Map,this._nodesCameraMap=new Map,this._skinMap=new Map,this._nodesSkinMap=new Map,this._materialNeedsUVsSet=new Set,!e)throw new Error("No scene available to export");this._babylonScene=e,this._options=c({shouldExportNode:function(){return!0},shouldExportAnimation:function(){return!0},metadataSelector:function(e){var t;return null===(t=null==e?void 0:e.gltf)||void 0===t?void 0:t.extras},animationSampleRate:1/60,exportWithoutWaitingForScene:!1,exportUnusedUVs:!1,removeNoopRootNodes:!0,includeCoordinateSystemConversionNodes:!1,meshCompressionMethod:"None"},n),this._loadExtensions()}return e.prototype._ApplyExtension=function(e,t,n,r){var o=this;if(n>=t.length)return Promise.resolve(e);var i=r(t[n],e);return i?i.then(function(e){return h(o,void 0,void 0,function(){var o;return f(this,function(i){switch(i.label){case 0:return e?[4,this._ApplyExtension(e,t,n+1,r)]:[3,2];case 1:return o=i.sent(),[3,3];case 2:o=null,i.label=3;case 3:return[2,o]}})})}):this._ApplyExtension(e,t,n+1,r)},e.prototype._ApplyExtensions=function(t,n){for(var r=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];r.push(this._extensions[a])}return this._ApplyExtension(t,r,0,n)},e.prototype._extensionsPostExportNodeAsync=function(e,t,n,r,o){var i=this;return this._ApplyExtensions(t,function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,n,r,o,i._bufferManager)})},e.prototype._extensionsPostExportMaterialAsync=function(e,t,n){return this._ApplyExtensions(t,function(t,r){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,r,n)})},e.prototype._extensionsPostExportMaterialAdditionalTexturesAsync=function(t,n,r){return h(this,void 0,void 0,function(){var o,i=this;return f(this,function(a){switch(a.label){case 0:return o=[],[4,Promise.all(e._ExtensionNames.map(function(e){return h(i,void 0,void 0,function(){var i,a;return f(this,function(s){switch(s.label){case 0:return(i=this._extensions[e]).postExportMaterialAdditionalTexturesAsync?[4,i.postExportMaterialAdditionalTexturesAsync(t,n,r)]:[3,2];case 1:a=s.sent(),o.push.apply(o,a),s.label=2;case 2:return[2]}})})}))];case 1:return a.sent(),[2,o]}})})},e.prototype._extensionsPostExportTextures=function(t,n,r){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,n,r)}},e.prototype._extensionsPostExportMeshPrimitive=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.postExportMeshPrimitive&&i.postExportMeshPrimitive(t,this._bufferManager,this._accessors)}},e.prototype._extensionsPreGenerateBinaryAsync=function(){return h(this,void 0,void 0,function(){var t,n,r,o;return f(this,function(i){switch(i.label){case 0:t=0,n=e._ExtensionNames,i.label=1;case 1:return t<n.length?(r=n[t],(o=this._extensions[r]).preGenerateBinaryAsync?[4,o.preGenerateBinaryAsync(this._bufferManager)]:[3,3]):[3,4];case 2:i.sent(),i.label=3;case 3:return t++,[3,1];case 4:return[2]}})})},e.prototype._forEachExtensions=function(t){for(var n=0,r=e._ExtensionNames;n<r.length;n++){var o=r[n],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions(function(t){var n,r,o;t.wasUsed&&((n=e._glTF).extensionsUsed||(n.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&((r=e._glTF).extensionsRequired||(r.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),(o=e._glTF).extensions||(o.extensions={}),t.onExporting&&t.onExporting())})},e.prototype._loadExtensions=function(){for(var t=0,n=e._ExtensionNames;t<n.length;t++){var r=n[t],o=e._ExtensionFactories[r](this);this._extensions[r]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(n,r,o){void 0===o&&(o=100),e.UnregisterExtension(n)&&t.Tools.Warn("Extension with the name ".concat(n," already exists")),e._ExtensionFactories[n]=r;var i=null!=o?o:0;e._ExtensionOrders[n]=i;for(var a=e._ExtensionNames.length,s=0;s<e._ExtensionNames.length;s++){var u=e._ExtensionNames[s];if(i<e._ExtensionOrders[u]){a=s;break}}e._ExtensionNames.splice(a,0,n)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t],delete e._ExtensionOrders[t];var n=e._ExtensionNames.indexOf(t);return-1!==n&&e._ExtensionNames.splice(n,1),!0},e.prototype._generateJSON=function(e,t,n){var r={byteLength:e};return r.byteLength&&(this._glTF.buffers=[r]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(this._glTF.images=this._images),this._shouldUseGlb||(r.uri=t+".bin"),n?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype.generateGLTFAsync=function(e){return h(this,void 0,void 0,function(){var t,n,r,o,a,s,u;return f(this,function(c){switch(c.label){case 0:return[4,this._generateBinaryAsync()];case 1:if(t=c.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength,e,!0),r=new Blob([t],{type:"application/octet-stream"}),o=e+".gltf",a=e+".bin",(s=new i).files[o]=n,s.files[a]=r,this._imageData)for(u in this._imageData)s.files[u]=this._imageData[u];return[2,s]}})})},e.prototype._generateBinaryAsync=function(){return h(this,void 0,void 0,function(){return f(this,function(e){switch(e.label){case 0:return[4,this._exportSceneAsync()];case 1:return e.sent(),[4,this._extensionsPreGenerateBinaryAsync()];case 2:return e.sent(),[2,this._bufferManager.generateBinary(this._bufferViews)]}})})},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype.generateGLBAsync=function(e){return h(this,void 0,void 0,function(){var t,n,r,o,a,s,u,c,l,h,p,d,m,g;return f(this,function(f){switch(f.label){case 0:return this._shouldUseGlb=!0,[4,this._generateBinaryAsync()];case 1:if(t=f.sent(),this._extensionsOnExporting(),n=this._generateJSON(t.byteLength),r=e+".glb",o=n.length,"undefined"!=typeof TextEncoder&&(s=new TextEncoder,a=s.encode(n),o=a.length),u=this._getPadding(o),c=this._getPadding(t.byteLength),l=28+o+u+t.byteLength+c,(h=new H(l)).writeUInt32(1179937895),h.writeUInt32(2),h.writeUInt32(l),h.writeUInt32(o+u),h.writeUInt32(1313821514),a)h.writeTypedArray(a);else for(p="_".charCodeAt(0),m=0;m<o;++m)(d=n.charCodeAt(m))!=n.codePointAt(m)?h.writeUInt8(p):h.writeUInt8(d);for(m=0;m<u;++m)h.writeUInt8(32);for(h.writeUInt32(t.byteLength+c),h.writeUInt32(5130562),h.writeTypedArray(t),m=0;m<c;++m)h.writeUInt8(0);return(g=new i).files[r]=new Blob([h.getOutputData()],{type:"application/octet-stream"}),[2,g]}})})},e.prototype._setNodeTransformation=function(e,n,r){var o;if(n.getPivotPoint().equalsWithEpsilon(E,t.Epsilon)||t.Tools.Warn("Pivot points are not supported in the glTF serializer"),!n.position.equalsWithEpsilon(E,t.Epsilon)){var i=t.TmpVectors.Vector3[0].copyFrom(n.position);r&&U(i),e.translation=i.asArray()}n.scaling.equalsWithEpsilon(S,t.Epsilon)||(e.scale=n.scaling.asArray());var a=(null===(o=n.rotationQuaternion)||void 0===o?void 0:o.clone())||t.Quaternion.FromEulerAngles(n.rotation.x,n.rotation.y,n.rotation.z);a.equalsWithEpsilon(I,t.Epsilon)||(r&&L(a),e.rotation=a.normalize().asArray())},e.prototype._setCameraTransformation=function(e,n,r){var o=t.TmpVectors.Vector3[0],i=t.TmpVectors.Quaternion[0],a=n.getWorldMatrix();if(n.parent){var s=n.parent.getWorldMatrix().invertToRef(t.TmpVectors.Matrix[0]);a.multiplyToRef(s,t.TmpVectors.Matrix[1]).decompose(void 0,i,o)}else a.decompose(void 0,i,o);o.equalsWithEpsilon(E,t.Epsilon)||(r&&U(o),e.translation=o.asArray()),r&&L(i),this._babylonScene.useRightHandedSystem||W(i),i.equalsWithEpsilon(I,t.Epsilon)||(e.rotation=i.asArray())},e.prototype._listAvailableCameras=function(){for(var e=0,n=this._babylonScene.cameras;e<n.length;e++){var r=n[e],o={type:r.mode===t.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(r.name&&(o.name=r.name),"perspective"===o.type)o.perspective={aspectRatio:r.getEngine().getAspectRatio(r),yfov:r.fovMode===t.Camera.FOVMODE_VERTICAL_FIXED?r.fov:r.fov*r.getEngine().getAspectRatio(r),znear:r.minZ,zfar:r.maxZ};else if("orthographic"===o.type){var i=r.orthoLeft&&r.orthoRight?.5*(r.orthoRight-r.orthoLeft):.5*r.getEngine().getRenderWidth(),a=r.orthoBottom&&r.orthoTop?.5*(r.orthoTop-r.orthoBottom):.5*r.getEngine().getRenderHeight();o.orthographic={xmag:i,ymag:a,znear:r.minZ,zfar:r.maxZ}}this._camerasMap.set(r,o)}},e.prototype._exportAndAssignCameras=function(){for(var e=0,t=Array.from(this._camerasMap.values());e<t.length;e++){var n=t[e],r=this._nodesCameraMap.get(n);if(void 0!==r){this._cameras.push(n);for(var o=0,i=r;o<i.length;o++)i[o].camera=this._cameras.length-1}}},e.prototype._listAvailableSkeletons=function(){for(var e=0,t=this._babylonScene.skeletons;e<t.length;e++){var n=t[e];n.bones.length<=0||this._skinMap.set(n,{joints:[]})}},e.prototype._exportAndAssignSkeletons=function(e){for(var n,r=function(r){if(r.bones.length<=0)return"continue";var i=o._skinMap.get(r);if(null==i)return"continue";for(var a={},s=-1,u=0;u<r.bones.length;++u){var c=r.bones[u];-1!==(h=null!==(n=c.getIndex())&&void 0!==n?n:u)&&(a[h]=c,h>s&&(s=h))}for(var l=[],h=0;h<=s;++h){var f=(c=a[h]).getTransformNode(),p=f?o._nodeMap.get(f):void 0;if(void 0!==p){i.joints.push(p);var d=c.getAbsoluteInverseBindMatrix().clone();e.has(f)&&k(d),l.push(d)}else t.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported.")}var m=o._nodesSkinMap.get(i);if(i.joints.length>0&&void 0!==m){var g=new Float32Array(16*l.length);l.forEach(function(e,t){g.set(e.m,16*t)});var x=o._bufferManager.createBufferView(g);o._accessors.push(o._bufferManager.createAccessor(x,"MAT4",5126,l.length)),i.inverseBindMatrices=o._accessors.length-1,o._skins.push(i);for(var _=o._skins.length-1,v=0,T=m;v<T.length;v++)T[v].skin=_}},o=this,i=0,a=this._babylonScene.skeletons;i<a.length;i++)r(a[i])},e.prototype._exportSceneAsync=function(){return h(this,void 0,void 0,function(){var e,n,r,o,i,a,s,u,c,l,h,p,d,m,g,x,_,v,T,y,b,M,w,A,C,E,I,S,V,F,B,O,N;return f(this,function(f){switch(f.label){case 0:if(e={nodes:[]},this._babylonScene.metadata&&(n=this._options.metadataSelector(this._babylonScene.metadata))&&(e.extras=n),r=new Array,o=new Array,i=new Array,this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes)for(s=0,u=this._babylonScene.animationGroups;s<u.length;s++)for(c=u[s],l=0,h=c.targetedAnimations;l<h.length;l++)p=h[l],(d=p.target)instanceof t.TransformNode&&!d.parent&&(null!=a?a:a=new Set).add(d);for(m=0,g=this._babylonScene.rootNodes;m<g.length;m++)x=g[m],_=x.animations,v=!!_&&_.length>0||(null==a?void 0:a.has(x)),this._options.removeNoopRootNodes&&!this._options.includeCoordinateSystemConversionNodes&&R(x,this._babylonScene.useRightHandedSystem)&&!v?i.push.apply(i,x.getChildren()):this._babylonScene.useRightHandedSystem?r.push(x):o.push(x);return this._listAvailableCameras(),this._listAvailableSkeletons(),T=new J(!0,!1),b=(y=(B=e.nodes).push).apply,M=[B],[4,this._exportNodesAsync(o,T)];case 1:return b.apply(y,M.concat([f.sent()])),w=new J(!1,!1),C=(A=(O=e.nodes).push).apply,E=[O],[4,this._exportNodesAsync(r,w)];case 2:return C.apply(A,E.concat([f.sent()])),I=new J(!1,!0),V=(S=(N=e.nodes).push).apply,F=[N],[4,this._exportNodesAsync(i,I)];case 3:return V.apply(S,F.concat([f.sent()])),e.nodes.length&&this._scenes.push(e),this._exportAndAssignCameras(),this._exportAndAssignSkeletons(T.getNodesSet()),this._babylonScene.animationGroups.length&&Z._CreateNodeAndMorphAnimationFromAnimationGroups(this._babylonScene,this._animations,this._nodeMap,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,T.getNodesSet(),this._options.shouldExportAnimation),[2]}})})},e.prototype._shouldExportNode=function(e){var t=this._shouldExportNodeMap.get(e);return void 0===t&&(t=this._options.shouldExportNode(e),this._shouldExportNodeMap.set(e,t)),t},e.prototype._exportNodesAsync=function(e,t){return h(this,void 0,void 0,function(){var n,r,o,i;return f(this,function(a){switch(a.label){case 0:n=new Array,this._exportBuffers(e,t),r=0,o=e,a.label=1;case 1:return r<o.length?(i=o[r],[4,this._exportNodeAsync(i,n,t)]):[3,4];case 2:a.sent(),a.label=3;case 3:return r++,[3,1];case 4:return[2,n]}})})},e.prototype._collectBuffers=function(e,n,r,o,i){if(this._shouldExportNode(e)&&e instanceof t.AbstractMesh&&e.geometry){var a=e.geometry.getVertexBuffers();if(a)for(var s in a)if(N(s)){var u=a[s];i.setHasVertexColorAlpha(u,e.hasVertexAlpha);var c=u._buffer,l=n.get(c)||[];n.set(c,l),-1===l.indexOf(u)&&l.push(u);var h=r.get(u)||[];r.set(u,h),-1===h.indexOf(e)&&h.push(e)}var f=e.morphTargetManager;if(f)for(var p=0;p<f.numTargets;p++){var d=f.getTarget(p);h=o.get(d)||[],o.set(d,h),-1===h.indexOf(e)&&h.push(e)}}for(var m=0,g=e.getChildren();m<g.length;m++){var x=g[m];this._collectBuffers(x,n,r,o,i)}},e.prototype._exportBuffers=function(e,n){for(var r=new Map,o=new Map,i=new Map,a=0,s=e;a<s.length;a++){var u=s[a];this._collectBuffers(u,r,o,i,n)}for(var c=Array.from(r.keys()),l=function(e){var i=e.getData();if(!i)throw new Error("Buffer data is not available");var a=r.get(e);if(!a)return"continue";var s=a[0].byteStride;if(a.some(function(e){return e.byteStride!==s}))throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");for(var u=function(e){if(e instanceof Array){var t=new Float32Array(e);return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}(i).slice(),c=function(e){var n=o.get(e),r=F(e,n),i=r.byteOffset,a=r.byteStride,s=r.componentCount,c=r.type,l=r.count,f=r.normalized;switch(r.kind){case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,i,a,s,c,l,f,function(e){var t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t>0){var n=1/t;e[0]*=n,e[1]*=n,e[2]*=n}});break;case t.VertexBuffer.ColorKind:var p=n.filter(function(e){return e.material instanceof t.StandardMaterial||null==e.material}).length;if(0==p)break;if(p!=n.length){t.Logger.Warn("Not converting vertex color space, as buffer is shared by StandardMaterials and other material types. Results may look incorrect.");break}c==t.VertexBuffer.UNSIGNED_BYTE&&t.Logger.Warn("Converting uint8 vertex colors to linear space. Results may look incorrect.");var d=new t.Color3,m=new t.Color4,g=h._babylonScene.getEngine().useExactSrgbConversions;t.EnumerateFloatValues(u,i,a,s,c,l,f,function(e){3===e.length?(d.fromArray(e,0),d.toLinearSpaceToRef(d,g),d.toArray(e,0)):(m.fromArray(e,0),m.toLinearSpaceToRef(m,g),m.toArray(e,0))})}},l=0,f=a;l<f.length;l++)c(B=f[l]);if(n.convertToRightHanded){for(var p=0,d=a;p<d.length;p++){var m=F(B=d[p],o.get(B)),g=m.byteOffset,x=m.byteStride,_=m.componentCount,v=m.type,T=m.count,y=m.normalized;switch(R=m.kind){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:case t.VertexBuffer.TangentKind:t.EnumerateFloatValues(u,g,x,_,v,T,y,function(e){e[0]=-e[0]})}}n.convertedToRightHandedBuffers.set(e,u)}var b=h._bufferManager.createBufferView(u,s);n.setVertexBufferView(e,b);for(var M=new Map,w=0,A=a;w<A.length;w++){var C=F(B=A[w],o.get(B)),R=C.kind,E=C.totalVertices;switch(R){case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:if(B.type==t.VertexBuffer.FLOAT){var I=B.getFloatData(E);null!==I&&M.set(B,I)}}}0!==M.size&&t.Logger.Warn("Joint indices conversion needed: some joint indices are stored as floats in Babylon but GLTF requires UNSIGNED BYTES. We will perform the conversion but this might lead to unused data in the buffer.");for(var S=0,V=Array.from(M.keys());S<V.length;S++){var B=V[S],N=M.get(B);if(N){for(var P=O(N),U=new(P?Uint16Array:Uint8Array)(N.length),k=0;k<N.length;k++)U[k]=N[k];var L=h._bufferManager.createBufferView(U,4*(P?2:1));n.setRemappedBufferView(e,B,L)}}},h=this,f=0,p=c;f<p.length;f++)l(p[f]);for(var d=0,m=Array.from(i.keys());d<m.length;d++){var g=m[d],x=i.get(g);if(x)for(var _=Y(g,x[0],this._bufferManager,this._bufferViews,this._accessors,n.convertToRightHanded),v=0,T=x;v<T.length;v++){var y=T[v];n.bindMorphDataToMesh(y,_)}}},e.prototype._exportNodeAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h=this;return f(this,function(f){switch(f.label){case 0:return void 0!==(r=this._nodeMap.get(e))?(t.includes(r)||t.push(r),[2]):[4,this._createNodeAsync(e,n)];case 1:(o=f.sent())&&(r=this._nodes.length,this._nodes.push(o),this._nodeMap.set(e,r),n.pushExportedNode(e),t.push(r),i={name:"runtime animations",channels:[],samplers:[]},a=[],this._babylonScene.animationGroups.length||(Z._CreateMorphTargetAnimationFromMorphTargetAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation),e.animations.length&&Z._CreateNodeAnimationFromNodeAnimations(e,i,a,this._nodeMap,this._nodes,this._bufferManager,this._bufferViews,this._accessors,this._animationSampleRate,n.convertToRightHanded,this._options.shouldExportAnimation)),i.channels.length&&i.samplers.length&&this._animations.push(i),a.forEach(function(e){e.channels.length&&e.samplers.length&&h._animations.push(e)})),s=o?[]:t,u=0,c=e.getChildren(),f.label=2;case 2:return u<c.length?(l=c[u],[4,this._exportNodeAsync(l,s,n)]):[3,5];case 3:f.sent(),f.label=4;case 4:return u++,[3,2];case 5:return o&&s.length&&(o.children=s),[2]}})})},e.prototype._createNodeAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,p,d,m;return f(this,function(f){switch(f.label){case 0:return this._shouldExportNode(e)?(r={},e.name&&(r.name=e.name),e.metadata&&(o=this._options.metadataSelector(e.metadata))&&(r.extras=o),e instanceof t.TransformNode?(this._setNodeTransformation(r,e,n.convertToRightHanded),e instanceof t.AbstractMesh?(i=e instanceof t.InstancedMesh?e.sourceMesh:e).subMeshes&&i.subMeshes.length>0?(a=r,[4,this._exportMeshAsync(i,n)]):[3,2]:[3,3]):[3,3]):[2,null];case 1:a.mesh=f.sent(),f.label=2;case 2:e.skeleton&&void 0!==(s=this._skinMap.get(e.skeleton))&&(void 0===this._nodesSkinMap.get(s)&&this._nodesSkinMap.set(s,[]),null===(p=this._nodesSkinMap.get(s))||void 0===p||p.push(r)),f.label=3;case 3:if(e instanceof t.TargetCamera&&(u=this._camerasMap.get(e))){if(void 0===this._nodesCameraMap.get(u)&&this._nodesCameraMap.set(u,[]),this._setCameraTransformation(r,e,n.convertToRightHanded),null!==(c=e.parent)&&z(e,c)&&void 0!==(l=this._nodeMap.get(c)))return h=this._nodes[l],D(r,h),null===(d=this._nodesCameraMap.get(u))||void 0===d||d.push(h),[2,null];null===(m=this._nodesCameraMap.get(u))||void 0===m||m.push(r)}return[4,this._extensionsPostExportNodeAsync("exportNodeAsync",r,e,this._nodeMap,n.convertToRightHanded)];case 4:return f.sent()?[2,r]:(t.Logger.Warn("Not exporting node ".concat(e.name)),[2,null])}})})},e.prototype._exportIndices=function(e,n,r,o,i,a,s,u,c){var l=null;c.mode=function(e){switch(e){case t.Material.TriangleFillMode:return 4;case t.Material.TriangleStripDrawMode:return 5;case t.Material.TriangleFanDrawMode:return 6;case t.Material.PointListDrawMode:case t.Material.PointFillMode:return 0;case t.Material.LineLoopDrawMode:return 2;case t.Material.LineListDrawMode:return 1;case t.Material.LineStripDrawMode:return 3}throw new Error("Unknown fill mode: ".concat(e))}(a);var h=s!==t.Material.CounterClockWiseSideOrientation&&function(e){switch(e){case t.Material.TriangleFillMode:case t.Material.TriangleStripDrawMode:case t.Material.TriangleFanDrawMode:return!0}return!1}(a);if(h){if(a===t.Material.TriangleStripDrawMode||a===t.Material.TriangleFanDrawMode)throw new Error("Triangle strip/fan fill mode is not implemented");var f=n?new Uint32Array(o):new Uint16Array(o);if(e)for(var p=0;p+2<o;p+=3)f[p]=e[r+p]+i,f[p+1]=e[r+p+2]+i,f[p+2]=e[r+p+1]+i;else for(p=0;p+2<o;p+=3)f[p]=p,f[p+1]=p+2,f[p+2]=p+1;l=f}else if(e&&0!==i){for(f=n?new Uint32Array(o):new Uint16Array(o),p=0;p<o;p++)f[p]=e[r+p]+i;l=f}else e&&(l=function(e,t,n,r){var o=e;return 0===t&&n===e.length||(o=Array.isArray(e)?e.slice(t,t+n):e.subarray(t,t+n)),o instanceof Int32Array?new Uint32Array(o.buffer,o.byteOffset,o.length):Array.isArray(o)?r?new Uint32Array(o):new Uint16Array(o):o}(e,r,o,n));if(l){var d=u.getIndicesAccessor(e,r,o,i,h);if(void 0===d){var m=this._bufferManager.createBufferView(l),g=n?5125:5123;this._accessors.push(this._bufferManager.createAccessor(m,"SCALAR",g,o,0)),d=this._accessors.length-1,u.setIndicesAccessor(e,r,o,i,h,d)}c.indices=d}},e.prototype._exportVertexBuffer=function(e,n,r,o,i,a){var s=e.getKind();if(N(s)&&(!s.startsWith("uv")||this._options.exportUnusedUVs||n&&this._materialNeedsUVsSet.has(n))){var u=i.getVertexAccessor(e,r,o);if(void 0===u){var c=i.convertedToRightHandedBuffers.get(e._buffer)||e._buffer.getData(),l=s===t.VertexBuffer.PositionKind?function(e,n,r,o){var i=n.byteOffset,a=n.byteStride,s=n.type,u=n.normalized,c=n.getSize(),l=new Array(c).fill(1/0),h=new Array(c).fill(-1/0);return t.EnumerateFloatValues(e,i+r*a,a,c,s,o*c,u,function(e){for(var t=0;t<c;t++)l[t]=Math.min(l[t],e[t]),h[t]=Math.max(h[t],e[t])}),{min:l,max:h}}(c,e,r,o):void 0,h=(s===t.VertexBuffer.MatricesIndicesKind||s===t.VertexBuffer.MatricesIndicesExtraKind)&&e.type===t.VertexBuffer.FLOAT,f=h?t.VertexBuffer.UNSIGNED_BYTE:e.type,p=h?void 0:e.normalized,d=h?i.getRemappedBufferView(e._buffer,e):i.getVertexBufferView(e._buffer),m=e.byteOffset+r*e.byteStride;this._accessors.push(this._bufferManager.createAccessor(d,function(e,n){if(e==t.VertexBuffer.ColorKind)return n?"VEC4":"VEC3";switch(e){case t.VertexBuffer.PositionKind:case t.VertexBuffer.NormalKind:return"VEC3";case t.VertexBuffer.TangentKind:case t.VertexBuffer.MatricesIndicesKind:case t.VertexBuffer.MatricesIndicesExtraKind:case t.VertexBuffer.MatricesWeightsKind:case t.VertexBuffer.MatricesWeightsExtraKind:return"VEC4";case t.VertexBuffer.UVKind:case t.VertexBuffer.UV2Kind:case t.VertexBuffer.UV3Kind:case t.VertexBuffer.UV4Kind:case t.VertexBuffer.UV5Kind:case t.VertexBuffer.UV6Kind:return"VEC2"}throw new Error("Unknown kind ".concat(e))}(s,i.hasVertexColorAlpha(e)),f,o,m,l,p)),u=this._accessors.length-1,i.setVertexAccessor(e,r,o,u)}a.attributes[function(e){switch(e){case t.VertexBuffer.PositionKind:return"POSITION";case t.VertexBuffer.NormalKind:return"NORMAL";case t.VertexBuffer.TangentKind:return"TANGENT";case t.VertexBuffer.ColorKind:return"COLOR_0";case t.VertexBuffer.UVKind:return"TEXCOORD_0";case t.VertexBuffer.UV2Kind:return"TEXCOORD_1";case t.VertexBuffer.UV3Kind:return"TEXCOORD_2";case t.VertexBuffer.UV4Kind:return"TEXCOORD_3";case t.VertexBuffer.UV5Kind:return"TEXCOORD_4";case t.VertexBuffer.UV6Kind:return"TEXCOORD_5";case t.VertexBuffer.MatricesIndicesKind:return"JOINTS_0";case t.VertexBuffer.MatricesIndicesExtraKind:return"JOINTS_1";case t.VertexBuffer.MatricesWeightsKind:return"WEIGHTS_0";case t.VertexBuffer.MatricesWeightsExtraKind:return"WEIGHTS_1"}throw new Error("Unknown kind: ".concat(e))}(s)]=u}},e.prototype._exportMaterialAsync=function(e,n,r,o){return h(this,void 0,void 0,function(){var i,a;return f(this,function(s){switch(s.label){case 0:return void 0!==(i=this._materialMap.get(e))?[3,8]:(a=n&&Object.keys(n).some(function(e){return e.startsWith("uv")}),(e=e instanceof t.MultiMaterial?e.subMaterials[r.materialIndex]:e)instanceof t.PBRBaseMaterial?[4,this._materialExporter.exportPBRMaterialAsync(e,a)]:[3,2]);case 1:return i=s.sent(),[3,7];case 2:return e instanceof t.StandardMaterial?[4,this._materialExporter.exportStandardMaterialAsync(e,a)]:[3,4];case 3:return i=s.sent(),[3,7];case 4:return e instanceof t.OpenPBRMaterial?[4,this._materialExporter.exportOpenPBRMaterialAsync(e,a)]:[3,6];case 5:return i=s.sent(),[3,7];case 6:return t.Logger.Warn("Unsupported material '".concat(e.name,"' with type ").concat(e.getClassName())),[2];case 7:this._materialMap.set(e,i),s.label=8;case 8:return o.material=i,[2]}})})},e.prototype._exportMeshAsync=function(e,n){return h(this,void 0,void 0,function(){var r,o,i,a,s,u,c,l,h,d,m,g,x,_,v,T,y,b,M,w,A,C,R,E,I,S,V,F,B,O,N,P,U,k;return f(this,function(f){switch(f.label){case 0:if(void 0!==(r=n.getMesh(e)))return[2,r];if(o={primitives:[]},r=this._meshes.length,this._meshes.push(o),n.setMesh(e,r),i=e.isUnIndexed?null:e.getIndices(),a=null===(B=e.geometry)||void 0===B?void 0:B.getVertexBuffers(),s=n.getMorphTargetsFromMesh(e),u=e instanceof t.LinesMesh,c=e instanceof t.GreasedLineBaseMesh,l=e.subMeshes,!(a&&l&&l.length>0))return[3,7];h=0,d=l,f.label=1;case 1:return h<d.length?(m=d[h],g={attributes:{}},x=m.getMaterial()||this._babylonScene.defaultMaterial,c?(y={name:x.name},b=e,_=t.Color3.White(),v=null!==(N=null===(O=b.material)||void 0===O?void 0:O.alpha)&&void 0!==N?N:1,(!(T=null!==(U=null===(P=b.greasedLineMaterial)||void 0===P?void 0:P.color)&&void 0!==U?U:_).equalsWithEpsilon(_,t.Epsilon)||v<1)&&(y.pbrMetallicRoughness={baseColorFactor:p(p([],T.asArray(),!0),[v],!1)}),this._materials.push(y),g.material=this._materials.length-1,[3,5]):[3,2]):[3,7];case 2:return u?(y={name:x.name},(!(b=e).color.equalsWithEpsilon(t.Color3.White(),t.Epsilon)||b.alpha<1)&&(y.pbrMetallicRoughness={baseColorFactor:p(p([],b.color.asArray(),!0),[b.alpha],!1)}),this._materials.push(y),g.material=this._materials.length-1,[3,5]):[3,3];case 3:return[4,this._exportMaterialAsync(x,a,m,g)];case 4:f.sent(),f.label=5;case 5:for(M=u||c?t.Material.LineListDrawMode:null!==(k=e.overrideRenderingFillMode)&&void 0!==k?k:x.fillMode,w=x._getEffectiveOrientation(e),n.wasAddedByNoopNode&&!e.getScene().useRightHandedSystem&&(w=w===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),this._exportIndices(i,i?t.AreIndices32Bits(i,m.indexCount,m.indexStart,m.verticesStart):m.verticesCount>65535,i?m.indexStart:m.verticesStart,i?m.indexCount:m.verticesCount,-m.verticesStart,M,w,n,g),A=0,C=Object.values(a);A<C.length;A++)R=C[A],this._exportVertexBuffer(R,x,m.verticesStart,m.verticesCount,n,g);if(s)for(g.targets=[],E=0,I=s;E<I.length;E++)F=I[E],g.targets.push(F.attributes);o.primitives.push(g),this._extensionsPostExportMeshPrimitive(g),f.label=6;case 6:return h++,[3,1];case 7:if(s)for(o.weights=[],o.extras||(o.extras={}),o.extras.targetNames=[],S=0,V=s;S<V.length;S++)F=V[S],o.weights.push(F.influence),o.extras.targetNames.push(F.name);return[2,r]}})})},e._ExtensionNames=new Array,e._ExtensionFactories={},e._ExtensionOrders={},e}(),ee=function(){function e(){}return e.GLTFAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o;return f(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new $(e,n)).generateGLTFAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e.GLBAsync=function(e,t,n){return h(this,void 0,void 0,function(){var r,o;return f(this,function(i){switch(i.label){case 0:return n&&n.exportWithoutWaitingForScene?[3,2]:[4,e.whenReadyAsync()];case 1:i.sent(),i.label=2;case 2:return[4,(r=new $(e,n)).generateGLBAsync(t.replace(/\.[^/.]+$/,""))];case 3:return o=i.sent(),r.dispose(),[2,o]}})})},e}(),te={__proto__:null,GLTF2Export:ee},ne="EXT_mesh_gpu_instancing";function re(e,t){for(var n=new Float32Array(3*t),r=0;r<t;r++)n[3*r+0]=e[4*r+0],n[3*r+1]=e[4*r+1],n[3*r+2]=e[4*r+2];return n}var oe=function(){function e(e){this.name=ne,this.enabled=!0,this.required=!1,this._instanceColorWarned=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportNodeAsync=function(e,n,r,o,i,a){return h(this,void 0,void 0,function(){var e=this;return f(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var s,u;if(n&&r instanceof t.Mesh&&r.hasThinInstances&&e._exporter){e._wasUsed=!0;for(var c=t.Vector3.Zero(),l=t.Quaternion.Identity(),h=t.Vector3.One(),f=r.thinInstanceGetWorldMatrices(),p=t.TmpVectors.Vector3[2],d=t.TmpVectors.Quaternion[1],m=t.TmpVectors.Vector3[3],g=!1,x=!1,_=!1,v=new Float32Array(3*r.thinInstanceCount),T=new Float32Array(4*r.thinInstanceCount),y=new Float32Array(3*r.thinInstanceCount),b=0,M=0,w=f;M<w.length;M++)w[M].decompose(m,d,p),i&&(U(p),L(d)),v.set(p.asArray(),3*b),T.set(d.normalize().asArray(),4*b),y.set(m.asArray(),3*b),g=g||!p.equalsWithEpsilon(c),x=x||!d.equalsWithEpsilon(l),_=_||!m.equalsWithEpsilon(h),b++;var A={attributes:{}};g&&(A.attributes.TRANSLATION=e._buildAccessor(v,"VEC3",r.thinInstanceCount,a)),x&&(A.attributes.ROTATION=e._buildAccessor(T,"VEC4",r.thinInstanceCount,a)),_&&(A.attributes.SCALE=e._buildAccessor(y,"VEC3",r.thinInstanceCount,a));var C=null===(u=null===(s=r._userThinInstanceBuffersStorage)||void 0===s?void 0:s.data)||void 0===u?void 0:u.instanceColor;if(C){var R=r.thinInstanceCount;r.hasVertexAlpha&&C.length===4*R?(e._instanceColorWarned||(t.Logger.Warn("EXT_mesh_gpu_instancing: Exporting instance colors as RGB, alpha channel of instance color is not exported"),e._instanceColorWarned=!0),C=re(C,R)):C.length===4*R&&(C=re(C,R)),C.length===3*R&&(A.attributes._COLOR_0=e._buildAccessor(C,"VEC3",R,a))}n.extensions=n.extensions||{},n.extensions[ne]=A}o(n)})];case 1:return[2,o.sent()]}})})},e.prototype._buildAccessor=function(e,t,n,r){var o=r.createBufferView(e),i=r.createAccessor(o,t,5126,n);return this._exporter._accessors.push(i),this._exporter._accessors.length-1},e}();$.RegisterExtension(ne,function(e){return new oe(e)});var ie="KHR_draco_mesh_compression";function ae(e){return"POSITION"===e?"POSITION":"NORMAL"===e?"NORMAL":e.startsWith("COLOR")?"COLOR":e.startsWith("TEXCOORD")?"TEX_COORD":"GENERIC"}var se=function(){function e(e){this.name=ie,this.required=!0,this._bufferViewsUsed=new Set,this._accessorsUsed=new Set,this._encodePromises=[],this._wasUsed=!1,this.enabled="Draco"===e.options.meshCompressionMethod&&t.DracoEncoder.DefaultAvailable}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMeshPrimitive=function(e,n,r){var o=this;if(this.enabled)if(4===e.mode||5===e.mode){var i=[],a=[],s=null;if(void 0!==e.indices){var u=r[e.indices],c=n.getBufferView(u);s=n.getData(c).slice(),i.push(c),a.push(u)}for(var l=[],h=0,f=Object.entries(e.attributes);h<f.length;h++){var p=f[h],d=p[0],m=(u=r[p[1]],c=n.getBufferView(u),B(u.type)),g=t.GetTypedArrayData(n.getData(c),m,u.componentType,u.byteOffset||0,c.byteStride||t.GetTypeByteLength(u.componentType)*m,u.count,!0);l.push({kind:d,dracoName:ae(d),size:B(u.type),data:g}),i.push(c),a.push(u)}var x={method:e.targets?"MESH_SEQUENTIAL_ENCODING":"MESH_EDGEBREAKER_ENCODING"},_=t.DracoEncoder.Default._encodeAsync(l,s,x).then(function(t){var r={bufferView:-1,attributes:t.attributeIds},s=n.createBufferView(t.data);n.setBufferView(r,s);for(var u=0,c=i;u<c.length;u++){var l=c[u];o._bufferViewsUsed.add(l)}for(var h=0,f=a;h<f.length;h++){var p=f[h];o._accessorsUsed.add(p)}e.extensions||(e.extensions={}),e.extensions[ie]=r}).catch(function(e){t.Logger.Error("KHR_draco_mesh_compression: Failed to export Draco-encoded primitive. Resulting glTF may be invalid. "+e.message)});this._encodePromises.push(_),this._wasUsed=!0}else t.Logger.Warn("Cannot compress primitive with mode "+e.mode+".")},e.prototype.preGenerateBinaryAsync=function(e){return h(this,void 0,void 0,function(){var t=this;return f(this,function(n){switch(n.label){case 0:return this.enabled?[4,Promise.all(this._encodePromises)]:[2];case 1:return n.sent(),this._bufferViewsUsed.forEach(function(n){e.getPropertiesWithBufferView(n).every(function(e){return t._accessorsUsed.has(e)})&&e.removeBufferView(n)}),this._bufferViewsUsed.clear(),this._accessorsUsed.clear(),[2]}})})},e}();$.RegisterExtension(ie,function(e){return new se(e)});var ue="KHR_lights_punctual",ce={name:"",color:[1,1,1],intensity:1,range:Number.MAX_VALUE},le={innerConeAngle:0,outerConeAngle:Math.PI/4},he=t.Vector3.Backward(),fe=function(){function e(e){this.name=ue,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[ue]=this._lights},e.prototype.postExportNodeAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a=this;return f(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){if(r instanceof t.Light){var u=r.getTypeID()==t.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==t.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==t.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(!(u&&r instanceof t.ShadowLight))return t.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(ue)),void s(n);if(r.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(ue," specification!")),!r.position.equalsToFloats(0,0,0)){var c=t.TmpVectors.Vector3[0].copyFrom(r.position);i&&U(c),n.translation=c.asArray()}if("point"!==u){var l=r.direction.normalizeToRef(t.TmpVectors.Vector3[0]);i&&U(l);var h=t.Quaternion.FromUnitVectorsToRef(he,l,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(h)||(n.rotation=h.asArray())}var f={type:u,name:r.name,color:r.diffuse.asArray(),intensity:r.intensity,range:r.range};if(K(f,ce),"spot"===u){var p=r;f.spot={innerConeAngle:p.innerAngle/2,outerConeAngle:p.angle/2},K(f.spot,le)}a._lights||(a._lights={lights:[]}),a._lights.lights.push(f);var d={light:a._lights.lights.length-1},m=r.parent;if(m&&z(r,m)){var g=o.get(m);if(g){var x=a._exporter._nodes[g];return D(n,x),x.extensions||(x.extensions={}),x.extensions[ue]=d,void s(null)}}n.extensions||(n.extensions={}),n.extensions[ue]=d,s(n)}else s(n)})];case 1:return[2,s.sent()]}})})},e}();$.RegisterExtension(ue,function(e){return new fe(e)});var pe="EXT_lights_area",de={name:"",color:[1,1,1],intensity:1,size:1},me={aspect:1},ge=t.Vector3.Backward(),xe=function(){function e(e){this.name=pe,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[pe]=this._lights},e.prototype.postExportNodeAsync=function(e,n,r,o,i){return h(this,void 0,void 0,function(){var a=this;return f(this,function(s){switch(s.label){case 0:return[4,new Promise(function(s){if(r instanceof t.Light){var u=r.getTypeID()==t.Light.LIGHTTYPEID_RECT_AREALIGHT?"rect":null;if(!u)return t.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(pe)),void s(n);var c=r;if(c.falloffType!==t.Light.FALLOFF_GLTF&&t.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(pe," specification!")),!c.position.equalsToFloats(0,0,0)){var l=t.TmpVectors.Vector3[0].copyFrom(c.position);i&&U(l),n.translation=l.asArray()}var h=t.Vector3.Forward();i&&U(h);var f=t.Quaternion.FromUnitVectorsToRef(ge,h,t.TmpVectors.Quaternion[0]);t.Quaternion.IsIdentity(f)||(n.rotation=f.asArray());var p={type:u,name:c.name,color:c.diffuse.asArray(),intensity:c.intensity,size:c.height,rect:{aspect:c.width/c.height}};K(p,de),p.rect&&K(p.rect,me),a._lights||(a._lights={lights:[]}),a._lights.lights.push(p);var d={light:a._lights.lights.length-1},m=r.parent;if(m&&z(c,m)){var g=o.get(m);if(g){var x=a._exporter._nodes[g];return D(n,x),x.extensions||(x.extensions={}),x.extensions[pe]=d,void s(null)}}n.extensions||(n.extensions={}),n.extensions[pe]=d,s(n)}else s(n)})];case 1:return[2,s.sent()]}})})},e}();$.RegisterExtension(pe,function(e){return new xe(e)});var _e="KHR_materials_anisotropy";function ve(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.specularRoughnessAnisotropyTexture,o=e.geometryTangentTexture,r||o?[4,t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent()]}})})}var Te=function(){function e(e){this.name=_e,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._anisoTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o;return f(this,function(i){switch(i.label){case 0:return e=[],r instanceof t.PBRBaseMaterial?r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&e.push(r.anisotropy.texture),[2,e]):[3,5]:[3,1];case 1:return r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0?(n=function(e){var t=e.specularRoughnessAnisotropyTexture,n=e.geometryTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}(r),this._anisoTexturesMap[n]?(e.push(this._anisoTexturesMap[n]),[3,4]):[3,2]):[3,5];case 2:return[4,ve(r)];case 3:(o=i.sent())&&(e.push(o),this._anisoTexturesMap[n]=o),i.label=4;case 4:return[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c,l;if(r instanceof t.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var h=o._exporter._materialExporter.getTextureInfo(r.anisotropy.texture);null!==(v={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=h?h:void 0}).anisotropyTexture&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[_e]=v}else if(r instanceof t.OpenPBRMaterial&&r.specularRoughnessAnisotropy>0){o._wasUsed=!0,n.extensions=n.extensions||{};var f=r.specularRoughnessTexture;r._useRoughnessFromMetallicTextureGreen&&(f=r.baseMetalnessTexture);var p=o._anisoTexturesMap[r.id];if(!f&&!p){var d=r.specularRoughness,m=r.specularRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var g=(a=r.specularRoughness,l=(1-(s=r.specularRoughnessAnisotropy))*(c=(u=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(l),newAnisotropyStrength:Math.min(Math.sqrt((c-u)/Math.max(1-u,1e-4)),1)});d=g.newBaseRoughness,m=g.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=d);var x={anisotropyStrength:m,anisotropyRotation:r.geometryTangentAngle+.5*Math.PI,anisotropyTexture:void 0};return n.extensions[_e]=x,e(n)}var _=p?o._exporter._materialExporter.getTextureInfo(p):null,v={anisotropyStrength:r.specularRoughnessAnisotropy,anisotropyRotation:r.geometryTangentAngle,anisotropyTexture:_||void 0,extensions:{}};r._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(i=o._exporter._glTF).extensionsUsed||(i.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&o._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr")),o._exporter._materialNeedsUVsSet.add(r),n.extensions[_e]=v}e(n)})},e}();$.RegisterExtension(_e,function(e){return new Te(e)});var ye="KHR_materials_clearcoat";function be(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatWeightTexture,o=e.coatRoughnessTexture,r||o?[4,t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function Me(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var we=function(){function e(e){this.name=ye,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i;return f(this,function(a){switch(a.label){case 0:return e=[],r instanceof t.PBRBaseMaterial?r.clearCoat.isEnabled?(r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),[2,e]):[3,5]:[3,1];case 1:return r instanceof t.OpenPBRMaterial&&r.coatWeight>0?(n=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):n=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):n=!0),n?(o=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,3]:[4,be(r)]):[3,4]):[3,5];case 2:(i=a.sent())&&(this._cachedInternalTexturesMap[o]=i),a.label=3;case 3:this._cachedInternalTexturesMap[o]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Me(this._cachedInternalTexturesMap[o],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Me(this._cachedInternalTexturesMap[o],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]))),a.label=4;case 4:return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),[2,e];case 5:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var i,a=o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);i=r.clearCoat.useRoughnessFromMainTexture?o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):o._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&t.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&t.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var s=o._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture);null===(l={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[ye]=l}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var u=void 0,c=void 0;r.coatWeightTexture&&(u=o._mergedTexturesMap[r.coatWeightTexture.uniqueId],c=o._exporter._materialExporter.getTextureInfo(u));var l,h=void 0,f=void 0;r.coatRoughnessTexture&&(h=o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId],f=o._exporter._materialExporter.getTextureInfo(h)),r.coatColorTexture&&t.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),s=o._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),null===(l={clearcoatFactor:r.coatWeight,clearcoatTexture:null!=c?c:void 0,clearcoatRoughnessFactor:r.coatRoughness,clearcoatRoughnessTexture:null!=f?f:void 0,clearcoatNormalTexture:null!=s?s:void 0}).clearcoatTexture&&null===l.clearcoatRoughnessTexture&&null===l.clearcoatRoughnessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[ye]=l}e(n)})},e}();$.RegisterExtension(ye,function(e){return new we(e)});var Ae="KHR_materials_coat";function Ce(e){var t=e.coatRoughnessAnisotropyTexture,n=e.geometryCoatTangentTexture,r=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoStrength",o=n&&n.getInternalTexture()?n.getInternalTexture().uniqueId:"NoTangent";return"".concat(r,"_").concat(o)}function Re(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatRoughnessAnisotropyTexture,o=e.geometryCoatTangentTexture,r||o?[4,t.MergeTexturesAsync("AnisotropyTexture",t.CreateRGBAConfiguration(o?t.CreateTextureInput(o,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,1):t.CreateConstantInput(0),r?t.CreateTextureInput(r,0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent()]}})})}function Ee(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.coatWeightTexture,o=e.coatRoughnessTexture,r||o?[4,t.MergeTexturesAsync("CoatTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useCoatRoughnessFromGreenChannel?1:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function Ie(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var Se=function(){function e(e){this.name=Ae,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i,a;return f(this,function(s){switch(s.label){case 0:return e=[],r instanceof t.PBRBaseMaterial?r.clearCoat.isEnabled?(r.clearCoat.texture&&e.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&e.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&e.push(r.clearCoat.bumpTexture),r.clearCoat.tintTexture&&e.push(r.clearCoat.tintTexture),[2,e]):[3,9]:[3,1];case 1:return r instanceof t.OpenPBRMaterial&&r.coatWeight>0?(n=!1,r.coatWeightTexture?r.coatRoughnessTexture?r._useCoatRoughnessFromGreenChannel&&r.coatWeightTexture.getInternalTexture()===r.coatRoughnessTexture.getInternalTexture()?(e.push(r.coatWeightTexture),e.push(r.coatRoughnessTexture)):n=!0:e.push(r.coatWeightTexture):r.coatRoughnessTexture&&(r._useCoatRoughnessFromGreenChannel?e.push(r.coatRoughnessTexture):n=!0),n?(i=function(e){var t=e.coatWeightTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoCoat",r=e.coatRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoRoughness";return"".concat(n,"_").concat(o)}(r),this._cachedInternalTexturesMap[i]?[3,3]:[4,Ee(r)]):[3,4]):[3,9];case 2:(o=s.sent())&&(this._cachedInternalTexturesMap[i]=o),s.label=3;case 3:this._cachedInternalTexturesMap[i]&&(r.coatWeightTexture&&(this._mergedTexturesMap[r.coatWeightTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[i],r.coatWeightTexture),e.push(this._mergedTexturesMap[r.coatWeightTexture.uniqueId])),r.coatRoughnessTexture&&(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]=Ie(this._cachedInternalTexturesMap[i],r.coatRoughnessTexture),e.push(this._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]))),s.label=4;case 4:return r.geometryCoatNormalTexture&&e.push(r.geometryCoatNormalTexture),r.coatColorTexture&&e.push(r.coatColorTexture),r.coatRoughnessAnisotropy>0?(i=Ce(r),this._mergedTexturesMap[i]?(e.push(this._mergedTexturesMap[i]),[3,7]):[3,5]):[3,8];case 5:return[4,Re(r)];case 6:(a=s.sent())&&(e.push(a),this._mergedTexturesMap[i]=a),s.label=7;case 7:case 8:return[2,e];case 9:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c,l;if(r instanceof t.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var h,f=o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture);h=r.clearCoat.useRoughnessFromMainTexture?o._exporter._materialExporter.getTextureInfo(r.clearCoat.texture):o._exporter._materialExporter.getTextureInfo(r.clearCoat.textureRoughness);var p=void 0;r.clearCoat.isTintEnabled&&(p=o._exporter._materialExporter.getTextureInfo(r.clearCoat.tintTexture));var d=o._exporter._materialExporter.getTextureInfo(r.clearCoat.bumpTexture),m=r.clearCoat.indexOfRefraction;null===(v={coatFactor:r.clearCoat.intensity,coatTexture:null!=f?f:void 0,coatRoughnessFactor:r.clearCoat.roughness,coatRoughnessTexture:null!=h?h:void 0,coatNormalTexture:null!=d?d:void 0,coatColorFactor:r.clearCoat.tintColor.asArray(),coatColorTexture:null!=p?p:void 0,coatIor:1.5!==m?m:void 0}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatColorTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[Ae]=v}else if(r instanceof t.OpenPBRMaterial){if(0==r.coatWeight)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var g=void 0;f=void 0,r.coatWeightTexture&&(g=o._mergedTexturesMap[r.coatWeightTexture.uniqueId]?o._mergedTexturesMap[r.coatWeightTexture.uniqueId]:r.coatWeightTexture,f=o._exporter._materialExporter.getTextureInfo(g));var x=void 0,_=void 0;r.coatRoughnessTexture&&(x=o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]?o._mergedTexturesMap[r.coatRoughnessTexture.uniqueId]:r.coatRoughnessTexture,_=o._exporter._materialExporter.getTextureInfo(x)),d=o._exporter._materialExporter.getTextureInfo(r.geometryCoatNormalTexture),p=o._exporter._materialExporter.getTextureInfo(r.coatColorTexture),m=r.coatIor;var v,T=r.coatDarkening,y=r.coatRoughnessTexture,b=Ce(r),M=o._mergedTexturesMap[b],w=0,A=0,C=void 0;if(r.coatRoughnessAnisotropy>0){if(y||M){var R=M?o._exporter._materialExporter.getTextureInfo(M):null;w=r.coatRoughnessAnisotropy,A=r.geometryCoatTangentAngle,C=R||void 0}else{var E=r.coatRoughness,I=r.coatRoughnessAnisotropy;if(!r._useGltfStyleAnisotropy){var S=(a=r.coatRoughness,l=(1-(s=r.coatRoughnessAnisotropy))*(c=(u=a*a)*Math.sqrt(2/(1+(1-s)*(1-s)))),{newBaseRoughness:Math.sqrt(l),newAnisotropyStrength:Math.min(Math.sqrt((c-u)/Math.max(1-u,1e-4)),1)});E=S.newBaseRoughness,I=S.newAnisotropyStrength}n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=E),w=I,A=r.geometryCoatTangentAngle+.5*Math.PI,C=void 0}r._useGltfStyleAnisotropy||(n.extensions.KHR_materials_openpbr={},(i=o._exporter._glTF).extensionsUsed||(i.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr")&&o._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr"))}null===(v={coatFactor:r.coatWeight,coatTexture:null!=f?f:void 0,coatRoughnessFactor:r.coatRoughness,coatRoughnessTexture:null!=_?_:void 0,coatNormalTexture:null!=d?d:void 0,coatColorFactor:r.coatColor.asArray(),coatColorTexture:null!=p?p:void 0,coatIor:1.5!==m?m:void 0,coatDarkeningFactor:1!==T?T:void 0,coatAnisotropyRotation:A,coatAnisotropyStrength:w,coatAnisotropyTexture:C}).coatTexture&&null===v.coatRoughnessTexture&&null===v.coatRoughnessTexture&&null===v.coatAnisotropyTexture&&null===v.coatColorTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[Ae]=v}e(n)})},e}();$.RegisterExtension(Ae,function(e){return new Se(e)});var Ve="KHR_materials_diffuse_transmission";function Fe(e,n){var r=n.subSurface,o=null;return r.translucencyIntensityTexture?o=r.translucencyIntensityTexture:r.thicknessTexture&&r.useMaskFromThicknessTexture&&(o=r.thicknessTexture),o&&!r.useGltfStyleTextures?(t.Logger.Warn("".concat(e,": Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ").concat(n.name),1),null):o}var Be=function(){function e(e){this.name=Ve,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var n,o;return f(this,function(i){return n=[],r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)?((o=Fe(e,r))&&n.push(o),r.subSurface.translucencyColorTexture&&n.push(r.subSurface.translucencyColorTexture),[2,n]):[2,n]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!!t.isTranslucencyEnabled&&!e.unlit&&!t.useAlbedoToTintTranslucency&&t.useGltfStyleTextures&&1===t.volumeIndexOfRefraction&&0===t.minimumThickness&&0===t.maximumThickness},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(i){var a,s;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var u=r.subSurface,c=Fe(e,r),l=0==u.translucencyIntensity?void 0:u.translucencyIntensity,h=null!==(a=o._exporter._materialExporter.getTextureInfo(c))&&void 0!==a?a:void 0,f=!u.translucencyColor||u.translucencyColor.equalsFloats(1,1,1)?void 0:u.translucencyColor.asArray(),p=null!==(s=o._exporter._materialExporter.getTextureInfo(u.translucencyColorTexture))&&void 0!==s?s:void 0,d={diffuseTransmissionFactor:l,diffuseTransmissionTexture:h,diffuseTransmissionColorFactor:f,diffuseTransmissionColorTexture:p};(h||p)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions=n.extensions||{},n.extensions[Ve]=d}i(n)})},e}();$.RegisterExtension(Ve,function(e){return new Be(e)});var Oe="KHR_materials_dispersion",Ne=function(){function e(){this.name=Oe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i={dispersion:r.subSurface.dispersion};n.extensions=n.extensions||{},n.extensions[Oe]=i}e(n)})},e}();$.RegisterExtension(Oe,function(){return new Ne});var Pe="KHR_materials_emissive_strength",Ue=function(){function e(){this.name=Pe,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e=this;return f(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){if(!(r instanceof t.PBRMaterial))return o(n);var i=r.emissiveColor.scale(r.emissiveIntensity),a=Math.max.apply(Math,i.asArray());if(a>1){n.emissiveFactor=i.scale(1/a).asArray(),e._wasUsed=!0;var s={emissiveStrength:a};n.extensions||(n.extensions={}),n.extensions[Pe]=s}else n.emissiveFactor=i.asArray();return o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(Pe,function(){return new Ue});var ke="KHR_materials_ior",Le=function(){function e(){this.name=ke,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(e instanceof t.OpenPBRMaterial?1.5!=e.specularIor:e instanceof t.PBRMaterial&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction)},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i={ior:r.indexOfRefraction};n.extensions=n.extensions||{},n.extensions[ke]=i}else r instanceof t.OpenPBRMaterial&&o._isExtensionEnabled(r)&&(o._wasUsed=!0,i={ior:r.specularIor},n.extensions=n.extensions||{},n.extensions[ke]=i);e(n)})},e}();$.RegisterExtension(ke,function(e){return new Le});var We="KHR_materials_iridescence",De=function(){function e(e){this.name=We,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){if(e=[],r instanceof t.PBRBaseMaterial){if(r.iridescence.isEnabled)return r.iridescence.texture&&e.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&e.push(r.iridescence.thicknessTexture),[2,e]}else if(r instanceof t.OpenPBRMaterial&&r.thinFilmWeight>0)return r.thinFilmWeightTexture&&e.push(r.thinFilmWeightTexture),r.thinFilmThicknessTexture&&r.thinFilmThicknessTexture!==r.thinFilmWeightTexture&&e.push(r.thinFilmThicknessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var i=o._exporter._materialExporter.getTextureInfo(r.iridescence.texture),a=o._exporter._materialExporter.getTextureInfo(r.iridescence.thicknessTexture);null===(s={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=i?i:void 0,iridescenceThicknessTexture:null!=a?a:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[We]=s}else if(r instanceof t.OpenPBRMaterial){if(r.thinFilmWeight<=0)return void e(n);o._wasUsed=!0,n.extensions=n.extensions||{};var s,u=o._exporter._materialExporter.getTextureInfo(r.thinFilmWeightTexture),c=o._exporter._materialExporter.getTextureInfo(r.thinFilmThicknessTexture);null===(s={iridescenceFactor:r.thinFilmWeight,iridescenceIor:r.thinFilmIor,iridescenceThicknessMinimum:1e3*r.thinFilmThicknessMin,iridescenceThicknessMaximum:1e3*r.thinFilmThickness,iridescenceTexture:null!=u?u:void 0,iridescenceThicknessTexture:null!=c?c:void 0}).iridescenceTexture&&null===s.iridescenceThicknessTexture||o._exporter._materialNeedsUVsSet.add(r),n.extensions[We]=s}e(n)})},e}();$.RegisterExtension(We,function(e){return new De(e)});var ze="KHR_materials_sheen",Ke=function(){function e(e){this.name=ze,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){return f(this,function(e){return r instanceof t.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[2,[r.sheen.texture]]:[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e=this;return f(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var i,a,s,u;if(r instanceof t.PBRMaterial){if(!r.sheen.isEnabled)return void o(n);e._wasUsed=!0,null==n.extensions&&(n.extensions={});var c={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=r.sheen.roughness)&&void 0!==i?i:0};null===c.sheenColorTexture&&null===c.sheenRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),r.sheen.texture&&(c.sheenColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?c.sheenRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(c.sheenRoughnessTexture=null!==(u=e._exporter._materialExporter.getTextureInfo(r.sheen.texture))&&void 0!==u?u:void 0),n.extensions[ze]=c}o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(ze,function(e){return new Ke(e)});var Ge="KHR_materials_fuzz";function qe(e){return h(this,void 0,void 0,function(){var n,r,o;return f(this,function(i){switch(i.label){case 0:return n=e.getScene(),r=e.fuzzColorTexture,o=e.fuzzRoughnessTexture,r||o?[4,t.MergeTexturesAsync("FuzzTexture",t.CreateRGBAConfiguration(r?t.CreateTextureInput(r,0):t.CreateConstantInput(1),r?t.CreateTextureInput(r,1):t.CreateConstantInput(1),r?t.CreateTextureInput(r,2):t.CreateConstantInput(1),o?t.CreateTextureInput(o,e._useFuzzRoughnessFromTextureAlpha?3:0):t.CreateConstantInput(1)),n)]:[2,null];case 1:return[2,i.sent().getInternalTexture()]}})})}function He(e,n){var r=new t.Texture(n.name,n.getScene());return r._texture=e,r.coordinatesIndex=n.coordinatesIndex,n instanceof t.Texture&&(r.uOffset=n.uOffset,r.vOffset=n.vOffset,r.uScale=n.uScale,r.vScale=n.vScale,r.wAng=n.wAng),r.wrapU=n.wrapU,r.wrapV=n.wrapV,r}var je=function(){function e(e){this.name=Ge,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._mergedTexturesMap={},this._cachedInternalTexturesMap={},this._exporter=e}return e.prototype.dispose=function(){for(var e=0,t=Object.keys(this._mergedTexturesMap);e<t.length;e++){var n=t[e];this._mergedTexturesMap[n].dispose()}this._mergedTexturesMap={};for(var r=0,o=Object.keys(this._cachedInternalTexturesMap);r<o.length;r++)n=o[r],this._cachedInternalTexturesMap[n].dispose();this._cachedInternalTexturesMap={}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e,n,o,i;return f(this,function(a){switch(a.label){case 0:return r instanceof t.OpenPBRMaterial?(e=[],r.fuzzWeight>0?(r.fuzzWeightTexture&&e.push(r.fuzzWeightTexture),n=!1,r.fuzzRoughnessTexture&&(r._useFuzzRoughnessFromTextureAlpha?e.push(r.fuzzRoughnessTexture):n=!0),r.fuzzColorTexture&&!n&&e.push(r.fuzzColorTexture),n?(o=function(e){var t=e.fuzzColorTexture,n=t&&t.getInternalTexture()?t.getInternalTexture().uniqueId:"NoFuzzColor",r=e.fuzzRoughnessTexture,o=r&&r.getInternalTexture()?r.getInternalTexture().uniqueId:"NoFuzzRoughness";return"FuzzColor_".concat(n,"_FuzzRoughness_").concat(o)}(r),this._cachedInternalTexturesMap[o]?[3,2]:[4,qe(r)]):[3,3]):[3,3]):[3,4];case 1:(i=a.sent())&&(this._cachedInternalTexturesMap[o]=i),a.label=2;case 2:this._cachedInternalTexturesMap[o]&&(r.fuzzColorTexture&&(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId]=He(this._cachedInternalTexturesMap[o],r.fuzzColorTexture),e.push(this._mergedTexturesMap[r.fuzzColorTexture.uniqueId])),r.fuzzRoughnessTexture&&(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]=He(this._cachedInternalTexturesMap[o],r.fuzzRoughnessTexture),e.push(this._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]))),a.label=3;case 3:return[2,e];case 4:return[2,[]]}})})},e.prototype.postExportMaterialAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e=this;return f(this,function(o){switch(o.label){case 0:return[4,new Promise(function(o){var i,a,s;if(r instanceof t.OpenPBRMaterial){if(0==r.fuzzWeight)return void o(n);e._wasUsed=!0,null==n.extensions&&(n.extensions={});var u={fuzzFactor:r.fuzzWeight,fuzzColorFactor:r.fuzzColor.asArray(),fuzzRoughnessFactor:r.fuzzRoughness};r.fuzzWeightTexture&&(u.fuzzTexture=null!==(i=e._exporter._materialExporter.getTextureInfo(r.fuzzWeightTexture))&&void 0!==i?i:void 0);var c=void 0;r.fuzzColorTexture&&(c=e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]?e._mergedTexturesMap[r.fuzzColorTexture.uniqueId]:r.fuzzColorTexture,u.fuzzColorTexture=null!==(a=e._exporter._materialExporter.getTextureInfo(c))&&void 0!==a?a:void 0);var l=void 0;r.fuzzRoughnessTexture&&(l=e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]?e._mergedTexturesMap[r.fuzzRoughnessTexture.uniqueId]:r.fuzzRoughnessTexture,u.fuzzRoughnessTexture=null!==(s=e._exporter._materialExporter.getTextureInfo(l))&&void 0!==s?s:void 0),null===u.fuzzColorTexture&&null===u.fuzzRoughnessTexture||e._exporter._materialNeedsUVsSet.add(r),n.extensions[Ge]=u}o(n)})];case 1:return[2,o.sent()]}})})},e}();$.RegisterExtension(Ge,function(e){return new je(e)});var Xe="KHR_materials_specular",Qe=function(){function e(e){this.name=Xe,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){return e=[],r instanceof t.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&e.push(r.metallicReflectanceTexture),r.reflectanceTexture&&e.push(r.reflectanceTexture),[2,e]):[2,e]})})},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a,s,u,c;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0,n.extensions=n.extensions||{};var l=null!==(i=o._exporter._materialExporter.getTextureInfo(r.metallicReflectanceTexture))&&void 0!==i?i:void 0,h=null!==(a=o._exporter._materialExporter.getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,f={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:l,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:h};o._hasTexturesExtension(r)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[Xe]=f}else if(r instanceof t.OpenPBRMaterial){n.extensions=n.extensions||{};var p=null!==(s=o._exporter._materialExporter.getTextureInfo(r.specularWeightTexture))&&void 0!==s?s:void 0,d=null!==(u=o._exporter._materialExporter.getTextureInfo(r.specularColorTexture))&&void 0!==u?u:void 0,m=1==r.specularWeight?void 0:r.specularWeight,g=r.specularColor.equalsFloats(1,1,1)?void 0:r.specularColor.asArray();if(!d&&!p&&void 0===m&&void 0===g)return e(n);o._wasUsed=!0,(f={specularFactor:m,specularTexture:p,specularColorFactor:g,specularColorTexture:d,extensions:{}}).extensions.EXT_materials_specular_edge_color={specularEdgeColorEnabled:!0},(c=o._exporter._glTF).extensionsUsed||(c.extensionsUsed=[]),-1===o._exporter._glTF.extensionsUsed.indexOf("EXT_materials_specular_edge_color")&&o._exporter._glTF.extensionsUsed.push("EXT_materials_specular_edge_color"),(p||d)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[Xe]=f}e(n)})},e}();$.RegisterExtension(Xe,function(e){return new Qe(e)});var Ze="KHR_materials_transmission",Ye=function(){function e(e){this.name=Ze,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){if(e=[],r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.refractionIntensityTexture&&r.subSurface.useGltfStyleTextures&&e.push(r.subSurface.refractionIntensityTexture),[2,e]}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionWeightTexture&&(e.push(r.transmissionWeightTexture),r.transmissionColorTexture&&e.push(r.transmissionColorTexture)),r.subsurfaceWeight>0&&r.subsurfaceWeightTexture&&e.push(r.subsurfaceWeightTexture));return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e instanceof t.OpenPBRMaterial&&!e.unlit)return e.transmissionWeight>0||e.subsurfaceWeight>0;if(e instanceof t.PBRMaterial&&!e.unlit){var n=e.subSurface;return n.isRefractionEnabled&&null!=n.refractionIntensity&&0!=n.refractionIntensity||null!=n.refractionIntensityTexture&&n.useGltfStyleTextures}return!1},e.prototype.postExportMaterialAsync=function(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,c,l;return f(this,function(h){return this._isExtensionEnabled(r)?(r instanceof t.PBRMaterial?(this._wasUsed=!0,o=r.subSurface,a=0===o.refractionIntensity?void 0:o.refractionIntensity,s={transmissionFactor:a},o.refractionIntensityTexture&&(o.useGltfStyleTextures?(this._exporter._materialNeedsUVsSet.add(r),(u=this._exporter._materialExporter.getTextureInfo(o.refractionIntensityTexture))&&(s.transmissionTexture=u)):t.Logger.Warn("".concat(e,": Exporting a subsurface refraction intensity texture without `useGltfStyleTextures` is not supported"))),n.extensions||(n.extensions={}),n.extensions[Ze]=s):r instanceof t.OpenPBRMaterial&&(this._wasUsed=!0,i=(1-r.transmissionWeight)*r.subsurfaceWeight,a=i+r.transmissionWeight,s={transmissionFactor:a},r.transmissionWeightTexture?(this._exporter._materialNeedsUVsSet.add(r),(u=this._exporter._materialExporter.getTextureInfo(r.transmissionWeightTexture))&&(s.transmissionTexture=u)):r.subsurfaceWeightTexture&&(this._exporter._materialNeedsUVsSet.add(r),(c=this._exporter._materialExporter.getTextureInfo(r.subsurfaceWeightTexture))&&(s.transmissionTexture=c)),0!=r.transmissionDepth||r.transmissionColor.equals(t.Color3.White())&&!r.transmissionColorTexture||n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor||(n.pbrMetallicRoughness.baseColorFactor=[1,1,1,1]),n.pbrMetallicRoughness.baseColorFactor[0]*=r.transmissionColor.r,n.pbrMetallicRoughness.baseColorFactor[1]*=r.transmissionColor.g,n.pbrMetallicRoughness.baseColorFactor[2]*=r.transmissionColor.b,r.transmissionColorTexture&&!n.pbrMetallicRoughness.baseColorTexture&&(l=this._exporter._materialExporter.getTextureInfo(r.transmissionColorTexture))&&(n.pbrMetallicRoughness.baseColorTexture=l,this._exporter._materialNeedsUVsSet.add(r))),n.extensions||(n.extensions={}),n.extensions[Ze]=s),[2,n]):[2,n]})})},e}();$.RegisterExtension(Ze,function(e){return new Ye(e)});var Je="KHR_materials_unlit",$e=function(){function e(){this.name=Je,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i=!1;r instanceof t.PBRMaterial?i=r.unlit:r instanceof t.StandardMaterial&&(i=r.disableLighting),i&&(o._wasUsed=!0,null==n.extensions&&(n.extensions={}),n.extensions[Je]={}),e(n)})},e}();$.RegisterExtension(Je,function(){return new $e});var et="KHR_materials_volume",tt=function(){function e(e){this.name=et,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){if(e=[],r instanceof t.PBRMaterial){if(this._isExtensionEnabled(r))return r.subSurface.thicknessTexture&&e.push(r.subSurface.thicknessTexture),[2,e]}else r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0||r.subsurfaceWeight>0)&&r.geometryThicknessTexture&&e.push(r.geometryThicknessTexture);return[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var n=e.subSurface;return!(!n.isRefractionEnabled&&!n.isTranslucencyEnabled)&&(null!=n.maximumThickness&&0!=n.maximumThickness||null!=n.tintColorAtDistance&&n.tintColorAtDistance!=Number.POSITIVE_INFINITY||null!=n.tintColor&&n.tintColor!=t.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i,a;if(r instanceof t.PBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var s=r.subSurface,u={thicknessFactor:f=0==s.maximumThickness?void 0:s.maximumThickness,thicknessTexture:h=null!==(i=o._exporter._materialExporter.getTextureInfo(s.thicknessTexture))&&void 0!==i?i:void 0,attenuationDistance:s.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:s.tintColorAtDistance,attenuationColor:V=s.tintColor.equalsFloats(1,1,1)?void 0:s.tintColor.asArray()};o._hasTexturesExtension(r)&&o._exporter._materialNeedsUVsSet.add(r),n.extensions=n.extensions||{},n.extensions[et]=u}else if(r instanceof t.OpenPBRMaterial){var c=r.transmissionWeight>0&&!r.geometryThinWalled,l=r.subsurfaceWeight>0&&!r.geometryThinWalled;if(c||l){o._wasUsed=!0;var h,f=r.geometryThickness;(h=null!==(a=o._exporter._materialExporter.getTextureInfo(r.geometryThicknessTexture))&&void 0!==a?a:void 0)&&o._exporter._materialNeedsUVsSet.add(r);var p=void 0,d=t.Color3.White().asArray();if(c&&r.transmissionDepth>0){var m=1/r.transmissionDepth,g=new t.Vector3(-Math.log(r.transmissionColor.r)*m,-Math.log(r.transmissionColor.g)*m,-Math.log(r.transmissionColor.b)*m),x=new t.Vector3(r.transmissionScatter.r*m,r.transmissionScatter.g*m,r.transmissionScatter.b*m),_=g.subtract(x),v=Math.min(_.x,_.y,_.z);v<0&&(_.x=_.x-v,_.y=_.y-v,_.z=_.z-v),g=_.add(x),p=1/Math.max(g.x,g.y,g.z),d[0]=Math.exp(-g.x*p),d[1]=Math.exp(-g.y*p),d[2]=Math.exp(-g.z*p)}else p=Number.MAX_VALUE,d[0]=1,d[1]=1,d[2]=1;var T=1,y=t.Color3.White().asArray();if(l){var b=r.subsurfaceRadius,M=r.subsurfaceRadiusScale,w=new t.Vector3(M.r,M.g,M.b).multiplyByFloats(b,b,b),A=new t.Vector3(1/Math.max(w.x,1e-6),1/Math.max(w.y,1e-6),1/Math.max(w.z,1e-6));T=1/Math.max(A.x,A.y,A.z),y[0]=Math.exp(-A.x*T),y[1]=Math.exp(-A.y*T),y[2]=Math.exp(-A.z*T)}var C=(1-r.transmissionWeight)*r.subsurfaceWeight,R=C+r.transmissionWeight,E=1/Math.max(R,1e-6),I=r.transmissionWeight*E,S=C*E,V=d.map(function(e,t){return e*I+y[t]*S});u={thicknessFactor:f,thicknessTexture:h,attenuationDistance:p*I+T*S,attenuationColor:V},n.extensions=n.extensions||{},n.extensions[et]=u}}e(n)})},e}();$.RegisterExtension(et,function(e){return new tt(e)});var nt="KHR_materials_volume_scatter",rt=function(){function e(e){this.name=nt,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){return e=[],r instanceof t.OpenPBRMaterial&&(r.transmissionWeight>0&&r.transmissionScatterTexture&&e.push(r.transmissionScatterTexture),r.subsurfaceWeight>0&&r.subsurfaceColorTexture&&e.push(r.subsurfaceColorTexture)),[2,e]})})},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var n=e.transmissionWeight>0&&!e.geometryThinWalled&&e.transmissionDepth>0&&!e.transmissionScatter.equals(t.Color3.Black()),r=e.subsurfaceWeight>0&&!e.geometryThinWalled;return!(!n&&!r)},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){if(r instanceof t.OpenPBRMaterial&&o._isExtensionEnabled(r)){o._wasUsed=!0;var i=t.Vector3.Zero(),a=0;if(r.transmissionWeight>0)x=new t.Vector3(r.transmissionScatter.r,r.transmissionScatter.g,r.transmissionScatter.b),_=new t.Vector3(Math.sqrt(1-x.x),Math.sqrt(1-x.y),Math.sqrt(1-x.z)),T=(v=new t.Vector3(1,1,1)).subtract(_),y=v.subtract(new t.Vector3(.139,.139,.139).multiplyInPlace(_)),b=v.add(new t.Vector3(1.17,1.17,1.17).multiplyInPlace(_)),i=T.multiplyInPlace(y).divideInPlace(b),a=r.transmissionScatterAnisotropy;var s=t.Vector3.Zero(),u=0;r.subsurfaceWeight>0&&(s.set(r.subsurfaceColor.r,r.subsurfaceColor.g,r.subsurfaceColor.b),u=r.subsurfaceScatterAnisotropy);var c=(1-r.transmissionWeight)*r.subsurfaceWeight,l=c+r.transmissionWeight,h=1/Math.max(l,1e-6),f=r.transmissionWeight*h,p=c*h,d={multiscatterColorFactor:i.multiplyByFloats(f,f,f).addInPlace(s.multiplyByFloats(p,p,p)).asArray(),scatterAnisotropy:a*f+u*p};if(r.subsurfaceWeight>0&&r.subsurfaceColorTexture){o._exporter._materialNeedsUVsSet.add(r);var m=o._exporter._materialExporter.getTextureInfo(r.subsurfaceColorTexture);m&&(d.multiscatterColorTexture=m)}else if(r.transmissionWeight>0&&r.transmissionScatterTexture){o._exporter._materialNeedsUVsSet.add(r);var g=o._exporter._materialExporter.getTextureInfo(r.transmissionScatterTexture);g&&(d.multiscatterColorTexture=g)}n.extensions=n.extensions||{},n.extensions[nt]=d}var x,_,v,T,y,b;e(n)})},e}();$.RegisterExtension(nt,function(e){return new rt(e)},101);var ot="KHR_materials_diffuse_roughness",it=function(){function e(e){this.name=ot,this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTexturesAsync=function(e,n,r){return h(this,void 0,void 0,function(){var e;return f(this,function(n){if(e=[],r instanceof t.PBRBaseMaterial){if(r._baseDiffuseRoughness)return r._baseDiffuseRoughnessTexture&&e.push(r._baseDiffuseRoughnessTexture),[2,e]}else if(r instanceof t.OpenPBRMaterial&&r.baseDiffuseRoughness)return r.baseDiffuseRoughnessTexture&&e.push(r.baseDiffuseRoughnessTexture),[2,e];return[2,[]]})})},e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){var i=null,a=null;if(r instanceof t.PBRBaseMaterial?(i=r._baseDiffuseRoughness,a=r._baseDiffuseRoughnessTexture):r instanceof t.OpenPBRMaterial&&(i=r.baseDiffuseRoughness,a=r.baseDiffuseRoughnessTexture),i){o._wasUsed=!0,n.extensions=n.extensions||{};var s=o._exporter._materialExporter.getTextureInfo(a),u={diffuseRoughnessFactor:i,diffuseRoughnessTexture:null!=s?s:void 0};null!==u.diffuseRoughnessTexture&&o._exporter._materialNeedsUVsSet.add(r),n.extensions[ot]=u,e(n)}else e(n)})},e}();$.RegisterExtension(ot,function(e){return new it(e)});var at="KHR_materials_openpbr",st=function(){function e(){this.name=at,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,n,r){var o=this;return new Promise(function(e){r instanceof t.OpenPBRMaterial&&(o._wasUsed=!0,n.extensions=n.extensions||{},n.extensions[at]={}),e(n)})},e}();$.RegisterExtension(at,function(e){return new st});var ut="KHR_texture_transform",ct=function(){function e(){this.name=ut,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,n,r){if(r.getScene()||t.Tools.Warn("".concat(e,': "scene" is not defined for Babylon texture ').concat(r.name,"!")),0===r.uAng&&0===r.vAng||(t.Tools.Warn("".concat(e,": Texture ").concat(r.name," with rotation in the u or v axis is not supported in glTF.")),0===r.uRotationCenter&&0===r.vRotationCenter)){var o={},i=!1;if(0===r.uOffset&&0===r.vOffset||(o.offset=[r.uOffset,r.vOffset],i=!0),1===r.uScale&&1===r.vScale||(o.scale=[r.uScale,r.vScale],i=!0),0!==r.wAng){if(0!==r.uRotationCenter||0!==r.vRotationCenter){if(r.homogeneousRotationInUVTransform&&r.uScale!==r.vScale)return void t.Tools.Warn("".concat(e,": Texture ").concat(r.name," with homogenousRotationInUVTransform, non-uniform scaling, and non-zero rotation cannot be exported with ").concat(ut,"."));t.Tools.Warn("".concat(e,": Texture ").concat(r.name," with non-origin rotation center will be exported using an adjusted offset with ").concat(ut,".")),o.offset=function(e){var t=e.uOffset,n=e.vOffset,r=e.uRotationCenter,o=e.vRotationCenter,i=e.uScale,a=e.vScale,s=e.wAng,u=Math.cos(s),c=Math.sin(s),l=r*i,h=o*a;return[t+(l*(1-u)+h*c),n+(h*(1-u)-l*c)]}(r)}o.rotation=-r.wAng,i=!0}0!==r.coordinatesIndex&&(o.texCoord=r.coordinatesIndex,i=!0),i&&(this._wasUsed=!0,n.extensions||(n.extensions={}),n.extensions[ut]=o)}},e}();$.RegisterExtension(ut,function(){return new ct});var lt="KHR_texture_basisu",ht=function(){function e(e){this.name=lt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/ktx2"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[lt]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(lt,function(e){return new ht(e)});var ft="EXT_texture_webp",pt=function(){function e(e){this.name=ft,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/webp"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[ft]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(ft,function(e){return new pt(e)});var dt="EXT_texture_avif",mt=function(){function e(e){this.name=dt,this.enabled=!0,this.required=!0,this._wasUsed=!1,this._exporter=e}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportTexture=function(e,n){var r=this._exporter._textures[n.index],o=r.source;if(void 0!==o){var i=this._exporter._images[o];"image/avif"===(i.mimeType||t.GetMimeType(i.uri))&&(r.source=void 0,r.extensions||(r.extensions={}),r.extensions[dt]={source:o},this._wasUsed=!0)}},e}();$.RegisterExtension(dt,function(e){return new mt(e)});var gt={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:oe,EXT_texture_avif:mt,EXT_texture_webp:pt,KHR_draco_mesh_compression:se,KHR_lights_punctual:fe,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:we,KHR_materials_coat:Se,KHR_materials_diffuse_roughness:it,KHR_materials_diffuse_transmission:Be,KHR_materials_dispersion:Ne,KHR_materials_emissive_strength:Ue,KHR_materials_fuzz:je,KHR_materials_ior:Le,KHR_materials_iridescence:De,KHR_materials_openpbr:st,KHR_materials_sheen:Ke,KHR_materials_specular:Qe,KHR_materials_transmission:Ye,KHR_materials_unlit:$e,KHR_materials_volume:tt,KHR_materials_volume_scatter:rt,KHR_texture_basisu:ht,KHR_texture_transform:ct},xt={__proto__:null,EXT_lights_area:xe,EXT_mesh_gpu_instancing:oe,EXT_texture_avif:mt,EXT_texture_webp:pt,GLTF2Export:ee,GLTFData:i,KHR_draco_mesh_compression:se,KHR_lights_punctual:fe,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:we,KHR_materials_coat:Se,KHR_materials_diffuse_roughness:it,KHR_materials_diffuse_transmission:Be,KHR_materials_dispersion:Ne,KHR_materials_emissive_strength:Ue,KHR_materials_fuzz:je,KHR_materials_ior:Le,KHR_materials_iridescence:De,KHR_materials_openpbr:st,KHR_materials_sheen:Ke,KHR_materials_specular:Qe,KHR_materials_transmission:Ye,KHR_materials_unlit:$e,KHR_materials_volume:tt,KHR_materials_volume_scatter:rt,KHR_texture_basisu:ht,KHR_texture_transform:ct,_ConvertToGLTFPBRMetallicRoughness:y,_SolveMetallic:T},_t=function(){function e(){}return e.CreateSTL=function(e,n,r,o,i,a,s,u){void 0===n&&(n=!0),void 0===r&&(r="stlmesh"),void 0===o&&(o=!1),void 0===i&&(i=!0),void 0===a&&(a=!1),void 0===s&&(s=!1),void 0===u&&(u=!1);var c=function(e,n,r){var o=[3*e[r],3*e[r+1],3*e[r+2]],i=[new t.Vector3(n[o[0]],n[o[0]+2],n[o[0]+1]),new t.Vector3(n[o[1]],n[o[1]+2],n[o[1]+1]),new t.Vector3(n[o[2]],n[o[2]+2],n[o[2]+1])],a=i[0].subtract(i[1]),s=i[2].subtract(i[1]);return{v:i,n:t.Vector3.Cross(s,a).normalize()}},l=function(e,t,n,r){return t=h(e,t,n.x,r),t=h(e,t,n.y,r),h(e,t,n.z,r)},h=function(e,t,n,r){return e.setFloat32(t,n,r),t+4},f=function(e){if(s){var n=e;e instanceof t.InstancedMesh&&(n=e.sourceMesh);var r=n.getVerticesData(t.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var o=t.Vector3.Zero(),i=void 0;for(i=0;i<r.length;i+=3)t.Vector3.TransformCoordinatesFromFloatsToRef(r[i],r[i+1],r[i+2],e.computeWorldMatrix(!0),o).toArray(r,i);return r}return e.getVerticesData(t.VertexBuffer.PositionKind)||[]};s&&(a=!0);var p="",d=0,m=0;if(o){for(var g=0;g<e.length;g++)d+=(T=(_=e[g]).getIndices())?T.length/3:0;var x=new ArrayBuffer(84+50*d);m+=80,(p=new DataView(x)).setUint32(m,d,i),m+=4}else u||(p="solid stlmesh\r\n");for(g=0;g<e.length;g++){var _=e[g];!o&&u&&(p+="solid "+_.name+"\r\n"),!a&&_ instanceof t.Mesh&&_.bakeCurrentTransformIntoVertices();for(var v=f(_),T=_.getIndices()||[],y=0;y<T.length;y+=3){var b=c(T,v,y);o?(m=l(p,m,b.n,i),m=l(p,m,b.v[0],i),m=l(p,m,b.v[1],i),m=l(p,m,b.v[2],i),m+=2):(p+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",p+="\t\touter loop\r\n",p+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",p+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",p+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",p+="\t\tendloop\r\n",p+="\tendfacet\r\n")}!o&&u&&(p+="endsolid "+name+"\r\n")}if(o||u||(p+="endsolid stlmesh"),n){var M=document.createElement("a"),w=new Blob([p],{type:"application/octet-stream"});M.href=window.URL.createObjectURL(w),M.download=r+".stl",M.click()}return p},e}(),vt={__proto__:null,STLExport:_t};function Tt(e,t,n,r){void 0===n&&(n=3),void 0===r&&(r=!1);for(var o=[],i=0;i<e.length/n;i++){var a=e[i*n]*(r?-1:1),s=e[i*n+1],u=e[i*n+2];o.push("(".concat(a.toPrecision(t.precision),", ").concat(s.toPrecision(t.precision),", ").concat(u.toPrecision(t.precision),")"))}return o.join(", ")}function yt(e,t){for(var n=[],r=0;r<e.length/2;r++){var o=e[2*r],i=e[2*r+1];n.push("(".concat(o.toPrecision(t.precision),", ").concat((1-i).toPrecision(t.precision),")"))}return n.join(", ")}function bt(e,n,r,o){var i=function(e,n,r,o){var i=e.getVerticesData(t.VertexBuffer.PositionKind),a=e.getVerticesData(t.VertexBuffer.NormalKind);if(i&&a)return'\n\tdef Mesh "'.concat("Geometry",'"\n\t{\n uniform token orientation = "').concat(r,'"\n\t\tint[] faceVertexCounts = [').concat(function(e){var t,n=(null===(t=e.getIndices())||void 0===t?void 0:t.length)?e.getTotalIndices():e.getTotalVertices();return Array(n/3).fill(3).join(", ")}(e),"]\n\t\tint[] faceVertexIndices = [").concat(function(e){var t,n=e.getIndices(),r=null!==(t=null==n?void 0:n.length)&&void 0!==t?t:e.getTotalVertices(),o=[];if(null!==n)for(var i=0;i<r;i++)o.push(n[i]);else for(i=0;i<r;i++)o.push(i);return o.join(", ")}(e),"]\n\t\tnormal3f[] normals = [").concat(Tt(a,n,void 0,o),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)\n\t\tpoint3f[] points = [').concat(Tt(i,n,void 0,o),"]\n ").concat(function(e,n){for(var r="",o=0;o<4;o++){var i=o>0?o:"",a=e.getVerticesData(t.VertexBuffer.UVKind+(i?i+1:""));a&&(r+="\n\t\ttexCoord2f[] primvars:st".concat(i," = [").concat(yt(a,n),'] (\n\t\t\tinterpolation = "vertex"\n\t\t)'))}var s=e.getVerticesData(t.VertexBuffer.ColorKind);return s&&(r+="\n\tcolor3f[] primvars:displayColor = [".concat(Tt(s,n,s.length/e.getTotalVertices()),'] (\n\t\tinterpolation = "vertex"\n\t\t)')),r}(e,n),'\n\t\tuniform token subdivisionScheme = "none"\n\t}\n')}(e,n,r,o);return'\n def "Geometry"\n {\n '.concat(i,"\n }\n ")}function Mt(e){var t='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )';return t+=e,fflate.strToU8(t)}function wt(e){var t=e.m;return"( ".concat(At(t,0),", ").concat(At(t,4),", ").concat(At(t,8),", ").concat(At(t,12)," )")}function At(e,t){return"(".concat(e[t+0],", ").concat(e[t+1],", ").concat(e[t+2],", ").concat(e[t+3],")")}function Ct(e,t){var n="Object_"+e.uniqueId,r=wt(t);return'def Xform "'.concat(n,'" (\n\tprepend references = @./geometries/Geometry_').concat(e.geometry.uniqueId,'.usda@</Geometry>\n\tprepend apiSchemas = ["MaterialBindingAPI"]\n)\n{\n\tmatrix4d xformOp:transform = ').concat(r,'\n\tuniform token[] xformOpOrder = ["xformOp:transform"]\t\n\n rel material:binding = </Root/Materials/Material_').concat(e.material.uniqueId,">\n}\n\n")}function Rt(e){switch(e){case t.Constants.TEXTURE_CLAMP_ADDRESSMODE:return"clamp";case t.Constants.TEXTURE_MIRROR_ADDRESSMODE:return"mirror";case t.Constants.TEXTURE_WRAP_ADDRESSMODE:default:return"repeat"}}function Et(e){return"(".concat(e.x,", ").concat(e.y,")")}function It(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,")")}function St(e,n,r,o,i,a){var s,u,c=e.getInternalTexture().uniqueId+"_"+e.invertY,l="image/jpeg"===(e.mimeType||t.GetMimeType(null!==(u=null===(s=e.getInternalTexture())||void 0===s?void 0:s.url)&&void 0!==u?u:""))?"jpg":"png";i[c]={texture:e,ext:l};var h=e.coordinatesIndex>0?"st"+e.coordinatesIndex:"st",f=new t.Vector2(e.uScale,e.vScale),p=new t.Vector2(e.uOffset,e.vOffset),d=e.wAng,m=Math.sin(d),g=Math.cos(d);return p.y=1-p.y-f.y,p.x+=m*f.x,p.y+=(1-g)*f.y,'\n def Shader "PrimvarReader_'.concat(r,'"\n {\n uniform token info:id = "UsdPrimvarReader_float2"\n float2 inputs:fallback = (0.0, 0.0)\n token inputs:varname = "').concat(h,'"\n float2 outputs:result\n }\n\n def Shader "Transform2d_').concat(r,'"\n {\n uniform token info:id = "UsdTransform2d"\n token inputs:in.connect = </Root/Materials/Material_').concat(n.uniqueId,"/PrimvarReader_").concat(r,".outputs:result>\n float inputs:rotation = ").concat((d*(180/Math.PI)).toFixed(a.precision),"\n float2 inputs:scale = ").concat(Et(f),"\n float2 inputs:translation = ").concat(Et(p),'\n float2 outputs:result\n }\n\n def Shader "Texture_').concat(e.uniqueId,"_").concat(r,'"\n {\n uniform token info:id = "UsdUVTexture"\n asset inputs:file = @textures/Texture_').concat(c,".").concat(l,"@\n float2 inputs:st.connect = </Root/Materials/Material_").concat(n.uniqueId,"/Transform2d_").concat(r,".outputs:result>\n ").concat(o?"float4 inputs:scale = "+function(e){return"(".concat(e.r,", ").concat(e.g,", ").concat(e.b,", 1.0)")}(o):"",'\n token inputs:sourceColorSpace = "').concat(e.gammaSpace?"sRGB":"raw",'"\n token inputs:wrapS = "').concat(Rt(e.wrapU),'"\n token inputs:wrapT = "').concat(Rt(e.wrapV),'"\n float outputs:r\n float outputs:g\n float outputs:b\n float3 outputs:rgb\n ').concat(n.needAlphaBlending()||n.needAlphaTesting()?"float outputs:a":"","\n }")}function Vt(e,n,r){var o="\t\t\t",i=[],a=[],s=function(e){var n,r,o={diffuseMap:null,diffuse:null,alphaCutOff:0,emissiveMap:null,emissive:null,normalMap:null,roughnessMap:null,roughnessChannel:"a",roughness:0,metalnessMap:null,metalnessChannel:"r",metalness:0,aoMap:null,aoMapChannel:"rgb",aoMapIntensity:0,alphaMap:null,ior:1,clearCoatEnabled:!1,clearCoat:0,clearCoatMap:null,clearCoatRoughness:0,clearCoatRoughnessMap:null};return e instanceof t.StandardMaterial?c(c({},o),{diffuseMap:e.diffuseTexture,diffuse:e.diffuseColor,alphaCutOff:e.alphaCutOff,emissiveMap:e.emissiveTexture,emissive:e.emissiveColor,roughness:1,alphaMap:e.opacityTexture}):e instanceof t.PBRBaseMaterial?c(c({},o),{diffuseMap:e._albedoTexture,diffuse:e._albedoColor,alphaCutOff:e._alphaCutOff,emissiveMap:e._emissiveTexture,emissive:e._emissiveColor,normalMap:e._bumpTexture,roughnessMap:e._metallicTexture,roughnessChannel:e._useRoughnessFromMetallicTextureAlpha?"a":"g",roughness:null!==(n=e._roughness)&&void 0!==n?n:1,metalnessMap:e._metallicTexture,metalnessChannel:e._useMetallnessFromMetallicTextureBlue?"b":"r",metalness:null!==(r=e._metallic)&&void 0!==r?r:0,aoMap:e._ambientTexture,aoMapChannel:e._useAmbientInGrayScale?"r":"rgb",aoMapIntensity:e._ambientTextureStrength,alphaMap:e._opacityTexture,ior:e.subSurface.indexOfRefraction,clearCoatEnabled:e.clearCoat.isEnabled,clearCoat:e.clearCoat.intensity,clearCoatMap:e.clearCoat.texture,clearCoatRoughness:e.clearCoat.roughness,clearCoatRoughnessMap:e.clearCoat.useRoughnessFromMainTexture?e.clearCoat.texture:e.clearCoat.textureRoughness}):o}(e),u=s.diffuseMap,l=s.diffuse,h=s.alphaCutOff,f=s.emissiveMap,p=s.emissive,d=s.normalMap,m=s.roughnessMap,g=s.roughnessChannel,x=s.roughness,_=s.metalnessMap,v=s.metalnessChannel,T=s.metalness,y=s.aoMap,b=s.aoMapChannel,M=s.aoMapIntensity,w=s.alphaMap,A=s.ior,C=s.clearCoatEnabled,R=s.clearCoat,E=s.clearCoatMap,I=s.clearCoatRoughness,S=s.clearCoatRoughnessMap;return null!==u?(i.push("".concat(o,"color3f inputs:diffuseColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:rgb>")),e.needAlphaBlending()?i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:a>")):e.needAlphaTesting()&&(i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(u.uniqueId,"_diffuse.outputs:a>")),i.push("".concat(o,"float inputs:opacityThreshold = ").concat(h))),a.push(St(u,e,"diffuse",l,n,r))):i.push("".concat(o,"color3f inputs:diffuseColor = ").concat(It(l||t.Color3.White()))),null!==f?(i.push("".concat(o,"color3f inputs:emissiveColor.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(f.uniqueId,"_emissive.outputs:rgb>")),a.push(St(f,e,"emissive",p,n,r))):p&&p.toLuminance()>0&&i.push("".concat(o,"color3f inputs:emissiveColor = ").concat(It(p))),null!==d&&(i.push("".concat(o,"normal3f inputs:normal.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(d.uniqueId,"_normal.outputs:rgb>")),a.push(St(d,e,"normal",null,n,r))),null!==y&&(i.push("".concat(o,"float inputs:occlusion.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(y.uniqueId,"_occlusion.outputs:").concat(b,">")),a.push(St(y,e,"occlusion",new t.Color3(M,M,M),n,r))),null!==m?(i.push("".concat(o,"float inputs:roughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(m.uniqueId,"_roughness.outputs:").concat(g,">")),a.push(St(m,e,"roughness",new t.Color3(x,x,x),n,r))):i.push("".concat(o,"float inputs:roughness = ").concat(x)),null!==_?(i.push("".concat(o,"float inputs:metallic.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(_.uniqueId,"_metallic.outputs:").concat(v,">")),a.push(St(_,e,"metallic",new t.Color3(T,T,T),n,r))):i.push("".concat(o,"float inputs:metallic = ").concat(T)),null!==w?(i.push("".concat(o,"float inputs:opacity.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(w.uniqueId,"_opacity.outputs:r>")),i.push("".concat(o,"float inputs:opacityThreshold = 0.0001")),a.push(St(w,e,"opacity",null,n,r))):i.push("".concat(o,"float inputs:opacity = ").concat(e.alpha)),C&&(null!==E?(i.push("".concat(o,"float inputs:clearcoat.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(E.uniqueId,"_clearcoat.outputs:r>")),a.push(St(E,e,"clearcoat",new t.Color3(R,R,R),n,r))):i.push("".concat(o,"float inputs:clearcoat = ").concat(R)),null!==S?(i.push("".concat(o,"float inputs:clearcoatRoughness.connect = </Root/Materials/Material_").concat(e.uniqueId,"/Texture_").concat(S.uniqueId,"_clearcoatRoughness.outputs:g>")),a.push(St(S,e,"clearcoatRoughness",new t.Color3(I,I,I),n,r))):i.push("".concat(o,"float inputs:clearcoatRoughness = ").concat(I))),i.push("".concat(o,"float inputs:ior = ").concat(A)),'\n\tdef Material "Material_'.concat(e.uniqueId,'"\n\t{\n\t\tdef Shader "PreviewSurface"\n\t\t{\n\t\t\tuniform token info:id = "UsdPreviewSurface"\n').concat(i.join("\n"),"\n\t\t\tint inputs:useSpecularWorkflow = 0\n\t\t\ttoken outputs:surface\n\t\t}\n\n\t\ttoken outputs:surface.connect = </Root/Materials/Material_").concat(e.uniqueId,"/PreviewSurface.outputs:surface>\n\n").concat(a.join("\n"),"\n\n\t}\n")}function Ft(e){var n,r;e.computeWorldMatrix(!0);for(var o=e.getWorldMatrix().clone(),i=e.getScene().useRightHandedSystem,a=null!==(r=null===(n=e.material)||void 0===n?void 0:n._getEffectiveOrientation(e))&&void 0!==r?r:e.sideOrientation,s=!i,u=e.parent;u;){if(R(u,i)&&null===u.parent){i||(o.multiplyToRef(u.getWorldMatrix().invert(),o),a=a===t.Material.ClockWiseSideOrientation?t.Material.CounterClockWiseSideOrientation:t.Material.ClockWiseSideOrientation),s=!1;break}u=u.parent}return o.determinant()<0&&t.Tools.Warn("Mesh ".concat(e.name," has a negative scale, which may look incorrect in destinations like QuickLook.")),{matrix:o,windingOrder:a===t.Material.ClockWiseSideOrientation?"leftHanded":"rightHanded",convertToRightHanded:s}}function Bt(e){return h(this,void 0,void 0,function(){var n,r,o,i,a;return f(this,function(s){switch(s.label){case 0:if(!(n=e.getInternalTexture())||1!==n.source)return[2,null];r=n._buffer,i=e.mimeType,s.label=1;case 1:return s.trys.push([1,12,,13]),r?[3,3]:[4,t.Tools.LoadFileAsync(n.url)];case 2:return o=s.sent(),i=t.GetMimeType(n.url)||i,[3,11];case 3:return ArrayBuffer.isView(r)?(o=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),[3,11]):[3,4];case 4:return r instanceof ArrayBuffer?(o=r,[3,11]):[3,5];case 5:return r instanceof Blob?[4,r.arrayBuffer()]:[3,7];case 6:return o=s.sent(),i=r.type||i,[3,11];case 7:return"string"!=typeof r?[3,9]:[4,t.Tools.LoadFileAsync(r)];case 8:return o=s.sent(),i=t.GetMimeType(r)||i,[3,11];case 9:return"undefined"!=typeof HTMLImageElement&&r instanceof HTMLImageElement?[4,t.Tools.LoadFileAsync(r.src)]:[3,11];case 10:o=s.sent(),i=t.GetMimeType(r.src)||i,s.label=11;case 11:return[3,13];case 12:return s.sent(),[2,null];case 13:return o&&!i&&n.url&&(a=n.url.match(/^data:([^;,]+)/),i=a?a[1]:t.GetMimeType(n.url)),o&&i?[2,{data:o,mimeType:i}]:[2,null]}})})}function Ot(e,n,r){return h(this,void 0,void 0,function(){var o,i,a,s,u,l,h,p,d,m,g,x,_,v,T,y,b,M,w,A,C,R,E,I,S,V,F,B,O,N,P,U,k,L,W;return f(this,function(f){switch(f.label){case 0:return o=c({fflateUrl:"https://unpkg.com/fflate@0.8.2",includeAnchoringProperties:!0,anchoringType:"plane",planeAnchoringAlignment:"horizontal",modelFileName:"model.usda",precision:5,exportCamera:!1,cameraSensorWidth:35},n),"undefined"!=typeof fflate?[3,2]:[4,t.Tools.LoadScriptAsync(o.fflateUrl)];case 1:f.sent(),f.label=2;case 2:for((i={})[o.modelFileName]=null,a='#usda 1.0\n (\n customLayerData = {\n string creator = "Babylon.js USDZExportAsync"\n }\n defaultPrim = "Root"\n metersPerUnit = 1\n upAxis = "Y"\n )',a+=function(e){var t=!0===e.includeAnchoringProperties?'\n\t\ttoken preliminary:anchoring:type = "'.concat(e.anchoringType,'"\n\t\ttoken preliminary:planeAnchoring:alignment = "').concat(e.planeAnchoringAlignment,'"'):"";return'def Xform "Root"\n {\n def Scope "Scenes" (\n kind = "sceneLibrary"\n )\n {\n def Xform "Scene" (\n customData = {\n bool preliminary_collidesWithEnvironment = 0\n string sceneName = "Scene"\n }\n sceneName = "Scene"\n )\n {'.concat(t,"\n ")}(o),s={},u=0,l=e.meshes;u<l.length;u++)0!==(h=l[u]).getTotalVertices()&&(d=(p=h).geometry,(m=p.material)&&d&&(!r||r(p))&&(-1!==["StandardMaterial","PBRMaterial","PBRMetallicRoughnessMaterial"].indexOf(m.getClassName())?(g="geometries/Geometry_"+d.uniqueId+".usda",x=Ft(p),_=x.matrix,v=x.windingOrder,T=x.convertToRightHanded,g in i||(y=bt(d,o,v,T),i[g]=Mt(y)),m.uniqueId in s||(s[m.uniqueId]=m),a+=Ct(p,_)):t.Tools.Warn("USDZExportAsync does not support this material type: "+m.getClassName())));for(A in e.activeCamera&&o.exportCamera&&(a+=function(e,n){var r="Camera_"+e.uniqueId,o=wt(t.Matrix.RotationY(Math.PI).multiply(e.getWorldMatrix()));if(e.mode===t.Constants.ORTHOGRAPHIC_CAMERA)return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(o,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(n.precision),", ").concat(e.maxZ.toPrecision(n.precision),")\n\t\t\tfloat horizontalAperture = ").concat((10*(Math.abs(e.orthoLeft||1)+Math.abs(e.orthoRight||1))).toPrecision(n.precision),"\n\t\t\tfloat verticalAperture = ").concat((10*(Math.abs(e.orthoTop||1)+Math.abs(e.orthoBottom||1))).toPrecision(n.precision),'\n\t\t\ttoken projection = "orthographic"\n\t\t}\n\t\n\t');var i=e.getEngine().getAspectRatio(e),a=n.cameraSensorWidth||35;return'def Camera "'.concat(r,'"\n\t\t{\n\t\t\tmatrix4d xformOp:transform = ').concat(o,'\n\t\t\tuniform token[] xformOpOrder = ["xformOp:transform"]\n\n\t\t\tfloat2 clippingRange = (').concat(e.minZ.toPrecision(n.precision),", ").concat(e.maxZ.toPrecision(n.precision),")\n\t\t\tfloat focalLength = ").concat((a/(2*Math.tan(.5*e.fov))).toPrecision(n.precision),'\n token projection = "perspective"\n\t\t\tfloat horizontalAperture = ').concat((a*i).toPrecision(n.precision),"\n\t\t\tfloat verticalAperture = ").concat((a/i).toPrecision(n.precision)," \n\t\t}\n\t\n\t")}(e.activeCamera,o)),a+="\n }\n }",a+=function(e,t,n){var r=[];for(var o in e){var i=e[o];r.push(Vt(i,t,n))}return'\n def "Materials"\n{\n'.concat(r.join(""),"\n}\n\n")}(s,b={},o),a+="\n }",i[o.modelFileName]=fflate.strToU8(a),w=[],M=b)w.push(A);C=0,f.label=3;case 3:return C<w.length?(A=w[C])in M?(E=b[R=A],I=E.texture,S=E.ext,[4,Bt(I)]):[3,8]:[3,9];case 4:return(V=f.sent())?(i["textures/Texture_".concat(R,".").concat(S)]=new Uint8Array(V.data),[3,8]):[3,5];case 5:return F=I.getSize(),[4,t.GetTextureDataAsync(I)];case 6:return B=f.sent(),[4,t.DumpTools.DumpDataAsync(F.width,F.height,B,"image/png",void 0,!1,!0)];case 7:O=f.sent(),i["textures/Texture_".concat(R,".").concat(S)]=new Uint8Array(O).slice(),f.label=8;case 8:return C++,[3,3];case 9:for(P in N=0,i)(U=i[P])&&(k=34+P.length,4!=(L=63&(N+=k))&&(W=new Uint8Array(64-L),i[P]=[U,{extra:{12345:W}}]),N=U.length);return[2,fflate.zipSync(i,{level:0})]}})})}var Nt={__proto__:null,USDZExportAsync:Ot},Pt=function(){function e(){}return e.Export=function(e,n,r){var o;if(void 0===n&&(n=[]),!e||0===e.bones.length)throw new Error("Invalid or empty skeleton provided");var i=n;n&&0!==n.length||(i=e.animations.map(function(e){return e.name}));for(var a=null,s=0,u=i;s<u.length;s++){var c=u[s],l=e.getAnimationRange(c);l&&(a=a?new t.AnimationRange("animation-range",Math.min(a.from,l.from),Math.max(a.to,l.to)):l)}if(!a&&(e.animations.length>0&&(a=e.getAnimationRange(e.animations[0].name)),!a))throw new Error("No animation range found in skeleton");for(var h=r||1/((null===(o=e.animations[0])||void 0===o?void 0:o.framePerSecond)||30),f=this._BuildBoneHierarchy(e,i),p=0,d=0,m=f;d<m.length;d++){var g=m[d];g.positionKeys.length>0&&(p=Math.max(p,g.positionKeys.length)),g.rotationKeys.length>0&&(p=Math.max(p,g.rotationKeys.length))}0===p&&(p=Math.floor((a.to-a.from)/h)+1);var x="";return x+="HIERARCHY\n",x+=this._ExportHierarchy(f,0),x+="MOTION\n",x+="Frames: ".concat(p,"\n"),(x+="Frame Time: ".concat(h.toFixed(6),"\n"))+this._ExportMotionData(f,p,0,i)},e._BuildBoneHierarchy=function(e,t){for(var n,r,o=new Map,i=[],a=0,s=e.bones;a<s.length;a++){var u={bone:h=s[a],children:[],hasPositionChannels:!1,hasRotationChannels:!1,positionKeys:[],rotationKeys:[]};o.set(h,u)}for(var c=0,l=e.bones;c<l.length;c++){var h=l[c];if(u=o.get(h),h.animations.length>0)for(var f=0,p=h.animations;f<p.length;f++){var d=p[f];t.includes(d.name)&&("position"===d.targetProperty?(u.hasPositionChannels=!0,(n=u.positionKeys).push.apply(n,d.getKeys())):"rotationQuaternion"===d.targetProperty&&(u.hasRotationChannels=!0,(r=u.rotationKeys).push.apply(r,d.getKeys())))}if(h.getParent()){var m=o.get(h.getParent());m&&m.children.push(u)}else i.push(u)}return i},e._ExportHierarchy=function(e,t){for(var n="",r=" ".repeat(t),o=0,i=e;o<i.length;o++){var a=i[o],s=a.bone;if(this._IsEndSite(a)){n+="".concat(r,"End Site\n"),n+="".concat(r,"{\n");var u=this._GetBoneOffset(s);n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n"),n+="".concat(r,"}\n")}else{n+="".concat(0===t?"ROOT":"".concat(r,"JOINT")," ").concat(s.name,"\n"),n+="".concat(r,"{\n"),u=this._GetBoneOffset(s),n+="".concat(r," OFFSET ").concat(u.x.toFixed(6)," ").concat(u.y.toFixed(6)," ").concat(u.z.toFixed(6),"\n");var c=[];a.hasPositionChannels&&c.push("Xposition","Yposition","Zposition"),a.hasRotationChannels&&c.push("Zrotation","Xrotation","Yrotation"),c.length>0&&(n+="".concat(r," CHANNELS ").concat(c.length," ").concat(c.join(" "),"\n")),a.children.length>0&&(n+=this._ExportHierarchy(a.children,t+1)),n+="".concat(r,"}\n")}}return n},e._IsEndSite=function(e){return 0===e.children.length},e._GetBoneOffset=function(e){try{return e.getParent()?e.getLocalMatrix().getTranslation():e.getRestMatrix().getTranslation()}catch(e){return t.Vector3.Zero()}},e._ExportMotionData=function(e,t,n,r){for(var o="",i=0;i<t;i++){var a=[];this._CollectFrameValues(e,i+n,a,r),o+=a.map(function(e){return e.toFixed(6)}).join(" ")+"\n"}return o},e._CollectFrameValues=function(e,t,n,r){for(var o=0,i=e;o<i.length;o++){var a=i[o];if(!this._IsEndSite(a)){if(a.hasPositionChannels){var s=this._GetPositionAtFrameIndex(a.positionKeys,t);n.push(s.x,s.y,s.z)}if(a.hasRotationChannels){var u=this._GetRotationAtFrameIndex(a.rotationKeys,t),c=this._QuaternionToEuler(u);n.push(c.z,c.x,c.y)}a.children.length>0&&this._CollectFrameValues(a.children,t,n,r)}}},e._GetPositionAtFrameIndex=function(e,n){return 0===e.length?t.Vector3.Zero():e[Math.max(0,Math.min(n,e.length-1))].value.clone()},e._GetRotationAtFrameIndex=function(e,n){return 0===e.length?t.Quaternion.Identity():e[Math.max(0,Math.min(n,e.length-1))].value.clone()},e._QuaternionToEuler=function(e){var n=new t.Matrix;e.toRotationMatrix(n);var r,o,i,a=n.m,s=Math.sqrt(a[0]*a[0]+a[1]*a[1]);return s>t.Epsilon?(r=Math.atan2(a[6],a[10]),o=Math.atan2(-a[2],s),i=Math.atan2(a[1],a[0])):(r=Math.atan2(-a[9],a[5]),o=Math.atan2(-a[2],s),i=0),new t.Vector3(t.Tools.ToDegrees(r),t.Tools.ToDegrees(o),t.Tools.ToDegrees(i))},e}(),Ut={__proto__:null,BVHExporter:Pt};function kt(e){return"string"==typeof(null==e?void 0:e.name)}var Lt=Symbol("__xml:meta$__"),Wt=Symbol("__xml:name$__");function Dt(e,t){var n,r=e.constructor;(null!==(n=r[Lt])&&void 0!==n?n:r[Lt]=[]).push(t)}function zt(e){return function(t){t[Wt]=e}}function Kt(){return function(e,t){return Dt(e,{kind:"none",prop:t,ignore:!0})}}function Gt(e){return function(t,n){return Dt(t,c({kind:"attr",prop:n},e))}}function qt(e){return function(t,n){return Dt(t,c({kind:"elem",prop:n},e))}}function Ht(e){var t,n;return null!==(n=null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Lt])&&void 0!==n?n:[]}function jt(e){var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t[Wt])||void 0}function Xt(e){return/^[A-Za-z_][A-Za-z0-9._-]*$/.test(e)}function Qt(e){if(kt(e))return e;var t=(null!=e?e:"").trim();if(!t)return{name:""};var n=t.indexOf(":");if(-1===n)return{name:t};if(-1!==t.indexOf(":",n+1))return{name:t};var r=t.slice(0,n),o=t.slice(n+1);return Xt(r)&&Xt(o)?{ns:r,name:o}:{name:t}}function Zt(e,t){return t?"".concat(t,":").concat(e):e}var Yt=Object.freeze({eps:1e-6,maxDecimalsCap:15,trimTrailingZeros:!0,allowScientific:!1,snapNearZero:!0}),Jt=Object.freeze({number:Yt});function $t(e){var t,n,r,o,i,a,s=null!==(t=null==e?void 0:e.eps)&&void 0!==t?t:Yt.eps;return{eps:s,maxDecimalsCap:null!==(n=null==e?void 0:e.maxDecimalsCap)&&void 0!==n?n:Yt.maxDecimalsCap,trimTrailingZeros:null!==(r=null==e?void 0:e.trimTrailingZeros)&&void 0!==r?r:Yt.trimTrailingZeros,fixedDecimals:null==e?void 0:e.fixedDecimals,allowScientific:null!==(o=null==e?void 0:e.allowScientific)&&void 0!==o?o:Yt.allowScientific,snapNearZero:null!==(i=null==e?void 0:e.snapNearZero)&&void 0!==i?i:Yt.snapNearZero,zeroThreshold:null!==(a=null==e?void 0:e.zeroThreshold)&&void 0!==a?a:s,perAttributeEps:null==e?void 0:e.perAttributeEps}}function en(e){return{number:$t(null==e?void 0:e.number)}}var tn=function(){function e(e){if(this.o=e,this._o=e.number,!Number.isFinite(this._o.eps)||this._o.eps<=0)throw new Error("opts.eps must be a finite, positive number")}return e.prototype.toString=function(e){var t,n,r,o;if(!Number.isFinite(e))throw new Error("Cannot format non-finite number: ".concat(e));var i,a=this._o,s=this._clampInt(null!==(t=a.maxDecimalsCap)&&void 0!==t?t:15,0,20),u=null===(n=a.trimTrailingZeros)||void 0===n||n,c=null===(r=a.snapNearZero)||void 0===r||r,l=null!==(o=a.zeroThreshold)&&void 0!==o?o:a.eps,h=1/a.eps,f=Math.round(e*h)/h;if(Object.is(f,-0)&&(f=0),c&&Math.abs(f)<=l&&(f=0),i=void 0!==a.fixedDecimals?this._clampInt(a.fixedDecimals,0,s):this._clampInt(Math.ceil(-Math.log10(a.eps)),0,s),a.allowScientific,0===i)return String(Math.trunc(f));var p=f.toFixed(i);if(u&&void 0===a.fixedDecimals&&(p=p.replace(/(\.\d*?[1-9])0+$/,"$1").replace(/\.0+$/,"").replace(/\.$/,"")),/[eE]/.test(p))throw new Error("Scientific notation not allowed in XML output: ".concat(p));return p},e.prototype._clampInt=function(e,t,n){return Number.isFinite(e)?(e=Math.trunc(e),Math.max(t,Math.min(n,e))):t},e}();function nn(e){return e instanceof Date}function rn(e){return"string"==typeof e}function on(e){return"number"==typeof e}function an(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||nn(e)}function sn(e){return"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||nn(e)}var un,cn=function(){function e(e,t){this._ns=new Map,this._prefixCount=0,this._builder=e,this._format=en(t),this._nFmt=new tn(this._format)}return e.prototype.withNamespace=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=0,r=e;n<r.length;n++){var o=r[n];this._assignNamespace(o)}return this},e.prototype.serialize=function(e,t){if(!(t=null!=t?t:jt(e)))throw new Error("can not find name for given object");var n=Qt(t);n.ns&&this._assignNamespace(n.ns,"xmlns"),this._gatherNamespaces(e,new WeakSet);for(var r=this._builder.ele(null,n.name),o=0,i=Array.from(this._ns.entries());o<i.length;o++){var a=i[o],s=a[0],u=a[1];r.att("xmlns",u,s)}this._writeObjectContent(r,e,(new WeakSet).add(e)),this._builder.end()},e.prototype._writeObject=function(e,t,n){if(!n.has(t))if(n.add(t),Array.isArray(t))for(var r=0,o=t;r<o.length;r++){var i=o[r];sn(i)||(rn(i)?this._builder.text(i):this._writeObject(e,i,n))}else{var a=jt(t);if(a){var s=Qt(a),u=this._getPrefix(s),c=Zt(s.name,u);e.ele(null,c),this._writeObjectContent(e,t,n),this._builder.end()}}},e.prototype._getPrefix=function(e){if(e.ns){var t=this._ns.get(e.ns.toLowerCase());if("xmlns"!==t)return t}},e.prototype._writeObjectContent=function(e,t,n){for(var r,o,i,a=null!==(r=Ht(t))&&void 0!==r?r:[],s=new Map,u=0,c=a;u<c.length;u++){var l=c[u],h=null!==(o=s.get(l.prop))&&void 0!==o?o:[];h.push(l),s.set(l.prop,h)}for(var f=Object.keys(t).sort(function(e,t){var n,r,o=(null!==(n=s.get(e))&&void 0!==n?n:[]).some(function(e){return"attr"===e.kind}),i=(null!==(r=s.get(t))&&void 0!==r?r:[]).some(function(e){return"attr"===e.kind});return o===i?0:o?-1:1}),p=0,d=f;p<d.length;p++){var m=d[p],g=t[m];if(null!=g){var x=s.get(m);if(x){var _=x.some(function(e){return!0===e.ignore||"none"===e.kind});if(_)continue;for(var v=0,T=x;v<T.length;v++){var y=null!==(i=(l=T[v]).name)&&void 0!==i?i:l.prop.toLowerCase();if(y&&"attr"===l.kind){var b=null;if(on(g)&&this._nFmt&&(b=this._nFmt.toString(g)),l.formatter&&(b=new l.formatter(this._format).toString(g)),b=null!=b?b:g.toString()){var M=Qt(y),w=this._getPrefix(M),A=Zt(M.name,w);e.att(null,A,b)}}}}else sn(g)||(rn(g)?this._builder.text(g):this._writeObject(e,g,n))}}},e.prototype._gatherNamespaces=function(e,t){var n,r;if(!t.has(e))if(t.add(e),Array.isArray(e))for(var o=0,i=e;o<i.length;o++){var a=i[o];an(a)||this._gatherNamespaces(a,t)}else{var s=jt(e);s&&this._assignNamespace(s);for(var u=null!==(n=Ht(e))&&void 0!==n?n:[],c=new Map,l=0,h=u;l<h.length;l++){var f=h[l],p=null!==(r=c.get(f.prop))&&void 0!==r?r:[];p.push(f),c.set(f.prop,p)}for(var d=[],m=0,g=Object.keys(e);m<g.length;m++){var x=g[m],_=e[x];if(null!=_){var v=c.get(x);if(v){var T=v.some(function(e){return!0===e.ignore||"none"===e.kind});if(T)continue;for(var y=0,b=v;y<b.length;y++)(f=b[y]).name&&this._assignNamespace(f.name)}d.push(_)}}for(var M=0,w=d;M<w.length;M++){var A=w[M];an(A)||this._gatherNamespaces(A,t)}}},e.prototype._assignNamespace=function(e,t){var n=Qt(e);if(null==n?void 0:n.ns){var r=n.ns.toLowerCase();this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r))}else"xmlns"===t&&(r=n.name.toLowerCase(),this._ns.get(r)||this._ns.set(r,null!=t?t:this._buildNsPrefix(r)))},e.prototype._buildNsPrefix=function(e){var t,n=!1;do{t="ns".concat(this._prefixCount++);for(var r=0,o=Array.from(this._ns.values());r<o.length;r++)if(o[r]===t){n=!0;break}}while(n);return t},e}(),ln=function(){function e(){}return e.OpenTag="<",e.CloseTag=">",e.Slash="/",e.Question="?",e.Quote='"',e.Equal="=",e.Space=" ",e.Semicolon=":",e.Dec="<?xml",e.Xml="xml",e.Xmlns="xmlns",e.Xsi="xsi",e.VersionKeyword="version",e.EncodingKeyword="encoding",e.StandaloneKeyword="standalone",e}();!function(e){e[e.Declaration=0]="Declaration",e[e.Tag=1]="Tag",e[e.Attribute=2]="Attribute",e[e.Text=3]="Text"}(un||(un={}));var hn,fn,pn=function(){function e(e){this._ctxStack=[],this._d=0,this._w=e}return e.prototype.dec=function(e,t,n){return this._w.write(ln.Dec),this._writeAttStr(ln.VersionKeyword,e),t&&this._writeAttStr(ln.EncodingKeyword,t),void 0!==n&&this._writeAttStr(ln.StandaloneKeyword,n?"yes":"no"),this._w.write(ln.Question,ln.CloseTag),this},e.prototype.att=function(e,t,n){var r=this._peekContext();if(!r)throw new Error("att() without open element");if(r.closed)throw new Error("att() after start tag closed for <".concat(r.name,">"));if(this._isXmlnsDecl(e,t)){if(t===ln.Xmlns)r.defaultNs=n,this._registerNamespace(r,"",n),this._writeAttStr(ln.Xmlns,n);else if(e)this._registerNamespace(r,t,n),this._writeAttStr("".concat(e,":").concat(t),n);else{var o=t.slice(6);this._registerNamespace(r,o,n),this._writeAttStr(t,n)}return r.lastToken=un.Attribute,this}var i=t;if(e){var a=this._ensurePrefixDeclared(r,e);i="".concat(a,":").concat(t)}return r.lastToken=un.Attribute,this._writeAttStr(i,n),this},e.prototype.ele=function(e,t){var n,r=this._peekContext();r&&this._closeOpenTagIfNeeded(r);var o=t;if(e){var i=null!==(n=this._lookupPrefix(e))&&void 0!==n?n:e;o="".concat(i,":").concat(t)}return this._pushContext(o,++this._d),this._w.write(ln.OpenTag,o),this},e.prototype.text=function(e){var t=this._peekContext();if(!t)throw new Error("text() without open element");return this._closeOpenTagIfNeeded(t),t.lastToken=un.Text,this._w.write(this._escText(e)),this},e.prototype.end=function(){var e=this._popContext();return e&&(this._d--,e.closed?this._w.write(ln.OpenTag,ln.Slash,e.name,ln.CloseTag):this._w.write(ln.Slash,ln.CloseTag)),this},e.prototype._pushContext=function(t,n){var r=new e.Context(t,n);return this._ctxStack.push(r),r},e.prototype._popContext=function(){return this._ctxStack.pop()},e.prototype._peekContext=function(){return this._ctxStack[this._ctxStack.length-1]},Object.defineProperty(e.prototype,"_contextDepth",{get:function(){return this._ctxStack.length},enumerable:!1,configurable:!0}),e.prototype._writeAttStr=function(e,t){this._w.write(ln.Space,e,ln.Equal,ln.Quote,this._escAttr(t),ln.Quote)},e.prototype._lookupPrefix=function(e){var t,n=this._ctxStack.length-1;if(n>=0)do{var r=null===(t=this._ctxStack[n--].ns2prefix)||void 0===t?void 0:t.get(e);if(r)return r}while(n>=0)},e.prototype._escText=function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")},e.prototype._escAttr=function(e){return this._escText(e).replace(/"/g,""").replace(/'/g,"'")},e.prototype._isXmlnsDecl=function(e,t){if(e)return e===ln.Xmlns;var n=t.length,r=ln.Xmlns.length;return n>=r&&t.startsWith(ln.Xmlns)&&(t.length==r||t[r]==ln.Semicolon)},e.prototype._registerNamespace=function(e,t,n){if(t===ln.Xml||t===ln.Xmlns)throw new Error("reserved prefix '".concat(t,"'"));var r=e.prefix2ns.get(t);if(r&&r!==n)throw new Error("prefix '".concat(t,"' already bound to a different namespace"));e.ns2prefix.get(n)||e.ns2prefix.set(n,t),e.prefix2ns.set(t,n)},e.prototype._allocPrefix=function(e){for(var t=1;;){var n="ns".concat(t++);if(!e.prefix2ns.has(n))return n}},e.prototype._ensurePrefixDeclared=function(e,t){var n=this._lookupPrefix(t);if(n)return n;if(e.closed)throw new Error("can not declare namespace after start tag closed for <".concat(e.name,">"));var r=this._allocPrefix(e);return this._writeAttStr("".concat(ln.Xmlns,":").concat(r),t),this._registerNamespace(e,r,t),r},e.prototype._closeOpenTagIfNeeded=function(e){e.closed||(this._w.write(ln.CloseTag),e.closed=!0)},e.Context=function(e,t){this.name="",this.closed=!1,this.lastToken=null,this.ns2prefix=new Map,this.prefix2ns=new Map,this.defaultNs=null,this.name=e,this.depth=t},e}(),dn=function(){function e(){this.count=0,this._chunks=[]}return e.prototype.write=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)return this;var n=e.join("");return this._chunks.push(n),this.count+=n.length,this},e.prototype.toString=function(){return this._chunks.join("")},e.prototype.clear=function(){this._chunks=[],this.count=0},e}(),mn=function(){function e(e,t){void 0===t&&(t={}),this._sink=e,this._opts=t,this.count=0,this._encoder=new TextEncoder,this._pending="",this._pendingChars=0}return e.prototype.write=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(0===t.length)return this;var r=t.join("");if(0===r.length)return this;this._pending+=r,this._pendingChars+=r.length;var o=null!==(e=this._opts.flushChars)&&void 0!==e?e:65536;return this._pendingChars>=o&&this.flush(),this},e.prototype.flush=function(){if(0===this._pendingChars)return this;var e=this._encoder.encode(this._pending);return this._sink.push(e),this.count+=e.length,this._pending="",this._pendingChars=0,this},e.prototype.finish=function(){this.flush(),this._sink.push(new Uint8Array(0),!0)},e.prototype.clear=function(){this._pending="",this._pendingChars=0,this.count=0},e}(),gn="http://schemas.microsoft.com/3dmanufacturing/core/2015/02",xn="http://schemas.microsoft.com/3dmanufacturing/trianglesets/2021/07";!function(e){e.micron="micron",e.millimeter="millimeter",e.centimeter="centimeter",e.inch="inch",e.foot="foot",e.meter="meter"}(hn||(hn={})),function(e){e.model="model",e.solidsupport="solidsupport",e.support="support",e.surface="surface",e.other="other"}(fn||(fn={}));var _n,vn="http://schemas.openxmlformats.org/package/2006/content-types",Tn="http://schemas.openxmlformats.org/package/2006/relationships";!function(e){e.Relationships="application/vnd.openxmlformats-package.relationships+xml",e.Model="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",e.Materials="application/vnd.ms-package.3dmanufacturing-material+xml",e.Colors="application/vnd.ms-package.3dmanufacturing-colors+xml",e.Texture="application/vnd.ms-package.3dmanufacturing-texture+xml",e.Texture2D="application/vnd.ms-package.3dmanufacturing-texture2d+xml",e.Production="application/vnd.ms-package.3dmanufacturing-production+xml",e.Slice="application/vnd.ms-package.3dmanufacturing-slice+xml",e.BeamLattice="application/vnd.ms-package.3dmanufacturing-beamlattice+xml",e.SecureContent="application/vnd.ms-package.3dmanufacturing-securecontent+xml",e.Png="image/png",e.Jpeg="image/jpeg",e.Tiff="image/tiff",e.Xml="application/xml"}(_n||(_n={}));var yn="_rels/",bn="3D/",Mn="3dmodel.model",wn=".rels",An="[Content_Types].xml",Cn=function(){function e(){}return e.IsKnown=function(t){return e.Known.has(t)},e.IsThreeDimModel=function(t){return t===e.ThreeDimModel},e.ThreeDimModel="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel",e.Thumbnail="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail",e.PrintTicket="http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket",e.MustPreserve="http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve",e.Known=new Set([e.ThreeDimModel,e.Thumbnail,e.PrintTicket,e.MustPreserve]),e}(),Rn=function(){function e(){this.items=[]}return l([zt({ns:vn,name:"Types"})],e)}(),En=function(){function e(e,t){this.ext=e,this.ct=t}return l([Gt({name:{ns:vn,name:"Extension"}})],e.prototype,"ext",void 0),l([Gt({name:{ns:vn,name:"ContentType"}})],e.prototype,"ct",void 0),l([zt({ns:vn,name:"Default"})],e)}(),In=function(){function e(){this.items=[]}return l([zt({ns:Tn,name:"Relationships"})],e)}(),Sn=function(){function e(e,t,n){this.id=e,this.type=t,this.target=n}return l([Gt({name:"Id"})],e.prototype,"id",void 0),l([Gt({name:"Type"})],e.prototype,"type",void 0),l([Gt({name:"Target"})],e.prototype,"target",void 0),l([zt({ns:Tn,name:"Relationship"})],e)}(),Vn=function(e,t,n){this.contentTypes=e,this.relationships=t,this.model=n},Fn=function(){function e(e){this.values=e}return e.Zero=function(){return new e([0,0,0,0,0,0,0,0,0,0,0,0])},e.prototype.toString=function(){return this.values.join(" ")},e}(),Bn=function(){function e(e){this.o=e,this._f=new tn(e)}return e.prototype.toString=function(e){var t=this;return e.values.map(function(e){return t._f.toString(e)}).join(" ")},e}(),On=function(){function e(){this.unit=hn.millimeter}return e.KnownMeta=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate","Application"],l([Gt({name:"unit"})],e.prototype,"unit",void 0),l([Gt({name:"requiredextensions"})],e.prototype,"requiredextensions",void 0),l([Gt({name:"recommendedextensions"})],e.prototype,"recommendedextensions",void 0),l([zt({ns:gn,name:"model"})],e)}(),Nn=function(){function e(e,t,n,r){this.name=e,this.value=t,this.preserve=n,this.type=r}return l([Gt({name:"name"})],e.prototype,"name",void 0),l([Gt({name:"preserve"})],e.prototype,"preserve",void 0),l([Gt({name:"type"})],e.prototype,"type",void 0),l([zt({ns:gn,name:"meta"})],e)}(),Pn=function(){function e(){this.metadata=[]}return l([zt({ns:gn,name:"metadatagroup"})],e)}(),Un=function(){function e(){this.object=[]}return l([zt({ns:gn,name:"resources"})],e)}(),kn=function(){function e(e,t){void 0===t&&(t=fn.model),this.id=e,this.type=t}return l([Gt({name:"id"})],e.prototype,"id",void 0),l([Gt({name:"type"})],e.prototype,"type",void 0),l([Gt({name:"thumbnail"})],e.prototype,"thumbnail",void 0),l([Gt({name:"partnumber"})],e.prototype,"partnumber",void 0),l([Gt({name:"name"})],e.prototype,"name",void 0),l([Gt({name:"pid"})],e.prototype,"pid",void 0),l([Gt({name:"pindex"})],e.prototype,"pindex",void 0),l([zt({ns:gn,name:"object"})],e)}(),Ln=function(){function e(e,t){this.vertices=null!=e?e:new Wn,this.triangles=null!=t?t:new zn}return l([zt({ns:gn,name:"mesh"})],e)}(),Wn=function(){function e(){this.vertex=[]}return l([zt({ns:gn,name:"vertices"})],e)}(),Dn=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=0),void 0===n&&(n=0),this.x=e,this.y=t,this.z=n}return l([Gt({name:"x"})],e.prototype,"x",void 0),l([Gt({name:"y"})],e.prototype,"y",void 0),l([Gt({name:"z"})],e.prototype,"z",void 0),l([zt({ns:gn,name:"vertex"})],e)}(),zn=function(){function e(){this.triangle=[]}return l([zt({ns:gn,name:"triangles"})],e)}(),Kn=function(){function e(e,t,n){this.v1=e,this.v2=t,this.v3=n}return l([Gt({name:"v1"})],e.prototype,"v1",void 0),l([Gt({name:"v2"})],e.prototype,"v2",void 0),l([Gt({name:"v3"})],e.prototype,"v3",void 0),l([Gt({name:"p1"})],e.prototype,"p1",void 0),l([Gt({name:"p2"})],e.prototype,"p2",void 0),l([Gt({name:"p3"})],e.prototype,"p3",void 0),l([Gt({name:"pid"})],e.prototype,"pid",void 0),l([zt({ns:gn,name:"triangle"})],e)}(),Gn=function(){function e(){this.component=[]}return l([zt({ns:gn,name:"components"})],e)}(),qn=function(){function e(e,t){this.objectid=e,this.transform=t}return l([Gt({name:"objectid"})],e.prototype,"objectid",void 0),l([Gt({name:"transform",formatter:Bn})],e.prototype,"transform",void 0),l([zt({ns:gn,name:"component"})],e)}(),Hn=function(){function e(e){this.base=[],this.id=e}return l([Gt({name:"id"})],e.prototype,"id",void 0),l([zt({ns:gn,name:"basematerials"})],e)}(),jn=function(){function e(e,t){this.name=e,this.displaycolor=t}return l([Gt({name:"name"})],e.prototype,"name",void 0),l([Gt({name:"displaycolor"})],e.prototype,"displaycolor",void 0),l([zt({ns:gn,name:"base"})],e)}(),Xn=function(){function e(){this.item=[]}return l([zt({ns:gn,name:"build"})],e)}(),Qn=function(){function e(e,t,n){this.objectid=e,this.transform=t,this.partnumber=n}return l([Gt({name:"objectid"})],e.prototype,"objectid",void 0),l([Gt({name:"transform",formatter:Bn})],e.prototype,"transform",void 0),l([Gt({name:"partnumber"})],e.prototype,"partnumber",void 0),l([zt({ns:gn,name:"item"})],e)}(),Zn=function(){function e(e,t){this._object=new kn(e,t)}return e.prototype.withName=function(e){return this._object.name=e,this},e.prototype.withThumbnail=function(e){return this._object.thumbnail=e,this},e.prototype.withProperty=function(e,t){return void 0===t&&(t=0),this._object.pid=e,this._object.id=t,this},e.prototype.build=function(){return this._object},e.prototype.reset=function(e,t){this._object=new kn(e,t)},e}(),Yn=function(e){function t(t,n){void 0===n&&(n=fn.model);var r=e.call(this,t,n)||this;return r._object.content=new Gn,r}return u(t,e),t.prototype.withComponent=function(e,t){return this._object.content.component.push(new qn(e,t)),this},t}(Zn),Jn=function(e){function t(t){return e.call(this,t,fn.model)||this}return u(t,e),t.prototype.withPostProcessHandlers=function(e,t){return this._vh=e,this._th=t,this},t.prototype.withData=function(e){return this._object.content=this._buildMesh(e),this},t.prototype.withMaterial=function(e,t){return this._object.pid=e,this._object.pindex=t,this},t.prototype._buildMesh=function(e){var t=this._buildVertices(e.positions),n=this._buildTriangle(e.indices);return new Ln(t,n)},t.prototype._buildVertices=function(e){var t=new Wn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Dn(r,o,i);this._vh&&(a=this._vh(a)),t.vertex.push(a)}return t},t.prototype._buildTriangle=function(e){var t=new zn;if(e)for(var n=0;n<e.length;){var r=e[n++],o=e[n++],i=e[n++],a=new Kn(r,o,i);this._th&&(a=this._th(a)),t.triangle.push(a)}return t},t}(Zn),$n=function(){function e(e){this._m=new Hn(e)}return e.prototype.withColor=function(e,t){var n;this._m.base=null!==(n=this._m.base)&&void 0!==n?n:[];var r=this._m.base.find(function(t){return t.name.toLowerCase()===e.toLowerCase()});return r?(r.displaycolor=this._rgbaToHex(t),this):(r=new jn(e,this._rgbaToHex(t)),this._m.base.push(r),this)},e.prototype.build=function(){return this._m},e.prototype._rgbaToHex=function(e){var t=function(e){return Math.round(Math.min(255,Math.max(0,255*Math.pow(e,1/2.2))))},n=t(e.r).toString(16).padStart(2,"0").toUpperCase(),r=t(e.g).toString(16).padStart(2,"0").toUpperCase(),o=t(e.b).toString(16).padStart(2,"0").toUpperCase();if("number"==typeof e.a){var i=Math.round(Math.min(255,Math.max(0,255*e.a))).toString(16).padStart(2,"0").toUpperCase();return"#".concat(n).concat(r).concat(o).concat(i)}return"#".concat(n).concat(r).concat(o)},e}(),er=function(){function e(){this._model=new On,this._objects=new Map}return e.prototype.withMetaData=function(e,t,n,r){return this._model.metadata||(this._model.metadata=new Array),this._model.metadata.push(new Nn(e,t,n,r)),this},e.prototype.withMaterial=function(e){var t,n;return e instanceof $n&&(e=e.build()),e&&(this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.basematerials=null!==(n=this._model.resources.basematerials)&&void 0!==n?n:[],this._model.resources.basematerials.push(e)),this},e.prototype.withMesh=function(e){var t;return e instanceof Jn&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.object.push(e),this},e.prototype.withComponents=function(e){var t;return e instanceof Yn&&(e=e.build()),this._model.resources=null!==(t=this._model.resources)&&void 0!==t?t:new Un,this._model.resources.object.push(e),this},e.prototype.withBuild=function(e,t,n){var r,o;return this._model.build=null!==(r=this._model.build)&&void 0!==r?r:new Xn,null===(o=this._model.build.item)||void 0===o||o.push(new Qn(e,t,n)),this},e.prototype.withUnit=function(e){return this._model.unit=e,this},e.prototype.reset=function(){return this._model=new On,this._objects=new Map,this},e.prototype.build=function(){var e,t,n,r;if(!(null===(t=null===(e=this._model.resources)||void 0===e?void 0:e.object)||void 0===t?void 0:t.length))throw new Error("Invalid state: resources MUST be defined ");if(!(null===(r=null===(n=this._model.build)||void 0===n?void 0:n.item)||void 0===r?void 0:r.length))throw new Error("Invalid state: Build MUST be defined ");return this._model},e.KnownMetaSet=new Set(On.KnownMeta.map(function(e){return e.toLowerCase()})),e}(),tr=function(){function e(){}return e.prototype.withContentType=function(e){this._cts||(this._cts=new Rn);var t=this._cts.items;return t.some(function(t){return t.ext===e.ext&&t.ct===e.ct})||t.push(e),this},e.prototype.withRelationship=function(e){this._rs||(this._rs=new In);var t=this._rs.items;return t.some(function(t){return t.id===e.id})||t.push(e),this.withContentType(new En("rels",_n.Relationships)),this},e.prototype.withModel=function(e){return e instanceof er&&(e=e.build()),this._m=e,this.withContentType(new En("model",_n.Model)),this},e.prototype.build=function(){if(!this._m)throw new Error("Invalid state: you Must provide at least a model.");var e="".concat(bn).concat(Mn);if(!this._rs){var t="/".concat(e);this.withRelationship(new Sn("rel".concat(0),Cn.ThreeDimModel,t))}return new Vn(this._cts,this._rs,this._m)},e}(),nr=function(){function e(e){this._o=e}return Object.defineProperty(e.prototype,"options",{get:function(){return this._o},enumerable:!1,configurable:!0}),e.prototype.serializeAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u;return f(this,function(c){switch(c.label){case 0:return[4,this.ensureZipLibReadyAsync()];case 1:if(!(n=c.sent()))return[2];if(r=n.Zip,o=n.ZipDeflate,!r||!o)throw new Error("fflate Zip / ZipDeflate not available");return i=function(e){return{push:function(t,n){return e.push(t,n)}}},a=function(e,t,n){var r=new o(t,{level:6});e.add(r);var a=i(r),s=new mn(a),u=new pn(s).dec("1.0","UTF-8");new cn(u).serialize(n),s.finish()},(s=this.toDocument.apply(this,t))?(u=new r(e),a(u,An,s.contentTypes),a(u,"".concat(yn).concat(wn),s.relationships),a(u,"".concat(bn).concat(Mn),s.model),u.end(),[2]):[2]}})})},e.prototype.toDocument=function(){for(var e,t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o=(new er).withUnit(null!==(t=null===(e=this._o)||void 0===e?void 0:e.unit)&&void 0!==t?t:hn.millimeter);if(this.options.metadata)for(var i in this.options.metadata)o.withMetaData(i,this.options.metadata[i]);return(new tr).withModel(this.toModel.apply(this,p([o],n,!1))).build()},e}(),rr=function(){function e(){}return e.SerializeToMemoryAsync=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return h(this,void 0,void 0,function(){var n,r,o,i,a,s,u,c;return f(this,function(l){switch(l.label){case 0:return n=new Array,r=0,o=function(e,t,o){n.push(t),r+=t.length},[4,e.serializeAsync.apply(e,p([o],t,!1))];case 1:if(l.sent(),!r)return[2,void 0];for(i=new Uint8Array(r),a=0,s=0,u=n;s<u.length;s++)c=u[s],i.set(c,a),a+=c.length;return[2,i]}})})},e}(),or=function(){function e(){}return e.FFLATEUrl="https://unpkg.com/fflate@0.8.2",e}(),ir=function(){function e(e,t,n){void 0===e&&(e=0),void 0===t&&(t=Number.MIN_SAFE_INTEGER),void 0===n&&(n=1),this._from=e,this._to=t,this._step=n,this._i=e}return e.prototype.next=function(){if(this._i<this._to)throw new Error("ST_ResourceID out of bound");var e=this._i;return this._i+=this._step,e},e.prototype.reset=function(){return this._i=this._from,this},e}(),ar=function(e){function n(t){return void 0===t&&(t={}),e.call(this,c(c({},n.DefaultOptions),t))||this}return u(n,e),n.prototype.toModel=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];n=n.filter(function(e){return e instanceof t.Mesh||e instanceof t.InstancedMesh});for(var o=new ir,i=e,a=new Map,s=this.options.exportInstances?[]:null,u=0;u<n.length;u++){var c=n[u];if(c instanceof t.InstancedMesh)null==s||s.push(c);else{var l=c.name||"mesh".concat(u),h=c.getWorldMatrix(),f=this._handleBabylonTo3mfMatrixTransformToRef(h,Fn.Zero());if(void 0!==(A=c.subMeshes))for(var p=1==A.length,d=0;d<A.length;d++){var m=A[d],g=this._extractSubMesh(c,m);if(g){var x=p?"".concat(l):"".concat(l,"_").concat(d),_=new Jn(o.next()).withData(g).withName(x).build();i.withMesh(_),i.withBuild(_.id,f),a.set(m,_)}}}}if(s&&s.length)for(var v=this._groupBy(s,function(e){return e.sourceMesh}),T=0,y=Array.from(v.entries());T<y.length;T++){var b=y[T],M=b[0],w=b[1];if(w&&w.length)for(u=0;u<w.length;u++){h=w[u].getWorldMatrix();var A=M.subMeshes;for(d=0;d<A.length;d++){m=A[d];var C=a.get(m);C&&i.withBuild(C.id,this._handleBabylonTo3mfMatrixTransformToRef(h,Fn.Zero()))}}}return i.build()},n.prototype.ensureZipLibReadyAsync=function(){return h(this,void 0,void 0,function(){var e=this;return f(this,function(n){switch(n.label){case 0:return this._fflateReadyPromise?[4,this._fflateReadyPromise]:[3,2];case 1:case 3:return[2,n.sent()];case 2:return this._fflateReadyPromise=h(e,void 0,void 0,function(){var e;return f(this,function(n){switch(n.label){case 0:return(e=globalThis).fflate?[3,2]:[4,t.Tools.LoadScriptAsync(or.FFLATEUrl)];case 1:n.sent(),n.label=2;case 2:return[2,e.fflate]}})}),[4,this._fflateReadyPromise]}})})},n.prototype._extractSubMesh=function(e,t){var r=e.getIndices();if(r){var o=e.getVerticesData(n._PositionKind);if(o){if(0==t.indexStart&&t.indexCount==r.length)return{positions:o,indices:r};for(var i=t.indexStart,a=new Map,s=[],u=new Uint32Array(t.indexCount),c=0;c<t.indexCount;c++){var l=r[i+c],h=a.get(l);if(void 0===h){h=a.size,a.set(l,h);var f=3*l;s.push(o[f],o[f+1],o[f+2])}u[c]=h}return{positions:new Float32Array(s),indices:u}}}},n.prototype._groupBy=function(e,t){for(var n=new Map,r=0,o=e;r<o.length;r++){var i=o[r],a=t(i),s=n.get(a);s?s.push(i):n.set(a,[i])}return n},n.prototype._handleBabylonTo3mfMatrixTransformToRef=function(e,r){var o=e.multiplyToRef(n._R_BJS_TO_3MF,t.Matrix.Zero()).m;return r.values=[o[0],o[1],o[2],o[4],o[5],o[6],o[8],o[9],o[10],o[12],o[13],o[14]],r},n.DefaultOptions={unit:hn.meter,exportInstances:!1},n._PositionKind="position",n._R_BJS_TO_3MF=t.Matrix.RotationX(Math.PI/2).multiply(t.Matrix.Scaling(1,-1,1)),n}(nr),sr={__proto__:null,AbstractThreeMfSerializer:nr,ContentTypeFileName:An,DefaultXmlSerializerFormatOptions:Jt,DefaultXmlSerializerNumberOptions:Yt,GetXmlFieldMeta:Ht,GetXmlName:jt,IsQualifiedName:kt,Known3mfRelationshipTypes:Cn,get KnownI3mfContentType(){return _n},Matrix3d:Fn,MatrixFormatter:Bn,ModelFileName:Mn,NumberFormatter:tn,Object3dDirName:bn,OpenXmlContentTypesNamespace:vn,OpenXmlRelationshipsNamespace:Tn,RelationshipDirName:yn,RelationshipFileName:wn,ResolveFormatOptions:en,ResolveNumberOptions:$t,get ST_ObjectType(){return fn},get ST_Unit(){return hn},StringXmlWriter:dn,ThreeDimModelNamespace:gn,ThreeMf:rr,ThreeMfBase:jn,ThreeMfBaseMaterials:Hn,ThreeMfBuild:Xn,ThreeMfComponent:qn,ThreeMfComponents:Gn,ThreeMfComponentsBuilder:Yn,ThreeMfContentType:En,ThreeMfContentTypes:Rn,ThreeMfDocument:Vn,ThreeMfDocumentBuilder:tr,ThreeMfItem:Qn,ThreeMfMaterialBuilder:$n,ThreeMfMesh:Ln,ThreeMfMeshBuilder:Jn,ThreeMfMeta:Nn,ThreeMfMetadataGroup:Pn,ThreeMfModel:On,ThreeMfModelBuilder:er,ThreeMfObject:kn,ThreeMfObjectBuilder:Zn,ThreeMfRelationship:Sn,ThreeMfRelationships:In,ThreeMfResources:Un,ThreeMfSerializer:ar,ThreeMfSerializerGlobalConfiguration:or,ThreeMfTriangle:Kn,ThreeMfTriangles:zn,ThreeMfVertex:Dn,ThreeMfVertices:Wn,ToQualifiedString:Zt,get TokenType(){return un},TriangleSetsNamespace:xn,Utf8XmlWriterToBytes:mn,XmlAttr:Gt,XmlBuilder:pn,XmlElem:qt,XmlIgnore:Kt,XmlName:zt,XmlNameToParts:Qt,XmlSerializer:cn},ur="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==ur)for(var cr in Ut)ur.BABYLON[cr]=Ut[cr];var lr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==lr){lr.BABYLON=lr.BABYLON||{};var hr=lr.BABYLON;hr.GLTF2=hr.GLTF2||{},hr.GLTF2.Exporter=hr.GLTF2.Exporter||{},hr.GLTF2.Exporter.Extensions=hr.GLTF2.Exporter.Extensions||{};var fr=[];for(var pr in o)hr[pr]=o[pr],fr.push(pr);for(var pr in a)hr[pr]=a[pr],fr.push(pr);for(var pr in te)hr[pr]=te[pr],fr.push(pr);for(var pr in gt)hr.GLTF2.Exporter.Extensions[pr]=gt[pr],fr.push(pr);for(var pr in xt)fr.indexOf(pr)>-1||(hr.GLTF2.Exporter[pr]=xt[pr])}var dr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==dr)for(var mr in r)dr.BABYLON[mr]=r[mr];var gr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==gr)for(var xr in vt)gr.BABYLON[xr]=vt[xr];var _r="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==_r)for(var vr in Nt)_r.BABYLON[vr]=Nt[vr];var Tr="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==Tr){var yr=[];for(var br in sr)yr.indexOf(br)>-1||(Tr.BABYLON[br]=sr[br],yr.push(br))}var Mr={__proto__:null,AbstractThreeMfSerializer:nr,BVHExporter:Pt,ContentTypeFileName:An,DefaultXmlSerializerFormatOptions:Jt,DefaultXmlSerializerNumberOptions:Yt,EXT_lights_area:xe,EXT_mesh_gpu_instancing:oe,EXT_texture_avif:mt,EXT_texture_webp:pt,GLTF2Export:ee,GLTFData:i,GetXmlFieldMeta:Ht,GetXmlName:jt,IsQualifiedName:kt,KHR_draco_mesh_compression:se,KHR_lights_punctual:fe,KHR_materials_anisotropy:Te,KHR_materials_clearcoat:we,KHR_materials_coat:Se,KHR_materials_diffuse_roughness:it,KHR_materials_diffuse_transmission:Be,KHR_materials_dispersion:Ne,KHR_materials_emissive_strength:Ue,KHR_materials_fuzz:je,KHR_materials_ior:Le,KHR_materials_iridescence:De,KHR_materials_openpbr:st,KHR_materials_sheen:Ke,KHR_materials_specular:Qe,KHR_materials_transmission:Ye,KHR_materials_unlit:$e,KHR_materials_volume:tt,KHR_materials_volume_scatter:rt,KHR_texture_basisu:ht,KHR_texture_transform:ct,Known3mfRelationshipTypes:Cn,get KnownI3mfContentType(){return _n},Matrix3d:Fn,MatrixFormatter:Bn,ModelFileName:Mn,NumberFormatter:tn,OBJExport:n,Object3dDirName:bn,OpenXmlContentTypesNamespace:vn,OpenXmlRelationshipsNamespace:Tn,RelationshipDirName:yn,RelationshipFileName:wn,ResolveFormatOptions:en,ResolveNumberOptions:$t,STLExport:_t,get ST_ObjectType(){return fn},get ST_Unit(){return hn},StringXmlWriter:dn,ThreeDimModelNamespace:gn,ThreeMf:rr,ThreeMfBase:jn,ThreeMfBaseMaterials:Hn,ThreeMfBuild:Xn,ThreeMfComponent:qn,ThreeMfComponents:Gn,ThreeMfComponentsBuilder:Yn,ThreeMfContentType:En,ThreeMfContentTypes:Rn,ThreeMfDocument:Vn,ThreeMfDocumentBuilder:tr,ThreeMfItem:Qn,ThreeMfMaterialBuilder:$n,ThreeMfMesh:Ln,ThreeMfMeshBuilder:Jn,ThreeMfMeta:Nn,ThreeMfMetadataGroup:Pn,ThreeMfModel:On,ThreeMfModelBuilder:er,ThreeMfObject:kn,ThreeMfObjectBuilder:Zn,ThreeMfRelationship:Sn,ThreeMfRelationships:In,ThreeMfResources:Un,ThreeMfSerializer:ar,ThreeMfSerializerGlobalConfiguration:or,ThreeMfTriangle:Kn,ThreeMfTriangles:zn,ThreeMfVertex:Dn,ThreeMfVertices:Wn,ToQualifiedString:Zt,get TokenType(){return un},TriangleSetsNamespace:xn,USDZExportAsync:Ot,Utf8XmlWriterToBytes:mn,XmlAttr:Gt,XmlBuilder:pn,XmlElem:qt,XmlIgnore:Kt,XmlName:zt,XmlNameToParts:Qt,XmlSerializer:cn,_ConvertToGLTFPBRMetallicRoughness:y,_SolveMetallic:T,__IGLTFExporterExtension:0};e.default=Mr,e.serializers=Mr,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
2
|
+
//# sourceMappingURL=babylonjs.serializers.min.js.map
|