123 |
- var BABYLON=BABYLON||"undefined"!=typeof require&&require("babylonjs"),__decorate=this&&this.__decorate||function(e,t,r,n){var a,o=arguments.length,i=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,r,i):a(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,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 r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),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,r,n,a,o,i,s){var u;if(this.isBinary(n)){var l=new e.Mesh("stlmesh",r);return this.parseBinary(l,n),o&&o.push(l),!0}for(var c=new Uint8Array(n),f="",d=0;d<n.byteLength;d++)f+=String.fromCharCode(c[d]);for(n=f;u=this.solidPattern.exec(n);){var h=u[1];if(h!=u[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 l=new e.Mesh(h,r);this.parseASCII(l,u[2]),o&&o.push(l)}return!0},t.prototype.load=function(e,t,r){var n=this.importMesh(null,e,t,r,null,null,null);return n&&e.createDefaultCameraOrLight(),n},t.prototype.isBinary=function(e){var t,r;if(r=new DataView(e),t=50,84+r.getUint32(80,!0)*t===r.byteLength)return!0;for(var n=r.byteLength,a=0;a<n;a++)if(r.getUint8(a,!1)>127)return!0;return!1},t.prototype.parseBinary=function(t,r){for(var n=new DataView(r),a=n.getUint32(80,!0),o=0,i=new Float32Array(3*a*3),s=new Float32Array(3*a*3),u=new Uint32Array(3*a),l=0,c=0;c<a;c++){for(var f=84+50*c,d=n.getFloat32(f,!0),h=n.getFloat32(f+4,!0),p=n.getFloat32(f+8,!0),m=1;m<=3;m++){var _=f+12*m;i[o]=n.getFloat32(_,!0),i[o+2]=n.getFloat32(_+4,!0),i[o+1]=n.getFloat32(_+8,!0),s[o]=d,s[o+2]=h,s[o+1]=p,o+=3}u[l]=l++,u[l]=l++,u[l]=l++}t.setVerticesData(e.VertexBuffer.PositionKind,i),t.setVerticesData(e.VertexBuffer.NormalKind,s),t.setIndices(u),t.computeWorldMatrix(!0)},t.prototype.parseASCII=function(t,r){for(var n,a=[],o=[],i=[],s=0;n=this.facetsPattern.exec(r);){var u=n[1],l=this.normalPattern.exec(u);if(this.normalPattern.lastIndex=0,l){for(var c,f=[Number(l[1]),Number(l[5]),Number(l[3])];c=this.vertexPattern.exec(u);)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(r,n,a){for(var o,i,s=n.split("\n"),u=0;u<s.length;u++){var l=s[u].trim();if(0!==l.length&&"#"!==l.charAt(0)){var c=l.indexOf(" "),f=c>=0?l.substring(0,c):l;f=f.toLowerCase();var d=c>=0?l.substring(c+1).trim():"";"newmtl"===f?(i&&this.materials.push(i),i=new e.StandardMaterial(d,r)):"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,r):"map_kd"===f?i.diffuseTexture=t._getTexture(a,d,r):"map_ks"===f?i.specularTexture=t._getTexture(a,d,r):"map_ns"===f||("map_bump"===f?i.bumpTexture=t._getTexture(a,d,r):"map_d"===f&&(i.opacityTexture=t._getTexture(a,d,r)))}}this.materials.push(i)}}return t._getTexture=function(t,r,n){if(!r)return null;var a=t;if("file:"===t){var o=r.lastIndexOf("\\");-1===o&&(o=r.lastIndexOf("/")),a+=o>-1?r.substr(o+1):r}else a+=r;return new e.Texture(a,n)},t})();e.MTLFileLoader=t;var r=(function(){function r(){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 r.prototype._loadMTL=function(t,r,n){var a=e.Tools.BaseUrl+r+t;e.Tools.LoadFile(a,n,null,null,!1,(function(){console.warn("Error - Unable to load "+a)}))},r.prototype.importMesh=function(e,t,r,n,a,o,i){var s=this._parseSolid(e,t,r,n);return a&&s.forEach((function(e){a.push(e)})),!0},r.prototype.load=function(e,t,r){return this.importMesh(null,e,t,r,null,null,null)},r.prototype._parseSolid=function(n,a,o,i){for(var s,u=[],l=[],c=[],f=[],d=[],h=[],p=[],m=[],_=[],T=0,A=!1,E=[],y=[],g=[],v=[],L="",N="",b=new t,x=1,M=!0,O=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[]});var r=e[t[0]].normals.indexOf(t[1]);return-1===r?-1:e[t[0]].idx[r]},S=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[],uv:[]});var r=e[t[0]].normals.indexOf(t[1]);return 1!=r&&t[2]==e[t[0]].uv[r]?e[t[0]].idx[r]:-1},I=function(e,t,n,a,o,i){var s;s=r.OPTIMIZE_WITH_UV?S(_,[e,n,t]):O(_,[e,n]),-1==s?(d.push(h.length),h.push(a),p.push(o),m.push(i),_[e].normals.push(n),_[e].idx.push(T++),r.OPTIMIZE_WITH_UV&&_[e].uv.push(t)):d.push(s)},R=function(){for(var e=0;e<h.length;e++)E.push(h[e].x,h[e].y,h[e].z),y.push(m[e].x,m[e].y,m[e].z),g.push(p[e].x,p[e].y);h=[],m=[],p=[],_=[],T=0},F=function(e,t){t+1<e.length&&(v.push(e[0],e[t],e[t+1]),t+=1,F(e,t))},B=function(){f.length>0&&(s=f[f.length-1],R(),d.reverse(),s.indices=d.slice(),s.positions=E.slice(),s.normals=y.slice(),s.uvs=g.slice(),d=[],E=[],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)))u.push(new e.Vector3(parseFloat(w[1]),parseFloat(w[2]),parseFloat(w[3])));else if(null!==(w=this.normalPattern.exec(D)))l.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){F(e,t);for(var r=0;r<v.length;r++){var n=v[r].split("/"),a=parseInt(n[0])-1,o=parseInt(n[1])-1,i=parseInt(n[2])-1;I(a,o,i,u[a],c[o],l[i])}v=[]})(w[1].trim().split(" "),1);else if(null!==(w=this.facePattern4.exec(D)))!(function(t,r){F(t,r);for(var n=0;n<v.length;n++){var a=v[n].split("//"),o=parseInt(a[0])-1,i=parseInt(a[1])-1;I(o,1,i,u[o],e.Vector2.Zero(),l[i])}v=[]})(w[1].trim().split(" "),1);else if(null!==(w=this.facePattern2.exec(D)))!(function(t,r){F(t,r);for(var n=0;n<v.length;n++){var a=v[n].split("/"),o=parseInt(a[0])-1,i=parseInt(a[1])-1;I(o,i,0,u[o],c[i],e.Vector3.Up())}v=[]})(w[1].trim().split(" "),1);else if(null!==(w=this.facePattern1.exec(D)))!(function(t,r){F(t,r);for(var n=0;n<v.length;n++){var a=parseInt(v[n])-1;I(a,0,0,u[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),A=!0,M=!0,x=1}else if(this.usemtl.test(D)){if(L=D.substring(7).trim(),!M){B();var G={name:"_mm"+x.toString(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:L};x++,f.push(G)}A&&M&&(f[f.length-1].materialName=L,M=!1)}else this.mtllib.test(D)?N=D.substring(7).trim():this.smooth.test(D)||console.log("Unhandled expression at line : "+D)}A&&(s=f[f.length-1],d.reverse(),R(),s.indices=d,s.positions=E,s.normals=y,s.uvs=g),A||(d.reverse(),R(),f.push({name:e.Geometry.RandomId(),indices:d,positions:E,normals:y,uvs:g,materialName:L}));for(var U=[],V=[],k=0;k<f.length;k++){if(n&&f[k].name)if(n instanceof Array){if(-1==n.indexOf(f[k].name))continue}else if(f[k].name!==n)continue;s=f[k];var H=new e.Mesh(f[k].name,a);V.push(f[k].materialName);var Y=new e.VertexData;Y.positions=s.positions,Y.normals=s.normals,Y.uvs=s.uvs,Y.indices=s.indices,Y.applyToMesh(H),U.push(H)}return""!==N&&this._loadMTL(N,i,(function(e){b.parseMTL(a,e,i);for(var t=0;t<b.materials.length;t++){for(var r,n=0,o=[];(r=V.indexOf(b.materials[t].name,n))>-1;)o.push(r),n=r+1;if(-1==r&&0==o.length)b.materials[t].dispose();else for(var s=0;s<o.length;s++)U[o[s]].material=b.materials[t]}})),U},r})();r.OPTIMIZE_WITH_UV=!1,e.OBJFileLoader=r,e.SceneLoader&&e.SceneLoader.RegisterPlugin(new r)})(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 r=(function(){function e(){this.coordinateSystemMode=t.AUTO,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.importMeshAsync=function(t,r,n,a,o,i,s){var u=e._parse(n,s);if(u){this.onParsed&&this.onParsed(u);var l=this._getLoader(u,s);l&&l.importMeshAsync(t,r,u,a,o,i,s)}},e.prototype.loadAsync=function(t,r,n,a,o,i){var s=e._parse(r,i);if(s){this.onParsed&&this.onParsed(s);var u=this._getLoader(s,i);if(u)return u.loadAsync(t,s,n,a,o,i)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e._parse=function(t,r){try{return t instanceof ArrayBuffer?e._parseBinary(t,r):{json:JSON.parse(t),bin:null}}catch(e){return r(e.message),null}},e.prototype._getLoader=function(t,r){var n={major:2,minor:0},a=t.json.asset||{},o=e._parseVersion(a.version);if(!o)return r("Invalid version: "+a.version),null;if(void 0!==a.minVersion){var i=e._parseVersion(a.minVersion);if(!i)return r("Invalid minimum version: "+a.minVersion),null;if(e._compareVersion(i,n)>0)return r("Incompatible minimum version: "+a.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},u=s[o.major];return u?u(this):(r("Unsupported version: "+a.version),null)},e._parseBinary=function(t,r){var a={Magic:1179937895},o=new n(t),i=o.readUint32();if(i!==a.Magic)return r("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return e._parseV1(o,r);case 2:return e._parseV2(o,r)}return r("Unsupported version: "+s),null},e._parseV1=function(t,r){var n={JSON:0},a=t.readUint32();if(a!=t.getLength())return r("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o,i=t.readUint32(),s=t.readUint32();switch(s){case n.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(i)));break;default:return r("Unexpected content format: "+s),null}var u=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(u)}},e._parseV2=function(t,r){var n={JSON:1313821514,BIN:5130562},a=t.readUint32();if(a!==t.getLength())return r("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o=t.readUint32(),i=t.readUint32();if(i!==n.JSON)return r("First chunk format is not JSON"),null;for(var s=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),u=null;t.getPosition()<t.getLength();)switch(o=t.readUint32(),i=t.readUint32()){case n.JSON:return r("Unexpected JSON chunk"),null;case n.BIN:u=t.readUint8Array(o);break;default:t.skipBytes(o)}return{json:s,bin:u}},e._parseVersion=function(e){if(!e)return null;var t=e.split(".");if(2!=t.length)return null;var r=+t[0];if(isNaN(r))return null;var n=+t[1];return isNaN(n)?null:{major:r,minor:n}},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="",r=e.byteLength,n=0;n<r;++n)t+=String.fromCharCode(e[n]);return t},e})();r.HomogeneousCoordinates=!1,r.IncrementalLoading=!0,e.GLTFFileLoader=r;var n=(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 r)})(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 r;!(function(e){e[e.IDENTIFIER=1]="IDENTIFIER",e[e.UNKNOWN=2]="UNKNOWN",e[e.END_OF_INPUT=3]="END_OF_INPUT"})(r||(r={}));var n=(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 r.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=r.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=r.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"],u=function(e,t){for(var r in e){var n=e[r];t.buffers[r]=n,t.buffersCount++}},l=function(e,t){for(var r in e){var n=e[r];t.shaders[r]=n,t.shaderscount++}},c=function(e,t,r){for(var n in e){var a=e[n];r[t][n]=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(r){for(var n in r.animations)for(var a=r.animations[n],o=null,u=0;u<a.channels.length;u++){var l=a.channels[u],c=a.samplers[l.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(r,r.accessors[f]),p=t.GLTFUtils.GetBufferFromAccessor(r,r.accessors[d]),m=l.target.id,_=r.scene.getNodeByID(m);if(null===_&&(_=r.scene.getNodeByName(m)),null!==_){var T=_ instanceof e.Bone,A=l.target.path,E=i.indexOf(A);-1!==E&&(A=s[E]);var y=e.Animation.ANIMATIONTYPE_MATRIX;T||("rotationQuaternion"===A?(y=e.Animation.ANIMATIONTYPE_QUATERNION,_.rotationQuaternion=new e.Quaternion):y=e.Animation.ANIMATIONTYPE_VECTOR3);var g=null,v=[],L=0,N=!1;T&&o&&o.getKeys().length===h.length&&(g=o,N=!0),N||(g=new e.Animation(n,T?"_matrix":A,1,y,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var b=0;b<h.length;b++){var x=null;if("rotationQuaternion"===A?(x=e.Quaternion.FromArray([p[L],p[L+1],p[L+2],p[L+3]]),L+=4):(x=e.Vector3.FromArray([p[L],p[L+1],p[L+2]]),L+=3),T){var M=_,O=e.Vector3.Zero(),S=new e.Quaternion,I=e.Vector3.Zero(),R=M.getBaseMatrix();N&&(R=o.getKeys()[b].value),R.decompose(I,S,O),"position"===A?O=x:"rotationQuaternion"===A?S=x:I=x,x=e.Matrix.Compose(I,S,O)}N?o.getKeys()[b].value=x:v.push({frame:h[b],value:x})}N||(g.setKeys(v),_.animations.push(g)),o=g,r.scene.stopAnimation(_),r.scene.beginAnimation(_,0,h[h.length-1],!0,1)}else e.Tools.Warn("Creating animation named "+n+". But cannot find node named "+m+" to attach to")}}},p=function(t){var r=null;if(t.translation||t.rotation||t.scale){var n=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]);r=e.Matrix.Compose(n,a,o)}else r=e.Matrix.FromArray(t.matrix);return r},m=function(t,r,n,a){for(var o=0;o<a.bones.length;o++)if(a.bones[o].name===n)return a.bones[o];var i=t.nodes;for(var s in i){var u=i[s];if(u.jointName)for(var l=u.children,o=0;o<l.length;o++){var c=t.nodes[l[o]];if(c.jointName&&c.jointName===n){var f=p(u),d=new e.Bone(u.name,a,m(t,r,u.jointName,a),f);return d.id=s,d}}}return null},_=function(e,t){for(var r=0;r<e.length;r++)for(var n=e[r],a=0;a<n.node.children.length;a++){var o=n.node.children[a];if(o===t)return n.bone}return null},T=function(e,t){var r=e.nodes,n=r[t];if(n)return{node:n,id:t};for(var a in r)if(n=r[a],n.jointName===t)return{node:n,id:a};return null},A=function(e,t){for(var r=0;r<e.jointNames.length;r++)if(e.jointNames[r]===t)return!0;return!1},E=function(t,r,n,a){for(var o in t.nodes){var i=t.nodes[o],s=o;if(i.jointName&&!A(n,i.jointName)){var u=p(i),l=new e.Bone(i.name,r,null,u);l.id=s,a.push({bone:l,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,_=0;_<a.length;_++)if(a[_].id===d[h]){m=a[_];break}m&&(m.bone._parent=f.bone,f.bone.children.push(m.bone))}},y=function(r,n,a,o,i){if(o||(o=new e.Skeleton(n.name,"",r.scene)),!n.babylonSkeleton)return o;var s=r.accessors[n.inverseBindMatrices],u=(t.GLTFUtils.GetBufferFromAccessor(r,s),e.Matrix.FromArray(n.bindShapeMatrix),[]),l=[];E(r,o,n,u),o.bones=[];for(var c=0;c<n.jointNames.length;c++){var f=T(r,n.jointNames[c]),d=f.node;if(d){var i=f.id,h=r.scene.getBoneByID(i);if(h)o.bones.push(h);else{for(var A=!1,y=null,g=0;g<c;g++){var v=T(r,n.jointNames[g]).node;if(v){var L=v.children;if(L){A=!1;for(var N=0;N<L.length;N++)if(L[N]===i){y=m(r,n,n.jointNames[g],o),A=!0;break}if(A)break}}else e.Tools.Warn("Joint named "+n.jointNames[g]+" does not exist when looking for parent")}var b=p(d);!y&&u.length>0&&(y=_(u,i))&&-1===l.indexOf(y)&&l.push(y);new e.Bone(d.jointName,o,y,b).id=i}}else e.Tools.Warn("Joint named "+n.jointNames[c]+" does not exist")}var x=o.bones;o.bones=[];for(var c=0;c<n.jointNames.length;c++){var f=T(r,n.jointNames[c]);if(f)for(var g=0;g<x.length;g++)if(x[g].id===f.id){o.bones.push(x[g]);break}}o.prepare();for(var c=0;c<l.length;c++)o.bones.push(l[c]);return o},g=function(r,n,a,o,i){if(i||(i=new e.Mesh(n.name,r.scene),i.id=o),!n.babylonNode)return i;var s=new e.MultiMaterial("multimat"+o,r.scene);i.material||(i.material=s);for(var u=new e.VertexData,l=new e.Geometry(o,r.scene,u,!1,i),c=[],d=[],h=[],p=[],m=0;m<a.length;m++){var _=a[m],T=r.meshes[_];if(T)for(var A=0;A<T.primitives.length;A++){var E=new e.VertexData,y=T.primitives[A];y.mode;var g=y.attributes,v=null,L=null;for(var N in g)if(v=r.accessors[g[N]],L=t.GLTFUtils.GetBufferFromAccessor(r,v),"NORMAL"===N)E.normals=new Float32Array(L.length),E.normals.set(L);else if("POSITION"===N){if(e.GLTFFileLoader.HomogeneousCoordinates){E.positions=new Float32Array(L.length-L.length/4);for(var b=0;b<L.length;b+=4)E.positions[b]=L[b],E.positions[b+1]=L[b+1],E.positions[b+2]=L[b+2]}else E.positions=new Float32Array(L.length),E.positions.set(L);d.push(E.positions.length)}else if(-1!==N.indexOf("TEXCOORD_")){var x=Number(N.split("_")[1]),M=e.VertexBuffer.UVKind+(0===x?"":x+1),O=new Float32Array(L.length);O.set(L),f(O),E.set(O,M)}else"JOINT"===N?(E.matricesIndices=new Float32Array(L.length),E.matricesIndices.set(L)):"WEIGHT"===N?(E.matricesWeights=new Float32Array(L.length),E.matricesWeights.set(L)):"COLOR"===N&&(E.colors=new Float32Array(L.length),E.colors.set(L));if(v=r.accessors[y.indices])L=t.GLTFUtils.GetBufferFromAccessor(r,v),E.indices=new Int32Array(L.length),E.indices.set(L),p.push(E.indices.length);else{for(var S=[],b=0;b<E.positions.length/3;b++)S.push(b);E.indices=new Int32Array(S),p.push(E.indices.length)}u.merge(E),E=void 0;var I=r.scene.getMaterialByID(y.material);s.subMaterials.push(null===I?t.GLTFUtils.GetDefaultMaterial(r.scene):I),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])}}l.setAllVerticesData(u,!1),i.computeWorldMatrix(!0),i.subMeshes=[];for(var R=0,m=0;m<a.length;m++){var _=a[m],T=r.meshes[_];if(T)for(var A=0;A<T.primitives.length;A++){T.primitives[A].mode;new e.SubMesh(R,c[R],d[R],h[R],p[R],i,i,!0);R++}}return i},v=function(e,t,r,n){e.position&&(e.position=t),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=r),e.scaling&&(e.scaling=n)},L=function(t,r,n){if(r.matrix){var a=new e.Vector3(0,0,0),o=new e.Quaternion,i=new e.Vector3(0,0,0);e.Matrix.FromArray(r.matrix).decompose(i,o,a),v(t,a,o,i)}else v(t,e.Vector3.FromArray(r.translation),e.Quaternion.FromArray(r.rotation),e.Vector3.FromArray(r.scale));t.computeWorldMatrix(!0)},N=function(t,r,n,a){var o=null;if(t.importOnlyMeshes&&(r.skin||r.meshes)&&t.importMeshesNames.length>0&&-1===t.importMeshesNames.indexOf(r.name))return null;if(r.skin){if(r.meshes){var i=t.skins[r.skin],s=g(t,r,r.meshes,n,r.babylonNode);s.skeleton=t.scene.getLastSkeletonByID(r.skin),null===s.skeleton&&(s.skeleton=y(t,i,0,i.babylonSkeleton,r.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),o=s}}else if(r.meshes){var s=g(t,r,r.mesh?[r.mesh]:r.meshes,n,r.babylonNode);o=s}else if(!r.light||r.babylonNode||t.importOnlyMeshes){if(r.camera&&!r.babylonNode&&!t.importOnlyMeshes){var u=t.cameras[r.camera];if(u)if("orthographic"===u.type){var l=(u[u.type],new e.FreeCamera(r.camera,e.Vector3.Zero(),t.scene));l.name=r.name,l.mode=e.Camera.ORTHOGRAPHIC_CAMERA,l.attachControl(t.scene.getEngine().getRenderingCanvas()),o=l}else if("perspective"===u.type){var c=u[u.type],f=new e.FreeCamera(r.camera,e.Vector3.Zero(),t.scene);f.name=r.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[r.light];if(d)if("ambient"===d.type){var h=d[d.type],p=new e.HemisphericLight(r.light,e.Vector3.Zero(),t.scene);p.name=r.name,h.color&&(p.diffuse=e.Color3.FromArray(h.color)),o=p}else if("directional"===d.type){var m=d[d.type],_=new e.DirectionalLight(r.light,e.Vector3.Zero(),t.scene);_.name=r.name,m.color&&(_.diffuse=e.Color3.FromArray(m.color)),o=_}else if("point"===d.type){var T=d[d.type],A=new e.PointLight(r.light,e.Vector3.Zero(),t.scene);A.name=r.name,T.color&&(A.diffuse=e.Color3.FromArray(T.color)),o=A}else if("spot"===d.type){var E=d[d.type],N=new e.SpotLight(r.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);N.name=r.name,E.color&&(N.diffuse=e.Color3.FromArray(E.color)),E.fallOfAngle&&(N.angle=E.fallOfAngle),E.fallOffExponent&&(N.exponent=E.fallOffExponent),o=N}}if(!r.jointName){if(r.babylonNode)return r.babylonNode;if(null===o){var b=new e.Mesh(r.name,t.scene);r.babylonNode=b,o=b}}if(null!==o){if(r.matrix&&o instanceof e.Mesh)L(o,r);else{var x=r.translation||[0,0,0],M=r.rotation||[0,0,0,1],O=r.scale||[1,1,1];v(o,e.Vector3.FromArray(x),e.Quaternion.FromArray(M),e.Vector3.FromArray(O))}o.updateCache(!0),r.babylonNode=o}return o},b=function(e,t,r,n){var a=e.nodes[t],o=null;if(n=!(e.importOnlyMeshes&&!n)||(-1!==e.importMeshesNames.indexOf(a.name)||0===e.importMeshesNames.length),!a.jointName&&n&&null!==(o=N(e,a,t))&&(o.id=t,o.parent=r),a.children)for(var i=0;i<a.children.length;i++)b(e,a.children[i],o,n)},x=function(e){var t=e.currentScene;if(t)for(var r=0;r<t.nodes.length;r++)b(e,t.nodes[r],null);else for(var n in e.scenes){t=e.scenes[n];for(var r=0;r<t.nodes.length;r++)b(e,t.nodes[r],null)}h(e);for(var r=0;r<e.scene.skeletons.length;r++){var a=e.scene.skeletons[r];e.scene.beginAnimation(a,0,Number.MAX_VALUE,!0,1)}},M=function(e,r,n,a,o,i,s){var u=i.values||o.parameters;for(var l in n){var c=n[l],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=r.scene.getNodeByName(c.source||c.node);if(null===d&&(d=r.scene.getNodeByID(c.source||c.node)),null===d)continue;t.GLTFUtils.SetMatrix(r.scene,d,c,l,a.getEffect())}}else t.GLTFUtils.SetMatrix(r.scene,e,c,l,a.getEffect());else{var h=u[o.uniforms[l]];if(!h)continue;if(f===t.EParameterType.SAMPLER_2D){var p=r.textures[i.values?h:c.value].babylonTexture;if(null===p||void 0===p)continue;a.getEffect().setTexture(l,p)}else t.GLTFUtils.SetUniform(a.getEffect(),l,h,f)}}s(a)},O=function(e,r,n,a,o){var i=a.values||n.parameters,s=n.uniforms;for(var u in o){var l=o[u],c=l.type,f=i[s[u]];if(void 0===f&&(f=l.value),f){var d=function(e){return function(t){l.value&&(r.setTexture(e,t),delete o[e])}};c===t.EParameterType.SAMPLER_2D?t.GLTFLoaderExtension.LoadTextureAsync(e,a.values?f:l.value,d(u),(function(){return d(null)})):l.value&&t.GLTFUtils.SetUniform(r,u,a.values?f:l.value,c)&&delete o[u]}}},S=function(e,t,r){return function(n,a){t.dispose(!0),r("Cannot compile program named "+e.name+". Error: "+a+". Default material will be applied")}},I=function(e,t,r,n,a,o){return function(i){O(e,t,r,n,a),t.onBind=function(i){M(i,e,a,t,r,n,o)}}},R=function(e,t,r){for(var n in t.uniforms){var i=t.uniforms[n],s=t.parameters[i];if(e.currentIdentifier===n&&s.semantic&&!s.source&&!s.node){var u=a.indexOf(s.semantic);if(-1!==u)return delete r[n],o[u]}}return e.currentIdentifier},F=function(e){for(var r in e.materials)t.GLTFLoaderExtension.LoadMaterialAsync(e,r,(function(e){}),(function(){}))},B=(function(){function i(){}return i.CreateRuntime=function(e,t,r){var n={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:r,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[]};return e.extensions&&c(e.extensions,"extensions",n),e.extensionsUsed&&c(e.extensionsUsed,"extensionsUsed",n),e.buffers&&u(e.buffers,n),e.bufferViews&&c(e.bufferViews,"bufferViews",n),e.accessors&&c(e.accessors,"accessors",n),e.meshes&&c(e.meshes,"meshes",n),e.lights&&c(e.lights,"lights",n),e.cameras&&c(e.cameras,"cameras",n),e.nodes&&c(e.nodes,"nodes",n),e.images&&c(e.images,"images",n),e.textures&&c(e.textures,"textures",n),e.shaders&&l(e.shaders,n),e.programs&&c(e.programs,"programs",n),e.samplers&&c(e.samplers,"samplers",n),e.techniques&&c(e.techniques,"techniques",n),e.materials&&c(e.materials,"materials",n),e.animations&&c(e.animations,"animations",n),e.skins&&c(e.skins,"skins",n),e.scenes&&(n.scenes=e.scenes),e.scene&&e.scenes&&(n.currentScene=e.scenes[e.scene]),n},i.LoadBufferAsync=function(r,n,a,o,i){var s=r.buffers[n];t.GLTFUtils.IsBase64(s.uri)?setTimeout((function(){return a(new Uint8Array(t.GLTFUtils.DecodeBase64(s.uri)))})):e.Tools.LoadFile(r.rootUrl+s.uri,(function(e){return a(new Uint8Array(e))}),i,null,!0,(function(e){o(e.status+" "+e.statusText)}))},i.LoadTextureBufferAsync=function(r,n,a,o){var i=r.textures[n];if(!i||!i.source)return void o(null);if(i.babylonTexture)return void a(null);var s=r.images[i.source];t.GLTFUtils.IsBase64(s.uri)?setTimeout((function(){return a(new Uint8Array(t.GLTFUtils.DecodeBase64(s.uri)))})):e.Tools.LoadFile(r.rootUrl+s.uri,(function(e){return a(new Uint8Array(e))}),null,null,!0,(function(e){o(e.status+" "+e.statusText)}))},i.CreateTextureAsync=function(r,n,a,o,i){var s=r.textures[n];if(s.babylonTexture)return void o(s.babylonTexture);var u=r.samplers[s.sampler],l=u.minFilter===t.ETextureFilterType.NEAREST_MIPMAP_NEAREST||u.minFilter===t.ETextureFilterType.NEAREST_MIPMAP_LINEAR||u.minFilter===t.ETextureFilterType.LINEAR_MIPMAP_NEAREST||u.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,r.scene,!l,!0,c,h,h);p.wrapU=t.GLTFUtils.GetWrapMode(u.wrapS),p.wrapV=t.GLTFUtils.GetWrapMode(u.wrapT),p.name=n,s.babylonTexture=p,o(p)},i.LoadShaderStringAsync=function(r,n,a,o){var i=r.shaders[n];if(t.GLTFUtils.IsBase64(i.uri)){a(atob(i.uri.split(",")[1]))}else e.Tools.LoadFile(r.rootUrl+i.uri,a,null,null,!1,(function(e){o(e.status+" "+e.statusText)}))},i.LoadMaterialAsync=function(i,s,u,l){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 u(h)}
- var p=i.programs[f.program],m=f.states,_=e.Effect.ShadersStore[p.vertexShader+"VertexShader"],T=e.Effect.ShadersStore[p.fragmentShader+"PixelShader"],A="",E="",y=new n(_),g=new n(T),v={},L=[],N=[],b=[];for(var x in f.uniforms){var M=f.uniforms[x],O=f.parameters[M];if(v[x]=O,!O.semantic||O.node||O.source)O.type===t.EParameterType.SAMPLER_2D?b.push(x):L.push(x);else{var F=a.indexOf(O.semantic);-1!==F?(L.push(o[F]),delete v[x]):L.push(x)}}for(var B in f.attributes){var P=f.attributes[B],C=f.parameters[P];C.semantic&&N.push(d(C))}for(;!y.isEnd()&&y.getNextToken();){var w=y.currentToken;if(w===r.IDENTIFIER){var D=!1;for(var B in f.attributes){var P=f.attributes[B],C=f.parameters[P];if(y.currentIdentifier===B&&C.semantic){A+=d(C),D=!0;break}}D||(A+=R(y,f,v))}else A+=y.currentString}for(;!g.isEnd()&&g.getNextToken();){var w=g.currentToken;w===r.IDENTIFIER?E+=R(g,f,v):E+=g.currentString}var G={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},U={attributes:N,uniforms:L,samplers:b,needAlphaBlending:m&&m.enable&&-1!==m.enable.indexOf(3042)};e.Effect.ShadersStore[p.vertexShader+s+"VertexShader"]=A,e.Effect.ShadersStore[p.fragmentShader+s+"PixelShader"]=E;var V=new e.ShaderMaterial(s,i.scene,G,U);if(V.onError=S(p,V,l),V.onCompiled=I(i,V,f,c,v,u),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 r(){}return r.RegisterExtension=function(t){if(r.Extensions[t.name])return void e.Tools.Error('Tool with the same name "'+t.name+'" already exists');r.Extensions[t.name]=t},r.prototype.importMeshAsync=function(r,n,a,o,i,s,u){var l=this;n.useRightHandedSystem=!0;t.GLTFLoaderExtension.LoadRuntimeAsync(n,a,o,(function(t){t.importOnlyMeshes=!0,""===r?t.importMeshesNames=[]:"string"==typeof r?t.importMeshesNames=[r]:!r||r instanceof Array?(t.importMeshesNames=[],e.Tools.Warn("Argument meshesNames must be of type string or string[]")):t.importMeshesNames=[r],l._createNodes(t);var n=[],a=[];for(var o in t.nodes){var u=t.nodes[o];u.babylonNode instanceof e.AbstractMesh&&n.push(u.babylonNode)}for(var c in t.skins){var f=t.skins[c];f.babylonSkeleton instanceof e.Skeleton&&a.push(f.babylonSkeleton)}l._loadBuffersAsync(t,(function(){l._loadShadersAsync(t,(function(){F(t),x(t),!e.GLTFFileLoader.IncrementalLoading&&i&&i(n,null,a)}))}),s),e.GLTFFileLoader.IncrementalLoading&&i&&i(n,null,a)}),u);return!0},r.prototype.loadAsync=function(r,n,a,o,i,s){var u=this;r.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(r,n,a,(function(r){t.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(r,(function(){u._createNodes(r),u._loadBuffersAsync(r,(function(){u._loadShadersAsync(r,(function(){F(r),x(r),e.GLTFFileLoader.IncrementalLoading||o()}))})),e.GLTFFileLoader.IncrementalLoading&&o()}),s)}),s)},r.prototype._loadShadersAsync=function(r,n){var a=!1,o=function(a,o){t.GLTFLoaderExtension.LoadShaderStringAsync(r,a,(function(i){r.loadedShaderCount++,i&&(e.Effect.ShadersStore[a+(o.type===t.EShaderType.VERTEX?"VertexShader":"PixelShader")]=i),r.loadedShaderCount===r.shaderscount&&n()}),(function(){e.Tools.Error("Error when loading shader program named "+a+" located at "+o.uri)}))};for(var i in r.shaders){a=!0;var s=r.shaders[i];s?o.bind(this,i,s)():e.Tools.Error("No shader named: "+i)}a||n()},r.prototype._loadBuffersAsync=function(r,n,a){var o=!1,i=function(a,o){t.GLTFLoaderExtension.LoadBufferAsync(r,a,(function(t){r.loadedBufferCount++,t&&(t.byteLength!=r.buffers[a].byteLength&&e.Tools.Error("Buffer named "+a+" is length "+t.byteLength+". Expected: "+o.byteLength),r.loadedBufferViews[a]=t),r.loadedBufferCount===r.buffersCount&&n()}),(function(){e.Tools.Error("Error when loading buffer named "+a+" located at "+o.uri)}))};for(var s in r.buffers){o=!0;var u=r.buffers[s];u?i.bind(this,s,u)():e.Tools.Error("No buffer named: "+s)}o||n()},r.prototype._createNodes=function(e){var t=e.currentScene;if(t)for(var r=0;r<t.nodes.length;r++)b(e,t.nodes[r],null);else for(var n in e.scenes){t=e.scenes[n];for(var r=0;r<t.nodes.length;r++)b(e,t.nodes[r],null)}},r})();P.Extensions={},t.GLTFLoader=P,e.GLTFFileLoader.CreateGLTFLoaderV1=function(){return new P}})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(){}return r.SetMatrix=function(r,n,a,o,i){var s=null;switch("MODEL"===a.semantic?s=n.getWorldMatrix():"PROJECTION"===a.semantic?s=r.getProjectionMatrix():"VIEW"===a.semantic?s=r.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===a.semantic?s=e.Matrix.Transpose(n.getWorldMatrix().multiply(r.getViewMatrix()).invert()):"MODELVIEW"===a.semantic?s=n.getWorldMatrix().multiply(r.getViewMatrix()):"MODELVIEWPROJECTION"===a.semantic?s=n.getWorldMatrix().multiply(r.getTransformMatrix()):"MODELINVERSE"===a.semantic?s=n.getWorldMatrix().invert():"VIEWINVERSE"===a.semantic?s=r.getViewMatrix().invert():"PROJECTIONINVERSE"===a.semantic?s=r.getProjectionMatrix().invert():"MODELVIEWINVERSE"===a.semantic?s=n.getWorldMatrix().multiply(r.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===a.semantic?s=n.getWorldMatrix().multiply(r.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===a.semantic&&(s=e.Matrix.Transpose(n.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)}},r.SetUniform=function(r,n,a,o){switch(o){case t.EParameterType.FLOAT:return r.setFloat(n,a),!0;case t.EParameterType.FLOAT_VEC2:return r.setVector2(n,e.Vector2.FromArray(a)),!0;case t.EParameterType.FLOAT_VEC3:return r.setVector3(n,e.Vector3.FromArray(a)),!0;case t.EParameterType.FLOAT_VEC4:return r.setVector4(n,e.Vector4.FromArray(a)),!0;default:return!1}},r.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},r.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),r=t.length,n=new Uint8Array(new ArrayBuffer(r)),a=0;a<r;a++)n[a]=t.charCodeAt(a);return n.buffer},r.GetWrapMode=function(r){switch(r){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}},r.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}},r.GetTextureFilterMode=function(r){switch(r){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}},r.GetBufferFromBufferView=function(e,r,n,a,o){var n=r.byteOffset+n,i=e.loadedBufferViews[r.buffer];if(n+a>i.byteLength)throw new Error("Buffer access is out of range");var s=i.buffer;switch(n+=i.byteOffset,o){case t.EComponentType.BYTE:return new Int8Array(s,n,a);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,n,a);case t.EComponentType.SHORT:return new Int16Array(s,n,a);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,n,a);default:return new Float32Array(s,n,a)}},r.GetBufferFromAccessor=function(e,t){var n=e.bufferViews[t.bufferView],a=t.count*r.GetByteStrideFromType(t);return r.GetBufferFromBufferView(e,n,t.byteOffset,a,t.componentType)},r.DecodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;++n)t+=String.fromCharCode(e[n]);return t},r.GetDefaultMaterial=function(t){if(!r._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 n={vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},a={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:[],needAlphaBlending:!1};r._DefaultMaterial=new e.ShaderMaterial("GLTFDefaultMaterial",t,n,a),r._DefaultMaterial.setColor4("u_emission",new e.Color4(.5,.5,.5,1))}return r._DefaultMaterial},r})();r._DefaultMaterial=null,t.GLTFUtils=r})(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,r,n,a){return!1},t.prototype.loadRuntimeExtensionsAsync=function(e,t,r){return!1},t.prototype.loadBufferAsync=function(e,t,r,n,a){return!1},t.prototype.loadTextureBufferAsync=function(e,t,r,n){return!1},t.prototype.createTextureAsync=function(e,t,r,n,a){return!1},t.prototype.loadShaderStringAsync=function(e,t,r,n){return!1},t.prototype.loadMaterialAsync=function(e,t,r,n){return!1},t.LoadRuntimeAsync=function(r,n,a,o,i){t.ApplyExtensions((function(e){return e.loadRuntimeAsync(r,n,a,o,i)}),(function(){setTimeout((function(){o(e.GLTFLoaderBase.CreateRuntime(n.json,r,a))}))}))},t.LoadRuntimeExtensionsAsync=function(e,r,n){t.ApplyExtensions((function(t){return t.loadRuntimeExtensionsAsync(e,r,n)}),(function(){setTimeout((function(){r()}))}))},t.LoadBufferAsync=function(r,n,a,o,i){t.ApplyExtensions((function(e){return e.loadBufferAsync(r,n,a,o,i)}),(function(){e.GLTFLoaderBase.LoadBufferAsync(r,n,a,o,i)}))},t.LoadTextureAsync=function(e,r,n,a){t.LoadTextureBufferAsync(e,r,(function(o){return t.CreateTextureAsync(e,r,o,n,a)}),a)},t.LoadShaderStringAsync=function(r,n,a,o){t.ApplyExtensions((function(e){return e.loadShaderStringAsync(r,n,a,o)}),(function(){e.GLTFLoaderBase.LoadShaderStringAsync(r,n,a,o)}))},t.LoadMaterialAsync=function(r,n,a,o){t.ApplyExtensions((function(e){return e.loadMaterialAsync(r,n,a,o)}),(function(){e.GLTFLoaderBase.LoadMaterialAsync(r,n,a,o)}))},t.LoadTextureBufferAsync=function(r,n,a,o){t.ApplyExtensions((function(e){return e.loadTextureBufferAsync(r,n,a,o)}),(function(){e.GLTFLoaderBase.LoadTextureBufferAsync(r,n,a,o)}))},t.CreateTextureAsync=function(r,n,a,o,i){t.ApplyExtensions((function(e){return e.createTextureAsync(r,n,a,o,i)}),(function(){e.GLTFLoaderBase.CreateTextureAsync(r,n,a,o,i)}))},t.ApplyExtensions=function(t,r){for(var n in e.GLTFLoader.Extensions){if(t(e.GLTFLoader.Extensions[n]))return}r()},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 r=(function(t){function r(){return t.call(this,"KHR_binary_glTF")||this}return __extends(r,t),r.prototype.loadRuntimeAsync=function(t,r,n,a,o){var i=r.json.extensionsUsed;return!(!i||-1===i.indexOf(this.name))&&(this._bin=r.bin,a(e.GLTFLoaderBase.CreateRuntime(r.json,t,n)),!0)},r.prototype.loadBufferAsync=function(e,t,r,n){return-1!==e.extensionsUsed.indexOf(this.name)&&("binary_glTF"===t&&(r(this._bin),!0))},r.prototype.loadTextureBufferAsync=function(t,r,n,a){var o=t.textures[r],i=t.images[o.source];if(!(i.extensions&&this.name in i.extensions))return!1;var s=i.extensions[this.name],u=t.bufferViews[s.bufferView];return n(e.GLTFUtils.GetBufferFromBufferView(t,u,0,u.byteLength,e.EComponentType.UNSIGNED_BYTE)),!0},r.prototype.loadShaderStringAsync=function(t,r,n,a){var o=t.shaders[r];if(!(o.extensions&&this.name in o.extensions))return!1;var i=o.extensions[this.name],s=t.bufferViews[i.bufferView],u=e.GLTFUtils.GetBufferFromBufferView(t,s,0,s.byteLength,e.EComponentType.UNSIGNED_BYTE);return setTimeout((function(){var t=e.GLTFUtils.DecodeBufferToText(u);n(t)})),!0},r})(e.GLTFLoaderExtension);e.GLTFBinaryExtension=r;!(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 r)})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(r){function n(){return r.call(this,"KHR_materials_common")||this}return __extends(n,r),n.prototype.loadRuntimeExtensionsAsync=function(t,r,n){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 u=new e.HemisphericLight(s.name,new e.Vector3(0,1,0),t.scene),l=s.ambient;u.diffuse=e.Color3.FromArray(l.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},n.prototype.loadMaterialAsync=function(t,r,n,a){var o=t.materials[r];if(!o||!o.extensions)return!1;var i=o.extensions[this.name];if(!i)return!1;var s=new e.StandardMaterial(r,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},n.prototype._loadTexture=function(e,r,n,a,o){t.GLTFLoaderBase.LoadTextureBufferAsync(e,r,(function(i){t.GLTFLoaderBase.CreateTextureAsync(e,r,i,(function(e){return n[a]=e}),o)}),o)},n})(t.GLTFLoaderExtension);t.GLTFMaterialsCommonExtension=r,t.GLTFLoader.RegisterExtension(new r)})(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 r=(function(){function e(e){this._pendingCount=0,this._callback=e}return e.prototype._addPendingData=function(e){this._pendingCount++},e.prototype._removePendingData=function(e){0==--this._pendingCount&&this._callback()},e})(),n=(function(){function n(t){this._renderReady=!1,this._disposed=!1,this._renderReadyObservable=new e.Observable,this._renderPendingCount=0,this._loaderPendingCount=0,this._loaderTrackers=new Array,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)},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,r,n,a,o,i){var s=this;this._loadAsync(e,t,r,n,(function(){a(s._getMeshes(),null,s._getSkeletons())}),o,i)},n.prototype.loadAsync=function(e,t,r,n,a,o){this._loadAsync(null,e,t,r,n,a,o)},n.prototype._loadAsync=function(e,t,r,n,a,o,i){try{this._loadData(r),this._babylonScene=t,this._rootUrl=n,this._successCallback=a,this._progressCallback=o,this._errorCallback=i,this._addPendingData(this),this._loadScene(e),this._loadAnimations(),this._removePendingData(this)}catch(e){this._onError(e.message)}},n.prototype._onError=function(t){this._disposed||(e.Tools.Error("glTF Loader Error: "+t),this._errorCallback&&this._errorCallback(t),this.dispose())},n.prototype._onProgress=function(e){this._disposed||this._progressCallback&&this._progressCallback(e)},n.prototype._executeWhenRenderReady=function(e){this._renderReady?e():this._renderReadyObservable.add(e)},n.prototype._onRenderReady=function(){this._rootNode.babylonMesh.setEnabled(!0),this._startAnimations(),this._successCallback(),this._renderReadyObservable.notifyObservers(this),this._parent.onReady&&this._parent.onReady()},n.prototype._onComplete=function(){this._parent.onComplete&&this._parent.onComplete(),this.dispose()},n.prototype._loadData=function(t){if(this._gltf=t.json,t.bin){var r=this._gltf.buffers;if(r&&r[0]&&!r[0].uri){var n=r[0];n.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),n.loadedData=t.bin}else e.Tools.Warn("Unexpected BIN chunk")}},n.prototype._getMeshes=function(){var e=[this._rootNode.babylonMesh],t=this._gltf.nodes;return t&&t.forEach((function(t){t.babylonMesh&&e.push(t.babylonMesh)})),e},n.prototype._getSkeletons=function(){var t=[],r=this._gltf.skins;return r&&r.forEach((function(r){r.babylonSkeleton instanceof e.Skeleton&&t.push(r.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._startAnimations=function(){var e=this;this._getAnimationTargets().forEach((function(t){return e._babylonScene.beginAnimation(t,0,Number.MAX_VALUE,!0)}))},n.prototype._loadScene=function(t){var r=this._getArrayItem(this._gltf.scenes,this._gltf.scene||0,"Scene");if(r){switch(this._rootNode={name:"__root__"},this._parent.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(this._rootNode.rotation=[0,1,0,0],this._rootNode.scale=[1,1,-1]);break;case e.GLTFLoaderCoordinateSystemMode.PASS_THROUGH:break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:return void e.Tools.Error("Invalid coordinate system mode ("+this._parent.coordinateSystemMode+")")}this._loadNode(this._rootNode);var n=r.nodes;this._traverseNodes(n,(function(e,t,r){return e.index=t,e.parent=r,!0}),this._rootNode);var a=this._gltf.materials;a&&a.forEach((function(e,t){return e.index=t}));var o=this._gltf.skins;if(o&&o.forEach((function(e,t){return e.index=t})),t){t instanceof Array||(t=[t]);var i=new Array;this._traverseNodes(n,(function(e){return-1===t.indexOf(e.name)||(i.push(e.index),!1)}),this._rootNode),n=i}for(var s=0;s<n.length;s++){var u=this._getArrayItem(this._gltf.nodes,n[s],"Node");if(!u)return;this._loadNode(u)}this._rootNode.babylonMesh.setEnabled(!1)}},n.prototype._loadNode=function(r){if(!t.GLTFLoaderExtension.LoadNode(this,r)){if(r.babylonMesh=new e.Mesh(r.name||"mesh"+r.index,this._babylonScene),this._loadTransform(r),void 0!==r.mesh){var n=this._getArrayItem(this._gltf.meshes,r.mesh,"Mesh");if(!n)return;this._loadMesh(r,n)}if(r.babylonMesh.parent=r.parent?r.parent.babylonMesh:null,r.babylonAnimationTargets=r.babylonAnimationTargets||[],r.babylonAnimationTargets.push(r.babylonMesh),void 0!==r.skin){var a=this._getArrayItem(this._gltf.skins,r.skin,"Skin");if(!a)return;r.babylonMesh.skeleton=this._loadSkin(a)}if(r.camera,r.children)for(var o=0;o<r.children.length;o++){var i=this._getArrayItem(this._gltf.nodes,r.children[o],"Node");if(!i)return;this._loadNode(i)}}},n.prototype._loadMesh=function(r,n){var a=this;r.babylonMesh.name=n.name||r.babylonMesh.name;var o=new e.MultiMaterial(r.babylonMesh.name,this._babylonScene);r.babylonMesh.material=o;var i=new e.Geometry(r.babylonMesh.name,this._babylonScene,null,!1,r.babylonMesh),s=new e.VertexData;s.positions=[],s.indices=[];for(var u=[],l=0,c=n.primitives.length,f=this,d=0;d<c;d++)!(function(d){var h=n.primitives[d];if(h.mode&&h.mode!==t.EMeshPrimitiveMode.TRIANGLES)throw new Error("Not implemented");f._createMorphTargets(r,n,h,r.babylonMesh),f._loadVertexDataAsync(h,(function(t){a._loadMorphTargetsData(n,h,t,r.babylonMesh),u.push({materialIndex:d,verticesStart:s.positions.length,verticesCount:t.positions.length,indicesStart:s.indices.length,indicesCount:t.indices.length,loadMaterial:function(){if(null==h.material)return void(o.subMaterials[d]=a._getDefaultMaterial());var e=a._getArrayItem(a._gltf.materials,h.material,"Material");e&&a._loadMaterial(e,(function(t,n){n&&a._parent.onMaterialLoaded&&a._parent.onMaterialLoaded(t),a._parent.onBeforeMaterialReadyAsync?(a._addLoaderPendingData(e),a._parent.onBeforeMaterialReadyAsync(t,r.babylonMesh,null!=o.subMaterials[d],(function(){o.subMaterials[d]=t,a._removeLoaderPendingData(e)}))):o.subMaterials[d]=t}))}}),s.merge(t),++l===c&&(i.setAllVerticesData(s,!1),u.forEach((function(e){return e.loadMaterial()})),r.babylonMesh.subMeshes=[],u.forEach((function(t){return new e.SubMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indicesStart,t.indicesCount,r.babylonMesh)})))}))})(d)},n.prototype._loadVertexDataAsync=function(t,r){var n=this,a=t.attributes;if(!a)return void this._onError("Primitive has no attributes");var o,i=new e.VertexData,s=0,u=Object.keys(a).length,l=this;for(var c in a){var f=(function(c){if(!(o=l._getArrayItem(l._gltf.accessors,a[c],"Mesh primitive attribute '"+c+"' accessor")))return{value:void 0};l._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 attribute '"+c+"'")}if(++s===u)if(null==t.indices)i.indices=new Uint32Array(i.positions.length/3),i.indices.forEach((function(e,t){return i.indices[t]=t})),r(i);else{var o=n._getArrayItem(n._gltf.accessors,t.indices,"Mesh primitive 'indices' accessor");if(!o)return;n._loadAccessorAsync(o,(function(e){i.indices=e,r(i)}))}}))})(c);if("object"==typeof f)return f.value}},n.prototype._createMorphTargets=function(t,r,n,a){var o=n.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]:r.weights?r.weights[i]:0;a.morphTargetManager.addTarget(new e.MorphTarget("morphTarget"+i,s))}}},n.prototype._loadMorphTargetsData=function(r,n,a,o){var i=n.targets;if(i)for(var s,u,l=this,c=0;c<i.length;c++){var f=(function(){var r=o.morphTargetManager.getTarget(c);s=i[c];for(var n in s){var f=(function(n){if(!(u=l._getArrayItem(l._gltf.accessors,s[n],"Mesh primitive morph target attribute '"+n+"' accessor")))return{value:void 0};l._loadAccessorAsync(u,(function(o){u.name&&(r.name=u.name);var i=o;switch(n){case"NORMAL":t.GLTFUtils.ForEach(i,(function(e,t){return i[t]+=a.normals[t]})),r.setNormals(i);break;case"POSITION":t.GLTFUtils.ForEach(i,(function(e,t){return i[t]+=a.positions[t]})),r.setPositions(i);break;case"TANGENT":for(var s=0,l=0;s<i.length;s++,l++)i[s]+=a.tangents[l],(s+1)%3==0&&l++;r.setTangents(i);break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+n+"'")}}))})(n);if("object"==typeof f)return f}})();if("object"==typeof f)return f.value}},n.prototype._loadTransform=function(t){var r=e.Vector3.Zero(),n=e.Quaternion.Identity(),a=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(a,n,r)}else t.translation&&(r=e.Vector3.FromArray(t.translation)),t.rotation&&(n=e.Quaternion.FromArray(t.rotation)),t.scale&&(a=e.Vector3.FromArray(t.scale));t.babylonMesh.position=r,t.babylonMesh.rotationQuaternion=n,t.babylonMesh.scaling=a},n.prototype._loadSkin=function(t){var r=this,n="skeleton"+t.index;if(t.babylonSkeleton=new e.Skeleton(t.name||n,n,this._babylonScene),null==t.inverseBindMatrices)this._loadBones(t,null);else{var a=this._getArrayItem(this._gltf.accessors,t.inverseBindMatrices,"Skin ("+t.index+") inverse bind matrices attribute accessor");if(!a)return;this._loadAccessorAsync(a,(function(e){r._loadBones(t,e)}))}return t.babylonSkeleton},n.prototype._createBone=function(t,r,n,a,o,i){var s=new e.Bone(t.name||"bone"+t.index,r.babylonSkeleton,n,a,null,o,i);return t.babylonBones=t.babylonBones||{},t.babylonBones[r.index]=s,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(s),s},n.prototype._loadBones=function(e,t){for(var r={},n=0;n<e.joints.length;n++){var a=this._getArrayItem(this._gltf.nodes,e.joints[n],"Skin ("+e.index+") joint");if(!a)return;this._loadBone(a,e,t,r)}},n.prototype._loadBone=function(t,r,n,a){var o=a[t.index];if(o)return o;var i=r.joints.indexOf(t.index),s=e.Matrix.Identity();n&&-1!==i&&(s=e.Matrix.FromArray(n,16*i),s.invertToRef(s));var u;return t.index!=r.skeleton&&t.parent&&(u=this._loadBone(t.parent,r,n,a),s.multiplyToRef(u.getInvertedAbsoluteTransform(),s)),o=this._createBone(t,r,u,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,r){void 0===r&&(r=null);for(var n=0;n<e.length;n++)this._traverseNode(e[n],t,r)},n.prototype._traverseNode=function(e,r,n){if(void 0===n&&(n=null),!t.GLTFLoaderExtension.TraverseNode(this,e,r,n)){var a=this._getArrayItem(this._gltf.nodes,e,"Node");a&&r(a,e,n)&&a.children&&this._traverseNodes(a.children,r,a)}},n.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e)for(var t=0;t<e.length;t++)for(var r=e[t],n=0;n<r.channels.length;n++)this._loadAnimationChannel(r,t,n)},n.prototype._loadAnimationChannel=function(t,r,n){var a=t.channels[n],o=a.sampler,i=t.samplers[o],s=this._getArrayItem(this._gltf.nodes,a.target.node,"Animation channel target");if(s){var u={translation:"position",rotation:"rotationQuaternion",scale:"scaling",weights:"influence"}[a.target.path];if(!u)return void this._onError("Invalid animation channel target path '"+a.target.path+"'");var l,c,f={position:e.Animation.ANIMATIONTYPE_VECTOR3,rotationQuaternion:e.Animation.ANIMATIONTYPE_QUATERNION,scaling:e.Animation.ANIMATIONTYPE_VECTOR3,influence:e.Animation.ANIMATIONTYPE_FLOAT}[u],d=function(){if(l&&c){for(var n=0,a={position:function(){var t=e.Vector3.FromArray(c,n);return n+=3,t},rotationQuaternion:function(){var t=e.Quaternion.FromArray(c,n);return n+=4,t},scaling:function(){var t=e.Vector3.FromArray(c,n);return n+=3,t},influence:function(){for(var e=s.babylonMesh.morphTargetManager.numTargets,t=new Array(e),r=0;r<e;r++)t[r]=c[n++];return t}}[u],o={LINEAR:function(e){return{frame:l[e],value:a()}},CUBICSPLINE:function(e){return{frame:l[e],inTangent:a(),value:a(),outTangent:a()}}}[i.interpolation],d=new Array(l.length),h=0;h<l.length;h++)d[h]=o(h);if(t.targets=t.targets||[],"influence"===u)for(var p=s.babylonMesh.morphTargetManager,m=0;m<p.numTargets;m++){var _=p.getTarget(m),T=(t.name||"anim"+r)+"_"+m,A=new e.Animation(T,u,1,f);A.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}}))),_.animations.push(A),t.targets.push(_)}else{var T=t.name||"anim"+r,A=new e.Animation(T,u,1,f);A.setKeys(d);for(var E=0;E<s.babylonAnimationTargets.length;E++){var y=s.babylonAnimationTargets[E];y.animations.push(A.clone()),t.targets.push(y)}}}},h=this._getArrayItem(this._gltf.accessors,i.input,"Animation sampler input accessor");if(h){this._loadAccessorAsync(h,(function(e){l=e,d()}));var p=this._getArrayItem(this._gltf.accessors,i.output,"Animation sampler output accessor");p&&this._loadAccessorAsync(p,(function(e){c=e,d()}))}}},n.prototype._validateUri=function(e){return!!e||(this._onError("Uri is missing"),!1)},n.prototype._loadBufferAsync=function(r,n){var a=this;if(this._addPendingData(r),r.loadedData)setTimeout((function(){n(r.loadedData),a._removePendingData(r)}));else if(r.loadedObservable)r.loadedObservable.add((function(e){n(e.loadedData),a._removePendingData(e)}));else if(this._validateUri(r.uri))if(t.GLTFUtils.IsBase64(r.uri)){var o=t.GLTFUtils.DecodeBase64(r.uri);r.loadedData=new Uint8Array(o),setTimeout((function(){n(r.loadedData),a._removePendingData(r)}))}else r.loadedObservable=new e.Observable,r.loadedObservable.add((function(e){n(e.loadedData),a._removePendingData(e)})),e.Tools.LoadFile(this._rootUrl+r.uri,(function(e){r.loadedData=new Uint8Array(e),r.loadedObservable.notifyObservers(r),r.loadedObservable=null}),(function(e){a._onProgress(e)}),this._babylonScene.database,!0,(function(e){a._onError("Failed to load file '"+r.uri+"'"+(e?": "+e.status+" "+e.statusText:""))}))},n.prototype._buildInt8ArrayBuffer=function(e,t,r,n,a){if(!n)return new Int8Array(e,t,r)
- ;var o=new Int8Array(e,t),i=new Int8Array(r);return this._extractInterleavedData(o,i,a,n,i.length),i},n.prototype._buildUint8ArrayBuffer=function(e,t,r,n,a){if(!n)return new Uint8Array(e,t,r);var o=new Uint8Array(e,t),i=new Uint8Array(r);return this._extractInterleavedData(o,i,a,n,i.length),i},n.prototype._buildInt16ArrayBuffer=function(e,t,r,n,a){if(!n)return new Int16Array(e,t,r);var o=new Int16Array(e,t),i=new Int16Array(r);return this._extractInterleavedData(o,i,a,n/2,i.length),i},n.prototype._buildUint16ArrayBuffer=function(e,t,r,n,a){if(!n)return new Uint16Array(e,t,r);var o=new Uint16Array(e,t),i=new Uint16Array(r);return this._extractInterleavedData(o,i,a,n/2,i.length),i},n.prototype._buildUint32ArrayBuffer=function(e,t,r,n,a){if(!n)return new Uint32Array(e,t,r);var o=new Uint32Array(e,t),i=new Uint32Array(r);return this._extractInterleavedData(o,i,a,n/4,i.length),i},n.prototype._buildFloat32ArrayBuffer=function(e,t,r,n,a){if(!n)return new Float32Array(e,t,r);var o=new Float32Array(e,t),i=new Float32Array(r);return this._extractInterleavedData(o,i,a,n/4,i.length),i},n.prototype._extractInterleavedData=function(e,t,r,n,a){for(var o=0,i=0,s=r;o<a;){for(var u=0;u<s;u++)t[o]=e[i+u],o++;i+=n}},n.prototype._loadBufferViewAsync=function(e,r,n,a,o,i){var s=this;r+=e.byteOffset||0;var u=this._getArrayItem(this._gltf.buffers,e.buffer,"Buffer");u&&this._loadBufferAsync(u,(function(u){if(r+n>u.byteLength)return void s._onError("Buffer access is out of range");var l=u.buffer;r+=u.byteOffset;var c;switch(o){case t.EComponentType.BYTE:c=s._buildInt8ArrayBuffer(l,r,n,e.byteStride,a);break;case t.EComponentType.UNSIGNED_BYTE:c=s._buildUint8ArrayBuffer(l,r,n,e.byteStride,a);break;case t.EComponentType.SHORT:c=s._buildInt16ArrayBuffer(l,r,n,e.byteStride,a);break;case t.EComponentType.UNSIGNED_SHORT:c=s._buildUint16ArrayBuffer(l,r,n,e.byteStride,a);break;case t.EComponentType.UNSIGNED_INT:c=s._buildUint32ArrayBuffer(l,r,n,e.byteStride,a);break;case t.EComponentType.FLOAT:c=s._buildFloat32ArrayBuffer(l,r,n,e.byteStride,a);break;default:return void s._onError("Invalid component type ("+o+")")}i(c)}))},n.prototype._loadAccessorAsync=function(e,t){var r=this._getArrayItem(this._gltf.bufferViews,e.bufferView,"Buffer view");if(r){var n=e.byteOffset||0,a=this._getByteStrideFromType(e),o=e.count*a;this._loadBufferViewAsync(r,n,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}},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._addLoaderPendingData=function(e){this._loaderPendingCount++,this._loaderTrackers.forEach((function(t){return t._addPendingData(e)}))},n.prototype._removeLoaderPendingData=function(e){this._loaderTrackers.forEach((function(t){return t._removePendingData(e)})),0==--this._loaderPendingCount&&this._onComplete()},n.prototype._whenAction=function(e,t){var n=this,a=new r(function(){n._loaderTrackers.splice(n._loaderTrackers.indexOf(a)),t()});this._loaderTrackers.push(a),this._addLoaderPendingData(a),e(),this._removeLoaderPendingData(a)},n.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",r=this._babylonScene.getMaterialByName(t);r||(r=new e.PBRMaterial(t,this._babylonScene),r.sideOrientation=e.Material.CounterClockWiseSideOrientation,r.metallic=1,r.roughness=1),this._defaultMaterial=r}return this._defaultMaterial},n.prototype._loadMaterialMetallicRoughnessProperties=function(t){var r=t.babylonMaterial;r.metallic=1,r.roughness=1;var n=t.pbrMetallicRoughness;n&&(r.albedoColor=n.baseColorFactor?e.Color3.FromArray(n.baseColorFactor):new e.Color3(1,1,1),r.metallic=null==n.metallicFactor?1:n.metallicFactor,r.roughness=null==n.roughnessFactor?1:n.roughnessFactor,n.baseColorTexture&&(r.albedoTexture=this._loadTexture(n.baseColorTexture)),n.metallicRoughnessTexture&&(r.metallicTexture=this._loadTexture(n.metallicRoughnessTexture),r.useMetallnessFromMetallicTextureBlue=!0,r.useRoughnessFromMetallicTextureGreen=!0,r.useRoughnessFromMetallicTextureAlpha=!1),this._loadMaterialAlphaProperties(t,n.baseColorFactor))},n.prototype._loadMaterial=function(e,r){if(e.babylonMaterial)return void r(e.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,r)||(this._createPbrMaterial(e),this._loadMaterialBaseProperties(e),this._loadMaterialMetallicRoughnessProperties(e),r(e.babylonMaterial,!0))},n.prototype._createPbrMaterial=function(t){var r=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);r.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=r},n.prototype._loadMaterialBaseProperties=function(t){var r=t.babylonMaterial;r.emissiveColor=t.emissiveFactor?e.Color3.FromArray(t.emissiveFactor):new e.Color3(0,0,0),t.doubleSided&&(r.backFaceCulling=!1,r.twoSidedLighting=!0),t.normalTexture&&(r.bumpTexture=this._loadTexture(t.normalTexture),r.invertNormalMapX=!this._babylonScene.useRightHandedSystem,r.invertNormalMapY=this._babylonScene.useRightHandedSystem,void 0!==t.normalTexture.scale&&(r.bumpTexture.level=t.normalTexture.scale)),t.occlusionTexture&&(r.ambientTexture=this._loadTexture(t.occlusionTexture),r.useAmbientInGrayScale=!0,void 0!==t.occlusionTexture.strength&&(r.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&(r.emissiveTexture=this._loadTexture(t.emissiveTexture))},n.prototype._loadMaterialAlphaProperties=function(e,t){var r=e.babylonMaterial;switch(e.alphaMode||"OPAQUE"){case"OPAQUE":break;case"MASK":r.alphaCutOff=null==e.alphaCutoff?.5:e.alphaCutoff,t&&(0==t[3]?r.alphaCutOff=1:r.alphaCutOff/=t[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0);break;case"BLEND":t&&(r.alpha=t[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture=!0);break;default:return void this._onError("Invalid alpha mode '"+e.alphaMode+"'")}},n.prototype._loadTexture=function(r){var n=this,a=this._getArrayItem(this._gltf.textures,r.index,"Texture");if(!a)return null;var o=r.texCoord||0,i=this._getArrayItem(this._gltf.images,a.source,"Texture ("+r.index+") source");if(!i)return null;var s=null==a.sampler?{}:this._getArrayItem(this._gltf.samplers,a.sampler,"Texture ("+r.index+") sampler");if(s){var u=s.minFilter===t.ETextureMinFilter.NEAREST||s.minFilter===t.ETextureMinFilter.LINEAR,l=t.GLTFUtils.GetTextureSamplingMode(s.magFilter,s.minFilter);this._addPendingData(a);var c=new e.Texture(null,this._babylonScene,u,!1,l,function(){n._disposed||n._removePendingData(a)},function(){n._disposed||(n._onError("Failed to load texture '"+i.uri+"'"),n._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){n._onProgress(e)}),this._babylonScene.database,!0,(function(e){n._onError("Failed to load file '"+i.uri+"': "+e.status+" "+e.statusText)}));else{var d=this._getArrayItem(this._gltf.bufferViews,i.bufferView,"Texture ("+r.index+") source ("+a.source+") buffer view");if(!d)return;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"+r.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(c),c}},n.prototype._getArrayItem=function(e,t,r){return e&&e[t]?e[t]:(this._onError(r+" index ("+t+") was not found"),null)},n})();n.Extensions={},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 r=(function(){function r(){}return r.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},r.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),r=t.length,n=new Uint8Array(new ArrayBuffer(r)),a=0;a<r;a++)n[a]=t.charCodeAt(a);return n.buffer},r.ForEach=function(e,t){for(var r=0;r<e.length;r++)t(e[r],r)},r.GetTextureWrapMode=function(r){switch(r=void 0===r?t.ETextureWrapMode.REPEAT:r){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 ("+r+")"),e.Texture.WRAP_ADDRESSMODE}},r.GetTextureSamplingMode=function(r,n){if(r=void 0===r?t.ETextureMagFilter.LINEAR:r,n=void 0===n?t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:n,r===t.ETextureMagFilter.LINEAR)switch(n){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 ("+n+")"),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(r!==t.ETextureMagFilter.NEAREST&&e.Tools.Warn("Invalid texture magnification filter ("+r+")"),n){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 ("+n+")"),e.Texture.NEAREST_NEAREST_MIPNEAREST}},r.DecodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;++n)t+=String.fromCharCode(e[n]);return t},r})();t.GLTFUtils=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(){this.enabled=!0}return e.prototype._traverseNode=function(e,t,r,n){return!1},e.prototype._loadNode=function(e,t){return!1},e.prototype._loadMaterial=function(e,t,r){return!1},e.prototype._loadExtension=function(e,t){var r=this;if(!e.extensions)return!1;var n=e.extensions[this.name];return!!n&&(e.extensions[this.name]=void 0,t(n,(function(){e.extensions[r.name]=n})),!0)},e.TraverseNode=function(e,t,r,n){return this._ApplyExtensions((function(a){return a._traverseNode(e,t,r,n)}))},e.LoadNode=function(e,t){return this._ApplyExtensions((function(r){return r._loadNode(e,t)}))},e.LoadMaterial=function(e,t,r){return this._ApplyExtensions((function(n){return n._loadMaterial(e,t,r)}))},e._ApplyExtensions=function(t){var r=e._Extensions;if(r){for(var n=0;n<r.length;n++){var a=r[n];if(a.enabled&&t(a))return!0}return!1}},e})();t._Extensions=[],e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n=(function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return __extends(r,t),Object.defineProperty(r.prototype,"name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),r.prototype._traverseNode=function(e,t,r,n){var a=e._getArrayItem(e._gltf.nodes,t,"Node");return!a||this._loadExtension(a,(function(a,o){for(var i=a.ids.length-1;i>=0;i--)e._traverseNode(a.ids[i],r,n);e._traverseNode(t,r,n),o()}))},r.prototype._loadNode=function(e,t){var r=this;return this._loadExtension(t,(function(n,a){var o=[t.index].concat(n.ids).map((function(t){return e._gltf.nodes[t]}));e._addLoaderPendingData(t),r._loadNodeLOD(e,o,o.length-1,(function(){e._removeLoaderPendingData(t),a()}))}))},r.prototype._loadNodeLOD=function(e,t,n,a){var o=this;e._whenAction((function(){e._loadNode(t[n])}),(function(){if(n!==t.length-1){t[n+1].babylonMesh.setEnabled(!1)}if(0===n)return void a();setTimeout((function(){o._loadNodeLOD(e,t,n-1,a)}),r.MinimalLODDelay)}))},r.prototype._loadMaterial=function(e,t,r){var n=this;return this._loadExtension(t,(function(a,o){var i=[t.index].concat(a.ids).map((function(t){return e._gltf.materials[t]}));e._addLoaderPendingData(t),n._loadMaterialLOD(e,i,i.length-1,r,(function(){t.extensions[n.name]=a,e._removeLoaderPendingData(t),o()}))}))},r.prototype._loadMaterialLOD=function(t,n,a,o,i){var s=this;t._loadMaterial(n[a],(function(u,l){if(o(u,l),0===a)return void i();t._executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(u.getActiveTextures(),(function(){setTimeout((function(){s._loadMaterialLOD(t,n,a-1,o,i)}),r.MinimalLODDelay)}))}))}))},r})(t.GLTFLoaderExtension);n.MinimalLODDelay=250,r.MSFTLOD=n,t.GLTFLoader.RegisterExtension(new n)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n=(function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return __extends(r,t),Object.defineProperty(r.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),r.prototype._loadMaterial=function(e,t,r){var n=this;return this._loadExtension(t,(function(a,o){e._createPbrMaterial(t),e._loadMaterialBaseProperties(t),n._loadSpecularGlossinessProperties(e,t,a),r(t.babylonMaterial,!0)}))},r.prototype._loadSpecularGlossinessProperties=function(t,r,n){var a=r.babylonMaterial;a.albedoColor=n.diffuseFactor?e.Color3.FromArray(n.diffuseFactor):new e.Color3(1,1,1),a.reflectivityColor=n.specularFactor?e.Color3.FromArray(n.specularFactor):new e.Color3(1,1,1),a.microSurface=void 0===n.glossinessFactor?1:n.glossinessFactor,n.diffuseTexture&&(a.albedoTexture=t._loadTexture(n.diffuseTexture)),n.specularGlossinessTexture&&(a.reflectivityTexture=t._loadTexture(n.specularGlossinessTexture),a.reflectivityTexture.hasAlpha=!0,a.useMicroSurfaceFromReflectivityMapAlpha=!0),t._loadMaterialAlphaProperties(r,n.diffuseFactor)},r})(t.GLTFLoaderExtension);r.KHRMaterialsPbrSpecularGlossiness=n,t.GLTFLoader.RegisterExtension(new n)})(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}));
|