123 |
- var BABYLON=BABYLON||"undefined"!=typeof require&&require("babylonjs"),__decorate=this&&this.__decorate||function(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a},__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,o,i,a,s){var l;if(this.isBinary(n)){var u=new e.Mesh("stlmesh",r);return this.parseBinary(u,n),i&&i.push(u),!0}for(var c=new Uint8Array(n),f="",d=0;d<n.byteLength;d++)f+=String.fromCharCode(c[d]);for(n=f;l=this.solidPattern.exec(n);){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,r);this.parseASCII(u,l[2]),i&&i.push(u)}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,o=0;o<n;o++)if(r.getUint8(o,!1)>127)return!0;return!1},t.prototype.parseBinary=function(t,r){for(var n=new DataView(r),o=n.getUint32(80,!0),i=0,a=new Float32Array(3*o*3),s=new Float32Array(3*o*3),l=new Uint32Array(3*o),u=0,c=0;c<o;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 T=f+12*m;a[i]=n.getFloat32(T,!0),a[i+2]=n.getFloat32(T+4,!0),a[i+1]=n.getFloat32(T+8,!0),s[i]=d,s[i+2]=h,s[i+1]=p,i+=3}l[u]=u++,l[u]=u++,l[u]=u++}t.setVerticesData(e.VertexBuffer.PositionKind,a),t.setVerticesData(e.VertexBuffer.NormalKind,s),t.setIndices(l),t.computeWorldMatrix(!0)},t.prototype.parseASCII=function(t,r){for(var n,o=[],i=[],a=[],s=0;n=this.facetsPattern.exec(r);){var l=n[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);)o.push(Number(c[1]),Number(c[5]),Number(c[3])),i.push(f[0],f[1],f[2]);a.push(s++,s++,s++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,t.setVerticesData(e.VertexBuffer.PositionKind,o),t.setVerticesData(e.VertexBuffer.NormalKind,i),t.setIndices(a),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,o){for(var i,a,s=n.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?(a&&this.materials.push(a),a=new e.StandardMaterial(d,r)):"kd"===f?(i=d.split(/\s+/,3).map(parseFloat),a.diffuseColor=e.Color3.FromArray(i)):"ka"===f?(i=d.split(/\s+/,3).map(parseFloat),a.ambientColor=e.Color3.FromArray(i)):"ks"===f?(i=d.split(/\s+/,3).map(parseFloat),a.specularColor=e.Color3.FromArray(i)):"ke"===f?(i=d.split(/\s+/,3).map(parseFloat),a.emissiveColor=e.Color3.FromArray(i)):"ns"===f?a.specularPower=parseFloat(d):"d"===f?a.alpha=parseFloat(d):"map_ka"===f?a.ambientTexture=t._getTexture(o,d,r):"map_kd"===f?a.diffuseTexture=t._getTexture(o,d,r):"map_ks"===f?a.specularTexture=t._getTexture(o,d,r):"map_ns"===f||("map_bump"===f?a.bumpTexture=t._getTexture(o,d,r):"map_d"===f&&(a.opacityTexture=t._getTexture(o,d,r)))}}this.materials.push(a)}}return t._getTexture=function(t,r,n){if(!r)return null;var o=t;if("file:"===t){var i=r.lastIndexOf("\\");-1===i&&(i=r.lastIndexOf("/")),o+=i>-1?r.substr(i+1):r}else o+=r;return new e.Texture(o,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 o=e.Tools.BaseUrl+r+t;e.Tools.LoadFile(o,n,null,null,!1,(function(){console.warn("Error - Unable to load "+o)}))},r.prototype.importMesh=function(e,t,r,n,o,i,a){var s=this._parseSolid(e,t,r,n);return o&&s.forEach((function(e){o.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,o,i,a){for(var s,l=[],u=[],c=[],f=[],d=[],h=[],p=[],m=[],T=[],E=0,_=!1,A=[],y=[],g=[],v=[],L="",b="",N=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]},F=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},S=function(e,t,n,o,i,a){var s;s=r.OPTIMIZE_WITH_UV?F(T,[e,n,t]):O(T,[e,n]),-1==s?(d.push(h.length),h.push(o),p.push(i),m.push(a),T[e].normals.push(n),T[e].idx.push(E++),r.OPTIMIZE_WITH_UV&&T[e].uv.push(t)):d.push(s)},I=function(){for(var e=0;e<h.length;e++)A.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=[],E=0},R=function(e,t){t+1<e.length&&(v.push(e[0],e[t],e[t+1]),t+=1,R(e,t))},w=function(){f.length>0&&(s=f[f.length-1],I(),d.reverse(),s.indices=d.slice(),s.positions=A.slice(),s.normals=y.slice(),s.uvs=g.slice(),d=[],A=[],y=[],g=[])},B=i.split("\n"),P=0;P<B.length;P++){var C,G=B[P].trim();if(0!==G.length&&"#"!==G.charAt(0))if(null!==(C=this.vertexPattern.exec(G)))l.push(new e.Vector3(parseFloat(C[1]),parseFloat(C[2]),parseFloat(C[3])));else if(null!==(C=this.normalPattern.exec(G)))u.push(new e.Vector3(parseFloat(C[1]),parseFloat(C[2]),parseFloat(C[3])));else if(null!==(C=this.uvPattern.exec(G)))c.push(new e.Vector2(parseFloat(C[1]),parseFloat(C[2])));else if(null!==(C=this.facePattern3.exec(G)))!(function(e,t){R(e,t);for(var r=0;r<v.length;r++){var n=v[r].split("/"),o=parseInt(n[0])-1,i=parseInt(n[1])-1,a=parseInt(n[2])-1;S(o,i,a,l[o],c[i],u[a])}v=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern4.exec(G)))!(function(t,r){R(t,r);for(var n=0;n<v.length;n++){var o=v[n].split("//"),i=parseInt(o[0])-1,a=parseInt(o[1])-1;S(i,1,a,l[i],e.Vector2.Zero(),u[a])}v=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern2.exec(G)))!(function(t,r){R(t,r);for(var n=0;n<v.length;n++){var o=v[n].split("/"),i=parseInt(o[0])-1,a=parseInt(o[1])-1;S(i,a,0,l[i],c[a],e.Vector3.Up())}v=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern1.exec(G)))!(function(t,r){R(t,r);for(var n=0;n<v.length;n++){var o=parseInt(v[n])-1;S(o,0,0,l[o],e.Vector2.Zero(),e.Vector3.Up())}v=[]})(C[1].trim().split(" "),1);else if(this.group.test(G)||this.obj.test(G)){var U={name:G.substring(2).trim(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:""};w(),f.push(U),_=!0,M=!0,x=1}else if(this.usemtl.test(G)){if(L=G.substring(7).trim(),!M){w();var U={name:"_mm"+x.toString(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:L};x++,f.push(U)}_&&M&&(f[f.length-1].materialName=L,M=!1)}else this.mtllib.test(G)?b=G.substring(7).trim():this.smooth.test(G)||console.log("Unhandled expression at line : "+G)}_&&(s=f[f.length-1],d.reverse(),I(),s.indices=d,s.positions=A,s.normals=y,s.uvs=g),_||(d.reverse(),I(),f.push({name:e.Geometry.RandomId(),indices:d,positions:A,normals:y,uvs:g,materialName:L}));for(var D=[],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 Y=new e.Mesh(f[k].name,o);V.push(f[k].materialName);var H=new e.VertexData;H.positions=s.positions,H.normals=s.normals,H.uvs=s.uvs,H.indices=s.indices,H.applyToMesh(Y),D.push(Y)}return""!==b&&this._loadMTL(b,a,(function(e){N.parseMTL(o,e,a);for(var t=0;t<N.materials.length;t++){for(var r,n=0,i=[];(r=V.indexOf(N.materials[t].name,n))>-1;)i.push(r),n=r+1;if(-1==r&&0==i.length)N.materials[t].dispose();else for(var s=0;s<i.length;s++)D[i[s]].material=N.materials[t]}})),D},r.OPTIMIZE_WITH_UV=!1,r})();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,o,i,a,s){var l=e._parse(n,s);if(l){this.onParsed&&this.onParsed(l);var u=this._getLoader(l,s);u&&u.importMeshAsync(t,r,l,o,i,a,s)}},e.prototype.loadAsync=function(t,r,n,o,i,a){var s=e._parse(r,a);if(s){this.onParsed&&this.onParsed(s);var l=this._getLoader(s,a);if(l)return l.loadAsync(t,s,n,o,i,a)}},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},o=t.json.asset||{},i=e._parseVersion(o.version);if(!i)return r("Invalid version: "+o.version),null;if(void 0!==o.minVersion){var a=e._parseVersion(o.minVersion);if(!a)return r("Invalid minimum version: "+o.minVersion),null;if(e._compareVersion(a,n)>0)return r("Incompatible minimum version: "+o.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},l=s[i.major];return l?l(this):(r("Unsupported version: "+o.version),null)},e._parseBinary=function(t,r){var o={Magic:1179937895},i=new n(t),a=i.readUint32();if(a!==o.Magic)return r("Unexpected magic: "+a),null;var s=i.readUint32();switch(s){case 1:return e._parseV1(i,r);case 2:return e._parseV2(i,r)}return r("Unsupported version: "+s),null},e._parseV1=function(t,r){var n={JSON:0},o=t.readUint32();if(o!=t.getLength())return r("Length in header does not match actual data length: "+o+" != "+t.getLength()),null;var i,a=t.readUint32(),s=t.readUint32();switch(s){case n.JSON:i=JSON.parse(e._decodeBufferToText(t.readUint8Array(a)));break;default:return r("Unexpected content format: "+s),null}var l=t.getLength()-t.getPosition();return{json:i,bin:t.readUint8Array(l)}},e._parseV2=function(t,r){var n={JSON:1313821514,BIN:5130562},o=t.readUint32();if(o!==t.getLength())return r("Length in header does not match actual data length: "+o+" != "+t.getLength()),null;var i=t.readUint32(),a=t.readUint32();if(a!==n.JSON)return r("First chunk format is not JSON"),null;for(var s=JSON.parse(e._decodeBufferToText(t.readUint8Array(i))),l=null;t.getPosition()<t.getLength();)switch(i=t.readUint32(),a=t.readUint32()){case n.JSON:return r("Unexpected JSON chunk"),null;case n.BIN:l=t.readUint8Array(i);break;default:t.skipBytes(i)}return{json:s,bin:l}},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.HomogeneousCoordinates=!1,e.IncrementalLoading=!0,e})();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})(),o=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],i=["world","view","projection","worldView","worldViewProjection","mBones"],a=["translation","rotation","scale"],s=["position","rotationQuaternion","scaling"],l=function(e,t){for(var r in e){var n=e[r];t.buffers[r]=n,t.buffersCount++}},u=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 o=e[n];r[t][n]=o}},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 o=r.animations[n],i=null,l=0;l<o.channels.length;l++){var u=o.channels[l],c=o.samplers[u.sampler];if(c){var f=null,d=null;o.parameters?(f=o.parameters[c.input],d=o.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=u.target.id,T=r.scene.getNodeByID(m);if(null===T&&(T=r.scene.getNodeByName(m)),null!==T){var E=T instanceof e.Bone,_=u.target.path,A=a.indexOf(_);-1!==A&&(_=s[A]);var y=e.Animation.ANIMATIONTYPE_MATRIX;E||("rotationQuaternion"===_?(y=e.Animation.ANIMATIONTYPE_QUATERNION,T.rotationQuaternion=new e.Quaternion):y=e.Animation.ANIMATIONTYPE_VECTOR3);var g=null,v=[],L=0,b=!1;E&&i&&i.getKeys().length===h.length&&(g=i,b=!0),b||(g=new e.Animation(n,E?"_matrix":_,1,y,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var N=0;N<h.length;N++){var x=null;if("rotationQuaternion"===_?(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),E){var M=T,O=e.Vector3.Zero(),F=new e.Quaternion,S=e.Vector3.Zero(),I=M.getBaseMatrix();b&&(I=i.getKeys()[N].value),I.decompose(S,F,O),"position"===_?O=x:"rotationQuaternion"===_?F=x:S=x,x=e.Matrix.Compose(S,F,O)}b?i.getKeys()[N].value=x:v.push({frame:h[N],value:x})}b||(g.setKeys(v),T.animations.push(g)),i=g,r.scene.stopAnimation(T),r.scene.beginAnimation(T,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]),o=e.Quaternion.FromArray(t.rotation||[0,0,0,1]),i=e.Vector3.FromArray(t.translation||[0,0,0]);r=e.Matrix.Compose(n,o,i)}else r=e.Matrix.FromArray(t.matrix);return r},m=function(t,r,n,o){for(var i=0;i<o.bones.length;i++)if(o.bones[i].name===n)return o.bones[i];var a=t.nodes;for(var s in a){var l=a[s];if(l.jointName)for(var u=l.children,i=0;i<u.length;i++){var c=t.nodes[u[i]];if(c.jointName&&c.jointName===n){var f=p(l),d=new e.Bone(l.name,o,m(t,r,l.jointName,o),f);return d.id=s,d}}}return null},T=function(e,t){for(var r=0;r<e.length;r++)for(var n=e[r],o=0;o<n.node.children.length;o++){var i=n.node.children[o];if(i===t)return n.bone}return null},E=function(e,t){var r=e.nodes,n=r[t];if(n)return{node:n,id:t};for(var o in r)if(n=r[o],n.jointName===t)return{node:n,id:o};return null},_=function(e,t){for(var r=0;r<e.jointNames.length;r++)if(e.jointNames[r]===t)return!0;return!1},A=function(t,r,n,o){for(var i in t.nodes){var a=t.nodes[i],s=i;if(a.jointName&&!_(n,a.jointName)){var l=p(a),u=new e.Bone(a.name,r,null,l);u.id=s,o.push({bone:u,node:a,id:s})}}for(var c=0;c<o.length;c++)for(var f=o[c],d=f.node.children,h=0;h<d.length;h++){for(var m=null,T=0;T<o.length;T++)if(o[T].id===d[h]){m=o[T];break}m&&(m.bone._parent=f.bone,f.bone.children.push(m.bone))}},y=function(r,n,o,i,a){if(i||(i=new e.Skeleton(n.name,"",r.scene)),!n.babylonSkeleton)return i;var s=r.accessors[n.inverseBindMatrices],l=(t.GLTFUtils.GetBufferFromAccessor(r,s),e.Matrix.FromArray(n.bindShapeMatrix),[]),u=[];A(r,i,n,l),i.bones=[];for(var c=0;c<n.jointNames.length;c++){var f=E(r,n.jointNames[c]),d=f.node;if(d){var a=f.id,h=r.scene.getBoneByID(a);if(h)i.bones.push(h);else{for(var _=!1,y=null,g=0;g<c;g++){var v=E(r,n.jointNames[g]).node;if(v){var L=v.children;if(L){_=!1;for(var b=0;b<L.length;b++)if(L[b]===a){y=m(r,n,n.jointNames[g],i),_=!0;break}if(_)break}}else e.Tools.Warn("Joint named "+n.jointNames[g]+" does not exist when looking for parent")}var N=p(d);!y&&l.length>0&&(y=T(l,a))&&-1===u.indexOf(y)&&u.push(y);new e.Bone(d.jointName,i,y,N).id=a}}else e.Tools.Warn("Joint named "+n.jointNames[c]+" does not exist")}var x=i.bones;i.bones=[];for(var c=0;c<n.jointNames.length;c++){var f=E(r,n.jointNames[c]);if(f)for(var g=0;g<x.length;g++)if(x[g].id===f.id){i.bones.push(x[g]);break}}i.prepare();for(var c=0;c<u.length;c++)i.bones.push(u[c]);return i},g=function(r,n,o,i,a){if(a||(a=new e.Mesh(n.name,r.scene),a.id=i),!n.babylonNode)return a;var s=new e.MultiMaterial("multimat"+i,r.scene);a.material||(a.material=s);for(var l=new e.VertexData,u=new e.Geometry(i,r.scene,l,!1,a),c=[],d=[],h=[],p=[],m=0;m<o.length;m++){var T=o[m],E=r.meshes[T];if(E)for(var _=0;_<E.primitives.length;_++){var A=new e.VertexData,y=E.primitives[_];y.mode;var g=y.attributes,v=null,L=null;for(var b in g)if(v=r.accessors[g[b]],L=t.GLTFUtils.GetBufferFromAccessor(r,v),"NORMAL"===b)A.normals=new Float32Array(L.length),A.normals.set(L);else if("POSITION"===b){if(e.GLTFFileLoader.HomogeneousCoordinates){A.positions=new Float32Array(L.length-L.length/4);for(var N=0;N<L.length;N+=4)A.positions[N]=L[N],A.positions[N+1]=L[N+1],A.positions[N+2]=L[N+2]}else A.positions=new Float32Array(L.length),A.positions.set(L);d.push(A.positions.length)}else if(-1!==b.indexOf("TEXCOORD_")){var x=Number(b.split("_")[1]),M=e.VertexBuffer.UVKind+(0===x?"":x+1),O=new Float32Array(L.length);O.set(L),f(O),A.set(O,M)}else"JOINT"===b?(A.matricesIndices=new Float32Array(L.length),A.matricesIndices.set(L)):"WEIGHT"===b?(A.matricesWeights=new Float32Array(L.length),A.matricesWeights.set(L)):"COLOR"===b&&(A.colors=new Float32Array(L.length),A.colors.set(L));if(v=r.accessors[y.indices])L=t.GLTFUtils.GetBufferFromAccessor(r,v),A.indices=new Int32Array(L.length),A.indices.set(L),p.push(A.indices.length);else{for(var F=[],N=0;N<A.positions.length/3;N++)F.push(N);A.indices=new Int32Array(F),p.push(A.indices.length)}l.merge(A),A=void 0;var S=r.scene.getMaterialByID(y.material);s.subMaterials.push(null===S?t.GLTFUtils.GetDefaultMaterial(r.scene):S),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),a.computeWorldMatrix(!0),a.subMeshes=[];for(var I=0,m=0;m<o.length;m++){var T=o[m],E=r.meshes[T];if(E)for(var _=0;_<E.primitives.length;_++){E.primitives[_].mode;new e.SubMesh(I,c[I],d[I],h[I],p[I],a,a,!0);I++}}return a},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 o=new e.Vector3(0,0,0),i=new e.Quaternion,a=new e.Vector3(0,0,0);e.Matrix.FromArray(r.matrix).decompose(a,i,o),v(t,o,i,a)}else v(t,e.Vector3.FromArray(r.translation),e.Quaternion.FromArray(r.rotation),e.Vector3.FromArray(r.scale));t.computeWorldMatrix(!0)},b=function(t,r,n,o){var i=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 a=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,a,0,a.babylonSkeleton,r.skin),a.babylonSkeleton||(a.babylonSkeleton=s.skeleton)),i=s}}else if(r.meshes){var s=g(t,r,r.mesh?[r.mesh]:r.meshes,n,r.babylonNode);i=s}else if(!r.light||r.babylonNode||t.importOnlyMeshes){if(r.camera&&!r.babylonNode&&!t.importOnlyMeshes){var l=t.cameras[r.camera];if(l)if("orthographic"===l.type){var u=(l[l.type],new e.FreeCamera(r.camera,e.Vector3.Zero(),t.scene));u.name=r.name,u.mode=e.Camera.ORTHOGRAPHIC_CAMERA,u.attachControl(t.scene.getEngine().getRenderingCanvas()),i=u}else if("perspective"===l.type){var c=l[l.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),i=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)),i=p}else if("directional"===d.type){var m=d[d.type],T=new e.DirectionalLight(r.light,e.Vector3.Zero(),t.scene);T.name=r.name,m.color&&(T.diffuse=e.Color3.FromArray(m.color)),i=T}else if("point"===d.type){var E=d[d.type],_=new e.PointLight(r.light,e.Vector3.Zero(),t.scene);_.name=r.name,E.color&&(_.diffuse=e.Color3.FromArray(E.color)),i=_}else if("spot"===d.type){var A=d[d.type],b=new e.SpotLight(r.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);b.name=r.name,A.color&&(b.diffuse=e.Color3.FromArray(A.color)),A.fallOfAngle&&(b.angle=A.fallOfAngle),A.fallOffExponent&&(b.exponent=A.fallOffExponent),i=b}}if(!r.jointName){if(r.babylonNode)return r.babylonNode;if(null===i){var N=new e.Mesh(r.name,t.scene);r.babylonNode=N,i=N}}if(null!==i){if(r.matrix&&i instanceof e.Mesh)L(i,r);else{var x=r.translation||[0,0,0],M=r.rotation||[0,0,0,1],O=r.scale||[1,1,1];v(i,e.Vector3.FromArray(x),e.Quaternion.FromArray(M),e.Vector3.FromArray(O))}i.updateCache(!0),r.babylonNode=i}return i},N=function(e,t,r,n){var o=e.nodes[t],i=null;if(n=!(e.importOnlyMeshes&&!n)||(-1!==e.importMeshesNames.indexOf(o.name)||0===e.importMeshesNames.length),!o.jointName&&n&&null!==(i=b(e,o,t))&&(i.id=t,i.parent=r),o.children)for(var a=0;a<o.children.length;a++)N(e,o.children[a],i,n)},x=function(e){var t=e.currentScene;if(t)for(var r=0;r<t.nodes.length;r++)N(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++)N(e,t.nodes[r],null)}h(e);for(var r=0;r<e.scene.skeletons.length;r++){var o=e.scene.skeletons[r];e.scene.beginAnimation(o,0,Number.MAX_VALUE,!0,1)}},M=function(e,r,n,o,i,a,s){var l=a.values||i.parameters;for(var u in n){var c=n[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=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,u,o.getEffect())}}else t.GLTFUtils.SetMatrix(r.scene,e,c,u,o.getEffect());else{var h=l[i.uniforms[u]];if(!h)continue;if(f===t.EParameterType.SAMPLER_2D){var p=r.textures[a.values?h:c.value].babylonTexture;if(null===p||void 0===p)continue;o.getEffect().setTexture(u,p)}else t.GLTFUtils.SetUniform(o.getEffect(),u,h,f)}}s(o)},O=function(e,r,n,o,i){var a=o.values||n.parameters,s=n.uniforms;for(var l in i){var u=i[l],c=u.type,f=a[s[l]];if(void 0===f&&(f=u.value),f){var d=function(e){return function(t){u.value&&(r.setTexture(e,t),delete i[e])}};c===t.EParameterType.SAMPLER_2D?t.GLTFLoaderExtension.LoadTextureAsync(e,o.values?f:u.value,d(l),(function(){return d(null)})):u.value&&t.GLTFUtils.SetUniform(r,l,o.values?f:u.value,c)&&delete i[l]}}},F=function(e,t,r){return function(n,o){t.dispose(!0),r("Cannot compile program named "+e.name+". Error: "+o+". Default material will be applied")}},S=function(e,t,r,n,o,i){return function(a){O(e,t,r,n,o),t.onBind=function(a){M(a,e,o,t,r,n,i)}}},I=function(e,t,r){for(var n in t.uniforms){var a=t.uniforms[n],s=t.parameters[a];if(e.currentIdentifier===n&&s.semantic&&!s.source&&!s.node){var l=o.indexOf(s.semantic);if(-1!==l)return delete r[n],i[l]}}return e.currentIdentifier},R=function(e){for(var r in e.materials)t.GLTFLoaderExtension.LoadMaterialAsync(e,r,(function(e){}),(function(){}))},w=(function(){function a(){}return a.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&&l(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&&u(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},a.LoadBufferAsync=function(r,n,o,i,a){var s=r.buffers[n];t.GLTFUtils.IsBase64(s.uri)?setTimeout((function(){return o(new Uint8Array(t.GLTFUtils.DecodeBase64(s.uri)))})):e.Tools.LoadFile(r.rootUrl+s.uri,(function(e){return o(new Uint8Array(e))}),a,null,!0,(function(e){i(e.status+" "+e.statusText)}))},a.LoadTextureBufferAsync=function(r,n,o,i){var a=r.textures[n];if(!a||!a.source)return void i(null);if(a.babylonTexture)return void o(null);var s=r.images[a.source];t.GLTFUtils.IsBase64(s.uri)?setTimeout((function(){return o(new Uint8Array(t.GLTFUtils.DecodeBase64(s.uri)))})):e.Tools.LoadFile(r.rootUrl+s.uri,(function(e){return o(new Uint8Array(e))}),null,null,!0,(function(e){i(e.status+" "+e.statusText)}))},a.CreateTextureAsync=function(r,n,o,i,a){var s=r.textures[n];if(s.babylonTexture)return void i(s.babylonTexture);var l=r.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([o]),d=URL.createObjectURL(f),h=function(){return URL.revokeObjectURL(d)},p=new e.Texture(d,r.scene,!u,!0,c,h,h);p.wrapU=t.GLTFUtils.GetWrapMode(l.wrapS),p.wrapV=t.GLTFUtils.GetWrapMode(l.wrapT),p.name=n,s.babylonTexture=p,i(p)},a.LoadShaderStringAsync=function(r,n,o,i){var a=r.shaders[n];if(t.GLTFUtils.IsBase64(a.uri)){o(atob(a.uri.split(",")[1]))}else e.Tools.LoadFile(r.rootUrl+a.uri,o,null,null,!1,(function(e){i(e.status+" "+e.statusText)}))},a.LoadMaterialAsync=function(a,s,l,u){var c=a.materials[s],f=a.techniques[c.technique];if(!f){var h=new e.StandardMaterial(s,a.scene);return h.diffuseColor=new e.Color3(.5,.5,.5),h.sideOrientation=e.Material.CounterClockWiseSideOrientation,void l(h)}
- var p=a.programs[f.program],m=f.states,T=e.Effect.ShadersStore[p.vertexShader+"VertexShader"],E=e.Effect.ShadersStore[p.fragmentShader+"PixelShader"],_="",A="",y=new n(T),g=new n(E),v={},L=[],b=[],N=[];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?N.push(x):L.push(x);else{var R=o.indexOf(O.semantic);-1!==R?(L.push(i[R]),delete v[x]):L.push(x)}}for(var w in f.attributes){var B=f.attributes[w],P=f.parameters[B];P.semantic&&b.push(d(P))}for(;!y.isEnd()&&y.getNextToken();){var C=y.currentToken;if(C===r.IDENTIFIER){var G=!1;for(var w in f.attributes){var B=f.attributes[w],P=f.parameters[B];if(y.currentIdentifier===w&&P.semantic){_+=d(P),G=!0;break}}G||(_+=I(y,f,v))}else _+=y.currentString}for(;!g.isEnd()&&g.getNextToken();){var C=g.currentToken;C===r.IDENTIFIER?A+=I(g,f,v):A+=g.currentString}var U={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},D={attributes:b,uniforms:L,samplers:N,needAlphaBlending:m&&m.enable&&-1!==m.enable.indexOf(3042)};e.Effect.ShadersStore[p.vertexShader+s+"VertexShader"]=_,e.Effect.ShadersStore[p.fragmentShader+s+"PixelShader"]=A;var V=new e.ShaderMaterial(s,a.scene,U,D);if(V.onError=F(p,V,u),V.onCompiled=S(a,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 Y=k.blendFuncSeparate;Y&&(Y[0]===t.EBlendingFunction.SRC_ALPHA&&Y[1]===t.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&Y[2]===t.EBlendingFunction.ONE&&Y[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_COMBINE:Y[0]===t.EBlendingFunction.ONE&&Y[1]===t.EBlendingFunction.ONE&&Y[2]===t.EBlendingFunction.ZERO&&Y[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_ONEONE:Y[0]===t.EBlendingFunction.SRC_ALPHA&&Y[1]===t.EBlendingFunction.ONE&&Y[2]===t.EBlendingFunction.ZERO&&Y[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_ADD:Y[0]===t.EBlendingFunction.ZERO&&Y[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&Y[2]===t.EBlendingFunction.ONE&&Y[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_SUBTRACT:Y[0]===t.EBlendingFunction.DST_COLOR&&Y[1]===t.EBlendingFunction.ZERO&&Y[2]===t.EBlendingFunction.ONE&&Y[3]===t.EBlendingFunction.ONE?V.alphaMode=e.Engine.ALPHA_MULTIPLY:Y[0]===t.EBlendingFunction.SRC_ALPHA&&Y[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&Y[2]===t.EBlendingFunction.ONE&&Y[3]===t.EBlendingFunction.ONE&&(V.alphaMode=e.Engine.ALPHA_MAXIMIZED))}},a})();t.GLTFLoaderBase=w;var B=(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,o,i,a,s,l){var u=this;n.useRightHandedSystem=!0;t.GLTFLoaderExtension.LoadRuntimeAsync(n,o,i,(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],u._createNodes(t);var n=[],o=[];for(var i in t.nodes){var l=t.nodes[i];l.babylonNode instanceof e.AbstractMesh&&n.push(l.babylonNode)}for(var c in t.skins){var f=t.skins[c];f.babylonSkeleton instanceof e.Skeleton&&o.push(f.babylonSkeleton)}u._loadBuffersAsync(t,(function(){u._loadShadersAsync(t,(function(){R(t),x(t),!e.GLTFFileLoader.IncrementalLoading&&a&&a(n,null,o)}))}),s),e.GLTFFileLoader.IncrementalLoading&&a&&a(n,null,o)}),l);return!0},r.prototype.loadAsync=function(r,n,o,i,a,s){var l=this;r.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(r,n,o,(function(r){t.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(r,(function(){l._createNodes(r),l._loadBuffersAsync(r,(function(){l._loadShadersAsync(r,(function(){R(r),x(r),e.GLTFFileLoader.IncrementalLoading||i()}))})),e.GLTFFileLoader.IncrementalLoading&&i()}),s)}),s)},r.prototype._loadShadersAsync=function(r,n){var o=!1,i=function(o,i){t.GLTFLoaderExtension.LoadShaderStringAsync(r,o,(function(a){r.loadedShaderCount++,a&&(e.Effect.ShadersStore[o+(i.type===t.EShaderType.VERTEX?"VertexShader":"PixelShader")]=a),r.loadedShaderCount===r.shaderscount&&n()}),(function(){e.Tools.Error("Error when loading shader program named "+o+" located at "+i.uri)}))};for(var a in r.shaders){o=!0;var s=r.shaders[a];s?i.bind(this,a,s)():e.Tools.Error("No shader named: "+a)}o||n()},r.prototype._loadBuffersAsync=function(r,n,o){var i=!1,a=function(o,i){t.GLTFLoaderExtension.LoadBufferAsync(r,o,(function(t){r.loadedBufferCount++,t&&(t.byteLength!=r.buffers[o].byteLength&&e.Tools.Error("Buffer named "+o+" is length "+t.byteLength+". Expected: "+i.byteLength),r.loadedBufferViews[o]=t),r.loadedBufferCount===r.buffersCount&&n()}),(function(){e.Tools.Error("Error when loading buffer named "+o+" located at "+i.uri)}))};for(var s in r.buffers){i=!0;var l=r.buffers[s];l?a.bind(this,s,l)():e.Tools.Error("No buffer named: "+s)}i||n()},r.prototype._createNodes=function(e){var t=e.currentScene;if(t)for(var r=0;r<t.nodes.length;r++)N(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++)N(e,t.nodes[r],null)}},r.Extensions={},r})();t.GLTFLoader=B,e.GLTFFileLoader.CreateGLTFLoaderV1=function(){return new B}})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(){}return r.SetMatrix=function(r,n,o,i,a){var s=null;switch("MODEL"===o.semantic?s=n.getWorldMatrix():"PROJECTION"===o.semantic?s=r.getProjectionMatrix():"VIEW"===o.semantic?s=r.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===o.semantic?s=e.Matrix.Transpose(n.getWorldMatrix().multiply(r.getViewMatrix()).invert()):"MODELVIEW"===o.semantic?s=n.getWorldMatrix().multiply(r.getViewMatrix()):"MODELVIEWPROJECTION"===o.semantic?s=n.getWorldMatrix().multiply(r.getTransformMatrix()):"MODELINVERSE"===o.semantic?s=n.getWorldMatrix().invert():"VIEWINVERSE"===o.semantic?s=r.getViewMatrix().invert():"PROJECTIONINVERSE"===o.semantic?s=r.getProjectionMatrix().invert():"MODELVIEWINVERSE"===o.semantic?s=n.getWorldMatrix().multiply(r.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===o.semantic?s=n.getWorldMatrix().multiply(r.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===o.semantic&&(s=e.Matrix.Transpose(n.getWorldMatrix().invert())),o.type){case t.EParameterType.FLOAT_MAT2:a.setMatrix2x2(i,e.Matrix.GetAsMatrix2x2(s));break;case t.EParameterType.FLOAT_MAT3:a.setMatrix3x3(i,e.Matrix.GetAsMatrix3x3(s));break;case t.EParameterType.FLOAT_MAT4:a.setMatrix(i,s)}},r.SetUniform=function(r,n,o,i){switch(i){case t.EParameterType.FLOAT:return r.setFloat(n,o),!0;case t.EParameterType.FLOAT_VEC2:return r.setVector2(n,e.Vector2.FromArray(o)),!0;case t.EParameterType.FLOAT_VEC3:return r.setVector3(n,e.Vector3.FromArray(o)),!0;case t.EParameterType.FLOAT_VEC4:return r.setVector4(n,e.Vector4.FromArray(o)),!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)),o=0;o<r;o++)n[o]=t.charCodeAt(o);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,o,i){var n=r.byteOffset+n,a=e.loadedBufferViews[r.buffer];if(n+o>a.byteLength)throw new Error("Buffer access is out of range");var s=a.buffer;switch(n+=a.byteOffset,i){case t.EComponentType.BYTE:return new Int8Array(s,n,o);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,n,o);case t.EComponentType.SHORT:return new Int16Array(s,n,o);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,n,o);default:return new Float32Array(s,n,o)}},r.GetBufferFromAccessor=function(e,t){var n=e.bufferViews[t.bufferView],o=t.count*r.GetByteStrideFromType(t);return r.GetBufferFromBufferView(e,n,t.byteOffset,o,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"},o={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:[],needAlphaBlending:!1};r._DefaultMaterial=new e.ShaderMaterial("GLTFDefaultMaterial",t,n,o),r._DefaultMaterial.setColor4("u_emission",new e.Color4(.5,.5,.5,1))}return r._DefaultMaterial},r._DefaultMaterial=null,r})();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,o){return!1},t.prototype.loadRuntimeExtensionsAsync=function(e,t,r){return!1},t.prototype.loadBufferAsync=function(e,t,r,n,o){return!1},t.prototype.loadTextureBufferAsync=function(e,t,r,n){return!1},t.prototype.createTextureAsync=function(e,t,r,n,o){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,o,i,a){t.ApplyExtensions((function(e){return e.loadRuntimeAsync(r,n,o,i,a)}),(function(){setTimeout((function(){i(e.GLTFLoaderBase.CreateRuntime(n.json,r,o))}))}))},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,o,i,a){t.ApplyExtensions((function(e){return e.loadBufferAsync(r,n,o,i,a)}),(function(){e.GLTFLoaderBase.LoadBufferAsync(r,n,o,i,a)}))},t.LoadTextureAsync=function(e,r,n,o){t.LoadTextureBufferAsync(e,r,(function(i){return t.CreateTextureAsync(e,r,i,n,o)}),o)},t.LoadShaderStringAsync=function(r,n,o,i){t.ApplyExtensions((function(e){return e.loadShaderStringAsync(r,n,o,i)}),(function(){e.GLTFLoaderBase.LoadShaderStringAsync(r,n,o,i)}))},t.LoadMaterialAsync=function(r,n,o,i){t.ApplyExtensions((function(e){return e.loadMaterialAsync(r,n,o,i)}),(function(){e.GLTFLoaderBase.LoadMaterialAsync(r,n,o,i)}))},t.LoadTextureBufferAsync=function(r,n,o,i){t.ApplyExtensions((function(e){return e.loadTextureBufferAsync(r,n,o,i)}),(function(){e.GLTFLoaderBase.LoadTextureBufferAsync(r,n,o,i)}))},t.CreateTextureAsync=function(r,n,o,i,a){t.ApplyExtensions((function(e){return e.createTextureAsync(r,n,o,i,a)}),(function(){e.GLTFLoaderBase.CreateTextureAsync(r,n,o,i,a)}))},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,o,i){var a=r.json.extensionsUsed;return!(!a||-1===a.indexOf(this.name))&&(this._bin=r.bin,o(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,o){var i=t.textures[r],a=t.images[i.source];if(!(a.extensions&&this.name in a.extensions))return!1;var s=a.extensions[this.name],l=t.bufferViews[s.bufferView];return n(e.GLTFUtils.GetBufferFromBufferView(t,l,0,l.byteLength,e.EComponentType.UNSIGNED_BYTE)),!0},r.prototype.loadShaderStringAsync=function(t,r,n,o){var i=t.shaders[r];if(!(i.extensions&&this.name in i.extensions))return!1;var a=i.extensions[this.name],s=t.bufferViews[a.bufferView],l=e.GLTFUtils.GetBufferFromBufferView(t,s,0,s.byteLength,e.EComponentType.UNSIGNED_BYTE);return setTimeout((function(){var t=e.GLTFUtils.DecodeBufferToText(l);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 o=t.extensions[this.name];if(!o)return!1;var i=o.lights;if(i)for(var a in i){var s=i[a];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},n.prototype.loadMaterialAsync=function(t,r,n,o){var i=t.materials[r];if(!i||!i.extensions)return!1;var a=i.extensions[this.name];if(!a)return!1;var s=new e.StandardMaterial(r,t.scene);return s.sideOrientation=e.Material.CounterClockWiseSideOrientation,"CONSTANT"===a.technique&&(s.disableLighting=!0),s.backFaceCulling=void 0!==a.doubleSided&&!a.doubleSided,s.alpha=void 0===a.values.transparency?1:a.values.transparency,s.specularPower=void 0===a.values.shininess?0:a.values.shininess,"string"==typeof a.values.ambient?this._loadTexture(t,a.values.ambient,s,"ambientTexture",o):s.ambientColor=e.Color3.FromArray(a.values.ambient||[0,0,0]),"string"==typeof a.values.diffuse?this._loadTexture(t,a.values.diffuse,s,"diffuseTexture",o):s.diffuseColor=e.Color3.FromArray(a.values.diffuse||[0,0,0]),"string"==typeof a.values.emission?this._loadTexture(t,a.values.emission,s,"emissiveTexture",o):s.emissiveColor=e.Color3.FromArray(a.values.emission||[0,0,0]),"string"==typeof a.values.specular?this._loadTexture(t,a.values.specular,s,"specularTexture",o):s.specularColor=e.Color3.FromArray(a.values.specular||[0,0,0]),!0},n.prototype._loadTexture=function(e,r,n,o,i){t.GLTFLoaderBase.LoadTextureBufferAsync(e,r,(function(a){t.GLTFLoaderBase.CreateTextureAsync(e,r,a,(function(e){return n[o]=e}),i)}),i)},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,o,i,a){var s=this;this._loadAsync(e,t,r,n,(function(){o(s._getMeshes(),null,s._getSkeletons())}),i,a)},n.prototype.loadAsync=function(e,t,r,n,o,i){this._loadAsync(null,e,t,r,n,o,i)},n.prototype._loadAsync=function(e,r,n,o,i,a,s){var l=this;this._tryCatchOnError((function(){l._loadData(n),l._babylonScene=r,l._rootUrl=o,l._successCallback=i,l._progressCallback=a,l._errorCallback=s,t.GLTFUtils.AssignIndices(l._gltf.accessors),t.GLTFUtils.AssignIndices(l._gltf.animations),t.GLTFUtils.AssignIndices(l._gltf.buffers),t.GLTFUtils.AssignIndices(l._gltf.bufferViews),t.GLTFUtils.AssignIndices(l._gltf.images),t.GLTFUtils.AssignIndices(l._gltf.materials),t.GLTFUtils.AssignIndices(l._gltf.meshes),t.GLTFUtils.AssignIndices(l._gltf.nodes),t.GLTFUtils.AssignIndices(l._gltf.scenes),t.GLTFUtils.AssignIndices(l._gltf.skins),t.GLTFUtils.AssignIndices(l._gltf.textures),l._addPendingData(l),l._loadDefaultScene(e),l._loadAnimations(),l._removePendingData(l)}))},n.prototype._onError=function(t){this._disposed||(e.Tools.Error("glTF Loader: "+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._loadDefaultScene=function(e){var r=t.GLTFUtils.GetArrayItem(this._gltf.scenes,this._gltf.scene||0);if(!r)throw new Error("Failed to find scene "+(this._gltf.scene||0));this._loadScene("scenes["+r.index+"]",r,e)},n.prototype._loadScene=function(r,n,o){switch(this._rootNode={babylonMesh:new e.Mesh("__root__",this._babylonScene)},this._parent.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(this._rootNode.babylonMesh.rotation=new e.Vector3(0,Math.PI,0),this._rootNode.babylonMesh.scaling=new e.Vector3(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+")")}var i=n.nodes;if(this._traverseNodes(r,i,(function(e,t){return e.parent=t,!0}),this._rootNode),o){o instanceof Array||(o=[o]);var a=new Array;this._traverseNodes(r,i,(function(e){return-1===o.indexOf(e.name)||(a.push(e.index),!1)}),this._rootNode),i=a}for(var s=0;s<i.length;s++){var l=t.GLTFUtils.GetArrayItem(this._gltf.nodes,i[s]);if(!l)throw new Error(r+": Failed to find node "+i[s]);this._loadNode("nodes["+i[s]+"]",l)}this._rootNode.babylonMesh.setEnabled(!1)},n.prototype._loadNode=function(r,n){if(!t.GLTFLoaderExtension.LoadNode(this,r,n)){if(n.babylonMesh=new e.Mesh(n.name||"mesh"+n.index,this._babylonScene),this._loadTransform(n),null!=n.mesh){var o=t.GLTFUtils.GetArrayItem(this._gltf.meshes,n.mesh);if(!o)throw new Error(r+": Failed to find mesh "+n.mesh);this._loadMesh("meshes["+n.mesh+"]",n,o)}if(n.babylonMesh.parent=n.parent?n.parent.babylonMesh:null,n.babylonAnimationTargets=n.babylonAnimationTargets||[],n.babylonAnimationTargets.push(n.babylonMesh),null!=n.skin){var i=t.GLTFUtils.GetArrayItem(this._gltf.skins,n.skin);if(!i)throw new Error(r+": Failed to find skin "+n.skin);n.babylonMesh.skeleton=this._loadSkin("skins["+n.skin+"]",i)}if(n.camera,n.children)for(var a=0;a<n.children.length;a++){var s=t.GLTFUtils.GetArrayItem(this._gltf.nodes,n.children[a]);if(!s)throw new Error(r+": Failed to find child node "+n.children[a]);this._loadNode("nodes["+n.children[a]+"]",s)}}},n.prototype._loadMesh=function(t,r,n){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),a=new e.VertexData;a.positions=[],a.indices=[];for(var s=[],l=n.primitives.length,u=0;u<n.primitives.length;u++){var c=n.primitives[u];this._loadPrimitive(t+"/primitives["+u+"]",r,n,c,(function(t,n){if(s.push({verticesStart:a.positions.length,verticesCount:t.positions.length,indicesStart:a.indices.length,indicesCount:t.indices.length,loadMaterial:n}),a.merge(t),0==--l){i.setAllVerticesData(a,!1),r.babylonMesh.subMeshes=[];for(var o=0;o<s.length;o++){var u=s[o];new e.SubMesh(o,u.verticesStart,u.verticesCount,u.indicesStart,u.indicesCount,r.babylonMesh),u.loadMaterial(o)}}}))}},n.prototype._loadPrimitive=function(e,r,n,o,i){var a=this,s=r.babylonMesh.material.subMaterials;if(o.mode&&o.mode!==t.EMeshPrimitiveMode.TRIANGLES)throw new Error(e+": Mode "+o.mode+" is not currently supported");this._createMorphTargets(r,n,o),this._loadVertexDataAsync(e,n,o,(function(l){a._loadMorphTargetsData(e,n,o,l,r.babylonMesh),i(l,(function(n){if(null==o.material)s[n]=a._getDefaultMaterial();else{var i=t.GLTFUtils.GetArrayItem(a._gltf.materials,o.material);if(!i)throw new Error(e+": Failed to find material "+o.material);a._loadMaterial("materials["+i.index+"]",i,(function(e,t){t&&a._parent.onMaterialLoaded&&a._parent.onMaterialLoaded(e),a._parent.onBeforeMaterialReadyAsync?(a._addLoaderPendingData(i),a._parent.onBeforeMaterialReadyAsync(e,r.babylonMesh,null!=s[n],(function(){s[n]=e,a._removeLoaderPendingData(i)}))):s[n]=e}))}}))}))},n.prototype._loadVertexDataAsync=function(r,n,o,i){var a=this,s=o.attributes;if(!s)throw new Error(r+": Attributes are missing");var l,u=new e.VertexData,c=Object.keys(s).length,f=this;for(var d in s)!(function(n){if(!(l=t.GLTFUtils.GetArrayItem(f._gltf.accessors,s[n])))throw new Error(r+": Failed to find attribute '"+n+"' accessor "+s[n]);f._loadAccessorAsync("accessors["+l.index+"]",l,(function(s){switch(n){case"NORMAL":u.normals=s;break;case"POSITION":u.positions=s;break;case"TANGENT":u.tangents=s;break;case"TEXCOORD_0":u.uvs=s;break;case"TEXCOORD_1":u.uvs2=s;break;case"JOINTS_0":u.matricesIndices=new Float32Array(Array.prototype.slice.apply(s));break;case"WEIGHTS_0":u.matricesWeights=s;break;case"COLOR_0":u.colors=s;break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+n+"'")}if(0==--c)if(null==o.indices)u.indices=new Uint32Array(u.positions.length/3),u.indices.forEach((function(e,t){return u.indices[t]=t})),i(u);else{var l=t.GLTFUtils.GetArrayItem(a._gltf.accessors,o.indices);if(!l)throw new Error(r+": Failed to find indices accessor "+o.indices);a._loadAccessorAsync("accessors["+l.index+"]",l,(function(e){u.indices=e,i(u)}))}}))})(d)},n.prototype._createMorphTargets=function(t,r,n){var o=n.targets;if(o){t.babylonMesh.morphTargetManager||(t.babylonMesh.morphTargetManager=new e.MorphTargetManager);for(var i=0;i<o.length;i++){var a=t.weights?t.weights[i]:r.weights?r.weights[i]:0;t.babylonMesh.morphTargetManager.addTarget(new e.MorphTarget("morphTarget"+i,a))}}},n.prototype._loadMorphTargetsData=function(r,n,o,i,a){var s=o.targets;if(s)for(var l,u,c=this,f=0;f<s.length;f++)!(function(){var n=a.morphTargetManager.getTarget(f);l=s[f];for(var o in l)!(function(o){if(!(u=t.GLTFUtils.GetArrayItem(c._gltf.accessors,l[o])))throw new Error(r+"/targets["+f+"]: Failed to find attribute '"+o+"' accessor "+l[o]);c._loadAccessorAsync("accessors["+u.index+"]",u,(function(r){u.name&&(n.name=u.name);var a=r;switch(o){case"NORMAL":t.GLTFUtils.ForEach(a,(function(e,t){return a[t]+=i.normals[t]})),n.setNormals(a);break;case"POSITION":t.GLTFUtils.ForEach(a,(function(e,t){return a[t]+=i.positions[t]})),n.setPositions(a);break;case"TANGENT":for(var s=0,l=0;s<a.length;s++,l++)a[s]+=i.tangents[l],(s+1)%3==0&&l++;n.setTangents(a);break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+o+"'")}}))})(o)})()},n.prototype._loadTransform=function(t){var r=e.Vector3.Zero(),n=e.Quaternion.Identity(),o=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(o,n,r)}else t.translation&&(r=e.Vector3.FromArray(t.translation)),t.rotation&&(n=e.Quaternion.FromArray(t.rotation)),t.scale&&(o=e.Vector3.FromArray(t.scale));t.babylonMesh.position=r,t.babylonMesh.rotationQuaternion=n,t.babylonMesh.scaling=o},n.prototype._loadSkin=function(r,n){var o=this,i="skeleton"+n.index;if(n.babylonSkeleton=new e.Skeleton(n.name||i,i,this._babylonScene),null==n.inverseBindMatrices)this._loadBones(r,n,null);else{var a=t.GLTFUtils.GetArrayItem(this._gltf.accessors,n.inverseBindMatrices);if(!a)throw new Error(r+": Failed to find inverse bind matrices attribute "+n.inverseBindMatrices);this._loadAccessorAsync("accessors["+a.index+"]",a,(function(e){o._loadBones(r,n,e)}))}return n.babylonSkeleton},n.prototype._createBone=function(t,r,n,o,i,a){var s=new e.Bone(t.name||"bone"+t.index,r.babylonSkeleton,n,o,null,i,a);return t.babylonBones=t.babylonBones||{},t.babylonBones[r.index]=s,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(s),s},n.prototype._loadBones=function(e,r,n){for(var o={},i=0;i<r.joints.length;i++){var a=t.GLTFUtils.GetArrayItem(this._gltf.nodes,r.joints[i]);if(!a)throw new Error(e+": Failed to find joint "+r.joints[i]);this._loadBone(a,r,n,o)}},n.prototype._loadBone=function(t,r,n,o){var i=o[t.index];if(i)return i;var a=r.joints.indexOf(t.index),s=e.Matrix.Identity();n&&-1!==a&&(s=e.Matrix.FromArray(n,16*a),s.invertToRef(s));var l;return t.index!==r.skeleton&&t.parent!==this._rootNode&&(l=this._loadBone(t.parent,r,n,o),s.multiplyToRef(l.getInvertedAbsoluteTransform(),s)),i=this._createBone(t,r,l,this._getNodeMatrix(t),s,a),o[t.index]=i,i},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,r,n,o){void 0===o&&(o=null);for(var i=0;i<r.length;i++){var a=t.GLTFUtils.GetArrayItem(this._gltf.nodes,r[i]);if(!a)throw new Error(e+": Failed to find node "+r[i]);this._traverseNode(e,a,n,o)}},n.prototype._traverseNode=function(e,r,n,o){void 0===o&&(o=null),t.GLTFLoaderExtension.TraverseNode(this,e,r,n,o)||n(r,o)&&r.children&&this._traverseNodes(e,r.children,n,r)},n.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e)for(var r=0;r<e.length;r++)for(var n=e[r],o="animations["+r+"]",i=0;i<n.channels.length;i++){var a=t.GLTFUtils.GetArrayItem(n.channels,i);if(!a)throw new Error(o+": Failed to find channel "+i);var s=t.GLTFUtils.GetArrayItem(n.samplers,a.sampler);if(!s)throw new Error(o+": Failed to find sampler "+a.sampler);this._loadAnimationChannel(n,o+"/channels["+i+"]",a,o+"/samplers["+a.sampler+"]",s)}},n.prototype._loadAnimationChannel=function(r,n,o,i,a){var s=t.GLTFUtils.GetArrayItem(this._gltf.nodes,o.target.node);if(!s)throw new Error(n+": Failed to find target node "+o.target.node);var l={translation:"position",rotation:"rotationQuaternion",scale:"scaling",weights:"influence"}[o.target.path];if(!l)throw new Error(n+": Invalid target path '"+o.target.path+"'");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){var t=0,n={position:function(){var r=e.Vector3.FromArray(c,t);return t+=3,r},rotationQuaternion:function(){var r=e.Quaternion.FromArray(c,t);return t+=4,r},scaling:function(){var r=e.Vector3.FromArray(c,t);return t+=3,r},influence:function(){for(var e=s.babylonMesh.morphTargetManager.numTargets,r=new Array(e),n=0;n<e;n++)r[n]=c[t++];return r}}[l],o={LINEAR:function(e){return{frame:u[e],value:n()}},CUBICSPLINE:function(e){return{frame:u[e],inTangent:n(),value:n(),outTangent:n()}}}[a.interpolation];if(!o)throw new Error(i+": Invalid interpolation '"+a.interpolation+"'");for(var d=new Array(u.length),h=0;h<u.length;h++)d[h]=o(h);if(r.targets=r.targets||[],"influence"===l)for(var p=s.babylonMesh.morphTargetManager,m=0;m<p.numTargets;m++){var T=p.getTarget(m),E=(r.name||"anim"+r.index)+"_"+m,_=new e.Animation(E,l,1,f);_.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(_),r.targets.push(T)}else{var E=r.name||"anim"+r.index,_=new e.Animation(E,l,1,f);_.setKeys(d)
- ;for(var A=0;A<s.babylonAnimationTargets.length;A++){var y=s.babylonAnimationTargets[A];y.animations.push(_.clone()),r.targets.push(y)}}}},h=t.GLTFUtils.GetArrayItem(this._gltf.accessors,a.input);if(!h)throw new Error(i+": Failed to find input accessor "+a.input);this._loadAccessorAsync("accessors["+h.index+"]",h,(function(e){u=e,d()}));var p=t.GLTFUtils.GetArrayItem(this._gltf.accessors,a.output);if(!p)throw new Error(i+": Failed to find output accessor "+a.output);this._loadAccessorAsync("accessors["+p.index+"]",p,(function(e){c=e,d()}))},n.prototype._loadBufferAsync=function(r,n,o){var i=this;if(this._addPendingData(n),n.loadedData)o(n.loadedData),this._removePendingData(n);else if(n.loadedObservable)n.loadedObservable.add((function(e){o(e.loadedData),i._removePendingData(e)}));else{if(!n.uri)throw new Error(r+": Uri is missing");if(t.GLTFUtils.IsBase64(n.uri)){var a=t.GLTFUtils.DecodeBase64(n.uri);n.loadedData=new Uint8Array(a),o(n.loadedData),this._removePendingData(n)}else{if(!t.GLTFUtils.ValidateUri(n.uri))throw new Error(r+": Uri '"+n.uri+"' is invalid");n.loadedObservable=new e.Observable,n.loadedObservable.add((function(e){o(e.loadedData),i._removePendingData(e)})),e.Tools.LoadFile(this._rootUrl+n.uri,(function(e){i._tryCatchOnError((function(){n.loadedData=new Uint8Array(e),n.loadedObservable.notifyObservers(n),n.loadedObservable=null}))}),(function(e){i._tryCatchOnError((function(){i._onProgress(e)}))}),this._babylonScene.database,!0,(function(e){i._tryCatchOnError((function(){throw new Error(r+": Failed to load '"+n.uri+"'"+(e?": "+e.status+" "+e.statusText:""))}))}))}}},n.prototype._loadBufferViewAsync=function(e,r,n){var o=this,i=t.GLTFUtils.GetArrayItem(this._gltf.buffers,r.buffer);if(!i)throw new Error(e+": Failed to find buffer "+r.buffer);this._loadBufferAsync("buffers["+i.index+"]",i,(function(t){if(!o._disposed){try{var i=new Uint8Array(t.buffer,t.byteOffset+(r.byteOffset||0),r.byteLength)}catch(t){throw new Error(e+": "+t.message)}n(i)}}))},n.prototype._loadAccessorAsync=function(e,r,n){var o=this;if(r.sparse)throw new Error(e+": Sparse accessors are not currently supported");if(r.normalized)throw new Error(e+": Normalized accessors are not currently supported");var i=t.GLTFUtils.GetArrayItem(this._gltf.bufferViews,r.bufferView);if(!i)throw new Error(e+": Failed to find buffer view "+r.bufferView);this._loadBufferViewAsync("bufferViews["+i.index+"]",i,(function(a){var s=o._getNumComponentsOfType(r.type);if(0===s)throw new Error(e+": Invalid type ("+r.type+")");var l;switch(r.componentType){case t.EComponentType.BYTE:l=o._buildArrayBuffer(Float32Array,e,a,r.byteOffset,r.count,s,i.byteStride);break;case t.EComponentType.UNSIGNED_BYTE:l=o._buildArrayBuffer(Uint8Array,e,a,r.byteOffset,r.count,s,i.byteStride);break;case t.EComponentType.SHORT:l=o._buildArrayBuffer(Int16Array,e,a,r.byteOffset,r.count,s,i.byteStride);break;case t.EComponentType.UNSIGNED_SHORT:l=o._buildArrayBuffer(Uint16Array,e,a,r.byteOffset,r.count,s,i.byteStride);break;case t.EComponentType.UNSIGNED_INT:l=o._buildArrayBuffer(Uint32Array,e,a,r.byteOffset,r.count,s,i.byteStride);break;case t.EComponentType.FLOAT:l=o._buildArrayBuffer(Float32Array,e,a,r.byteOffset,r.count,s,i.byteStride);break;default:throw new Error(e+": Invalid component type ("+r.componentType+")")}n(l)}))},n.prototype._getNumComponentsOfType=function(e){switch(e){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}return 0},n.prototype._buildArrayBuffer=function(e,t,r,n,o,i,a){try{var n=r.byteOffset+(n||0),s=o*i;if(null==a||a===i*e.BYTES_PER_ELEMENT)return new e(r.buffer,n,s);for(var l=a/e.BYTES_PER_ELEMENT,u=new e(r.buffer,n,l*o),c=new e(s),f=0,d=0;d<s;){for(var h=0;h<i;h++)c[d]=u[f+h],d++;f+=l}return c}catch(e){throw new Error(t+": "+e)}},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,o=new r(function(){n._loaderTrackers.splice(n._loaderTrackers.indexOf(o)),t()});this._loaderTrackers.push(o),this._addLoaderPendingData(o),e(),this._removeLoaderPendingData(o)},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(r,n){var o=n.babylonMaterial;o.metallic=1,o.roughness=1;var i=n.pbrMetallicRoughness;if(i){if(o.albedoColor=i.baseColorFactor?e.Color3.FromArray(i.baseColorFactor):new e.Color3(1,1,1),o.metallic=null==i.metallicFactor?1:i.metallicFactor,o.roughness=null==i.roughnessFactor?1:i.roughnessFactor,i.baseColorTexture){var a=t.GLTFUtils.GetArrayItem(this._gltf.textures,i.baseColorTexture.index);if(!a)throw new Error(r+": Failed to find base color texture "+i.baseColorTexture.index);o.albedoTexture=this._loadTexture("textures["+a.index+"]",a,i.baseColorTexture.texCoord)}if(i.metallicRoughnessTexture){var a=t.GLTFUtils.GetArrayItem(this._gltf.textures,i.metallicRoughnessTexture.index);if(!a)throw new Error(r+": Failed to find metallic roughness texture "+i.metallicRoughnessTexture.index);o.metallicTexture=this._loadTexture("textures["+a.index+"]",a,i.metallicRoughnessTexture.texCoord),o.useMetallnessFromMetallicTextureBlue=!0,o.useRoughnessFromMetallicTextureGreen=!0,o.useRoughnessFromMetallicTextureAlpha=!1}this._loadMaterialAlphaProperties(r,n,i.baseColorFactor)}},n.prototype._loadMaterial=function(e,r,n){if(r.babylonMaterial)return void n(r.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,r,n)||(this._createPbrMaterial(r),this._loadMaterialBaseProperties(e,r),this._loadMaterialMetallicRoughnessProperties(e,r),n(r.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(r,n){var o=n.babylonMaterial;if(o.emissiveColor=n.emissiveFactor?e.Color3.FromArray(n.emissiveFactor):new e.Color3(0,0,0),n.doubleSided&&(o.backFaceCulling=!1,o.twoSidedLighting=!0),n.normalTexture){var i=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.normalTexture.index);if(!i)throw new Error(r+": Failed to find normal texture "+n.normalTexture.index);o.bumpTexture=this._loadTexture("textures["+i.index+"]",i,n.normalTexture.texCoord),o.invertNormalMapX=!this._babylonScene.useRightHandedSystem,o.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=n.normalTexture.scale&&(o.bumpTexture.level=n.normalTexture.scale)}if(n.occlusionTexture){var i=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.occlusionTexture.index);if(!i)throw new Error(r+": Failed to find occlusion texture "+n.occlusionTexture.index);o.ambientTexture=this._loadTexture("textures["+i.index+"]",i,n.occlusionTexture.texCoord),o.useAmbientInGrayScale=!0,null!=n.occlusionTexture.strength&&(o.ambientTextureStrength=n.occlusionTexture.strength)}if(n.emissiveTexture){var i=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.emissiveTexture.index);if(!i)throw new Error(r+": Failed to find emissive texture "+n.emissiveTexture.index);o.emissiveTexture=this._loadTexture("textures["+i.index+"]",i,n.emissiveTexture.texCoord)}},n.prototype._loadMaterialAlphaProperties=function(e,t,r){var n=t.babylonMaterial;switch(t.alphaMode||"OPAQUE"){case"OPAQUE":break;case"MASK":n.alphaCutOff=null==t.alphaCutoff?.5:t.alphaCutoff,r&&(0==r[3]?n.alphaCutOff=1:n.alphaCutOff/=r[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":r&&(n.alpha=r[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(e+": Invalid alpha mode '"+t.alphaMode+"'")}},n.prototype._loadTexture=function(r,n,o){var i=this,a=null==n.sampler?{}:t.GLTFUtils.GetArrayItem(this._gltf.samplers,n.sampler);if(!a)throw new Error(r+": Failed to find sampler "+n.sampler);var s=a.minFilter===t.ETextureMinFilter.NEAREST||a.minFilter===t.ETextureMinFilter.LINEAR,l=t.GLTFUtils.GetTextureSamplingMode(a.magFilter,a.minFilter);this._addPendingData(n);var u=new e.Texture(null,this._babylonScene,s,!1,l,function(){i._tryCatchOnError((function(){i._removePendingData(n)}))},function(e){i._tryCatchOnError((function(){throw new Error(r+": "+e)}))});if(n.url)u.updateURL(n.url);else if(n.dataReadyObservable)n.dataReadyObservable.add((function(e){u.updateURL(e.url)}));else{n.dataReadyObservable=new e.Observable,n.dataReadyObservable.add((function(e){u.updateURL(e.url)}));var c=t.GLTFUtils.GetArrayItem(this._gltf.images,n.source);if(!c)throw new Error(r+": Failed to find source "+n.source);this._loadImage("images["+c.index+"]",c,(function(e){n.url=URL.createObjectURL(new Blob([e],{type:c.mimeType})),n.dataReadyObservable.notifyObservers(n)}))}return u.coordinatesIndex=o||0,u.wrapU=t.GLTFUtils.GetTextureWrapMode(a.wrapS),u.wrapV=t.GLTFUtils.GetTextureWrapMode(a.wrapT),u.name=n.name||"texture"+n.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(u),u},n.prototype._loadImage=function(r,n,o){var i=this;if(n.uri){if(!t.GLTFUtils.ValidateUri(n.uri))throw new Error(r+": Uri '"+n.uri+"' is invalid");t.GLTFUtils.IsBase64(n.uri)?o(new Uint8Array(t.GLTFUtils.DecodeBase64(n.uri))):e.Tools.LoadFile(this._rootUrl+n.uri,(function(e){i._tryCatchOnError((function(){o(e)}))}),(function(e){i._tryCatchOnError((function(){i._onProgress(e)}))}),this._babylonScene.database,!0,(function(e){i._tryCatchOnError((function(){throw new Error(r+": Failed to load '"+n.uri+"'"+(e?": "+e.status+" "+e.statusText:""))}))}))}else{var a=t.GLTFUtils.GetArrayItem(this._gltf.bufferViews,n.bufferView);if(!a)throw new Error(r+": Failed to find buffer view "+n.bufferView);this._loadBufferViewAsync("bufferViews["+a.index+"]",a,o)}},n.prototype._tryCatchOnError=function(e){try{e()}catch(e){this._onError(e.message)}},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 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)),o=0;o<r;o++)n[o]=t.charCodeAt(o);return n.buffer},r.ForEach=function(e,t){for(var r=0;r<e.length;r++)t(e[r],r)},r.ValidateUri=function(e){return-1===e.indexOf("..")},r.AssignIndices=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},r.GetArrayItem=function(e,t){return e&&e[t]?e[t]:null},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,o){return!1},e.prototype._loadNode=function(e,t,r){return!1},e.prototype._loadMaterial=function(e,t,r,n){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,o){return this._ApplyExtensions((function(i){return i._traverseNode(e,t,r,n,o)}))},e.LoadNode=function(e,t,r){return this._ApplyExtensions((function(n){return n._loadNode(e,t,r)}))},e.LoadMaterial=function(e,t,r,n){return this._ApplyExtensions((function(o){return o._loadMaterial(e,t,r,n)}))},e._ApplyExtensions=function(t){var r=e._Extensions;if(r){for(var n=0;n<r.length;n++){var o=r[n];if(o.enabled&&t(o))return!0}return!1}},e._Extensions=[],e})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n=(function(r){function n(){return null!==r&&r.apply(this,arguments)||this}return __extends(n,r),Object.defineProperty(n.prototype,"name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),n.prototype._traverseNode=function(e,r,n,o,i){return this._loadExtension(n,(function(a,s){for(var l=a.ids.length-1;l>=0;l--){var u=t.GLTFUtils.GetArrayItem(e._gltf.nodes,a.ids[l]);if(!u)throw new Error(r+": Failed to find node "+a.ids[l]);e._traverseNode(r,u,o,i)}e._traverseNode(r,n,o,i),s()}))},n.prototype._loadNode=function(e,t,r){var n=this;return this._loadExtension(r,(function(o,i){var a=[r.index].concat(o.ids).map((function(t){return e._gltf.nodes[t]}));e._addLoaderPendingData(r),n._loadNodeLOD(e,t,a,a.length-1,(function(){e._removeLoaderPendingData(r),i()}))}))},n.prototype._loadNodeLOD=function(e,t,r,o,i){var a=this;e._whenAction((function(){e._loadNode(t,r[o])}),(function(){if(o!==r.length-1){r[o+1].babylonMesh.setEnabled(!1)}if(0===o)return void i();setTimeout((function(){a._loadNodeLOD(e,t,r,o-1,i)}),n.MinimalLODDelay)}))},n.prototype._loadMaterial=function(e,t,r,n){var o=this;return this._loadExtension(r,(function(i,a){var s=[r.index].concat(i.ids).map((function(t){return e._gltf.materials[t]}));e._addLoaderPendingData(r),o._loadMaterialLOD(e,t,s,s.length-1,n,(function(){r.extensions[o.name]=i,e._removeLoaderPendingData(r),a()}))}))},n.prototype._loadMaterialLOD=function(t,r,o,i,a,s){var l=this;t._loadMaterial(r,o[i],(function(u,c){if(a(u,c),0===i)return void s();t._executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(u.getActiveTextures(),(function(){setTimeout((function(){l._loadMaterialLOD(t,r,o,i-1,a,s)}),n.MinimalLODDelay)}))}))}))},n.MinimalLODDelay=250,n})(t.GLTFLoaderExtension);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(r){function n(){return null!==r&&r.apply(this,arguments)||this}return __extends(n,r),Object.defineProperty(n.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),n.prototype._loadMaterial=function(e,t,r,n){var o=this;return this._loadExtension(r,(function(i,a){e._createPbrMaterial(r),e._loadMaterialBaseProperties(t,r),o._loadSpecularGlossinessProperties(e,t,r,i),n(r.babylonMaterial,!0)}))},n.prototype._loadSpecularGlossinessProperties=function(r,n,o,i){var a=o.babylonMaterial;if(a.albedoColor=i.diffuseFactor?e.Color3.FromArray(i.diffuseFactor):new e.Color3(1,1,1),a.reflectivityColor=i.specularFactor?e.Color3.FromArray(i.specularFactor):new e.Color3(1,1,1),a.microSurface=null==i.glossinessFactor?1:i.glossinessFactor,i.diffuseTexture){var s=t.GLTFUtils.GetArrayItem(r._gltf.textures,i.diffuseTexture.index);if(!s)throw new Error(n+": Failed to find diffuse texture "+i.diffuseTexture.index);a.albedoTexture=r._loadTexture("textures["+s.index+"]",s,i.diffuseTexture.texCoord)}if(i.specularGlossinessTexture){var s=t.GLTFUtils.GetArrayItem(r._gltf.textures,i.specularGlossinessTexture.index);if(!s)throw new Error(n+": Failed to find diffuse texture "+i.specularGlossinessTexture.index);a.reflectivityTexture=r._loadTexture("textures["+s.index+"]",s,i.specularGlossinessTexture.texCoord),a.reflectivityTexture.hasAlpha=!0,a.useMicroSurfaceFromReflectivityMapAlpha=!0}r._loadMaterialAlphaProperties(n,o,i.diffuseFactor)},n})(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}));
|