babylon.glTFFileLoader.min.js 69 KB

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