12 |
- !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,(function(e){return(()=>{"use strict";var t={520:t=>{t.exports=e}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{n.d(a,{default:()=>z});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 o={};n.r(o),n.d(o,{GLTF2Export:()=>F});var i={};n.r(i),n.d(i,{KHR_lights_punctual:()=>C,KHR_materials_clearcoat:()=>w,KHR_materials_sheen:()=>B,KHR_materials_unlit:()=>P,KHR_texture_transform:()=>E});var s={};n.r(s),n.d(s,{GLTF2Export:()=>F,GLTFData:()=>g,KHR_lights_punctual:()=>C,KHR_materials_clearcoat:()=>w,KHR_materials_sheen:()=>B,KHR_materials_unlit:()=>P,KHR_texture_transform:()=>E,_BinaryWriter:()=>b,_Exporter:()=>v,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtensionV2:()=>A});var u={};n.r(u),n.d(u,{STLExport:()=>N});var l={};n.r(l),n.d(l,{GLTF2Export:()=>F,GLTFData:()=>g,KHR_lights_punctual:()=>C,KHR_materials_clearcoat:()=>w,KHR_materials_sheen:()=>B,KHR_materials_unlit:()=>P,KHR_texture_transform:()=>E,OBJExport:()=>h,STLExport:()=>N,_BinaryWriter:()=>b,_Exporter:()=>v,_GLTFAnimation:()=>m,_GLTFMaterialExporter:()=>T,_GLTFUtilities:()=>d,__IGLTFExporterExtension:()=>p,__IGLTFExporterExtensionV2:()=>A});var c,f=n(520),h=function(){function e(){}return e.OBJ=function(e,t,r,n){var a=[],o=1,i=1;t&&(r||(r="mat"),a.push("mtllib "+r+".mtl"));for(var s=0;s<e.length;s++){a.push("g object"+s),a.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&&a.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?a.push("v "+p[y]+" "+p[y+1]+" "+p[y+2]):a.push("v "+p[y]+" "+p[y+1]+" "+-p[y+2]),_++;if(null!=d)for(y=0;y<d.length;y+=3)a.push("vn "+d[y]+" "+d[y+1]+" "+d[y+2]);if(null!=m)for(y=0;y<m.length;y+=2)a.push("vt "+m[y]+" "+m[y+1]),x++;for(y=0;y<g.length;y+=3){var T=[String(g[y+2]+o),String(g[y+1]+o),String(g[y]+o)],v=[String(g[y+2]+i),String(g[y+1]+i),String(g[y]+i)],b=["","",""],A=T,F=null!=m?v:b,M=null!=d?T:b;a.push("f "+A[0]+"/"+F[0]+"/"+M[0]+" "+A[1]+"/"+F[1]+"/"+M[1]+" "+A[2]+"/"+F[2]+"/"+M[2])}n&&u&&e[s].bakeTransformIntoVertices(u),o+=_,i+=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 a.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,a){var o={buffer:e,byteLength:r};return t&&(o.byteOffset=t),a&&(o.name=a),n&&(o.byteStride=n),o},e._CreateAccessor=function(e,t,r,n,a,o,i,s){var u={name:t,bufferView:e,componentType:n,count:a,type:r};return null!=i&&(u.min=i),null!=s&&(u.max=s),null!=o&&(u.byteOffset=o),u},e._CalculateMinMaxPositions=function(t,r,n,a){var o,i,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){o=3*c,i=f.Vector3.FromArray(t,o),a&&e._GetRightHandedPositionVector3FromRef(i),s=i.asArray();for(var p=0;p<3;++p){var d=s[p];d<u[p]&&(u[p]=d),d>l[p]&&(l[p]=d),++o}}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._CreateNodeAnimation=function(t,r,n,a,o,i){var s=[],u=[],l=r.getKeys(),c=e.calculateMinMaxKeyFrames(l),h=e._DeduceInterpolation(l,n,o),p=c.max-c.min,d=h.interpolationType,m=h.shouldBakeAnimation;return m?e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,s,u,c,a,o):"LINEAR"===d||"STEP"===d?e._CreateLinearOrStepAnimation(t,r,n,p,s,u,a,o):"CUBICSPLINE"===d?e._CreateCubicSplineAnimation(t,r,n,p,s,u,a,o):e._CreateBakedAnimation(t,r,n,c.min,c.max,r.framePerSecond,i,s,u,c,a,o),s.length&&u.length?{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)}:null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,a=e.targetProperty.split(".");switch(a[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(a[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,a,o,i,s,u,l,c){var h;if(t instanceof f.TransformNode&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p],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,a,i,s,u,l,g.useQuaternion,c),h.samplers.length&&h.channels.length&&n.push(h))}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,a,o,i,s,u,l,c){var h;if(t instanceof f.Mesh){var p=t.morphTargetManager;if(p)for(var d=0;d<p.numTargets;++d)for(var m=0,g=p.getTarget(d).animations;m<g.length;m++){for(var _=g[m],x=new f.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),v=0;v<T.length;++v)for(var b=T[v],A=0;A<p.numTargets;++A)A==d?y.push(b):y.push({frame:b.frame,value:0});x.setKeys(y);var F=e._DeduceAnimationInfo(x);F&&(h={name:x.name,samplers:[],channels:[]},e.AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:h,t,x,F.dataAccessorType,F.animationChannelTargetPath,a,i,s,u,l,F.useQuaternion,c,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,a,o,i,s,u,l){var c,h;if(t.animationGroups)for(var p=function(a){var p=new Map,d=new Map,m=new Set,g=a.to-a.from;h={name:a.name,channels:[],samplers:[]};for(var _=function(r){var g=a.targetedAnimations[r],_=g.target,x=g.animation;if(_ instanceof f.TransformNode||1===_.length&&_[0]instanceof f.TransformNode){if(v=e._DeduceAnimationInfo(g.animation)){var y=_ instanceof f.TransformNode?_:_[0],T=u[y.uniqueId];e.AddAnimation("".concat(x.name),h,y,x,v.dataAccessorType,v.animationChannelTargetPath,n,o,i,s,T,v.useQuaternion,l)}}else if(_ instanceof f.MorphTarget||1===_.length&&_[0]instanceof f.MorphTarget){var v;if(v=e._DeduceAnimationInfo(g.animation)){var b=_ instanceof f.MorphTarget?_:_[0];if(b){var A=t.morphTargetManagers.find((function(e){for(var t=0;t<e.numTargets;++t)if(e.getTarget(t)===b)return!0;return!1}));if(A){var F=t.meshes.find((function(e){return e.morphTargetManager===A}));F&&(p.has(F)||p.set(F,new Map),null===(c=p.get(F))||void 0===c||c.set(b,x),m.add(F),d.set(F,x))}}}}},x=0;x<a.targetedAnimations.length;++x)_(x);m.forEach((function(t){for(var r=t.morphTargetManager,u=null,c=[],m=d.get(t).getKeys(),_=m.length,x=0;x<_;++x)for(var y=0;y<r.numTargets;++y){var T=r.getTarget(y),v=p.get(t);if(v){var b=v.get(T);b?(u||(u=new f.Animation("".concat(a.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,f.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),c.push(b.getKeys()[x])):c.push({frame:a.from+g/_*x,value:T.influence,inTangent:m[0].inTangent?0:void 0,outTangent:m[0].outTangent?0:void 0})}}u.setKeys(c);var A=e._DeduceAnimationInfo(u);A&&e.AddAnimation("".concat(a.name,"_").concat(t.name,"_MorphWeightAnimation"),h,t,u,A.dataAccessorType,A.animationChannelTargetPath,n,o,i,s,!1,A.useQuaternion,l,null==r?void 0:r.numTargets)})),h.channels.length&&h.samplers.length&&r.push(h)},d=0,m=t.animationGroups;d<m.length;d++)p(m[d])},e.AddAnimation=function(t,r,n,a,o,i,s,u,l,c,f,h,p,m){var g,_,x,y,T,v,b,A=e._CreateNodeAnimation(n,a,i,f,h,p);if(A){if(m){for(var F=0,M=0,E=[];A.inputs.length>0;)M=A.inputs.shift(),F%m==0&&E.push(M),F++;A.inputs=E}var R=s[n.uniqueId],C=4*A.inputs.length;g=d._CreateBufferView(0,u.getByteOffset(),C,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,C=4*d._GetDataAccessorElementCount(o)*A.outputs.length,g=d._CreateBufferView(0,u.getByteOffset(),C,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"),o,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:i}},r.channels.push(b)}},e._CreateBakedAnimation=function(t,r,n,a,o,i,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(a/i);for(var A=r.getKeys(),F=0,M=A.length;F<M;++F){if(b=null,y=A[F],F+1<M)if(T=A[F+1],y.value.equals&&y.value.equals(T.value)||y.value===T.value){if(0!==F)continue;b=y.frame}else b=T.frame;else{if(v=A[F-1],y.value.equals&&y.value.equals(v.value)||y.value===v.value)continue;b=o}if(b)for(var E=y.frame;E<=b;E+=s)if((m=f.Tools.FloatRound(E/i))!==_){_=m,x=m;var R={key:0,repeatCount:0,loopMode:r.loopMode};d=r._interpolate(E,R),e._SetInterpolatedValue(t,d,m,r,n,g,u,l,h,p)}}x&&(c.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,a,o,i,s){var u,l,c=null,h=e._GetBasePositionRotationOrScale(r,o,i,s);if(a===f.Animation.ANIMATIONTYPE_FLOAT)switch(l=(u=n.targetProperty.split("."))?u[1]:"",c=s?f.Quaternion.FromArray(h).normalize():f.Vector3.FromArray(h),l){case"x":case"y":c[l]=i&&s&&"scale"!==o?-t:t;break;case"z":c[l]=i&&!s&&"scale"!==o?-t:t;break;case"w":c.w=t;break;default:f.Tools.Error('glTFAnimation: Unsupported component type "'.concat(l,'" for scale animation!'))}return c},e._SetInterpolatedValue=function(e,t,r,n,a,o,i,s,u,l){var c,h=n.dataType;i.push(r),"number"==typeof t&&e instanceof f.TransformNode&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,h,a,u,l)),t&&("rotation"===a?(l?o=t:(c=t,f.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,o)),u&&(d._GetRightHandedQuaternionFromRef(o),e.parent||(o=f.Quaternion.FromArray([0,1,0,0]).multiply(o))),s.push(o.asArray())):"weights"===a?s.push([t]):(c=t,u&&"scale"!==a&&(d._GetRightHandedPositionVector3FromRef(c),e.parent||(c.x*=-1,c.z*=-1)),s.push(c.asArray())))},e._CreateLinearOrStepAnimation=function(t,r,n,a,o,i,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];o.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,i,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,n,a,o,i,s,u){r.getKeys().forEach((function(l){o.push(l.frame/r.framePerSecond),e.AddSplineTangent(t,c.INTANGENT,i,n,"CUBICSPLINE",l,a,u,s),e._AddKeyframeValue(l,r,i,n,t,s,u),e.AddSplineTangent(t,c.OUTTANGENT,i,n,"CUBICSPLINE",l,a,u,s)}))},e._GetBasePositionRotationOrScale=function(e,t,r,n){var a;return"rotation"===t?n?e.rotationQuaternion?(a=e.rotationQuaternion.asArray(),r&&(d._GetRightHandedQuaternionArrayFromRef(a),e.parent||(a=f.Quaternion.FromArray([0,1,0,0]).multiply(f.Quaternion.FromArray(a)).asArray()))):a=f.Quaternion.Identity().asArray():(a=e.rotation.asArray(),d._GetRightHandedNormalArray3FromRef(a)):"translation"===t?(a=e.position.asArray(),r&&d._GetRightHandedPositionArray3FromRef(a)):a=e.scaling.asArray(),a},e._AddKeyframeValue=function(e,t,r,n,a,o,i){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);o&&(d._GetRightHandedQuaternionFromRef(h),a.parent||(h=f.Quaternion.FromArray([0,1,0,0]).multiply(h))),s=h.asArray()}else"translation"===n&&o&&(d._GetRightHandedNormalArray3FromRef(s),a.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,a,t,l,n,o,i)){if("rotation"===n){var p=i?u:f.Quaternion.RotationYawPitchRoll(u.y,u.x,u.z).normalize();o&&(d._GetRightHandedQuaternionFromRef(p),a.parent||(p=f.Quaternion.FromArray([0,1,0,0]).multiply(p))),r.push(p.asArray())}else"translation"===n&&o&&(d._GetRightHandedNormalVector3FromRef(u),a.parent||(u.x*=-1,u.z*=-1));r.push(u.asArray())}}else l===f.Animation.ANIMATIONTYPE_QUATERNION?(s=e.value.normalize().asArray(),o&&(d._GetRightHandedQuaternionArrayFromRef(s),a.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,a,o=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var i=0,s=e.length;i<s;++i)if((a=e[i]).inTangent||a.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",o=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||a.interpolation&&a.interpolation===f.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",o=!0;break}}else n=a.interpolation&&a.interpolation===f.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:o}},e.AddSplineTangent=function(e,t,r,n,a,o,i,s,u){var l,h=t===c.INTANGENT?o.inTangent:o.outTangent;if("CUBICSPLINE"===a){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],a=void 0;e(t,".glb")?a={type:"model/gltf-binary"}:e(t,".bin")?a={type:"application/octet-stream"}:e(t,".gltf")?a={type:"model/gltf+json"}:e(t,".jpeg")||e(t,".jpg")?a={type:"image/jpeg"}:e(t,".png")&&(a={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],a)),r.click()}},e}();function _(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function x(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!((a=(a=i.trys).length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function y(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}Object.create,Object.create;var T=function(){function e(e){this._textureMap={},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,a=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?a.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?a.push(n._convertPBRMaterialAsync(e,t,r)):f.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(a).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 a=e.extensions[n];if(a)return null===(t=a.hasTextures)||void 0===t?void 0:t.call(a)}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,a,o,i,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().scale(.5),d=t.alpha,m=(r=f.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower),n=Math.pow(r/h.x,.333333),a=u.y,o=l.y,i=c.y,s=h.y,(1-n)*(1-n)*(1-n)*a+3*(1-n)*(1-n)*n*o+3*(1-n)*n*n*i+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,a=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,o=a*a-4*n*(this._DielectricSpecular.r-t);return f.Scalar.Clamp((-a+Math.sqrt(o))/(2*n),0,1)},e._SetAlphaMode=function(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)},e.prototype._convertStandardMaterialAsync=function(t,r,n){var a=this._exporter._materialMap,o=this._exporter._materials,i=[],s=this._convertToGLTFPBRMetallicRoughness(t),u={name:t.name};return null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||f.Tools.Warn(t.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),u.doubleSided=!0),n&&(t.diffuseTexture&&i.push(this._exportTextureAsync(t.diffuseTexture,r).then((function(e){e&&(s.baseColorTexture=e)}))),t.bumpTexture&&i.push(this._exportTextureAsync(t.bumpTexture,r).then((function(e){e&&(u.normalTexture=e,null!=t.bumpTexture&&1!==t.bumpTexture.level&&(u.normalTexture.scale=t.bumpTexture.level))}))),t.emissiveTexture&&(u.emissiveFactor=[1,1,1],i.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(u.emissiveTexture=e)})))),t.ambientTexture&&i.push(this._exportTextureAsync(t.ambientTexture,r).then((function(e){if(e){var t={index:e.index};u.occlusionTexture=t,t.strength=1}})))),(t.alpha<1||t.opacityTexture)&&(t.alphaMode===f.Constants.ALPHA_COMBINE?u.alphaMode="BLEND":f.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e.FuzzyEquals(t.emissiveColor,f.Color3.Black(),e._Epsilon)&&(u.emissiveFactor=t.emissiveColor.asArray()),u.pbrMetallicRoughness=s,e._SetAlphaMode(u,t),o.push(u),a[t.uniqueId]=o.length-1,this._finishMaterial(i,u,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var a=this;return Promise.all(e).then((function(){for(var e=null,o=0,i=a._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);o<i.length;o++){var s=i[o];e||(e=[]),e.push(a._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=a._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._convertPBRMetallicRoughnessMaterialAsync=function(t,r,n){var a=this._exporter._materialMap,o=this._exporter._materials,i=[],s={};t.baseColor&&(s.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,t.alpha]),null!=t.metallic&&1!==t.metallic&&(s.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(s.roughnessFactor=t.roughness);var u={name:t.name};return t.doubleSided&&(u.doubleSided=t.doubleSided),e._SetAlphaMode(u,t),n&&(null!=t.baseTexture&&i.push(this._exportTextureAsync(t.baseTexture,r).then((function(e){e&&(s.baseColorTexture=e)}))),t.normalTexture&&i.push(this._exportTextureAsync(t.normalTexture,r).then((function(e){e&&(u.normalTexture=e,1!==t.normalTexture.level&&(u.normalTexture.scale=t.normalTexture.level))}))),t.occlusionTexture&&i.push(this._exportTextureAsync(t.occlusionTexture,r).then((function(e){e&&(u.occlusionTexture=e,null!=t.occlusionStrength&&(u.occlusionTexture.strength=t.occlusionStrength))}))),t.emissiveTexture&&i.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(u.emissiveTexture=e)})))),e.FuzzyEquals(t.emissiveColor,f.Color3.Black(),e._Epsilon)&&(u.emissiveFactor=t.emissiveColor.asArray()),u.pbrMetallicRoughness=s,o.push(u),a[t.uniqueId]=o.length-1,this._finishMaterial(i,u,t,r)},e.prototype._createBase64FromCanvasAsync=function(e,t,r,n){var a=this;return new Promise((function(o,i){return _(a,void 0,void 0,(function(){var a,i,s,u,l,c;return x(this,(function(h){switch(h.label){case 0:return a=f.Constants.TEXTURETYPE_UNSIGNED_INT,i=this._exporter._babylonScene,s=i.getEngine(),u=s.createRawTexture(e,t,r,f.Constants.TEXTUREFORMAT_RGBA,!1,!0,f.Texture.NEAREST_SAMPLINGMODE,null,a),[4,f.TextureTools.ApplyPostProcess("pass",u,i,a,f.Constants.TEXTURE_NEAREST_SAMPLINGMODE,f.Constants.TEXTUREFORMAT_RGBA)];case 1:return h.sent(),[4,s._readTexturePixels(u,t,r)];case 2:return l=h.sent(),[4,f.Tools.DumpDataAsync(t,r,l,n,void 0,!0,!1)];case 3:return c=h.sent(),o(c),[2]}}))}))}))},e.prototype._createWhiteTexture=function(e,t,r){for(var n=new Uint8Array(e*t*4),a=0;a<n.length;a+=4)n[a]=n[a+1]=n[a+2]=n[a+3]=255;return f.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,a,o=e?e.getSize():{width:0,height:0},i=t?t.getSize():{width:0,height:0};return o.width<i.width?(n=e&&e instanceof f.Texture?f.TextureTools.CreateResizedCopy(e,i.width,i.height,!0):this._createWhiteTexture(i.width,i.height,r),a=t):o.width>i.width?(a=t&&t instanceof f.Texture?f.TextureTools.CreateResizedCopy(t,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,r),n=e):(n=e,a=t),{texture1:n,texture2:a}},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,a){var o;return _(this,void 0,void 0,(function(){var i,s,u,l,c,h,p,d,m,g,_,y,T,v,b,A,F,M,E,R,C,V,w,S,B,I,P,N,L,O,k,G;return x(this,(function(x){switch(x.label){case 0:return i=[],t||r?(s=t?t.getScene():r?r.getScene():null)?(u=this._resizeTexturesToSameDimensions(t,r,s),l=null===(o=u.texture1)||void 0===o?void 0:o.getSize(),c=void 0,h=void 0,p=l.width,d=l.height,[4,u.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return 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,I=0;I<d;++I)for(P=0;P<p;++P)F=4*(p*I+P),M=new f.Color3(c[F],c[F+1],c[F+2]).toLinearSpace().multiply(n.diffuseColor),E=new f.Color3(h[F],h[F+1],h[F+2]).toLinearSpace().multiply(n.specularColor),R=h[F+3]*n.glossiness,C={diffuseColor:M,specularColor:E,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(C),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),T[F]=255*V.baseColor.r,T[F+1]=255*V.baseColor.g,T[F+2]=255*V.baseColor.b,T[F+3]=u.texture1.hasAlpha?255*c[F+3]:255,y[F]=0,y[F+1]=255*V.roughness,y[F+2]=255*V.metallic,y[F+3]=255;for(w={baseColor:v,metallic:b,roughness:A},S=!1,B=!1,I=0;I<d;++I)for(P=0;P<p;++P)T[N=4*(p*I+P)]/=w.baseColor.r>e._Epsilon?w.baseColor.r:1,T[N+1]/=w.baseColor.g>e._Epsilon?w.baseColor.g:1,T[N+2]/=w.baseColor.b>e._Epsilon?w.baseColor.b:1,L=f.Color3.FromInts(T[N],T[N+1],T[N+2]),O=L.toGammaSpace(),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)||(B=!0),y[N+1]/=w.roughness>e._Epsilon?w.roughness:1,y[N+2]/=w.metallic>e._Epsilon?w.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&&(G=this._createBase64FromCanvasAsync(y,p,d,a).then((function(e){w.metallicRoughnessTextureBase64=e})),i.push(G)),B&&(G=this._createBase64FromCanvasAsync(T,p,d,a).then((function(e){w.baseColorTextureBase64=e})),i.push(G)),[2,Promise.all(i).then((function(){return w}))];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),a=1-this._getMaxComponent(t.specularColor),o=e._SolveMetallic(r,n,a),i=t.diffuseColor.scale(a/(1-e._DielectricSpecular.r)/Math.max(1-o,e._Epsilon)),s=t.specularColor.subtract(e._DielectricSpecular.scale(1-o)).scale(1/Math.max(o,e._Epsilon)),u=f.Color3.Lerp(i,s,o*o);return{baseColor:u=u.clampToRef(0,1,u),metallic:o,roughness:1-t.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){var a=[],o={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&a.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var i=e._metallicTexture;i&&a.push(this._exportTextureAsync(i,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(a).then((function(){return o}))},e.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof f.Texture?e.samplingMode:null;if(null!=r)switch(r){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._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof f.Texture?e.wrapU:f.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof f.Texture?e.wrapV:f.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){var a=this;return Promise.resolve().then((function(){var o=a._exporter._samplers,i=a._exporter._textures,s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},u=null,l=e._albedoTexture,c=e._reflectivityTexture;if(l){var f=a._getGLTFTextureSampler(l);null!=f.magFilter&&null!=f.minFilter&&null!=f.wrapS&&null!=f.wrapT&&(o.push(f),u=o.length-1)}var h=e._useMicroSurfaceFromReflectivityMapAlpha;return c&&!h?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(l||c)&&n?a._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(l,c,s,t).then((function(e){if(e.baseColorTextureBase64){var n=a._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+i.length+".png",t,l?l.coordinatesIndex:null,u);n&&(r.baseColorTexture=n)}if(e.metallicRoughnessTextureBase64){var o=a._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+i.length+".png",t,c?c.coordinatesIndex:null,u);o&&(r.metallicRoughnessTexture=o)}return e})):a._convertSpecularGlossinessToMetallicRoughness(s)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,a={},o={name:e.name};if(e.isMetallicWorkflow()){var i=e._albedoColor,s=e.alpha;return i&&(a.baseColorFactor=[i.r,i.g,i.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(i){return n.setMetallicRoughnessPbrMaterial(i,e,o,a,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(i){return n.setMetallicRoughnessPbrMaterial(i,e,o,a,t,r)}))},e.prototype.setMetallicRoughnessPbrMaterial=function(t,r,n,a,o,i){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||(a.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(a.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(a.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||f.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),i){var c=r._bumpTexture;if(c){var h=this._exportTextureAsync(c,o).then((function(e){e&&(n.normalTexture=e,1!==c.level&&(n.normalTexture.scale=c.level))}));l.push(h)}var p=r._ambientTexture;p&&(h=this._exportTextureAsync(p,o).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord};n.occlusionTexture=t;var a=r._ambientTextureStrength;a&&(t.strength=a)}})),l.push(h));var d=r._emissiveTexture;d&&(h=this._exportTextureAsync(d,o).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=a,u.push(n),s[r.uniqueId]=u.length-1}return this._finishMaterial(l,n,r,o)},e.prototype.getPixelsFromTexture=function(e){return e.textureType,f.Constants.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},e.prototype._exportTextureAsync=function(e,t){var r=this,n=this._exporter._extensionsPreExportTextureAsync("exporter",e,t);return n?n.then((function(n){return n?r._exportTextureInfoAsync(n,t):r._exportTextureInfoAsync(e,t)})):this._exportTextureInfoAsync(e,t)},e.prototype._exportTextureInfoAsync=function(e,t){var r=this;return Promise.resolve().then((function(){return _(r,void 0,void 0,(function(){var r,n,a,o,i,s,u,l,c,f=this;return x(this,(function(h){switch(h.label){case 0:return(r=e.uid)in this._textureMap?[2,this._textureMap[r]]:[3,1];case 1:return[4,this.getPixelsFromTexture(e)];case 2:if(!(n=h.sent()))return[2,null];for(a=this._exporter._samplers,o=this._getGLTFTextureSampler(e),i=null,s=null,u=0;u<a.length;++u)if((l=a[u]).minFilter===o.minFilter&&l.magFilter===o.magFilter&&l.wrapS===o.wrapS&&l.wrapT===o.wrapT){s=u;break}if(null==s?(a.push(o),i=a.length-1):i=s,c=e.getSize(),e.mimeType)switch(e.mimeType){case"image/jpeg":t="image/jpeg";break;case"image/png":t="image/png"}return[2,this._createBase64FromCanvasAsync(n,c.width,c.height,t).then((function(n){var a=f._getTextureInfoFromBase64(n,e.name.replace(/\.\/|\/|\.\\|\\/g,"_"),t,e.coordinatesIndex,i);return a&&(f._textureMap[r]=a,f._exporter._extensionsPostExportTextures("linkTextureInfo",a,e)),a}))]}}))}))}))},e.prototype._getTextureInfoFromBase64=function(e,t,r,n,a){var o=this._exporter._textures,i=this._exporter._images,s=this._exporter._imageData,u=null,l={source:i.length,name:t};null!=a&&(l.sampler=a);for(var c=atob(e.split(",")[1]),h=new ArrayBuffer(c.length),p=new Uint8Array(h),d=0,m=c.length;d<m;++d)p[d]=c.charCodeAt(d);var g={data:p,mimeType:r},_="image/jpeg"===r?".jpeg":".png",x=t+_,y=x;if(x in s&&(x="".concat(t,"_").concat(f.Tools.RandomId()).concat(_)),s[x]=g,"image/jpeg"===r||"image/png"===r){var T={name:t,uri:x},v=null;for(d=0;d<i.length;++d)if(i[d].uri===y){v=d;break}null==v?(i.push(T),l.source=i.length-1):l.source=v,o.push(l),u={index:o.length-1},null!=n&&(u.texCoord=n)}else f.Tools.Error("Unsupported texture mime type ".concat(r));return u},e._DielectricSpecular=new f.Color3(.04,.04,.04),e._MaxSpecularPower=1024,e._Epsilon=1e-6,e}(),v=function(){function e(e,t){this._includeCoordinateSystemConversionNodes=!1,this._extensions={},this._glTF={asset:{generator:"BabylonJS",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 a=this;if(r>=t.length)return Promise.resolve(e);var o=n(t[r],e);return o?o.then((function(e){return a._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],a=0,o=e._ExtensionNames;a<o.length;a++){var i=o[a];n.push(this._extensions[i])}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,a){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,a,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,r,n)}))},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 a=[],o=0,i=e._ExtensionNames;o<i.length;o++){var s=i[o],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&a.push.apply(a,u.postExportMaterialAdditionalTextures(t,r,n))}return a},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var a=0,o=e._ExtensionNames;a<o.length;a++){var i=o[a],s=this._extensions[i];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var a=n[r],o=this._extensions[a];o.enabled&&t(o)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],a=e._ExtensionFactories[n](this);this._extensions[n]=a}},e.prototype.dispose=function(){for(var e in this._extensions)this._extensions[e].dispose()},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,a){switch(t){case f.Material.TriangleFillMode:n||(n=0);for(var o=e.indexStart,i=e.indexStart+e.indexCount;o<i;o+=3){var s=n+4*o,u=a.getUInt32(s+4),l=a.getUInt32(s+8);a.setUInt32(l,s+4),a.setUInt32(u,s+8)}break;case f.Material.TriangleFanDrawMode:o=e.indexStart+e.indexCount-1;for(var c=e.indexStart;o>=c;--o)a.setUInt32(r[o],n),n+=4;break;case f.Material.TriangleStripDrawMode:e.indexCount>=3&&(a.setUInt32(r[e.indexStart+2],n+4),a.setUInt32(r[e.indexStart+1],n+8))}},e.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,a,o,i,s){if(s&&r===f.Material.ClockWiseSideOrientation)switch(t){case f.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,n,a,o,i,s);break;case f.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,n,a,o,i,s);break;case f.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,n,a,o,i,s)}},e.prototype.reorderTriangleFillMode=function(e,t,r,n,a,o,i,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(a,h)),c.push(f.Vector3.FromArray(a,h+2*l)),c.push(f.Vector3.FromArray(a,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(a,h)),c.push(f.Vector4.FromArray(a,h+2*l)),c.push(f.Vector4.FromArray(a,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(a,h)),c.push(f.Vector4.FromArray(a,h+2*l)),c.push(f.Vector4.FromArray(a,h+l))):(c.push(f.Vector3.FromArray(a,h)),c.push(f.Vector3.FromArray(a,h+2*l)),c.push(f.Vector3.FromArray(a,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(a,h)),c.push(f.Vector2.FromArray(a,h+2*l)),c.push(f.Vector2.FromArray(a,h+l));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this.writeVertexAttributeData(c,o,n,a,i,s)}}else f.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(n," not present!"))},e.prototype.reorderTriangleStripDrawMode=function(e,t,r,n,a,o,i,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(a,h+2*l)),c.push(f.Vector3.FromArray(a,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(a,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(a,h)):c.push(f.Vector3.FromArray(a,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(a,h));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this.writeVertexAttributeData(c,o+12,n,a,i,s)}else f.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype.reorderTriangleFanMode=function(e,t,r,n,a,o,i,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(a,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(a,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(a,h)),4===u.getSize()?c.push(f.Vector4.FromArray(a,h)):c.push(f.Vector3.FromArray(a,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(a,h));break;default:f.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this.writeVertexAttributeData(c,o,n,a,i,s)}else f.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype.writeVertexAttributeData=function(e,t,r,n,a,o){for(var i=0,s=e;i<s.length;i++){var u=s[i];!o||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];a.setFloat32(h,t),t+=4}}},e.prototype.writeAttributeData=function(e,t,r,n,a,o,i){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);o&&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),o&&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),o&&d._GetRightHandedVector4FromRef(p),d._NormalizeTangentFromRef(p),l.push(p.asArray());break;case f.VertexBuffer.ColorKind:for(var _=i.material,x=!_||"StandardMaterial"===_.getClassName(),y=(p=3===n?new f.Color3:new f.Color4,c=0,r.length/n);c<y;++c)s=c*n,3===n?(f.Color3.FromArrayToRef(r,s,p),x&&p.toLinearSpaceToRef(p)):(f.Color4.FromArrayToRef(r,s,p),x&&p.toLinearSpaceToRef(p)),l.push(p.asArray());break;case f.VertexBuffer.UVKind:case f.VertexBuffer.UV2Kind:c=0;for(var T=r.length/n;c<T;++c)s=c*n,l.push([r[s],r[s+1]]);break;case f.VertexBuffer.MatricesIndicesKind:case f.VertexBuffer.MatricesIndicesExtraKind:c=0;for(var v=r.length/n;c<v;++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 b=r.length/n;c<b;++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=a.setUInt8.bind(a);break;case 5123:u=a.setUInt16.bind(a);break;case 5125:u=a.setUInt32.bind(a);case 5126:u=a.setFloat32.bind(a);break;default:return void f.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,F=l;A<F.length;A++)for(var M=0,E=F[A];M<E.length;M++)u(E[M])},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,a,o,i,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+_*i;var x=f.Vector3.FromArray(a,c);m=(y=f.Vector3.FromArray(o,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+_*i,(x=f.Vector3.FromArray(a,c)).normalize(),(y=f.Vector3.FromArray(o,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+_*(i+1),x=f.Vector4.FromArray(a,c),d._NormalizeTangentFromRef(x);var y=f.Vector4.FromArray(o,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);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,a,o,i=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&&(a=i._imageData[e.uri],i._orderedImageData.push(a),n=e.uri.split(".")[0]+" image",o=d._CreateBufferView(0,u,a.data.length,void 0,n),u+=a.data.buffer.byteLength,i._bufferViews.push(o),e.bufferView=i._bufferViews.length-1,e.name=n,e.mimeType=a.mimeType,e.uri=void 0,i._glTF.images||(i._glTF.images=[]),i._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 a=r.generateJSON(!1,e,!0),o=new Blob([n],{type:"application/octet-stream"}),i=e+".gltf",s=e+".bin",u=new g;if(u.glTFFiles[i]=a,u.glTFFiles[s]=o,r._imageData)for(var l in r._imageData)u.glTFFiles[l]=new Blob([r._imageData[l].data],{type:r._imageData[l].mimeType});return t&&r.dispose(),u}))},e.prototype._generateBinaryAsync=function(){var e=this,t=new b(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 a,o=r.generateJSON(!0),i=e+".glb",s=o.length,u=0;"undefined"!=typeof TextEncoder&&(s=(a=(new TextEncoder).encode(o)).length);for(var l=0;l<r._orderedImageData.length;++l)u+=r._orderedImageData[l].data.byteLength;var c=r._getPadding(s),f=r._getPadding(n.byteLength),h=r._getPadding(u),p=28+s+c+n.byteLength+f+u+h,d=new ArrayBuffer(12),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(a)y.set(a);else{var T="_".charCodeAt(0);for(l=0;l<s;++l){var v=o.charCodeAt(l);v!=o.codePointAt(l)?y[l]=T:y[l]=v}}var b=new Uint8Array(_,8+s);for(l=0;l<c;++l)b[l]=32;var A=new ArrayBuffer(8),F=new DataView(A);F.setUint32(0,n.byteLength+u+h,!0),F.setUint32(4,5130562,!0);var M=new ArrayBuffer(f),E=new Uint8Array(M);for(l=0;l<f;++l)E[l]=0;var R=new ArrayBuffer(h),C=new Uint8Array(R);for(l=0;l<h;++l)C[l]=0;var V=[d,_,A,n];for(l=0;l<r._orderedImageData.length;++l)V.push(r._orderedImageData[l].data.buffer);V.push(M),V.push(R);var w=new Blob(V,{type:"application/octet-stream"}),S=new g;return S.glTFFiles[i]=w,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.absoluteRotation;f.Quaternion.IsIdentity(n)||(r&&d._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype.getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},e.prototype.createBufferViewKind=function(e,t,r,n,a,o){var i=r instanceof f.Mesh?r:r instanceof f.InstancedMesh?r.sourceMesh:null;if(i){var s=i.getVertexBuffer(e),u=i.getVerticesData(e);if(s&&u){var l=f.VertexBuffer.GetTypeByteLength(t),c=u.length*l,h=d._CreateBufferView(0,n.getByteOffset(),c,a,e+" - "+i.name);this._bufferViews.push(h),this.writeAttributeData(e,t,u,a/l,n,o,r)}}},e.prototype.setMorphTargetAttributes=function(e,t,r,n,a){if(r){t.targets||(t.targets=[]);var o={};if(r.hasNormals){var i=e.getMesh().getVerticesData(f.VertexBuffer.NormalKind),s=r.getNormals(),u=(_=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL");this._bufferViews.push(l);var c=this._bufferViews.length-1,h=d._CreateAccessor(c,r.name+" - NORMAL","VEC3",5126,_,0,null,null);this._accessors.push(h),o.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.NormalKind,5126,e,r,i,s,x/4,n,a)}if(r.hasPositions){var p=e.getMesh().getVerticesData(f.VertexBuffer.PositionKind),m=r.getPositions();u=(_=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_POSITION"),this._bufferViews.push(l),c=this._bufferViews.length-1;var g={min:new f.Vector3(1/0,1/0,1/0),max:new f.Vector3(-1/0,-1/0,-1/0)};h=d._CreateAccessor(c,r.name+" - POSITION","VEC3",5126,_,0,null,null),this._accessors.push(h),o.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.PositionKind,5126,e,r,p,m,x/4,n,a,g),h.min=g.min.asArray(),h.max=g.max.asArray()}if(r.hasTangents){var _,x,y=e.getMesh().getVerticesData(f.VertexBuffer.TangentKind),T=r.getTangents();u=(_=e.verticesCount)*(x=12),l=d._CreateBufferView(0,n.getByteOffset(),u,x,r.name+"_NORMAL"),this._bufferViews.push(l),c=this._bufferViews.length-1,h=d._CreateAccessor(c,r.name+" - TANGENT","VEC3",5126,_,0,null,null),this._accessors.push(h),o.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(f.VertexBuffer.TangentKind,5126,e,r,y,T,x/4,n,a)}t.targets.push(o)}},e.prototype.getMeshPrimitiveMode=function(e){return e instanceof f.LinesMesh?f.Material.LineListDrawMode: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:e.mode=0;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 a,o,i,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)){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;o=d._CreateBufferView(0,r.getByteOffset(),b,void 0,"Indices - "+u.name),this._bufferViews.push(o),c=this._bufferViews.length-1;for(var A=0,F=v.length;A<F;++A)r.setUInt32(v[A])}}if(u.subMeshes)for(var M=0,E=u.subMeshes;M<E.length;M++){var R=E[M],C=R.getMaterial()||u.getScene().defaultMaterial,V=null;if(C)if(u instanceof f.LinesMesh){var w={name:u.name+" material"};(!u.color.equals(f.Color3.White())||u.alpha<1)&&(w.pbrMetallicRoughness={baseColorFactor:u.color.asArray().concat([u.alpha])}),this._materials.push(w),V=this._materials.length-1}else if("MultiMaterial"===C.getClassName()){var S=C.subMaterials[R.materialIndex];S&&(C=S,V=this._materialMap[C.uniqueId])}else V=this._materialMap[C.uniqueId];var B=null!=V?this._materials[V]:null,I={attributes:{}};this.setPrimitiveMode(I,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||B&&this._glTFMaterialExporter._hasTexturesPresent(B))&&(z=u.getVerticesData(x))&&(T=this.getVertexBufferFromMesh(x,u))){var L=T.getSize(),O=W.bufferViewIndex;if(null!=O){i={min:null,max:null},x==f.VertexBuffer.PositionKind&&(i=d._CalculateMinMaxPositions(z,0,z.length/L,n));var k=d._CreateAccessor(O,x+" - "+t.name,W.accessorType,W.accessorComponentType,z.length/L,0,i.min,i.max);this._accessors.push(k),this.setAttributeKind(I,x)}}if(c&&(k=d._CreateAccessor(c,"indices - "+t.name,"SCALAR",5125,R.indexCount,4*R.indexStart,null,null),this._accessors.push(k),I.indices=this._accessors.length-1),null!=V&&Object.keys(I.attributes).length>0){var G=null!==u.overrideMaterialSideOrientation?u.overrideMaterialSideOrientation:C.sideOrientation;if(G==f.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||G==f.Material.ClockWiseSideOrientation&&n&&u.overrideMaterialSideOrientation!==(null===(a=u.material)||void 0===a?void 0:a.sideOrientation)){var U=null!=c?this._bufferViews[c].byteOffset:null;null==U&&(U=0);var D=null;if(null!=c&&(D=u.getIndices()),D)this.reorderIndicesBasedOnPrimitiveMode(R,h,D,U,r);else for(var K=0,H=l;K<H.length;K++){var z,W=H[K];if(z=u.getVerticesData(W.kind)){var q=this._bufferViews[p[W.kind]].byteOffset;q||(q=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(R,h,G,W.kind,z,q,r,n)}}}I.material=V}if(m)for(var Q=void 0,j=0;j<m.numTargets;++j)Q=m.getTarget(j),this.setMorphTargetAttributes(R,I,Q,r,n);e.primitives.push(I),this._extensionsPostExportMeshPrimitiveAsync("postExport",I,R,r),s.push()}}return Promise.all(s).then((function(){}))},e.prototype.isBabylonCoordinateSystemConvertingNode=function(e){return e instanceof f.TransformNode&&"__root__"===e.name&&1!==e.getWorldMatrix().determinant()&&!(e instanceof f.Mesh&&null!==e.geometry||e instanceof f.InstancedMesh&&null!==e.sourceMesh.geometry)&&!this._includeCoordinateSystemConversionNodes},e.prototype.createSceneAsync=function(e,t){var r,n,a,o=this,i={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.rootNodes.forEach((function(e){o._convertToRightHandedSystemMap[e.uniqueId]=o._convertToRightHandedSystem,e.getDescendants(!1).forEach((function(e){o._convertToRightHandedSystemMap[e.uniqueId]=o._convertToRightHandedSystem}))})),e.rootNodes.forEach((function(e){if(o.isBabylonCoordinateSystemConvertingNode(e)){u.push(e);var t=s.indexOf(e);-1!==t&&s.splice(t,1),e.getDescendants(!1).forEach((function(e){o._convertToRightHandedSystemMap[e.uniqueId]=!1}))}}));var l=new Map;e.cameras.forEach((function(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._cache.fovMode===f.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e._cache.aspectRatio,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,o._cameras.length),o._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 o.createNodeMapAndAnimationsAsync(e,h,t).then((function(c){return o.createSkinsAsync(e,c,t).then((function(e){if(o._nodeMap=c,o._totalByteLength=t.getByteOffset(),null==o._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=o._nodeMap[d.uniqueId])){if(n=o._nodes[r],d.metadata&&(o._options.metadataSelector?n.extras=o._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)||(o._options.shouldExportNode&&!o._options.shouldExportNode(d)?f.Tools.Log("Omitting "+d.name+" from scene."):(o._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()),i.nodes.push(r))),d instanceof f.Mesh){var m=d;m.skeleton&&(n.skin=e[m.skeleton.uniqueId])}if(a=d.getDescendants(!0),!n.children&&a&&a.length){for(var g=[],_=0,x=a;_<x.length;_++){var y=x[_];null!=o._nodeMap[y.uniqueId]&&g.push(o._nodeMap[y.uniqueId])}g.length&&(n.children=g)}}}i.nodes.length&&o._scenes.push(i)}))}))}))},e.prototype.getExportNodes=function(e){for(var t=[],r=new Set,n=0,a=e;n<a.length;n++){var o=a[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(o))if(t.push(o),"Mesh"===o.getClassName())(u=o).material&&r.add(u.material);else for(var i=0,s=o.getChildMeshes(!1);i<s.length;i++){var u;(u=s[i]).material&&r.add(u.material)}else"Excluding node ".concat(o.name)}return[t,r]},e.prototype.createNodeMapAndAnimationsAsync=function(e,t,r){for(var n,a=this,o=Promise.resolve(),i={},s={name:"runtime animations",channels:[],samplers:[]},u=[],l=function(t){o=o.then((function(){var o=a._convertToRightHandedSystemMap[t.uniqueId];return a.createNodeAsync(t,r,o,i).then((function(l){var c=a._extensionsPostExportNodeAsync("createNodeAsync",l,t,i);return null==c?(f.Tools.Warn("Not exporting node ".concat(t.name)),Promise.resolve()):c.then((function(l){l&&(a._nodes.push(l),n=a._nodes.length-1,i[t.uniqueId]=n,e.animationGroups.length||(m._CreateMorphTargetAnimationFromMorphTargetAnimations(t,s,u,i,a._nodes,r,a._bufferViews,a._accessors,o,a._animationSampleRate),t.animations.length&&m._CreateNodeAnimationFromNodeAnimations(t,s,u,i,a._nodes,r,a._bufferViews,a._accessors,o,a._animationSampleRate)))}))}))}))},c=0,h=t;c<h.length;c++)l(h[c]);return o.then((function(){return s.channels.length&&s.samplers.length&&a._animations.push(s),u.forEach((function(e){e.channels.length&&e.samplers.length&&a._animations.push(e)})),e.animationGroups.length&&m._CreateNodeAndMorphAnimationFromAnimationGroups(e,a._animations,i,a._nodes,r,a._bufferViews,a._accessors,a._convertToRightHandedSystemMap,a._animationSampleRate),i}))},e.prototype.createNodeAsync=function(e,t,r,n){var a=this;return Promise.resolve().then((function(){var n={},o={primitives:[]};if(e.name&&(n.name=e.name),e instanceof f.TransformNode){if(a.setNodeTransformation(n,e,r),e instanceof f.Mesh){var i=e.morphTargetManager;if(i&&i.numTargets>0){o.weights=[];for(var s=0;s<i.numTargets;++s)o.weights.push(i.getTarget(s).influence)}}return a.setPrimitiveAttributesAsync(o,e,t,r).then((function(){return o.primitives.length&&(a._meshes.push(o),n.mesh=a._meshes.length-1),n}))}return e instanceof f.Camera?(a.setCameraTransformation(n,e,r),n):n}))},e.prototype.createSkinsAsync=function(e,t,r){for(var n,a=Promise.resolve(),o={},i=0,s=e.skeletons;i<s.length;i++){for(var u=s[i],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?l.joints.push(t[x.uniqueId]):f.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}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),F=this._accessors.push(A)-1;l.inverseBindMatrices=F,this._skins.push(l),o[u.uniqueId]=this._skins.length-1,c.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))}return a.then((function(){return o}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),b=function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype.resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),n=new Uint8Array(t),a=0,o=n.byteLength;a<o;++a)n[a]=r[a];return 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}(),A=0,F=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var n=t.replace(/\.[^/.]+$/,"");return new v(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 a=t.replace(/\.[^/.]+$/,"");return new v(e,r)._generateGLBAsync(a).then((function(t){return n._PostExportAsync(e,t,r)}))}))},e}();f.ShaderStore.ShadersStore.textureTransformPixelShader="precision highp float;varying vec2 vUV;uniform sampler2D textureSampler;uniform mat4 textureTransformMat;void main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\nvec2 uvTransformed=(textureTransformMat*vec4(vUV.xy,1,1)).xy;gl_FragColor=texture2D(textureSampler,uvTransformed);\n#define CUSTOM_FRAGMENT_MAIN_END\n}";var M="KHR_texture_transform",E=function(){function e(e){this._recordedTextures=[],this.name=M,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){for(var e=0,t=this._recordedTextures;e<t.length;e++)t[e].dispose()},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={},a=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],a=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],a=!0),0!==r.wAng&&(n.rotation=r.wAng,a=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,a=!0),!a)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[M]=n}},e.prototype.preExportTextureAsync=function(e,t,r){var n=this;return new Promise((function(r,a){var o=t.getScene();if(o){var i=!1;if(0===t.uAng&&0===t.wAng&&0===t.vAng||0===t.uRotationCenter&&0===t.vRotationCenter||(i=!0),i)return n._textureTransformTextureAsync(t,o).then((function(e){r(e)})).catch((function(e){a(e)}));r(t)}else a("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e.prototype._textureTransformTextureAsync=function(e,t){var r=this;return new Promise((function(n){var a=new f.ProceduralTexture("".concat(e.name),e.getSize(),"textureTransform",t);a||(f.Tools.Log("Cannot create procedural texture for ".concat(e.name,"!")),n(e)),a.reservedDataStore={hidden:!0,source:e},r._recordedTextures.push(a),a.coordinatesIndex=e.coordinatesIndex,a.setTexture("textureSampler",e),a.setMatrix("textureTransformMat",e.getTextureMatrix()),a.isReady()?(a.render(),n(a)):a.getEffect().executeWhenCompiled((function(){a.render(),n(a)}))}))},e}();v.RegisterExtension(M,(function(e){return new E(e)}));var R="KHR_lights_punctual",C=function(){function e(e){this.name=R,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){this._lights=null},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!1,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions.KHR_lights_punctual=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,n){var a=this;return new Promise((function(o,i){if(t&&r instanceof f.ShadowLight){var s=r,u=void 0,l=s.getTypeID()==f.Light.LIGHTTYPEID_POINTLIGHT?"point":s.getTypeID()==f.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":s.getTypeID()==f.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==l)f.Logger.Warn("".concat(e,": Light ").concat(s.name," is not supported in ").concat(R));else{var c=s.position.clone(),h=a._exporter._convertToRightHandedSystemMap[r.uniqueId];if(c.equals(f.Vector3.Zero())||(h&&d._GetRightHandedPositionVector3FromRef(c),t.translation=c.asArray()),"point"!==l){var p=s.direction,m=-Math.atan2(p.z*(a._exporter._babylonScene.useRightHandedSystem?-1:1),p.x)+Math.PI/2,g=Math.sqrt(p.x*p.x+p.z*p.z),_=-Math.atan2(p.y,g),x=f.Quaternion.RotationYawPitchRoll(m,_,0);h&&d._GetRightHandedQuaternionFromRef(x),x.equals(f.Quaternion.Identity())||(t.rotation=x.asArray())}if(s.falloffType!==f.Light.FALLOFF_GLTF&&f.Logger.Warn("".concat(e,": Light falloff for ").concat(s.name," does not match the ").concat(R," specification!")),u={type:l},s.diffuse.equals(f.Color3.White())||(u.color=s.diffuse.asArray()),1!==s.intensity&&(u.intensity=s.intensity),s.range!==Number.MAX_VALUE&&(u.range=s.range),"spot"===l){var y=s;y.angle!==Math.PI/2&&(null==u.spot&&(u.spot={}),u.spot.outerConeAngle=y.angle/2),0!==y.innerAngle&&(null==u.spot&&(u.spot={}),u.spot.innerConeAngle=y.innerAngle/2)}null==a._lights&&(a._lights={lights:[]}),a._lights.lights.push(u);var T={light:a._lights.lights.length-1},v=r.parent;if(v&&1==v.getChildren().length){var b=a._exporter._nodes[n[v.uniqueId]];if(b){var A=f.TmpVectors.Matrix[0],F=f.TmpVectors.Matrix[1],M=b.translation?new f.Vector3(b.translation[0],b.translation[1],b.translation[2]):f.Vector3.Zero(),E=b.rotation?new f.Quaternion(b.rotation[0],b.rotation[1],b.rotation[2],b.rotation[3]):f.Quaternion.Identity(),C=b.scale?new f.Vector3(b.scale[0],b.scale[1],b.scale[2]):f.Vector3.One();f.Matrix.ComposeToRef(C,E,M,A),A.invertToRef(F);var V=f.TmpVectors.Matrix[2],w=t.translation?new f.Vector3(t.translation[0],t.translation[1],t.translation[2]):f.Vector3.Zero();s instanceof f.DirectionalLight&&w.subtractInPlace(a._exporter._babylonScene.useRightHandedSystem?s.direction:d._GetRightHandedPositionVector3(s.direction));var S=a._exporter._babylonScene.useRightHandedSystem?f.Quaternion.Identity():new f.Quaternion(0,1,0,0);t.rotation&&S.multiplyInPlace(new f.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var B=t.scale?new f.Vector3(t.scale[0],t.scale[1],t.scale[2]):f.Vector3.One();f.Matrix.ComposeToRef(B,S,w,V),V.multiplyToRef(F,V);var I=f.TmpVectors.Vector3[0],P=f.TmpVectors.Quaternion[0],N=f.TmpVectors.Vector3[1];return V.decompose(I,P,N),b.scale=I.asArray(),b.rotation=P.asArray(),b.translation=N.asArray(),null==b.extensions&&(b.extensions={}),b.extensions.KHR_lights_punctual=T,void o(null)}}null==t.extensions&&(t.extensions={}),t.extensions.KHR_lights_punctual=T}}o(t)}))},e}();v.RegisterExtension(R,(function(e){return new C(e)}));var V="KHR_materials_clearcoat",w=function(){function e(e){this.name=V,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,a){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 s=n._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.bumpTexture),u={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=o?o:void 0,clearcoatNormalTexture:null!=s?s:void 0,hasTextures:function(){return null!==u.clearcoatTexture||null!==u.clearcoatRoughnessTexture||null!==u.clearcoatRoughnessTexture}};t.extensions.KHR_materials_clearcoat=u}e(t)}))},e}();v.RegisterExtension(V,(function(e){return new w(e)}));var S="KHR_materials_sheen",B=function(){function e(e){this.name=S,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,a){var o,i,s,u;if(r instanceof f.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);n._wasUsed=!0,null==t.extensions&&(t.extensions={});var l={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(o=r.sheen.roughness)&&void 0!==o?o:0,hasTextures:function(){return null!==l.sheenColorTexture||null!==l.sheenRoughnessTexture}};r.sheen.texture&&(l.sheenColorTexture=null!==(i=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==i?i:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?l.sheenRoughnessTexture=null!==(s=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.textureRoughness))&&void 0!==s?s:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(l.sheenRoughnessTexture=null!==(u=n._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==u?u:void 0),t.extensions.KHR_materials_sheen=l}e(t)}))},e}();v.RegisterExtension(S,(function(e){return new B(e)}));var I="KHR_materials_unlit",P=function(){function e(e){this.name=I,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,a){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.KHR_materials_unlit={}),e(t)}))},e}();v.RegisterExtension(I,(function(e){return new P(e)}));var N=function(){function e(){}return e.CreateSTL=function(e,t,r,n,a,o){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===n&&(n=!1),void 0===a&&(a=!0),void 0===o&&(o=!1);var i,s=function(e,t,r){var n=[3*e[r],3*e[r+1],3*e[r+2]],a=[new f.Vector3(t[n[0]],t[n[0]+2],t[n[0]+1]),new f.Vector3(t[n[1]],t[n[1]+2],t[n[1]+1]),new f.Vector3(t[n[2]],t[n[2]+2],t[n[2]+1])],o=a[0].subtract(a[1]),i=a[2].subtract(a[1]);return{v:a,n:f.Vector3.Cross(i,o).normalize()}},u=function(e,t,r,n){return t=l(e,t,r.x,n),t=l(e,t,r.y,n),l(e,t,r.z,n)},l=function(e,t,r,n){return e.setFloat32(t,r,n),t+4},c=0,h=0;if(n){for(var p=0;p<e.length;p++)c+=(_=(m=e[p]).getIndices())?_.length/3:0;var d=new ArrayBuffer(84+50*c);h+=80,(i=new DataView(d)).setUint32(h,c,a),h+=4}else i="solid stlmesh\r\n";for(p=0;p<e.length;p++){var m=e[p];o||m.bakeCurrentTransformIntoVertices();for(var g=m.getVerticesData(f.VertexBuffer.PositionKind)||[],_=m.getIndices()||[],x=0;x<_.length;x+=3){var y=s(_,g,x);n?(h=u(i,h,y.n,a),h=u(i,h,y.v[0],a),h=u(i,h,y.v[1],a),h=u(i,h,y.v[2],a),h+=2):(i+="facet normal "+y.n.x+" "+y.n.y+" "+y.n.z+"\r\n",i+="\touter loop\r\n",i+="\t\tvertex "+y.v[0].x+" "+y.v[0].y+" "+y.v[0].z+"\r\n",i+="\t\tvertex "+y.v[1].x+" "+y.v[1].y+" "+y.v[1].z+"\r\n",i+="\t\tvertex "+y.v[2].x+" "+y.v[2].y+" "+y.v[2].z+"\r\n",i+="\tendloop\r\n",i+="endfacet\r\n")}}if(n||(i+="endsolid stlmesh"),t){var T=document.createElement("a"),v=new Blob([i],{type:"application/octet-stream"});T.href=window.URL.createObjectURL(v),T.download=r+".stl",T.click()}return i},e}(),L=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==L){L.BABYLON=L.BABYLON||{};var O=L.BABYLON;O.GLTF2=O.GLTF2||{},O.GLTF2.Exporter=O.GLTF2.Exporter||{},O.GLTF2.Exporter.Extensions=O.GLTF2.Exporter.Extensions||{};var k=[];for(var G in t)O[G]=t[G],k.push(G);for(var G in r)O[G]=r[G],k.push(G);for(var G in o)O[G]=o[G],k.push(G);for(var G in i)O.GLTF2.Exporter.Extensions[G]=i[G],k.push(G);for(var G in s)k.indexOf(G)>-1||(O.GLTF2.Exporter[G]=s[G])}var U=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==U)for(var D in e)U.BABYLON[D]=e[D];var K=void 0!==n.g?n.g:"undefined"!=typeof window?window:void 0;if(void 0!==K)for(var H in u)K.BABYLON[H]=u[H];const z=l})(),a.default})()}));
- //# sourceMappingURL=babylonjs.serializers.min.js.map
|