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={}));var o=(function(){function o(){this.onParsedObservable=new e.Observable,this.coordinateSystemMode=t.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this._loader=null,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return Object.defineProperty(o.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),o.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this.onParsedObservable.clear(),this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCompleteObservable.clear(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},o.prototype.importMeshAsync=function(t,r,o,n,a,i,s){try{var l=this._parse(o);this._loader=this._getLoader(l),this._loader.importMeshAsync(t,r,l,n,a,i,s)}catch(t){s?s(t.message,t):e.Tools.Error(t.message)}},o.prototype.loadAsync=function(t,r,o,n,a,i){try{var s=this._parse(r);this._loader=this._getLoader(s),this._loader.loadAsync(t,s,o,n,a,i)}catch(t){i?i(t.message,t):e.Tools.Error(t.message)}},o.prototype.loadAssetsAsync=function(t,r,o,n,a,i){try{var s=this._parse(r);this._loader=this._getLoader(s),this._loader.importMeshAsync(null,t,s,o,(function(r,o,a){var i=new e.AssetContainer(t);Array.prototype.push.apply(i.meshes,r),Array.prototype.push.apply(i.particleSystems,o),Array.prototype.push.apply(i.skeletons,a),i.removeAllFromScene(),n(i)}),a,i)}catch(t){i?i(t.message,t):e.Tools.Error(t.message)}},o.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},o.prototype.createPlugin=function(){return new o},o.prototype._parse=function(e){var t;return t=e instanceof ArrayBuffer?o._parseBinary(e):{json:JSON.parse(e),bin:null},this.onParsedObservable.notifyObservers(t),t},o.prototype._getLoader=function(e){var t=this,r={major:2,minor:0},n=e.json.asset||{},a=o._parseVersion(n.version);if(!a)throw new Error("Invalid version: "+n.version);if(void 0!==n.minVersion){var i=o._parseVersion(n.minVersion);if(!i)throw new Error("Invalid minimum version: "+n.minVersion);if(o._compareVersion(i,r)>0)throw new Error("Incompatible minimum version: "+n.minVersion)}var s={1:o.CreateGLTFLoaderV1,2:o.CreateGLTFLoaderV2},l=s[a.major];if(!l)throw new Error("Unsupported version: "+n.version);var d=l();return d.coordinateSystemMode=this.coordinateSystemMode,d.animationStartMode=this.animationStartMode,d.compileMaterials=this.compileMaterials,d.useClipPlane=this.useClipPlane,d.compileShadowGenerators=this.compileShadowGenerators,d.onMeshLoadedObservable.add((function(e){return t.onMeshLoadedObservable.notifyObservers(e)})),d.onTextureLoadedObservable.add((function(e){return t.onTextureLoadedObservable.notifyObservers(e)})),d.onMaterialLoadedObservable.add((function(e){return t.onMaterialLoadedObservable.notifyObservers(e)})),d.onCompleteObservable.add((function(){return t.onCompleteObservable.notifyObservers(t)})),d},o._parseBinary=function(e){var t={Magic:1179937895},r=new n(e),a=r.readUint32();if(a!==t.Magic)throw new Error("Unexpected magic: "+a);var i=r.readUint32();switch(i){case 1:return o._parseV1(r);case 2:return o._parseV2(r)}throw new Error("Unsupported version: "+i)},o._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 n,a=e.readUint32(),i=e.readUint32();switch(i){case t.JSON:n=JSON.parse(o._decodeBufferToText(e.readUint8Array(a)));break;default:throw new Error("Unexpected content format: "+i)}var s=e.getLength()-e.getPosition();return{json:n,bin:e.readUint8Array(s)}},o._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 n=e.readUint32();if(e.readUint32()!==t.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(o._decodeBufferToText(e.readUint8Array(n))),i=null;e.getPosition()t.major?1:e.majort.minor?1:e.minorr.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+a.byteLength+") from JSON does not match chunk length ("+r.bin.byteLength+")"),a.loadedData=r.bin}else e.Tools.Warn("Unexpected BIN chunk")}},o.prototype._getMeshes=function(){var e=new Array;e.push(this._rootNode.babylonMesh);var t=this._gltf.nodes;if(t)for(var r=0,o=t;r=0;l--){var d=t.GLTFLoader._GetProperty(e._gltf.nodes,i.ids[l]);if(!d)throw new Error(r+": Failed to find node "+i.ids[l]);e._traverseNode(r,d,n,a)}e._traverseNode(r,o,n,a),s()}))},o.prototype._loadNode=function(e,r,o){var n=this;return this._loadExtension(r,o,(function(r,a,i){for(var s=[o],l=0,d=a.ids;l=0&&e._gltf.extensions){var n=e._gltf.extensions.KHR_lights.lights[r.light];if("ambient"!==n.type)return;var a=n.color?n.color:[1,1,1];e._babylonScene.ambientColor.copyFromFloats(a[0],a[1],a[2])}o()}))},o.prototype._loadNode=function(r,o,n){var a=this;return this._loadExtension(o,n,(function(o,i,s){if(i.light>=0&&r._gltf.extensions){var l=r._gltf.extensions.KHR_lights.lights[i.light],d=n.name||"Light",u=void 0;u=n.matrix?e.Matrix.FromArray(n.matrix):e.Matrix.Identity();var c=new e.Vector3(0,0,1);if("directional"==l.type||"spot"==l.type){var f=u.getRotationMatrix();e.Vector3.TransformCoordinatesToRef(c,f,c)}var h=void 0;if("directional"==l.type)h=new e.DirectionalLight(d,c,r._babylonScene);else{var p=u.getTranslation();if("spot"==l.type){var _=l.spot&&l.spot.outerConeAngle?l.spot.outerConeAngle:Math.PI/2;h=new e.SpotLight(d,p,c,_,2,r._babylonScene)}else h=new e.PointLight(d,p,r._babylonScene)}if(a.applyCommonProperties(h,l),i.babylonLight=h,i.babylonLight.parent=n.parent?n.parent.babylonMesh:null,n.children)for(var b=0,y=n.children;b