babylon.glTF1FileLoader.min.js 45 KB

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