123 |
- var babylonDependency;try{babylonDependency=BABYLON||"undefined"!=typeof require&&require("../babylon.max")}catch(e){babylonDependency=BABYLON||"undefined"!=typeof require&&require("babylonjs")}var BABYLON=babylonDependency,__decorate=this&&this.__decorate||function(e,t,r,n){var a,o=arguments.length,i=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,r,i):a(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,i),i},__extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){var t=(function(){function t(){this.solidPattern=/solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g,this.facetsPattern=/facet([\s\S]*?)endfacet/g,this.normalPattern=/normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g,this.vertexPattern=/vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g,this.name="stl",this.extensions={".stl":{isBinary:!0}}}return t.prototype.importMesh=function(t,r,n,a,o,i,s){var l;if(this.isBinary(n)){var u=new e.Mesh("stlmesh",r);return this.parseBinary(u,n),o&&o.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]),o&&o.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,a=0;a<n;a++)if(r.getUint8(a)>127)return!0;return!1},t.prototype.parseBinary=function(t,r){for(var n=new DataView(r),a=n.getUint32(80,!0),o=0,i=new Float32Array(3*a*3),s=new Float32Array(3*a*3),l=new Uint32Array(3*a),u=0,c=0;c<a;c++){for(var f=84+50*c,d=n.getFloat32(f,!0),h=n.getFloat32(f+4,!0),p=n.getFloat32(f+8,!0),m=1;m<=3;m++){var T=f+12*m;i[o]=n.getFloat32(T,!0),i[o+2]=n.getFloat32(T+4,!0),i[o+1]=n.getFloat32(T+8,!0),s[o]=d,s[o+2]=h,s[o+1]=p,o+=3}l[u]=u++,l[u]=u++,l[u]=u++}t.setVerticesData(e.VertexBuffer.PositionKind,i),t.setVerticesData(e.VertexBuffer.NormalKind,s),t.setIndices(l),t.computeWorldMatrix(!0)},t.prototype.parseASCII=function(t,r){for(var n,a=[],o=[],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);)a.push(Number(c[1]),Number(c[5]),Number(c[3])),o.push(f[0],f[1],f[2]);i.push(s++,s++,s++),this.vertexPattern.lastIndex=0}}this.facetsPattern.lastIndex=0,t.setVerticesData(e.VertexBuffer.PositionKind,a),t.setVerticesData(e.VertexBuffer.NormalKind,o),t.setIndices(i),t.computeWorldMatrix(!0)},t})();e.STLFileLoader=t,e.SceneLoader&&e.SceneLoader.RegisterPlugin(new t)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function t(){this.materials=[]}return t.prototype.parseMTL=function(r,n,a){for(var o,i,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?(i&&this.materials.push(i),i=new e.StandardMaterial(d,r)):"kd"===f?(o=d.split(/\s+/,3).map(parseFloat),i.diffuseColor=e.Color3.FromArray(o)):"ka"===f?(o=d.split(/\s+/,3).map(parseFloat),i.ambientColor=e.Color3.FromArray(o)):"ks"===f?(o=d.split(/\s+/,3).map(parseFloat),i.specularColor=e.Color3.FromArray(o)):"ke"===f?(o=d.split(/\s+/,3).map(parseFloat),i.emissiveColor=e.Color3.FromArray(o)):"ns"===f?i.specularPower=parseFloat(d):"d"===f?i.alpha=parseFloat(d):"map_ka"===f?i.ambientTexture=t._getTexture(a,d,r):"map_kd"===f?i.diffuseTexture=t._getTexture(a,d,r):"map_ks"===f?i.specularTexture=t._getTexture(a,d,r):"map_ns"===f||("map_bump"===f?i.bumpTexture=t._getTexture(a,d,r):"map_d"===f&&(i.opacityTexture=t._getTexture(a,d,r)))}}this.materials.push(i)},t._getTexture=function(t,r,n){if(!r)return null;var a=t;if("file:"===t){var o=r.lastIndexOf("\\");o===-1&&(o=r.lastIndexOf("/")),a+=o>-1?r.substr(o+1):r}else a+=r;return new e.Texture(a,n)},t})();e.MTLFileLoader=t;var r=(function(){function r(){this.name="obj",this.extensions=".obj",this.obj=/^o/,this.group=/^g/,this.mtllib=/^mtllib /,this.usemtl=/^usemtl /,this.smooth=/^s /,this.vertexPattern=/v( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.normalPattern=/vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.uvPattern=/vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.facePattern1=/f\s+(([\d]{1,}[\s]?){3,})+/,this.facePattern2=/f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern3=/f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern4=/f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/}return r.prototype._loadMTL=function(t,r,n){var a=e.Tools.BaseUrl+r+t;e.Tools.LoadFile(a,n,null,null,!1,(function(){console.warn("Error - Unable to load "+a)}))},r.prototype.importMesh=function(e,t,r,n,a,o,i){var s=this._parseSolid(e,t,r,n);return a&&s.forEach((function(e){a.push(e)})),!0},r.prototype.load=function(e,t,r){return this.importMesh(null,e,t,r,null,null,null)},r.prototype._parseSolid=function(n,a,o,i){for(var s,l=[],u=[],c=[],f=[],d=[],h=[],p=[],m=[],T=[],E=0,A=!1,_=[],y=[],g=[],v=[],L="",b="",x=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 r===-1?-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},I=function(e,t,n,a,o,i){var s;s=r.OPTIMIZE_WITH_UV?F(T,[e,n,t]):O(T,[e,n]),s==-1?(d.push(h.length),h.push(a),p.push(o),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++)_.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],S(),d.reverse(),s.indices=d.slice(),s.positions=_.slice(),s.normals=y.slice(),s.uvs=g.slice(),d=[],_=[],y=[],g=[])},B=o.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("/"),a=parseInt(n[0])-1,o=parseInt(n[1])-1,i=parseInt(n[2])-1;I(a,o,i,l[a],c[o],u[i])}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 a=v[n].split("//"),o=parseInt(a[0])-1,i=parseInt(a[1])-1;I(o,1,i,l[o],e.Vector2.Zero(),u[i])}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 a=v[n].split("/"),o=parseInt(a[0])-1,i=parseInt(a[1])-1;I(o,i,0,l[o],c[i],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 a=parseInt(v[n])-1;I(a,0,0,l[a],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),A=!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)}A&&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)}A&&(s=f[f.length-1],d.reverse(),S(),s.indices=d,s.positions=_,s.normals=y,s.uvs=g),A||(d.reverse(),S(),f.push({name:e.Geometry.RandomId(),indices:d,positions:_,normals:y,uvs:g,materialName:L}));for(var U=[],V=new Array,k=0;k<f.length;k++){if(n&&f[k].name)if(n instanceof Array){if(n.indexOf(f[k].name)==-1)continue}else if(f[k].name!==n)continue;s=f[k];var Y=new e.Mesh(f[k].name,a);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),U.push(Y)}return""!==b&&this._loadMTL(b,i,(function(e){x.parseMTL(a,e,i);for(var t=0;t<x.materials.length;t++){for(var r,n=0,o=[];(r=V.indexOf(x.materials[t].name,n))>-1;)o.push(r),n=r+1;if(r==-1&&0==o.length)x.materials[t].dispose();else for(var s=0;s<o.length;s++)U[o[s]].material=x.materials[t]}})),U},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(),this._loader=null)},e.prototype.importMeshAsync=function(t,r,n,a,o,i,s){var l=e._parse(n,s);l&&(this.onParsed&&this.onParsed(l),this._loader=this._getLoader(l,s),this._loader&&this._loader.importMeshAsync(t,r,l,a,o,i,s))},e.prototype.loadAsync=function(t,r,n,a,o,i){var s=e._parse(r,i);if(s&&(this.onParsed&&this.onParsed(s),this._loader=this._getLoader(s,i),this._loader))return this._loader.loadAsync(t,s,n,a,o,i)},e.prototype.canDirectLoad=function(e){return e.indexOf("scene")!==-1&&e.indexOf("node")!==-1},e._parse=function(t,r){try{return t instanceof ArrayBuffer?e._parseBinary(t,r):{json:JSON.parse(t),bin:null}}catch(e){return r(e.message),null}},e.prototype._getLoader=function(t,r){var n={major:2,minor:0},a=t.json.asset||{},o=e._parseVersion(a.version);if(!o)return r("Invalid version: "+a.version),null;if(void 0!==a.minVersion){var i=e._parseVersion(a.minVersion);if(!i)return r("Invalid minimum version: "+a.minVersion),null;if(e._compareVersion(i,n)>0)return r("Incompatible minimum version: "+a.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},l=s[o.major];return l?l(this):(r("Unsupported version: "+a.version),null)},e._parseBinary=function(t,r){var a={Magic:1179937895},o=new n(t),i=o.readUint32();if(i!==a.Magic)return r("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return e._parseV1(o,r);case 2:return e._parseV2(o,r)}return r("Unsupported version: "+s),null},e._parseV1=function(t,r){var n={JSON:0},a=t.readUint32();if(a!=t.getLength())return r("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o,i=t.readUint32(),s=t.readUint32();switch(s){case n.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(i)));break;default:return r("Unexpected content format: "+s),null}var l=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(l)}},e._parseV2=function(t,r){var n={JSON:1313821514,BIN:5130562},a=t.readUint32();if(a!==t.getLength())return r("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o=t.readUint32();if(t.readUint32()!==n.JSON)return r("First chunk format is not JSON"),null;for(var i=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),s=null;t.getPosition()<t.getLength();){var l=t.readUint32();switch(t.readUint32()){case n.JSON:return r("Unexpected JSON chunk"),null;case n.BIN:s=t.readUint8Array(l);break;default:t.skipBytes(l)}}return{json:i,bin:s}},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})(),a=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],o=["world","view","projection","worldView","worldViewProjection","mBones"],i=["translation","rotation","scale"],s=["position","rotationQuaternion","scaling"],l=function(e,t){for(var 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 a=e[n];r[t][n]=a}},f=function(e){if(e)for(var t=0;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},d=function(e){if("NORMAL"===e.semantic)return"normal";if("POSITION"===e.semantic)return"position";if("JOINT"===e.semantic)return"matricesIndices";if("WEIGHT"===e.semantic)return"matricesWeights";if("COLOR"===e.semantic)return"color";if(e.semantic.indexOf("TEXCOORD_")!==-1){var t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}return null},h=function(r){for(var n in r.animations)for(var a=r.animations[n],o=null,l=0;l<a.channels.length;l++){var u=a.channels[l],c=a.samplers[u.sampler];if(c){var f=null,d=null;a.parameters?(f=a.parameters[c.input],d=a.parameters[c.output]):(f=c.input,d=c.output);var h=t.GLTFUtils.GetBufferFromAccessor(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,A=u.target.path,_=i.indexOf(A);_!==-1&&(A=s[_]);var y=e.Animation.ANIMATIONTYPE_MATRIX;E||("rotationQuaternion"===A?(y=e.Animation.ANIMATIONTYPE_QUATERNION,T.rotationQuaternion=new e.Quaternion):y=e.Animation.ANIMATIONTYPE_VECTOR3);var g=null,v=[],L=0,b=!1;E&&o&&o.getKeys().length===h.length&&(g=o,b=!0),b||(g=new e.Animation(n,E?"_matrix":A,1,y,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var x=0;x<h.length;x++){var N=null;if("rotationQuaternion"===A?(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,I=e.Vector3.Zero(),S=M.getBaseMatrix();b&&(S=o.getKeys()[x].value),S.decompose(I,F,O),"position"===A?O=N:"rotationQuaternion"===A?F=N:I=N,N=e.Matrix.Compose(I,F,O)}b?o.getKeys()[x].value=N:v.push({frame:h[x],value:N})}b||(g.setKeys(v),T.animations.push(g)),o=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]),a=e.Quaternion.FromArray(t.rotation||[0,0,0,1]),o=e.Vector3.FromArray(t.translation||[0,0,0]);r=e.Matrix.Compose(n,a,o)}else r=e.Matrix.FromArray(t.matrix);return r},m=function(t,r,n,a){for(var o=0;o<a.bones.length;o++)if(a.bones[o].name===n)return a.bones[o];var i=t.nodes;for(var s in i){var l=i[s];if(l.jointName)for(var u=l.children,o=0;o<u.length;o++){var c=t.nodes[u[o]];if(c.jointName&&c.jointName===n){var f=p(l),d=new e.Bone(l.name,a,m(t,r,l.jointName,a),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],a=0;a<n.node.children.length;a++){var o=n.node.children[a];if(o===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 a in r)if(n=r[a],n.jointName===t)return{node:n,id:a};return null},A=function(e,t){for(var r=0;r<e.jointNames.length;r++)if(e.jointNames[r]===t)return!0;return!1},_=function(t,r,n,a){for(var o in t.nodes){var i=t.nodes[o],s=o;if(i.jointName&&!A(n,i.jointName)){var l=p(i),u=new e.Bone(i.name,r,null,l);u.id=s,a.push({bone:u,node:i,id:s})}}for(var c=0;c<a.length;c++)for(var f=a[c],d=f.node.children,h=0;h<d.length;h++){for(var m=null,T=0;T<a.length;T++)if(a[T].id===d[h]){m=a[T];break}m&&(m.bone._parent=f.bone,f.bone.children.push(m.bone))}},y=function(t,r,n,a,o){if(a||(a=new e.Skeleton(r.name,"",t.scene)),!r.babylonSkeleton)return a;var i=[],s=[];_(t,a,r,i),a.bones=[];for(var l=0;l<r.jointNames.length;l++){var u=E(t,r.jointNames[l]),c=u.node;if(c){var o=u.id,f=t.scene.getBoneByID(o);if(f)a.bones.push(f);else{for(var d=!1,h=null,A=0;A<l;A++){var y=E(t,r.jointNames[A]).node;if(y){var g=y.children;if(g){d=!1;for(var v=0;v<g.length;v++)if(g[v]===o){h=m(t,r,r.jointNames[A],a),d=!0;break}if(d)break}}else e.Tools.Warn("Joint named "+r.jointNames[A]+" does not exist when looking for parent")}var L=p(c);!h&&i.length>0&&(h=T(i,o))&&s.indexOf(h)===-1&&s.push(h);new e.Bone(c.jointName,a,h,L).id=o}}else e.Tools.Warn("Joint named "+r.jointNames[l]+" does not exist")}var b=a.bones;a.bones=[];for(var l=0;l<r.jointNames.length;l++){var u=E(t,r.jointNames[l]);if(u)for(var A=0;A<b.length;A++)if(b[A].id===u.id){a.bones.push(b[A]);break}}a.prepare();for(var l=0;l<s.length;l++)a.bones.push(s[l]);return a},g=function(r,n,a,o,i){if(i||(i=new e.Mesh(n.name,r.scene),i.id=o),!n.babylonNode)return i;var s=new e.MultiMaterial("multimat"+o,r.scene);i.material||(i.material=s);for(var l=new e.VertexData,u=new e.Geometry(o,r.scene,l,!1,i),c=new Array,d=new Array,h=new Array,p=new Array,m=0;m<a.length;m++){var T=a[m],E=r.meshes[T];if(E)for(var A=0;A<E.primitives.length;A++){var _=new e.VertexData,y=E.primitives[A];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)_.normals=new Float32Array(L.length),_.normals.set(L);else if("POSITION"===b){if(e.GLTFFileLoader.HomogeneousCoordinates){_.positions=new Float32Array(L.length-L.length/4);for(var x=0;x<L.length;x+=4)_.positions[x]=L[x],_.positions[x+1]=L[x+1],_.positions[x+2]=L[x+2]}else _.positions=new Float32Array(L.length),_.positions.set(L);d.push(_.positions.length)}else if(b.indexOf("TEXCOORD_")!==-1){var N=Number(b.split("_")[1]),M=e.VertexBuffer.UVKind+(0===N?"":N+1),O=new Float32Array(L.length);O.set(L),f(O),_.set(O,M)}else"JOINT"===b?(_.matricesIndices=new Float32Array(L.length),_.matricesIndices.set(L)):"WEIGHT"===b?(_.matricesWeights=new Float32Array(L.length),_.matricesWeights.set(L)):"COLOR"===b&&(_.colors=new Float32Array(L.length),_.colors.set(L));if(v=r.accessors[y.indices])L=t.GLTFUtils.GetBufferFromAccessor(r,v),_.indices=new Int32Array(L.length),_.indices.set(L),p.push(_.indices.length);else{for(var F=[],x=0;x<_.positions.length/3;x++)F.push(x);_.indices=new Int32Array(F),p.push(_.indices.length)}l.merge(_),_=void 0;var I=r.scene.getMaterialByID(y.material);s.subMaterials.push(null===I?t.GLTFUtils.GetDefaultMaterial(r.scene):I),c.push(0===c.length?0:c[c.length-1]+d[d.length-2]),h.push(0===h.length?0:h[h.length-1]+p[p.length-2])}}u.setAllVerticesData(l,!1),i.computeWorldMatrix(!0),i.subMeshes=[];for(var S=0,m=0;m<a.length;m++){var T=a[m],E=r.meshes[T];if(E)for(var A=0;A<E.primitives.length;A++)E.primitives[A].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 a=new e.Vector3(0,0,0),o=new e.Quaternion,i=new e.Vector3(0,0,0);e.Matrix.FromArray(r.matrix).decompose(i,o,a),v(t,a,o,i)}else v(t,e.Vector3.FromArray(r.translation),e.Quaternion.FromArray(r.rotation),e.Vector3.FromArray(r.scale));t.computeWorldMatrix(!0)},b=function(t,r,n,a){var o=null;if(t.importOnlyMeshes&&(r.skin||r.meshes)&&t.importMeshesNames.length>0&&t.importMeshesNames.indexOf(r.name)===-1)return null;if(r.skin){if(r.meshes){var i=t.skins[r.skin],s=g(t,r,r.meshes,n,r.babylonNode);s.skeleton=t.scene.getLastSkeletonByID(r.skin),null===s.skeleton&&(s.skeleton=y(t,i,0,i.babylonSkeleton,r.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),o=s}}else if(r.meshes){var s=g(t,r,r.mesh?[r.mesh]:r.meshes,n,r.babylonNode);o=s}else if(!r.light||r.babylonNode||t.importOnlyMeshes){if(r.camera&&!r.babylonNode&&!t.importOnlyMeshes){var 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()),o=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),o=f}}}else{var d=t.lights[r.light];if(d)if("ambient"===d.type){var h=d[d.type],p=new e.HemisphericLight(r.light,e.Vector3.Zero(),t.scene);p.name=r.name,h.color&&(p.diffuse=e.Color3.FromArray(h.color)),o=p}else if("directional"===d.type){var m=d[d.type],T=new e.DirectionalLight(r.light,e.Vector3.Zero(),t.scene);T.name=r.name,m.color&&(T.diffuse=e.Color3.FromArray(m.color)),o=T}else if("point"===d.type){var E=d[d.type],A=new e.PointLight(r.light,e.Vector3.Zero(),t.scene);A.name=r.name,E.color&&(A.diffuse=e.Color3.FromArray(E.color)),o=A}else if("spot"===d.type){var _=d[d.type],b=new e.SpotLight(r.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);b.name=r.name,_.color&&(b.diffuse=e.Color3.FromArray(_.color)),_.fallOfAngle&&(b.angle=_.fallOfAngle),_.fallOffExponent&&(b.exponent=_.fallOffExponent),o=b}}if(!r.jointName){if(r.babylonNode)return r.babylonNode;if(null===o){var x=new e.Mesh(r.name,t.scene);r.babylonNode=x,o=x}}if(null!==o){if(r.matrix&&o instanceof e.Mesh)L(o,r);else{var N=r.translation||[0,0,0],M=r.rotation||[0,0,0,1],O=r.scale||[1,1,1];v(o,e.Vector3.FromArray(N),e.Quaternion.FromArray(M),e.Vector3.FromArray(O))}o.updateCache(!0),r.babylonNode=o}return o},x=function(e,t,r,n){var a=e.nodes[t],o=null;if(n=!(e.importOnlyMeshes&&!n)||(e.importMeshesNames.indexOf(a.name)!==-1||0===e.importMeshesNames.length),!a.jointName&&n&&null!==(o=b(e,a,t))&&(o.id=t,o.parent=r),a.children)for(var i=0;i<a.children.length;i++)x(e,a.children[i],o,n)},N=function(e){var t=e.currentScene;if(t)for(var r=0;r<t.nodes.length;r++)x(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++)x(e,t.nodes[r],null)}h(e);for(var r=0;r<e.scene.skeletons.length;r++){var a=e.scene.skeletons[r];e.scene.beginAnimation(a,0,Number.MAX_VALUE,!0,1)}},M=function(e,r,n,a,o,i,s){var l=i.values||o.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,a.getEffect())}}else t.GLTFUtils.SetMatrix(r.scene,e,c,u,a.getEffect());else{var h=l[o.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;a.getEffect().setTexture(u,p)}else t.GLTFUtils.SetUniform(a.getEffect(),u,h,f)}}s(a)},O=function(e,r,n,a,o){var i=a.values||n.parameters,s=n.uniforms;for(var l in o){var u=o[l],c=u.type,f=i[s[l]];if(void 0===f&&(f=u.value),f){var d=function(e){return function(t){u.value&&(r.setTexture(e,t),delete o[e])}};c===t.EParameterType.SAMPLER_2D?t.GLTFLoaderExtension.LoadTextureAsync(e,a.values?f:u.value,d(l),(function(){return d(null)})):u.value&&t.GLTFUtils.SetUniform(r,l,a.values?f:u.value,c)&&delete o[l]}}},F=function(e,t,r){return function(n,a){t.dispose(!0),r("Cannot compile program named "+e.name+". Error: "+a+". Default material will be applied")}},I=function(e,t,r,n,a,o){return function(i){O(e,t,r,n,a),t.onBind=function(i){M(i,e,a,t,r,n,o)}}},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=a.indexOf(s.semantic);if(l!==-1)return delete r[n],o[l]}}return e.currentIdentifier},R=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,a,o,i){var s=r.buffers[n];t.GLTFUtils.IsBase64(s.uri)?setTimeout((function(){return a(new Uint8Array(t.GLTFUtils.DecodeBase64(s.uri)))})):e.Tools.LoadFile(r.rootUrl+s.uri,(function(e){return a(new Uint8Array(e))}),i,null,!0,(function(e){o(e.status+" "+e.statusText)}))},i.LoadTextureBufferAsync=function(r,n,a,o){var i=r.textures[n];if(!i||!i.source)return void o(null);if(i.babylonTexture)return void a(null);var s=r.images[i.source];t.GLTFUtils.IsBase64(s.uri)?setTimeout((function(){return a(new Uint8Array(t.GLTFUtils.DecodeBase64(s.uri)))})):e.Tools.LoadFile(r.rootUrl+s.uri,(function(e){return a(new Uint8Array(e))}),null,null,!0,(function(e){o(e.status+" "+e.statusText)}))},i.CreateTextureAsync=function(r,n,a,o,i){var s=r.textures[n];if(s.babylonTexture)return void o(s.babylonTexture);var 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([a]),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,o(p)},i.LoadShaderStringAsync=function(r,n,a,o){var i=r.shaders[n];if(t.GLTFUtils.IsBase64(i.uri)){a(atob(i.uri.split(",")[1]))}else e.Tools.LoadFile(r.rootUrl+i.uri,a,null,null,!1,(function(e){o(e.status+" "+e.statusText)}))},i.LoadMaterialAsync=function(i,s,l,u){var c=i.materials[s],f=i.techniques[c.technique];if(!f){
- var h=new e.StandardMaterial(s,i.scene);return h.diffuseColor=new e.Color3(.5,.5,.5),h.sideOrientation=e.Material.CounterClockWiseSideOrientation,void l(h)}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=[],b=[],x=[];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?x.push(N):L.push(N);else{var R=a.indexOf(O.semantic);R!==-1?(L.push(o[R]),delete v[N]):L.push(N)}}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){A+=d(P),G=!0;break}}G||(A+=S(y,f,v))}else A+=y.currentString}for(;!g.isEnd()&&g.getNextToken();){var C=g.currentToken;C===r.IDENTIFIER?_+=S(g,f,v):_+=g.currentString}var D={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},U={attributes:b,uniforms:L,samplers:x,needAlphaBlending:m&&m.enable&&m.enable.indexOf(3042)!==-1};e.Effect.ShadersStore[p.vertexShader+s+"VertexShader"]=A,e.Effect.ShadersStore[p.fragmentShader+s+"PixelShader"]=_;var V=new e.ShaderMaterial(s,i.scene,D,U);if(V.onError=F(p,V,u),V.onCompiled=I(i,V,f,c,v,l),V.sideOrientation=e.Material.CounterClockWiseSideOrientation,m&&m.functions){var k=m.functions;k.cullFace&&k.cullFace[0]!==t.ECullingType.BACK&&(V.backFaceCulling=!1);var 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))}},i})();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.dispose=function(){},r.prototype.importMeshAsync=function(r,n,a,o,i,s,l){var u=this;return n.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(n,a,o,(function(t){t.importOnlyMeshes=!0,""===r?t.importMeshesNames=[]:"string"==typeof r?t.importMeshesNames=[r]:!r||r instanceof Array?(t.importMeshesNames=[],e.Tools.Warn("Argument meshesNames must be of type string or string[]")):t.importMeshesNames=[r],u._createNodes(t);var n=new Array,a=new Array;for(var o in t.nodes){var l=t.nodes[o];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&&a.push(f.babylonSkeleton)}u._loadBuffersAsync(t,(function(){u._loadShadersAsync(t,(function(){R(t),N(t),!e.GLTFFileLoader.IncrementalLoading&&i&&i(n,null,a)}))}),s),e.GLTFFileLoader.IncrementalLoading&&i&&i(n,null,a)}),l),!0},r.prototype.loadAsync=function(r,n,a,o,i,s){var l=this;r.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(r,n,a,(function(r){t.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(r,(function(){l._createNodes(r),l._loadBuffersAsync(r,(function(){l._loadShadersAsync(r,(function(){R(r),N(r),e.GLTFFileLoader.IncrementalLoading||o()}))})),e.GLTFFileLoader.IncrementalLoading&&o()}),s)}),s)},r.prototype._loadShadersAsync=function(r,n){var a=!1,o=function(a,o){t.GLTFLoaderExtension.LoadShaderStringAsync(r,a,(function(i){r.loadedShaderCount++,i&&(e.Effect.ShadersStore[a+(o.type===t.EShaderType.VERTEX?"VertexShader":"PixelShader")]=i),r.loadedShaderCount===r.shaderscount&&n()}),(function(){e.Tools.Error("Error when loading shader program named "+a+" located at "+o.uri)}))};for(var i in r.shaders){a=!0;var s=r.shaders[i];s?o.bind(this,i,s)():e.Tools.Error("No shader named: "+i)}a||n()},r.prototype._loadBuffersAsync=function(r,n,a){var o=!1,i=function(a,o){t.GLTFLoaderExtension.LoadBufferAsync(r,a,(function(t){r.loadedBufferCount++,t&&(t.byteLength!=r.buffers[a].byteLength&&e.Tools.Error("Buffer named "+a+" is length "+t.byteLength+". Expected: "+o.byteLength),r.loadedBufferViews[a]=t),r.loadedBufferCount===r.buffersCount&&n()}),(function(){e.Tools.Error("Error when loading buffer named "+a+" located at "+o.uri)}))};for(var s in r.buffers){o=!0;var l=r.buffers[s];l?i.bind(this,s,l)():e.Tools.Error("No buffer named: "+s)}o||n()},r.prototype._createNodes=function(e){var t=e.currentScene;if(t)for(var r=0;r<t.nodes.length;r++)x(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++)x(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,a,o,i){var s=null;switch("MODEL"===a.semantic?s=n.getWorldMatrix():"PROJECTION"===a.semantic?s=r.getProjectionMatrix():"VIEW"===a.semantic?s=r.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===a.semantic?s=e.Matrix.Transpose(n.getWorldMatrix().multiply(r.getViewMatrix()).invert()):"MODELVIEW"===a.semantic?s=n.getWorldMatrix().multiply(r.getViewMatrix()):"MODELVIEWPROJECTION"===a.semantic?s=n.getWorldMatrix().multiply(r.getTransformMatrix()):"MODELINVERSE"===a.semantic?s=n.getWorldMatrix().invert():"VIEWINVERSE"===a.semantic?s=r.getViewMatrix().invert():"PROJECTIONINVERSE"===a.semantic?s=r.getProjectionMatrix().invert():"MODELVIEWINVERSE"===a.semantic?s=n.getWorldMatrix().multiply(r.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===a.semantic?s=n.getWorldMatrix().multiply(r.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===a.semantic&&(s=e.Matrix.Transpose(n.getWorldMatrix().invert())),a.type){case t.EParameterType.FLOAT_MAT2:i.setMatrix2x2(o,e.Matrix.GetAsMatrix2x2(s));break;case t.EParameterType.FLOAT_MAT3:i.setMatrix3x3(o,e.Matrix.GetAsMatrix3x3(s));break;case t.EParameterType.FLOAT_MAT4:i.setMatrix(o,s)}},r.SetUniform=function(r,n,a,o){switch(o){case t.EParameterType.FLOAT:return r.setFloat(n,a),!0;case t.EParameterType.FLOAT_VEC2:return r.setVector2(n,e.Vector2.FromArray(a)),!0;case t.EParameterType.FLOAT_VEC3:return r.setVector3(n,e.Vector3.FromArray(a)),!0;case t.EParameterType.FLOAT_VEC4:return r.setVector4(n,e.Vector4.FromArray(a)),!0;default:return!1}},r.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},r.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),r=t.length,n=new Uint8Array(new ArrayBuffer(r)),a=0;a<r;a++)n[a]=t.charCodeAt(a);return n.buffer},r.GetWrapMode=function(r){switch(r){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:default:return e.Texture.WRAP_ADDRESSMODE}},r.GetByteStrideFromType=function(e){switch(e.type){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 1}},r.GetTextureFilterMode=function(r){switch(r){case t.ETextureFilterType.LINEAR:case t.ETextureFilterType.LINEAR_MIPMAP_NEAREST:case t.ETextureFilterType.LINEAR_MIPMAP_LINEAR:return e.Texture.TRILINEAR_SAMPLINGMODE;case t.ETextureFilterType.NEAREST:case t.ETextureFilterType.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_SAMPLINGMODE;default:return e.Texture.BILINEAR_SAMPLINGMODE}},r.GetBufferFromBufferView=function(e,r,n,a,o){var n=r.byteOffset+n,i=e.loadedBufferViews[r.buffer];if(n+a>i.byteLength)throw new Error("Buffer access is out of range");var s=i.buffer;switch(n+=i.byteOffset,o){case t.EComponentType.BYTE:return new Int8Array(s,n,a);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,n,a);case t.EComponentType.SHORT:return new Int16Array(s,n,a);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,n,a);default:return new Float32Array(s,n,a)}},r.GetBufferFromAccessor=function(e,t){var n=e.bufferViews[t.bufferView],a=t.count*r.GetByteStrideFromType(t);return r.GetBufferFromBufferView(e,n,t.byteOffset,a,t.componentType)},r.DecodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;++n)t+=String.fromCharCode(e[n]);return t},r.GetDefaultMaterial=function(t){if(!r._DefaultMaterial){e.Effect.ShadersStore.GLTFDefaultMaterialVertexShader=["precision highp float;","","uniform mat4 worldView;","uniform mat4 projection;","","attribute vec3 position;","","void main(void)","{"," gl_Position = projection * worldView * vec4(position, 1.0);","}"].join("\n"),e.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");var n={vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},a={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};r._DefaultMaterial=new e.ShaderMaterial("GLTFDefaultMaterial",t,n,a),r._DefaultMaterial.setColor4("u_emission",new e.Color4(.5,.5,.5,1))}return r._DefaultMaterial},r._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,a){return!1},t.prototype.loadRuntimeExtensionsAsync=function(e,t,r){return!1},t.prototype.loadBufferAsync=function(e,t,r,n,a){return!1},t.prototype.loadTextureBufferAsync=function(e,t,r,n){return!1},t.prototype.createTextureAsync=function(e,t,r,n,a){return!1},t.prototype.loadShaderStringAsync=function(e,t,r,n){return!1},t.prototype.loadMaterialAsync=function(e,t,r,n){return!1},t.LoadRuntimeAsync=function(r,n,a,o,i){t.ApplyExtensions((function(e){return e.loadRuntimeAsync(r,n,a,o,i)}),(function(){setTimeout((function(){o(e.GLTFLoaderBase.CreateRuntime(n.json,r,a))}))}))},t.LoadRuntimeExtensionsAsync=function(e,r,n){t.ApplyExtensions((function(t){return t.loadRuntimeExtensionsAsync(e,r,n)}),(function(){setTimeout((function(){r()}))}))},t.LoadBufferAsync=function(r,n,a,o,i){t.ApplyExtensions((function(e){return e.loadBufferAsync(r,n,a,o,i)}),(function(){e.GLTFLoaderBase.LoadBufferAsync(r,n,a,o,i)}))},t.LoadTextureAsync=function(e,r,n,a){t.LoadTextureBufferAsync(e,r,(function(o){return t.CreateTextureAsync(e,r,o,n,a)}),a)},t.LoadShaderStringAsync=function(r,n,a,o){t.ApplyExtensions((function(e){return e.loadShaderStringAsync(r,n,a,o)}),(function(){e.GLTFLoaderBase.LoadShaderStringAsync(r,n,a,o)}))},t.LoadMaterialAsync=function(r,n,a,o){t.ApplyExtensions((function(e){return e.loadMaterialAsync(r,n,a,o)}),(function(){e.GLTFLoaderBase.LoadMaterialAsync(r,n,a,o)}))},t.LoadTextureBufferAsync=function(r,n,a,o){t.ApplyExtensions((function(e){return e.loadTextureBufferAsync(r,n,a,o)}),(function(){e.GLTFLoaderBase.LoadTextureBufferAsync(r,n,a,o)}))},t.CreateTextureAsync=function(r,n,a,o,i){t.ApplyExtensions((function(e){return e.createTextureAsync(r,n,a,o,i)}),(function(){e.GLTFLoaderBase.CreateTextureAsync(r,n,a,o,i)}))},t.ApplyExtensions=function(t,r){for(var n in e.GLTFLoader.Extensions){if(t(e.GLTFLoader.Extensions[n]))return}r()},t})();e.GLTFLoaderExtension=t})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(t){function r(){return t.call(this,"KHR_binary_glTF")||this}return __extends(r,t),r.prototype.loadRuntimeAsync=function(t,r,n,a,o){var i=r.json.extensionsUsed;return!(!i||i.indexOf(this.name)===-1)&&(this._bin=r.bin,a(e.GLTFLoaderBase.CreateRuntime(r.json,t,n)),!0)},r.prototype.loadBufferAsync=function(e,t,r,n){return e.extensionsUsed.indexOf(this.name)!==-1&&("binary_glTF"===t&&(r(this._bin),!0))},r.prototype.loadTextureBufferAsync=function(t,r,n,a){var o=t.textures[r],i=t.images[o.source];if(!(i.extensions&&this.name in i.extensions))return!1;var s=i.extensions[this.name],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,a){var o=t.shaders[r];if(!(o.extensions&&this.name in o.extensions))return!1;var i=o.extensions[this.name],s=t.bufferViews[i.bufferView],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 a=t.extensions[this.name];if(!a)return!1;var o=a.lights;if(o)for(var i in o){var s=o[i];switch(s.type){case"ambient":var l=new e.HemisphericLight(s.name,new e.Vector3(0,1,0),t.scene),u=s.ambient;l.diffuse=e.Color3.FromArray(u.color||[1,1,1]);break;case"point":var c=new e.PointLight(s.name,new e.Vector3(10,10,10),t.scene),f=s.point;c.diffuse=e.Color3.FromArray(f.color||[1,1,1]);break;case"directional":var d=new e.DirectionalLight(s.name,new e.Vector3(0,-1,0),t.scene),h=s.directional;d.diffuse=e.Color3.FromArray(h.color||[1,1,1]);break;case"spot":var p=s.spot,m=new e.SpotLight(s.name,new e.Vector3(0,10,0),new e.Vector3(0,-1,0),s.spot.fallOffAngle||Math.PI,s.spot.fallOffExponent||0,t.scene);m.diffuse=e.Color3.FromArray(p.color||[1,1,1]);break;default:e.Tools.Warn('GLTF Material Common extension: light type "'+s.type+"” not supported")}}return!1},n.prototype.loadMaterialAsync=function(t,r,n,a){var o=t.materials[r];if(!o||!o.extensions)return!1;var i=o.extensions[this.name];if(!i)return!1;var s=new e.StandardMaterial(r,t.scene);return s.sideOrientation=e.Material.CounterClockWiseSideOrientation,"CONSTANT"===i.technique&&(s.disableLighting=!0),s.backFaceCulling=void 0!==i.doubleSided&&!i.doubleSided,s.alpha=void 0===i.values.transparency?1:i.values.transparency,s.specularPower=void 0===i.values.shininess?0:i.values.shininess,"string"==typeof i.values.ambient?this._loadTexture(t,i.values.ambient,s,"ambientTexture",a):s.ambientColor=e.Color3.FromArray(i.values.ambient||[0,0,0]),"string"==typeof i.values.diffuse?this._loadTexture(t,i.values.diffuse,s,"diffuseTexture",a):s.diffuseColor=e.Color3.FromArray(i.values.diffuse||[0,0,0]),"string"==typeof i.values.emission?this._loadTexture(t,i.values.emission,s,"emissiveTexture",a):s.emissiveColor=e.Color3.FromArray(i.values.emission||[0,0,0]),"string"==typeof i.values.specular?this._loadTexture(t,i.values.specular,s,"specularTexture",a):s.specularColor=e.Color3.FromArray(i.values.specular||[0,0,0]),!0},n.prototype._loadTexture=function(e,r,n,a,o){t.GLTFLoaderBase.LoadTextureBufferAsync(e,r,(function(i){t.GLTFLoaderBase.CreateTextureAsync(e,r,i,(function(e){return n[a]=e}),o)}),o)},n})(t.GLTFLoaderExtension);t.GLTFMaterialsCommonExtension=r,t.GLTFLoader.RegisterExtension(new r)})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT"})(e.EComponentType||(e.EComponentType={}));!(function(e){e[e.POINTS=0]="POINTS",e[e.LINES=1]="LINES",e[e.LINE_LOOP=2]="LINE_LOOP",e[e.LINE_STRIP=3]="LINE_STRIP",e[e.TRIANGLES=4]="TRIANGLES",e[e.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",e[e.TRIANGLE_FAN=6]="TRIANGLE_FAN"})(e.EMeshPrimitiveMode||(e.EMeshPrimitiveMode={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR"})(e.ETextureMagFilter||(e.ETextureMagFilter={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"})(e.ETextureMinFilter||(e.ETextureMinFilter={}));!(function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"})(e.ETextureWrapMode||(e.ETextureWrapMode={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function e(e){this._pendingCount=0,this._callback=e}return e.prototype._addPendingData=function(e){this._pendingCount++},e.prototype._removePendingData=function(e){0==--this._pendingCount&&this._callback()},e})(),n=(function(){function n(t){this._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,a=this._gltf.textures;n<a.length;n++){var o=a[n];o.url&&URL.revokeObjectURL(o.url)}this._gltf=void 0,this._babylonScene=void 0,this._parent=void 0,this._rootUrl=void 0,this._defaultMaterial=void 0,this._rootNode=void 0,this._successCallback=void 0,this._progressCallback=void 0,this._errorCallback=void 0,this._renderReady=!1,this._requests=void 0,this._renderReadyObservable=void 0,this._renderPendingCount=0,this._loaderPendingCount=0,this._loaderTrackers=void 0}},n.prototype.importMeshAsync=function(e,t,r,n,a,o,i){var s=this;this._loadAsync(e,t,r,n,(function(){a(s._getMeshes(),null,s._getSkeletons())}),o,i)},n.prototype.loadAsync=function(e,t,r,n,a,o){this._loadAsync(null,e,t,r,n,a,o)},n.prototype._loadAsync=function(e,r,n,a,o,i,s){var l=this;this._tryCatchOnError((function(){l._loadData(n),l._babylonScene=r,l._rootUrl=a,l._successCallback=o,l._progressCallback=i,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)},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;if(t)for(var r=0,n=t;r<n.length;r++){var a=n[r];a.babylonMesh&&e.push(a.babylonMesh)}return e},n.prototype._getSkeletons=function(){var t=new Array,r=this._gltf.skins;if(r)for(var n=0,a=r;n<a.length;n++){var o=a[n];o.babylonSkeleton instanceof e.Skeleton&&t.push(o.babylonSkeleton)}return t},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 a=n[r];e.push.apply(e,a.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 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,a){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 o=n.nodes;if(this._traverseNodes(r,o,(function(e,t){return e.parent=t,!0}),this._rootNode),a){a instanceof Array||(a=[a]);var i=new Array;this._traverseNodes(r,o,(function(e){return a.indexOf(e.name)===-1||(i.push(e.index),!1)}),this._rootNode),o=i}for(var s=0,l=o;s<l.length;s++){var u=l[s],c=t.GLTFUtils.GetArrayItem(this._gltf.nodes,u);if(!c)throw new Error(r+": Failed to find node "+u);this._loadNode("#/nodes/"+u,c)}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 a=t.GLTFUtils.GetArrayItem(this._gltf.meshes,n.mesh);if(!a)throw new Error(r+": Failed to find mesh "+n.mesh);this._loadMesh("#/meshes/"+n.mesh,n,a)}if(n.babylonMesh.parent=n.parent?n.parent.babylonMesh:null,n.babylonAnimationTargets=n.babylonAnimationTargets||[],n.babylonAnimationTargets.push(n.babylonMesh),null!=n.skin){var o=t.GLTFUtils.GetArrayItem(this._gltf.skins,n.skin);if(!o)throw new Error(r+": Failed to find skin "+n.skin);n.babylonMesh.skeleton=this._loadSkin("#/skins/"+n.skin,o)}if(n.camera,n.children)for(var i=0,s=n.children;i<s.length;i++){var l=s[i],u=t.GLTFUtils.GetArrayItem(this._gltf.nodes,l);if(!u)throw new Error(r+": Failed to find child node "+l);this._loadNode("#/nodes/"+l,u)}}},n.prototype._loadMesh=function(r,n,a){var o=this;n.babylonMesh.name=n.babylonMesh.name||a.name;var i=a.primitives;if(!i||0===i.length)throw new Error(r+": Primitives are missing");this._createMorphTargets(r,n,a),this._loadAllVertexDataAsync(r,a,(function(){o._loadMorphTargets(r,n,a);for(var t=new e.VertexData,s=0,l=i;s<l.length;s++){var u=l[s];t.merge(u.vertexData)}new e.Geometry(n.babylonMesh.name,o._babylonScene,t,!1,n.babylonMesh),n.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,n.babylonMesh),c+=p,f+=m}}));var s=new e.MultiMaterial(n.babylonMesh.name,this._babylonScene);n.babylonMesh.material=s;for(var l=s.subMaterials,u=this,c=0;c<i.length;c++)!(function(e){var a=i[e];if(null==a.material)l[e]=u._getDefaultMaterial();else{var s=t.GLTFUtils.GetArrayItem(u._gltf.materials,a.material);if(!s)throw new Error(r+": Failed to find material "+a.material);u._loadMaterial("#/materials/"+s.index,s,(function(t,r){r&&o._parent.onMaterialLoaded&&o._parent.onMaterialLoaded(t),o._parent.onBeforeMaterialReadyAsync?(o._addLoaderPendingData(s),o._parent.onBeforeMaterialReadyAsync(t,n.babylonMesh,null!=l[e],(function(){o._tryCatchOnError((function(){l[e]=t,o._removeLoaderPendingData(s)}))}))):l[e]=t}))}})(c)},n.prototype._loadAllVertexDataAsync=function(e,t,r){for(var n=t.primitives,a=n.length,o=this,i=0;i<n.length;i++)!(function(i){var s=n[i];o._loadVertexDataAsync(e+"/primitive/"+i,t,s,(function(e){s.vertexData=e,0==--a&&r()}))})(i)},n.prototype._loadVertexDataAsync=function(r,n,a,o){var i=this,s=a.attributes;if(!s)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 l=new e.VertexData,u=Object.keys(s).length,c=this;for(var f in s)!(function(n){var f=t.GLTFUtils.GetArrayItem(c._gltf.accessors,s[n]);if(!f)throw new Error(r+": Failed to find attribute '"+n+"' accessor "+s[n]);c._loadAccessorAsync("#/accessors/"+f.index,f,(function(s){switch(n){case"NORMAL":l.normals=s;break;case"POSITION":l.positions=s;break;case"TANGENT":l.tangents=s;break;case"TEXCOORD_0":l.uvs=s;break;case"TEXCOORD_1":l.uvs2=s;break;case"JOINTS_0":l.matricesIndices=new Float32Array(Array.prototype.slice.apply(s));break;case"WEIGHTS_0":l.matricesWeights=s;break;case"COLOR_0":l.colors=s;break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+n+"'")}if(0==--u)if(null==a.indices){l.indices=new Uint32Array(l.positions.length/3);for(var c=0;c<l.indices.length;c++)l.indices[c]=c;o(l)}else{var f=t.GLTFUtils.GetArrayItem(i._gltf.accessors,a.indices);if(!f)throw new Error(r+": Failed to find indices accessor "+a.indices);i._loadAccessorAsync("#/accessors/"+f.index,f,(function(e){l.indices=e,o(l)}))}}))})(f)},n.prototype._createMorphTargets=function(t,r,n){var a=n.primitives,o=a[0].targets;if(o){for(var i=0,s=a;i<s.length;i++){var l=s[i];if(!l.targets||l.targets.length!=o.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<o.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 a=r.babylonMesh.morphTargetManager;a&&this._loadAllMorphTargetVertexDataAsync(t,r,n,(function(){for(var t=a.numTargets,r=0;r<t;r++){for(var o=new e.VertexData,i=0,s=n.primitives;i<s.length;i++){var l=s[i];o.merge(l.targetsVertexData[r],{tangentLength:3})}var u=a.getTarget(r);u.setNormals(o.normals),u.setPositions(o.positions),u.setTangents(o.tangents)}}))},n.prototype._loadAllMorphTargetVertexDataAsync=function(e,t,r,n){for(var a=r.primitives.length*t.babylonMesh.morphTargetManager.numTargets,o=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){o._loadMorphTargetVertexDataAsync(e+"/targets/"+i,t.vertexData,r[i],(function(e){t.targetsVertexData[i]=e,0==--a&&n()}))})(i)})(l)}},n.prototype._loadMorphTargetVertexDataAsync=function(r,n,a,o){var i=new e.VertexData,s=Object.keys(a).length,l=this;for(var u in a)!(function(u){var c=t.GLTFUtils.GetArrayItem(l._gltf.accessors,a[u]);if(!c)throw new Error(r+": Failed to find attribute '"+u+"' accessor "+a[u]);l._loadAccessorAsync("#/accessors/"+c.index,c,(function(t){var r=t;switch(u){case"NORMAL":for(var a=0;a<r.length;a++)r[a]+=n.normals[a];i.normals=r;break;case"POSITION":for(var a=0;a<r.length;a++)r[a]+=n.positions[a];i.positions=r;break;case"TANGENT":for(var a=0,l=0;a<r.length;a++,l++)r[a]+=n.tangents[l],(a+1)%3==0&&l++;i.tangents=r;break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+u+"'")}0==--s&&o(i)}))})(u)},n.prototype._loadTransform=function(t){var r=e.Vector3.Zero(),n=e.Quaternion.Identity(),a=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(a,n,r)}else t.translation&&(r=e.Vector3.FromArray(t.translation)),t.rotation&&(n=e.Quaternion.FromArray(t.rotation)),t.scale&&(a=e.Vector3.FromArray(t.scale));t.babylonMesh.position=r,t.babylonMesh.rotationQuaternion=n,t.babylonMesh.scaling=a},n.prototype._loadSkin=function(r,n){var a=this,o="skeleton"+n.index;if(n.babylonSkeleton=new e.Skeleton(n.name||o,o,this._babylonScene),null==n.inverseBindMatrices)this._loadBones(r,n,null);else{var i=t.GLTFUtils.GetArrayItem(this._gltf.accessors,n.inverseBindMatrices);if(!i)throw new Error(r+": Failed to find inverse bind matrices attribute "+n.inverseBindMatrices);this._loadAccessorAsync("#/accessors/"+i.index,i,(function(e){a._loadBones(r,n,e)}))}return n.babylonSkeleton},n.prototype._createBone=function(t,r,n,a,o,i){var s=new e.Bone(t.name||"bone"+t.index,r.babylonSkeleton,n,a,null,o,i);return t.babylonBones=t.babylonBones||{},t.babylonBones[r.index]=s,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(s),s},n.prototype._loadBones=function(e,r,n){for(var a={},o=0,i=r.joints;o<i.length;o++){var s=i[o],l=t.GLTFUtils.GetArrayItem(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find joint "+s);this._loadBone(l,r,n,a)}},n.prototype._loadBone=function(t,r,n,a){var o=a[t.index];if(o)return o;var i=r.joints.indexOf(t.index),s=e.Matrix.Identity();n&&i!==-1&&(s=e.Matrix.FromArray(n,16*i),s.invertToRef(s));var l;return t.index!==r.skeleton&&t.parent!==this._rootNode&&(l=this._loadBone(t.parent,r,n,a),s.multiplyToRef(l.getInvertedAbsoluteTransform(),s)),o=this._createBone(t,r,l,this._getNodeMatrix(t),s,i),a[t.index]=o,o},n.prototype._getNodeMatrix=function(t){return t.matrix?e.Matrix.FromArray(t.matrix):e.Matrix.Compose(t.scale?e.Vector3.FromArray(t.scale):e.Vector3.One(),t.rotation?e.Quaternion.FromArray(t.rotation):e.Quaternion.Identity(),t.translation?e.Vector3.FromArray(t.translation):e.Vector3.Zero())},n.prototype._traverseNodes=function(e,r,n,a){void 0===a&&(a=null);for(var o=0,i=r;o<i.length;o++){var s=i[o],l=t.GLTFUtils.GetArrayItem(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find node "+s);this._traverseNode(e,l,n,a)}},n.prototype._traverseNode=function(e,r,n,a){void 0===a&&(a=null),t.GLTFLoaderExtension.TraverseNode(this,e,r,n,a)||n(r,a)&&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],a="#/animations/"+r,o=0;o<n.channels.length;o++){var i=t.GLTFUtils.GetArrayItem(n.channels,o);if(!i)throw new Error(a+": Failed to find channel "+o);var s=t.GLTFUtils.GetArrayItem(n.samplers,i.sampler);if(!s)throw new Error(a+": Failed to find sampler "+i.sampler);this._loadAnimationChannel(n,a+"/channels/"+o,i,a+"/samplers/"+i.sampler,s)}},n.prototype._loadAnimationChannel=function(r,n,a,o,i){var s=t.GLTFUtils.GetArrayItem(this._gltf.nodes,a.target.node);if(!s)throw new Error(n+": Failed to find target node "+a.target.node);var l,u;switch(a.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(n+": Invalid target path '"+a.target.path+"'")}var c,f,d=function(){if(c&&f){var t,n=0;switch(l){case"position":t=function(){var t=e.Vector3.FromArray(f,n);return n+=3,t};break;case"rotationQuaternion":t=function(){var t=e.Quaternion.FromArray(f,n);return n+=4,t};break;case"scaling":t=function(){var t=e.Vector3.FromArray(f,n);return n+=3,t}
- ;break;case"influence":t=function(){for(var e=s.babylonMesh.morphTargetManager.numTargets,t=new Array(e),r=0;r<e;r++)t[r]=f[n++];return t}}var a;switch(i.interpolation){case"LINEAR":a=function(e){return{frame:c[e],value:t()}};break;case"CUBICSPLINE":a=function(e){return{frame:c[e],inTangent:t(),value:t(),outTangent:t()}};break;default:throw new Error(o+": Invalid interpolation '"+i.interpolation+"'")}for(var d=new Array(c.length),h=0;h<c.length;h++)d[h]=a(h);if(r.targets=r.targets||[],"influence"===l)for(var p=s.babylonMesh.morphTargetManager,m=0;m<p.numTargets;m++)!(function(t){var n=p.getTarget(t),a=(r.name||"anim"+r.index)+"_"+t,o=new e.Animation(a,l,1,u);o.setKeys(d.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[t]:void 0,value:e.value[t],outTangent:e.outTangent?e.outTangent[t]:void 0}}))),n.animations.push(o),r.targets.push(n)})(m);else{var T=r.name||"anim"+r.index,E=new e.Animation(T,l,1,u);E.setKeys(d);for(var A=0,_=s.babylonAnimationTargets;A<_.length;A++){var y=_[A];y.animations.push(E.clone()),r.targets.push(y)}}}},h=t.GLTFUtils.GetArrayItem(this._gltf.accessors,i.input);if(!h)throw new Error(o+": Failed to find input accessor "+i.input);this._loadAccessorAsync("#/accessors/"+h.index,h,(function(e){c=e,d()}));var p=t.GLTFUtils.GetArrayItem(this._gltf.accessors,i.output);if(!p)throw new Error(o+": Failed to find output accessor "+i.output);this._loadAccessorAsync("#/accessors/"+p.index,p,(function(e){f=e,d()}))},n.prototype._loadBufferAsync=function(r,n,a){var o=this;if(this._addPendingData(n),n.loadedData)a(n.loadedData),this._removePendingData(n);else if(n.loadedObservable)n.loadedObservable.add((function(e){a(e.loadedData),o._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),a(n.loadedData),this._removePendingData(n)}else n.loadedObservable=new e.Observable,n.loadedObservable.add((function(e){a(e.loadedData),o._removePendingData(e)})),this._loadUri(r,n.uri,(function(e){n.loadedData=e,n.loadedObservable.notifyObservers(n),n.loadedObservable=null}))}},n.prototype._loadBufferViewAsync=function(e,r,n){var a=this,o=t.GLTFUtils.GetArrayItem(this._gltf.buffers,r.buffer);if(!o)throw new Error(e+": Failed to find buffer "+r.buffer);this._loadBufferAsync("#/buffers/"+o.index,o,(function(t){if(!a._disposed){var o;try{o=new Uint8Array(t.buffer,t.byteOffset+(r.byteOffset||0),r.byteLength)}catch(t){throw new Error(e+": "+t.message)}n(o)}}))},n.prototype._loadAccessorAsync=function(e,r,n){var a=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 o=t.GLTFUtils.GetArrayItem(this._gltf.bufferViews,r.bufferView);if(!o)throw new Error(e+": Failed to find buffer view "+r.bufferView);this._loadBufferViewAsync("#/bufferViews/"+o.index,o,(function(i){var s=a._getNumComponentsOfType(r.type);if(0===s)throw new Error(e+": Invalid type ("+r.type+")");var l;try{switch(r.componentType){case t.EComponentType.BYTE:l=a._buildArrayBuffer(Float32Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.UNSIGNED_BYTE:l=a._buildArrayBuffer(Uint8Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.SHORT:l=a._buildArrayBuffer(Int16Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.UNSIGNED_SHORT:l=a._buildArrayBuffer(Uint16Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.UNSIGNED_INT:l=a._buildArrayBuffer(Uint32Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.FLOAT:l=a._buildArrayBuffer(Float32Array,i,r.byteOffset,r.count,s,o.byteStride);break;default:throw new Error(e+": Invalid component type ("+r.componentType+")")}}catch(t){throw new Error(e+": "+t)}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,a,o){r=t.byteOffset+(r||0);var i=n*a;if(null==o||o===a*e.BYTES_PER_ELEMENT)return new e(t.buffer,r,i);for(var s=o/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<a;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,a=new r(function(){n._loaderTrackers.splice(n._loaderTrackers.indexOf(a)),t()});this._loaderTrackers.push(a),this._addLoaderPendingData(a),e(),this._removeLoaderPendingData(a)},n.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",r=this._babylonScene.getMaterialByName(t);r||(r=new e.PBRMaterial(t,this._babylonScene),r.sideOrientation=e.Material.CounterClockWiseSideOrientation,r.metallic=1,r.roughness=1),this._defaultMaterial=r}return this._defaultMaterial},n.prototype._loadMaterialMetallicRoughnessProperties=function(r,n){var a=n.babylonMaterial;a.metallic=1,a.roughness=1;var o=n.pbrMetallicRoughness;if(o){if(a.albedoColor=o.baseColorFactor?e.Color3.FromArray(o.baseColorFactor):new e.Color3(1,1,1),a.metallic=null==o.metallicFactor?1:o.metallicFactor,a.roughness=null==o.roughnessFactor?1:o.roughnessFactor,o.baseColorTexture){var i=t.GLTFUtils.GetArrayItem(this._gltf.textures,o.baseColorTexture.index);if(!i)throw new Error(r+": Failed to find base color texture "+o.baseColorTexture.index);a.albedoTexture=this._loadTexture("#/textures/"+i.index,i,o.baseColorTexture.texCoord)}if(o.metallicRoughnessTexture){var i=t.GLTFUtils.GetArrayItem(this._gltf.textures,o.metallicRoughnessTexture.index);if(!i)throw new Error(r+": Failed to find metallic roughness texture "+o.metallicRoughnessTexture.index);a.metallicTexture=this._loadTexture("#/textures/"+i.index,i,o.metallicRoughnessTexture.texCoord),a.useMetallnessFromMetallicTextureBlue=!0,a.useRoughnessFromMetallicTextureGreen=!0,a.useRoughnessFromMetallicTextureAlpha=!1}this._loadMaterialAlphaProperties(r,n,o.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 a=n.babylonMaterial;if(a.emissiveColor=n.emissiveFactor?e.Color3.FromArray(n.emissiveFactor):new e.Color3(0,0,0),n.doubleSided&&(a.backFaceCulling=!1,a.twoSidedLighting=!0),n.normalTexture){var o=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.normalTexture.index);if(!o)throw new Error(r+": Failed to find normal texture "+n.normalTexture.index);a.bumpTexture=this._loadTexture("#/textures/"+o.index,o,n.normalTexture.texCoord),a.invertNormalMapX=!this._babylonScene.useRightHandedSystem,a.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=n.normalTexture.scale&&(a.bumpTexture.level=n.normalTexture.scale)}if(n.occlusionTexture){var o=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.occlusionTexture.index);if(!o)throw new Error(r+": Failed to find occlusion texture "+n.occlusionTexture.index);a.ambientTexture=this._loadTexture("#/textures/"+o.index,o,n.occlusionTexture.texCoord),a.useAmbientInGrayScale=!0,null!=n.occlusionTexture.strength&&(a.ambientTextureStrength=n.occlusionTexture.strength)}if(n.emissiveTexture){var o=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.emissiveTexture.index);if(!o)throw new Error(r+": Failed to find emissive texture "+n.emissiveTexture.index);a.emissiveTexture=this._loadTexture("#/textures/"+o.index,o,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,a){var o=this,i=null==n.sampler?{}:t.GLTFUtils.GetArrayItem(this._gltf.samplers,n.sampler);if(!i)throw new Error(r+": Failed to find sampler "+n.sampler);var s=i.minFilter===t.ETextureMinFilter.NEAREST||i.minFilter===t.ETextureMinFilter.LINEAR,l=t.GLTFUtils.GetTextureSamplingMode(i.magFilter,i.minFilter);this._addPendingData(n);var u=new e.Texture(null,this._babylonScene,s,!1,l,function(){o._tryCatchOnError((function(){o._removePendingData(n)}))},function(e){o._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=a||0,u.wrapU=t.GLTFUtils.GetTextureWrapMode(i.wrapS),u.wrapV=t.GLTFUtils.GetTextureWrapMode(i.wrapT),u.name=n.name||"texture"+n.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(u),u},n.prototype._loadImage=function(e,r,n){if(r.uri)t.GLTFUtils.IsBase64(r.uri)?n(new Uint8Array(t.GLTFUtils.DecodeBase64(r.uri))):this._loadUri(e,r.uri,n);else{var a=t.GLTFUtils.GetArrayItem(this._gltf.bufferViews,r.bufferView);if(!a)throw new Error(e+": Failed to find buffer view "+r.bufferView);this._loadBufferViewAsync("#/bufferViews/"+a.index,a,n)}},n.prototype._loadUri=function(r,n,a){var o=this;if(!t.GLTFUtils.ValidateUri(n))throw new Error(r+": Uri '"+n+"' is invalid");var i=e.Tools.LoadFile(this._rootUrl+n,(function(e){o._tryCatchOnError((function(){a(new Uint8Array(e))}))}),(function(e){o._tryCatchOnError((function(){o._onProgress(e)}))}),this._babylonScene.database,!0,(function(e){o._tryCatchOnError((function(){throw new Error(r+": Failed to load '"+n+"'"+(e?": "+e.status+" "+e.statusText:""))}))}));i&&this._requests.push(i)},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)),a=0;a<r;a++)n[a]=t.charCodeAt(a);return n.buffer},r.ValidateUri=function(e){return e.indexOf("..")===-1},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})();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,a){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,a){return this._ApplyExtensions((function(o){return o._traverseNode(e,t,r,n,a)}))},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(a){return a._loadMaterial(e,t,r,n)}))},e._ApplyExtensions=function(t){var r=e._Extensions;if(!r)return!1;for(var n=0,a=r;n<a.length;n++){var o=a[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,a,o){return this._loadExtension(n,(function(i,s){for(var l=i.ids.length-1;l>=0;l--){var u=t.GLTFUtils.GetArrayItem(e._gltf.nodes,i.ids[l]);if(!u)throw new Error(r+": Failed to find node "+i.ids[l]);e._traverseNode(r,u,a,o)}e._traverseNode(r,n,a,o),s()}))},n.prototype._loadNode=function(e,t,r){var n=this;return this._loadExtension(r,(function(a,o){var i=[r.index].concat(a.ids).map((function(t){return e._gltf.nodes[t]}));e._addLoaderPendingData(r),n._loadNodeLOD(e,t,i,i.length-1,(function(){e._removeLoaderPendingData(r),o()}))}))},n.prototype._loadNodeLOD=function(e,t,r,a,o){var i=this;e._whenAction((function(){e._loadNode(t,r[a])}),(function(){if(a!==r.length-1){r[a+1].babylonMesh.setEnabled(!1)}if(0===a)return void o();setTimeout((function(){e._tryCatchOnError((function(){i._loadNodeLOD(e,t,r,a-1,o)}))}),n.MinimalLODDelay)}))},n.prototype._loadMaterial=function(e,t,r,n){var a=this;return this._loadExtension(r,(function(o,i){var s=[r.index].concat(o.ids).map((function(t){return e._gltf.materials[t]}));e._addLoaderPendingData(r),a._loadMaterialLOD(e,t,s,s.length-1,n,(function(){r.extensions[a.name]=o,e._removeLoaderPendingData(r),i()}))}))},n.prototype._loadMaterialLOD=function(t,r,a,o,i,s){var l=this;t._loadMaterial(r,a[o],(function(u,c){if(i(u,c),0===o)return void s();t._executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(u.getActiveTextures(),(function(){setTimeout((function(){t._tryCatchOnError((function(){l._loadMaterialLOD(t,r,a,o-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 a=this;return this._loadExtension(r,(function(o,i){e._createPbrMaterial(r),e._loadMaterialBaseProperties(t,r),a._loadSpecularGlossinessProperties(e,t,r,o),n(r.babylonMaterial,!0)}))},n.prototype._loadSpecularGlossinessProperties=function(r,n,a,o){var i=a.babylonMaterial;if(i.albedoColor=o.diffuseFactor?e.Color3.FromArray(o.diffuseFactor):new e.Color3(1,1,1),i.reflectivityColor=o.specularFactor?e.Color3.FromArray(o.specularFactor):new e.Color3(1,1,1),i.microSurface=null==o.glossinessFactor?1:o.glossinessFactor,o.diffuseTexture){var s=t.GLTFUtils.GetArrayItem(r._gltf.textures,o.diffuseTexture.index);if(!s)throw new Error(n+": Failed to find diffuse texture "+o.diffuseTexture.index);i.albedoTexture=r._loadTexture("textures["+s.index+"]",s,o.diffuseTexture.texCoord)}if(o.specularGlossinessTexture){var s=t.GLTFUtils.GetArrayItem(r._gltf.textures,o.specularGlossinessTexture.index);if(!s)throw new Error(n+": Failed to find diffuse texture "+o.specularGlossinessTexture.index);i.reflectivityTexture=r._loadTexture("textures["+s.index+"]",s,o.specularGlossinessTexture.texCoord),i.reflectivityTexture.hasAlpha=!0,i.useMicroSurfaceFromReflectivityMapAlpha=!0}r._loadMaterialAlphaProperties(n,a,o.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}));
|