var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var r;!(function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"})(r=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}));!(function(e){e[e.LOADING=0]="LOADING",e[e.READY=1]="READY",e[e.COMPLETE=2]="COMPLETE"})(e.GLTFLoaderState||(e.GLTFLoaderState={}));var n=(function(){function n(){this.onParsedObservable=new e.Observable,this.coordinateSystemMode=t.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.transparencyAsCoverage=!1,this._normalizeAnimationGroupsToBeginAtZero=!0,this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCameraLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this._loader=null,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}},this._logIndentLevel=0,this._loggingEnabled=!1,this._log=this._logDisabled,this._capturePerformanceCounters=!1,this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled}return Object.defineProperty(n.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onCameraLoaded",{set:function(e){this._onCameraLoadedObserver&&this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver),this._onCameraLoadedObserver=this.onCameraLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onExtensionLoaded",{set:function(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)},enumerable:!0,configurable:!0}),n.prototype.whenCompleteAsync=function(){var e=this;return new Promise(function(t){e.onCompleteObservable.addOnce((function(){t()}))})},Object.defineProperty(n.prototype,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"loggingEnabled",{get:function(){return this._loggingEnabled},set:function(e){this._loggingEnabled!==e&&(this._loggingEnabled=e,this._loggingEnabled?this._log=this._logEnabled:this._log=this._logDisabled)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"capturePerformanceCounters",{get:function(){return this._capturePerformanceCounters},set:function(e){this._capturePerformanceCounters!==e&&(this._capturePerformanceCounters=e,this._capturePerformanceCounters?(this._startPerformanceCounter=this._startPerformanceCounterEnabled,this._endPerformanceCounter=this._endPerformanceCounterEnabled):(this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),n.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this._clear(),this.onDisposeObservable.notifyObservers(void 0),this.onDisposeObservable.clear()},n.prototype._clear=function(){this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCameraLoadedObservable.clear(),this.onCompleteObservable.clear(),this.onExtensionLoadedObservable.clear()},n.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=a._parse(r);return a._loader=a._getLoader(i),a._loader.importMeshAsync(e,t,i,n,o)}))},n.prototype.loadAsync=function(e,t,r,n){var o=this;return Promise.resolve().then((function(){var a=o._parse(t);return o._loader=o._getLoader(a),o._loader.loadAsync(e,a,r,n)}))},n.prototype.loadAssetContainerAsync=function(t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=a._parse(r);return a._loader=a._getLoader(i),a._loader.importMeshAsync(null,t,i,n,o).then((function(r){var n=new e.AssetContainer(t);return Array.prototype.push.apply(n.meshes,r.meshes),Array.prototype.push.apply(n.particleSystems,r.particleSystems),Array.prototype.push.apply(n.skeletons,r.skeletons),Array.prototype.push.apply(n.animationGroups,r.animationGroups),n.removeAllFromScene(),n}))}))},n.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},n.prototype.createPlugin=function(){return new n},n.prototype._parse=function(e){this._startPerformanceCounter("Parse");var t;return e instanceof ArrayBuffer?(this._log("Parsing binary"),t=this._parseBinary(e)):(this._log("Parsing JSON"),this._log("JSON length: "+e.length),t={json:JSON.parse(e),bin:null}),this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),this._endPerformanceCounter("Parse"),t},n.prototype._getLoader=function(e){var t=e.json.asset||{};this._log("Asset version: "+t.version),t.minVersion&&this._log("Asset minimum version: "+t.minVersion),t.generator&&this._log("Asset generator: "+t.generator);var r=n._parseVersion(t.version);if(!r)throw new Error("Invalid version: "+t.version);if(void 0!==t.minVersion){var o=n._parseVersion(t.minVersion);if(!o)throw new Error("Invalid minimum version: "+t.minVersion);if(n._compareVersion(o,{major:2,minor:0})>0)throw new Error("Incompatible minimum version: "+t.minVersion)}var a={1:n._CreateGLTFLoaderV1,2:n._CreateGLTFLoaderV2},i=a[r.major];if(!i)throw new Error("Unsupported version: "+t.version);return i(this)},n.prototype._parseBinary=function(e){var t={Magic:1179937895};this._log("Binary length: "+e.byteLength);var r=new o(e),n=r.readUint32();if(n!==t.Magic)throw new Error("Unexpected magic: "+n);var a=r.readUint32();switch(this.loggingEnabled&&this._log("Binary version: "+a),a){case 1:return this._parseV1(r);case 2:return this._parseV2(r)}throw new Error("Unsupported version: "+a)},n.prototype._parseV1=function(e){var t={JSON:0},r=e.readUint32();if(r!=e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o,a=e.readUint32(),i=e.readUint32();switch(i){case t.JSON:o=JSON.parse(n._decodeBufferToText(e.readUint8Array(a)));break;default:throw new Error("Unexpected content format: "+i)}var s=e.getLength()-e.getPosition();return{json:o,bin:e.readUint8Array(s)}},n.prototype._parseV2=function(e){var t={JSON:1313821514,BIN:5130562},r=e.readUint32();if(r!==e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==t.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(n._decodeBufferToText(e.readUint8Array(o))),i=null;e.getPosition()t.major?1:e.majort.minor?1:e.minor Ready"),r._parent._startPerformanceCounter("Loading => Complete"),r._state=e.GLTFLoaderState.LOADING,r._parent._log("Loading");var o=new e.Deferred;r._readyPromise=o.promise,r._loadExtensions(),r._checkExtensions();var a=new Array;if(t)a.push(r._loadSceneAsync("#/nodes",{nodes:t,_index:-1}));else{var i=n._GetProperty("#/scene",r._gltf.scenes,r._gltf.scene||0);a.push(r._loadSceneAsync("#/scenes/"+i._index,i))}r._parent.compileMaterials&&a.push(r._compileMaterialsAsync()),r._parent.compileShadowGenerators&&a.push(r._compileShadowGeneratorsAsync());var s=Promise.all(a).then((function(){r._state=e.GLTFLoaderState.READY,r._parent._log("Ready"),o.resolve(),r._startAnimations()}));return s.then((function(){r._parent._endPerformanceCounter("Loading => Ready"),e.Tools.SetImmediate((function(){r._disposed||Promise.all(r._completePromises).then((function(){r._parent._endPerformanceCounter("Loading => Complete"),r._state=e.GLTFLoaderState.COMPLETE,r._parent._log("Complete"),r._parent.onCompleteObservable.notifyObservers(void 0),r._parent.onCompleteObservable.clear(),r.dispose()})).catch((function(t){e.Tools.Error("glTF Loader: "+t.message),r.dispose()}))}))})),s})).catch((function(t){if(!r._disposed)throw e.Tools.Error("glTF Loader: "+t.message),r.dispose(),t}))},n.prototype._loadData=function(t){if(this._gltf=t.json,this._setupData(),t.bin){var r=this._gltf.buffers;if(r&&r[0]&&!r[0].uri){var n=r[0];(n.byteLengtht.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),n._data=Promise.resolve(t.bin)}else e.Tools.Warn("Unexpected BIN chunk")}},n.prototype._setupData=function(){if(r.Assign(this._gltf.accessors),r.Assign(this._gltf.animations),r.Assign(this._gltf.buffers),r.Assign(this._gltf.bufferViews),r.Assign(this._gltf.cameras),r.Assign(this._gltf.images),r.Assign(this._gltf.materials),r.Assign(this._gltf.meshes),r.Assign(this._gltf.nodes),r.Assign(this._gltf.samplers),r.Assign(this._gltf.scenes),r.Assign(this._gltf.skins),r.Assign(this._gltf.textures),this._gltf.nodes){for(var e={},t=0,n=this._gltf.nodes;t=0;i--)if(a.push(t.GLTFLoader._GetProperty(e+"/ids/"+o[i],n,o[i])),a.length===this.maxLODsToLoad)return a;return a.push(r),a},o.prototype._disposeUnusedMaterials=function(){var e=this._loader._gltf.materials;if(e)for(var t=0,r=e;t