text: !(function(i){var e,t,n,r,o;(t=e=i.GLTFLoaderCoordinateSystemMode||(i.GLTFLoaderCoordinateSystemMode={}))[t.AUTO=0]="AUTO",t[t.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED",(r=n=i.GLTFLoaderAnimationStartMode||(i.GLTFLoaderAnimationStartMode={}))[r.NONE=0]="NONE",r[r.FIRST=1]="FIRST",r[r.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=n.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,n,e,r,o,a){var i=this;return this._parseAsync(n,e,r,a).then((function(e){return i._log("Loading "+(a||"")),i._loader=i._getLoader(e),i._loader.importMeshAsync(t,n,e,r,o,a)}))},l.prototype.loadAsync=function(t,e,n,r,o){var a=this;return this._parseAsync(t,e,n,o).then((function(e){return a._log("Loading "+(o||"")),a._loader=a._getLoader(e),a._loader.loadAsync(t,e,n,r,o)}))},l.prototype.loadAssetContainerAsync=function(n,e,t,r,o){var a=this;return this._parseAsync(n,e,t,o).then((function(e){return a._log("Loading "+(o||"")),a._loader=a._getLoader(e),a._loader.importMeshAsync(null,n,e,t,r,o).then((function(e){var t=new i.AssetContainer(n);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 n=this;return new Promise(function(e,t){n.onCompleteObservable.addOnce((function(){e()})),n.onErrorObservable.addOnce((function(e){t(e)}))})},l.prototype._parseAsync=function(e,n,r,o){var a=this;return Promise.resolve().then((function(){var t=n instanceof ArrayBuffer?a._unpackBinary(n):{json:n,bin:null};return a._validateAsync(e,t.json,r,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,n,r){var o=this;if(!this.validate||"undefined"==typeof GLTFValidator)return Promise.resolve();this._startPerformanceCounter("Validate JSON");var a={externalResourceFunction:function(e){return o.preprocessUrlAsync(n+e).then((function(e){return t._loadFileAsync(e,!0,!0)})).then((function(e){return new Uint8Array(e)}))}};return r&&"data:"!==r.substr(0,5)&&(a.uri="file:"===n?r:""+n+r),GLTFValidator.validateString(e,a).then((function(e){o._endPerformanceCounter("Validate JSON"),o.onValidatedObservable.notifyObservers(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 n=l._parseVersion(t.version);if(!n)throw new Error("Invalid version: "+t.version);if(void 0!==t.minVersion){var r=l._parseVersion(t.minVersion);if(!r)throw new Error("Invalid minimum version: "+t.minVersion);if(0<l._compareVersion(r,{major:2,minor:0}))throw new Error("Incompatible minimum version: "+t.minVersion)}var o={1:l._CreateGLTFLoaderV1,2:l._CreateGLTFLoaderV2}[n.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),n=t.readUint32();if(1179937895!==n)throw new Error("Unexpected magic: "+n);var r,o=t.readUint32();switch(this.loggingEnabled&&this._log("Binary version: "+o),o){case 1:r=this._unpackBinaryV1(t);break;case 2:r=this._unpackBinaryV2(t);break;default:throw new Error("Unsupported version: "+o)}return this._endPerformanceCounter("Unpack binary"),r},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 n,r=e.readUint32(),o=e.readUint32();switch(o){case 0:n=l._decodeBufferToText(e.readUint8Array(r));break;default:throw new Error("Unexpected content format: "+o)}var a=e.getLength()-e.getPosition();return{json:n,bin:e.readUint8Array(a)}},l.prototype._unpackBinaryV2=function(e){var t=1313821514,n=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)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 n: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="",n=e.byteLength,r=0;r<n;r++)t+=String.fromCharCode(e[r]);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(e){var t,n,r,o,a,i,s,l,u;t=e.GLTF1||(e.GLTF1={}),(n=t.EComponentType||(t.EComponentType={}))[n.BYTE=5120]="BYTE",n[n.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",n[n.SHORT=5122]="SHORT",n[n.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",n[n.FLOAT=5126]="FLOAT",(r=t.EShaderType||(t.EShaderType={}))[r.FRAGMENT=35632]="FRAGMENT",r[r.VERTEX=35633]="VERTEX",(o=t.EParameterType||(t.EParameterType={}))[o.BYTE=5120]="BYTE",o[o.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",o[o.SHORT=5122]="SHORT",o[o.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",o[o.INT=5124]="INT",o[o.UNSIGNED_INT=5125]="UNSIGNED_INT",o[o.FLOAT=5126]="FLOAT",o[o.FLOAT_VEC2=35664]="FLOAT_VEC2",o[o.FLOAT_VEC3=35665]="FLOAT_VEC3",o[o.FLOAT_VEC4=35666]="FLOAT_VEC4",o[o.INT_VEC2=35667]="INT_VEC2",o[o.INT_VEC3=35668]="INT_VEC3",o[o.INT_VEC4=35669]="INT_VEC4",o[o.BOOL=35670]="BOOL",o[o.BOOL_VEC2=35671]="BOOL_VEC2",o[o.BOOL_VEC3=35672]="BOOL_VEC3",o[o.BOOL_VEC4=35673]="BOOL_VEC4",o[o.FLOAT_MAT2=35674]="FLOAT_MAT2",o[o.FLOAT_MAT3=35675]="FLOAT_MAT3",o[o.FLOAT_MAT4=35676]="FLOAT_MAT4",o[o.SAMPLER_2D=35678]="SAMPLER_2D",(a=t.ETextureWrapMode||(t.ETextureWrapMode={}))[a.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",a[a.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",a[a.REPEAT=10497]="REPEAT",(i=t.ETextureFilterType||(t.ETextureFilterType={}))[i.NEAREST=9728]="NEAREST",i[i.LINEAR=9728]="LINEAR",i[i.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",i[i.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",i[i.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",i[i.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR",(s=t.ETextureFormat||(t.ETextureFormat={}))[s.ALPHA=6406]="ALPHA",s[s.RGB=6407]="RGB",s[s.RGBA=6408]="RGBA",s[s.LUMINANCE=6409]="LUMINANCE",s[s.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",(l=t.ECullingType||(t.ECullingType={}))[l.FRONT=1028]="FRONT",l[l.BACK=1029]="BACK",l[l.FRONT_AND_BACK=1032]="FRONT_AND_BACK",(u=t.EBlendingFunction||(t.EBlendingFunction={}))[u.ZERO=0]="ZERO",u[u.ONE=1]="ONE",u[u.SRC_COLOR=768]="SRC_COLOR",u[u.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",u[u.DST_COLOR=774]="DST_COLOR",u[u.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",u[u.SRC_ALPHA=770]="SRC_ALPHA",u[u.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",u[u.DST_ALPHA=772]="DST_ALPHA",u[u.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",u[u.CONSTANT_COLOR=32769]="CONSTANT_COLOR",u[u.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",u[u.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",u[u.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",u[u.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE"})(BABYLON||(BABYLON={})),(function(W){!(function(B){var D,e;(e=D||(D={}))[e.IDENTIFIER=1]="IDENTIFIER",e[e.UNKNOWN=2]="UNKNOWN",e[e.END_OF_INPUT=3]="END_OF_INPUT";var G=(function(){function e(e){this._pos=0,this.currentToken=D.UNKNOWN,this.currentIdentifier="",this.currentString="",this.isLetterOrDigitPattern=/^[a-zA-Z0-9]+$/,this._toParse=e,this._maxPos=e.length}return e.prototype.getNextToken=function(){if(this.isEnd())return D.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=D.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=D.IDENTIFIER,this.currentIdentifier=this.currentString;!this.isEnd()&&(this.isLetterOrDigitPattern.test(this.currentString=this.peek())||"_"===this.currentString);)this.currentIdentifier+=this.currentString,this.forward();return this.currentToken},e.prototype.peek=function(){return this._toParse[this._pos]},e.prototype.read=function(){return this._toParse[this._pos++]},e.prototype.forward=function(){this._pos++},e.prototype.isEnd=function(){return this._pos>=this._maxPos},e})(),V=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],U=["world","view","projection","worldView","worldViewProjection","mBones"],w=["translation","rotation","scale"],S=["position","rotationQuaternion","scaling"],o=function(e,t,n){for(var r in e){var o=e[r];n[t][r]=o}},N=function(e){if(e)for(var t=0;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},k=function(e){if("NORMAL"===e.semantic)return"normal";if("POSITION"===e.semantic)return"position";if("JOINT"===e.semantic)return"matricesIndices";if("WEIGHT"===e.semantic)return"matricesWeights";if("COLOR"===e.semantic)return"color";if(e.semantic&&-1!==e.semantic.indexOf("TEXCOORD_")){var t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}return null},v=function(e){var t=null;if(e.translation||e.rotation||e.scale){var n=W.Vector3.FromArray(e.scale||[1,1,1]),r=W.Quaternion.FromArray(e.rotation||[0,0,0,1]),o=W.Vector3.FromArray(e.translation||[0,0,0]);t=W.Matrix.Compose(n,r,o)}else t=W.Matrix.FromArray(e.matrix);return t},b=function(e,t,n,r){for(var o=0;o<r.bones.length;o++)if(r.bones[o].name===n)return r.bones[o];var a=e.nodes;for(var i in a){var s=a[i];if(s.jointName){var l=s.children;for(o=0;o<l.length;o++){var u=e.nodes[l[o]];if(u.jointName&&u.jointName===n){var c=v(s),d=new W.Bone(s.name||"",r,b(e,t,s.jointName,r),c);return d.id=i,d}}}}return null},T=function(e,t){for(var n=0;n<e.length;n++)for(var r=e[n],o=0;o<r.node.children.length;o++){if(r.node.children[o]===t)return r.bone}return null},L=function(e,t){var n=e.nodes,r=n[t];if(r)return{node:r,id:t};for(var o in n)if((r=n[o]).jointName===t)return{node:r,id:o};return null},E=function(e,t){for(var n=0;n<e.jointNames.length;n++)if(e.jointNames[n]===t)return!0;return!1},x=function(e,t,n,r,o){if(r||(r=new W.Skeleton(t.name||"","",e.scene)),!t.babylonSkeleton)return r;var a=[],i=[];!(function(e,t,n,r){for(var o in e.nodes){var a=e.nodes[o],i=o;if(a.jointName&&!E(n,a.jointName)){var s=v(a),l=new W.Bone(a.name||"",t,null,s);l.id=i,r.push({bone:l,node:a,id:i})}}for(var u=0;u<r.length;u++)for(var c=r[u],d=c.node.children,f=0;f<d.length;f++){for(var h=null,p=0;p<r.length;p++)if(r[p].id===d[f]){h=r[p];break}h&&(h.bone._parent=c.bone,c.bone.children.push(h.bone))}})(e,r,t,a),r.bones=[];for(var s=0;s<t.jointNames.length;s++){if(g=L(e,t.jointNames[s])){var l=g.node;if(l){o=g.id;var u=e.scene.getBoneByID(o);if(u)r.bones.push(u);else{for(var c=!1,d=null,f=0;f<s;f++){var h=L(e,t.jointNames[f]);if(h){var p=h.node;if(p){var m=p.children;if(m){c=!1;for(var _=0;_<m.length;_++)if(m[_]===o){d=b(e,t,t.jointNames[f],r),c=!0;break}if(c)break}}else W.Tools.Warn("Joint named "+t.jointNames[f]+" does not exist when looking for parent")}}var y=v(l);!d&&0<a.length&&(d=T(a,o))&&-1===i.indexOf(d)&&i.push(d),new W.Bone(l.jointName||"",r,d,y).id=o}}else W.Tools.Warn("Joint named "+t.jointNames[s]+" does not exist")}}var A=r.bones;r.bones=[];for(s=0;s<t.jointNames.length;s++){var g;if(g=L(e,t.jointNames[s]))for(f=0;f<A.length;f++)if(A[f].id===g.id){r.bones.push(A[f]);break}}r.prepare();for(s=0;s<i.length;s++)r.bones.push(i[s]);return r},O=function(e,t,n,r,o){if(o||((o=new W.Mesh(t.name||"",e.scene)).id=r),!t.babylonNode)return o;for(var a,i=[],s=null,l=new Array,u=new Array,c=new Array,d=new Array,f=0;f<n.length;f++){var h=n[f];if(w=e.meshes[h])for(var p=0;p<w.primitives.length;p++){var m=new W.VertexData,_=w.primitives[p];_.mode;var y=_.attributes,A=null,g=null;for(var v in y)if(A=e.accessors[y[v]],g=B.GLTFUtils.GetBufferFromAccessor(e,A),"NORMAL"===v)m.normals=new Float32Array(g.length),m.normals.set(g);else if("POSITION"===v){if(W.GLTFFileLoader.HomogeneousCoordinates){m.positions=new Float32Array(g.length-g.length/4);for(var b=0;b<g.length;b+=4)m.positions[b]=g[b],m.positions[b+1]=g[b+1],m.positions[b+2]=g[b+2]}else m.positions=new Float32Array(g.length),m.positions.set(g);u.push(m.positions.length)}else if(-1!==v.indexOf("TEXCOORD_")){var T=Number(v.split("_")[1]),L=W.VertexBuffer.UVKind+(0===T?"":T+1),E=new Float32Array(g.length);E.set(g),N(E),m.set(E,L)}else"JOINT"===v?(m.matricesIndices=new Float32Array(g.length),m.matricesIndices.set(g)):"WEIGHT"===v?(m.matricesWeights=new Float32Array(g.length),m.matricesWeights.set(g)):"COLOR"===v&&(m.colors=new Float32Array(g.length),m.colors.set(g));if(A=e.accessors[_.indices])g=B.GLTFUtils.GetBufferFromAccessor(e,A),m.indices=new Int32Array(g.length),m.indices.set(g),d.push(m.indices.length);else{var x=[];for(b=0;b<m.positions.length/3;b++)x.push(b);m.indices=new Int32Array(x),d.push(m.indices.length)}s?s.merge(m):s=m;var O=e.scene.getMaterialByID(_.material);i.push(null===O?B.GLTFUtils.GetDefaultMaterial(e.scene):O),l.push(0===l.length?0:l[l.length-1]+u[u.length-2]),c.push(0===c.length?0:c[c.length-1]+d[d.length-2])}}1<i.length?(a=new W.MultiMaterial("multimat"+r,e.scene)).subMaterials=i:a=new W.StandardMaterial("multimat"+r,e.scene),1===i.length&&(a=i[0]),o.material||(o.material=a),new W.Geometry(r,e.scene,s,!1,o),o.computeWorldMatrix(!0),o.subMeshes=[];var M=0;for(f=0;f<n.length;f++){var w;h=n[f];if(w=e.meshes[h])for(p=0;p<w.primitives.length;p++)w.primitives[p].mode,W.SubMesh.AddToMesh(M,l[M],u[M],c[M],d[M],o,o,!0),M++}return o},M=function(e,t,n,r){e.position&&(e.position=t),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=n),e.scaling&&(e.scaling=r)},s=function(e,t,n,r){var o=null;if(e.importOnlyMeshes&&(t.skin||t.meshes)&&e.importMeshesNames&&0<e.importMeshesNames.length&&-1===e.importMeshesNames.indexOf(t.name||""))return null;if(t.skin){if(t.meshes){var a=e.skins[t.skin];(i=O(e,t,t.meshes,n,t.babylonNode)).skeleton=e.scene.getLastSkeletonByID(t.skin),null===i.skeleton&&(i.skeleton=x(e,a,0,a.babylonSkeleton,t.skin),a.babylonSkeleton||(a.babylonSkeleton=i.skeleton)),o=i}}else if(t.meshes){var i;o=i=O(e,t,t.mesh?[t.mesh]:t.meshes,n,t.babylonNode)}else if(!t.light||t.babylonNode||e.importOnlyMeshes){if(t.camera&&!t.babylonNode&&!e.importOnlyMeshes){var s=e.cameras[t.camera];if(s)if("orthographic"===s.type){var l=new W.FreeCamera(t.camera,W.Vector3.Zero(),e.scene,!1);l.name=t.name||"",l.mode=W.Camera.ORTHOGRAPHIC_CAMERA,l.attachControl(e.scene.getEngine().getRenderingCanvas()),o=l}else if("perspective"===s.type){var u=s[s.type],c=new W.FreeCamera(t.camera,W.Vector3.Zero(),e.scene,!1);c.name=t.name||"",c.attachControl(e.scene.getEngine().getRenderingCanvas()),u.aspectRatio||(u.aspectRatio=e.scene.getEngine().getRenderWidth()/e.scene.getEngine().getRenderHeight()),u.znear&&u.zfar&&(c.maxZ=u.zfar,c.minZ=u.znear),o=c}}}else{var d=e.lights[t.light];if(d)if("ambient"===d.type){var f=d[d.type],h=new W.HemisphericLight(t.light,W.Vector3.Zero(),e.scene);h.name=t.name||"",f.color&&(h.diffuse=W.Color3.FromArray(f.color)),o=h}else if("directional"===d.type){var p=d[d.type],m=new W.DirectionalLight(t.light,W.Vector3.Zero(),e.scene);m.name=t.name||"",p.color&&(m.diffuse=W.Color3.FromArray(p.color)),o=m}else if("point"===d.type){var _=d[d.type],y=new W.PointLight(t.light,W.Vector3.Zero(),e.scene);y.name=t.name||"",_.color&&(y.diffuse=W.Color3.FromArray(_.color)),o=y}else if("spot"===d.type){var A=d[d.type],g=new W.SpotLight(t.light,W.Vector3.Zero(),W.Vector3.Zero(),0,0,e.scene);g.name=t.name||"",A.color&&(g.diffuse=W.Color3.FromArray(A.color)),A.fallOfAngle&&(g.angle=A.fallOfAngle),A.fallOffExponent&&(g.exponent=A.fallOffExponent),o=g}}if(!t.jointName){if(t.babylonNode)return t.babylonNode;if(null===o){var v=new W.Mesh(t.name||"",e.scene);o=t.babylonNode=v}}if(null!==o){if(t.matrix&&o instanceof W.Mesh)!(function(e,t,n){if(t.matrix){var r=new W.Vector3(0,0,0),o=new W.Quaternion,a=new W.Vector3(0,0,0);W.Matrix.FromArray(t.matrix).decompose(a,o,r),M(e,r,o,a)}else t.translation&&t.rotation&&t.scale&&M(e,W.Vector3.FromArray(t.translation),W.Quaternion.FromArray(t.rotation),W.Vector3.FromArray(t.scale));e.computeWorldMatrix(!0)})(o,t);else{var b=t.translation||[0,0,0],T=t.rotation||[0,0,0,1],L=t.scale||[1,1,1];M(o,W.Vector3.FromArray(b),W.Quaternion.FromArray(T),W.Vector3.FromArray(L))}o.updateCache(!0),t.babylonNode=o}return o},l=function(e,t,n,r){void 0===r&&(r=!1);var o=e.nodes[t],a=null;if(r=!(e.importOnlyMeshes&&!r&&e.importMeshesNames)||(-1!==e.importMeshesNames.indexOf(o.name||"")||0===e.importMeshesNames.length),!o.jointName&&r&&null!==(a=s(e,o,t))&&(a.id=t,a.parent=n),o.children)for(var i=0;i<o.children.length;i++)l(e,o.children[i],a,r)},d=function(e){var t=e.currentScene;if(t)for(var n=0;n<t.nodes.length;n++)l(e,t.nodes[n],null);else for(var r in e.scenes){t=e.scenes[r];for(n=0;n<t.nodes.length;n++)l(e,t.nodes[n],null)}!(function(e){for(var t in e.animations){var n=e.animations[t];if(n.channels&&n.samplers)for(var r=null,o=0;o<n.channels.length;o++){var a=n.channels[o],i=n.samplers[a.sampler];if(i){var s=null,l=null;n.parameters?(s=n.parameters[i.input],l=n.parameters[i.output]):(s=i.input,l=i.output);var u=B.GLTFUtils.GetBufferFromAccessor(e,e.accessors[s]),c=B.GLTFUtils.GetBufferFromAccessor(e,e.accessors[l]),d=a.target.id,f=e.scene.getNodeByID(d);if(null===f&&(f=e.scene.getNodeByName(d)),null!==f){var h=f instanceof W.Bone,p=a.target.path,m=w.indexOf(p);-1!==m&&(p=S[m]);var _=W.Animation.ANIMATIONTYPE_MATRIX;h||("rotationQuaternion"===p?(_=W.Animation.ANIMATIONTYPE_QUATERNION,f.rotationQuaternion=new W.Quaternion):_=W.Animation.ANIMATIONTYPE_VECTOR3);var y=null,A=[],g=0,v=!1;h&&r&&r.getKeys().length===u.length&&(y=r,v=!0),v||(y=new W.Animation(t,h?"_matrix":p,1,_,W.Animation.ANIMATIONLOOPMODE_CYCLE));for(var b=0;b<u.length;b++){var T=null;if("rotationQuaternion"===p?(T=W.Quaternion.FromArray([c[g],c[g+1],c[g+2],c[g+3]]),g+=4):(T=W.Vector3.FromArray([c[g],c[g+1],c[g+2]]),g+=3),h){var L=f,E=W.Vector3.Zero(),x=new W.Quaternion,O=W.Vector3.Zero(),M=L.getBaseMatrix();v&&r&&(M=r.getKeys()[b].value),M.decompose(O,x,E),"position"===p?E=T:"rotationQuaternion"===p?x=T:O=T,T=W.Matrix.Compose(O,x,E)}v?r&&(r.getKeys()[b].value=T):A.push({frame:u[b],value:T})}!v&&y&&(y.setKeys(A),f.animations.push(y)),r=y,e.scene.stopAnimation(f),e.scene.beginAnimation(f,0,u[u.length-1],!0,1)}else W.Tools.Warn("Creating animation named "+t+". But cannot find node named "+d+" to attach to")}}}})(e);for(n=0;n<e.scene.skeletons.length;n++){var o=e.scene.skeletons[n];e.scene.beginAnimation(o,0,Number.MAX_VALUE,!0,1)}},H=function(t,n,r,o,a,i){return function(e){!(function(e,n,t,r,o){var a=r.values||t.parameters,i=t.uniforms;for(var s in o){var l=o[s],u=l.type,c=a[i[s]];if(void 0===c&&(c=l.value),c){var d=function(t){return function(e){l.value&&t&&(n.setTexture(t,e),delete o[t])}};u===B.EParameterType.SAMPLER_2D?B.GLTFLoaderExtension.LoadTextureAsync(e,r.values?c:l.value,d(s),(function(){return d(null)})):l.value&&B.GLTFUtils.SetUniform(n,s,r.values?c:l.value,u)&&delete o[s]}}})(t,n,r,o,a),n.onBind=function(e){!(function(e,t,n,r,o,a,i){var s=a.values||o.parameters;for(var l in n){var u=n[l],c=u.type;if(c===B.EParameterType.FLOAT_MAT2||c===B.EParameterType.FLOAT_MAT3||c===B.EParameterType.FLOAT_MAT4)if(!u.semantic||u.source||u.node){if(u.semantic&&(u.source||u.node)){var d=t.scene.getNodeByName(u.source||u.node||"");if(null===d&&(d=t.scene.getNodeByID(u.source||u.node||"")),null===d)continue;B.GLTFUtils.SetMatrix(t.scene,d,u,l,r.getEffect())}}else B.GLTFUtils.SetMatrix(t.scene,e,u,l,r.getEffect());else{var f=s[o.uniforms[l]];if(!f)continue;if(c===B.EParameterType.SAMPLER_2D){var h=t.textures[a.values?f:u.value].babylonTexture;if(null==h)continue;r.getEffect().setTexture(l,h)}else B.GLTFUtils.SetUniform(r.getEffect(),l,f,c)}}i(r)})(e,t,a,n,r,o,i)}}},j=function(e,t,n){for(var r in t.uniforms){var o=t.uniforms[r],a=t.parameters[o];if(e.currentIdentifier===r&&a.semantic&&!a.source&&!a.node){var i=V.indexOf(a.semantic);if(-1!==i)return delete n[r],U[i]}}return e.currentIdentifier},f=function(e){for(var t in e.materials)B.GLTFLoaderExtension.LoadMaterialAsync(e,t,(function(e){}),(function(){}))},t=(function(){function e(){}return e.CreateRuntime=function(e,t,n){var r={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:t,rootUrl:n,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[]};return e.extensions&&o(e.extensions,"extensions",r),e.extensionsUsed&&o(e.extensionsUsed,"extensionsUsed",r),e.buffers&&(function(e,t){for(var n in e){var r=e[n];t.buffers[n]=r,t.buffersCount++}})(e.buffers,r),e.bufferViews&&o(e.bufferViews,"bufferViews",r),e.accessors&&o(e.accessors,"accessors",r),e.meshes&&o(e.meshes,"meshes",r),e.lights&&o(e.lights,"lights",r),e.cameras&&o(e.cameras,"cameras",r),e.nodes&&o(e.nodes,"nodes",r),e.images&&o(e.images,"images",r),e.textures&&o(e.textures,"textures",r),e.shaders&&(function(e,t){for(var n in e){var r=e[n];t.shaders[n]=r,t.shaderscount++}})(e.shaders,r),e.programs&&o(e.programs,"programs",r),e.samplers&&o(e.samplers,"samplers",r),e.techniques&&o(e.techniques,"techniques",r),e.materials&&o(e.materials,"materials",r),e.animations&&o(e.animations,"animations",r),e.skins&&o(e.skins,"skins",r),e.scenes&&(r.scenes=e.scenes),e.scene&&e.scenes&&(r.currentScene=e.scenes[e.scene]),r},e.LoadBufferAsync=function(e,t,n,r,o){var a=e.buffers[t];W.Tools.IsBase64(a.uri)?setTimeout((function(){return n(new Uint8Array(W.Tools.DecodeBase64(a.uri)))})):W.Tools.LoadFile(e.rootUrl+a.uri,(function(e){return n(new Uint8Array(e))}),o,void 0,!0,(function(e){e&&r(e.status+" "+e.statusText)}))},e.LoadTextureBufferAsync=function(e,t,n,r){var o=e.textures[t];if(o&&o.source)if(o.babylonTexture)n(null);else{var a=e.images[o.source];W.Tools.IsBase64(a.uri)?setTimeout((function(){return n(new Uint8Array(W.Tools.DecodeBase64(a.uri)))})):W.Tools.LoadFile(e.rootUrl+a.uri,(function(e){return n(new Uint8Array(e))}),void 0,void 0,!0,(function(e){e&&r(e.status+" "+e.statusText)}))}else r("")},e.CreateTextureAsync=function(e,t,n,r,o){var a=e.textures[t];if(a.babylonTexture)r(a.babylonTexture);else{var i=e.samplers[a.sampler],s=i.minFilter===B.ETextureFilterType.NEAREST_MIPMAP_NEAREST||i.minFilter===B.ETextureFilterType.NEAREST_MIPMAP_LINEAR||i.minFilter===B.ETextureFilterType.LINEAR_MIPMAP_NEAREST||i.minFilter===B.ETextureFilterType.LINEAR_MIPMAP_LINEAR,l=W.Texture.BILINEAR_SAMPLINGMODE,u=null==n?new Blob:new Blob([n]),c=URL.createObjectURL(u),d=function(){return URL.revokeObjectURL(c)},f=new W.Texture(c,e.scene,!s,!0,l,d,d);void 0!==i.wrapS&&(f.wrapU=B.GLTFUtils.GetWrapMode(i.wrapS)),void 0!==i.wrapT&&(f.wrapV=B.GLTFUtils.GetWrapMode(i.wrapT)),f.name=t,r(a.babylonTexture=f)}},e.LoadShaderStringAsync=function(e,t,n,r){var o=e.shaders[t];if(W.Tools.IsBase64(o.uri)){var a=atob(o.uri.split(",")[1]);n&&n(a)}else W.Tools.LoadFile(e.rootUrl+o.uri,n,void 0,void 0,!1,(function(e){e&&r&&r(e.status+" "+e.statusText)}))},e.LoadMaterialAsync=function(e,t,n,r){var o=e.materials[t];if(o.technique){var a=e.techniques[o.technique];if(!a){var i=new W.StandardMaterial(t,e.scene);return i.diffuseColor=new W.Color3(.5,.5,.5),i.sideOrientation=W.Material.CounterClockWiseSideOrientation,void n(i)}var s=e.programs[a.program],l=a.states,u=W.Effect.ShadersStore[s.vertexShader+"VertexShader"],c=W.Effect.ShadersStore[s.fragmentShader+"PixelShader"],d="",f="",h=new G(u),p=new G(c),m={},_=[],y=[],A=[];for(var g in a.uniforms){var v=a.uniforms[g],b=a.parameters[v];if(!(m[g]=b).semantic||b.node||b.source)b.type===B.EParameterType.SAMPLER_2D?A.push(g):_.push(g);else{var T=V.indexOf(b.semantic);-1!==T?(_.push(U[T]),delete m[g]):_.push(g)}}for(var L in a.attributes){var E=a.attributes[L];if((M=a.parameters[E]).semantic){var x=k(M);x&&y.push(x)}}for(;!h.isEnd()&&h.getNextToken();){if(h.currentToken===D.IDENTIFIER){var O=!1;for(var L in a.attributes){E=a.attributes[L];var M=a.parameters[E];if(h.currentIdentifier===L&&M.semantic){d+=k(M),O=!0;break}}O||(d+=j(h,a,m))}else d+=h.currentString}for(;!p.isEnd()&&p.getNextToken();){p.currentToken===D.IDENTIFIER?f+=j(p,a,m):f+=p.currentString}var w={vertex:s.vertexShader+t,fragment:s.fragmentShader+t},S={attributes:y,uniforms:_,samplers:A,needAlphaBlending:l&&l.enable&&-1!==l.enable.indexOf(3042)};W.Effect.ShadersStore[s.vertexShader+t+"VertexShader"]=d,W.Effect.ShadersStore[s.fragmentShader+t+"PixelShader"]=f;var N,F,C,P=new W.ShaderMaterial(t,e.scene,w,S);if(P.onError=(N=s,F=P,C=r,function(e,t){F.dispose(!0),C("Cannot compile program named "+N.name+". Error: "+t+". Default material will be applied")}),P.onCompiled=H(e,P,a,o,m,n),P.sideOrientation=W.Material.CounterClockWiseSideOrientation,l&&l.functions){var I=l.functions;I.cullFace&&I.cullFace[0]!==B.ECullingType.BACK&&(P.backFaceCulling=!1);var R=I.blendFuncSeparate;R&&(R[0]===B.EBlendingFunction.SRC_ALPHA&&R[1]===B.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&R[2]===B.EBlendingFunction.ONE&&R[3]===B.EBlendingFunction.ONE?P.alphaMode=W.Engine.ALPHA_COMBINE:R[0]===B.EBlendingFunction.ONE&&R[1]===B.EBlendingFunction.ONE&&R[2]===B.EBlendingFunction.ZERO&&R[3]===B.EBlendingFunction.ONE?P.alphaMode=W.Engine.ALPHA_ONEONE:R[0]===B.EBlendingFunction.SRC_ALPHA&&R[1]===B.EBlendingFunction.ONE&&R[2]===B.EBlendingFunction.ZERO&&R[3]===B.EBlendingFunction.ONE?P.alphaMode=W.Engine.ALPHA_ADD:R[0]===B.EBlendingFunction.ZERO&&R[1]===B.EBlendingFunction.ONE_MINUS_SRC_COLOR&&R[2]===B.EBlendingFunction.ONE&&R[3]===B.EBlendingFunction.ONE?P.alphaMode=W.Engine.ALPHA_SUBTRACT:R[0]===B.EBlendingFunction.DST_COLOR&&R[1]===B.EBlendingFunction.ZERO&&R[2]===B.EBlendingFunction.ONE&&R[3]===B.EBlendingFunction.ONE?P.alphaMode=W.Engine.ALPHA_MULTIPLY:R[0]===B.EBlendingFunction.SRC_ALPHA&&R[1]===B.EBlendingFunction.ONE_MINUS_SRC_COLOR&&R[2]===B.EBlendingFunction.ONE&&R[3]===B.EBlendingFunction.ONE&&(P.alphaMode=W.Engine.ALPHA_MAXIMIZED))}}else r&&r("No technique found.")},e})();B.GLTFLoaderBase=t;var n=(function(){function t(){this.state=null}return t.RegisterExtension=function(e){t.Extensions[e.name]?W.Tools.Error('Tool with the same name "'+e.name+'" already exists'):t.Extensions[e.name]=e},t.prototype.dispose=function(){},t.prototype._importMeshAsync=function(s,e,t,n,l,u,r){var c=this;return e.useRightHandedSystem=!0,B.GLTFLoaderExtension.LoadRuntimeAsync(e,t,n,(function(e){e.importOnlyMeshes=!0,""===s?e.importMeshesNames=[]:"string"==typeof s?e.importMeshesNames=[s]:!s||s instanceof Array?(e.importMeshesNames=[],W.Tools.Warn("Argument meshesNames must be of type string or string[]")):e.importMeshesNames=[s],c._createNodes(e);var t=new Array,n=new Array;for(var r in e.nodes){var o=e.nodes[r];o.babylonNode instanceof W.AbstractMesh&&t.push(o.babylonNode)}for(var a in e.skins){var i=e.skins[a];i.babylonSkeleton instanceof W.Skeleton&&n.push(i.babylonSkeleton)}c._loadBuffersAsync(e,(function(){c._loadShadersAsync(e,(function(){f(e),d(e),!W.GLTFFileLoader.IncrementalLoading&&l&&l(t,n)}))}),u),W.GLTFFileLoader.IncrementalLoading&&l&&l(t,n)}),r),!0},t.prototype.importMeshAsync=function(e,r,o,a,i){var s=this;return new Promise(function(n,t){s._importMeshAsync(e,r,o,a,(function(e,t){n({meshes:e,particleSystems:[],skeletons:t,animationGroups:[]})}),i,(function(e){t(new Error(e))}))})},t.prototype._loadAsync=function(e,t,n,r,o,a){var i=this;e.useRightHandedSystem=!0,B.GLTFLoaderExtension.LoadRuntimeAsync(e,t,n,(function(e){B.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(e,(function(){i._createNodes(e),i._loadBuffersAsync(e,(function(){i._loadShadersAsync(e,(function(){f(e),d(e),W.GLTFFileLoader.IncrementalLoading||r()}))})),W.GLTFFileLoader.IncrementalLoading&&r()}),a)}),a)},t.prototype.loadAsync=function(n,r,o,a){var i=this;return new Promise(function(e,t){i._loadAsync(n,r,o,(function(){e()}),a,(function(e){t(new Error(e))}))})},t.prototype._loadShadersAsync=function(r,o){var e=!1,t=function(t,n){B.GLTFLoaderExtension.LoadShaderStringAsync(r,t,(function(e){e instanceof ArrayBuffer||(r.loadedShaderCount++,e&&(W.Effect.ShadersStore[t+(n.type===B.EShaderType.VERTEX?"VertexShader":"PixelShader")]=e),r.loadedShaderCount===r.shaderscount&&o())}),(function(){W.Tools.Error("Error when loading shader program named "+t+" located at "+n.uri)}))};for(var n in r.shaders){e=!0;var a=r.shaders[n];a?t.bind(this,n,a)():W.Tools.Error("No shader named: "+n)}e||o()},t.prototype._loadBuffersAsync=function(r,o,e){var t=!1,n=function(t,n){B.GLTFLoaderExtension.LoadBufferAsync(r,t,(function(e){r.loadedBufferCount++,e&&(e.byteLength!=r.buffers[t].byteLength&&W.Tools.Error("Buffer named "+t+" is length "+e.byteLength+". Expected: "+n.byteLength),r.loadedBufferViews[t]=e),r.loadedBufferCount===r.buffersCount&&o()}),(function(){W.Tools.Error("Error when loading buffer named "+t+" located at "+n.uri)}))};for(var a in r.buffers){t=!0;var i=r.buffers[a];i?n.bind(this,a,i)():W.Tools.Error("No buffer named: "+a)}t||o()},t.prototype._createNodes=function(e){var t=e.currentScene;if(t)for(var n=0;n<t.nodes.length;n++)l(e,t.nodes[n],null);else for(var r in e.scenes){t=e.scenes[r];for(n=0;n<t.nodes.length;n++)l(e,t.nodes[n],null)}},t.Extensions={},t})();B.GLTFLoader=n,W.GLTFFileLoader._CreateGLTFLoaderV1=function(){return new n}})(W.GLTF1||(W.GLTF1={}))})(BABYLON||(BABYLON={})),(function(i){var s,e;s=i.GLTF1||(i.GLTF1={}),e=(function(){function o(){}return o.SetMatrix=function(e,t,n,r,o){var a=null;if("MODEL"===n.semantic?a=t.getWorldMatrix():"PROJECTION"===n.semantic?a=e.getProjectionMatrix():"VIEW"===n.semantic?a=e.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===n.semantic?a=i.Matrix.Transpose(t.getWorldMatrix().multiply(e.getViewMatrix()).invert()):"MODELVIEW"===n.semantic?a=t.getWorldMatrix().multiply(e.getViewMatrix()):"MODELVIEWPROJECTION"===n.semantic?a=t.getWorldMatrix().multiply(e.getTransformMatrix()):"MODELINVERSE"===n.semantic?a=t.getWorldMatrix().invert():"VIEWINVERSE"===n.semantic?a=e.getViewMatrix().invert():"PROJECTIONINVERSE"===n.semantic?a=e.getProjectionMatrix().invert():"MODELVIEWINVERSE"===n.semantic?a=t.getWorldMatrix().multiply(e.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===n.semantic?a=t.getWorldMatrix().multiply(e.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===n.semantic&&(a=i.Matrix.Transpose(t.getWorldMatrix().invert())),a)switch(n.type){case s.EParameterType.FLOAT_MAT2:o.setMatrix2x2(r,i.Matrix.GetAsMatrix2x2(a));break;case s.EParameterType.FLOAT_MAT3:o.setMatrix3x3(r,i.Matrix.GetAsMatrix3x3(a));break;case s.EParameterType.FLOAT_MAT4:o.setMatrix(r,a)}},o.SetUniform=function(e,t,n,r){switch(r){case s.EParameterType.FLOAT:return e.setFloat(t,n),!0;case s.EParameterType.FLOAT_VEC2:return e.setVector2(t,i.Vector2.FromArray(n)),!0;case s.EParameterType.FLOAT_VEC3:return e.setVector3(t,i.Vector3.FromArray(n)),!0;case s.EParameterType.FLOAT_VEC4:return e.setVector4(t,i.Vector4.FromArray(n)),!0;default:return!1}},o.GetWrapMode=function(e){switch(e){case s.ETextureWrapMode.CLAMP_TO_EDGE:return i.Texture.CLAMP_ADDRESSMODE;case s.ETextureWrapMode.MIRRORED_REPEAT:return i.Texture.MIRROR_ADDRESSMODE;case s.ETextureWrapMode.REPEAT:default:return i.Texture.WRAP_ADDRESSMODE}},o.GetByteStrideFromType=function(e){switch(e.type){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 1}},o.GetTextureFilterMode=function(e){switch(e){case s.ETextureFilterType.LINEAR:case s.ETextureFilterType.LINEAR_MIPMAP_NEAREST:case s.ETextureFilterType.LINEAR_MIPMAP_LINEAR:return i.Texture.TRILINEAR_SAMPLINGMODE;case s.ETextureFilterType.NEAREST:case s.ETextureFilterType.NEAREST_MIPMAP_NEAREST:return i.Texture.NEAREST_SAMPLINGMODE;default:return i.Texture.BILINEAR_SAMPLINGMODE}},o.GetBufferFromBufferView=function(e,t,n,r,o){n=t.byteOffset+n;var a=e.loadedBufferViews[t.buffer];if(n+r>a.byteLength)throw new Error("Buffer access is out of range");var i=a.buffer;switch(n+=a.byteOffset,o){case s.EComponentType.BYTE:return new Int8Array(i,n,r);case s.EComponentType.UNSIGNED_BYTE:return new Uint8Array(i,n,r);case s.EComponentType.SHORT:return new Int16Array(i,n,r);case s.EComponentType.UNSIGNED_SHORT:return new Uint16Array(i,n,r);default:return new Float32Array(i,n,r)}},o.GetBufferFromAccessor=function(e,t){var n=e.bufferViews[t.bufferView],r=t.count*o.GetByteStrideFromType(t);return o.GetBufferFromBufferView(e,n,t.byteOffset,r,t.componentType)},o.DecodeBufferToText=function(e){for(var t="",n=e.byteLength,r=0;r<n;++r)t+=String.fromCharCode(e[r]);return t},o.GetDefaultMaterial=function(e){if(!o._DefaultMaterial){i.Effect.ShadersStore.GLTFDefaultMaterialVertexShader=["precision highp float;","","uniform mat4 worldView;","uniform mat4 projection;","","attribute vec3 position;","","void main(void)","{","    gl_Position = projection * worldView * vec4(position, 1.0);","}"].join("\n"),i.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{","    gl_FragColor = u_emission;","}"].join("\n");var t={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};(o._DefaultMaterial=new i.ShaderMaterial("GLTFDefaultMaterial",e,{vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},t)).setColor4("u_emission",new i.Color4(.5,.5,.5,1))}return o._DefaultMaterial},o._DefaultMaterial=null,o})(),s.GLTFUtils=e})(BABYLON||(BABYLON={})),(function(e){var s,t;s=e.GLTF1||(e.GLTF1={}),t=(function(){function i(e){this._name=e}return Object.defineProperty(i.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),i.prototype.loadRuntimeAsync=function(e,t,n,r,o){return!1},i.prototype.loadRuntimeExtensionsAsync=function(e,t,n){return!1},i.prototype.loadBufferAsync=function(e,t,n,r,o){return!1},i.prototype.loadTextureBufferAsync=function(e,t,n,r){return!1},i.prototype.createTextureAsync=function(e,t,n,r,o){return!1},i.prototype.loadShaderStringAsync=function(e,t,n,r){return!1},i.prototype.loadMaterialAsync=function(e,t,n,r){return!1},i.LoadRuntimeAsync=function(t,n,r,o,a){i.ApplyExtensions((function(e){return e.loadRuntimeAsync(t,n,r,o,a)}),(function(){setTimeout((function(){o&&o(s.GLTFLoaderBase.CreateRuntime(n.json,t,r))}))}))},i.LoadRuntimeExtensionsAsync=function(t,n,r){i.ApplyExtensions((function(e){return e.loadRuntimeExtensionsAsync(t,n,r)}),(function(){setTimeout((function(){n()}))}))},i.LoadBufferAsync=function(t,n,r,o,a){i.ApplyExtensions((function(e){return e.loadBufferAsync(t,n,r,o,a)}),(function(){s.GLTFLoaderBase.LoadBufferAsync(t,n,r,o,a)}))},i.LoadTextureAsync=function(t,n,r,o){i.LoadTextureBufferAsync(t,n,(function(e){e&&i.CreateTextureAsync(t,n,e,r,o)}),o)},i.LoadShaderStringAsync=function(t,n,r,o){i.ApplyExtensions((function(e){return e.loadShaderStringAsync(t,n,r,o)}),(function(){s.GLTFLoaderBase.LoadShaderStringAsync(t,n,r,o)}))},i.LoadMaterialAsync=function(t,n,r,o){i.ApplyExtensions((function(e){return e.loadMaterialAsync(t,n,r,o)}),(function(){s.GLTFLoaderBase.LoadMaterialAsync(t,n,r,o)}))},i.LoadTextureBufferAsync=function(t,n,r,o){i.ApplyExtensions((function(e){return e.loadTextureBufferAsync(t,n,r,o)}),(function(){s.GLTFLoaderBase.LoadTextureBufferAsync(t,n,r,o)}))},i.CreateTextureAsync=function(t,n,r,o,a){i.ApplyExtensions((function(e){return e.createTextureAsync(t,n,r,o,a)}),(function(){s.GLTFLoaderBase.CreateTextureAsync(t,n,r,o,a)}))},i.ApplyExtensions=function(e,t){for(var n in s.GLTFLoader.Extensions){if(e(s.GLTFLoader.Extensions[n]))return}t()},i})(),s.GLTFLoaderExtension=t})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};return function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}})();!(function(e){var l,t;l=e.GLTF1||(e.GLTF1={}),t=(function(e){function t(){return e.call(this,"KHR_binary_glTF")||this}return __extends(t,e),t.prototype.loadRuntimeAsync=function(e,t,n,r,o){var a=t.json.extensionsUsed;return!(!a||-1===a.indexOf(this.name)||!t.bin)&&(this._bin=t.bin,r(l.GLTFLoaderBase.CreateRuntime(t.json,e,n)),!0)},t.prototype.loadBufferAsync=function(e,t,n,r){return-1!==e.extensionsUsed.indexOf(this.name)&&("binary_glTF"===t&&(n(this._bin),!0))},t.prototype.loadTextureBufferAsync=function(e,t,n,r){var o=e.textures[t],a=e.images[o.source];if(!(a.extensions&&this.name in a.extensions))return!1;var i=a.extensions[this.name],s=e.bufferViews[i.bufferView];return n(l.GLTFUtils.GetBufferFromBufferView(e,s,0,s.byteLength,l.EComponentType.UNSIGNED_BYTE)),!0},t.prototype.loadShaderStringAsync=function(e,t,n,r){var o=e.shaders[t];if(!(o.extensions&&this.name in o.extensions))return!1;var a=o.extensions[this.name],i=e.bufferViews[a.bufferView],s=l.GLTFUtils.GetBufferFromBufferView(e,i,0,i.byteLength,l.EComponentType.UNSIGNED_BYTE);return setTimeout((function(){var e=l.GLTFUtils.DecodeBufferToText(s);n(e)})),!0},t})(l.GLTFLoaderExtension),l.GLTFBinaryExtension=t,l.GLTFLoader.RegisterExtension(new t)})(BABYLON||(BABYLON={}));var BABYLON;__extends=this&&this.__extends||(function(){var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};return function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}})();!(function(p){var i,e;i=p.GLTF1||(p.GLTF1={}),e=(function(e){function t(){return e.call(this,"KHR_materials_common")||this}return __extends(t,e),t.prototype.loadRuntimeExtensionsAsync=function(e,t,n){if(!e.extensions)return!1;var r=e.extensions[this.name];if(!r)return!1;var o=r.lights;if(o)for(var a in o){var i=o[a];switch(i.type){case"ambient":var s=new p.HemisphericLight(i.name,new p.Vector3(0,1,0),e.scene),l=i.ambient;l&&(s.diffuse=p.Color3.FromArray(l.color||[1,1,1]));break;case"point":var u=new p.PointLight(i.name,new p.Vector3(10,10,10),e.scene),c=i.point;c&&(u.diffuse=p.Color3.FromArray(c.color||[1,1,1]));break;case"directional":var d=new p.DirectionalLight(i.name,new p.Vector3(0,-1,0),e.scene),f=i.directional;f&&(d.diffuse=p.Color3.FromArray(f.color||[1,1,1]));break;case"spot":var h=i.spot;if(h)new p.SpotLight(i.name,new p.Vector3(0,10,0),new p.Vector3(0,-1,0),h.fallOffAngle||Math.PI,h.fallOffExponent||0,e.scene).diffuse=p.Color3.FromArray(h.color||[1,1,1]);break;default:p.Tools.Warn('GLTF Material Common extension: light type "'+i.type+"” not supported")}}return!1},t.prototype.loadMaterialAsync=function(e,t,n,r){var o=e.materials[t];if(!o||!o.extensions)return!1;var a=o.extensions[this.name];if(!a)return!1;var i=new p.StandardMaterial(t,e.scene);return i.sideOrientation=p.Material.CounterClockWiseSideOrientation,"CONSTANT"===a.technique&&(i.disableLighting=!0),i.backFaceCulling=void 0!==a.doubleSided&&!a.doubleSided,i.alpha=void 0===a.values.transparency?1:a.values.transparency,i.specularPower=void 0===a.values.shininess?0:a.values.shininess,"string"==typeof a.values.ambient?this._loadTexture(e,a.values.ambient,i,"ambientTexture",r):i.ambientColor=p.Color3.FromArray(a.values.ambient||[0,0,0]),"string"==typeof a.values.diffuse?this._loadTexture(e,a.values.diffuse,i,"diffuseTexture",r):i.diffuseColor=p.Color3.FromArray(a.values.diffuse||[0,0,0]),"string"==typeof a.values.emission?this._loadTexture(e,a.values.emission,i,"emissiveTexture",r):i.emissiveColor=p.Color3.FromArray(a.values.emission||[0,0,0]),"string"==typeof a.values.specular?this._loadTexture(e,a.values.specular,i,"specularTexture",r):i.specularColor=p.Color3.FromArray(a.values.specular||[0,0,0]),!0},t.prototype._loadTexture=function(t,n,r,o,a){i.GLTFLoaderBase.LoadTextureBufferAsync(t,n,(function(e){i.GLTFLoaderBase.CreateTextureAsync(t,n,e,(function(e){return r[o]=e}),a)}),a)},t})(i.GLTFLoaderExtension),i.GLTFMaterialsCommonExtension=e,i.GLTFLoader.RegisterExtension(new e)})(BABYLON||(BABYLON={})),(function(b){!(function(e){var v=(function(){function e(){}return e.Get=function(e,t,n){if(!t||null==n||!t[n])throw new Error(e+": Failed to find index ("+n+")");return t[n]},e.Assign=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},e})();e.ArrayItem=v;var t=(function(){function p(e){this._completePromises=new Array,this._disposed=!1,this._state=null,this._extensions={},this._defaultBabylonMaterialData={},this._requests=new Array,this._parent=e}return p.RegisterExtension=function(e,t){p.UnregisterExtension(e)&&b.Tools.Warn("Extension with the name '"+e+"' already exists"),p._ExtensionFactories[e]=t,p._ExtensionNames.push(e)},p.UnregisterExtension=function(e){if(!p._ExtensionFactories[e])return!1;delete p._ExtensionFactories[e];var t=p._ExtensionNames.indexOf(e);return-1!==t&&p._ExtensionNames.splice(t,1),!0},Object.defineProperty(p.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),p.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 n in this._requests.length=0,delete this.gltf,delete this.babylonScene,this._completePromises.length=0,this._extensions){this._extensions[n].dispose&&this._extensions[n].dispose()}this._extensions={},delete this._rootBabylonMesh,delete this._progressCallback,this._parent._clear()}},p.prototype.importMeshAsync=function(a,i,s,l,u,c){var d=this;return Promise.resolve().then((function(){d.babylonScene=i,d._rootUrl=l,d._fileName=c||"scene",d._progressCallback=u,d._loadData(s);var e=null;if(a){var n={};if(d.gltf.nodes)for(var t=0,r=d.gltf.nodes;t<r.length;t++){var o=r[t];o.name&&(n[o.name]=o.index)}e=(a instanceof Array?a:[a]).map((function(e){var t=n[e];if(void 0===t)throw new Error("Failed to find node '"+e+"'");return t}))}return d._loadAsync(e,(function(){return{meshes:d._getMeshes(),particleSystems:[],skeletons:d._getSkeletons(),animationGroups:d._getAnimationGroups()}}))}))},p.prototype.loadAsync=function(e,t,n,r,o){var a=this;return Promise.resolve().then((function(){return a.babylonScene=e,a._rootUrl=n,a._fileName=o||"scene",a._progressCallback=r,a._loadData(t),a._loadAsync(null,(function(){}))}))},p.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 n=new Array;if(a)n.push(s.loadSceneAsync("#/nodes",{nodes:a,index:-1}));else{var r=v.Get("#/scene",s.gltf.scenes,s.gltf.scene||0);n.push(s.loadSceneAsync("#/scenes/"+r.index,r))}s._parent.compileMaterials&&n.push(s._compileMaterialsAsync()),s._parent.compileShadowGenerators&&n.push(s._compileShadowGeneratorsAsync());var o=Promise.all(n).then((function(){return 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}))},p.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 n=t[0];(n.byteLength<e.bin.byteLength-3||n.byteLength>e.bin.byteLength)&&b.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+e.bin.byteLength+")"),n._data=Promise.resolve(e.bin)}else b.Tools.Warn("Unexpected BIN chunk")}},p.prototype._setupData=function(){if(v.Assign(this.gltf.accessors),v.Assign(this.gltf.animations),v.Assign(this.gltf.buffers),v.Assign(this.gltf.bufferViews),v.Assign(this.gltf.cameras),v.Assign(this.gltf.images),v.Assign(this.gltf.materials),v.Assign(this.gltf.meshes),v.Assign(this.gltf.nodes),v.Assign(this.gltf.samplers),v.Assign(this.gltf.scenes),v.Assign(this.gltf.skins),v.Assign(this.gltf.textures),this.gltf.nodes){for(var e={},t=0,n=this.gltf.nodes;t<n.length;t++){if((l=n[t]).children)for(var r=0,o=l.children;r<o.length;r++){e[o[r]]=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]}}},p.prototype._loadExtensions=function(){for(var e=0,t=p._ExtensionNames;e<t.length;e++){var n=t[e],r=p._ExtensionFactories[n](this);this._extensions[n]=r,this._parent.onExtensionLoadedObservable.notifyObservers(r)}this._parent.onExtensionLoadedObservable.clear()},p.prototype._checkExtensions=function(){if(this.gltf.extensionsRequired)for(var e=0,t=this.gltf.extensionsRequired;e<t.length;e++){var n=t[e],r=this._extensions[n];if(!r||!r.enabled)throw new Error("Require extension "+n+" is not available")}},p.prototype._setState=function(e){this._state=e,this.log(b.GLTFLoaderState[this._state])},p.prototype._createRootNode=function(){this._rootBabylonMesh=new b.Mesh("__root__",this.babylonScene);var e={_babylonMesh: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],p._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},p.prototype.loadSceneAsync=function(e,t){var n=this,r=this._extensionsLoadSceneAsync(e,t);if(r)return r;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=v.Get(e+"/nodes/"+s,this.gltf.nodes,s);o.push(this.loadNodeAsync("#/nodes/"+l.index,l,(function(e){e.parent=n._rootBabylonMesh})))}return o.push(this._loadAnimationsAsync()),this.logClose(),Promise.all(o).then((function(){}))},p.prototype._forEachPrimitive=function(e,t){if(e._primitiveBabylonMeshes)for(var n=0,r=e._primitiveBabylonMeshes;n<r.length;n++){t(r[n])}else t(e._babylonMesh)},p.prototype._getMeshes=function(){var e=new Array;e.push(this._rootBabylonMesh);var t=this.gltf.nodes;if(t)for(var n=0,r=t;n<r.length;n++){var o=r[n];if(o._babylonMesh&&e.push(o._babylonMesh),o._primitiveBabylonMeshes)for(var a=0,i=o._primitiveBabylonMeshes;a<i.length;a++){var s=i[a];e.push(s)}}return e},p.prototype._getSkeletons=function(){var e=new Array,t=this.gltf.skins;if(t)for(var n=0,r=t;n<r.length;n++){var o=r[n];o._babylonSkeleton&&e.push(o._babylonSkeleton)}return e},p.prototype._getAnimationGroups=function(){var e=new Array,t=this.gltf.animations;if(t)for(var n=0,r=t;n<r.length;n++){var o=r[n];o._babylonAnimationGroup&&e.push(o._babylonAnimationGroup)}return e},p.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,n=e=this._getAnimationGroups();t<n.length;t++){n[t].start(!0)}break;default:return void b.Tools.Error("Invalid animation start mode ("+this._parent.animationStartMode+")")}},p.prototype.loadNodeAsync=function(n,r,e){var o=this;void 0===e&&(e=function(){});var t=this._extensionsLoadNodeAsync(n,r,e);if(t)return t;if(r._babylonMesh)throw new Error(n+": Invalid recursive node hierarchy");var a=new Array;this.logOpen(n+" "+(r.name||""));var i=new b.Mesh(r.name||"node"+r.index,this.babylonScene);if((r._babylonMesh=i).setEnabled(!1),p._LoadTransform(r,i),null!=r.mesh){var s=v.Get(n+"/mesh",this.gltf.meshes,r.mesh);a.push(this._loadMeshAsync("#/meshes/"+s.index,r,s,i))}if(null!=r.camera){var l=v.Get(n+"/camera",this.gltf.cameras,r.camera);a.push(this.loadCameraAsync("#/cameras/"+l.index,l,(function(e){e.parent=i})))}if(r.children)for(var u=function(e){var t=v.Get(n+"/children/"+e,c.gltf.nodes,e);a.push(c.loadNodeAsync("#/nodes/"+r.index,t,(function(e){null==t.skin?e.parent=i:e.parent=o._rootBabylonMesh})))},c=this,d=0,f=r.children;d<f.length;d++){u(f[d])}return e(i),this._parent.onMeshLoadedObservable.notifyObservers(i),this.logClose(),Promise.all(a).then((function(){return i.setEnabled(!0),i}))},p.prototype._loadMeshAsync=function(e,t,n,r){var o=this,a=new Array;this.logOpen(e+" "+(n.name||""));var i=n.primitives;if(!i||0===i.length)throw new Error(e+": Primitives are missing");if(v.Assign(i),1===i.length){var s=i[0];a.push(this._loadMeshPrimitiveAsync(e+"/primitives/"+s.index,t,n,s,r))}else{t._primitiveBabylonMeshes=[];for(var l=0,u=i;l<u.length;l++){s=u[l];var c=new b.Mesh((n.name||r.name)+"_"+s.index,this.babylonScene,r);t._primitiveBabylonMeshes.push(c),a.push(this._loadMeshPrimitiveAsync(e+"/primitives/"+s.index,t,n,s,c)),this._parent.onMeshLoadedObservable.notifyObservers(r)}}if(null!=t.skin){var d=v.Get(e+"/skin",this.gltf.skins,t.skin);a.push(this._loadSkinAsync("#/skins/"+d.index,t,d))}return this.logClose(),Promise.all(a).then((function(){o._forEachPrimitive(t,(function(e){e._refreshBoundingInfo(!0)}))}))},p.prototype._loadMeshPrimitiveAsync=function(t,e,n,r,o){var a=this,i=new Array;this.logOpen(""+t),this._createMorphTargets(t,e,n,r,o),i.push(this._loadVertexDataAsync(t,r,o).then((function(e){return a._loadMorphTargetsAsync(t,r,o,e).then((function(){e.applyToMesh(o)}))})));var s=p._GetDrawMode(t,r.mode);if(null==r.material){var l=this._defaultBabylonMaterialData[s];l||(l=this._createDefaultMaterial("__gltf_default",s),this._parent.onMaterialLoadedObservable.notifyObservers(l),this._defaultBabylonMaterialData[s]=l),o.material=l}else{var u=v.Get(t+"/material",this.gltf.materials,r.material);i.push(this._loadMaterialAsync("#/materials/"+u.index,u,o,s,(function(e){o.material=e})))}return this.logClose(),Promise.all(i).then((function(){}))},p.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 n=v.Get(o+"/indices",this.gltf.accessors,e.indices);l.push(this._loadIndicesAccessorAsync("#/accessors/"+n.index,n).then((function(e){u.setIndices(e)})))}var r=function(e,t,n){if(null!=s[e]){a._delayInfo=a._delayInfo||[],-1===a._delayInfo.indexOf(t)&&a._delayInfo.push(t);var r=v.Get(o+"/attributes/"+e,i.gltf.accessors,s[e]);l.push(i._loadVertexAccessorAsync("#/accessors/"+r.index,r,t).then((function(e){u.setVerticesBuffer(e,r.count)}))),n&&n(r)}};return r("POSITION",b.VertexBuffer.PositionKind),r("NORMAL",b.VertexBuffer.NormalKind),r("TANGENT",b.VertexBuffer.TangentKind),r("TEXCOORD_0",b.VertexBuffer.UVKind),r("TEXCOORD_1",b.VertexBuffer.UV2Kind),r("JOINTS_0",b.VertexBuffer.MatricesIndicesKind),r("WEIGHTS_0",b.VertexBuffer.MatricesWeightsKind),r("COLOR_0",b.VertexBuffer.ColorKind,(function(e){"VEC4"===e.type&&(a.hasVertexAlpha=!0)})),Promise.all(l).then((function(){return u}))},p.prototype._createMorphTargets=function(e,t,n,r,o){if(r.targets){if(null==t._numMorphTargets)t._numMorphTargets=r.targets.length;else if(r.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<r.targets.length;a++){var i=t.weights?t.weights[a]:n.weights?n.weights[a]:0;o.morphTargetManager.addTarget(new b.MorphTarget("morphTarget"+a,i))}}},p.prototype._loadMorphTargetsAsync=function(e,t,n,r){if(!t.targets)return Promise.resolve();for(var o=new Array,a=n.morphTargetManager,i=0;i<a.numTargets;i++){var s=a.getTarget(i);o.push(this._loadMorphTargetVertexDataAsync(e+"/targets/"+i,r,t.targets[i],s))}return Promise.all(o).then((function(){}))},p.prototype._loadMorphTargetVertexDataAsync=function(a,i,s,t){var l=this,u=new Array,e=function(e,t,n){if(null!=s[e]){var r=i.getVertexBuffer(t);if(r){var o=v.Get(a+"/"+e,l.gltf.accessors,s[e]);u.push(l._loadFloatAccessorAsync("#/accessors/"+o.index,o).then((function(e){n(r,e)})))}}};return e("POSITION",b.VertexBuffer.PositionKind,(function(e,n){e.forEach(n.length,(function(e,t){n[t]+=e})),t.setPositions(n)})),e("NORMAL",b.VertexBuffer.NormalKind,(function(e,n){e.forEach(n.length,(function(e,t){n[t]+=e})),t.setNormals(n)})),e("TANGENT",b.VertexBuffer.TangentKind,(function(e,n){var r=0;e.forEach(n.length/3*4,(function(e,t){(t+1)%4!=0&&(n[r++]+=e)})),t.setTangents(n)})),Promise.all(u).then((function(){}))},p._LoadTransform=function(e,t){var n=b.Vector3.Zero(),r=b.Quaternion.Identity(),o=b.Vector3.One();e.matrix?b.Matrix.FromArray(e.matrix).decompose(o,r,n):(e.translation&&(n=b.Vector3.FromArray(e.translation)),e.rotation&&(r=b.Quaternion.FromArray(e.rotation)),e.scale&&(o=b.Vector3.FromArray(e.scale)));t.position=n,t.rotationQuaternion=r,t.scaling=o},p.prototype._loadSkinAsync=function(e,n,t){var r=this,o=function(t){r._forEachPrimitive(n,(function(e){e.skeleton=t})),n._babylonMesh.position=b.Vector3.Zero(),n._babylonMesh.rotationQuaternion=b.Quaternion.Identity(),n._babylonMesh.scaling=b.Vector3.One()};if(t._promise)return t._promise.then((function(){o(t._babylonSkeleton)}));var a="skeleton"+t.index,i=new b.Skeleton(t.name||a,a,this.babylonScene);return t._babylonSkeleton=i,this._loadBones(e,t),o(i),t._promise=this._loadSkinInverseBindMatricesDataAsync(e,t).then((function(e){r._updateBoneMatrices(i,e)}))},p.prototype._loadBones=function(e,t){for(var n={},r=0,o=t.joints;r<o.length;r++){var a=o[r],i=v.Get(e+"/joints/"+a,this.gltf.nodes,a);this._loadBone(i,t,n)}},p.prototype._loadBone=function(e,t,n){var r=n[e.index];if(r)return r;var o=null;e.parent&&e.parent._babylonMesh!==this._rootBabylonMesh&&(o=this._loadBone(e.parent,t,n));var a=t.joints.indexOf(e.index);return r=new b.Bone(e.name||"joint"+e.index,t._babylonSkeleton,o,this._getNodeMatrix(e),null,null,a),n[e.index]=r,e._babylonBones=e._babylonBones||[],e._babylonBones.push(r),r},p.prototype._loadSkinInverseBindMatricesDataAsync=function(e,t){if(null==t.inverseBindMatrices)return Promise.resolve(null);var n=v.Get(e+"/inverseBindMatrices",this.gltf.accessors,t.inverseBindMatrices);return this._loadFloatAccessorAsync("#/accessors/"+n.index,n)},p.prototype._updateBoneMatrices=function(e,t){for(var n=0,r=e.bones;n<r.length;n++){var o=r[n],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)}},p.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())},p.prototype.loadCameraAsync=function(e,t,n){void 0===n&&(n=function(){});var r=this._extensionsLoadCameraAsync(e,t,n);if(r)return r;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 n(a),this._parent.onCameraLoadedObservable.notifyObservers(a),Promise.all(o).then((function(){return a}))},p.prototype._loadAnimationsAsync=function(){var e=this.gltf.animations;if(!e)return Promise.resolve();for(var t=new Array,n=0;n<e.length;n++){var r=e[n];t.push(this.loadAnimationAsync("#/animations/"+r.index,r))}return Promise.all(t).then((function(){}))},p.prototype.loadAnimationAsync=function(e,t){var n=this._extensionsLoadAnimationAsync(e,t);if(n)return n;var r=new b.AnimationGroup(t.name||"animation"+t.index,this.babylonScene);t._babylonAnimationGroup=r;var o=new Array;v.Assign(t.channels),v.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,r))}return Promise.all(o).then((function(){return r.normalize(0),r}))},p.prototype._loadAnimationChannelAsync=function(m,e,t,_,y){var A=this,g=v.Get(m+"/target/node",this.gltf.nodes,_.target.node);if("weights"===_.target.path&&!g._numMorphTargets||"weights"!==_.target.path&&!g._babylonMesh)return Promise.resolve();if(null!=g.skin&&"weights"!==_.target.path)return Promise.resolve();var n=v.Get(m+"/sampler",t.samplers,_.sampler);return this._loadAnimationSamplerAsync(e+"/samplers/"+_.sampler,n).then((function(n){var t,a;switch(_.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(m+"/target/path: Invalid value ("+_.target.path+")")}var r,e,o=0;switch(t){case"position":r=function(){var e=b.Vector3.FromArray(n.output,o);return o+=3,e};break;case"rotationQuaternion":r=function(){var e=b.Quaternion.FromArray(n.output,o);return o+=4,e};break;case"scaling":r=function(){var e=b.Vector3.FromArray(n.output,o);return o+=3,e};break;case"influence":r=function(){for(var e=new Array(g._numMorphTargets),t=0;t<g._numMorphTargets;t++)e[t]=n.output[o++];return e}}switch(n.interpolation){case"STEP":e=function(e){return{frame:n.input[e],value:r(),interpolation:b.AnimationKeyInterpolation.STEP}};break;case"LINEAR":e=function(e){return{frame:n.input[e],value:r()}};break;case"CUBICSPLINE":e=function(e){return{frame:n.input[e],inTangent:r(),value:r(),outTangent:r()}}}for(var i=new Array(n.input.length),s=0;s<n.input.length;s++)i[s]=e(s);if("influence"===t)for(var l=function(r){var e=y.name+"_channel"+y.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[r]:void 0,value:e.value[r],outTangent:e.outTangent?e.outTangent[r]:void 0}}))),A._forEachPrimitive(g,(function(e){var t=e.morphTargetManager.getTarget(r),n=o.clone();t.animations.push(n),y.addTargetedAnimation(n,t)}))},u=0;u<g._numMorphTargets;u++)l(u);else{var c=y.name+"_channel"+y.targetedAnimations.length,d=new b.Animation(c,t,1,a);if(d.setKeys(i),g._babylonBones){for(var f=[g._babylonMesh].concat(g._babylonBones),h=0,p=f;h<p.length;h++){p[h].animations.push(d)}y.addTargetedAnimation(d,f)}else g._babylonMesh.animations.push(d),y.addTargetedAnimation(d,g._babylonMesh)}}))},p.prototype._loadAnimationSamplerAsync=function(e,t){if(t._data)return t._data;var r=t.interpolation||"LINEAR";switch(r){case"STEP":case"LINEAR":case"CUBICSPLINE":break;default:throw new Error(e+"/interpolation: Invalid value ("+t.interpolation+")")}var n=v.Get(e+"/input",this.gltf.accessors,t.input),o=v.Get(e+"/output",this.gltf.accessors,t.output);return t._data=Promise.all([this._loadFloatAccessorAsync("#/accessors/"+n.index,n),this._loadFloatAccessorAsync("#/accessors/"+o.index,o)]).then((function(e){var t=e[0],n=e[1];return{input:t,interpolation:r,output:n}})),t._data},p.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},p.prototype.loadBufferViewAsync=function(t,n){if(n._data)return n._data;var e=v.Get(t+"/buffer",this.gltf.buffers,n.buffer);return n._data=this._loadBufferAsync("#/buffers/"+e.index,e).then((function(e){try{return new Uint8Array(e.buffer,e.byteOffset+(n.byteOffset||0),n.byteLength)}catch(e){throw new Error(t+": "+e.message)}})),n._data},p.prototype._loadIndicesAccessorAsync=function(t,n){if("SCALAR"!==n.type)throw new Error(t+"/type: Invalid value "+n.type);if(5121!==n.componentType&&5123!==n.componentType&&5125!==n.componentType)throw new Error(t+"/componentType: Invalid value "+n.componentType);if(n._data)return n._data;var e=v.Get(t+"/bufferView",this.gltf.bufferViews,n.bufferView);return n._data=this.loadBufferViewAsync("#/bufferViews/"+e.index,e).then((function(e){return p._GetTypedArray(t,n.componentType,e,n.byteOffset,n.count)})),n._data},p.prototype._loadFloatAccessorAsync=function(c,d){var n=this;if(5126!==d.componentType)throw new Error("Invalid component type "+d.componentType);if(d._data)return d._data;var f=p._GetNumComponents(c,d.type),t=f*d.count;if(null==d.bufferView)d._data=Promise.resolve(new Float32Array(t));else{var e=v.Get(c+"/bufferView",this.gltf.bufferViews,d.bufferView);d._data=this.loadBufferViewAsync("#/bufferViews/"+e.index,e).then((function(e){return p._GetTypedArray(c,d.componentType,e,d.byteOffset,t)}))}if(d.sparse){var h=d.sparse;d._data=d._data.then((function(u){var e=v.Get(c+"/sparse/indices/bufferView",n.gltf.bufferViews,h.indices.bufferView),t=v.Get(c+"/sparse/values/bufferView",n.gltf.bufferViews,h.values.bufferView);return Promise.all([n.loadBufferViewAsync("#/bufferViews/"+e.index,e),n.loadBufferViewAsync("#/bufferViews/"+t.index,t)]).then((function(e){for(var t=e[0],n=e[1],r=p._GetTypedArray(c+"/sparse/indices",h.indices.componentType,t,h.indices.byteOffset,h.count),o=p._GetTypedArray(c+"/sparse/values",d.componentType,n,h.values.byteOffset,f*h.count),a=0,i=0;i<r.length;i++)for(var s=r[i]*f,l=0;l<f;l++)u[s++]=o[a++];return u}))}))}return d._data},p.prototype._loadVertexBufferViewAsync=function(e,t){var n=this;return e._babylonBuffer||(e._babylonBuffer=this.loadBufferViewAsync("#/bufferViews/"+e.index,e).then((function(e){return new b.Buffer(n.babylonScene.getEngine(),e,!1)}))),e._babylonBuffer},p.prototype._loadVertexAccessorAsync=function(n,r,o){var a=this;if(r._babylonVertexBuffer)return r._babylonVertexBuffer;if(r.sparse)r._babylonVertexBuffer=this._loadFloatAccessorAsync("#/accessors/"+r.index,r).then((function(e){return new b.VertexBuffer(a.babylonScene.getEngine(),e,o,!1)}));else if(r.byteOffset&&r.byteOffset%b.VertexBuffer.GetTypeByteLength(r.componentType)!=0)b.Tools.Warn("Accessor byte offset is not a multiple of component type byte length"),r._babylonVertexBuffer=this._loadFloatAccessorAsync("#/accessors/"+r.index,r).then((function(e){return new b.VertexBuffer(a.babylonScene.getEngine(),e,o,!1)}));else{var i=v.Get(n+"/bufferView",this.gltf.bufferViews,r.bufferView);r._babylonVertexBuffer=this._loadVertexBufferViewAsync(i,o).then((function(e){var t=p._GetNumComponents(n,r.type);return new b.VertexBuffer(a.babylonScene.getEngine(),e,o,!1,!1,i.byteStride,!1,r.byteOffset,t,r.componentType,r.normalized,!0)}))}return r._babylonVertexBuffer},p.prototype._loadMaterialMetallicRoughnessPropertiesAsync=function(e,t,n){if(!(n instanceof b.PBRMaterial))throw new Error(e+": Material type not supported");var r=new Array;return t&&(t.baseColorFactor?(n.albedoColor=b.Color3.FromArray(t.baseColorFactor),n.alpha=t.baseColorFactor[3]):n.albedoColor=b.Color3.White(),n.metallic=null==t.metallicFactor?1:t.metallicFactor,n.roughness=null==t.roughnessFactor?1:t.roughnessFactor,t.baseColorTexture&&r.push(this.loadTextureInfoAsync(e+"/baseColorTexture",t.baseColorTexture,(function(e){n.albedoTexture=e}))),t.metallicRoughnessTexture&&(r.push(this.loadTextureInfoAsync(e+"/metallicRoughnessTexture",t.metallicRoughnessTexture,(function(e){n.metallicTexture=e}))),n.useMetallnessFromMetallicTextureBlue=!0,n.useRoughnessFromMetallicTextureGreen=!0,n.useRoughnessFromMetallicTextureAlpha=!1)),Promise.all(r).then((function(){}))},p.prototype._loadMaterialAsync=function(e,t,n,r,o){void 0===o&&(o=function(){});var a=this._extensionsLoadMaterialAsync(e,t,n,r,o);if(a)return a;t._babylonData=t._babylonData||{};var i=t._babylonData[r];if(!i){this.logOpen(e+" "+(t.name||""));var s=this.createMaterial(e,t,r);i={material:s,meshes:[],promise:this.loadMaterialPropertiesAsync(e,t,s)},t._babylonData[r]=i,this._parent.onMaterialLoadedObservable.notifyObservers(s),this.logClose()}return i.meshes.push(n),n.onDisposeObservable.addOnce((function(){var e=i.meshes.indexOf(n);-1!==e&&i.meshes.splice(e,1)})),o(i.material),i.promise.then((function(){return i.material}))},p.prototype._createDefaultMaterial=function(e,t){var n=new b.PBRMaterial(e,this.babylonScene);return n.sideOrientation=this.babylonScene.useRightHandedSystem?b.Material.CounterClockWiseSideOrientation:b.Material.ClockWiseSideOrientation,n.fillMode=t,n.enableSpecularAntiAliasing=!0,n.useRadianceOverAlpha=!this._parent.transparencyAsCoverage,n.useSpecularOverAlpha=!this._parent.transparencyAsCoverage,n.transparencyMode=b.PBRMaterial.PBRMATERIAL_OPAQUE,n.metallic=1,n.roughness=1,n},p.prototype.createMaterial=function(e,t,n){var r=this._extensionsCreateMaterial(e,t,n);if(r)return r;var o=t.name||"material"+t.index;return this._createDefaultMaterial(o,n)},p.prototype.loadMaterialPropertiesAsync=function(e,t,n){var r=this._extensionsLoadMaterialPropertiesAsync(e,t,n);if(r)return r;var o=new Array;return o.push(this.loadMaterialBasePropertiesAsync(e,t,n)),t.pbrMetallicRoughness&&o.push(this._loadMaterialMetallicRoughnessPropertiesAsync(e+"/pbrMetallicRoughness",t.pbrMetallicRoughness,n)),this.loadMaterialAlphaProperties(e,t,n),Promise.all(o).then((function(){}))},p.prototype.loadMaterialBasePropertiesAsync=function(e,t,n){if(!(n instanceof b.PBRMaterial))throw new Error(e+": Material type not supported");var r=new Array;return n.emissiveColor=t.emissiveFactor?b.Color3.FromArray(t.emissiveFactor):new b.Color3(0,0,0),t.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),t.normalTexture&&(r.push(this.loadTextureInfoAsync(e+"/normalTexture",t.normalTexture,(function(e){n.bumpTexture=e}))),n.invertNormalMapX=!this.babylonScene.useRightHandedSystem,n.invertNormalMapY=this.babylonScene.useRightHandedSystem,null!=t.normalTexture.scale&&(n.bumpTexture.level=t.normalTexture.scale)),t.occlusionTexture&&(r.push(this.loadTextureInfoAsync(e+"/occlusionTexture",t.occlusionTexture,(function(e){n.ambientTexture=e}))),n.useAmbientInGrayScale=!0,null!=t.occlusionTexture.strength&&(n.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&r.push(this.loadTextureInfoAsync(e+"/emissiveTexture",t.emissiveTexture,(function(e){n.emissiveTexture=e}))),Promise.all(r).then((function(){}))},p.prototype.loadMaterialAlphaProperties=function(e,t,n){if(!(n instanceof b.PBRMaterial))throw new Error(e+": Material type not supported");switch(t.alphaMode||"OPAQUE"){case"OPAQUE":n.transparencyMode=b.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":n.transparencyMode=b.PBRMaterial.PBRMATERIAL_ALPHATEST,n.alphaCutOff=null==t.alphaCutoff?.5:t.alphaCutoff,n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":n.transparencyMode=b.PBRMaterial.PBRMATERIAL_ALPHABLEND,n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(e+"/alphaMode: Invalid value ("+t.alphaMode+")")}},p.prototype.loadTextureInfoAsync=function(e,t,n){void 0===n&&(n=function(){});var r=this._extensionsLoadTextureInfoAsync(e,t,n);if(r)return r;this.logOpen(""+e);var o=v.Get(e+"/index",this.gltf.textures,t.index),a=this._loadTextureAsync("#/textures/"+t.index,o,(function(e){e.coordinatesIndex=t.texCoord||0,n(e)}));return this.logClose(),a},p.prototype._loadTextureAsync=function(n,e,t){var r=this;void 0===t&&(t=function(){});var o=new Array;this.logOpen(n+" "+(e.name||""));var a=null==e.sampler?p._DefaultSampler:v.Get(n+"/sampler",this.gltf.samplers,e.sampler),i=this._loadSampler("#/samplers/"+a.index,a),s=new b.Deferred,l=new b.Texture(null,this.babylonScene,i.noMipMaps,!1,i.samplingMode,function(){r._disposed||s.resolve()},function(e,t){r._disposed||s.reject(new Error(n+": "+(t&&t.message?t.message:e||"Failed to load texture")))});o.push(s.promise),l.name=e.name||"texture"+e.index,l.wrapU=i.wrapU,l.wrapV=i.wrapV;var u=v.Get(n+"/source",this.gltf.images,e.source);return o.push(this.loadImageAsync("#/images/"+u.index,u).then((function(e){var t=u.uri||r._fileName+"#image"+u.index,n="data:"+r._uniqueRootUrl+t;l.updateURL(n,new Blob([e],{type:u.mimeType}))}))),t(l),this._parent.onTextureLoadedObservable.notifyObservers(l),this.logClose(),Promise.all(o).then((function(){return l}))},p.prototype._loadSampler=function(e,t){return t._data||(t._data={noMipMaps:9728===t.minFilter||9729===t.minFilter,samplingMode:p._GetTextureSamplingMode(e,t),wrapU:p._GetTextureWrapMode(e+"/wrapS",t.wrapS),wrapV:p._GetTextureWrapMode(e+"/wrapT",t.wrapT)}),t._data},p.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 n=v.Get(e+"/bufferView",this.gltf.bufferViews,t.bufferView);t._data=this.loadBufferViewAsync("#/bufferViews/"+n.index,n)}this.logClose()}return t._data},p.prototype.loadUriAsync=function(o,a){var i=this,e=this._extensionsLoadUriAsync(o,a);if(e)return e;if(!p._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(n,r){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)"),n(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){r(e)}}),i.babylonScene.database,!0,(function(e,t){i._disposed||r(new b.LoadFileError(o+": Failed to load '"+a+"'"+(e?": "+e.status+" "+e.statusText:""),e))}));i._requests.push(t)}})}))},p.prototype._onProgress=function(){if(this._progressCallback){for(var e=!0,t=0,n=0,r=0,o=this._requests;r<o.length;r++){var a=o[r];if(void 0===a._lengthComputable||void 0===a._loaded||void 0===a._total)return;e=e&&a._lengthComputable,t+=a._loaded,n+=a._total}this._progressCallback(new b.SceneLoaderProgressEvent(e,t,e?n:0))}},p._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}},p._GetTextureSamplingMode=function(e,t){var n=null==t.magFilter?9729:t.magFilter,r=null==t.minFilter?9987:t.minFilter;if(9729===n)switch(r){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 ("+r+")"),b.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(9728!==n&&b.Tools.Warn(e+"/magFilter: Invalid value ("+n+")"),r){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 ("+r+")"),b.Texture.NEAREST_NEAREST_MIPNEAREST}},p._GetTypedArray=function(t,e,n,r,o){var a=n.buffer;r=n.byteOffset+(r||0);try{switch(e){case 5120:return new Int8Array(a,r,o);case 5121:return new Uint8Array(a,r,o);case 5122:return new Int16Array(a,r,o);case 5123:return new Uint16Array(a,r,o);case 5125:return new Uint32Array(a,r,o);case 5126:return new Float32Array(a,r,o);default:throw new Error("Invalid component type "+e)}}catch(e){throw new Error(t+": "+e)}},p._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+")")},p._ValidateUri=function(e){return b.Tools.IsBase64(e)||-1===e.indexOf("..")},p._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+")")},p.prototype._compileMaterialsAsync=function(){var e=this;this._parent._startPerformanceCounter("Compile materials");var t=new Array;if(this.gltf.materials)for(var n=0,r=this.gltf.materials;n<r.length;n++){var o=r[n];if(o._babylonData)for(var a in o._babylonData)for(var i=o._babylonData[a],s=0,l=i.meshes;s<l.length;s++){var u=l[s];u.computeWorldMatrix(!0);var c=i.material;t.push(c.forceCompilationAsync(u)),this._parent.useClipPlane&&t.push(c.forceCompilationAsync(u,{clipPlane:!0}))}}return Promise.all(t).then((function(){e._parent._endPerformanceCounter("Compile materials")}))},p.prototype._compileShadowGeneratorsAsync=function(){var e=this;this._parent._startPerformanceCounter("Compile shadow generators");for(var t=new Array,n=0,r=this.babylonScene.lights;n<r.length;n++){var o=r[n].getShadowGenerator();o&&t.push(o.forceCompilationAsync())}return Promise.all(t).then((function(){e._parent._endPerformanceCounter("Compile shadow generators")}))},p.prototype._forEachExtensions=function(e){for(var t=0,n=p._ExtensionNames;t<n.length;t++){var r=n[t],o=this._extensions[r];o.enabled&&e(o)}},p.prototype._applyExtensions=function(e,t){for(var n=0,r=p._ExtensionNames;n<r.length;n++){var o=r[n],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},p.prototype._extensionsOnLoading=function(){this._forEachExtensions((function(e){return e.onLoading&&e.onLoading()}))},p.prototype._extensionsOnReady=function(){this._forEachExtensions((function(e){return e.onReady&&e.onReady()}))},p.prototype._extensionsLoadSceneAsync=function(t,n){return this._applyExtensions(n,(function(e){return e.loadSceneAsync&&e.loadSceneAsync(t,n)}))},p.prototype._extensionsLoadNodeAsync=function(t,n,r){return this._applyExtensions(n,(function(e){return e.loadNodeAsync&&e.loadNodeAsync(t,n,r)}))},p.prototype._extensionsLoadCameraAsync=function(t,n,r){return this._applyExtensions(n,(function(e){return e.loadCameraAsync&&e.loadCameraAsync(t,n,r)}))},p.prototype._extensionsLoadVertexDataAsync=function(t,n,r){return this._applyExtensions(n,(function(e){return e._loadVertexDataAsync&&e._loadVertexDataAsync(t,n,r)}))},p.prototype._extensionsLoadMaterialAsync=function(t,n,r,o,a){return this._applyExtensions(n,(function(e){return e._loadMaterialAsync&&e._loadMaterialAsync(t,n,r,o,a)}))},p.prototype._extensionsCreateMaterial=function(t,n,r){return this._applyExtensions({},(function(e){return e.createMaterial&&e.createMaterial(t,n,r)}))},p.prototype._extensionsLoadMaterialPropertiesAsync=function(t,n,r){return this._applyExtensions(n,(function(e){return e.loadMaterialPropertiesAsync&&e.loadMaterialPropertiesAsync(t,n,r)}))},p.prototype._extensionsLoadTextureInfoAsync=function(t,n,r){return this._applyExtensions(n,(function(e){return e.loadTextureInfoAsync&&e.loadTextureInfoAsync(t,n,r)}))},p.prototype._extensionsLoadAnimationAsync=function(t,n){return this._applyExtensions(n,(function(e){return e.loadAnimationAsync&&e.loadAnimationAsync(t,n)}))},p.prototype._extensionsLoadUriAsync=function(t,n){return this._applyExtensions({},(function(e){return e._loadUriAsync&&e._loadUriAsync(t,n)}))},p.LoadExtensionAsync=function(e,t,n,r){if(!t.extensions)return null;var o=t.extensions[n];return o?r(e+"/extensions/"+n,o):null},p.LoadExtraAsync=function(e,t,n,r){if(!t.extras)return null;var o=t.extras[n];return o?r(e+"/extras/"+n,o):null},p.prototype.logOpen=function(e){this._parent._logOpen(e)},p.prototype.logClose=function(){this._parent._logClose()},p.prototype.log=function(e){this._parent._log(e)},p.prototype.startPerformanceCounter=function(e){this._parent._startPerformanceCounter(e)},p.prototype.endPerformanceCounter=function(e){this._parent._endPerformanceCounter(e)},p._DefaultSampler={index:-1},p._ExtensionNames=new Array,p._ExtensionFactories={},p})();e.GLTFLoader=t,b.GLTFFileLoader._CreateGLTFLoaderV2=function(e){return new t(e)}})(b.GLTF2||(b.GLTF2={}))})(BABYLON||(BABYLON={})),(function(l){var d,e,t,n,r;d=l.GLTF2||(l.GLTF2={}),e=d.Loader||(d.Loader={}),t=e.Extensions||(e.Extensions={}),n="MSFT_lod",r=(function(){function e(e){this.name=n,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 n=this,e=function(e){var t=Promise.all(r._nodePromiseLODs[e]).then((function(){0!==e&&n._loader.endPerformanceCounter("Node LOD "+e),n._loader.log("Loaded node LOD "+e),n.onNodeLODsLoadedObservable.notifyObservers(e),e!==n._nodePromiseLODs.length-1&&(n._loader.startPerformanceCounter("Node LOD "+(e+1)),n._nodeSignalLODs[e]&&n._nodeSignalLODs[e].resolve())}));r._loader._completePromises.push(t)},r=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&&n._loader.endPerformanceCounter("Material LOD "+e),n._loader.log("Loaded material LOD "+e),n.onMaterialLODsLoadedObservable.notifyObservers(e),e!==n._materialPromiseLODs.length-1&&(n._loader.startPerformanceCounter("Material LOD "+(e+1)),n._materialSignalLODs[e]&&n._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 d.GLTFLoader.LoadExtensionAsync(e,i,this.name,(function(e,t){var r,o=s._getLODs(e,i,s._loader.gltf.nodes,t.ids);s._loader.logOpen(""+e);for(var n=function(n){var e=o[n];0!==n&&(s._nodeIndexLOD=n,s._nodeSignalLODs[n]=s._nodeSignalLODs[n]||new l.Deferred);var t=s._loader.loadNodeAsync("#/nodes/"+e.index,e).then((function(e){if(0!==n){var t=o[n-1];t._babylonMesh&&(t._babylonMesh.dispose(),delete t._babylonMesh,s._disposeUnusedMaterials())}return e}));0===n?r=t:s._nodeIndexLOD=null,s._nodePromiseLODs[n]=s._nodePromiseLODs[n]||[],s._nodePromiseLODs[n].push(t)},a=0;a<o.length;a++)n(a);return s._loader.logClose(),r}))},e.prototype._loadMaterialAsync=function(e,i,s,l,u){var c=this;return this._nodeIndexLOD?null:d.GLTFLoader.LoadExtensionAsync(e,i,this.name,(function(e,t){var r,o=c._getLODs(e,i,c._loader.gltf.materials,t.ids);c._loader.logOpen(""+e);for(var n=function(n){var e=o[n];0!==n&&(c._materialIndexLOD=n);var t=c._loader._loadMaterialAsync("#/materials/"+e.index,e,s,l,(function(e){0===n&&u(e)})).then((function(e){if(0!==n){u(e);var t=o[n-1]._babylonData;t[l]&&(t[l].material.dispose(),delete t[l])}return e}));0===n?r=t:c._materialIndexLOD=null,c._materialPromiseLODs[n]=c._materialPromiseLODs[n]||[],c._materialPromiseLODs[n].push(t)},a=0;a<o.length;a++)n(a);return c._loader.logClose(),r}))},e.prototype._loadUriAsync=function(e,t){var n=this;if(null!==this._materialIndexLOD){this._loader.log("deferred");var r=this._materialIndexLOD-1;return this._materialSignalLODs[r]=this._materialSignalLODs[r]||new l.Deferred,this._materialSignalLODs[r].promise.then((function(){return n._loader.loadUriAsync(e,t)}))}return null!==this._nodeIndexLOD?(this._loader.log("deferred"),r=this._nodeIndexLOD-1,this._nodeSignalLODs[r]=this._nodeSignalLODs[r]||new l.Deferred,this._nodeSignalLODs[this._nodeIndexLOD-1].promise.then((function(){return n._loader.loadUriAsync(e,t)}))):null},e.prototype._getLODs=function(e,t,n,r){if(this.maxLODsToLoad<=0)throw new Error("maxLODsToLoad must be greater than zero");for(var o=new Array,a=r.length-1;0<=a;a--)if(o.push(d.ArrayItem.Get(e+"/ids/"+r[a],n,r[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,n=e;t<n.length;t++){var r=n[t];if(r._babylonData)for(var o in r._babylonData){var a=r._babylonData[o];0===a.meshes.length&&(a.material.dispose(!1,!0),delete r._babylonData[o])}}},e})(),t.MSFT_lod=r,d.GLTFLoader.RegisterExtension(n,(function(e){return new r(e)}))})(BABYLON||(BABYLON={})),(function(s){var t,e,n,r,o;t=s.GLTF2||(s.GLTF2={}),e=t.Loader||(t.Loader={}),n=e.Extensions||(e.Extensions={}),r="MSFT_minecraftMesh",o=(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(r,o,a){var i=this;return t.GLTFLoader.LoadExtraAsync(r,o,this.name,(function(e,t){if(t){if(!(a instanceof s.PBRMaterial))throw new Error(e+": Material type not supported");var n=i._loader.loadMaterialPropertiesAsync(r,o,a);return a.needAlphaBlending()&&(a.forceDepthWrite=!0,a.separateCullingPass=!0),a.backFaceCulling=a.forceDepthWrite,a.twoSidedLighting=!0,n}return null}))},e})(),n.MSFT_minecraftMesh=o,t.GLTFLoader.RegisterExtension(r,(function(e){return new o(e)}))})(BABYLON||(BABYLON={})),(function(s){var t,e,n,r,o;t=s.GLTF2||(s.GLTF2={}),e=t.Loader||(t.Loader={}),n=e.Extensions||(e.Extensions={}),r="MSFT_sRGBFactors",o=(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(r,o,a){var i=this;return t.GLTFLoader.LoadExtraAsync(r,o,this.name,(function(e,t){if(t){if(!(a instanceof s.PBRMaterial))throw new Error(e+": Material type not supported");var n=i._loader.loadMaterialPropertiesAsync(r,o,a);return a.albedoTexture||a.albedoColor.toLinearSpaceToRef(a.albedoColor),a.reflectivityTexture||a.reflectivityColor.toLinearSpaceToRef(a.reflectivityColor),n}return null}))},e})(),n.MSFT_sRGBFactors=o,t.GLTFLoader.RegisterExtension(r,(function(e){return new o(e)}))})(BABYLON||(BABYLON={})),(function(c){var d,e,t,n,r;d=c.GLTF2||(c.GLTF2={}),e=d.Loader||(d.Loader={}),t=e.Extensions||(e.Extensions={}),n="MSFT_audio_emitter",r=(function(){function e(e){this.name=n,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,d.ArrayItem.Assign(this._clips),d.ArrayItem.Assign(this._emitters)}},e.prototype.loadSceneAsync=function(s,l){var u=this;return d.GLTFLoader.LoadExtensionAsync(s,l,this.name,(function(e,t){var n=new Array;n.push(u._loader.loadSceneAsync(s,l));for(var r=0,o=t.emitters;r<o.length;r++){var a=o[r],i=d.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");n.push(u._loadEmitterAsync(e+"/emitters/"+i.index,i))}return Promise.all(n).then((function(){}))}))},e.prototype.loadNodeAsync=function(e,t,s){var l=this;return d.GLTFLoader.LoadExtensionAsync(e,t,this.name,(function(a,r){var i=new Array;return l._loader.loadNodeAsync(a,t,(function(o){for(var e=function(e){var r=d.ArrayItem.Get(a+"/emitters",l._emitters,e);i.push(l._loadEmitterAsync(a+"/emitters/"+r.index,r).then((function(){for(var e=0,t=r._babylonSounds;e<t.length;e++){var n=t[e];n.attachToMesh(o),null==r.innerAngle&&null==r.outerAngle||(n.setLocalDirectionToMesh(c.Vector3.Forward()),n.setDirectionalCone(2*c.Tools.ToDegrees(null==r.innerAngle?Math.PI:r.innerAngle),2*c.Tools.ToDegrees(null==r.outerAngle?Math.PI:r.outerAngle),0))}})))},t=0,n=r.emitters;t<n.length;t++)e(n[t]);s(o)})).then((function(e){return Promise.all(i).then((function(){return e}))}))}))},e.prototype.loadAnimationAsync=function(s,l){var u=this;return d.GLTFLoader.LoadExtensionAsync(s,l,this.name,(function(a,i){return u._loader.loadAnimationAsync(s,l).then((function(e){var t=new Array;d.ArrayItem.Assign(i.events);for(var n=0,r=i.events;n<r.length;n++){var o=r[n];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 n;if(t.uri)n=this._loader.loadUriAsync(e,t.uri);else{var r=d.ArrayItem.Get(e+"/bufferView",this._loader.gltf.bufferViews,t.bufferView);n=this._loader.loadBufferViewAsync("#/bufferViews/"+r.index,r)}return t._objectURL=n.then((function(e){return URL.createObjectURL(new Blob([e],{type:t.mimeType}))})),t._objectURL},e.prototype._loadEmitterAsync=function(e,r){var o=this;if(r._babylonSounds=r._babylonSounds||[],!r._babylonData){for(var a=new Array,i=r.name||"emitter"+r.index,s={loop:!1,autoplay:!1,volume:null==r.volume?1:r.volume},t=function(n){var e="#/extensions/"+l.name+"/clips",t=d.ArrayItem.Get(e,l._clips,r.clips[n].clip);a.push(l._loadClipAsync(e+"/"+r.clips[n].clip,t).then((function(e){var t=r._babylonSounds[n]=new c.Sound(i,e,o._loader.babylonScene,null,s);t.refDistance=r.refDistance||1,t.maxDistance=r.maxDistance||256,t.rolloffFactor=r.rolloffFactor||1,t.distanceModel=r.distanceModel||"exponential",t._positionInEmitterSpace=!0})))},l=this,n=0;n<r.clips.length;n++)t(n);var u=Promise.all(a).then((function(){var e=r.clips.map((function(e){return e.weight||1})),t=new c.WeightedSound(r.loop||!1,r._babylonSounds,e);r.innerAngle&&(t.directionalConeInnerAngle=2*c.Tools.ToDegrees(r.innerAngle)),r.outerAngle&&(t.directionalConeOuterAngle=2*c.Tools.ToDegrees(r.outerAngle)),r.volume&&(t.volume=r.volume),r._babylonData.sound=t}));r._babylonData={loaded:u}}return r._babylonData.loaded},e.prototype._getEventAction=function(e,n,t,r,o){switch(t){case"play":return function(e){var t=(o||0)+(e-r);n.play(t)};case"stop":return function(e){n.stop()};case"pause":return function(e){n.pause()};default:throw new Error(e+": Unsupported action "+t)}},e.prototype._loadAnimationEventAsync=function(n,e,t,r,o){var a=this;if(0==o.targetedAnimations.length)return Promise.resolve();var i=o.targetedAnimations[0],s=r.emitter,l=d.ArrayItem.Get("#/extensions/"+this.name+"/emitters",this._emitters,s);return this._loadEmitterAsync(n,l).then((function(){var e=l._babylonData.sound;if(e){var t=new c.AnimationEvent(r.time,a._getEventAction(n,e,r.action,r.time,r.startOffset));i.animation.addEvent(t),o.onAnimationGroupEndObservable.add((function(){e.stop()})),o.onAnimationGroupPauseObservable.add((function(){e.pause()}))}}))},e})(),t.MSFT_audio_emitter=r,d.GLTFLoader.RegisterExtension(n,(function(e){return new r(e)}))})(BABYLON||(BABYLON={})),(function(u){var c,e,t,n,r;c=u.GLTF2||(u.GLTF2={}),e=c.Loader||(c.Loader={}),t=e.Extensions||(e.Extensions={}),n="KHR_draco_mesh_compression",r=(function(){function e(e){this.name=n,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 c.GLTFLoader.LoadExtensionAsync(a,i,this.name,(function(e,r){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 n=r.attributes[e];null!=n&&(s._delayInfo=s._delayInfo||[],-1===s._delayInfo.indexOf(t)&&s._delayInfo.push(t),o[t]=n)};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 n=c.ArrayItem.Get(e,l._loader.gltf.bufferViews,r.bufferView);return n._dracoBabylonGeometry||(n._dracoBabylonGeometry=l._loader.loadBufferViewAsync("#/bufferViews/"+n.index,n).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)}))}))),n._dracoBabylonGeometry}))},e})(),t.KHR_draco_mesh_compression=r,c.GLTFLoader.RegisterExtension(n,(function(e){return new r(e)}))})(BABYLON||(BABYLON={})),(function(a){var t,e,n,r,o;t=a.GLTF2||(a.GLTF2={}),e=t.Loader||(t.Loader={}),n=e.Extensions||(e.Extensions={}),r="KHR_materials_pbrSpecularGlossiness",o=(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(r,o,a){var i=this;return t.GLTFLoader.LoadExtensionAsync(r,o,this.name,(function(e,t){var n=new Array;return n.push(i._loader.loadMaterialBasePropertiesAsync(r,o,a)),n.push(i._loadSpecularGlossinessPropertiesAsync(e,o,t,a)),i._loader.loadMaterialAlphaProperties(r,o,a),Promise.all(n).then((function(){}))}))},e.prototype._loadSpecularGlossinessPropertiesAsync=function(e,t,n,r){if(!(r instanceof a.PBRMaterial))throw new Error(e+": Material type not supported");var o=new Array;return r.metallic=null,r.roughness=null,n.diffuseFactor?(r.albedoColor=a.Color3.FromArray(n.diffuseFactor),r.alpha=n.diffuseFactor[3]):r.albedoColor=a.Color3.White(),r.reflectivityColor=n.specularFactor?a.Color3.FromArray(n.specularFactor):a.Color3.White(),r.microSurface=null==n.glossinessFactor?1:n.glossinessFactor,n.diffuseTexture&&o.push(this._loader.loadTextureInfoAsync(e+"/diffuseTexture",n.diffuseTexture,(function(e){return r.albedoTexture=e,Promise.resolve()}))),n.specularGlossinessTexture&&(o.push(this._loader.loadTextureInfoAsync(e+"/specularGlossinessTexture",n.specularGlossinessTexture,(function(e){return r.reflectivityTexture=e,Promise.resolve()}))),r.reflectivityTexture.hasAlpha=!0,r.useMicroSurfaceFromReflectivityMapAlpha=!0),Promise.all(o).then((function(){}))},e})(),n.KHR_materials_pbrSpecularGlossiness=o,t.GLTFLoader.RegisterExtension(r,(function(e){return new o(e)}))})(BABYLON||(BABYLON={})),(function(a){var o,e,t,n,r;o=a.GLTF2||(a.GLTF2={}),e=o.Loader||(o.Loader={}),t=e.Extensions||(e.Extensions={}),n="KHR_materials_unlit",r=(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(e,t,n){var r=this;return o.GLTFLoader.LoadExtensionAsync(e,t,this.name,(function(){return r._loadUnlitPropertiesAsync(e,t,n)}))},e.prototype._loadUnlitPropertiesAsync=function(e,t,n){if(!(n instanceof a.PBRMaterial))throw new Error(e+": Material type not supported");var r=new Array;n.unlit=!0;var o=t.pbrMetallicRoughness;return o&&(o.baseColorFactor?(n.albedoColor=a.Color3.FromArray(o.baseColorFactor),n.alpha=o.baseColorFactor[3]):n.albedoColor=a.Color3.White(),o.baseColorTexture&&r.push(this._loader.loadTextureInfoAsync(e+"/baseColorTexture",o.baseColorTexture,(function(e){return n.albedoTexture=e,Promise.resolve()})))),t.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),this._loader.loadMaterialAlphaProperties(e,t,n),Promise.all(r).then((function(){}))},e})(),t.KHR_materials_unlit=r,o.GLTFLoader.RegisterExtension(n,(function(e){return new r(e)}))})(BABYLON||(BABYLON={})),(function(c){var d,e;d=c.GLTF2||(c.GLTF2={}),(function(e){var u,t,n="KHR_lights_punctual";(t=u||(u={})).DIRECTIONAL="directional",t.POINT="point",t.SPOT="spot";var r=(function(){function e(e){this.name=n,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 d.GLTFLoader.LoadExtensionAsync(e,t,this.name,(function(a,i){return l._loader.loadNodeAsync(e,t,(function(e){var t,n=d.ArrayItem.Get(a,l._lights,i.light),r=n.name||e.name;switch(n.type){case u.DIRECTIONAL:t=new c.DirectionalLight(r,c.Vector3.Backward(),l._loader.babylonScene);break;case u.POINT:t=new c.PointLight(r,c.Vector3.Zero(),l._loader.babylonScene);break;case u.SPOT:var o=new c.SpotLight(r,c.Vector3.Zero(),c.Vector3.Backward(),0,1,l._loader.babylonScene);o.angle=2*(n.spot&&n.spot.outerConeAngle||Math.PI/4),o.innerAngle=2*(n.spot&&n.spot.innerConeAngle||0),t=o;break;default:throw new Error(a+": Invalid light type ("+n.type+")")}t.falloffType=c.Light.FALLOFF_GLTF,t.diffuse=n.color?c.Color3.FromArray(n.color):c.Color3.White(),t.intensity=null==n.intensity?1:n.intensity,t.range=null==n.range?Number.MAX_VALUE:n.range,t.parent=e,s(e)}))}))},e})();e.KHR_lights=r,d.GLTFLoader.RegisterExtension(n,(function(e){return new r(e)}))})((e=d.Loader||(d.Loader={})).Extensions||(e.Extensions={}))})(BABYLON||(BABYLON={})),(function(i){var t,e,n,r,o;t=i.GLTF2||(i.GLTF2={}),e=t.Loader||(t.Loader={}),n=e.Extensions||(e.Extensions={}),r="KHR_texture_transform",o=(function(){function e(e){this.name=r,this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader},e.prototype.loadTextureInfoAsync=function(e,r,o){var a=this;return t.GLTFLoader.LoadExtensionAsync(e,r,this.name,(function(t,n){return a._loader.loadTextureInfoAsync(e,r,(function(e){if(!(e instanceof i.Texture))throw new Error(t+": Texture type not supported");n.offset&&(e.uOffset=n.offset[0],e.vOffset=n.offset[1]),e.uRotationCenter=0,e.vRotationCenter=0,n.rotation&&(e.wAng=-n.rotation),n.scale&&(e.uScale=n.scale[0],e.vScale=n.scale[1]),null!=n.texCoord&&(e.coordinatesIndex=n.texCoord),o(e)}))}))},e})(),n.KHR_texture_transform=o,t.GLTFLoader.RegisterExtension(r,(function(e){return new o(e)}))})(BABYLON||(BABYLON={})),(function(d){var f,e,t,n,r;f=d.GLTF2||(d.GLTF2={}),e=f.Loader||(f.Loader={}),t=e.Extensions||(e.Extensions={}),n="EXT_lights_image_based",r=(function(){function e(e){this.name=n,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 n=new Array;n.push(i._loader.loadSceneAsync(o,a)),i._loader.logOpen(""+e);var r=f.ArrayItem.Get(e+"/light",i._lights,t.light);return n.push(i._loadLightAsync("#/extensions/"+i.name+"/lights/"+t.light,r).then((function(e){i._loader.babylonScene.environmentTexture=e}))),i._loader.logClose(),Promise.all(n).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;c._loader.logOpen(""+e);var n=a[t],r=f.ArrayItem.Get(e,c._loader.gltf.images,n);l.push(c._loader.loadImageAsync("#/images/"+n,r).then((function(e){u[o][t]=e}))),c._loader.logClose()},t=0;t<a.length;t++)e(t)},c=this,t=0;t<s.specularImages.length;t++)e(t);this._loader.logClose(),s._loaded=Promise.all(l).then((function(){var e=new d.RawCubeTexture(a._loader.babylonScene,null,s.specularImageSize);if(s._babylonTexture=e,null!=s.intensity&&(e.level=s.intensity),s.rotation){var t=d.Quaternion.FromArray(s.rotation);a._loader.babylonScene.useRightHandedSystem||(t=d.Quaternion.Inverse(t)),d.Matrix.FromQuaternionToRef(t,e.getReflectionTextureMatrix())}var n=d.SphericalHarmonics.FromArray(s.irradianceCoefficients);n.scale(s.intensity),n.convertIrradianceToLambertianRadiance();var r=d.SphericalPolynomial.FromHarmonics(n),o=(u.length-1)/d.Scalar.Log2(s.specularImageSize);return e.updateRGBDAsync(u,r,o)}))}return s._loaded.then((function(){return s._babylonTexture}))},e})(),t.EXT_lights_image_based=r,f.GLTFLoader.RegisterExtension(n,(function(e){return new r(e)}))})(BABYLON||(BABYLON={}));