var BABYLON;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r,a){var n=r.replace(/\.[^\/.]+$/,""),i=new e.GLTF2._Exporter(t,a);return t.isReady?i._generateGLTF(n):(e.Tools.Error("glTF Serializer: Scene is not ready!"),null)},t.GLB=function(t,r,a){var n=r.replace(/\.[^\/.]+$/,""),i=new e.GLTF2._Exporter(t,a);return t.isReady?i._generateGLB(n):(e.Tools.Error("glTF Serializer: Scene is not ready!"),null)},t})();e.GLTF2Export=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(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.textures=[],this.animations=[],this.imageData={},this.convertToRightHandedSystem=!this.babylonScene.useRightHandedSystem;var r=t||{};this.shouldExportMesh=r.shouldExportMesh?r.shouldExportMesh:function(e){return!0},this.animationSampleRate=r.animationSampleRate?r.animationSampleRate:1/60}return r.prototype.writeAttributeData=function(r,a,n){for(var i,s,o=e.VertexBuffer.DeduceStride(r),l=0,u=a.length/o;l0&&(u?(t._GLTFMaterial._HasTexturesPresent(this.materials[x])||(delete c.attributes.TEXCOORD_0,delete c.attributes.TEXCOORD_1),c.material=x):t._GLTFMaterial._HasTexturesPresent(this.materials[x])&&(p=t._GLTFMaterial._StripTexturesFromMaterial(this.materials[x]),this.materials.push(p),c.material=this.materials.length-1))),r.primitives.push(c)}}}},r.prototype.createScene=function(r,a){if(r.meshes.length){var n,i,s,o=r.meshes,l={nodes:[]};t._GLTFMaterial._ConvertMaterialsToGLTF(r.materials,"image/png",this.images,this.textures,this.materials,this.imageData,!0),this.nodeMap=this.createNodeMapAndAnimations(r,a),this.totalByteLength=a.getByteOffset();var u=this;o.forEach((function(t){if(n=u.nodeMap[t.uniqueId],i=u.nodes[n],t.parent||(u.shouldExportMesh(t)?l.nodes.push(n):e.Tools.Log("Omitting "+t.name+" from scene.")),s=t.getDescendants(!0),!i.children&&s&&s.length){i.children=[];for(var r=0,a=s;rthis._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset++,e)},e.prototype.setFloat32=function(e){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){this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4},e})();t._BinaryWriter=a})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var 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],n=void 0;e(t,".glb")?n={type:"model/gltf-binary"}:e(t,".bin")?n={type:"application/octet-stream"}:e(t,".gltf")?n={type:"model/gltf+json"}:e(t,".jpeg")?n={type:"image/jpeg"}:e(t,".png")&&(n={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([a],n)),r.click()}},e})();e.GLTFData=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function t(){}return t.FuzzyEquals=function(t,r,a){return e.Scalar.WithinEpsilon(t.r,r.r,a)&&e.Scalar.WithinEpsilon(t.g,r.g,a)&&e.Scalar.WithinEpsilon(t.b,r.b,a)},t._ConvertMaterialsToGLTF=function(r,a,n,i,s,o,l){for(var u=0;uo.width?(i=r?e.TextureTools.CreateResizedCopy(r,s.width,s.height,!0):this._CreateWhiteTexture(s.width,s.height,a),n=t):(n=t,i=r),{texture1:n,texture2:i}},t._ConvertSpecularGlossinessTexturesToMetallicRoughness=function(t,r,a,n){if(!t&&!r)return null;var i=t?t.getScene():r.getScene();if(!i)return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!"),null;var s,o,l=this._ResizeTexturesToSameDimensions(t,r,i),u=l.texture1.getSize(),c=u.width,h=u.height,f=l.texture1.readPixels();if(!(f instanceof Uint8Array))return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture1.name),null;if(s=l.texture1.readPixels(),!((f=l.texture2.readPixels())instanceof Uint8Array))return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture2.name),null;o=l.texture2.readPixels();for(var m=o.byteLength,p=new Uint8Array(m),d=new Uint8Array(m),g=e.Color3.Black(),T=0,y=0,v=0;vthis._epsilon?M.baseColor.r:1,d[S+1]/=M.baseColor.g>this._epsilon?M.baseColor.g:1,d[S+2]/=M.baseColor.b>this._epsilon?M.baseColor.b:1;var L=e.Color3.FromInts(d[S],d[S+1],d[S+2]),w=L.toGammaSpace();d[S]=255*w.r,d[S+1]=255*w.g,d[S+2]=255*w.b,this.FuzzyEquals(w,e.Color3.White(),this._epsilon)||(R=!0),p[S+1]/=M.roughness>this._epsilon?M.roughness:1,p[S+2]/=M.metallic>this._epsilon?M.metallic:1;var P=e.Color3.FromInts(255,p[S+1],p[S+2]);this.FuzzyEquals(P,e.Color3.White(),this._epsilon)||(E=!0)}if(E){var V=this._CreateBase64FromCanvas(p,c,h,n);M.metallicRoughnessTextureBase64=V}if(R){var G=this._CreateBase64FromCanvas(d,c,h,n);M.baseColorTextureBase64=G}return M},t._ConvertSpecularGlossinessToMetallicRoughness=function(r){var a=t._GetPerceivedBrightness(r.diffuseColor),n=t._GetPerceivedBrightness(r.specularColor),i=1-t._GetMaxComponent(r.specularColor),s=t._SolveMetallic(a,n,i),o=r.diffuseColor.scale(i/(1-this._dielectricSpecular.r)/Math.max(1-s,this._epsilon)),l=r.specularColor.subtract(this._dielectricSpecular.scale(1-s)).scale(1/Math.max(s,this._epsilon)),u=e.Color3.Lerp(o,l,s*s);return u=u.clampToRef(0,1,u),{baseColor:u,metallic:s,roughness:1-r.glossiness}},t._GetPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},t._GetMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},t._ConvertMetalRoughFactorsToMetallicRoughness=function(e,r,a,n,i,s,o){var l={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};if(o){if(e.albedoTexture){var u=t._ExportTexture(e.albedoTexture,r,a,n,s);u&&(i.baseColorTexture=u)}if(e.metallicTexture){var u=t._ExportTexture(e.metallicTexture,r,a,n,s);null!=u&&(i.metallicRoughnessTexture=u)}}return l},t._ConvertSpecGlossFactorsToMetallicRoughness=function(r,a,n,i,s,o,l){var u={diffuseColor:r.albedoColor||e.Color3.White(),specularColor:r.reflectivityColor||e.Color3.White(),glossiness:r.microSurface||1};if(r.reflectivityTexture&&!r.useMicroSurfaceFromReflectivityMapAlpha)return e.Tools.Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported"),null;var c=this._ConvertSpecularGlossinessTexturesToMetallicRoughness(r.albedoTexture,r.reflectivityTexture,u,a);if(c){if(l){if(c.baseColorTextureBase64){var h=t._GetTextureInfoFromBase64(c.baseColorTextureBase64,"bjsBaseColorTexture_"+i.length+".png",a,n,i,o);null!=h&&(s.baseColorTexture=h)}if(c.metallicRoughnessTextureBase64){var f=t._GetTextureInfoFromBase64(c.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+i.length+".png",a,n,i,o);null!=f&&(s.metallicRoughnessTexture=f)}}}else c=this._ConvertSpecularGlossinessToMetallicRoughness(u);return c},t._ConvertPBRMaterial=function(r,a,n,i,s,o,l){var u,c={},h={name:r.name};if(u=r.isMetallicWorkflow()?this._ConvertMetalRoughFactorsToMetallicRoughness(r,a,n,i,c,o,l):this._ConvertSpecGlossFactorsToMetallicRoughness(r,a,n,i,c,o,l)){if(this.FuzzyEquals(u.baseColor,e.Color3.White(),this._epsilon)&&r.alpha>=this._epsilon||(c.baseColorFactor=[u.baseColor.r,u.baseColor.g,u.baseColor.b,r.alpha]),null!=u.metallic&&1!==u.metallic&&(c.metallicFactor=u.metallic),null!=u.roughness&&1!==u.roughness&&(c.roughnessFactor=u.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),h.doubleSided=!0),l){if(r.bumpTexture){var f=t._ExportTexture(r.bumpTexture,a,n,i,o);f&&(h.normalTexture=f)}if(r.ambientTexture){var f=t._ExportTexture(r.ambientTexture,a,n,i,o);if(f){var m={index:f.index};h.occlusionTexture=m,r.ambientTextureStrength&&(m.strength=r.ambientTextureStrength)}}if(r.emissiveTexture){var f=t._ExportTexture(r.emissiveTexture,a,n,i,o);null!=f&&(h.emissiveTexture=f)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)||(h.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var p=t._GetAlphaMode(r);p&&"OPAQUE"!==p&&(h.alphaMode=p,"BLEND"===p&&(h.alphaCutoff=r.alphaCutOff))}h.pbrMetallicRoughness=c,s.push(h)}},t.GetPixelsFromTexture=function(t){return t.textureType,e.Engine.TEXTURETYPE_UNSIGNED_INT,t.readPixels()},t._ExportTexture=function(r,a,n,i,s){var o="texture_"+(i.length-1).toString(),l=r.getInternalTexture();null!=l&&(o=l.url||o),o=e.Tools.GetFilename(o);var u=o.split(".")[0],c="";if("image/jpeg"===a)c=".jpg";else{if("image/png"!==a)return e.Tools.Error("Unsupported mime type "+a),null;c=".png"}o=u+c;var h=t.GetPixelsFromTexture(r),f=r.getSize(),m=this._CreateBase64FromCanvas(h,f.width,f.height,a);return this._GetTextureInfoFromBase64(m,o,a,n,i,s)},t._GetTextureInfoFromBase64=function(e,t,r,a,n,i){for(var s=null,o={source:a.length},l=atob(e.split(",")[1]),u=new ArrayBuffer(l.length),c=new Uint8Array(u),h=0,f=l.length;hc[m]&&(c[m]=p),++s}}return{min:u,max:c}},t.GetRightHandedVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t.GetRightHandedVector3FromRef=function(e){e.z*=-1},t.GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},t.GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},t})();t._GLTFUtilities=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));