babylon.glTF1FileLoader.min.js 46 KB

1
  1. !(function(a){var e,n,r,t,o;(n=e=a.GLTFLoaderCoordinateSystemMode||(a.GLTFLoaderCoordinateSystemMode={}))[n.AUTO=0]="AUTO",n[n.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED",(t=r=a.GLTFLoaderAnimationStartMode||(a.GLTFLoaderAnimationStartMode={}))[t.NONE=0]="NONE",t[t.FIRST=1]="FIRST",t[t.ALL=2]="ALL",(o=a.GLTFLoaderState||(a.GLTFLoaderState={}))[o.LOADING=0]="LOADING",o[o.READY=1]="READY",o[o.COMPLETE=2]="COMPLETE";var i=(function(){function u(){this.onParsedObservable=new a.Observable,this.coordinateSystemMode=e.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.transparencyAsCoverage=!1,this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable=new a.Observable,this.onTextureLoadedObservable=new a.Observable,this.onMaterialLoadedObservable=new a.Observable,this.onCameraLoadedObservable=new a.Observable,this.onCompleteObservable=new a.Observable,this.onErrorObservable=new a.Observable,this.onDisposeObservable=new a.Observable,this.onExtensionLoadedObservable=new a.Observable,this.validate=!1,this.onValidatedObservable=new a.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(u.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"onCameraLoaded",{set:function(e){this._onCameraLoadedObserver&&this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver),this._onCameraLoadedObserver=this.onCameraLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"onError",{set:function(e){this._onErrorObserver&&this.onErrorObservable.remove(this._onErrorObserver),this._onErrorObserver=this.onErrorObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.prototype,"onExtensionLoaded",{set:function(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(u.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(u.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(u.prototype,"onValidated",{set:function(e){this._onValidatedObserver&&this.onValidatedObservable.remove(this._onValidatedObserver),this._onValidatedObserver=this.onValidatedObservable.add(e)},enumerable:!0,configurable:!0}),u.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this._clear(),this.onDisposeObservable.notifyObservers(void 0),this.onDisposeObservable.clear()},u.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()},u.prototype.importMeshAsync=function(n,r,e,t,o,i){var a=this;return this._parseAsync(r,e,t,i).then((function(e){return a._log("Loading "+(i||"")),a._loader=a._getLoader(e),a._loader.importMeshAsync(n,r,e,t,o,i)}))},u.prototype.loadAsync=function(n,e,r,t,o){var i=this;return this._parseAsync(n,e,r,o).then((function(e){return i._log("Loading "+(o||"")),i._loader=i._getLoader(e),i._loader.loadAsync(n,e,r,t,o)}))},u.prototype.loadAssetContainerAsync=function(r,e,n,t,o){var i=this;return this._parseAsync(r,e,n,o).then((function(e){return i._log("Loading "+(o||"")),i._loader=i._getLoader(e),i._loader.importMeshAsync(null,r,e,n,t,o).then((function(e){var n=new a.AssetContainer(r);return Array.prototype.push.apply(n.meshes,e.meshes),Array.prototype.push.apply(n.particleSystems,e.particleSystems),Array.prototype.push.apply(n.skeletons,e.skeletons),Array.prototype.push.apply(n.animationGroups,e.animationGroups),n.removeAllFromScene(),n}))}))},u.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},u.prototype.createPlugin=function(){return new u},Object.defineProperty(u.prototype,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),u.prototype.whenCompleteAsync=function(){var r=this;return new Promise(function(e,n){r.onCompleteObservable.addOnce((function(){e()})),r.onErrorObservable.addOnce((function(e){n(e)}))})},u.prototype._parseAsync=function(e,r,t,o){var i=this;return Promise.resolve().then((function(){var n=r instanceof ArrayBuffer?i._unpackBinary(r):{json:r,bin:null};return i._validateAsync(e,n.json,t,o).then((function(){i._startPerformanceCounter("Parse JSON"),i._log("JSON length: "+n.json.length);var e={json:JSON.parse(n.json),bin:n.bin};return i._endPerformanceCounter("Parse JSON"),i.onParsedObservable.notifyObservers(e),i.onParsedObservable.clear(),e}))}))},u.prototype._validateAsync=function(n,e,r,t){var o=this;if(!this.validate||"undefined"==typeof GLTFValidator)return Promise.resolve();this._startPerformanceCounter("Validate JSON");var i={externalResourceFunction:function(e){return o.preprocessUrlAsync(r+e).then((function(e){return n._loadFileAsync(e,!0,!0)})).then((function(e){return new Uint8Array(e)}))}};return t&&"data:"!==t.substr(0,5)&&(i.uri="file:"===r?t:""+r+t),GLTFValidator.validateString(e,i).then((function(e){o._endPerformanceCounter("Validate JSON"),o.onValidatedObservable.notifyObservers(e),o.onValidatedObservable.clear()}))},u.prototype._getLoader=function(e){var n=e.json.asset||{};this._log("Asset version: "+n.version),n.minVersion&&this._log("Asset minimum version: "+n.minVersion),n.generator&&this._log("Asset generator: "+n.generator);var r=u._parseVersion(n.version);if(!r)throw new Error("Invalid version: "+n.version);if(void 0!==n.minVersion){var t=u._parseVersion(n.minVersion);if(!t)throw new Error("Invalid minimum version: "+n.minVersion);if(0<u._compareVersion(t,{major:2,minor:0}))throw new Error("Incompatible minimum version: "+n.minVersion)}var o={1:u._CreateGLTFLoaderV1,2:u._CreateGLTFLoaderV2}[r.major];if(!o)throw new Error("Unsupported version: "+n.version);return o(this)},u.prototype._unpackBinary=function(e){this._startPerformanceCounter("Unpack binary"),this._log("Binary length: "+e.byteLength);var n=new s(e),r=n.readUint32();if(1179937895!==r)throw new Error("Unexpected magic: "+r);var t,o=n.readUint32();switch(this.loggingEnabled&&this._log("Binary version: "+o),o){case 1:t=this._unpackBinaryV1(n);break;case 2:t=this._unpackBinaryV2(n);break;default:throw new Error("Unsupported version: "+o)}return this._endPerformanceCounter("Unpack binary"),t},u.prototype._unpackBinaryV1=function(e){var n=e.readUint32();if(n!=e.getLength())throw new Error("Length in header does not match actual data length: "+n+" != "+e.getLength());var r,t=e.readUint32(),o=e.readUint32();switch(o){case 0:r=u._decodeBufferToText(e.readUint8Array(t));break;default:throw new Error("Unexpected content format: "+o)}var i=e.getLength()-e.getPosition();return{json:r,bin:e.readUint8Array(i)}},u.prototype._unpackBinaryV2=function(e){var n=1313821514,r=5130562,t=e.readUint32();if(t!==e.getLength())throw new Error("Length in header does not match actual data length: "+t+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==n)throw new Error("First chunk format is not JSON");for(var i=u._decodeBufferToText(e.readUint8Array(o)),a=null;e.getPosition()<e.getLength();){var s=e.readUint32();switch(e.readUint32()){case n:throw new Error("Unexpected JSON chunk");case r:a=e.readUint8Array(s);break;default:e.skipBytes(s)}}return{json:i,bin:a}},u._parseVersion=function(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};var n=(e+"").match(/^(\d+)\.(\d+)/);return n?{major:parseInt(n[1]),minor:parseInt(n[2])}:null},u._compareVersion=function(e,n){return e.major>n.major?1:e.major<n.major?-1:e.minor>n.minor?1:e.minor<n.minor?-1:0},u._decodeBufferToText=function(e){for(var n="",r=e.byteLength,t=0;t<r;t++)n+=String.fromCharCode(e[t]);return n},u.prototype._logOpen=function(e){this._log(e),this._logIndentLevel++},u.prototype._logClose=function(){--this._logIndentLevel},u.prototype._logEnabled=function(e){var n=u._logSpaces.substr(0,2*this._logIndentLevel);a.Tools.Log(""+n+e)},u.prototype._logDisabled=function(e){},u.prototype._startPerformanceCounterEnabled=function(e){a.Tools.StartPerformanceCounter(e)},u.prototype._startPerformanceCounterDisabled=function(e){},u.prototype._endPerformanceCounterEnabled=function(e){a.Tools.EndPerformanceCounter(e)},u.prototype._endPerformanceCounterDisabled=function(e){},u.IncrementalLoading=!0,u.HomogeneousCoordinates=!1,u._logSpaces=" ",u})();a.GLTFFileLoader=i;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 n=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,n},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();a.SceneLoader&&a.SceneLoader.RegisterPlugin(new i)})(BABYLON||(BABYLON={})),(function(e){var n,r,t,o,i,a,s,u,l;n=e.GLTF1||(e.GLTF1={}),(r=n.EComponentType||(n.EComponentType={}))[r.BYTE=5120]="BYTE",r[r.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",r[r.SHORT=5122]="SHORT",r[r.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",r[r.FLOAT=5126]="FLOAT",(t=n.EShaderType||(n.EShaderType={}))[t.FRAGMENT=35632]="FRAGMENT",t[t.VERTEX=35633]="VERTEX",(o=n.EParameterType||(n.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",(i=n.ETextureWrapMode||(n.ETextureWrapMode={}))[i.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",i[i.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",i[i.REPEAT=10497]="REPEAT",(a=n.ETextureFilterType||(n.ETextureFilterType={}))[a.NEAREST=9728]="NEAREST",a[a.LINEAR=9728]="LINEAR",a[a.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",a[a.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",a[a.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",a[a.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR",(s=n.ETextureFormat||(n.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",(u=n.ECullingType||(n.ECullingType={}))[u.FRONT=1028]="FRONT",u[u.BACK=1029]="BACK",u[u.FRONT_AND_BACK=1032]="FRONT_AND_BACK",(l=n.EBlendingFunction||(n.EBlendingFunction={}))[l.ZERO=0]="ZERO",l[l.ONE=1]="ONE",l[l.SRC_COLOR=768]="SRC_COLOR",l[l.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",l[l.DST_COLOR=774]="DST_COLOR",l[l.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",l[l.SRC_ALPHA=770]="SRC_ALPHA",l[l.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",l[l.DST_ALPHA=772]="DST_ALPHA",l[l.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",l[l.CONSTANT_COLOR=32769]="CONSTANT_COLOR",l[l.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",l[l.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",l[l.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",l[l.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE"})(BABYLON||(BABYLON={})),(function(W){!(function(w){var V,e;(e=V||(V={}))[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=V.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 V.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=V.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=V.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})(),D=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],U=["world","view","projection","worldView","worldViewProjection","mBones"],M=["translation","rotation","scale"],x=["position","rotationQuaternion","scaling"],o=function(e,n,r){for(var t in e){var o=e[t];r[n][t]=o}},F=function(e){if(e)for(var n=0;n<e.length/2;n++)e[2*n+1]=1-e[2*n+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 n=Number(e.semantic.split("_")[1]);return"uv"+(0===n?"":n+1)}return null},_=function(e){var n=null;if(e.translation||e.rotation||e.scale){var r=W.Vector3.FromArray(e.scale||[1,1,1]),t=W.Quaternion.FromArray(e.rotation||[0,0,0,1]),o=W.Vector3.FromArray(e.translation||[0,0,0]);n=W.Matrix.Compose(r,t,o)}else n=W.Matrix.FromArray(e.matrix);return n},v=function(e,n,r,t){for(var o=0;o<t.bones.length;o++)if(t.bones[o].name===r)return t.bones[o];var i=e.nodes;for(var a in i){var s=i[a];if(s.jointName){var u=s.children;for(o=0;o<u.length;o++){var l=e.nodes[u[o]];if(l.jointName&&l.jointName===r){var c=_(s),f=new W.Bone(s.name||"",t,v(e,n,s.jointName,t),c);return f.id=a,f}}}}return null},L=function(e,n){for(var r=0;r<e.length;r++)for(var t=e[r],o=0;o<t.node.children.length;o++){if(t.node.children[o]===n)return t.bone}return null},O=function(e,n){var r=e.nodes,t=r[n];if(t)return{node:t,id:n};for(var o in r)if((t=r[o]).jointName===n)return{node:t,id:o};return null},b=function(e,n){for(var r=0;r<e.jointNames.length;r++)if(e.jointNames[r]===n)return!0;return!1},g=function(e,n,r,t,o){if(t||(t=new W.Skeleton(n.name||"","",e.scene)),!n.babylonSkeleton)return t;var i=[],a=[];!(function(e,n,r,t){for(var o in e.nodes){var i=e.nodes[o],a=o;if(i.jointName&&!b(r,i.jointName)){var s=_(i),u=new W.Bone(i.name||"",n,null,s);u.id=a,t.push({bone:u,node:i,id:a})}}for(var l=0;l<t.length;l++)for(var c=t[l],f=c.node.children,d=0;d<f.length;d++){for(var m=null,h=0;h<t.length;h++)if(t[h].id===f[d]){m=t[h];break}m&&(m.bone._parent=c.bone,c.bone.children.push(m.bone))}})(e,t,n,i),t.bones=[];for(var s=0;s<n.jointNames.length;s++){if(y=O(e,n.jointNames[s])){var u=y.node;if(u){o=y.id;var l=e.scene.getBoneByID(o);if(l)t.bones.push(l);else{for(var c=!1,f=null,d=0;d<s;d++){var m=O(e,n.jointNames[d]);if(m){var h=m.node;if(h){var p=h.children;if(p){c=!1;for(var E=0;E<p.length;E++)if(p[E]===o){f=v(e,n,n.jointNames[d],t),c=!0;break}if(c)break}}else W.Tools.Warn("Joint named "+n.jointNames[d]+" does not exist when looking for parent")}}var A=_(u);!f&&0<i.length&&(f=L(i,o))&&-1===a.indexOf(f)&&a.push(f),new W.Bone(u.jointName||"",t,f,A).id=o}}else W.Tools.Warn("Joint named "+n.jointNames[s]+" does not exist")}}var T=t.bones;t.bones=[];for(s=0;s<n.jointNames.length;s++){var y;if(y=O(e,n.jointNames[s]))for(d=0;d<T.length;d++)if(T[d].id===y.id){t.bones.push(T[d]);break}}t.prepare();for(s=0;s<a.length;s++)t.bones.push(a[s]);return t},N=function(e,n,r,t,o){if(o||((o=new W.Mesh(n.name||"",e.scene)).id=t),!n.babylonNode)return o;for(var i,a=[],s=null,u=new Array,l=new Array,c=new Array,f=new Array,d=0;d<r.length;d++){var m=r[d];if(M=e.meshes[m])for(var h=0;h<M.primitives.length;h++){var p=new W.VertexData,E=M.primitives[h];E.mode;var A=E.attributes,T=null,y=null;for(var _ in A)if(T=e.accessors[A[_]],y=w.GLTFUtils.GetBufferFromAccessor(e,T),"NORMAL"===_)p.normals=new Float32Array(y.length),p.normals.set(y);else if("POSITION"===_){if(W.GLTFFileLoader.HomogeneousCoordinates){p.positions=new Float32Array(y.length-y.length/4);for(var v=0;v<y.length;v+=4)p.positions[v]=y[v],p.positions[v+1]=y[v+1],p.positions[v+2]=y[v+2]}else p.positions=new Float32Array(y.length),p.positions.set(y);l.push(p.positions.length)}else if(-1!==_.indexOf("TEXCOORD_")){var L=Number(_.split("_")[1]),O=W.VertexBuffer.UVKind+(0===L?"":L+1),b=new Float32Array(y.length);b.set(y),F(b),p.set(b,O)}else"JOINT"===_?(p.matricesIndices=new Float32Array(y.length),p.matricesIndices.set(y)):"WEIGHT"===_?(p.matricesWeights=new Float32Array(y.length),p.matricesWeights.set(y)):"COLOR"===_&&(p.colors=new Float32Array(y.length),p.colors.set(y));if(T=e.accessors[E.indices])y=w.GLTFUtils.GetBufferFromAccessor(e,T),p.indices=new Int32Array(y.length),p.indices.set(y),f.push(p.indices.length);else{var g=[];for(v=0;v<p.positions.length/3;v++)g.push(v);p.indices=new Int32Array(g),f.push(p.indices.length)}s?s.merge(p):s=p;var N=e.scene.getMaterialByID(E.material);a.push(null===N?w.GLTFUtils.GetDefaultMaterial(e.scene):N),u.push(0===u.length?0:u[u.length-1]+l[l.length-2]),c.push(0===c.length?0:c[c.length-1]+f[f.length-2])}}1<a.length?(i=new W.MultiMaterial("multimat"+t,e.scene)).subMaterials=a:i=new W.StandardMaterial("multimat"+t,e.scene),1===a.length&&(i=a[0]),o.material||(o.material=i),new W.Geometry(t,e.scene,s,!1,o),o.computeWorldMatrix(!0),o.subMeshes=[];var S=0;for(d=0;d<r.length;d++){var M;m=r[d];if(M=e.meshes[m])for(h=0;h<M.primitives.length;h++)M.primitives[h].mode,W.SubMesh.AddToMesh(S,u[S],l[S],c[S],f[S],o,o,!0),S++}return o},S=function(e,n,r,t){e.position&&(e.position=n),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=r),e.scaling&&(e.scaling=t)},s=function(e,n,r,t){var o=null;if(e.importOnlyMeshes&&(n.skin||n.meshes)&&e.importMeshesNames&&0<e.importMeshesNames.length&&-1===e.importMeshesNames.indexOf(n.name||""))return null;if(n.skin){if(n.meshes){var i=e.skins[n.skin];(a=N(e,n,n.meshes,r,n.babylonNode)).skeleton=e.scene.getLastSkeletonByID(n.skin),null===a.skeleton&&(a.skeleton=g(e,i,0,i.babylonSkeleton,n.skin),i.babylonSkeleton||(i.babylonSkeleton=a.skeleton)),o=a}}else if(n.meshes){var a;o=a=N(e,n,n.mesh?[n.mesh]:n.meshes,r,n.babylonNode)}else if(!n.light||n.babylonNode||e.importOnlyMeshes){if(n.camera&&!n.babylonNode&&!e.importOnlyMeshes){var s=e.cameras[n.camera];if(s)if("orthographic"===s.type){var u=new W.FreeCamera(n.camera,W.Vector3.Zero(),e.scene,!1);u.name=n.name||"",u.mode=W.Camera.ORTHOGRAPHIC_CAMERA,u.attachControl(e.scene.getEngine().getRenderingCanvas()),o=u}else if("perspective"===s.type){var l=s[s.type],c=new W.FreeCamera(n.camera,W.Vector3.Zero(),e.scene,!1);c.name=n.name||"",c.attachControl(e.scene.getEngine().getRenderingCanvas()),l.aspectRatio||(l.aspectRatio=e.scene.getEngine().getRenderWidth()/e.scene.getEngine().getRenderHeight()),l.znear&&l.zfar&&(c.maxZ=l.zfar,c.minZ=l.znear),o=c}}}else{var f=e.lights[n.light];if(f)if("ambient"===f.type){var d=f[f.type],m=new W.HemisphericLight(n.light,W.Vector3.Zero(),e.scene);m.name=n.name||"",d.color&&(m.diffuse=W.Color3.FromArray(d.color)),o=m}else if("directional"===f.type){var h=f[f.type],p=new W.DirectionalLight(n.light,W.Vector3.Zero(),e.scene);p.name=n.name||"",h.color&&(p.diffuse=W.Color3.FromArray(h.color)),o=p}else if("point"===f.type){var E=f[f.type],A=new W.PointLight(n.light,W.Vector3.Zero(),e.scene);A.name=n.name||"",E.color&&(A.diffuse=W.Color3.FromArray(E.color)),o=A}else if("spot"===f.type){var T=f[f.type],y=new W.SpotLight(n.light,W.Vector3.Zero(),W.Vector3.Zero(),0,0,e.scene);y.name=n.name||"",T.color&&(y.diffuse=W.Color3.FromArray(T.color)),T.fallOfAngle&&(y.angle=T.fallOfAngle),T.fallOffExponent&&(y.exponent=T.fallOffExponent),o=y}}if(!n.jointName){if(n.babylonNode)return n.babylonNode;if(null===o){var _=new W.Mesh(n.name||"",e.scene);o=n.babylonNode=_}}if(null!==o){if(n.matrix&&o instanceof W.Mesh)!(function(e,n,r){if(n.matrix){var t=new W.Vector3(0,0,0),o=new W.Quaternion,i=new W.Vector3(0,0,0);W.Matrix.FromArray(n.matrix).decompose(i,o,t),S(e,t,o,i)}else n.translation&&n.rotation&&n.scale&&S(e,W.Vector3.FromArray(n.translation),W.Quaternion.FromArray(n.rotation),W.Vector3.FromArray(n.scale));e.computeWorldMatrix(!0)})(o,n);else{var v=n.translation||[0,0,0],L=n.rotation||[0,0,0,1],O=n.scale||[1,1,1];S(o,W.Vector3.FromArray(v),W.Quaternion.FromArray(L),W.Vector3.FromArray(O))}o.updateCache(!0),n.babylonNode=o}return o},u=function(e,n,r,t){void 0===t&&(t=!1);var o=e.nodes[n],i=null;if(t=!(e.importOnlyMeshes&&!t&&e.importMeshesNames)||(-1!==e.importMeshesNames.indexOf(o.name||"")||0===e.importMeshesNames.length),!o.jointName&&t&&null!==(i=s(e,o,n))&&(i.id=n,i.parent=r),o.children)for(var a=0;a<o.children.length;a++)u(e,o.children[a],i,t)},f=function(e){var n=e.currentScene;if(n)for(var r=0;r<n.nodes.length;r++)u(e,n.nodes[r],null);else for(var t in e.scenes){n=e.scenes[t];for(r=0;r<n.nodes.length;r++)u(e,n.nodes[r],null)}!(function(e){for(var n in e.animations){var r=e.animations[n];if(r.channels&&r.samplers)for(var t=null,o=0;o<r.channels.length;o++){var i=r.channels[o],a=r.samplers[i.sampler];if(a){var s=null,u=null;r.parameters?(s=r.parameters[a.input],u=r.parameters[a.output]):(s=a.input,u=a.output);var l=w.GLTFUtils.GetBufferFromAccessor(e,e.accessors[s]),c=w.GLTFUtils.GetBufferFromAccessor(e,e.accessors[u]),f=i.target.id,d=e.scene.getNodeByID(f);if(null===d&&(d=e.scene.getNodeByName(f)),null!==d){var m=d instanceof W.Bone,h=i.target.path,p=M.indexOf(h);-1!==p&&(h=x[p]);var E=W.Animation.ANIMATIONTYPE_MATRIX;m||("rotationQuaternion"===h?(E=W.Animation.ANIMATIONTYPE_QUATERNION,d.rotationQuaternion=new W.Quaternion):E=W.Animation.ANIMATIONTYPE_VECTOR3);var A=null,T=[],y=0,_=!1;m&&t&&t.getKeys().length===l.length&&(A=t,_=!0),_||(A=new W.Animation(n,m?"_matrix":h,1,E,W.Animation.ANIMATIONLOOPMODE_CYCLE));for(var v=0;v<l.length;v++){var L=null;if("rotationQuaternion"===h?(L=W.Quaternion.FromArray([c[y],c[y+1],c[y+2],c[y+3]]),y+=4):(L=W.Vector3.FromArray([c[y],c[y+1],c[y+2]]),y+=3),m){var O=d,b=W.Vector3.Zero(),g=new W.Quaternion,N=W.Vector3.Zero(),S=O.getBaseMatrix();_&&t&&(S=t.getKeys()[v].value),S.decompose(N,g,b),"position"===h?b=L:"rotationQuaternion"===h?g=L:N=L,L=W.Matrix.Compose(N,g,b)}_?t&&(t.getKeys()[v].value=L):T.push({frame:l[v],value:L})}!_&&A&&(A.setKeys(T),d.animations.push(A)),t=A,e.scene.stopAnimation(d),e.scene.beginAnimation(d,0,l[l.length-1],!0,1)}else W.Tools.Warn("Creating animation named "+n+". But cannot find node named "+f+" to attach to")}}}})(e);for(r=0;r<e.scene.skeletons.length;r++){var o=e.scene.skeletons[r];e.scene.beginAnimation(o,0,Number.MAX_VALUE,!0,1)}},j=function(n,r,t,o,i,a){return function(e){!(function(e,r,n,t,o){var i=t.values||n.parameters,a=n.uniforms;for(var s in o){var u=o[s],l=u.type,c=i[a[s]];if(void 0===c&&(c=u.value),c){var f=function(n){return function(e){u.value&&n&&(r.setTexture(n,e),delete o[n])}};l===w.EParameterType.SAMPLER_2D?w.GLTFLoaderExtension.LoadTextureAsync(e,t.values?c:u.value,f(s),(function(){return f(null)})):u.value&&w.GLTFUtils.SetUniform(r,s,t.values?c:u.value,l)&&delete o[s]}}})(n,r,t,o,i),r.onBind=function(e){!(function(e,n,r,t,o,i,a){var s=i.values||o.parameters;for(var u in r){var l=r[u],c=l.type;if(c===w.EParameterType.FLOAT_MAT2||c===w.EParameterType.FLOAT_MAT3||c===w.EParameterType.FLOAT_MAT4)if(!l.semantic||l.source||l.node){if(l.semantic&&(l.source||l.node)){var f=n.scene.getNodeByName(l.source||l.node||"");if(null===f&&(f=n.scene.getNodeByID(l.source||l.node||"")),null===f)continue;w.GLTFUtils.SetMatrix(n.scene,f,l,u,t.getEffect())}}else w.GLTFUtils.SetMatrix(n.scene,e,l,u,t.getEffect());else{var d=s[o.uniforms[u]];if(!d)continue;if(c===w.EParameterType.SAMPLER_2D){var m=n.textures[i.values?d:l.value].babylonTexture;if(null==m)continue;t.getEffect().setTexture(u,m)}else w.GLTFUtils.SetUniform(t.getEffect(),u,d,c)}}a(t)})(e,n,i,r,t,o,a)}}},H=function(e,n,r){for(var t in n.uniforms){var o=n.uniforms[t],i=n.parameters[o];if(e.currentIdentifier===t&&i.semantic&&!i.source&&!i.node){var a=D.indexOf(i.semantic);if(-1!==a)return delete r[t],U[a]}}return e.currentIdentifier},d=function(e){for(var n in e.materials)w.GLTFLoaderExtension.LoadMaterialAsync(e,n,(function(e){}),(function(){}))},n=(function(){function e(){}return e.CreateRuntime=function(e,n,r){var t={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:n,rootUrl:r,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[]};return e.extensions&&o(e.extensions,"extensions",t),e.extensionsUsed&&o(e.extensionsUsed,"extensionsUsed",t),e.buffers&&(function(e,n){for(var r in e){var t=e[r];n.buffers[r]=t,n.buffersCount++}})(e.buffers,t),e.bufferViews&&o(e.bufferViews,"bufferViews",t),e.accessors&&o(e.accessors,"accessors",t),e.meshes&&o(e.meshes,"meshes",t),e.lights&&o(e.lights,"lights",t),e.cameras&&o(e.cameras,"cameras",t),e.nodes&&o(e.nodes,"nodes",t),e.images&&o(e.images,"images",t),e.textures&&o(e.textures,"textures",t),e.shaders&&(function(e,n){for(var r in e){var t=e[r];n.shaders[r]=t,n.shaderscount++}})(e.shaders,t),e.programs&&o(e.programs,"programs",t),e.samplers&&o(e.samplers,"samplers",t),e.techniques&&o(e.techniques,"techniques",t),e.materials&&o(e.materials,"materials",t),e.animations&&o(e.animations,"animations",t),e.skins&&o(e.skins,"skins",t),e.scenes&&(t.scenes=e.scenes),e.scene&&e.scenes&&(t.currentScene=e.scenes[e.scene]),t},e.LoadBufferAsync=function(e,n,r,t,o){var i=e.buffers[n];W.Tools.IsBase64(i.uri)?setTimeout((function(){return r(new Uint8Array(W.Tools.DecodeBase64(i.uri)))})):W.Tools.LoadFile(e.rootUrl+i.uri,(function(e){return r(new Uint8Array(e))}),o,void 0,!0,(function(e){e&&t(e.status+" "+e.statusText)}))},e.LoadTextureBufferAsync=function(e,n,r,t){var o=e.textures[n];if(o&&o.source)if(o.babylonTexture)r(null);else{var i=e.images[o.source];W.Tools.IsBase64(i.uri)?setTimeout((function(){return r(new Uint8Array(W.Tools.DecodeBase64(i.uri)))})):W.Tools.LoadFile(e.rootUrl+i.uri,(function(e){return r(new Uint8Array(e))}),void 0,void 0,!0,(function(e){e&&t(e.status+" "+e.statusText)}))}else t("")},e.CreateTextureAsync=function(e,n,r,t,o){var i=e.textures[n];if(i.babylonTexture)t(i.babylonTexture);else{var a=e.samplers[i.sampler],s=a.minFilter===w.ETextureFilterType.NEAREST_MIPMAP_NEAREST||a.minFilter===w.ETextureFilterType.NEAREST_MIPMAP_LINEAR||a.minFilter===w.ETextureFilterType.LINEAR_MIPMAP_NEAREST||a.minFilter===w.ETextureFilterType.LINEAR_MIPMAP_LINEAR,u=W.Texture.BILINEAR_SAMPLINGMODE,l=null==r?new Blob:new Blob([r]),c=URL.createObjectURL(l),f=function(){return URL.revokeObjectURL(c)},d=new W.Texture(c,e.scene,!s,!0,u,f,f);void 0!==a.wrapS&&(d.wrapU=w.GLTFUtils.GetWrapMode(a.wrapS)),void 0!==a.wrapT&&(d.wrapV=w.GLTFUtils.GetWrapMode(a.wrapT)),d.name=n,t(i.babylonTexture=d)}},e.LoadShaderStringAsync=function(e,n,r,t){var o=e.shaders[n];if(W.Tools.IsBase64(o.uri)){var i=atob(o.uri.split(",")[1]);r&&r(i)}else W.Tools.LoadFile(e.rootUrl+o.uri,r,void 0,void 0,!1,(function(e){e&&t&&t(e.status+" "+e.statusText)}))},e.LoadMaterialAsync=function(e,n,r,t){var o=e.materials[n];if(o.technique){var i=e.techniques[o.technique];if(!i){var a=new W.StandardMaterial(n,e.scene);return a.diffuseColor=new W.Color3(.5,.5,.5),a.sideOrientation=W.Material.CounterClockWiseSideOrientation,void r(a)}var s=e.programs[i.program],u=i.states,l=W.Effect.ShadersStore[s.vertexShader+"VertexShader"],c=W.Effect.ShadersStore[s.fragmentShader+"PixelShader"],f="",d="",m=new G(l),h=new G(c),p={},E=[],A=[],T=[];for(var y in i.uniforms){var _=i.uniforms[y],v=i.parameters[_];if(!(p[y]=v).semantic||v.node||v.source)v.type===w.EParameterType.SAMPLER_2D?T.push(y):E.push(y);else{var L=D.indexOf(v.semantic);-1!==L?(E.push(U[L]),delete p[y]):E.push(y)}}for(var O in i.attributes){var b=i.attributes[O];if((S=i.parameters[b]).semantic){var g=k(S);g&&A.push(g)}}for(;!m.isEnd()&&m.getNextToken();){if(m.currentToken===V.IDENTIFIER){var N=!1;for(var O in i.attributes){b=i.attributes[O];var S=i.parameters[b];if(m.currentIdentifier===O&&S.semantic){f+=k(S),N=!0;break}}N||(f+=H(m,i,p))}else f+=m.currentString}for(;!h.isEnd()&&h.getNextToken();){h.currentToken===V.IDENTIFIER?d+=H(h,i,p):d+=h.currentString}var M={vertex:s.vertexShader+n,fragment:s.fragmentShader+n},x={attributes:A,uniforms:E,samplers:T,needAlphaBlending:u&&u.enable&&-1!==u.enable.indexOf(3042)};W.Effect.ShadersStore[s.vertexShader+n+"VertexShader"]=f,W.Effect.ShadersStore[s.fragmentShader+n+"PixelShader"]=d;var F,C,P,R=new W.ShaderMaterial(n,e.scene,M,x);if(R.onError=(F=s,C=R,P=t,function(e,n){C.dispose(!0),P("Cannot compile program named "+F.name+". Error: "+n+". Default material will be applied")}),R.onCompiled=j(e,R,i,o,p,r),R.sideOrientation=W.Material.CounterClockWiseSideOrientation,u&&u.functions){var I=u.functions;I.cullFace&&I.cullFace[0]!==w.ECullingType.BACK&&(R.backFaceCulling=!1);var B=I.blendFuncSeparate;B&&(B[0]===w.EBlendingFunction.SRC_ALPHA&&B[1]===w.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&B[2]===w.EBlendingFunction.ONE&&B[3]===w.EBlendingFunction.ONE?R.alphaMode=W.Engine.ALPHA_COMBINE:B[0]===w.EBlendingFunction.ONE&&B[1]===w.EBlendingFunction.ONE&&B[2]===w.EBlendingFunction.ZERO&&B[3]===w.EBlendingFunction.ONE?R.alphaMode=W.Engine.ALPHA_ONEONE:B[0]===w.EBlendingFunction.SRC_ALPHA&&B[1]===w.EBlendingFunction.ONE&&B[2]===w.EBlendingFunction.ZERO&&B[3]===w.EBlendingFunction.ONE?R.alphaMode=W.Engine.ALPHA_ADD:B[0]===w.EBlendingFunction.ZERO&&B[1]===w.EBlendingFunction.ONE_MINUS_SRC_COLOR&&B[2]===w.EBlendingFunction.ONE&&B[3]===w.EBlendingFunction.ONE?R.alphaMode=W.Engine.ALPHA_SUBTRACT:B[0]===w.EBlendingFunction.DST_COLOR&&B[1]===w.EBlendingFunction.ZERO&&B[2]===w.EBlendingFunction.ONE&&B[3]===w.EBlendingFunction.ONE?R.alphaMode=W.Engine.ALPHA_MULTIPLY:B[0]===w.EBlendingFunction.SRC_ALPHA&&B[1]===w.EBlendingFunction.ONE_MINUS_SRC_COLOR&&B[2]===w.EBlendingFunction.ONE&&B[3]===w.EBlendingFunction.ONE&&(R.alphaMode=W.Engine.ALPHA_MAXIMIZED))}}else t&&t("No technique found.")},e})();w.GLTFLoaderBase=n;var r=(function(){function n(){this.state=null}return n.RegisterExtension=function(e){n.Extensions[e.name]?W.Tools.Error('Tool with the same name "'+e.name+'" already exists'):n.Extensions[e.name]=e},n.prototype.dispose=function(){},n.prototype._importMeshAsync=function(s,e,n,r,u,l,t){var c=this;return e.useRightHandedSystem=!0,w.GLTFLoaderExtension.LoadRuntimeAsync(e,n,r,(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 n=new Array,r=new Array;for(var t in e.nodes){var o=e.nodes[t];o.babylonNode instanceof W.AbstractMesh&&n.push(o.babylonNode)}for(var i in e.skins){var a=e.skins[i];a.babylonSkeleton instanceof W.Skeleton&&r.push(a.babylonSkeleton)}c._loadBuffersAsync(e,(function(){c._loadShadersAsync(e,(function(){d(e),f(e),!W.GLTFFileLoader.IncrementalLoading&&u&&u(n,r)}))}),l),W.GLTFFileLoader.IncrementalLoading&&u&&u(n,r)}),t),!0},n.prototype.importMeshAsync=function(e,t,o,i,a){var s=this;return new Promise(function(r,n){s._importMeshAsync(e,t,o,i,(function(e,n){r({meshes:e,particleSystems:[],skeletons:n,animationGroups:[]})}),a,(function(e){n(new Error(e))}))})},n.prototype._loadAsync=function(e,n,r,t,o,i){var a=this;e.useRightHandedSystem=!0,w.GLTFLoaderExtension.LoadRuntimeAsync(e,n,r,(function(e){w.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(e,(function(){a._createNodes(e),a._loadBuffersAsync(e,(function(){a._loadShadersAsync(e,(function(){d(e),f(e),W.GLTFFileLoader.IncrementalLoading||t()}))})),W.GLTFFileLoader.IncrementalLoading&&t()}),i)}),i)},n.prototype.loadAsync=function(r,t,o,i){var a=this;return new Promise(function(e,n){a._loadAsync(r,t,o,(function(){e()}),i,(function(e){n(new Error(e))}))})},n.prototype._loadShadersAsync=function(t,o){var e=!1,n=function(n,r){w.GLTFLoaderExtension.LoadShaderStringAsync(t,n,(function(e){e instanceof ArrayBuffer||(t.loadedShaderCount++,e&&(W.Effect.ShadersStore[n+(r.type===w.EShaderType.VERTEX?"VertexShader":"PixelShader")]=e),t.loadedShaderCount===t.shaderscount&&o())}),(function(){W.Tools.Error("Error when loading shader program named "+n+" located at "+r.uri)}))};for(var r in t.shaders){e=!0;var i=t.shaders[r];i?n.bind(this,r,i)():W.Tools.Error("No shader named: "+r)}e||o()},n.prototype._loadBuffersAsync=function(t,o,e){var n=!1,r=function(n,r){w.GLTFLoaderExtension.LoadBufferAsync(t,n,(function(e){t.loadedBufferCount++,e&&(e.byteLength!=t.buffers[n].byteLength&&W.Tools.Error("Buffer named "+n+" is length "+e.byteLength+". Expected: "+r.byteLength),t.loadedBufferViews[n]=e),t.loadedBufferCount===t.buffersCount&&o()}),(function(){W.Tools.Error("Error when loading buffer named "+n+" located at "+r.uri)}))};for(var i in t.buffers){n=!0;var a=t.buffers[i];a?r.bind(this,i,a)():W.Tools.Error("No buffer named: "+i)}n||o()},n.prototype._createNodes=function(e){var n=e.currentScene;if(n)for(var r=0;r<n.nodes.length;r++)u(e,n.nodes[r],null);else for(var t in e.scenes){n=e.scenes[t];for(r=0;r<n.nodes.length;r++)u(e,n.nodes[r],null)}},n.Extensions={},n})();w.GLTFLoader=r,W.GLTFFileLoader._CreateGLTFLoaderV1=function(){return new r}})(W.GLTF1||(W.GLTF1={}))})(BABYLON||(BABYLON={})),(function(a){var s,e;s=a.GLTF1||(a.GLTF1={}),e=(function(){function o(){}return o.SetMatrix=function(e,n,r,t,o){var i=null;if("MODEL"===r.semantic?i=n.getWorldMatrix():"PROJECTION"===r.semantic?i=e.getProjectionMatrix():"VIEW"===r.semantic?i=e.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===r.semantic?i=a.Matrix.Transpose(n.getWorldMatrix().multiply(e.getViewMatrix()).invert()):"MODELVIEW"===r.semantic?i=n.getWorldMatrix().multiply(e.getViewMatrix()):"MODELVIEWPROJECTION"===r.semantic?i=n.getWorldMatrix().multiply(e.getTransformMatrix()):"MODELINVERSE"===r.semantic?i=n.getWorldMatrix().invert():"VIEWINVERSE"===r.semantic?i=e.getViewMatrix().invert():"PROJECTIONINVERSE"===r.semantic?i=e.getProjectionMatrix().invert():"MODELVIEWINVERSE"===r.semantic?i=n.getWorldMatrix().multiply(e.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===r.semantic?i=n.getWorldMatrix().multiply(e.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===r.semantic&&(i=a.Matrix.Transpose(n.getWorldMatrix().invert())),i)switch(r.type){case s.EParameterType.FLOAT_MAT2:o.setMatrix2x2(t,a.Matrix.GetAsMatrix2x2(i));break;case s.EParameterType.FLOAT_MAT3:o.setMatrix3x3(t,a.Matrix.GetAsMatrix3x3(i));break;case s.EParameterType.FLOAT_MAT4:o.setMatrix(t,i)}},o.SetUniform=function(e,n,r,t){switch(t){case s.EParameterType.FLOAT:return e.setFloat(n,r),!0;case s.EParameterType.FLOAT_VEC2:return e.setVector2(n,a.Vector2.FromArray(r)),!0;case s.EParameterType.FLOAT_VEC3:return e.setVector3(n,a.Vector3.FromArray(r)),!0;case s.EParameterType.FLOAT_VEC4:return e.setVector4(n,a.Vector4.FromArray(r)),!0;default:return!1}},o.GetWrapMode=function(e){switch(e){case s.ETextureWrapMode.CLAMP_TO_EDGE:return a.Texture.CLAMP_ADDRESSMODE;case s.ETextureWrapMode.MIRRORED_REPEAT:return a.Texture.MIRROR_ADDRESSMODE;case s.ETextureWrapMode.REPEAT:default:return a.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 a.Texture.TRILINEAR_SAMPLINGMODE;case s.ETextureFilterType.NEAREST:case s.ETextureFilterType.NEAREST_MIPMAP_NEAREST:return a.Texture.NEAREST_SAMPLINGMODE;default:return a.Texture.BILINEAR_SAMPLINGMODE}},o.GetBufferFromBufferView=function(e,n,r,t,o){r=n.byteOffset+r;var i=e.loadedBufferViews[n.buffer];if(r+t>i.byteLength)throw new Error("Buffer access is out of range");var a=i.buffer;switch(r+=i.byteOffset,o){case s.EComponentType.BYTE:return new Int8Array(a,r,t);case s.EComponentType.UNSIGNED_BYTE:return new Uint8Array(a,r,t);case s.EComponentType.SHORT:return new Int16Array(a,r,t);case s.EComponentType.UNSIGNED_SHORT:return new Uint16Array(a,r,t);default:return new Float32Array(a,r,t)}},o.GetBufferFromAccessor=function(e,n){var r=e.bufferViews[n.bufferView],t=n.count*o.GetByteStrideFromType(n);return o.GetBufferFromBufferView(e,r,n.byteOffset,t,n.componentType)},o.DecodeBufferToText=function(e){for(var n="",r=e.byteLength,t=0;t<r;++t)n+=String.fromCharCode(e[t]);return n},o.GetDefaultMaterial=function(e){if(!o._DefaultMaterial){a.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"),a.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");var n={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};(o._DefaultMaterial=new a.ShaderMaterial("GLTFDefaultMaterial",e,{vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},n)).setColor4("u_emission",new a.Color4(.5,.5,.5,1))}return o._DefaultMaterial},o._DefaultMaterial=null,o})(),s.GLTFUtils=e})(BABYLON||(BABYLON={})),(function(e){var s,n;s=e.GLTF1||(e.GLTF1={}),n=(function(){function a(e){this._name=e}return Object.defineProperty(a.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),a.prototype.loadRuntimeAsync=function(e,n,r,t,o){return!1},a.prototype.loadRuntimeExtensionsAsync=function(e,n,r){return!1},a.prototype.loadBufferAsync=function(e,n,r,t,o){return!1},a.prototype.loadTextureBufferAsync=function(e,n,r,t){return!1},a.prototype.createTextureAsync=function(e,n,r,t,o){return!1},a.prototype.loadShaderStringAsync=function(e,n,r,t){return!1},a.prototype.loadMaterialAsync=function(e,n,r,t){return!1},a.LoadRuntimeAsync=function(n,r,t,o,i){a.ApplyExtensions((function(e){return e.loadRuntimeAsync(n,r,t,o,i)}),(function(){setTimeout((function(){o&&o(s.GLTFLoaderBase.CreateRuntime(r.json,n,t))}))}))},a.LoadRuntimeExtensionsAsync=function(n,r,t){a.ApplyExtensions((function(e){return e.loadRuntimeExtensionsAsync(n,r,t)}),(function(){setTimeout((function(){r()}))}))},a.LoadBufferAsync=function(n,r,t,o,i){a.ApplyExtensions((function(e){return e.loadBufferAsync(n,r,t,o,i)}),(function(){s.GLTFLoaderBase.LoadBufferAsync(n,r,t,o,i)}))},a.LoadTextureAsync=function(n,r,t,o){a.LoadTextureBufferAsync(n,r,(function(e){e&&a.CreateTextureAsync(n,r,e,t,o)}),o)},a.LoadShaderStringAsync=function(n,r,t,o){a.ApplyExtensions((function(e){return e.loadShaderStringAsync(n,r,t,o)}),(function(){s.GLTFLoaderBase.LoadShaderStringAsync(n,r,t,o)}))},a.LoadMaterialAsync=function(n,r,t,o){a.ApplyExtensions((function(e){return e.loadMaterialAsync(n,r,t,o)}),(function(){s.GLTFLoaderBase.LoadMaterialAsync(n,r,t,o)}))},a.LoadTextureBufferAsync=function(n,r,t,o){a.ApplyExtensions((function(e){return e.loadTextureBufferAsync(n,r,t,o)}),(function(){s.GLTFLoaderBase.LoadTextureBufferAsync(n,r,t,o)}))},a.CreateTextureAsync=function(n,r,t,o,i){a.ApplyExtensions((function(e){return e.createTextureAsync(n,r,t,o,i)}),(function(){s.GLTFLoaderBase.CreateTextureAsync(n,r,t,o,i)}))},a.ApplyExtensions=function(e,n){for(var r in s.GLTFLoader.Extensions){if(e(s.GLTFLoader.Extensions[r]))return}n()},a})(),s.GLTFLoaderExtension=n})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}})();!(function(e){var u,n;u=e.GLTF1||(e.GLTF1={}),n=(function(e){function n(){return e.call(this,"KHR_binary_glTF")||this}return __extends(n,e),n.prototype.loadRuntimeAsync=function(e,n,r,t,o){var i=n.json.extensionsUsed;return!(!i||-1===i.indexOf(this.name)||!n.bin)&&(this._bin=n.bin,t(u.GLTFLoaderBase.CreateRuntime(n.json,e,r)),!0)},n.prototype.loadBufferAsync=function(e,n,r,t){return-1!==e.extensionsUsed.indexOf(this.name)&&("binary_glTF"===n&&(r(this._bin),!0))},n.prototype.loadTextureBufferAsync=function(e,n,r,t){var o=e.textures[n],i=e.images[o.source];if(!(i.extensions&&this.name in i.extensions))return!1;var a=i.extensions[this.name],s=e.bufferViews[a.bufferView];return r(u.GLTFUtils.GetBufferFromBufferView(e,s,0,s.byteLength,u.EComponentType.UNSIGNED_BYTE)),!0},n.prototype.loadShaderStringAsync=function(e,n,r,t){var o=e.shaders[n];if(!(o.extensions&&this.name in o.extensions))return!1;var i=o.extensions[this.name],a=e.bufferViews[i.bufferView],s=u.GLTFUtils.GetBufferFromBufferView(e,a,0,a.byteLength,u.EComponentType.UNSIGNED_BYTE);return setTimeout((function(){var e=u.GLTFUtils.DecodeBufferToText(s);r(e)})),!0},n})(u.GLTFLoaderExtension),u.GLTFBinaryExtension=n,u.GLTFLoader.RegisterExtension(new n)})(BABYLON||(BABYLON={}));var BABYLON;__extends=this&&this.__extends||(function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}})();!(function(h){var a,e;a=h.GLTF1||(h.GLTF1={}),e=(function(e){function n(){return e.call(this,"KHR_materials_common")||this}return __extends(n,e),n.prototype.loadRuntimeExtensionsAsync=function(e,n,r){if(!e.extensions)return!1;var t=e.extensions[this.name];if(!t)return!1;var o=t.lights;if(o)for(var i in o){var a=o[i];switch(a.type){case"ambient":var s=new h.HemisphericLight(a.name,new h.Vector3(0,1,0),e.scene),u=a.ambient;u&&(s.diffuse=h.Color3.FromArray(u.color||[1,1,1]));break;case"point":var l=new h.PointLight(a.name,new h.Vector3(10,10,10),e.scene),c=a.point;c&&(l.diffuse=h.Color3.FromArray(c.color||[1,1,1]));break;case"directional":var f=new h.DirectionalLight(a.name,new h.Vector3(0,-1,0),e.scene),d=a.directional;d&&(f.diffuse=h.Color3.FromArray(d.color||[1,1,1]));break;case"spot":var m=a.spot;if(m)new h.SpotLight(a.name,new h.Vector3(0,10,0),new h.Vector3(0,-1,0),m.fallOffAngle||Math.PI,m.fallOffExponent||0,e.scene).diffuse=h.Color3.FromArray(m.color||[1,1,1]);break;default:h.Tools.Warn('GLTF Material Common extension: light type "'+a.type+"” not supported")}}return!1},n.prototype.loadMaterialAsync=function(e,n,r,t){var o=e.materials[n];if(!o||!o.extensions)return!1;var i=o.extensions[this.name];if(!i)return!1;var a=new h.StandardMaterial(n,e.scene);return a.sideOrientation=h.Material.CounterClockWiseSideOrientation,"CONSTANT"===i.technique&&(a.disableLighting=!0),a.backFaceCulling=void 0!==i.doubleSided&&!i.doubleSided,a.alpha=void 0===i.values.transparency?1:i.values.transparency,a.specularPower=void 0===i.values.shininess?0:i.values.shininess,"string"==typeof i.values.ambient?this._loadTexture(e,i.values.ambient,a,"ambientTexture",t):a.ambientColor=h.Color3.FromArray(i.values.ambient||[0,0,0]),"string"==typeof i.values.diffuse?this._loadTexture(e,i.values.diffuse,a,"diffuseTexture",t):a.diffuseColor=h.Color3.FromArray(i.values.diffuse||[0,0,0]),"string"==typeof i.values.emission?this._loadTexture(e,i.values.emission,a,"emissiveTexture",t):a.emissiveColor=h.Color3.FromArray(i.values.emission||[0,0,0]),"string"==typeof i.values.specular?this._loadTexture(e,i.values.specular,a,"specularTexture",t):a.specularColor=h.Color3.FromArray(i.values.specular||[0,0,0]),!0},n.prototype._loadTexture=function(n,r,t,o,i){a.GLTFLoaderBase.LoadTextureBufferAsync(n,r,(function(e){a.GLTFLoaderBase.CreateTextureAsync(n,r,e,(function(e){return t[o]=e}),i)}),i)},n})(a.GLTFLoaderExtension),a.GLTFMaterialsCommonExtension=e,a.GLTFLoader.RegisterExtension(new e)})(BABYLON||(BABYLON={}));