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 r(){this.coordinateSystemMode=t.AUTO,this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return r.prototype.importMeshAsync=function(e,t,n,a,o,i){var s=r._parse(n),l=this._getLoader(s);if(!l)return void i();l.importMeshAsync(e,t,s,a,o,i)},r.prototype.loadAsync=function(e,t,n,a,o){var i=r._parse(t),s=this._getLoader(i);return s?s.loadAsync(e,i,n,a,o):void o()},r.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},r._parse=function(e){return e instanceof ArrayBuffer?r._parseBinary(e):{json:JSON.parse(e),bin:null}},r.prototype._getLoader=function(t){var n={major:2,minor:0},a=t.json.asset||{},o=r._parseVersion(a.version);if(!o)return e.Tools.Error("Invalid version"),null;var i=r._parseVersion(a.minVersion);if(i&&r._compareVersion(i,n)>0)return e.Tools.Error("Incompatible version"),null;var s={1:r.CreateGLTFLoaderV1,2:r.CreateGLTFLoaderV2},l=s[o.major](this);return null===l?(e.Tools.Error("Unsupported version"),null):l},r._parseBinary=function(t){var a={Magic:1179937895},o=new n(t),i=o.readUint32();if(i!==a.Magic)return e.Tools.Error("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return r._parseV1(o);case 2:return r._parseV2(o)}return e.Tools.Error("Unsupported version: "+s),null},r._parseV1=function(t){var n={JSON:0},a=t.readUint32();if(a!=t.getLength())return e.Tools.Error("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(r._decodeBufferToText(t.readUint8Array(i)));break;default:return e.Tools.Error("Unexpected content format: "+s),null}var l=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(l)}},r._parseV2=function(t){var n={JSON:1313821514,BIN:5130562},a=t.readUint32();if(a!==t.getLength())return e.Tools.Error("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 e.Tools.Error("First chunk format is not JSON"),null;for(var s=JSON.parse(r._decodeBufferToText(t.readUint8Array(o))),l=null;t.getPosition()1&&2!=t.length)return null;parseInt(t[1]);return{major:r,minor:parseInt(t[0])}},r._compareVersion=function(e,t){return e.major>t.major?1:e.majort.minor?1:e.minor0&&void 0===n[0].uri&&(r=n[0]),t.bin&&(r?r.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+r.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"):e.Tools.Warn("Unexpected BIN chunk"),r.loadedData=t.bin)},r.prototype._addRightHandToLeftHandRootTransform=function(){var t=new e.Mesh("root",this._babylonScene);t.scaling=new e.Vector3(1,1,-1),t.rotationQuaternion=new e.Quaternion(0,1,0,0);for(var r=this._gltf.nodes,n=0;ne.byteLength)return void i._errors.push("Buffer access is out of range");var s=e.buffer;r+=e.byteOffset;var l;switch(a){case t.EComponentType.BYTE:l=new Int8Array(s,r,n);break;case t.EComponentType.UNSIGNED_BYTE:l=new Uint8Array(s,r,n);break;case t.EComponentType.SHORT:l=new Int16Array(s,r,n);break;case t.EComponentType.UNSIGNED_SHORT:l=new Uint16Array(s,r,n);break;case t.EComponentType.UNSIGNED_INT:l=new Uint32Array(s,r,n);break;case t.EComponentType.FLOAT:l=new Float32Array(s,r,n);break;default:return void i._errors.push("Invalid component type ("+a+")")}o(l)}))},r.prototype._loadAccessorAsync=function(e,r){var n=this._gltf.bufferViews[e.bufferView],a=e.byteOffset||0,o=e.count*t.GLTFUtils.GetByteStrideFromType(e);this._loadBufferViewAsync(n,a,o,e.componentType,r)},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++},r.prototype.removeLoaderPendingData=function(e){0==--this._loaderPendingCount&&this._onLoaderComplete()},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),this.loadMaterialAlphaProperties(t)),n.metallicRoughnessTexture&&(r.metallicTexture=this.loadTexture(n.metallicRoughnessTexture),r.useMetallnessFromMetallicTextureBlue=!0,r.useRoughnessFromMetallicTextureGreen=!0,r.useRoughnessFromMetallicTextureAlpha=!1))},r.prototype.loadMaterial=function(e,r){var n=this._gltf.materials[e];if(n.index=e,n.babylonMaterial)return void r(n.babylonMaterial);t.GLTFLoaderExtension.LoadMaterial(this,n,r)||(this.createPbrMaterial(n),this.loadMaterialBaseProperties(n),this._loadMaterialMetallicRoughnessProperties(n),r(n.babylonMaterial))},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),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){var r=t.babylonMaterial;switch(t.alphaMode||"OPAQUE"){case"OPAQUE":break;case"MASK":r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture=!1;break;case"BLEND":r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture=!0;break;default:e.Tools.Warn("Invalid alpha mode '"+t.alphaMode+"'")}},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;if(a.babylonTextures){if(!(i=a.babylonTextures[o]))for(var s=0;s