123 |
- var globalObject="undefined"!=typeof global?global:"undefined"!=typeof window?window:this,babylonDependency=globalObject&&globalObject.BABYLON||BABYLON||"undefined"!=typeof require&&require("babylonjs"),BABYLON=babylonDependency,__decorate=this&&this.__decorate||function(e,t,r,n){var o,a=arguments.length,i=a<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--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>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,o,a,i,s){var l;if(this.isBinary(n)){var u=new e.Mesh("stlmesh",r);return this.parseBinary(u,n),a&&a.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]),a&&a.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)>127)return!0;return!1},t.prototype.parseBinary=function(t,r){for(var n=new DataView(r),o=n.getUint32(80,!0),a=0,i=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;i[a]=n.getFloat32(T,!0),i[a+2]=n.getFloat32(T+4,!0),i[a+1]=n.getFloat32(T+8,!0),s[a]=d,s[a+2]=h,s[a+1]=p,a+=3}l[u]=u++,l[u]=u++,l[u]=u++}t.setVerticesData(e.VertexBuffer.PositionKind,i),t.setVerticesData(e.VertexBuffer.NormalKind,s),t.setIndices(l),t.computeWorldMatrix(!0)},t.prototype.parseASCII=function(t,r){for(var n,o=[],a=[],i=[],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])),a.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,o),t.setVerticesData(e.VertexBuffer.NormalKind,a),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=[]}return t.prototype.parseMTL=function(r,n,o){for(var a,i=n.split("\n"),s=null,l=0;l<i.length;l++){var u=i[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?(s&&this.materials.push(s),s=new e.StandardMaterial(d,r)):"kd"===f&&s?(a=d.split(/\s+/,3).map(parseFloat),s.diffuseColor=e.Color3.FromArray(a)):"ka"===f&&s?(a=d.split(/\s+/,3).map(parseFloat),s.ambientColor=e.Color3.FromArray(a)):"ks"===f&&s?(a=d.split(/\s+/,3).map(parseFloat),s.specularColor=e.Color3.FromArray(a)):"ke"===f&&s?(a=d.split(/\s+/,3).map(parseFloat),s.emissiveColor=e.Color3.FromArray(a)):"ns"===f&&s?s.specularPower=parseFloat(d):"d"===f&&s?s.alpha=parseFloat(d):"map_ka"===f&&s?s.ambientTexture=t._getTexture(o,d,r):"map_kd"===f&&s?s.diffuseTexture=t._getTexture(o,d,r):"map_ks"===f&&s?s.specularTexture=t._getTexture(o,d,r):"map_ns"===f||("map_bump"===f&&s?s.bumpTexture=t._getTexture(o,d,r):"map_d"===f&&s&&(s.opacityTexture=t._getTexture(o,d,r)))}}s&&this.materials.push(s)},t._getTexture=function(t,r,n){if(!r)return null;var o=t;if("file:"===t){var a=r.lastIndexOf("\\");-1===a&&(a=r.lastIndexOf("/")),o+=a>-1?r.substr(a+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,void 0,void 0,!1,(function(){console.warn("Error - Unable to load "+o)}))},r.prototype.importMesh=function(e,t,r,n,o,a,i){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,a,i){for(var s,l=[],u=[],c=[],f=[],d=[],h=[],p=[],m=[],T=[],E=0,_=!1,A=[],y=[],g=[],v=[],L="",x="",b=new t,N=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},R=function(e,t,n,o,a,i){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(a),m.push(i),T[e].normals.push(n),T[e].idx.push(E++),r.OPTIMIZE_WITH_UV&&T[e].uv.push(t)):d.push(s)},S=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},I=function(e,t){t+1<e.length&&(v.push(e[0],e[t],e[t+1]),t+=1,I(e,t))},w=function(){f.length>0&&(s=f[f.length-1],S(),d.reverse(),s.indices=d.slice(),s.positions=A.slice(),s.normals=y.slice(),s.uvs=g.slice(),d=[],A=[],y=[],g=[])},P=a.split("\n"),B=0;B<P.length;B++){var C,G=P[B].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){I(e,t);for(var r=0;r<v.length;r++){var n=v[r].split("/"),o=parseInt(n[0])-1,a=parseInt(n[1])-1,i=parseInt(n[2])-1;R(o,a,i,l[o],c[a],u[i])}v=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern4.exec(G)))!(function(t,r){I(t,r);for(var n=0;n<v.length;n++){var o=v[n].split("//"),a=parseInt(o[0])-1,i=parseInt(o[1])-1;R(a,1,i,l[a],e.Vector2.Zero(),u[i])}v=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern2.exec(G)))!(function(t,r){I(t,r);for(var n=0;n<v.length;n++){var o=v[n].split("/"),a=parseInt(o[0])-1,i=parseInt(o[1])-1;R(a,i,0,l[a],c[i],e.Vector3.Up())}v=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern1.exec(G)))!(function(t,r){I(t,r);for(var n=0;n<v.length;n++){var o=parseInt(v[n])-1;R(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 D={name:G.substring(2).trim(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:""};w(),f.push(D),_=!0,M=!0,N=1}else if(this.usemtl.test(G)){if(L=G.substring(7).trim(),!M){w();var D={name:"_mm"+N.toString(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:L};N++,f.push(D)}_&&M&&(f[f.length-1].materialName=L,M=!1)}else this.mtllib.test(G)?x=G.substring(7).trim():this.smooth.test(G)||console.log("Unhandled expression at line : "+G)}_&&(s=f[f.length-1],d.reverse(),S(),s.indices=d,s.positions=A,s.normals=y,s.uvs=g),_||(d.reverse(),S(),f.push({name:e.Geometry.RandomId(),indices:d,positions:A,normals:y,uvs:g,materialName:L}));for(var V=[],U=new Array,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,o);U.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),V.push(H)}return""!==x&&this._loadMTL(x,i,(function(e){b.parseMTL(o,e,i);for(var t=0;t<b.materials.length;t++){for(var r,n=0,a=[];(r=U.indexOf(b.materials[t].name,n))>-1;)a.push(r),n=r+1;if(-1==r&&0==a.length)b.materials[t].dispose();else for(var s=0;s<a.length;s++)V[a[s]].material=b.materials[t]}})),V},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.dispose=function(){this._loader&&this._loader.dispose()},e.prototype.importMeshAsync=function(t,r,n,o,a,i,s){try{var l=e._parse(n);this.onParsed&&this.onParsed(l),this._loader=this._getLoader(l),this._loader.importMeshAsync(t,r,l,o,a,i,s)}catch(e){s(e.message)}},e.prototype.loadAsync=function(t,r,n,o,a,i){try{var s=e._parse(r);this.onParsed&&this.onParsed(s),this._loader=this._getLoader(s),this._loader.loadAsync(t,s,n,o,a,i)}catch(e){i(e.message)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e.prototype.createPlugin=function(){return new e},e._parse=function(t){return t instanceof ArrayBuffer?e._parseBinary(t):{json:JSON.parse(t),bin:null}},e.prototype._getLoader=function(t){var r={major:2,minor:0},n=t.json.asset||{},o=e._parseVersion(n.version);if(!o)throw new Error("Invalid version: "+n.version);if(void 0!==n.minVersion){var a=e._parseVersion(n.minVersion);if(!a)throw new Error("Invalid minimum version: "+n.minVersion);if(e._compareVersion(a,r)>0)throw new Error("Incompatible minimum version: "+n.minVersion)}var i={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},s=i[o.major];if(!s)throw new Error("Unsupported version: "+n.version);return s(this)},e._parseBinary=function(t){var r={Magic:1179937895},o=new n(t),a=o.readUint32();if(a!==r.Magic)throw new Error("Unexpected magic: "+a);var i=o.readUint32();switch(i){case 1:return e._parseV1(o);case 2:return e._parseV2(o)}throw new Error("Unsupported version: "+i)},e._parseV1=function(t){var r={JSON:0},n=t.readUint32();if(n!=t.getLength())throw new Error("Length in header does not match actual data length: "+n+" != "+t.getLength());var o,a=t.readUint32(),i=t.readUint32();switch(i){case r.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(a)));break;default:throw new Error("Unexpected content format: "+i)}var s=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(s)}},e._parseV2=function(t){var r={JSON:1313821514,BIN:5130562},n=t.readUint32();if(n!==t.getLength())throw new Error("Length in header does not match actual data length: "+n+" != "+t.getLength());var o=t.readUint32();if(t.readUint32()!==r.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),i=null;t.getPosition()<t.getLength();){var s=t.readUint32();switch(t.readUint32()){case r.JSON:throw new Error("Unexpected JSON chunk");case r.BIN:i=t.readUint8Array(s);break;default:t.skipBytes(s)}}return{json:a,bin:i}},e._parseVersion=function(e){var t=(e+"").match(/^(\d+)\.(\d+)$/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null},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"],a=["world","view","projection","worldView","worldViewProjection","mBones"],i=["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(e.semantic&&-1!==e.semantic.indexOf("TEXCOORD_")){var t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}return null},h=function(r){for(var n in r.animations){var o=r.animations[n];if(o.channels&&o.samplers)for(var a=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=i.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,x=!1;E&&a&&a.getKeys().length===h.length&&(g=a,x=!0),x||(g=new e.Animation(n,E?"_matrix":_,1,y,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var b=0;b<h.length;b++){var N=null;if("rotationQuaternion"===_?(N=e.Quaternion.FromArray([p[L],p[L+1],p[L+2],p[L+3]]),L+=4):(N=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,R=e.Vector3.Zero(),S=M.getBaseMatrix();x&&a&&(S=a.getKeys()[b].value),S.decompose(R,F,O),"position"===_?O=N:"rotationQuaternion"===_?F=N:R=N,N=e.Matrix.Compose(R,F,O)}x?a&&(a.getKeys()[b].value=N):v.push({frame:h[b],value:N})}!x&&g&&(g.setKeys(v),T.animations.push(g)),a=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]),a=e.Vector3.FromArray(t.translation||[0,0,0]);r=e.Matrix.Compose(n,o,a)}else r=e.Matrix.FromArray(t.matrix);return r},m=function(t,r,n,o){for(var a=0;a<o.bones.length;a++)if(o.bones[a].name===n)return o.bones[a];var i=t.nodes;for(var s in i){var l=i[s];if(l.jointName)for(var u=l.children,a=0;a<u.length;a++){var c=t.nodes[u[a]];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 a=n.node.children[o];if(a===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 a in t.nodes){var i=t.nodes[a],s=a;if(i.jointName&&!_(n,i.jointName)){var l=p(i),u=new e.Bone(i.name||"",r,null,l);u.id=s,o.push({bone:u,node:i,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(t,r,n,o,a){if(o||(o=new e.Skeleton(r.name||"","",t.scene)),!r.babylonSkeleton)return o;var i=[],s=[];A(t,o,r,i),o.bones=[];for(var l=0;l<r.jointNames.length;l++){var u=E(t,r.jointNames[l]);if(u){var c=u.node;if(c){var a=u.id,f=t.scene.getBoneByID(a);if(f)o.bones.push(f);else{for(var d=!1,h=null,_=0;_<l;_++){var y=E(t,r.jointNames[_]);if(y){var g=y.node;if(g){var v=g.children;if(v){d=!1;for(var L=0;L<v.length;L++)if(v[L]===a){h=m(t,r,r.jointNames[_],o),d=!0;break}if(d)break}}else e.Tools.Warn("Joint named "+r.jointNames[_]+" does not exist when looking for parent")}}var x=p(c);!h&&i.length>0&&(h=T(i,a))&&-1===s.indexOf(h)&&s.push(h);new e.Bone(c.jointName||"",o,h,x).id=a}}else e.Tools.Warn("Joint named "+r.jointNames[l]+" does not exist")}}var b=o.bones;o.bones=[];for(var l=0;l<r.jointNames.length;l++){var u=E(t,r.jointNames[l]);if(u)for(var _=0;_<b.length;_++)if(b[_].id===u.id){o.bones.push(b[_]);break}}o.prepare();for(var l=0;l<s.length;l++)o.bones.push(s[l]);return o},g=function(r,n,o,a,i){if(i||(i=new e.Mesh(n.name||"",r.scene),i.id=a),!n.babylonNode)return i;var s=new e.MultiMaterial("multimat"+a,r.scene);i.material||(i.material=s);for(var l=new e.VertexData,u=new e.Geometry(a,r.scene,l,!1,i),c=new Array,d=new Array,h=new Array,p=new Array,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 x in g)if(v=r.accessors[g[x]],L=t.GLTFUtils.GetBufferFromAccessor(r,v),"NORMAL"===x)A.normals=new Float32Array(L.length),A.normals.set(L);else if("POSITION"===x){if(e.GLTFFileLoader.HomogeneousCoordinates){A.positions=new Float32Array(L.length-L.length/4);for(var b=0;b<L.length;b+=4)A.positions[b]=L[b],A.positions[b+1]=L[b+1],A.positions[b+2]=L[b+2]}else A.positions=new Float32Array(L.length),A.positions.set(L);d.push(A.positions.length)}else if(-1!==x.indexOf("TEXCOORD_")){var N=Number(x.split("_")[1]),M=e.VertexBuffer.UVKind+(0===N?"":N+1),O=new Float32Array(L.length);O.set(L),f(O),A.set(O,M)}else"JOINT"===x?(A.matricesIndices=new Float32Array(L.length),A.matricesIndices.set(L)):"WEIGHT"===x?(A.matricesWeights=new Float32Array(L.length),A.matricesWeights.set(L)):"COLOR"===x&&(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=[],b=0;b<A.positions.length/3;b++)F.push(b);A.indices=new Int32Array(F),p.push(A.indices.length)}l.merge(A);var R=r.scene.getMaterialByID(y.material);s.subMaterials.push(null===R?t.GLTFUtils.GetDefaultMaterial(r.scene):R),c.push(0===c.length?0:c[c.length-1]+d[d.length-2]),h.push(0===h.length?0:h[h.length-1]+p[p.length-2])}}u.setAllVerticesData(l,!1),i.computeWorldMatrix(!0),i.subMeshes=[];for(var S=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,e.SubMesh.AddToMesh(S,c[S],d[S],h[S],p[S],i,i,!0),S++}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 o=new e.Vector3(0,0,0),a=new e.Quaternion,i=new e.Vector3(0,0,0);e.Matrix.FromArray(r.matrix).decompose(i,a,o),v(t,o,a,i)}else r.translation&&r.rotation&&r.scale&&v(t,e.Vector3.FromArray(r.translation),e.Quaternion.FromArray(r.rotation),e.Vector3.FromArray(r.scale));t.computeWorldMatrix(!0)},x=function(t,r,n,o){var a=null;if(t.importOnlyMeshes&&(r.skin||r.meshes)&&t.importMeshesNames&&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&&i.babylonSkeleton&&(s.skeleton=y(t,i,0,i.babylonSkeleton,r.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),a=s}}else if(r.meshes){var s=g(t,r,r.mesh?[r.mesh]:r.meshes,n,r.babylonNode);a=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=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()),a=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),a=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)),a=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)),a=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)),a=_}else if("spot"===d.type){var A=d[d.type],x=new e.SpotLight(r.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);x.name=r.name||"",A.color&&(x.diffuse=e.Color3.FromArray(A.color)),A.fallOfAngle&&(x.angle=A.fallOfAngle),A.fallOffExponent&&(x.exponent=A.fallOffExponent),a=x}}if(!r.jointName){if(r.babylonNode)return r.babylonNode;if(null===a){var b=new e.Mesh(r.name||"",t.scene);r.babylonNode=b,a=b}}if(null!==a){if(r.matrix&&a instanceof e.Mesh)L(a,r);else{var N=r.translation||[0,0,0],M=r.rotation||[0,0,0,1],O=r.scale||[1,1,1];v(a,e.Vector3.FromArray(N),e.Quaternion.FromArray(M),e.Vector3.FromArray(O))}a.updateCache(!0),r.babylonNode=a}return a},b=function(e,t,r,n){void 0===n&&(n=!1);var o=e.nodes[t],a=null;if(n=!(e.importOnlyMeshes&&!n&&e.importMeshesNames)||(-1!==e.importMeshesNames.indexOf(o.name||"")||0===e.importMeshesNames.length),!o.jointName&&n&&null!==(a=x(e,o,t))&&(a.id=t,a.parent=r),o.children)for(var i=0;i<o.children.length;i++)b(e,o.children[i],a,n)},N=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 o=e.scene.skeletons[r];e.scene.beginAnimation(o,0,Number.MAX_VALUE,!0,1)}},M=function(e,r,n,o,a,i,s){var l=i.values||a.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[a.uniforms[u]];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;o.getEffect().setTexture(u,p)}else t.GLTFUtils.SetUniform(o.getEffect(),u,h,f)}}s(o)},O=function(e,r,n,o,a){var i=o.values||n.parameters,s=n.uniforms;for(var l in a){var u=a[l],c=u.type,f=i[s[l]];if(void 0===f&&(f=u.value),f){var d=function(e){return function(t){u.value&&e&&(r.setTexture(e,t),delete a[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 a[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")}},R=function(e,t,r,n,o,a){return function(i){O(e,t,r,n,o),t.onBind=function(i){M(i,e,o,t,r,n,a)}}},S=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 l=o.indexOf(s.semantic);if(-1!==l)return delete r[n],a[l]}}return e.currentIdentifier},I=function(e){for(var r in e.materials)t.GLTFLoaderExtension.LoadMaterialAsync(e,r,(function(e){}),(function(){}))},w=(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&&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},i.LoadBufferAsync=function(r,n,o,a,i){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))}),i,void 0,!0,(function(e){e&&a(e.status+" "+e.statusText)}))},i.LoadTextureBufferAsync=function(r,n,o,a){var i=r.textures[n];if(!i||!i.source)return void a("");if(i.babylonTexture)return void o(null);var s=r.images[i.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))}),void 0,void 0,!0,(function(e){e&&a(e.status+" "+e.statusText)}))},i.CreateTextureAsync=function(r,n,o,a,i){var s=r.textures[n];if(s.babylonTexture)return void a(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);void 0!==l.wrapS&&(p.wrapU=t.GLTFUtils.GetWrapMode(l.wrapS)),void 0!==l.wrapT&&(p.wrapV=t.GLTFUtils.GetWrapMode(l.wrapT)),
- p.name=n,s.babylonTexture=p,a(p)},i.LoadShaderStringAsync=function(r,n,o,a){var i=r.shaders[n];if(t.GLTFUtils.IsBase64(i.uri)){o(atob(i.uri.split(",")[1]))}else e.Tools.LoadFile(r.rootUrl+i.uri,o,void 0,void 0,!1,(function(e){e&&a(e.status+" "+e.statusText)}))},i.LoadMaterialAsync=function(i,s,l,u){var c=i.materials[s];if(!c.technique)return void(u&&u("No technique found."));var f=i.techniques[c.technique];if(!f){var h=new e.StandardMaterial(s,i.scene);return h.diffuseColor=new e.Color3(.5,.5,.5),h.sideOrientation=e.Material.CounterClockWiseSideOrientation,void l(h)}var p=i.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=[],x=[],b=[];for(var N in f.uniforms){var M=f.uniforms[N],O=f.parameters[M];if(v[N]=O,!O.semantic||O.node||O.source)O.type===t.EParameterType.SAMPLER_2D?b.push(N):L.push(N);else{var I=o.indexOf(O.semantic);-1!==I?(L.push(a[I]),delete v[N]):L.push(N)}}for(var w in f.attributes){var P=f.attributes[w],B=f.parameters[P];B.semantic&&x.push(d(B))}for(;!y.isEnd()&&y.getNextToken();){var C=y.currentToken;if(C===r.IDENTIFIER){var G=!1;for(var w in f.attributes){var P=f.attributes[w],B=f.parameters[P];if(y.currentIdentifier===w&&B.semantic){_+=d(B),G=!0;break}}G||(_+=S(y,f,v))}else _+=y.currentString}for(;!g.isEnd()&&g.getNextToken();){var C=g.currentToken;C===r.IDENTIFIER?A+=S(g,f,v):A+=g.currentString}var D={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},V={attributes:x,uniforms:L,samplers:b,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 U=new e.ShaderMaterial(s,i.scene,D,V);if(U.onError=F(p,U,u),U.onCompiled=R(i,U,f,c,v,l),U.sideOrientation=e.Material.CounterClockWiseSideOrientation,m&&m.functions){var k=m.functions;k.cullFace&&k.cullFace[0]!==t.ECullingType.BACK&&(U.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?U.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?U.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?U.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?U.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?U.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&&(U.alphaMode=e.Engine.ALPHA_MAXIMIZED))}},i})();t.GLTFLoaderBase=w;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.dispose=function(){},r.prototype.importMeshAsync=function(r,n,o,a,i,s,l){var u=this;return n.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(n,o,a,(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=new Array,o=new Array;for(var a in t.nodes){var l=t.nodes[a];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(){I(t),N(t),!e.GLTFFileLoader.IncrementalLoading&&i&&i(n,[],o)}))}),s),e.GLTFFileLoader.IncrementalLoading&&i&&i(n,[],o)}),l),!0},r.prototype.loadAsync=function(r,n,o,a,i,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(){I(r),N(r),e.GLTFFileLoader.IncrementalLoading||a()}))})),e.GLTFFileLoader.IncrementalLoading&&a()}),s)}),s)},r.prototype._loadShadersAsync=function(r,n){var o=!1,a=function(o,a){t.GLTFLoaderExtension.LoadShaderStringAsync(r,o,(function(i){r.loadedShaderCount++,i&&(e.Effect.ShadersStore[o+(a.type===t.EShaderType.VERTEX?"VertexShader":"PixelShader")]=i),r.loadedShaderCount===r.shaderscount&&n()}),(function(){e.Tools.Error("Error when loading shader program named "+o+" located at "+a.uri)}))};for(var i in r.shaders){o=!0;var s=r.shaders[i];s?a.bind(this,i,s)():e.Tools.Error("No shader named: "+i)}o||n()},r.prototype._loadBuffersAsync=function(r,n,o){var a=!1,i=function(o,a){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: "+a.byteLength),r.loadedBufferViews[o]=t),r.loadedBufferCount===r.buffersCount&&n()}),(function(){e.Tools.Error("Error when loading buffer named "+o+" located at "+a.uri)}))};for(var s in r.buffers){a=!0;var l=r.buffers[s];l?i.bind(this,s,l)():e.Tools.Error("No buffer named: "+s)}a||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.Extensions={},r})();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,o,a,i){var s=null;if("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())),s)switch(o.type){case t.EParameterType.FLOAT_MAT2:i.setMatrix2x2(a,e.Matrix.GetAsMatrix2x2(s));break;case t.EParameterType.FLOAT_MAT3:i.setMatrix3x3(a,e.Matrix.GetAsMatrix3x3(s));break;case t.EParameterType.FLOAT_MAT4:i.setMatrix(a,s)}},r.SetUniform=function(r,n,o,a){switch(a){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,a){var n=r.byteOffset+n,i=e.loadedBufferViews[r.buffer];if(n+o>i.byteLength)throw new Error("Buffer access is out of range");var s=i.buffer;switch(n+=i.byteOffset,a){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:new Array,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,a,i){t.ApplyExtensions((function(e){return e.loadRuntimeAsync(r,n,o,a,i)}),(function(){setTimeout((function(){a(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,a,i){t.ApplyExtensions((function(e){return e.loadBufferAsync(r,n,o,a,i)}),(function(){e.GLTFLoaderBase.LoadBufferAsync(r,n,o,a,i)}))},t.LoadTextureAsync=function(e,r,n,o){t.LoadTextureBufferAsync(e,r,(function(a){return t.CreateTextureAsync(e,r,a,n,o)}),o)},t.LoadShaderStringAsync=function(r,n,o,a){t.ApplyExtensions((function(e){return e.loadShaderStringAsync(r,n,o,a)}),(function(){e.GLTFLoaderBase.LoadShaderStringAsync(r,n,o,a)}))},t.LoadMaterialAsync=function(r,n,o,a){t.ApplyExtensions((function(e){return e.loadMaterialAsync(r,n,o,a)}),(function(){e.GLTFLoaderBase.LoadMaterialAsync(r,n,o,a)}))},t.LoadTextureBufferAsync=function(r,n,o,a){t.ApplyExtensions((function(e){return e.loadTextureBufferAsync(r,n,o,a)}),(function(){e.GLTFLoaderBase.LoadTextureBufferAsync(r,n,o,a)}))},t.CreateTextureAsync=function(r,n,o,a,i){t.ApplyExtensions((function(e){return e.createTextureAsync(r,n,o,a,i)}),(function(){e.GLTFLoaderBase.CreateTextureAsync(r,n,o,a,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(t){function r(){return t.call(this,"KHR_binary_glTF")||this}return __extends(r,t),r.prototype.loadRuntimeAsync=function(t,r,n,o,a){var i=r.json.extensionsUsed;return!(!i||-1===i.indexOf(this.name)||!r.bin)&&(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 a=t.textures[r],i=t.images[a.source];if(!(i.extensions&&this.name in i.extensions))return!1;var s=i.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 a=t.shaders[r];if(!(a.extensions&&this.name in a.extensions))return!1;var i=a.extensions[this.name],s=t.bufferViews[i.bufferView],l=e.GLTFUtils.GetBufferFromBufferView(t,s,0,s.byteLength,e.EComponentType.UNSIGNED_BYTE);return setTimeout((function(){var t=e.GLTFUtils.DecodeBufferToText(l);n(t)})),!0},r})(e.GLTFLoaderExtension);e.GLTFBinaryExtension=t,e.GLTFLoader.RegisterExtension(new t)})(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 a=o.lights;if(a)for(var i in a){var s=a[i];switch(s.type){case"ambient":var l=new e.HemisphericLight(s.name,new e.Vector3(0,1,0),t.scene),u=s.ambient;u&&(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;f&&(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;h&&(d.diffuse=e.Color3.FromArray(h.color||[1,1,1]));break;case"spot":var p=s.spot;if(p){var m=new e.SpotLight(s.name,new e.Vector3(0,10,0),new e.Vector3(0,-1,0),p.fallOffAngle||Math.PI,p.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 a=t.materials[r];if(!a||!a.extensions)return!1;var i=a.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",o):s.ambientColor=e.Color3.FromArray(i.values.ambient||[0,0,0]),"string"==typeof i.values.diffuse?this._loadTexture(t,i.values.diffuse,s,"diffuseTexture",o):s.diffuseColor=e.Color3.FromArray(i.values.diffuse||[0,0,0]),"string"==typeof i.values.emission?this._loadTexture(t,i.values.emission,s,"emissiveTexture",o):s.emissiveColor=e.Color3.FromArray(i.values.emission||[0,0,0]),"string"==typeof i.values.specular?this._loadTexture(t,i.values.specular,s,"specularTexture",o):s.specularColor=e.Color3.FromArray(i.values.specular||[0,0,0]),!0},n.prototype._loadTexture=function(e,r,n,o,a){t.GLTFLoaderBase.LoadTextureBufferAsync(e,r,(function(i){t.GLTFLoaderBase.CreateTextureAsync(e,r,i,(function(e){return n[o]=e}),a)}),a)},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._disposed=!1,this._renderReady=!1,this._requests=new Array,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(){if(!this._disposed){this._disposed=!0;for(var e=0,t=this._requests;e<t.length;e++){var r=t[e];r.readyState!==(XMLHttpRequest.DONE||4)&&r.abort()}if(this._gltf.textures)for(var n=0,o=this._gltf.textures;n<o.length;n++){var a=o[n];a.url&&URL.revokeObjectURL(a.url)}}},n.prototype.importMeshAsync=function(e,t,r,n,o,a,i){var s=this;this._loadAsync(e,t,r,n,(function(){o(s._getMeshes(),[],s._getSkeletons())}),a,i)},n.prototype.loadAsync=function(e,t,r,n,o,a){this._loadAsync(null,e,t,r,n,o,a)},n.prototype._loadAsync=function(e,t,r,n,o,a,i){var s=this;this._tryCatchOnError((function(){s._loadData(r),s._babylonScene=t,s._rootUrl=n,s._successCallback=o,s._progressCallback=a,s._errorCallback=i,s._addPendingData(s),s._loadDefaultScene(e),s._loadAnimations(),s._removePendingData(s)}))},n.prototype._onProgress=function(e){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)},n.prototype._onComplete=function(){this._parent.onComplete&&this._parent.onComplete(),this.dispose()},n.prototype._loadData=function(t){if(this._gltf=t.json,n._AssignIndices(this._gltf.accessors),n._AssignIndices(this._gltf.animations),n._AssignIndices(this._gltf.buffers),n._AssignIndices(this._gltf.bufferViews),n._AssignIndices(this._gltf.images),n._AssignIndices(this._gltf.materials),n._AssignIndices(this._gltf.meshes),n._AssignIndices(this._gltf.nodes),n._AssignIndices(this._gltf.scenes),n._AssignIndices(this._gltf.skins),n._AssignIndices(this._gltf.textures),t.bin){var r=this._gltf.buffers;if(r&&r[0]&&!r[0].uri){var o=r[0];o.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+o.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),o.loadedData=t.bin}else e.Tools.Warn("Unexpected BIN chunk")}},n.prototype._getMeshes=function(){var e=new Array;e.push(this._rootNode.babylonMesh);var t=this._gltf.nodes;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];o.babylonMesh&&e.push(o.babylonMesh)}return e},n.prototype._getSkeletons=function(){var e=new Array,t=this._gltf.skins;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];o.babylonSkeleton&&e.push(o.babylonSkeleton)}return e},n.prototype._getAnimationTargets=function(){var e=new Array,t=this._gltf.animations;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];e.push.apply(e,o.targets)}return e},n.prototype._startAnimations=function(){for(var e=0,t=this._getAnimationTargets();e<t.length;e++){var r=t[e];this._babylonScene.beginAnimation(r,0,Number.MAX_VALUE,!0)}},n.prototype._loadDefaultScene=function(e){var t=n._GetProperty(this._gltf.scenes,this._gltf.scene||0);if(!t)throw new Error("Failed to find scene "+(this._gltf.scene||0));this._loadScene("#/scenes/"+t.index,t,e)},n.prototype._loadScene=function(t,r,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 a=r.nodes;if(this._traverseNodes(t,a,(function(e,t){return e.parent=t,!0}),this._rootNode),o){o instanceof Array||(o=[o]);var i=new Array;this._traverseNodes(t,a,(function(e){return-1===o.indexOf(e.name)||(i.push(e.index),!1)}),this._rootNode),a=i}for(var s=0,l=a;s<l.length;s++){var u=l[s],c=n._GetProperty(this._gltf.nodes,u);if(!c)throw new Error(t+": Failed to find node "+u);this._loadNode("#/nodes/"+u,c)}this._rootNode.babylonMesh.setEnabled(!1)},n.prototype._loadNode=function(r,o){if(!t.GLTFLoaderExtension.LoadNode(this,r,o)){if(o.babylonMesh=new e.Mesh(o.name||"mesh"+o.index,this._babylonScene),o.babylonMesh.hasVertexAlpha=!0,this._loadTransform(o),null!=o.mesh){var a=n._GetProperty(this._gltf.meshes,o.mesh);if(!a)throw new Error(r+": Failed to find mesh "+o.mesh);this._loadMesh("#/meshes/"+o.mesh,o,a)}if(o.babylonMesh.parent=o.parent?o.parent.babylonMesh:null,o.babylonAnimationTargets=o.babylonAnimationTargets||[],o.babylonAnimationTargets.push(o.babylonMesh),null!=o.skin){var i=n._GetProperty(this._gltf.skins,o.skin);if(!i)throw new Error(r+": Failed to find skin "+o.skin);o.babylonMesh.skeleton=this._loadSkin("#/skins/"+o.skin,i)}if(o.camera,o.children)for(var s=0,l=o.children;s<l.length;s++){var u=l[s],c=n._GetProperty(this._gltf.nodes,u);if(!c)throw new Error(r+": Failed to find child node "+u);this._loadNode("#/nodes/"+u,c)}}},n.prototype._loadMesh=function(t,r,o){var a=this,i=o.primitives;if(!i||0===i.length)throw new Error(t+": Primitives are missing");this._createMorphTargets(t,r,o),this._loadAllVertexDataAsync(t,o,(function(){a._loadMorphTargets(t,r,o);for(var n=new e.VertexData,s=0,l=i;s<l.length;s++){var u=l[s];n.merge(u.vertexData)}new e.Geometry(r.babylonMesh.name,a._babylonScene,n,!1,r.babylonMesh),r.babylonMesh.subMeshes=[];for(var c=0,f=0,d=0;d<i.length;d++){var h=i[d].vertexData,p=h.positions.length,m=h.indices.length;e.SubMesh.AddToMesh(d,c,p,f,m,r.babylonMesh),c+=p,f+=m}}));var s=new e.MultiMaterial(r.babylonMesh.name,this._babylonScene);r.babylonMesh.material=s;for(var l=s.subMaterials,u=this,c=0;c<i.length;c++)!(function(e){var o=i[e];if(null==o.material)l[e]=u._getDefaultMaterial();else{var s=n._GetProperty(u._gltf.materials,o.material);if(!s)throw new Error(t+": Failed to find material "+o.material);u._loadMaterial("#/materials/"+s.index,s,(function(t,n){n&&a._parent.onMaterialLoaded&&a._parent.onMaterialLoaded(t),a._parent.onBeforeMaterialReadyAsync?(a._addLoaderPendingData(s),a._parent.onBeforeMaterialReadyAsync(t,r.babylonMesh,null!=l[e],(function(){a._tryCatchOnError((function(){l[e]=t,a._removeLoaderPendingData(s)}))}))):l[e]=t}))}})(c)},n.prototype._loadAllVertexDataAsync=function(e,t,r){for(var n=t.primitives,o=n.length,a=this,i=0;i<n.length;i++)!(function(i){var s=n[i];a._loadVertexDataAsync(e+"/primitive/"+i,t,s,(function(e){s.vertexData=e,0==--o&&r()}))})(i)},n.prototype._convertToFloat4TextureCoordArray=function(e,r,n){if(n.componentType==t.EComponentType.FLOAT)return r;var o=r,a=1;switch(n.componentType){case t.EComponentType.UNSIGNED_BYTE:a=1/255;break;case t.EComponentType.UNSIGNED_SHORT:a=1/65535;break;default:throw new Error(e+": Invalid component type ("+n.componentType+")")}for(var i=new Float32Array(2*n.count),s=0;s<i.length;++s)i[s]=o[s]*a;return i},n.prototype._convertToFloat4ColorArray=function(e,r,o){var a=n._GetNumComponents(o.type);if(4===a&&o.componentType===t.EComponentType.FLOAT)return r;var i=r,s=1;switch(o.componentType){case t.EComponentType.FLOAT:s=1;break;case t.EComponentType.UNSIGNED_BYTE:s=1/255;break;case t.EComponentType.UNSIGNED_SHORT:s=1/65535;break;default:throw new Error(e+": Invalid component type ("+o.componentType+")")}var l=new Float32Array(4*o.count);if(4===a)for(var u=0;u<l.length;++u)l[u]=i[u]*s;else for(var c=0,u=0;u<l.length;++u)l[u]=(u+1)%4==0?1:i[c++]*s;return l},n.prototype._loadVertexDataAsync=function(r,o,a,i){var s=this,l=a.attributes;if(!l)throw new Error(r+": Attributes are missing");if(a.mode&&a.mode!==t.EMeshPrimitiveMode.TRIANGLES)throw new Error(r+": Mode "+a.mode+" is not currently supported");var u=new e.VertexData,c=Object.keys(l).length,f=this;for(var d in l)!(function(t){var o=n._GetProperty(f._gltf.accessors,l[t]);if(!o)throw new Error(r+": Failed to find attribute '"+t+"' accessor "+l[t]);f._loadAccessorAsync("#/accessors/"+o.index,o,(function(l){switch(t){case"POSITION":u.positions=l;break;case"NORMAL":u.normals=l;break;case"TANGENT":u.tangents=l;break;case"TEXCOORD_0":u.uvs=s._convertToFloat4TextureCoordArray(r,l,o);break;case"TEXCOORD_1":u.uvs2=s._convertToFloat4TextureCoordArray(r,l,o);break;case"JOINTS_0":u.matricesIndices=new Float32Array(Array.prototype.slice.apply(l));break;case"WEIGHTS_0":u.matricesWeights=l;break;case"COLOR_0":u.colors=s._convertToFloat4ColorArray(r,l,o);break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+t+"'")}if(0==--c)if(null==a.indices){u.indices=new Uint32Array(u.positions.length/3);for(var f=0;f<u.indices.length;f++)u.indices[f]=f;i(u)}else{var d=n._GetProperty(s._gltf.accessors,a.indices);if(!d)throw new Error(r+": Failed to find indices accessor "+a.indices);s._loadAccessorAsync("#/accessors/"+d.index,d,(function(e){u.indices=e,i(u)}))}}))})(d)},n.prototype._createMorphTargets=function(t,r,n){var o=n.primitives,a=o[0].targets;if(a){for(var i=0,s=o;i<s.length;i++){var l=s[i];if(!l.targets||l.targets.length!=a.length)throw new Error(t+": All primitives are required to list the same number of targets")}var u=new e.MorphTargetManager;r.babylonMesh.morphTargetManager=u;for(var c=0;c<a.length;c++){var f=r.weights?r.weights[c]:n.weights?n.weights[c]:0;u.addTarget(new e.MorphTarget("morphTarget"+c,f))}}},n.prototype._loadMorphTargets=function(t,r,n){var o=r.babylonMesh.morphTargetManager;o&&this._loadAllMorphTargetVertexDataAsync(t,r,n,(function(){for(var r=o.numTargets,a=0;a<r;a++){for(var i=new e.VertexData,s=0,l=n.primitives;s<l.length;s++){var u=l[s];i.merge(u.targetsVertexData[a],{tangentLength:3})}if(!i.positions)throw new Error(t+": Positions are missing");var c=o.getTarget(a);c.setPositions(i.positions),c.setNormals(i.normals),c.setTangents(i.tangents)}}))},n.prototype._loadAllMorphTargetVertexDataAsync=function(e,t,r,n){for(var o=r.primitives.length*t.babylonMesh.morphTargetManager.numTargets,a=this,i=0,s=r.primitives;i<s.length;i++){var l=s[i];!(function(t){var r=t.targets;t.targetsVertexData=new Array(r.length);for(var i=0;i<r.length;i++)!(function(i){a._loadMorphTargetVertexDataAsync(e+"/targets/"+i,t.vertexData,r[i],(function(e){t.targetsVertexData[i]=e,0==--o&&n()}))})(i)})(l)}},n.prototype._loadMorphTargetVertexDataAsync=function(t,r,o,a){var i=new e.VertexData,s=Object.keys(o).length,l=this;for(var u in o)!(function(u){var c=n._GetProperty(l._gltf.accessors,o[u]);if(!c)throw new Error(t+": Failed to find attribute '"+u+"' accessor "+o[u]);l._loadAccessorAsync("#/accessors/"+c.index,c,(function(t){var n=t;switch(u){case"POSITION":for(var o=0;o<n.length;o++)n[o]+=r.positions[o];i.positions=n;break;case"NORMAL":for(var o=0;o<n.length;o++)n[o]+=r.normals[o];i.normals=n;break;case"TANGENT":for(var o=0,l=0;o<n.length;o++,l++)n[o]+=r.tangents[l],(o+1)%3==0&&l++;i.tangents=n;break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+u+"'")}0==--s&&a(i)}))})(u)},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(t,r){var o=this,a="skeleton"+r.index;if(r.babylonSkeleton=new e.Skeleton(r.name||a,a,this._babylonScene),null==r.inverseBindMatrices)this._loadBones(t,r,null);else{var i=n._GetProperty(this._gltf.accessors,r.inverseBindMatrices);if(!i)throw new Error(t+": Failed to find inverse bind matrices attribute "+r.inverseBindMatrices);this._loadAccessorAsync("#/accessors/"+i.index,i,(function(e){o._loadBones(t,r,e)}))}return r.babylonSkeleton},n.prototype._createBone=function(t,r,n,o,a,i){var s=new e.Bone(t.name||"bone"+t.index,r.babylonSkeleton,n,o,null,a,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,r){for(var o={},a=0,i=t.joints;a<i.length;a++){var s=i[a],l=n._GetProperty(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find joint "+s);this._loadBone(l,t,r,o)}},n.prototype._loadBone=function(t,r,n,o){var a=o[t.index];if(a)return a;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 l=null;return t.index!==r.skeleton&&t.parent&&t.parent!==this._rootNode&&(l=this._loadBone(t.parent,r,n,o),s.multiplyToRef(l.getInvertedAbsoluteTransform(),s)),a=this._createBone(t,r,l,this._getNodeMatrix(t),s,i),o[t.index]=a,a},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,o){void 0===o&&(o=null);for(var a=0,i=t;a<i.length;a++){var s=i[a],l=n._GetProperty(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find node "+s);this._traverseNode(e,l,r,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 t=0;t<e.length;t++){var r=e[t];this._loadAnimation("#/animations/"+t,r)}},n.prototype._loadAnimation=function(e,t){t.targets=[];for(var r=0;r<t.channels.length;r++){var o=n._GetProperty(t.channels,r);if(!o)throw new Error(e+": Failed to find channel "+r);var a=n._GetProperty(t.samplers,o.sampler);if(!a)throw new Error(e+": Failed to find sampler "+o.sampler)
- ;this._loadAnimationChannel(t,e+"/channels/"+r,o,e+"/samplers/"+o.sampler,a)}},n.prototype._loadAnimationChannel=function(t,r,o,a,i){var s=n._GetProperty(this._gltf.nodes,o.target.node);if(!s)throw new Error(r+": Failed to find target node "+o.target.node);var l,u;switch(o.target.path){case"translation":l="position",u=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":l="rotationQuaternion",u=e.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":l="scaling",u=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":l="influence",u=e.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(r+": Invalid target path "+o.target.path)}var c,f,d=function(){if(c&&f){var r,n=0;switch(l){case"position":r=function(){var t=e.Vector3.FromArray(f,n);return n+=3,t};break;case"rotationQuaternion":r=function(){var t=e.Quaternion.FromArray(f,n);return n+=4,t};break;case"scaling":r=function(){var t=e.Vector3.FromArray(f,n);return n+=3,t};break;case"influence":r=function(){for(var e=s.babylonMesh.morphTargetManager.numTargets,t=new Array(e),r=0;r<e;r++)t[r]=f[n++];return t}}var o;switch(i.interpolation){case"LINEAR":o=function(e){return{frame:c[e],value:r()}};break;case"CUBICSPLINE":o=function(e){return{frame:c[e],inTangent:r(),value:r(),outTangent:r()}};break;default:throw new Error(a+": Invalid interpolation "+i.interpolation)}for(var d=new Array(c.length),h=0;h<c.length;h++)d[h]=o(h);if("influence"===l)for(var p=s.babylonMesh.morphTargetManager,m=0;m<p.numTargets;m++)!(function(r){var n=p.getTarget(r),o=(t.name||"anim"+t.index)+"_"+r,a=new e.Animation(o,l,1,u);a.setKeys(d.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[r]:void 0,value:e.value[r],outTangent:e.outTangent?e.outTangent[r]:void 0}}))),n.animations.push(a),t.targets.push(n)})(m);else{var T=t.name||"anim"+t.index,E=new e.Animation(T,l,1,u);if(E.setKeys(d),s.babylonAnimationTargets)for(var _=0,A=s.babylonAnimationTargets;_<A.length;_++){var y=A[_];y.animations.push(E.clone()),t.targets.push(y)}}}},h=n._GetProperty(this._gltf.accessors,i.input);if(!h)throw new Error(a+": Failed to find input accessor "+i.input);this._loadAccessorAsync("#/accessors/"+h.index,h,(function(e){c=e,d()}));var p=n._GetProperty(this._gltf.accessors,i.output);if(!p)throw new Error(a+": Failed to find output accessor "+i.output);this._loadAccessorAsync("#/accessors/"+p.index,p,(function(e){f=e,d()}))},n.prototype._loadBufferAsync=function(r,n,o){var a=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),a._removePendingData(e)}));else{if(!n.uri)throw new Error(r+": Uri is missing");if(t.GLTFUtils.IsBase64(n.uri)){var i=t.GLTFUtils.DecodeBase64(n.uri);n.loadedData=new Uint8Array(i),o(n.loadedData),this._removePendingData(n)}else n.loadedObservable=new e.Observable,n.loadedObservable.add((function(e){o(e.loadedData),a._removePendingData(e)})),this._loadUri(r,n.uri,(function(e){n.loadedData=e,n.loadedObservable.notifyObservers(n),n.loadedObservable=void 0}))}},n.prototype._loadBufferViewAsync=function(e,t,r){var o=n._GetProperty(this._gltf.buffers,t.buffer);if(!o)throw new Error(e+": Failed to find buffer "+t.buffer);this._loadBufferAsync("#/buffers/"+o.index,o,(function(n){var o;try{o=new Uint8Array(n.buffer,n.byteOffset+(t.byteOffset||0),t.byteLength)}catch(t){throw new Error(e+": "+t.message)}r(o)}))},n.prototype._loadAccessorAsync=function(e,r,o){var a=this;if(r.sparse)throw new Error(e+": Sparse accessors are not currently supported");var i=n._GetProperty(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(s){var l=n._GetNumComponents(r.type);if(0===l)throw new Error(e+": Invalid type "+r.type);var u,c=r.byteOffset||0,f=i.byteStride;try{switch(r.componentType){case t.EComponentType.BYTE:u=a._buildArrayBuffer(Float32Array,s,c,r.count,l,f);break;case t.EComponentType.UNSIGNED_BYTE:u=a._buildArrayBuffer(Uint8Array,s,c,r.count,l,f);break;case t.EComponentType.SHORT:u=a._buildArrayBuffer(Int16Array,s,c,r.count,l,f);break;case t.EComponentType.UNSIGNED_SHORT:u=a._buildArrayBuffer(Uint16Array,s,c,r.count,l,f);break;case t.EComponentType.UNSIGNED_INT:u=a._buildArrayBuffer(Uint32Array,s,c,r.count,l,f);break;case t.EComponentType.FLOAT:u=a._buildArrayBuffer(Float32Array,s,c,r.count,l,f);break;default:throw new Error(e+": Invalid component type "+r.componentType)}}catch(t){throw new Error(e+": "+t)}o(u)}))},n.prototype._buildArrayBuffer=function(e,t,r,n,o,a){r+=t.byteOffset;var i=n*o;if(null==a||a===o*e.BYTES_PER_ELEMENT)return new e(t.buffer,r,i);for(var s=a/e.BYTES_PER_ELEMENT,l=new e(t.buffer,r,s*n),u=new e(i),c=0,f=0;f<i;){for(var d=0;d<o;d++)u[f]=l[c+d],f++;c+=s}return u},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++;for(var t=0,r=this._loaderTrackers;t<r.length;t++){r[t]._addPendingData(e)}},n.prototype._removeLoaderPendingData=function(e){for(var t=0,r=this._loaderTrackers;t<r.length;t++){r[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),1),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(t,r){var o=r.babylonMaterial;o.metallic=1,o.roughness=1;var a=r.pbrMetallicRoughness;if(a){if(o.albedoColor=a.baseColorFactor?e.Color3.FromArray(a.baseColorFactor):new e.Color3(1,1,1),o.metallic=null==a.metallicFactor?1:a.metallicFactor,o.roughness=null==a.roughnessFactor?1:a.roughnessFactor,a.baseColorTexture){var i=n._GetProperty(this._gltf.textures,a.baseColorTexture.index);if(!i)throw new Error(t+": Failed to find base color texture "+a.baseColorTexture.index);o.albedoTexture=this._loadTexture("#/textures/"+i.index,i,a.baseColorTexture.texCoord)}if(a.metallicRoughnessTexture){var i=n._GetProperty(this._gltf.textures,a.metallicRoughnessTexture.index);if(!i)throw new Error(t+": Failed to find metallic roughness texture "+a.metallicRoughnessTexture.index);o.metallicTexture=this._loadTexture("#/textures/"+i.index,i,a.metallicRoughnessTexture.texCoord),o.useMetallnessFromMetallicTextureBlue=!0,o.useRoughnessFromMetallicTextureGreen=!0,o.useRoughnessFromMetallicTextureAlpha=!1}this._loadMaterialAlphaProperties(t,r,a.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(t,r){var o=r.babylonMaterial;if(o.emissiveColor=r.emissiveFactor?e.Color3.FromArray(r.emissiveFactor):new e.Color3(0,0,0),r.doubleSided&&(o.backFaceCulling=!1,o.twoSidedLighting=!0),r.normalTexture){var a=n._GetProperty(this._gltf.textures,r.normalTexture.index);if(!a)throw new Error(t+": Failed to find normal texture "+r.normalTexture.index);o.bumpTexture=this._loadTexture("#/textures/"+a.index,a,r.normalTexture.texCoord),o.invertNormalMapX=!this._babylonScene.useRightHandedSystem,o.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=r.normalTexture.scale&&(o.bumpTexture.level=r.normalTexture.scale)}if(r.occlusionTexture){var a=n._GetProperty(this._gltf.textures,r.occlusionTexture.index);if(!a)throw new Error(t+": Failed to find occlusion texture "+r.occlusionTexture.index);o.ambientTexture=this._loadTexture("#/textures/"+a.index,a,r.occlusionTexture.texCoord),o.useAmbientInGrayScale=!0,null!=r.occlusionTexture.strength&&(o.ambientTextureStrength=r.occlusionTexture.strength)}if(r.emissiveTexture){var a=n._GetProperty(this._gltf.textures,r.emissiveTexture.index);if(!a)throw new Error(t+": Failed to find emissive texture "+r.emissiveTexture.index);o.emissiveTexture=this._loadTexture("#/textures/"+a.index,a,r.emissiveTexture.texCoord)}},n.prototype._loadMaterialAlphaProperties=function(t,r,n){var o=r.babylonMaterial;switch(r.alphaMode||"OPAQUE"){case"OPAQUE":o.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":o.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHATEST,o.alphaCutOff=null==r.alphaCutoff?.5:r.alphaCutoff,n&&(0==n[3]?o.alphaCutOff=1:o.alphaCutOff/=n[3]),o.albedoTexture&&(o.albedoTexture.hasAlpha=!0);break;case"BLEND":o.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHABLEND,n&&(o.alpha=n[3]),o.albedoTexture&&(o.albedoTexture.hasAlpha=!0,o.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(t+": Invalid alpha mode "+r.alphaMode)}},n.prototype._loadTexture=function(r,o,a){var i=this,s=null==o.sampler?{}:n._GetProperty(this._gltf.samplers,o.sampler);if(!s)throw new Error(r+": Failed to find sampler "+o.sampler);var l=s.minFilter===t.ETextureMinFilter.NEAREST||s.minFilter===t.ETextureMinFilter.LINEAR,u=n._GetTextureSamplingMode(s.magFilter,s.minFilter);this._addPendingData(o);var c=new e.Texture(null,this._babylonScene,l,!1,u,function(){i._tryCatchOnError((function(){i._removePendingData(o)}))},function(e){i._tryCatchOnError((function(){throw new Error(r+": "+e)}))});if(o.url)c.updateURL(o.url);else if(o.dataReadyObservable)o.dataReadyObservable.add((function(e){c.updateURL(e.url)}));else{o.dataReadyObservable=new e.Observable,o.dataReadyObservable.add((function(e){c.updateURL(e.url)}));var f=n._GetProperty(this._gltf.images,o.source);if(!f)throw new Error(r+": Failed to find source "+o.source);this._loadImage("#/images/"+f.index,f,(function(e){o.url=URL.createObjectURL(new Blob([e],{type:f.mimeType})),o.dataReadyObservable.notifyObservers(o),o.dataReadyObservable=void 0}))}return c.coordinatesIndex=a||0,c.wrapU=n._GetTextureWrapMode(s.wrapS),c.wrapV=n._GetTextureWrapMode(s.wrapT),c.name=o.name||"texture"+o.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(c),c},n.prototype._loadImage=function(e,r,o){if(r.uri)t.GLTFUtils.IsBase64(r.uri)?o(new Uint8Array(t.GLTFUtils.DecodeBase64(r.uri))):this._loadUri(e,r.uri,o);else{var a=n._GetProperty(this._gltf.bufferViews,r.bufferView);if(!a)throw new Error(e+": Failed to find buffer view "+r.bufferView);this._loadBufferViewAsync("#/bufferViews/"+a.index,a,o)}},n.prototype._loadUri=function(r,n,o){var a=this;if(!t.GLTFUtils.ValidateUri(n))throw new Error(r+": Uri '"+n+"' is invalid");var i=e.Tools.LoadFile(this._rootUrl+n,(function(e){a._tryCatchOnError((function(){o(new Uint8Array(e))}))}),(function(e){a._tryCatchOnError((function(){a._onProgress(e)}))}),this._babylonScene.database,!0,(function(e){a._tryCatchOnError((function(){throw new Error(r+": Failed to load '"+n+"'"+(e?": "+e.status+" "+e.statusText:""))}))}));i&&this._requests.push(i)},n.prototype._tryCatchOnError=function(t){if(!this._disposed)try{t()}catch(t){e.Tools.Error("glTF Loader: "+t.message),this._errorCallback&&this._errorCallback(t.message),this.dispose()}},n._AssignIndices=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},n._GetProperty=function(e,t){return e&&void 0!=t&&e[t]?e[t]:null},n._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}},n._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}},n._GetNumComponents=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.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(e){var t=(function(){function e(){}return e.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},e.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},e.ValidateUri=function(e){return-1===e.indexOf("..")},e})();e.GLTFUtils=t})(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,r){var n=this;if(!t.extensions)return!1;var o=t.extensions[this.name];return!!o&&(t.extensions[this.name]=void 0,r(e+"extensions/"+this.name,o,(function(){t.extensions[n.name]=o})),!0)},e.TraverseNode=function(e,t,r,n,o){return this._ApplyExtensions((function(a){return a._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)return!1;for(var n=0,o=r;n<o.length;n++){var a=o[n];if(a.enabled&&t(a))return!0}return!1},e._Extensions=[],e})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(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,a){return this._loadExtension(r,n,(function(r,i,s){for(var l=i.ids.length-1;l>=0;l--){var u=t.GLTFLoader._GetProperty(e._gltf.nodes,i.ids[l]);if(!u)throw new Error(r+": Failed to find node "+i.ids[l]);e._traverseNode(r,u,o,a)}e._traverseNode(r,n,o,a),s()}))},n.prototype._loadNode=function(e,r,n){var o=this;return this._loadExtension(r,n,(function(r,a,i){for(var s=[n],l=0,u=a.ids;l<u.length;l++){var c=u[l],f=t.GLTFLoader._GetProperty(e._gltf.nodes,c);if(!f)throw new Error(r+": Failed to find node "+c);s.push(f)}e._addLoaderPendingData(n),o._loadNodeLOD(e,r,s,s.length-1,(function(){e._removeLoaderPendingData(n),i()}))}))},n.prototype._loadNodeLOD=function(e,t,r,o,a){var i=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 a();setTimeout((function(){e._tryCatchOnError((function(){i._loadNodeLOD(e,t,r,o-1,a)}))}),n.MinimalLODDelay)}))},n.prototype._loadMaterial=function(e,r,n,o){var a=this;return this._loadExtension(r,n,(function(r,i,s){for(var l=[n],u=0,c=i.ids;u<c.length;u++){var f=c[u],d=t.GLTFLoader._GetProperty(e._gltf.materials,f);if(!d)throw new Error(r+": Failed to find material "+f);l.push(d)}e._addLoaderPendingData(n),a._loadMaterialLOD(e,r,l,l.length-1,o,(function(){e._removeLoaderPendingData(n),s()}))}))},n.prototype._loadMaterialLOD=function(t,r,o,a,i,s){var l=this;t._loadMaterial(r,o[a],(function(u,c){if(i(u,c),0===a)return void s();t._executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(u.getActiveTextures(),(function(){setTimeout((function(){t._tryCatchOnError((function(){l._loadMaterialLOD(t,r,o,a-1,i,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(t,r,(function(t,a,i){e._createPbrMaterial(r),e._loadMaterialBaseProperties(t,r),o._loadSpecularGlossinessProperties(e,t,r,a),n(r.babylonMaterial,!0)}))},n.prototype._loadSpecularGlossinessProperties=function(r,n,o,a){var i=o.babylonMaterial;if(i.albedoColor=a.diffuseFactor?e.Color3.FromArray(a.diffuseFactor):new e.Color3(1,1,1),i.reflectivityColor=a.specularFactor?e.Color3.FromArray(a.specularFactor):new e.Color3(1,1,1),i.microSurface=null==a.glossinessFactor?1:a.glossinessFactor,a.diffuseTexture){var s=t.GLTFLoader._GetProperty(r._gltf.textures,a.diffuseTexture.index);if(!s)throw new Error(n+": Failed to find diffuse texture "+a.diffuseTexture.index);i.albedoTexture=r._loadTexture("textures["+s.index+"]",s,a.diffuseTexture.texCoord)}if(a.specularGlossinessTexture){var s=t.GLTFLoader._GetProperty(r._gltf.textures,a.specularGlossinessTexture.index);if(!s)throw new Error(n+": Failed to find diffuse texture "+a.specularGlossinessTexture.index);i.reflectivityTexture=r._loadTexture("textures["+s.index+"]",s,a.specularGlossinessTexture.texCoord),i.reflectivityTexture.hasAlpha=!0,i.useMicroSurfaceFromReflectivityMapAlpha=!0}r._loadMaterialAlphaProperties(n,o,a.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){var r=t();e&&e.BABYLON||("object"==typeof exports&&"object"==typeof module?module.exports=r:"function"==typeof define&&define.amd?define(["BJSLoaders"],t):"object"==typeof exports?exports.BJSLoaders=r:e.BABYLON=r)})(this,(function(){return BABYLON}));
|