var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.PASS_THROUGH=1]="PASS_THROUGH",e[e.FORCE_RIGHT_HANDED=2]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var r=(function(){function e(){this.coordinateSystemMode=t.AUTO,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.importMeshAsync=function(t,r,n,a,o,i,s){var l=e._parse(n,s);if(l){var u=this._getLoader(l,s);u&&u.importMeshAsync(t,r,l,a,o,i,s)}},e.prototype.loadAsync=function(t,r,n,a,o,i){var s=e._parse(r,i);if(s){var l=this._getLoader(s,i);if(l)return l.loadAsync(t,s,n,a,o,i)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e._parse=function(t,r){if(t instanceof ArrayBuffer)return e._parseBinary(t,r);try{return{json:JSON.parse(t),bin:null}}catch(e){return r(e.message),null}},e.prototype._getLoader=function(t,r){var n={major:2,minor:0},a=t.json.asset||{},o=e._parseVersion(a.version);if(!o)return r("Invalid version: "+a.version),null;if(void 0!==a.minVersion){var i=e._parseVersion(a.minVersion);if(!i)return r("Invalid minimum version: "+a.minVersion),null;if(e._compareVersion(i,n)>0)return r("Incompatible minimum version: "+a.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},l=s[o.major];return l?l(this):(r("Unsupported version: "+a.version),null)},e._parseBinary=function(t,r){var a={Magic:1179937895},o=new n(t),i=o.readUint32();if(i!==a.Magic)return r("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return e._parseV1(o,r);case 2:return e._parseV2(o,r)}return r("Unsupported version: "+s),null},e._parseV1=function(t,r){var n={JSON:0},a=t.readUint32();if(a!=t.getLength())return r("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o,i=t.readUint32(),s=t.readUint32();switch(s){case n.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(i)));break;default:return r("Unexpected content format: "+s),null}var l=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(l)}},e._parseV2=function(t,r){var n={JSON:1313821514,BIN:5130562},a=t.readUint32();if(a!==t.getLength())return r("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o=t.readUint32(),i=t.readUint32();if(i!==n.JSON)return r("First chunk format is not JSON"),null;for(var s=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),l=null;t.getPosition()t.major?1:e.majort.minor?1:e.minorl.byteLength)return void s._onError("Buffer access is out of range");var u=l.buffer;r+=l.byteOffset;var d;switch(o){case t.EComponentType.BYTE:d=s._buildInt8ArrayBuffer(u,r,n,e.byteStride,a);break;case t.EComponentType.UNSIGNED_BYTE:d=s._buildUint8ArrayBuffer(u,r,n,e.byteStride,a);break;case t.EComponentType.SHORT:d=s._buildInt16ArrayBuffer(u,r,n,e.byteStride,a);break;case t.EComponentType.UNSIGNED_SHORT:d=s._buildUint16ArrayBuffer(u,r,n,e.byteStride,a);break;case t.EComponentType.UNSIGNED_INT:d=s._buildUint32ArrayBuffer(u,r,n,e.byteStride,a);break;case t.EComponentType.FLOAT:d=s._buildFloat32ArrayBuffer(u,r,n,e.byteStride,a);break;default:return void s._onError("Invalid component type ("+o+")")}i(d)}))},r.prototype._loadAccessorAsync=function(e,t){var r=this._gltf.bufferViews[e.bufferView],n=e.byteOffset||0,a=this._getByteStrideFromType(e),o=e.count*a;this._loadBufferViewAsync(r,n,o,a,e.componentType,t)},r.prototype._getByteStrideFromType=function(e){switch(e.type){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return this._onError("Invalid accessor type ("+e.type+")"),0}},Object.defineProperty(r.prototype,"blockPendingTracking",{set:function(e){this._blockPendingTracking=e},enumerable:!0,configurable:!0}),r.prototype.addPendingData=function(e){this._renderReady||this._renderPendingCount++,this.addLoaderPendingData(e)},r.prototype.removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._onRenderReady()),this.removeLoaderPendingData(e)},r.prototype.addLoaderNonBlockingPendingData=function(e){this._nonBlockingData||(this._nonBlockingData=new Array),this._nonBlockingData.push(e)},r.prototype.addLoaderPendingData=function(e){if(this._blockPendingTracking)return void this.addLoaderNonBlockingPendingData(e);this._loaderPendingCount++},r.prototype.removeLoaderPendingData=function(e){var t=this._nonBlockingData?this._nonBlockingData.indexOf(e):-1;-1!==t?this._nonBlockingData.splice(t,1):0==--this._loaderPendingCount&&this._onLoaderFirstLODComplete(),this._nonBlockingData&&0!==this._nonBlockingData.length||0!==this._loaderPendingCount||(this._onLoaderComplete(),this.dispose())},r.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",r=this._babylonScene.getMaterialByName(t);r||(r=new e.PBRMaterial(t,this._babylonScene),r.sideOrientation=e.Material.CounterClockWiseSideOrientation,r.metallic=1,r.roughness=1),this._defaultMaterial=r}return this._defaultMaterial},r.prototype._loadMaterialMetallicRoughnessProperties=function(t){var r=t.babylonMaterial;r.metallic=1,r.roughness=1;var n=t.pbrMetallicRoughness;n&&(r.albedoColor=n.baseColorFactor?e.Color3.FromArray(n.baseColorFactor):new e.Color3(1,1,1),r.metallic=void 0===n.metallicFactor?1:n.metallicFactor,r.roughness=void 0===n.roughnessFactor?1:n.roughnessFactor,n.baseColorTexture&&(r.albedoTexture=this.loadTexture(n.baseColorTexture)),n.metallicRoughnessTexture&&(r.metallicTexture=this.loadTexture(n.metallicRoughnessTexture),r.useMetallnessFromMetallicTextureBlue=!0,r.useRoughnessFromMetallicTextureGreen=!0,r.useRoughnessFromMetallicTextureAlpha=!1),this.loadMaterialAlphaProperties(t,n.baseColorFactor))},r.prototype.loadMaterial=function(e,r){if(e.babylonMaterial)return void r(e.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,r)||(this.createPbrMaterial(e),this.loadMaterialBaseProperties(e),this._loadMaterialMetallicRoughnessProperties(e),r(e.babylonMaterial,!0))},r.prototype.createPbrMaterial=function(t){var r=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);r.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=r},r.prototype.loadMaterialBaseProperties=function(t){var r=t.babylonMaterial;r.emissiveColor=t.emissiveFactor?e.Color3.FromArray(t.emissiveFactor):new e.Color3(0,0,0),t.doubleSided&&(r.backFaceCulling=!1,r.twoSidedLighting=!0),t.normalTexture&&(r.bumpTexture=this.loadTexture(t.normalTexture),r.invertNormalMapX=!0,r.invertNormalMapY=!1,void 0!==t.normalTexture.scale&&(r.bumpTexture.level=t.normalTexture.scale)),t.occlusionTexture&&(r.ambientTexture=this.loadTexture(t.occlusionTexture),r.useAmbientInGrayScale=!0,void 0!==t.occlusionTexture.strength&&(r.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&(r.emissiveTexture=this.loadTexture(t.emissiveTexture))},r.prototype.loadMaterialAlphaProperties=function(t,r){var n=t.babylonMaterial,a=t.alphaMode||"OPAQUE";switch(a){case"OPAQUE":break;case"MASK":case"BLEND":r&&(n.alpha=r[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture="BLEND"===a);break;default:e.Tools.Warn("Invalid alpha mode '"+t.alphaMode+"'")}n.alphaCutOff=void 0===t.alphaCutoff?.5:t.alphaCutoff},r.prototype.loadTexture=function(r){var n=this,a=this._gltf.textures[r.index],o=r.texCoord||0;if(!a||void 0===a.source)return null;var i=this._gltf.images[a.source],s=void 0===a.sampler?{}:this._gltf.samplers[a.sampler],l=s.minFilter===t.ETextureMinFilter.NEAREST||s.minFilter===t.ETextureMinFilter.LINEAR,u=t.GLTFUtils.GetTextureSamplingMode(s.magFilter,s.minFilter);this.addPendingData(a);var d=new e.Texture(null,this._babylonScene,l,!1,u,function(){n._disposed||n.removePendingData(a)},function(){n._disposed||(n._onError("Failed to load texture '"+i.uri+"'"),n.removePendingData(a))});if(a.url)d.updateURL(a.url);else if(a.dataReadyObservable)a.dataReadyObservable.add((function(e){d.updateURL(e.url)}));else{a.dataReadyObservable=new e.Observable,a.dataReadyObservable.add((function(e){d.updateURL(e.url)}));var c=function(e){a.url=URL.createObjectURL(new Blob([e],{type:i.mimeType})),a.dataReadyObservable.notifyObservers(a)};if(i.uri)t.GLTFUtils.IsBase64(i.uri)?c(new Uint8Array(t.GLTFUtils.DecodeBase64(i.uri))):e.Tools.LoadFile(this._rootUrl+i.uri,c,(function(e){n._disposed||n._onProgress(e)}),this._babylonScene.database,!0,(function(e){n._onError("Failed to load file '"+i.uri+"': "+e.status+" "+e.statusText)}));else{var f=this._gltf.bufferViews[i.bufferView];this._loadBufferViewAsync(f,0,f.byteLength,1,t.EComponentType.UNSIGNED_BYTE,c)}}return d.coordinatesIndex=o,d.wrapU=t.GLTFUtils.GetTextureWrapMode(s.wrapS),d.wrapV=t.GLTFUtils.GetTextureWrapMode(s.wrapT),d.name=a.name||"texture"+r.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(d),d},r.Extensions={},r})();t.GLTFLoader=r,e.GLTFFileLoader.CreateGLTFLoaderV2=function(e){return new r(e)}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(){}return r.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},r.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),r=t.length,n=new Uint8Array(new ArrayBuffer(r)),a=0;a