babylon.glTF2Serializer.min.js 59 KB

1
  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,function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=13)}([function(t,r){t.exports=e},function(e,t,r){"use strict";r.d(t,"a",function(){return a});var n=r(0),a=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,a){var i={buffer:e,byteLength:r};return t&&(i.byteOffset=t),a&&(i.name=a),n&&(i.byteStride=n),i},e._CreateAccessor=function(e,t,r,n,a,i,o,s){var l={name:t,bufferView:e,componentType:n,count:a,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=i&&(l.byteOffset=i),l},e._CalculateMinMaxPositions=function(t,r,a,i){var o,s,l,u=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(a)for(var f=r,h=r+a;f<h;++f){o=3*f,s=n.Vector3.FromArray(t,o),i&&e._GetRightHandedPositionVector3FromRef(s),l=s.asArray();for(var p=0;p<3;++p){var d=l[p];d<u[p]&&(u[p]=d),d>c[p]&&(c[p]=d),++o}}return{min:u,max:c}},e._GetRightHandedPositionVector3=function(e){return new n.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 n.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}()},function(e,t,r){"use strict";r.d(t,"b",function(){return l}),r.d(t,"a",function(){return u});var n=r(0),a=r(10),i=r(1),o=r(3),s=r(7),l=function(){function e(e,t){this._extensions={},this._glTF={asset:{generator:"BabylonJS",version:"2.0"}},this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._animations=[],this._imageData={},this._convertToRightHandedSystem=!this._babylonScene.useRightHandedSystem;var r=t||{};this._shouldExportNode=r.shouldExportNode?r.shouldExportNode:function(e){return!0},this._animationSampleRate=r.animationSampleRate?r.animationSampleRate:1/60,this._glTFMaterialExporter=new a.a(this),this._loadExtensions()}return e.prototype._applyExtensions=function(t,r){for(var n=0,a=e._ExtensionNames;n<a.length;n++){var i=a[n],o=this._extensions[i];if(o.enabled){var s=t;s._activeLoaderExtensions=s._activeLoaderExtensions||{};var l=s._activeLoaderExtensions;if(!l[i]){l[i]=!0;try{var u=r(o);if(u)return u}finally{delete l[i],delete s._activeLoaderExtensions}}}}return null},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,function(n){return n.preExportTextureAsync&&n.preExportTextureAsync(e,t,r)})},e.prototype._extensionsPostExportMeshPrimitiveAsync=function(e,t,r,n){return this._applyExtensions(t,function(a){return a.postExportMeshPrimitiveAsync&&a.postExportMeshPrimitiveAsync(e,t,r,n)})},e.prototype._extensionsPostExportNodeAsync=function(e,t,r){return this._applyExtensions(t,function(n){return n.postExportNodeAsync&&n.postExportNodeAsync(e,t,r)})},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var a=n[r],i=this._extensions[a];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){this._forEachExtensions(function(e){return e.onExporting&&e.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.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&n.Tools.Warn("Extension with the name "+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._getLocalEngine=function(){if(!this._localEngine){var e=document.createElement("canvas");e.id="WriteCanvas",e.width=2048,e.height=2048,this._localEngine=new n.Engine(e,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!0}),this._localEngine.setViewport(new n.Viewport(0,0,1,1))}return this._localEngine},e.prototype.reorderIndicesBasedOnPrimitiveMode=function(e,t,r,a,i){switch(t){case n.Material.TriangleFillMode:a||(a=0);for(var o=e.indexStart,s=e.indexStart+e.indexCount;o<s;o+=3){var l=a+4*o,u=i.getUInt32(l+4),c=i.getUInt32(l+8);i.setUInt32(c,l+4),i.setUInt32(u,l+8)}break;case n.Material.TriangleFanDrawMode:o=e.indexStart+e.indexCount-1;for(var f=e.indexStart;o>=f;--o)i.setUInt32(r[o],a),a+=4;break;case n.Material.TriangleStripDrawMode:e.indexCount>=3&&(i.setUInt32(r[e.indexStart+2],a+4),i.setUInt32(r[e.indexStart+1],a+8))}},e.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,a,i,o,s){if(this._convertToRightHandedSystem&&r===n.Material.ClockWiseSideOrientation)switch(t){case n.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,a,i,o,s);break;case n.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,a,i,o,s);break;case n.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,a,i,o,s)}},e.prototype.reorderTriangleFillMode=function(e,t,r,a,i,o,s){var l=this.getVertexBufferFromMesh(a,e.getMesh());if(l){var u=l.byteStride/n.VertexBuffer.GetTypeByteLength(l.type);if(e.verticesCount%3!=0)n.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],f=0;switch(a){case n.VertexBuffer.PositionKind:case n.VertexBuffer.NormalKind:for(var h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*u,c.push(n.Vector3.FromArray(i,f)),c.push(n.Vector3.FromArray(i,f+2*u)),c.push(n.Vector3.FromArray(i,f+u));break;case n.VertexBuffer.TangentKind:for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*u,c.push(n.Vector4.FromArray(i,f)),c.push(n.Vector4.FromArray(i,f+2*u)),c.push(n.Vector4.FromArray(i,f+u));break;case n.VertexBuffer.ColorKind:var p=l.getSize();for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=p)f=h*u,4===p?(c.push(n.Vector4.FromArray(i,f)),c.push(n.Vector4.FromArray(i,f+2*u)),c.push(n.Vector4.FromArray(i,f+u))):(c.push(n.Vector3.FromArray(i,f)),c.push(n.Vector3.FromArray(i,f+2*u)),c.push(n.Vector3.FromArray(i,f+u)));break;case n.VertexBuffer.UVKind:case n.VertexBuffer.UV2Kind:for(h=e.verticesStart;h<e.verticesStart+e.verticesCount;h+=3)f=h*u,c.push(n.Vector2.FromArray(i,f)),c.push(n.Vector2.FromArray(i,f+2*u)),c.push(n.Vector2.FromArray(i,f+u));break;default:n.Tools.Error("Unsupported Vertex Buffer type: "+a)}this.writeVertexAttributeData(c,o,a,i,s)}}else n.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+a+" not present!")},e.prototype.reorderTriangleStripDrawMode=function(e,t,r,a,i,o,s){var l=this.getVertexBufferFromMesh(a,e.getMesh());if(l){var u=l.byteStride/n.VertexBuffer.GetTypeByteLength(l.type),c=[],f=0;switch(a){case n.VertexBuffer.PositionKind:case n.VertexBuffer.NormalKind:f=e.verticesStart,c.push(n.Vector3.FromArray(i,f+2*u)),c.push(n.Vector3.FromArray(i,f+u));break;case n.VertexBuffer.TangentKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*u,c.push(n.Vector4.FromArray(i,f));break;case n.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*u,4===l.getSize()?c.push(n.Vector4.FromArray(i,f)):c.push(n.Vector3.FromArray(i,f));break;case n.VertexBuffer.UVKind:case n.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*u,c.push(n.Vector2.FromArray(i,f));break;default:n.Tools.Error("Unsupported Vertex Buffer type: "+a)}this.writeVertexAttributeData(c,o+12,a,i,s)}else n.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+a+" not present!")},e.prototype.reorderTriangleFanMode=function(e,t,r,a,i,o,s){var l=this.getVertexBufferFromMesh(a,e.getMesh());if(l){var u=l.byteStride/n.VertexBuffer.GetTypeByteLength(l.type),c=[],f=0;switch(a){case n.VertexBuffer.PositionKind:case n.VertexBuffer.NormalKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*u,c.push(n.Vector3.FromArray(i,f));break;case n.VertexBuffer.TangentKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*u,c.push(n.Vector4.FromArray(i,f));break;case n.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*u,c.push(n.Vector4.FromArray(i,f)),4===l.getSize()?c.push(n.Vector4.FromArray(i,f)):c.push(n.Vector3.FromArray(i,f));break;case n.VertexBuffer.UVKind:case n.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)f=h*u,c.push(n.Vector2.FromArray(i,f));break;default:n.Tools.Error("Unsupported Vertex Buffer type: "+a)}this.writeVertexAttributeData(c,o,a,i,s)}else n.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+a+" not present!")},e.prototype.writeVertexAttributeData=function(e,t,r,a,o){for(var s=0,l=e;s<l.length;s++){var u=l[s];!this._convertToRightHandedSystem||r===n.VertexBuffer.ColorKind||u instanceof n.Vector2||(u instanceof n.Vector3?r===n.VertexBuffer.NormalKind?i.a._GetRightHandedNormalVector3FromRef(u):r===n.VertexBuffer.PositionKind?i.a._GetRightHandedPositionVector3FromRef(u):n.Tools.Error("Unsupported vertex attribute kind!"):i.a._GetRightHandedVector4FromRef(u)),r===n.VertexBuffer.NormalKind?u.normalize():r===n.VertexBuffer.TangentKind&&u instanceof n.Vector4&&i.a._NormalizeTangentFromRef(u);for(var c=0,f=u.asArray();c<f.length;c++){var h=f[c];o.setFloat32(h,t),t+=4}}},e.prototype.writeAttributeData=function(e,t,r,a){var o,s=r/4,l=[];switch(e){case n.VertexBuffer.PositionKind:for(var u=0,c=t.length/s;u<c;++u){o=u*s;var f=n.Vector3.FromArray(t,o);this._convertToRightHandedSystem&&i.a._GetRightHandedPositionVector3FromRef(f),l.push(f.asArray())}break;case n.VertexBuffer.NormalKind:u=0;for(var h=t.length/s;u<h;++u){o=u*s;f=n.Vector3.FromArray(t,o);this._convertToRightHandedSystem&&i.a._GetRightHandedNormalVector3FromRef(f),f.normalize(),l.push(f.asArray())}break;case n.VertexBuffer.TangentKind:u=0;for(var p=t.length/s;u<p;++u){o=u*s;f=n.Vector4.FromArray(t,o);this._convertToRightHandedSystem&&i.a._GetRightHandedVector4FromRef(f),i.a._NormalizeTangentFromRef(f),l.push(f.asArray())}break;case n.VertexBuffer.ColorKind:u=0;for(var d=t.length/s;u<d;++u){o=u*s;f=3===s?n.Vector3.FromArray(t,o):n.Vector4.FromArray(t,o);l.push(f.asArray())}break;case n.VertexBuffer.UVKind:case n.VertexBuffer.UV2Kind:u=0;for(var g=t.length/s;u<g;++u)o=u*s,l.push((this._convertToRightHandedSystem,[t[o],t[o+1]]));break;default:n.Tools.Warn("Unsupported Vertex Buffer Type: "+e),l=[]}for(var m=0,_=l;m<_.length;m++)for(var y=0,x=_[m];y<x.length;y++){var T=x[y];a.setFloat32(T)}},e.prototype.generateJSON=function(e,t,r){var n,a,o,s=this,l={byteLength:this._totalByteLength},u=this._totalByteLength;return l.byteLength&&(this._glTF.buffers=[l]),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._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._images&&this._images.length&&(e?(this._glTF.images=[],this._images.forEach(function(e){e.uri&&(a=s._imageData[e.uri],n=e.uri.split(".")[0]+" image",o=i.a._CreateBufferView(0,u,a.data.length,void 0,n),u+=a.data.buffer.byteLength,s._bufferViews.push(o),e.bufferView=s._bufferViews.length-1,e.name=n,e.mimeType=a.mimeType,e.uri=void 0,s._glTF.images||(s._glTF.images=[]),s._glTF.images.push(e))}),l.byteLength=u):this._glTF.images=this._images),e||(l.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype._generateGLTFAsync=function(e){var t=this;return this._generateBinaryAsync().then(function(r){t._extensionsOnExporting();var n=t.generateJSON(!1,e,!0),a=new Blob([r],{type:"application/octet-stream"}),i=e+".gltf",s=e+".bin",l=new o.GLTFData;if(l.glTFFiles[i]=n,l.glTFFiles[s]=a,t._imageData)for(var u in t._imageData)l.glTFFiles[u]=new Blob([t._imageData[u].data],{type:t._imageData[u].mimeType});return l})},e.prototype._generateBinaryAsync=function(){var e=this,t=new u(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){var t=this;return this._generateBinaryAsync().then(function(r){t._extensionsOnExporting();var n=t.generateJSON(!0),a=e+".glb",i=n.length,s=0;for(var l in t._imageData)s+=t._imageData[l].data.byteLength;var u=t._getPadding(i),c=t._getPadding(r.byteLength),f=t._getPadding(s),h=28+i+u+r.byteLength+c+s+f,p=new ArrayBuffer(12),d=new DataView(p);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,h,!0);var g=new ArrayBuffer(8+i+u),m=new DataView(g);m.setUint32(0,i+u,!0),m.setUint32(4,1313821514,!0);for(var _=new Uint8Array(g,8),y=0;y<i;++y)_[y]=n.charCodeAt(y);var x=new Uint8Array(g,8+i);for(y=0;y<u;++y)x[y]=32;var T=new ArrayBuffer(8),v=new DataView(T);v.setUint32(0,r.byteLength+s+f,!0),v.setUint32(4,5130562,!0);var A=new ArrayBuffer(c),b=new Uint8Array(A);for(y=0;y<c;++y)b[y]=0;var F=new ArrayBuffer(f),E=new Uint8Array(F);for(y=0;y<f;++y)E[y]=0;var R=[p,g,T,r];for(var l in t._imageData)R.push(t._imageData[l].data.buffer);R.push(A),R.push(F);var M=new Blob(R,{type:"application/octet-stream"}),S=new o.GLTFData;return S.glTFFiles[a]=M,null!=t._localEngine&&t._localEngine.dispose(),S})},e.prototype.setNodeTransformation=function(e,t){t.getPivotPoint().equalsToFloats(0,0,0)||n.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=this._convertToRightHandedSystem?i.a._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var r=n.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),0===r.x&&0===r.y&&0===r.z&&1===r.w||(this._convertToRightHandedSystem&&i.a._GetRightHandedQuaternionFromRef(r),e.rotation=r.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,a){var o=t instanceof n.Mesh?t:t instanceof n.InstancedMesh?t.sourceMesh:null;if(o){var s=o.getVerticesData(e);if(s){var l=4*s.length,u=i.a._CreateBufferView(0,r.getByteOffset(),l,a,e+" - "+o.name);this._bufferViews.push(u),this.writeAttributeData(e,s,a,r)}}},e.prototype.getMeshPrimitiveMode=function(e){return e instanceof n.LinesMesh?n.Material.LineListDrawMode:e.material?e.material.fillMode:n.Material.TriangleFillMode},e.prototype.setPrimitiveMode=function(e,t){switch(t){case n.Material.TriangleFillMode:break;case n.Material.TriangleStripDrawMode:e.mode=5;break;case n.Material.TriangleFanDrawMode:e.mode=6;break;case n.Material.PointListDrawMode:e.mode=0;case n.Material.PointFillMode:e.mode=0;break;case n.Material.LineLoopDrawMode:e.mode=2;break;case n.Material.LineListDrawMode:e.mode=1;break;case n.Material.LineStripDrawMode:e.mode=3}},e.prototype.setAttributeKind=function(e,t){switch(t){case n.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case n.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case n.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case n.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case n.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case n.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;default:n.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},e.prototype.setPrimitiveAttributesAsync=function(e,t,r){var a,o,s,l=[],u=null;t instanceof n.Mesh?u=t:t instanceof n.InstancedMesh&&(u=t.sourceMesh);var c=[{kind:n.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:n.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:n.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:n.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:n.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:n.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(u){for(var f=null,h=this.getMeshPrimitiveMode(u),p={},d=0,g=c;d<g.length;d++){var m=(K=g[d]).kind;if(u.isVerticesDataPresent(m)){var _=this.getVertexBufferFromMesh(m,u);K.byteStride=_?4*_.getSize():4*n.VertexBuffer.DeduceStride(m),12===K.byteStride&&(K.accessorType="VEC3"),this.createBufferViewKind(m,t,r,K.byteStride),K.bufferViewIndex=this._bufferViews.length-1,p[m]=K.bufferViewIndex}}if(u.getTotalIndices()){var y=u.getIndices();if(y){var x=4*y.length;a=i.a._CreateBufferView(0,r.getByteOffset(),x,void 0,"Indices - "+u.name),this._bufferViews.push(a),f=this._bufferViews.length-1;for(var T=0,v=y.length;T<v;++T)r.setUInt32(y[T])}}if(u.subMeshes)for(var A=0,b=u.subMeshes;A<b.length;A++){var F=b[A];o=!1;var E=F.getMaterial()||u.getScene().defaultMaterial,R=null;if(E)if(u instanceof n.LinesMesh){var M={name:u.name+" material"};(!u.color.equals(n.Color3.White())||u.alpha<1)&&(M.pbrMetallicRoughness={baseColorFactor:u.color.asArray().concat([u.alpha])}),this._materials.push(M),R=this._materials.length-1}else if(E instanceof n.MultiMaterial){var S=E.subMaterials[F.materialIndex];S&&(E=S,R=this._materialMap[E.uniqueId])}else R=this._materialMap[E.uniqueId];var V=null!=R?this._materials[R]:null,w={attributes:{}};this.setPrimitiveMode(w,h);for(var C=0,B=c;C<B.length;C++){if((m=(K=B[C]).kind)!==n.VertexBuffer.UVKind&&m!==n.VertexBuffer.UV2Kind||!V||this._glTFMaterialExporter._hasTexturesPresent(V))if(k=u.getVerticesData(m))if(_=this.getVertexBufferFromMesh(m,u)){var P=_.getSize(),L=K.bufferViewIndex;if(null!=L){s={min:null,max:null},m==n.VertexBuffer.PositionKind&&(s=i.a._CalculateMinMaxPositions(k,0,k.length/P,this._convertToRightHandedSystem));var N=i.a._CreateAccessor(L,m+" - "+t.name,K.accessorType,5126,k.length/P,0,s.min,s.max);this._accessors.push(N),this.setAttributeKind(w,m),null==w.attributes.TEXCOORD_0&&null==w.attributes.TEXCOORD_1||(o=!0)}}}if(f){N=i.a._CreateAccessor(f,"indices - "+t.name,"SCALAR",5125,F.indexCount,4*F.indexStart,null,null);this._accessors.push(N),w.indices=this._accessors.length-1}if(null!=R&&Object.keys(w.attributes).length>0){var I=E.sideOrientation;if(this._convertToRightHandedSystem&&I===n.Material.ClockWiseSideOrientation){var G=null!=f?this._bufferViews[f].byteOffset:null;null==G&&(G=0);var O=null;if(null!=f&&(O=u.getIndices()),O)this.reorderIndicesBasedOnPrimitiveMode(F,h,O,G,r);else for(var D=0,U=c;D<U.length;D++){var k,K=U[D];if(k=u.getVerticesData(K.kind)){var z=this._bufferViews[p[K.kind]].byteOffset;z||(z=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(F,h,I,K.kind,k,z,r)}}}if(!o&&this._glTFMaterialExporter._hasTexturesPresent(this._materials[R])){var H=this._glTFMaterialExporter._stripTexturesFromMaterial(this._materials[R]);this._materials.push(H),R=this._materials.length-1}w.material=R}e.primitives.push(w),this._extensionsPostExportMeshPrimitiveAsync("postExport",w,F,r)&&l.push()}}return Promise.all(l).then(function(){})},e.prototype.createSceneAsync=function(e,t){var r,a,i,o=this,s={nodes:[]},l=e.transformNodes.concat(e.meshes,e.lights);return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(e.materials,"image/png",!0).then(function(){return o.createNodeMapAndAnimationsAsync(e,l,o._shouldExportNode,t).then(function(e){if(o._nodeMap=e,o._totalByteLength=t.getByteOffset(),null==o._totalByteLength)throw new Error("undefined byte length!");for(var u=0,c=l;u<c.length;u++){var f=c[u];if(void 0!==(r=o._nodeMap[f.uniqueId])&&(a=o._nodes[r],f.parent||(o._shouldExportNode(f)?(o._convertToRightHandedSystem&&(a.translation&&(a.translation[2]*=-1,a.translation[0]*=-1),a.rotation=a.rotation?n.Quaternion.FromArray([0,1,0,0]).multiply(n.Quaternion.FromArray(a.rotation)).asArray():n.Quaternion.FromArray([0,1,0,0]).asArray()),s.nodes.push(r)):n.Tools.Log("Omitting "+f.name+" from scene.")),i=f.getDescendants(!0),!a.children&&i&&i.length)){for(var h=[],p=0,d=i;p<d.length;p++){var g=d[p];null!=o._nodeMap[g.uniqueId]&&h.push(o._nodeMap[g.uniqueId])}h.length&&(a.children=h)}}s.nodes.length&&o._scenes.push(s)})})},e.prototype.createNodeMapAndAnimationsAsync=function(e,t,r,a){for(var i,o=this,l=Promise.resolve(),u={},c={name:"runtime animations",channels:[],samplers:[]},f=[],h=function(t){r(t)?l=l.then(function(){return o.createNodeAsync(t,a).then(function(r){var l=o._extensionsPostExportNodeAsync("createNodeAsync",r,t);return null==l?(n.Tools.Warn("Not exporting node "+t.name),Promise.resolve()):l.then(function(r){(t.getDescendants(!0,function(e){return e instanceof n.Node}).length||null!=r.mesh||r.extensions)&&(o._nodes.push(r),i=o._nodes.length-1,u[t.uniqueId]=i),!e.animationGroups.length&&t.animations.length&&s.a._CreateNodeAnimationFromNodeAnimations(t,c,f,u,o._nodes,a,o._bufferViews,o._accessors,o._convertToRightHandedSystem,o._animationSampleRate)})})}):t.name},p=0,d=t;p<d.length;p++){h(d[p])}return l.then(function(){return c.channels.length&&c.samplers.length&&o._animations.push(c),f.forEach(function(e){e.channels.length&&e.samplers.length&&o._animations.push(e)}),e.animationGroups.length&&s.a._CreateNodeAnimationFromAnimationGroups(e,o._animations,u,o._nodes,a,o._bufferViews,o._accessors,o._convertToRightHandedSystem,o._animationSampleRate),u})},e.prototype.createNodeAsync=function(e,t){var r=this;return Promise.resolve().then(function(){var a={},i={primitives:[]};return e.name&&(a.name=e.name),e instanceof n.TransformNode?(r.setNodeTransformation(a,e),r.setPrimitiveAttributesAsync(i,e,t).then(function(){return i.primitives.length&&(r._meshes.push(i),a.mesh=r._meshes.length-1),a})):a})},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),u=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,i=n.byteLength;a<i;++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):n.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))},e.prototype.getUInt32=function(e){if(e<this._byteOffset)return this._dataView.getUint32(e,!0);throw n.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?n.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?n.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?n.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?n.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)&&n.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):n.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):n.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}()},function(e,t,r){"use strict";r.r(t),r.d(t,"GLTFData",function(){return n});var n=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")?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){"use strict";r.r(t),r.d(t,"__IGLTFExporterExtension",function(){return n});var n=0},,function(e,t,r){"use strict";r.r(t);var n=r(7),a=r(3),i=r(2),o=r(10),s=r(8),l=r(1),u=r(9);r.d(t,"_GLTFAnimation",function(){return n.a}),r.d(t,"GLTFData",function(){return a.GLTFData}),r.d(t,"_Exporter",function(){return i.b}),r.d(t,"_BinaryWriter",function(){return i.a}),r.d(t,"__IGLTFExporterExtensionV2",function(){return 0}),r.d(t,"_GLTFMaterialExporter",function(){return o.a}),r.d(t,"GLTF2Export",function(){return s.GLTF2Export}),r.d(t,"_GLTFUtilities",function(){return l.a}),r.d(t,"KHR_texture_transform",function(){return u.KHR_texture_transform}),r.d(t,"KHR_lights_punctual",function(){return u.KHR_lights_punctual})},function(e,t,r){"use strict";r.d(t,"a",function(){return o});var n,a=r(0),i=r(1);!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(n||(n={}));var o=function(){function e(){}return e._CreateNodeAnimation=function(t,r,n,i,o,s){var l=[],u=[],c=r.getKeys(),f=e.calculateMinMaxKeyFrames(c),h=e._DeduceInterpolation(c,n,o),p=f.max-f.min,d=h.interpolationType,g=h.shouldBakeAnimation;return g?e._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,l,u,f,i,o):"LINEAR"===d||"STEP"===d?e._CreateLinearOrStepAnimation(t,r,n,p,l,u,i,o):"CUBICSPLINE"===d?e._CreateCubicSplineAnimation(t,r,n,p,l,u,i,o):e._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,l,u,f,i,o),l.length&&u.length?{inputs:l,outputs:u,samplerInterpolation:d,inputsMin:g?f.min:a.Tools.FloatRound(f.min/r.framePerSecond),inputsMax:g?f.max:a.Tools.FloatRound(f.max/r.framePerSecond)}:null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,i=e.targetProperty.split(".");switch(i[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;default:a.Tools.Error("Unsupported animatable property "+i[0])}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(a.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,i,o,s,l,u,c,f){var h;if(t instanceof a.TransformNode&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var g=d[p],m=e._DeduceAnimationInfo(g);m&&(h={name:g.name,samplers:[],channels:[]},e.AddAnimation(""+g.name,g.hasRunningRuntimeAnimations?r:h,t,g,m.dataAccessorType,m.animationChannelTargetPath,i,s,l,u,c,m.useQuaternion,f),h.samplers.length&&h.channels.length&&n.push(h))}},e._CreateNodeAnimationFromAnimationGroups=function(t,r,n,i,o,s,l,u,c){var f;if(t.animationGroups)for(var h=0,p=t.animationGroups;h<p.length;h++){var d=p[h];f={name:d.name,channels:[],samplers:[]};for(var g=0,m=d.targetedAnimations;g<m.length;g++){var _=m[g],y=_.target,x=_.animation;if(y instanceof a.Mesh||1===y.length&&y[0]instanceof a.Mesh){var T=e._DeduceAnimationInfo(_.animation);if(T){var v=y instanceof a.Mesh?y:y[0];e.AddAnimation(""+x.name,f,v,x,T.dataAccessorType,T.animationChannelTargetPath,n,o,s,l,u,T.useQuaternion,c)}}}f.channels.length&&f.samplers.length&&r.push(f)}},e.AddAnimation=function(t,r,n,a,o,s,l,u,c,f,h,p,d){var g,m,_,y,x,T,v,A=e._CreateNodeAnimation(n,a,s,h,p,d);if(A){var b=l[n.uniqueId],F=4*A.inputs.length;g=i.a._CreateBufferView(0,u.getByteOffset(),F,void 0,t+" keyframe data view"),c.push(g),A.inputs.forEach(function(e){u.setFloat32(e)}),m=i.a._CreateAccessor(c.length-1,t+" keyframes","SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),f.push(m),_=f.length-1,x=A.outputs.length,F="VEC3"===o?12*A.outputs.length:16*A.outputs.length,g=i.a._CreateBufferView(0,u.getByteOffset(),F,void 0,t+" data view"),c.push(g),A.outputs.forEach(function(e){e.forEach(function(e){u.setFloat32(e)})}),m=i.a._CreateAccessor(c.length-1,t+" data",o,5126,x,null,null,null),f.push(m),y=f.length-1,T={interpolation:A.samplerInterpolation,input:_,output:y},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:b,path:s}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,i,o,s,l,u,c,f,h,p){var d,g,m=a.Quaternion.Identity(),_=null,y=null,x=null,T=null,v=null,A=null;f.min=a.Tools.FloatRound(i/s);for(var b=r.getKeys(),F=0,E=b.length;F<E;++F){if(A=null,x=b[F],F+1<E)if(T=b[F+1],x.value.equals(T.value)){if(0!==F)continue;A=x.frame}else A=T.frame;else{if(v=b[F-1],x.value.equals(v.value))continue;A=o}if(A)for(var R=x.frame;R<=A;R+=l)(g=a.Tools.FloatRound(R/s))!==_&&(_=g,y=g,d=r._interpolate(R,0,void 0,r.loopMode),e._SetInterpolatedValue(t,d,g,r,n,m,u,c,h,p))}y&&(f.max=y)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,i,o,s,l){var u,c,f=null,h=e._GetBasePositionRotationOrScale(r,o,s,l);if(i===a.Animation.ANIMATIONTYPE_FLOAT)switch(c=(u=n.targetProperty.split("."))?u[1]:"",f=l?a.Quaternion.FromArray(h).normalize():a.Vector3.FromArray(h),c){case"x":case"y":f[c]=s&&l&&"scale"!==o?-t:t;break;case"z":f[c]=s&&!l&&"scale"!==o?-t:t;break;case"w":f.w=t;break;default:a.Tools.Error('glTFAnimation: Unsupported component type "'+c+'" for scale animation!')}return f},e._SetInterpolatedValue=function(e,t,r,n,o,s,l,u,c,f){var h,p=n.dataType;l.push(r),"number"==typeof t&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,p,o,c,f)),t&&("rotation"===o?(f?s=t:(h=t,a.Quaternion.RotationYawPitchRollToRef(h.y,h.x,h.z,s)),c&&(i.a._GetRightHandedQuaternionFromRef(s),e.parent||(s=a.Quaternion.FromArray([0,1,0,0]).multiply(s))),u.push(s.asArray())):(h=t,c&&"scale"!==o&&(i.a._GetRightHandedPositionVector3FromRef(h),e.parent||(h.x*=-1,h.z*=-1)),u.push(h.asArray())))},e._CreateLinearOrStepAnimation=function(t,r,n,a,i,o,s,l){for(var u=0,c=r.getKeys();u<c.length;u++){var f=c[u];i.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,o,n,t,s,l)}},e._CreateCubicSplineAnimation=function(t,r,a,i,o,s,l,u){r.getKeys().forEach(function(c){o.push(c.frame/r.framePerSecond),e.AddSplineTangent(t,n.INTANGENT,s,a,"CUBICSPLINE",c,i,u,l),e._AddKeyframeValue(c,r,s,a,t,l,u),e.AddSplineTangent(t,n.OUTTANGENT,s,a,"CUBICSPLINE",c,i,u,l)})},e._GetBasePositionRotationOrScale=function(e,t,r,n){var o;return"rotation"===t?n?e.rotationQuaternion?(o=e.rotationQuaternion.asArray(),r&&(i.a._GetRightHandedQuaternionArrayFromRef(o),e.parent||(o=a.Quaternion.FromArray([0,1,0,0]).multiply(a.Quaternion.FromArray(o)).asArray()))):o=a.Quaternion.Identity().asArray():(o=e.rotation.asArray(),i.a._GetRightHandedNormalArray3FromRef(o)):"translation"===t?(o=e.position.asArray(),r&&i.a._GetRightHandedPositionArray3FromRef(o)):o=e.scaling.asArray(),o},e._AddKeyframeValue=function(e,t,r,n,o,s,l){var u,c,f=t.dataType;if(f===a.Animation.ANIMATIONTYPE_VECTOR3){if(u=e.value.asArray(),"rotation"===n){var h=a.Vector3.FromArray(u),p=a.Quaternion.RotationYawPitchRoll(h.y,h.x,h.z);s&&(i.a._GetRightHandedQuaternionFromRef(p),o.parent||(p=a.Quaternion.FromArray([0,1,0,0]).multiply(p))),u=p.asArray()}else"translation"===n&&s&&(i.a._GetRightHandedNormalArray3FromRef(u),o.parent||(u[0]*=-1,u[2]*=-1));r.push(u)}else if(f===a.Animation.ANIMATIONTYPE_FLOAT){if(c=this._ConvertFactorToVector3OrQuaternion(e.value,o,t,f,n,s,l)){if("rotation"===n){var d=l?c:a.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).normalize();s&&(i.a._GetRightHandedQuaternionFromRef(d),o.parent||(d=a.Quaternion.FromArray([0,1,0,0]).multiply(d))),r.push(d.asArray())}else"translation"===n&&s&&(i.a._GetRightHandedNormalVector3FromRef(c),o.parent||(c.x*=-1,c.z*=-1));r.push(c.asArray())}}else f===a.Animation.ANIMATIONTYPE_QUATERNION?(u=e.value.normalize().asArray(),s&&(i.a._GetRightHandedQuaternionArrayFromRef(u),o.parent||(u=a.Quaternion.FromArray([0,1,0,0]).multiply(a.Quaternion.FromArray(u)).asArray())),r.push(u)):a.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,i,o=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,l=e.length;s<l;++s)if((i=e[s]).inTangent||i.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",o=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||i.interpolation&&i.interpolation===a.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",o=!0;break}}else n=i.interpolation&&i.interpolation===a.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:o}},e.AddSplineTangent=function(e,t,r,o,s,l,u,c,f){var h,p=t===n.INTANGENT?l.inTangent:l.outTangent;if("CUBICSPLINE"===s){if("rotation"===o)if(p){if(c)h=p.scale(u).asArray();else{var d=p.scale(u);h=a.Quaternion.RotationYawPitchRoll(d.y,d.x,d.z).asArray()}f&&(i.a._GetRightHandedQuaternionArrayFromRef(h),e.parent||(h=a.Quaternion.FromArray([0,1,0,0]).multiply(a.Quaternion.FromArray(h)).asArray()))}else h=[0,0,0,0];else p?(h=p.scale(u).asArray(),f&&"translation"===o&&(i.a._GetRightHandedPositionArray3FromRef(h),e.parent||(h[0]*=-1,h[2]*=-1))):h=[0,0,0];r.push(h)}},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}()},function(e,t,r){"use strict";r.r(t),r.d(t,"GLTF2Export",function(){return a});var n=r(2),a=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then(function(){var a=t.replace(/\.[^\/.]+$/,"");return new n.b(e,r)._generateGLTFAsync(a)})},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 a=this;return this._PreExportAsync(e,r).then(function(){var i=t.replace(/\.[^\/.]+$/,"");return new n.b(e,r)._generateGLBAsync(i).then(function(t){return a._PostExportAsync(e,t,r)})})},e}()},function(e,t,r){"use strict";r.r(t);var n=r(0),a=r(2),i="precision highp float;\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 textureTransformMat;\nvoid main(void) {\nvec2 uvTransformed=(textureTransformMat*vec4(vUV.xy,1,1)).xy;\ngl_FragColor=texture2D(textureSampler,uvTransformed);\n}";n.Effect.ShadersStore.textureTransformPixelShader=i;var o="KHR_texture_transform",s=function(){function e(e){this.name=o,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){delete this._exporter},e.prototype.preExportTextureAsync=function(e,t,r){var a=this;return new Promise(function(r,i){var o={};0===t.uOffset&&0===t.vOffset||(o.offset=[t.uOffset,t.vOffset]),1===t.uScale&&1===t.vScale||(o.scale=[t.uScale,t.vScale]),0!==t.wAng&&(o.rotation=t.wAng),Object.keys(o).length||r(t);var s=o.scale?new n.Vector2(o.scale[0],o.scale[1]):n.Vector2.One(),l=null!=o.rotation?o.rotation:0,u=o.offset?new n.Vector2(o.offset[0],o.offset[1]):n.Vector2.Zero(),c=t.getScene();c?a.textureTransformTextureAsync(t,u,l,s,c).then(function(e){r(e)}):i(e+': "scene" is not defined for Babylon texture '+t.name+"!")})},e.prototype.textureTransformTextureAsync=function(e,t,r,a,i){return new Promise(function(t,r){var a=new n.ProceduralTexture(""+e.name,e.getSize(),"textureTransform",i);a||(n.Tools.Log("Cannot create procedural texture for "+e.name+"!"),t(e)),a.setTexture("textureSampler",e),a.setMatrix("textureTransformMat",e.getTextureMatrix()),a.isReady()?(a.render(),t(a)):a.getEffect().executeWhenCompiled(function(){a.render(),t(a)})})},e}();a.b.RegisterExtension(o,function(e){return new s(e)});var l,u=r(1),c="KHR_lights_punctual";!function(e){e.DIRECTIONAL="directional",e.POINT="point",e.SPOT="spot"}(l||(l={}));var f=function(){function e(e){this.name=c,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){delete this._exporter,delete this._lights},e.prototype.onExporting=function(){this._lights&&(null==this._exporter._glTF.extensionsUsed&&(this._exporter._glTF.extensionsUsed=[]),-1===this._exporter._glTF.extensionsUsed.indexOf(c)&&this._exporter._glTF.extensionsUsed.push(c),this.required&&(null==this._exporter._glTF.extensionsRequired&&(this._exporter._glTF.extensionsRequired=[]),-1===this._exporter._glTF.extensionsRequired.indexOf(c)&&this._exporter._glTF.extensionsRequired.push(c)),null==this._exporter._glTF.extensions&&(this._exporter._glTF.extensions={}),this._exporter._glTF.extensions[c]=this._lights)},e.prototype.postExportNodeAsync=function(e,t,r){var a=this;return new Promise(function(i,o){if(r instanceof n.ShadowLight){var s=r,f=void 0,h=s.getTypeID()==n.Light.LIGHTTYPEID_POINTLIGHT?l.POINT:s.getTypeID()==n.Light.LIGHTTYPEID_DIRECTIONALLIGHT?l.DIRECTIONAL:s.getTypeID()==n.Light.LIGHTTYPEID_SPOTLIGHT?l.SPOT:null;if(null==h)n.Logger.Warn(e+": Light "+s.name+" is not supported in "+c);else{var p=s.position.clone();if(p.equals(n.Vector3.Zero())||(a._exporter._convertToRightHandedSystem&&u.a._GetRightHandedPositionVector3FromRef(p),t.translation=p.asArray()),h!==l.POINT){var d=s.direction,g=-Math.atan2(d.z,d.x)+Math.PI/2,m=Math.sqrt(d.x*d.x+d.z*d.z),_=-Math.atan2(d.y,m),y=n.Quaternion.RotationYawPitchRoll(g,_,0);a._exporter._convertToRightHandedSystem&&u.a._GetRightHandedQuaternionFromRef(y),y.equals(n.Quaternion.Identity())||(t.rotation=y.asArray())}if(s.falloffType!==n.Light.FALLOFF_GLTF&&n.Logger.Warn(e+": Light falloff for "+s.name+" does not match the "+c+" specification!"),f={type:h},s.diffuse.equals(n.Color3.White())||(f.color=s.diffuse.asArray()),1!==s.intensity&&(f.intensity=s.intensity),s.range!==Number.MAX_VALUE&&(f.range=s.range),h===l.SPOT){var x=s;x.angle!==Math.PI/2&&(null==f.spot&&(f.spot={}),f.spot.outerConeAngle=x.angle/2),0!==x.innerAngle&&(null==f.spot&&(f.spot={}),f.spot.innerConeAngle=x.innerAngle/2)}null==a._lights&&(a._lights={lights:[]}),a._lights.lights.push(f),null==t.extensions&&(t.extensions={});var T={light:a._lights.lights.length-1};t.extensions[c]=T}}i(t)})},e}();a.b.RegisterExtension(c,function(e){return new f(e)}),r.d(t,"KHR_texture_transform",function(){return s}),r.d(t,"KHR_lights_punctual",function(){return f})},function(e,t,r){"use strict";r.d(t,"a",function(){return a});var n=r(0),a=function(){function e(e){this._textureMap={},this._textureMap={},this._exporter=e}return e.FuzzyEquals=function(e,t,r){return n.Scalar.WithinEpsilon(e.r,t.r,r)&&n.Scalar.WithinEpsilon(e.g,t.g,r)&&n.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){for(var a=[],i=0,o=e;i<o.length;i++){var s=o[i];s instanceof n.StandardMaterial?a.push(this._convertStandardMaterialAsync(s,t,r)):s instanceof n.PBRMetallicRoughnessMaterial?a.push(this._convertPBRMetallicRoughnessMaterialAsync(s,t,r)):s instanceof n.PBRMaterial?a.push(this._convertPBRMaterialAsync(s,t,r)):n.Tools.Warn("Unsupported material type: "+s.name)}return 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){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},e.prototype._convertToGLTFPBRMetallicRoughness=function(t){var r=new n.Vector2(0,1),a=new n.Vector2(0,.1),i=new n.Vector2(0,.1),o=new n.Vector2(1300,.1);var s=t.diffuseColor.toLinearSpace().scale(.5),l=t.alpha,u=function(e){return function(e,t,r,n,a){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*n+e*e*e*a}(Math.pow(e/o.x,.333333),r.y,a.y,i.y,o.y)}(n.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower));return{baseColorFactor:[s.r,s.g,s.b,l],metallicFactor:0,roughnessFactor:u}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var a=this._DielectricSpecular.r,i=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,o=i*i-4*a*(this._DielectricSpecular.r-t);return n.Scalar.Clamp((-i+Math.sqrt(o))/(2*a),0,1)},e.prototype._getAlphaMode=function(e){return e.needAlphaBlending()?"BLEND":e.needAlphaTesting()?"MASK":"OPAQUE"},e.prototype._convertStandardMaterialAsync=function(t,r,a){var i=this._exporter._materialMap,o=this._exporter._materials,s=this._getAlphaMode(t),l=[],u=this._convertToGLTFPBRMetallicRoughness(t),c={name:t.name};if(null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||n.Tools.Warn(t.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),c.doubleSided=!0),a&&(t.diffuseTexture&&l.push(this._exportTextureAsync(t.diffuseTexture,r).then(function(e){e&&(u.baseColorTexture=e)})),t.bumpTexture&&l.push(this._exportTextureAsync(t.bumpTexture,r).then(function(e){e&&(c.normalTexture=e,null!=t.bumpTexture&&1!==t.bumpTexture.level&&(c.normalTexture.scale=t.bumpTexture.level))})),t.emissiveTexture&&(c.emissiveFactor=[1,1,1],l.push(this._exportTextureAsync(t.emissiveTexture,r).then(function(e){e&&(c.emissiveTexture=e)}))),t.ambientTexture&&l.push(this._exportTextureAsync(t.ambientTexture,r).then(function(e){if(e){var t={index:e.index};c.occlusionTexture=t,t.strength=1}}))),(t.alpha<1||t.opacityTexture)&&(t.alphaMode===n.Engine.ALPHA_COMBINE?c.alphaMode="BLEND":n.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e.FuzzyEquals(t.emissiveColor,n.Color3.Black(),e._Epsilon)&&(c.emissiveFactor=t.emissiveColor.asArray()),c.pbrMetallicRoughness=u,"OPAQUE"!==s)switch(s){case"BLEND":c.alphaMode="BLEND";break;case"MASK":c.alphaMode="MASK",c.alphaCutoff=t.alphaCutOff;break;default:n.Tools.Warn("Unsupported alpha mode "+s)}return o.push(c),i[t.uniqueId]=o.length-1,Promise.all(l).then(function(){})},e.prototype._convertPBRMetallicRoughnessMaterialAsync=function(t,r,a){var i=this._exporter._materialMap,o=this._exporter._materials,s=[],l={};t.baseColor&&(l.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,t.alpha]),null!=t.metallic&&1!==t.metallic&&(l.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(l.roughnessFactor=t.roughness);var u={name:t.name};t.doubleSided&&(u.doubleSided=t.doubleSided);var c=null;return null!=t.transparencyMode&&(c=this._getAlphaMode(t))&&"OPAQUE"!==c&&(u.alphaMode=c,"MASK"===c&&(u.alphaCutoff=t.alphaCutOff)),a&&(null!=t.baseTexture&&s.push(this._exportTextureAsync(t.baseTexture,r).then(function(e){e&&(l.baseColorTexture=e)})),t.normalTexture&&s.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&&s.push(this._exportTextureAsync(t.occlusionTexture,r).then(function(e){e&&(u.occlusionTexture=e,null!=t.occlusionStrength&&(u.occlusionTexture.strength=t.occlusionStrength))})),t.emissiveTexture&&s.push(this._exportTextureAsync(t.emissiveTexture,r).then(function(e){e&&(u.emissiveTexture=e)}))),e.FuzzyEquals(t.emissiveColor,n.Color3.Black(),e._Epsilon)&&(u.emissiveFactor=t.emissiveColor.asArray()),u.pbrMetallicRoughness=l,o.push(u),i[t.uniqueId]=o.length-1,Promise.all(s).then(function(){})},e.prototype._createBase64FromCanvasAsync=function(e,t,r,a){var i=this;return new Promise(function(a,o){var s,l=n.Engine.TEXTURETYPE_UNSIGNED_INT,u=i._exporter._getLocalEngine();s=new n.Scene(u);var c=u.createRawTexture(e,t,r,n.Engine.TEXTUREFORMAT_RGBA,!1,!0,n.Texture.NEAREST_SAMPLINGMODE,null,l),f=new n.PostProcess("pass","pass",null,null,1,null,n.Texture.NEAREST_SAMPLINGMODE,u,!1,void 0,n.Engine.TEXTURETYPE_UNSIGNED_INT,void 0,null,!1);f.getEffect().executeWhenCompiled(function(){f.onApply=function(e){e._bindTexture("textureSampler",c)},u.setSize(t,r),s.postProcessManager.directRender([f],null),f.dispose(),c.dispose();var e=u.getRenderingCanvas();if(e)if(e.toBlob)n.Tools.ToBlob(e,function(e){if(e){var t=new FileReader;t.onload=function(e){var t=e.target.result;s.dispose(),a(t)},t.readAsDataURL(e)}else o("gltfMaterialExporter: Failed to get blob from image canvas!")});else{var i=e.toDataURL();a(i)}else o("Engine is missing a canvas!")})})},e.prototype._createWhiteTexture=function(e,t,r){for(var a=new Uint8Array(e*t*4),i=0;i<a.length;i+=4)a[i]=a[i+1]=a[i+2]=a[i+3]=255;return n.RawTexture.CreateRGBATexture(a,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var a,i,o=e?e.getSize():{width:0,height:0},s=t?t.getSize():{width:0,height:0};return o.width<s.width?(a=e&&e instanceof n.Texture?n.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):this._createWhiteTexture(s.width,s.height,r),i=t):o.width>s.width?(i=t&&t instanceof n.Texture?n.TextureTools.CreateResizedCopy(t,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,r),a=e):(a=e,i=t),{texture1:a,texture2:i}},e.prototype._convertPixelArrayToFloat32=function(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(t,r,a,i){var o=[];if(!t&&!r)return Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!");var s=t?t.getScene():r?r.getScene():null;if(s){var l=this._resizeTexturesToSameDimensions(t,r,s),u=l.texture1.getSize(),c=void 0,f=void 0,h=u.width,p=u.height,d=l.texture1.readPixels(),g=l.texture2.readPixels();if(!d)return Promise.reject("Failed to retrieve pixels from diffuse texture!");if(c=this._convertPixelArrayToFloat32(d),!g)return Promise.reject("Failed to retrieve pixels from specular glossiness texture!");for(var m=(f=this._convertPixelArrayToFloat32(g)).byteLength,_=new Uint8Array(m),y=new Uint8Array(m),x=n.Color3.Black(),T=0,v=0,A=0;A<p;++A)for(var b=0;b<h;++b){var F=4*(h*A+b),E={diffuseColor:new n.Color3(c[F],c[F+1],c[F+2]).toLinearSpace().multiply(a.diffuseColor),specularColor:new n.Color3(f[F],f[F+1],f[F+2]).toLinearSpace().multiply(a.specularColor),glossiness:f[F+3]*a.glossiness},R=this._convertSpecularGlossinessToMetallicRoughness(E);x.r=Math.max(x.r,R.baseColor.r),x.g=Math.max(x.g,R.baseColor.g),x.b=Math.max(x.b,R.baseColor.b),T=Math.max(T,R.metallic),v=Math.max(v,R.roughness),y[F]=255*R.baseColor.r,y[F+1]=255*R.baseColor.g,y[F+2]=255*R.baseColor.b,y[F+3]=l.texture1.hasAlpha?255*c[F+3]:255,_[F]=0,_[F+1]=255*R.roughness,_[F+2]=255*R.metallic,_[F+3]=255}var M={baseColor:x,metallic:T,roughness:v},S=!1,V=!1;for(A=0;A<p;++A)for(b=0;b<h;++b){var w=4*(h*A+b);y[w]/=M.baseColor.r>e._Epsilon?M.baseColor.r:1,y[w+1]/=M.baseColor.g>e._Epsilon?M.baseColor.g:1,y[w+2]/=M.baseColor.b>e._Epsilon?M.baseColor.b:1;var C=n.Color3.FromInts(y[w],y[w+1],y[w+2]).toGammaSpace();y[w]=255*C.r,y[w+1]=255*C.g,y[w+2]=255*C.b,e.FuzzyEquals(C,n.Color3.White(),e._Epsilon)||(V=!0),_[w+1]/=M.roughness>e._Epsilon?M.roughness:1,_[w+2]/=M.metallic>e._Epsilon?M.metallic:1;var B=n.Color3.FromInts(255,_[w+1],_[w+2]);e.FuzzyEquals(B,n.Color3.White(),e._Epsilon)||(S=!0)}if(S){var P=this._createBase64FromCanvasAsync(_,h,p,i).then(function(e){M.metallicRoughnessTextureBase64=e});o.push(P)}if(V){P=this._createBase64FromCanvasAsync(y,h,p,i).then(function(e){M.baseColorTextureBase64=e});o.push(P)}return Promise.all(o).then(function(){return M})}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),a=this._getPerceivedBrightness(t.specularColor),i=1-this._getMaxComponent(t.specularColor),o=e._SolveMetallic(r,a,i),s=t.diffuseColor.scale(i/(1-e._DielectricSpecular.r)/Math.max(1-o,e._Epsilon)),l=t.specularColor.subtract(e._DielectricSpecular.scale(1-o)).scale(1/Math.max(o,e._Epsilon)),u=n.Color3.Lerp(s,l,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=[],i={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};return n&&(e.albedoTexture&&a.push(this._exportTextureAsync(e.albedoTexture,t).then(function(e){e&&(r.baseColorTexture=e)})),e.metallicTexture&&a.push(this._exportTextureAsync(e.metallicTexture,t).then(function(e){e&&(r.metallicRoughnessTexture=e)}))),Promise.all(a).then(function(){return i})},e.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof n.Texture?e.samplingMode:null;if(null!=r)switch(r){case n.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case n.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case n.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case n.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case n.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case n.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case n.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case n.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case n.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case n.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case n.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case n.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case n.Texture.WRAP_ADDRESSMODE:return 10497;case n.Texture.CLAMP_ADDRESSMODE:return 33071;case n.Texture.MIRROR_ADDRESSMODE:return 33648;default:return n.Tools.Error("Unsupported Texture Wrap Mode "+e+"!"),10497}},e.prototype._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof n.Texture?e.wrapU:n.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof n.Texture?e.wrapV:n.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,a){var i=this;return Promise.resolve().then(function(){var o=i._exporter._samplers,s=i._exporter._textures,l={diffuseColor:e.albedoColor||n.Color3.White(),specularColor:e.reflectivityColor||n.Color3.White(),glossiness:e.microSurface||1},u=null,c=i._getGLTFTextureSampler(e.albedoTexture);return null!=c.magFilter&&null!=c.minFilter&&null!=c.wrapS&&null!=c.wrapT&&(o.push(c),u=o.length-1),e.reflectivityTexture&&!e.useMicroSurfaceFromReflectivityMapAlpha?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(e.albedoTexture||e.reflectivityTexture)&&a?i._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(e.albedoTexture,e.reflectivityTexture,l,t).then(function(n){if(n.baseColorTextureBase64){var a=i._getTextureInfoFromBase64(n.baseColorTextureBase64,"bjsBaseColorTexture_"+s.length+".png",t,e.albedoTexture?e.albedoTexture.coordinatesIndex:null,u);a&&(r.baseColorTexture=a)}if(n.metallicRoughnessTextureBase64){var o=i._getTextureInfoFromBase64(n.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+s.length+".png",t,e.reflectivityTexture?e.reflectivityTexture.coordinatesIndex:null,u);o&&(r.metallicRoughnessTexture=o)}return n}):i._convertSpecularGlossinessToMetallicRoughness(l)})},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,a={},i={name:e.name};return e.isMetallicWorkflow()?(e.albedoColor&&(a.baseColorFactor=[e.albedoColor.r,e.albedoColor.g,e.albedoColor.b,e.alpha]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,a,r).then(function(o){return n.setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)})):this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,a,r).then(function(o){return n.setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)})},e.prototype.setMetallicRoughnessPbrMaterial=function(t,r,a,i,o,s){var l=this._exporter._materialMap,u=this._exporter._materials,c=[];if(t){var f=null;if(null!=r.transparencyMode&&(f=this._getAlphaMode(r))&&"OPAQUE"!==f&&(a.alphaMode=f,"MASK"===f&&(a.alphaCutoff=r.alphaCutOff)),e.FuzzyEquals(t.baseColor,n.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(i.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(i.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(i.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||n.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),a.doubleSided=!0),s){if(r.bumpTexture){var h=this._exportTextureAsync(r.bumpTexture,o).then(function(e){e&&(a.normalTexture=e,1!==r.bumpTexture.level&&(a.normalTexture.scale=r.bumpTexture.level))});c.push(h)}if(r.ambientTexture){h=this._exportTextureAsync(r.ambientTexture,o).then(function(e){if(e){var t={index:e.index};a.occlusionTexture=t,r.ambientTextureStrength&&(t.strength=r.ambientTextureStrength)}});c.push(h)}if(r.emissiveTexture){h=this._exportTextureAsync(r.emissiveTexture,o).then(function(e){e&&(a.emissiveTexture=e)});c.push(h)}}e.FuzzyEquals(r.emissiveColor,n.Color3.Black(),e._Epsilon)||(a.emissiveFactor=r.emissiveColor.asArray()),a.pbrMetallicRoughness=i,u.push(a),l[r.uniqueId]=u.length-1}return Promise.all(c).then(function(e){})},e.prototype.getPixelsFromTexture=function(e){return e.textureType,n.Engine.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(){var n=e.uid;if(n in r._textureMap)return r._textureMap[n];for(var a=r._exporter._samplers,i=r._getGLTFTextureSampler(e),o=null,s=null,l=0;l<a.length;++l){var u=a[l];if(u.minFilter===i.minFilter&&u.magFilter===i.magFilter&&u.wrapS===i.wrapS&&u.wrapT===i.wrapT){s=l;break}}null==s?(a.push(i),o=a.length-1):o=s;var c=r.getPixelsFromTexture(e),f=e.getSize();return r._createBase64FromCanvasAsync(c,f.width,f.height,t).then(function(a){var i=r._getTextureInfoFromBase64(a,e.name.replace(/\.\/|\/|\.\\|\\/g,"_"),t,e.coordinatesIndex,o);return i&&(r._textureMap[n]=i),i})})},e.prototype._getTextureInfoFromBase64=function(e,t,r,a,i){var o=this._exporter._textures,s=this._exporter._images,l=this._exporter._imageData,u=null,c={source:s.length,name:t};null!=i&&(c.sampler=i);for(var f=atob(e.split(",")[1]),h=new ArrayBuffer(f.length),p=new Uint8Array(h),d=0,g=f.length;d<g;++d)p[d]=f.charCodeAt(d);var m={data:p,mimeType:r},_="image/jpeg"===r?".jpeg":".png",y=t+_;if(y in l&&(y=t+"_"+n.Tools.RandomId()+_),l[y]=m,"image/jpeg"===r||"image/png"===r){var x={name:t,uri:y},T=null;for(d=0;d<s.length;++d)if(s[d].uri===y){T=d;break}null==T?(s.push(x),c.source=s.length-1):c.source=T,o.push(c),u={index:o.length-1},null!=a&&(u.texCoord=a)}else n.Tools.Error("Unsupported texture mime type "+r);return u},e._DielectricSpecular=new n.Color3(.04,.04,.04),e._MaxSpecularPower=1024,e._Epsilon=1e-6,e}()},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},,function(e,t,r){"use strict";r.r(t),function(e){var n=r(4),a=r(3),i=r(8),o=r(9),s=r(6);r.d(t,"__IGLTFExporterExtension",function(){return n.__IGLTFExporterExtension}),r.d(t,"GLTFData",function(){return s.GLTFData}),r.d(t,"GLTF2Export",function(){return s.GLTF2Export}),r.d(t,"_GLTFAnimation",function(){return s._GLTFAnimation}),r.d(t,"_Exporter",function(){return s._Exporter}),r.d(t,"_BinaryWriter",function(){return s._BinaryWriter}),r.d(t,"__IGLTFExporterExtensionV2",function(){return s.__IGLTFExporterExtensionV2}),r.d(t,"_GLTFMaterialExporter",function(){return s._GLTFMaterialExporter}),r.d(t,"_GLTFUtilities",function(){return s._GLTFUtilities}),r.d(t,"KHR_texture_transform",function(){return s.KHR_texture_transform}),r.d(t,"KHR_lights_punctual",function(){return s.KHR_lights_punctual});var l=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==l){l.BABYLON=l.BABYLON||{};var u=l.BABYLON;u.GLTF2=u.GLTF2||{},u.GLTF2.Exporter=u.GLTF2.Exporter||{},u.GLTF2.Exporter.Extensions=u.GLTF2.Exporter.Extensions||{};var c=[];for(var f in n)u[f]=n[f],c.push(f);for(var f in a)u[f]=a[f],c.push(f);for(var f in i)u[f]=i[f],c.push(f);for(var f in o)u.GLTF2.Exporter.Extensions[f]=o[f],c.push(f);for(var f in s)c.indexOf(f)>-1||(u.GLTF2.Exporter[f]=s[f])}}.call(this,r(11))}])});