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){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){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.minor0&&void 0===r[0].uri&&(n=r[0]),t.bin&&(n?n.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"):e.Tools.Warn("Unexpected BIN chunk"),n.loadedData=t.bin)},n.prototype._addRightHandToLeftHandRootTransform=function(){var t=new e.Mesh("root",this._babylonScene);t.scaling=new e.Vector3(1,1,-1),t.rotation.y=Math.PI;for(var n=this._gltf.nodes,r=0;re.byteLength)return void i._onError("Buffer access is out of range");var s=e.buffer;n+=e.byteOffset;var l;switch(a){case t.EComponentType.BYTE:l=new Int8Array(s,n,r);break;case t.EComponentType.UNSIGNED_BYTE:l=new Uint8Array(s,n,r);break;case t.EComponentType.SHORT:l=new Int16Array(s,n,r);break;case t.EComponentType.UNSIGNED_SHORT:l=new Uint16Array(s,n,r);break;case t.EComponentType.UNSIGNED_INT:l=new Uint32Array(s,n,r);break;case t.EComponentType.FLOAT:l=new Float32Array(s,n,r);break;default:return void i._onError("Invalid component type ("+a+")")}o(l)}))},n.prototype._loadAccessorAsync=function(e,t){var n=this._gltf.bufferViews[e.bufferView],r=e.byteOffset||0,a=e.count*this._getByteStrideFromType(e);this._loadBufferViewAsync(n,r,a,e.componentType,t)},n.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}},n.prototype.addPendingData=function(e){this._renderReady||this._renderPendingCount++,this.addLoaderPendingData(e)},n.prototype.removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._onRenderReady()),this.removeLoaderPendingData(e)},n.prototype.addLoaderPendingData=function(e){this._loaderPendingCount++},n.prototype.removeLoaderPendingData=function(e){0==--this._loaderPendingCount&&this._onLoaderComplete()},n.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},n.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))},n.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))},n.prototype.createPbrMaterial=function(t){var n=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);n.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=n},n.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=!0,n.invertNormalMapY=!0,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))},n.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+"'")}},n.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;if(a.babylonTextures){if(!(i=a.babylonTextures[o]))for(var s=0;s