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 n=(function(){function e(){this.coordinateSystemMode=t.AUTO,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.importMeshAsync=function(t,n,r,a,o,i,s){var l=e._parse(r,s);if(l){this.onParsed&&this.onParsed(l);var u=this._getLoader(l,s);u&&u.importMeshAsync(t,n,l,a,o,i,s)}},e.prototype.loadAsync=function(t,n,r,a,o,i){var s=e._parse(n,i);if(s){this.onParsed&&this.onParsed(s);var l=this._getLoader(s,i);if(l)return l.loadAsync(t,s,r,a,o,i)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e._parse=function(t,n){if(t instanceof ArrayBuffer)return e._parseBinary(t,n);try{return{json:JSON.parse(t),bin:null}}catch(e){return n(e.message),null}},e.prototype._getLoader=function(t,n){var r={major:2,minor:0},a=t.json.asset||{},o=e._parseVersion(a.version);if(!o)return n("Invalid version: "+a.version),null;if(void 0!==a.minVersion){var i=e._parseVersion(a.minVersion);if(!i)return n("Invalid minimum version: "+a.minVersion),null;if(e._compareVersion(i,r)>0)return n("Incompatible minimum version: "+a.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},l=s[o.major];return l?l(this):(n("Unsupported version: "+a.version),null)},e._parseBinary=function(t,n){var a={Magic:1179937895},o=new r(t),i=o.readUint32();if(i!==a.Magic)return n("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return e._parseV1(o,n);case 2:return e._parseV2(o,n)}return n("Unsupported version: "+s),null},e._parseV1=function(t,n){var r={JSON:0},a=t.readUint32();if(a!=t.getLength())return n("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o,i=t.readUint32(),s=t.readUint32();switch(s){case r.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(i)));break;default:return n("Unexpected content format: "+s),null}var l=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(l)}},e._parseV2=function(t,n){var r={JSON:1313821514,BIN:5130562},a=t.readUint32();if(a!==t.getLength())return n("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o=t.readUint32(),i=t.readUint32();if(i!==r.JSON)return n("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;n+=l.byteOffset;var d;switch(o){case t.EComponentType.BYTE:d=s._buildInt8ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_BYTE:d=s._buildUint8ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.SHORT:d=s._buildInt16ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_SHORT:d=s._buildUint16ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_INT:d=s._buildUint32ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.FLOAT:d=s._buildFloat32ArrayBuffer(u,n,r,e.byteStride,a);break;default:return void s._onError("Invalid component type ("+o+")")}i(d)}))},r.prototype._loadAccessorAsync=function(e,t){var n=this._gltf.bufferViews[e.bufferView],r=e.byteOffset||0,a=this._getByteStrideFromType(e),o=e.count*a;this._loadBufferViewAsync(n,r,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}},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._addLoaderPendingData=function(e){this._loaderPendingCount++,this._loaderTrackers.forEach((function(t){return t._addPendingData(e)}))},r.prototype._removeLoaderPendingData=function(e){this._loaderTrackers.forEach((function(t){return t._removePendingData(e)})),0==--this._loaderPendingCount&&this._onComplete()},r.prototype._whenAction=function(e,t){var r=this,a=new n(function(){r._loaderTrackers.splice(r._loaderTrackers.indexOf(a)),t()});this._loaderTrackers.push(a),this._addLoaderPendingData(a),e(),this._removeLoaderPendingData(a)},r.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",n=this._babylonScene.getMaterialByName(t);n||(n=new e.PBRMaterial(t,this._babylonScene),n.sideOrientation=e.Material.CounterClockWiseSideOrientation,n.metallic=1,n.roughness=1),this._defaultMaterial=n}return this._defaultMaterial},r.prototype._loadMaterialMetallicRoughnessProperties=function(t){var n=t.babylonMaterial;n.metallic=1,n.roughness=1;var r=t.pbrMetallicRoughness;r&&(n.albedoColor=r.baseColorFactor?e.Color3.FromArray(r.baseColorFactor):new e.Color3(1,1,1),n.metallic=void 0===r.metallicFactor?1:r.metallicFactor,n.roughness=void 0===r.roughnessFactor?1:r.roughnessFactor,r.baseColorTexture&&(n.albedoTexture=this._loadTexture(r.baseColorTexture)),r.metallicRoughnessTexture&&(n.metallicTexture=this._loadTexture(r.metallicRoughnessTexture),n.useMetallnessFromMetallicTextureBlue=!0,n.useRoughnessFromMetallicTextureGreen=!0,n.useRoughnessFromMetallicTextureAlpha=!1),this._loadMaterialAlphaProperties(t,r.baseColorFactor))},r.prototype._loadMaterial=function(e,n){if(e.babylonMaterial)return void n(e.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,n)||(this._createPbrMaterial(e),this._loadMaterialBaseProperties(e),this._loadMaterialMetallicRoughnessProperties(e),n(e.babylonMaterial,!0))},r.prototype._createPbrMaterial=function(t){var n=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);n.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=n},r.prototype._loadMaterialBaseProperties=function(t){var n=t.babylonMaterial;n.emissiveColor=t.emissiveFactor?e.Color3.FromArray(t.emissiveFactor):new e.Color3(0,0,0),t.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),t.normalTexture&&(n.bumpTexture=this._loadTexture(t.normalTexture),n.invertNormalMapX=!this._babylonScene.useRightHandedSystem,n.invertNormalMapY=this._babylonScene.useRightHandedSystem,void 0!==t.normalTexture.scale&&(n.bumpTexture.level=t.normalTexture.scale)),t.occlusionTexture&&(n.ambientTexture=this._loadTexture(t.occlusionTexture),n.useAmbientInGrayScale=!0,void 0!==t.occlusionTexture.strength&&(n.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&(n.emissiveTexture=this._loadTexture(t.emissiveTexture))},r.prototype._loadMaterialAlphaProperties=function(t,n){var r=t.babylonMaterial,a=t.alphaMode||"OPAQUE";switch(a){case"OPAQUE":break;case"MASK":case"BLEND":n&&(r.alpha=n[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture="BLEND"===a);break;default:e.Tools.Warn("Invalid alpha mode '"+t.alphaMode+"'")}r.alphaCutOff=void 0===t.alphaCutoff?.5:t.alphaCutoff},r.prototype._loadTexture=function(n){var r=this,a=this._gltf.textures[n.index],o=n.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(){r._disposed||r._removePendingData(a)},function(){r._disposed||(r._onError("Failed to load texture '"+i.uri+"'"),r._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){r._disposed||r._onProgress(e)}),this._babylonScene.database,!0,(function(e){r._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"+n.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 n=(function(){function n(){}return n.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},n.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),n=t.length,r=new Uint8Array(new ArrayBuffer(n)),a=0;a=0;i--)e._traverseNode(a.ids[i],n,r);e._traverseNode(t,n,r),o()}))},n.prototype._loadNode=function(e,t){var n=this;return this._loadExtension(t,(function(r,a){var o=[t.index].concat(r.ids).map((function(t){return e._gltf.nodes[t]}));e._addLoaderPendingData(t),n._loadNodeLOD(e,o,o.length-1,(function(){e._removeLoaderPendingData(t),a()}))}))},n.prototype._loadNodeLOD=function(e,t,r,a){var o=this;e._whenAction((function(){e._loadNode(t[r])}),(function(){if(r!==t.length-1){t[r+1].babylonMesh.setEnabled(!1)}if(0===r)return void a();setTimeout((function(){o._loadNodeLOD(e,t,r-1,a)}),n.MinimalLODDelay)}))},n.prototype._loadMaterial=function(e,t,n){var r=this;return this._loadExtension(t,(function(a,o){var i=[t.index].concat(a.ids).map((function(t){return e._gltf.materials[t]}));e._addLoaderPendingData(t),r._loadMaterialLOD(e,i,i.length-1,n,(function(){t.extensions[r.name]=a,e._removeLoaderPendingData(t),o()}))}))},n.prototype._loadMaterialLOD=function(t,r,a,o,i){var s=this;t._loadMaterial(r[a],(function(l,u){if(o(l,u),0===a)return void i();t._executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(l.getActiveTextures(),(function(){setTimeout((function(){s._loadMaterialLOD(t,r,a-1,o,i)}),n.MinimalLODDelay)}))}))}))},n.MinimalLODDelay=250,n})(t.GLTFLoaderExtension);n.MSFTLOD=r,t.GLTFLoader.RegisterExtension(new r)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){ for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}})(),BABYLON;!(function(e){!(function(t){!(function(n){var r=(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),Object.defineProperty(n.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),n.prototype._loadMaterial=function(e,t,n){var r=this;return this._loadExtension(t,(function(a,o){e._createPbrMaterial(t),e._loadMaterialBaseProperties(t),r._loadSpecularGlossinessProperties(e,t,a),n(t.babylonMaterial,!0)}))},n.prototype._loadSpecularGlossinessProperties=function(t,n,r){var a=n.babylonMaterial;a.albedoColor=r.diffuseFactor?e.Color3.FromArray(r.diffuseFactor):new e.Color3(1,1,1),a.reflectivityColor=r.specularFactor?e.Color3.FromArray(r.specularFactor):new e.Color3(1,1,1),a.microSurface=void 0===r.glossinessFactor?1:r.glossinessFactor,r.diffuseTexture&&(a.albedoTexture=t._loadTexture(r.diffuseTexture)),r.specularGlossinessTexture&&(a.reflectivityTexture=t._loadTexture(r.specularGlossinessTexture),a.reflectivityTexture.hasAlpha=!0,a.useMicroSurfaceFromReflectivityMapAlpha=!0),t._loadMaterialAlphaProperties(n,r.diffuseFactor)},n})(t.GLTFLoaderExtension);n.KHRMaterialsPbrSpecularGlossiness=r,t.GLTFLoader.RegisterExtension(new r)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));