babylonjs.loaders.min.js 75 KB

123
  1. var BABYLON=BABYLON||"undefined"!=typeof require&&require("babylonjs"),__decorate=this&&this.__decorate||function(e,t,n,r){var a,o=arguments.length,i=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,n,i):a(t,n))||i);return o>3&&i&&Object.defineProperty(t,n,i),i},__extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}})(),BABYLON;!(function(e){var t=(function(){function t(){this.solidPattern=/solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g,this.facetsPattern=/facet([\s\S]*?)endfacet/g,this.normalPattern=/normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g,this.vertexPattern=/vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g,this.name="stl",this.extensions={".stl":{isBinary:!0}}}return t.prototype.importMesh=function(t,n,r,a,o,i,s){var l;if(this.isBinary(r)){var u=new e.Mesh("stlmesh",n);return this.parseBinary(u,r),o&&o.push(u),!0}for(var c=new Uint8Array(r),f="",d=0;d<r.byteLength;d++)f+=String.fromCharCode(c[d]);for(r=f;l=this.solidPattern.exec(r);){var h=l[1];if(h!=l[3])return e.Tools.Error("Error in STL, solid name != endsolid name"),!1;if(t&&h)if(t instanceof Array){if(!t.indexOf(h))continue}else if(h!==t)continue;h=h||"stlmesh";var u=new e.Mesh(h,n);this.parseASCII(u,l[2]),o&&o.push(u)}return!0},t.prototype.load=function(e,t,n){var r=this.importMesh(null,e,t,n,null,null,null);return r&&e.createDefaultCameraOrLight(),r},t.prototype.isBinary=function(e){var t,n;if(n=new DataView(e),t=50,84+n.getUint32(80,!0)*t===n.byteLength)return!0;for(var r=n.byteLength,a=0;a<r;a++)if(n.getUint8(a,!1)>127)return!0;return!1},t.prototype.parseBinary=function(t,n){for(var r=new DataView(n),a=r.getUint32(80,!0),o=0,i=new Float32Array(3*a*3),s=new Float32Array(3*a*3),l=new Uint32Array(3*a),u=0,c=0;c<a;c++){for(var f=84+50*c,d=r.getFloat32(f,!0),h=r.getFloat32(f+4,!0),p=r.getFloat32(f+8,!0),m=1;m<=3;m++){var T=f+12*m;i[o]=r.getFloat32(T,!0),i[o+2]=r.getFloat32(T+4,!0),i[o+1]=r.getFloat32(T+8,!0),s[o]=d,s[o+2]=h,s[o+1]=p,o+=3}l[u]=u++,l[u]=u++,l[u]=u++}t.setVerticesData(e.VertexBuffer.PositionKind,i),t.setVerticesData(e.VertexBuffer.NormalKind,s),t.setIndices(l),t.computeWorldMatrix(!0)},t.prototype.parseASCII=function(t,n){for(var r,a=[],o=[],i=[],s=0;r=this.facetsPattern.exec(n);){var l=r[1],u=this.normalPattern.exec(l);if(this.normalPattern.lastIndex=0,u){for(var c,f=[Number(u[1]),Number(u[5]),Number(u[3])];c=this.vertexPattern.exec(l);)a.push(Number(c[1]),Number(c[5]),Number(c[3])),o.push(f[0],f[1],f[2]);i.push(s++,s++,s++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,t.setVerticesData(e.VertexBuffer.PositionKind,a),t.setVerticesData(e.VertexBuffer.NormalKind,o),t.setIndices(i),t.computeWorldMatrix(!0)},t})();e.STLFileLoader=t,e.SceneLoader&&e.SceneLoader.RegisterPlugin(new t)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function t(){this.materials=[],this.parseMTL=function(n,r,a){for(var o,i,s=r.split("\n"),l=0;l<s.length;l++){var u=s[l].trim();if(0!==u.length&&"#"!==u.charAt(0)){var c=u.indexOf(" "),f=c>=0?u.substring(0,c):u;f=f.toLowerCase();var d=c>=0?u.substring(c+1).trim():"";"newmtl"===f?(i&&this.materials.push(i),i=new e.StandardMaterial(d,n)):"kd"===f?(o=d.split(/\s+/,3).map(parseFloat),i.diffuseColor=e.Color3.FromArray(o)):"ka"===f?(o=d.split(/\s+/,3).map(parseFloat),i.ambientColor=e.Color3.FromArray(o)):"ks"===f?(o=d.split(/\s+/,3).map(parseFloat),i.specularColor=e.Color3.FromArray(o)):"ke"===f?(o=d.split(/\s+/,3).map(parseFloat),i.emissiveColor=e.Color3.FromArray(o)):"ns"===f?i.specularPower=parseFloat(d):"d"===f?i.alpha=parseFloat(d):"map_ka"===f?i.ambientTexture=t._getTexture(a,d,n):"map_kd"===f?i.diffuseTexture=t._getTexture(a,d,n):"map_ks"===f?i.specularTexture=t._getTexture(a,d,n):"map_ns"===f||("map_bump"===f?i.bumpTexture=t._getTexture(a,d,n):"map_d"===f&&(i.opacityTexture=t._getTexture(a,d,n)))}}this.materials.push(i)}}return t._getTexture=function(t,n,r){if(!n)return null;var a=t;if("file:"===t){var o=n.lastIndexOf("\\");-1===o&&(o=n.lastIndexOf("/")),a+=o>-1?n.substr(o+1):n}else a+=n;return new e.Texture(a,r)},t})();e.MTLFileLoader=t;var n=(function(){function n(){this.name="obj",this.extensions=".obj",this.obj=/^o/,this.group=/^g/,this.mtllib=/^mtllib /,this.usemtl=/^usemtl /,this.smooth=/^s /,this.vertexPattern=/v( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.normalPattern=/vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.uvPattern=/vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.facePattern1=/f\s+(([\d]{1,}[\s]?){3,})+/,this.facePattern2=/f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern3=/f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern4=/f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/}return n.prototype._loadMTL=function(t,n,r){var a=e.Tools.BaseUrl+n+t;e.Tools.LoadFile(a,r,null,null,!1,(function(){console.warn("Error - Unable to load "+a)}))},n.prototype.importMesh=function(e,t,n,r,a,o,i){var s=this._parseSolid(e,t,n,r);return a&&s.forEach((function(e){a.push(e)})),!0},n.prototype.load=function(e,t,n){return this.importMesh(null,e,t,n,null,null,null)},n.prototype._parseSolid=function(r,a,o,i){for(var s,l=[],u=[],c=[],f=[],d=[],h=[],p=[],m=[],T=[],A=0,E=!1,y=[],_=[],g=[],v=[],L="",b="",N=new t,M=1,x=!0,O=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[]});var n=e[t[0]].normals.indexOf(t[1]);return-1===n?-1:e[t[0]].idx[n]},S=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[],uv:[]});var n=e[t[0]].normals.indexOf(t[1]);return 1!=n&&t[2]==e[t[0]].uv[n]?e[t[0]].idx[n]:-1},R=function(e,t,r,a,o,i){var s;s=n.OPTIMIZE_WITH_UV?S(T,[e,r,t]):O(T,[e,r]),-1==s?(d.push(h.length),h.push(a),p.push(o),m.push(i),T[e].normals.push(r),T[e].idx.push(A++),n.OPTIMIZE_WITH_UV&&T[e].uv.push(t)):d.push(s)},F=function(){for(var e=0;e<h.length;e++)y.push(h[e].x,h[e].y,h[e].z),_.push(m[e].x,m[e].y,m[e].z),g.push(p[e].x,p[e].y);h=[],m=[],p=[],T=[],A=0},I=function(e,t){t+1<e.length&&(v.push(e[0],e[t],e[t+1]),t+=1,I(e,t))},B=function(){f.length>0&&(s=f[f.length-1],F(),d.reverse(),s.indices=d.slice(),s.positions=y.slice(),s.normals=_.slice(),s.uvs=g.slice(),d=[],y=[],_=[],g=[])},P=o.split("\n"),C=0;C<P.length;C++){var w,D=P[C].trim();if(0!==D.length&&"#"!==D.charAt(0))if(null!==(w=this.vertexPattern.exec(D)))l.push(new e.Vector3(parseFloat(w[1]),parseFloat(w[2]),parseFloat(w[3])));else if(null!==(w=this.normalPattern.exec(D)))u.push(new e.Vector3(parseFloat(w[1]),parseFloat(w[2]),parseFloat(w[3])));else if(null!==(w=this.uvPattern.exec(D)))c.push(new e.Vector2(parseFloat(w[1]),parseFloat(w[2])));else if(null!==(w=this.facePattern3.exec(D)))!(function(e,t){I(e,t);for(var n=0;n<v.length;n++){var r=v[n].split("/"),a=parseInt(r[0])-1,o=parseInt(r[1])-1,i=parseInt(r[2])-1;R(a,o,i,l[a],c[o],u[i])}v=[]})(w[1].trim().split(" "),1);else if(null!==(w=this.facePattern4.exec(D)))!(function(t,n){I(t,n);for(var r=0;r<v.length;r++){var a=v[r].split("//"),o=parseInt(a[0])-1,i=parseInt(a[1])-1;R(o,1,i,l[o],e.Vector2.Zero(),u[i])}v=[]})(w[1].trim().split(" "),1);else if(null!==(w=this.facePattern2.exec(D)))!(function(t,n){I(t,n);for(var r=0;r<v.length;r++){var a=v[r].split("/"),o=parseInt(a[0])-1,i=parseInt(a[1])-1;R(o,i,0,l[o],c[i],e.Vector3.Up())}v=[]})(w[1].trim().split(" "),1);else if(null!==(w=this.facePattern1.exec(D)))!(function(t,n){I(t,n);for(var r=0;r<v.length;r++){var a=parseInt(v[r])-1;R(a,0,0,l[a],e.Vector2.Zero(),e.Vector3.Up())}v=[]})(w[1].trim().split(" "),1);else if(this.group.test(D)||this.obj.test(D)){var G={name:D.substring(2).trim(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:""};B(),f.push(G),E=!0,x=!0,M=1}else if(this.usemtl.test(D)){if(L=D.substring(7).trim(),!x){B();var G={name:"_mm"+M.toString(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:L};M++,f.push(G)}E&&x&&(f[f.length-1].materialName=L,x=!1)}else this.mtllib.test(D)?b=D.substring(7).trim():this.smooth.test(D)||console.log("Unhandled expression at line : "+D)}E&&(s=f[f.length-1],d.reverse(),F(),s.indices=d,s.positions=y,s.normals=_,s.uvs=g),E||(d.reverse(),F(),f.push({name:e.Geometry.RandomId(),indices:d,positions:y,normals:_,uvs:g,materialName:L}));for(var U=[],V=[],k=0;k<f.length;k++){if(r&&f[k].name)if(r instanceof Array){if(-1==r.indexOf(f[k].name))continue}else if(f[k].name!==r)continue;s=f[k];var H=new e.Mesh(f[k].name,a);V.push(f[k].materialName);var W=new e.VertexData;W.positions=s.positions,W.normals=s.normals,W.uvs=s.uvs,W.indices=s.indices,W.applyToMesh(H),U.push(H)}return""!==b&&this._loadMTL(b,i,(function(e){N.parseMTL(a,e,i);for(var t=0;t<N.materials.length;t++){for(var n,r=0,o=[];(n=V.indexOf(N.materials[t].name,r))>-1;)o.push(n),r=n+1;if(-1==n&&0==o.length)N.materials[t].dispose();else for(var s=0;s<o.length;s++)U[o[s]].material=N.materials[t]}})),U},n.OPTIMIZE_WITH_UV=!1,n})();e.OBJFileLoader=n,e.SceneLoader&&e.SceneLoader.RegisterPlugin(new n)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.PASS_THROUGH=1]="PASS_THROUGH",e[e.FORCE_RIGHT_HANDED=2]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var n=(function(){function e(){this.coordinateSystemMode=t.AUTO,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.importMeshAsync=function(t,n,r,a,o,i,s){var l=e._parse(r,s);if(l){this.onParsed&&this.onParsed(l);var u=this._getLoader(l,s);u&&u.importMeshAsync(t,n,l,a,o,i,s)}},e.prototype.loadAsync=function(t,n,r,a,o,i){var s=e._parse(n,i);if(s){this.onParsed&&this.onParsed(s);var l=this._getLoader(s,i);if(l)return l.loadAsync(t,s,r,a,o,i)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e._parse=function(t,n){if(t instanceof ArrayBuffer)return e._parseBinary(t,n);try{return{json:JSON.parse(t),bin:null}}catch(e){return n(e.message),null}},e.prototype._getLoader=function(t,n){var r={major:2,minor:0},a=t.json.asset||{},o=e._parseVersion(a.version);if(!o)return n("Invalid version: "+a.version),null;if(void 0!==a.minVersion){var i=e._parseVersion(a.minVersion);if(!i)return n("Invalid minimum version: "+a.minVersion),null;if(e._compareVersion(i,r)>0)return n("Incompatible minimum version: "+a.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},l=s[o.major];return l?l(this):(n("Unsupported version: "+a.version),null)},e._parseBinary=function(t,n){var a={Magic:1179937895},o=new r(t),i=o.readUint32();if(i!==a.Magic)return n("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return e._parseV1(o,n);case 2:return e._parseV2(o,n)}return n("Unsupported version: "+s),null},e._parseV1=function(t,n){var r={JSON:0},a=t.readUint32();if(a!=t.getLength())return n("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o,i=t.readUint32(),s=t.readUint32();switch(s){case r.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(i)));break;default:return n("Unexpected content format: "+s),null}var l=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(l)}},e._parseV2=function(t,n){var r={JSON:1313821514,BIN:5130562},a=t.readUint32();if(a!==t.getLength())return n("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o=t.readUint32(),i=t.readUint32();if(i!==r.JSON)return n("First chunk format is not JSON"),null;for(var s=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),l=null;t.getPosition()<t.getLength();)switch(o=t.readUint32(),i=t.readUint32()){case r.JSON:return n("Unexpected JSON chunk"),null;case r.BIN:l=t.readUint8Array(o);break;default:t.skipBytes(o)}return{json:s,bin:l}},e._parseVersion=function(e){if(!e)return null;var t=e.split(".");if(2!=t.length)return null;var n=+t[0];if(isNaN(n))return null;var r=+t[1];return isNaN(r)?null:{major:n,minor:r}},e._compareVersion=function(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0},e._decodeBufferToText=function(e){for(var t="",n=e.byteLength,r=0;r<n;++r)t+=String.fromCharCode(e[r]);return t},e.HomogeneousCoordinates=!1,e.IncrementalLoading=!0,e})();e.GLTFFileLoader=n;var r=(function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new n)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.FLOAT=5126]="FLOAT"})(e.EComponentType||(e.EComponentType={}));!(function(e){e[e.FRAGMENT=35632]="FRAGMENT",e[e.VERTEX=35633]="VERTEX"})(e.EShaderType||(e.EShaderType={}));!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.INT=5124]="INT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT",e[e.FLOAT_VEC2=35664]="FLOAT_VEC2",e[e.FLOAT_VEC3=35665]="FLOAT_VEC3",e[e.FLOAT_VEC4=35666]="FLOAT_VEC4",e[e.INT_VEC2=35667]="INT_VEC2",e[e.INT_VEC3=35668]="INT_VEC3",e[e.INT_VEC4=35669]="INT_VEC4",e[e.BOOL=35670]="BOOL",e[e.BOOL_VEC2=35671]="BOOL_VEC2",e[e.BOOL_VEC3=35672]="BOOL_VEC3",e[e.BOOL_VEC4=35673]="BOOL_VEC4",e[e.FLOAT_MAT2=35674]="FLOAT_MAT2",e[e.FLOAT_MAT3=35675]="FLOAT_MAT3",e[e.FLOAT_MAT4=35676]="FLOAT_MAT4",e[e.SAMPLER_2D=35678]="SAMPLER_2D"})(e.EParameterType||(e.EParameterType={}));!(function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"})(e.ETextureWrapMode||(e.ETextureWrapMode={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9728]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"})(e.ETextureFilterType||(e.ETextureFilterType={}));!(function(e){e[e.ALPHA=6406]="ALPHA",e[e.RGB=6407]="RGB",e[e.RGBA=6408]="RGBA",e[e.LUMINANCE=6409]="LUMINANCE",e[e.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA"})(e.ETextureFormat||(e.ETextureFormat={}));!(function(e){e[e.FRONT=1028]="FRONT",e[e.BACK=1029]="BACK",e[e.FRONT_AND_BACK=1032]="FRONT_AND_BACK"})(e.ECullingType||(e.ECullingType={}));!(function(e){e[e.ZERO=0]="ZERO",e[e.ONE=1]="ONE",e[e.SRC_COLOR=768]="SRC_COLOR",e[e.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",e[e.DST_COLOR=774]="DST_COLOR",e[e.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.DST_ALPHA=772]="DST_ALPHA",e[e.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",e[e.CONSTANT_COLOR=32769]="CONSTANT_COLOR",e[e.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",e[e.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",e[e.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",e[e.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE"})(e.EBlendingFunction||(e.EBlendingFunction={}))})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var n;!(function(e){e[e.IDENTIFIER=1]="IDENTIFIER",e[e.UNKNOWN=2]="UNKNOWN",e[e.END_OF_INPUT=3]="END_OF_INPUT"})(n||(n={}));var r=(function(){function e(e){this._pos=0,this.isLetterOrDigitPattern=/^[a-zA-Z0-9]+$/,this._toParse=e,this._maxPos=e.length}return e.prototype.getNextToken=function(){if(this.isEnd())return n.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=n.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=n.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})(),a=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],o=["world","view","projection","worldView","worldViewProjection","mBones"],i=["translation","rotation","scale"],s=["position","rotationQuaternion","scaling"],l=function(e,t){for(var n in e){var r=e[n];t.buffers[n]=r,t.buffersCount++}},u=function(e,t){for(var n in e){var r=e[n];t.shaders[n]=r,t.shaderscount++}},c=function(e,t,n){for(var r in e){var a=e[r];n[t][r]=a}},f=function(e){if(e)for(var t=0;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},d=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(-1!==e.semantic.indexOf("TEXCOORD_")){var t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}},h=function(n){for(var r in n.animations)for(var a=n.animations[r],o=null,l=0;l<a.channels.length;l++){var u=a.channels[l],c=a.samplers[u.sampler];if(c){var f=null,d=null;a.parameters?(f=a.parameters[c.input],d=a.parameters[c.output]):(f=c.input,d=c.output);var h=t.GLTFUtils.GetBufferFromAccessor(n,n.accessors[f]),p=t.GLTFUtils.GetBufferFromAccessor(n,n.accessors[d]),m=u.target.id,T=n.scene.getNodeByID(m);if(null===T&&(T=n.scene.getNodeByName(m)),null!==T){var A=T instanceof e.Bone,E=u.target.path,y=i.indexOf(E);-1!==y&&(E=s[y]);var _=e.Animation.ANIMATIONTYPE_MATRIX;A||("rotationQuaternion"===E?(_=e.Animation.ANIMATIONTYPE_QUATERNION,T.rotationQuaternion=new e.Quaternion):_=e.Animation.ANIMATIONTYPE_VECTOR3);var g=null,v=[],L=0,b=!1;A&&o&&o.getKeys().length===h.length&&(g=o,b=!0),b||(g=new e.Animation(r,A?"_matrix":E,1,_,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var N=0;N<h.length;N++){var M=null;if("rotationQuaternion"===E?(M=e.Quaternion.FromArray([p[L],p[L+1],p[L+2],p[L+3]]),L+=4):(M=e.Vector3.FromArray([p[L],p[L+1],p[L+2]]),L+=3),A){var x=T,O=e.Vector3.Zero(),S=new e.Quaternion,R=e.Vector3.Zero(),F=x.getBaseMatrix();b&&(F=o.getKeys()[N].value),F.decompose(R,S,O),"position"===E?O=M:"rotationQuaternion"===E?S=M:R=M,M=e.Matrix.Compose(R,S,O)}b?o.getKeys()[N].value=M:v.push({frame:h[N],value:M})}b||(g.setKeys(v),T.animations.push(g)),o=g,n.scene.stopAnimation(T),n.scene.beginAnimation(T,0,h[h.length-1],!0,1)}else e.Tools.Warn("Creating animation named "+r+". But cannot find node named "+m+" to attach to")}}},p=function(t){var n=null;if(t.translation||t.rotation||t.scale){var r=e.Vector3.FromArray(t.scale||[1,1,1]),a=e.Quaternion.FromArray(t.rotation||[0,0,0,1]),o=e.Vector3.FromArray(t.translation||[0,0,0]);n=e.Matrix.Compose(r,a,o)}else n=e.Matrix.FromArray(t.matrix);return n},m=function(t,n,r,a){for(var o=0;o<a.bones.length;o++)if(a.bones[o].name===r)return a.bones[o];var i=t.nodes;for(var s in i){var l=i[s];if(l.jointName)for(var u=l.children,o=0;o<u.length;o++){var c=t.nodes[u[o]];if(c.jointName&&c.jointName===r){var f=p(l),d=new e.Bone(l.name,a,m(t,n,l.jointName,a),f);return d.id=s,d}}}return null},T=function(e,t){for(var n=0;n<e.length;n++)for(var r=e[n],a=0;a<r.node.children.length;a++){var o=r.node.children[a];if(o===t)return r.bone}return null},A=function(e,t){var n=e.nodes,r=n[t];if(r)return{node:r,id:t};for(var a in n)if(r=n[a],r.jointName===t)return{node:r,id:a};return null},E=function(e,t){for(var n=0;n<e.jointNames.length;n++)if(e.jointNames[n]===t)return!0;return!1},y=function(t,n,r,a){for(var o in t.nodes){var i=t.nodes[o],s=o;if(i.jointName&&!E(r,i.jointName)){var l=p(i),u=new e.Bone(i.name,n,null,l);u.id=s,a.push({bone:u,node:i,id:s})}}for(var c=0;c<a.length;c++)for(var f=a[c],d=f.node.children,h=0;h<d.length;h++){for(var m=null,T=0;T<a.length;T++)if(a[T].id===d[h]){m=a[T];break}m&&(m.bone._parent=f.bone,f.bone.children.push(m.bone))}},_=function(n,r,a,o,i){if(o||(o=new e.Skeleton(r.name,"",n.scene)),!r.babylonSkeleton)return o;var s=n.accessors[r.inverseBindMatrices],l=(t.GLTFUtils.GetBufferFromAccessor(n,s),e.Matrix.FromArray(r.bindShapeMatrix),[]),u=[];y(n,o,r,l),o.bones=[];for(var c=0;c<r.jointNames.length;c++){var f=A(n,r.jointNames[c]),d=f.node;if(d){var i=f.id,h=n.scene.getBoneByID(i);if(h)o.bones.push(h);else{for(var E=!1,_=null,g=0;g<c;g++){var v=A(n,r.jointNames[g]).node;if(v){var L=v.children;if(L){E=!1;for(var b=0;b<L.length;b++)if(L[b]===i){_=m(n,r,r.jointNames[g],o),E=!0;break}if(E)break}}else e.Tools.Warn("Joint named "+r.jointNames[g]+" does not exist when looking for parent")}var N=p(d);!_&&l.length>0&&(_=T(l,i))&&-1===u.indexOf(_)&&u.push(_);new e.Bone(d.jointName,o,_,N).id=i}}else e.Tools.Warn("Joint named "+r.jointNames[c]+" does not exist")}var M=o.bones;o.bones=[];for(var c=0;c<r.jointNames.length;c++){var f=A(n,r.jointNames[c]);if(f)for(var g=0;g<M.length;g++)if(M[g].id===f.id){o.bones.push(M[g]);break}}o.prepare();for(var c=0;c<u.length;c++)o.bones.push(u[c]);return o},g=function(n,r,a,o,i){if(i||(i=new e.Mesh(r.name,n.scene),i.id=o),!r.babylonNode)return i;var s=new e.MultiMaterial("multimat"+o,n.scene);i.material||(i.material=s);for(var l=new e.VertexData,u=new e.Geometry(o,n.scene,l,!1,i),c=[],d=[],h=[],p=[],m=0;m<a.length;m++){var T=a[m],A=n.meshes[T];if(A)for(var E=0;E<A.primitives.length;E++){var y=new e.VertexData,_=A.primitives[E];_.mode;var g=_.attributes,v=null,L=null;for(var b in g)if(v=n.accessors[g[b]],L=t.GLTFUtils.GetBufferFromAccessor(n,v),"NORMAL"===b)y.normals=new Float32Array(L.length),y.normals.set(L);else if("POSITION"===b){if(e.GLTFFileLoader.HomogeneousCoordinates){y.positions=new Float32Array(L.length-L.length/4);for(var N=0;N<L.length;N+=4)y.positions[N]=L[N],y.positions[N+1]=L[N+1],y.positions[N+2]=L[N+2]}else y.positions=new Float32Array(L.length),y.positions.set(L);d.push(y.positions.length)}else if(-1!==b.indexOf("TEXCOORD_")){var M=Number(b.split("_")[1]),x=e.VertexBuffer.UVKind+(0===M?"":M+1),O=new Float32Array(L.length);O.set(L),f(O),y.set(O,x)}else"JOINT"===b?(y.matricesIndices=new Float32Array(L.length),y.matricesIndices.set(L)):"WEIGHT"===b?(y.matricesWeights=new Float32Array(L.length),y.matricesWeights.set(L)):"COLOR"===b&&(y.colors=new Float32Array(L.length),y.colors.set(L));if(v=n.accessors[_.indices])L=t.GLTFUtils.GetBufferFromAccessor(n,v),y.indices=new Int32Array(L.length),y.indices.set(L),p.push(y.indices.length);else{for(var S=[],N=0;N<y.positions.length/3;N++)S.push(N);y.indices=new Int32Array(S),p.push(y.indices.length)}l.merge(y),y=void 0;var R=n.scene.getMaterialByID(_.material);s.subMaterials.push(null===R?t.GLTFUtils.GetDefaultMaterial(n.scene):R),c.push(0===c.length?0:c[c.length-1]+d[d.length-2]),h.push(0===h.length?0:h[h.length-1]+p[p.length-2])}}u.setAllVerticesData(l,!1),i.computeWorldMatrix(!0),i.subMeshes=[];for(var F=0,m=0;m<a.length;m++){var T=a[m],A=n.meshes[T];if(A)for(var E=0;E<A.primitives.length;E++){A.primitives[E].mode;new e.SubMesh(F,c[F],d[F],h[F],p[F],i,i,!0);F++}}return i},v=function(e,t,n,r){e.position&&(e.position=t),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=n),e.scaling&&(e.scaling=r)},L=function(t,n,r){if(n.matrix){var a=new e.Vector3(0,0,0),o=new e.Quaternion,i=new e.Vector3(0,0,0);e.Matrix.FromArray(n.matrix).decompose(i,o,a),v(t,a,o,i)}else v(t,e.Vector3.FromArray(n.translation),e.Quaternion.FromArray(n.rotation),e.Vector3.FromArray(n.scale));t.computeWorldMatrix(!0)},b=function(t,n,r,a){var o=null;if(t.importOnlyMeshes&&(n.skin||n.meshes)&&t.importMeshesNames.length>0&&-1===t.importMeshesNames.indexOf(n.name))return null;if(n.skin){if(n.meshes){var i=t.skins[n.skin],s=g(t,n,n.meshes,r,n.babylonNode);s.skeleton=t.scene.getLastSkeletonByID(n.skin),null===s.skeleton&&(s.skeleton=_(t,i,0,i.babylonSkeleton,n.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),o=s}}else if(n.meshes){var s=g(t,n,n.mesh?[n.mesh]:n.meshes,r,n.babylonNode);o=s}else if(!n.light||n.babylonNode||t.importOnlyMeshes){if(n.camera&&!n.babylonNode&&!t.importOnlyMeshes){var l=t.cameras[n.camera];if(l)if("orthographic"===l.type){var u=(l[l.type],new e.FreeCamera(n.camera,e.Vector3.Zero(),t.scene));u.name=n.name,u.mode=e.Camera.ORTHOGRAPHIC_CAMERA,u.attachControl(t.scene.getEngine().getRenderingCanvas()),o=u}else if("perspective"===l.type){var c=l[l.type],f=new e.FreeCamera(n.camera,e.Vector3.Zero(),t.scene);f.name=n.name,f.attachControl(t.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(f.maxZ=c.zfar,f.minZ=c.znear),o=f}}}else{var d=t.lights[n.light];if(d)if("ambient"===d.type){var h=d[d.type],p=new e.HemisphericLight(n.light,e.Vector3.Zero(),t.scene);p.name=n.name,h.color&&(p.diffuse=e.Color3.FromArray(h.color)),o=p}else if("directional"===d.type){var m=d[d.type],T=new e.DirectionalLight(n.light,e.Vector3.Zero(),t.scene);T.name=n.name,m.color&&(T.diffuse=e.Color3.FromArray(m.color)),o=T}else if("point"===d.type){var A=d[d.type],E=new e.PointLight(n.light,e.Vector3.Zero(),t.scene);E.name=n.name,A.color&&(E.diffuse=e.Color3.FromArray(A.color)),o=E}else if("spot"===d.type){var y=d[d.type],b=new e.SpotLight(n.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);b.name=n.name,y.color&&(b.diffuse=e.Color3.FromArray(y.color)),y.fallOfAngle&&(b.angle=y.fallOfAngle),y.fallOffExponent&&(b.exponent=y.fallOffExponent),o=b}}if(!n.jointName){if(n.babylonNode)return n.babylonNode;if(null===o){var N=new e.Mesh(n.name,t.scene);n.babylonNode=N,o=N}}if(null!==o){if(n.matrix&&o instanceof e.Mesh)L(o,n);else{var M=n.translation||[0,0,0],x=n.rotation||[0,0,0,1],O=n.scale||[1,1,1];v(o,e.Vector3.FromArray(M),e.Quaternion.FromArray(x),e.Vector3.FromArray(O))}o.updateCache(!0),n.babylonNode=o}return o},N=function(e,t,n,r){var a=e.nodes[t],o=null;if(r=!(e.importOnlyMeshes&&!r)||(-1!==e.importMeshesNames.indexOf(a.name)||0===e.importMeshesNames.length),!a.jointName&&r&&null!==(o=b(e,a,t))&&(o.id=t,o.parent=n),a.children)for(var i=0;i<a.children.length;i++)N(e,a.children[i],o,r)},M=function(e){var t=e.currentScene;if(t)for(var n=0;n<t.nodes.length;n++)N(e,t.nodes[n],null);else for(var r in e.scenes){t=e.scenes[r];for(var n=0;n<t.nodes.length;n++)N(e,t.nodes[n],null)}h(e);for(var n=0;n<e.scene.skeletons.length;n++){var a=e.scene.skeletons[n];e.scene.beginAnimation(a,0,Number.MAX_VALUE,!0,1)}},x=function(e,n,r,a,o,i,s){var l=i.values||o.parameters;for(var u in r){var c=r[u],f=c.type;if(f===t.EParameterType.FLOAT_MAT2||f===t.EParameterType.FLOAT_MAT3||f===t.EParameterType.FLOAT_MAT4)if(!c.semantic||c.source||c.node){if(c.semantic&&(c.source||c.node)){var d=n.scene.getNodeByName(c.source||c.node);if(null===d&&(d=n.scene.getNodeByID(c.source||c.node)),null===d)continue;t.GLTFUtils.SetMatrix(n.scene,d,c,u,a.getEffect())}}else t.GLTFUtils.SetMatrix(n.scene,e,c,u,a.getEffect());else{var h=l[o.uniforms[u]];if(!h)continue;if(f===t.EParameterType.SAMPLER_2D){var p=n.textures[i.values?h:c.value].babylonTexture;if(null===p||void 0===p)continue;a.getEffect().setTexture(u,p)}else t.GLTFUtils.SetUniform(a.getEffect(),u,h,f)}}s(a)},O=function(e,n,r,a,o){var i=a.values||r.parameters,s=r.uniforms;for(var l in o){var u=o[l],c=u.type,f=i[s[l]];if(void 0===f&&(f=u.value),f){var d=function(e){return function(t){u.value&&(n.setTexture(e,t),delete o[e])}};c===t.EParameterType.SAMPLER_2D?t.GLTFLoaderExtension.LoadTextureAsync(e,a.values?f:u.value,d(l),(function(){return d(null)})):u.value&&t.GLTFUtils.SetUniform(n,l,a.values?f:u.value,c)&&delete o[l]}}},S=function(e,t,n){return function(r,a){t.dispose(!0),n("Cannot compile program named "+e.name+". Error: "+a+". Default material will be applied")}},R=function(e,t,n,r,a,o){return function(i){O(e,t,n,r,a),t.onBind=function(i){x(i,e,a,t,n,r,o)}}},F=function(e,t,n){for(var r in t.uniforms){var i=t.uniforms[r],s=t.parameters[i];if(e.currentIdentifier===r&&s.semantic&&!s.source&&!s.node){var l=a.indexOf(s.semantic);if(-1!==l)return delete n[r],o[l]}}return e.currentIdentifier},I=function(e){for(var n in e.materials)t.GLTFLoaderExtension.LoadMaterialAsync(e,n,(function(e){}),(function(){}))},B=(function(){function i(){}return i.CreateRuntime=function(e,t,n){var r={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:t,rootUrl:n,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[]};return e.extensions&&c(e.extensions,"extensions",r),e.extensionsUsed&&c(e.extensionsUsed,"extensionsUsed",r),e.buffers&&l(e.buffers,r),e.bufferViews&&c(e.bufferViews,"bufferViews",r),e.accessors&&c(e.accessors,"accessors",r),e.meshes&&c(e.meshes,"meshes",r),e.lights&&c(e.lights,"lights",r),e.cameras&&c(e.cameras,"cameras",r),e.nodes&&c(e.nodes,"nodes",r),e.images&&c(e.images,"images",r),e.textures&&c(e.textures,"textures",r),e.shaders&&u(e.shaders,r),e.programs&&c(e.programs,"programs",r),e.samplers&&c(e.samplers,"samplers",r),e.techniques&&c(e.techniques,"techniques",r),e.materials&&c(e.materials,"materials",r),e.animations&&c(e.animations,"animations",r),e.skins&&c(e.skins,"skins",r),e.scenes&&(r.scenes=e.scenes),e.scene&&e.scenes&&(r.currentScene=e.scenes[e.scene]),r},i.LoadBufferAsync=function(n,r,a,o,i){var s=n.buffers[r];t.GLTFUtils.IsBase64(s.uri)?setTimeout((function(){return a(new Uint8Array(t.GLTFUtils.DecodeBase64(s.uri)))})):e.Tools.LoadFile(n.rootUrl+s.uri,(function(e){return a(new Uint8Array(e))}),i,null,!0,(function(e){o(e.status+" "+e.statusText)}))},i.LoadTextureBufferAsync=function(n,r,a,o){var i=n.textures[r];if(!i||!i.source)return void o(null);if(i.babylonTexture)return void a(null);var s=n.images[i.source];t.GLTFUtils.IsBase64(s.uri)?setTimeout((function(){return a(new Uint8Array(t.GLTFUtils.DecodeBase64(s.uri)))})):e.Tools.LoadFile(n.rootUrl+s.uri,(function(e){return a(new Uint8Array(e))}),null,null,!0,(function(e){o(e.status+" "+e.statusText)}))},i.CreateTextureAsync=function(n,r,a,o,i){var s=n.textures[r];if(s.babylonTexture)return void o(s.babylonTexture);var l=n.samplers[s.sampler],u=l.minFilter===t.ETextureFilterType.NEAREST_MIPMAP_NEAREST||l.minFilter===t.ETextureFilterType.NEAREST_MIPMAP_LINEAR||l.minFilter===t.ETextureFilterType.LINEAR_MIPMAP_NEAREST||l.minFilter===t.ETextureFilterType.LINEAR_MIPMAP_LINEAR,c=e.Texture.BILINEAR_SAMPLINGMODE,f=new Blob([a]),d=URL.createObjectURL(f),h=function(){return URL.revokeObjectURL(d)},p=new e.Texture(d,n.scene,!u,!0,c,h,h);p.wrapU=t.GLTFUtils.GetWrapMode(l.wrapS),p.wrapV=t.GLTFUtils.GetWrapMode(l.wrapT),p.name=r,s.babylonTexture=p,o(p)},i.LoadShaderStringAsync=function(n,r,a,o){var i=n.shaders[r];if(t.GLTFUtils.IsBase64(i.uri)){a(atob(i.uri.split(",")[1]))}else e.Tools.LoadFile(n.rootUrl+i.uri,a,null,null,!1,(function(e){o(e.status+" "+e.statusText)}))},i.LoadMaterialAsync=function(i,s,l,u){var c=i.materials[s],f=i.techniques[c.technique];if(!f){var h=new e.StandardMaterial(s,i.scene);return h.diffuseColor=new e.Color3(.5,.5,.5),h.sideOrientation=e.Material.CounterClockWiseSideOrientation,void l(h)}
  2. var p=i.programs[f.program],m=f.states,T=e.Effect.ShadersStore[p.vertexShader+"VertexShader"],A=e.Effect.ShadersStore[p.fragmentShader+"PixelShader"],E="",y="",_=new r(T),g=new r(A),v={},L=[],b=[],N=[];for(var M in f.uniforms){var x=f.uniforms[M],O=f.parameters[x];if(v[M]=O,!O.semantic||O.node||O.source)O.type===t.EParameterType.SAMPLER_2D?N.push(M):L.push(M);else{var I=a.indexOf(O.semantic);-1!==I?(L.push(o[I]),delete v[M]):L.push(M)}}for(var B in f.attributes){var P=f.attributes[B],C=f.parameters[P];C.semantic&&b.push(d(C))}for(;!_.isEnd()&&_.getNextToken();){var w=_.currentToken;if(w===n.IDENTIFIER){var D=!1;for(var B in f.attributes){var P=f.attributes[B],C=f.parameters[P];if(_.currentIdentifier===B&&C.semantic){E+=d(C),D=!0;break}}D||(E+=F(_,f,v))}else E+=_.currentString}for(;!g.isEnd()&&g.getNextToken();){var w=g.currentToken;w===n.IDENTIFIER?y+=F(g,f,v):y+=g.currentString}var G={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},U={attributes:b,uniforms:L,samplers:N,needAlphaBlending:m&&m.enable&&-1!==m.enable.indexOf(3042)};e.Effect.ShadersStore[p.vertexShader+s+"VertexShader"]=E,e.Effect.ShadersStore[p.fragmentShader+s+"PixelShader"]=y;var V=new e.ShaderMaterial(s,i.scene,G,U);if(V.onError=S(p,V,u),V.onCompiled=R(i,V,f,c,v,l),V.sideOrientation=e.Material.CounterClockWiseSideOrientation,m&&m.functions){var k=m.functions;k.cullFace&&k.cullFace[0]!==t.ECullingType.BACK&&(V.backFaceCulling=!1);var H=k.blendFuncSeparate;H&&(H[0]===t.EBlendingFunction.SRC_ALPHA&&H[1]===t.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&H[2]===t.EBlendingFunction.ONE&&H[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_COMBINE:H[0]===t.EBlendingFunction.ONE&&H[1]===t.EBlendingFunction.ONE&&H[2]===t.EBlendingFunction.ZERO&&H[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_ONEONE:H[0]===t.EBlendingFunction.SRC_ALPHA&&H[1]===t.EBlendingFunction.ONE&&H[2]===t.EBlendingFunction.ZERO&&H[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_ADD:H[0]===t.EBlendingFunction.ZERO&&H[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&H[2]===t.EBlendingFunction.ONE&&H[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_SUBTRACT:H[0]===t.EBlendingFunction.DST_COLOR&&H[1]===t.EBlendingFunction.ZERO&&H[2]===t.EBlendingFunction.ONE&&H[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_MULTIPLY:H[0]===t.EBlendingFunction.SRC_ALPHA&&H[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&H[2]===t.EBlendingFunction.ONE&&H[3]===t.EBlendingFunction.ONE&&(V.alphaMode=e.Engine.ALPHA_MAXIMIZED))}},i})();t.GLTFLoaderBase=B;var P=(function(){function n(){}return n.RegisterExtension=function(t){if(n.Extensions[t.name])return void e.Tools.Error('Tool with the same name "'+t.name+'" already exists');n.Extensions[t.name]=t},n.prototype.importMeshAsync=function(n,r,a,o,i,s,l){var u=this;r.useRightHandedSystem=!0;t.GLTFLoaderExtension.LoadRuntimeAsync(r,a,o,(function(t){t.importOnlyMeshes=!0,""===n?t.importMeshesNames=[]:"string"==typeof n?t.importMeshesNames=[n]:!n||n instanceof Array?(t.importMeshesNames=[],e.Tools.Warn("Argument meshesNames must be of type string or string[]")):t.importMeshesNames=[n],u._createNodes(t);var r=[],a=[];for(var o in t.nodes){var l=t.nodes[o];l.babylonNode instanceof e.AbstractMesh&&r.push(l.babylonNode)}for(var c in t.skins){var f=t.skins[c];f.babylonSkeleton instanceof e.Skeleton&&a.push(f.babylonSkeleton)}u._loadBuffersAsync(t,(function(){u._loadShadersAsync(t,(function(){I(t),M(t),!e.GLTFFileLoader.IncrementalLoading&&i&&i(r,null,a)}))}),s),e.GLTFFileLoader.IncrementalLoading&&i&&i(r,null,a)}),l);return!0},n.prototype.loadAsync=function(n,r,a,o,i,s){var l=this;n.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(n,r,a,(function(n){t.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(n,(function(){l._createNodes(n),l._loadBuffersAsync(n,(function(){l._loadShadersAsync(n,(function(){I(n),M(n),e.GLTFFileLoader.IncrementalLoading||o()}))})),e.GLTFFileLoader.IncrementalLoading&&o()}),s)}),s)},n.prototype._loadShadersAsync=function(n,r){var a=!1,o=function(a,o){t.GLTFLoaderExtension.LoadShaderStringAsync(n,a,(function(i){n.loadedShaderCount++,i&&(e.Effect.ShadersStore[a+(o.type===t.EShaderType.VERTEX?"VertexShader":"PixelShader")]=i),n.loadedShaderCount===n.shaderscount&&r()}),(function(){e.Tools.Error("Error when loading shader program named "+a+" located at "+o.uri)}))};for(var i in n.shaders){a=!0;var s=n.shaders[i];s?o.bind(this,i,s)():e.Tools.Error("No shader named: "+i)}a||r()},n.prototype._loadBuffersAsync=function(n,r,a){var o=!1,i=function(a,o){t.GLTFLoaderExtension.LoadBufferAsync(n,a,(function(t){n.loadedBufferCount++,t&&(t.byteLength!=n.buffers[a].byteLength&&e.Tools.Error("Buffer named "+a+" is length "+t.byteLength+". Expected: "+o.byteLength),n.loadedBufferViews[a]=t),n.loadedBufferCount===n.buffersCount&&r()}),(function(){e.Tools.Error("Error when loading buffer named "+a+" located at "+o.uri)}))};for(var s in n.buffers){o=!0;var l=n.buffers[s];l?i.bind(this,s,l)():e.Tools.Error("No buffer named: "+s)}o||r()},n.prototype._createNodes=function(e){var t=e.currentScene;if(t)for(var n=0;n<t.nodes.length;n++)N(e,t.nodes[n],null);else for(var r in e.scenes){t=e.scenes[r];for(var n=0;n<t.nodes.length;n++)N(e,t.nodes[n],null)}},n.Extensions={},n})();t.GLTFLoader=P,e.GLTFFileLoader.CreateGLTFLoaderV1=function(){return new P}})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var n=(function(){function n(){}return n.SetMatrix=function(n,r,a,o,i){var s=null;switch("MODEL"===a.semantic?s=r.getWorldMatrix():"PROJECTION"===a.semantic?s=n.getProjectionMatrix():"VIEW"===a.semantic?s=n.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===a.semantic?s=e.Matrix.Transpose(r.getWorldMatrix().multiply(n.getViewMatrix()).invert()):"MODELVIEW"===a.semantic?s=r.getWorldMatrix().multiply(n.getViewMatrix()):"MODELVIEWPROJECTION"===a.semantic?s=r.getWorldMatrix().multiply(n.getTransformMatrix()):"MODELINVERSE"===a.semantic?s=r.getWorldMatrix().invert():"VIEWINVERSE"===a.semantic?s=n.getViewMatrix().invert():"PROJECTIONINVERSE"===a.semantic?s=n.getProjectionMatrix().invert():"MODELVIEWINVERSE"===a.semantic?s=r.getWorldMatrix().multiply(n.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===a.semantic?s=r.getWorldMatrix().multiply(n.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===a.semantic&&(s=e.Matrix.Transpose(r.getWorldMatrix().invert())),a.type){case t.EParameterType.FLOAT_MAT2:i.setMatrix2x2(o,e.Matrix.GetAsMatrix2x2(s));break;case t.EParameterType.FLOAT_MAT3:i.setMatrix3x3(o,e.Matrix.GetAsMatrix3x3(s));break;case t.EParameterType.FLOAT_MAT4:i.setMatrix(o,s)}},n.SetUniform=function(n,r,a,o){switch(o){case t.EParameterType.FLOAT:return n.setFloat(r,a),!0;case t.EParameterType.FLOAT_VEC2:return n.setVector2(r,e.Vector2.FromArray(a)),!0;case t.EParameterType.FLOAT_VEC3:return n.setVector3(r,e.Vector3.FromArray(a)),!0;case t.EParameterType.FLOAT_VEC4:return n.setVector4(r,e.Vector4.FromArray(a)),!0;default:return!1}},n.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},n.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),n=t.length,r=new Uint8Array(new ArrayBuffer(n)),a=0;a<n;a++)r[a]=t.charCodeAt(a);return r.buffer},n.GetWrapMode=function(n){switch(n){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:default:return e.Texture.WRAP_ADDRESSMODE}},n.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}},n.GetTextureFilterMode=function(n){switch(n){case t.ETextureFilterType.LINEAR:case t.ETextureFilterType.LINEAR_MIPMAP_NEAREST:case t.ETextureFilterType.LINEAR_MIPMAP_LINEAR:return e.Texture.TRILINEAR_SAMPLINGMODE;case t.ETextureFilterType.NEAREST:case t.ETextureFilterType.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_SAMPLINGMODE;default:return e.Texture.BILINEAR_SAMPLINGMODE}},n.GetBufferFromBufferView=function(e,n,r,a,o){var r=n.byteOffset+r,i=e.loadedBufferViews[n.buffer];if(r+a>i.byteLength)throw new Error("Buffer access is out of range");var s=i.buffer;switch(r+=i.byteOffset,o){case t.EComponentType.BYTE:return new Int8Array(s,r,a);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,r,a);case t.EComponentType.SHORT:return new Int16Array(s,r,a);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,r,a);default:return new Float32Array(s,r,a)}},n.GetBufferFromAccessor=function(e,t){var r=e.bufferViews[t.bufferView],a=t.count*n.GetByteStrideFromType(t);return n.GetBufferFromBufferView(e,r,t.byteOffset,a,t.componentType)},n.DecodeBufferToText=function(e){for(var t="",n=e.byteLength,r=0;r<n;++r)t+=String.fromCharCode(e[r]);return t},n.GetDefaultMaterial=function(t){if(!n._DefaultMaterial){e.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"),e.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");var r={vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},a={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:[],needAlphaBlending:!1};n._DefaultMaterial=new e.ShaderMaterial("GLTFDefaultMaterial",t,r,a),n._DefaultMaterial.setColor4("u_emission",new e.Color4(.5,.5,.5,1))}return n._DefaultMaterial},n._DefaultMaterial=null,n})();t.GLTFUtils=n})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function t(e){this._name=e}return Object.defineProperty(t.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),t.prototype.loadRuntimeAsync=function(e,t,n,r,a){return!1},t.prototype.loadRuntimeExtensionsAsync=function(e,t,n){return!1},t.prototype.loadBufferAsync=function(e,t,n,r,a){return!1},t.prototype.loadTextureBufferAsync=function(e,t,n,r){return!1},t.prototype.createTextureAsync=function(e,t,n,r,a){return!1},t.prototype.loadShaderStringAsync=function(e,t,n,r){return!1},t.prototype.loadMaterialAsync=function(e,t,n,r){return!1},t.LoadRuntimeAsync=function(n,r,a,o,i){t.ApplyExtensions((function(e){return e.loadRuntimeAsync(n,r,a,o,i)}),(function(){setTimeout((function(){o(e.GLTFLoaderBase.CreateRuntime(r.json,n,a))}))}))},t.LoadRuntimeExtensionsAsync=function(e,n,r){t.ApplyExtensions((function(t){return t.loadRuntimeExtensionsAsync(e,n,r)}),(function(){setTimeout((function(){n()}))}))},t.LoadBufferAsync=function(n,r,a,o,i){t.ApplyExtensions((function(e){return e.loadBufferAsync(n,r,a,o,i)}),(function(){e.GLTFLoaderBase.LoadBufferAsync(n,r,a,o,i)}))},t.LoadTextureAsync=function(e,n,r,a){t.LoadTextureBufferAsync(e,n,(function(o){return t.CreateTextureAsync(e,n,o,r,a)}),a)},t.LoadShaderStringAsync=function(n,r,a,o){t.ApplyExtensions((function(e){return e.loadShaderStringAsync(n,r,a,o)}),(function(){e.GLTFLoaderBase.LoadShaderStringAsync(n,r,a,o)}))},t.LoadMaterialAsync=function(n,r,a,o){t.ApplyExtensions((function(e){return e.loadMaterialAsync(n,r,a,o)}),(function(){e.GLTFLoaderBase.LoadMaterialAsync(n,r,a,o)}))},t.LoadTextureBufferAsync=function(n,r,a,o){t.ApplyExtensions((function(e){return e.loadTextureBufferAsync(n,r,a,o)}),(function(){e.GLTFLoaderBase.LoadTextureBufferAsync(n,r,a,o)}))},t.CreateTextureAsync=function(n,r,a,o,i){t.ApplyExtensions((function(e){return e.createTextureAsync(n,r,a,o,i)}),(function(){e.GLTFLoaderBase.CreateTextureAsync(n,r,a,o,i)}))},t.ApplyExtensions=function(t,n){for(var r in e.GLTFLoader.Extensions){if(t(e.GLTFLoader.Extensions[r]))return}n()},t})();e.GLTFLoaderExtension=t})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t;!(function(e){e[e.JSON=0]="JSON"})(t||(t={}));var n=(function(t){function n(){return t.call(this,"KHR_binary_glTF")||this}return __extends(n,t),n.prototype.loadRuntimeAsync=function(t,n,r,a,o){var i=n.json.extensionsUsed;return!(!i||-1===i.indexOf(this.name))&&(this._bin=n.bin,a(e.GLTFLoaderBase.CreateRuntime(n.json,t,r)),!0)},n.prototype.loadBufferAsync=function(e,t,n,r){return-1!==e.extensionsUsed.indexOf(this.name)&&("binary_glTF"===t&&(n(this._bin),!0))},n.prototype.loadTextureBufferAsync=function(t,n,r,a){var o=t.textures[n],i=t.images[o.source];if(!(i.extensions&&this.name in i.extensions))return!1;var s=i.extensions[this.name],l=t.bufferViews[s.bufferView];return r(e.GLTFUtils.GetBufferFromBufferView(t,l,0,l.byteLength,e.EComponentType.UNSIGNED_BYTE)),!0},n.prototype.loadShaderStringAsync=function(t,n,r,a){var o=t.shaders[n];if(!(o.extensions&&this.name in o.extensions))return!1;var i=o.extensions[this.name],s=t.bufferViews[i.bufferView],l=e.GLTFUtils.GetBufferFromBufferView(t,s,0,s.byteLength,e.EComponentType.UNSIGNED_BYTE);return setTimeout((function(){var t=e.GLTFUtils.DecodeBufferToText(l);r(t)})),!0},n})(e.GLTFLoaderExtension);e.GLTFBinaryExtension=n;!(function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}e.prototype.getUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.getUint8Array=function(e){e||(e=this._arrayBuffer.byteLength-this._byteOffset);var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t}})();e.GLTFLoader.RegisterExtension(new n)})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var n=(function(n){function r(){return n.call(this,"KHR_materials_common")||this}return __extends(r,n),r.prototype.loadRuntimeExtensionsAsync=function(t,n,r){if(!t.extensions)return!1;var a=t.extensions[this.name];if(!a)return!1;var o=a.lights;if(o)for(var i in o){var s=o[i];switch(s.type){case"ambient":var l=new e.HemisphericLight(s.name,new e.Vector3(0,1,0),t.scene),u=s.ambient;l.diffuse=e.Color3.FromArray(u.color||[1,1,1]);break;case"point":var c=new e.PointLight(s.name,new e.Vector3(10,10,10),t.scene),f=s.point;c.diffuse=e.Color3.FromArray(f.color||[1,1,1]);break;case"directional":var d=new e.DirectionalLight(s.name,new e.Vector3(0,-1,0),t.scene),h=s.directional;d.diffuse=e.Color3.FromArray(h.color||[1,1,1]);break;case"spot":var p=s.spot,m=new e.SpotLight(s.name,new e.Vector3(0,10,0),new e.Vector3(0,-1,0),s.spot.fallOffAngle||Math.PI,s.spot.fallOffExponent||0,t.scene);m.diffuse=e.Color3.FromArray(p.color||[1,1,1]);break;default:e.Tools.Warn('GLTF Material Common extension: light type "'+s.type+"” not supported")}}return!1},r.prototype.loadMaterialAsync=function(t,n,r,a){var o=t.materials[n];if(!o||!o.extensions)return!1;var i=o.extensions[this.name];if(!i)return!1;var s=new e.StandardMaterial(n,t.scene);return s.sideOrientation=e.Material.CounterClockWiseSideOrientation,"CONSTANT"===i.technique&&(s.disableLighting=!0),s.backFaceCulling=void 0!==i.doubleSided&&!i.doubleSided,s.alpha=void 0===i.values.transparency?1:i.values.transparency,s.specularPower=void 0===i.values.shininess?0:i.values.shininess,"string"==typeof i.values.ambient?this._loadTexture(t,i.values.ambient,s,"ambientTexture",a):s.ambientColor=e.Color3.FromArray(i.values.ambient||[0,0,0]),"string"==typeof i.values.diffuse?this._loadTexture(t,i.values.diffuse,s,"diffuseTexture",a):s.diffuseColor=e.Color3.FromArray(i.values.diffuse||[0,0,0]),"string"==typeof i.values.emission?this._loadTexture(t,i.values.emission,s,"emissiveTexture",a):s.emissiveColor=e.Color3.FromArray(i.values.emission||[0,0,0]),"string"==typeof i.values.specular?this._loadTexture(t,i.values.specular,s,"specularTexture",a):s.specularColor=e.Color3.FromArray(i.values.specular||[0,0,0]),!0},r.prototype._loadTexture=function(e,n,r,a,o){t.GLTFLoaderBase.LoadTextureBufferAsync(e,n,(function(i){t.GLTFLoaderBase.CreateTextureAsync(e,n,i,(function(e){return r[a]=e}),o)}),o)},r})(t.GLTFLoaderExtension);t.GLTFMaterialsCommonExtension=n,t.GLTFLoader.RegisterExtension(new n)})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT"})(e.EComponentType||(e.EComponentType={}));!(function(e){e[e.POINTS=0]="POINTS",e[e.LINES=1]="LINES",e[e.LINE_LOOP=2]="LINE_LOOP",e[e.LINE_STRIP=3]="LINE_STRIP",e[e.TRIANGLES=4]="TRIANGLES",e[e.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",e[e.TRIANGLE_FAN=6]="TRIANGLE_FAN"})(e.EMeshPrimitiveMode||(e.EMeshPrimitiveMode={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR"})(e.ETextureMagFilter||(e.ETextureMagFilter={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"})(e.ETextureMinFilter||(e.ETextureMinFilter={}));!(function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"})(e.ETextureWrapMode||(e.ETextureWrapMode={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var n=(function(){function n(t){this._renderReady=!1,this._disposed=!1,this._blockPendingTracking=!1,this._renderReadyObservable=new e.Observable,this._renderPendingCount=0,this._loaderPendingCount=0,this._parent=t}return n.RegisterExtension=function(r){if(n.Extensions[r.name])return void e.Tools.Error("Extension with the same name '"+r.name+"' already exists");n.Extensions[r.name]=r,t.GLTFLoaderExtension._Extensions.push(r)},Object.defineProperty(n.prototype,"gltf",{get:function(){return this._gltf},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"babylonScene",{get:function(){return this._babylonScene},enumerable:!0,configurable:!0}),n.prototype.executeWhenRenderReady=function(e){this._renderReady?e():this._renderReadyObservable.add(e)},n.prototype.dispose=function(){this._disposed||(this._disposed=!0,this._gltf.textures&&this._gltf.textures.forEach((function(e){e.url&&URL.revokeObjectURL(e.url)})),this._gltf=void 0,this._babylonScene=void 0,this._rootUrl=void 0,this._defaultMaterial=void 0,this._successCallback=void 0,this._errorCallback=void 0,this._renderReady=!1,this._renderReadyObservable.clear(),this._renderPendingCount=0,this._loaderPendingCount=0)},n.prototype.importMeshAsync=function(e,t,n,r,a,o,i){var s=this;this._loadAsync(e,t,n,r,(function(){a(s._getMeshes(),null,s._getSkeletons())}),o,i)},n.prototype.loadAsync=function(e,t,n,r,a,o){this._loadAsync(null,e,t,n,r,a,o)},n.prototype._loadAsync=function(e,t,n,r,a,o,i){this._loadData(n),this._babylonScene=t,this._rootUrl=r,this._successCallback=a,this._progressCallback=o,this._errorCallback=i,this.addPendingData(this),this._loadScene(e),this._loadAnimations(),this.removePendingData(this)},n.prototype._onError=function(e){this._errorCallback(e),this.dispose()},n.prototype._onProgress=function(e){this._progressCallback(e)},n.prototype._onRenderReady=function(){switch(this._parent.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||this._addRightHandToLeftHandRootTransform();break;case e.GLTFLoaderCoordinateSystemMode.PASS_THROUGH:break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:e.Tools.Error("Invalid coordinate system mode ("+this._parent.coordinateSystemMode+")")}this._showMeshes(),this._startAnimations(),this._successCallback(),this._renderReadyObservable.notifyObservers(this)},n.prototype._onLoaderComplete=function(){this._parent.onComplete&&this._parent.onComplete()},n.prototype._onLoaderFirstLODComplete=function(){this._parent.onFirstLODComplete&&this._parent.onFirstLODComplete()},n.prototype._loadData=function(t){this._gltf=t.json;var n,r=this._gltf.buffers;r&&void 0===r[0].uri&&(n=r[0]),t.bin&&(n?n.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"):e.Tools.Warn("Unexpected BIN chunk"),n.loadedData=t.bin)},n.prototype._addRightHandToLeftHandRootTransform=function(){this._rootMesh=new e.Mesh("root",this._babylonScene),this._rootMesh.isVisible=!1,this._rootMesh.scaling=new e.Vector3(1,1,-1),this._rootMesh.rotation.y=Math.PI;var t=this._gltf.nodes;if(t)for(var n=0;n<t.length;n++){var r=t[n].babylonMesh;r&&!r.parent&&(r.parent=this._rootMesh)}},n.prototype._getMeshes=function(){var e=[];this._rootMesh&&e.push(this._rootMesh);var t=this._gltf.nodes;return t&&t.forEach((function(t){t.babylonMesh&&e.push(t.babylonMesh)})),e},n.prototype._getSkeletons=function(){var t=[],n=this._gltf.skins;return n&&n.forEach((function(n){n.babylonSkeleton instanceof e.Skeleton&&t.push(n.babylonSkeleton)})),t},n.prototype._getAnimationTargets=function(){var e=[],t=this._gltf.animations;return t&&t.forEach((function(t){e.push.apply(e,t.targets)})),e},n.prototype._showMeshes=function(){this._getMeshes().forEach((function(e){return e.isVisible=!0}))},n.prototype._startAnimations=function(){var e=this;this._getAnimationTargets().forEach((function(t){return e._babylonScene.beginAnimation(t,0,Number.MAX_VALUE,!0)}))},n.prototype._loadScene=function(e){var t=this,n=this._gltf.scenes[this._gltf.scene||0],r=n.nodes;this._traverseNodes(r,(function(e,t,n){return e.index=t,e.parent=n,!0}));var a=this._gltf.materials;if(a&&a.forEach((function(e,t){return e.index=t})),e){e instanceof Array||(e=[e]);var o=new Array;this._traverseNodes(r,(function(t){return-1===e.indexOf(t.name)||(o.push(t.index),!1)})),r=o}this._traverseNodes(r,(function(e){return t._loadNode(e)}))},n.prototype._loadNode=function(t){if(t.babylonMesh=new e.Mesh(t.name||"mesh"+t.index,this._babylonScene),t.babylonMesh.isVisible=!1,this._loadTransform(t),void 0!==t.mesh){var n=this._gltf.meshes[t.mesh];this._loadMesh(t,n)}if(t.babylonMesh.parent=t.parent?t.parent.babylonMesh:null,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(t.babylonMesh),void 0!==t.skin){var r=this._gltf.skins[t.skin];r.index=t.skin,t.babylonMesh.skeleton=this._loadSkin(r)}return t.camera,!0},n.prototype._loadMesh=function(n,r){var a=this;n.babylonMesh.name=r.name||n.babylonMesh.name;var o=new e.MultiMaterial(n.babylonMesh.name,this._babylonScene);n.babylonMesh.material=o;var i=new e.Geometry(n.babylonMesh.name,this._babylonScene,null,!1,n.babylonMesh),s=new e.VertexData;s.positions=[],s.indices=[];for(var l=[],u=0,c=r.primitives.length,f=this,d=0;d<c;d++)!(function(d){var h=r.primitives[d];if(h.mode&&h.mode!==t.EMeshPrimitiveMode.TRIANGLES)throw new Error("Not implemented");f._createMorphTargets(n,r,h,n.babylonMesh),f._loadVertexDataAsync(h,(function(t){a._loadMorphTargetsData(r,h,t,n.babylonMesh),l.push({materialIndex:d,verticesStart:s.positions.length,verticesCount:t.positions.length,indicesStart:s.indices.length,indicesCount:t.indices.length,loadMaterial:function(){if(void 0===h.material)o.subMaterials[d]=a._getDefaultMaterial();else{var e=a._gltf.materials[h.material];a.loadMaterial(e,(function(t,r){r&&a._parent.onMaterialLoaded&&a._parent.onMaterialLoaded(t),a._parent.onBeforeMaterialReadyAsync?(a.addLoaderPendingData(e),a._parent.onBeforeMaterialReadyAsync(t,n.babylonMesh,null!=o.subMaterials[d],(function(){o.subMaterials[d]=t,a.removeLoaderPendingData(e)}))):o.subMaterials[d]=t}))}}}),s.merge(t),++u===c&&(i.setAllVerticesData(s,!1),l.forEach((function(e){return e.loadMaterial()})),n.babylonMesh.subMeshes=[],l.forEach((function(t){return new e.SubMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indicesStart,t.indicesCount,n.babylonMesh)})))}))})(d)},n.prototype._loadVertexDataAsync=function(t,n){var r=this,a=t.attributes;if(!a)return void this._onError("Primitive has no attributes");var o,i=new e.VertexData,s=0,l=Object.keys(a).length,u=this;for(var c in a)!(function(c){o=u._gltf.accessors[a[c]],u._loadAccessorAsync(o,(function(a){switch(c){case"NORMAL":i.normals=a;break;case"POSITION":i.positions=a;break;case"TANGENT":i.tangents=a;break;case"TEXCOORD_0":i.uvs=a;break;case"TEXCOORD_1":i.uvs2=a;break;case"JOINTS_0":i.matricesIndices=new Float32Array(Array.prototype.slice.apply(a));break;case"WEIGHTS_0":i.matricesWeights=a;break;case"COLOR_0":i.colors=a;break;default:e.Tools.Warn("Ignoring unrecognized semantic '"+c+"'")}if(++s===l){var o=r._gltf.accessors[t.indices];o?r._loadAccessorAsync(o,(function(e){i.indices=e,n(i)})):(i.indices=new Uint32Array(i.positions.length/3),i.indices.forEach((function(e,t){return i.indices[t]=t})),n(i))}}))})(c)},n.prototype._createMorphTargets=function(t,n,r,a){var o=r.targets;if(o){a.morphTargetManager||(a.morphTargetManager=new e.MorphTargetManager);for(var i=0;i<o.length;i++){var s=t.weights?t.weights[i]:n.weights?n.weights[i]:0;a.morphTargetManager.addTarget(new e.MorphTarget("morphTarget"+i,s))}}},n.prototype._loadMorphTargetsData=function(n,r,a,o){var i=r.targets;if(i)for(var s,l,u=this,c=0;c<i.length;c++)!(function(){var n=o.morphTargetManager.getTarget(c);s=i[c];for(var r in s)!(function(r){l=u._gltf.accessors[s[r]],u._loadAccessorAsync(l,(function(o){l.name&&(n.name=l.name);var i=o;switch(r){case"NORMAL":t.GLTFUtils.ForEach(i,(function(e,t){return i[t]+=a.normals[t]})),n.setNormals(i);break;case"POSITION":t.GLTFUtils.ForEach(i,(function(e,t){return i[t]+=a.positions[t]})),n.setPositions(i);break;case"TANGENT":for(var s=0,u=0;s<i.length;s++,u++)i[s]+=a.tangents[u],(s+1)%3==0&&u++;n.setTangents(i);break;default:e.Tools.Warn("Ignoring unrecognized semantic '"+r+"'")}}))})(r)})()},n.prototype._loadTransform=function(t){var n=e.Vector3.Zero(),r=e.Quaternion.Identity(),a=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(a,r,n)}else t.translation&&(n=e.Vector3.FromArray(t.translation)),t.rotation&&(r=e.Quaternion.FromArray(t.rotation)),t.scale&&(a=e.Vector3.FromArray(t.scale));t.babylonMesh.position=n,t.babylonMesh.rotationQuaternion=r,t.babylonMesh.scaling=a},n.prototype._loadSkin=function(t){var n=this,r="skeleton"+t.index;if(t.babylonSkeleton=new e.Skeleton(t.name||r,r,this._babylonScene),void 0===t.inverseBindMatrices)this._loadBones(t,null);else{var a=this._gltf.accessors[t.inverseBindMatrices];this._loadAccessorAsync(a,(function(e){n._loadBones(t,e)}))}return t.babylonSkeleton},n.prototype._createBone=function(t,n,r,a,o,i){var s=new e.Bone(t.name||"bone"+t.index,n.babylonSkeleton,r,a,null,o,i);return t.babylonBones=t.babylonBones||{},t.babylonBones[n.index]=s,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(s),s},n.prototype._loadBones=function(e,t){for(var n={},r=0;r<e.joints.length;r++){var a=this._gltf.nodes[e.joints[r]];this._loadBone(a,e,t,n)}},n.prototype._loadBone=function(t,n,r,a){var o=a[t.index];if(o)return o;var i=n.joints.indexOf(t.index),s=e.Matrix.Identity();r&&-1!==i&&(s=e.Matrix.FromArray(r,16*i),s.invertToRef(s));var l;return t.index!=n.skeleton&&t.parent&&(l=this._loadBone(t.parent,n,r,a),s.multiplyToRef(l.getInvertedAbsoluteTransform(),s)),o=this._createBone(t,n,l,this._getNodeMatrix(t),s,i),a[t.index]=o,o},n.prototype._getNodeMatrix=function(t){return t.matrix?e.Matrix.FromArray(t.matrix):e.Matrix.Compose(t.scale?e.Vector3.FromArray(t.scale):e.Vector3.One(),t.rotation?e.Quaternion.FromArray(t.rotation):e.Quaternion.Identity(),t.translation?e.Vector3.FromArray(t.translation):e.Vector3.Zero())},n.prototype._traverseNodes=function(e,t,n){void 0===n&&(n=null);for(var r=0;r<e.length;r++)this._traverseNode(e[r],t,n)},n.prototype._traverseNode=function(e,t,n){void 0===n&&(n=null);var r=this._gltf.nodes[e];if(t(r,e,n)&&r.children)for(var a=0;a<r.children.length;a++)this._traverseNode(r.children[a],t,r)},n.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e&&0!==e.length)for(var t=0;t<e.length;t++)for(var n=e[t],r=0;r<n.channels.length;r++)this._loadAnimationChannel(n,t,r)},n.prototype._loadAnimationChannel=function(t,n,r){var a=t.channels[r],o=a.sampler,i=t.samplers[o],s=this._gltf.nodes[a.target.node];if(!s)return void e.Tools.Warn("Animation channel target node ("+a.target.node+") does not exist");var l={translation:"position",rotation:"rotationQuaternion",scale:"scaling",weights:"influence"}[a.target.path];if(!l)return void e.Tools.Warn("Animation channel target path '"+a.target.path+"' is not valid");var u,c,f={position:e.Animation.ANIMATIONTYPE_VECTOR3,rotationQuaternion:e.Animation.ANIMATIONTYPE_QUATERNION,scaling:e.Animation.ANIMATIONTYPE_VECTOR3,influence:e.Animation.ANIMATIONTYPE_FLOAT}[l],d=function(){if(u&&c){for(var r=0,a={position:function(){var t=e.Vector3.FromArray(c,r);return r+=3,t},rotationQuaternion:function(){var t=e.Quaternion.FromArray(c,r);return r+=4,t},scaling:function(){var t=e.Vector3.FromArray(c,r);return r+=3,t},influence:function(){for(var e=s.babylonMesh.morphTargetManager.numTargets,t=new Array(e),n=0;n<e;n++)t[n]=c[r++];return t}}[l],o={LINEAR:function(e){return{frame:u[e],value:a()}},CUBICSPLINE:function(e){return{frame:u[e],inTangent:a(),value:a(),outTangent:a()}}}[i.interpolation],d=new Array(u.length),h=0;h<u.length;h++)d[h]=o(h);if(t.targets=t.targets||[],"influence"===l)for(var p=s.babylonMesh.morphTargetManager,m=0;m<p.numTargets;m++){var T=p.getTarget(m),A=(t.name||"anim"+n)+"_"+m,E=new e.Animation(A,l,1,f);E.setKeys(d.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[m]:void 0,value:e.value[m],outTangent:e.outTangent?e.outTangent[m]:void 0}}))),T.animations.push(E),t.targets.push(T)}else{var A=t.name||"anim"+n,E=new e.Animation(A,l,1,f);E.setKeys(d);for(var y=0;y<s.babylonAnimationTargets.length;y++){var _=s.babylonAnimationTargets[y];_.animations.push(E.clone()),t.targets.push(_)}}}};this._loadAccessorAsync(this._gltf.accessors[i.input],(function(e){u=e,d()})),this._loadAccessorAsync(this._gltf.accessors[i.output],(function(e){c=e,d()}))},n.prototype._loadBufferAsync=function(n,r){var a=this,o=this._gltf.buffers[n];if(this.addPendingData(o),o.loadedData)setTimeout((function(){r(o.loadedData),a.removePendingData(o)}));else if(t.GLTFUtils.IsBase64(o.uri)){var i=t.GLTFUtils.DecodeBase64(o.uri);o.loadedData=new Uint8Array(i),setTimeout((function(){r(o.loadedData),a.removePendingData(o)}))}else o.loadedObservable?o.loadedObservable.add((function(e){r(e.loadedData),a.removePendingData(e)})):(o.loadedObservable=new e.Observable,o.loadedObservable.add((function(e){r(e.loadedData),a.removePendingData(e)})),e.Tools.LoadFile(this._rootUrl+o.uri,(function(e){o.loadedData=new Uint8Array(e),o.loadedObservable.notifyObservers(o),o.loadedObservable=null}),(function(e){a._disposed||a._onProgress(e)}),this._babylonScene.database,!0,(function(e){a._disposed||(a._onError("Failed to load file '"+o.uri+"': "+e.status+" "+e.statusText),a.removePendingData(o))})))},n.prototype._buildInt8ArrayBuffer=function(e,t,n,r,a){if(!r)return new Int8Array(e,t,n);var o=new Int8Array(e,t),i=new Int8Array(n);return this._extractInterleavedData(o,i,a,r,i.length),i},n.prototype._buildUint8ArrayBuffer=function(e,t,n,r,a){if(!r)return new Uint8Array(e,t,n);var o=new Uint8Array(e,t),i=new Uint8Array(n);return this._extractInterleavedData(o,i,a,r,i.length),i},n.prototype._buildInt16ArrayBuffer=function(e,t,n,r,a){if(!r)return new Int16Array(e,t,n);var o=new Int16Array(e,t),i=new Int16Array(n);return this._extractInterleavedData(o,i,a,r/2,i.length),i},n.prototype._buildUint16ArrayBuffer=function(e,t,n,r,a){if(!r)return new Uint16Array(e,t,n);var o=new Uint16Array(e,t),i=new Uint16Array(n);return this._extractInterleavedData(o,i,a,r/2,i.length),i},n.prototype._buildUint32ArrayBuffer=function(e,t,n,r,a){if(!r)return new Uint32Array(e,t,n);var o=new Uint32Array(e,t),i=new Uint32Array(n);return this._extractInterleavedData(o,i,a,r/4,i.length),i},n.prototype._buildFloat32ArrayBuffer=function(e,t,n,r,a){if(!r)return new Float32Array(e,t,n)
  3. ;var o=new Float32Array(e,t),i=new Float32Array(n);return this._extractInterleavedData(o,i,a,r/4,i.length),i},n.prototype._extractInterleavedData=function(e,t,n,r,a){for(var o=0,i=0,s=n;o<a;){for(var l=0;l<s;l++)t[o]=e[i+l],o++;i+=r}},n.prototype._loadBufferViewAsync=function(e,n,r,a,o,i){var s=this;n+=e.byteOffset||0,this._loadBufferAsync(e.buffer,(function(l){if(n+r>l.byteLength)return void s._onError("Buffer access is out of range");var u=l.buffer;n+=l.byteOffset;var c;switch(o){case t.EComponentType.BYTE:c=s._buildInt8ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_BYTE:c=s._buildUint8ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.SHORT:c=s._buildInt16ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_SHORT:c=s._buildUint16ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_INT:c=s._buildUint32ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.FLOAT:c=s._buildFloat32ArrayBuffer(u,n,r,e.byteStride,a);break;default:return void s._onError("Invalid component type ("+o+")")}i(c)}))},n.prototype._loadAccessorAsync=function(e,t){var n=this._gltf.bufferViews[e.bufferView],r=e.byteOffset||0,a=this._getByteStrideFromType(e),o=e.count*a;this._loadBufferViewAsync(n,r,o,a,e.componentType,t)},n.prototype._getByteStrideFromType=function(e){switch(e.type){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return this._onError("Invalid accessor type ("+e.type+")"),0}},Object.defineProperty(n.prototype,"blockPendingTracking",{set:function(e){this._blockPendingTracking=e},enumerable:!0,configurable:!0}),n.prototype.addPendingData=function(e){this._renderReady||this._renderPendingCount++,this.addLoaderPendingData(e)},n.prototype.removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._onRenderReady()),this.removeLoaderPendingData(e)},n.prototype.addLoaderNonBlockingPendingData=function(e){this._nonBlockingData||(this._nonBlockingData=new Array),this._nonBlockingData.push(e)},n.prototype.addLoaderPendingData=function(e){if(this._blockPendingTracking)return void this.addLoaderNonBlockingPendingData(e);this._loaderPendingCount++},n.prototype.removeLoaderPendingData=function(e){var t=this._nonBlockingData?this._nonBlockingData.indexOf(e):-1;-1!==t?this._nonBlockingData.splice(t,1):0==--this._loaderPendingCount&&this._onLoaderFirstLODComplete(),this._nonBlockingData&&0!==this._nonBlockingData.length||0!==this._loaderPendingCount||(this._onLoaderComplete(),this.dispose())},n.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",n=this._babylonScene.getMaterialByName(t);n||(n=new e.PBRMaterial(t,this._babylonScene),n.sideOrientation=e.Material.CounterClockWiseSideOrientation,n.metallic=1,n.roughness=1),this._defaultMaterial=n}return this._defaultMaterial},n.prototype._loadMaterialMetallicRoughnessProperties=function(t){var n=t.babylonMaterial;n.metallic=1,n.roughness=1;var r=t.pbrMetallicRoughness;r&&(n.albedoColor=r.baseColorFactor?e.Color3.FromArray(r.baseColorFactor):new e.Color3(1,1,1),n.metallic=void 0===r.metallicFactor?1:r.metallicFactor,n.roughness=void 0===r.roughnessFactor?1:r.roughnessFactor,r.baseColorTexture&&(n.albedoTexture=this.loadTexture(r.baseColorTexture)),r.metallicRoughnessTexture&&(n.metallicTexture=this.loadTexture(r.metallicRoughnessTexture),n.useMetallnessFromMetallicTextureBlue=!0,n.useRoughnessFromMetallicTextureGreen=!0,n.useRoughnessFromMetallicTextureAlpha=!1),this.loadMaterialAlphaProperties(t,r.baseColorFactor))},n.prototype.loadMaterial=function(e,n){if(e.babylonMaterial)return void n(e.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,n)||(this.createPbrMaterial(e),this.loadMaterialBaseProperties(e),this._loadMaterialMetallicRoughnessProperties(e),n(e.babylonMaterial,!0))},n.prototype.createPbrMaterial=function(t){var n=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);n.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=n},n.prototype.loadMaterialBaseProperties=function(t){var n=t.babylonMaterial;n.emissiveColor=t.emissiveFactor?e.Color3.FromArray(t.emissiveFactor):new e.Color3(0,0,0),t.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),t.normalTexture&&(n.bumpTexture=this.loadTexture(t.normalTexture),n.invertNormalMapX=!this._babylonScene.useRightHandedSystem,n.invertNormalMapY=this._babylonScene.useRightHandedSystem,void 0!==t.normalTexture.scale&&(n.bumpTexture.level=t.normalTexture.scale)),t.occlusionTexture&&(n.ambientTexture=this.loadTexture(t.occlusionTexture),n.useAmbientInGrayScale=!0,void 0!==t.occlusionTexture.strength&&(n.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&(n.emissiveTexture=this.loadTexture(t.emissiveTexture))},n.prototype.loadMaterialAlphaProperties=function(t,n){var r=t.babylonMaterial,a=t.alphaMode||"OPAQUE";switch(a){case"OPAQUE":break;case"MASK":case"BLEND":n&&(r.alpha=n[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture="BLEND"===a);break;default:e.Tools.Warn("Invalid alpha mode '"+t.alphaMode+"'")}r.alphaCutOff=void 0===t.alphaCutoff?.5:t.alphaCutoff},n.prototype.loadTexture=function(n){var r=this,a=this._gltf.textures[n.index],o=n.texCoord||0;if(!a||void 0===a.source)return null;var i=this._gltf.images[a.source],s=void 0===a.sampler?{}:this._gltf.samplers[a.sampler],l=s.minFilter===t.ETextureMinFilter.NEAREST||s.minFilter===t.ETextureMinFilter.LINEAR,u=t.GLTFUtils.GetTextureSamplingMode(s.magFilter,s.minFilter);this.addPendingData(a);var c=new e.Texture(null,this._babylonScene,l,!1,u,function(){r._disposed||r.removePendingData(a)},function(){r._disposed||(r._onError("Failed to load texture '"+i.uri+"'"),r.removePendingData(a))});if(a.url)c.updateURL(a.url);else if(a.dataReadyObservable)a.dataReadyObservable.add((function(e){c.updateURL(e.url)}));else{a.dataReadyObservable=new e.Observable,a.dataReadyObservable.add((function(e){c.updateURL(e.url)}));var f=function(e){a.url=URL.createObjectURL(new Blob([e],{type:i.mimeType})),a.dataReadyObservable.notifyObservers(a)};if(i.uri)t.GLTFUtils.IsBase64(i.uri)?f(new Uint8Array(t.GLTFUtils.DecodeBase64(i.uri))):e.Tools.LoadFile(this._rootUrl+i.uri,f,(function(e){r._disposed||r._onProgress(e)}),this._babylonScene.database,!0,(function(e){r._onError("Failed to load file '"+i.uri+"': "+e.status+" "+e.statusText)}));else{var d=this._gltf.bufferViews[i.bufferView];this._loadBufferViewAsync(d,0,d.byteLength,1,t.EComponentType.UNSIGNED_BYTE,f)}}return c.coordinatesIndex=o,c.wrapU=t.GLTFUtils.GetTextureWrapMode(s.wrapS),c.wrapV=t.GLTFUtils.GetTextureWrapMode(s.wrapT),c.name=a.name||"texture"+n.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(c),c},n.Extensions={},n})();t.GLTFLoader=n,e.GLTFFileLoader.CreateGLTFLoaderV2=function(e){return new n(e)}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var n=(function(){function n(){}return n.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},n.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),n=t.length,r=new Uint8Array(new ArrayBuffer(n)),a=0;a<n;a++)r[a]=t.charCodeAt(a);return r.buffer},n.ForEach=function(e,t){for(var n=0;n<e.length;n++)t(e[n],n)},n.GetTextureWrapMode=function(n){switch(n=void 0===n?t.ETextureWrapMode.REPEAT:n){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:return e.Texture.WRAP_ADDRESSMODE;default:return e.Tools.Warn("Invalid texture wrap mode ("+n+")"),e.Texture.WRAP_ADDRESSMODE}},n.GetTextureSamplingMode=function(n,r){if(n=void 0===n?t.ETextureMagFilter.LINEAR:n,r=void 0===r?t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:r,n===t.ETextureMagFilter.LINEAR)switch(r){case t.ETextureMinFilter.NEAREST:return e.Texture.LINEAR_NEAREST;case t.ETextureMinFilter.LINEAR:return e.Texture.LINEAR_LINEAR;case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.LINEAR_NEAREST_MIPNEAREST;case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return e.Texture.LINEAR_LINEAR_MIPNEAREST;case t.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return e.Texture.LINEAR_NEAREST_MIPLINEAR;case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.LINEAR_LINEAR_MIPLINEAR;default:return e.Tools.Warn("Invalid texture minification filter ("+r+")"),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(n!==t.ETextureMagFilter.NEAREST&&e.Tools.Warn("Invalid texture magnification filter ("+n+")"),r){case t.ETextureMinFilter.NEAREST:return e.Texture.NEAREST_NEAREST;case t.ETextureMinFilter.LINEAR:return e.Texture.NEAREST_LINEAR;case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_NEAREST_MIPNEAREST;case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return e.Texture.NEAREST_LINEAR_MIPNEAREST;case t.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return e.Texture.NEAREST_NEAREST_MIPLINEAR;case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.NEAREST_LINEAR_MIPLINEAR;default:return e.Tools.Warn("Invalid texture minification filter ("+r+")"),e.Texture.NEAREST_NEAREST_MIPNEAREST}},n.DecodeBufferToText=function(e){for(var t="",n=e.byteLength,r=0;r<n;++r)t+=String.fromCharCode(e[r]);return t},n})();t.GLTFUtils=n})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(){this.enabled=!0}return e.prototype.loadMaterial=function(e,t,n){return!1},e.LoadMaterial=function(e,t,n){return this._ApplyExtensions((function(r){return r.loadMaterial(e,t,n)}))},e._ApplyExtensions=function(t){var n=e._Extensions;if(n){for(var r=0;r<n.length;r++){var a=n[r];if(a.enabled&&t(a))return!0}return!1}},e._Extensions=[],e})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(n){var r=(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),Object.defineProperty(n.prototype,"name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),n.prototype.loadMaterial=function(e,t,n){if(!t.extensions)return!1;var r=t.extensions[this.name];if(!r)return!1;t.extensions[this.name]=void 0;var a=[t.index].concat(r.ids);e.addLoaderPendingData(t);for(var o=0;o<a.length;o++)e.addLoaderNonBlockingPendingData(o);return this.loadMaterialLOD(e,t,a,a.length-1,n),!0},n.prototype.loadMaterialLOD=function(t,r,a,o,i){var s=this,l=t.gltf.materials[a[o]];o!==a.length-1&&(t.blockPendingTracking=!0),t.loadMaterial(l,(function(l,u){if(i(l,u),t.removeLoaderPendingData(o),o===a.length-1&&t.removeLoaderPendingData(r),0===o)return void(t.blockPendingTracking=!1);t.executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(l.getActiveTextures(),(function(){setTimeout((function(){s.loadMaterialLOD(t,r,a,o-1,i)}),n.MinimalLODDelay)}))}))}))},n.MinimalLODDelay=250,n})(t.GLTFLoaderExtension);n.MSFTLOD=r,t.GLTFLoader.RegisterExtension(new r)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(n){var r=(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),Object.defineProperty(n.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),n.prototype.loadMaterial=function(e,t,n){if(!t.extensions)return!1;var r=t.extensions[this.name];return!!r&&(e.createPbrMaterial(t),e.loadMaterialBaseProperties(t),this._loadSpecularGlossinessProperties(e,t,r),n(t.babylonMaterial,!0),!0)},n.prototype._loadSpecularGlossinessProperties=function(t,n,r){var a=n.babylonMaterial;a.albedoColor=r.diffuseFactor?e.Color3.FromArray(r.diffuseFactor):new e.Color3(1,1,1),a.reflectivityColor=r.specularFactor?e.Color3.FromArray(r.specularFactor):new e.Color3(1,1,1),a.microSurface=void 0===r.glossinessFactor?1:r.glossinessFactor,r.diffuseTexture&&(a.albedoTexture=t.loadTexture(r.diffuseTexture)),r.specularGlossinessTexture&&(a.reflectivityTexture=t.loadTexture(r.specularGlossinessTexture),a.reflectivityTexture.hasAlpha=!0,a.useMicroSurfaceFromReflectivityMapAlpha=!0),t.loadMaterialAlphaProperties(n,r.diffuseFactor)},n})(t.GLTFLoaderExtension);n.KHRMaterialsPbrSpecularGlossiness=r,t.GLTFLoader.RegisterExtension(new r)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={})),(function(e,t){e&&e.BABYLON||("object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.BJSLoaders=t():e.BABYLON=t())})(this,(function(){return BABYLON}));