var BABYLON;!(function(i){var e=(function(){function e(){}return e.GLTFAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var e=r.replace(/\.[^/.]+$/,"");return new i.GLTF2._Exporter(t,a)._generateGLTFAsync(e)}))},e.GLBAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var e=r.replace(/\.[^/.]+$/,"");return new i.GLTF2._Exporter(t,a)._generateGLBAsync(e)}))},e})();i.GLTF2Export=e})(BABYLON||(BABYLON={})),(function(z){!(function(K){var e=(function(){function e(e,t){this._asset={generator:"BabylonJS",version:"2.0"},this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._animations=[],this._imageData={},this._convertToRightHandedSystem=!this._babylonScene.useRightHandedSystem;var r=t||{};this._shouldExportTransformNode=r.shouldExportTransformNode?r.shouldExportTransformNode:function(e){return!0},this._animationSampleRate=r.animationSampleRate?r.animationSampleRate:1/60,this._glTFMaterialExporter=new K._GLTFMaterialExporter(this)}return e.prototype._getLocalEngine=function(){if(!this._localEngine){var e=document.createElement("canvas");e.id="WriteCanvas",e.width=2048,e.height=2048,this._localEngine=new z.Engine(e,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!0}),this._localEngine.setViewport(new z.Viewport(0,0,1,1))}return this._localEngine},e.prototype.reorderIndicesBasedOnPrimitiveMode=function(e,t,r,a,i){switch(t){case z.Material.TriangleFillMode:a||(a=0);for(var n=e.indexStart,o=e.indexStart+e.indexCount;n=e.verticesStart;--h)c=h*l,u.push(z.Vector4.FromArray(i,c));break;case z.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)c=h*l,4===s.getSize()?u.push(z.Vector4.FromArray(i,c)):u.push(z.Vector3.FromArray(i,c));break;case z.VertexBuffer.UVKind:case z.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)c=h*l,u.push(z.Vector2.FromArray(i,c));break;default:z.Tools.Error("Unsupported Vertex Buffer type: "+a)}this.writeVertexAttributeData(u,n+12,a,i,o)}else z.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+a+" not present!")},e.prototype.reorderTriangleFanMode=function(e,t,r,a,i,n,o){var s=this.getVertexBufferFromMesh(a,e.getMesh());if(s){var l=s.byteStride/z.VertexBuffer.GetTypeByteLength(s.type),u=[],c=0;switch(a){case z.VertexBuffer.PositionKind:case z.VertexBuffer.NormalKind:for(var h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)c=h*l,u.push(z.Vector3.FromArray(i,c));break;case z.VertexBuffer.TangentKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)c=h*l,u.push(z.Vector4.FromArray(i,c));break;case z.VertexBuffer.ColorKind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)c=h*l,u.push(z.Vector4.FromArray(i,c)),4===s.getSize()?u.push(z.Vector4.FromArray(i,c)):u.push(z.Vector3.FromArray(i,c));break;case z.VertexBuffer.UVKind:case z.VertexBuffer.UV2Kind:for(h=e.verticesStart+e.verticesCount-1;h>=e.verticesStart;--h)c=h*l,u.push(z.Vector2.FromArray(i,c));break;default:z.Tools.Error("Unsupported Vertex Buffer type: "+a)}this.writeVertexAttributeData(u,n,a,i,o)}else z.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+a+" not present!")},e.prototype.writeVertexAttributeData=function(e,t,r,a,i){for(var n=0,o=e;nthis._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset++,e))},e.prototype.getUInt32=function(e){if(ethis._byteOffset?z.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?z.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?z.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?z.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)&&z.Tools.Error("Invalid data being written!"),null!=t&&(tthis._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?tthis._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4)},e})();K._BinaryWriter=r})(z.GLTF2||(z.GLTF2={}))})(BABYLON||(BABYLON={})),(function(e){var t=(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 a=this.glTFFiles[t],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([a],i)),r.click()}},e})();e.GLTFData=t})(BABYLON||(BABYLON={})),(function(L){var e,t;e=L.GLTF2||(L.GLTF2={}),t=(function(){function w(e){this._textureMap={},this._textureMap={},this._exporter=e}return w.FuzzyEquals=function(e,t,r){return L.Scalar.WithinEpsilon(e.r,t.r,r)&&L.Scalar.WithinEpsilon(e.g,t.g,r)&&L.Scalar.WithinEpsilon(e.b,t.b,r)},w.prototype._convertMaterialsToGLTFAsync=function(e,t,r){for(var a=[],i=0,n=e;io.width?(i=t&&t instanceof L.Texture?L.TextureTools.CreateResizedCopy(t,n.width,n.height,!0):this._createWhiteTexture(n.width,n.height,r),a=e):(a=e,i=t),{texture1:a,texture2:i}},w.prototype._convertPixelArrayToFloat32=function(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),a=0;aw._Epsilon?M.baseColor.r:1,g[V+1]/=M.baseColor.g>w._Epsilon?M.baseColor.g:1,g[V+2]/=M.baseColor.b>w._Epsilon?M.baseColor.b:1;var E=L.Color3.FromInts(g[V],g[V+1],g[V+2]).toGammaSpace();g[V]=255*E.r,g[V+1]=255*E.g,g[V+2]=255*E.b,w.FuzzyEquals(E,L.Color3.White(),w._Epsilon)||(S=!0),m[V+1]/=M.roughness>w._Epsilon?M.roughness:1,m[V+2]/=M.metallic>w._Epsilon?M.metallic:1;var B=L.Color3.FromInts(255,m[V+1],m[V+2]);w.FuzzyEquals(B,L.Color3.White(),w._Epsilon)||(R=!0)}if(R){var C=this._createBase64FromCanvasAsync(m,c,h,a).then((function(e){M.metallicRoughnessTextureBase64=e}));i.push(C)}if(S){C=this._createBase64FromCanvasAsync(g,c,h,a).then((function(e){M.baseColorTextureBase64=e}));i.push(C)}return Promise.all(i).then((function(){return M}))}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")},w.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),a=1-this._getMaxComponent(e.specularColor),i=w._SolveMetallic(t,r,a),n=e.diffuseColor.scale(a/(1-w._DielectricSpecular.r)/Math.max(1-i,w._Epsilon)),o=e.specularColor.subtract(w._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,w._Epsilon)),s=L.Color3.Lerp(n,o,i*i);return{baseColor:s=s.clampToRef(0,1,s),metallic:i,roughness:1-e.glossiness}},w.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},w.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},w.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,a){var i=[],n={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};return a&&(e.albedoTexture&&i.push(this._exportTextureAsync(e.albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),e.metallicTexture&&i.push(this._exportTextureAsync(e.metallicTexture,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),Promise.all(i).then((function(){return n}))},w.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof L.Texture?e.samplingMode:null;if(null!=r)switch(r){case L.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case L.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case L.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case L.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case L.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case L.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case L.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case L.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case L.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case L.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case L.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case L.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},w.prototype._getGLTFTextureWrapMode=function(e){switch(e){case L.Texture.WRAP_ADDRESSMODE:return 10497;case L.Texture.CLAMP_ADDRESSMODE:return 33071;case L.Texture.MIRROR_ADDRESSMODE:return 33648;default:return L.Tools.Error("Unsupported Texture Wrap Mode "+e+"!"),10497}},w.prototype._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof L.Texture?e.wrapU:L.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof L.Texture?e.wrapV:L.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},w.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(n,o,s,l){var u=this;return Promise.resolve().then((function(){var e=u._exporter._samplers,a=u._exporter._textures,t={diffuseColor:n.albedoColor||L.Color3.White(),specularColor:n.reflectivityColor||L.Color3.White(),glossiness:n.microSurface||1},i=null,r=u._getGLTFTextureSampler(n.albedoTexture);return null!=r.magFilter&&null!=r.minFilter&&null!=r.wrapS&&null!=r.wrapT&&(e.push(r),i=e.length-1),n.reflectivityTexture&&!n.useMicroSurfaceFromReflectivityMapAlpha?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(n.albedoTexture||n.reflectivityTexture)&&l?u._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(n.albedoTexture,n.reflectivityTexture,t,o).then((function(e){if(e.baseColorTextureBase64){var t=u._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+a.length+".png",o,n.albedoTexture?n.albedoTexture.coordinatesIndex:null,i);t&&(s.baseColorTexture=t)}if(e.metallicRoughnessTextureBase64){var r=u._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+a.length+".png",o,n.reflectivityTexture?n.reflectivityTexture.coordinatesIndex:null,i);r&&(s.metallicRoughnessTexture=r)}return e})):u._convertSpecularGlossinessToMetallicRoughness(t)}))},w.prototype._convertPBRMaterialAsync=function(t,r,a){var i=this,n={},o={name:t.name};return t.isMetallicWorkflow()?(t.albedoColor&&(n.baseColorFactor=[t.albedoColor.r,t.albedoColor.g,t.albedoColor.b,t.alpha]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(t,r,n,a).then((function(e){return i.setMetallicRoughnessPbrMaterial(e,t,o,n,r,a)}))):this._convertSpecGlossFactorsToMetallicRoughnessAsync(t,r,n,a).then((function(e){return i.setMetallicRoughnessPbrMaterial(e,t,o,n,r,a)}))},w.prototype.setMetallicRoughnessPbrMaterial=function(e,r,a,t,i,n){var o=this._exporter._materialMap,s=this._exporter._materials,l=[];if(e){var u=null;if(null!=r.transparencyMode&&(u=this._getAlphaMode(r))&&"OPAQUE"!==u&&"MASK"===(a.alphaMode=u)&&(a.alphaCutoff=r.alphaCutOff),w.FuzzyEquals(e.baseColor,L.Color3.White(),w._Epsilon)&&r.alpha>=w._Epsilon||(t.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,r.alpha]),null!=e.metallic&&1!==e.metallic&&(t.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(t.roughnessFactor=e.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||L.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),a.doubleSided=!0),n){if(r.bumpTexture){var c=this._exportTextureAsync(r.bumpTexture,i).then((function(e){e&&(a.normalTexture=e,1!==r.bumpTexture.level&&(a.normalTexture.scale=r.bumpTexture.level))}));l.push(c)}if(r.ambientTexture){c=this._exportTextureAsync(r.ambientTexture,i).then((function(e){if(e){var t={index:e.index};a.occlusionTexture=t,r.ambientTextureStrength&&(t.strength=r.ambientTextureStrength)}}));l.push(c)}if(r.emissiveTexture){c=this._exportTextureAsync(r.emissiveTexture,i).then((function(e){e&&(a.emissiveTexture=e)}));l.push(c)}}w.FuzzyEquals(r.emissiveColor,L.Color3.Black(),w._Epsilon)||(a.emissiveFactor=r.emissiveColor.asArray()),a.pbrMetallicRoughness=t,s.push(a),o[r.uniqueId]=s.length-1}return Promise.all(l).then((function(e){}))},w.prototype.getPixelsFromTexture=function(e){return e.textureType,L.Engine.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},w.prototype._exportTextureAsync=function(u,c){var h=this;return Promise.resolve().then((function(){var r=u.uid;if(r in h._textureMap)return h._textureMap[r];for(var e=h._exporter._samplers,t=h._getGLTFTextureSampler(u),a=null,i=null,n=0;nl[h]&&(l[h]=f),++i}}return{min:s,max:l}},p._GetRightHandedPositionVector3=function(e){return new d.Vector3(e.x,e.y,-e.z)},p._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},p._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},p._GetRightHandedNormalVector3=function(e){return new d.Vector3(e.x,e.y,-e.z)},p._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},p._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},p._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},p._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},p._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},p._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},p._NormalizeTangentFromRef=function(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);0