babylonjs-serializers 7.0.0 → 7.2.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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{n.d(i,{default:()=>fe});var e={};n.r(e),n.d(e,{OBJExport:()=>h});var t={};n.r(t),n.d(t,{__IGLTFExporterExtension:()=>p});var r={};n.r(r),n.d(r,{GLTFData:()=>m});var o={};n.r(o),n.d(o,{GLTF2Export:()=>w});var a={};n.r(a),n.d(a,{EXT_mesh_gpu_instancing:()=>$,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>U,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>J,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>V});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>$,GLTF2Export:()=>w,GLTFData:()=>m,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>U,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>J,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>V,_BinaryWriter:()=>M,_Exporter:()=>E,_GLTFAnimation:()=>_,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtensionV2:()=>F});var u={};n.r(u),n.d(u,{STLExport:()=>re});var l={};n.r(l),n.d(l,{EXT_mesh_gpu_instancing:()=>$,GLTF2Export:()=>w,GLTFData:()=>m,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>U,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>J,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>V,OBJExport:()=>h,STLExport:()=>re,_BinaryWriter:()=>M,_Exporter:()=>E,_GLTFAnimation:()=>_,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtension:()=>p,__IGLTFExporterExtensionV2:()=>F});var c,f=n(597),h=function(){function e(){}return e.OBJ=function(e,t,r,n){var i=[],o=1,a=1;t&&(r||(r="mat"),i.push("mtllib "+r+".mtl"));for(var s=0;s<e.length;s++){var u=e[s].name||"mesh".concat(s,"}");i.push("o ".concat(u));var l=null;if(n){var c=e[s].computeWorldMatrix(!0);l=new f.Matrix,c.invertToRef(l),e[s].bakeTransformIntoVertices(c)}if(t){var h=e[s].material;h&&i.push("usemtl "+h.id)}var p=e[s].geometry;if(p){var d=p.getVerticesData("position"),_=p.getVerticesData("normal"),m=p.getVerticesData("uv"),g=p.getIndices(),x=0,y=0;if(d&&g){for(var T=e[0].getScene().useRightHandedSystem,v=T?1:-1,b=0;b<d.length;b+=3)i.push("v "+d[b]*v+" "+d[b+1]+" "+d[b+2]),x++;if(null!=_)for(b=0;b<_.length;b+=3)i.push("vn "+_[b]*v+" "+_[b+1]+" "+_[b+2]);if(null!=m)for(b=0;b<m.length;b+=2)i.push("vt "+m[b]+" "+m[b+1]),y++;var A=["","",""],E=T?[2,1]:[1,2],M=E[0],F=E[1];for(b=0;b<g.length;b+=3){var w=[String(g[b]+o),String(g[b+M]+o),String(g[b+F]+o)],C=[String(g[b]+a),String(g[b+M]+a),String(g[b+F]+a)],V=w,R=null!=m?C:A,S=null!=_?w:A;i.push("f "+V[0]+"/"+R[0]+"/"+S[0]+" "+V[1]+"/"+R[1]+"/"+S[1]+" "+V[2]+"/"+R[2]+"/"+S[2])}n&&l&&e[s].bakeTransformIntoVertices(l),o+=x,a+=y}else f.Tools.Warn("There are no position vertices or indices on the mesh!")}else f.Tools.Warn("No geometry is present on the mesh")}return i.join("\n")},e.MTL=function(e){var t=[],r=e.material;return t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4)),r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e}(),p=0,d=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,i){var o={buffer:e,byteLength:r};return t&&(o.byteOffset=t),i&&(o.name=i),n&&(o.byteStride=n),o},e._CreateAccessor=function(e,t,r,n,i,o,a,s){var u={name:t,bufferView:e,componentType:n,count:i,type:r};return null!=a&&(u.min=a),null!=s&&(u.max=s),null!=o&&(u.byteOffset=o),u},e._CalculateMinMaxPositions=function(e,t,r){var n,i,o=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];if(r)for(var s=t,u=t+r;s<u;++s){n=3*s,i=f.Vector3.FromArray(e,n).asArray();for(var l=0;l<3;++l){var c=i[l];c<o[l]&&(o[l]=c),c>a[l]&&(a[l]=c),++n}}return{min:o,max:a}},e._NormalizeTangentFromRef=function(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)},e._GetDataAccessorElementCount=function(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}},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(c||(c={}));var _=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof f.TransformNode||e instanceof f.Camera||e instanceof f.Light)},e._CreateNodeAnimation=function(t,r,n,i,o){if(this._IsTransformable(t)){var a=[],s=[],u=r.getKeys(),l=e._CalculateMinMaxKeyFrames(u),c=e._DeduceInterpolation(u,n,i),h=c.interpolationType,p=c.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,o,a,s,l,i):"LINEAR"===h||"STEP"===h?e._CreateLinearOrStepAnimation(t,r,n,a,s,i):"CUBICSPLINE"===h?e._CreateCubicSplineAnimation(t,r,n,a,s,i):e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,o,a,s,l,i),a.length&&s.length)return{inputs:a,outputs:s,samplerInterpolation:h,inputsMin:p?l.min:f.Tools.FloatRound(l.min/r.framePerSecond),inputsMax:p?l.max:f.Tools.FloatRound(l.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,i=e.targetProperty.split(".");switch(i[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:f.Tools.Error("Unsupported animatable property ".concat(i[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(f.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,i,o,a,s,u,l,c){var f;if(e._IsTransformable(t)&&t.animations)for(var h=0,p=t.animations;h<p.length;h++){var d=p[h];if(!c||c(d)){var _=e._DeduceAnimationInfo(d);_&&(f={name:d.name,samplers:[],channels:[]},e._AddAnimation("".concat(d.name),d.hasRunningRuntimeAnimations?r:f,t,d,_.dataAccessorType,_.animationChannelTargetPath,i,a,s,u,_.useQuaternion,l),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,i,o,a,s,u,l,c){var h;if(t instanceof f.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var _=0,m=p.getTarget(d).animations;_<m.length;_++){var g=m[_];if(!c||c(g)){for(var x=new f.Animation("".concat(g.name),"influence",g.framePerSecond,g.dataType,g.loopMode,g.enableBlending),y=[],T=g.getKeys(),v=0;v<T.length;++v)for(var b=T[v],A=0;A<p.numTargets;++A)A==d?y.push(b):y.push({frame:b.frame,value:0});x.setKeys(y);var E=e._DeduceAnimationInfo(x);E&&(h={name:x.name,samplers:[],channels:[]},e._AddAnimation(g.name,g.hasRunningRuntimeAnimations?r:h,t,x,E.dataAccessorType,E.animationChannelTargetPath,i,a,s,u,E.useQuaternion,l,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,i,o,a,s,u){var l,c;if(t.animationGroups)for(var h=t.animationGroups,p=function(h){var p=new Map,_=new Map,m=new Set,g=h.to-h.from;c={name:h.name,channels:[],samplers:[]};for(var x=function(r){var g=h.targetedAnimations[r],x=g.target,y=g.animation;if(u&&!u(y))return"continue";if(d._IsTransformable(x)||1===x.length&&d._IsTransformable(x[0])){if(v=e._DeduceAnimationInfo(g.animation)){var T=d._IsTransformable(x)?x:d._IsTransformable(x[0])?x[0]:null;T&&e._AddAnimation("".concat(y.name),c,T,y,v.dataAccessorType,v.animationChannelTargetPath,n,i,o,a,v.useQuaternion,s)}}else if(x instanceof f.MorphTarget||1===x.length&&x[0]instanceof f.MorphTarget){var v;if(v=e._DeduceAnimationInfo(g.animation)){var b=x instanceof f.MorphTarget?x:x[0];if(b){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===b)return!0;return!1}));if(A){var E=t.meshes.find((function(e){return e.morphTargetManager===A}));E&&(p.has(E)||p.set(E,new Map),null===(l=p.get(E))||void 0===l||l.set(b,y),m.add(E),_.set(E,y))}}}}},y=0;y<h.targetedAnimations.length;++y)x(y);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,l=[],d=_.get(t).getKeys(),m=d.length,x=0;x<m;++x)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=p.get(t);if(v){var b=v.get(T);b?(u||(u=new f.Animation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,f.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[x])):l.push({frame:h.from+g/m*x,value:T.influence,inTangent:d[0].inTangent?0:void 0,outTangent:d[0].outTangent?0:void 0})}}u.setKeys(l);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),c,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,i,o,a,A.useQuaternion,s,null==r?void 0:r.numTargets)})),c.channels.length&&c.samplers.length&&r.push(c)},d=this,_=0,m=h;_<m.length;_++)p(m[_])},e._AddAnimation=function(t,r,n,i,o,a,s,u,l,c,f,h,p){var _,m,g,x,y,T,v,b=e._CreateNodeAnimation(n,i,a,f,h);if(b){if(p){for(var A=0,E=0,M=[];b.inputs.length>0;)E=b.inputs.shift(),A%p==0&&M.push(E),A++;b.inputs=M}var F=s[n.uniqueId],w=4*b.inputs.length;_=d._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(_),b.inputs.forEach((function(e){u.setFloat32(e)})),m=d._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,b.inputs.length,null,[b.inputsMin],[b.inputsMax]),c.push(m),g=c.length-1,y=b.outputs.length,w=4*d._GetDataAccessorElementCount(o)*b.outputs.length,_=d._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(_),b.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),m=d._CreateAccessor(l.length-1,"".concat(t," data"),o,5126,y,null,null,null),c.push(m),x=c.length-1,T={interpolation:b.samplerInterpolation,input:g,output:x},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:F,path:a}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,i,o,a,s,u,l,c,h){var p,d,_=f.Quaternion.Identity(),m=null,g=null,x=null,y=null,T=null,v=null;c.min=f.Tools.FloatRound(i/a);for(var b=r.getKeys(),A=0,E=b.length;A<E;++A){if(v=null,x=b[A],A+1<E)if(y=b[A+1],x.value.equals&&x.value.equals(y.value)||x.value===y.value){if(0!==A)continue;v=x.frame}else v=y.frame;else{if(T=b[A-1],x.value.equals&&x.value.equals(T.value)||x.value===T.value)continue;v=o}if(v)for(var M=x.frame;M<=v;M+=s)if((d=f.Tools.FloatRound(M/a))!==m){m=d,g=d;var F={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(M,F),e._SetInterpolatedValue(t,p,d,r,n,_,u,l,h)}}g&&(c.max=g)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,i,o){var a=e._GetBasePositionRotationOrScale(r,i,o),s=n.targetProperty.split("."),u=s?s[1]:"",l=o?f.Quaternion.FromArray(a).normalize():f.Vector3.FromArray(a);switch(u){case"x":case"y":case"z":l[u]=t;break;case"w":l.w=t;break;default:f.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return l},e._SetInterpolatedValue=function(e,t,r,n,i,o,a,s,u){var l;a.push(r),"weights"!==i?(n.dataType===f.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,i,u)),"rotation"===i?(u?o=t:(l=t,f.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,o)),s.push(o.asArray())):(l=t,s.push(l.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,i,o,a){for(var s=0,u=r.getKeys();s<u.length;s++){var l=u[s];i.push(l.frame/r.framePerSecond),e._AddKeyframeValue(l,r,o,n,t,a)}},e._CreateCubicSplineAnimation=function(t,r,n,i,o,a){r.getKeys().forEach((function(s){i.push(s.frame/r.framePerSecond),e._AddSplineTangent(c.INTANGENT,o,n,"CUBICSPLINE",s,a),e._AddKeyframeValue(s,r,o,n,t,a),e._AddSplineTangent(c.OUTTANGENT,o,n,"CUBICSPLINE",s,a)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var i=e.rotationQuaternion;n=(null!=i?i:f.Quaternion.Identity()).asArray()}else{var o=e.rotation;n=(null!=o?o:f.Vector3.Zero()).asArray()}else if("translation"===t){var a=e.position;n=(null!=a?a:f.Vector3.Zero()).asArray()}else{var s=e.scaling;n=(null!=s?s:f.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,i,o){var a,s=t.dataType;if(s===f.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var l=f.Vector3.FromArray(u);u=f.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}r.push(u)}else if(s===f.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(a=this._ConvertFactorToVector3OrQuaternion(e.value,i,t,n,o)){if("rotation"===n){var c=o?a:f.Quaternion.RotationYawPitchRoll(a.y,a.x,a.z).normalize();r.push(c.asArray())}r.push(a.asArray())}}else s===f.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):f.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,i,o=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((i=e[a]).inTangent||i.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",o=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||i.interpolation&&i.interpolation===f.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",o=!0;break}}else n=i.interpolation&&i.interpolation===f.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:o}},e._AddSplineTangent=function(e,t,r,n,i,o){var a,s=e===c.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(s)if(o)a=s.asArray();else{var u=s;a=f.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else a=[0,0,0,0];else a="weights"===r?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(a)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}(),m=function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-1!==e.indexOf(t,e.length-t.length)}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var n=this.glTFFiles[t],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")||e(t,".jpg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],i)),r.click()}},e}();function g(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}function x(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((i=(i=a.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function y(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var T=function(){function e(e){this._textureMap={},this._internalTextureToImage={},this._textureMap={},this._exporter=e}return e._FuzzyEquals=function(e,t,r){return f.Scalar.WithinEpsilon(e.r,t.r,r)&&f.Scalar.WithinEpsilon(e.g,t.g,r)&&f.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){var n=this,i=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?i.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?i.push(n._convertPBRMaterialAsync(e,t,r)):f.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(i).then((function(){}))},e.prototype._stripTexturesFromMaterial=function(e){var t={};if(e){t.name=e.name,t.doubleSided=e.doubleSided,t.alphaMode=e.alphaMode,t.alphaCutoff=e.alphaCutoff,t.emissiveFactor=e.emissiveFactor;var r=e.pbrMetallicRoughness;r&&(t.pbrMetallicRoughness={},t.pbrMetallicRoughness.baseColorFactor=r.baseColorFactor,t.pbrMetallicRoughness.metallicFactor=r.metallicFactor,t.pbrMetallicRoughness.roughnessFactor=r.roughnessFactor)}return t},e.prototype._hasTexturesPresent=function(e){var t;if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var r=e.pbrMetallicRoughness;if(r&&(r.baseColorTexture||r.metallicRoughnessTexture))return!0;if(e.extensions)for(var n in e.extensions){var i=e.extensions[n];if(i)return null===(t=i.hasTextures)||void 0===t?void 0:t.call(i)}return!1},e.prototype._getTextureInfo=function(e){if(e){var t=e.uid;if(t in this._textureMap)return this._textureMap[t]}return null},e.prototype._convertToGLTFPBRMetallicRoughness=function(t){var r,n,i,o,a,s,u=new f.Vector2(0,1),l=new f.Vector2(0,.1),c=new f.Vector2(0,.1),h=new f.Vector2(1300,.1),p=t.diffuseColor.toLinearSpace(t.getScene().getEngine().useExactSrgbConversions).scale(.5),d=t.alpha,_=(r=f.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower),n=Math.pow(r/h.x,.333333),i=u.y,o=l.y,a=c.y,s=h.y,(1-n)*(1-n)*(1-n)*i+3*(1-n)*(1-n)*n*o+3*(1-n)*n*n*a+n*n*n*s);return{baseColorFactor:[p.r,p.g,p.b,d],metallicFactor:0,roughnessFactor:_}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,i=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,o=i*i-4*n*(this._DielectricSpecular.r-t);return f.Scalar.Clamp((-i+Math.sqrt(o))/(2*n),0,1)},e._SetAlphaMode=function(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)},e.prototype._convertStandardMaterialAsync=function(t,r,n){var i=this._exporter._materialMap,o=this._exporter._materials,a=[],s=this._convertToGLTFPBRMetallicRoughness(t),u={name:t.name};if(null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||f.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),u.doubleSided=!0),n){t.diffuseTexture&&a.push(this._exportTextureAsync(t.diffuseTexture,r).then((function(e){e&&(s.baseColorTexture=e)})));var l=t.bumpTexture;l&&a.push(this._exportTextureAsync(l,r).then((function(e){e&&(u.normalTexture=e,1!==l.level&&(u.normalTexture.scale=l.level))}))),t.emissiveTexture&&(u.emissiveFactor=[1,1,1],a.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(u.emissiveTexture=e)})))),t.ambientTexture&&a.push(this._exportTextureAsync(t.ambientTexture,r).then((function(e){if(e){var t={index:e.index};u.occlusionTexture=t}})))}return(t.alpha<1||t.opacityTexture)&&(t.alphaMode===f.Constants.ALPHA_COMBINE?u.alphaMode="BLEND":f.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e._FuzzyEquals(t.emissiveColor,f.Color3.Black(),e._Epsilon)&&(u.emissiveFactor=t.emissiveColor.asArray()),u.pbrMetallicRoughness=s,e._SetAlphaMode(u,t),o.push(u),i[t.uniqueId]=o.length-1,this._finishMaterial(a,u,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var i=this;return Promise.all(e).then((function(){for(var e=null,o=0,a=i._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);o<a.length;o++){var s=a[o];e||(e=[]),e.push(i._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=i._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var i,o,a,s,u;return x(this,(function(l){switch(l.label){case 0:return i=f.Constants.TEXTURETYPE_UNSIGNED_INT,o=this._exporter._babylonScene,a=o.getEngine(),s=a.createRawTexture(e,t,r,f.Constants.TEXTUREFORMAT_RGBA,!1,!0,f.Texture.NEAREST_SAMPLINGMODE,null,i),[4,f.TextureTools.ApplyPostProcess("pass",s,o,i,f.Constants.TEXTURE_NEAREST_SAMPLINGMODE,f.Constants.TEXTUREFORMAT_RGBA)];case 1:return l.sent(),[4,a._readTexturePixels(s,t,r)];case 2:return u=l.sent(),[4,f.DumpTools.DumpDataAsync(t,r,u,n,void 0,!0,!0)];case 3:return[2,l.sent()]}}))}))},e.prototype._createWhiteTexture=function(e,t,r){for(var n=new Uint8Array(e*t*4),i=0;i<n.length;i+=4)n[i]=n[i+1]=n[i+2]=n[i+3]=255;return f.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,i,o=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return o.width<a.width?(n=e&&e instanceof f.Texture?f.TextureTools.CreateResizedCopy(e,a.width,a.height,!0):this._createWhiteTexture(a.width,a.height,r),i=t):o.width>a.width?(i=t&&t instanceof f.Texture?f.TextureTools.CreateResizedCopy(t,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,r),n=e):(n=e,i=t),{texture1:n,texture2:i}},e.prototype._convertPixelArrayToFloat32=function(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(t,r,n,i){var o;return g(this,void 0,void 0,(function(){var a,s,u,l,c,h,p,d,_,m,g,y,T,v,b,A,E,M,F,w,C,V,R,S,I,B,P,N,L,O,k;return x(this,(function(x){switch(x.label){case 0:return a=new Array,t||r?(s=t?t.getScene():r?r.getScene():null)?(u=this._resizeTexturesToSameDimensions(t,r,s),l=null===(o=u.texture1)||void 0===o?void 0:o.getSize(),c=void 0,h=void 0,p=l.width,d=l.height,[4,u.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return _=x.sent(),[4,u.texture2.readPixels()];case 2:if(m=x.sent(),!_)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(_),!m)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(m),g=h.byteLength,y=new Uint8Array(g),T=new Uint8Array(g),v=f.Color3.Black(),b=0,A=0,B=0;B<d;++B)for(P=0;P<p;++P)E=4*(p*B+P),M=new f.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),F=new f.Color3(h[E],h[E+1],h[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.specularColor),w=h[E+3]*n.glossiness,C={diffuseColor:M,specularColor:F,glossiness:w},V=this._convertSpecularGlossinessToMetallicRoughness(C),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),T[E]=255*V.baseColor.r,T[E+1]=255*V.baseColor.g,T[E+2]=255*V.baseColor.b,T[E+3]=u.texture1.hasAlpha?255*c[E+3]:255,y[E]=0,y[E+1]=255*V.roughness,y[E+2]=255*V.metallic,y[E+3]=255;for(R={baseColor:v,metallic:b,roughness:A},S=!1,I=!1,B=0;B<d;++B)for(P=0;P<p;++P)T[N=4*(p*B+P)]/=R.baseColor.r>e._Epsilon?R.baseColor.r:1,T[N+1]/=R.baseColor.g>e._Epsilon?R.baseColor.g:1,T[N+2]/=R.baseColor.b>e._Epsilon?R.baseColor.b:1,L=f.Color3.FromInts(T[N],T[N+1],T[N+2]),O=L.toGammaSpace(s.getEngine().useExactSrgbConversions),T[N]=255*O.r,T[N+1]=255*O.g,T[N+2]=255*O.b,e._FuzzyEquals(O,f.Color3.White(),e._Epsilon)||(I=!0),y[N+1]/=R.roughness>e._Epsilon?R.roughness:1,y[N+2]/=R.metallic>e._Epsilon?R.metallic:1,k=f.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(k,f.Color3.White(),e._Epsilon)||(S=!0);return S&&a.push(this._getImageDataAsync(y,p,d,i).then((function(e){R.metallicRoughnessTextureData=e}))),I&&a.push(this._getImageDataAsync(T,p,d,i).then((function(e){R.baseColorTextureData=e}))),[2,Promise.all(a).then((function(){return R}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),n=this._getPerceivedBrightness(t.specularColor),i=1-this._getMaxComponent(t.specularColor),o=e._SolveMetallic(r,n,i),a=t.diffuseColor.scale(i/(1-e._DielectricSpecular.r)/Math.max(1-o,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-o)).scale(1/Math.max(o,e._Epsilon)),u=f.Color3.Lerp(a,s,o*o);return{baseColor:u=u.clampToRef(0,1,u),metallic:o,roughness:1-t.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){var i=[],o={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&i.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var a=e._metallicTexture;a&&i.push(this._exportTextureAsync(a,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(i).then((function(){return o}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof f.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case f.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case f.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case f.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case f.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case f.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case f.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case f.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case f.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case f.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case f.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case f.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case f.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case f.Texture.WRAP_ADDRESSMODE:return 10497;case f.Texture.CLAMP_ADDRESSMODE:return 33071;case f.Texture.MIRROR_ADDRESSMODE:return 33648;default:return f.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){var i=this;return Promise.resolve().then((function(){var o={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},a=e._albedoTexture,s=e._reflectivityTexture,u=e._useMicroSurfaceFromReflectivityMapAlpha;if(s&&!u)return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");if((a||s)&&n){var l=i._exportTextureSampler(a||s);return i._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,s,o,t).then((function(e){var n=i._exporter._textures;if(e.baseColorTextureData){var o=i._exportImage("baseColor".concat(n.length),t,e.baseColorTextureData);r.baseColorTexture=i._exportTextureInfo(o,l,null==a?void 0:a.coordinatesIndex)}return e.metallicRoughnessTextureData&&(o=i._exportImage("metallicRoughness".concat(n.length),t,e.metallicRoughnessTextureData),r.metallicRoughnessTexture=i._exportTextureInfo(o,l,null==s?void 0:s.coordinatesIndex)),e}))}return i._convertSpecularGlossinessToMetallicRoughness(o)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,i={},o={name:e.name};if(e.isMetallicWorkflow()){var a=e._albedoColor,s=e.alpha;return a&&(i.baseColorFactor=[a.r,a.g,a.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(a){return n._setMetallicRoughnessPbrMaterial(a,e,o,i,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(a){return n._setMetallicRoughnessPbrMaterial(a,e,o,i,t,r)}))},e.prototype._setMetallicRoughnessPbrMaterial=function(t,r,n,i,o,a){var s=this._exporter._materialMap,u=this._exporter._materials,l=[];if(t){if(e._SetAlphaMode(n,r),e._FuzzyEquals(t.baseColor,f.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(i.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(i.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(i.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||f.Tools.Warn(r.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),a){var c=r._bumpTexture;if(c){var h=this._exportTextureAsync(c,o).then((function(e){e&&(n.normalTexture=e,1!==c.level&&(n.normalTexture.scale=c.level))}));l.push(h)}var p=r._ambientTexture;p&&(h=this._exportTextureAsync(p,o).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=t;var i=r._ambientTextureStrength;i&&(t.strength=i)}})),l.push(h));var d=r._emissiveTexture;d&&(h=this._exportTextureAsync(d,o).then((function(e){e&&(n.emissiveTexture=e)})),l.push(h))}var _=r._emissiveColor;e._FuzzyEquals(_,f.Color3.Black(),e._Epsilon)||(n.emissiveFactor=_.asArray()),n.pbrMetallicRoughness=i,u.push(n),s[r.uniqueId]=u.length-1}return this._finishMaterial(l,n,r,o)},e.prototype._getPixelsFromTexture=function(e){return e.textureType,f.Constants.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},e.prototype._exportTextureAsync=function(e,t){var r=this,n=this._exporter._extensionsPreExportTextureAsync("exporter",e,t);return n?n.then((function(n){return n?r._exportTextureInfoAsync(n,t):r._exportTextureInfoAsync(e,t)})):this._exportTextureInfoAsync(e,t)},e.prototype._exportTextureInfoAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,i,o,a,s,u,l,c,h,p=this;return x(this,(function(d){switch(d.label){case 0:return(r=e.uid)in this._textureMap?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=d.sent()))return[2,null];if(i=this._exportTextureSampler(e),o=e.mimeType)switch(o){case"image/jpeg":case"image/png":case"image/webp":t=o;break;default:f.Tools.Warn("Unsupported media type: ".concat(o))}return a=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,a[s]||(a[s]={}),void 0===(u=a[s][t])&&(l=e.getSize(),u=g(p,void 0,void 0,(function(){var r;return x(this,(function(i){switch(i.label){case 0:return[4,this._getImageDataAsync(n,l.width,l.height,t)];case 1:return r=i.sent(),[2,this._exportImage(e.name,t,r)]}}))})),a[s][t]=u),h=this._exportTextureInfo,[4,u];case 2:c=h.apply(this,[d.sent(),i,e.coordinatesIndex]),this._textureMap[r]=c,this._exporter._extensionsPostExportTextures("exporter",this._textureMap[r],e),d.label=3;case 3:return[2,this._textureMap[r]]}}))}))},e.prototype._exportImage=function(e,t,r){var n=this._exporter._imageData,i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),o=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp"}}(t),a=i+o;a in n&&(a="".concat(i,"_").concat(f.Tools.RandomId()).concat(o)),n[a]={data:r,mimeType:t};var s=this._exporter._images;return s.push({name:e,uri:a}),s.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,i=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===i&&(i=n.length,n.push({source:e,sampler:t}));var o={index:i};return r&&(o.texCoord=r),o},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e._DielectricSpecular=new f.Color3(.04,.04,.04),e._MaxSpecularPower=1024,e._Epsilon=1e-6,e}(),v=f.Matrix.Compose(new f.Vector3(-1,1,1),f.Quaternion.Identity(),f.Vector3.Zero()),b=new f.Quaternion(0,1,0,0);function A(e,t){if(!(e instanceof f.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(v,f.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof f.Mesh&&e.geometry||e instanceof f.InstancedMesh&&e.sourceMesh.geometry)}var E=function(){function e(e,t){this._extensions={},this._glTF={asset:{generator:"Babylon.js v".concat(f.Engine.Version),version:"2.0"}},(e=e||f.EngineStore.LastCreatedScene)&&(this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._cameras=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._skins=[],this._animations=[],this._imageData={},this._orderedImageData=[],this._options=t||{},this._animationSampleRate=this._options.animationSampleRate||1/60,this._glTFMaterialExporter=new T(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var i=this;if(r>=t.length)return Promise.resolve(e);var o=n(t[r],e);return o?o.then((function(e){return i._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],i=0,o=e._ExtensionNames;i<o.length;i++){var a=o[i];n.push(this._extensions[a])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportMeshPrimitiveAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,i){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,i,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,i){return this._applyExtensions(t,(function(t,o){return t.postExportNodeAsync&&t.postExportNodeAsync(e,o,r,n,i)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var i=[],o=0,a=e._ExtensionNames;o<a.length;o++){var s=a[o],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&i.push.apply(i,u.postExportMaterialAdditionalTextures(t,r,n))}return i},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var i=0,o=e._ExtensionNames;i<o.length;i++){var a=o[i],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var i=n[r],o=this._extensions[i];o.enabled&&t(o)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],i=e._ExtensionFactories[n](this);this._extensions[n]=i}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&f.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,i){switch(t){case f.Material.TriangleFillMode:n||(n=0);for(var o=e.indexStart,a=e.indexStart+e.indexCount;o<a;o+=3){var s=n+4*o,u=i.getUInt32(s+4),l=i.getUInt32(s+8);i.setUInt32(l,s+4),i.setUInt32(u,s+8)}break;case f.Material.TriangleFanDrawMode:o=e.indexStart+e.indexCount-1;for(var c=e.indexStart;o>=c;--o)i.setUInt32(r[o],n),n+=4;break;case f.Material.TriangleStripDrawMode:e.indexCount>=3&&(i.setUInt32(r[e.indexStart+2],n+4),i.setUInt32(r[e.indexStart+1],n+8))}},e.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,i,o){switch(t){case f.Material.TriangleFillMode:this._reorderTriangleFillMode(e,r,n,i,o);break;case f.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,r,n,i,o);break;case f.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,r,n,i,o)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,i){var o=this._getVertexBufferFromMesh(t,e.getMesh());if(o){var a=o.byteStride/f.VertexBuffer.GetTypeByteLength(o.type);if(e.verticesCount%3!=0)f.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var s=[],u=0;switch(t){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:for(var l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*a,s.push(f.Vector3.FromArray(r,u)),s.push(f.Vector3.FromArray(r,u+2*a)),s.push(f.Vector3.FromArray(r,u+a));break;case f.VertexBuffer.TangentKind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*a,s.push(f.Vector4.FromArray(r,u)),s.push(f.Vector4.FromArray(r,u+2*a)),s.push(f.Vector4.FromArray(r,u+a));break;case f.VertexBuffer.ColorKind:var c=o.getSize();for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=c)u=l*a,4===c?(s.push(f.Vector4.FromArray(r,u)),s.push(f.Vector4.FromArray(r,u+2*a)),s.push(f.Vector4.FromArray(r,u+a))):(s.push(f.Vector3.FromArray(r,u)),s.push(f.Vector3.FromArray(r,u+2*a)),s.push(f.Vector3.FromArray(r,u+a)));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*a,s.push(f.Vector2.FromArray(r,u)),s.push(f.Vector2.FromArray(r,u+2*a)),s.push(f.Vector2.FromArray(r,u+a));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,i)}}else f.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(t," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,i){var o=this._getVertexBufferFromMesh(t,e.getMesh());if(o){var a=o.byteStride/f.VertexBuffer.GetTypeByteLength(o.type),s=[],u=0;switch(t){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:u=e.verticesStart,s.push(f.Vector3.FromArray(r,u+2*a)),s.push(f.Vector3.FromArray(r,u+a));break;case f.VertexBuffer.TangentKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(f.Vector4.FromArray(r,u));break;case f.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,4===o.getSize()?s.push(f.Vector4.FromArray(r,u)):s.push(f.Vector3.FromArray(r,u));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(f.Vector2.FromArray(r,u));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n+12,t,i)}else f.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,i){var o=this._getVertexBufferFromMesh(t,e.getMesh());if(o){var a=o.byteStride/f.VertexBuffer.GetTypeByteLength(o.type),s=[],u=0;switch(t){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(f.Vector3.FromArray(r,u));break;case f.VertexBuffer.TangentKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(f.Vector4.FromArray(r,u));break;case f.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(f.Vector4.FromArray(r,u)),4===o.getSize()?s.push(f.Vector4.FromArray(r,u)):s.push(f.Vector3.FromArray(r,u));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*a,s.push(f.Vector2.FromArray(r,u));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,i)}else f.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n){for(var i=0,o=e;i<o.length;i++){var a=o[i];r===f.VertexBuffer.NormalKind?a.normalize():r===f.VertexBuffer.TangentKind&&a instanceof f.Vector4&&d._NormalizeTangentFromRef(a);for(var s=0,u=a.asArray();s<u.length;s++){var l=u[s];n.setFloat32(l,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,i,o){var a,s,u=[];switch(e){case f.VertexBuffer.PositionKind:for(var l=0,c=r.length/n;l<c;++l){a=l*n;var h=f.Vector3.FromArray(r,a);u.push(h.asArray())}break;case f.VertexBuffer.NormalKind:l=0;for(var p=r.length/n;l<p;++l)a=l*n,h=f.Vector3.FromArray(r,a),u.push(h.normalize().asArray());break;case f.VertexBuffer.TangentKind:l=0;for(var _=r.length/n;l<_;++l)a=l*n,h=f.Vector4.FromArray(r,a),d._NormalizeTangentFromRef(h),u.push(h.asArray());break;case f.VertexBuffer.ColorKind:for(var m=o.material,g=!m||"StandardMaterial"===m.getClassName(),x=(h=3===n?new f.Color3:new f.Color4,this._babylonScene.getEngine().useExactSrgbConversions),y=(l=0,r.length/n);l<y;++l)a=l*n,3===n?(f.Color3.FromArrayToRef(r,a,h),g&&h.toLinearSpaceToRef(h,x)):(f.Color4.FromArrayToRef(r,a,h),g&&h.toLinearSpaceToRef(h,x)),u.push(h.asArray());break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:l=0;for(var T=r.length/n;l<T;++l)a=l*n,h=f.Vector2.FromArray(r,a),u.push(h.asArray());break;case f.VertexBuffer.MatricesIndicesKind:case f.VertexBuffer.MatricesIndicesExtraKind:l=0;for(var v=r.length/n;l<v;++l)a=l*n,h=f.Vector4.FromArray(r,a),u.push(h.asArray());break;case f.VertexBuffer.MatricesWeightsKind:case f.VertexBuffer.MatricesWeightsExtraKind:l=0;for(var b=r.length/n;l<b;++l)a=l*n,h=f.Vector4.FromArray(r,a),u.push(h.asArray());break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+e),u=[]}switch(t){case 5121:s=i.setUInt8.bind(i);break;case 5123:s=i.setUInt16.bind(i);break;case 5125:s=i.setUInt32.bind(i);break;case 5126:s=i.setFloat32.bind(i);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,E=u;A<E.length;A++)for(var M=0,F=E[A];M<F.length;M++)s(F[M])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,i,o,a,s){var u,l,c=[],h=new f.Vector3,p=new f.Vector4(0,0,0,0);switch(e){case f.VertexBuffer.PositionKind:for(var _=r.verticesStart;_<r.verticesCount;++_){u=r.indexStart+_*o;var m=f.Vector3.FromArray(n,u);h=(g=f.Vector3.FromArray(i,u)).subtractToRef(m,h),s&&(s.min.copyFromFloats(Math.min(h.x,s.min.x),Math.min(h.y,s.min.y),Math.min(h.z,s.min.z)),s.max.copyFromFloats(Math.max(h.x,s.max.x),Math.max(h.y,s.max.y),Math.max(h.z,s.max.z))),c.push(h.asArray())}break;case f.VertexBuffer.NormalKind:for(_=r.verticesStart;_<r.verticesCount;++_)u=r.indexStart+_*o,m=f.Vector3.FromArray(n,u).normalize(),h=(g=f.Vector3.FromArray(i,u).normalize()).subtractToRef(m,h),c.push(h.asArray());break;case f.VertexBuffer.TangentKind:for(_=r.verticesStart;_<r.verticesCount;++_){u=r.indexStart+_*(o+1),m=f.Vector4.FromArray(n,u),d._NormalizeTangentFromRef(m);var g=f.Vector4.FromArray(i,u);d._NormalizeTangentFromRef(g),p=g.subtractToRef(m,p),c.push([p.x,p.y,p.z])}break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+e),c=[]}switch(t){case 5121:l=a.setUInt8.bind(a);break;case 5123:l=a.setUInt16.bind(a);break;case 5125:l=a.setUInt32.bind(a);break;case 5126:l=a.setFloat32.bind(a);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var x=0,y=c;x<y.length;x++)for(var T=0,v=y[x];T<v.length;T++)l(v[T])},e.prototype._generateJSON=function(e,t,r){var n,i,o,a=this,s={byteLength:this._totalByteLength},u=this._totalByteLength;return s.byteLength&&(this._glTF.buffers=[s]),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&&(e?(this._glTF.images=[],this._images.forEach((function(e){e.uri&&(i=a._imageData[e.uri],a._orderedImageData.push(i),n=e.uri.split(".")[0]+" image",o=d._CreateBufferView(0,u,i.data.byteLength,void 0,n),u+=i.data.byteLength,a._bufferViews.push(o),e.bufferView=a._bufferViews.length-1,e.name=n,e.mimeType=i.mimeType,e.uri=void 0,a._glTF.images||(a._glTF.images=[]),a._glTF.images.push(e))})),s.byteLength=u):this._glTF.images=this._images),e||(s.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype._generateGLTFAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var i=r._generateJSON(!1,e,!0),o=new Blob([n],{type:"application/octet-stream"}),a=e+".gltf",s=e+".bin",u=new m;if(u.glTFFiles[a]=i,u.glTFFiles[s]=o,r._imageData)for(var l in r._imageData)u.glTFFiles[l]=new Blob([r._imageData[l].data],{type:r._imageData[l].mimeType});return t&&r.dispose(),u}))},e.prototype._generateBinaryAsync=function(){var e=this,t=new M(4);return this._createSceneAsync(t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype._generateGLBAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var i,o=r._generateJSON(!0),a=e+".glb",s=o.length,u=0;"undefined"!=typeof TextEncoder&&(s=(i=(new TextEncoder).encode(o)).length);for(var l=0;l<r._orderedImageData.length;++l)u+=r._orderedImageData[l].data.byteLength;var c=r._getPadding(s),f=r._getPadding(n.byteLength),h=r._getPadding(u),p=28+s+c+n.byteLength+f+u+h,d=new ArrayBuffer(12),_=new DataView(d);_.setUint32(0,1179937895,!0),_.setUint32(4,2,!0),_.setUint32(8,p,!0);var g=new ArrayBuffer(8+s+c),x=new DataView(g);x.setUint32(0,s+c,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(g,8);if(i)y.set(i);else{var T="_".charCodeAt(0);for(l=0;l<s;++l){var v=o.charCodeAt(l);v!=o.codePointAt(l)?y[l]=T:y[l]=v}}var b=new Uint8Array(g,8+s);for(l=0;l<c;++l)b[l]=32;var A=new ArrayBuffer(8),E=new DataView(A);E.setUint32(0,n.byteLength+u+h,!0),E.setUint32(4,5130562,!0);var M=new ArrayBuffer(f),F=new Uint8Array(M);for(l=0;l<f;++l)F[l]=0;var w=new ArrayBuffer(h),C=new Uint8Array(w);for(l=0;l<h;++l)C[l]=0;var V=[d,g,A,n];for(l=0;l<r._orderedImageData.length;++l)V.push(r._orderedImageData[l].data);V.push(M),V.push(w);var R=new Blob(V,{type:"application/octet-stream"}),S=new m;return S.glTFFiles[a]=R,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t){t.getPivotPoint().equalsToFloats(0,0,0)||f.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var r=f.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),f.Quaternion.IsIdentity(r)||(e.rotation=r.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t){var r=f.TmpVectors.Vector3[0],n=f.TmpVectors.Quaternion[0];t.getWorldMatrix().decompose(void 0,n,r),r.equalsToFloats(0,0,0)||(e.translation=r.asArray()),n.multiplyInPlace(b),f.Quaternion.IsIdentity(n)||(e.rotation=n.asArray())},e.prototype._getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e,!0)){var r=t.getVertexBuffer(e,!0);if(r)return r}return null},e.prototype._createBufferViewKind=function(e,t,r,n,i){var o=r instanceof f.Mesh?r:r instanceof f.InstancedMesh?r.sourceMesh:null;if(o){var a=o.getVertexBuffer(e,!0),s=o.getVerticesData(e,void 0,void 0,!0);if(a&&s){var u=f.VertexBuffer.GetTypeByteLength(t),l=s.length*u,c=d._CreateBufferView(0,n.getByteOffset(),l,i,e+" - "+o.name);this._bufferViews.push(c),this._writeAttributeData(e,t,s,i/u,n,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n){if(r){t.targets||(t.targets=[]);var i={},o=e.getMesh();if(r.hasNormals){var a=o.getVerticesData(f.VertexBuffer.NormalKind,void 0,void 0,!0),s=r.getNormals(),u=(g=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL");this._bufferViews.push(l);var c=this._bufferViews.length-1,h=d._CreateAccessor(c,r.name+" - NORMAL","VEC3",5126,g,0,null,null);this._accessors.push(h),i.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.NormalKind,5126,e,a,s,x/4,n)}if(r.hasPositions){var p=o.getVerticesData(f.VertexBuffer.PositionKind,void 0,void 0,!0),_=r.getPositions();u=(g=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_POSITION"),this._bufferViews.push(l),c=this._bufferViews.length-1;var m={min:new f.Vector3(1/0,1/0,1/0),max:new f.Vector3(-1/0,-1/0,-1/0)};h=d._CreateAccessor(c,r.name+" - POSITION","VEC3",5126,g,0,null,null),this._accessors.push(h),i.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.PositionKind,5126,e,p,_,x/4,n,m),h.min=m.min.asArray(),h.max=m.max.asArray()}if(r.hasTangents){var g,x,y=o.getVerticesData(f.VertexBuffer.TangentKind,void 0,void 0,!0),T=r.getTangents();u=(g=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL"),this._bufferViews.push(l),c=this._bufferViews.length-1,h=d._CreateAccessor(c,r.name+" - TANGENT","VEC3",5126,g,0,null,null),this._accessors.push(h),i.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.TangentKind,5126,e,y,T,x/4,n)}t.targets.push(i)}},e.prototype._getMeshPrimitiveMode=function(e){if(e instanceof f.LinesMesh)return f.Material.LineListDrawMode;if(e instanceof f.InstancedMesh||e instanceof f.Mesh){var t=e instanceof f.Mesh?e:e.sourceMesh;if("number"==typeof t.overrideRenderingFillMode)return t.overrideRenderingFillMode}return e.material?e.material.fillMode:f.Material.TriangleFillMode},e.prototype._setPrimitiveMode=function(e,t){switch(t){case f.Material.TriangleFillMode:break;case f.Material.TriangleStripDrawMode:e.mode=5;break;case f.Material.TriangleFanDrawMode:e.mode=6;break;case f.Material.PointListDrawMode:case f.Material.PointFillMode:e.mode=0;break;case f.Material.LineLoopDrawMode:e.mode=2;break;case f.Material.LineListDrawMode:e.mode=1;break;case f.Material.LineStripDrawMode:e.mode=3}},e.prototype._setAttributeKind=function(e,t){switch(t){case f.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case f.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case f.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case f.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case f.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case f.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;case f.VertexBuffer.MatricesIndicesKind:e.attributes.JOINTS_0=this._accessors.length-1;break;case f.VertexBuffer.MatricesIndicesExtraKind:e.attributes.JOINTS_1=this._accessors.length-1;break;case f.VertexBuffer.MatricesWeightsKind:e.attributes.WEIGHTS_0=this._accessors.length-1;break;case f.VertexBuffer.MatricesWeightsExtraKind:e.attributes.WEIGHTS_1=this._accessors.length-1;break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},e.prototype._setPrimitiveAttributesAsync=function(e,t,r){var n,i,o=[],a=null;t instanceof f.Mesh?a=t:t instanceof f.InstancedMesh&&(a=t.sourceMesh);var s=[{kind:f.VertexBuffer.PositionKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:f.VertexBuffer.NormalKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:f.VertexBuffer.ColorKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:f.VertexBuffer.TangentKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:f.VertexBuffer.UVKind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:f.VertexBuffer.UV2Kind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:f.VertexBuffer.MatricesIndicesKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:f.VertexBuffer.MatricesIndicesExtraKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:f.VertexBuffer.MatricesWeightsKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:f.VertexBuffer.MatricesWeightsExtraKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16}];if(a){for(var u=null,l=this._getMeshPrimitiveMode(a),c={},h=a.morphTargetManager,p=0,_=s;p<_.length;p++){var m=(G=_[p]).kind,g=G.accessorComponentType;if(a.isVerticesDataPresent(m,!0)){var x=this._getVertexBufferFromMesh(m,a);G.byteStride=x?x.getSize()*f.VertexBuffer.GetTypeByteLength(G.accessorComponentType):4*f.VertexBuffer.DeduceStride(m),12===G.byteStride&&(G.accessorType="VEC3"),this._createBufferViewKind(m,g,t,r,G.byteStride),G.bufferViewIndex=this._bufferViews.length-1,c[m]=G.bufferViewIndex}}if(a.getTotalIndices()){var y=a.getIndices();if(y){var T=4*y.length;n=d._CreateBufferView(0,r.getByteOffset(),T,void 0,"Indices - "+a.name),this._bufferViews.push(n),u=this._bufferViews.length-1;for(var v=0,b=y.length;v<b;++v)r.setUInt32(y[v])}}if(a.subMeshes)for(var A=0,E=a.subMeshes;A<E.length;A++){var M=E[A],F=M.getMaterial()||a.getScene().defaultMaterial,w=null;if(F)if(a instanceof f.LinesMesh){var C={name:a.name+" material"};(!a.color.equals(f.Color3.White())||a.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:a.color.asArray().concat([a.alpha])}),this._materials.push(C),w=this._materials.length-1}else if(F instanceof f.MultiMaterial){var V=F.subMaterials[M.materialIndex];V&&(F=V,w=this._materialMap[F.uniqueId])}else w=this._materialMap[F.uniqueId];var R=null!=w?this._materials[w]:null,S={attributes:{}};this._setPrimitiveMode(S,l);for(var I=0,B=s;I<B.length;I++)if(((m=(G=B[I]).kind)!==f.VertexBuffer.UVKind&&m!==f.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||R&&this._glTFMaterialExporter._hasTexturesPresent(R))&&(D=a.getVerticesData(m,void 0,void 0,!0))&&(x=this._getVertexBufferFromMesh(m,a))){var P=x.getSize(),N=G.bufferViewIndex;if(null!=N){i={min:null,max:null},m==f.VertexBuffer.PositionKind&&(i=d._CalculateMinMaxPositions(D,0,D.length/P));var L=d._CreateAccessor(N,m+" - "+t.name,G.accessorType,G.accessorComponentType,D.length/P,0,i.min,i.max);this._accessors.push(L),this._setAttributeKind(S,m)}}if(u&&(L=d._CreateAccessor(u,"indices - "+t.name,"SCALAR",5125,M.indexCount,4*M.indexStart,null,null),this._accessors.push(L),S.indices=this._accessors.length-1),Object.keys(S.attributes).length>0){if((null!==a.overrideMaterialSideOrientation?a.overrideMaterialSideOrientation:F.sideOrientation)===(this._babylonScene.useRightHandedSystem?f.Material.ClockWiseSideOrientation:f.Material.CounterClockWiseSideOrientation)){var O=null!=u?this._bufferViews[u].byteOffset:null;null==O&&(O=0);var k=null;if(null!=u&&(k=a.getIndices()),k)this._reorderIndicesBasedOnPrimitiveMode(M,l,k,O,r);else for(var U=0,K=s;U<K.length;U++){var D,G=K[U];if(D=a.getVerticesData(G.kind,void 0,void 0,!0)){var z=this._bufferViews[c[G.kind]].byteOffset||0;this._reorderVertexAttributeDataBasedOnPrimitiveMode(M,l,G.kind,D,z,r)}}}null!=w&&(S.material=w)}if(h){e.extras||(e.extras={}),e.extras.targetNames=[];for(var W=0;W<h.numTargets;++W){var q=h.getTarget(W);this._setMorphTargetAttributes(M,S,q,r),e.extras.targetNames.push(q.name)}}e.primitives.push(S),this._extensionsPostExportMeshPrimitiveAsync("postExport",S,M,r),o.push()}}return Promise.all(o).then((function(){}))},e.prototype._createSceneAsync=function(e){var t,r,n,i,o,a=this,s={nodes:[]},u=y(y(y(y([],this._babylonScene.transformNodes,!0),this._babylonScene.meshes,!0),this._babylonScene.lights,!0),this._babylonScene.cameras,!0),l=new Set;if(this._babylonScene.metadata&&(this._options.metadataSelector?s.extras=this._options.metadataSelector(this._babylonScene.metadata):this._babylonScene.metadata.gltf&&(s.extras=this._babylonScene.metadata.gltf.extras)),(null===(r=this._options.removeNoopRootNodes)||void 0===r||r)&&!this._options.includeCoordinateSystemConversionNodes)for(var c=0,h=this._babylonScene.rootNodes;c<h.length;c++){var p=h[c];A(p,this._babylonScene.useRightHandedSystem)&&(l.add(p),u.splice(u.indexOf(p),1))}var d=new Map;this._babylonScene.cameras.forEach((function(e){if(!a._options.shouldExportNode||a._options.shouldExportNode(e)){var t={type:e.mode===f.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(t.name=e.name),"perspective"===t.type)t.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===f.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===t.type){var r=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),n=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();t.orthographic={xmag:r,ymag:n,znear:e.minZ,zfar:e.maxZ}}d.set(e,a._cameras.length),a._cameras.push(t)}}));var _=(t=this._getExportNodes(u))[0],m=t[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(m,"image/png",!0).then((function(){return a._createNodeMapAndAnimationsAsync(_,e).then((function(t){return a._createSkinsAsync(t,e).then((function(r){if(a._nodeMap=t,a._totalByteLength=e.getByteOffset(),null==a._totalByteLength)throw new Error("undefined byte length!");for(var c=0,h=u;c<h.length;c++){var p=h[c];if(void 0!==(n=a._nodeMap[p.uniqueId])&&(i=a._nodes[n],p.metadata&&(a._options.metadataSelector?i.extras=a._options.metadataSelector(p.metadata):p.metadata.gltf&&(i.extras=p.metadata.gltf.extras)),p instanceof f.Camera&&(i.camera=d.get(p)),a._options.shouldExportNode&&!a._options.shouldExportNode(p)?f.Tools.Log("Omitting "+p.name+" from scene."):(p.parent||a._babylonScene.useRightHandedSystem||(y=i,T=void 0,b=void 0,A=void 0,T=f.Vector3.FromArrayToRef(y.translation||[0,0,0],0,f.TmpVectors.Vector3[0]),b=f.Quaternion.FromArrayToRef(y.rotation||[0,0,0,1],0,f.TmpVectors.Quaternion[0]),A=f.Vector3.FromArrayToRef(y.scale||[1,1,1],0,f.TmpVectors.Vector3[1]),f.Matrix.ComposeToRef(A,b,T,f.TmpVectors.Matrix[0]).multiplyToRef(v,f.TmpVectors.Matrix[0]).decompose(A,b,T),T.equalsToFloats(0,0,0)?delete y.translation:y.translation=T.asArray(),f.Quaternion.IsIdentity(b)?delete y.rotation:y.rotation=b.asArray(),A.equalsToFloats(1,1,1)?delete y.scale:y.scale=A.asArray()),p.parent&&!l.has(p.parent)||s.nodes.push(n)),p instanceof f.Mesh&&p.skeleton&&(i.skin=r[p.skeleton.uniqueId]),o=p.getDescendants(!0),!i.children&&o&&o.length)){for(var _=[],m=0,g=o;m<g.length;m++){var x=g[m];null!=a._nodeMap[x.uniqueId]&&_.push(a._nodeMap[x.uniqueId])}_.length&&(i.children=_)}}var y,T,b,A;s.nodes.length&&a._scenes.push(s)}))}))}))},e.prototype._getExportNodes=function(e){for(var t=[],r=new Set,n=0,i=e;n<i.length;n++){var o=i[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(o)){t.push(o);var a=o;if(a.subMeshes&&a.subMeshes.length>0){var s=a.material||a.getScene().defaultMaterial;if(s instanceof f.MultiMaterial)for(var u=0,l=s.subMaterials;u<l.length;u++){var c=l[u];c&&r.add(c)}else r.add(s)}}else"Excluding node ".concat(o.name)}return[t,r]},e.prototype._createNodeMapAndAnimationsAsync=function(e,t){for(var r,n=this,i=Promise.resolve(),o={},a={name:"runtime animations",channels:[],samplers:[]},s=[],u=function(e){i=i.then((function(){return n._createNodeAsync(e,t).then((function(i){var u=n._extensionsPostExportNodeAsync("createNodeAsync",i,e,o,t);return null==u?(f.Tools.Warn("Not exporting node ".concat(e.name)),Promise.resolve()):u.then((function(i){i&&(n._nodes.push(i),r=n._nodes.length-1,o[e.uniqueId]=r,n._babylonScene.animationGroups.length||(_._CreateMorphTargetAnimationFromMorphTargetAnimations(e,a,s,o,n._nodes,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation),e.animations.length&&_._CreateNodeAnimationFromNodeAnimations(e,a,s,o,n._nodes,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation)))}))}))}))},l=0,c=e;l<c.length;l++)u(c[l]);return i.then((function(){return a.channels.length&&a.samplers.length&&n._animations.push(a),s.forEach((function(e){e.channels.length&&e.samplers.length&&n._animations.push(e)})),n._babylonScene.animationGroups.length&&_._CreateNodeAndMorphAnimationFromAnimationGroups(n._babylonScene,n._animations,o,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation),o}))},e.prototype._createNodeAsync=function(e,t){var r=this;return Promise.resolve().then((function(){var n={},i={primitives:[]};if(e.name&&(n.name=e.name),e instanceof f.TransformNode){if(r._setNodeTransformation(n,e),e instanceof f.Mesh){var o=e.morphTargetManager;if(o&&o.numTargets>0){i.weights=[];for(var a=0;a<o.numTargets;++a)i.weights.push(o.getTarget(a).influence)}}return r._setPrimitiveAttributesAsync(i,e,t).then((function(){return i.primitives.length&&(r._meshes.push(i),n.mesh=r._meshes.length-1),n}))}return e instanceof f.Camera?(r._setCameraTransformation(n,e),n):n}))},e.prototype._createSkinsAsync=function(e,t){for(var r,n=Promise.resolve(),i={},o=0,a=this._babylonScene.skeletons;o<a.length;o++){var s=a[o];if(!(s.bones.length<=0)){for(var u={joints:[]},l=[],c={},h=-1,p=0;p<s.bones.length;++p)-1!==(_=null!==(r=(m=s.bones[p]).getIndex())&&void 0!==r?r:p)&&(c[_]=m,_>h&&(h=_));for(var _=0;_<=h;++_){var m=c[_];l.push(m.getInvertedAbsoluteTransform());var g=m.getTransformNode();g&&null!==e[g.uniqueId]&&void 0!==e[g.uniqueId]?u.joints.push(e[g.uniqueId]):f.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}if(u.joints.length>0){var x=64*l.length,y=t.getByteOffset(),T=d._CreateBufferView(0,y,x,void 0,"InverseBindMatrices - "+s.name);this._bufferViews.push(T);var v=this._bufferViews.length-1,b=d._CreateAccessor(v,"InverseBindMatrices - "+s.name,"MAT4",5126,l.length,null,null,null),A=this._accessors.push(b)-1;u.inverseBindMatrices=A,this._skins.push(u),i[s.uniqueId]=this._skins.length-1,l.forEach((function(e){e.m.forEach((function(e){t.setFloat32(e)}))}))}}}return n.then((function(){return i}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),M=function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype._resizeBuffer=function(e){var t=new ArrayBuffer(e),r=Math.min(this._arrayBuffer.byteLength,e),n=new Uint8Array(this._arrayBuffer,0,r);return new Uint8Array(t).set(n,0),this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer),t},e.prototype.getArrayBuffer=function(){return this._resizeBuffer(this.getByteOffset())},e.prototype.getByteOffset=function(){if(null==this._byteOffset)throw new Error("Byte offset is undefined!");return this._byteOffset},e.prototype.setUInt8=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint8(t,e):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset,e),this._byteOffset+=1)},e.prototype.setUInt16=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint16(t,e,!0):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+2>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.getUInt32=function(e){if(e<this._byteOffset)return this._dataView.getUint32(e,!0);throw f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},e.prototype.getVector3Float32FromRef=function(e,t){t+8>this._byteOffset?f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0))},e.prototype.setVector3Float32FromRef=function(e,t){t+8>this._byteOffset?f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0))},e.prototype.getVector4Float32FromRef=function(e,t){t+12>this._byteOffset?f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0),e.w=this._dataView.getFloat32(t+12,!0))},e.prototype.setVector4Float32FromRef=function(e,t){t+12>this._byteOffset?f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0),this._dataView.setFloat32(t+12,e.w,!0))},e.prototype.setFloat32=function(e,t){isNaN(e)&&f.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!")),this._byteOffset+4>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.setUInt32=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint32(t,e,!0):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+4>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4)},e.prototype.setInt16=function(e,t){null!=t?t<this._byteOffset?this._dataView.setInt16(t,e,!0):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+2>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.setByte=function(e,t){null!=t?t<this._byteOffset?this._dataView.setInt8(t,e):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++)},e}(),F=0,w=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new E(e,r)._generateGLTFAsync(n)}))},e._PreExportAsync=function(e,t){return Promise.resolve().then((function(){return t&&t.exportWithoutWaitingForScene?Promise.resolve():e.whenReadyAsync()}))},e._PostExportAsync=function(e,t,r){return Promise.resolve().then((function(){return r&&r.exportWithoutWaitingForScene,t}))},e.GLBAsync=function(e,t,r){var n=this;return this._PreExportAsync(e,r).then((function(){var i=t.replace(/\.[^/.]+$/,"");return new E(e,r)._generateGLBAsync(i).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),C="KHR_texture_transform",V=function(){function e(){this.name=C,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,r){if(r&&(0===r.uAng&&0===r.wAng&&0===r.vAng||0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},i=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],i=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],i=!0),0!==r.wAng&&(n.rotation=-r.wAng,i=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,i=!0),!i)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[C]=n}},e.prototype.preExportTextureAsync=function(e,t){return new Promise((function(r,n){t.getScene()?0!==t.uAng||0!==t.vAng?(f.Tools.Warn("".concat(e,": Texture ").concat(t.name," with rotation in the u or v axis is not supported in glTF.")),r(null)):0===t.wAng||0===t.uRotationCenter&&0===t.vRotationCenter?r(t):(f.Tools.Warn("".concat(e,": Texture ").concat(t.name," with rotation not centered at the origin cannot be exported with ").concat(C)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();E.RegisterExtension(C,(function(){return new V}));var R="KHR_lights_punctual",S=function(){function e(e){this.name=R,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[R]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n){var i=this;return new Promise((function(o){if(t&&r instanceof f.ShadowLight){var a=void 0,s=r.getTypeID()==f.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==f.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==f.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==s)f.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(R));else{if(r.position.equalsToFloats(0,0,0)||(t.translation=r.position.asArray()),"point"!==s){var u=r.direction,l=-Math.atan2(u.z,u.x)+Math.PI/2,c=Math.sqrt(u.x*u.x+u.z*u.z),h=-Math.atan2(u.y,c),p=f.Quaternion.RotationYawPitchRoll(l+Math.PI,h,0);f.Quaternion.IsIdentity(p)||(t.rotation=p.asArray())}if(r.falloffType!==f.Light.FALLOFF_GLTF&&f.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(R," specification!")),a={type:s},r.diffuse.equals(f.Color3.White())||(a.color=r.diffuse.asArray()),1!==r.intensity&&(a.intensity=r.intensity),r.range!==Number.MAX_VALUE&&(a.range=r.range),"spot"===s){var d=r;d.angle!==Math.PI/2&&(null==a.spot&&(a.spot={}),a.spot.outerConeAngle=d.angle/2),0!==d.innerAngle&&(null==a.spot&&(a.spot={}),a.spot.innerConeAngle=d.innerAngle/2)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(a);var _={light:i._lights.lights.length-1},m=r.parent;if(m&&1==m.getChildren().length){var g=i._exporter._nodes[n[m.uniqueId]];if(g){var x=f.Vector3.FromArrayToRef(g.translation||[0,0,0],0,f.TmpVectors.Vector3[0]),y=f.Quaternion.FromArrayToRef(g.rotation||[0,0,0,1],0,f.TmpVectors.Quaternion[0]),T=f.Vector3.FromArrayToRef(g.scale||[1,1,1],0,f.TmpVectors.Vector3[1]),v=f.Matrix.ComposeToRef(T,y,x,f.TmpVectors.Matrix[0]),b=f.Vector3.FromArrayToRef(t.translation||[0,0,0],0,f.TmpVectors.Vector3[2]),A=f.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,f.TmpVectors.Quaternion[1]),E=f.Matrix.ComposeToRef(f.Vector3.OneReadOnly,A,b,f.TmpVectors.Matrix[1]);return v.multiplyToRef(E,E),E.decompose(T,y,x),x.equalsToFloats(0,0,0)?delete g.translation:g.translation=x.asArray(),f.Quaternion.IsIdentity(y)?delete g.rotation:g.rotation=y.asArray(),T.equalsToFloats(1,1,1)?delete g.scale:g.scale=T.asArray(),g.extensions||(g.extensions={}),g.extensions[R]=_,void o(null)}}t.extensions||(t.extensions={}),t.extensions[R]=_}}o(t)}))},e}();E.RegisterExtension(R,(function(e){return new S(e)}));var I="KHR_materials_clearcoat",B=function(){function e(e){this.name=I,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRBaseMaterial&&r.clearCoat.isEnabled?(r.clearCoat.texture&&n.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&n.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&n.push(r.clearCoat.bumpTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i,o=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture);i=r.clearCoat.useRoughnessFromMainTexture?n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture):n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&f.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&f.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var a=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.bumpTexture),s={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=o?o:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=a?a:void 0,hasTextures:function(){return null!==s.clearcoatTexture||null!==s.clearcoatRoughnessTexture||null!==s.clearcoatRoughnessTexture}};t.extensions[I]=s}e(t)}))},e}();E.RegisterExtension(I,(function(e){return new B(e)}));var P="KHR_materials_iridescence",N=function(){function e(e){this.name=P,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRBaseMaterial&&r.iridescence.isEnabled?(r.iridescence.texture&&n.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&n.push(r.iridescence.thicknessTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.texture),o=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.thicknessTexture),a={iridescenceFactor:r.iridescence.intensity,iridescenceIor:r.iridescence.indexOfRefraction,iridescenceThicknessMinimum:r.iridescence.minimumThickness,iridescenceThicknessMaximum:r.iridescence.maximumThickness,iridescenceTexture:null!=i?i:void 0,iridescenceThicknessTexture:null!=o?o:void 0,hasTextures:function(){return null!==a.iridescenceTexture||null!==a.iridescenceThicknessTexture}};t.extensions[P]=a}e(t)}))},e}();E.RegisterExtension(P,(function(e){return new N(e)}));var L="KHR_materials_anisotropy",O=function(){function e(e){this.name=L,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRBaseMaterial&&r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&n.push(r.anisotropy.texture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i=n._exporter._glTFMaterialExporter._getTextureInfo(r.anisotropy.texture),o={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=i?i:void 0,hasTextures:function(){return null!==o.anisotropyTexture}};t.extensions[L]=o}e(t)}))},e}();E.RegisterExtension(L,(function(e){return new O(e)}));var k="KHR_materials_sheen",U=function(){function e(e){this.name=k,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.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof f.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i,o,a,s;if(r instanceof f.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=r.sheen.roughness)&&void 0!==i?i:0,hasTextures:function(){return null!==u.sheenColorTexture||null!==u.sheenRoughnessTexture}};r.sheen.texture&&(u.sheenColorTexture=null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==o?o:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.textureRoughness))&&void 0!==a?a:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==s?s:void 0),t.extensions[k]=u}e(t)}))},e}();E.RegisterExtension(k,(function(e){return new U(e)}));var K="KHR_materials_unlit",D=function(){function e(){this.name=K,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i=!1;r instanceof f.PBRMaterial?i=r.unlit:r instanceof f.StandardMaterial&&(i=r.disableLighting),i&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[K]={}),e(t)}))},e}();E.RegisterExtension(K,(function(){return new D}));var G="KHR_materials_ior",z=function(){function e(){this.name=G,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[G]=i}e(t)}))},e}();E.RegisterExtension(G,(function(e){return new z}));var W="KHR_materials_specular",q=function(){function e(e){this.name=W,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&n.push(r.metallicReflectanceTexture),r.reflectanceTexture&&n.push(r.reflectanceTexture),n):n},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i,o;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var a=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.metallicReflectanceTexture))&&void 0!==i?i:void 0,s=null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(r.reflectanceTexture))&&void 0!==o?o:void 0,u={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:a,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:s,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions[W]=u}e(t)}))},e}();E.RegisterExtension(W,(function(e){return new q(e)}));var H="KHR_materials_volume",j=function(){function e(e){this.name=H,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},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!=f.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o=r.subSurface,a={thicknessFactor:0==o.maximumThickness?void 0:o.maximumThickness,thicknessTexture:null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(o.thicknessTexture))&&void 0!==i?i:void 0,attenuationDistance:o.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:o.tintColorAtDistance,attenuationColor:o.tintColor.equalsFloats(1,1,1)?void 0:o.tintColor.asArray(),hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions[H]=a}e(t)}))},e}();E.RegisterExtension(H,(function(e){return new j(e)}));var Q="KHR_materials_dispersion",Y=function(){function e(){this.name=Q,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Q]=i}e(t)}))},e}();E.RegisterExtension(Q,(function(){return new Y}));var X="KHR_materials_transmission",J=function(){function e(e){this.name=X,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||this._hasTexturesExtension(e)},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.refractionIntensityTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var o=r.subSurface,a={transmissionFactor:0===o.refractionIntensity?void 0:o.refractionIntensity,transmissionTexture:null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(o.refractionIntensityTexture))&&void 0!==i?i:void 0,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions[X]=a}e(t)}))},e}();E.RegisterExtension(X,(function(e){return new J(e)}));var Z="EXT_mesh_gpu_instancing",$=function(){function e(e){this.name=Z,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.postExportNodeAsync=function(e,t,r,n,i){var o=this;return new Promise((function(e){if(t&&r instanceof f.Mesh&&r.hasThinInstances&&i){o._wasUsed=!0;for(var n=f.Vector3.Zero(),a=f.Quaternion.Identity(),s=f.Vector3.One(),u=r.thinInstanceGetWorldMatrices(),l=f.TmpVectors.Vector3[2],c=f.TmpVectors.Quaternion[1],h=f.TmpVectors.Vector3[3],p=!1,d=!1,_=!1,m=new Float32Array(3*r.thinInstanceCount),g=new Float32Array(4*r.thinInstanceCount),x=new Float32Array(3*r.thinInstanceCount),y=0,T=0,v=u;T<v.length;T++)v[T].decompose(h,c,l),m.set(l.asArray(),3*y),g.set(c.normalize().asArray(),4*y),x.set(h.asArray(),3*y),p=p||!l.equalsWithEpsilon(n),d=d||!c.equalsWithEpsilon(a),_=_||!h.equalsWithEpsilon(s),y++;var b={attributes:{}};p&&(b.attributes.TRANSLATION=o._buildAccessor(m,"VEC3",r.thinInstanceCount,i,5126)),d&&(b.attributes.ROTATION=o._buildAccessor(g,"VEC4",r.thinInstanceCount,i,5126)),_&&(b.attributes.SCALE=o._buildAccessor(x,"VEC3",r.thinInstanceCount,i,5126)),t.extensions=t.extensions||{},t.extensions[Z]=b}e(t)}))},e.prototype._buildAccessor=function(e,t,r,n,i){var o=n.getByteOffset();switch(i){case 5126:for(var a=0;a!=e.length;a++)n.setFloat32(e[a]);break;case 5120:for(a=0;a!=e.length;a++)n.setByte(127*e[a]);break;case 5122:for(a=0;a!=e.length;a++)n.setInt16(32767*e[a])}var s={buffer:0,byteOffset:o,byteLength:e.length*f.VertexBuffer.GetTypeByteLength(i)},u=this._exporter._bufferViews.length;this._exporter._bufferViews.push(s);var l=this._exporter._accessors.length,c={bufferView:u,componentType:i,count:r,type:t,normalized:5120==i||5122==i};return this._exporter._accessors.push(c),l},e}();E.RegisterExtension(Z,(function(e){return new $(e)}));var ee="KHR_materials_emissive_strength",te=function(){function e(){this.name=ee,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(!(r instanceof f.PBRMaterial))return e(t);var i=r.emissiveColor.asArray(),o=Math.max.apply(Math,i);if(o>1){n._wasUsed=!0,t.extensions||(t.extensions={});var a={emissiveStrength:o},s=r.emissiveColor.scale(1/a.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[ee]=a}return e(t)}))},e}();E.RegisterExtension(ee,(function(e){return new te}));var re=function(){function e(){}return e.CreateSTL=function(e,t,r,n,i,o,a,s){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===n&&(n=!1),void 0===i&&(i=!0),void 0===o&&(o=!1),void 0===a&&(a=!1),void 0===s&&(s=!1);var u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],i=[new f.Vector3(t[n[0]],t[n[0]+2],t[n[0]+1]),new f.Vector3(t[n[1]],t[n[1]+2],t[n[1]+1]),new f.Vector3(t[n[2]],t[n[2]+2],t[n[2]+1])],o=i[0].subtract(i[1]),a=i[2].subtract(i[1]);return{v:i,n:f.Vector3.Cross(a,o).normalize()}},l=function(e,t,r,n){return t=c(e,t,r.x,n),t=c(e,t,r.y,n),c(e,t,r.z,n)},c=function(e,t,r,n){return e.setFloat32(t,r,n),t+4},h=function(e){if(a){var t=e;e instanceof f.InstancedMesh&&(t=e.sourceMesh);var r=t.getVerticesData(f.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var n=f.Vector3.Zero(),i=void 0;for(i=0;i<r.length;i+=3)f.Vector3.TransformCoordinatesFromFloatsToRef(r[i],r[i+1],r[i+2],e.computeWorldMatrix(!0),n).toArray(r,i);return r}return e.getVerticesData(f.VertexBuffer.PositionKind)||[]};a&&(o=!0);var p="",d=0,_=0;if(n){for(var m=0;m<e.length;m++)d+=(T=(x=e[m]).getIndices())?T.length/3:0;var g=new ArrayBuffer(84+50*d);_+=80,(p=new DataView(g)).setUint32(_,d,i),_+=4}else s||(p="solid stlmesh\r\n");for(m=0;m<e.length;m++){var x=e[m];!n&&s&&(p+="solid "+x.name+"\r\n"),!o&&x instanceof f.Mesh&&x.bakeCurrentTransformIntoVertices();for(var y=h(x),T=x.getIndices()||[],v=0;v<T.length;v+=3){var b=u(T,y,v);n?(_=l(p,_,b.n,i),_=l(p,_,b.v[0],i),_=l(p,_,b.v[1],i),_=l(p,_,b.v[2],i),_+=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")}!n&&s&&(p+="endsolid "+name+"\r\n")}if(n||s||(p+="endsolid stlmesh"),t){var A=document.createElement("a"),E=new Blob([p],{type:"application/octet-stream"});A.href=window.URL.createObjectURL(E),A.download=r+".stl",A.click()}return p},e}(),ne=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==ne){ne.BABYLON=ne.BABYLON||{};var ie=ne.BABYLON;ie.GLTF2=ie.GLTF2||{},ie.GLTF2.Exporter=ie.GLTF2.Exporter||{},ie.GLTF2.Exporter.Extensions=ie.GLTF2.Exporter.Extensions||{};var oe=[];for(var ae in t)ie[ae]=t[ae],oe.push(ae);for(var ae in r)ie[ae]=r[ae],oe.push(ae);for(var ae in o)ie[ae]=o[ae],oe.push(ae);for(var ae in a)ie.GLTF2.Exporter.Extensions[ae]=a[ae],oe.push(ae);for(var ae in s)oe.indexOf(ae)>-1||(ie.GLTF2.Exporter[ae]=s[ae])}var se=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==se)for(var ue in e)se.BABYLON[ue]=e[ue];var le=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==le)for(var ce in u)le.BABYLON[ce]=u[ce];const fe=l})(),i.default})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},r={};function n(e){var i=r[e];if(void 0!==i)return i.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{n.d(i,{default:()=>fe});var e={};n.r(e),n.d(e,{OBJExport:()=>h});var t={};n.r(t),n.d(t,{__IGLTFExporterExtension:()=>p});var r={};n.r(r),n.d(r,{GLTFData:()=>m});var a={};n.r(a),n.d(a,{GLTF2Export:()=>w});var o={};n.r(o),n.d(o,{EXT_mesh_gpu_instancing:()=>$,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>U,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>J,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>V});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>$,GLTF2Export:()=>w,GLTFData:()=>m,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>U,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>J,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>V,_BinaryWriter:()=>M,_Exporter:()=>E,_GLTFAnimation:()=>_,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtensionV2:()=>F});var u={};n.r(u),n.d(u,{STLExport:()=>re});var l={};n.r(l),n.d(l,{EXT_mesh_gpu_instancing:()=>$,GLTF2Export:()=>w,GLTFData:()=>m,KHR_lights_punctual:()=>S,KHR_materials_anisotropy:()=>O,KHR_materials_clearcoat:()=>B,KHR_materials_dispersion:()=>Y,KHR_materials_emissive_strength:()=>te,KHR_materials_ior:()=>z,KHR_materials_iridescence:()=>N,KHR_materials_sheen:()=>U,KHR_materials_specular:()=>q,KHR_materials_transmission:()=>J,KHR_materials_unlit:()=>D,KHR_materials_volume:()=>j,KHR_texture_transform:()=>V,OBJExport:()=>h,STLExport:()=>re,_BinaryWriter:()=>M,_Exporter:()=>E,_GLTFAnimation:()=>_,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtension:()=>p,__IGLTFExporterExtensionV2:()=>F});var c,f=n(597),h=function(){function e(){}return e.OBJ=function(e,t,r,n){var i=[],a=1,o=1;t&&(r||(r="mat"),i.push("mtllib "+r+".mtl"));for(var s=0;s<e.length;s++){var u=e[s].name||"mesh".concat(s,"}");i.push("o ".concat(u));var l=null;if(n){var c=e[s].computeWorldMatrix(!0);l=new f.Matrix,c.invertToRef(l),e[s].bakeTransformIntoVertices(c)}if(t){var h=e[s].material;h&&i.push("usemtl "+h.id)}var p=e[s].geometry;if(p){var d=p.getVerticesData("position"),_=p.getVerticesData("normal"),m=p.getVerticesData("uv"),g=p.getIndices(),x=0,y=0;if(d&&g){for(var T=e[0].getScene().useRightHandedSystem,v=T?1:-1,b=0;b<d.length;b+=3)i.push("v "+d[b]*v+" "+d[b+1]+" "+d[b+2]),x++;if(null!=_)for(b=0;b<_.length;b+=3)i.push("vn "+_[b]*v+" "+_[b+1]+" "+_[b+2]);if(null!=m)for(b=0;b<m.length;b+=2)i.push("vt "+m[b]+" "+m[b+1]),y++;var A=["","",""],E=T?[2,1]:[1,2],M=E[0],F=E[1];for(b=0;b<g.length;b+=3){var w=[String(g[b]+a),String(g[b+M]+a),String(g[b+F]+a)],C=[String(g[b]+o),String(g[b+M]+o),String(g[b+F]+o)],V=w,R=null!=m?C:A,S=null!=_?w:A;i.push("f "+V[0]+"/"+R[0]+"/"+S[0]+" "+V[1]+"/"+R[1]+"/"+S[1]+" "+V[2]+"/"+R[2]+"/"+S[2])}n&&l&&e[s].bakeTransformIntoVertices(l),a+=x,o+=y}else f.Tools.Warn("There are no position vertices or indices on the mesh!")}else f.Tools.Warn("No geometry is present on the mesh")}return i.join("\n")},e.MTL=function(e){var t=[],r=e.material;return t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4)),r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e}(),p=0,d=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,i){var a={buffer:e,byteLength:r};return t&&(a.byteOffset=t),i&&(a.name=i),n&&(a.byteStride=n),a},e._CreateAccessor=function(e,t,r,n,i,a,o,s){var u={name:t,bufferView:e,componentType:n,count:i,type:r};return null!=o&&(u.min=o),null!=s&&(u.max=s),null!=a&&(u.byteOffset=a),u},e._CalculateMinMaxPositions=function(e,t,r){var n,i,a=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];if(r)for(var s=t,u=t+r;s<u;++s){n=3*s,i=f.Vector3.FromArray(e,n).asArray();for(var l=0;l<3;++l){var c=i[l];c<a[l]&&(a[l]=c),c>o[l]&&(o[l]=c),++n}}return{min:a,max:o}},e._NormalizeTangentFromRef=function(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)},e._GetDataAccessorElementCount=function(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}},e}();!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(c||(c={}));var _=function(){function e(){}return e._IsTransformable=function(e){return e&&(e instanceof f.TransformNode||e instanceof f.Camera||e instanceof f.Light)},e._CreateNodeAnimation=function(t,r,n,i,a){if(this._IsTransformable(t)){var o=[],s=[],u=r.getKeys(),l=e._CalculateMinMaxKeyFrames(u),c=e._DeduceInterpolation(u,n,i),h=c.interpolationType,p=c.shouldBakeAnimation;if(p?e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,a,o,s,l,i):"LINEAR"===h||"STEP"===h?e._CreateLinearOrStepAnimation(t,r,n,o,s,i):"CUBICSPLINE"===h?e._CreateCubicSplineAnimation(t,r,n,o,s,i):e._CreateBakedAnimation(t,r,n,l.min,l.max,r.framePerSecond,a,o,s,l,i),o.length&&s.length)return{inputs:o,outputs:s,samplerInterpolation:h,inputsMin:p?l.min:f.Tools.FloatRound(l.min/r.framePerSecond),inputsMax:p?l.max:f.Tools.FloatRound(l.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,i=e.targetProperty.split(".");switch(i[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:f.Tools.Error("Unsupported animatable property ".concat(i[0]))}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(f.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,i,a,o,s,u,l,c){var f;if(e._IsTransformable(t)&&t.animations)for(var h=0,p=t.animations;h<p.length;h++){var d=p[h];if(!c||c(d)){var _=e._DeduceAnimationInfo(d);_&&(f={name:d.name,samplers:[],channels:[]},e._AddAnimation("".concat(d.name),d.hasRunningRuntimeAnimations?r:f,t,d,_.dataAccessorType,_.animationChannelTargetPath,i,o,s,u,_.useQuaternion,l),f.samplers.length&&f.channels.length&&n.push(f))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,i,a,o,s,u,l,c){var h;if(t instanceof f.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var _=0,m=p.getTarget(d).animations;_<m.length;_++){var g=m[_];if(!c||c(g)){for(var x=new f.Animation("".concat(g.name),"influence",g.framePerSecond,g.dataType,g.loopMode,g.enableBlending),y=[],T=g.getKeys(),v=0;v<T.length;++v)for(var b=T[v],A=0;A<p.numTargets;++A)A==d?y.push(b):y.push({frame:b.frame,value:0});x.setKeys(y);var E=e._DeduceAnimationInfo(x);E&&(h={name:x.name,samplers:[],channels:[]},e._AddAnimation(g.name,g.hasRunningRuntimeAnimations?r:h,t,x,E.dataAccessorType,E.animationChannelTargetPath,i,o,s,u,E.useQuaternion,l,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,i,a,o,s,u){var l,c;if(t.animationGroups)for(var h=t.animationGroups,p=function(h){var p=new Map,_=new Map,m=new Set,g=h.to-h.from;c={name:h.name,channels:[],samplers:[]};for(var x=function(r){var g=h.targetedAnimations[r],x=g.target,y=g.animation;if(u&&!u(y))return"continue";if(d._IsTransformable(x)||1===x.length&&d._IsTransformable(x[0])){if(v=e._DeduceAnimationInfo(g.animation)){var T=d._IsTransformable(x)?x:d._IsTransformable(x[0])?x[0]:null;T&&e._AddAnimation("".concat(y.name),c,T,y,v.dataAccessorType,v.animationChannelTargetPath,n,i,a,o,v.useQuaternion,s)}}else if(x instanceof f.MorphTarget||1===x.length&&x[0]instanceof f.MorphTarget){var v;if(v=e._DeduceAnimationInfo(g.animation)){var b=x instanceof f.MorphTarget?x:x[0];if(b){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===b)return!0;return!1}));if(A){var E=t.meshes.find((function(e){return e.morphTargetManager===A}));E&&(p.has(E)||p.set(E,new Map),null===(l=p.get(E))||void 0===l||l.set(b,y),m.add(E),_.set(E,y))}}}}},y=0;y<h.targetedAnimations.length;++y)x(y);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,l=[],d=_.get(t).getKeys(),m=d.length,x=0;x<m;++x)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=p.get(t);if(v){var b=v.get(T);b?(u||(u=new f.Animation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,f.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),l.push(b.getKeys()[x])):l.push({frame:h.from+g/m*x,value:T.influence,inTangent:d[0].inTangent?0:void 0,outTangent:d[0].outTangent?0:void 0})}}u.setKeys(l);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(h.name,"_").concat(t.name,"_MorphWeightAnimation"),c,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,i,a,o,A.useQuaternion,s,null==r?void 0:r.numTargets)})),c.channels.length&&c.samplers.length&&r.push(c)},d=this,_=0,m=h;_<m.length;_++)p(m[_])},e._AddAnimation=function(t,r,n,i,a,o,s,u,l,c,f,h,p){var _,m,g,x,y,T,v,b=e._CreateNodeAnimation(n,i,o,f,h);if(b){if(p){for(var A=0,E=0,M=[];b.inputs.length>0;)E=b.inputs.shift(),A%p==0&&M.push(E),A++;b.inputs=M}var F=s[n.uniqueId],w=4*b.inputs.length;_=d._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(_),b.inputs.forEach((function(e){u.setFloat32(e)})),m=d._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,b.inputs.length,null,[b.inputsMin],[b.inputsMax]),c.push(m),g=c.length-1,y=b.outputs.length,w=4*d._GetDataAccessorElementCount(a)*b.outputs.length,_=d._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(_),b.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),m=d._CreateAccessor(l.length-1,"".concat(t," data"),a,5126,y,null,null,null),c.push(m),x=c.length-1,T={interpolation:b.samplerInterpolation,input:g,output:x},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:F,path:o}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,i,a,o,s,u,l,c,h){var p,d,_=f.Quaternion.Identity(),m=null,g=null,x=null,y=null,T=null,v=null;c.min=f.Tools.FloatRound(i/o);for(var b=r.getKeys(),A=0,E=b.length;A<E;++A){if(v=null,x=b[A],A+1<E)if(y=b[A+1],x.value.equals&&x.value.equals(y.value)||x.value===y.value){if(0!==A)continue;v=x.frame}else v=y.frame;else{if(T=b[A-1],x.value.equals&&x.value.equals(T.value)||x.value===T.value)continue;v=a}if(v)for(var M=x.frame;M<=v;M+=s)if((d=f.Tools.FloatRound(M/o))!==m){m=d,g=d;var F={key:0,repeatCount:0,loopMode:r.loopMode};p=r._interpolate(M,F),e._SetInterpolatedValue(t,p,d,r,n,_,u,l,h)}}g&&(c.max=g)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,i,a){var o=e._GetBasePositionRotationOrScale(r,i,a),s=n.targetProperty.split("."),u=s?s[1]:"",l=a?f.Quaternion.FromArray(o).normalize():f.Vector3.FromArray(o);switch(u){case"x":case"y":case"z":l[u]=t;break;case"w":l.w=t;break;default:f.Tools.Error('glTFAnimation: Unsupported component name "'.concat(u,'"!'))}return l},e._SetInterpolatedValue=function(e,t,r,n,i,a,o,s,u){var l;o.push(r),"weights"!==i?(n.dataType===f.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,i,u)),"rotation"===i?(u?a=t:(l=t,f.Quaternion.RotationYawPitchRollToRef(l.y,l.x,l.z,a)),s.push(a.asArray())):(l=t,s.push(l.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,i,a,o){for(var s=0,u=r.getKeys();s<u.length;s++){var l=u[s];i.push(l.frame/r.framePerSecond),e._AddKeyframeValue(l,r,a,n,t,o)}},e._CreateCubicSplineAnimation=function(t,r,n,i,a,o){r.getKeys().forEach((function(s){i.push(s.frame/r.framePerSecond),e._AddSplineTangent(c.INTANGENT,a,n,"CUBICSPLINE",s,o),e._AddKeyframeValue(s,r,a,n,t,o),e._AddSplineTangent(c.OUTTANGENT,a,n,"CUBICSPLINE",s,o)}))},e._GetBasePositionRotationOrScale=function(e,t,r){var n;if("rotation"===t)if(r){var i=e.rotationQuaternion;n=(null!=i?i:f.Quaternion.Identity()).asArray()}else{var a=e.rotation;n=(null!=a?a:f.Vector3.Zero()).asArray()}else if("translation"===t){var o=e.position;n=(null!=o?o:f.Vector3.Zero()).asArray()}else{var s=e.scaling;n=(null!=s?s:f.Vector3.One()).asArray()}return n},e._AddKeyframeValue=function(e,t,r,n,i,a){var o,s=t.dataType;if(s===f.Animation.ANIMATIONTYPE_VECTOR3){var u=e.value.asArray();if("rotation"===n){var l=f.Vector3.FromArray(u);u=f.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).asArray()}r.push(u)}else if(s===f.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(o=this._ConvertFactorToVector3OrQuaternion(e.value,i,t,n,a)){if("rotation"===n){var c=a?o:f.Quaternion.RotationYawPitchRoll(o.y,o.x,o.z).normalize();r.push(c.asArray())}r.push(o.asArray())}}else s===f.Animation.ANIMATIONTYPE_QUATERNION?r.push(e.value.normalize().asArray()):f.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,i,a=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var o=0,s=e.length;o<s;++o)if((i=e[o]).inTangent||i.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",a=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||i.interpolation&&i.interpolation===f.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=i.interpolation&&i.interpolation===f.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},e._AddSplineTangent=function(e,t,r,n,i,a){var o,s=e===c.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===n){if("rotation"===r)if(s)if(a)o=s.asArray();else{var u=s;o=f.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).asArray()}else o=[0,0,0,0];else o="weights"===r?s?[s]:[0]:s?s.asArray():[0,0,0];t.push(o)}},e._CalculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},e}(),m=function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-1!==e.indexOf(t,e.length-t.length)}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var n=this.glTFFiles[t],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")||e(t,".jpg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],i)),r.click()}},e}();function g(e,t,r,n){return new(r||(r=Promise))((function(i,a){function o(e){try{u(n.next(e))}catch(e){a(e)}}function s(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,s)}u((n=n.apply(e,t||[])).next())}))}function x(e,t){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function y(e,t,r){if(r||2===arguments.length)for(var n,i=0,a=t.length;i<a;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var T=function(){function e(e){this._textureMap={},this._internalTextureToImage={},this._textureMap={},this._exporter=e}return e._FuzzyEquals=function(e,t,r){return f.Scalar.WithinEpsilon(e.r,t.r,r)&&f.Scalar.WithinEpsilon(e.g,t.g,r)&&f.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){var n=this,i=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?i.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?i.push(n._convertPBRMaterialAsync(e,t,r)):f.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(i).then((function(){}))},e.prototype._stripTexturesFromMaterial=function(e){var t={};if(e){t.name=e.name,t.doubleSided=e.doubleSided,t.alphaMode=e.alphaMode,t.alphaCutoff=e.alphaCutoff,t.emissiveFactor=e.emissiveFactor;var r=e.pbrMetallicRoughness;r&&(t.pbrMetallicRoughness={},t.pbrMetallicRoughness.baseColorFactor=r.baseColorFactor,t.pbrMetallicRoughness.metallicFactor=r.metallicFactor,t.pbrMetallicRoughness.roughnessFactor=r.roughnessFactor)}return t},e.prototype._hasTexturesPresent=function(e){var t;if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var r=e.pbrMetallicRoughness;if(r&&(r.baseColorTexture||r.metallicRoughnessTexture))return!0;if(e.extensions)for(var n in e.extensions){var i=e.extensions[n];if(i)return null===(t=i.hasTextures)||void 0===t?void 0:t.call(i)}return!1},e.prototype._getTextureInfo=function(e){if(e){var t=e.uid;if(t in this._textureMap)return this._textureMap[t]}return null},e.prototype._convertToGLTFPBRMetallicRoughness=function(t){var r,n,i,a,o,s,u=new f.Vector2(0,1),l=new f.Vector2(0,.1),c=new f.Vector2(0,.1),h=new f.Vector2(1300,.1),p=t.diffuseColor.toLinearSpace(t.getScene().getEngine().useExactSrgbConversions).scale(.5),d=t.alpha,_=(r=f.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower),n=Math.pow(r/h.x,.333333),i=u.y,a=l.y,o=c.y,s=h.y,(1-n)*(1-n)*(1-n)*i+3*(1-n)*(1-n)*n*a+3*(1-n)*n*n*o+n*n*n*s);return{baseColorFactor:[p.r,p.g,p.b,d],metallicFactor:0,roughnessFactor:_}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,i=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,a=i*i-4*n*(this._DielectricSpecular.r-t);return f.Scalar.Clamp((-i+Math.sqrt(a))/(2*n),0,1)},e._SetAlphaMode=function(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)},e.prototype._convertStandardMaterialAsync=function(t,r,n){var i=this._exporter._materialMap,a=this._exporter._materials,o=[],s=this._convertToGLTFPBRMetallicRoughness(t),u={name:t.name};if(null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||f.Tools.Warn(t.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),u.doubleSided=!0),n){t.diffuseTexture&&o.push(this._exportTextureAsync(t.diffuseTexture,r).then((function(e){e&&(s.baseColorTexture=e)})));var l=t.bumpTexture;l&&o.push(this._exportTextureAsync(l,r).then((function(e){e&&(u.normalTexture=e,1!==l.level&&(u.normalTexture.scale=l.level))}))),t.emissiveTexture&&(u.emissiveFactor=[1,1,1],o.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(u.emissiveTexture=e)})))),t.ambientTexture&&o.push(this._exportTextureAsync(t.ambientTexture,r).then((function(e){if(e){var t={index:e.index};u.occlusionTexture=t}})))}return(t.alpha<1||t.opacityTexture)&&(t.alphaMode===f.Constants.ALPHA_COMBINE?u.alphaMode="BLEND":f.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e._FuzzyEquals(t.emissiveColor,f.Color3.Black(),e._Epsilon)&&(u.emissiveFactor=t.emissiveColor.asArray()),u.pbrMetallicRoughness=s,e._SetAlphaMode(u,t),a.push(u),i[t.uniqueId]=a.length-1,this._finishMaterial(o,u,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var i=this;return Promise.all(e).then((function(){for(var e=null,a=0,o=i._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);a<o.length;a++){var s=o[a];e||(e=[]),e.push(i._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=i._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return g(this,void 0,void 0,(function(){var i,a,o,s,u;return x(this,(function(l){switch(l.label){case 0:return i=f.Constants.TEXTURETYPE_UNSIGNED_INT,a=this._exporter._babylonScene,o=a.getEngine(),s=o.createRawTexture(e,t,r,f.Constants.TEXTUREFORMAT_RGBA,!1,!0,f.Texture.NEAREST_SAMPLINGMODE,null,i),[4,f.TextureTools.ApplyPostProcess("pass",s,a,i,f.Constants.TEXTURE_NEAREST_SAMPLINGMODE,f.Constants.TEXTUREFORMAT_RGBA)];case 1:return l.sent(),[4,o._readTexturePixels(s,t,r)];case 2:return u=l.sent(),[4,f.DumpTools.DumpDataAsync(t,r,u,n,void 0,!0,!0)];case 3:return[2,l.sent()]}}))}))},e.prototype._createWhiteTexture=function(e,t,r){for(var n=new Uint8Array(e*t*4),i=0;i<n.length;i+=4)n[i]=n[i+1]=n[i+2]=n[i+3]=255;return f.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,i,a=e?e.getSize():{width:0,height:0},o=t?t.getSize():{width:0,height:0};return a.width<o.width?(n=e&&e instanceof f.Texture?f.TextureTools.CreateResizedCopy(e,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,r),i=t):a.width>o.width?(i=t&&t instanceof f.Texture?f.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):this._createWhiteTexture(a.width,a.height,r),n=e):(n=e,i=t),{texture1:n,texture2:i}},e.prototype._convertPixelArrayToFloat32=function(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(t,r,n,i){var a;return g(this,void 0,void 0,(function(){var o,s,u,l,c,h,p,d,_,m,g,y,T,v,b,A,E,M,F,w,C,V,R,S,I,B,P,N,L,O,k;return x(this,(function(x){switch(x.label){case 0:return o=new Array,t||r?(s=t?t.getScene():r?r.getScene():null)?(u=this._resizeTexturesToSameDimensions(t,r,s),l=null===(a=u.texture1)||void 0===a?void 0:a.getSize(),c=void 0,h=void 0,p=l.width,d=l.height,[4,u.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return _=x.sent(),[4,u.texture2.readPixels()];case 2:if(m=x.sent(),!_)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(_),!m)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(m),g=h.byteLength,y=new Uint8Array(g),T=new Uint8Array(g),v=f.Color3.Black(),b=0,A=0,B=0;B<d;++B)for(P=0;P<p;++P)E=4*(p*B+P),M=new f.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),F=new f.Color3(h[E],h[E+1],h[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.specularColor),w=h[E+3]*n.glossiness,C={diffuseColor:M,specularColor:F,glossiness:w},V=this._convertSpecularGlossinessToMetallicRoughness(C),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),T[E]=255*V.baseColor.r,T[E+1]=255*V.baseColor.g,T[E+2]=255*V.baseColor.b,T[E+3]=u.texture1.hasAlpha?255*c[E+3]:255,y[E]=0,y[E+1]=255*V.roughness,y[E+2]=255*V.metallic,y[E+3]=255;for(R={baseColor:v,metallic:b,roughness:A},S=!1,I=!1,B=0;B<d;++B)for(P=0;P<p;++P)T[N=4*(p*B+P)]/=R.baseColor.r>e._Epsilon?R.baseColor.r:1,T[N+1]/=R.baseColor.g>e._Epsilon?R.baseColor.g:1,T[N+2]/=R.baseColor.b>e._Epsilon?R.baseColor.b:1,L=f.Color3.FromInts(T[N],T[N+1],T[N+2]),O=L.toGammaSpace(s.getEngine().useExactSrgbConversions),T[N]=255*O.r,T[N+1]=255*O.g,T[N+2]=255*O.b,e._FuzzyEquals(O,f.Color3.White(),e._Epsilon)||(I=!0),y[N+1]/=R.roughness>e._Epsilon?R.roughness:1,y[N+2]/=R.metallic>e._Epsilon?R.metallic:1,k=f.Color3.FromInts(255,y[N+1],y[N+2]),e._FuzzyEquals(k,f.Color3.White(),e._Epsilon)||(S=!0);return S&&o.push(this._getImageDataAsync(y,p,d,i).then((function(e){R.metallicRoughnessTextureData=e}))),I&&o.push(this._getImageDataAsync(T,p,d,i).then((function(e){R.baseColorTextureData=e}))),[2,Promise.all(o).then((function(){return R}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),n=this._getPerceivedBrightness(t.specularColor),i=1-this._getMaxComponent(t.specularColor),a=e._SolveMetallic(r,n,i),o=t.diffuseColor.scale(i/(1-e._DielectricSpecular.r)/Math.max(1-a,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-a)).scale(1/Math.max(a,e._Epsilon)),u=f.Color3.Lerp(o,s,a*a);return{baseColor:u=u.clampToRef(0,1,u),metallic:a,roughness:1-t.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){var i=[],a={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&i.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var o=e._metallicTexture;o&&i.push(this._exportTextureAsync(o,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(i).then((function(){return a}))},e.prototype._getTextureSampler=function(e){var t={};if(!(e&&e instanceof f.Texture))return t;var r=this._getGLTFTextureWrapMode(e.wrapU);10497!==r&&(t.wrapS=r);var n=this._getGLTFTextureWrapMode(e.wrapV);switch(10497!==n&&(t.wrapT=n),e.samplingMode){case f.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case f.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case f.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case f.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case f.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case f.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case f.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case f.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case f.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case f.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case f.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case f.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case f.Texture.WRAP_ADDRESSMODE:return 10497;case f.Texture.CLAMP_ADDRESSMODE:return 33071;case f.Texture.MIRROR_ADDRESSMODE:return 33648;default:return f.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){var i=this;return Promise.resolve().then((function(){var a={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},o=e._albedoTexture,s=e._reflectivityTexture,u=e._useMicroSurfaceFromReflectivityMapAlpha;if(s&&!u)return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");if((o||s)&&n){var l=i._exportTextureSampler(o||s);return i._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(o,s,a,t).then((function(e){var n=i._exporter._textures;if(e.baseColorTextureData){var a=i._exportImage("baseColor".concat(n.length),t,e.baseColorTextureData);r.baseColorTexture=i._exportTextureInfo(a,l,null==o?void 0:o.coordinatesIndex)}return e.metallicRoughnessTextureData&&(a=i._exportImage("metallicRoughness".concat(n.length),t,e.metallicRoughnessTextureData),r.metallicRoughnessTexture=i._exportTextureInfo(a,l,null==s?void 0:s.coordinatesIndex)),e}))}return i._convertSpecularGlossinessToMetallicRoughness(a)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,i={},a={name:e.name};if(e.isMetallicWorkflow()){var o=e._albedoColor,s=e.alpha;return o&&(i.baseColorFactor=[o.r,o.g,o.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(o){return n._setMetallicRoughnessPbrMaterial(o,e,a,i,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(o){return n._setMetallicRoughnessPbrMaterial(o,e,a,i,t,r)}))},e.prototype._setMetallicRoughnessPbrMaterial=function(t,r,n,i,a,o){var s=this._exporter._materialMap,u=this._exporter._materials,l=[];if(t){if(e._SetAlphaMode(n,r),e._FuzzyEquals(t.baseColor,f.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(i.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(i.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(i.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||f.Tools.Warn(r.name+": Back-face culling disabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),o){var c=r._bumpTexture;if(c){var h=this._exportTextureAsync(c,a).then((function(e){e&&(n.normalTexture=e,1!==c.level&&(n.normalTexture.scale=c.level))}));l.push(h)}var p=r._ambientTexture;p&&(h=this._exportTextureAsync(p,a).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=t;var i=r._ambientTextureStrength;i&&(t.strength=i)}})),l.push(h));var d=r._emissiveTexture;d&&(h=this._exportTextureAsync(d,a).then((function(e){e&&(n.emissiveTexture=e)})),l.push(h))}var _=r._emissiveColor;e._FuzzyEquals(_,f.Color3.Black(),e._Epsilon)||(n.emissiveFactor=_.asArray()),n.pbrMetallicRoughness=i,u.push(n),s[r.uniqueId]=u.length-1}return this._finishMaterial(l,n,r,a)},e.prototype._getPixelsFromTexture=function(e){return e.textureType,f.Constants.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},e.prototype._exportTextureAsync=function(e,t){var r=this,n=this._exporter._extensionsPreExportTextureAsync("exporter",e,t);return n?n.then((function(n){return n?r._exportTextureInfoAsync(n,t):r._exportTextureInfoAsync(e,t)})):this._exportTextureInfoAsync(e,t)},e.prototype._exportTextureInfoAsync=function(e,t){return g(this,void 0,void 0,(function(){var r,n,i,a,o,s,u,l,c,h,p=this;return x(this,(function(d){switch(d.label){case 0:return(r=e.uid)in this._textureMap?[3,3]:[4,this._getPixelsFromTexture(e)];case 1:if(!(n=d.sent()))return[2,null];if(i=this._exportTextureSampler(e),a=e.mimeType)switch(a){case"image/jpeg":case"image/png":case"image/webp":t=a;break;default:f.Tools.Warn("Unsupported media type: ".concat(a))}return o=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,o[s]||(o[s]={}),void 0===(u=o[s][t])&&(l=e.getSize(),u=g(p,void 0,void 0,(function(){var r;return x(this,(function(i){switch(i.label){case 0:return[4,this._getImageDataAsync(n,l.width,l.height,t)];case 1:return r=i.sent(),[2,this._exportImage(e.name,t,r)]}}))})),o[s][t]=u),h=this._exportTextureInfo,[4,u];case 2:c=h.apply(this,[d.sent(),i,e.coordinatesIndex]),this._textureMap[r]=c,this._exporter._extensionsPostExportTextures("exporter",this._textureMap[r],e),d.label=3;case 3:return[2,this._textureMap[r]]}}))}))},e.prototype._exportImage=function(e,t,r){var n=this._exporter._imageData,i=e.replace(/\.\/|\/|\.\\|\\/g,"_"),a=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp";case"image/avif":return".avif"}}(t),o=i+a;o in n&&(o="".concat(i,"_").concat(f.Tools.RandomId()).concat(a)),n[o]={data:r,mimeType:t};var s=this._exporter._images;return s.push({name:e,uri:o}),s.length-1},e.prototype._exportTextureInfo=function(e,t,r){var n=this._exporter._textures,i=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===i&&(i=n.length,n.push({source:e,sampler:t}));var a={index:i};return r&&(a.texCoord=r),a},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e._DielectricSpecular=new f.Color3(.04,.04,.04),e._MaxSpecularPower=1024,e._Epsilon=1e-6,e}(),v=f.Matrix.Compose(new f.Vector3(-1,1,1),f.Quaternion.Identity(),f.Vector3.Zero()),b=new f.Quaternion(0,1,0,0);function A(e,t){if(!(e instanceof f.TransformNode))return!1;if(t){if(!e.getWorldMatrix().isIdentity())return!1}else if(!e.getWorldMatrix().multiplyToRef(v,f.TmpVectors.Matrix[0]).isIdentity())return!1;return!(e instanceof f.Mesh&&e.geometry||e instanceof f.InstancedMesh&&e.sourceMesh.geometry)}var E=function(){function e(e,t){this._extensions={},this._glTF={asset:{generator:"Babylon.js v".concat(f.Engine.Version),version:"2.0"}},(e=e||f.EngineStore.LastCreatedScene)&&(this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._cameras=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._skins=[],this._animations=[],this._imageData={},this._orderedImageData=[],this._options=t||{},this._animationSampleRate=this._options.animationSampleRate||1/60,this._glTFMaterialExporter=new T(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var i=this;if(r>=t.length)return Promise.resolve(e);var a=n(t[r],e);return a?a.then((function(e){return i._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],i=0,a=e._ExtensionNames;i<a.length;i++){var o=a[i];n.push(this._extensions[o])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportMeshPrimitiveAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,i){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,i,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,i){return this._applyExtensions(t,(function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,r,n,i)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var i=[],a=0,o=e._ExtensionNames;a<o.length;a++){var s=o[a],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&i.push.apply(i,u.postExportMaterialAdditionalTextures(t,r,n))}return i},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var i=0,a=e._ExtensionNames;i<a.length;i++){var o=a[i],s=this._extensions[o];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var i=n[r],a=this._extensions[i];a.enabled&&t(a)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],i=e._ExtensionFactories[n](this);this._extensions[n]=i}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&f.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,i){switch(t){case f.Material.TriangleFillMode:n||(n=0);for(var a=e.indexStart,o=e.indexStart+e.indexCount;a<o;a+=3){var s=n+4*a,u=i.getUInt32(s+4),l=i.getUInt32(s+8);i.setUInt32(l,s+4),i.setUInt32(u,s+8)}break;case f.Material.TriangleFanDrawMode:a=e.indexStart+e.indexCount-1;for(var c=e.indexStart;a>=c;--a)i.setUInt32(r[a],n),n+=4;break;case f.Material.TriangleStripDrawMode:e.indexCount>=3&&(i.setUInt32(r[e.indexStart+2],n+4),i.setUInt32(r[e.indexStart+1],n+8))}},e.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,i,a){switch(t){case f.Material.TriangleFillMode:this._reorderTriangleFillMode(e,r,n,i,a);break;case f.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,r,n,i,a);break;case f.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,r,n,i,a)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,i){var a=this._getVertexBufferFromMesh(t,e.getMesh());if(a){var o=a.byteStride/f.VertexBuffer.GetTypeByteLength(a.type);if(e.verticesCount%3!=0)f.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var s=[],u=0;switch(t){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:for(var l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(f.Vector3.FromArray(r,u)),s.push(f.Vector3.FromArray(r,u+2*o)),s.push(f.Vector3.FromArray(r,u+o));break;case f.VertexBuffer.TangentKind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(f.Vector4.FromArray(r,u)),s.push(f.Vector4.FromArray(r,u+2*o)),s.push(f.Vector4.FromArray(r,u+o));break;case f.VertexBuffer.ColorKind:var c=a.getSize();for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=c)u=l*o,4===c?(s.push(f.Vector4.FromArray(r,u)),s.push(f.Vector4.FromArray(r,u+2*o)),s.push(f.Vector4.FromArray(r,u+o))):(s.push(f.Vector3.FromArray(r,u)),s.push(f.Vector3.FromArray(r,u+2*o)),s.push(f.Vector3.FromArray(r,u+o)));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(l=e.verticesStart;l<e.verticesStart+e.verticesCount;l+=3)u=l*o,s.push(f.Vector2.FromArray(r,u)),s.push(f.Vector2.FromArray(r,u+2*o)),s.push(f.Vector2.FromArray(r,u+o));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,i)}}else f.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(t," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,i){var a=this._getVertexBufferFromMesh(t,e.getMesh());if(a){var o=a.byteStride/f.VertexBuffer.GetTypeByteLength(a.type),s=[],u=0;switch(t){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:u=e.verticesStart,s.push(f.Vector3.FromArray(r,u+2*o)),s.push(f.Vector3.FromArray(r,u+o));break;case f.VertexBuffer.TangentKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(f.Vector4.FromArray(r,u));break;case f.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,4===a.getSize()?s.push(f.Vector4.FromArray(r,u)):s.push(f.Vector3.FromArray(r,u));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(f.Vector2.FromArray(r,u));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n+12,t,i)}else f.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,i){var a=this._getVertexBufferFromMesh(t,e.getMesh());if(a){var o=a.byteStride/f.VertexBuffer.GetTypeByteLength(a.type),s=[],u=0;switch(t){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:for(var l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(f.Vector3.FromArray(r,u));break;case f.VertexBuffer.TangentKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(f.Vector4.FromArray(r,u));break;case f.VertexBuffer.ColorKind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(f.Vector4.FromArray(r,u)),4===a.getSize()?s.push(f.Vector4.FromArray(r,u)):s.push(f.Vector3.FromArray(r,u));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(l=e.verticesStart+e.verticesCount-1;l>=e.verticesStart;--l)u=l*o,s.push(f.Vector2.FromArray(r,u));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(t))}this._writeVertexAttributeData(s,n,t,i)}else f.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(t," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n){for(var i=0,a=e;i<a.length;i++){var o=a[i];r===f.VertexBuffer.NormalKind?o.normalize():r===f.VertexBuffer.TangentKind&&o instanceof f.Vector4&&d._NormalizeTangentFromRef(o);for(var s=0,u=o.asArray();s<u.length;s++){var l=u[s];n.setFloat32(l,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,i,a){var o,s,u=[];switch(e){case f.VertexBuffer.PositionKind:for(var l=0,c=r.length/n;l<c;++l){o=l*n;var h=f.Vector3.FromArray(r,o);u.push(h.asArray())}break;case f.VertexBuffer.NormalKind:l=0;for(var p=r.length/n;l<p;++l)o=l*n,h=f.Vector3.FromArray(r,o),u.push(h.normalize().asArray());break;case f.VertexBuffer.TangentKind:l=0;for(var _=r.length/n;l<_;++l)o=l*n,h=f.Vector4.FromArray(r,o),d._NormalizeTangentFromRef(h),u.push(h.asArray());break;case f.VertexBuffer.ColorKind:for(var m=a.material,g=!m||"StandardMaterial"===m.getClassName(),x=(h=3===n?new f.Color3:new f.Color4,this._babylonScene.getEngine().useExactSrgbConversions),y=(l=0,r.length/n);l<y;++l)o=l*n,3===n?(f.Color3.FromArrayToRef(r,o,h),g&&h.toLinearSpaceToRef(h,x)):(f.Color4.FromArrayToRef(r,o,h),g&&h.toLinearSpaceToRef(h,x)),u.push(h.asArray());break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:l=0;for(var T=r.length/n;l<T;++l)o=l*n,h=f.Vector2.FromArray(r,o),u.push(h.asArray());break;case f.VertexBuffer.MatricesIndicesKind:case f.VertexBuffer.MatricesIndicesExtraKind:l=0;for(var v=r.length/n;l<v;++l)o=l*n,h=f.Vector4.FromArray(r,o),u.push(h.asArray());break;case f.VertexBuffer.MatricesWeightsKind:case f.VertexBuffer.MatricesWeightsExtraKind:l=0;for(var b=r.length/n;l<b;++l)o=l*n,h=f.Vector4.FromArray(r,o),u.push(h.asArray());break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+e),u=[]}switch(t){case 5121:s=i.setUInt8.bind(i);break;case 5123:s=i.setUInt16.bind(i);break;case 5125:s=i.setUInt32.bind(i);break;case 5126:s=i.setFloat32.bind(i);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,E=u;A<E.length;A++)for(var M=0,F=E[A];M<F.length;M++)s(F[M])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,i,a,o,s){var u,l,c=[],h=new f.Vector3,p=new f.Vector4(0,0,0,0);switch(e){case f.VertexBuffer.PositionKind:for(var _=r.verticesStart;_<r.verticesCount;++_){u=r.indexStart+_*a;var m=f.Vector3.FromArray(n,u);h=(g=f.Vector3.FromArray(i,u)).subtractToRef(m,h),s&&(s.min.copyFromFloats(Math.min(h.x,s.min.x),Math.min(h.y,s.min.y),Math.min(h.z,s.min.z)),s.max.copyFromFloats(Math.max(h.x,s.max.x),Math.max(h.y,s.max.y),Math.max(h.z,s.max.z))),c.push(h.asArray())}break;case f.VertexBuffer.NormalKind:for(_=r.verticesStart;_<r.verticesCount;++_)u=r.indexStart+_*a,m=f.Vector3.FromArray(n,u).normalize(),h=(g=f.Vector3.FromArray(i,u).normalize()).subtractToRef(m,h),c.push(h.asArray());break;case f.VertexBuffer.TangentKind:for(_=r.verticesStart;_<r.verticesCount;++_){u=r.indexStart+_*(a+1),m=f.Vector4.FromArray(n,u),d._NormalizeTangentFromRef(m);var g=f.Vector4.FromArray(i,u);d._NormalizeTangentFromRef(g),p=g.subtractToRef(m,p),c.push([p.x,p.y,p.z])}break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+e),c=[]}switch(t){case 5121:l=o.setUInt8.bind(o);break;case 5123:l=o.setUInt16.bind(o);break;case 5125:l=o.setUInt32.bind(o);break;case 5126:l=o.setFloat32.bind(o);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var x=0,y=c;x<y.length;x++)for(var T=0,v=y[x];T<v.length;T++)l(v[T])},e.prototype._generateJSON=function(e,t,r){var n,i,a,o=this,s={byteLength:this._totalByteLength},u=this._totalByteLength;return s.byteLength&&(this._glTF.buffers=[s]),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&&(e?(this._glTF.images=[],this._images.forEach((function(e){e.uri&&(i=o._imageData[e.uri],o._orderedImageData.push(i),n=e.uri.split(".")[0]+" image",a=d._CreateBufferView(0,u,i.data.byteLength,void 0,n),u+=i.data.byteLength,o._bufferViews.push(a),e.bufferView=o._bufferViews.length-1,e.name=n,e.mimeType=i.mimeType,e.uri=void 0,o._glTF.images||(o._glTF.images=[]),o._glTF.images.push(e))})),s.byteLength=u):this._glTF.images=this._images),e||(s.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype._generateGLTFAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var i=r._generateJSON(!1,e,!0),a=new Blob([n],{type:"application/octet-stream"}),o=e+".gltf",s=e+".bin",u=new m;if(u.glTFFiles[o]=i,u.glTFFiles[s]=a,r._imageData)for(var l in r._imageData)u.glTFFiles[l]=new Blob([r._imageData[l].data],{type:r._imageData[l].mimeType});return t&&r.dispose(),u}))},e.prototype._generateBinaryAsync=function(){var e=this,t=new M(4);return this._createSceneAsync(t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype._generateGLBAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var i,a=r._generateJSON(!0),o=e+".glb",s=a.length,u=0;"undefined"!=typeof TextEncoder&&(s=(i=(new TextEncoder).encode(a)).length);for(var l=0;l<r._orderedImageData.length;++l)u+=r._orderedImageData[l].data.byteLength;var c=r._getPadding(s),f=r._getPadding(n.byteLength),h=r._getPadding(u),p=28+s+c+n.byteLength+f+u+h,d=new ArrayBuffer(12),_=new DataView(d);_.setUint32(0,1179937895,!0),_.setUint32(4,2,!0),_.setUint32(8,p,!0);var g=new ArrayBuffer(8+s+c),x=new DataView(g);x.setUint32(0,s+c,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(g,8);if(i)y.set(i);else{var T="_".charCodeAt(0);for(l=0;l<s;++l){var v=a.charCodeAt(l);v!=a.codePointAt(l)?y[l]=T:y[l]=v}}var b=new Uint8Array(g,8+s);for(l=0;l<c;++l)b[l]=32;var A=new ArrayBuffer(8),E=new DataView(A);E.setUint32(0,n.byteLength+u+h,!0),E.setUint32(4,5130562,!0);var M=new ArrayBuffer(f),F=new Uint8Array(M);for(l=0;l<f;++l)F[l]=0;var w=new ArrayBuffer(h),C=new Uint8Array(w);for(l=0;l<h;++l)C[l]=0;var V=[d,g,A,n];for(l=0;l<r._orderedImageData.length;++l)V.push(r._orderedImageData[l].data);V.push(M),V.push(w);var R=new Blob(V,{type:"application/octet-stream"}),S=new m;return S.glTFFiles[o]=R,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t){t.getPivotPoint().equalsToFloats(0,0,0)||f.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var r=f.Quaternion.FromEulerAngles(t.rotation.x,t.rotation.y,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),f.Quaternion.IsIdentity(r)||(e.rotation=r.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t){var r=f.TmpVectors.Vector3[0],n=f.TmpVectors.Quaternion[0];t.getWorldMatrix().decompose(void 0,n,r),r.equalsToFloats(0,0,0)||(e.translation=r.asArray()),n.multiplyInPlace(b),f.Quaternion.IsIdentity(n)||(e.rotation=n.asArray())},e.prototype._getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e,!0)){var r=t.getVertexBuffer(e,!0);if(r)return r}return null},e.prototype._createBufferViewKind=function(e,t,r,n,i){var a=r instanceof f.Mesh?r:r instanceof f.InstancedMesh?r.sourceMesh:null;if(a){var o=a.getVertexBuffer(e,!0),s=a.getVerticesData(e,void 0,void 0,!0);if(o&&s){var u=f.VertexBuffer.GetTypeByteLength(t),l=s.length*u,c=d._CreateBufferView(0,n.getByteOffset(),l,i,e+" - "+a.name);this._bufferViews.push(c),this._writeAttributeData(e,t,s,i/u,n,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n){if(r){t.targets||(t.targets=[]);var i={},a=e.getMesh();if(r.hasNormals){var o=a.getVerticesData(f.VertexBuffer.NormalKind,void 0,void 0,!0),s=r.getNormals(),u=(g=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL");this._bufferViews.push(l);var c=this._bufferViews.length-1,h=d._CreateAccessor(c,r.name+" - NORMAL","VEC3",5126,g,0,null,null);this._accessors.push(h),i.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.NormalKind,5126,e,o,s,x/4,n)}if(r.hasPositions){var p=a.getVerticesData(f.VertexBuffer.PositionKind,void 0,void 0,!0),_=r.getPositions();u=(g=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_POSITION"),this._bufferViews.push(l),c=this._bufferViews.length-1;var m={min:new f.Vector3(1/0,1/0,1/0),max:new f.Vector3(-1/0,-1/0,-1/0)};h=d._CreateAccessor(c,r.name+" - POSITION","VEC3",5126,g,0,null,null),this._accessors.push(h),i.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.PositionKind,5126,e,p,_,x/4,n,m),h.min=m.min.asArray(),h.max=m.max.asArray()}if(r.hasTangents){var g,x,y=a.getVerticesData(f.VertexBuffer.TangentKind,void 0,void 0,!0),T=r.getTangents();u=(g=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL"),this._bufferViews.push(l),c=this._bufferViews.length-1,h=d._CreateAccessor(c,r.name+" - TANGENT","VEC3",5126,g,0,null,null),this._accessors.push(h),i.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.TangentKind,5126,e,y,T,x/4,n)}t.targets.push(i)}},e.prototype._getMeshPrimitiveMode=function(e){if(e instanceof f.LinesMesh)return f.Material.LineListDrawMode;if(e instanceof f.InstancedMesh||e instanceof f.Mesh){var t=e instanceof f.Mesh?e:e.sourceMesh;if("number"==typeof t.overrideRenderingFillMode)return t.overrideRenderingFillMode}return e.material?e.material.fillMode:f.Material.TriangleFillMode},e.prototype._setPrimitiveMode=function(e,t){switch(t){case f.Material.TriangleFillMode:break;case f.Material.TriangleStripDrawMode:e.mode=5;break;case f.Material.TriangleFanDrawMode:e.mode=6;break;case f.Material.PointListDrawMode:case f.Material.PointFillMode:e.mode=0;break;case f.Material.LineLoopDrawMode:e.mode=2;break;case f.Material.LineListDrawMode:e.mode=1;break;case f.Material.LineStripDrawMode:e.mode=3}},e.prototype._setAttributeKind=function(e,t){switch(t){case f.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case f.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case f.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case f.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case f.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case f.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;case f.VertexBuffer.MatricesIndicesKind:e.attributes.JOINTS_0=this._accessors.length-1;break;case f.VertexBuffer.MatricesIndicesExtraKind:e.attributes.JOINTS_1=this._accessors.length-1;break;case f.VertexBuffer.MatricesWeightsKind:e.attributes.WEIGHTS_0=this._accessors.length-1;break;case f.VertexBuffer.MatricesWeightsExtraKind:e.attributes.WEIGHTS_1=this._accessors.length-1;break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},e.prototype._setPrimitiveAttributesAsync=function(e,t,r){var n,i,a=[],o=null;t instanceof f.Mesh?o=t:t instanceof f.InstancedMesh&&(o=t.sourceMesh);var s=[{kind:f.VertexBuffer.PositionKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:f.VertexBuffer.NormalKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:f.VertexBuffer.ColorKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:f.VertexBuffer.TangentKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:f.VertexBuffer.UVKind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:f.VertexBuffer.UV2Kind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:f.VertexBuffer.MatricesIndicesKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:f.VertexBuffer.MatricesIndicesExtraKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:f.VertexBuffer.MatricesWeightsKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:f.VertexBuffer.MatricesWeightsExtraKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16}];if(o){for(var u=null,l=this._getMeshPrimitiveMode(o),c={},h=o.morphTargetManager,p=0,_=s;p<_.length;p++){var m=(G=_[p]).kind,g=G.accessorComponentType;if(o.isVerticesDataPresent(m,!0)){var x=this._getVertexBufferFromMesh(m,o);G.byteStride=x?x.getSize()*f.VertexBuffer.GetTypeByteLength(G.accessorComponentType):4*f.VertexBuffer.DeduceStride(m),12===G.byteStride&&(G.accessorType="VEC3"),this._createBufferViewKind(m,g,t,r,G.byteStride),G.bufferViewIndex=this._bufferViews.length-1,c[m]=G.bufferViewIndex}}if(o.getTotalIndices()){var y=o.getIndices();if(y){var T=4*y.length;n=d._CreateBufferView(0,r.getByteOffset(),T,void 0,"Indices - "+o.name),this._bufferViews.push(n),u=this._bufferViews.length-1;for(var v=0,b=y.length;v<b;++v)r.setUInt32(y[v])}}if(o.subMeshes)for(var A=0,E=o.subMeshes;A<E.length;A++){var M=E[A],F=M.getMaterial()||o.getScene().defaultMaterial,w=null;if(F)if(o instanceof f.LinesMesh){var C={name:o.name+" material"};(!o.color.equals(f.Color3.White())||o.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:o.color.asArray().concat([o.alpha])}),this._materials.push(C),w=this._materials.length-1}else if(F instanceof f.MultiMaterial){var V=F.subMaterials[M.materialIndex];V&&(F=V,w=this._materialMap[F.uniqueId])}else w=this._materialMap[F.uniqueId];var R=null!=w?this._materials[w]:null,S={attributes:{}};this._setPrimitiveMode(S,l);for(var I=0,B=s;I<B.length;I++)if(((m=(G=B[I]).kind)!==f.VertexBuffer.UVKind&&m!==f.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||R&&this._glTFMaterialExporter._hasTexturesPresent(R))&&(D=o.getVerticesData(m,void 0,void 0,!0))&&(x=this._getVertexBufferFromMesh(m,o))){var P=x.getSize(),N=G.bufferViewIndex;if(null!=N){i={min:null,max:null},m==f.VertexBuffer.PositionKind&&(i=d._CalculateMinMaxPositions(D,0,D.length/P));var L=d._CreateAccessor(N,m+" - "+t.name,G.accessorType,G.accessorComponentType,D.length/P,0,i.min,i.max);this._accessors.push(L),this._setAttributeKind(S,m)}}if(u&&(L=d._CreateAccessor(u,"indices - "+t.name,"SCALAR",5125,M.indexCount,4*M.indexStart,null,null),this._accessors.push(L),S.indices=this._accessors.length-1),Object.keys(S.attributes).length>0){if((null!==o.overrideMaterialSideOrientation?o.overrideMaterialSideOrientation:F.sideOrientation)===(this._babylonScene.useRightHandedSystem?f.Material.ClockWiseSideOrientation:f.Material.CounterClockWiseSideOrientation)){var O=null!=u?this._bufferViews[u].byteOffset:null;null==O&&(O=0);var k=null;if(null!=u&&(k=o.getIndices()),k)this._reorderIndicesBasedOnPrimitiveMode(M,l,k,O,r);else for(var U=0,K=s;U<K.length;U++){var D,G=K[U];if(D=o.getVerticesData(G.kind,void 0,void 0,!0)){var z=this._bufferViews[c[G.kind]].byteOffset||0;this._reorderVertexAttributeDataBasedOnPrimitiveMode(M,l,G.kind,D,z,r)}}}null!=w&&(S.material=w)}if(h){e.extras||(e.extras={}),e.extras.targetNames=[];for(var W=0;W<h.numTargets;++W){var q=h.getTarget(W);this._setMorphTargetAttributes(M,S,q,r),e.extras.targetNames.push(q.name)}}e.primitives.push(S),this._extensionsPostExportMeshPrimitiveAsync("postExport",S,M,r),a.push()}}return Promise.all(a).then((function(){}))},e.prototype._createSceneAsync=function(e){var t,r,n,i,a,o=this,s={nodes:[]},u=y(y(y(y([],this._babylonScene.transformNodes,!0),this._babylonScene.meshes,!0),this._babylonScene.lights,!0),this._babylonScene.cameras,!0),l=new Set;if(this._babylonScene.metadata&&(this._options.metadataSelector?s.extras=this._options.metadataSelector(this._babylonScene.metadata):this._babylonScene.metadata.gltf&&(s.extras=this._babylonScene.metadata.gltf.extras)),(null===(r=this._options.removeNoopRootNodes)||void 0===r||r)&&!this._options.includeCoordinateSystemConversionNodes)for(var c=0,h=this._babylonScene.rootNodes;c<h.length;c++){var p=h[c];A(p,this._babylonScene.useRightHandedSystem)&&(l.add(p),u.splice(u.indexOf(p),1))}var d=new Map;this._babylonScene.cameras.forEach((function(e){if(!o._options.shouldExportNode||o._options.shouldExportNode(e)){var t={type:e.mode===f.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(t.name=e.name),"perspective"===t.type)t.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e.fovMode===f.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e.getEngine().getAspectRatio(e),znear:e.minZ,zfar:e.maxZ};else if("orthographic"===t.type){var r=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),n=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();t.orthographic={xmag:r,ymag:n,znear:e.minZ,zfar:e.maxZ}}d.set(e,o._cameras.length),o._cameras.push(t)}}));var _=(t=this._getExportNodes(u))[0],m=t[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(m,"image/png",!0).then((function(){return o._createNodeMapAndAnimationsAsync(_,e).then((function(t){return o._createSkinsAsync(t,e).then((function(r){if(o._nodeMap=t,o._totalByteLength=e.getByteOffset(),null==o._totalByteLength)throw new Error("undefined byte length!");for(var c=0,h=u;c<h.length;c++){var p=h[c];if(void 0!==(n=o._nodeMap[p.uniqueId])&&(i=o._nodes[n],p.metadata&&(o._options.metadataSelector?i.extras=o._options.metadataSelector(p.metadata):p.metadata.gltf&&(i.extras=p.metadata.gltf.extras)),p instanceof f.Camera&&(i.camera=d.get(p)),o._options.shouldExportNode&&!o._options.shouldExportNode(p)?f.Tools.Log("Omitting "+p.name+" from scene."):(p.parent||o._babylonScene.useRightHandedSystem||(y=i,T=void 0,b=void 0,A=void 0,T=f.Vector3.FromArrayToRef(y.translation||[0,0,0],0,f.TmpVectors.Vector3[0]),b=f.Quaternion.FromArrayToRef(y.rotation||[0,0,0,1],0,f.TmpVectors.Quaternion[0]),A=f.Vector3.FromArrayToRef(y.scale||[1,1,1],0,f.TmpVectors.Vector3[1]),f.Matrix.ComposeToRef(A,b,T,f.TmpVectors.Matrix[0]).multiplyToRef(v,f.TmpVectors.Matrix[0]).decompose(A,b,T),T.equalsToFloats(0,0,0)?delete y.translation:y.translation=T.asArray(),f.Quaternion.IsIdentity(b)?delete y.rotation:y.rotation=b.asArray(),A.equalsToFloats(1,1,1)?delete y.scale:y.scale=A.asArray()),p.parent&&!l.has(p.parent)||s.nodes.push(n)),p instanceof f.Mesh&&p.skeleton&&(i.skin=r[p.skeleton.uniqueId]),a=p.getDescendants(!0),!i.children&&a&&a.length)){for(var _=[],m=0,g=a;m<g.length;m++){var x=g[m];null!=o._nodeMap[x.uniqueId]&&_.push(o._nodeMap[x.uniqueId])}_.length&&(i.children=_)}}var y,T,b,A;s.nodes.length&&o._scenes.push(s)}))}))}))},e.prototype._getExportNodes=function(e){for(var t=[],r=new Set,n=0,i=e;n<i.length;n++){var a=i[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(a)){t.push(a);var o=a;if(o.subMeshes&&o.subMeshes.length>0){var s=o.material||o.getScene().defaultMaterial;if(s instanceof f.MultiMaterial)for(var u=0,l=s.subMaterials;u<l.length;u++){var c=l[u];c&&r.add(c)}else r.add(s)}}else"Excluding node ".concat(a.name)}return[t,r]},e.prototype._createNodeMapAndAnimationsAsync=function(e,t){for(var r,n=this,i=Promise.resolve(),a={},o={name:"runtime animations",channels:[],samplers:[]},s=[],u=function(e){i=i.then((function(){return n._createNodeAsync(e,t).then((function(i){var u=n._extensionsPostExportNodeAsync("createNodeAsync",i,e,a,t);return null==u?(f.Tools.Warn("Not exporting node ".concat(e.name)),Promise.resolve()):u.then((function(i){i&&(n._nodes.push(i),r=n._nodes.length-1,a[e.uniqueId]=r,n._babylonScene.animationGroups.length||(_._CreateMorphTargetAnimationFromMorphTargetAnimations(e,o,s,a,n._nodes,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation),e.animations.length&&_._CreateNodeAnimationFromNodeAnimations(e,o,s,a,n._nodes,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation)))}))}))}))},l=0,c=e;l<c.length;l++)u(c[l]);return i.then((function(){return o.channels.length&&o.samplers.length&&n._animations.push(o),s.forEach((function(e){e.channels.length&&e.samplers.length&&n._animations.push(e)})),n._babylonScene.animationGroups.length&&_._CreateNodeAndMorphAnimationFromAnimationGroups(n._babylonScene,n._animations,a,t,n._bufferViews,n._accessors,n._animationSampleRate,n._options.shouldExportAnimation),a}))},e.prototype._createNodeAsync=function(e,t){var r=this;return Promise.resolve().then((function(){var n={},i={primitives:[]};if(e.name&&(n.name=e.name),e instanceof f.TransformNode){if(r._setNodeTransformation(n,e),e instanceof f.Mesh){var a=e.morphTargetManager;if(a&&a.numTargets>0){i.weights=[];for(var o=0;o<a.numTargets;++o)i.weights.push(a.getTarget(o).influence)}}return r._setPrimitiveAttributesAsync(i,e,t).then((function(){return i.primitives.length&&(r._meshes.push(i),n.mesh=r._meshes.length-1),n}))}return e instanceof f.Camera?(r._setCameraTransformation(n,e),n):n}))},e.prototype._createSkinsAsync=function(e,t){for(var r,n=Promise.resolve(),i={},a=0,o=this._babylonScene.skeletons;a<o.length;a++){var s=o[a];if(!(s.bones.length<=0)){for(var u={joints:[]},l=[],c={},h=-1,p=0;p<s.bones.length;++p)-1!==(_=null!==(r=(m=s.bones[p]).getIndex())&&void 0!==r?r:p)&&(c[_]=m,_>h&&(h=_));for(var _=0;_<=h;++_){var m=c[_];l.push(m.getInvertedAbsoluteTransform());var g=m.getTransformNode();g&&null!==e[g.uniqueId]&&void 0!==e[g.uniqueId]?u.joints.push(e[g.uniqueId]):f.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}if(u.joints.length>0){var x=64*l.length,y=t.getByteOffset(),T=d._CreateBufferView(0,y,x,void 0,"InverseBindMatrices - "+s.name);this._bufferViews.push(T);var v=this._bufferViews.length-1,b=d._CreateAccessor(v,"InverseBindMatrices - "+s.name,"MAT4",5126,l.length,null,null,null),A=this._accessors.push(b)-1;u.inverseBindMatrices=A,this._skins.push(u),i[s.uniqueId]=this._skins.length-1,l.forEach((function(e){e.m.forEach((function(e){t.setFloat32(e)}))}))}}}return n.then((function(){return i}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),M=function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype._resizeBuffer=function(e){var t=new ArrayBuffer(e),r=Math.min(this._arrayBuffer.byteLength,e),n=new Uint8Array(this._arrayBuffer,0,r);return new Uint8Array(t).set(n,0),this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer),t},e.prototype.getArrayBuffer=function(){return this._resizeBuffer(this.getByteOffset())},e.prototype.getByteOffset=function(){if(null==this._byteOffset)throw new Error("Byte offset is undefined!");return this._byteOffset},e.prototype.setUInt8=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint8(t,e):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset,e),this._byteOffset+=1)},e.prototype.setUInt16=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint16(t,e,!0):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+2>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.getUInt32=function(e){if(e<this._byteOffset)return this._dataView.getUint32(e,!0);throw f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},e.prototype.getVector3Float32FromRef=function(e,t){t+8>this._byteOffset?f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0))},e.prototype.setVector3Float32FromRef=function(e,t){t+8>this._byteOffset?f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0))},e.prototype.getVector4Float32FromRef=function(e,t){t+12>this._byteOffset?f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0),e.w=this._dataView.getFloat32(t+12,!0))},e.prototype.setVector4Float32FromRef=function(e,t){t+12>this._byteOffset?f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0),this._dataView.setFloat32(t+12,e.w,!0))},e.prototype.setFloat32=function(e,t){isNaN(e)&&f.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!")),this._byteOffset+4>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.setUInt32=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint32(t,e,!0):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+4>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4)},e.prototype.setInt16=function(e,t){null!=t?t<this._byteOffset?this._dataView.setInt16(t,e,!0):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+2>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setInt16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.setByte=function(e,t){null!=t?t<this._byteOffset?this._dataView.setInt8(t,e):f.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this._resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setInt8(this._byteOffset,e),this._byteOffset++)},e}(),F=0,w=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new E(e,r)._generateGLTFAsync(n)}))},e._PreExportAsync=function(e,t){return Promise.resolve().then((function(){return t&&t.exportWithoutWaitingForScene?Promise.resolve():e.whenReadyAsync()}))},e._PostExportAsync=function(e,t,r){return Promise.resolve().then((function(){return r&&r.exportWithoutWaitingForScene,t}))},e.GLBAsync=function(e,t,r){var n=this;return this._PreExportAsync(e,r).then((function(){var i=t.replace(/\.[^/.]+$/,"");return new E(e,r)._generateGLBAsync(i).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),C="KHR_texture_transform",V=function(){function e(){this.name=C,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportTexture=function(e,t,r){if(r&&(0===r.uAng&&0===r.wAng&&0===r.vAng||0===r.uRotationCenter&&0===r.vRotationCenter)){var n={},i=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],i=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],i=!0),0!==r.wAng&&(n.rotation=-r.wAng,i=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,i=!0),!i)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[C]=n}},e.prototype.preExportTextureAsync=function(e,t){return new Promise((function(r,n){t.getScene()?0!==t.uAng||0!==t.vAng?(f.Tools.Warn("".concat(e,": Texture ").concat(t.name," with rotation in the u or v axis is not supported in glTF.")),r(null)):0===t.wAng||0===t.uRotationCenter&&0===t.vRotationCenter?r(t):(f.Tools.Warn("".concat(e,": Texture ").concat(t.name," with rotation not centered at the origin cannot be exported with ").concat(C)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();E.RegisterExtension(C,(function(){return new V}));var R="KHR_lights_punctual",S=function(){function e(e){this.name=R,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[R]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n){var i=this;return new Promise((function(a){if(t&&r instanceof f.ShadowLight){var o=void 0,s=r.getTypeID()==f.Light.LIGHTTYPEID_POINTLIGHT?"point":r.getTypeID()==f.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":r.getTypeID()==f.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==s)f.Logger.Warn("".concat(e,": Light ").concat(r.name," is not supported in ").concat(R));else{if(r.position.equalsToFloats(0,0,0)||(t.translation=r.position.asArray()),"point"!==s){var u=r.direction,l=-Math.atan2(u.z,u.x)+Math.PI/2,c=Math.sqrt(u.x*u.x+u.z*u.z),h=-Math.atan2(u.y,c),p=f.Quaternion.RotationYawPitchRoll(l+Math.PI,h,0);f.Quaternion.IsIdentity(p)||(t.rotation=p.asArray())}if(r.falloffType!==f.Light.FALLOFF_GLTF&&f.Logger.Warn("".concat(e,": Light falloff for ").concat(r.name," does not match the ").concat(R," specification!")),o={type:s},r.diffuse.equals(f.Color3.White())||(o.color=r.diffuse.asArray()),1!==r.intensity&&(o.intensity=r.intensity),r.range!==Number.MAX_VALUE&&(o.range=r.range),"spot"===s){var d=r;d.angle!==Math.PI/2&&(null==o.spot&&(o.spot={}),o.spot.outerConeAngle=d.angle/2),0!==d.innerAngle&&(null==o.spot&&(o.spot={}),o.spot.innerConeAngle=d.innerAngle/2)}i._lights||(i._lights={lights:[]}),i._lights.lights.push(o);var _={light:i._lights.lights.length-1},m=r.parent;if(m&&1==m.getChildren().length){var g=i._exporter._nodes[n[m.uniqueId]];if(g){var x=f.Vector3.FromArrayToRef(g.translation||[0,0,0],0,f.TmpVectors.Vector3[0]),y=f.Quaternion.FromArrayToRef(g.rotation||[0,0,0,1],0,f.TmpVectors.Quaternion[0]),T=f.Vector3.FromArrayToRef(g.scale||[1,1,1],0,f.TmpVectors.Vector3[1]),v=f.Matrix.ComposeToRef(T,y,x,f.TmpVectors.Matrix[0]),b=f.Vector3.FromArrayToRef(t.translation||[0,0,0],0,f.TmpVectors.Vector3[2]),A=f.Quaternion.FromArrayToRef(t.rotation||[0,0,0,1],0,f.TmpVectors.Quaternion[1]),E=f.Matrix.ComposeToRef(f.Vector3.OneReadOnly,A,b,f.TmpVectors.Matrix[1]);return v.multiplyToRef(E,E),E.decompose(T,y,x),x.equalsToFloats(0,0,0)?delete g.translation:g.translation=x.asArray(),f.Quaternion.IsIdentity(y)?delete g.rotation:g.rotation=y.asArray(),T.equalsToFloats(1,1,1)?delete g.scale:g.scale=T.asArray(),g.extensions||(g.extensions={}),g.extensions[R]=_,void a(null)}}t.extensions||(t.extensions={}),t.extensions[R]=_}}a(t)}))},e}();E.RegisterExtension(R,(function(e){return new S(e)}));var I="KHR_materials_clearcoat",B=function(){function e(e){this.name=I,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRBaseMaterial&&r.clearCoat.isEnabled?(r.clearCoat.texture&&n.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&n.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&n.push(r.clearCoat.bumpTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i,a=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture);i=r.clearCoat.useRoughnessFromMainTexture?n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture):n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&f.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&f.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var o=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.bumpTexture),s={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=a?a:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=i?i:void 0,clearcoatNormalTexture:null!=o?o:void 0,hasTextures:function(){return null!==s.clearcoatTexture||null!==s.clearcoatRoughnessTexture||null!==s.clearcoatRoughnessTexture}};t.extensions[I]=s}e(t)}))},e}();E.RegisterExtension(I,(function(e){return new B(e)}));var P="KHR_materials_iridescence",N=function(){function e(e){this.name=P,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRBaseMaterial&&r.iridescence.isEnabled?(r.iridescence.texture&&n.push(r.iridescence.texture),r.iridescence.thicknessTexture&&r.iridescence.thicknessTexture!==r.iridescence.texture&&n.push(r.iridescence.thicknessTexture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRBaseMaterial){if(!r.iridescence.isEnabled)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.texture),a=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.thicknessTexture),o={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,hasTextures:function(){return null!==o.iridescenceTexture||null!==o.iridescenceThicknessTexture}};t.extensions[P]=o}e(t)}))},e}();E.RegisterExtension(P,(function(e){return new N(e)}));var L="KHR_materials_anisotropy",O=function(){function e(e){this.name=L,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRBaseMaterial&&r.anisotropy.isEnabled&&!r.anisotropy.legacy?(r.anisotropy.texture&&n.push(r.anisotropy.texture),n):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRBaseMaterial){if(!r.anisotropy.isEnabled||r.anisotropy.legacy)return void e(t);n._wasUsed=!0,t.extensions=t.extensions||{};var i=n._exporter._glTFMaterialExporter._getTextureInfo(r.anisotropy.texture),a={anisotropyStrength:r.anisotropy.intensity,anisotropyRotation:r.anisotropy.angle,anisotropyTexture:null!=i?i:void 0,hasTextures:function(){return null!==a.anisotropyTexture}};t.extensions[L]=a}e(t)}))},e}();E.RegisterExtension(L,(function(e){return new O(e)}));var k="KHR_materials_sheen",U=function(){function e(e){this.name=k,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.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof f.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i,a,o,s;if(r instanceof f.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._wasUsed=!0,null==t.extensions&&(t.extensions={});var u={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=r.sheen.roughness)&&void 0!==i?i:0,hasTextures:function(){return null!==u.sheenColorTexture||null!==u.sheenRoughnessTexture}};r.sheen.texture&&(u.sheenColorTexture=null!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==a?a:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?u.sheenRoughnessTexture=null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.textureRoughness))&&void 0!==o?o:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(u.sheenRoughnessTexture=null!==(s=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==s?s:void 0),t.extensions[k]=u}e(t)}))},e}();E.RegisterExtension(k,(function(e){return new U(e)}));var K="KHR_materials_unlit",D=function(){function e(){this.name=K,this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i=!1;r instanceof f.PBRMaterial?i=r.unlit:r instanceof f.StandardMaterial&&(i=r.disableLighting),i&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[K]={}),e(t)}))},e}();E.RegisterExtension(K,(function(){return new D}));var G="KHR_materials_ior",z=function(){function e(){this.name=G,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){return!e.unlit&&null!=e.indexOfRefraction&&1.5!=e.indexOfRefraction},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[G]=i}e(t)}))},e}();E.RegisterExtension(G,(function(e){return new z}));var W="KHR_materials_specular",q=function(){function e(e){this.name=W,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRMaterial&&this._isExtensionEnabled(r)?(r.metallicReflectanceTexture&&n.push(r.metallicReflectanceTexture),r.reflectanceTexture&&n.push(r.reflectanceTexture),n):n},e.prototype._isExtensionEnabled=function(e){return!e.unlit&&(null!=e.metallicF0Factor&&1!=e.metallicF0Factor||null!=e.metallicReflectanceColor&&!e.metallicReflectanceColor.equalsFloats(1,1,1)||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.metallicReflectanceTexture||null!=e.reflectanceTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i,a;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var o=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.metallicReflectanceTexture))&&void 0!==i?i:void 0,s=null!==(a=n._exporter._glTFMaterialExporter._getTextureInfo(r.reflectanceTexture))&&void 0!==a?a:void 0,u={specularFactor:1==r.metallicF0Factor?void 0:r.metallicF0Factor,specularTexture:o,specularColorFactor:r.metallicReflectanceColor.equalsFloats(1,1,1)?void 0:r.metallicReflectanceColor.asArray(),specularColorTexture:s,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions[W]=u}e(t)}))},e}();E.RegisterExtension(W,(function(e){return new q(e)}));var H="KHR_materials_volume",j=function(){function e(e){this.name=H,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},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!=f.Color3.White()||this._hasTexturesExtension(e))},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.thicknessTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,o={thicknessFactor:0==a.maximumThickness?void 0:a.maximumThickness,thicknessTexture:null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(a.thicknessTexture))&&void 0!==i?i:void 0,attenuationDistance:a.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:a.tintColorAtDistance,attenuationColor:a.tintColor.equalsFloats(1,1,1)?void 0:a.tintColor.asArray(),hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions[H]=o}e(t)}))},e}();E.RegisterExtension(H,(function(e){return new j(e)}));var Q="KHR_materials_dispersion",Y=function(){function e(){this.name=Q,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return!(!t.isRefractionEnabled&&!t.isDispersionEnabled)},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i={dispersion:r.subSurface.dispersion};t.extensions=t.extensions||{},t.extensions[Q]=i}e(t)}))},e}();E.RegisterExtension(Q,(function(){return new Y}));var X="KHR_materials_transmission",J=function(){function e(e){this.name=X,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.postExportMaterialAdditionalTextures=function(e,t,r){var n=[];return r instanceof f.PBRMaterial&&this._isExtensionEnabled(r)?(r.subSurface.thicknessTexture&&n.push(r.subSurface.thicknessTexture),n):n},e.prototype._isExtensionEnabled=function(e){if(e.unlit)return!1;var t=e.subSurface;return t.isRefractionEnabled&&null!=t.refractionIntensity&&0!=t.refractionIntensity||this._hasTexturesExtension(e)},e.prototype._hasTexturesExtension=function(e){return null!=e.subSurface.refractionIntensityTexture},e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){var i;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var a=r.subSurface,o={transmissionFactor:0===a.refractionIntensity?void 0:a.refractionIntensity,transmissionTexture:null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(a.refractionIntensityTexture))&&void 0!==i?i:void 0,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions[X]=o}e(t)}))},e}();E.RegisterExtension(X,(function(e){return new J(e)}));var Z="EXT_mesh_gpu_instancing",$=function(){function e(e){this.name=Z,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.postExportNodeAsync=function(e,t,r,n,i){var a=this;return new Promise((function(e){if(t&&r instanceof f.Mesh&&r.hasThinInstances&&i){a._wasUsed=!0;for(var n=f.Vector3.Zero(),o=f.Quaternion.Identity(),s=f.Vector3.One(),u=r.thinInstanceGetWorldMatrices(),l=f.TmpVectors.Vector3[2],c=f.TmpVectors.Quaternion[1],h=f.TmpVectors.Vector3[3],p=!1,d=!1,_=!1,m=new Float32Array(3*r.thinInstanceCount),g=new Float32Array(4*r.thinInstanceCount),x=new Float32Array(3*r.thinInstanceCount),y=0,T=0,v=u;T<v.length;T++)v[T].decompose(h,c,l),m.set(l.asArray(),3*y),g.set(c.normalize().asArray(),4*y),x.set(h.asArray(),3*y),p=p||!l.equalsWithEpsilon(n),d=d||!c.equalsWithEpsilon(o),_=_||!h.equalsWithEpsilon(s),y++;var b={attributes:{}};p&&(b.attributes.TRANSLATION=a._buildAccessor(m,"VEC3",r.thinInstanceCount,i,5126)),d&&(b.attributes.ROTATION=a._buildAccessor(g,"VEC4",r.thinInstanceCount,i,5126)),_&&(b.attributes.SCALE=a._buildAccessor(x,"VEC3",r.thinInstanceCount,i,5126)),t.extensions=t.extensions||{},t.extensions[Z]=b}e(t)}))},e.prototype._buildAccessor=function(e,t,r,n,i){var a=n.getByteOffset();switch(i){case 5126:for(var o=0;o!=e.length;o++)n.setFloat32(e[o]);break;case 5120:for(o=0;o!=e.length;o++)n.setByte(127*e[o]);break;case 5122:for(o=0;o!=e.length;o++)n.setInt16(32767*e[o])}var s={buffer:0,byteOffset:a,byteLength:e.length*f.VertexBuffer.GetTypeByteLength(i)},u=this._exporter._bufferViews.length;this._exporter._bufferViews.push(s);var l=this._exporter._accessors.length,c={bufferView:u,componentType:i,count:r,type:t,normalized:5120==i||5122==i};return this._exporter._accessors.push(c),l},e}();E.RegisterExtension(Z,(function(e){return new $(e)}));var ee="KHR_materials_emissive_strength",te=function(){function e(){this.name=ee,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAsync=function(e,t,r){var n=this;return new Promise((function(e){if(!(r instanceof f.PBRMaterial))return e(t);var i=r.emissiveColor.asArray(),a=Math.max.apply(Math,i);if(a>1){n._wasUsed=!0,t.extensions||(t.extensions={});var o={emissiveStrength:a},s=r.emissiveColor.scale(1/o.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[ee]=o}return e(t)}))},e}();E.RegisterExtension(ee,(function(e){return new te}));var re=function(){function e(){}return e.CreateSTL=function(e,t,r,n,i,a,o,s){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===n&&(n=!1),void 0===i&&(i=!0),void 0===a&&(a=!1),void 0===o&&(o=!1),void 0===s&&(s=!1);var u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],i=[new f.Vector3(t[n[0]],t[n[0]+2],t[n[0]+1]),new f.Vector3(t[n[1]],t[n[1]+2],t[n[1]+1]),new f.Vector3(t[n[2]],t[n[2]+2],t[n[2]+1])],a=i[0].subtract(i[1]),o=i[2].subtract(i[1]);return{v:i,n:f.Vector3.Cross(o,a).normalize()}},l=function(e,t,r,n){return t=c(e,t,r.x,n),t=c(e,t,r.y,n),c(e,t,r.z,n)},c=function(e,t,r,n){return e.setFloat32(t,r,n),t+4},h=function(e){if(o){var t=e;e instanceof f.InstancedMesh&&(t=e.sourceMesh);var r=t.getVerticesData(f.VertexBuffer.PositionKind,!0,!0);if(!r)return[];var n=f.Vector3.Zero(),i=void 0;for(i=0;i<r.length;i+=3)f.Vector3.TransformCoordinatesFromFloatsToRef(r[i],r[i+1],r[i+2],e.computeWorldMatrix(!0),n).toArray(r,i);return r}return e.getVerticesData(f.VertexBuffer.PositionKind)||[]};o&&(a=!0);var p="",d=0,_=0;if(n){for(var m=0;m<e.length;m++)d+=(T=(x=e[m]).getIndices())?T.length/3:0;var g=new ArrayBuffer(84+50*d);_+=80,(p=new DataView(g)).setUint32(_,d,i),_+=4}else s||(p="solid stlmesh\r\n");for(m=0;m<e.length;m++){var x=e[m];!n&&s&&(p+="solid "+x.name+"\r\n"),!a&&x instanceof f.Mesh&&x.bakeCurrentTransformIntoVertices();for(var y=h(x),T=x.getIndices()||[],v=0;v<T.length;v+=3){var b=u(T,y,v);n?(_=l(p,_,b.n,i),_=l(p,_,b.v[0],i),_=l(p,_,b.v[1],i),_=l(p,_,b.v[2],i),_+=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")}!n&&s&&(p+="endsolid "+name+"\r\n")}if(n||s||(p+="endsolid stlmesh"),t){var A=document.createElement("a"),E=new Blob([p],{type:"application/octet-stream"});A.href=window.URL.createObjectURL(E),A.download=r+".stl",A.click()}return p},e}(),ne=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==ne){ne.BABYLON=ne.BABYLON||{};var ie=ne.BABYLON;ie.GLTF2=ie.GLTF2||{},ie.GLTF2.Exporter=ie.GLTF2.Exporter||{},ie.GLTF2.Exporter.Extensions=ie.GLTF2.Exporter.Extensions||{};var ae=[];for(var oe in t)ie[oe]=t[oe],ae.push(oe);for(var oe in r)ie[oe]=r[oe],ae.push(oe);for(var oe in a)ie[oe]=a[oe],ae.push(oe);for(var oe in o)ie.GLTF2.Exporter.Extensions[oe]=o[oe],ae.push(oe);for(var oe in s)ae.indexOf(oe)>-1||(ie.GLTF2.Exporter[oe]=s[oe])}var se=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==se)for(var ue in e)se.BABYLON[ue]=e[ue];var le=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==le)for(var ce in u)le.BABYLON[ce]=u[ce];const fe=l})(),i.default})()));
|
|
2
2
|
//# sourceMappingURL=babylonjs.serializers.min.js.map
|