@vrspace/babylonjs
Version:
vrspace.org babylonjs client
1 lines • 93.2 kB
JavaScript
!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);