text: var BABYLON;!(function(i){var e,t,r,n,o;(t=e=i.GLTFLoaderCoordinateSystemMode||(i.GLTFLoaderCoordinateSystemMode={}))[t.AUTO=0]="AUTO",t[t.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED",(n=r=i.GLTFLoaderAnimationStartMode||(i.GLTFLoaderAnimationStartMode={}))[n.NONE=0]="NONE",n[n.FIRST=1]="FIRST",n[n.ALL=2]="ALL",(o=i.GLTFLoaderState||(i.GLTFLoaderState={}))[o.LOADING=0]="LOADING",o[o.READY=1]="READY",o[o.COMPLETE=2]="COMPLETE";var a=(function(){function l(){this.onParsedObservable=new i.Observable,this.coordinateSystemMode=e.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.transparencyAsCoverage=!1,this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable=new i.Observable,this.onTextureLoadedObservable=new i.Observable,this.onMaterialLoadedObservable=new i.Observable,this.onCameraLoadedObservable=new i.Observable,this.onCompleteObservable=new i.Observable,this.onErrorObservable=new i.Observable,this.onDisposeObservable=new i.Observable,this.onExtensionLoadedObservable=new i.Observable,this.validate=!1,this.onValidatedObservable=new i.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(l.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"onCameraLoaded",{set:function(e){this._onCameraLoadedObserver&&this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver),this._onCameraLoadedObserver=this.onCameraLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"onError",{set:function(e){this._onErrorObserver&&this.onErrorObservable.remove(this._onErrorObserver),this._onErrorObserver=this.onErrorObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.prototype,"onExtensionLoaded",{set:function(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(l.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(l.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}),Object.defineProperty(l.prototype,"onValidated",{set:function(e){this._onValidatedObserver&&this.onValidatedObservable.remove(this._onValidatedObserver),this._onValidatedObserver=this.onValidatedObservable.add(e)},enumerable:!0,configurable:!0}),l.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this._clear(),this.onDisposeObservable.notifyObservers(void 0),this.onDisposeObservable.clear()},l.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()},l.prototype.importMeshAsync=function(t,r,e,n,o,a){var i=this;return this._parseAsync(r,e,n,a).then((function(e){return i._log("Loading "+(a||"")),i._loader=i._getLoader(e),i._loader.importMeshAsync(t,r,e,n,o,a)}))},l.prototype.loadAsync=function(t,e,r,n,o){var a=this;return this._parseAsync(t,e,r,o).then((function(e){return a._log("Loading "+(o||"")),a._loader=a._getLoader(e),a._loader.loadAsync(t,e,r,n,o)}))},l.prototype.loadAssetContainerAsync=function(r,e,t,n,o){var a=this;return this._parseAsync(r,e,t,o).then((function(e){return a._log("Loading "+(o||"")),a._loader=a._getLoader(e),a._loader.importMeshAsync(null,r,e,t,n,o).then((function(e){var t=new i.AssetContainer(r);return Array.prototype.push.apply(t.meshes,e.meshes),Array.prototype.push.apply(t.particleSystems,e.particleSystems),Array.prototype.push.apply(t.skeletons,e.skeletons),Array.prototype.push.apply(t.animationGroups,e.animationGroups),t.removeAllFromScene(),t}))}))},l.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},l.prototype.createPlugin=function(){return new l},Object.defineProperty(l.prototype,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),l.prototype.whenCompleteAsync=function(){var r=this;return new Promise(function(e,t){r.onCompleteObservable.addOnce((function(){e()})),r.onErrorObservable.addOnce((function(e){t(e)}))})},l.prototype._parseAsync=function(e,r,n,o){var a=this;return Promise.resolve().then((function(){var t=r instanceof ArrayBuffer?a._unpackBinary(r):{json:r,bin:null};return a._validateAsync(e,t.json,n,o).then((function(){a._startPerformanceCounter("Parse JSON"),a._log("JSON length: "+t.json.length);var e={json:JSON.parse(t.json),bin:t.bin};return a._endPerformanceCounter("Parse JSON"),a.onParsedObservable.notifyObservers(e),a.onParsedObservable.clear(),e}))}))},l.prototype._validateAsync=function(t,e,r,n){var o=this;if(!this.validate||"undefined"==typeof GLTFValidator)return Promise.resolve();this._startPerformanceCounter("Validate JSON");var a={externalResourceFunction:function(e){return o.preprocessUrlAsync(r+e).then((function(e){return t._loadFileAsync(e,!0,!0)})).then((function(e){return new Uint8Array(e)}))}};return n&&"data:"!==n.substr(0,5)&&(a.uri="file:"===r?n:""+r+n),GLTFValidator.validateString(e,a).then((function(e){o._endPerformanceCounter("Validate JSON"),o.onValidatedObservable.notifyObservers(e),o.onValidatedObservable.clear()}),(function(e){o._endPerformanceCounter("Validate JSON"),i.Tools.Warn("Failed to validate: "+e),o.onValidatedObservable.clear()}))},l.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=l._parseVersion(t.version);if(!r)throw new Error("Invalid version: "+t.version);if(void 0!==t.minVersion){var n=l._parseVersion(t.minVersion);if(!n)throw new Error("Invalid minimum version: "+t.minVersion);if(0<l._compareVersion(n,{major:2,minor:0}))throw new Error("Incompatible minimum version: "+t.minVersion)}var o={1:l._CreateGLTFLoaderV1,2:l._CreateGLTFLoaderV2}[r.major];if(!o)throw new Error("Unsupported version: "+t.version);return o(this)},l.prototype._unpackBinary=function(e){this._startPerformanceCounter("Unpack binary"),this._log("Binary length: "+e.byteLength);var t=new s(e),r=t.readUint32();if(1179937895!==r)throw new Error("Unexpected magic: "+r);var n,o=t.readUint32();switch(this.loggingEnabled&&this._log("Binary version: "+o),o){case 1:n=this._unpackBinaryV1(t);break;case 2:n=this._unpackBinaryV2(t);break;default:throw new Error("Unsupported version: "+o)}return this._endPerformanceCounter("Unpack binary"),n},l.prototype._unpackBinaryV1=function(e){var t=e.readUint32();if(t!=e.getLength())throw new Error("Length in header does not match actual data length: "+t+" != "+e.getLength());var r,n=e.readUint32(),o=e.readUint32();switch(o){case 0:r=l._decodeBufferToText(e.readUint8Array(n));break;default:throw new Error("Unexpected content format: "+o)}var a=e.getLength()-e.getPosition();return{json:r,bin:e.readUint8Array(a)}},l.prototype._unpackBinaryV2=function(e){var t=1313821514,r=5130562,n=e.readUint32();if(n!==e.getLength())throw new Error("Length in header does not match actual data length: "+n+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==t)throw new Error("First chunk format is not JSON");for(var a=l._decodeBufferToText(e.readUint8Array(o)),i=null;e.getPosition()<e.getLength();){var s=e.readUint32();switch(e.readUint32()){case t:throw new Error("Unexpected JSON chunk");case r:i=e.readUint8Array(s);break;default:e.skipBytes(s)}}return{json:a,bin:i}},l._parseVersion=function(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};var t=(e+"").match(/^(\d+)\.(\d+)/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null},l._compareVersion=function(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0},l._decodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;n++)t+=String.fromCharCode(e[n]);return t},l.prototype._logOpen=function(e){this._log(e),this._logIndentLevel++},l.prototype._logClose=function(){--this._logIndentLevel},l.prototype._logEnabled=function(e){var t=l._logSpaces.substr(0,2*this._logIndentLevel);i.Tools.Log(""+t+e)},l.prototype._logDisabled=function(e){},l.prototype._startPerformanceCounterEnabled=function(e){i.Tools.StartPerformanceCounter(e)},l.prototype._startPerformanceCounterDisabled=function(e){},l.prototype._endPerformanceCounterEnabled=function(e){i.Tools.EndPerformanceCounter(e)},l.prototype._endPerformanceCounterDisabled=function(e){},l.IncrementalLoading=!0,l.HomogeneousCoordinates=!1,l._logSpaces="                                ",l})();i.GLTFFileLoader=a;var s=(function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();i.SceneLoader&&i.SceneLoader.RegisterPlugin(new a)})(BABYLON||(BABYLON={})),(function(b){!(function(e){var y=(function(){function e(){}return e.Get=function(e,t,r){if(!t||null==r||!t[r])throw new Error(e+": Failed to find index ("+r+")");return t[r]},e.Assign=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},e})();e.ArrayItem=y;var t=(function(){function m(e){this._completePromises=new Array,this._disposed=!1,this._state=null,this._extensions={},this._defaultBabylonMaterialData={},this._requests=new Array,this._parent=e}return m.RegisterExtension=function(e,t){m.UnregisterExtension(e)&&b.Tools.Warn("Extension with the name '"+e+"' already exists"),m._ExtensionFactories[e]=t,m._ExtensionNames.push(e)},m.UnregisterExtension=function(e){if(!m._ExtensionFactories[e])return!1;delete m._ExtensionFactories[e];var t=m._ExtensionNames.indexOf(e);return-1!==t&&m._ExtensionNames.splice(t,1),!0},Object.defineProperty(m.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),m.prototype.dispose=function(){if(!this._disposed){this._disposed=!0;for(var e=0,t=this._requests;e<t.length;e++){t[e].abort()}for(var r in this._requests.length=0,delete this.gltf,delete this.babylonScene,this._completePromises.length=0,this._extensions){this._extensions[r].dispose&&this._extensions[r].dispose()}this._extensions={},delete this._rootBabylonMesh,delete this._progressCallback,this._parent._clear()}},m.prototype.importMeshAsync=function(a,i,s,l,u,d){var c=this;return Promise.resolve().then((function(){c.babylonScene=i,c._rootUrl=l,c._fileName=d||"scene",c._progressCallback=u,c._loadData(s);var e=null;if(a){var r={};if(c.gltf.nodes)for(var t=0,n=c.gltf.nodes;t<n.length;t++){var o=n[t];o.name&&(r[o.name]=o.index)}e=(a instanceof Array?a:[a]).map((function(e){var t=r[e];if(void 0===t)throw new Error("Failed to find node '"+e+"'");return t}))}return c._loadAsync(e,(function(){return{meshes:c._getMeshes(),particleSystems:[],skeletons:c._getSkeletons(),animationGroups:c._getAnimationGroups()}}))}))},m.prototype.loadAsync=function(e,t,r,n,o){var a=this;return Promise.resolve().then((function(){return a.babylonScene=e,a._rootUrl=r,a._fileName=o||"scene",a._progressCallback=n,a._loadData(t),a._loadAsync(null,(function(){}))}))},m.prototype._loadAsync=function(a,i){var s=this;return Promise.resolve().then((function(){s._uniqueRootUrl=-1===s._rootUrl.indexOf("file:")&&s._fileName?s._rootUrl:""+s._rootUrl+Date.now()+"/",s._loadExtensions(),s._checkExtensions();var e=b.GLTFLoaderState[b.GLTFLoaderState.LOADING]+" => "+b.GLTFLoaderState[b.GLTFLoaderState.READY],t=b.GLTFLoaderState[b.GLTFLoaderState.LOADING]+" => "+b.GLTFLoaderState[b.GLTFLoaderState.COMPLETE];s._parent._startPerformanceCounter(e),s._parent._startPerformanceCounter(t),s._setState(b.GLTFLoaderState.LOADING),s._extensionsOnLoading();var r=new Array;if(a)r.push(s.loadSceneAsync("/nodes",{nodes:a,index:-1}));else{var n=y.Get("/scene",s.gltf.scenes,s.gltf.scene||0);r.push(s.loadSceneAsync("/scenes/"+n.index,n))}s._parent.compileMaterials&&r.push(s._compileMaterialsAsync()),s._parent.compileShadowGenerators&&r.push(s._compileShadowGeneratorsAsync());var o=Promise.all(r).then((function(){return s._rootBabylonMesh&&s._rootBabylonMesh.setEnabled(!0),s._setState(b.GLTFLoaderState.READY),s._extensionsOnReady(),s._startAnimations(),i()}));return o.then((function(){s._parent._endPerformanceCounter(e),b.Tools.SetImmediate((function(){s._disposed||Promise.all(s._completePromises).then((function(){s._parent._endPerformanceCounter(t),s._setState(b.GLTFLoaderState.COMPLETE),s._parent.onCompleteObservable.notifyObservers(void 0),s._parent.onCompleteObservable.clear(),s.dispose()}),(function(e){s._parent.onErrorObservable.notifyObservers(e),s._parent.onErrorObservable.clear(),s.dispose()}))}))})),o}),(function(e){throw s._disposed||(s._parent.onErrorObservable.notifyObservers(e),s._parent.onErrorObservable.clear(),s.dispose()),e}))},m.prototype._loadData=function(e){if(this.gltf=e.json,this._setupData(),e.bin){var t=this.gltf.buffers;if(t&&t[0]&&!t[0].uri){var r=t[0];(r.byteLength<e.bin.byteLength-3||r.byteLength>e.bin.byteLength)&&b.Tools.Warn("Binary buffer length ("+r.byteLength+") from JSON does not match chunk length ("+e.bin.byteLength+")"),r._data=Promise.resolve(e.bin)}else b.Tools.Warn("Unexpected BIN chunk")}},m.prototype._setupData=function(){if(y.Assign(this.gltf.accessors),y.Assign(this.gltf.animations),y.Assign(this.gltf.buffers),y.Assign(this.gltf.bufferViews),y.Assign(this.gltf.cameras),y.Assign(this.gltf.images),y.Assign(this.gltf.materials),y.Assign(this.gltf.meshes),y.Assign(this.gltf.nodes),y.Assign(this.gltf.samplers),y.Assign(this.gltf.scenes),y.Assign(this.gltf.skins),y.Assign(this.gltf.textures),this.gltf.nodes){for(var e={},t=0,r=this.gltf.nodes;t<r.length;t++){if((l=r[t]).children)for(var n=0,o=l.children;n<o.length;n++){e[o[n]]=l.index}}for(var a=this._createRootNode(),i=0,s=this.gltf.nodes;i<s.length;i++){var l,u=e[(l=s[i]).index];l.parent=void 0===u?a:this.gltf.nodes[u]}}},m.prototype._loadExtensions=function(){for(var e=0,t=m._ExtensionNames;e<t.length;e++){var r=t[e],n=m._ExtensionFactories[r](this);this._extensions[r]=n,this._parent.onExtensionLoadedObservable.notifyObservers(n)}this._parent.onExtensionLoadedObservable.clear()},m.prototype._checkExtensions=function(){if(this.gltf.extensionsRequired)for(var e=0,t=this.gltf.extensionsRequired;e<t.length;e++){var r=t[e],n=this._extensions[r];if(!n||!n.enabled)throw new Error("Require extension "+r+" is not available")}},m.prototype._setState=function(e){this._state=e,this.log(b.GLTFLoaderState[this._state])},m.prototype._createRootNode=function(){this._rootBabylonMesh=new b.Mesh("__root__",this.babylonScene),this._rootBabylonMesh.setEnabled(!1);var e={_babylonTransformNode:this._rootBabylonMesh,index:-1};switch(this._parent.coordinateSystemMode){case b.GLTFLoaderCoordinateSystemMode.AUTO:this.babylonScene.useRightHandedSystem||(e.rotation=[0,1,0,0],e.scale=[1,1,-1],m._LoadTransform(e,this._rootBabylonMesh));break;case b.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this.babylonScene.useRightHandedSystem=!0;break;default:throw new Error("Invalid coordinate system mode ("+this._parent.coordinateSystemMode+")")}return this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh),e},m.prototype.loadSceneAsync=function(e,t){var r=this,n=this._extensionsLoadSceneAsync(e,t);if(n)return n;var o=new Array;if(this.logOpen(e+" "+(t.name||"")),t.nodes)for(var a=0,i=t.nodes;a<i.length;a++){var s=i[a],l=y.Get(e+"/nodes/"+s,this.gltf.nodes,s);o.push(this.loadNodeAsync("/nodes/"+l.index,l,(function(e){e.parent=r._rootBabylonMesh})))}if(this.gltf.nodes)for(var u=0,d=this.gltf.nodes;u<d.length;u++){if((l=d[u])._babylonTransformNode&&l._babylonBones)for(var c=0,f=l._babylonBones;c<f.length;c++){f[c].linkTransformNode(l._babylonTransformNode)}}return o.push(this._loadAnimationsAsync()),this.logClose(),Promise.all(o).then((function(){}))},m.prototype._forEachPrimitive=function(e,t){if(e._primitiveBabylonMeshes)for(var r=0,n=e._primitiveBabylonMeshes;r<n.length;r++){t(n[r])}},m.prototype._getMeshes=function(){var t=new Array;t.push(this._rootBabylonMesh);var e=this.gltf.nodes;if(e)for(var r=0,n=e;r<n.length;r++){var o=n[r];this._forEachPrimitive(o,(function(e){t.push(e)}))}return t},m.prototype._getSkeletons=function(){var e=new Array,t=this.gltf.skins;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];o._data&&e.push(o._data.babylonSkeleton)}return e},m.prototype._getAnimationGroups=function(){var e=new Array,t=this.gltf.animations;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];o._babylonAnimationGroup&&e.push(o._babylonAnimationGroup)}return e},m.prototype._startAnimations=function(){switch(this._parent.animationStartMode){case b.GLTFLoaderAnimationStartMode.NONE:break;case b.GLTFLoaderAnimationStartMode.FIRST:0!==(e=this._getAnimationGroups()).length&&e[0].start(!0);break;case b.GLTFLoaderAnimationStartMode.ALL:for(var e,t=0,r=e=this._getAnimationGroups();t<r.length;t++){r[t].start(!0)}break;default:return void b.Tools.Error("Invalid animation start mode ("+this._parent.animationStartMode+")")}},m.prototype.loadNodeAsync=function(i,s,l){var u=this;void 0===l&&(l=function(){});var e=this._extensionsLoadNodeAsync(i,s,l);if(e)return e;if(s._babylonTransformNode)throw new Error(i+": Invalid recursive node hierarchy");var d=new Array;this.logOpen(i+" "+(s.name||""));var t=function(t){if(m.AddPointerMetadata(t,i),m._LoadTransform(s,t),null!=s.camera){var e=y.Get(i+"/camera",u.gltf.cameras,s.camera);d.push(u.loadCameraAsync("/cameras/"+e.index,e,(function(e){e.parent=t})))}if(s.children)for(var r=0,n=s.children;r<n.length;r++){var o=n[r],a=y.Get(i+"/children/"+o,u.gltf.nodes,o);d.push(u.loadNodeAsync("/nodes/"+a.index,a,(function(e){e.parent=t})))}l(t)};if(null==s.mesh){var r=s.name||"node"+s.index;s._babylonTransformNode=new b.TransformNode(r,this.babylonScene),t(s._babylonTransformNode)}else{var n=y.Get(i+"/mesh",this.gltf.meshes,s.mesh);d.push(this._loadMeshAsync("/meshes/"+n.index,s,n,t))}return this.logClose(),Promise.all(d).then((function(){return u._forEachPrimitive(s,(function(e){e.refreshBoundingInfo(!0)})),s._babylonTransformNode}))},m.prototype._loadMeshAsync=function(e,t,r,n){var o=r.primitives;if(!o||!o.length)throw new Error(e+": Primitives are missing");null==o[0].index&&y.Assign(o);var a=new Array;this.logOpen(e+" "+(r.name||""));var i=t.name||"node"+t.index;if(1===o.length){var s=r.primitives[0];a.push(this._loadMeshPrimitiveAsync(e+"/primitives/"+s.index,i,t,r,s,(function(e){t._babylonTransformNode=e,t._primitiveBabylonMeshes=[e]})))}else{t._babylonTransformNode=new b.TransformNode(i,this.babylonScene),t._primitiveBabylonMeshes=[];for(var l=0,u=o;l<u.length;l++){s=u[l];a.push(this._loadMeshPrimitiveAsync(e+"/primitives/"+s.index,i+"_primitive"+s.index,t,r,s,(function(e){e.parent=t._babylonTransformNode,t._primitiveBabylonMeshes.push(e)})))}}if(null!=t.skin){var d=y.Get(e+"/skin",this.gltf.skins,t.skin);a.push(this._loadSkinAsync("/skins/"+d.index,t,d))}return n(t._babylonTransformNode),this.logClose(),Promise.all(a).then((function(){return t._babylonTransformNode}))},m.prototype._loadMeshPrimitiveAsync=function(t,e,r,n,o,a){var i=this;this.logOpen(""+t);var s,l,u=null==r.skin&&!n.primitives[0].targets,d=o._instanceData;if(u&&d)s=d.babylonSourceMesh.createInstance(e),l=d.promise;else{var c=new Array,f=new b.Mesh(e,this.babylonScene);this._createMorphTargets(t,r,n,o,f),c.push(this._loadVertexDataAsync(t,o,f).then((function(e){return i._loadMorphTargetsAsync(t,o,f,e).then((function(){e.applyToMesh(f)}))})));var h=m._GetDrawMode(t,o.mode);if(null==o.material){var p=this._defaultBabylonMaterialData[h];p||(p=this._createDefaultMaterial("__gltf_default",h),this._parent.onMaterialLoadedObservable.notifyObservers(p),this._defaultBabylonMaterialData[h]=p),f.material=p}else{var _=y.Get(t+"/material",this.gltf.materials,o.material);c.push(this._loadMaterialAsync("/materials/"+_.index,_,f,h,(function(e){f.material=e})))}l=Promise.all(c),u&&(o._instanceData={babylonSourceMesh:f,promise:l}),s=f}return m.AddPointerMetadata(s,t),this._parent.onMeshLoadedObservable.notifyObservers(s),a(s),this.logClose(),l.then((function(){return s}))},m.prototype._loadVertexDataAsync=function(o,e,a){var i=this,t=this._extensionsLoadVertexDataAsync(o,e,a);if(t)return t;var s=e.attributes;if(!s)throw new Error(o+": Attributes are missing");var l=new Array,u=new b.Geometry(a.name,this.babylonScene);if(null==e.indices)a.isUnIndexed=!0;else{var r=y.Get(o+"/indices",this.gltf.accessors,e.indices);l.push(this._loadIndicesAccessorAsync("/accessors/"+r.index,r).then((function(e){u.setIndices(e)})))}var n=function(e,t,r){if(null!=s[e]){a._delayInfo=a._delayInfo||[],-1===a._delayInfo.indexOf(t)&&a._delayInfo.push(t);var n=y.Get(o+"/attributes/"+e,i.gltf.accessors,s[e]);l.push(i._loadVertexAccessorAsync("/accessors/"+n.index,n,t).then((function(e){u.setVerticesBuffer(e,n.count)}))),r&&r(n)}};return n("POSITION",b.VertexBuffer.PositionKind),n("NORMAL",b.VertexBuffer.NormalKind),n("TANGENT",b.VertexBuffer.TangentKind),n("TEXCOORD_0",b.VertexBuffer.UVKind),n("TEXCOORD_1",b.VertexBuffer.UV2Kind),n("JOINTS_0",b.VertexBuffer.MatricesIndicesKind),n("WEIGHTS_0",b.VertexBuffer.MatricesWeightsKind),n("COLOR_0",b.VertexBuffer.ColorKind,(function(e){"VEC4"===e.type&&(a.hasVertexAlpha=!0)})),Promise.all(l).then((function(){return u}))},m.prototype._createMorphTargets=function(e,t,r,n,o){if(n.targets){if(null==t._numMorphTargets)t._numMorphTargets=n.targets.length;else if(n.targets.length!==t._numMorphTargets)throw new Error(e+": Primitives do not have the same number of targets");o.morphTargetManager=new b.MorphTargetManager;for(var a=0;a<n.targets.length;a++){var i=t.weights?t.weights[a]:r.weights?r.weights[a]:0;o.morphTargetManager.addTarget(new b.MorphTarget("morphTarget"+a,i))}}},m.prototype._loadMorphTargetsAsync=function(e,t,r,n){if(!t.targets)return Promise.resolve();for(var o=new Array,a=r.morphTargetManager,i=0;i<a.numTargets;i++){var s=a.getTarget(i);o.push(this._loadMorphTargetVertexDataAsync(e+"/targets/"+i,n,t.targets[i],s))}return Promise.all(o).then((function(){}))},m.prototype._loadMorphTargetVertexDataAsync=function(a,i,s,t){var l=this,u=new Array,e=function(e,t,r){if(null!=s[e]){var n=i.getVertexBuffer(t);if(n){var o=y.Get(a+"/"+e,l.gltf.accessors,s[e]);u.push(l._loadFloatAccessorAsync("/accessors/"+o.index,o).then((function(e){r(n,e)})))}}};return e("POSITION",b.VertexBuffer.PositionKind,(function(e,r){e.forEach(r.length,(function(e,t){r[t]+=e})),t.setPositions(r)})),e("NORMAL",b.VertexBuffer.NormalKind,(function(e,r){e.forEach(r.length,(function(e,t){r[t]+=e})),t.setNormals(r)})),e("TANGENT",b.VertexBuffer.TangentKind,(function(e,r){var n=0;e.forEach(r.length/3*4,(function(e,t){(t+1)%4!=0&&(r[n++]+=e)})),t.setTangents(r)})),Promise.all(u).then((function(){}))},m._LoadTransform=function(e,t){if(null==e.skin){var r=b.Vector3.Zero(),n=b.Quaternion.Identity(),o=b.Vector3.One();if(e.matrix)b.Matrix.FromArray(e.matrix).decompose(o,n,r);else e.translation&&(r=b.Vector3.FromArray(e.translation)),e.rotation&&(n=b.Quaternion.FromArray(e.rotation)),e.scale&&(o=b.Vector3.FromArray(e.scale));t.position=r,t.rotationQuaternion=n,t.scaling=o}},m.prototype._loadSkinAsync=function(e,r,t){var n=this,o=function(t){n._forEachPrimitive(r,(function(e){e.skeleton=t}))};if(t._data)return o(t._data.babylonSkeleton),t._data.promise;var a="skeleton"+t.index,i=new b.Skeleton(t.name||a,a,this.babylonScene);i.overrideMesh=this._rootBabylonMesh,this._loadBones(e,t,i),o(i);var s=this._loadSkinInverseBindMatricesDataAsync(e,t).then((function(e){n._updateBoneMatrices(i,e)}));return t._data={babylonSkeleton:i,promise:s},s},m.prototype._loadBones=function(e,t,r){for(var n={},o=0,a=t.joints;o<a.length;o++){var i=a[o],s=y.Get(e+"/joints/"+i,this.gltf.nodes,i);this._loadBone(s,t,r,n)}},m.prototype._loadBone=function(e,t,r,n){var o=n[e.index];if(o)return o;var a=null;e.parent&&e.parent._babylonTransformNode!==this._rootBabylonMesh&&(a=this._loadBone(e.parent,t,r,n));var i=t.joints.indexOf(e.index);return o=new b.Bone(e.name||"joint"+e.index,r,a,this._getNodeMatrix(e),null,null,i),n[e.index]=o,e._babylonBones=e._babylonBones||[],e._babylonBones.push(o),o},m.prototype._loadSkinInverseBindMatricesDataAsync=function(e,t){if(null==t.inverseBindMatrices)return Promise.resolve(null);var r=y.Get(e+"/inverseBindMatrices",this.gltf.accessors,t.inverseBindMatrices);return this._loadFloatAccessorAsync("/accessors/"+r.index,r)},m.prototype._updateBoneMatrices=function(e,t){for(var r=0,n=e.bones;r<n.length;r++){var o=n[r],a=b.Matrix.Identity(),i=o._index;t&&-1!==i&&(b.Matrix.FromArrayToRef(t,16*i,a),a.invertToRef(a));var s=o.getParent();s&&a.multiplyToRef(s.getInvertedAbsoluteTransform(),a),o.updateMatrix(a,!1,!1),o._updateDifferenceMatrix(void 0,!1)}},m.prototype._getNodeMatrix=function(e){return e.matrix?b.Matrix.FromArray(e.matrix):b.Matrix.Compose(e.scale?b.Vector3.FromArray(e.scale):b.Vector3.One(),e.rotation?b.Quaternion.FromArray(e.rotation):b.Quaternion.Identity(),e.translation?b.Vector3.FromArray(e.translation):b.Vector3.Zero())},m.prototype.loadCameraAsync=function(e,t,r){void 0===r&&(r=function(){});var n=this._extensionsLoadCameraAsync(e,t,r);if(n)return n;var o=new Array;this.logOpen(e+" "+(t.name||""));var a=new b.FreeCamera(t.name||"camera"+t.index,b.Vector3.Zero(),this.babylonScene,!1);switch(a.rotation=new b.Vector3(0,Math.PI,0),t.type){case"perspective":var i=t.perspective;if(!i)throw new Error(e+": Camera perspective properties are missing");a.fov=i.yfov,a.minZ=i.znear,a.maxZ=i.zfar||Number.MAX_VALUE;break;case"orthographic":if(!t.orthographic)throw new Error(e+": Camera orthographic properties are missing");a.mode=b.Camera.ORTHOGRAPHIC_CAMERA,a.orthoLeft=-t.orthographic.xmag,a.orthoRight=t.orthographic.xmag,a.orthoBottom=-t.orthographic.ymag,a.orthoTop=t.orthographic.ymag,a.minZ=t.orthographic.znear,a.maxZ=t.orthographic.zfar;break;default:throw new Error(e+": Invalid camera type ("+t.type+")")}return m.AddPointerMetadata(a,e),this._parent.onCameraLoadedObservable.notifyObservers(a),r(a),Promise.all(o).then((function(){return a}))},m.prototype._loadAnimationsAsync=function(){var e=this.gltf.animations;if(!e)return Promise.resolve();for(var t=new Array,r=0;r<e.length;r++){var n=e[r];t.push(this.loadAnimationAsync("/animations/"+n.index,n))}return Promise.all(t).then((function(){}))},m.prototype.loadAnimationAsync=function(e,t){var r=this._extensionsLoadAnimationAsync(e,t);if(r)return r;var n=new b.AnimationGroup(t.name||"animation"+t.index,this.babylonScene);t._babylonAnimationGroup=n;var o=new Array;y.Assign(t.channels),y.Assign(t.samplers);for(var a=0,i=t.channels;a<i.length;a++){var s=i[a];o.push(this._loadAnimationChannelAsync(e+"/channels/"+s.index,e,t,s,n))}return Promise.all(o).then((function(){return n.normalize(0),n}))},m.prototype._loadAnimationChannelAsync=function(f,e,t,h,p){var _=this;if(null==h.target.node)return Promise.resolve();var m=y.Get(f+"/target/node",this.gltf.nodes,h.target.node);if("weights"===h.target.path&&!m._numMorphTargets||"weights"!==h.target.path&&!m._babylonTransformNode)return Promise.resolve();var r=y.Get(f+"/sampler",t.samplers,h.sampler);return this._loadAnimationSamplerAsync(e+"/samplers/"+h.sampler,r).then((function(r){var t,a;switch(h.target.path){case"translation":t="position",a=b.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":t="rotationQuaternion",a=b.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":t="scaling",a=b.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":t="influence",a=b.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(f+"/target/path: Invalid value ("+h.target.path+")")}var n,e,o=0;switch(t){case"position":n=function(){var e=b.Vector3.FromArray(r.output,o);return o+=3,e};break;case"rotationQuaternion":n=function(){var e=b.Quaternion.FromArray(r.output,o);return o+=4,e};break;case"scaling":n=function(){var e=b.Vector3.FromArray(r.output,o);return o+=3,e};break;case"influence":n=function(){for(var e=new Array(m._numMorphTargets),t=0;t<m._numMorphTargets;t++)e[t]=r.output[o++];return e}}switch(r.interpolation){case"STEP":e=function(e){return{frame:r.input[e],value:n(),interpolation:b.AnimationKeyInterpolation.STEP}};break;case"LINEAR":e=function(e){return{frame:r.input[e],value:n()}};break;case"CUBICSPLINE":e=function(e){return{frame:r.input[e],inTangent:n(),value:n(),outTangent:n()}}}for(var i=new Array(r.input.length),s=0;s<r.input.length;s++)i[s]=e(s);if("influence"===t)for(var l=function(n){var e=p.name+"_channel"+p.targetedAnimations.length,o=new b.Animation(e,t,1,a);o.setKeys(i.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[n]:void 0,value:e.value[n],outTangent:e.outTangent?e.outTangent[n]:void 0}}))),_._forEachPrimitive(m,(function(e){var t=e.morphTargetManager.getTarget(n),r=o.clone();t.animations.push(r),p.addTargetedAnimation(r,t)}))},u=0;u<m._numMorphTargets;u++)l(u);else{var d=p.name+"_channel"+p.targetedAnimations.length,c=new b.Animation(d,t,1,a);c.setKeys(i),m._babylonTransformNode.animations.push(c),p.addTargetedAnimation(c,m._babylonTransformNode)}}))},m.prototype._loadAnimationSamplerAsync=function(e,t){if(t._data)return t._data;var n=t.interpolation||"LINEAR";switch(n){case"STEP":case"LINEAR":case"CUBICSPLINE":break;default:throw new Error(e+"/interpolation: Invalid value ("+t.interpolation+")")}var r=y.Get(e+"/input",this.gltf.accessors,t.input),o=y.Get(e+"/output",this.gltf.accessors,t.output);return t._data=Promise.all([this._loadFloatAccessorAsync("/accessors/"+r.index,r),this._loadFloatAccessorAsync("/accessors/"+o.index,o)]).then((function(e){var t=e[0],r=e[1];return{input:t,interpolation:n,output:r}})),t._data},m.prototype._loadBufferAsync=function(e,t){if(t._data)return t._data;if(!t.uri)throw new Error(e+"/uri: Value is missing");return t._data=this.loadUriAsync(e+"/uri",t.uri),t._data},m.prototype.loadBufferViewAsync=function(t,r){if(r._data)return r._data;var e=y.Get(t+"/buffer",this.gltf.buffers,r.buffer);return r._data=this._loadBufferAsync("/buffers/"+e.index,e).then((function(e){try{return new Uint8Array(e.buffer,e.byteOffset+(r.byteOffset||0),r.byteLength)}catch(e){throw new Error(t+": "+e.message)}})),r._data},m.prototype._loadIndicesAccessorAsync=function(t,r){if("SCALAR"!==r.type)throw new Error(t+"/type: Invalid value "+r.type);if(5121!==r.componentType&&5123!==r.componentType&&5125!==r.componentType)throw new Error(t+"/componentType: Invalid value "+r.componentType);if(r._data)return r._data;var e=y.Get(t+"/bufferView",this.gltf.bufferViews,r.bufferView);return r._data=this.loadBufferViewAsync("/bufferViews/"+e.index,e).then((function(e){return m._GetTypedArray(t,r.componentType,e,r.byteOffset,r.count)})),r._data},m.prototype._loadFloatAccessorAsync=function(d,c){var r=this;if(5126!==c.componentType)throw new Error("Invalid component type "+c.componentType);if(c._data)return c._data;var f=m._GetNumComponents(d,c.type),t=f*c.count;if(null==c.bufferView)c._data=Promise.resolve(new Float32Array(t));else{var e=y.Get(d+"/bufferView",this.gltf.bufferViews,c.bufferView);c._data=this.loadBufferViewAsync("/bufferViews/"+e.index,e).then((function(e){return m._GetTypedArray(d,c.componentType,e,c.byteOffset,t)}))}if(c.sparse){var h=c.sparse;c._data=c._data.then((function(u){var e=y.Get(d+"/sparse/indices/bufferView",r.gltf.bufferViews,h.indices.bufferView),t=y.Get(d+"/sparse/values/bufferView",r.gltf.bufferViews,h.values.bufferView);return Promise.all([r.loadBufferViewAsync("/bufferViews/"+e.index,e),r.loadBufferViewAsync("/bufferViews/"+t.index,t)]).then((function(e){for(var t=e[0],r=e[1],n=m._GetTypedArray(d+"/sparse/indices",h.indices.componentType,t,h.indices.byteOffset,h.count),o=m._GetTypedArray(d+"/sparse/values",c.componentType,r,h.values.byteOffset,f*h.count),a=0,i=0;i<n.length;i++)for(var s=n[i]*f,l=0;l<f;l++)u[s++]=o[a++];return u}))}))}return c._data},m.prototype._loadVertexBufferViewAsync=function(e,t){var r=this;return e._babylonBuffer||(e._babylonBuffer=this.loadBufferViewAsync("/bufferViews/"+e.index,e).then((function(e){return new b.Buffer(r.babylonScene.getEngine(),e,!1)}))),e._babylonBuffer},m.prototype._loadVertexAccessorAsync=function(r,n,o){var a=this;if(n._babylonVertexBuffer)return n._babylonVertexBuffer;if(n.sparse)n._babylonVertexBuffer=this._loadFloatAccessorAsync("/accessors/"+n.index,n).then((function(e){return new b.VertexBuffer(a.babylonScene.getEngine(),e,o,!1)}));else if(n.byteOffset&&n.byteOffset%b.VertexBuffer.GetTypeByteLength(n.componentType)!=0)b.Tools.Warn("Accessor byte offset is not a multiple of component type byte length"),n._babylonVertexBuffer=this._loadFloatAccessorAsync("/accessors/"+n.index,n).then((function(e){return new b.VertexBuffer(a.babylonScene.getEngine(),e,o,!1)}));else{var i=y.Get(r+"/bufferView",this.gltf.bufferViews,n.bufferView);n._babylonVertexBuffer=this._loadVertexBufferViewAsync(i,o).then((function(e){var t=m._GetNumComponents(r,n.type);return new b.VertexBuffer(a.babylonScene.getEngine(),e,o,!1,!1,i.byteStride,!1,n.byteOffset,t,n.componentType,n.normalized,!0)}))}return n._babylonVertexBuffer},m.prototype._loadMaterialMetallicRoughnessPropertiesAsync=function(e,t,r){if(!(r instanceof b.PBRMaterial))throw new Error(e+": Material type not supported");var n=new Array;return t&&(t.baseColorFactor?(r.albedoColor=b.Color3.FromArray(t.baseColorFactor),r.alpha=t.baseColorFactor[3]):r.albedoColor=b.Color3.White(),r.metallic=null==t.metallicFactor?1:t.metallicFactor,r.roughness=null==t.roughnessFactor?1:t.roughnessFactor,t.baseColorTexture&&n.push(this.loadTextureInfoAsync(e+"/baseColorTexture",t.baseColorTexture,(function(e){e.name=r.name+" (Base Color)",r.albedoTexture=e}))),t.metallicRoughnessTexture&&(n.push(this.loadTextureInfoAsync(e+"/metallicRoughnessTexture",t.metallicRoughnessTexture,(function(e){e.name=r.name+" (Metallic Roughness)",r.metallicTexture=e}))),r.useMetallnessFromMetallicTextureBlue=!0,r.useRoughnessFromMetallicTextureGreen=!0,r.useRoughnessFromMetallicTextureAlpha=!1)),Promise.all(n).then((function(){}))},m.prototype._loadMaterialAsync=function(e,t,r,n,o){void 0===o&&(o=function(){});var a=this._extensionsLoadMaterialAsync(e,t,r,n,o);if(a)return a;t._data=t._data||{};var i=t._data[n];if(!i){this.logOpen(e+" "+(t.name||""));var s=this.createMaterial(e,t,n);i={babylonMaterial:s,babylonMeshes:[],promise:this.loadMaterialPropertiesAsync(e,t,s)},t._data[n]=i,m.AddPointerMetadata(s,e),this._parent.onMaterialLoadedObservable.notifyObservers(s),this.logClose()}return i.babylonMeshes.push(r),r.onDisposeObservable.addOnce((function(){var e=i.babylonMeshes.indexOf(r);-1!==e&&i.babylonMeshes.splice(e,1)})),o(i.babylonMaterial),i.promise.then((function(){return i.babylonMaterial}))},m.prototype._createDefaultMaterial=function(e,t){var r=new b.PBRMaterial(e,this.babylonScene);return r.sideOrientation=this.babylonScene.useRightHandedSystem?b.Material.CounterClockWiseSideOrientation:b.Material.ClockWiseSideOrientation,r.fillMode=t,r.enableSpecularAntiAliasing=!0,r.useRadianceOverAlpha=!this._parent.transparencyAsCoverage,r.useSpecularOverAlpha=!this._parent.transparencyAsCoverage,r.transparencyMode=b.PBRMaterial.PBRMATERIAL_OPAQUE,r.metallic=1,r.roughness=1,r},m.prototype.createMaterial=function(e,t,r){var n=this._extensionsCreateMaterial(e,t,r);if(n)return n;var o=t.name||"material"+t.index;return this._createDefaultMaterial(o,r)},m.prototype.loadMaterialPropertiesAsync=function(e,t,r){var n=this._extensionsLoadMaterialPropertiesAsync(e,t,r);if(n)return n;var o=new Array;return o.push(this.loadMaterialBasePropertiesAsync(e,t,r)),t.pbrMetallicRoughness&&o.push(this._loadMaterialMetallicRoughnessPropertiesAsync(e+"/pbrMetallicRoughness",t.pbrMetallicRoughness,r)),this.loadMaterialAlphaProperties(e,t,r),Promise.all(o).then((function(){}))},m.prototype.loadMaterialBasePropertiesAsync=function(e,t,r){if(!(r instanceof b.PBRMaterial))throw new Error(e+": Material type not supported");var n=new Array;return r.emissiveColor=t.emissiveFactor?b.Color3.FromArray(t.emissiveFactor):new b.Color3(0,0,0),t.doubleSided&&(r.backFaceCulling=!1,r.twoSidedLighting=!0),t.normalTexture&&(n.push(this.loadTextureInfoAsync(e+"/normalTexture",t.normalTexture,(function(e){e.name=r.name+" (Normal)",r.bumpTexture=e}))),r.invertNormalMapX=!this.babylonScene.useRightHandedSystem,r.invertNormalMapY=this.babylonScene.useRightHandedSystem,null!=t.normalTexture.scale&&(r.bumpTexture.level=t.normalTexture.scale),r.forceIrradianceInFragment=!0),t.occlusionTexture&&(n.push(this.loadTextureInfoAsync(e+"/occlusionTexture",t.occlusionTexture,(function(e){e.name=r.name+" (Occlusion)",r.ambientTexture=e}))),r.useAmbientInGrayScale=!0,null!=t.occlusionTexture.strength&&(r.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&n.push(this.loadTextureInfoAsync(e+"/emissiveTexture",t.emissiveTexture,(function(e){e.name=r.name+" (Emissive)",r.emissiveTexture=e}))),Promise.all(n).then((function(){}))},m.prototype.loadMaterialAlphaProperties=function(e,t,r){if(!(r instanceof b.PBRMaterial))throw new Error(e+": Material type not supported");switch(t.alphaMode||"OPAQUE"){case"OPAQUE":r.transparencyMode=b.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":r.transparencyMode=b.PBRMaterial.PBRMATERIAL_ALPHATEST,r.alphaCutOff=null==t.alphaCutoff?.5:t.alphaCutoff,r.albedoTexture&&(r.albedoTexture.hasAlpha=!0);break;case"BLEND":r.transparencyMode=b.PBRMaterial.PBRMATERIAL_ALPHABLEND,r.albedoTexture&&(r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(e+"/alphaMode: Invalid value ("+t.alphaMode+")")}},m.prototype.loadTextureInfoAsync=function(t,r,n){var o=this;void 0===n&&(n=function(){});var e=this._extensionsLoadTextureInfoAsync(t,r,n);if(e)return e;this.logOpen(""+t);var a=y.Get(t+"/index",this.gltf.textures,r.index),i=this._loadTextureAsync("/textures/"+r.index,a,(function(e){e.coordinatesIndex=r.texCoord||0,m.AddPointerMetadata(e,t),o._parent.onTextureLoadedObservable.notifyObservers(e),n(e)}));return this.logClose(),i},m.prototype._loadTextureAsync=function(r,e,t){var n=this;void 0===t&&(t=function(){});var o=new Array;this.logOpen(r+" "+(e.name||""));var a=null==e.sampler?m._DefaultSampler:y.Get(r+"/sampler",this.gltf.samplers,e.sampler),i=this._loadSampler("/samplers/"+a.index,a),s=y.Get(r+"/source",this.gltf.images,e.source),l=null;s.uri&&(b.Tools.IsBase64(s.uri)?l=s.uri:this.babylonScene.getEngine().textureFormatInUse&&(l=this._rootUrl+s.uri));var u=new b.Deferred,d=new b.Texture(l,this.babylonScene,i.noMipMaps,!1,i.samplingMode,function(){n._disposed||u.resolve()},function(e,t){n._disposed||u.reject(new Error(r+": "+(t&&t.message?t.message:e||"Failed to load texture")))});return o.push(u.promise),l||o.push(this.loadImageAsync("/images/"+s.index,s).then((function(e){var t=s.uri||n._fileName+"#image"+s.index,r="data:"+n._uniqueRootUrl+t;d.updateURL(r,new Blob([e],{type:s.mimeType}))}))),d.wrapU=i.wrapU,d.wrapV=i.wrapV,t(d),this.logClose(),Promise.all(o).then((function(){return d}))},m.prototype._loadSampler=function(e,t){return t._data||(t._data={noMipMaps:9728===t.minFilter||9729===t.minFilter,samplingMode:m._GetTextureSamplingMode(e,t),wrapU:m._GetTextureWrapMode(e+"/wrapS",t.wrapS),wrapV:m._GetTextureWrapMode(e+"/wrapT",t.wrapT)}),t._data},m.prototype.loadImageAsync=function(e,t){if(!t._data){if(this.logOpen(e+" "+(t.name||"")),t.uri)t._data=this.loadUriAsync(e+"/uri",t.uri);else{var r=y.Get(e+"/bufferView",this.gltf.bufferViews,t.bufferView);t._data=this.loadBufferViewAsync("/bufferViews/"+r.index,r)}this.logClose()}return t._data},m.prototype.loadUriAsync=function(o,a){var i=this,e=this._extensionsLoadUriAsync(o,a);if(e)return e;if(!m._ValidateUri(a))throw new Error(o+": '"+a+"' is invalid");if(b.Tools.IsBase64(a)){var t=new Uint8Array(b.Tools.DecodeBase64(a));return this.log("Decoded "+a.substr(0,64)+"... ("+t.length+" bytes)"),Promise.resolve(t)}return this.log("Loading "+a),this._parent.preprocessUrlAsync(this._rootUrl+a).then((function(e){return new Promise(function(r,n){if(!i._disposed){var t=b.Tools.LoadFile(e,(function(e){if(!i._disposed){var t=new Uint8Array(e);i.log("Loaded "+a+" ("+t.length+" bytes)"),r(t)}}),(function(e){if(!i._disposed&&(t&&(t._lengthComputable=e.lengthComputable,t._loaded=e.loaded,t._total=e.total),i._state===b.GLTFLoaderState.LOADING))try{i._onProgress()}catch(e){n(e)}}),i.babylonScene.offlineProvider,!0,(function(e,t){i._disposed||n(new b.LoadFileError(o+": Failed to load '"+a+"'"+(e?": "+e.status+" "+e.statusText:""),e))}));i._requests.push(t)}})}))},m.prototype._onProgress=function(){if(this._progressCallback){for(var e=!0,t=0,r=0,n=0,o=this._requests;n<o.length;n++){var a=o[n];if(void 0===a._lengthComputable||void 0===a._loaded||void 0===a._total)return;e=e&&a._lengthComputable,t+=a._loaded,r+=a._total}this._progressCallback(new b.SceneLoaderProgressEvent(e,t,e?r:0))}},m.AddPointerMetadata=function(e,t){var r=e.metadata=e.metadata||{},n=r.gltf=r.gltf||{};(n.pointers=n.pointers||[]).push(t)},m._GetTextureWrapMode=function(e,t){switch(t=null==t?10497:t){case 33071:return b.Texture.CLAMP_ADDRESSMODE;case 33648:return b.Texture.MIRROR_ADDRESSMODE;case 10497:return b.Texture.WRAP_ADDRESSMODE;default:return b.Tools.Warn(e+": Invalid value ("+t+")"),b.Texture.WRAP_ADDRESSMODE}},m._GetTextureSamplingMode=function(e,t){var r=null==t.magFilter?9729:t.magFilter,n=null==t.minFilter?9987:t.minFilter;if(9729===r)switch(n){case 9728:return b.Texture.LINEAR_NEAREST;case 9729:return b.Texture.LINEAR_LINEAR;case 9984:return b.Texture.LINEAR_NEAREST_MIPNEAREST;case 9985:return b.Texture.LINEAR_LINEAR_MIPNEAREST;case 9986:return b.Texture.LINEAR_NEAREST_MIPLINEAR;case 9987:return b.Texture.LINEAR_LINEAR_MIPLINEAR;default:return b.Tools.Warn(e+"/minFilter: Invalid value ("+n+")"),b.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(9728!==r&&b.Tools.Warn(e+"/magFilter: Invalid value ("+r+")"),n){case 9728:return b.Texture.NEAREST_NEAREST;case 9729:return b.Texture.NEAREST_LINEAR;case 9984:return b.Texture.NEAREST_NEAREST_MIPNEAREST;case 9985:return b.Texture.NEAREST_LINEAR_MIPNEAREST;case 9986:return b.Texture.NEAREST_NEAREST_MIPLINEAR;case 9987:return b.Texture.NEAREST_LINEAR_MIPLINEAR;default:return b.Tools.Warn(e+"/minFilter: Invalid value ("+n+")"),b.Texture.NEAREST_NEAREST_MIPNEAREST}},m._GetTypedArray=function(t,e,r,n,o){var a=r.buffer;n=r.byteOffset+(n||0);try{switch(e){case 5120:return new Int8Array(a,n,o);case 5121:return new Uint8Array(a,n,o);case 5122:return new Int16Array(a,n,o);case 5123:return new Uint16Array(a,n,o);case 5125:return new Uint32Array(a,n,o);case 5126:return new Float32Array(a,n,o);default:throw new Error("Invalid component type "+e)}}catch(e){throw new Error(t+": "+e)}},m._GetNumComponents=function(e,t){switch(t){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}throw new Error(e+": Invalid type ("+t+")")},m._ValidateUri=function(e){return b.Tools.IsBase64(e)||-1===e.indexOf("..")},m._GetDrawMode=function(e,t){switch(null==t&&(t=4),t){case 0:return b.Material.PointListDrawMode;case 1:return b.Material.LineListDrawMode;case 2:return b.Material.LineLoopDrawMode;case 3:return b.Material.LineStripDrawMode;case 4:return b.Material.TriangleFillMode;case 5:return b.Material.TriangleStripDrawMode;case 6:return b.Material.TriangleFanDrawMode}throw new Error(e+": Invalid mesh primitive mode ("+t+")")},m.prototype._compileMaterialsAsync=function(){var e=this;this._parent._startPerformanceCounter("Compile materials");var t=new Array;if(this.gltf.materials)for(var r=0,n=this.gltf.materials;r<n.length;r++){var o=n[r];if(o._data)for(var a in o._data)for(var i=o._data[a],s=0,l=i.babylonMeshes;s<l.length;s++){var u=l[s];u.computeWorldMatrix(!0);var d=i.babylonMaterial;t.push(d.forceCompilationAsync(u)),this._parent.useClipPlane&&t.push(d.forceCompilationAsync(u,{clipPlane:!0}))}}return Promise.all(t).then((function(){e._parent._endPerformanceCounter("Compile materials")}))},m.prototype._compileShadowGeneratorsAsync=function(){var e=this;this._parent._startPerformanceCounter("Compile shadow generators");for(var t=new Array,r=0,n=this.babylonScene.lights;r<n.length;r++){var o=n[r].getShadowGenerator();o&&t.push(o.forceCompilationAsync())}return Promise.all(t).then((function(){e._parent._endPerformanceCounter("Compile shadow generators")}))},m.prototype._forEachExtensions=function(e){for(var t=0,r=m._ExtensionNames;t<r.length;t++){var n=r[t],o=this._extensions[n];o.enabled&&e(o)}},m.prototype._applyExtensions=function(e,t){for(var r=0,n=m._ExtensionNames;r<n.length;r++){var o=n[r],a=this._extensions[o];if(a.enabled){var i=e;i._activeLoaderExtensions=i._activeLoaderExtensions||{};var s=i._activeLoaderExtensions;if(!s[o]){s[o]=!0;try{var l=t(a);if(l)return l}finally{delete s[o]}}}}return null},m.prototype._extensionsOnLoading=function(){this._forEachExtensions((function(e){return e.onLoading&&e.onLoading()}))},m.prototype._extensionsOnReady=function(){this._forEachExtensions((function(e){return e.onReady&&e.onReady()}))},m.prototype._extensionsLoadSceneAsync=function(t,r){return this._applyExtensions(r,(function(e){return e.loadSceneAsync&&e.loadSceneAsync(t,r)}))},m.prototype._extensionsLoadNodeAsync=function(t,r,n){return this._applyExtensions(r,(function(e){return e.loadNodeAsync&&e.loadNodeAsync(t,r,n)}))},m.prototype._extensionsLoadCameraAsync=function(t,r,n){return this._applyExtensions(r,(function(e){return e.loadCameraAsync&&e.loadCameraAsync(t,r,n)}))},m.prototype._extensionsLoadVertexDataAsync=function(t,r,n){return this._applyExtensions(r,(function(e){return e._loadVertexDataAsync&&e._loadVertexDataAsync(t,r,n)}))},m.prototype._extensionsLoadMaterialAsync=function(t,r,n,o,a){return this._applyExtensions(r,(function(e){return e._loadMaterialAsync&&e._loadMaterialAsync(t,r,n,o,a)}))},m.prototype._extensionsCreateMaterial=function(t,r,n){return this._applyExtensions({},(function(e){return e.createMaterial&&e.createMaterial(t,r,n)}))},m.prototype._extensionsLoadMaterialPropertiesAsync=function(t,r,n){return this._applyExtensions(r,(function(e){return e.loadMaterialPropertiesAsync&&e.loadMaterialPropertiesAsync(t,r,n)}))},m.prototype._extensionsLoadTextureInfoAsync=function(t,r,n){return this._applyExtensions(r,(function(e){return e.loadTextureInfoAsync&&e.loadTextureInfoAsync(t,r,n)}))},m.prototype._extensionsLoadAnimationAsync=function(t,r){return this._applyExtensions(r,(function(e){return e.loadAnimationAsync&&e.loadAnimationAsync(t,r)}))},m.prototype._extensionsLoadUriAsync=function(t,r){return this._applyExtensions({},(function(e){return e._loadUriAsync&&e._loadUriAsync(t,r)}))},m.LoadExtensionAsync=function(e,t,r,n){if(!t.extensions)return null;var o=t.extensions[r];return o?n(e+"/extensions/"+r,o):null},m.LoadExtraAsync=function(e,t,r,n){if(!t.extras)return null;var o=t.extras[r];return o?n(e+"/extras/"+r,o):null},m.prototype.logOpen=function(e){this._parent._logOpen(e)},m.prototype.logClose=function(){this._parent._logClose()},m.prototype.log=function(e){this._parent._log(e)},m.prototype.startPerformanceCounter=function(e){this._parent._startPerformanceCounter(e)},m.prototype.endPerformanceCounter=function(e){this._parent._endPerformanceCounter(e)},m._DefaultSampler={index:-1},m._ExtensionNames=new Array,m._ExtensionFactories={},m})();e.GLTFLoader=t,b.GLTFFileLoader._CreateGLTFLoaderV2=function(e){return new t(e)}})(b.GLTF2||(b.GLTF2={}))})(BABYLON||(BABYLON={})),(function(l){var c,e,t,r,n;c=l.GLTF2||(l.GLTF2={}),e=c.Loader||(c.Loader={}),t=e.Extensions||(e.Extensions={}),r="MSFT_lod",n=(function(){function e(e){this.name=r,this.enabled=!0,this.maxLODsToLoad=Number.MAX_VALUE,this.onNodeLODsLoadedObservable=new l.Observable,this.onMaterialLODsLoadedObservable=new l.Observable,this._nodeIndexLOD=null,this._nodeSignalLODs=new Array,this._nodePromiseLODs=new Array,this._materialIndexLOD=null,this._materialSignalLODs=new Array,this._materialPromiseLODs=new Array,this._loader=e}return e.prototype.dispose=function(){delete this._loader,this._nodeIndexLOD=null,this._nodeSignalLODs.length=0,this._nodePromiseLODs.length=0,this._materialIndexLOD=null,this._materialSignalLODs.length=0,this._materialPromiseLODs.length=0,this.onMaterialLODsLoadedObservable.clear(),this.onNodeLODsLoadedObservable.clear()},e.prototype.onReady=function(){for(var r=this,e=function(e){var t=Promise.all(n._nodePromiseLODs[e]).then((function(){0!==e&&r._loader.endPerformanceCounter("Node LOD "+e),r._loader.log("Loaded node LOD "+e),r.onNodeLODsLoadedObservable.notifyObservers(e),e!==r._nodePromiseLODs.length-1&&(r._loader.startPerformanceCounter("Node LOD "+(e+1)),r._nodeSignalLODs[e]&&r._nodeSignalLODs[e].resolve())}));n._loader._completePromises.push(t)},n=this,t=0;t<this._nodePromiseLODs.length;t++)e(t);var o=function(e){var t=Promise.all(a._materialPromiseLODs[e]).then((function(){0!==e&&r._loader.endPerformanceCounter("Material LOD "+e),r._loader.log("Loaded material LOD "+e),r.onMaterialLODsLoadedObservable.notifyObservers(e),e!==r._materialPromiseLODs.length-1&&(r._loader.startPerformanceCounter("Material LOD "+(e+1)),r._materialSignalLODs[e]&&r._materialSignalLODs[e].resolve())}));a._loader._completePromises.push(t)},a=this;for(t=0;t<this._materialPromiseLODs.length;t++)o(t)},e.prototype.loadNodeAsync=function(e,i,t){var s=this;return c.GLTFLoader.LoadExtensionAsync(e,i,this.name,(function(e,t){var n,o=s._getLODs(e,i,s._loader.gltf.nodes,t.ids);s._loader.logOpen(""+e);for(var r=function(r){var e=o[r];0!==r&&(s._nodeIndexLOD=r,s._nodeSignalLODs[r]=s._nodeSignalLODs[r]||new l.Deferred);var t=s._loader.loadNodeAsync("#/nodes/"+e.index,e,(function(e){e.setEnabled(!1)})).then((function(e){if(0!==r){var t=o[r-1];t._babylonTransformNode&&(t._babylonTransformNode.dispose(),delete t._babylonTransformNode,s._disposeUnusedMaterials())}return e.setEnabled(!0),e}));0===r?n=t:s._nodeIndexLOD=null,s._nodePromiseLODs[r]=s._nodePromiseLODs[r]||[],s._nodePromiseLODs[r].push(t)},a=0;a<o.length;a++)r(a);return s._loader.logClose(),n}))},e.prototype._loadMaterialAsync=function(e,i,s,l,u){var d=this;return this._nodeIndexLOD?null:c.GLTFLoader.LoadExtensionAsync(e,i,this.name,(function(e,t){var n,o=d._getLODs(e,i,d._loader.gltf.materials,t.ids);d._loader.logOpen(""+e);for(var r=function(r){var e=o[r];0!==r&&(d._materialIndexLOD=r);var t=d._loader._loadMaterialAsync("#/materials/"+e.index,e,s,l,(function(e){0===r&&u(e)})).then((function(e){if(0!==r){u(e);var t=o[r-1]._data;t[l]&&(t[l].babylonMaterial.dispose(),delete t[l])}return e}));0===r?n=t:d._materialIndexLOD=null,d._materialPromiseLODs[r]=d._materialPromiseLODs[r]||[],d._materialPromiseLODs[r].push(t)},a=0;a<o.length;a++)r(a);return d._loader.logClose(),n}))},e.prototype._loadUriAsync=function(e,t){var r=this;if(null!==this._materialIndexLOD){this._loader.log("deferred");var n=this._materialIndexLOD-1;return this._materialSignalLODs[n]=this._materialSignalLODs[n]||new l.Deferred,this._materialSignalLODs[n].promise.then((function(){return r._loader.loadUriAsync(e,t)}))}return null!==this._nodeIndexLOD?(this._loader.log("deferred"),n=this._nodeIndexLOD-1,this._nodeSignalLODs[n]=this._nodeSignalLODs[n]||new l.Deferred,this._nodeSignalLODs[this._nodeIndexLOD-1].promise.then((function(){return r._loader.loadUriAsync(e,t)}))):null},e.prototype._getLODs=function(e,t,r,n){if(this.maxLODsToLoad<=0)throw new Error("maxLODsToLoad must be greater than zero");for(var o=new Array,a=n.length-1;0<=a;a--)if(o.push(c.ArrayItem.Get(e+"/ids/"+n[a],r,n[a])),o.length===this.maxLODsToLoad)return o;return o.push(t),o},e.prototype._disposeUnusedMaterials=function(){var e=this._loader.gltf.materials;if(e)for(var t=0,r=e;t<r.length;t++){var n=r[t];if(n._data)for(var o in n._data){var a=n._data[o];0===a.babylonMeshes.length&&(a.babylonMaterial.dispose(!1,!0),delete n._data[o])}}},e})(),t.MSFT_lod=n,c.GLTFLoader.RegisterExtension(r,(function(e){return new n(e)}))})(BABYLON||(BABYLON={})),(function(s){var t,e,r,n,o;t=s.GLTF2||(s.GLTF2={}),e=t.Loader||(t.Loader={}),r=e.Extensions||(e.Extensions={}),n="MSFT_minecraftMesh",o=(function(){function e(e){this.name=n,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader},e.prototype.loadMaterialPropertiesAsync=function(n,o,a){var i=this;return t.GLTFLoader.LoadExtraAsync(n,o,this.name,(function(e,t){if(t){if(!(a instanceof s.PBRMaterial))throw new Error(e+": Material type not supported");var r=i._loader.loadMaterialPropertiesAsync(n,o,a);return a.needAlphaBlending()&&(a.forceDepthWrite=!0,a.separateCullingPass=!0),a.backFaceCulling=a.forceDepthWrite,a.twoSidedLighting=!0,r}return null}))},e})(),r.MSFT_minecraftMesh=o,t.GLTFLoader.RegisterExtension(n,(function(e){return new o(e)}))})(BABYLON||(BABYLON={})),(function(s){var t,e,r,n,o;t=s.GLTF2||(s.GLTF2={}),e=t.Loader||(t.Loader={}),r=e.Extensions||(e.Extensions={}),n="MSFT_sRGBFactors",o=(function(){function e(e){this.name=n,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader},e.prototype.loadMaterialPropertiesAsync=function(n,o,a){var i=this;return t.GLTFLoader.LoadExtraAsync(n,o,this.name,(function(e,t){if(t){if(!(a instanceof s.PBRMaterial))throw new Error(e+": Material type not supported");var r=i._loader.loadMaterialPropertiesAsync(n,o,a);return a.albedoTexture||a.albedoColor.toLinearSpaceToRef(a.albedoColor),a.reflectivityTexture||a.reflectivityColor.toLinearSpaceToRef(a.reflectivityColor),r}return null}))},e})(),r.MSFT_sRGBFactors=o,t.GLTFLoader.RegisterExtension(n,(function(e){return new o(e)}))})(BABYLON||(BABYLON={})),(function(d){var c,e,t,r,n;c=d.GLTF2||(d.GLTF2={}),e=c.Loader||(c.Loader={}),t=e.Extensions||(e.Extensions={}),r="MSFT_audio_emitter",n=(function(){function e(e){this.name=r,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader,delete this._clips,delete this._emitters},e.prototype.onLoading=function(){var e=this._loader.gltf.extensions;if(e&&e[this.name]){var t=e[this.name];this._clips=t.clips,this._emitters=t.emitters,c.ArrayItem.Assign(this._clips),c.ArrayItem.Assign(this._emitters)}},e.prototype.loadSceneAsync=function(s,l){var u=this;return c.GLTFLoader.LoadExtensionAsync(s,l,this.name,(function(e,t){var r=new Array;r.push(u._loader.loadSceneAsync(s,l));for(var n=0,o=t.emitters;n<o.length;n++){var a=o[n],i=c.ArrayItem.Get(e+"/emitters",u._emitters,a);if(null!=i.refDistance||null!=i.maxDistance||null!=i.rolloffFactor||null!=i.distanceModel||null!=i.innerAngle||null!=i.outerAngle)throw new Error(e+": Direction or Distance properties are not allowed on emitters attached to a scene");r.push(u._loadEmitterAsync(e+"/emitters/"+i.index,i))}return Promise.all(r).then((function(){}))}))},e.prototype.loadNodeAsync=function(e,t,s){var l=this;return c.GLTFLoader.LoadExtensionAsync(e,t,this.name,(function(a,n){var i=new Array;return l._loader.loadNodeAsync(a,t,(function(o){for(var e=function(e){var n=c.ArrayItem.Get(a+"/emitters",l._emitters,e);i.push(l._loadEmitterAsync(a+"/emitters/"+n.index,n).then((function(){for(var e=0,t=n._babylonSounds;e<t.length;e++){var r=t[e];r.attachToMesh(o),null==n.innerAngle&&null==n.outerAngle||(r.setLocalDirectionToMesh(d.Vector3.Forward()),r.setDirectionalCone(2*d.Tools.ToDegrees(null==n.innerAngle?Math.PI:n.innerAngle),2*d.Tools.ToDegrees(null==n.outerAngle?Math.PI:n.outerAngle),0))}})))},t=0,r=n.emitters;t<r.length;t++)e(r[t]);s(o)})).then((function(e){return Promise.all(i).then((function(){return e}))}))}))},e.prototype.loadAnimationAsync=function(s,l){var u=this;return c.GLTFLoader.LoadExtensionAsync(s,l,this.name,(function(a,i){return u._loader.loadAnimationAsync(s,l).then((function(e){var t=new Array;c.ArrayItem.Assign(i.events);for(var r=0,n=i.events;r<n.length;r++){var o=n[r];t.push(u._loadAnimationEventAsync(a+"/events/"+o.index,s,l,o,e))}return Promise.all(t).then((function(){return e}))}))}))},e.prototype._loadClipAsync=function(e,t){if(t._objectURL)return t._objectURL;var r;if(t.uri)r=this._loader.loadUriAsync(e,t.uri);else{var n=c.ArrayItem.Get(e+"/bufferView",this._loader.gltf.bufferViews,t.bufferView);r=this._loader.loadBufferViewAsync("#/bufferViews/"+n.index,n)}return t._objectURL=r.then((function(e){return URL.createObjectURL(new Blob([e],{type:t.mimeType}))})),t._objectURL},e.prototype._loadEmitterAsync=function(e,n){var o=this;if(n._babylonSounds=n._babylonSounds||[],!n._babylonData){for(var a=new Array,i=n.name||"emitter"+n.index,s={loop:!1,autoplay:!1,volume:null==n.volume?1:n.volume},t=function(r){var e="#/extensions/"+l.name+"/clips",t=c.ArrayItem.Get(e,l._clips,n.clips[r].clip);a.push(l._loadClipAsync(e+"/"+n.clips[r].clip,t).then((function(e){var t=n._babylonSounds[r]=new d.Sound(i,e,o._loader.babylonScene,null,s);t.refDistance=n.refDistance||1,t.maxDistance=n.maxDistance||256,t.rolloffFactor=n.rolloffFactor||1,t.distanceModel=n.distanceModel||"exponential",t._positionInEmitterSpace=!0})))},l=this,r=0;r<n.clips.length;r++)t(r);var u=Promise.all(a).then((function(){var e=n.clips.map((function(e){return e.weight||1})),t=new d.WeightedSound(n.loop||!1,n._babylonSounds,e);n.innerAngle&&(t.directionalConeInnerAngle=2*d.Tools.ToDegrees(n.innerAngle)),n.outerAngle&&(t.directionalConeOuterAngle=2*d.Tools.ToDegrees(n.outerAngle)),n.volume&&(t.volume=n.volume),n._babylonData.sound=t}));n._babylonData={loaded:u}}return n._babylonData.loaded},e.prototype._getEventAction=function(e,r,t,n,o){switch(t){case"play":return function(e){var t=(o||0)+(e-n);r.play(t)};case"stop":return function(e){r.stop()};case"pause":return function(e){r.pause()};default:throw new Error(e+": Unsupported action "+t)}},e.prototype._loadAnimationEventAsync=function(r,e,t,n,o){var a=this;if(0==o.targetedAnimations.length)return Promise.resolve();var i=o.targetedAnimations[0],s=n.emitter,l=c.ArrayItem.Get("#/extensions/"+this.name+"/emitters",this._emitters,s);return this._loadEmitterAsync(r,l).then((function(){var e=l._babylonData.sound;if(e){var t=new d.AnimationEvent(n.time,a._getEventAction(r,e,n.action,n.time,n.startOffset));i.animation.addEvent(t),o.onAnimationGroupEndObservable.add((function(){e.stop()})),o.onAnimationGroupPauseObservable.add((function(){e.pause()}))}}))},e})(),t.MSFT_audio_emitter=n,c.GLTFLoader.RegisterExtension(r,(function(e){return new n(e)}))})(BABYLON||(BABYLON={})),(function(u){var d,e,t,r,n;d=u.GLTF2||(u.GLTF2={}),e=d.Loader||(d.Loader={}),t=e.Extensions||(e.Extensions={}),r="KHR_draco_mesh_compression",n=(function(){function e(e){this.name=r,this.enabled=u.DracoCompression.DecoderAvailable,this._loader=e}return e.prototype.dispose=function(){this._dracoCompression&&(this._dracoCompression.dispose(),delete this._dracoCompression),delete this._loader},e.prototype._loadVertexDataAsync=function(a,i,s){var l=this;return d.GLTFLoader.LoadExtensionAsync(a,i,this.name,(function(e,n){if(null!=i.mode){if(5!==i.mode&&4!==i.mode)throw new Error(a+": Unsupported mode "+i.mode);if(5===i.mode)throw new Error(a+": Mode "+i.mode+" is not currently supported")}var o={},t=function(e,t){var r=n.attributes[e];null!=r&&(s._delayInfo=s._delayInfo||[],-1===s._delayInfo.indexOf(t)&&s._delayInfo.push(t),o[t]=r)};t("POSITION",u.VertexBuffer.PositionKind),t("NORMAL",u.VertexBuffer.NormalKind),t("TANGENT",u.VertexBuffer.TangentKind),t("TEXCOORD_0",u.VertexBuffer.UVKind),t("TEXCOORD_1",u.VertexBuffer.UV2Kind),t("JOINTS_0",u.VertexBuffer.MatricesIndicesKind),t("WEIGHTS_0",u.VertexBuffer.MatricesWeightsKind),t("COLOR_0",u.VertexBuffer.ColorKind);var r=d.ArrayItem.Get(e,l._loader.gltf.bufferViews,n.bufferView);return r._dracoBabylonGeometry||(r._dracoBabylonGeometry=l._loader.loadBufferViewAsync("#/bufferViews/"+r.index,r).then((function(e){return l._dracoCompression||(l._dracoCompression=new u.DracoCompression),l._dracoCompression.decodeMeshAsync(e,o).then((function(e){var t=new u.Geometry(s.name,l._loader.babylonScene);return e.applyToGeometry(t),t})).catch((function(e){throw new Error(a+": "+e.message)}))}))),r._dracoBabylonGeometry}))},e})(),t.KHR_draco_mesh_compression=n,d.GLTFLoader.RegisterExtension(r,(function(e){return new n(e)}))})(BABYLON||(BABYLON={})),(function(a){var t,e,r,n,o;t=a.GLTF2||(a.GLTF2={}),e=t.Loader||(t.Loader={}),r=e.Extensions||(e.Extensions={}),n="KHR_materials_pbrSpecularGlossiness",o=(function(){function e(e){this.name=n,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader},e.prototype.loadMaterialPropertiesAsync=function(n,o,a){var i=this;return t.GLTFLoader.LoadExtensionAsync(n,o,this.name,(function(e,t){var r=new Array;return r.push(i._loader.loadMaterialBasePropertiesAsync(n,o,a)),r.push(i._loadSpecularGlossinessPropertiesAsync(e,o,t,a)),i._loader.loadMaterialAlphaProperties(n,o,a),Promise.all(r).then((function(){}))}))},e.prototype._loadSpecularGlossinessPropertiesAsync=function(e,t,r,n){if(!(n instanceof a.PBRMaterial))throw new Error(e+": Material type not supported");var o=new Array;return n.metallic=null,n.roughness=null,r.diffuseFactor?(n.albedoColor=a.Color3.FromArray(r.diffuseFactor),n.alpha=r.diffuseFactor[3]):n.albedoColor=a.Color3.White(),n.reflectivityColor=r.specularFactor?a.Color3.FromArray(r.specularFactor):a.Color3.White(),n.microSurface=null==r.glossinessFactor?1:r.glossinessFactor,r.diffuseTexture&&o.push(this._loader.loadTextureInfoAsync(e+"/diffuseTexture",r.diffuseTexture,(function(e){e.name=n.name+" (Diffuse)",n.albedoTexture=e}))),r.specularGlossinessTexture&&(o.push(this._loader.loadTextureInfoAsync(e+"/specularGlossinessTexture",r.specularGlossinessTexture,(function(e){e.name=n.name+" (Specular Glossiness)",n.reflectivityTexture=e}))),n.reflectivityTexture.hasAlpha=!0,n.useMicroSurfaceFromReflectivityMapAlpha=!0),Promise.all(o).then((function(){}))},e})(),r.KHR_materials_pbrSpecularGlossiness=o,t.GLTFLoader.RegisterExtension(n,(function(e){return new o(e)}))})(BABYLON||(BABYLON={})),(function(a){var o,e,t,r,n;o=a.GLTF2||(a.GLTF2={}),e=o.Loader||(o.Loader={}),t=e.Extensions||(e.Extensions={}),r="KHR_materials_unlit",n=(function(){function e(e){this.name=r,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader},e.prototype.loadMaterialPropertiesAsync=function(e,t,r){var n=this;return o.GLTFLoader.LoadExtensionAsync(e,t,this.name,(function(){return n._loadUnlitPropertiesAsync(e,t,r)}))},e.prototype._loadUnlitPropertiesAsync=function(e,t,r){if(!(r instanceof a.PBRMaterial))throw new Error(e+": Material type not supported");var n=new Array;r.unlit=!0;var o=t.pbrMetallicRoughness;return o&&(o.baseColorFactor?(r.albedoColor=a.Color3.FromArray(o.baseColorFactor),r.alpha=o.baseColorFactor[3]):r.albedoColor=a.Color3.White(),o.baseColorTexture&&n.push(this._loader.loadTextureInfoAsync(e+"/baseColorTexture",o.baseColorTexture,(function(e){e.name=r.name+" (Base Color)",r.albedoTexture=e})))),t.doubleSided&&(r.backFaceCulling=!1,r.twoSidedLighting=!0),this._loader.loadMaterialAlphaProperties(e,t,r),Promise.all(n).then((function(){}))},e})(),t.KHR_materials_unlit=n,o.GLTFLoader.RegisterExtension(r,(function(e){return new n(e)}))})(BABYLON||(BABYLON={})),(function(d){var c,e;c=d.GLTF2||(d.GLTF2={}),(function(e){var u,t,r="KHR_lights_punctual";(t=u||(u={})).DIRECTIONAL="directional",t.POINT="point",t.SPOT="spot";var n=(function(){function e(e){this.name=r,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader,delete this._lights},e.prototype.onLoading=function(){var e=this._loader.gltf.extensions;if(e&&e[this.name]){var t=e[this.name];this._lights=t.lights}},e.prototype.loadNodeAsync=function(e,t,s){var l=this;return c.GLTFLoader.LoadExtensionAsync(e,t,this.name,(function(a,i){return l._loader.loadNodeAsync(e,t,(function(e){var t,r=c.ArrayItem.Get(a,l._lights,i.light),n=r.name||e.name;switch(r.type){case u.DIRECTIONAL:t=new d.DirectionalLight(n,d.Vector3.Backward(),l._loader.babylonScene);break;case u.POINT:t=new d.PointLight(n,d.Vector3.Zero(),l._loader.babylonScene);break;case u.SPOT:var o=new d.SpotLight(n,d.Vector3.Zero(),d.Vector3.Backward(),0,1,l._loader.babylonScene);o.angle=2*(r.spot&&r.spot.outerConeAngle||Math.PI/4),o.innerAngle=2*(r.spot&&r.spot.innerConeAngle||0),t=o;break;default:throw new Error(a+": Invalid light type ("+r.type+")")}t.falloffType=d.Light.FALLOFF_GLTF,t.diffuse=r.color?d.Color3.FromArray(r.color):d.Color3.White(),t.intensity=null==r.intensity?1:r.intensity,t.range=null==r.range?Number.MAX_VALUE:r.range,t.parent=e,c.GLTFLoader.AddPointerMetadata(t,a),s(e)}))}))},e})();e.KHR_lights=n,c.GLTFLoader.RegisterExtension(r,(function(e){return new n(e)}))})((e=c.Loader||(c.Loader={})).Extensions||(e.Extensions={}))})(BABYLON||(BABYLON={})),(function(i){var t,e,r,n,o;t=i.GLTF2||(i.GLTF2={}),e=t.Loader||(t.Loader={}),r=e.Extensions||(e.Extensions={}),n="KHR_texture_transform",o=(function(){function e(e){this.name=n,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader},e.prototype.loadTextureInfoAsync=function(e,n,o){var a=this;return t.GLTFLoader.LoadExtensionAsync(e,n,this.name,(function(t,r){return a._loader.loadTextureInfoAsync(e,n,(function(e){if(!(e instanceof i.Texture))throw new Error(t+": Texture type not supported");r.offset&&(e.uOffset=r.offset[0],e.vOffset=r.offset[1]),e.uRotationCenter=0,e.vRotationCenter=0,r.rotation&&(e.wAng=-r.rotation),r.scale&&(e.uScale=r.scale[0],e.vScale=r.scale[1]),null!=r.texCoord&&(e.coordinatesIndex=r.texCoord),o(e)}))}))},e})(),r.KHR_texture_transform=o,t.GLTFLoader.RegisterExtension(n,(function(e){return new o(e)}))})(BABYLON||(BABYLON={})),(function(c){var f,e,t,r,n;f=c.GLTF2||(c.GLTF2={}),e=f.Loader||(f.Loader={}),t=e.Extensions||(e.Extensions={}),r="EXT_lights_image_based",n=(function(){function e(e){this.name=r,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader,delete this._lights},e.prototype.onLoading=function(){var e=this._loader.gltf.extensions;if(e&&e[this.name]){var t=e[this.name];this._lights=t.lights}},e.prototype.loadSceneAsync=function(o,a){var i=this;return f.GLTFLoader.LoadExtensionAsync(o,a,this.name,(function(e,t){var r=new Array;r.push(i._loader.loadSceneAsync(o,a)),i._loader.logOpen(""+e);var n=f.ArrayItem.Get(e+"/light",i._lights,t.light);return r.push(i._loadLightAsync("#/extensions/"+i.name+"/lights/"+t.light,n).then((function(e){i._loader.babylonScene.environmentTexture=e}))),i._loader.logClose(),Promise.all(r).then((function(){}))}))},e.prototype._loadLightAsync=function(i,s){var a=this;if(!s._loaded){var l=new Array;this._loader.logOpen(""+i);for(var u=new Array(s.specularImages.length),e=function(o){var a=s.specularImages[o];u[o]=new Array(a.length);for(var e=function(t){var e=i+"/specularImages/"+o+"/"+t;d._loader.logOpen(""+e);var r=a[t],n=f.ArrayItem.Get(e,d._loader.gltf.images,r);l.push(d._loader.loadImageAsync("#/images/"+r,n).then((function(e){u[o][t]=e}))),d._loader.logClose()},t=0;t<a.length;t++)e(t)},d=this,t=0;t<s.specularImages.length;t++)e(t);this._loader.logClose(),s._loaded=Promise.all(l).then((function(){var e=new c.RawCubeTexture(a._loader.babylonScene,null,s.specularImageSize);if(s._babylonTexture=e,null!=s.intensity&&(e.level=s.intensity),s.rotation){var t=c.Quaternion.FromArray(s.rotation);a._loader.babylonScene.useRightHandedSystem||(t=c.Quaternion.Inverse(t)),c.Matrix.FromQuaternionToRef(t,e.getReflectionTextureMatrix())}var r=c.SphericalHarmonics.FromArray(s.irradianceCoefficients);r.scale(s.intensity),r.convertIrradianceToLambertianRadiance();var n=c.SphericalPolynomial.FromHarmonics(r),o=(u.length-1)/c.Scalar.Log2(s.specularImageSize);return e.updateRGBDAsync(u,n,o)}))}return s._loaded.then((function(){return s._babylonTexture}))},e})(),t.EXT_lights_image_based=n,f.GLTFLoader.RegisterExtension(r,(function(e){return new n(e)}))})(BABYLON||(BABYLON={}));