babylonjs-serializers 6.4.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babylon.stlSerializer.js +21 -11
- package/babylon.stlSerializer.js.map +1 -1
- package/babylon.stlSerializer.min.js +1 -1
- package/babylon.stlSerializer.min.js.map +1 -1
- package/babylonjs.serializers.d.ts +2 -1
- package/babylonjs.serializers.js +21 -11
- package/babylonjs.serializers.js.map +1 -1
- package/babylonjs.serializers.min.js +1 -1
- package/babylonjs.serializers.min.js.map +1 -1
- package/babylonjs.serializers.module.d.ts +4 -2
- package/package.json +3 -3
|
@@ -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={520:t=>{t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.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 o={};return(()=>{n.d(o,{default:()=>ie});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:()=>g});var i={};n.r(i),n.d(i,{GLTF2Export:()=>F});var a={};n.r(a),n.d(a,{EXT_mesh_gpu_instancing:()=>Q,KHR_lights_punctual:()=>V,KHR_materials_clearcoat:()=>S,KHR_materials_emissive_strength:()=>Y,KHR_materials_ior:()=>U,KHR_materials_iridescence:()=>B,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>W,KHR_materials_unlit:()=>O,KHR_materials_volume:()=>H,KHR_texture_transform:()=>R});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>Q,GLTF2Export:()=>F,GLTFData:()=>g,KHR_lights_punctual:()=>V,KHR_materials_clearcoat:()=>S,KHR_materials_emissive_strength:()=>Y,KHR_materials_ior:()=>U,KHR_materials_iridescence:()=>B,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>W,KHR_materials_unlit:()=>O,KHR_materials_volume:()=>H,KHR_texture_transform:()=>R,_BinaryWriter:()=>A,_Exporter:()=>b,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtensionV2:()=>E});var u={};n.r(u),n.d(u,{STLExport:()=>X});var l={};n.r(l),n.d(l,{EXT_mesh_gpu_instancing:()=>Q,GLTF2Export:()=>F,GLTFData:()=>g,KHR_lights_punctual:()=>V,KHR_materials_clearcoat:()=>S,KHR_materials_emissive_strength:()=>Y,KHR_materials_ior:()=>U,KHR_materials_iridescence:()=>B,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>W,KHR_materials_unlit:()=>O,KHR_materials_volume:()=>H,KHR_texture_transform:()=>R,OBJExport:()=>h,STLExport:()=>X,_BinaryWriter:()=>A,_Exporter:()=>b,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtension:()=>p,__IGLTFExporterExtensionV2:()=>E});var c,f=n(520),h=function(){function e(){}return e.OBJ=function(e,t,r,n){var o=[],i=1,a=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var s=0;s<e.length;s++){o.push("g object"+s),o.push("o object_"+s);var u=null;if(n){var l=e[s].computeWorldMatrix(!0);u=new f.Matrix,l.invertToRef(u),e[s].bakeTransformIntoVertices(l)}if(t){var c=e[s].material;c&&o.push("usemtl "+c.id)}var h=e[s].geometry;if(h){var p=h.getVerticesData("position"),d=h.getVerticesData("normal"),m=h.getVerticesData("uv"),g=h.getIndices(),_=0,x=0;if(p&&g){for(var y=0;y<p.length;y+=3)e[0].getScene().useRightHandedSystem?o.push("v "+p[y]+" "+p[y+1]+" "+p[y+2]):o.push("v "+p[y]+" "+p[y+1]+" "+-p[y+2]),_++;if(null!=d)for(y=0;y<d.length;y+=3)o.push("vn "+d[y]+" "+d[y+1]+" "+d[y+2]);if(null!=m)for(y=0;y<m.length;y+=2)o.push("vt "+m[y]+" "+m[y+1]),x++;for(y=0;y<g.length;y+=3){var T=[String(g[y+2]+i),String(g[y+1]+i),String(g[y]+i)],v=[String(g[y+2]+a),String(g[y+1]+a),String(g[y]+a)],b=["","",""],A=T,E=null!=m?v:b,F=null!=d?T:b;o.push("f "+A[0]+"/"+E[0]+"/"+F[0]+" "+A[1]+"/"+E[1]+"/"+F[1]+" "+A[2]+"/"+E[2]+"/"+F[2])}n&&u&&e[s].bakeTransformIntoVertices(u),i+=_,a+=x}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 o.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,o){var i={buffer:e,byteLength:r};return t&&(i.byteOffset=t),o&&(i.name=o),n&&(i.byteStride=n),i},e._CreateAccessor=function(e,t,r,n,o,i,a,s){var u={name:t,bufferView:e,componentType:n,count:o,type:r};return null!=a&&(u.min=a),null!=s&&(u.max=s),null!=i&&(u.byteOffset=i),u},e._CalculateMinMaxPositions=function(t,r,n,o){var i,a,s,u=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];if(n)for(var c=r,h=r+n;c<h;++c){i=3*c,a=f.Vector3.FromArray(t,i),o&&e._GetRightHandedPositionVector3FromRef(a),s=a.asArray();for(var p=0;p<3;++p){var d=s[p];d<u[p]&&(u[p]=d),d>l[p]&&(l[p]=d),++i}}return{min:u,max:l}},e._GetRightHandedPositionVector3=function(e){return new f.Vector3(e.x,e.y,-e.z)},e._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},e._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedNormalVector3=function(e){return new f.Vector3(e.x,e.y,-e.z)},e._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},e._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},e._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},e._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},e._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},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 m=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,o,i,a){if(this._IsTransformable(t)){var s=[],u=[],l=r.getKeys(),c=e._CalculateMinMaxKeyFrames(l),h=e._DeduceInterpolation(l,n,i),p=c.max-c.min,d=h.interpolationType,m=h.shouldBakeAnimation;if(m?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,u,c,o,i):"LINEAR"===d||"STEP"===d?e._CreateLinearOrStepAnimation(t,r,n,p,s,u,o,i):"CUBICSPLINE"===d?e._CreateCubicSplineAnimation(t,r,n,p,s,u,o,i):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,u,c,o,i),s.length&&u.length)return{inputs:s,outputs:u,samplerInterpolation:d,inputsMin:m?c.min:f.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:m?c.max:f.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[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(o[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,o,i,a,s,u,l,c,f){var h;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!f||f(m)){var g=e._DeduceAnimationInfo(m);g&&(h={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?r:h,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,l,g.useQuaternion,c),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,i,a,s,u,l,c,h){var p;if(t instanceof f.Mesh){var d=t.morphTargetManager;if(d)for(var m=0;m<d.numTargets;++m)for(var g=0,_=d.getTarget(m).animations;g<_.length;g++){var x=_[g];if(!h||h(x)){for(var y=new f.Animation("".concat(x.name),"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),T=[],v=x.getKeys(),b=0;b<v.length;++b)for(var A=v[b],E=0;E<d.numTargets;++E)E==m?T.push(A):T.push({frame:A.frame,value:0});y.setKeys(T);var F=e._DeduceAnimationInfo(y);F&&(p={name:y.name,samplers:[],channels:[]},e._AddAnimation(x.name,x.hasRunningRuntimeAnimations?r:p,t,y,F.dataAccessorType,F.animationChannelTargetPath,o,a,s,u,l,F.useQuaternion,c,d.numTargets),p.samplers.length&&p.channels.length&&n.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,i,a,s,u,l,c){var h,p;if(t.animationGroups)for(var d=t.animationGroups,m=function(o){var d=new Map,m=new Map,_=new Set,x=o.to-o.from;p={name:o.name,channels:[],samplers:[]};for(var y=function(r){var x=o.targetedAnimations[r],y=x.target,T=x.animation;if(c&&!c(T))return"continue";if(g._IsTransformable(y)||1===y.length&&g._IsTransformable(y[0])){if(A=e._DeduceAnimationInfo(x.animation)){var v=g._IsTransformable(y)?y:g._IsTransformable(y[0])?y[0]:null;if(v){var b=u[v.uniqueId];e._AddAnimation("".concat(T.name),p,v,T,A.dataAccessorType,A.animationChannelTargetPath,n,i,a,s,b,A.useQuaternion,l)}}}else if(y instanceof f.MorphTarget||1===y.length&&y[0]instanceof f.MorphTarget){var A;if(A=e._DeduceAnimationInfo(x.animation)){var E=y instanceof f.MorphTarget?y:y[0];if(E){var F=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===E)return!0;return!1}));if(F){var M=t.meshes.find((function(e){return e.morphTargetManager===F}));M&&(d.has(M)||d.set(M,new Map),null===(h=d.get(M))||void 0===h||h.set(E,T),_.add(M),m.set(M,T))}}}}},T=0;T<o.targetedAnimations.length;++T)y(T);_.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],h=m.get(t).getKeys(),g=h.length,_=0;_<g;++_)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=d.get(t);if(v){var b=v.get(T);b?(u||(u=new f.Animation("".concat(o.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,f.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[_])):c.push({frame:o.from+x/g*_,value:T.influence,inTangent:h[0].inTangent?0:void 0,outTangent:h[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(o.name,"_").concat(t.name,"_MorphWeightAnimation"),p,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,i,a,s,!1,A.useQuaternion,l,null==r?void 0:r.numTargets)})),p.channels.length&&p.samplers.length&&r.push(p)},g=this,_=0,x=d;_<x.length;_++)m(x[_])},e._AddAnimation=function(t,r,n,o,i,a,s,u,l,c,f,h,p,m){var g,_,x,y,T,v,b,A=e._CreateNodeAnimation(n,o,a,f,h,p);if(A){if(m){for(var E=0,F=0,M=[];A.inputs.length>0;)F=A.inputs.shift(),E%m==0&&M.push(F),E++;A.inputs=M}var R=s[n.uniqueId],w=4*A.inputs.length;g=d._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(g),A.inputs.forEach((function(e){u.setFloat32(e)})),_=d._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),c.push(_),x=c.length-1,T=A.outputs.length,w=4*d._GetDataAccessorElementCount(i)*A.outputs.length,g=d._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(g),A.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),_=d._CreateAccessor(l.length-1,"".concat(t," data"),i,5126,T,null,null,null),c.push(_),y=c.length-1,v={interpolation:A.samplerInterpolation,input:x,output:y},r.samplers.push(v),b={sampler:r.samplers.length-1,target:{node:R,path:a}},r.channels.push(b)}},e._CreateBakedAnimation=function(t,r,n,o,i,a,s,u,l,c,h,p){var d,m,g=f.Quaternion.Identity(),_=null,x=null,y=null,T=null,v=null,b=null;c.min=f.Tools.FloatRound(o/a);for(var A=r.getKeys(),E=0,F=A.length;E<F;++E){if(b=null,y=A[E],E+1<F)if(T=A[E+1],y.value.equals&&y.value.equals(T.value)||y.value===T.value){if(0!==E)continue;b=y.frame}else b=T.frame;else{if(v=A[E-1],y.value.equals&&y.value.equals(v.value)||y.value===v.value)continue;b=i}if(b)for(var M=y.frame;M<=b;M+=s)if((m=f.Tools.FloatRound(M/a))!==_){_=m,x=m;var R={key:0,repeatCount:0,loopMode:r.loopMode};d=r._interpolate(M,R),e._SetInterpolatedValue(t,d,m,r,n,g,u,l,h,p)}}x&&(c.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,i,a){var s=e._GetBasePositionRotationOrScale(r,o,i,a),u=n.targetProperty.split("."),l=u?u[1]:"",c=a?f.Quaternion.FromArray(s).normalize():f.Vector3.FromArray(s);switch(l){case"x":case"y":c[l]=i&&a&&"scale"!==o?-t:t;break;case"z":c[l]=i&&!a&&"scale"!==o?-t:t;break;case"w":c.w=t;break;default:f.Tools.Error('glTFAnimation: Unsupported component name "'.concat(l,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,i,a,s,u,l){var c;a.push(r),"weights"!==o?(n.dataType===f.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u,l)),"rotation"===o?(l?i=t:(c=t,f.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),u&&(d._GetRightHandedQuaternionFromRef(i),e.parent||(i=f.Quaternion.FromArray([0,1,0,0]).multiply(i))),s.push(i.asArray())):(c=t,u&&"scale"!==o&&(d._GetRightHandedPositionVector3FromRef(c),e.parent||(c.x*=-1,c.z*=-1)),s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,o,i,a,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];i.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,a,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,n,o,i,a,s,u){r.getKeys().forEach((function(l){i.push(l.frame/r.framePerSecond),e._AddSplineTangent(t,c.INTANGENT,a,n,"CUBICSPLINE",l,o,u,s),e._AddKeyframeValue(l,r,a,n,t,s,u),e._AddSplineTangent(t,c.OUTTANGENT,a,n,"CUBICSPLINE",l,o,u,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r,n){var o;if("rotation"===t)if(n){var i=e.rotationQuaternion;o=(null!=i?i:f.Quaternion.Identity()).asArray(),r&&(d._GetRightHandedQuaternionArrayFromRef(o),e.parent||(o=f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(o)).asArray()))}else{var a=e.rotation;o=(null!=a?a:f.Vector3.Zero()).asArray(),d._GetRightHandedNormalArray3FromRef(o)}else if("translation"===t){var s=e.position;o=(null!=s?s:f.Vector3.Zero()).asArray(),r&&d._GetRightHandedPositionArray3FromRef(o)}else{var u=e.scaling;o=(null!=u?u:f.Vector3.One()).asArray()}return o},e._AddKeyframeValue=function(e,t,r,n,o,i,a){var s,u,l=t.dataType;if(l===f.Animation.ANIMATIONTYPE_VECTOR3){if(s=e.value.asArray(),"rotation"===n){var c=f.Vector3.FromArray(s),h=f.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z);i&&(d._GetRightHandedQuaternionFromRef(h),o.parent||(h=f.Quaternion.FromArray([0,1,0,0]).multiply(h))),s=h.asArray()}else"translation"===n&&i&&(d._GetRightHandedNormalArray3FromRef(s),o.parent||(s[0]*=-1,s[2]*=-1));r.push(s)}else if(l===f.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(u=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,i,a)){if("rotation"===n){var p=a?u:f.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).normalize();i&&(d._GetRightHandedQuaternionFromRef(p),o.parent||(p=f.Quaternion.FromArray([0,1,0,0]).multiply(p))),r.push(p.asArray())}else"translation"===n&&i&&(d._GetRightHandedNormalVector3FromRef(u),o.parent||(u.x*=-1,u.z*=-1));r.push(u.asArray())}}else l===f.Animation.ANIMATIONTYPE_QUATERNION?(s=e.value.normalize().asArray(),i&&(d._GetRightHandedQuaternionArrayFromRef(s),o.parent||(s=f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(s)).asArray())),r.push(s)):f.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&o.interpolation===f.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=o.interpolation&&o.interpolation===f.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,o,i,a,s,u){var l,h=t===c.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===o){if("rotation"===n)if(h){if(s)l=h.asArray();else{var p=h;l=f.Quaternion.RotationYawPitchRoll(p.y,p.x,p.z).asArray()}u&&(d._GetRightHandedQuaternionArrayFromRef(l),e.parent||(l=f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(l)).asArray()))}else l=[0,0,0,0];else"weights"===n?l=h?[h]:[0]:h?(l=h.asArray(),u&&"translation"===n&&(d._GetRightHandedPositionArray3FromRef(l),e.parent||(l[0]*=-1,l[2]*=-1))):l=[0,0,0];r.push(l)}},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}(),g=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],o=void 0;e(t,".glb")?o={type:"model/gltf-binary"}:e(t,".bin")?o={type:"application/octet-stream"}:e(t,".gltf")?o={type:"model/gltf+json"}:e(t,".jpeg")||e(t,".jpg")?o={type:"image/jpeg"}:e(t,".png")&&(o={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],o)),r.click()}},e}();function _(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(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,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=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(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=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,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create;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,o=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?o.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?o.push(n._convertPBRMaterialAsync(e,t,r)):f.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(o).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 o=e.extensions[n];if(o)return null===(t=o.hasTextures)||void 0===t?void 0:t.call(o)}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,o,i,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,m=(r=f.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower),n=Math.pow(r/h.x,.333333),o=u.y,i=l.y,a=c.y,s=h.y,(1-n)*(1-n)*(1-n)*o+3*(1-n)*(1-n)*n*i+3*(1-n)*n*n*a+n*n*n*s);return{baseColorFactor:[p.r,p.g,p.b,d],metallicFactor:0,roughnessFactor:m}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,o=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,i=o*o-4*n*(this._DielectricSpecular.r-t);return f.Scalar.Clamp((-o+Math.sqrt(i))/(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 o=this._exporter._materialMap,i=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),i.push(u),o[t.uniqueId]=i.length-1,this._finishMaterial(a,u,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var o=this;return Promise.all(e).then((function(){for(var e=null,i=0,a=o._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);i<a.length;i++){var s=a[i];e||(e=[]),e.push(o._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=o._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return _(this,void 0,void 0,(function(){var o,i,a,s,u;return x(this,(function(l){switch(l.label){case 0:return o=f.Constants.TEXTURETYPE_UNSIGNED_INT,i=this._exporter._babylonScene,a=i.getEngine(),s=a.createRawTexture(e,t,r,f.Constants.TEXTUREFORMAT_RGBA,!1,!0,f.Texture.NEAREST_SAMPLINGMODE,null,o),[4,f.TextureTools.ApplyPostProcess("pass",s,i,o,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),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return f.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,i=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return i.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),o=t):i.width>a.width?(o=t&&t instanceof f.Texture?f.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):this._createWhiteTexture(i.width,i.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},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,o){var i;return _(this,void 0,void 0,(function(){var a,s,u,l,c,h,p,d,m,g,_,y,T,v,b,A,E,F,M,R,w,V,C,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===(i=u.texture1)||void 0===i?void 0:i.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 m=x.sent(),[4,u.texture2.readPixels()];case 2:if(g=x.sent(),!m)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(m),!g)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(g),_=h.byteLength,y=new Uint8Array(_),T=new Uint8Array(_),v=f.Color3.Black(),b=0,A=0,B=0;B<d;++B)for(P=0;P<p;++P)E=4*(p*B+P),F=new f.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),M=new f.Color3(h[E],h[E+1],h[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.specularColor),R=h[E+3]*n.glossiness,w={diffuseColor:F,specularColor:M,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(w),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(C={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)]/=C.baseColor.r>e._Epsilon?C.baseColor.r:1,T[N+1]/=C.baseColor.g>e._Epsilon?C.baseColor.g:1,T[N+2]/=C.baseColor.b>e._Epsilon?C.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]/=C.roughness>e._Epsilon?C.roughness:1,y[N+2]/=C.metallic>e._Epsilon?C.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,o).then((function(e){C.metallicRoughnessTextureData=e}))),I&&a.push(this._getImageDataAsync(T,p,d,o).then((function(e){C.baseColorTextureData=e}))),[2,Promise.all(a).then((function(){return C}))];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),o=1-this._getMaxComponent(t.specularColor),i=e._SolveMetallic(r,n,o),a=t.diffuseColor.scale(o/(1-e._DielectricSpecular.r)/Math.max(1-i,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,e._Epsilon)),u=f.Color3.Lerp(a,s,i*i);return{baseColor:u=u.clampToRef(0,1,u),metallic:i,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 o=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&o.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var a=e._metallicTexture;a&&o.push(this._exportTextureAsync(a,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(o).then((function(){return i}))},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 o=this;return Promise.resolve().then((function(){var i={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=o._exportTextureSampler(a||s);return o._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,s,i,t).then((function(e){var n=o._exporter._textures;if(e.baseColorTextureData){var i=o._exportImage("baseColor".concat(n.length),t,e.baseColorTextureData);r.baseColorTexture=o._exportTextureInfo(i,l,null==a?void 0:a.coordinatesIndex)}return e.metallicRoughnessTextureData&&(i=o._exportImage("metallicRoughness".concat(n.length),t,e.metallicRoughnessTextureData),r.metallicRoughnessTexture=o._exportTextureInfo(i,l,null==s?void 0:s.coordinatesIndex)),e}))}return o._convertSpecularGlossinessToMetallicRoughness(i)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,o={},i={name:e.name};if(e.isMetallicWorkflow()){var a=e._albedoColor,s=e.alpha;return a&&(o.baseColorFactor=[a.r,a.g,a.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,o,r).then((function(a){return n._setMetallicRoughnessPbrMaterial(a,e,i,o,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,o,r).then((function(a){return n._setMetallicRoughnessPbrMaterial(a,e,i,o,t,r)}))},e.prototype._setMetallicRoughnessPbrMaterial=function(t,r,n,o,i,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||(o.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(o.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(o.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,i).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,i).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=t;var o=r._ambientTextureStrength;o&&(t.strength=o)}})),l.push(h));var d=r._emissiveTexture;d&&(h=this._exportTextureAsync(d,i).then((function(e){e&&(n.emissiveTexture=e)})),l.push(h))}var m=r._emissiveColor;e._FuzzyEquals(m,f.Color3.Black(),e._Epsilon)||(n.emissiveFactor=m.asArray()),n.pbrMetallicRoughness=o,u.push(n),s[r.uniqueId]=u.length-1}return this._finishMaterial(l,n,r,i)},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 _(this,void 0,void 0,(function(){var r,n,o,i,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(o=this._exportTextureSampler(e),i=e.mimeType)switch(i){case"image/jpeg":case"image/png":case"image/webp":t=i;break;default:f.Tools.Warn("Unsupported media type: ".concat(i))}return a=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,a[s]||(a[s]={}),void 0===(u=a[s][t])&&(l=e.getSize(),u=_(p,void 0,void 0,(function(){var r;return x(this,(function(o){switch(o.label){case 0:return[4,this._getImageDataAsync(n,l.width,l.height,t)];case 1:return r=o.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(),o,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,o=e.replace(/\.\/|\/|\.\\|\\/g,"_"),i=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp"}}(t),a=o+i;a in n&&(a="".concat(o,"_").concat(f.Tools.RandomId()).concat(i)),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,o=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===o&&(o=n.length,n.push({source:e,sampler:t}));var i={index:o};return r&&(i.texCoord=r),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e._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=function(){function e(e,t){this._includeCoordinateSystemConversionNodes=!1,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=t&&t.animationSampleRate?t.animationSampleRate:1/60,this._includeCoordinateSystemConversionNodes=!(!t||!t.includeCoordinateSystemConversionNodes),this._glTFMaterialExporter=new T(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var o=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return o._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];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,o){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,o,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){return this._applyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,r,n,o)}))},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 o=[],i=0,a=e._ExtensionNames;i<a.length;i++){var s=a[i],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],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 o=n[r],i=this._extensions[o];i.enabled&&t(i)}},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],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,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,o){switch(t){case f.Material.TriangleFillMode:n||(n=0);for(var i=e.indexStart,a=e.indexStart+e.indexCount;i<a;i+=3){var s=n+4*i,u=o.getUInt32(s+4),l=o.getUInt32(s+8);o.setUInt32(l,s+4),o.setUInt32(u,s+8)}break;case f.Material.TriangleFanDrawMode:i=e.indexStart+e.indexCount-1;for(var c=e.indexStart;i>=c;--i)o.setUInt32(r[i],n),n+=4;break;case f.Material.TriangleStripDrawMode:e.indexCount>=3&&(o.setUInt32(r[e.indexStart+2],n+4),o.setUInt32(r[e.indexStart+1],n+8))}},e.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,o,i,a,s){if(s&&r===f.Material.ClockWiseSideOrientation)switch(t){case f.Material.TriangleFillMode:this._reorderTriangleFillMode(e,t,r,n,o,i,a,s);break;case f.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,t,r,n,o,i,a,s);break;case f.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,t,r,n,o,i,a,s)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,o,i,a,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/f.VertexBuffer.GetTypeByteLength(u.type);if(e.verticesCount%3!=0)f.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],h=0;switch(n){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:for(var p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*l,c.push(f.Vector3.FromArray(o,h)),c.push(f.Vector3.FromArray(o,h+2*l)),c.push(f.Vector3.FromArray(o,h+l));break;case f.VertexBuffer.TangentKind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*l,c.push(f.Vector4.FromArray(o,h)),c.push(f.Vector4.FromArray(o,h+2*l)),c.push(f.Vector4.FromArray(o,h+l));break;case f.VertexBuffer.ColorKind:var d=u.getSize();for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=d)h=p*l,4===d?(c.push(f.Vector4.FromArray(o,h)),c.push(f.Vector4.FromArray(o,h+2*l)),c.push(f.Vector4.FromArray(o,h+l))):(c.push(f.Vector3.FromArray(o,h)),c.push(f.Vector3.FromArray(o,h+2*l)),c.push(f.Vector3.FromArray(o,h+l)));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*l,c.push(f.Vector2.FromArray(o,h)),c.push(f.Vector2.FromArray(o,h+2*l)),c.push(f.Vector2.FromArray(o,h+l));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,o,a,s)}}else f.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(n," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,o,i,a,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/f.VertexBuffer.GetTypeByteLength(u.type),c=[],h=0;switch(n){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:h=e.verticesStart,c.push(f.Vector3.FromArray(o,h+2*l)),c.push(f.Vector3.FromArray(o,h+l));break;case f.VertexBuffer.TangentKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector4.FromArray(o,h));break;case f.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,4===u.getSize()?c.push(f.Vector4.FromArray(o,h)):c.push(f.Vector3.FromArray(o,h));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector2.FromArray(o,h));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i+12,n,o,a,s)}else f.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,o,i,a,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/f.VertexBuffer.GetTypeByteLength(u.type),c=[],h=0;switch(n){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector3.FromArray(o,h));break;case f.VertexBuffer.TangentKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector4.FromArray(o,h));break;case f.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector4.FromArray(o,h)),4===u.getSize()?c.push(f.Vector4.FromArray(o,h)):c.push(f.Vector3.FromArray(o,h));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector2.FromArray(o,h));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,o,a,s)}else f.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n,o,i){for(var a=0,s=e;a<s.length;a++){var u=s[a];!i||r===f.VertexBuffer.ColorKind||u instanceof f.Vector2||(u instanceof f.Vector3?r===f.VertexBuffer.NormalKind?d._GetRightHandedNormalVector3FromRef(u):r===f.VertexBuffer.PositionKind?d._GetRightHandedPositionVector3FromRef(u):f.Tools.Error("Unsupported vertex attribute kind!"):d._GetRightHandedVector4FromRef(u)),r===f.VertexBuffer.NormalKind?u.normalize():r===f.VertexBuffer.TangentKind&&u instanceof f.Vector4&&d._NormalizeTangentFromRef(u);for(var l=0,c=u.asArray();l<c.length;l++){var h=c[l];o.setFloat32(h,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,o,i,a){var s,u,l=[];switch(e){case f.VertexBuffer.PositionKind:for(var c=0,h=r.length/n;c<h;++c){s=c*n;var p=f.Vector3.FromArray(r,s);i&&d._GetRightHandedPositionVector3FromRef(p),l.push(p.asArray())}break;case f.VertexBuffer.NormalKind:c=0;for(var m=r.length/n;c<m;++c)s=c*n,p=f.Vector3.FromArray(r,s),i&&d._GetRightHandedNormalVector3FromRef(p),p.normalize(),l.push(p.asArray());break;case f.VertexBuffer.TangentKind:c=0;for(var g=r.length/n;c<g;++c)s=c*n,p=f.Vector4.FromArray(r,s),i&&d._GetRightHandedVector4FromRef(p),d._NormalizeTangentFromRef(p),l.push(p.asArray());break;case f.VertexBuffer.ColorKind:for(var _=a.material,x=!_||"StandardMaterial"===_.getClassName(),y=(p=3===n?new f.Color3:new f.Color4,this._babylonScene.getEngine().useExactSrgbConversions),T=(c=0,r.length/n);c<T;++c)s=c*n,3===n?(f.Color3.FromArrayToRef(r,s,p),x&&p.toLinearSpaceToRef(p,y)):(f.Color4.FromArrayToRef(r,s,p),x&&p.toLinearSpaceToRef(p,y)),l.push(p.asArray());break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:c=0;for(var v=r.length/n;c<v;++c)s=c*n,l.push([r[s],r[s+1]]);break;case f.VertexBuffer.MatricesIndicesKind:case f.VertexBuffer.MatricesIndicesExtraKind:c=0;for(var b=r.length/n;c<b;++c)s=c*n,p=f.Vector4.FromArray(r,s),l.push(p.asArray());break;case f.VertexBuffer.MatricesWeightsKind:case f.VertexBuffer.MatricesWeightsExtraKind:c=0;for(var A=r.length/n;c<A;++c)s=c*n,p=f.Vector4.FromArray(r,s),l.push(p.asArray());break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+e),l=[]}switch(t){case 5121:u=o.setUInt8.bind(o);break;case 5123:u=o.setUInt16.bind(o);break;case 5125:u=o.setUInt32.bind(o);break;case 5126:u=o.setFloat32.bind(o);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var E=0,F=l;E<F.length;E++)for(var M=0,R=F[E];M<R.length;M++)u(R[M])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,o,i,a,s,u,l){var c,h,p=[],m=new f.Vector3,g=new f.Vector4(0,0,0,0);switch(e){case f.VertexBuffer.PositionKind:for(var _=r.verticesStart;_<r.verticesCount;++_){c=r.indexStart+_*a;var x=f.Vector3.FromArray(o,c);m=(y=f.Vector3.FromArray(i,c)).subtractToRef(x,m),u&&d._GetRightHandedPositionVector3FromRef(m),l&&(l.min.copyFromFloats(Math.min(m.x,l.min.x),Math.min(m.y,l.min.y),Math.min(m.z,l.min.z)),l.max.copyFromFloats(Math.max(m.x,l.max.x),Math.max(m.y,l.max.y),Math.max(m.z,l.max.z))),p.push(m.asArray())}break;case f.VertexBuffer.NormalKind:for(_=r.verticesStart;_<r.verticesCount;++_)c=r.indexStart+_*a,(x=f.Vector3.FromArray(o,c)).normalize(),(y=f.Vector3.FromArray(i,c)).normalize(),m=y.subtractToRef(x,m),u&&d._GetRightHandedNormalVector3FromRef(m),p.push(m.asArray());break;case f.VertexBuffer.TangentKind:for(_=r.verticesStart;_<r.verticesCount;++_){c=r.indexStart+_*(a+1),x=f.Vector4.FromArray(o,c),d._NormalizeTangentFromRef(x);var y=f.Vector4.FromArray(i,c);d._NormalizeTangentFromRef(y),g=y.subtractToRef(x,g),u&&d._GetRightHandedVector4FromRef(g),p.push([g.x,g.y,g.z])}break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+e),p=[]}switch(t){case 5121:h=s.setUInt8.bind(s);break;case 5123:h=s.setUInt16.bind(s);break;case 5125:h=s.setUInt32.bind(s);break;case 5126:h=s.setFloat32.bind(s);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var T=0,v=p;T<v.length;T++)for(var b=0,A=v[T];b<A.length;b++)h(A[b])},e.prototype._generateJSON=function(e,t,r){var n,o,i,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&&(o=a._imageData[e.uri],a._orderedImageData.push(o),n=e.uri.split(".")[0]+" image",i=d._CreateBufferView(0,u,o.data.byteLength,void 0,n),u+=o.data.byteLength,a._bufferViews.push(i),e.bufferView=a._bufferViews.length-1,e.name=n,e.mimeType=o.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 o=r._generateJSON(!1,e,!0),i=new Blob([n],{type:"application/octet-stream"}),a=e+".gltf",s=e+".bin",u=new g;if(u.glTFFiles[a]=o,u.glTFFiles[s]=i,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 A(4);return this._createSceneAsync(this._babylonScene,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 o,i=r._generateJSON(!0),a=e+".glb",s=i.length,u=0;"undefined"!=typeof TextEncoder&&(s=(o=(new TextEncoder).encode(i)).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),m=new DataView(d);m.setUint32(0,1179937895,!0),m.setUint32(4,2,!0),m.setUint32(8,p,!0);var _=new ArrayBuffer(8+s+c),x=new DataView(_);x.setUint32(0,s+c,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(_,8);if(o)y.set(o);else{var T="_".charCodeAt(0);for(l=0;l<s;++l){var v=i.charCodeAt(l);v!=i.codePointAt(l)?y[l]=T:y[l]=v}}var b=new Uint8Array(_,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 F=new ArrayBuffer(f),M=new Uint8Array(F);for(l=0;l<f;++l)M[l]=0;var R=new ArrayBuffer(h),w=new Uint8Array(R);for(l=0;l<h;++l)w[l]=0;var V=[d,_,A,n];for(l=0;l<r._orderedImageData.length;++l)V.push(r._orderedImageData[l].data);V.push(F),V.push(R);var C=new Blob(V,{type:"application/octet-stream"}),S=new g;return S.glTFFiles[a]=C,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t,r){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=r?d._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var n=f.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&n.multiplyInPlace(t.rotationQuaternion),f.Quaternion.IsIdentity(n)||(r&&d._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){t.position.equalsToFloats(0,0,0)||(e.translation=r?d._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray());var n=t.rotationQuaternion;n&&!f.Quaternion.IsIdentity(n)&&(r&&d._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().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,o,i){var a=r instanceof f.Mesh?r:r instanceof f.InstancedMesh?r.sourceMesh:null;if(a){var s=a.getVertexBuffer(e,!0),u=a.getVerticesData(e,void 0,void 0,!0);if(s&&u){var l=f.VertexBuffer.GetTypeByteLength(t),c=u.length*l,h=d._CreateBufferView(0,n.getByteOffset(),c,o,e+" - "+a.name);this._bufferViews.push(h),this._writeAttributeData(e,t,u,o/l,n,i,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n,o){if(r){t.targets||(t.targets=[]);var i={},a=e.getMesh();if(r.hasNormals){var s=a.getVerticesData(f.VertexBuffer.NormalKind,void 0,void 0,!0),u=r.getNormals(),l=(x=e.verticesCount)*(y=12),c=d._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_NORMAL");this._bufferViews.push(c);var h=this._bufferViews.length-1,p=d._CreateAccessor(h,r.name+" - NORMAL","VEC3",5126,x,0,null,null);this._accessors.push(p),i.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.NormalKind,5126,e,r,s,u,y/4,n,o)}if(r.hasPositions){var m=a.getVerticesData(f.VertexBuffer.PositionKind,void 0,void 0,!0),g=r.getPositions();l=(x=e.verticesCount)*(y=12),c=d._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_POSITION"),this._bufferViews.push(c),h=this._bufferViews.length-1;var _={min:new f.Vector3(1/0,1/0,1/0),max:new f.Vector3(-1/0,-1/0,-1/0)};p=d._CreateAccessor(h,r.name+" - POSITION","VEC3",5126,x,0,null,null),this._accessors.push(p),i.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.PositionKind,5126,e,r,m,g,y/4,n,o,_),p.min=_.min.asArray(),p.max=_.max.asArray()}if(r.hasTangents){var x,y,T=a.getVerticesData(f.VertexBuffer.TangentKind,void 0,void 0,!0),v=r.getTangents();l=(x=e.verticesCount)*(y=12),c=d._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_NORMAL"),this._bufferViews.push(c),h=this._bufferViews.length-1,p=d._CreateAccessor(h,r.name+" - TANGENT","VEC3",5126,x,0,null,null),this._accessors.push(p),i.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.TangentKind,5126,e,r,T,v,y/4,n,o)}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,n){var o,i,a,s=[],u=null;t instanceof f.Mesh?u=t:t instanceof f.InstancedMesh&&(u=t.sourceMesh);var l=[{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(u){for(var c=null,h=this._getMeshPrimitiveMode(u),p={},m=u.morphTargetManager,g=0,_=l;g<_.length;g++){var x=(W=_[g]).kind,y=W.accessorComponentType;if(u.isVerticesDataPresent(x,!0)){var T=this._getVertexBufferFromMesh(x,u);W.byteStride=T?T.getSize()*f.VertexBuffer.GetTypeByteLength(W.accessorComponentType):4*f.VertexBuffer.DeduceStride(x),12===W.byteStride&&(W.accessorType="VEC3"),this._createBufferViewKind(x,y,t,r,W.byteStride,n),W.bufferViewIndex=this._bufferViews.length-1,p[x]=W.bufferViewIndex}}if(u.getTotalIndices()){var v=u.getIndices();if(v){var b=4*v.length;i=d._CreateBufferView(0,r.getByteOffset(),b,void 0,"Indices - "+u.name),this._bufferViews.push(i),c=this._bufferViews.length-1;for(var A=0,E=v.length;A<E;++A)r.setUInt32(v[A])}}if(u.subMeshes)for(var F=0,M=u.subMeshes;F<M.length;F++){var R=M[F],w=R.getMaterial()||u.getScene().defaultMaterial,V=null;if(w)if(u instanceof f.LinesMesh){var C={name:u.name+" material"};(!u.color.equals(f.Color3.White())||u.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:u.color.asArray().concat([u.alpha])}),this._materials.push(C),V=this._materials.length-1}else if(w instanceof f.MultiMaterial){var S=w.subMaterials[R.materialIndex];S&&(w=S,V=this._materialMap[w.uniqueId])}else V=this._materialMap[w.uniqueId];var I=null!=V?this._materials[V]:null,B={attributes:{}};this._setPrimitiveMode(B,h);for(var P=0,N=l;P<N.length;P++)if(((x=(W=N[P]).kind)!==f.VertexBuffer.UVKind&&x!==f.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||I&&this._glTFMaterialExporter._hasTexturesPresent(I))&&(z=u.getVerticesData(x,void 0,void 0,!0))&&(T=this._getVertexBufferFromMesh(x,u))){var L=T.getSize(),O=W.bufferViewIndex;if(null!=O){a={min:null,max:null},x==f.VertexBuffer.PositionKind&&(a=d._CalculateMinMaxPositions(z,0,z.length/L,n));var k=d._CreateAccessor(O,x+" - "+t.name,W.accessorType,W.accessorComponentType,z.length/L,0,a.min,a.max);this._accessors.push(k),this._setAttributeKind(B,x)}}if(c&&(k=d._CreateAccessor(c,"indices - "+t.name,"SCALAR",5125,R.indexCount,4*R.indexStart,null,null),this._accessors.push(k),B.indices=this._accessors.length-1),null!=V&&Object.keys(B.attributes).length>0){var U=null!==u.overrideMaterialSideOrientation?u.overrideMaterialSideOrientation:w.sideOrientation;if(U==f.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||U==f.Material.ClockWiseSideOrientation&&n&&u.overrideMaterialSideOrientation!==(null===(o=u.material)||void 0===o?void 0:o.sideOrientation)){var K=null!=c?this._bufferViews[c].byteOffset:null;null==K&&(K=0);var D=null;if(null!=c&&(D=u.getIndices()),D)this._reorderIndicesBasedOnPrimitiveMode(R,h,D,K,r);else for(var G=0,H=l;G<H.length;G++){var z,W=H[G];if(z=u.getVerticesData(W.kind,void 0,void 0,!0)){var q=this._bufferViews[p[W.kind]].byteOffset;q||(q=0),this._reorderVertexAttributeDataBasedOnPrimitiveMode(R,h,U,W.kind,z,q,r,n)}}}B.material=V}if(m)for(var Q=void 0,j=0;j<m.numTargets;++j)Q=m.getTarget(j),this._setMorphTargetAttributes(R,B,Q,r,n);e.primitives.push(B),this._extensionsPostExportMeshPrimitiveAsync("postExport",B,R,r),s.push()}}return Promise.all(s).then((function(){}))},e.prototype._isBabylonCoordinateSystemConvertingNode=function(e){return e instanceof f.TransformNode&&!!e.getWorldMatrix().multiplyToRef(v,f.TmpVectors.Matrix[0]).isIdentity()&&!(e instanceof f.Mesh&&null!==e.geometry||e instanceof f.InstancedMesh&&null!==e.sourceMesh.geometry)},e.prototype._createSceneAsync=function(e,t){var r,n,o,i=this,a={nodes:[]},s=y(y(y(y([],e.transformNodes,!0),e.meshes,!0),e.lights,!0),e.cameras,!0),u=[];this._convertToRightHandedSystem=!e.useRightHandedSystem,this._convertToRightHandedSystemMap={},e.metadata&&(this._options.metadataSelector?a.extras=this._options.metadataSelector(e.metadata):e.metadata.gltf&&(a.extras=e.metadata.gltf.extras)),e.rootNodes.forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem,e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem}))})),e.rootNodes.forEach((function(e){if(!i._includeCoordinateSystemConversionNodes&&i._isBabylonCoordinateSystemConvertingNode(e)){u.push(e);var t=s.indexOf(e);-1!==t&&s.splice(t,1),e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=!1}))}}));var l=new Map;e.cameras.forEach((function(e){if(!i._options.shouldExportNode||i._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}}l.set(e,i._cameras.length),i._cameras.push(t)}}));var c=this._getExportNodes(s),h=c[0],p=c[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(p,"image/png",!0).then((function(){return i._createNodeMapAndAnimationsAsync(e,h,t).then((function(c){return i._createSkinsAsync(e,c,t).then((function(e){if(i._nodeMap=c,i._totalByteLength=t.getByteOffset(),null==i._totalByteLength)throw new Error("undefined byte length!");for(var h=0,p=s;h<p.length;h++){var d=p[h];if(void 0!==(r=i._nodeMap[d.uniqueId])){if(n=i._nodes[r],d.metadata&&(i._options.metadataSelector?n.extras=i._options.metadataSelector(d.metadata):d.metadata.gltf&&(n.extras=d.metadata.gltf.extras)),d instanceof f.Camera&&(n.camera=l.get(d)),d.parent&&-1===u.indexOf(d.parent)||(i._options.shouldExportNode&&!i._options.shouldExportNode(d)?f.Tools.Log("Omitting "+d.name+" from scene."):(i._convertToRightHandedSystemMap[d.uniqueId]&&(n.translation&&(n.translation[2]*=-1,n.translation[0]*=-1),n.rotation=n.rotation?f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(n.rotation)).asArray():f.Quaternion.FromArray([0,1,0,0]).asArray()),a.nodes.push(r))),d instanceof f.Mesh){var m=d;m.skeleton&&(n.skin=e[m.skeleton.uniqueId])}if(o=d.getDescendants(!0),!n.children&&o&&o.length){for(var g=[],_=0,x=o;_<x.length;_++){var y=x[_];null!=i._nodeMap[y.uniqueId]&&g.push(i._nodeMap[y.uniqueId])}g.length&&(n.children=g)}}}a.nodes.length&&i._scenes.push(a)}))}))}))},e.prototype._getExportNodes=function(e){for(var t=[],r=new Set,n=0,o=e;n<o.length;n++){var i=o[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(i)){t.push(i);var a=i;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(i.name)}return[t,r]},e.prototype._createNodeMapAndAnimationsAsync=function(e,t,r){for(var n,o=this,i=Promise.resolve(),a={},s={name:"runtime animations",channels:[],samplers:[]},u=[],l=function(t){i=i.then((function(){var i=o._convertToRightHandedSystemMap[t.uniqueId];return o._createNodeAsync(t,r,i).then((function(l){var c=o._extensionsPostExportNodeAsync("createNodeAsync",l,t,a,r);return null==c?(f.Tools.Warn("Not exporting node ".concat(t.name)),Promise.resolve()):c.then((function(l){l&&(o._nodes.push(l),n=o._nodes.length-1,a[t.uniqueId]=n,e.animationGroups.length||(m._CreateMorphTargetAnimationFromMorphTargetAnimations(t,s,u,a,o._nodes,r,o._bufferViews,o._accessors,i,o._animationSampleRate,o._options.shouldExportAnimation),t.animations.length&&m._CreateNodeAnimationFromNodeAnimations(t,s,u,a,o._nodes,r,o._bufferViews,o._accessors,i,o._animationSampleRate,o._options.shouldExportAnimation)))}))}))}))},c=0,h=t;c<h.length;c++)l(h[c]);return i.then((function(){return s.channels.length&&s.samplers.length&&o._animations.push(s),u.forEach((function(e){e.channels.length&&e.samplers.length&&o._animations.push(e)})),e.animationGroups.length&&m._CreateNodeAndMorphAnimationFromAnimationGroups(e,o._animations,a,o._nodes,r,o._bufferViews,o._accessors,o._convertToRightHandedSystemMap,o._animationSampleRate,o._options.shouldExportAnimation),a}))},e.prototype._createNodeAsync=function(e,t,r){var n=this;return Promise.resolve().then((function(){var o={},i={primitives:[]};if(e.name&&(o.name=e.name),e instanceof f.TransformNode){if(n._setNodeTransformation(o,e,r),e instanceof f.Mesh){var a=e.morphTargetManager;if(a&&a.numTargets>0){i.weights=[];for(var s=0;s<a.numTargets;++s)i.weights.push(a.getTarget(s).influence)}}return n._setPrimitiveAttributesAsync(i,e,t,r).then((function(){return i.primitives.length&&(n._meshes.push(i),o.mesh=n._meshes.length-1),o}))}return e instanceof f.Camera?(n._setCameraTransformation(o,e,r),o):o}))},e.prototype._createSkinsAsync=function(e,t,r){for(var n,o=Promise.resolve(),i={},a=0,s=e.skeletons;a<s.length;a++){var u=s[a];if(!(u.bones.length<=0)){for(var l={joints:[]},c=[],h={},p=-1,m=0;m<u.bones.length;++m)-1!==(g=null!==(n=(_=u.bones[m]).getIndex())&&void 0!==n?n:m)&&(h[g]=_,g>p&&(p=g));for(var g=0;g<=p;++g){var _=h[g];c.push(_.getInvertedAbsoluteTransform());var x=_.getTransformNode();x&&null!==t[x.uniqueId]&&void 0!==t[x.uniqueId]?l.joints.push(t[x.uniqueId]):f.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}if(l.joints.length>0){var y=64*c.length,T=r.getByteOffset(),v=d._CreateBufferView(0,T,y,void 0,"InverseBindMatrices - "+u.name);this._bufferViews.push(v);var b=this._bufferViews.length-1,A=d._CreateAccessor(b,"InverseBindMatrices - "+u.name,"MAT4",5126,c.length,null,null,null),E=this._accessors.push(A)-1;l.inverseBindMatrices=E,this._skins.push(l),i[u.uniqueId]=this._skins.length-1,c.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))}}}return o.then((function(){return i}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),A=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}(),E=0,F=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new b(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 o=t.replace(/\.[^/.]+$/,"");return new b(e,r)._generateGLBAsync(o).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),M="KHR_texture_transform",R=function(){function e(){this.name=M,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={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng&&(n.rotation=-r.wAng,o=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),!o)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[M]=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(M)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();b.RegisterExtension(M,(function(){return new R}));var w="KHR_lights_punctual",V=function(){function e(e){this.name=w,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[w]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n){var o=this;return new Promise((function(i){if(t&&r instanceof f.ShadowLight){var a=r,s=void 0,u=a.getTypeID()==f.Light.LIGHTTYPEID_POINTLIGHT?"point":a.getTypeID()==f.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":a.getTypeID()==f.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==u)f.Logger.Warn("".concat(e,": Light ").concat(a.name," is not supported in ").concat(w));else{var l=a.position.clone(),c=o._exporter._convertToRightHandedSystemMap[r.uniqueId];if(l.equals(f.Vector3.Zero())||(c&&d._GetRightHandedPositionVector3FromRef(l),t.translation=l.asArray()),"point"!==u){var h=a.direction,p=-Math.atan2(h.z*(o._exporter._babylonScene.useRightHandedSystem?-1:1),h.x)+Math.PI/2,m=Math.sqrt(h.x*h.x+h.z*h.z),g=-Math.atan2(h.y,m),_=f.Quaternion.RotationYawPitchRoll(p,g,0);c&&d._GetRightHandedQuaternionFromRef(_),_.equals(f.Quaternion.Identity())||(t.rotation=_.asArray())}if(a.falloffType!==f.Light.FALLOFF_GLTF&&f.Logger.Warn("".concat(e,": Light falloff for ").concat(a.name," does not match the ").concat(w," specification!")),s={type:u},a.diffuse.equals(f.Color3.White())||(s.color=a.diffuse.asArray()),1!==a.intensity&&(s.intensity=a.intensity),a.range!==Number.MAX_VALUE&&(s.range=a.range),"spot"===u){var x=a;x.angle!==Math.PI/2&&(null==s.spot&&(s.spot={}),s.spot.outerConeAngle=x.angle/2),0!==x.innerAngle&&(null==s.spot&&(s.spot={}),s.spot.innerConeAngle=x.innerAngle/2)}null==o._lights&&(o._lights={lights:[]}),o._lights.lights.push(s);var y={light:o._lights.lights.length-1},T=r.parent;if(T&&1==T.getChildren().length){var v=o._exporter._nodes[n[T.uniqueId]];if(v){var b=f.TmpVectors.Matrix[0],A=f.TmpVectors.Matrix[1],E=v.translation?new f.Vector3(v.translation[0],v.translation[1],v.translation[2]):f.Vector3.Zero(),F=v.rotation?new f.Quaternion(v.rotation[0],v.rotation[1],v.rotation[2],v.rotation[3]):f.Quaternion.Identity(),M=v.scale?new f.Vector3(v.scale[0],v.scale[1],v.scale[2]):f.Vector3.One();f.Matrix.ComposeToRef(M,F,E,b),b.invertToRef(A);var R=f.TmpVectors.Matrix[2],V=t.translation?new f.Vector3(t.translation[0],t.translation[1],t.translation[2]):f.Vector3.Zero();a instanceof f.DirectionalLight&&V.subtractInPlace(o._exporter._babylonScene.useRightHandedSystem?a.direction:d._GetRightHandedPositionVector3(a.direction));var C=o._exporter._babylonScene.useRightHandedSystem?f.Quaternion.Identity():new f.Quaternion(0,1,0,0);t.rotation&&C.multiplyInPlace(new f.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var S=t.scale?new f.Vector3(t.scale[0],t.scale[1],t.scale[2]):f.Vector3.One();f.Matrix.ComposeToRef(S,C,V,R),R.multiplyToRef(A,R);var I=f.TmpVectors.Vector3[0],B=f.TmpVectors.Quaternion[0],P=f.TmpVectors.Vector3[1];return R.decompose(I,B,P),v.scale=I.asArray(),v.rotation=B.asArray(),v.translation=P.asArray(),null==v.extensions&&(v.extensions={}),v.extensions[w]=y,void i(null)}}null==t.extensions&&(t.extensions={}),t.extensions[w]=y}}i(t)}))},e}();b.RegisterExtension(w,(function(e){return new V(e)}));var C="KHR_materials_clearcoat",S=function(){function e(e){this.name=C,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 o,i=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture);o=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!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=a?a:void 0,hasTextures:function(){return null!==s.clearcoatTexture||null!==s.clearcoatRoughnessTexture||null!==s.clearcoatRoughnessTexture}};t.extensions[C]=s}e(t)}))},e}();b.RegisterExtension(C,(function(e){return new S(e)}));var I="KHR_materials_iridescence",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.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 o=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.texture),i=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!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0,hasTextures:function(){return null!==a.iridescenceTexture||null!==a.iridescenceThicknessTexture}};t.extensions[I]=a}e(t)}))},e}();b.RegisterExtension(I,(function(e){return new B(e)}));var P="KHR_materials_sheen",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){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 o,i,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!==(o=r.sheen.roughness)&&void 0!==o?o:0,hasTextures:function(){return null!==u.sheenColorTexture||null!==u.sheenRoughnessTexture}};r.sheen.texture&&(u.sheenColorTexture=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==i?i: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[P]=u}e(t)}))},e}();b.RegisterExtension(P,(function(e){return new N(e)}));var L="KHR_materials_unlit",O=function(){function e(){this.name=L,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 o=!1;r instanceof f.PBRMaterial?o=r.unlit:r instanceof f.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[L]={}),e(t)}))},e}();b.RegisterExtension(L,(function(){return new O}));var k="KHR_materials_ior",U=function(){function e(){this.name=k,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 o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[k]=o}e(t)}))},e}();b.RegisterExtension(k,(function(e){return new U}));var K="KHR_materials_specular",D=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){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 o,i;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var a=null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,s=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.reflectanceTexture))&&void 0!==i?i: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[K]=u}e(t)}))},e}();b.RegisterExtension(K,(function(e){return new D(e)}));var G="KHR_materials_volume",H=function(){function e(e){this.name=G,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 o;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,a={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(i.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray(),hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions[G]=a}e(t)}))},e}();b.RegisterExtension(G,(function(e){return new H(e)}));var z="KHR_materials_transmission",W=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.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 o;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,a={transmissionFactor:0===i.refractionIntensity?void 0:i.refractionIntensity,transmissionTexture:null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(i.refractionIntensityTexture))&&void 0!==o?o:void 0,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions[z]=a}e(t)}))},e}();b.RegisterExtension(z,(function(e){return new W(e)}));var q="EXT_mesh_gpu_instancing",Q=function(){function e(e){this.name=q,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,o){var i=this;return new Promise((function(e){if(t&&r instanceof f.Mesh&&r.hasThinInstances&&o){i._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,m=!1,g=new Float32Array(3*r.thinInstanceCount),_=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),g.set(l.asArray(),3*y),_.set(c.normalize().asArray(),4*y),x.set(h.asArray(),3*y),p=p||!l.equalsWithEpsilon(n),d=d||!c.equalsWithEpsilon(a),m=m||!h.equalsWithEpsilon(s),y++;var b={attributes:{}};p&&(b.attributes.TRANSLATION=i._buildAccessor(g,"VEC3",r.thinInstanceCount,o,5126)),d&&(b.attributes.ROTATION=i._buildAccessor(_,"VEC4",r.thinInstanceCount,o,5126)),m&&(b.attributes.SCALE=i._buildAccessor(x,"VEC3",r.thinInstanceCount,o,5126)),t.extensions=t.extensions||{},t.extensions[q]=b}e(t)}))},e.prototype._buildAccessor=function(e,t,r,n,o){var i=n.getByteOffset();switch(o){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:i,byteLength:e.length*f.VertexBuffer.GetTypeByteLength(o)},u=this._exporter._bufferViews.length;this._exporter._bufferViews.push(s);var l=this._exporter._accessors.length,c={bufferView:u,componentType:o,count:r,type:t,normalized:5120==o||5122==o};return this._exporter._accessors.push(c),l},e}();b.RegisterExtension(q,(function(e){return new Q(e)}));var j="KHR_materials_emissive_strength",Y=function(){function e(){this.name=j,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 o=r.emissiveColor.asArray(),i=Math.max.apply(Math,o);if(i>1){n._wasUsed=!0,t.extensions||(t.extensions={});var a={emissiveStrength:i},s=r.emissiveColor.scale(1/a.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[j]=a}return e(t)}))},e}();b.RegisterExtension(j,(function(e){return new Y}));var X=function(){function e(){}return e.CreateSTL=function(e,t,r,n,o,i,a){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===i&&(i=!1),void 0===a&&(a=!1);var s,u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],o=[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])],i=o[0].subtract(o[1]),a=o[2].subtract(o[1]);return{v:o,n:f.Vector3.Cross(a,i).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(),o=void 0;for(o=0;o<r.length;o+=3)f.Vector3.TransformCoordinatesFromFloatsToRef(r[o],r[o+1],r[o+2],e.computeWorldMatrix(!0),n).toArray(r,o);return r}return e.getVerticesData(f.VertexBuffer.PositionKind)||[]};a&&(i=!0);var p=0,d=0;if(n){for(var m=0;m<e.length;m++)p+=(y=(_=e[m]).getIndices())?y.length/3:0;var g=new ArrayBuffer(84+50*p);d+=80,(s=new DataView(g)).setUint32(d,p,o),d+=4}else s="solid stlmesh\r\n";for(m=0;m<e.length;m++){var _=e[m];!i&&_ instanceof f.Mesh&&_.bakeCurrentTransformIntoVertices();for(var x=h(_),y=_.getIndices()||[],T=0;T<y.length;T+=3){var v=u(y,x,T);n?(d=l(s,d,v.n,o),d=l(s,d,v.v[0],o),d=l(s,d,v.v[1],o),d=l(s,d,v.v[2],o),d+=2):(s+="facet normal "+v.n.x+" "+v.n.y+" "+v.n.z+"\r\n",s+="\touter loop\r\n",s+="\t\tvertex "+v.v[0].x+" "+v.v[0].y+" "+v.v[0].z+"\r\n",s+="\t\tvertex "+v.v[1].x+" "+v.v[1].y+" "+v.v[1].z+"\r\n",s+="\t\tvertex "+v.v[2].x+" "+v.v[2].y+" "+v.v[2].z+"\r\n",s+="\tendloop\r\n",s+="endfacet\r\n")}}if(n||(s+="endsolid stlmesh"),t){var b=document.createElement("a"),A=new Blob([s],{type:"application/octet-stream"});b.href=window.URL.createObjectURL(A),b.download=r+".stl",b.click()}return s},e}(),Z=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Z){Z.BABYLON=Z.BABYLON||{};var J=Z.BABYLON;J.GLTF2=J.GLTF2||{},J.GLTF2.Exporter=J.GLTF2.Exporter||{},J.GLTF2.Exporter.Extensions=J.GLTF2.Exporter.Extensions||{};var $=[];for(var ee in t)J[ee]=t[ee],$.push(ee);for(var ee in r)J[ee]=r[ee],$.push(ee);for(var ee in i)J[ee]=i[ee],$.push(ee);for(var ee in a)J.GLTF2.Exporter.Extensions[ee]=a[ee],$.push(ee);for(var ee in s)$.indexOf(ee)>-1||(J.GLTF2.Exporter[ee]=s[ee])}var te=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==te)for(var re in e)te.BABYLON[re]=e[re];var ne=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==ne)for(var oe in u)ne.BABYLON[oe]=u[oe];const ie=l})(),o.default})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var t={520:t=>{t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.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 o={};return(()=>{n.d(o,{default:()=>ie});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:()=>g});var i={};n.r(i),n.d(i,{GLTF2Export:()=>F});var a={};n.r(a),n.d(a,{EXT_mesh_gpu_instancing:()=>Q,KHR_lights_punctual:()=>V,KHR_materials_clearcoat:()=>S,KHR_materials_emissive_strength:()=>Y,KHR_materials_ior:()=>U,KHR_materials_iridescence:()=>B,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>W,KHR_materials_unlit:()=>O,KHR_materials_volume:()=>H,KHR_texture_transform:()=>R});var s={};n.r(s),n.d(s,{EXT_mesh_gpu_instancing:()=>Q,GLTF2Export:()=>F,GLTFData:()=>g,KHR_lights_punctual:()=>V,KHR_materials_clearcoat:()=>S,KHR_materials_emissive_strength:()=>Y,KHR_materials_ior:()=>U,KHR_materials_iridescence:()=>B,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>W,KHR_materials_unlit:()=>O,KHR_materials_volume:()=>H,KHR_texture_transform:()=>R,_BinaryWriter:()=>A,_Exporter:()=>b,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtensionV2:()=>E});var u={};n.r(u),n.d(u,{STLExport:()=>X});var l={};n.r(l),n.d(l,{EXT_mesh_gpu_instancing:()=>Q,GLTF2Export:()=>F,GLTFData:()=>g,KHR_lights_punctual:()=>V,KHR_materials_clearcoat:()=>S,KHR_materials_emissive_strength:()=>Y,KHR_materials_ior:()=>U,KHR_materials_iridescence:()=>B,KHR_materials_sheen:()=>N,KHR_materials_specular:()=>D,KHR_materials_transmission:()=>W,KHR_materials_unlit:()=>O,KHR_materials_volume:()=>H,KHR_texture_transform:()=>R,OBJExport:()=>h,STLExport:()=>X,_BinaryWriter:()=>A,_Exporter:()=>b,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtension:()=>p,__IGLTFExporterExtensionV2:()=>E});var c,f=n(520),h=function(){function e(){}return e.OBJ=function(e,t,r,n){var o=[],i=1,a=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var s=0;s<e.length;s++){o.push("g object"+s),o.push("o object_"+s);var u=null;if(n){var l=e[s].computeWorldMatrix(!0);u=new f.Matrix,l.invertToRef(u),e[s].bakeTransformIntoVertices(l)}if(t){var c=e[s].material;c&&o.push("usemtl "+c.id)}var h=e[s].geometry;if(h){var p=h.getVerticesData("position"),d=h.getVerticesData("normal"),m=h.getVerticesData("uv"),g=h.getIndices(),_=0,x=0;if(p&&g){for(var y=0;y<p.length;y+=3)e[0].getScene().useRightHandedSystem?o.push("v "+p[y]+" "+p[y+1]+" "+p[y+2]):o.push("v "+p[y]+" "+p[y+1]+" "+-p[y+2]),_++;if(null!=d)for(y=0;y<d.length;y+=3)o.push("vn "+d[y]+" "+d[y+1]+" "+d[y+2]);if(null!=m)for(y=0;y<m.length;y+=2)o.push("vt "+m[y]+" "+m[y+1]),x++;for(y=0;y<g.length;y+=3){var T=[String(g[y+2]+i),String(g[y+1]+i),String(g[y]+i)],v=[String(g[y+2]+a),String(g[y+1]+a),String(g[y]+a)],b=["","",""],A=T,E=null!=m?v:b,F=null!=d?T:b;o.push("f "+A[0]+"/"+E[0]+"/"+F[0]+" "+A[1]+"/"+E[1]+"/"+F[1]+" "+A[2]+"/"+E[2]+"/"+F[2])}n&&u&&e[s].bakeTransformIntoVertices(u),i+=_,a+=x}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 o.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,o){var i={buffer:e,byteLength:r};return t&&(i.byteOffset=t),o&&(i.name=o),n&&(i.byteStride=n),i},e._CreateAccessor=function(e,t,r,n,o,i,a,s){var u={name:t,bufferView:e,componentType:n,count:o,type:r};return null!=a&&(u.min=a),null!=s&&(u.max=s),null!=i&&(u.byteOffset=i),u},e._CalculateMinMaxPositions=function(t,r,n,o){var i,a,s,u=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];if(n)for(var c=r,h=r+n;c<h;++c){i=3*c,a=f.Vector3.FromArray(t,i),o&&e._GetRightHandedPositionVector3FromRef(a),s=a.asArray();for(var p=0;p<3;++p){var d=s[p];d<u[p]&&(u[p]=d),d>l[p]&&(l[p]=d),++i}}return{min:u,max:l}},e._GetRightHandedPositionVector3=function(e){return new f.Vector3(e.x,e.y,-e.z)},e._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},e._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedNormalVector3=function(e){return new f.Vector3(e.x,e.y,-e.z)},e._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},e._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},e._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},e._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},e._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},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 m=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,o,i,a){if(this._IsTransformable(t)){var s=[],u=[],l=r.getKeys(),c=e._CalculateMinMaxKeyFrames(l),h=e._DeduceInterpolation(l,n,i),p=c.max-c.min,d=h.interpolationType,m=h.shouldBakeAnimation;if(m?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,u,c,o,i):"LINEAR"===d||"STEP"===d?e._CreateLinearOrStepAnimation(t,r,n,p,s,u,o,i):"CUBICSPLINE"===d?e._CreateCubicSplineAnimation(t,r,n,p,s,u,o,i):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,a,s,u,c,o,i),s.length&&u.length)return{inputs:s,outputs:u,samplerInterpolation:d,inputsMin:m?c.min:f.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:m?c.max:f.Tools.FloatRound(c.max/r.framePerSecond)}}return null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[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(o[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,o,i,a,s,u,l,c,f){var h;if(e._IsTransformable(t)&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p];if(!f||f(m)){var g=e._DeduceAnimationInfo(m);g&&(h={name:m.name,samplers:[],channels:[]},e._AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?r:h,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,a,s,u,l,g.useQuaternion,c),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,i,a,s,u,l,c,h){var p;if(t instanceof f.Mesh){var d=t.morphTargetManager;if(d)for(var m=0;m<d.numTargets;++m)for(var g=0,_=d.getTarget(m).animations;g<_.length;g++){var x=_[g];if(!h||h(x)){for(var y=new f.Animation("".concat(x.name),"influence",x.framePerSecond,x.dataType,x.loopMode,x.enableBlending),T=[],v=x.getKeys(),b=0;b<v.length;++b)for(var A=v[b],E=0;E<d.numTargets;++E)E==m?T.push(A):T.push({frame:A.frame,value:0});y.setKeys(T);var F=e._DeduceAnimationInfo(y);F&&(p={name:y.name,samplers:[],channels:[]},e._AddAnimation(x.name,x.hasRunningRuntimeAnimations?r:p,t,y,F.dataAccessorType,F.animationChannelTargetPath,o,a,s,u,l,F.useQuaternion,c,d.numTargets),p.samplers.length&&p.channels.length&&n.push(p))}}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,i,a,s,u,l,c){var h,p;if(t.animationGroups)for(var d=t.animationGroups,m=function(o){var d=new Map,m=new Map,_=new Set,x=o.to-o.from;p={name:o.name,channels:[],samplers:[]};for(var y=function(r){var x=o.targetedAnimations[r],y=x.target,T=x.animation;if(c&&!c(T))return"continue";if(g._IsTransformable(y)||1===y.length&&g._IsTransformable(y[0])){if(A=e._DeduceAnimationInfo(x.animation)){var v=g._IsTransformable(y)?y:g._IsTransformable(y[0])?y[0]:null;if(v){var b=u[v.uniqueId];e._AddAnimation("".concat(T.name),p,v,T,A.dataAccessorType,A.animationChannelTargetPath,n,i,a,s,b,A.useQuaternion,l)}}}else if(y instanceof f.MorphTarget||1===y.length&&y[0]instanceof f.MorphTarget){var A;if(A=e._DeduceAnimationInfo(x.animation)){var E=y instanceof f.MorphTarget?y:y[0];if(E){var F=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===E)return!0;return!1}));if(F){var M=t.meshes.find((function(e){return e.morphTargetManager===F}));M&&(d.has(M)||d.set(M,new Map),null===(h=d.get(M))||void 0===h||h.set(E,T),_.add(M),m.set(M,T))}}}}},T=0;T<o.targetedAnimations.length;++T)y(T);_.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],h=m.get(t).getKeys(),g=h.length,_=0;_<g;++_)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=d.get(t);if(v){var b=v.get(T);b?(u||(u=new f.Animation("".concat(o.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,f.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[_])):c.push({frame:o.from+x/g*_,value:T.influence,inTangent:h[0].inTangent?0:void 0,outTangent:h[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e._AddAnimation("".concat(o.name,"_").concat(t.name,"_MorphWeightAnimation"),p,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,i,a,s,!1,A.useQuaternion,l,null==r?void 0:r.numTargets)})),p.channels.length&&p.samplers.length&&r.push(p)},g=this,_=0,x=d;_<x.length;_++)m(x[_])},e._AddAnimation=function(t,r,n,o,i,a,s,u,l,c,f,h,p,m){var g,_,x,y,T,v,b,A=e._CreateNodeAnimation(n,o,a,f,h,p);if(A){if(m){for(var E=0,F=0,M=[];A.inputs.length>0;)F=A.inputs.shift(),E%m==0&&M.push(F),E++;A.inputs=M}var R=s[n.uniqueId],w=4*A.inputs.length;g=d._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," keyframe data view")),l.push(g),A.inputs.forEach((function(e){u.setFloat32(e)})),_=d._CreateAccessor(l.length-1,"".concat(t," keyframes"),"SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),c.push(_),x=c.length-1,T=A.outputs.length,w=4*d._GetDataAccessorElementCount(i)*A.outputs.length,g=d._CreateBufferView(0,u.getByteOffset(),w,void 0,"".concat(t," data view")),l.push(g),A.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),_=d._CreateAccessor(l.length-1,"".concat(t," data"),i,5126,T,null,null,null),c.push(_),y=c.length-1,v={interpolation:A.samplerInterpolation,input:x,output:y},r.samplers.push(v),b={sampler:r.samplers.length-1,target:{node:R,path:a}},r.channels.push(b)}},e._CreateBakedAnimation=function(t,r,n,o,i,a,s,u,l,c,h,p){var d,m,g=f.Quaternion.Identity(),_=null,x=null,y=null,T=null,v=null,b=null;c.min=f.Tools.FloatRound(o/a);for(var A=r.getKeys(),E=0,F=A.length;E<F;++E){if(b=null,y=A[E],E+1<F)if(T=A[E+1],y.value.equals&&y.value.equals(T.value)||y.value===T.value){if(0!==E)continue;b=y.frame}else b=T.frame;else{if(v=A[E-1],y.value.equals&&y.value.equals(v.value)||y.value===v.value)continue;b=i}if(b)for(var M=y.frame;M<=b;M+=s)if((m=f.Tools.FloatRound(M/a))!==_){_=m,x=m;var R={key:0,repeatCount:0,loopMode:r.loopMode};d=r._interpolate(M,R),e._SetInterpolatedValue(t,d,m,r,n,g,u,l,h,p)}}x&&(c.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,i,a){var s=e._GetBasePositionRotationOrScale(r,o,i,a),u=n.targetProperty.split("."),l=u?u[1]:"",c=a?f.Quaternion.FromArray(s).normalize():f.Vector3.FromArray(s);switch(l){case"x":case"y":c[l]=i&&a&&"scale"!==o?-t:t;break;case"z":c[l]=i&&!a&&"scale"!==o?-t:t;break;case"w":c.w=t;break;default:f.Tools.Error('glTFAnimation: Unsupported component name "'.concat(l,'"!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,o,i,a,s,u,l){var c;a.push(r),"weights"!==o?(n.dataType===f.Animation.ANIMATIONTYPE_FLOAT&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,o,u,l)),"rotation"===o?(l?i=t:(c=t,f.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,i)),u&&(d._GetRightHandedQuaternionFromRef(i),e.parent||(i=f.Quaternion.FromArray([0,1,0,0]).multiply(i))),s.push(i.asArray())):(c=t,u&&"scale"!==o&&(d._GetRightHandedPositionVector3FromRef(c),e.parent||(c.x*=-1,c.z*=-1)),s.push(c.asArray()))):s.push([t])},e._CreateLinearOrStepAnimation=function(t,r,n,o,i,a,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];i.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,a,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,n,o,i,a,s,u){r.getKeys().forEach((function(l){i.push(l.frame/r.framePerSecond),e._AddSplineTangent(t,c.INTANGENT,a,n,"CUBICSPLINE",l,o,u,s),e._AddKeyframeValue(l,r,a,n,t,s,u),e._AddSplineTangent(t,c.OUTTANGENT,a,n,"CUBICSPLINE",l,o,u,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r,n){var o;if("rotation"===t)if(n){var i=e.rotationQuaternion;o=(null!=i?i:f.Quaternion.Identity()).asArray(),r&&(d._GetRightHandedQuaternionArrayFromRef(o),e.parent||(o=f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(o)).asArray()))}else{var a=e.rotation;o=(null!=a?a:f.Vector3.Zero()).asArray(),d._GetRightHandedNormalArray3FromRef(o)}else if("translation"===t){var s=e.position;o=(null!=s?s:f.Vector3.Zero()).asArray(),r&&d._GetRightHandedPositionArray3FromRef(o)}else{var u=e.scaling;o=(null!=u?u:f.Vector3.One()).asArray()}return o},e._AddKeyframeValue=function(e,t,r,n,o,i,a){var s,u,l=t.dataType;if(l===f.Animation.ANIMATIONTYPE_VECTOR3){if(s=e.value.asArray(),"rotation"===n){var c=f.Vector3.FromArray(s),h=f.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z);i&&(d._GetRightHandedQuaternionFromRef(h),o.parent||(h=f.Quaternion.FromArray([0,1,0,0]).multiply(h))),s=h.asArray()}else"translation"===n&&i&&(d._GetRightHandedNormalArray3FromRef(s),o.parent||(s[0]*=-1,s[2]*=-1));r.push(s)}else if(l===f.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(u=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,n,i,a)){if("rotation"===n){var p=a?u:f.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).normalize();i&&(d._GetRightHandedQuaternionFromRef(p),o.parent||(p=f.Quaternion.FromArray([0,1,0,0]).multiply(p))),r.push(p.asArray())}else"translation"===n&&i&&(d._GetRightHandedNormalVector3FromRef(u),o.parent||(u.x*=-1,u.z*=-1));r.push(u.asArray())}}else l===f.Animation.ANIMATIONTYPE_QUATERNION?(s=e.value.normalize().asArray(),i&&(d._GetRightHandedQuaternionArrayFromRef(s),o.parent||(s=f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(s)).asArray())),r.push(s)):f.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var a=0,s=e.length;a<s;++a)if((o=e[a]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&o.interpolation===f.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=o.interpolation&&o.interpolation===f.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e._AddSplineTangent=function(e,t,r,n,o,i,a,s,u){var l,h=t===c.INTANGENT?i.inTangent:i.outTangent;if("CUBICSPLINE"===o){if("rotation"===n)if(h){if(s)l=h.asArray();else{var p=h;l=f.Quaternion.RotationYawPitchRoll(p.y,p.x,p.z).asArray()}u&&(d._GetRightHandedQuaternionArrayFromRef(l),e.parent||(l=f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(l)).asArray()))}else l=[0,0,0,0];else"weights"===n?l=h?[h]:[0]:h?(l=h.asArray(),u&&"translation"===n&&(d._GetRightHandedPositionArray3FromRef(l),e.parent||(l[0]*=-1,l[2]*=-1))):l=[0,0,0];r.push(l)}},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}(),g=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],o=void 0;e(t,".glb")?o={type:"model/gltf-binary"}:e(t,".bin")?o={type:"application/octet-stream"}:e(t,".gltf")?o={type:"model/gltf+json"}:e(t,".jpeg")||e(t,".jpg")?o={type:"image/jpeg"}:e(t,".png")&&(o={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],o)),r.click()}},e}();function _(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(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,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=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(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=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,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create;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,o=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?o.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?o.push(n._convertPBRMaterialAsync(e,t,r)):f.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(o).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 o=e.extensions[n];if(o)return null===(t=o.hasTextures)||void 0===t?void 0:t.call(o)}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,o,i,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,m=(r=f.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower),n=Math.pow(r/h.x,.333333),o=u.y,i=l.y,a=c.y,s=h.y,(1-n)*(1-n)*(1-n)*o+3*(1-n)*(1-n)*n*i+3*(1-n)*n*n*a+n*n*n*s);return{baseColorFactor:[p.r,p.g,p.b,d],metallicFactor:0,roughnessFactor:m}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,o=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,i=o*o-4*n*(this._DielectricSpecular.r-t);return f.Scalar.Clamp((-o+Math.sqrt(i))/(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 o=this._exporter._materialMap,i=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),i.push(u),o[t.uniqueId]=i.length-1,this._finishMaterial(a,u,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var o=this;return Promise.all(e).then((function(){for(var e=null,i=0,a=o._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);i<a.length;i++){var s=a[i];e||(e=[]),e.push(o._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=o._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._getImageDataAsync=function(e,t,r,n){return _(this,void 0,void 0,(function(){var o,i,a,s,u;return x(this,(function(l){switch(l.label){case 0:return o=f.Constants.TEXTURETYPE_UNSIGNED_INT,i=this._exporter._babylonScene,a=i.getEngine(),s=a.createRawTexture(e,t,r,f.Constants.TEXTUREFORMAT_RGBA,!1,!0,f.Texture.NEAREST_SAMPLINGMODE,null,o),[4,f.TextureTools.ApplyPostProcess("pass",s,i,o,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),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return f.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,i=e?e.getSize():{width:0,height:0},a=t?t.getSize():{width:0,height:0};return i.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),o=t):i.width>a.width?(o=t&&t instanceof f.Texture?f.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):this._createWhiteTexture(i.width,i.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},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,o){var i;return _(this,void 0,void 0,(function(){var a,s,u,l,c,h,p,d,m,g,_,y,T,v,b,A,E,F,M,R,w,V,C,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===(i=u.texture1)||void 0===i?void 0:i.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 m=x.sent(),[4,u.texture2.readPixels()];case 2:if(g=x.sent(),!m)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(c=this._convertPixelArrayToFloat32(m),!g)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(g),_=h.byteLength,y=new Uint8Array(_),T=new Uint8Array(_),v=f.Color3.Black(),b=0,A=0,B=0;B<d;++B)for(P=0;P<p;++P)E=4*(p*B+P),F=new f.Color3(c[E],c[E+1],c[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.diffuseColor),M=new f.Color3(h[E],h[E+1],h[E+2]).toLinearSpace(s.getEngine().useExactSrgbConversions).multiply(n.specularColor),R=h[E+3]*n.glossiness,w={diffuseColor:F,specularColor:M,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(w),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(C={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)]/=C.baseColor.r>e._Epsilon?C.baseColor.r:1,T[N+1]/=C.baseColor.g>e._Epsilon?C.baseColor.g:1,T[N+2]/=C.baseColor.b>e._Epsilon?C.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]/=C.roughness>e._Epsilon?C.roughness:1,y[N+2]/=C.metallic>e._Epsilon?C.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,o).then((function(e){C.metallicRoughnessTextureData=e}))),I&&a.push(this._getImageDataAsync(T,p,d,o).then((function(e){C.baseColorTextureData=e}))),[2,Promise.all(a).then((function(){return C}))];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),o=1-this._getMaxComponent(t.specularColor),i=e._SolveMetallic(r,n,o),a=t.diffuseColor.scale(o/(1-e._DielectricSpecular.r)/Math.max(1-i,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,e._Epsilon)),u=f.Color3.Lerp(a,s,i*i);return{baseColor:u=u.clampToRef(0,1,u),metallic:i,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 o=[],i={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&o.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var a=e._metallicTexture;a&&o.push(this._exportTextureAsync(a,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(o).then((function(){return i}))},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 o=this;return Promise.resolve().then((function(){var i={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=o._exportTextureSampler(a||s);return o._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a,s,i,t).then((function(e){var n=o._exporter._textures;if(e.baseColorTextureData){var i=o._exportImage("baseColor".concat(n.length),t,e.baseColorTextureData);r.baseColorTexture=o._exportTextureInfo(i,l,null==a?void 0:a.coordinatesIndex)}return e.metallicRoughnessTextureData&&(i=o._exportImage("metallicRoughness".concat(n.length),t,e.metallicRoughnessTextureData),r.metallicRoughnessTexture=o._exportTextureInfo(i,l,null==s?void 0:s.coordinatesIndex)),e}))}return o._convertSpecularGlossinessToMetallicRoughness(i)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,o={},i={name:e.name};if(e.isMetallicWorkflow()){var a=e._albedoColor,s=e.alpha;return a&&(o.baseColorFactor=[a.r,a.g,a.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,o,r).then((function(a){return n._setMetallicRoughnessPbrMaterial(a,e,i,o,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,o,r).then((function(a){return n._setMetallicRoughnessPbrMaterial(a,e,i,o,t,r)}))},e.prototype._setMetallicRoughnessPbrMaterial=function(t,r,n,o,i,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||(o.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(o.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(o.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,i).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,i).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord,extensions:e.extensions};n.occlusionTexture=t;var o=r._ambientTextureStrength;o&&(t.strength=o)}})),l.push(h));var d=r._emissiveTexture;d&&(h=this._exportTextureAsync(d,i).then((function(e){e&&(n.emissiveTexture=e)})),l.push(h))}var m=r._emissiveColor;e._FuzzyEquals(m,f.Color3.Black(),e._Epsilon)||(n.emissiveFactor=m.asArray()),n.pbrMetallicRoughness=o,u.push(n),s[r.uniqueId]=u.length-1}return this._finishMaterial(l,n,r,i)},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 _(this,void 0,void 0,(function(){var r,n,o,i,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(o=this._exportTextureSampler(e),i=e.mimeType)switch(i){case"image/jpeg":case"image/png":case"image/webp":t=i;break;default:f.Tools.Warn("Unsupported media type: ".concat(i))}return a=this._internalTextureToImage,s=e.getInternalTexture().uniqueId,a[s]||(a[s]={}),void 0===(u=a[s][t])&&(l=e.getSize(),u=_(p,void 0,void 0,(function(){var r;return x(this,(function(o){switch(o.label){case 0:return[4,this._getImageDataAsync(n,l.width,l.height,t)];case 1:return r=o.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(),o,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,o=e.replace(/\.\/|\/|\.\\|\\/g,"_"),i=function(e){switch(e){case"image/jpeg":return".jpg";case"image/png":return".png";case"image/webp":return".webp"}}(t),a=o+i;a in n&&(a="".concat(o,"_").concat(f.Tools.RandomId()).concat(i)),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,o=n.findIndex((function(r){return r.sampler==t&&r.source===e}));-1===o&&(o=n.length,n.push({source:e,sampler:t}));var i={index:o};return r&&(i.texCoord=r),i},e.prototype._exportTextureSampler=function(e){var t=this._getTextureSampler(e),r=this._exporter._samplers,n=r.findIndex((function(e){return e.minFilter===t.minFilter&&e.magFilter===t.magFilter&&e.wrapS===t.wrapS&&e.wrapT===t.wrapT}));return-1!==n?n:(r.push(t),r.length-1)},e._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=function(){function e(e,t){this._includeCoordinateSystemConversionNodes=!1,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=t&&t.animationSampleRate?t.animationSampleRate:1/60,this._includeCoordinateSystemConversionNodes=!(!t||!t.includeCoordinateSystemConversionNodes),this._glTFMaterialExporter=new T(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var o=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then((function(e){return o._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o];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,o){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,o,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n,o){return this._applyExtensions(t,(function(t,i){return t.postExportNodeAsync&&t.postExportNodeAsync(e,i,r,n,o)}))},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 o=[],i=0,a=e._ExtensionNames;i<a.length;i++){var s=a[i],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],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 o=n[r],i=this._extensions[o];i.enabled&&t(i)}},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],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e.RegisterExtension=function(t,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,o){switch(t){case f.Material.TriangleFillMode:n||(n=0);for(var i=e.indexStart,a=e.indexStart+e.indexCount;i<a;i+=3){var s=n+4*i,u=o.getUInt32(s+4),l=o.getUInt32(s+8);o.setUInt32(l,s+4),o.setUInt32(u,s+8)}break;case f.Material.TriangleFanDrawMode:i=e.indexStart+e.indexCount-1;for(var c=e.indexStart;i>=c;--i)o.setUInt32(r[i],n),n+=4;break;case f.Material.TriangleStripDrawMode:e.indexCount>=3&&(o.setUInt32(r[e.indexStart+2],n+4),o.setUInt32(r[e.indexStart+1],n+8))}},e.prototype._reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,o,i,a,s){if(s&&r===f.Material.ClockWiseSideOrientation)switch(t){case f.Material.TriangleFillMode:this._reorderTriangleFillMode(e,t,r,n,o,i,a,s);break;case f.Material.TriangleStripDrawMode:this._reorderTriangleStripDrawMode(e,t,r,n,o,i,a,s);break;case f.Material.TriangleFanDrawMode:this._reorderTriangleFanMode(e,t,r,n,o,i,a,s)}},e.prototype._reorderTriangleFillMode=function(e,t,r,n,o,i,a,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/f.VertexBuffer.GetTypeByteLength(u.type);if(e.verticesCount%3!=0)f.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],h=0;switch(n){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:for(var p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*l,c.push(f.Vector3.FromArray(o,h)),c.push(f.Vector3.FromArray(o,h+2*l)),c.push(f.Vector3.FromArray(o,h+l));break;case f.VertexBuffer.TangentKind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*l,c.push(f.Vector4.FromArray(o,h)),c.push(f.Vector4.FromArray(o,h+2*l)),c.push(f.Vector4.FromArray(o,h+l));break;case f.VertexBuffer.ColorKind:var d=u.getSize();for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=d)h=p*l,4===d?(c.push(f.Vector4.FromArray(o,h)),c.push(f.Vector4.FromArray(o,h+2*l)),c.push(f.Vector4.FromArray(o,h+l))):(c.push(f.Vector3.FromArray(o,h)),c.push(f.Vector3.FromArray(o,h+2*l)),c.push(f.Vector3.FromArray(o,h+l)));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*l,c.push(f.Vector2.FromArray(o,h)),c.push(f.Vector2.FromArray(o,h+2*l)),c.push(f.Vector2.FromArray(o,h+l));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,o,a,s)}}else f.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(n," not present!"))},e.prototype._reorderTriangleStripDrawMode=function(e,t,r,n,o,i,a,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/f.VertexBuffer.GetTypeByteLength(u.type),c=[],h=0;switch(n){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:h=e.verticesStart,c.push(f.Vector3.FromArray(o,h+2*l)),c.push(f.Vector3.FromArray(o,h+l));break;case f.VertexBuffer.TangentKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector4.FromArray(o,h));break;case f.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,4===u.getSize()?c.push(f.Vector4.FromArray(o,h)):c.push(f.Vector3.FromArray(o,h));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector2.FromArray(o,h));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i+12,n,o,a,s)}else f.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._reorderTriangleFanMode=function(e,t,r,n,o,i,a,s){var u=this._getVertexBufferFromMesh(n,e.getMesh());if(u){var l=u.byteStride/f.VertexBuffer.GetTypeByteLength(u.type),c=[],h=0;switch(n){case f.VertexBuffer.PositionKind:case f.VertexBuffer.NormalKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector3.FromArray(o,h));break;case f.VertexBuffer.TangentKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector4.FromArray(o,h));break;case f.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector4.FromArray(o,h)),4===u.getSize()?c.push(f.Vector4.FromArray(o,h)):c.push(f.Vector3.FromArray(o,h));break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*l,c.push(f.Vector2.FromArray(o,h));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this._writeVertexAttributeData(c,i,n,o,a,s)}else f.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype._writeVertexAttributeData=function(e,t,r,n,o,i){for(var a=0,s=e;a<s.length;a++){var u=s[a];!i||r===f.VertexBuffer.ColorKind||u instanceof f.Vector2||(u instanceof f.Vector3?r===f.VertexBuffer.NormalKind?d._GetRightHandedNormalVector3FromRef(u):r===f.VertexBuffer.PositionKind?d._GetRightHandedPositionVector3FromRef(u):f.Tools.Error("Unsupported vertex attribute kind!"):d._GetRightHandedVector4FromRef(u)),r===f.VertexBuffer.NormalKind?u.normalize():r===f.VertexBuffer.TangentKind&&u instanceof f.Vector4&&d._NormalizeTangentFromRef(u);for(var l=0,c=u.asArray();l<c.length;l++){var h=c[l];o.setFloat32(h,t),t+=4}}},e.prototype._writeAttributeData=function(e,t,r,n,o,i,a){var s,u,l=[];switch(e){case f.VertexBuffer.PositionKind:for(var c=0,h=r.length/n;c<h;++c){s=c*n;var p=f.Vector3.FromArray(r,s);i&&d._GetRightHandedPositionVector3FromRef(p),l.push(p.asArray())}break;case f.VertexBuffer.NormalKind:c=0;for(var m=r.length/n;c<m;++c)s=c*n,p=f.Vector3.FromArray(r,s),i&&d._GetRightHandedNormalVector3FromRef(p),p.normalize(),l.push(p.asArray());break;case f.VertexBuffer.TangentKind:c=0;for(var g=r.length/n;c<g;++c)s=c*n,p=f.Vector4.FromArray(r,s),i&&d._GetRightHandedVector4FromRef(p),d._NormalizeTangentFromRef(p),l.push(p.asArray());break;case f.VertexBuffer.ColorKind:for(var _=a.material,x=!_||"StandardMaterial"===_.getClassName(),y=(p=3===n?new f.Color3:new f.Color4,this._babylonScene.getEngine().useExactSrgbConversions),T=(c=0,r.length/n);c<T;++c)s=c*n,3===n?(f.Color3.FromArrayToRef(r,s,p),x&&p.toLinearSpaceToRef(p,y)):(f.Color4.FromArrayToRef(r,s,p),x&&p.toLinearSpaceToRef(p,y)),l.push(p.asArray());break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:c=0;for(var v=r.length/n;c<v;++c)s=c*n,l.push([r[s],r[s+1]]);break;case f.VertexBuffer.MatricesIndicesKind:case f.VertexBuffer.MatricesIndicesExtraKind:c=0;for(var b=r.length/n;c<b;++c)s=c*n,p=f.Vector4.FromArray(r,s),l.push(p.asArray());break;case f.VertexBuffer.MatricesWeightsKind:case f.VertexBuffer.MatricesWeightsExtraKind:c=0;for(var A=r.length/n;c<A;++c)s=c*n,p=f.Vector4.FromArray(r,s),l.push(p.asArray());break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+e),l=[]}switch(t){case 5121:u=o.setUInt8.bind(o);break;case 5123:u=o.setUInt16.bind(o);break;case 5125:u=o.setUInt32.bind(o);break;case 5126:u=o.setFloat32.bind(o);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var E=0,F=l;E<F.length;E++)for(var M=0,R=F[E];M<R.length;M++)u(R[M])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,o,i,a,s,u,l){var c,h,p=[],m=new f.Vector3,g=new f.Vector4(0,0,0,0);switch(e){case f.VertexBuffer.PositionKind:for(var _=r.verticesStart;_<r.verticesCount;++_){c=r.indexStart+_*a;var x=f.Vector3.FromArray(o,c);m=(y=f.Vector3.FromArray(i,c)).subtractToRef(x,m),u&&d._GetRightHandedPositionVector3FromRef(m),l&&(l.min.copyFromFloats(Math.min(m.x,l.min.x),Math.min(m.y,l.min.y),Math.min(m.z,l.min.z)),l.max.copyFromFloats(Math.max(m.x,l.max.x),Math.max(m.y,l.max.y),Math.max(m.z,l.max.z))),p.push(m.asArray())}break;case f.VertexBuffer.NormalKind:for(_=r.verticesStart;_<r.verticesCount;++_)c=r.indexStart+_*a,(x=f.Vector3.FromArray(o,c)).normalize(),(y=f.Vector3.FromArray(i,c)).normalize(),m=y.subtractToRef(x,m),u&&d._GetRightHandedNormalVector3FromRef(m),p.push(m.asArray());break;case f.VertexBuffer.TangentKind:for(_=r.verticesStart;_<r.verticesCount;++_){c=r.indexStart+_*(a+1),x=f.Vector4.FromArray(o,c),d._NormalizeTangentFromRef(x);var y=f.Vector4.FromArray(i,c);d._NormalizeTangentFromRef(y),g=y.subtractToRef(x,g),u&&d._GetRightHandedVector4FromRef(g),p.push([g.x,g.y,g.z])}break;default:f.Tools.Warn("Unsupported Vertex Buffer Type: "+e),p=[]}switch(t){case 5121:h=s.setUInt8.bind(s);break;case 5123:h=s.setUInt16.bind(s);break;case 5125:h=s.setUInt32.bind(s);break;case 5126:h=s.setFloat32.bind(s);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var T=0,v=p;T<v.length;T++)for(var b=0,A=v[T];b<A.length;b++)h(A[b])},e.prototype._generateJSON=function(e,t,r){var n,o,i,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&&(o=a._imageData[e.uri],a._orderedImageData.push(o),n=e.uri.split(".")[0]+" image",i=d._CreateBufferView(0,u,o.data.byteLength,void 0,n),u+=o.data.byteLength,a._bufferViews.push(i),e.bufferView=a._bufferViews.length-1,e.name=n,e.mimeType=o.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 o=r._generateJSON(!1,e,!0),i=new Blob([n],{type:"application/octet-stream"}),a=e+".gltf",s=e+".bin",u=new g;if(u.glTFFiles[a]=o,u.glTFFiles[s]=i,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 A(4);return this._createSceneAsync(this._babylonScene,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 o,i=r._generateJSON(!0),a=e+".glb",s=i.length,u=0;"undefined"!=typeof TextEncoder&&(s=(o=(new TextEncoder).encode(i)).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),m=new DataView(d);m.setUint32(0,1179937895,!0),m.setUint32(4,2,!0),m.setUint32(8,p,!0);var _=new ArrayBuffer(8+s+c),x=new DataView(_);x.setUint32(0,s+c,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(_,8);if(o)y.set(o);else{var T="_".charCodeAt(0);for(l=0;l<s;++l){var v=i.charCodeAt(l);v!=i.codePointAt(l)?y[l]=T:y[l]=v}}var b=new Uint8Array(_,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 F=new ArrayBuffer(f),M=new Uint8Array(F);for(l=0;l<f;++l)M[l]=0;var R=new ArrayBuffer(h),w=new Uint8Array(R);for(l=0;l<h;++l)w[l]=0;var V=[d,_,A,n];for(l=0;l<r._orderedImageData.length;++l)V.push(r._orderedImageData[l].data);V.push(F),V.push(R);var C=new Blob(V,{type:"application/octet-stream"}),S=new g;return S.glTFFiles[a]=C,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype._setNodeTransformation=function(e,t,r){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=r?d._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var n=f.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&n.multiplyInPlace(t.rotationQuaternion),f.Quaternion.IsIdentity(n)||(r&&d._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype._setCameraTransformation=function(e,t,r){t.position.equalsToFloats(0,0,0)||(e.translation=r?d._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray());var n=t.rotationQuaternion;n&&!f.Quaternion.IsIdentity(n)&&(r&&d._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().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,o,i){var a=r instanceof f.Mesh?r:r instanceof f.InstancedMesh?r.sourceMesh:null;if(a){var s=a.getVertexBuffer(e,!0),u=a.getVerticesData(e,void 0,void 0,!0);if(s&&u){var l=f.VertexBuffer.GetTypeByteLength(t),c=u.length*l,h=d._CreateBufferView(0,n.getByteOffset(),c,o,e+" - "+a.name);this._bufferViews.push(h),this._writeAttributeData(e,t,u,o/l,n,i,r)}}},e.prototype._setMorphTargetAttributes=function(e,t,r,n,o){if(r){t.targets||(t.targets=[]);var i={},a=e.getMesh();if(r.hasNormals){var s=a.getVerticesData(f.VertexBuffer.NormalKind,void 0,void 0,!0),u=r.getNormals(),l=(x=e.verticesCount)*(y=12),c=d._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_NORMAL");this._bufferViews.push(c);var h=this._bufferViews.length-1,p=d._CreateAccessor(h,r.name+" - NORMAL","VEC3",5126,x,0,null,null);this._accessors.push(p),i.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.NormalKind,5126,e,r,s,u,y/4,n,o)}if(r.hasPositions){var m=a.getVerticesData(f.VertexBuffer.PositionKind,void 0,void 0,!0),g=r.getPositions();l=(x=e.verticesCount)*(y=12),c=d._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_POSITION"),this._bufferViews.push(c),h=this._bufferViews.length-1;var _={min:new f.Vector3(1/0,1/0,1/0),max:new f.Vector3(-1/0,-1/0,-1/0)};p=d._CreateAccessor(h,r.name+" - POSITION","VEC3",5126,x,0,null,null),this._accessors.push(p),i.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.PositionKind,5126,e,r,m,g,y/4,n,o,_),p.min=_.min.asArray(),p.max=_.max.asArray()}if(r.hasTangents){var x,y,T=a.getVerticesData(f.VertexBuffer.TangentKind,void 0,void 0,!0),v=r.getTangents();l=(x=e.verticesCount)*(y=12),c=d._CreateBufferView(0,n.getByteOffset(),l,y,r.name+"_NORMAL"),this._bufferViews.push(c),h=this._bufferViews.length-1,p=d._CreateAccessor(h,r.name+" - TANGENT","VEC3",5126,x,0,null,null),this._accessors.push(p),i.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.TangentKind,5126,e,r,T,v,y/4,n,o)}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,n){var o,i,a,s=[],u=null;t instanceof f.Mesh?u=t:t instanceof f.InstancedMesh&&(u=t.sourceMesh);var l=[{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(u){for(var c=null,h=this._getMeshPrimitiveMode(u),p={},m=u.morphTargetManager,g=0,_=l;g<_.length;g++){var x=(W=_[g]).kind,y=W.accessorComponentType;if(u.isVerticesDataPresent(x,!0)){var T=this._getVertexBufferFromMesh(x,u);W.byteStride=T?T.getSize()*f.VertexBuffer.GetTypeByteLength(W.accessorComponentType):4*f.VertexBuffer.DeduceStride(x),12===W.byteStride&&(W.accessorType="VEC3"),this._createBufferViewKind(x,y,t,r,W.byteStride,n),W.bufferViewIndex=this._bufferViews.length-1,p[x]=W.bufferViewIndex}}if(u.getTotalIndices()){var v=u.getIndices();if(v){var b=4*v.length;i=d._CreateBufferView(0,r.getByteOffset(),b,void 0,"Indices - "+u.name),this._bufferViews.push(i),c=this._bufferViews.length-1;for(var A=0,E=v.length;A<E;++A)r.setUInt32(v[A])}}if(u.subMeshes)for(var F=0,M=u.subMeshes;F<M.length;F++){var R=M[F],w=R.getMaterial()||u.getScene().defaultMaterial,V=null;if(w)if(u instanceof f.LinesMesh){var C={name:u.name+" material"};(!u.color.equals(f.Color3.White())||u.alpha<1)&&(C.pbrMetallicRoughness={baseColorFactor:u.color.asArray().concat([u.alpha])}),this._materials.push(C),V=this._materials.length-1}else if(w instanceof f.MultiMaterial){var S=w.subMaterials[R.materialIndex];S&&(w=S,V=this._materialMap[w.uniqueId])}else V=this._materialMap[w.uniqueId];var I=null!=V?this._materials[V]:null,B={attributes:{}};this._setPrimitiveMode(B,h);for(var P=0,N=l;P<N.length;P++)if(((x=(W=N[P]).kind)!==f.VertexBuffer.UVKind&&x!==f.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||I&&this._glTFMaterialExporter._hasTexturesPresent(I))&&(z=u.getVerticesData(x,void 0,void 0,!0))&&(T=this._getVertexBufferFromMesh(x,u))){var L=T.getSize(),O=W.bufferViewIndex;if(null!=O){a={min:null,max:null},x==f.VertexBuffer.PositionKind&&(a=d._CalculateMinMaxPositions(z,0,z.length/L,n));var k=d._CreateAccessor(O,x+" - "+t.name,W.accessorType,W.accessorComponentType,z.length/L,0,a.min,a.max);this._accessors.push(k),this._setAttributeKind(B,x)}}if(c&&(k=d._CreateAccessor(c,"indices - "+t.name,"SCALAR",5125,R.indexCount,4*R.indexStart,null,null),this._accessors.push(k),B.indices=this._accessors.length-1),null!=V&&Object.keys(B.attributes).length>0){var U=null!==u.overrideMaterialSideOrientation?u.overrideMaterialSideOrientation:w.sideOrientation;if(U==f.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||U==f.Material.ClockWiseSideOrientation&&n&&u.overrideMaterialSideOrientation!==(null===(o=u.material)||void 0===o?void 0:o.sideOrientation)){var K=null!=c?this._bufferViews[c].byteOffset:null;null==K&&(K=0);var D=null;if(null!=c&&(D=u.getIndices()),D)this._reorderIndicesBasedOnPrimitiveMode(R,h,D,K,r);else for(var G=0,H=l;G<H.length;G++){var z,W=H[G];if(z=u.getVerticesData(W.kind,void 0,void 0,!0)){var q=this._bufferViews[p[W.kind]].byteOffset;q||(q=0),this._reorderVertexAttributeDataBasedOnPrimitiveMode(R,h,U,W.kind,z,q,r,n)}}}B.material=V}if(m)for(var Q=void 0,j=0;j<m.numTargets;++j)Q=m.getTarget(j),this._setMorphTargetAttributes(R,B,Q,r,n);e.primitives.push(B),this._extensionsPostExportMeshPrimitiveAsync("postExport",B,R,r),s.push()}}return Promise.all(s).then((function(){}))},e.prototype._isBabylonCoordinateSystemConvertingNode=function(e){return e instanceof f.TransformNode&&!!e.getWorldMatrix().multiplyToRef(v,f.TmpVectors.Matrix[0]).isIdentity()&&!(e instanceof f.Mesh&&null!==e.geometry||e instanceof f.InstancedMesh&&null!==e.sourceMesh.geometry)},e.prototype._createSceneAsync=function(e,t){var r,n,o,i=this,a={nodes:[]},s=y(y(y(y([],e.transformNodes,!0),e.meshes,!0),e.lights,!0),e.cameras,!0),u=[];this._convertToRightHandedSystem=!e.useRightHandedSystem,this._convertToRightHandedSystemMap={},e.metadata&&(this._options.metadataSelector?a.extras=this._options.metadataSelector(e.metadata):e.metadata.gltf&&(a.extras=e.metadata.gltf.extras)),e.rootNodes.forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem,e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=i._convertToRightHandedSystem}))})),e.rootNodes.forEach((function(e){if(!i._includeCoordinateSystemConversionNodes&&i._isBabylonCoordinateSystemConvertingNode(e)){u.push(e);var t=s.indexOf(e);-1!==t&&s.splice(t,1),e.getDescendants(!1).forEach((function(e){i._convertToRightHandedSystemMap[e.uniqueId]=!1}))}}));var l=new Map;e.cameras.forEach((function(e){if(!i._options.shouldExportNode||i._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}}l.set(e,i._cameras.length),i._cameras.push(t)}}));var c=this._getExportNodes(s),h=c[0],p=c[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(p,"image/png",!0).then((function(){return i._createNodeMapAndAnimationsAsync(e,h,t).then((function(c){return i._createSkinsAsync(e,c,t).then((function(e){if(i._nodeMap=c,i._totalByteLength=t.getByteOffset(),null==i._totalByteLength)throw new Error("undefined byte length!");for(var h=0,p=s;h<p.length;h++){var d=p[h];if(void 0!==(r=i._nodeMap[d.uniqueId])){if(n=i._nodes[r],d.metadata&&(i._options.metadataSelector?n.extras=i._options.metadataSelector(d.metadata):d.metadata.gltf&&(n.extras=d.metadata.gltf.extras)),d instanceof f.Camera&&(n.camera=l.get(d)),d.parent&&-1===u.indexOf(d.parent)||(i._options.shouldExportNode&&!i._options.shouldExportNode(d)?f.Tools.Log("Omitting "+d.name+" from scene."):(i._convertToRightHandedSystemMap[d.uniqueId]&&(n.translation&&(n.translation[2]*=-1,n.translation[0]*=-1),n.rotation=n.rotation?f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(n.rotation)).asArray():f.Quaternion.FromArray([0,1,0,0]).asArray()),a.nodes.push(r))),d instanceof f.Mesh){var m=d;m.skeleton&&(n.skin=e[m.skeleton.uniqueId])}if(o=d.getDescendants(!0),!n.children&&o&&o.length){for(var g=[],_=0,x=o;_<x.length;_++){var y=x[_];null!=i._nodeMap[y.uniqueId]&&g.push(i._nodeMap[y.uniqueId])}g.length&&(n.children=g)}}}a.nodes.length&&i._scenes.push(a)}))}))}))},e.prototype._getExportNodes=function(e){for(var t=[],r=new Set,n=0,o=e;n<o.length;n++){var i=o[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(i)){t.push(i);var a=i;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(i.name)}return[t,r]},e.prototype._createNodeMapAndAnimationsAsync=function(e,t,r){for(var n,o=this,i=Promise.resolve(),a={},s={name:"runtime animations",channels:[],samplers:[]},u=[],l=function(t){i=i.then((function(){var i=o._convertToRightHandedSystemMap[t.uniqueId];return o._createNodeAsync(t,r,i).then((function(l){var c=o._extensionsPostExportNodeAsync("createNodeAsync",l,t,a,r);return null==c?(f.Tools.Warn("Not exporting node ".concat(t.name)),Promise.resolve()):c.then((function(l){l&&(o._nodes.push(l),n=o._nodes.length-1,a[t.uniqueId]=n,e.animationGroups.length||(m._CreateMorphTargetAnimationFromMorphTargetAnimations(t,s,u,a,o._nodes,r,o._bufferViews,o._accessors,i,o._animationSampleRate,o._options.shouldExportAnimation),t.animations.length&&m._CreateNodeAnimationFromNodeAnimations(t,s,u,a,o._nodes,r,o._bufferViews,o._accessors,i,o._animationSampleRate,o._options.shouldExportAnimation)))}))}))}))},c=0,h=t;c<h.length;c++)l(h[c]);return i.then((function(){return s.channels.length&&s.samplers.length&&o._animations.push(s),u.forEach((function(e){e.channels.length&&e.samplers.length&&o._animations.push(e)})),e.animationGroups.length&&m._CreateNodeAndMorphAnimationFromAnimationGroups(e,o._animations,a,o._nodes,r,o._bufferViews,o._accessors,o._convertToRightHandedSystemMap,o._animationSampleRate,o._options.shouldExportAnimation),a}))},e.prototype._createNodeAsync=function(e,t,r){var n=this;return Promise.resolve().then((function(){var o={},i={primitives:[]};if(e.name&&(o.name=e.name),e instanceof f.TransformNode){if(n._setNodeTransformation(o,e,r),e instanceof f.Mesh){var a=e.morphTargetManager;if(a&&a.numTargets>0){i.weights=[];for(var s=0;s<a.numTargets;++s)i.weights.push(a.getTarget(s).influence)}}return n._setPrimitiveAttributesAsync(i,e,t,r).then((function(){return i.primitives.length&&(n._meshes.push(i),o.mesh=n._meshes.length-1),o}))}return e instanceof f.Camera?(n._setCameraTransformation(o,e,r),o):o}))},e.prototype._createSkinsAsync=function(e,t,r){for(var n,o=Promise.resolve(),i={},a=0,s=e.skeletons;a<s.length;a++){var u=s[a];if(!(u.bones.length<=0)){for(var l={joints:[]},c=[],h={},p=-1,m=0;m<u.bones.length;++m)-1!==(g=null!==(n=(_=u.bones[m]).getIndex())&&void 0!==n?n:m)&&(h[g]=_,g>p&&(p=g));for(var g=0;g<=p;++g){var _=h[g];c.push(_.getInvertedAbsoluteTransform());var x=_.getTransformNode();x&&null!==t[x.uniqueId]&&void 0!==t[x.uniqueId]?l.joints.push(t[x.uniqueId]):f.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}if(l.joints.length>0){var y=64*c.length,T=r.getByteOffset(),v=d._CreateBufferView(0,T,y,void 0,"InverseBindMatrices - "+u.name);this._bufferViews.push(v);var b=this._bufferViews.length-1,A=d._CreateAccessor(b,"InverseBindMatrices - "+u.name,"MAT4",5126,c.length,null,null,null),E=this._accessors.push(A)-1;l.inverseBindMatrices=E,this._skins.push(l),i[u.uniqueId]=this._skins.length-1,c.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))}}}return o.then((function(){return i}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),A=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}(),E=0,F=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new b(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 o=t.replace(/\.[^/.]+$/,"");return new b(e,r)._generateGLBAsync(o).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}(),M="KHR_texture_transform",R=function(){function e(){this.name=M,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={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng&&(n.rotation=-r.wAng,o=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),!o)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[M]=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(M)),r(null)):n("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e}();b.RegisterExtension(M,(function(){return new R}));var w="KHR_lights_punctual",V=function(){function e(e){this.name=w,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[w]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n){var o=this;return new Promise((function(i){if(t&&r instanceof f.ShadowLight){var a=r,s=void 0,u=a.getTypeID()==f.Light.LIGHTTYPEID_POINTLIGHT?"point":a.getTypeID()==f.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":a.getTypeID()==f.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==u)f.Logger.Warn("".concat(e,": Light ").concat(a.name," is not supported in ").concat(w));else{var l=a.position.clone(),c=o._exporter._convertToRightHandedSystemMap[r.uniqueId];if(l.equals(f.Vector3.Zero())||(c&&d._GetRightHandedPositionVector3FromRef(l),t.translation=l.asArray()),"point"!==u){var h=a.direction,p=-Math.atan2(h.z*(o._exporter._babylonScene.useRightHandedSystem?-1:1),h.x)+Math.PI/2,m=Math.sqrt(h.x*h.x+h.z*h.z),g=-Math.atan2(h.y,m),_=f.Quaternion.RotationYawPitchRoll(p,g,0);c&&d._GetRightHandedQuaternionFromRef(_),_.equals(f.Quaternion.Identity())||(t.rotation=_.asArray())}if(a.falloffType!==f.Light.FALLOFF_GLTF&&f.Logger.Warn("".concat(e,": Light falloff for ").concat(a.name," does not match the ").concat(w," specification!")),s={type:u},a.diffuse.equals(f.Color3.White())||(s.color=a.diffuse.asArray()),1!==a.intensity&&(s.intensity=a.intensity),a.range!==Number.MAX_VALUE&&(s.range=a.range),"spot"===u){var x=a;x.angle!==Math.PI/2&&(null==s.spot&&(s.spot={}),s.spot.outerConeAngle=x.angle/2),0!==x.innerAngle&&(null==s.spot&&(s.spot={}),s.spot.innerConeAngle=x.innerAngle/2)}null==o._lights&&(o._lights={lights:[]}),o._lights.lights.push(s);var y={light:o._lights.lights.length-1},T=r.parent;if(T&&1==T.getChildren().length){var v=o._exporter._nodes[n[T.uniqueId]];if(v){var b=f.TmpVectors.Matrix[0],A=f.TmpVectors.Matrix[1],E=v.translation?new f.Vector3(v.translation[0],v.translation[1],v.translation[2]):f.Vector3.Zero(),F=v.rotation?new f.Quaternion(v.rotation[0],v.rotation[1],v.rotation[2],v.rotation[3]):f.Quaternion.Identity(),M=v.scale?new f.Vector3(v.scale[0],v.scale[1],v.scale[2]):f.Vector3.One();f.Matrix.ComposeToRef(M,F,E,b),b.invertToRef(A);var R=f.TmpVectors.Matrix[2],V=t.translation?new f.Vector3(t.translation[0],t.translation[1],t.translation[2]):f.Vector3.Zero();a instanceof f.DirectionalLight&&V.subtractInPlace(o._exporter._babylonScene.useRightHandedSystem?a.direction:d._GetRightHandedPositionVector3(a.direction));var C=o._exporter._babylonScene.useRightHandedSystem?f.Quaternion.Identity():new f.Quaternion(0,1,0,0);t.rotation&&C.multiplyInPlace(new f.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var S=t.scale?new f.Vector3(t.scale[0],t.scale[1],t.scale[2]):f.Vector3.One();f.Matrix.ComposeToRef(S,C,V,R),R.multiplyToRef(A,R);var I=f.TmpVectors.Vector3[0],B=f.TmpVectors.Quaternion[0],P=f.TmpVectors.Vector3[1];return R.decompose(I,B,P),v.scale=I.asArray(),v.rotation=B.asArray(),v.translation=P.asArray(),null==v.extensions&&(v.extensions={}),v.extensions[w]=y,void i(null)}}null==t.extensions&&(t.extensions={}),t.extensions[w]=y}}i(t)}))},e}();b.RegisterExtension(w,(function(e){return new V(e)}));var C="KHR_materials_clearcoat",S=function(){function e(e){this.name=C,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 o,i=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture);o=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!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=a?a:void 0,hasTextures:function(){return null!==s.clearcoatTexture||null!==s.clearcoatRoughnessTexture||null!==s.clearcoatRoughnessTexture}};t.extensions[C]=s}e(t)}))},e}();b.RegisterExtension(C,(function(e){return new S(e)}));var I="KHR_materials_iridescence",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.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 o=n._exporter._glTFMaterialExporter._getTextureInfo(r.iridescence.texture),i=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!=o?o:void 0,iridescenceThicknessTexture:null!=i?i:void 0,hasTextures:function(){return null!==a.iridescenceTexture||null!==a.iridescenceThicknessTexture}};t.extensions[I]=a}e(t)}))},e}();b.RegisterExtension(I,(function(e){return new B(e)}));var P="KHR_materials_sheen",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){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 o,i,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!==(o=r.sheen.roughness)&&void 0!==o?o:0,hasTextures:function(){return null!==u.sheenColorTexture||null!==u.sheenRoughnessTexture}};r.sheen.texture&&(u.sheenColorTexture=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==i?i: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[P]=u}e(t)}))},e}();b.RegisterExtension(P,(function(e){return new N(e)}));var L="KHR_materials_unlit",O=function(){function e(){this.name=L,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 o=!1;r instanceof f.PBRMaterial?o=r.unlit:r instanceof f.StandardMaterial&&(o=r.disableLighting),o&&(n._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions[L]={}),e(t)}))},e}();b.RegisterExtension(L,(function(){return new O}));var k="KHR_materials_ior",U=function(){function e(){this.name=k,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 o={ior:r.indexOfRefraction};t.extensions=t.extensions||{},t.extensions[k]=o}e(t)}))},e}();b.RegisterExtension(k,(function(e){return new U}));var K="KHR_materials_specular",D=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){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 o,i;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0,t.extensions=t.extensions||{};var a=null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(r.metallicReflectanceTexture))&&void 0!==o?o:void 0,s=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.reflectanceTexture))&&void 0!==i?i: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[K]=u}e(t)}))},e}();b.RegisterExtension(K,(function(e){return new D(e)}));var G="KHR_materials_volume",H=function(){function e(e){this.name=G,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 o;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,a={thicknessFactor:0==i.maximumThickness?void 0:i.maximumThickness,thicknessTexture:null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(i.thicknessTexture))&&void 0!==o?o:void 0,attenuationDistance:i.tintColorAtDistance==Number.POSITIVE_INFINITY?void 0:i.tintColorAtDistance,attenuationColor:i.tintColor.equalsFloats(1,1,1)?void 0:i.tintColor.asArray(),hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions[G]=a}e(t)}))},e}();b.RegisterExtension(G,(function(e){return new H(e)}));var z="KHR_materials_transmission",W=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.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 o;if(r instanceof f.PBRMaterial&&n._isExtensionEnabled(r)){n._wasUsed=!0;var i=r.subSurface,a={transmissionFactor:0===i.refractionIntensity?void 0:i.refractionIntensity,transmissionTexture:null!==(o=n._exporter._glTFMaterialExporter._getTextureInfo(i.refractionIntensityTexture))&&void 0!==o?o:void 0,hasTextures:function(){return n._hasTexturesExtension(r)}};t.extensions=t.extensions||{},t.extensions[z]=a}e(t)}))},e}();b.RegisterExtension(z,(function(e){return new W(e)}));var q="EXT_mesh_gpu_instancing",Q=function(){function e(e){this.name=q,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,o){var i=this;return new Promise((function(e){if(t&&r instanceof f.Mesh&&r.hasThinInstances&&o){i._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,m=!1,g=new Float32Array(3*r.thinInstanceCount),_=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),g.set(l.asArray(),3*y),_.set(c.normalize().asArray(),4*y),x.set(h.asArray(),3*y),p=p||!l.equalsWithEpsilon(n),d=d||!c.equalsWithEpsilon(a),m=m||!h.equalsWithEpsilon(s),y++;var b={attributes:{}};p&&(b.attributes.TRANSLATION=i._buildAccessor(g,"VEC3",r.thinInstanceCount,o,5126)),d&&(b.attributes.ROTATION=i._buildAccessor(_,"VEC4",r.thinInstanceCount,o,5126)),m&&(b.attributes.SCALE=i._buildAccessor(x,"VEC3",r.thinInstanceCount,o,5126)),t.extensions=t.extensions||{},t.extensions[q]=b}e(t)}))},e.prototype._buildAccessor=function(e,t,r,n,o){var i=n.getByteOffset();switch(o){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:i,byteLength:e.length*f.VertexBuffer.GetTypeByteLength(o)},u=this._exporter._bufferViews.length;this._exporter._bufferViews.push(s);var l=this._exporter._accessors.length,c={bufferView:u,componentType:o,count:r,type:t,normalized:5120==o||5122==o};return this._exporter._accessors.push(c),l},e}();b.RegisterExtension(q,(function(e){return new Q(e)}));var j="KHR_materials_emissive_strength",Y=function(){function e(){this.name=j,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 o=r.emissiveColor.asArray(),i=Math.max.apply(Math,o);if(i>1){n._wasUsed=!0,t.extensions||(t.extensions={});var a={emissiveStrength:i},s=r.emissiveColor.scale(1/a.emissiveStrength);t.emissiveFactor=s.asArray(),t.extensions[j]=a}return e(t)}))},e}();b.RegisterExtension(j,(function(e){return new Y}));var X=function(){function e(){}return e.CreateSTL=function(e,t,r,n,o,i,a,s){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===n&&(n=!1),void 0===o&&(o=!0),void 0===i&&(i=!1),void 0===a&&(a=!1),void 0===s&&(s=!1);var u=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],o=[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])],i=o[0].subtract(o[1]),a=o[2].subtract(o[1]);return{v:o,n:f.Vector3.Cross(a,i).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(),o=void 0;for(o=0;o<r.length;o+=3)f.Vector3.TransformCoordinatesFromFloatsToRef(r[o],r[o+1],r[o+2],e.computeWorldMatrix(!0),n).toArray(r,o);return r}return e.getVerticesData(f.VertexBuffer.PositionKind)||[]};a&&(i=!0);var p="",d=0,m=0;if(n){for(var g=0;g<e.length;g++)d+=(T=(x=e[g]).getIndices())?T.length/3:0;var _=new ArrayBuffer(84+50*d);m+=80,(p=new DataView(_)).setUint32(m,d,o),m+=4}else s||(p="solid stlmesh\r\n");for(g=0;g<e.length;g++){var x=e[g];!n&&s&&(p+="solid "+x.name+"\r\n"),!i&&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?(m=l(p,m,b.n,o),m=l(p,m,b.v[0],o),m=l(p,m,b.v[1],o),m=l(p,m,b.v[2],o),m+=2):(p+="\tfacet normal "+b.n.x+" "+b.n.y+" "+b.n.z+"\r\n",p+="\t\touter loop\r\n",p+="\t\t\tvertex "+b.v[0].x+" "+b.v[0].y+" "+b.v[0].z+"\r\n",p+="\t\t\tvertex "+b.v[1].x+" "+b.v[1].y+" "+b.v[1].z+"\r\n",p+="\t\t\tvertex "+b.v[2].x+" "+b.v[2].y+" "+b.v[2].z+"\r\n",p+="\t\tendloop\r\n",p+="\tendfacet\r\n")}!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}(),Z=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==Z){Z.BABYLON=Z.BABYLON||{};var J=Z.BABYLON;J.GLTF2=J.GLTF2||{},J.GLTF2.Exporter=J.GLTF2.Exporter||{},J.GLTF2.Exporter.Extensions=J.GLTF2.Exporter.Extensions||{};var $=[];for(var ee in t)J[ee]=t[ee],$.push(ee);for(var ee in r)J[ee]=r[ee],$.push(ee);for(var ee in i)J[ee]=i[ee],$.push(ee);for(var ee in a)J.GLTF2.Exporter.Extensions[ee]=a[ee],$.push(ee);for(var ee in s)$.indexOf(ee)>-1||(J.GLTF2.Exporter[ee]=s[ee])}var te=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==te)for(var re in e)te.BABYLON[re]=e[re];var ne=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==ne)for(var oe in u)ne.BABYLON[oe]=u[oe];const ie=l})(),o.default})()));
|
|
2
2
|
//# sourceMappingURL=babylonjs.serializers.min.js.map
|