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),d="",f=0;f<n.byteLength;f++)d+=String.fromCharCode(c[f]);for(n=d;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.loadAssetContainer=function(t,r,n,o){var a=new e.AssetContainer(t);return this.importMesh(null,t,r,n,a.meshes,null,null),a.removeAllFromScene(),a},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 d=84+50*c,f=n.getFloat32(d,!0),h=n.getFloat32(d+4,!0),p=n.getFloat32(d+8,!0),m=1;m<=3;m++){var _=d+12*m;i[a]=n.getFloat32(_,!0),i[a+2]=n.getFloat32(_+4,!0),i[a+1]=n.getFloat32(_+8,!0),s[a]=f,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,d=[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(d[0],d[1],d[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(" "),d=c>=0?u.substring(0,c):u;d=d.toLowerCase();var f=c>=0?u.substring(c+1).trim():"";"newmtl"===d?(s&&this.materials.push(s),s=new e.StandardMaterial(f,r)):"kd"===d&&s?(a=f.split(/\s+/,3).map(parseFloat),s.diffuseColor=e.Color3.FromArray(a)):"ka"===d&&s?(a=f.split(/\s+/,3).map(parseFloat),s.ambientColor=e.Color3.FromArray(a)):"ks"===d&&s?(a=f.split(/\s+/,3).map(parseFloat),s.specularColor=e.Color3.FromArray(a)):"ke"===d&&s?(a=f.split(/\s+/,3).map(parseFloat),s.emissiveColor=e.Color3.FromArray(a)):"ns"===d&&s?s.specularPower=parseFloat(f):"d"===d&&s?s.alpha=parseFloat(f):"map_ka"===d&&s?s.ambientTexture=t._getTexture(o,f,r):"map_kd"===d&&s?s.diffuseTexture=t._getTexture(o,f,r):"map_ks"===d&&s?s.specularTexture=t._getTexture(o,f,r):"map_ns"===d||("map_bump"===d&&s?s.bumpTexture=t._getTexture(o,f,r):"map_d"===d&&s&&(s.opacityTexture=t._getTexture(o,f,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("\\");a===-1&&(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.loadAssetContainer=function(t,r,n,o){var a=new e.AssetContainer(t);return this.importMesh(null,t,r,n,a.meshes,null,null),a.removeAllFromScene(),a},r.prototype._parseSolid=function(n,o,a,i){for(var s,l=[],u=[],c=[],d=[],f=[],h=[],p=[],m=[],_=[],y=0,A=!1,v=[],b=[],T=[],g=[],L="",E="",O=new t,x=1,M=!0,N=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]},S=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[],uv:[]});var r=e[t[0]].normals.indexOf(t[1]);return 1!=r&&t[2]==e[t[0]].uv[r]?e[t[0]].idx[r]:-1},w=function(e,t,n,o,a,i){var s;s=r.OPTIMIZE_WITH_UV?S(_,[e,n,t]):N(_,[e,n]),s==-1?(f.push(h.length),h.push(o),p.push(a),m.push(i),_[e].normals.push(n),_[e].idx.push(y++),r.OPTIMIZE_WITH_UV&&_[e].uv.push(t)):f.push(s)},F=function(){for(var e=0;e<h.length;e++)v.push(h[e].x,h[e].y,h[e].z),b.push(m[e].x,m[e].y,m[e].z),T.push(p[e].x,p[e].y);h=[],m=[],p=[],_=[],y=0},B=function(e,t){t+1<e.length&&(g.push(e[0],e[t],e[t+1]),t+=1,B(e,t))},I=function(){d.length>0&&(s=d[d.length-1],F(),f.reverse(),s.indices=f.slice(),s.positions=v.slice(),s.normals=b.slice(),s.uvs=T.slice(),f=[],v=[],b=[],T=[])},R=a.split("\n"),P=0;P<R.length;P++){var C,G=R[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){B(e,t);for(var r=0;r<g.length;r++){var n=g[r].split("/"),o=parseInt(n[0])-1,a=parseInt(n[1])-1,i=parseInt(n[2])-1;w(o,a,i,l[o],c[a],u[i])}g=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern4.exec(G)))!(function(t,r){B(t,r);for(var n=0;n<g.length;n++){var o=g[n].split("//"),a=parseInt(o[0])-1,i=parseInt(o[1])-1;w(a,1,i,l[a],e.Vector2.Zero(),u[i])}g=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern2.exec(G)))!(function(t,r){B(t,r);for(var n=0;n<g.length;n++){var o=g[n].split("/"),a=parseInt(o[0])-1,i=parseInt(o[1])-1;w(a,i,0,l[a],c[i],e.Vector3.Up())}g=[]})(C[1].trim().split(" "),1);else if(null!==(C=this.facePattern1.exec(G)))!(function(t,r){B(t,r);for(var n=0;n<g.length;n++){var o=parseInt(g[n])-1;w(o,0,0,l[o],e.Vector2.Zero(),e.Vector3.Up())}g=[]})(C[1].trim().split(" "),1);else if(this.group.test(G)||this.obj.test(G)){var V={name:G.substring(2).trim(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:""};I(),d.push(V),A=!0,M=!0,x=1}else if(this.usemtl.test(G)){if(L=G.substring(7).trim(),!M){I();var V={name:"_mm"+x.toString(),indices:void 0,positions:void 0,normals:void 0,uvs:void 0,materialName:L};x++,d.push(V)}A&&M&&(d[d.length-1].materialName=L,M=!1)}else this.mtllib.test(G)?E=G.substring(7).trim():this.smooth.test(G)||console.log("Unhandled expression at line : "+G)}A&&(s=d[d.length-1],f.reverse(),F(),s.indices=f,s.positions=v,s.normals=b,s.uvs=T),A||(f.reverse(),F(),d.push({name:e.Geometry.RandomId(),indices:f,positions:v,normals:b,uvs:T,materialName:L}));for(var D=[],U=new Array,k=0;k<d.length;k++){if(n&&d[k].name)if(n instanceof Array){if(n.indexOf(d[k].name)==-1)continue}else if(d[k].name!==n)continue;s=d[k];var j=new e.Mesh(d[k].name,o);U.push(d[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(j),D.push(j)}return""!==E&&this._loadMTL(E,i,(function(e){O.parseMTL(o,e,i);for(var t=0;t<O.materials.length;t++){for(var r,n=0,a=[];(r=U.indexOf(O.materials[t].name,n))>-1;)a.push(r),n=r+1;if(r==-1&&0==a.length)O.materials[t].dispose();else for(var s=0;s<a.length;s++)D[a[s]].material=O.materials[t]}})),D},r.OPTIMIZE_WITH_UV=!1,r})();e.OBJFileLoader=r,e.SceneLoader&&e.SceneLoader.RegisterPlugin(new r)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var r;!(function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"})(r=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}));!(function(e){e[e.Loading=0]="Loading",e[e.Ready=1]="Ready",e[e.Complete=2]="Complete"})(e.GLTFLoaderState||(e.GLTFLoaderState={}));var n=(function(){function n(){this.onParsedObservable=new e.Observable,this.coordinateSystemMode=t.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this._loader=null,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return Object.defineProperty(n.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onExtensionLoaded",{set:function(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),n.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},n.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=a._parse(r);return a._loader=a._getLoader(i),a._loader.importMeshAsync(e,t,i,n,o)}))},n.prototype.loadAsync=function(e,t,r,n){var o=this;return Promise.resolve().then((function(){var a=o._parse(t);return o._loader=o._getLoader(a),o._loader.loadAsync(e,a,r,n)}))},n.prototype.loadAssetContainerAsync=function(t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=a._parse(r);return a._loader=a._getLoader(i),a._loader.importMeshAsync(null,t,i,n,o).then((function(r){var n=new e.AssetContainer(t);return Array.prototype.push.apply(n.meshes,r.meshes),Array.prototype.push.apply(n.particleSystems,r.particleSystems),Array.prototype.push.apply(n.skeletons,r.skeletons),n.removeAllFromScene(),n}))}))},n.prototype.canDirectLoad=function(e){return e.indexOf("scene")!==-1&&e.indexOf("node")!==-1},n.prototype.createPlugin=function(){return new n},n.prototype._parse=function(e){var t;return t=e instanceof ArrayBuffer?n._parseBinary(e):{json:JSON.parse(e),bin:null},this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),t},n.prototype._getLoader=function(e){var t=this,r={major:2,minor:0},o=e.json.asset||{},a=n._parseVersion(o.version);if(!a)throw new Error("Invalid version: "+o.version);if(void 0!==o.minVersion){var i=n._parseVersion(o.minVersion);if(!i)throw new Error("Invalid minimum version: "+o.minVersion);if(n._compareVersion(i,r)>0)throw new Error("Incompatible minimum version: "+o.minVersion)}var s={1:n.CreateGLTFLoaderV1,2:n.CreateGLTFLoaderV2},l=s[a.major];if(!l)throw new Error("Unsupported version: "+o.version);var u=l();return u.coordinateSystemMode=this.coordinateSystemMode,u.animationStartMode=this.animationStartMode,u.compileMaterials=this.compileMaterials,u.useClipPlane=this.useClipPlane,u.compileShadowGenerators=this.compileShadowGenerators,u.onMeshLoadedObservable.add((function(e){return t.onMeshLoadedObservable.notifyObservers(e)})),u.onTextureLoadedObservable.add((function(e){return t.onTextureLoadedObservable.notifyObservers(e)})),u.onMaterialLoadedObservable.add((function(e){return t.onMaterialLoadedObservable.notifyObservers(e)})),u.onExtensionLoadedObservable.add((function(e){return t.onExtensionLoadedObservable.notifyObservers(e)})),u.onCompleteObservable.add((function(){t.onMeshLoadedObservable.clear(),t.onTextureLoadedObservable.clear(),t.onMaterialLoadedObservable.clear(),t.onCompleteObservable.notifyObservers(t),t.onCompleteObservable.clear()})),u},n._parseBinary=function(e){var t={Magic:1179937895},r=new o(e),a=r.readUint32();if(a!==t.Magic)throw new Error("Unexpected magic: "+a);var i=r.readUint32();switch(i){case 1:return n._parseV1(r);case 2:return n._parseV2(r)}throw new Error("Unsupported version: "+i)},n._parseV1=function(e){var t={JSON:0},r=e.readUint32();if(r!=e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o,a=e.readUint32(),i=e.readUint32();switch(i){case t.JSON:o=JSON.parse(n._decodeBufferToText(e.readUint8Array(a)));break;default:throw new Error("Unexpected content format: "+i)}var s=e.getLength()-e.getPosition();return{json:o,bin:e.readUint8Array(s)}},n._parseV2=function(e){var t={JSON:1313821514,BIN:5130562},r=e.readUint32();if(r!==e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==t.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(n._decodeBufferToText(e.readUint8Array(o))),i=null;e.getPosition()<e.getLength();){var s=e.readUint32();switch(e.readUint32()){case t.JSON:throw new Error("Unexpected JSON chunk");case t.BIN:i=e.readUint8Array(s);break;default:e.skipBytes(s)}}return{json:a,bin:i}},n._parseVersion=function(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};var t=(e+"").match(/^(\d+)\.(\d+)/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null},n._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},n._decodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;n++)t+=String.fromCharCode(e[n]);return t},n.IncrementalLoading=!0,n.HomogeneousCoordinates=!1,n})();e.GLTFFileLoader=n;var o=(function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new n)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.FLOAT=5126]="FLOAT"})(e.EComponentType||(e.EComponentType={}));!(function(e){e[e.FRAGMENT=35632]="FRAGMENT",e[e.VERTEX=35633]="VERTEX"})(e.EShaderType||(e.EShaderType={}));!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.INT=5124]="INT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT",e[e.FLOAT_VEC2=35664]="FLOAT_VEC2",e[e.FLOAT_VEC3=35665]="FLOAT_VEC3",e[e.FLOAT_VEC4=35666]="FLOAT_VEC4",e[e.INT_VEC2=35667]="INT_VEC2",e[e.INT_VEC3=35668]="INT_VEC3",e[e.INT_VEC4=35669]="INT_VEC4",e[e.BOOL=35670]="BOOL",e[e.BOOL_VEC2=35671]="BOOL_VEC2",e[e.BOOL_VEC3=35672]="BOOL_VEC3",e[e.BOOL_VEC4=35673]="BOOL_VEC4",e[e.FLOAT_MAT2=35674]="FLOAT_MAT2",e[e.FLOAT_MAT3=35675]="FLOAT_MAT3",e[e.FLOAT_MAT4=35676]="FLOAT_MAT4",e[e.SAMPLER_2D=35678]="SAMPLER_2D"})(e.EParameterType||(e.EParameterType={}));!(function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"})(e.ETextureWrapMode||(e.ETextureWrapMode={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9728]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"})(e.ETextureFilterType||(e.ETextureFilterType={}));!(function(e){e[e.ALPHA=6406]="ALPHA",e[e.RGB=6407]="RGB",e[e.RGBA=6408]="RGBA",e[e.LUMINANCE=6409]="LUMINANCE",e[e.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA"})(e.ETextureFormat||(e.ETextureFormat={}));!(function(e){e[e.FRONT=1028]="FRONT",e[e.BACK=1029]="BACK",e[e.FRONT_AND_BACK=1032]="FRONT_AND_BACK"})(e.ECullingType||(e.ECullingType={}));!(function(e){e[e.ZERO=0]="ZERO",e[e.ONE=1]="ONE",e[e.SRC_COLOR=768]="SRC_COLOR",e[e.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",e[e.DST_COLOR=774]="DST_COLOR",e[e.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.DST_ALPHA=772]="DST_ALPHA",e[e.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",e[e.CONSTANT_COLOR=32769]="CONSTANT_COLOR",e[e.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",e[e.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",e[e.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",e[e.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE"})(e.EBlendingFunction||(e.EBlendingFunction={}))})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var 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}},d=function(e){if(e)for(var t=0;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},f=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&&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){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 d=null,f=null;o.parameters?(d=o.parameters[c.input],f=o.parameters[c.output]):(d=c.input,f=c.output);var h=t.GLTFUtils.GetBufferFromAccessor(r,r.accessors[d]),p=t.GLTFUtils.GetBufferFromAccessor(r,r.accessors[f]),m=u.target.id,_=r.scene.getNodeByID(m);if(null===_&&(_=r.scene.getNodeByName(m)),null!==_){var y=_ instanceof e.Bone,A=u.target.path,v=i.indexOf(A);v!==-1&&(A=s[v]);var b=e.Animation.ANIMATIONTYPE_MATRIX;y||("rotationQuaternion"===A?(b=e.Animation.ANIMATIONTYPE_QUATERNION,_.rotationQuaternion=new e.Quaternion):b=e.Animation.ANIMATIONTYPE_VECTOR3);var T=null,g=[],L=0,E=!1;y&&a&&a.getKeys().length===h.length&&(T=a,E=!0),E||(T=new e.Animation(n,y?"_matrix":A,1,b,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var O=0;O<h.length;O++){var x=null;if("rotationQuaternion"===A?(x=e.Quaternion.FromArray([p[L],p[L+1],p[L+2],p[L+3]]),L+=4):(x=e.Vector3.FromArray([p[L],p[L+1],p[L+2]]),L+=3),y){var M=_,N=e.Vector3.Zero(),S=new e.Quaternion,w=e.Vector3.Zero(),F=M.getBaseMatrix();E&&a&&(F=a.getKeys()[O].value),F.decompose(w,S,N),"position"===A?N=x:"rotationQuaternion"===A?S=x:w=x,x=e.Matrix.Compose(w,S,N)}E?a&&(a.getKeys()[O].value=x):g.push({frame:h[O],value:x})}!E&&T&&(T.setKeys(g),_.animations.push(T)),a=T,r.scene.stopAnimation(_),r.scene.beginAnimation(_,0,h[h.length-1],!0,1)}else e.Tools.Warn("Creating animation named "+n+". But cannot find node named "+m+" to attach to")}}}},p=function(t){var r=null;if(t.translation||t.rotation||t.scale){var n=e.Vector3.FromArray(t.scale||[1,1,1]),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 d=p(l),f=new e.Bone(l.name||"",o,m(t,r,l.jointName,o),d);return f.id=s,f}}}return null},_=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},y=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},A=function(e,t){for(var r=0;r<e.jointNames.length;r++)if(e.jointNames[r]===t)return!0;return!1},v=function(t,r,n,o){for(var a in t.nodes){var i=t.nodes[a],s=a;if(i.jointName&&!A(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 d=o[c],f=d.node.children,h=0;h<f.length;h++){for(var m=null,_=0;_<o.length;_++)if(o[_].id===f[h]){m=o[_];break}m&&(m.bone._parent=d.bone,d.bone.children.push(m.bone))}},b=function(t,r,n,o,a){if(o||(o=new e.Skeleton(r.name||"","",t.scene)),!r.babylonSkeleton)return o;var i=[],s=[];v(t,o,r,i),o.bones=[];for(var l=0;l<r.jointNames.length;l++){var u=y(t,r.jointNames[l]);if(u){var c=u.node;if(c){var a=u.id,d=t.scene.getBoneByID(a);if(d)o.bones.push(d);else{for(var f=!1,h=null,A=0;A<l;A++){var b=y(t,r.jointNames[A]);if(b){var T=b.node;if(T){var g=T.children;if(g){f=!1;for(var L=0;L<g.length;L++)if(g[L]===a){h=m(t,r,r.jointNames[A],o),f=!0;break}if(f)break}}else e.Tools.Warn("Joint named "+r.jointNames[A]+" does not exist when looking for parent")}}var E=p(c);!h&&i.length>0&&(h=_(i,a))&&s.indexOf(h)===-1&&s.push(h);new e.Bone(c.jointName||"",o,h,E).id=a}}else e.Tools.Warn("Joint named "+r.jointNames[l]+" does not exist")}}var O=o.bones;o.bones=[];for(var l=0;l<r.jointNames.length;l++){var u=y(t,r.jointNames[l]);if(u)for(var A=0;A<O.length;A++)if(O[A].id===u.id){o.bones.push(O[A]);break}}o.prepare();for(var l=0;l<s.length;l++)o.bones.push(s[l]);return o},T=function(r,n,o,a,i){if(i||(i=new e.Mesh(n.name||"",r.scene),i.id=a),!n.babylonNode)return i;for(var s=[],l=null,u=new Array,c=new Array,f=new Array,h=new Array,p=0;p<o.length;p++){var m=o[p],_=r.meshes[m];if(_)for(var y=0;y<_.primitives.length;y++){var A=new e.VertexData,v=_.primitives[y];v.mode;var b=v.attributes,T=null,g=null;for(var L in b)if(T=r.accessors[b[L]],g=t.GLTFUtils.GetBufferFromAccessor(r,T),"NORMAL"===L)A.normals=new Float32Array(g.length),A.normals.set(g);else if("POSITION"===L){if(e.GLTFFileLoader.HomogeneousCoordinates){A.positions=new Float32Array(g.length-g.length/4);for(var E=0;E<g.length;E+=4)A.positions[E]=g[E],A.positions[E+1]=g[E+1],A.positions[E+2]=g[E+2]}else A.positions=new Float32Array(g.length),A.positions.set(g);c.push(A.positions.length)}else if(L.indexOf("TEXCOORD_")!==-1){var O=Number(L.split("_")[1]),x=e.VertexBuffer.UVKind+(0===O?"":O+1),M=new Float32Array(g.length);M.set(g),d(M),A.set(M,x)}else"JOINT"===L?(A.matricesIndices=new Float32Array(g.length),A.matricesIndices.set(g)):"WEIGHT"===L?(A.matricesWeights=new Float32Array(g.length),A.matricesWeights.set(g)):"COLOR"===L&&(A.colors=new Float32Array(g.length),A.colors.set(g));if(T=r.accessors[v.indices])g=t.GLTFUtils.GetBufferFromAccessor(r,T),A.indices=new Int32Array(g.length),A.indices.set(g),h.push(A.indices.length);else{for(var N=[],E=0;E<A.positions.length/3;E++)N.push(E);A.indices=new Int32Array(N),h.push(A.indices.length)}l?l.merge(A):l=A;var S=r.scene.getMaterialByID(v.material);s.push(null===S?t.GLTFUtils.GetDefaultMaterial(r.scene):S),u.push(0===u.length?0:u[u.length-1]+c[c.length-2]),f.push(0===f.length?0:f[f.length-1]+h[h.length-2])}}var w;s.length>1?(w=new e.MultiMaterial("multimat"+a,r.scene),w.subMaterials=s):w=new e.StandardMaterial("multimat"+a,r.scene),1===s.length&&(w=s[0]),i.material||(i.material=w),new e.Geometry(a,r.scene,l,!1,i),i.computeWorldMatrix(!0),i.subMeshes=[];for(var F=0,p=0;p<o.length;p++){var m=o[p],_=r.meshes[m];if(_)for(var y=0;y<_.primitives.length;y++)_.primitives[y].mode,e.SubMesh.AddToMesh(F,u[F],c[F],f[F],h[F],i,i,!0),F++}return i},g=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),g(t,o,a,i)}else r.translation&&r.rotation&&r.scale&&g(t,e.Vector3.FromArray(r.translation),e.Quaternion.FromArray(r.rotation),e.Vector3.FromArray(r.scale));t.computeWorldMatrix(!0)},E=function(t,r,n,o){var a=null;if(t.importOnlyMeshes&&(r.skin||r.meshes)&&t.importMeshesNames&&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=T(t,r,r.meshes,n,r.babylonNode);s.skeleton=t.scene.getLastSkeletonByID(r.skin),null===s.skeleton&&(s.skeleton=b(t,i,0,i.babylonSkeleton,r.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),a=s}}else if(r.meshes){var s=T(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],d=new e.FreeCamera(r.camera,e.Vector3.Zero(),t.scene);d.name=r.name||"",d.attachControl(t.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(d.maxZ=c.zfar,d.minZ=c.znear),a=d}}}else{var f=t.lights[r.light];if(f)if("ambient"===f.type){var h=f[f.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"===f.type){var m=f[f.type],_=new e.DirectionalLight(r.light,e.Vector3.Zero(),t.scene);_.name=r.name||"",m.color&&(_.diffuse=e.Color3.FromArray(m.color)),a=_}else if("point"===f.type){var y=f[f.type],A=new e.PointLight(r.light,e.Vector3.Zero(),t.scene);A.name=r.name||"",y.color&&(A.diffuse=e.Color3.FromArray(y.color)),a=A}else if("spot"===f.type){var v=f[f.type],E=new e.SpotLight(r.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);E.name=r.name||"",v.color&&(E.diffuse=e.Color3.FromArray(v.color)),v.fallOfAngle&&(E.angle=v.fallOfAngle),v.fallOffExponent&&(E.exponent=v.fallOffExponent),a=E}}if(!r.jointName){if(r.babylonNode)return r.babylonNode;if(null===a){var O=new e.Mesh(r.name||"",t.scene);r.babylonNode=O,a=O}}if(null!==a){if(r.matrix&&a instanceof e.Mesh)L(a,r);else{var x=r.translation||[0,0,0],M=r.rotation||[0,0,0,1],N=r.scale||[1,1,1];g(a,e.Vector3.FromArray(x),e.Quaternion.FromArray(M),e.Vector3.FromArray(N))}a.updateCache(!0),r.babylonNode=a}return a},O=function(e,t,r,n){void 0===n&&(n=!1);var o=e.nodes[t],a=null;if(n=!(e.importOnlyMeshes&&!n&&e.importMeshesNames)||(e.importMeshesNames.indexOf(o.name||"")!==-1||0===e.importMeshesNames.length),!o.jointName&&n&&null!==(a=E(e,o,t))&&(a.id=t,a.parent=r),o.children)for(var i=0;i<o.children.length;i++)O(e,o.children[i],a,n)},x=function(e){var t=e.currentScene
- ;if(t)for(var r=0;r<t.nodes.length;r++)O(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++)O(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],d=c.type;if(d===t.EParameterType.FLOAT_MAT2||d===t.EParameterType.FLOAT_MAT3||d===t.EParameterType.FLOAT_MAT4)if(!c.semantic||c.source||c.node){if(c.semantic&&(c.source||c.node)){var f=r.scene.getNodeByName(c.source||c.node||"");if(null===f&&(f=r.scene.getNodeByID(c.source||c.node||"")),null===f)continue;t.GLTFUtils.SetMatrix(r.scene,f,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(d===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,d)}}s(o)},N=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,d=i[s[l]];if(void 0===d&&(d=u.value),d){var f=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?d:u.value,f(l),(function(){return f(null)})):u.value&&t.GLTFUtils.SetUniform(r,l,o.values?d:u.value,c)&&delete a[l]}}},S=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")}},w=function(e,t,r,n,o,a){return function(i){N(e,t,r,n,o),t.onBind=function(i){M(i,e,o,t,r,n,a)}}},F=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(l!==-1)return delete r[n],a[l]}}return e.currentIdentifier},B=function(e){for(var r in e.materials)t.GLTFLoaderExtension.LoadMaterialAsync(e,r,(function(e){}),(function(){}))},I=(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(t,r,n,o,a){var i=t.buffers[r];e.Tools.IsBase64(i.uri)?setTimeout((function(){return n(new Uint8Array(e.Tools.DecodeBase64(i.uri)))})):e.Tools.LoadFile(t.rootUrl+i.uri,(function(e){return n(new Uint8Array(e))}),a,void 0,!0,(function(e){e&&o(e.status+" "+e.statusText)}))},i.LoadTextureBufferAsync=function(t,r,n,o){var a=t.textures[r];if(!a||!a.source)return void o("");if(a.babylonTexture)return void n(null);var i=t.images[a.source];e.Tools.IsBase64(i.uri)?setTimeout((function(){return n(new Uint8Array(e.Tools.DecodeBase64(i.uri)))})):e.Tools.LoadFile(t.rootUrl+i.uri,(function(e){return n(new Uint8Array(e))}),void 0,void 0,!0,(function(e){e&&o(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,d=new Blob([o]),f=URL.createObjectURL(d),h=function(){return URL.revokeObjectURL(f)},p=new e.Texture(f,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(t,r,n,o){var a=t.shaders[r];if(e.Tools.IsBase64(a.uri)){n(atob(a.uri.split(",")[1]))}else e.Tools.LoadFile(t.rootUrl+a.uri,n,void 0,void 0,!1,(function(e){e&&o(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 d=i.techniques[c.technique];if(!d){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[d.program],m=d.states,_=e.Effect.ShadersStore[p.vertexShader+"VertexShader"],y=e.Effect.ShadersStore[p.fragmentShader+"PixelShader"],A="",v="",b=new n(_),T=new n(y),g={},L=[],E=[],O=[];for(var x in d.uniforms){var M=d.uniforms[x],N=d.parameters[M];if(g[x]=N,!N.semantic||N.node||N.source)N.type===t.EParameterType.SAMPLER_2D?O.push(x):L.push(x);else{var B=o.indexOf(N.semantic);B!==-1?(L.push(a[B]),delete g[x]):L.push(x)}}for(var I in d.attributes){var R=d.attributes[I],P=d.parameters[R];P.semantic&&E.push(f(P))}for(;!b.isEnd()&&b.getNextToken();){var C=b.currentToken;if(C===r.IDENTIFIER){var G=!1;for(var I in d.attributes){var R=d.attributes[I],P=d.parameters[R];if(b.currentIdentifier===I&&P.semantic){A+=f(P),G=!0;break}}G||(A+=F(b,d,g))}else A+=b.currentString}for(;!T.isEnd()&&T.getNextToken();){var C=T.currentToken;C===r.IDENTIFIER?v+=F(T,d,g):v+=T.currentString}var V={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},D={attributes:E,uniforms:L,samplers:O,needAlphaBlending:m&&m.enable&&m.enable.indexOf(3042)!==-1};e.Effect.ShadersStore[p.vertexShader+s+"VertexShader"]=A,e.Effect.ShadersStore[p.fragmentShader+s+"PixelShader"]=v;var U=new e.ShaderMaterial(s,i.scene,V,D);if(U.onError=S(p,U,u),U.onCompiled=w(i,U,d,c,g,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 j=k.blendFuncSeparate;j&&(j[0]===t.EBlendingFunction.SRC_ALPHA&&j[1]===t.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&j[2]===t.EBlendingFunction.ONE&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_COMBINE:j[0]===t.EBlendingFunction.ONE&&j[1]===t.EBlendingFunction.ONE&&j[2]===t.EBlendingFunction.ZERO&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_ONEONE:j[0]===t.EBlendingFunction.SRC_ALPHA&&j[1]===t.EBlendingFunction.ONE&&j[2]===t.EBlendingFunction.ZERO&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_ADD:j[0]===t.EBlendingFunction.ZERO&&j[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&j[2]===t.EBlendingFunction.ONE&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_SUBTRACT:j[0]===t.EBlendingFunction.DST_COLOR&&j[1]===t.EBlendingFunction.ZERO&&j[2]===t.EBlendingFunction.ONE&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_MULTIPLY:j[0]===t.EBlendingFunction.SRC_ALPHA&&j[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&j[2]===t.EBlendingFunction.ONE&&j[3]===t.EBlendingFunction.ONE&&(U.alphaMode=e.Engine.ALPHA_MAXIMIZED))}},i})();t.GLTFLoaderBase=I;var R=(function(){function r(){this.coordinateSystemMode=e.GLTFLoaderCoordinateSystemMode.AUTO,this.animationStartMode=e.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onDisposeObservable=new e.Observable,this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this.state=null}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 d=t.skins[c];d.babylonSkeleton instanceof e.Skeleton&&o.push(d.babylonSkeleton)}u._loadBuffersAsync(t,(function(){u._loadShadersAsync(t,(function(){B(t),x(t),!e.GLTFFileLoader.IncrementalLoading&&i&&i(n,[],o)}))}),s),e.GLTFFileLoader.IncrementalLoading&&i&&i(n,[],o)}),l),!0},r.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return new Promise(function(i,s){a._importMeshAsync(e,t,r,n,(function(e,t,r){i({meshes:e,particleSystems:t,skeletons:r})}),o,(function(e){s(new Error(e))}))})},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(){B(r),x(r),e.GLTFFileLoader.IncrementalLoading||a()}))})),e.GLTFFileLoader.IncrementalLoading&&a()}),s)}),s)},r.prototype.loadAsync=function(e,t,r,n){var o=this;return new Promise(function(a,i){o._loadAsync(e,t,r,(function(){a()}),n,(function(e){i(new Error(e))}))})},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++)O(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++)O(e,t.nodes[r],null)}},r.Extensions={},r})();t.GLTFLoader=R,e.GLTFFileLoader.CreateGLTFLoaderV1=function(){return new R}})(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.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||i.indexOf(this.name)===-1||!r.bin)&&(this._bin=r.bin,o(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,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),d=s.point;d&&(c.diffuse=e.Color3.FromArray(d.color||[1,1,1]));break;case"directional":var f=new e.DirectionalLight(s.name,new e.Vector3(0,-1,0),t.scene),h=s.directional;h&&(f.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){var t=(function(){function e(){}return e.Assign=function(e){if(e)for(var t=0;t<e.length;t++)e[t]._index=t},e})();e.ArrayItem=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(){this._completePromises=new Array,this._disposed=!1,this._state=null,this._extensions={},this._defaultSampler={},this._requests=new Array,this.coordinateSystemMode=e.GLTFLoaderCoordinateSystemMode.AUTO,this.animationStartMode=e.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onDisposeObservable=new e.Observable,this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable}return r._Register=function(t,n){if(r._Factories[t])return void e.Tools.Error("Extension with the name '"+t+"' already exists");r._Factories[t]=n,r._Names.push(t)},Object.defineProperty(r.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),r.prototype.dispose=function(){this._disposed||(this._disposed=!0,this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this._clear())},r.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=null;if(e){var s={};if(a._gltf.nodes)for(var l=0,u=a._gltf.nodes;l<u.length;l++){var c=u[l];c.name&&(s[c.name]=c)}i=(e instanceof Array?e:[e]).map((function(e){var t=s[e];if(!t)throw new Error("Failed to find node "+e);return t}))}return a._loadAsync(i,t,r,n,o).then((function(){return{meshes:a._getMeshes(),particleSystems:[],skeletons:a._getSkeletons()}}))}))},r.prototype.loadAsync=function(e,t,r,n){return this._loadAsync(null,e,t,r,n)},r.prototype._loadAsync=function(t,n,o,a,i){var s=this;return Promise.resolve().then((function(){s._loadExtensions(),s._babylonScene=n,s._rootUrl=a,s._progressCallback=i,s._state=e.GLTFLoaderState.Loading,s._loadData(o),s._checkExtensions();var l=new Array;if(t)l.push(s._loadNodesAsync(t));else{var u=r._GetProperty("#/scene",s._gltf.scenes,s._gltf.scene||0);l.push(s._loadSceneAsync("#/scenes/"+u._index,u))}return s.compileMaterials&&l.push(s._compileMaterialsAsync()),s.compileShadowGenerators&&l.push(s._compileShadowGeneratorsAsync()),Promise.all(l).then((function(){s._state=e.GLTFLoaderState.Ready,s._startAnimations(),e.Tools.SetImmediate((function(){s._disposed||Promise.all(s._completePromises).then((function(){s._state=e.GLTFLoaderState.Complete,s.onCompleteObservable.notifyObservers(s),s.onCompleteObservable.clear(),s._clear()})).catch((function(t){e.Tools.Error("glTF Loader: "+t.message),s._clear()}))}))}))})).catch((function(t){throw e.Tools.Error("glTF Loader: "+t.message),s._clear(),t}))},r.prototype._loadExtensions=function(){for(var e=0,t=r._Names;e<t.length;e++){var n=t[e],o=r._Factories[n](this);this._extensions[n]=o,this.onExtensionLoadedObservable.notifyObservers(o)}this.onExtensionLoadedObservable.clear()},r.prototype._loadData=function(t){if(this._gltf=t.json,this._setupData(),t.bin){var r=this._gltf.buffers;if(r&&r[0]&&!r[0].uri){var n=r[0];(n.byteLength<t.bin.byteLength-3||n.byteLength>t.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),n._data=Promise.resolve(t.bin)}else e.Tools.Warn("Unexpected BIN chunk")}},r.prototype._setupData=function(){if(t.ArrayItem.Assign(this._gltf.accessors),t.ArrayItem.Assign(this._gltf.animations),t.ArrayItem.Assign(this._gltf.buffers),t.ArrayItem.Assign(this._gltf.bufferViews),t.ArrayItem.Assign(this._gltf.cameras),t.ArrayItem.Assign(this._gltf.images),t.ArrayItem.Assign(this._gltf.materials),t.ArrayItem.Assign(this._gltf.meshes),t.ArrayItem.Assign(this._gltf.nodes),t.ArrayItem.Assign(this._gltf.samplers),t.ArrayItem.Assign(this._gltf.scenes),t.ArrayItem.Assign(this._gltf.skins),t.ArrayItem.Assign(this._gltf.textures),this._gltf.nodes){for(var e={},r=0,n=this._gltf.nodes;r<n.length;r++){var o=n[r];if(o.children)for(var a=0,i=o.children;a<i.length;a++){var s=i[a];e[s]=o._index}}for(var l=this._createRootNode(),u=0,c=this._gltf.nodes;u<c.length;u++){var o=c[u],d=e[o._index];o._parent=void 0===d?l:this._gltf.nodes[d]}}},r.prototype._checkExtensions=function(){if(this._gltf.extensionsRequired)for(var e=0,t=this._gltf.extensionsRequired;e<t.length;e++){var r=t[e],n=this._extensions[r];if(!n||!n.enabled)throw new Error("Require extension "+r+" is not available")}},r.prototype._createRootNode=function(){this._rootBabylonMesh=new e.Mesh("__root__",this._babylonScene);var t={_babylonMesh:this._rootBabylonMesh};switch(this.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(t.rotation=[0,1,0,0],t.scale=[1,1,-1],r._LoadTransform(t,this._rootBabylonMesh));break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:throw new Error("Invalid coordinate system mode "+this.coordinateSystemMode)}return this.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh),t},r.prototype._loadNodesAsync=function(e){for(var t=new Array,r=0,n=e;r<n.length;r++){var o=n[r];t.push(this._loadNodeAsync("#/nodes/"+o._index,o))}return t.push(this._loadAnimationsAsync()),Promise.all(t).then((function(){}))},r.prototype._loadSceneAsync=function(e,n){var o=t.GLTFLoaderExtension._LoadSceneAsync(this,e,n);if(o)return o;for(var a=new Array,i=0,s=n.nodes;i<s.length;i++){var l=s[i],u=r._GetProperty(e+"/nodes/"+l,this._gltf.nodes,l);a.push(this._loadNodeAsync("#/nodes/"+u._index,u))}return a.push(this._loadAnimationsAsync()),Promise.all(a).then((function(){}))},r.prototype._getMeshes=function(){var e=new Array;e.push(this._rootBabylonMesh);var t=this._gltf.nodes;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];if(o._babylonMesh&&e.push(o._babylonMesh),o._primitiveBabylonMeshes)for(var a=0,i=o._primitiveBabylonMeshes;a<i.length;a++){var s=i[a];e.push(s)}}return e},r.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},r.prototype._startAnimations=function(){var t=this._gltf.animations;if(t)switch(this.animationStartMode){case e.GLTFLoaderAnimationStartMode.NONE:break;case e.GLTFLoaderAnimationStartMode.FIRST:var r=t[0];r._babylonAnimationGroup.start(!0);break;case e.GLTFLoaderAnimationStartMode.ALL:for(var n=0,o=t;n<o.length;n++){var r=o[n];r._babylonAnimationGroup.start(!0)}break;default:return void e.Tools.Error("Invalid animation start mode "+this.animationStartMode)}},r.prototype._loadNodeAsync=function(n,o){var a=t.GLTFLoaderExtension._LoadNodeAsync(this,n,o);if(a)return a;if(o._babylonMesh)throw new Error(n+": Invalid recursive node hierarchy");var i=new Array,s=new e.Mesh(o.name||"node"+o._index,this._babylonScene,o._parent._babylonMesh);if(o._babylonMesh=s,o._babylonAnimationTargets=o._babylonAnimationTargets||[],o._babylonAnimationTargets.push(s),r._LoadTransform(o,s),void 0!=o.mesh){var l=r._GetProperty(n+"/mesh",this._gltf.meshes,o.mesh);i.push(this._loadMeshAsync("#/meshes/"+l._index,o,l))}if(o.children)for(var u=0,c=o.children;u<c.length;u++){var d=c[u],f=r._GetProperty(n+"/children/"+d,this._gltf.nodes,d);i.push(this._loadNodeAsync("#/nodes/"+d,f))}return this.onMeshLoadedObservable.notifyObservers(s),Promise.all(i).then((function(){}))},r.prototype._loadMeshAsync=function(e,n,o){var a=new Array,i=o.primitives;if(!i||0===i.length)throw new Error(e+": Primitives are missing");t.ArrayItem.Assign(i);for(var s=0,l=i;s<l.length;s++){var u=l[s];a.push(this._loadPrimitiveAsync(e+"/primitives/"+u._index,n,o,u))}if(void 0!=n.skin){var c=r._GetProperty(e+"/skin",this._gltf.skins,n.skin);a.push(this._loadSkinAsync("#/skins/"+c._index,n,o,c))}return Promise.all(a).then((function(){if(n._primitiveBabylonMeshes)for(var e=0,t=n._primitiveBabylonMeshes;e<t.length;e++){var r=t[e];r._refreshBoundingInfo(!0)}}))},r.prototype._loadPrimitiveAsync=function(t,n,o,a){var i=this,s=new Array,l=new e.Mesh((o.name||n._babylonMesh.name)+"_"+a._index,this._babylonScene,n._babylonMesh);if(l.setEnabled(!1),n._primitiveBabylonMeshes=n._primitiveBabylonMeshes||[],n._primitiveBabylonMeshes[a._index]=l,this._createMorphTargets(t,n,o,a,l),s.push(this._loadVertexDataAsync(t,a,l).then((function(r){return new e.Geometry(l.name,i._babylonScene,r,!1,l),i._loadMorphTargetsAsync(t,a,l,r)}))),void 0==a.material)l.material=this._getDefaultMaterial();else{var u=r._GetProperty(t+"/material",this._gltf.materials,a.material);s.push(this._loadMaterialAsync("#/materials/"+u._index,u,l))}return this.onMeshLoadedObservable.notifyObservers(l),Promise.all(s).then((function(){l.setEnabled(!0)}))},r.prototype._loadVertexDataAsync=function(n,o,a){var i=this,s=t.GLTFLoaderExtension._LoadVertexDataAsync(this,n,o,a);if(s)return s;var l=o.attributes;if(!l)throw new Error(n+": Attributes are missing");if(void 0!=o.mode&&4!==o.mode)throw new Error(n+": Mode "+o.mode+" is not currently supported");var u=new Array,c=new e.VertexData;if(void 0==o.indices){var d=l.POSITION;if(void 0!=d){var f=r._GetProperty(n+"/attributes/POSITION",this._gltf.accessors,d);c.indices=new Uint32Array(f.count);for(var h=0;h<c.indices.length;h++)c.indices[h]=h}}else{var p=r._GetProperty(n+"/indices",this._gltf.accessors,o.indices);u.push(this._loadAccessorAsync("#/accessors/"+p._index,p).then((function(e){c.indices=e})))}var m=function(e,t){if(void 0!=l[e]){a._delayInfo=a._delayInfo||[],a._delayInfo.indexOf(t)===-1&&a._delayInfo.push(t);var o=r._GetProperty(n+"/attributes/"+e,i._gltf.accessors,l[e]);u.push(i._loadAccessorAsync("#/accessors/"+o._index,o).then((function(i){var s=r._ConvertToFloat32Array(n,o,i);"COLOR_0"===e&&(a.hasVertexAlpha=!0,"VEC3"===o.type&&(s=r._ConvertVec3ToVec4(n,s))),c.set(s,t)})))}};return m("POSITION",e.VertexBuffer.PositionKind),m("NORMAL",e.VertexBuffer.NormalKind),m("TANGENT",e.VertexBuffer.TangentKind),m("TEXCOORD_0",e.VertexBuffer.UVKind),m("TEXCOORD_1",e.VertexBuffer.UV2Kind),m("JOINTS_0",e.VertexBuffer.MatricesIndicesKind),m("WEIGHTS_0",e.VertexBuffer.MatricesWeightsKind),m("COLOR_0",e.VertexBuffer.ColorKind),Promise.all(u).then((function(){return c}))},r.prototype._createMorphTargets=function(t,r,n,o,a){if(o.targets){
- if(void 0==r._numMorphTargets)r._numMorphTargets=o.targets.length;else if(o.targets.length!==r._numMorphTargets)throw new Error(t+": Primitives do not have the same number of targets");a.morphTargetManager=new e.MorphTargetManager;for(var i=0;i<o.targets.length;i++){var s=r.weights?r.weights[i]:n.weights?n.weights[i]:0;a.morphTargetManager.addTarget(new e.MorphTarget("morphTarget"+i,s))}}},r.prototype._loadMorphTargetsAsync=function(e,t,r,n){if(!t.targets)return Promise.resolve();for(var o=new Array,a=r.morphTargetManager,i=0;i<a.numTargets;i++){var s=a.getTarget(i);o.push(this._loadMorphTargetVertexDataAsync(e+"/targets/"+i,n,t.targets[i],s))}return Promise.all(o).then((function(){}))},r.prototype._loadMorphTargetVertexDataAsync=function(e,t,n,o){var a=this,i=new Array,s=function(t,o){if(void 0!=n[t]){var s=r._GetProperty(e+"/"+t,a._gltf.accessors,n[t]);i.push(a._loadAccessorAsync("#/accessors/"+s._index,s).then((function(e){o(e)})))}};return s("POSITION",(function(e){if(t.positions){for(var r=0;r<e.length;r++)e[r]+=t.positions[r];o.setPositions(e)}})),s("NORMAL",(function(e){if(t.normals){for(var r=0;r<e.length;r++)e[r]+=t.normals[r];o.setNormals(e)}})),s("TANGENT",(function(e){if(t.tangents){for(var r=0,n=0;r<e.length;r++)e[r]+=t.tangents[n++],(r+1)%3==0&&n++;o.setTangents(e)}})),Promise.all(i).then((function(){}))},r._ConvertToFloat32Array=function(e,t,n){if(5126==t.componentType)return n;var o=1;if(t.normalized)switch(t.componentType){case 5121:o=1/255;break;case 5123:o=1/65535;break;default:throw new Error(e+": Invalid component type "+t.componentType)}for(var a=new Float32Array(t.count*r._GetNumComponents(e,t.type)),i=0;i<a.length;i++)a[i]=n[i]*o;return a},r._ConvertVec3ToVec4=function(e,t){for(var r=new Float32Array(t.length/3*4),n=0,o=0;o<r.length;o++)r[o]=(o+1)%4==0?1:t[n++];return r},r._LoadTransform=function(t,r){var n=e.Vector3.Zero(),o=e.Quaternion.Identity(),a=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(a,o,n)}else t.translation&&(n=e.Vector3.FromArray(t.translation)),t.rotation&&(o=e.Quaternion.FromArray(t.rotation)),t.scale&&(a=e.Vector3.FromArray(t.scale));r.position=n,r.rotationQuaternion=o,r.scaling=a},r.prototype._loadSkinAsync=function(t,r,n,o){var a=this,i=function(){for(var t=0,n=r._primitiveBabylonMeshes;t<n.length;t++){n[t].skeleton=o._babylonSkeleton}r._babylonMesh.parent=a._rootBabylonMesh,r._babylonMesh.position=e.Vector3.Zero(),r._babylonMesh.rotationQuaternion=e.Quaternion.Identity(),r._babylonMesh.scaling=e.Vector3.One()};return o._loaded?(i(),o._loaded):o._loaded=this._loadSkinInverseBindMatricesDataAsync(t,o).then((function(r){var n="skeleton"+o._index,s=new e.Skeleton(o.name||n,n,a._babylonScene);o._babylonSkeleton=s,a._loadBones(t,o,r),i()}))},r.prototype._loadSkinInverseBindMatricesDataAsync=function(e,t){if(void 0==t.inverseBindMatrices)return Promise.resolve(null);var n=r._GetProperty(e+"/inverseBindMatrices",this._gltf.accessors,t.inverseBindMatrices);return this._loadAccessorAsync("#/accessors/"+n._index,n).then((function(e){return e}))},r.prototype._createBone=function(t,r,n,o,a,i){var s=new e.Bone(t.name||"joint"+t._index,r._babylonSkeleton,n,o,null,a,i);return t._babylonAnimationTargets=t._babylonAnimationTargets||[],t._babylonAnimationTargets.push(s),s},r.prototype._loadBones=function(e,t,n){for(var o={},a=0,i=t.joints;a<i.length;a++){var s=i[a],l=r._GetProperty(e+"/joints/"+s,this._gltf.nodes,s);this._loadBone(l,t,n,o)}},r.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&&i!==-1&&(s=e.Matrix.FromArray(n,16*i),s.invertToRef(s));var l=null;return t._parent._babylonMesh!==this._rootBabylonMesh&&(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},r.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())},r.prototype._loadAnimationsAsync=function(){var e=this._gltf.animations;if(!e)return Promise.resolve();for(var t=new Array,r=0;r<e.length;r++){var n=e[r];t.push(this._loadAnimationAsync("#/animations/"+r,n))}return Promise.all(t).then((function(){}))},r.prototype._loadAnimationAsync=function(r,n){var o=new e.AnimationGroup(n.name||"animation"+n._index,this._babylonScene);n._babylonAnimationGroup=o;var a=new Array;t.ArrayItem.Assign(n.channels),t.ArrayItem.Assign(n.samplers);for(var i=0,s=n.channels;i<s.length;i++){var l=s[i];a.push(this._loadAnimationChannelAsync(r+"/channels/"+l._index,r,n,l,o))}return Promise.all(a).then((function(){o.normalize()}))},r.prototype._loadAnimationChannelAsync=function(t,n,o,a,i){var s=r._GetProperty(t+"/target/node",this._gltf.nodes,a.target.node);if(!s._babylonMesh)return Promise.resolve();var l=r._GetProperty(t+"/sampler",o.samplers,a.sampler);return this._loadAnimationSamplerAsync(n+"/samplers/"+a.sampler,l).then((function(r){var n,o;switch(a.target.path){case"translation":n="position",o=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":n="rotationQuaternion",o=e.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":n="scaling",o=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":n="influence",o=e.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(t+": Invalid target path "+a.target.path)}var l,u=0;switch(n){case"position":l=function(){var t=e.Vector3.FromArray(r.output,u);return u+=3,t};break;case"rotationQuaternion":l=function(){var t=e.Quaternion.FromArray(r.output,u);return u+=4,t};break;case"scaling":l=function(){var t=e.Vector3.FromArray(r.output,u);return u+=3,t};break;case"influence":l=function(){for(var e=new Array(s._numMorphTargets),t=0;t<s._numMorphTargets;t++)e[t]=r.output[u++];return e}}var c;switch(r.interpolation){case"STEP":c=function(t){return{frame:r.input[t],value:l(),interpolation:e.AnimationKeyInterpolation.STEP}};break;case"LINEAR":c=function(e){return{frame:r.input[e],value:l()}};break;case"CUBICSPLINE":c=function(e){return{frame:r.input[e],inTangent:l(),value:l(),outTangent:l()}}}var d;if(1===r.input.length){var f=c(0);d=[{frame:f.frame,value:f.value},{frame:f.frame+1,value:f.value}]}else{d=new Array(r.input.length);for(var h=0;h<r.input.length;h++)d[h]=c(h)}if("influence"===n)for(var p=0;p<s._numMorphTargets;p++)!(function(t){var r=i.name+"_channel"+i.targetedAnimations.length,a=new e.Animation(r,n,1,o);a.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}})));for(var l=0,u=s._primitiveBabylonMeshes;l<u.length;l++){var c=u[l],f=c.morphTargetManager.getTarget(t);i.addTargetedAnimation(a,f)}})(p);else{var m=i.name+"_channel"+i.targetedAnimations.length,_=new e.Animation(m,n,1,o);if(_.setKeys(d),s._babylonAnimationTargets)for(var y=0,A=s._babylonAnimationTargets;y<A.length;y++){var v=A[y];i.addTargetedAnimation(_,v)}}}))},r.prototype._loadAnimationSamplerAsync=function(e,t){if(t._data)return t._data;var n=t.interpolation||"LINEAR";switch(n){case"STEP":case"LINEAR":case"CUBICSPLINE":break;default:throw new Error(e+": Invalid interpolation "+t.interpolation)}var o,a,i=r._GetProperty(e+"/input",this._gltf.accessors,t.input),s=r._GetProperty(e+"/output",this._gltf.accessors,t.output);return t._data=Promise.all([this._loadAccessorAsync("#/accessors/"+i._index,i).then((function(e){o=e})),this._loadAccessorAsync("#/accessors/"+s._index,s).then((function(e){a=e}))]).then((function(){return{input:o,interpolation:n,output:a}})),t._data},r.prototype._loadBufferAsync=function(e,t){if(t._data)return t._data;if(!t.uri)throw new Error(e+": Uri is missing");return t._data=this._loadUriAsync(e,t.uri),t._data},r.prototype._loadBufferViewAsync=function(e,t){if(t._data)return t._data;var n=r._GetProperty(e+"/buffer",this._gltf.buffers,t.buffer);return t._data=this._loadBufferAsync("#/buffers/"+n._index,n).then((function(r){try{return new Uint8Array(r.buffer,r.byteOffset+(t.byteOffset||0),t.byteLength)}catch(t){throw new Error(e+": "+t.message)}})),t._data},r.prototype._loadAccessorAsync=function(t,n){var o=this;if(n.sparse)throw new Error(t+": Sparse accessors are not currently supported");if(n._data)return n._data;var a=r._GetProperty(t+"/bufferView",this._gltf.bufferViews,n.bufferView);return n._data=this._loadBufferViewAsync("#/bufferViews/"+a._index,a).then((function(i){var s=r._GetNumComponents(t,n.type),l=n.byteOffset||0,u=a.byteStride;0===u&&e.Tools.Warn(t+": Byte stride of 0 is not valid");try{switch(n.componentType){case 5120:return o._buildArrayBuffer(Float32Array,i,l,n.count,s,u);case 5121:return o._buildArrayBuffer(Uint8Array,i,l,n.count,s,u);case 5122:return o._buildArrayBuffer(Int16Array,i,l,n.count,s,u);case 5123:return o._buildArrayBuffer(Uint16Array,i,l,n.count,s,u);case 5125:return o._buildArrayBuffer(Uint32Array,i,l,n.count,s,u);case 5126:return o._buildArrayBuffer(Float32Array,i,l,n.count,s,u);default:throw new Error(t+": Invalid component type "+n.componentType)}}catch(e){throw new Error(t+": "+e)}})),n._data},r.prototype._buildArrayBuffer=function(e,t,r,n,o,a){r+=t.byteOffset;var i=n*o;if(!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,d=0;d<i;){for(var f=0;f<o;f++)u[d]=l[c+f],d++;c+=s}return u},r.prototype._getDefaultMaterial=function(){var t="__gltf_default",r=this._babylonScene.getMaterialByName(t);return r||(r=new e.PBRMaterial(t,this._babylonScene),r.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE,r.sideOrientation=this._babylonScene.useRightHandedSystem?e.Material.CounterClockWiseSideOrientation:e.Material.ClockWiseSideOrientation,r.metallic=1,r.roughness=1,this.onMaterialLoadedObservable.notifyObservers(r)),r},r.prototype._loadMaterialMetallicRoughnessPropertiesAsync=function(t,r){var n=new Array,o=r._babylonMaterial;o.metallic=1,o.roughness=1;var a=r.pbrMetallicRoughness;return a&&(a.baseColorFactor?(o.albedoColor=e.Color3.FromArray(a.baseColorFactor),o.alpha=a.baseColorFactor[3]):o.albedoColor=e.Color3.White(),o.metallic=void 0==a.metallicFactor?1:a.metallicFactor,o.roughness=void 0==a.roughnessFactor?1:a.roughnessFactor,a.baseColorTexture&&n.push(this._loadTextureAsync(t+"/baseColorTexture",a.baseColorTexture,(function(e){o.albedoTexture=e}))),a.metallicRoughnessTexture&&(n.push(this._loadTextureAsync(t+"/metallicRoughnessTexture",a.metallicRoughnessTexture,(function(e){o.metallicTexture=e}))),o.useMetallnessFromMetallicTextureBlue=!0,o.useRoughnessFromMetallicTextureGreen=!0,o.useRoughnessFromMetallicTextureAlpha=!1)),this._loadMaterialAlphaProperties(t,r),Promise.all(n).then((function(){}))},r.prototype._loadMaterialAsync=function(e,r,n){var o=t.GLTFLoaderExtension._LoadMaterialAsync(this,e,r,n);if(o)return o;if(r._babylonMeshes=r._babylonMeshes||[],r._babylonMeshes.push(n),r._loaded)return n.material=r._babylonMaterial,r._loaded;var a=new Array,i=this._createMaterial(r);return r._babylonMaterial=i,a.push(this._loadMaterialBasePropertiesAsync(e,r)),a.push(this._loadMaterialMetallicRoughnessPropertiesAsync(e,r)),this.onMaterialLoadedObservable.notifyObservers(i),n.material=i,r._loaded=Promise.all(a).then((function(){}))},r.prototype._createMaterial=function(t){var r=new e.PBRMaterial(t.name||"material"+t._index,this._babylonScene);return r.sideOrientation=this._babylonScene.useRightHandedSystem?e.Material.CounterClockWiseSideOrientation:e.Material.ClockWiseSideOrientation,r},r.prototype._loadMaterialBasePropertiesAsync=function(t,r){var n=new Array,o=r._babylonMaterial;return 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&&(n.push(this._loadTextureAsync(t+"/normalTexture",r.normalTexture,(function(e){o.bumpTexture=e}))),o.invertNormalMapX=!this._babylonScene.useRightHandedSystem,o.invertNormalMapY=this._babylonScene.useRightHandedSystem,void 0!=r.normalTexture.scale&&(o.bumpTexture.level=r.normalTexture.scale)),r.occlusionTexture&&(n.push(this._loadTextureAsync(t+"/occlusionTexture",r.occlusionTexture,(function(e){o.ambientTexture=e}))),o.useAmbientInGrayScale=!0,void 0!=r.occlusionTexture.strength&&(o.ambientTextureStrength=r.occlusionTexture.strength)),r.emissiveTexture&&n.push(this._loadTextureAsync(t+"/emissiveTexture",r.emissiveTexture,(function(e){o.emissiveTexture=e}))),Promise.all(n).then((function(){}))},r.prototype._loadMaterialAlphaProperties=function(t,r){var n=r._babylonMaterial;switch(r.alphaMode||"OPAQUE"){case"OPAQUE":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHATEST,n.alphaCutOff=void 0==r.alphaCutoff?.5:r.alphaCutoff,n.alpha&&(0===n.alpha?n.alphaCutOff=1:n.alphaCutOff/=n.alpha,n.alpha=1),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHABLEND,n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(t+": Invalid alpha mode "+r.alphaMode)}},r.prototype._loadTextureAsync=function(t,n,o){var a=this,i=r._GetProperty(t+"/index",this._gltf.textures,n.index);t="#/textures/"+n.index;var s=new Array,l=void 0==i.sampler?this._defaultSampler:r._GetProperty(t+"/sampler",this._gltf.samplers,i.sampler),u=this._loadSampler("#/samplers/"+l._index,l),c=new e.Deferred,d=new e.Texture(null,this._babylonScene,u.noMipMaps,!1,u.samplingMode,function(){a._disposed||c.resolve()},function(e,r){a._disposed||c.reject(new Error(t+": "+(r&&r.message)?r.message:e||"Failed to load texture"))});s.push(c.promise),d.name=i.name||"texture"+i._index,d.wrapU=u.wrapU,d.wrapV=u.wrapV,d.coordinatesIndex=n.texCoord||0;var f=r._GetProperty(t+"/source",this._gltf.images,i.source);return s.push(this._loadImageAsync("#/images/"+f._index,f).then((function(e){d.updateURL(e)}))),o(d),this.onTextureLoadedObservable.notifyObservers(d),Promise.all(s).then((function(){}))},r.prototype._loadSampler=function(e,t){return t._data||(t._data={noMipMaps:9728===t.minFilter||9729===t.minFilter,samplingMode:r._GetTextureSamplingMode(e,t.magFilter,t.minFilter),wrapU:r._GetTextureWrapMode(e,t.wrapS),wrapV:r._GetTextureWrapMode(e,t.wrapT)}),t._data},r.prototype._loadImageAsync=function(e,t){if(t._objectURL)return t._objectURL;var n;if(t.uri)n=this._loadUriAsync(e,t.uri);else{var o=r._GetProperty(e+"/bufferView",this._gltf.bufferViews,t.bufferView);n=this._loadBufferViewAsync("#/bufferViews/"+o._index,o)}return t._objectURL=n.then((function(e){return URL.createObjectURL(new Blob([e],{type:t.mimeType}))})),t._objectURL},r.prototype._loadUriAsync=function(n,o){var a=this,i=t.GLTFLoaderExtension._LoadUriAsync(this,n,o);if(i)return i;if(!r._ValidateUri(o))throw new Error(n+": Uri '"+o+"' is invalid");return e.Tools.IsBase64(o)?Promise.resolve(new Uint8Array(e.Tools.DecodeBase64(o))):new Promise(function(t,r){var i=e.Tools.LoadFile(a._rootUrl+o,(function(e){a._disposed||t(new Uint8Array(e))}),(function(t){if(!a._disposed)try{i&&a._state===e.GLTFLoaderState.Loading&&(i._lengthComputable=t.lengthComputable,i._loaded=t.loaded,i._total=t.total,a._onProgress())}catch(e){r(e)}}),a._babylonScene.database,!0,(function(t,i){a._disposed||r(new e.LoadFileError(n+": Failed to load '"+o+"'"+(t?": "+t.status+" "+t.statusText:""),t))}));a._requests.push(i)})},r.prototype._onProgress=function(){if(this._progressCallback){for(var t=!0,r=0,n=0,o=0,a=this._requests;o<a.length;o++){var i=a[o];if(void 0===i._lengthComputable||void 0===i._loaded||void 0===i._total)return;t=t&&i._lengthComputable,r+=i._loaded,n+=i._total}this._progressCallback(new e.SceneLoaderProgressEvent(t,r,t?n:0))}},r._GetProperty=function(e,t,r){if(!t||void 0==r||!t[r])throw new Error(e+": Failed to find index "+r);return t[r]},r._GetTextureWrapMode=function(t,r){switch(r=void 0==r?10497:r){case 33071:return e.Texture.CLAMP_ADDRESSMODE;case 33648:return e.Texture.MIRROR_ADDRESSMODE;case 10497:return e.Texture.WRAP_ADDRESSMODE;default:return e.Tools.Warn(t+": Invalid texture wrap mode "+r),e.Texture.WRAP_ADDRESSMODE}},r._GetTextureSamplingMode=function(t,r,n){if(r=void 0==r?9729:r,n=void 0==n?9987:n,9729===r)switch(n){case 9728:return e.Texture.LINEAR_NEAREST;case 9729:return e.Texture.LINEAR_LINEAR;case 9984:return e.Texture.LINEAR_NEAREST_MIPNEAREST;case 9985:return e.Texture.LINEAR_LINEAR_MIPNEAREST;case 9986:return e.Texture.LINEAR_NEAREST_MIPLINEAR;case 9987:return e.Texture.LINEAR_LINEAR_MIPLINEAR;default:return e.Tools.Warn(t+": Invalid texture minification filter "+n),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(9728!==r&&e.Tools.Warn(t+": Invalid texture magnification filter "+r),n){case 9728:return e.Texture.NEAREST_NEAREST;case 9729:return e.Texture.NEAREST_LINEAR;case 9984:return e.Texture.NEAREST_NEAREST_MIPNEAREST;case 9985:return e.Texture.NEAREST_LINEAR_MIPNEAREST;case 9986:return e.Texture.NEAREST_NEAREST_MIPLINEAR;case 9987:return e.Texture.NEAREST_LINEAR_MIPLINEAR;default:return e.Tools.Warn(t+": Invalid texture minification filter "+n),e.Texture.NEAREST_NEAREST_MIPNEAREST}},r._GetNumComponents=function(e,t){switch(t){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}throw new Error(e+": Invalid type "+t)},r._ValidateUri=function(t){return e.Tools.IsBase64(t)||t.indexOf("..")===-1},r.prototype._compileMaterialsAsync=function(){var e=new Array;if(this._gltf.materials)for(var t=0,r=this._gltf.materials;t<r.length;t++){var n=r[t],o=n._babylonMaterial,a=n._babylonMeshes;if(o&&a)for(var i=0,s=a;i<s.length;i++){var l=s[i];e.push(o.forceCompilationAsync(l)),this.useClipPlane&&e.push(o.forceCompilationAsync(l,{clipPlane:!0}))}}return Promise.all(e).then((function(){}))},r.prototype._compileShadowGeneratorsAsync=function(){for(var e=new Array,t=this._babylonScene.lights,r=0,n=t;r<n.length;r++){var o=n[r],a=o.getShadowGenerator();a&&e.push(a.forceCompilationAsync())}return Promise.all(e).then((function(){}))},r.prototype._clear=function(){for(var e=0,t=this._requests;e<t.length;e++){t[e].abort()}if(this._requests.length=0,this._gltf&&this._gltf.images)for(var r=0,n=this._gltf.images;r<n.length;r++){var o=n[r];o._objectURL&&(o._objectURL.then((function(e){URL.revokeObjectURL(e)})),o._objectURL=void 0)}delete this._gltf,delete this._babylonScene,this._completePromises.length=0,this._extensions={},delete this._rootBabylonMesh,delete this._progressCallback,this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear()},r.prototype._applyExtensions=function(e){for(var t=0,n=r._Names;t<n.length;t++){var o=n[t],a=this._extensions[o];if(a.enabled){var i=e(a);if(i)return i}}return null},r._Names=new Array,r._Factories={},r})();t.GLTFLoader=r,e.GLTFFileLoader.CreateGLTFLoaderV2=function(){return new r}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(e){this.enabled=!0,this._loader=e}return e.prototype._loadSceneAsync=function(e,t){return null},e.prototype._loadNodeAsync=function(e,t){return null},e.prototype._loadVertexDataAsync=function(e,t,r){return null},e.prototype._loadMaterialAsync=function(e,t,r){return null},e.prototype._loadUriAsync=function(e,t){return null},e.prototype._loadExtensionAsync=function(e,t,r){if(!t.extensions)return null;var n=t.extensions,o=n[this.name];if(!o)return null;delete n[this.name];try{return r(e+"/extensions/"+this.name,o)}finally{n[this.name]=o}},e._LoadSceneAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadSceneAsync(t,r)}))},e._LoadNodeAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadNodeAsync(t,r)}))},e._LoadVertexDataAsync=function(e,t,r,n){return e._applyExtensions((function(e){return e._loadVertexDataAsync(t,r,n)}))},e._LoadMaterialAsync=function(e,t,r,n){return e._applyExtensions((function(e){return e._loadMaterialAsync(t,r,n)}))},e._LoadUriAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadUriAsync(t,r)}))},e})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n="MSFT_lod",o=(function(r){function o(){var e=null!==r&&r.apply(this,arguments)||this;return e.name=n,e.maxLODsToLoad=Number.MAX_VALUE,e._loadingNodeLOD=null,e._loadNodeSignals={},e._loadingMaterialLOD=null,e._loadMaterialSignals={},e}return __extends(o,r),o.prototype._loadNodeAsync=function(t,r){var n=this;return this._loadExtensionAsync(t,r,(function(t,o){for(var a,i=n._getLODs(t,r,n._loader._gltf.nodes,o.ids),s=0;s<i.length;s++)!(function(t){var r=i[t];0!==t&&(n._loadingNodeLOD=r,n._loadNodeSignals[r._index]=new e.Deferred);var o=n._loader._loadNodeAsync("#/nodes/"+r._index,r).then((function(){if(0!==t){i[t-1]._babylonMesh.setEnabled(!1)}if(t!==i.length-1){var e=i[t+1]._index;n._loadNodeSignals[e].resolve(),delete n._loadNodeSignals[e]}}));0===t?a=o:(n._loader._completePromises.push(o),n._loadingNodeLOD=null)})(s);return a}))},o.prototype._loadMaterialAsync=function(t,r,n){var o=this;return this._loadingNodeLOD?null:this._loadExtensionAsync(t,r,(function(t,a){for(var i,s=o._getLODs(t,r,o._loader._gltf.materials,a.ids),l=0;l<s.length;l++)!(function(t){var r=s[t];0!==t&&(o._loadingMaterialLOD=r,o._loadMaterialSignals[r._index]=new e.Deferred);var a=o._loader._loadMaterialAsync("#/materials/"+r._index,r,n).then((function(){if(t!==s.length-1){var e=s[t+1]._index;o._loadMaterialSignals[e].resolve(),delete o._loadMaterialSignals[e]}}));0===t?i=a:(o._loader._completePromises.push(a),o._loadingMaterialLOD=null)})(l);return i}))},o.prototype._loadUriAsync=function(e,t){var r=this;if(this._loadingMaterialLOD){var n=this._loadingMaterialLOD._index;return this._loadMaterialSignals[n].promise.then((function(){return r._loader._loadUriAsync(e,t)}))}if(this._loadingNodeLOD){var n=this._loadingNodeLOD._index;return this._loadNodeSignals[n].promise.then((function(){return r._loader._loadUriAsync(e,t)}))}return null},o.prototype._getLODs=function(e,r,n,o){if(this.maxLODsToLoad<=0)throw new Error("maxLODsToLoad must be greater than zero");for(var a=new Array,i=o.length-1;i>=0;i--)if(a.push(t.GLTFLoader._GetProperty(e+"/ids/"+o[i],n,o[i])),a.length===this.maxLODsToLoad)return a;return a.push(r),a},o})(t.GLTFLoaderExtension);r.MSFT_lod=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n="KHR_draco_mesh_compression",o=(function(r){function o(){var e=null!==r&&r.apply(this,arguments)||this;return e.name=n,e}return __extends(o,r),o.prototype._loadVertexDataAsync=function(r,n,o){var a=this;return this._loadExtensionAsync(r,n,(function(i,s){if(void 0!=n.mode){if(5!==n.mode&&4!==n.mode)throw new Error(r+": Unsupported mode "+n.mode);if(5===n.mode)throw new Error(r+": Mode "+n.mode+" is not currently supported")}var l={},u=function(e,t){var r=s.attributes[e];void 0!=r&&(o._delayInfo=o._delayInfo||[],o._delayInfo.indexOf(t)===-1&&o._delayInfo.push(t),l[t]=r)};u("POSITION",e.VertexBuffer.PositionKind),u("NORMAL",e.VertexBuffer.NormalKind),u("TANGENT",e.VertexBuffer.TangentKind),u("TEXCOORD_0",e.VertexBuffer.UVKind),u("TEXCOORD_1",e.VertexBuffer.UV2Kind),u("JOINTS_0",e.VertexBuffer.MatricesIndicesKind),u("WEIGHTS_0",e.VertexBuffer.MatricesWeightsKind),u("COLOR_0",e.VertexBuffer.ColorKind);var c=t.GLTFLoader._GetProperty(i,a._loader._gltf.bufferViews,s.bufferView);return a._loader._loadBufferViewAsync("#/bufferViews/"+c._index,c).then((function(t){try{return e.DracoCompression.Decode(t,l)}catch(e){throw new Error(r+": "+e.message)}}))}))},o})(t.GLTFLoaderExtension);r.KHR_draco_mesh_compression=o,e.DracoCompression.IsSupported&&t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n="KHR_materials_pbrSpecularGlossiness",o=(function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=n,e}return __extends(r,t),r.prototype._loadMaterialAsync=function(e,t,r){var n=this;return this._loadExtensionAsync(e,t,(function(e,o){if(t._babylonMeshes=t._babylonMeshes||[],t._babylonMeshes.push(r),t._loaded)return r.material=t._babylonMaterial,t._loaded;var a=new Array,i=n._loader._createMaterial(t);return t._babylonMaterial=i,a.push(n._loader._loadMaterialBasePropertiesAsync(e,t)),a.push(n._loadSpecularGlossinessPropertiesAsync(n._loader,e,t,o)),n._loader.onMaterialLoadedObservable.notifyObservers(i),r.material=i,t._loaded=Promise.all(a).then((function(){}))}))},r.prototype._loadSpecularGlossinessPropertiesAsync=function(t,r,n,o){var a=new Array,i=n._babylonMaterial;return o.diffuseFactor?(i.albedoColor=e.Color3.FromArray(o.diffuseFactor),i.alpha=o.diffuseFactor[3]):i.albedoColor=e.Color3.White(),i.reflectivityColor=o.specularFactor?e.Color3.FromArray(o.specularFactor):e.Color3.White(),i.microSurface=void 0==o.glossinessFactor?1:o.glossinessFactor,o.diffuseTexture&&a.push(t._loadTextureAsync(r+"/diffuseTexture",o.diffuseTexture,(function(e){i.albedoTexture=e}))),o.specularGlossinessTexture&&(a.push(t._loadTextureAsync(r+"/specularGlossinessTexture",o.specularGlossinessTexture,(function(e){i.reflectivityTexture=e}))),i.reflectivityTexture.hasAlpha=!0,i.useMicroSurfaceFromReflectivityMapAlpha=!0),t._loadMaterialAlphaProperties(r,n),Promise.all(a).then((function(){}))},r})(t.GLTFLoaderExtension);r.KHR_materials_pbrSpecularGlossiness=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n,o="KHR_lights";!(function(e){e.AMBIENT="ambient",e.DIRECTIONAL="directional",e.POINT="point",e.SPOT="spot"})(n||(n={}));var a=(function(r){function a(){var e=null!==r&&r.apply(this,arguments)||this;return e.name=o,e}return __extends(a,r),a.prototype._loadSceneAsync=function(r,o){var a=this;return this._loadExtensionAsync(r,o,(function(r,i){var s=a._loader._loadSceneAsync(r,o),l=t.GLTFLoader._GetProperty(r,a._lights,i.light);if(l.type!==n.AMBIENT)throw new Error(r+": Only ambient lights are allowed on a scene");return a._loader._babylonScene.ambientColor=l.color?e.Color3.FromArray(l.color):e.Color3.Black(),s}))},a.prototype._loadNodeAsync=function(r,o){var a=this;return this._loadExtensionAsync(r,o,(function(r,i){var s,l=a._loader._loadNodeAsync(r,o),u=t.GLTFLoader._GetProperty(r,a._lights,i.light),c=o._babylonMesh.name;switch(u.type){case n.AMBIENT:throw new Error(r+": Ambient lights are not allowed on a node");case n.DIRECTIONAL:s=new e.DirectionalLight(c,e.Vector3.Forward(),a._loader._babylonScene);break;case n.POINT:s=new e.PointLight(c,e.Vector3.Zero(),a._loader._babylonScene);break;case n.SPOT:var d=u,f=d.outerConeAngle||Math.PI/4;s=new e.SpotLight(c,e.Vector3.Zero(),e.Vector3.Forward(),f,2,a._loader._babylonScene);break;default:throw new Error(r+": Invalid light type "+u.type)}return s.diffuse=u.color?e.Color3.FromArray(u.color):e.Color3.White(),s.intensity=void 0==u.intensity?1:u.intensity,s.parent=o._babylonMesh,l}))},Object.defineProperty(a.prototype,"_lights",{get:function(){var e=this._loader._gltf.extensions;if(!e||!e[this.name])throw new Error("#/extensions: "+this.name+" not found");return e[this.name].lights},enumerable:!0,configurable:!0}),a})(t.GLTFLoaderExtension);r.KHR_lights=a,t.GLTFLoader._Register(o,(function(e){return new a(e)}))})(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}));
|