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 o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.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 o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));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=17)}([function(t,r){t.exports=e},function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));var n=r(0),o=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,o){var a={buffer:e,byteLength:r};return t&&(a.byteOffset=t),o&&(a.name=o),n&&(a.byteStride=n),a},e._CreateAccessor=function(e,t,r,n,o,a,i,s){var u={name:t,bufferView:e,componentType:n,count:o,type:r};return null!=i&&(u.min=i),null!=s&&(u.max=s),null!=a&&(u.byteOffset=a),u},e._CalculateMinMaxPositions=function(t,r,o,a){var i,s,u,l=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(o)for(var f=r,h=r+o;f<h;++f){i=3*f,s=n.Vector3.FromArray(t,i),a&&e._GetRightHandedPositionVector3FromRef(s),u=s.asArray();for(var p=0;p<3;++p){var d=u[p];d<l[p]&&(l[p]=d),d>c[p]&&(c[p]=d),++i}}return{min:l,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._GetRightHandedMatrixFromRef=function(e){var t=e.m;n.Matrix.FromValuesToRef(t[0],t[1],-t[2],t[3],t[4],t[5],-t[6],t[7],-t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15],e)},e._GetDataAccessorElementCount=function(e){switch(e){case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":return 4}},e}()},function(e,t,r){"use strict";r.d(t,"b",(function(){return l})),r.d(t,"a",(function(){return c}));var n=r(3),o=r(0),a=r(11),i=r(1),s=r(4),u=r(8),l=function(){function e(e,t){this._includeCoordinateSystemConversionNodes=!1,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._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 a.a(this),this._loadExtensions()}return e.prototype._applyExtension=function(e,t,r,n){var o=this;if(r>=t.length)return Promise.resolve(e);var a=n(t[r],e);return a?a.then((function(e){return o._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o];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,o){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,o,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,o){return t.postExportNodeAsync&&t.postExportNodeAsync(e,o,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 o=[],a=0,i=e._ExtensionNames;a<i.length;a++){var s=i[a],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,a=e._ExtensionNames;o<a.length;o++){var i=a[o],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 o=n[r],a=this._extensions[o];a.enabled&&t(a)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions){this._extensions[e].dispose()}},e.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&o.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.reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,a){switch(t){case o.Material.TriangleFillMode:n||(n=0);for(var i=e.indexStart,s=e.indexStart+e.indexCount;i<s;i+=3){var u=n+4*i,l=a.getUInt32(u+4),c=a.getUInt32(u+8);a.setUInt32(c,u+4),a.setUInt32(l,u+8)}break;case o.Material.TriangleFanDrawMode:i=e.indexStart+e.indexCount-1;for(var f=e.indexStart;i>=f;--i)a.setUInt32(r[i],n),n+=4;break;case o.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,i,s,u){if(u&&r===o.Material.ClockWiseSideOrientation)switch(t){case o.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,n,a,i,s,u);break;case o.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,n,a,i,s,u);break;case o.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,n,a,i,s,u)}},e.prototype.reorderTriangleFillMode=function(e,t,r,n,a,i,s,u){var l=this.getVertexBufferFromMesh(n,e.getMesh());if(l){var c=l.byteStride/o.VertexBuffer.GetTypeByteLength(l.type);if(e.verticesCount%3!=0)o.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var f=[],h=0;switch(n){case o.VertexBuffer.PositionKind:case o.VertexBuffer.NormalKind:for(var p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*c,f.push(o.Vector3.FromArray(a,h)),f.push(o.Vector3.FromArray(a,h+2*c)),f.push(o.Vector3.FromArray(a,h+c));break;case o.VertexBuffer.TangentKind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*c,f.push(o.Vector4.FromArray(a,h)),f.push(o.Vector4.FromArray(a,h+2*c)),f.push(o.Vector4.FromArray(a,h+c));break;case o.VertexBuffer.ColorKind:var d=l.getSize();for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=d)h=p*c,4===d?(f.push(o.Vector4.FromArray(a,h)),f.push(o.Vector4.FromArray(a,h+2*c)),f.push(o.Vector4.FromArray(a,h+c))):(f.push(o.Vector3.FromArray(a,h)),f.push(o.Vector3.FromArray(a,h+2*c)),f.push(o.Vector3.FromArray(a,h+c)));break;case o.VertexBuffer.UVKind:case o.VertexBuffer.UV2Kind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*c,f.push(o.Vector2.FromArray(a,h)),f.push(o.Vector2.FromArray(a,h+2*c)),f.push(o.Vector2.FromArray(a,h+c));break;default:o.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(f,i,n,a,s,u)}}else o.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+n+" not present!")},e.prototype.reorderTriangleStripDrawMode=function(e,t,r,n,a,i,s,u){var l=this.getVertexBufferFromMesh(n,e.getMesh());if(l){var c=l.byteStride/o.VertexBuffer.GetTypeByteLength(l.type),f=[],h=0;switch(n){case o.VertexBuffer.PositionKind:case o.VertexBuffer.NormalKind:h=e.verticesStart,f.push(o.Vector3.FromArray(a,h+2*c)),f.push(o.Vector3.FromArray(a,h+c));break;case o.VertexBuffer.TangentKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(o.Vector4.FromArray(a,h));break;case o.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,4===l.getSize()?f.push(o.Vector4.FromArray(a,h)):f.push(o.Vector3.FromArray(a,h));break;case o.VertexBuffer.UVKind:case o.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(o.Vector2.FromArray(a,h));break;default:o.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(f,i+12,n,a,s,u)}else o.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+n+" not present!")},e.prototype.reorderTriangleFanMode=function(e,t,r,n,a,i,s,u){var l=this.getVertexBufferFromMesh(n,e.getMesh());if(l){var c=l.byteStride/o.VertexBuffer.GetTypeByteLength(l.type),f=[],h=0;switch(n){case o.VertexBuffer.PositionKind:case o.VertexBuffer.NormalKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(o.Vector3.FromArray(a,h));break;case o.VertexBuffer.TangentKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(o.Vector4.FromArray(a,h));break;case o.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(o.Vector4.FromArray(a,h)),4===l.getSize()?f.push(o.Vector4.FromArray(a,h)):f.push(o.Vector3.FromArray(a,h));break;case o.VertexBuffer.UVKind:case o.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(o.Vector2.FromArray(a,h));break;default:o.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(f,i,n,a,s,u)}else o.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+n+" not present!")},e.prototype.writeVertexAttributeData=function(e,t,r,n,a,s){for(var u=0,l=e;u<l.length;u++){var c=l[u];!s||r===o.VertexBuffer.ColorKind||c instanceof o.Vector2||(c instanceof o.Vector3?r===o.VertexBuffer.NormalKind?i.a._GetRightHandedNormalVector3FromRef(c):r===o.VertexBuffer.PositionKind?i.a._GetRightHandedPositionVector3FromRef(c):o.Tools.Error("Unsupported vertex attribute kind!"):i.a._GetRightHandedVector4FromRef(c)),r===o.VertexBuffer.NormalKind?c.normalize():r===o.VertexBuffer.TangentKind&&c instanceof o.Vector4&&i.a._NormalizeTangentFromRef(c);for(var f=0,h=c.asArray();f<h.length;f++){var p=h[f];a.setFloat32(p,t),t+=4}}},e.prototype.writeAttributeData=function(e,t,r,n,a,s,u){var l,c,f=[];switch(e){case o.VertexBuffer.PositionKind:for(var h=0,p=r.length/n;h<p;++h){l=h*n;var d=o.Vector3.FromArray(r,l);s&&i.a._GetRightHandedPositionVector3FromRef(d),f.push(d.asArray())}break;case o.VertexBuffer.NormalKind:h=0;for(var m=r.length/n;h<m;++h){l=h*n;d=o.Vector3.FromArray(r,l);s&&i.a._GetRightHandedNormalVector3FromRef(d),d.normalize(),f.push(d.asArray())}break;case o.VertexBuffer.TangentKind:h=0;for(var g=r.length/n;h<g;++h){l=h*n;d=o.Vector4.FromArray(r,l);s&&i.a._GetRightHandedVector4FromRef(d),i.a._NormalizeTangentFromRef(d),f.push(d.asArray())}break;case o.VertexBuffer.ColorKind:for(var _=u.material,x=!_||_ instanceof o.StandardMaterial,y=(d=3===n?new o.Color3:new o.Color4,h=0,r.length/n);h<y;++h)l=h*n,3===n?(o.Color3.FromArrayToRef(r,l,d),x&&d.toLinearSpaceToRef(d)):(o.Color4.FromArrayToRef(r,l,d),x&&d.toLinearSpaceToRef(d)),f.push(d.asArray());break;case o.VertexBuffer.UVKind:case o.VertexBuffer.UV2Kind:h=0;for(var T=r.length/n;h<T;++h)l=h*n,f.push([r[l],r[l+1]]);break;case o.VertexBuffer.MatricesIndicesKind:case o.VertexBuffer.MatricesIndicesExtraKind:h=0;for(var v=r.length/n;h<v;++h){l=h*n;d=o.Vector4.FromArray(r,l);f.push(d.asArray())}break;case o.VertexBuffer.MatricesWeightsKind:case o.VertexBuffer.MatricesWeightsExtraKind:h=0;for(var b=r.length/n;h<b;++h){l=h*n;d=o.Vector4.FromArray(r,l);f.push(d.asArray())}break;default:o.Tools.Warn("Unsupported Vertex Buffer Type: "+e),f=[]}switch(t){case 5121:c=a.setUInt8.bind(a);break;case 5123:c=a.setUInt16.bind(a);break;case 5125:c=a.setUInt32.bind(a);case 5126:c=a.setFloat32.bind(a);break;default:return void o.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,F=f;A<F.length;A++)for(var M=0,E=F[A];M<E.length;M++){c(E[M])}},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,a,s,u,l,c,f){var h,p,d=[],m=new o.Vector3,g=new o.Vector4(0,0,0,0);switch(e){case o.VertexBuffer.PositionKind:for(var _=r.verticesStart;_<r.verticesCount;++_){h=r.indexStart+_*u;var x=o.Vector3.FromArray(a,h);m=(y=o.Vector3.FromArray(s,h)).subtractToRef(x,m),c&&i.a._GetRightHandedPositionVector3FromRef(m),f&&(f.min.copyFromFloats(Math.min(m.x,f.min.x),Math.min(m.y,f.min.y),Math.min(m.z,f.min.z)),f.max.copyFromFloats(Math.max(m.x,f.max.x),Math.max(m.y,f.max.y),Math.max(m.z,f.max.z))),d.push(m.asArray())}break;case o.VertexBuffer.NormalKind:for(_=r.verticesStart;_<r.verticesCount;++_){h=r.indexStart+_*u,(x=o.Vector3.FromArray(a,h)).normalize(),(y=o.Vector3.FromArray(s,h)).normalize(),m=y.subtractToRef(x,m),c&&i.a._GetRightHandedNormalVector3FromRef(m),d.push(m.asArray())}break;case o.VertexBuffer.TangentKind:for(_=r.verticesStart;_<r.verticesCount;++_){h=r.indexStart+_*(u+1);x=o.Vector4.FromArray(a,h);i.a._NormalizeTangentFromRef(x);var y=o.Vector4.FromArray(s,h);i.a._NormalizeTangentFromRef(y),g=y.subtractToRef(x,g),c&&i.a._GetRightHandedVector4FromRef(g),d.push([g.x,g.y,g.z])}break;default:o.Tools.Warn("Unsupported Vertex Buffer Type: "+e),d=[]}switch(t){case 5121:p=l.setUInt8.bind(l);break;case 5123:p=l.setUInt16.bind(l);break;case 5125:p=l.setUInt32.bind(l);case 5126:p=l.setFloat32.bind(l);break;default:return void o.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var T=0,v=d;T<v.length;T++)for(var b=0,A=v[T];b<A.length;b++){p(A[b])}},e.prototype.generateJSON=function(e,t,r){var n,o,a,s=this,u={byteLength:this._totalByteLength},l=this._totalByteLength;return u.byteLength&&(this._glTF.buffers=[u]),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._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(e?(this._glTF.images=[],this._images.forEach((function(e){e.uri&&(o=s._imageData[e.uri],s._orderedImageData.push(o),n=e.uri.split(".")[0]+" image",a=i.a._CreateBufferView(0,l,o.data.length,void 0,n),l+=o.data.buffer.byteLength,s._bufferViews.push(a),e.bufferView=s._bufferViews.length-1,e.name=n,e.mimeType=o.mimeType,e.uri=void 0,s._glTF.images||(s._glTF.images=[]),s._glTF.images.push(e))})),u.byteLength=l):this._glTF.images=this._images),e||(u.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype._generateGLTFAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then((function(n){r._extensionsOnExporting();var o=r.generateJSON(!1,e,!0),a=new Blob([n],{type:"application/octet-stream"}),i=e+".gltf",u=e+".bin",l=new s.GLTFData;if(l.glTFFiles[i]=o,l.glTFFiles[u]=a,r._imageData)for(var c in r._imageData)l.glTFFiles[c]=new Blob([r._imageData[c].data],{type:r._imageData[c].mimeType});return t&&r.dispose(),l}))},e.prototype._generateBinaryAsync=function(){var e=this,t=new c(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();for(var o=r.generateJSON(!0),a=e+".glb",i=o.length,u=0,l=0;l<r._orderedImageData.length;++l)u+=r._orderedImageData[l].data.byteLength;var c=r._getPadding(i),f=r._getPadding(n.byteLength),h=r._getPadding(u),p=28+i+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 g=new ArrayBuffer(8+i+c),_=new DataView(g);_.setUint32(0,i+c,!0),_.setUint32(4,1313821514,!0);var x=new Uint8Array(g,8);for(l=0;l<i;++l)x[l]=o.charCodeAt(l);var y=new Uint8Array(g,8+i);for(l=0;l<c;++l)y[l]=32;var T=new ArrayBuffer(8),v=new DataView(T);v.setUint32(0,n.byteLength+u+h,!0),v.setUint32(4,5130562,!0);var b=new ArrayBuffer(f),A=new Uint8Array(b);for(l=0;l<f;++l)A[l]=0;var F=new ArrayBuffer(h),M=new Uint8Array(F);for(l=0;l<h;++l)M[l]=0;var E=[d,g,T,n];for(l=0;l<r._orderedImageData.length;++l)E.push(r._orderedImageData[l].data.buffer);E.push(b),E.push(F);var R=new Blob(E,{type:"application/octet-stream"}),V=new s.GLTFData;return V.glTFFiles[a]=R,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),V}))},e.prototype.setNodeTransformation=function(e,t,r){t.getPivotPoint().equalsToFloats(0,0,0)||o.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=r?i.a._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var n=o.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&n.multiplyInPlace(t.rotationQuaternion),0===n.x&&0===n.y&&0===n.z&&1===n.w||(r&&i.a._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,s){var u=r instanceof o.Mesh?r:r instanceof o.InstancedMesh?r.sourceMesh:null;if(u){var l=u.getVertexBuffer(e),c=u.getVerticesData(e);if(l&&c){var f=o.VertexBuffer.GetTypeByteLength(t),h=c.length*f,p=i.a._CreateBufferView(0,n.getByteOffset(),h,a,e+" - "+u.name);this._bufferViews.push(p),this.writeAttributeData(e,t,c,a/f,n,s,r)}}},e.prototype.setMorphTargetAttributes=function(e,t,r,n,a){if(r){t.targets||(t.targets=[]);var s={};if(r.hasNormals){var u=e.getMesh().getVerticesData(o.VertexBuffer.NormalKind),l=r.getNormals(),c=(_=e.verticesCount)*(x=12),f=i.a._CreateBufferView(0,n.getByteOffset(),c,x,r.name+"_NORMAL");this._bufferViews.push(f);var h=this._bufferViews.length-1,p=i.a._CreateAccessor(h,r.name+" - NORMAL","VEC3",5126,_,0,null,null);this._accessors.push(p),s.NORMAL=this._accessors.length-1,this.writeMorphTargetAttributeData(o.VertexBuffer.NormalKind,5126,e,r,u,l,x/4,n,a)}if(r.hasPositions){var d=e.getMesh().getVerticesData(o.VertexBuffer.PositionKind),m=r.getPositions();c=(_=e.verticesCount)*(x=12),f=i.a._CreateBufferView(0,n.getByteOffset(),c,x,r.name+"_POSITION");this._bufferViews.push(f);h=this._bufferViews.length-1;var g={min:new o.Vector3(1/0,1/0,1/0),max:new o.Vector3(-1/0,-1/0,-1/0)};p=i.a._CreateAccessor(h,r.name+" - POSITION","VEC3",5126,_,0,null,null);this._accessors.push(p),s.POSITION=this._accessors.length-1,this.writeMorphTargetAttributeData(o.VertexBuffer.PositionKind,5126,e,r,d,m,x/4,n,a,g),p.min=g.min.asArray(),p.max=g.max.asArray()}if(r.hasTangents){var _,x,y=e.getMesh().getVerticesData(o.VertexBuffer.TangentKind),T=r.getTangents();c=(_=e.verticesCount)*(x=12),f=i.a._CreateBufferView(0,n.getByteOffset(),c,x,r.name+"_NORMAL");this._bufferViews.push(f);h=this._bufferViews.length-1,p=i.a._CreateAccessor(h,r.name+" - TANGENT","VEC3",5126,_,0,null,null);this._accessors.push(p),s.TANGENT=this._accessors.length-1,this.writeMorphTargetAttributeData(o.VertexBuffer.TangentKind,5126,e,r,y,T,x/4,n,a)}t.targets.push(s)}},e.prototype.getMeshPrimitiveMode=function(e){return e instanceof o.LinesMesh?o.Material.LineListDrawMode:e.material?e.material.fillMode:o.Material.TriangleFillMode},e.prototype.setPrimitiveMode=function(e,t){switch(t){case o.Material.TriangleFillMode:break;case o.Material.TriangleStripDrawMode:e.mode=5;break;case o.Material.TriangleFanDrawMode:e.mode=6;break;case o.Material.PointListDrawMode:e.mode=0;case o.Material.PointFillMode:e.mode=0;break;case o.Material.LineLoopDrawMode:e.mode=2;break;case o.Material.LineListDrawMode:e.mode=1;break;case o.Material.LineStripDrawMode:e.mode=3}},e.prototype.setAttributeKind=function(e,t){switch(t){case o.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case o.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case o.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case o.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case o.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case o.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;case o.VertexBuffer.MatricesIndicesKind:e.attributes.JOINTS_0=this._accessors.length-1;break;case o.VertexBuffer.MatricesIndicesExtraKind:e.attributes.JOINTS_1=this._accessors.length-1;break;case o.VertexBuffer.MatricesWeightsKind:e.attributes.WEIGHTS_0=this._accessors.length-1;break;case o.VertexBuffer.MatricesWeightsExtraKind:e.attributes.WEIGHTS_1=this._accessors.length-1;break;default:o.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},e.prototype.setPrimitiveAttributesAsync=function(e,t,r,n){var a,s,u,l=[],c=null;t instanceof o.Mesh?c=t:t instanceof o.InstancedMesh&&(c=t.sourceMesh);var f=[{kind:o.VertexBuffer.PositionKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:o.VertexBuffer.NormalKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:o.VertexBuffer.ColorKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:o.VertexBuffer.TangentKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:o.VertexBuffer.UVKind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:o.VertexBuffer.UV2Kind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:o.VertexBuffer.MatricesIndicesKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:o.VertexBuffer.MatricesIndicesExtraKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:o.VertexBuffer.MatricesWeightsKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:o.VertexBuffer.MatricesWeightsExtraKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16}];if(c){for(var h=null,p=this.getMeshPrimitiveMode(c),d={},m=c.morphTargetManager,g=0,_=f;g<_.length;g++){var x=(W=_[g]).kind,y=W.accessorComponentType;if(c.isVerticesDataPresent(x)){var T=this.getVertexBufferFromMesh(x,c);W.byteStride=T?T.getSize()*o.VertexBuffer.GetTypeByteLength(W.accessorComponentType):4*o.VertexBuffer.DeduceStride(x),12===W.byteStride&&(W.accessorType="VEC3"),this.createBufferViewKind(x,y,t,r,W.byteStride,n),W.bufferViewIndex=this._bufferViews.length-1,d[x]=W.bufferViewIndex}}if(c.getTotalIndices()){var v=c.getIndices();if(v){var b=4*v.length;s=i.a._CreateBufferView(0,r.getByteOffset(),b,void 0,"Indices - "+c.name),this._bufferViews.push(s),h=this._bufferViews.length-1;for(var A=0,F=v.length;A<F;++A)r.setUInt32(v[A])}}if(c.subMeshes)for(var M=0,E=c.subMeshes;M<E.length;M++){var R=E[M],V=R.getMaterial()||c.getScene().defaultMaterial,w=null;if(V)if(c instanceof o.LinesMesh){var S={name:c.name+" material"};(!c.color.equals(o.Color3.White())||c.alpha<1)&&(S.pbrMetallicRoughness={baseColorFactor:c.color.asArray().concat([c.alpha])}),this._materials.push(S),w=this._materials.length-1}else if(V instanceof o.MultiMaterial){var C=V.subMaterials[R.materialIndex];C&&(V=C,w=this._materialMap[V.uniqueId])}else w=this._materialMap[V.uniqueId];var B=null!=w?this._materials[w]:null,I={attributes:{}};this.setPrimitiveMode(I,p);for(var P=0,L=f;P<L.length;P++){if((x=(W=L[P]).kind)!==o.VertexBuffer.UVKind&&x!==o.VertexBuffer.UV2Kind||!B||this._glTFMaterialExporter._hasTexturesPresent(B))if(z=c.getVerticesData(x))if(T=this.getVertexBufferFromMesh(x,c)){var N=T.getSize(),O=W.bufferViewIndex;if(null!=O){u={min:null,max:null},x==o.VertexBuffer.PositionKind&&(u=i.a._CalculateMinMaxPositions(z,0,z.length/N,n));var G=i.a._CreateAccessor(O,x+" - "+t.name,W.accessorType,W.accessorComponentType,z.length/N,0,u.min,u.max);this._accessors.push(G),this.setAttributeKind(I,x)}}}if(h){G=i.a._CreateAccessor(h,"indices - "+t.name,"SCALAR",5125,R.indexCount,4*R.indexStart,null,null);this._accessors.push(G),I.indices=this._accessors.length-1}if(null!=w&&Object.keys(I.attributes).length>0){var k=null!==c.overrideMaterialSideOrientation?c.overrideMaterialSideOrientation:V.sideOrientation;if(k==o.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||k==o.Material.ClockWiseSideOrientation&&n&&c.overrideMaterialSideOrientation!==(null===(a=c.material)||void 0===a?void 0:a.sideOrientation)){var K=null!=h?this._bufferViews[h].byteOffset:null;null==K&&(K=0);var D=null;if(null!=h&&(D=c.getIndices()),D)this.reorderIndicesBasedOnPrimitiveMode(R,p,D,K,r);else for(var U=0,H=f;U<H.length;U++){var z,W=H[U];if(z=c.getVerticesData(W.kind)){var q=this._bufferViews[d[W.kind]].byteOffset;q||(q=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(R,p,k,W.kind,z,q,r,n)}}}I.material=w}if(m)for(var j=void 0,Q=0;Q<m.numTargets;++Q)j=m.getTarget(Q),this.setMorphTargetAttributes(R,I,j,r,n);e.primitives.push(I),this._extensionsPostExportMeshPrimitiveAsync("postExport",I,R,r)&&l.push()}}return Promise.all(l).then((function(){}))},e.prototype.isBabylonCoordinateSystemConvertingNode=function(e){if(e instanceof o.TransformNode){if("__root__"!==e.name)return!1;for(var t=e.getWorldMatrix(),r=o.Matrix.Compose(this._convertToRightHandedSystem?new o.Vector3(-1,1,1):o.Vector3.One(),o.Quaternion.Identity(),o.Vector3.Zero()),n=t.multiply(r),a=o.Matrix.IdentityReadOnly,i=0;i<16;i++)if(Math.abs(n.m[i]-a.m[i])>o.Epsilon)return!1;return!(e instanceof o.Mesh&&null!==e.geometry||e instanceof o.InstancedMesh&&null!==e.sourceMesh.geometry)&&!this._includeCoordinateSystemConversionNodes}return!1},e.prototype.createSceneAsync=function(e,t){var r,a,i,s=this,u={nodes:[]},l=Object(n.c)(e.transformNodes,e.meshes,e.lights),c=[];return this._convertToRightHandedSystem=!e.useRightHandedSystem,this._convertToRightHandedSystemMap={},e.rootNodes.forEach((function(e){s._convertToRightHandedSystemMap[e.uniqueId]=s._convertToRightHandedSystem,e.getDescendants(!1).forEach((function(e){s._convertToRightHandedSystemMap[e.uniqueId]=s._convertToRightHandedSystem}))})),e.rootNodes.forEach((function(e){if(s.isBabylonCoordinateSystemConvertingNode(e)){c.push(e);var t=l.indexOf(e);-1!==t&&l.splice(t,1),e.getDescendants(!1).forEach((function(e){s._convertToRightHandedSystemMap[e.uniqueId]=!1}))}})),this._glTFMaterialExporter._convertMaterialsToGLTFAsync(e.materials,"image/png",!0).then((function(){return s.createNodeMapAndAnimationsAsync(e,l,t).then((function(n){return s.createSkinsAsync(e,n,t).then((function(e){if(s._nodeMap=n,s._totalByteLength=t.getByteOffset(),null==s._totalByteLength)throw new Error("undefined byte length!");for(var f=0,h=l;f<h.length;f++){var p=h[f];if(void 0!==(r=s._nodeMap[p.uniqueId])){if(a=s._nodes[r],p.metadata&&(s._options.metadataSelector?a.extras=s._options.metadataSelector(p.metadata):p.metadata.gltf&&(a.extras=p.metadata.gltf.extras)),!p.parent||-1!==c.indexOf(p.parent))if(s._options.shouldExportNode&&!s._options.shouldExportNode(p))o.Tools.Log("Omitting "+p.name+" from scene.");else s._convertToRightHandedSystemMap[p.uniqueId]&&(a.translation&&(a.translation[2]*=-1,a.translation[0]*=-1),a.rotation=a.rotation?o.Quaternion.FromArray([0,1,0,0]).multiply(o.Quaternion.FromArray(a.rotation)).asArray():o.Quaternion.FromArray([0,1,0,0]).asArray()),u.nodes.push(r);if(p instanceof o.Mesh){var d=p;d.skeleton&&(a.skin=e[d.skeleton.uniqueId])}if(i=p.getDescendants(!0),!a.children&&i&&i.length){for(var m=[],g=0,_=i;g<_.length;g++){var x=_[g];null!=s._nodeMap[x.uniqueId]&&m.push(s._nodeMap[x.uniqueId])}m.length&&(a.children=m)}}}u.nodes.length&&s._scenes.push(u)}))}))}))},e.prototype.createNodeMapAndAnimationsAsync=function(e,t,r){for(var n,a=this,i=Promise.resolve(),s={},l={name:"runtime animations",channels:[],samplers:[]},c=[],f=function(t){!h._options.shouldExportNode||h._options.shouldExportNode(t)?i=i.then((function(){var i=a._convertToRightHandedSystemMap[t.uniqueId];return a.createNodeAsync(t,r,i,s).then((function(f){var h=a._extensionsPostExportNodeAsync("createNodeAsync",f,t,s);return null==h?(o.Tools.Warn("Not exporting node "+t.name),Promise.resolve()):h.then((function(o){o&&(a._nodes.push(o),n=a._nodes.length-1,s[t.uniqueId]=n,e.animationGroups.length||(u.a._CreateMorphTargetAnimationFromMorphTargetAnimations(t,l,c,s,a._nodes,r,a._bufferViews,a._accessors,i,a._animationSampleRate),t.animations.length&&u.a._CreateNodeAnimationFromNodeAnimations(t,l,c,s,a._nodes,r,a._bufferViews,a._accessors,i,a._animationSampleRate)))}))}))})):t.name},h=this,p=0,d=t;p<d.length;p++){f(d[p])}return i.then((function(){return l.channels.length&&l.samplers.length&&a._animations.push(l),c.forEach((function(e){e.channels.length&&e.samplers.length&&a._animations.push(e)})),e.animationGroups.length&&u.a._CreateNodeAndMorphAnimationFromAnimationGroups(e,a._animations,s,a._nodes,r,a._bufferViews,a._accessors,a._convertToRightHandedSystemMap,a._animationSampleRate),s}))},e.prototype.createNodeAsync=function(e,t,r,n){var a=this;return Promise.resolve().then((function(){var n={},i={primitives:[]};if(e.name&&(n.name=e.name),e instanceof o.TransformNode){if(a.setNodeTransformation(n,e,r),e instanceof o.Mesh){var s=e.morphTargetManager;if(s&&s.numTargets>0){i.weights=[];for(var u=0;u<s.numTargets;++u)i.weights.push(s.getTarget(u).influence)}}return a.setPrimitiveAttributesAsync(i,e,t,r).then((function(){return i.primitives.length&&(a._meshes.push(i),n.mesh=a._meshes.length-1),n}))}return n}))},e.prototype.createSkinsAsync=function(e,t,r){for(var n=Promise.resolve(),o={},a=function(n){var a={joints:[]},u=[],l=e.meshes.find((function(e){e.skeleton}));a.skeleton=null===n.overrideMesh?l?t[l.uniqueId]:void 0:t[n.overrideMesh.uniqueId];for(var c={},f=-1,h=-1,p=0,d=n.bones;p<d.length;p++){(h=(g=d[p]).getIndex())>-1&&(c[h]=g),f=Math.max(f,h)}for(var m=0;m<=f;++m){var g,_=(g=c[m]).getTransformNode();if(_){var x=g.getInvertedAbsoluteTransform();s._convertToRightHandedSystem&&i.a._GetRightHandedMatrixFromRef(x),u.push(x),a.joints.push(t[_.uniqueId])}}var y=64*u.length,T=r.getByteOffset(),v=i.a._CreateBufferView(0,T,y,64,"InverseBindMatrices - "+n.name);s._bufferViews.push(v);var b=s._bufferViews.length-1,A=i.a._CreateAccessor(b,"InverseBindMatrices - "+n.name,"MAT4",5126,u.length,null,null,null),F=s._accessors.push(A)-1;a.inverseBindMatrices=F,s._skins.push(a),o[n.uniqueId]=s._skins.length-1,u.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))},s=this,u=0,l=e.skeletons;u<l.length;u++){a(l[u])}return n.then((function(){return o}))},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),c=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),o=0,a=n.byteLength;o<a;++o)n[o]=r[o];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):o.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):o.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 o.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?o.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?o.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?o.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?o.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)&&o.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):o.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):o.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.d(t,"a",(function(){return n})),r.d(t,"b",(function(){return o})),r.d(t,"c",(function(){return a}));function n(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function s(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(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 o(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}Object.create;function a(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var a=arguments[t],i=0,s=a.length;i<s;i++,o++)n[o]=a[i];return n}Object.create},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],o=void 0;e(t,".glb")?o={type:"model/gltf-binary"}:e(t,".bin")?o={type:"application/octet-stream"}:e(t,".gltf")?o={type:"model/gltf+json"}:e(t,".jpeg")?o={type:"image/jpeg"}:e(t,".png")&&(o={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],o)),r.click()}},e}()},function(e,t,r){"use strict";r.r(t),r.d(t,"__IGLTFExporterExtension",(function(){return n}));var n=0},function(e,t,r){"use strict";r.r(t),r.d(t,"OBJExport",(function(){return o}));var n=r(0),o=function(){function e(){}return e.OBJ=function(e,t,r,o){var a=[],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(o){var l=n.Matrix.Translation(e[s].position.x,e[s].position.y,e[s].position.z);u=n.Matrix.Translation(-e[s].position.x,-e[s].position.y,-e[s].position.z),e[s].bakeTransformIntoVertices(l)}if(t){var c=e[s].material;c&&a.push("usemtl "+c.id)}var f=e[s].geometry;if(f){var h=f.getVerticesData("position"),p=f.getVerticesData("normal"),d=f.getVerticesData("uv"),m=f.getIndices(),g=0;if(h&&m){for(var _=0;_<h.length;_+=3)e[0].getScene().useRightHandedSystem?a.push("v "+h[_]+" "+h[_+1]+" "+h[_+2]):a.push("v "+h[_]+" "+h[_+1]+" "+-h[_+2]),g++;if(null!=p)for(_=0;_<p.length;_+=3)a.push("vn "+p[_]+" "+p[_+1]+" "+p[_+2]);if(null!=d)for(_=0;_<d.length;_+=2)a.push("vt "+d[_]+" "+d[_+1]);for(_=0;_<m.length;_+=3){var x=[String(m[_+2]+i),String(m[_+1]+i),String(m[_]+i)],y=["","",""],T=x,v=null!=d?x:y,b=null!=p?x:y;a.push("f "+T[0]+"/"+v[0]+"/"+b[0]+" "+T[1]+"/"+v[1]+"/"+b[1]+" "+T[2]+"/"+v[2]+"/"+b[2])}o&&u&&e[s].bakeTransformIntoVertices(u),i+=g}else n.Tools.Warn("There are no position vertices or indices on the mesh!")}else n.Tools.Warn("No geometry is present on the mesh")}return a.join("\n")},e.MTL=function(e){var t=[],r=e.material;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));return 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}()},function(e,t,r){"use strict";r.r(t),r.d(t,"_GLTFAnimation",(function(){return n.a})),r.d(t,"GLTFData",(function(){return o.GLTFData})),r.d(t,"_Exporter",(function(){return a.b})),r.d(t,"_BinaryWriter",(function(){return a.a})),r.d(t,"__IGLTFExporterExtensionV2",(function(){return i})),r.d(t,"_GLTFMaterialExporter",(function(){return s.a})),r.d(t,"GLTF2Export",(function(){return u.GLTF2Export})),r.d(t,"_GLTFUtilities",(function(){return l.a})),r.d(t,"KHR_texture_transform",(function(){return c.KHR_texture_transform})),r.d(t,"KHR_lights_punctual",(function(){return c.KHR_lights_punctual})),r.d(t,"KHR_materials_sheen",(function(){return c.KHR_materials_sheen})),r.d(t,"KHR_materials_unlit",(function(){return c.KHR_materials_unlit}));var n=r(8),o=r(4),a=r(2),i=0,s=r(11),u=r(9),l=r(1),c=r(10)},function(e,t,r){"use strict";r.d(t,"a",(function(){return i}));var n,o=r(0),a=r(1);!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(n||(n={}));var i=function(){function e(){}return e._CreateNodeAnimation=function(t,r,n,a,i,s){var u=[],l=[],c=r.getKeys(),f=e.calculateMinMaxKeyFrames(c),h=e._DeduceInterpolation(c,n,i),p=f.max-f.min,d=h.interpolationType,m=h.shouldBakeAnimation;return m?e._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,u,l,f,a,i):"LINEAR"===d||"STEP"===d?e._CreateLinearOrStepAnimation(t,r,n,p,u,l,a,i):"CUBICSPLINE"===d?e._CreateCubicSplineAnimation(t,r,n,p,u,l,a,i):e._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,u,l,f,a,i),u.length&&l.length?{inputs:u,outputs:l,samplerInterpolation:d,inputsMin:m?f.min:o.Tools.FloatRound(f.min/r.framePerSecond),inputsMax:m?f.max:o.Tools.FloatRound(f.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:o.Tools.Error("Unsupported animatable property "+a[0])}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(o.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,a,i,s,u,l,c,f){var h;if(t instanceof o.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(""+m.name,m.hasRunningRuntimeAnimations?r:h,t,m,g.dataAccessorType,g.animationChannelTargetPath,a,s,u,l,c,g.useQuaternion,f),h.samplers.length&&h.channels.length&&n.push(h))}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,a,i,s,u,l,c,f){var h;if(t instanceof o.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 o.Animation(""+_.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,s,u,l,c,F.useQuaternion,f,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,a,i,s,u,l,c){var f,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 o.TransformNode||1===_.length&&_[0]instanceof o.TransformNode){if(v=e._DeduceAnimationInfo(g.animation)){var y=_ instanceof o.TransformNode?_:_[0],T=l[y.uniqueId];e.AddAnimation(""+x.name,h,y,x,v.dataAccessorType,v.animationChannelTargetPath,n,i,s,u,T,v.useQuaternion,c)}}else if(_ instanceof o.MorphTarget||1===_.length&&_[0]instanceof o.MorphTarget){var v;if(v=e._DeduceAnimationInfo(g.animation)){var b=_ instanceof o.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===(f=p.get(F))||void 0===f||f.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,l=null,f=[],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?(l||(l=new o.Animation(a.name+"_"+t.name+"_MorphWeightAnimation","influence",b.framePerSecond,o.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),f.push(b.getKeys()[x])):f.push({frame:a.from+g/_*x,value:T.influence,inTangent:m[0].inTangent?0:void 0,outTangent:m[0].outTangent?0:void 0})}}l.setKeys(f);var A=e._DeduceAnimationInfo(l);A&&e.AddAnimation(a.name+"_"+t.name+"_MorphWeightAnimation",h,t,l,A.dataAccessorType,A.animationChannelTargetPath,n,i,s,u,!1,A.useQuaternion,c,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,o,i,s,u,l,c,f,h,p,d,m){var g,_,x,y,T,v,b,A=e._CreateNodeAnimation(n,o,s,h,p,d);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=u[n.uniqueId],V=4*A.inputs.length;g=a.a._CreateBufferView(0,l.getByteOffset(),V,void 0,t+" keyframe data view"),c.push(g),A.inputs.forEach((function(e){l.setFloat32(e)})),_=a.a._CreateAccessor(c.length-1,t+" keyframes","SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),f.push(_),x=f.length-1,T=A.outputs.length,V=4*a.a._GetDataAccessorElementCount(i)*A.outputs.length,g=a.a._CreateBufferView(0,l.getByteOffset(),V,void 0,t+" data view"),c.push(g),A.outputs.forEach((function(e){e.forEach((function(e){l.setFloat32(e)}))})),_=a.a._CreateAccessor(c.length-1,t+" data",i,5126,T,null,null,null),f.push(_),y=f.length-1,v={interpolation:A.samplerInterpolation,input:x,output:y},r.samplers.push(v),b={sampler:r.samplers.length-1,target:{node:R,path:s}},r.channels.push(b)}},e._CreateBakedAnimation=function(t,r,n,a,i,s,u,l,c,f,h,p){var d,m,g=o.Quaternion.Identity(),_=null,x=null,y=null,T=null,v=null,b=null;f.min=o.Tools.FloatRound(a/s);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=i}if(b)for(var E=y.frame;E<=b;E+=u)if((m=o.Tools.FloatRound(E/s))!==_){_=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,l,c,h,p)}}x&&(f.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,a,i,s,u){var l,c,f=null,h=e._GetBasePositionRotationOrScale(r,i,s,u);if(a===o.Animation.ANIMATIONTYPE_FLOAT)switch(c=(l=n.targetProperty.split("."))?l[1]:"",f=u?o.Quaternion.FromArray(h).normalize():o.Vector3.FromArray(h),c){case"x":case"y":f[c]=s&&u&&"scale"!==i?-t:t;break;case"z":f[c]=s&&!u&&"scale"!==i?-t:t;break;case"w":f.w=t;break;default:o.Tools.Error('glTFAnimation: Unsupported component type "'+c+'" for scale animation!')}return f},e._SetInterpolatedValue=function(e,t,r,n,i,s,u,l,c,f){var h,p=n.dataType;u.push(r),"number"==typeof t&&e instanceof o.TransformNode&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,p,i,c,f)),t&&("rotation"===i?(f?s=t:(h=t,o.Quaternion.RotationYawPitchRollToRef(h.y,h.x,h.z,s)),c&&(a.a._GetRightHandedQuaternionFromRef(s),e.parent||(s=o.Quaternion.FromArray([0,1,0,0]).multiply(s))),l.push(s.asArray())):"weights"===i?l.push([t]):(h=t,c&&"scale"!==i&&(a.a._GetRightHandedPositionVector3FromRef(h),e.parent||(h.x*=-1,h.z*=-1)),l.push(h.asArray())))},e._CreateLinearOrStepAnimation=function(t,r,n,o,a,i,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];a.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,i,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,o,a,i,s,u,l){r.getKeys().forEach((function(c){i.push(c.frame/r.framePerSecond),e.AddSplineTangent(t,n.INTANGENT,s,o,"CUBICSPLINE",c,a,l,u),e._AddKeyframeValue(c,r,s,o,t,u,l),e.AddSplineTangent(t,n.OUTTANGENT,s,o,"CUBICSPLINE",c,a,l,u)}))},e._GetBasePositionRotationOrScale=function(e,t,r,n){var i;return"rotation"===t?n?e.rotationQuaternion?(i=e.rotationQuaternion.asArray(),r&&(a.a._GetRightHandedQuaternionArrayFromRef(i),e.parent||(i=o.Quaternion.FromArray([0,1,0,0]).multiply(o.Quaternion.FromArray(i)).asArray()))):i=o.Quaternion.Identity().asArray():(i=e.rotation.asArray(),a.a._GetRightHandedNormalArray3FromRef(i)):"translation"===t?(i=e.position.asArray(),r&&a.a._GetRightHandedPositionArray3FromRef(i)):i=e.scaling.asArray(),i},e._AddKeyframeValue=function(e,t,r,n,i,s,u){var l,c,f=t.dataType;if(f===o.Animation.ANIMATIONTYPE_VECTOR3){if(l=e.value.asArray(),"rotation"===n){var h=o.Vector3.FromArray(l),p=o.Quaternion.RotationYawPitchRoll(h.y,h.x,h.z);s&&(a.a._GetRightHandedQuaternionFromRef(p),i.parent||(p=o.Quaternion.FromArray([0,1,0,0]).multiply(p))),l=p.asArray()}else"translation"===n&&s&&(a.a._GetRightHandedNormalArray3FromRef(l),i.parent||(l[0]*=-1,l[2]*=-1));r.push(l)}else if(f===o.Animation.ANIMATIONTYPE_FLOAT){if("weights"===n)r.push([e.value]);else if(c=this._ConvertFactorToVector3OrQuaternion(e.value,i,t,f,n,s,u)){if("rotation"===n){var d=u?c:o.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).normalize();s&&(a.a._GetRightHandedQuaternionFromRef(d),i.parent||(d=o.Quaternion.FromArray([0,1,0,0]).multiply(d))),r.push(d.asArray())}else"translation"===n&&s&&(a.a._GetRightHandedNormalVector3FromRef(c),i.parent||(c.x*=-1,c.z*=-1));r.push(c.asArray())}}else f===o.Animation.ANIMATIONTYPE_QUATERNION?(l=e.value.normalize().asArray(),s&&(a.a._GetRightHandedQuaternionArrayFromRef(l),i.parent||(l=o.Quaternion.FromArray([0,1,0,0]).multiply(o.Quaternion.FromArray(l)).asArray())),r.push(l)):o.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,a,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,u=e.length;s<u;++s)if((a=e[s]).inTangent||a.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||a.interpolation&&a.interpolation===o.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=a.interpolation&&a.interpolation===o.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:i}},e.AddSplineTangent=function(e,t,r,i,s,u,l,c,f){var h,p=t===n.INTANGENT?u.inTangent:u.outTangent;if("CUBICSPLINE"===s){if("rotation"===i)if(p){if(c)h=p.asArray();else{var d=p;h=o.Quaternion.RotationYawPitchRoll(d.y,d.x,d.z).asArray()}f&&(a.a._GetRightHandedQuaternionArrayFromRef(h),e.parent||(h=o.Quaternion.FromArray([0,1,0,0]).multiply(o.Quaternion.FromArray(h)).asArray()))}else h=[0,0,0,0];else"weights"===i?h=p?[p]:[0]:p?(h=p.asArray(),f&&"translation"===i&&(a.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 o}));var n=r(2),o=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then((function(){var o=t.replace(/\.[^/.]+$/,"");return new n.b(e,r)._generateGLTFAsync(o)}))},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 o=this;return this._PreExportAsync(e,r).then((function(){var a=t.replace(/\.[^/.]+$/,"");return new n.b(e,r)._generateGLBAsync(a).then((function(t){return o._PostExportAsync(e,t,r)}))}))},e}()},function(e,t,r){"use strict";r.r(t),r.d(t,"KHR_texture_transform",(function(){return s})),r.d(t,"KHR_lights_punctual",(function(){return l})),r.d(t,"KHR_materials_sheen",(function(){return c})),r.d(t,"KHR_materials_unlit",(function(){return f}));var n=r(0),o=r(2),a="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=a;var i="KHR_texture_transform",s=function(){function e(e){this._recordedTextures=[],this.name=i,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={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng&&(n.rotation=r.wAng,o=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),!o)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[i]=n}},e.prototype.preExportTextureAsync=function(e,t,r){var n=this;return new Promise((function(r,o){var a=t.getScene();if(a){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,a).then((function(e){r(e)})).catch((function(e){o(e)}));r(t)}else o(e+': "scene" is not defined for Babylon texture '+t.name+"!")}))},e.prototype._textureTransformTextureAsync=function(e,t){var r=this;return new Promise((function(o){var a=new n.ProceduralTexture(""+e.name,e.getSize(),"textureTransform",t);a||(n.Tools.Log("Cannot create procedural texture for "+e.name+"!"),o(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(),o(a)):a.getEffect().executeWhenCompiled((function(){a.render(),o(a)}))}))},e}();o.b.RegisterExtension(i,(function(e){return new s(e)}));var u=r(1),l=function(){function e(e){this.name="KHR_lights_punctual",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,o){var a=this;return new Promise((function(i,s){if(t&&r instanceof n.ShadowLight){var l=r,c=void 0,f=l.getTypeID()==n.Light.LIGHTTYPEID_POINTLIGHT?"point":l.getTypeID()==n.Light.LIGHTTYPEID_DIRECTIONALLIGHT?"directional":l.getTypeID()==n.Light.LIGHTTYPEID_SPOTLIGHT?"spot":null;if(null==f)n.Logger.Warn(e+": Light "+l.name+" is not supported in KHR_lights_punctual");else{var h=l.position.clone(),p=a._exporter._convertToRightHandedSystemMap[r.uniqueId];if(h.equals(n.Vector3.Zero())||(p&&u.a._GetRightHandedPositionVector3FromRef(h),t.translation=h.asArray()),"point"!==f){var d=l.direction,m=-Math.atan2(d.z*(a._exporter._babylonScene.useRightHandedSystem?-1:1),d.x)+Math.PI/2,g=Math.sqrt(d.x*d.x+d.z*d.z),_=-Math.atan2(d.y,g),x=n.Quaternion.RotationYawPitchRoll(m,_,0);p&&u.a._GetRightHandedQuaternionFromRef(x),x.equals(n.Quaternion.Identity())||(t.rotation=x.asArray())}if(l.falloffType!==n.Light.FALLOFF_GLTF&&n.Logger.Warn(e+": Light falloff for "+l.name+" does not match the KHR_lights_punctual specification!"),c={type:f},l.diffuse.equals(n.Color3.White())||(c.color=l.diffuse.asArray()),1!==l.intensity&&(c.intensity=l.intensity),l.range!==Number.MAX_VALUE&&(c.range=l.range),"spot"===f){var y=l;y.angle!==Math.PI/2&&(null==c.spot&&(c.spot={}),c.spot.outerConeAngle=y.angle/2),0!==y.innerAngle&&(null==c.spot&&(c.spot={}),c.spot.innerConeAngle=y.innerAngle/2)}null==a._lights&&(a._lights={lights:[]}),a._lights.lights.push(c);var T={light:a._lights.lights.length-1},v=r.parent;if(v&&1==v.getChildren().length){var b=a._exporter._nodes[o[v.uniqueId]];if(b){var A=n.TmpVectors.Matrix[0],F=n.TmpVectors.Matrix[1],M=b.translation?new n.Vector3(b.translation[0],b.translation[1],b.translation[2]):n.Vector3.Zero(),E=b.rotation?new n.Quaternion(b.rotation[0],b.rotation[1],b.rotation[2],b.rotation[3]):n.Quaternion.Identity(),R=b.scale?new n.Vector3(b.scale[0],b.scale[1],b.scale[2]):n.Vector3.One();n.Matrix.ComposeToRef(R,E,M,A),A.invertToRef(F);var V=n.TmpVectors.Matrix[2],w=t.translation?new n.Vector3(t.translation[0],t.translation[1],t.translation[2]):n.Vector3.Zero();l instanceof n.DirectionalLight&&w.subtractInPlace(a._exporter._babylonScene.useRightHandedSystem?l.direction:u.a._GetRightHandedPositionVector3(l.direction));var S=a._exporter._babylonScene.useRightHandedSystem?n.Quaternion.Identity():new n.Quaternion(0,1,0,0);t.rotation&&S.multiplyInPlace(new n.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var C=t.scale?new n.Vector3(t.scale[0],t.scale[1],t.scale[2]):n.Vector3.One();n.Matrix.ComposeToRef(C,S,w,V),V.multiplyToRef(F,V);var B=n.TmpVectors.Vector3[0],I=n.TmpVectors.Quaternion[0],P=n.TmpVectors.Vector3[1];return V.decompose(B,I,P),b.scale=B.asArray(),b.rotation=I.asArray(),b.translation=P.asArray(),null==b.extensions&&(b.extensions={}),b.extensions.KHR_lights_punctual=T,void i(null)}}null==t.extensions&&(t.extensions={}),t.extensions.KHR_lights_punctual=T}}i(t)}))},e}();o.b.RegisterExtension("KHR_lights_punctual",(function(e){return new l(e)}));var c=function(){function e(e){this.name="KHR_materials_sheen",this.enabled=!0,this.required=!1,this._textureInfos=[],this._exportedTextures=[],this._wasUsed=!1}return e.prototype.dispose=function(){this._textureInfos=[],this._exportedTextures=[]},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype._getTextureIndex=function(e){var t=this._exportedTextures.indexOf(e);return-1===t&&e.reservedDataStore&&(t=this._exportedTextures.indexOf(e.reservedDataStore.source)),t},e.prototype.postExportTexture=function(e,t,r){var n=this._getTextureIndex(r);n>-1&&(this._textureInfos[n]=t)},e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof n.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?(this._exportedTextures.push(r.sheen.texture),[r.sheen.texture]):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var o=this;return new Promise((function(e,a){var i;if(r instanceof n.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);o._wasUsed=!0,null==t.extensions&&(t.extensions={});var s={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=r.sheen.roughness)&&void 0!==i?i:0};if(r.sheen.texture)(u=o._getTextureIndex(r.sheen.texture))>-1&&(s.sheenColorTexture=o._textureInfos[u]);if(r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture)(u=o._getTextureIndex(r.sheen.textureRoughness))>-1&&(s.sheenRoughnessTexture=o._textureInfos[u]);else if(r.sheen.texture&&r.sheen.useRoughnessFromMainTexture){var u;(u=o._getTextureIndex(r.sheen.texture))>-1&&(s.sheenRoughnessTexture=o._textureInfos[u])}t.extensions.KHR_materials_sheen=s}e(t)}))},e}();o.b.RegisterExtension("KHR_materials_sheen",(function(e){return new c(e)}));var f=function(){function e(e){this.name="KHR_materials_unlit",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 o=this;return new Promise((function(e,a){var i=!1;r instanceof n.PBRMaterial?i=r.unlit:r instanceof n.StandardMaterial&&(i=r.disableLighting),i&&(o._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions.KHR_materials_unlit={}),e(t)}))},e}();o.b.RegisterExtension("KHR_materials_unlit",(function(e){return new f(e)}))},function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));var n=r(3),o=r(0),a=function(){function e(e){this._textureMap={},this._textureMap={},this._exporter=e}return e.FuzzyEquals=function(e,t,r){return o.Scalar.WithinEpsilon(e.r,t.r,r)&&o.Scalar.WithinEpsilon(e.g,t.g,r)&&o.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){for(var n=[],a=0,i=e;a<i.length;a++){var s=i[a];s instanceof o.StandardMaterial?n.push(this._convertStandardMaterialAsync(s,t,r)):s instanceof o.PBRBaseMaterial?n.push(this._convertPBRMaterialAsync(s,t,r)):o.Tools.Warn("Unsupported material type: "+s.name)}return Promise.all(n).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 o.Vector2(0,1),n=new o.Vector2(0,.1),a=new o.Vector2(0,.1),i=new o.Vector2(1300,.1);var s=t.diffuseColor.toLinearSpace().scale(.5),u=t.alpha,l=function(e){return function(e,t,r,n,o){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*n+e*e*e*o}(Math.pow(e/i.x,.333333),r.y,n.y,a.y,i.y)}(o.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower));return{baseColorFactor:[s.r,s.g,s.b,u],metallicFactor:0,roughnessFactor:l}},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,i=a*a-4*n*(this._DielectricSpecular.r-t);return o.Scalar.Clamp((-a+Math.sqrt(i))/(2*n),0,1)},e._SetAlphaMode=function(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)},e.prototype._convertStandardMaterialAsync=function(t,r,n){var a=this._exporter._materialMap,i=this._exporter._materials,s=[],u=this._convertToGLTFPBRMetallicRoughness(t),l={name:t.name};return null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||o.Tools.Warn(t.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),l.doubleSided=!0),n&&(t.diffuseTexture&&s.push(this._exportTextureAsync(t.diffuseTexture,r).then((function(e){e&&(u.baseColorTexture=e)}))),t.bumpTexture&&s.push(this._exportTextureAsync(t.bumpTexture,r).then((function(e){e&&(l.normalTexture=e,null!=t.bumpTexture&&1!==t.bumpTexture.level&&(l.normalTexture.scale=t.bumpTexture.level))}))),t.emissiveTexture&&(l.emissiveFactor=[1,1,1],s.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(l.emissiveTexture=e)})))),t.ambientTexture&&s.push(this._exportTextureAsync(t.ambientTexture,r).then((function(e){if(e){var t={index:e.index};l.occlusionTexture=t,t.strength=1}})))),(t.alpha<1||t.opacityTexture)&&(t.alphaMode===o.Constants.ALPHA_COMBINE?l.alphaMode="BLEND":o.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e.FuzzyEquals(t.emissiveColor,o.Color3.Black(),e._Epsilon)&&(l.emissiveFactor=t.emissiveColor.asArray()),l.pbrMetallicRoughness=u,e._SetAlphaMode(l,t),i.push(l),a[t.uniqueId]=i.length-1,this._finishMaterial(s,l,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var o=this;return Promise.all(e).then((function(){for(var e=null,a=0,i=o._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);a<i.length;a++){var s=i[a];e||(e=[]),e.push(o._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=o._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._convertPBRMetallicRoughnessMaterialAsync=function(t,r,n){var a=this._exporter._materialMap,i=this._exporter._materials,s=[],u={};t.baseColor&&(u.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,t.alpha]),null!=t.metallic&&1!==t.metallic&&(u.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(u.roughnessFactor=t.roughness);var l={name:t.name};return t.doubleSided&&(l.doubleSided=t.doubleSided),e._SetAlphaMode(l,t),n&&(null!=t.baseTexture&&s.push(this._exportTextureAsync(t.baseTexture,r).then((function(e){e&&(u.baseColorTexture=e)}))),t.normalTexture&&s.push(this._exportTextureAsync(t.normalTexture,r).then((function(e){e&&(l.normalTexture=e,1!==t.normalTexture.level&&(l.normalTexture.scale=t.normalTexture.level))}))),t.occlusionTexture&&s.push(this._exportTextureAsync(t.occlusionTexture,r).then((function(e){e&&(l.occlusionTexture=e,null!=t.occlusionStrength&&(l.occlusionTexture.strength=t.occlusionStrength))}))),t.emissiveTexture&&s.push(this._exportTextureAsync(t.emissiveTexture,r).then((function(e){e&&(l.emissiveTexture=e)})))),e.FuzzyEquals(t.emissiveColor,o.Color3.Black(),e._Epsilon)&&(l.emissiveFactor=t.emissiveColor.asArray()),l.pbrMetallicRoughness=u,i.push(l),a[t.uniqueId]=i.length-1,this._finishMaterial(s,l,t,r)},e.prototype._createBase64FromCanvasAsync=function(e,t,r,a){var i=this;return new Promise((function(s,u){return Object(n.a)(i,void 0,void 0,(function(){var i,u,l,c,f,h;return Object(n.b)(this,(function(n){switch(n.label){case 0:return i=o.Constants.TEXTURETYPE_UNSIGNED_INT,u=this._exporter._babylonScene,l=u.getEngine(),c=l.createRawTexture(e,t,r,o.Constants.TEXTUREFORMAT_RGBA,!1,!0,o.Texture.NEAREST_SAMPLINGMODE,null,i),[4,o.TextureTools.ApplyPostProcess("pass",c,u,i,o.Constants.TEXTURE_NEAREST_SAMPLINGMODE,o.Constants.TEXTUREFORMAT_RGBA)];case 1:return n.sent(),[4,l._readTexturePixels(c,t,r)];case 2:return f=n.sent(),[4,o.Tools.DumpDataAsync(t,r,f,a,void 0,!0,!1)];case 3:return h=n.sent(),s(h),[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 o.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,a,i=e?e.getSize():{width:0,height:0},s=t?t.getSize():{width:0,height:0};return i.width<s.width?(n=e&&e instanceof o.Texture?o.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):this._createWhiteTexture(s.width,s.height,r),a=t):i.width>s.width?(a=t&&t instanceof o.Texture?o.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):this._createWhiteTexture(i.width,i.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,a,i){return Object(n.a)(this,void 0,void 0,(function(){var s,u,l,c,f,h,p,d,m,g,_,x,y,T,v,b,A,F,M,E,R,V,w,S,C,B,I,P,L,N,O,G;return Object(n.b)(this,(function(n){switch(n.label){case 0:return s=[],t||r?(u=t?t.getScene():r?r.getScene():null)?(l=this._resizeTexturesToSameDimensions(t,r,u),c=l.texture1.getSize(),f=void 0,h=void 0,p=c.width,d=c.height,[4,l.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return m=n.sent(),[4,l.texture2.readPixels()];case 2:if(g=n.sent(),!m)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(f=this._convertPixelArrayToFloat32(m),!g)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(h=this._convertPixelArrayToFloat32(g),_=h.byteLength,x=new Uint8Array(_),y=new Uint8Array(_),4,T=o.Color3.Black(),v=0,b=0,B=0;B<d;++B)for(I=0;I<p;++I)A=4*(p*B+I),F=new o.Color3(f[A],f[A+1],f[A+2]).toLinearSpace().multiply(a.diffuseColor),M=new o.Color3(h[A],h[A+1],h[A+2]).toLinearSpace().multiply(a.specularColor),E=h[A+3]*a.glossiness,R={diffuseColor:F,specularColor:M,glossiness:E},V=this._convertSpecularGlossinessToMetallicRoughness(R),T.r=Math.max(T.r,V.baseColor.r),T.g=Math.max(T.g,V.baseColor.g),T.b=Math.max(T.b,V.baseColor.b),v=Math.max(v,V.metallic),b=Math.max(b,V.roughness),y[A]=255*V.baseColor.r,y[A+1]=255*V.baseColor.g,y[A+2]=255*V.baseColor.b,y[A+3]=l.texture1.hasAlpha?255*f[A+3]:255,x[A]=0,x[A+1]=255*V.roughness,x[A+2]=255*V.metallic,x[A+3]=255;for(w={baseColor:T,metallic:v,roughness:b},S=!1,C=!1,B=0;B<d;++B)for(I=0;I<p;++I)y[P=4*(p*B+I)]/=w.baseColor.r>e._Epsilon?w.baseColor.r:1,y[P+1]/=w.baseColor.g>e._Epsilon?w.baseColor.g:1,y[P+2]/=w.baseColor.b>e._Epsilon?w.baseColor.b:1,L=o.Color3.FromInts(y[P],y[P+1],y[P+2]),N=L.toGammaSpace(),y[P]=255*N.r,y[P+1]=255*N.g,y[P+2]=255*N.b,e.FuzzyEquals(N,o.Color3.White(),e._Epsilon)||(C=!0),x[P+1]/=w.roughness>e._Epsilon?w.roughness:1,x[P+2]/=w.metallic>e._Epsilon?w.metallic:1,O=o.Color3.FromInts(255,x[P+1],x[P+2]),e.FuzzyEquals(O,o.Color3.White(),e._Epsilon)||(S=!0);return S&&(G=this._createBase64FromCanvasAsync(x,p,d,i).then((function(e){w.metallicRoughnessTextureBase64=e})),s.push(G)),C&&(G=this._createBase64FromCanvasAsync(y,p,d,i).then((function(e){w.baseColorTextureBase64=e})),s.push(G)),[2,Promise.all(s).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),i=e._SolveMetallic(r,n,a),s=t.diffuseColor.scale(a/(1-e._DielectricSpecular.r)/Math.max(1-i,e._Epsilon)),u=t.specularColor.subtract(e._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,e._Epsilon)),l=o.Color3.Lerp(s,u,i*i);return{baseColor:l=l.clampToRef(0,1,l),metallic:i,roughness:1-t.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){var o=[],a={baseColor:e.albedoColor||e.baseColor,metallic:e.metallic||e.metallic,roughness:e.roughness||e.roughness};if(n){(e.albedoTexture||e.baseTexture)&&o.push(this._exportTextureAsync(e.albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var i=e.metallicTexture||e.metallicRoughnessTexture;i&&o.push(this._exportTextureAsync(i,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(o).then((function(){return a}))},e.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof o.Texture?e.samplingMode:null;if(null!=r)switch(r){case o.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case o.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case o.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case o.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case o.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case o.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case o.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case o.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case o.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case o.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case o.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case o.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case o.Texture.WRAP_ADDRESSMODE:return 10497;case o.Texture.CLAMP_ADDRESSMODE:return 33071;case o.Texture.MIRROR_ADDRESSMODE:return 33648;default:return o.Tools.Error("Unsupported Texture Wrap Mode "+e+"!"),10497}},e.prototype._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof o.Texture?e.wrapU:o.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof o.Texture?e.wrapV:o.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 i=a._exporter._samplers,s=a._exporter._textures,u={diffuseColor:e.albedoColor||e.diffuseColor||o.Color3.White(),specularColor:e.reflectivityColor||e.specularColor||o.Color3.White(),glossiness:e.microSurface||e.glossiness||1},l=null,c=e.albedoTexture||e.diffuseTexture,f=e.reflectivityTexture||e.specularGlossinessTexture,h=a._getGLTFTextureSampler(c);null!=h.magFilter&&null!=h.minFilter&&null!=h.wrapS&&null!=h.wrapT&&(i.push(h),l=i.length-1);var p=e.useMicroSurfaceFromReflectivityMapAlpha||e.useMicroSurfaceFromReflectivityMapAlpha;return f&&!p?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(c||f)&&n?a._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(c,f,u,t).then((function(e){if(e.baseColorTextureBase64){var n=a._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+s.length+".png",t,c?c.coordinatesIndex:null,l);n&&(r.baseColorTexture=n)}if(e.metallicRoughnessTextureBase64){var o=a._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+s.length+".png",t,f?f.coordinatesIndex:null,l);o&&(r.metallicRoughnessTexture=o)}return e})):a._convertSpecularGlossinessToMetallicRoughness(u)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,o={},a={name:e.name};if(e.isMetallicWorkflow()){var i=e.albedoColor||e.diffuseColor||e.baseColor,s=e.alpha;return i&&(o.baseColorFactor=[i.r,i.g,i.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,o,r).then((function(i){return n.setMetallicRoughnessPbrMaterial(i,e,a,o,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,o,r).then((function(i){return n.setMetallicRoughnessPbrMaterial(i,e,a,o,t,r)}))},e.prototype.setMetallicRoughnessPbrMaterial=function(t,r,n,a,i,s){var u=this._exporter._materialMap,l=this._exporter._materials,c=[];if(t){if(e._SetAlphaMode(n,r),e.FuzzyEquals(t.baseColor,o.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||r.doubleSided||o.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),s){var f=r.bumpTexture||r.normalTexture;if(f){var h=this._exportTextureAsync(f,i).then((function(e){e&&(n.normalTexture=e,1!==f.level&&(n.normalTexture.scale=f.level))}));c.push(h)}var p=r.ambientTexture||r.occlusionTexture;if(p){h=this._exportTextureAsync(p,i).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord};n.occlusionTexture=t;var o=r.ambientTextureStrength||r.occlusionStrength;o&&(t.strength=o)}}));c.push(h)}var d=r.emissiveTexture||r.emissiveTexture;if(d){h=this._exportTextureAsync(d,i).then((function(e){e&&(n.emissiveTexture=e)}));c.push(h)}}var m=r.emissiveColor||r.emissiveColor;e.FuzzyEquals(m,o.Color3.Black(),e._Epsilon)||(n.emissiveFactor=m.asArray()),n.pbrMetallicRoughness=a,l.push(n),u[r.uniqueId]=l.length-1}return this._finishMaterial(c,n,r,i)},e.prototype.getPixelsFromTexture=function(e){return e.textureType,o.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 Object(n.a)(r,void 0,void 0,(function(){var r,o,a,i,s,u,l,c,f,h=this;return Object(n.b)(this,(function(n){switch(n.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(!(o=n.sent()))return[2,null];for(a=this._exporter._samplers,i=this._getGLTFTextureSampler(e),s=null,u=null,l=0;l<a.length;++l)if((c=a[l]).minFilter===i.minFilter&&c.magFilter===i.magFilter&&c.wrapS===i.wrapS&&c.wrapT===i.wrapT){u=l;break}if(null==u?(a.push(i),s=a.length-1):s=u,f=e.getSize(),e.mimeType)switch(e.mimeType){case"image/jpeg":t="image/jpeg";break;case"image/png":t="image/png"}return[2,this._createBase64FromCanvasAsync(o,f.width,f.height,t).then((function(n){var o=h._getTextureInfoFromBase64(n,e.name.replace(/\.\/|\/|\.\\|\\/g,"_"),t,e.coordinatesIndex,s);return o&&(h._textureMap[r]=o,h._exporter._extensionsPostExportTextures("linkTextureInfo",o,e)),o}))]}}))}))}))},e.prototype._getTextureInfoFromBase64=function(e,t,r,n,a){var i=this._exporter._textures,s=this._exporter._images,u=this._exporter._imageData,l=null,c={source:s.length,name:t};null!=a&&(c.sampler=a);for(var f=atob(e.split(",")[1]),h=new ArrayBuffer(f.length),p=new Uint8Array(h),d=0,m=f.length;d<m;++d)p[d]=f.charCodeAt(d);var g={data:p,mimeType:r},_="image/jpeg"===r?".jpeg":".png",x=t+_,y=x;if(x in u&&(x=t+"_"+o.Tools.RandomId()+_),u[x]=g,"image/jpeg"===r||"image/png"===r){var T={name:t,uri:x},v=null;for(d=0;d<s.length;++d)if(s[d].uri===y){v=d;break}null==v?(s.push(T),c.source=s.length-1):c.source=v,i.push(c),l={index:i.length-1},null!=n&&(l.texCoord=n)}else o.Tools.Error("Unsupported texture mime type "+r);return l},e._DielectricSpecular=new o.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),r.d(t,"STLExport",(function(){return o}));var n=r(0),o=function(){function e(){}return e.CreateSTL=function(e,t,r,o,a,i){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===o&&(o=!1),void 0===a&&(a=!0),void 0===i&&(i=!1);var s,u=function(e,t,r){var o=[3*e[r],3*e[r+1],3*e[r+2]],a=[new n.Vector3(t[o[0]],t[o[0]+2],t[o[0]+1]),new n.Vector3(t[o[1]],t[o[1]+2],t[o[1]+1]),new n.Vector3(t[o[2]],t[o[2]+2],t[o[2]+1])],i=a[0].subtract(a[1]),s=a[2].subtract(a[1]);return{v:a,n:n.Vector3.Cross(s,i).normalize()}},l=function(e,t,r,n){return t=c(e,t,r.x,n),t=c(e,t,r.y,n),c(e,t,r.z,n)},c=function(e,t,r,n){return e.setFloat32(t,r,n),t+4},f=0,h=0;if(o){for(var p=0;p<e.length;p++){f+=(_=(m=e[p]).getIndices())?_.length/3:0}var d=new ArrayBuffer(84+50*f);h+=80,(s=new DataView(d)).setUint32(h,f,a),h+=4}else s="solid stlmesh\r\n";for(p=0;p<e.length;p++){var m=e[p];i||m.bakeCurrentTransformIntoVertices();for(var g=m.getVerticesData(n.VertexBuffer.PositionKind)||[],_=m.getIndices()||[],x=0;x<_.length;x+=3){var y=u(_,g,x);o?(h=l(s,h,y.n,a),h=l(s,h,y.v[0],a),h=l(s,h,y.v[1],a),h=l(s,h,y.v[2],a),h+=2):(s+="facet normal "+y.n.x+" "+y.n.y+" "+y.n.z+"\r\n",s+="\touter loop\r\n",s+="\t\tvertex "+y.v[0].x+" "+y.v[0].y+" "+y.v[0].z+"\r\n",s+="\t\tvertex "+y.v[1].x+" "+y.v[1].y+" "+y.v[1].z+"\r\n",s+="\t\tvertex "+y.v[2].x+" "+y.v[2].y+" "+y.v[2].z+"\r\n",s+="\tendloop\r\n",s+="endfacet\r\n")}}if(o||(s+="endsolid stlmesh"),t){var T=document.createElement("a"),v=new Blob([s],{type:"application/octet-stream"});T.href=window.URL.createObjectURL(v),T.download=r+".stl",T.click()}return s},e}()},function(e,t,r){"use strict";r.r(t),function(e){var n=r(5),o=r(4),a=r(9),i=r(10),s=r(7);r.d(t,"__IGLTFExporterExtension",(function(){return n.__IGLTFExporterExtension})),r.d(t,"_GLTFAnimation",(function(){return s._GLTFAnimation})),r.d(t,"GLTFData",(function(){return s.GLTFData})),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,"GLTF2Export",(function(){return s.GLTF2Export})),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})),r.d(t,"KHR_materials_sheen",(function(){return s.KHR_materials_sheen})),r.d(t,"KHR_materials_unlit",(function(){return s.KHR_materials_unlit}));var u=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==u){u.BABYLON=u.BABYLON||{};var l=u.BABYLON;l.GLTF2=l.GLTF2||{},l.GLTF2.Exporter=l.GLTF2.Exporter||{},l.GLTF2.Exporter.Extensions=l.GLTF2.Exporter.Extensions||{};var c=[];for(var f in n)l[f]=n[f],c.push(f);for(var f in o)l[f]=o[f],c.push(f);for(var f in a)l[f]=a[f],c.push(f);for(var f in i)l.GLTF2.Exporter.Extensions[f]=i[f],c.push(f);for(var f in s)c.indexOf(f)>-1||(l.GLTF2.Exporter[f]=s[f])}}.call(this,r(12))},function(e,t,r){"use strict";r.r(t),function(e){var n=r(6);r.d(t,"OBJExport",(function(){return n.OBJExport}));var o=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==o)for(var a in n)o.BABYLON[a]=n[a]}.call(this,r(12))},function(e,t,r){"use strict";(function(e){var n=r(13);r.d(t,"a",(function(){return n.STLExport}));var o=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==o)for(var a in n)o.BABYLON[a]=n[a]}).call(this,r(12))},function(e,t,r){"use strict";r.r(t),r.d(t,"__IGLTFExporterExtension",(function(){return n.__IGLTFExporterExtension})),r.d(t,"_GLTFAnimation",(function(){return n._GLTFAnimation})),r.d(t,"GLTFData",(function(){return n.GLTFData})),r.d(t,"_Exporter",(function(){return n._Exporter})),r.d(t,"_BinaryWriter",(function(){return n._BinaryWriter})),r.d(t,"__IGLTFExporterExtensionV2",(function(){return n.__IGLTFExporterExtensionV2})),r.d(t,"_GLTFMaterialExporter",(function(){return n._GLTFMaterialExporter})),r.d(t,"GLTF2Export",(function(){return n.GLTF2Export})),r.d(t,"_GLTFUtilities",(function(){return n._GLTFUtilities})),r.d(t,"KHR_texture_transform",(function(){return n.KHR_texture_transform})),r.d(t,"KHR_lights_punctual",(function(){return n.KHR_lights_punctual})),r.d(t,"KHR_materials_sheen",(function(){return n.KHR_materials_sheen})),r.d(t,"KHR_materials_unlit",(function(){return n.KHR_materials_unlit})),r.d(t,"OBJExport",(function(){return o.OBJExport})),r.d(t,"STLExport",(function(){return a.a}));r(6),r(5),r(7),r(13);var n=r(14),o=r(15),a=r(16)}])}));
|