Spaces:
Running
Running
!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=17)}([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 o={buffer:e,byteLength:r};return t&&(o.byteOffset=t),a&&(o.name=a),n&&(o.byteStride=n),o},e._CreateAccessor=function(e,t,r,n,a,o,i,s){var u={name:t,bufferView:e,componentType:n,count:a,type:r};return null!=i&&(u.min=i),null!=s&&(u.max=s),null!=o&&(u.byteOffset=o),u},e._CalculateMinMaxPositions=function(t,r,a,o){var i,s,u,l=[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){i=3*f,s=n.Vector3.FromArray(t,i),o&&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._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),a=r(0),o=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"}},(e=e||a.EngineStore.LastCreatedScene)&&(this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._cameras=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._skins=[],this._animations=[],this._imageData={},this._orderedImageData=[],this._options=t||{},this._animationSampleRate=t&&t.animationSampleRate?t.animationSampleRate:1/60,this._includeCoordinateSystemConversionNodes=!(!t||!t.includeCoordinateSystemConversionNodes),this._glTFMaterialExporter=new o.a(this),this._loadExtensions())}return e.prototype._applyExtension=function(e,t,r,n){var a=this;if(r>=t.length)return Promise.resolve(e);var o=n(t[r],e);return o?o.then((function(e){return a._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],a=0,o=e._ExtensionNames;a<o.length;a++){var i=o[a];n.push(this._extensions[i])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)}))},e.prototype._extensionsPostExportMeshPrimitiveAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,a){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,a,r,n)}))},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n){return this._applyExtensions(t,(function(t,a){return t.postExportNodeAsync&&t.postExportNodeAsync(e,a,r,n)}))},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._applyExtensions(t,(function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)}))},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var a=[],o=0,i=e._ExtensionNames;o<i.length;o++){var s=i[o],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&a.push.apply(a,u.postExportMaterialAdditionalTextures(t,r,n))}return a},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var a=0,o=e._ExtensionNames;a<o.length;a++){var i=o[a],s=this._extensions[i];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var a=n[r],o=this._extensions[a];o.enabled&&t(o)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions((function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())}))},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],a=e._ExtensionFactories[n](this);this._extensions[n]=a}},e.prototype.dispose=function(){for(var e in this._extensions){this._extensions[e].dispose()}},e.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&a.Tools.Warn("Extension with the name ".concat(t," already exists")),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype.reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,o){switch(t){case a.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=o.getUInt32(u+4),c=o.getUInt32(u+8);o.setUInt32(c,u+4),o.setUInt32(l,u+8)}break;case a.Material.TriangleFanDrawMode:i=e.indexStart+e.indexCount-1;for(var f=e.indexStart;i>=f;--i)o.setUInt32(r[i],n),n+=4;break;case a.Material.TriangleStripDrawMode:e.indexCount>=3&&(o.setUInt32(r[e.indexStart+2],n+4),o.setUInt32(r[e.indexStart+1],n+8))}},e.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,o,i,s,u){if(u&&r===a.Material.ClockWiseSideOrientation)switch(t){case a.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,n,o,i,s,u);break;case a.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,n,o,i,s,u);break;case a.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,n,o,i,s,u)}},e.prototype.reorderTriangleFillMode=function(e,t,r,n,o,i,s,u){var l=this.getVertexBufferFromMesh(n,e.getMesh());if(l){var c=l.byteStride/a.VertexBuffer.GetTypeByteLength(l.type);if(e.verticesCount%3!=0)a.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var f=[],h=0;switch(n){case a.VertexBuffer.PositionKind:case a.VertexBuffer.NormalKind:for(var p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*c,f.push(a.Vector3.FromArray(o,h)),f.push(a.Vector3.FromArray(o,h+2*c)),f.push(a.Vector3.FromArray(o,h+c));break;case a.VertexBuffer.TangentKind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*c,f.push(a.Vector4.FromArray(o,h)),f.push(a.Vector4.FromArray(o,h+2*c)),f.push(a.Vector4.FromArray(o,h+c));break;case a.VertexBuffer.ColorKind:var d=l.getSize();for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=d)h=p*c,4===d?(f.push(a.Vector4.FromArray(o,h)),f.push(a.Vector4.FromArray(o,h+2*c)),f.push(a.Vector4.FromArray(o,h+c))):(f.push(a.Vector3.FromArray(o,h)),f.push(a.Vector3.FromArray(o,h+2*c)),f.push(a.Vector3.FromArray(o,h+c)));break;case a.VertexBuffer.UVKind:case a.VertexBuffer.UV2Kind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*c,f.push(a.Vector2.FromArray(o,h)),f.push(a.Vector2.FromArray(o,h+2*c)),f.push(a.Vector2.FromArray(o,h+c));break;default:a.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this.writeVertexAttributeData(f,i,n,o,s,u)}}else a.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind ".concat(n," not present!"))},e.prototype.reorderTriangleStripDrawMode=function(e,t,r,n,o,i,s,u){var l=this.getVertexBufferFromMesh(n,e.getMesh());if(l){var c=l.byteStride/a.VertexBuffer.GetTypeByteLength(l.type),f=[],h=0;switch(n){case a.VertexBuffer.PositionKind:case a.VertexBuffer.NormalKind:h=e.verticesStart,f.push(a.Vector3.FromArray(o,h+2*c)),f.push(a.Vector3.FromArray(o,h+c));break;case a.VertexBuffer.TangentKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector4.FromArray(o,h));break;case a.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,4===l.getSize()?f.push(a.Vector4.FromArray(o,h)):f.push(a.Vector3.FromArray(o,h));break;case a.VertexBuffer.UVKind:case a.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector2.FromArray(o,h));break;default:a.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this.writeVertexAttributeData(f,i+12,n,o,s,u)}else a.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype.reorderTriangleFanMode=function(e,t,r,n,o,i,s,u){var l=this.getVertexBufferFromMesh(n,e.getMesh());if(l){var c=l.byteStride/a.VertexBuffer.GetTypeByteLength(l.type),f=[],h=0;switch(n){case a.VertexBuffer.PositionKind:case a.VertexBuffer.NormalKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector3.FromArray(o,h));break;case a.VertexBuffer.TangentKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector4.FromArray(o,h));break;case a.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector4.FromArray(o,h)),4===l.getSize()?f.push(a.Vector4.FromArray(o,h)):f.push(a.Vector3.FromArray(o,h));break;case a.VertexBuffer.UVKind:case a.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector2.FromArray(o,h));break;default:a.Tools.Error("Unsupported Vertex Buffer type: ".concat(n))}this.writeVertexAttributeData(f,i,n,o,s,u)}else a.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind ".concat(n," not present!"))},e.prototype.writeVertexAttributeData=function(e,t,r,n,o,s){for(var u=0,l=e;u<l.length;u++){var c=l[u];!s||r===a.VertexBuffer.ColorKind||c instanceof a.Vector2||(c instanceof a.Vector3?r===a.VertexBuffer.NormalKind?i.a._GetRightHandedNormalVector3FromRef(c):r===a.VertexBuffer.PositionKind?i.a._GetRightHandedPositionVector3FromRef(c):a.Tools.Error("Unsupported vertex attribute kind!"):i.a._GetRightHandedVector4FromRef(c)),r===a.VertexBuffer.NormalKind?c.normalize():r===a.VertexBuffer.TangentKind&&c instanceof a.Vector4&&i.a._NormalizeTangentFromRef(c);for(var f=0,h=c.asArray();f<h.length;f++){var p=h[f];o.setFloat32(p,t),t+=4}}},e.prototype.writeAttributeData=function(e,t,r,n,o,s,u){var l,c,f=[];switch(e){case a.VertexBuffer.PositionKind:for(var h=0,p=r.length/n;h<p;++h){l=h*n;var d=a.Vector3.FromArray(r,l);s&&i.a._GetRightHandedPositionVector3FromRef(d),f.push(d.asArray())}break;case a.VertexBuffer.NormalKind:h=0;for(var m=r.length/n;h<m;++h){l=h*n;d=a.Vector3.FromArray(r,l);s&&i.a._GetRightHandedNormalVector3FromRef(d),d.normalize(),f.push(d.asArray())}break;case a.VertexBuffer.TangentKind:h=0;for(var g=r.length/n;h<g;++h){l=h*n;d=a.Vector4.FromArray(r,l);s&&i.a._GetRightHandedVector4FromRef(d),i.a._NormalizeTangentFromRef(d),f.push(d.asArray())}break;case a.VertexBuffer.ColorKind:for(var _=u.material,x=!_||"StandardMaterial"===_.getClassName(),y=(d=3===n?new a.Color3:new a.Color4,h=0,r.length/n);h<y;++h)l=h*n,3===n?(a.Color3.FromArrayToRef(r,l,d),x&&d.toLinearSpaceToRef(d)):(a.Color4.FromArrayToRef(r,l,d),x&&d.toLinearSpaceToRef(d)),f.push(d.asArray());break;case a.VertexBuffer.UVKind:case a.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 a.VertexBuffer.MatricesIndicesKind:case a.VertexBuffer.MatricesIndicesExtraKind:h=0;for(var v=r.length/n;h<v;++h){l=h*n;d=a.Vector4.FromArray(r,l);f.push(d.asArray())}break;case a.VertexBuffer.MatricesWeightsKind:case a.VertexBuffer.MatricesWeightsExtraKind:h=0;for(var b=r.length/n;h<b;++h){l=h*n;d=a.Vector4.FromArray(r,l);f.push(d.asArray())}break;default:a.Tools.Warn("Unsupported Vertex Buffer Type: "+e),f=[]}switch(t){case 5121:c=o.setUInt8.bind(o);break;case 5123:c=o.setUInt16.bind(o);break;case 5125:c=o.setUInt32.bind(o);case 5126:c=o.setFloat32.bind(o);break;default:return void a.Tools.Warn("Unsupported Attribute Component kind: "+t)}for(var A=0,F=f;A<F.length;A++)for(var E=0,M=F[A];E<M.length;E++){c(M[E])}},e.prototype.writeMorphTargetAttributeData=function(e,t,r,n,o,s,u,l,c,f){var h,p,d=[],m=new a.Vector3,g=new a.Vector4(0,0,0,0);switch(e){case a.VertexBuffer.PositionKind:for(var _=r.verticesStart;_<r.verticesCount;++_){h=r.indexStart+_*u;var x=a.Vector3.FromArray(o,h);m=(y=a.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 a.VertexBuffer.NormalKind:for(_=r.verticesStart;_<r.verticesCount;++_){h=r.indexStart+_*u,(x=a.Vector3.FromArray(o,h)).normalize(),(y=a.Vector3.FromArray(s,h)).normalize(),m=y.subtractToRef(x,m),c&&i.a._GetRightHandedNormalVector3FromRef(m),d.push(m.asArray())}break;case a.VertexBuffer.TangentKind:for(_=r.verticesStart;_<r.verticesCount;++_){h=r.indexStart+_*(u+1);x=a.Vector4.FromArray(o,h);i.a._NormalizeTangentFromRef(x);var y=a.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:a.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 a.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,a,o,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._cameras&&this._cameras.length&&(this._glTF.cameras=this._cameras),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._skins&&this._skins.length&&(this._glTF.skins=this._skins),this._images&&this._images.length&&(e?(this._glTF.images=[],this._images.forEach((function(e){e.uri&&(a=s._imageData[e.uri],s._orderedImageData.push(a),n=e.uri.split(".")[0]+" image",o=i.a._CreateBufferView(0,l,a.data.length,void 0,n),l+=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))})),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 a=r.generateJSON(!1,e,!0),o=new Blob([n],{type:"application/octet-stream"}),i=e+".gltf",u=e+".bin",l=new s.GLTFData;if(l.glTFFiles[i]=a,l.glTFFiles[u]=o,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();var a,o=r.generateJSON(!0),i=e+".glb",u=o.length,l=0;"undefined"!=typeof TextEncoder&&(u=(a=(new TextEncoder).encode(o)).length);for(var c=0;c<r._orderedImageData.length;++c)l+=r._orderedImageData[c].data.byteLength;var f=r._getPadding(u),h=r._getPadding(n.byteLength),p=r._getPadding(l),d=28+u+f+n.byteLength+h+l+p,m=new ArrayBuffer(12),g=new DataView(m);g.setUint32(0,1179937895,!0),g.setUint32(4,2,!0),g.setUint32(8,d,!0);var _=new ArrayBuffer(8+u+f),x=new DataView(_);x.setUint32(0,u+f,!0),x.setUint32(4,1313821514,!0);var y=new Uint8Array(_,8);if(a)y.set(a);else{var T="_".charCodeAt(0);for(c=0;c<u;++c){var v=o.charCodeAt(c);v!=o.codePointAt(c)?y[c]=T:y[c]=v}}var b=new Uint8Array(_,8+u);for(c=0;c<f;++c)b[c]=32;var A=new ArrayBuffer(8),F=new DataView(A);F.setUint32(0,n.byteLength+l+p,!0),F.setUint32(4,5130562,!0);var E=new ArrayBuffer(h),M=new Uint8Array(E);for(c=0;c<h;++c)M[c]=0;var R=new ArrayBuffer(p),C=new Uint8Array(R);for(c=0;c<p;++c)C[c]=0;var V=[m,_,A,n];for(c=0;c<r._orderedImageData.length;++c)V.push(r._orderedImageData[c].data.buffer);V.push(E),V.push(R);var w=new Blob(V,{type:"application/octet-stream"}),S=new s.GLTFData;return S.glTFFiles[i]=w,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),S}))},e.prototype.setNodeTransformation=function(e,t,r){t.getPivotPoint().equalsToFloats(0,0,0)||a.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=a.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&n.multiplyInPlace(t.rotationQuaternion),a.Quaternion.IsIdentity(n)||(r&&i.a._GetRightHandedQuaternionFromRef(n),e.rotation=n.normalize().asArray())},e.prototype.setCameraTransformation=function(e,t,r){t.position.equalsToFloats(0,0,0)||(e.translation=r?i.a._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray());var n=t.absoluteRotation;a.Quaternion.IsIdentity(n)||(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,o,s){var u=r instanceof a.Mesh?r:r instanceof a.InstancedMesh?r.sourceMesh:null;if(u){var l=u.getVertexBuffer(e),c=u.getVerticesData(e);if(l&&c){var f=a.VertexBuffer.GetTypeByteLength(t),h=c.length*f,p=i.a._CreateBufferView(0,n.getByteOffset(),h,o,e+" - "+u.name);this._bufferViews.push(p),this.writeAttributeData(e,t,c,o/f,n,s,r)}}},e.prototype.setMorphTargetAttributes=function(e,t,r,n,o){if(r){t.targets||(t.targets=[]);var s={};if(r.hasNormals){var u=e.getMesh().getVerticesData(a.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(a.VertexBuffer.NormalKind,5126,e,r,u,l,x/4,n,o)}if(r.hasPositions){var d=e.getMesh().getVerticesData(a.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 a.Vector3(1/0,1/0,1/0),max:new a.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(a.VertexBuffer.PositionKind,5126,e,r,d,m,x/4,n,o,g),p.min=g.min.asArray(),p.max=g.max.asArray()}if(r.hasTangents){var _,x,y=e.getMesh().getVerticesData(a.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(a.VertexBuffer.TangentKind,5126,e,r,y,T,x/4,n,o)}t.targets.push(s)}},e.prototype.getMeshPrimitiveMode=function(e){return e instanceof a.LinesMesh?a.Material.LineListDrawMode:e.material?e.material.fillMode:a.Material.TriangleFillMode},e.prototype.setPrimitiveMode=function(e,t){switch(t){case a.Material.TriangleFillMode:break;case a.Material.TriangleStripDrawMode:e.mode=5;break;case a.Material.TriangleFanDrawMode:e.mode=6;break;case a.Material.PointListDrawMode:e.mode=0;case a.Material.PointFillMode:e.mode=0;break;case a.Material.LineLoopDrawMode:e.mode=2;break;case a.Material.LineListDrawMode:e.mode=1;break;case a.Material.LineStripDrawMode:e.mode=3}},e.prototype.setAttributeKind=function(e,t){switch(t){case a.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case a.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case a.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case a.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case a.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case a.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;case a.VertexBuffer.MatricesIndicesKind:e.attributes.JOINTS_0=this._accessors.length-1;break;case a.VertexBuffer.MatricesIndicesExtraKind:e.attributes.JOINTS_1=this._accessors.length-1;break;case a.VertexBuffer.MatricesWeightsKind:e.attributes.WEIGHTS_0=this._accessors.length-1;break;case a.VertexBuffer.MatricesWeightsExtraKind:e.attributes.WEIGHTS_1=this._accessors.length-1;break;default:a.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},e.prototype.setPrimitiveAttributesAsync=function(e,t,r,n){var o,s,u,l=[],c=null;t instanceof a.Mesh?c=t:t instanceof a.InstancedMesh&&(c=t.sourceMesh);var f=[{kind:a.VertexBuffer.PositionKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:a.VertexBuffer.NormalKind,accessorType:"VEC3",accessorComponentType:5126,byteStride:12},{kind:a.VertexBuffer.ColorKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:a.VertexBuffer.TangentKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:a.VertexBuffer.UVKind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:a.VertexBuffer.UV2Kind,accessorType:"VEC2",accessorComponentType:5126,byteStride:8},{kind:a.VertexBuffer.MatricesIndicesKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:a.VertexBuffer.MatricesIndicesExtraKind,accessorType:"VEC4",accessorComponentType:5123,byteStride:8},{kind:a.VertexBuffer.MatricesWeightsKind,accessorType:"VEC4",accessorComponentType:5126,byteStride:16},{kind:a.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()*a.VertexBuffer.GetTypeByteLength(W.accessorComponentType):4*a.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 E=0,M=c.subMeshes;E<M.length;E++){var R=M[E],C=R.getMaterial()||c.getScene().defaultMaterial,V=null;if(C)if(c instanceof a.LinesMesh){var w={name:c.name+" material"};(!c.color.equals(a.Color3.White())||c.alpha<1)&&(w.pbrMetallicRoughness={baseColorFactor:c.color.asArray().concat([c.alpha])}),this._materials.push(w),V=this._materials.length-1}else if("MultiMaterial"===C.getClassName()){var S=C.subMaterials[R.materialIndex];S&&(C=S,V=this._materialMap[C.uniqueId])}else V=this._materialMap[C.uniqueId];var B=null!=V?this._materials[V]:null,I={attributes:{}};this.setPrimitiveMode(I,p);for(var P=0,N=f;P<N.length;P++){if((x=(W=N[P]).kind)!==a.VertexBuffer.UVKind&&x!==a.VertexBuffer.UV2Kind||this._options.exportUnusedUVs||B&&this._glTFMaterialExporter._hasTexturesPresent(B))if(z=c.getVerticesData(x))if(T=this.getVertexBufferFromMesh(x,c)){var L=T.getSize(),O=W.bufferViewIndex;if(null!=O){u={min:null,max:null},x==a.VertexBuffer.PositionKind&&(u=i.a._CalculateMinMaxPositions(z,0,z.length/L,n));var G=i.a._CreateAccessor(O,x+" - "+t.name,W.accessorType,W.accessorComponentType,z.length/L,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!=V&&Object.keys(I.attributes).length>0){var K=null!==c.overrideMaterialSideOrientation?c.overrideMaterialSideOrientation:C.sideOrientation;if(K==a.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||K==a.Material.ClockWiseSideOrientation&&n&&c.overrideMaterialSideOrientation!==(null===(o=c.material)||void 0===o?void 0:o.sideOrientation)){var k=null!=h?this._bufferViews[h].byteOffset:null;null==k&&(k=0);var U=null;if(null!=h&&(U=c.getIndices()),U)this.reorderIndicesBasedOnPrimitiveMode(R,p,U,k,r);else for(var D=0,H=f;D<H.length;D++){var z,W=H[D];if(z=c.getVerticesData(W.kind)){var j=this._bufferViews[d[W.kind]].byteOffset;j||(j=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(R,p,K,W.kind,z,j,r,n)}}}I.material=V}if(m)for(var q=void 0,Q=0;Q<m.numTargets;++Q)q=m.getTarget(Q),this.setMorphTargetAttributes(R,I,q,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){return e instanceof a.TransformNode&&("__root__"===e.name&&(1!==e.getWorldMatrix().determinant()&&(!(e instanceof a.Mesh&&null!==e.geometry||e instanceof a.InstancedMesh&&null!==e.sourceMesh.geometry)&&!this._includeCoordinateSystemConversionNodes)))},e.prototype.createSceneAsync=function(e,t){var r,o,i,s=this,u={nodes:[]},l=Object(n.c)(Object(n.c)(Object(n.c)(Object(n.c)([],e.transformNodes,!0),e.meshes,!0),e.lights,!0),e.cameras,!0),c=[];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}))}}));var f=new Map;e.cameras.forEach((function(e){var t={type:e.mode===a.Camera.PERSPECTIVE_CAMERA?"perspective":"orthographic"};if(e.name&&(t.name=e.name),"perspective"===t.type)t.perspective={aspectRatio:e.getEngine().getAspectRatio(e),yfov:e._cache.fovMode===a.Camera.FOVMODE_VERTICAL_FIXED?e.fov:e.fov*e._cache.aspectRatio,znear:e.minZ,zfar:e.maxZ};else if("orthographic"===t.type){var r=e.orthoLeft&&e.orthoRight?.5*(e.orthoRight-e.orthoLeft):.5*e.getEngine().getRenderWidth(),n=e.orthoBottom&&e.orthoTop?.5*(e.orthoTop-e.orthoBottom):.5*e.getEngine().getRenderHeight();t.orthographic={xmag:r,ymag:n,znear:e.minZ,zfar:e.maxZ}}f.set(e,s._cameras.length),s._cameras.push(t)}));var h=this.getExportNodes(l),p=h[0],d=h[1];return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(d,"image/png",!0).then((function(){return s.createNodeMapAndAnimationsAsync(e,p,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 h=0,p=l;h<p.length;h++){var d=p[h];if(void 0!==(r=s._nodeMap[d.uniqueId])){if(o=s._nodes[r],d.metadata&&(s._options.metadataSelector?o.extras=s._options.metadataSelector(d.metadata):d.metadata.gltf&&(o.extras=d.metadata.gltf.extras)),d instanceof a.Camera&&(o.camera=f.get(d)),!d.parent||-1!==c.indexOf(d.parent))if(s._options.shouldExportNode&&!s._options.shouldExportNode(d))a.Tools.Log("Omitting "+d.name+" from scene.");else s._convertToRightHandedSystemMap[d.uniqueId]&&(o.translation&&(o.translation[2]*=-1,o.translation[0]*=-1),o.rotation=o.rotation?a.Quaternion.FromArray([0,1,0,0]).multiply(a.Quaternion.FromArray(o.rotation)).asArray():a.Quaternion.FromArray([0,1,0,0]).asArray()),u.nodes.push(r);if(d instanceof a.Mesh){var m=d;m.skeleton&&(o.skin=e[m.skeleton.uniqueId])}if(i=d.getDescendants(!0),!o.children&&i&&i.length){for(var g=[],_=0,x=i;_<x.length;_++){var y=x[_];null!=s._nodeMap[y.uniqueId]&&g.push(s._nodeMap[y.uniqueId])}g.length&&(o.children=g)}}}u.nodes.length&&s._scenes.push(u)}))}))}))},e.prototype.getExportNodes=function(e){for(var t=[],r=new Set,n=0,a=e;n<a.length;n++){var o=a[n];if(!this._options.shouldExportNode||this._options.shouldExportNode(o))if(t.push(o),"Mesh"===o.getClassName())(u=o).material&&r.add(u.material);else for(var i=0,s=o.getChildMeshes(!1);i<s.length;i++){var u;(u=s[i]).material&&r.add(u.material)}else"Excluding node ".concat(o.name)}return[t,r]},e.prototype.createNodeMapAndAnimationsAsync=function(e,t,r){for(var n,o=this,i=Promise.resolve(),s={},l={name:"runtime animations",channels:[],samplers:[]},c=[],f=function(t){i=i.then((function(){var i=o._convertToRightHandedSystemMap[t.uniqueId];return o.createNodeAsync(t,r,i,s).then((function(f){var h=o._extensionsPostExportNodeAsync("createNodeAsync",f,t,s);return null==h?(a.Tools.Warn("Not exporting node ".concat(t.name)),Promise.resolve()):h.then((function(a){a&&(o._nodes.push(a),n=o._nodes.length-1,s[t.uniqueId]=n,e.animationGroups.length||(u.a._CreateMorphTargetAnimationFromMorphTargetAnimations(t,l,c,s,o._nodes,r,o._bufferViews,o._accessors,i,o._animationSampleRate),t.animations.length&&u.a._CreateNodeAnimationFromNodeAnimations(t,l,c,s,o._nodes,r,o._bufferViews,o._accessors,i,o._animationSampleRate)))}))}))}))},h=0,p=t;h<p.length;h++){f(p[h])}return i.then((function(){return l.channels.length&&l.samplers.length&&o._animations.push(l),c.forEach((function(e){e.channels.length&&e.samplers.length&&o._animations.push(e)})),e.animationGroups.length&&u.a._CreateNodeAndMorphAnimationFromAnimationGroups(e,o._animations,s,o._nodes,r,o._bufferViews,o._accessors,o._convertToRightHandedSystemMap,o._animationSampleRate),s}))},e.prototype.createNodeAsync=function(e,t,r,n){var o=this;return Promise.resolve().then((function(){var n={},i={primitives:[]};if(e.name&&(n.name=e.name),e instanceof a.TransformNode){if(o.setNodeTransformation(n,e,r),e instanceof a.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 o.setPrimitiveAttributesAsync(i,e,t,r).then((function(){return i.primitives.length&&(o._meshes.push(i),n.mesh=o._meshes.length-1),n}))}return e instanceof a.Camera?(o.setCameraTransformation(n,e,r),n):n}))},e.prototype.createSkinsAsync=function(e,t,r){for(var n,o=Promise.resolve(),s={},u=0,l=e.skeletons;u<l.length;u++){for(var c=l[u],f={joints:[]},h=[],p={},d=-1,m=0;m<c.bones.length;++m){-1!==(g=null!==(n=(_=c.bones[m]).getIndex())&&void 0!==n?n:m)&&(p[g]=_,g>d&&(d=g))}for(var g=0;g<=d;++g){var _=p[g];h.push(_.getInvertedAbsoluteTransform());var x=_.getTransformNode();x?f.joints.push(t[x.uniqueId]):a.Tools.Warn("Exporting a bone without a linked transform node is currently unsupported")}var y=64*h.length,T=r.getByteOffset(),v=i.a._CreateBufferView(0,T,y,void 0,"InverseBindMatrices - "+c.name);this._bufferViews.push(v);var b=this._bufferViews.length-1,A=i.a._CreateAccessor(b,"InverseBindMatrices - "+c.name,"MAT4",5126,h.length,null,null,null),F=this._accessors.push(A)-1;f.inverseBindMatrices=F,this._skins.push(f),s[c.uniqueId]=this._skins.length-1,h.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))}return o.then((function(){return s}))},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),a=0,o=n.byteLength;a<o;++a)n[a]=r[a];return this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer),t},e.prototype.getArrayBuffer=function(){return this.resizeBuffer(this.getByteOffset())},e.prototype.getByteOffset=function(){if(null==this._byteOffset)throw new Error("Byte offset is undefined!");return this._byteOffset},e.prototype.setUInt8=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint8(t,e):a.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):a.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 a.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?a.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?a.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?a.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?a.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)&&a.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):a.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):a.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 a})),r.d(t,"c",(function(){return o}));function n(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function a(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],n=0}finally{r=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}Object.create;function o(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}Object.create},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")||e(t,".jpg")?a={type:"image/jpeg"}:e(t,".png")&&(a={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],a)),r.click()}},e}()},function(e,t,r){"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 a}));var n=r(0),a=function(){function e(){}return e.OBJ=function(e,t,r,a){var o=[],i=1,s=1;t&&(r||(r="mat"),o.push("mtllib "+r+".mtl"));for(var u=0;u<e.length;u++){o.push("g object"+u),o.push("o object_"+u);var l=null;if(a){var c=e[u].computeWorldMatrix(!0);l=new n.Matrix,c.invertToRef(l),e[u].bakeTransformIntoVertices(c)}if(t){var f=e[u].material;f&&o.push("usemtl "+f.id)}var h=e[u].geometry;if(h){var p=h.getVerticesData("position"),d=h.getVerticesData("normal"),m=h.getVerticesData("uv"),g=h.getIndices(),_=0,x=0;if(p&&g){for(var y=0;y<p.length;y+=3)e[0].getScene().useRightHandedSystem?o.push("v "+p[y]+" "+p[y+1]+" "+p[y+2]):o.push("v "+p[y]+" "+p[y+1]+" "+-p[y+2]),_++;if(null!=d)for(y=0;y<d.length;y+=3)o.push("vn "+d[y]+" "+d[y+1]+" "+d[y+2]);if(null!=m)for(y=0;y<m.length;y+=2)o.push("vt "+m[y]+" "+m[y+1]),x++;for(y=0;y<g.length;y+=3){var T=[String(g[y+2]+i),String(g[y+1]+i),String(g[y]+i)],v=[String(g[y+2]+s),String(g[y+1]+s),String(g[y]+s)],b=["","",""],A=T,F=null!=m?v:b,E=null!=d?T:b;o.push("f "+A[0]+"/"+F[0]+"/"+E[0]+" "+A[1]+"/"+F[1]+"/"+E[1]+" "+A[2]+"/"+F[2]+"/"+E[2])}a&&l&&e[u].bakeTransformIntoVertices(l),i+=_,s+=x}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 o.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 a.GLTFData})),r.d(t,"_Exporter",(function(){return o.b})),r.d(t,"_BinaryWriter",(function(){return o.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_clearcoat",(function(){return c.KHR_materials_clearcoat})),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),a=r(4),o=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,a=r(0),o=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,o,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,o,i):"LINEAR"===d||"STEP"===d?e._CreateLinearOrStepAnimation(t,r,n,p,u,l,o,i):"CUBICSPLINE"===d?e._CreateCubicSplineAnimation(t,r,n,p,u,l,o,i):e._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,u,l,f,o,i),u.length&&l.length?{inputs:u,outputs:l,samplerInterpolation:d,inputsMin:m?f.min:a.Tools.FloatRound(f.min/r.framePerSecond),inputsMax:m?f.max:a.Tools.FloatRound(f.max/r.framePerSecond)}:null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,o=e.targetProperty.split(".");switch(o[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:a.Tools.Error("Unsupported animatable property ".concat(o[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,o,i,s,u,l,c,f){var h;if(t instanceof a.TransformNode&&t.animations)for(var p=0,d=t.animations;p<d.length;p++){var m=d[p],g=e._DeduceAnimationInfo(m);g&&(h={name:m.name,samplers:[],channels:[]},e.AddAnimation("".concat(m.name),m.hasRunningRuntimeAnimations?r:h,t,m,g.dataAccessorType,g.animationChannelTargetPath,o,s,u,l,c,g.useQuaternion,f),h.samplers.length&&h.channels.length&&n.push(h))}},e._CreateMorphTargetAnimationFromMorphTargetAnimations=function(t,r,n,o,i,s,u,l,c,f){var h;if(t instanceof a.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 a.Animation("".concat(_.name),"influence",_.framePerSecond,_.dataType,_.loopMode,_.enableBlending),y=[],T=_.getKeys(),v=0;v<T.length;++v)for(var b=T[v],A=0;A<p.numTargets;++A)A==d?y.push(b):y.push({frame:b.frame,value:0});x.setKeys(y);var F=e._DeduceAnimationInfo(x);F&&(h={name:x.name,samplers:[],channels:[]},e.AddAnimation(_.name,_.hasRunningRuntimeAnimations?r:h,t,x,F.dataAccessorType,F.animationChannelTargetPath,o,s,u,l,c,F.useQuaternion,f,p.numTargets),h.samplers.length&&h.channels.length&&n.push(h))}}},e._CreateNodeAndMorphAnimationFromAnimationGroups=function(t,r,n,o,i,s,u,l,c){var f,h;if(t.animationGroups)for(var p=function(o){var p=new Map,d=new Map,m=new Set,g=o.to-o.from;h={name:o.name,channels:[],samplers:[]};for(var _=function(r){var g=o.targetedAnimations[r],_=g.target,x=g.animation;if(_ instanceof a.TransformNode||1===_.length&&_[0]instanceof a.TransformNode){if(v=e._DeduceAnimationInfo(g.animation)){var y=_ instanceof a.TransformNode?_:_[0],T=l[y.uniqueId];e.AddAnimation("".concat(x.name),h,y,x,v.dataAccessorType,v.animationChannelTargetPath,n,i,s,u,T,v.useQuaternion,c)}}else if(_ instanceof a.MorphTarget||1===_.length&&_[0]instanceof a.MorphTarget){var v;if(v=e._DeduceAnimationInfo(g.animation)){var b=_ instanceof a.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<o.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 a.Animation("".concat(o.name,"_").concat(t.name,"_MorphWeightAnimation"),"influence",b.framePerSecond,a.Animation.ANIMATIONTYPE_FLOAT,b.loopMode,b.enableBlending)),f.push(b.getKeys()[x])):f.push({frame:o.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("".concat(o.name,"_").concat(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,a,i,s,u,l,c,f,h,p,d,m){var g,_,x,y,T,v,b,A=e._CreateNodeAnimation(n,a,s,h,p,d);if(A){if(m){for(var F=0,E=0,M=[];A.inputs.length>0;)E=A.inputs.shift(),F%m==0&&M.push(E),F++;A.inputs=M}var R=u[n.uniqueId],C=4*A.inputs.length;g=o.a._CreateBufferView(0,l.getByteOffset(),C,void 0,"".concat(t," keyframe data view")),c.push(g),A.inputs.forEach((function(e){l.setFloat32(e)})),_=o.a._CreateAccessor(c.length-1,"".concat(t," keyframes"),"SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),f.push(_),x=f.length-1,T=A.outputs.length,C=4*o.a._GetDataAccessorElementCount(i)*A.outputs.length,g=o.a._CreateBufferView(0,l.getByteOffset(),C,void 0,"".concat(t," data view")),c.push(g),A.outputs.forEach((function(e){e.forEach((function(e){l.setFloat32(e)}))})),_=o.a._CreateAccessor(c.length-1,"".concat(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,o,i,s,u,l,c,f,h,p){var d,m,g=a.Quaternion.Identity(),_=null,x=null,y=null,T=null,v=null,b=null;f.min=a.Tools.FloatRound(o/s);for(var A=r.getKeys(),F=0,E=A.length;F<E;++F){if(b=null,y=A[F],F+1<E)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 M=y.frame;M<=b;M+=u)if((m=a.Tools.FloatRound(M/s))!==_){_=m,x=m;var R={key:0,repeatCount:0,loopMode:r.loopMode};d=r._interpolate(M,R),e._SetInterpolatedValue(t,d,m,r,n,g,l,c,h,p)}}x&&(f.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,o,i,s,u){var l,c,f=null,h=e._GetBasePositionRotationOrScale(r,i,s,u);if(o===a.Animation.ANIMATIONTYPE_FLOAT)switch(c=(l=n.targetProperty.split("."))?l[1]:"",f=u?a.Quaternion.FromArray(h).normalize():a.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:a.Tools.Error('glTFAnimation: Unsupported component type "'.concat(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 a.TransformNode&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,p,i,c,f)),t&&("rotation"===i?(f?s=t:(h=t,a.Quaternion.RotationYawPitchRollToRef(h.y,h.x,h.z,s)),c&&(o.a._GetRightHandedQuaternionFromRef(s),e.parent||(s=a.Quaternion.FromArray([0,1,0,0]).multiply(s))),l.push(s.asArray())):"weights"===i?l.push([t]):(h=t,c&&"scale"!==i&&(o.a._GetRightHandedPositionVector3FromRef(h),e.parent||(h.x*=-1,h.z*=-1)),l.push(h.asArray())))},e._CreateLinearOrStepAnimation=function(t,r,n,a,o,i,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];o.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,i,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,a,o,i,s,u,l){r.getKeys().forEach((function(c){i.push(c.frame/r.framePerSecond),e.AddSplineTangent(t,n.INTANGENT,s,a,"CUBICSPLINE",c,o,l,u),e._AddKeyframeValue(c,r,s,a,t,u,l),e.AddSplineTangent(t,n.OUTTANGENT,s,a,"CUBICSPLINE",c,o,l,u)}))},e._GetBasePositionRotationOrScale=function(e,t,r,n){var i;return"rotation"===t?n?e.rotationQuaternion?(i=e.rotationQuaternion.asArray(),r&&(o.a._GetRightHandedQuaternionArrayFromRef(i),e.parent||(i=a.Quaternion.FromArray([0,1,0,0]).multiply(a.Quaternion.FromArray(i)).asArray()))):i=a.Quaternion.Identity().asArray():(i=e.rotation.asArray(),o.a._GetRightHandedNormalArray3FromRef(i)):"translation"===t?(i=e.position.asArray(),r&&o.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===a.Animation.ANIMATIONTYPE_VECTOR3){if(l=e.value.asArray(),"rotation"===n){var h=a.Vector3.FromArray(l),p=a.Quaternion.RotationYawPitchRoll(h.y,h.x,h.z);s&&(o.a._GetRightHandedQuaternionFromRef(p),i.parent||(p=a.Quaternion.FromArray([0,1,0,0]).multiply(p))),l=p.asArray()}else"translation"===n&&s&&(o.a._GetRightHandedNormalArray3FromRef(l),i.parent||(l[0]*=-1,l[2]*=-1));r.push(l)}else if(f===a.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:a.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).normalize();s&&(o.a._GetRightHandedQuaternionFromRef(d),i.parent||(d=a.Quaternion.FromArray([0,1,0,0]).multiply(d))),r.push(d.asArray())}else"translation"===n&&s&&(o.a._GetRightHandedNormalVector3FromRef(c),i.parent||(c.x*=-1,c.z*=-1));r.push(c.asArray())}}else f===a.Animation.ANIMATIONTYPE_QUATERNION?(l=e.value.normalize().asArray(),s&&(o.a._GetRightHandedQuaternionArrayFromRef(l),i.parent||(l=a.Quaternion.FromArray([0,1,0,0]).multiply(a.Quaternion.FromArray(l)).asArray())),r.push(l)):a.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,o,i=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,u=e.length;s<u;++s)if((o=e[s]).inTangent||o.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",i=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||o.interpolation&&o.interpolation===a.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",i=!0;break}}else n=o.interpolation&&o.interpolation===a.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=a.Quaternion.RotationYawPitchRoll(d.y,d.x,d.z).asArray()}f&&(o.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"weights"===i?h=p?[p]:[0]:p?(h=p.asArray(),f&&"translation"===i&&(o.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 o=t.replace(/\.[^/.]+$/,"");return new n.b(e,r)._generateGLBAsync(o).then((function(t){return a._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_clearcoat",(function(){return c})),r.d(t,"KHR_materials_sheen",(function(){return f})),r.d(t,"KHR_materials_unlit",(function(){return h}));var n=r(0),a=r(2),o="precision highp float;\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 textureTransformMat;\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\nvec2 uvTransformed=(textureTransformMat*vec4(vUV.xy,1,1)).xy;\ngl_FragColor=texture2D(textureSampler,uvTransformed);\n#define CUSTOM_FRAGMENT_MAIN_END\n}";n.ShaderStore.ShadersStore.textureTransformPixelShader=o;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={},a=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],a=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],a=!0),0!==r.wAng&&(n.rotation=r.wAng,a=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,a=!0),!a)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[i]=n}},e.prototype.preExportTextureAsync=function(e,t,r){var n=this;return new Promise((function(r,a){var o=t.getScene();if(o){var i=!1;if(0===t.uAng&&0===t.wAng&&0===t.vAng||0===t.uRotationCenter&&0===t.vRotationCenter||(i=!0),i)return n._textureTransformTextureAsync(t,o).then((function(e){r(e)})).catch((function(e){a(e)}));r(t)}else a("".concat(e,': "scene" is not defined for Babylon texture ').concat(t.name,"!"))}))},e.prototype._textureTransformTextureAsync=function(e,t){var r=this;return new Promise((function(a){var o=new n.ProceduralTexture("".concat(e.name),e.getSize(),"textureTransform",t);o||(n.Tools.Log("Cannot create procedural texture for ".concat(e.name,"!")),a(e)),o.reservedDataStore={hidden:!0,source:e},r._recordedTextures.push(o),o.coordinatesIndex=e.coordinatesIndex,o.setTexture("textureSampler",e),o.setMatrix("textureTransformMat",e.getTextureMatrix()),o.isReady()?(o.render(),a(o)):o.getEffect().executeWhenCompiled((function(){o.render(),a(o)}))}))},e}();a.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,a){var o=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("".concat(e,": Light ").concat(l.name," is not supported in ").concat("KHR_lights_punctual"));else{var h=l.position.clone(),p=o._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*(o._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("".concat(e,": Light falloff for ").concat(l.name," does not match the ").concat("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==o._lights&&(o._lights={lights:[]}),o._lights.lights.push(c);var T={light:o._lights.lights.length-1},v=r.parent;if(v&&1==v.getChildren().length){var b=o._exporter._nodes[a[v.uniqueId]];if(b){var A=n.TmpVectors.Matrix[0],F=n.TmpVectors.Matrix[1],E=b.translation?new n.Vector3(b.translation[0],b.translation[1],b.translation[2]):n.Vector3.Zero(),M=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,M,E,A),A.invertToRef(F);var C=n.TmpVectors.Matrix[2],V=t.translation?new n.Vector3(t.translation[0],t.translation[1],t.translation[2]):n.Vector3.Zero();l instanceof n.DirectionalLight&&V.subtractInPlace(o._exporter._babylonScene.useRightHandedSystem?l.direction:u.a._GetRightHandedPositionVector3(l.direction));var w=o._exporter._babylonScene.useRightHandedSystem?n.Quaternion.Identity():new n.Quaternion(0,1,0,0);t.rotation&&w.multiplyInPlace(new n.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var S=t.scale?new n.Vector3(t.scale[0],t.scale[1],t.scale[2]):n.Vector3.One();n.Matrix.ComposeToRef(S,w,V,C),C.multiplyToRef(F,C);var B=n.TmpVectors.Vector3[0],I=n.TmpVectors.Quaternion[0],P=n.TmpVectors.Vector3[1];return C.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}();a.b.RegisterExtension("KHR_lights_punctual",(function(e){return new l(e)}));var c=function(){function e(e){this.name="KHR_materials_clearcoat",this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){var a=[];return r instanceof n.PBRBaseMaterial&&r.clearCoat.isEnabled?(r.clearCoat.texture&&a.push(r.clearCoat.texture),!r.clearCoat.useRoughnessFromMainTexture&&r.clearCoat.textureRoughness&&a.push(r.clearCoat.textureRoughness),r.clearCoat.bumpTexture&&a.push(r.clearCoat.bumpTexture),a):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var a=this;return new Promise((function(e,o){if(r instanceof n.PBRBaseMaterial){if(!r.clearCoat.isEnabled)return void e(t);a._wasUsed=!0,t.extensions=t.extensions||{};var i=a._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture),s=void 0;s=r.clearCoat.useRoughnessFromMainTexture?a._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.texture):a._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.textureRoughness),r.clearCoat.isTintEnabled&&n.Tools.Warn("Clear Color tint is not supported for glTF export. Ignoring for: ".concat(r.name)),r.clearCoat.remapF0OnInterfaceChange&&n.Tools.Warn("Clear Color F0 remapping is not supported for glTF export. Ignoring for: ".concat(r.name));var u=a._exporter._glTFMaterialExporter._getTextureInfo(r.clearCoat.bumpTexture),l={clearcoatFactor:r.clearCoat.intensity,clearcoatTexture:null!=i?i:void 0,clearcoatRoughnessFactor:r.clearCoat.roughness,clearcoatRoughnessTexture:null!=s?s:void 0,clearcoatNormalTexture:null!=u?u:void 0,hasTextures:function(){return null!==l.clearcoatTexture||null!==l.clearcoatRoughnessTexture||null!==l.clearcoatRoughnessTexture}};t.extensions.KHR_materials_clearcoat=l}e(t)}))},e}();a.b.RegisterExtension("KHR_materials_clearcoat",(function(e){return new c(e)}));var f=function(){function e(e){this.name="KHR_materials_sheen",this.enabled=!0,this.required=!1,this._wasUsed=!1,this._exporter=e}return e.prototype.dispose=function(){},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof n.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?[r.sheen.texture]:[]},e.prototype.postExportMaterialAsync=function(e,t,r){var a=this;return new Promise((function(e,o){var i,s,u,l;if(r instanceof n.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);a._wasUsed=!0,null==t.extensions&&(t.extensions={});var c={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=r.sheen.roughness)&&void 0!==i?i:0,hasTextures:function(){return null!==c.sheenColorTexture||null!==c.sheenRoughnessTexture}};r.sheen.texture&&(c.sheenColorTexture=null!==(s=a._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==s?s:void 0),r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture?c.sheenRoughnessTexture=null!==(u=a._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.textureRoughness))&&void 0!==u?u:void 0:r.sheen.texture&&r.sheen.useRoughnessFromMainTexture&&(c.sheenRoughnessTexture=null!==(l=a._exporter._glTFMaterialExporter._getTextureInfo(r.sheen.texture))&&void 0!==l?l:void 0),t.extensions.KHR_materials_sheen=c}e(t)}))},e}();a.b.RegisterExtension("KHR_materials_sheen",(function(e){return new f(e)}));var h=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 a=this;return new Promise((function(e,o){var i=!1;r instanceof n.PBRMaterial?i=r.unlit:r instanceof n.StandardMaterial&&(i=r.disableLighting),i&&(a._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions.KHR_materials_unlit={}),e(t)}))},e}();a.b.RegisterExtension("KHR_materials_unlit",(function(e){return new h(e)}))},function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));var n=r(3),a=r(0),o=function(){function e(e){this._textureMap={},this._textureMap={},this._exporter=e}return e.FuzzyEquals=function(e,t,r){return a.Scalar.WithinEpsilon(e.r,t.r,r)&&a.Scalar.WithinEpsilon(e.g,t.g,r)&&a.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){var n=this,o=[];return e.forEach((function(e){"StandardMaterial"===e.getClassName()?o.push(n._convertStandardMaterialAsync(e,t,r)):-1!==e.getClassName().indexOf("PBR")?o.push(n._convertPBRMaterialAsync(e,t,r)):a.Tools.Warn("Unsupported material type: ".concat(e.name))})),Promise.all(o).then((function(){}))},e.prototype._stripTexturesFromMaterial=function(e){var t={};if(e){t.name=e.name,t.doubleSided=e.doubleSided,t.alphaMode=e.alphaMode,t.alphaCutoff=e.alphaCutoff,t.emissiveFactor=e.emissiveFactor;var r=e.pbrMetallicRoughness;r&&(t.pbrMetallicRoughness={},t.pbrMetallicRoughness.baseColorFactor=r.baseColorFactor,t.pbrMetallicRoughness.metallicFactor=r.metallicFactor,t.pbrMetallicRoughness.roughnessFactor=r.roughnessFactor)}return t},e.prototype._hasTexturesPresent=function(e){var t;if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var r=e.pbrMetallicRoughness;if(r&&(r.baseColorTexture||r.metallicRoughnessTexture))return!0;if(e.extensions)for(var n in e.extensions){var a=e.extensions[n];if(a)return null===(t=a.hasTextures)||void 0===t?void 0:t.call(a)}return!1},e.prototype._getTextureInfo=function(e){if(e){var t=e.uid;if(t in this._textureMap)return this._textureMap[t]}return null},e.prototype._convertToGLTFPBRMetallicRoughness=function(t){var r=new a.Vector2(0,1),n=new a.Vector2(0,.1),o=new a.Vector2(0,.1),i=new a.Vector2(1300,.1);var s=t.diffuseColor.toLinearSpace().scale(.5),u=t.alpha,l=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/i.x,.333333),r.y,n.y,o.y,i.y)}(a.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,o=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,i=o*o-4*n*(this._DielectricSpecular.r-t);return a.Scalar.Clamp((-o+Math.sqrt(i))/(2*n),0,1)},e._SetAlphaMode=function(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)},e.prototype._convertStandardMaterialAsync=function(t,r,n){var o=this._exporter._materialMap,i=this._exporter._materials,s=[],u=this._convertToGLTFPBRMetallicRoughness(t),l={name:t.name};return null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||a.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===a.Constants.ALPHA_COMBINE?l.alphaMode="BLEND":a.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e.FuzzyEquals(t.emissiveColor,a.Color3.Black(),e._Epsilon)&&(l.emissiveFactor=t.emissiveColor.asArray()),l.pbrMetallicRoughness=u,e._SetAlphaMode(l,t),i.push(l),o[t.uniqueId]=i.length-1,this._finishMaterial(s,l,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var a=this;return Promise.all(e).then((function(){for(var e=null,o=0,i=a._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);o<i.length;o++){var s=i[o];e||(e=[]),e.push(a._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then((function(){var e=a._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then((function(){return t})):t}))}))},e.prototype._convertPBRMetallicRoughnessMaterialAsync=function(t,r,n){var o=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,a.Color3.Black(),e._Epsilon)&&(l.emissiveFactor=t.emissiveColor.asArray()),l.pbrMetallicRoughness=u,i.push(l),o[t.uniqueId]=i.length-1,this._finishMaterial(s,l,t,r)},e.prototype._createBase64FromCanvasAsync=function(e,t,r,o){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=a.Constants.TEXTURETYPE_UNSIGNED_INT,u=this._exporter._babylonScene,l=u.getEngine(),c=l.createRawTexture(e,t,r,a.Constants.TEXTUREFORMAT_RGBA,!1,!0,a.Texture.NEAREST_SAMPLINGMODE,null,i),[4,a.TextureTools.ApplyPostProcess("pass",c,u,i,a.Constants.TEXTURE_NEAREST_SAMPLINGMODE,a.Constants.TEXTUREFORMAT_RGBA)];case 1:return n.sent(),[4,l._readTexturePixels(c,t,r)];case 2:return f=n.sent(),[4,a.Tools.DumpDataAsync(t,r,f,o,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),o=0;o<n.length;o+=4)n[o]=n[o+1]=n[o+2]=n[o+3]=255;return a.RawTexture.CreateRGBATexture(n,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,o,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 a.Texture?a.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):this._createWhiteTexture(s.width,s.height,r),o=t):i.width>s.width?(o=t&&t instanceof a.Texture?a.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):this._createWhiteTexture(i.width,i.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertPixelArrayToFloat32=function(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(t,r,o,i){var s;return Object(n.a)(this,void 0,void 0,(function(){var u,l,c,f,h,p,d,m,g,_,x,y,T,v,b,A,F,E,M,R,C,V,w,S,B,I,P,N,L,O,G,K;return Object(n.b)(this,(function(n){switch(n.label){case 0:return u=[],t||r?(l=t?t.getScene():r?r.getScene():null)?(c=this._resizeTexturesToSameDimensions(t,r,l),f=null===(s=c.texture1)||void 0===s?void 0:s.getSize(),h=void 0,p=void 0,d=f.width,m=f.height,[4,c.texture1.readPixels()]):[3,3]:[2,Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!")];case 1:return g=n.sent(),[4,c.texture2.readPixels()];case 2:if(_=n.sent(),!g)return[2,Promise.reject("Failed to retrieve pixels from diffuse texture!")];if(h=this._convertPixelArrayToFloat32(g),!_)return[2,Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];for(p=this._convertPixelArrayToFloat32(_),x=p.byteLength,y=new Uint8Array(x),T=new Uint8Array(x),4,v=a.Color3.Black(),b=0,A=0,I=0;I<m;++I)for(P=0;P<d;++P)F=4*(d*I+P),E=new a.Color3(h[F],h[F+1],h[F+2]).toLinearSpace().multiply(o.diffuseColor),M=new a.Color3(p[F],p[F+1],p[F+2]).toLinearSpace().multiply(o.specularColor),R=p[F+3]*o.glossiness,C={diffuseColor:E,specularColor:M,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(C),v.r=Math.max(v.r,V.baseColor.r),v.g=Math.max(v.g,V.baseColor.g),v.b=Math.max(v.b,V.baseColor.b),b=Math.max(b,V.metallic),A=Math.max(A,V.roughness),T[F]=255*V.baseColor.r,T[F+1]=255*V.baseColor.g,T[F+2]=255*V.baseColor.b,T[F+3]=c.texture1.hasAlpha?255*h[F+3]:255,y[F]=0,y[F+1]=255*V.roughness,y[F+2]=255*V.metallic,y[F+3]=255;for(w={baseColor:v,metallic:b,roughness:A},S=!1,B=!1,I=0;I<m;++I)for(P=0;P<d;++P)T[N=4*(d*I+P)]/=w.baseColor.r>e._Epsilon?w.baseColor.r:1,T[N+1]/=w.baseColor.g>e._Epsilon?w.baseColor.g:1,T[N+2]/=w.baseColor.b>e._Epsilon?w.baseColor.b:1,L=a.Color3.FromInts(T[N],T[N+1],T[N+2]),O=L.toGammaSpace(),T[N]=255*O.r,T[N+1]=255*O.g,T[N+2]=255*O.b,e.FuzzyEquals(O,a.Color3.White(),e._Epsilon)||(B=!0),y[N+1]/=w.roughness>e._Epsilon?w.roughness:1,y[N+2]/=w.metallic>e._Epsilon?w.metallic:1,G=a.Color3.FromInts(255,y[N+1],y[N+2]),e.FuzzyEquals(G,a.Color3.White(),e._Epsilon)||(S=!0);return S&&(K=this._createBase64FromCanvasAsync(y,d,m,i).then((function(e){w.metallicRoughnessTextureBase64=e})),u.push(K)),B&&(K=this._createBase64FromCanvasAsync(T,d,m,i).then((function(e){w.baseColorTextureBase64=e})),u.push(K)),[2,Promise.all(u).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),o=1-this._getMaxComponent(t.specularColor),i=e._SolveMetallic(r,n,o),s=t.diffuseColor.scale(o/(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=a.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 a=[],o={baseColor:e._albedoColor,metallic:e._metallic,roughness:e._roughness};if(n){e._albedoTexture&&a.push(this._exportTextureAsync(e._albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var i=e._metallicTexture;i&&a.push(this._exportTextureAsync(i,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(a).then((function(){return o}))},e.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof a.Texture?e.samplingMode:null;if(null!=r)switch(r){case a.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case a.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case a.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case a.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case a.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case a.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case a.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case a.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case a.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case a.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case a.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case a.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case a.Texture.WRAP_ADDRESSMODE:return 10497;case a.Texture.CLAMP_ADDRESSMODE:return 33071;case a.Texture.MIRROR_ADDRESSMODE:return 33648;default:return a.Tools.Error("Unsupported Texture Wrap Mode ".concat(e,"!")),10497}},e.prototype._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof a.Texture?e.wrapU:a.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof a.Texture?e.wrapV:a.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){var a=this;return Promise.resolve().then((function(){var o=a._exporter._samplers,i=a._exporter._textures,s={diffuseColor:e._albedoColor,specularColor:e._reflectivityColor,glossiness:e._microSurface},u=null,l=e._albedoTexture,c=e._reflectivityTexture;if(l){var f=a._getGLTFTextureSampler(l);null!=f.magFilter&&null!=f.minFilter&&null!=f.wrapS&&null!=f.wrapT&&(o.push(f),u=o.length-1)}var h=e._useMicroSurfaceFromReflectivityMapAlpha;return c&&!h?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(l||c)&&n?a._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(l,c,s,t).then((function(e){if(e.baseColorTextureBase64){var n=a._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+i.length+".png",t,l?l.coordinatesIndex:null,u);n&&(r.baseColorTexture=n)}if(e.metallicRoughnessTextureBase64){var o=a._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+i.length+".png",t,c?c.coordinatesIndex:null,u);o&&(r.metallicRoughnessTexture=o)}return e})):a._convertSpecularGlossinessToMetallicRoughness(s)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,a={},o={name:e.name};if(e.isMetallicWorkflow()){var i=e._albedoColor,s=e.alpha;return i&&(a.baseColorFactor=[i.r,i.g,i.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(i){return n.setMetallicRoughnessPbrMaterial(i,e,o,a,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(i){return n.setMetallicRoughnessPbrMaterial(i,e,o,a,t,r)}))},e.prototype.setMetallicRoughnessPbrMaterial=function(t,r,n,o,i,s){var u=this._exporter._materialMap,l=this._exporter._materials,c=[];if(t){if(e._SetAlphaMode(n,r),e.FuzzyEquals(t.baseColor,a.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(o.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(o.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(o.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r._twoSidedLighting||a.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;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;if(p){h=this._exportTextureAsync(p,i).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord};n.occlusionTexture=t;var a=r._ambientTextureStrength;a&&(t.strength=a)}}));c.push(h)}var d=r._emissiveTexture;if(d){h=this._exportTextureAsync(d,i).then((function(e){e&&(n.emissiveTexture=e)}));c.push(h)}}var m=r._emissiveColor;e.FuzzyEquals(m,a.Color3.Black(),e._Epsilon)||(n.emissiveFactor=m.asArray()),n.pbrMetallicRoughness=o,l.push(n),u[r.uniqueId]=l.length-1}return this._finishMaterial(c,n,r,i)},e.prototype.getPixelsFromTexture=function(e){return e.textureType,a.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,a,o,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(!(a=n.sent()))return[2,null];for(o=this._exporter._samplers,i=this._getGLTFTextureSampler(e),s=null,u=null,l=0;l<o.length;++l)if((c=o[l]).minFilter===i.minFilter&&c.magFilter===i.magFilter&&c.wrapS===i.wrapS&&c.wrapT===i.wrapT){u=l;break}if(null==u?(o.push(i),s=o.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(a,f.width,f.height,t).then((function(n){var a=h._getTextureInfoFromBase64(n,e.name.replace(/\.\/|\/|\.\\|\\/g,"_"),t,e.coordinatesIndex,s);return a&&(h._textureMap[r]=a,h._exporter._extensionsPostExportTextures("linkTextureInfo",a,e)),a}))]}}))}))}))},e.prototype._getTextureInfoFromBase64=function(e,t,r,n,o){var i=this._exporter._textures,s=this._exporter._images,u=this._exporter._imageData,l=null,c={source:s.length,name:t};null!=o&&(c.sampler=o);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="".concat(t,"_").concat(a.Tools.RandomId()).concat(_)),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 a.Tools.Error("Unsupported texture mime type ".concat(r));return l},e._DielectricSpecular=new a.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 a}));var n=r(0),a=function(){function e(){}return e.CreateSTL=function(e,t,r,a,o,i){void 0===t&&(t=!0),void 0===r&&(r="stlmesh"),void 0===a&&(a=!1),void 0===o&&(o=!0),void 0===i&&(i=!1);var s,u=function(e,t,r){var a=[3*e[r],3*e[r+1],3*e[r+2]],o=[new n.Vector3(t[a[0]],t[a[0]+2],t[a[0]+1]),new n.Vector3(t[a[1]],t[a[1]+2],t[a[1]+1]),new n.Vector3(t[a[2]],t[a[2]+2],t[a[2]+1])],i=o[0].subtract(o[1]),s=o[2].subtract(o[1]);return{v:o,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(a){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,o),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);a?(h=l(s,h,y.n,o),h=l(s,h,y.v[0],o),h=l(s,h,y.v[1],o),h=l(s,h,y.v[2],o),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(a||(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),a=r(4),o=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_clearcoat",(function(){return s.KHR_materials_clearcoat})),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 a)l[f]=a[f],c.push(f);for(var f in o)l[f]=o[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 a=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==a)for(var o in n)a.BABYLON[o]=n[o]}.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 a=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==a)for(var o in n)a.BABYLON[o]=n[o]}).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_clearcoat",(function(){return n.KHR_materials_clearcoat})),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 a.OBJExport})),r.d(t,"STLExport",(function(){return o.a}));r(6),r(5),r(7),r(13);var n=r(14),a=r(15),o=r(16)}])})); |