babylon.glTFFileLoader.min.js 67 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){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){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){if(t instanceof ArrayBuffer)return e._parseBinary(t,n);try{return{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.HomogeneousCoordinates=!1,e.IncrementalLoading=!0,e})();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]),p=t.GLTFUtils.GetBufferFromAccessor(n,n.accessors[d]),T=l.target.id,A=n.scene.getNodeByID(T);if(null===A&&(A=n.scene.getNodeByName(T)),null!==A){var E=A instanceof e.Bone,m=l.target.path,_=i.indexOf(m);-1!==_&&(m=s[_]);var y=e.Animation.ANIMATIONTYPE_MATRIX;E||("rotationQuaternion"===m?(y=e.Animation.ANIMATIONTYPE_QUATERNION,A.rotationQuaternion=new e.Quaternion):y=e.Animation.ANIMATIONTYPE_VECTOR3);var g=null,v=[],L=0,b=!1;E&&a&&a.getKeys().length===h.length&&(g=a,b=!0),b||(g=new e.Animation(r,E?"_matrix":m,1,y,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var N=0;N<h.length;N++){var M=null;if("rotationQuaternion"===m?(M=e.Quaternion.FromArray([p[L],p[L+1],p[L+2],p[L+3]]),L+=4):(M=e.Vector3.FromArray([p[L],p[L+1],p[L+2]]),L+=3),E){var O=A,x=e.Vector3.Zero(),R=new e.Quaternion,S=e.Vector3.Zero(),F=O.getBaseMatrix();b&&(F=a.getKeys()[N].value),F.decompose(S,R,x),"position"===m?x=M:"rotationQuaternion"===m?R=M:S=M,M=e.Matrix.Compose(S,R,x)}b?a.getKeys()[N].value=M:v.push({frame:h[N],value:M})}b||(g.setKeys(v),A.animations.push(g)),a=g,n.scene.stopAnimation(A),n.scene.beginAnimation(A,0,h[h.length-1],!0,1)}else e.Tools.Warn("Creating animation named "+r+". But cannot find node named "+T+" to attach to")}}},p=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},T=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=p(u),d=new e.Bone(u.name,o,T(t,n,u.jointName,o),f);return d.id=s,d}}}return null},A=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},E=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},m=function(e,t){for(var n=0;n<e.jointNames.length;n++)if(e.jointNames[n]===t)return!0;return!1},_=function(t,n,r,o){for(var a in t.nodes){var i=t.nodes[a],s=a;if(i.jointName&&!m(r,i.jointName)){var u=p(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 T=null,A=0;A<o.length;A++)if(o[A].id===d[h]){T=o[A];break}T&&(T.bone._parent=f.bone,f.bone.children.push(T.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=[];_(n,a,r,u),a.bones=[];for(var c=0;c<r.jointNames.length;c++){var f=E(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 m=!1,y=null,g=0;g<c;g++){var v=E(n,r.jointNames[g]).node;if(v){var L=v.children;if(L){m=!1;for(var b=0;b<L.length;b++)if(L[b]===i){y=T(n,r,r.jointNames[g],a),m=!0;break}if(m)break}}else e.Tools.Warn("Joint named "+r.jointNames[g]+" does not exist when looking for parent")}var N=p(d);!y&&u.length>0&&(y=A(u,i))&&-1===l.indexOf(y)&&l.push(y);new e.Bone(d.jointName,a,y,N).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=E(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=[],T=0;T<o.length;T++){var A=o[T],E=n.meshes[A];if(E)for(var m=0;m<E.primitives.length;m++){var _=new e.VertexData,y=E.primitives[m];y.mode;var g=y.attributes,v=null,L=null;for(var b in g)if(v=n.accessors[g[b]],L=t.GLTFUtils.GetBufferFromAccessor(n,v),"NORMAL"===b)_.normals=new Float32Array(L.length),_.normals.set(L);else if("POSITION"===b){if(e.GLTFFileLoader.HomogeneousCoordinates){_.positions=new Float32Array(L.length-L.length/4);for(var N=0;N<L.length;N+=4)_.positions[N]=L[N],_.positions[N+1]=L[N+1],_.positions[N+2]=L[N+2]}else _.positions=new Float32Array(L.length),_.positions.set(L);d.push(_.positions.length)}else if(-1!==b.indexOf("TEXCOORD_")){var M=Number(b.split("_")[1]),O=e.VertexBuffer.UVKind+(0===M?"":M+1),x=new Float32Array(L.length);x.set(L),f(x),_.set(x,O)}else"JOINT"===b?(_.matricesIndices=new Float32Array(L.length),_.matricesIndices.set(L)):"WEIGHT"===b?(_.matricesWeights=new Float32Array(L.length),_.matricesWeights.set(L)):"COLOR"===b&&(_.colors=new Float32Array(L.length),_.colors.set(L));if(v=n.accessors[y.indices])L=t.GLTFUtils.GetBufferFromAccessor(n,v),_.indices=new Int32Array(L.length),_.indices.set(L),p.push(_.indices.length);else{for(var R=[],N=0;N<_.positions.length/3;N++)R.push(N);_.indices=new Int32Array(R),p.push(_.indices.length)}u.merge(_),_=void 0;var S=n.scene.getMaterialByID(y.material);s.subMaterials.push(null===S?t.GLTFUtils.GetDefaultMaterial(n.scene):S),c.push(0===c.length?0:c[c.length-1]+d[d.length-2]),h.push(0===h.length?0:h[h.length-1]+p[p.length-2])}}l.setAllVerticesData(u,!1),i.computeWorldMatrix(!0),i.subMeshes=[];for(var F=0,T=0;T<o.length;T++){var A=o[T],E=n.meshes[A];if(E)for(var m=0;m<E.primitives.length;m++){E.primitives[m].mode;new e.SubMesh(F,c[F],d[F],h[F],p[F],i,i,!0);F++}}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)},b=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],p=new e.HemisphericLight(n.light,e.Vector3.Zero(),t.scene);p.name=n.name,h.color&&(p.diffuse=e.Color3.FromArray(h.color)),a=p}else if("directional"===d.type){var T=d[d.type],A=new e.DirectionalLight(n.light,e.Vector3.Zero(),t.scene);A.name=n.name,T.color&&(A.diffuse=e.Color3.FromArray(T.color)),a=A}else if("point"===d.type){var E=d[d.type],m=new e.PointLight(n.light,e.Vector3.Zero(),t.scene);m.name=n.name,E.color&&(m.diffuse=e.Color3.FromArray(E.color)),a=m}else if("spot"===d.type){var _=d[d.type],b=new e.SpotLight(n.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);b.name=n.name,_.color&&(b.diffuse=e.Color3.FromArray(_.color)),_.fallOfAngle&&(b.angle=_.fallOfAngle),_.fallOffExponent&&(b.exponent=_.fallOffExponent),a=b}}if(!n.jointName){if(n.babylonNode)return n.babylonNode;if(null===a){var N=new e.Mesh(n.name,t.scene);n.babylonNode=N,a=N}}if(null!==a){if(n.matrix&&a instanceof e.Mesh)L(a,n);else{var M=n.translation||[0,0,0],O=n.rotation||[0,0,0,1],x=n.scale||[1,1,1];v(a,e.Vector3.FromArray(M),e.Quaternion.FromArray(O),e.Vector3.FromArray(x))}a.updateCache(!0),n.babylonNode=a}return a},N=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=b(e,o,t))&&(a.id=t,a.parent=n),o.children)for(var i=0;i<o.children.length;i++)N(e,o.children[i],a,r)},M=function(e){var t=e.currentScene;if(t)for(var n=0;n<t.nodes.length;n++)N(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++)N(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)}},O=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 p=n.textures[i.values?h:c.value].babylonTexture;if(null===p||void 0===p)continue;o.getEffect().setTexture(l,p)}else t.GLTFUtils.SetUniform(o.getEffect(),l,h,f)}}s(o)},x=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]}}},R=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")}},S=function(e,t,n,r,o,a){return function(i){x(e,t,n,r,o),t.onBind=function(i){O(i,e,o,t,n,r,a)}}},F=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},I=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)},p=new e.Texture(d,n.scene,!l,!0,c,h,h);p.wrapU=t.GLTFUtils.GetWrapMode(u.wrapS),p.wrapV=t.GLTFUtils.GetWrapMode(u.wrapT),p.name=r,s.babylonTexture=p,a(p)},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 p=i.programs[f.program],T=f.states,A=e.Effect.ShadersStore[p.vertexShader+"VertexShader"],E=e.Effect.ShadersStore[p.fragmentShader+"PixelShader"],m="",_="",y=new r(A),g=new r(E),v={},L=[],b=[],N=[];for(var M in f.uniforms){var O=f.uniforms[M],x=f.parameters[O];if(v[M]=x,!x.semantic||x.node||x.source)x.type===t.EParameterType.SAMPLER_2D?N.push(M):L.push(M);else{var I=o.indexOf(x.semantic);-1!==I?(L.push(a[I]),delete v[M]):L.push(M)}}for(var B in f.attributes){var P=f.attributes[B],C=f.parameters[P];C.semantic&&b.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){m+=d(C),D=!0;break}}D||(m+=F(y,f,v))}else m+=y.currentString}for(;!g.isEnd()&&g.getNextToken();){var w=g.currentToken;w===n.IDENTIFIER?_+=F(g,f,v):_+=g.currentString}var G={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},U={attributes:b,uniforms:L,samplers:N,needAlphaBlending:T&&T.enable&&-1!==T.enable.indexOf(3042)};e.Effect.ShadersStore[p.vertexShader+s+"VertexShader"]=m,e.Effect.ShadersStore[p.fragmentShader+s+"PixelShader"]=_;var V=new e.ShaderMaterial(s,i.scene,G,U);if(V.onError=R(p,V,l),V.onCompiled=S(i,V,f,c,v,u),V.sideOrientation=e.Material.CounterClockWiseSideOrientation,T&&T.functions){var k=T.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(){I(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(){I(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++)N(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++)N(e,t.nodes[n],null)}},n.Extensions={},n})();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};n._DefaultMaterial=new e.ShaderMaterial("GLTFDefaultMaterial",t,r,o),
  2. n._DefaultMaterial.setColor4("u_emission",new e.Color4(.5,.5,.5,1))}return n._DefaultMaterial},n._DefaultMaterial=null,n})();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 p=s.spot,T=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);T.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},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 n(t){this._renderReady=!1,this._disposed=!1,this._blockPendingTracking=!1,this._renderReadyObservable=new e.Observable,this._renderPendingCount=0,this._loaderPendingCount=0,this._parent=t}return n.RegisterExtension=function(r){if(n.Extensions[r.name])return void e.Tools.Error("Extension with the same name '"+r.name+"' already exists");n.Extensions[r.name]=r,t.GLTFLoaderExtension._Extensions.push(r)},Object.defineProperty(n.prototype,"gltf",{get:function(){return this._gltf},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"babylonScene",{get:function(){return this._babylonScene},enumerable:!0,configurable:!0}),n.prototype.executeWhenRenderReady=function(e){this._renderReady?e():this._renderReadyObservable.add(e)},n.prototype.dispose=function(){this._disposed||(this._disposed=!0,this._gltf.textures&&this._gltf.textures.forEach((function(e){e.url&&URL.revokeObjectURL(e.url)})),this._gltf=void 0,this._babylonScene=void 0,this._rootUrl=void 0,this._defaultMaterial=void 0,this._successCallback=void 0,this._errorCallback=void 0,this._renderReady=!1,this._renderReadyObservable.clear(),this._renderPendingCount=0,this._loaderPendingCount=0)},n.prototype.importMeshAsync=function(e,t,n,r,o,a,i){var s=this;this._loadAsync(e,t,n,r,(function(){o(s._getMeshes(),null,s._getSkeletons())}),a,i)},n.prototype.loadAsync=function(e,t,n,r,o,a){this._loadAsync(null,e,t,n,r,o,a)},n.prototype._loadAsync=function(e,t,n,r,o,a,i){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)},n.prototype._onError=function(e){this._errorCallback(e),this.dispose()},n.prototype._onProgress=function(e){this._progressCallback(e)},n.prototype._onRenderReady=function(){switch(this._parent.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||this._addRightHandToLeftHandRootTransform();break;case e.GLTFLoaderCoordinateSystemMode.PASS_THROUGH:break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:e.Tools.Error("Invalid coordinate system mode ("+this._parent.coordinateSystemMode+")")}this._showMeshes(),this._startAnimations(),this._successCallback(),this._renderReadyObservable.notifyObservers(this)},n.prototype._onLoaderComplete=function(){this._parent.onComplete&&this._parent.onComplete()},n.prototype._onLoaderFirstLODComplete=function(){this._parent.onFirstLODComplete&&this._parent.onFirstLODComplete()},n.prototype._loadData=function(t){this._gltf=t.json;var n,r=this._gltf.buffers;r&&void 0===r[0].uri&&(n=r[0]),t.bin&&(n?n.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"):e.Tools.Warn("Unexpected BIN chunk"),n.loadedData=t.bin)},n.prototype._addRightHandToLeftHandRootTransform=function(){this._rootMesh=new e.Mesh("root",this._babylonScene),this._rootMesh.isVisible=!1,this._rootMesh.scaling=new e.Vector3(1,1,-1),this._rootMesh.rotation.y=Math.PI;var t=this._gltf.nodes;if(t)for(var n=0;n<t.length;n++){var r=t[n].babylonMesh;r&&!r.parent&&(r.parent=this._rootMesh)}},n.prototype._getMeshes=function(){var e=[];this._rootMesh&&e.push(this._rootMesh);var t=this._gltf.nodes;return t&&t.forEach((function(t){t.babylonMesh&&e.push(t.babylonMesh)})),e},n.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},n.prototype._getAnimationTargets=function(){var e=[],t=this._gltf.animations;return t&&t.forEach((function(t){e.push.apply(e,t.targets)})),e},n.prototype._showMeshes=function(){this._getMeshes().forEach((function(e){return e.isVisible=!0}))},n.prototype._startAnimations=function(){var e=this;this._getAnimationTargets().forEach((function(t){return e._babylonScene.beginAnimation(t,0,Number.MAX_VALUE,!0)}))},n.prototype._loadScene=function(e){var t=this,n=this._gltf.scenes[this._gltf.scene||0],r=n.nodes;this._traverseNodes(r,(function(e,t,n){return e.index=t,e.parent=n,!0}));var o=this._gltf.materials;if(o&&o.forEach((function(e,t){return e.index=t})),e){e instanceof Array||(e=[e]);var a=new Array;this._traverseNodes(r,(function(t){return-1===e.indexOf(t.name)||(a.push(t.index),!1)})),r=a}this._traverseNodes(r,(function(e){return t._loadNode(e)}))},n.prototype._loadNode=function(t){if(t.babylonMesh=new e.Mesh(t.name||"mesh"+t.index,this._babylonScene),t.babylonMesh.isVisible=!1,this._loadTransform(t),void 0!==t.mesh){var n=this._gltf.meshes[t.mesh];this._loadMesh(t,n)}if(t.babylonMesh.parent=t.parent?t.parent.babylonMesh:null,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(t.babylonMesh),void 0!==t.skin){var r=this._gltf.skins[t.skin];r.index=t.skin,t.babylonMesh.skeleton=this._loadSkin(r)}return t.camera,!0},n.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(void 0===h.material)a.subMaterials[d]=o._getDefaultMaterial();else{var e=o._gltf.materials[h.material];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)},n.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)!(function(c){a=l._gltf.accessors[o[c]],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 semantic '"+c+"'")}if(++s===u){var a=r._gltf.accessors[t.indices];a?r._loadAccessorAsync(a,(function(e){i.indices=e,n(i)})):(i.indices=new Uint32Array(i.positions.length/3),i.indices.forEach((function(e,t){return i.indices[t]=t})),n(i))}}))})(c)},n.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))}}},n.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++)!(function(){var n=a.morphTargetManager.getTarget(c);s=i[c];for(var r in s)!(function(r){u=l._gltf.accessors[s[r]],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 semantic '"+r+"'")}}))})(r)})()},n.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},n.prototype._loadSkin=function(t){var n=this,r="skeleton"+t.index;if(t.babylonSkeleton=new e.Skeleton(t.name||r,r,this._babylonScene),void 0===t.inverseBindMatrices)this._loadBones(t,null);else{var o=this._gltf.accessors[t.inverseBindMatrices];this._loadAccessorAsync(o,(function(e){n._loadBones(t,e)}))}return t.babylonSkeleton},n.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},n.prototype._loadBones=function(e,t){for(var n={},r=0;r<e.joints.length;r++){var o=this._gltf.nodes[e.joints[r]];this._loadBone(o,e,t,n)}},n.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},n.prototype._getNodeMatrix=function(t){return t.matrix?e.Matrix.FromArray(t.matrix):e.Matrix.Compose(t.scale?e.Vector3.FromArray(t.scale):e.Vector3.One(),t.rotation?e.Quaternion.FromArray(t.rotation):e.Quaternion.Identity(),t.translation?e.Vector3.FromArray(t.translation):e.Vector3.Zero())},n.prototype._traverseNodes=function(e,t,n){void 0===n&&(n=null);for(var r=0;r<e.length;r++)this._traverseNode(e[r],t,n)},n.prototype._traverseNode=function(e,t,n){void 0===n&&(n=null);var r=this._gltf.nodes[e];if(t(r,e,n)&&r.children)for(var o=0;o<r.children.length;o++)this._traverseNode(r.children[o],t,r)},n.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e&&0!==e.length)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)},n.prototype._loadAnimationChannel=function(t,n,r){var o=t.channels[r],a=o.sampler,i=t.samplers[a],s=this._gltf.nodes[o.target.node];if(!s)return void e.Tools.Warn("Animation channel target node ("+o.target.node+") does not exist");var u={translation:"position",rotation:"rotationQuaternion",scale:"scaling",weights:"influence"}[o.target.path];if(!u)return void e.Tools.Warn("Animation channel target path '"+o.target.path+"' is not valid");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 p=s.babylonMesh.morphTargetManager,T=0;T<p.numTargets;T++){var A=p.getTarget(T),E=(t.name||"anim"+n)+"_"+T,m=new e.Animation(E,u,1,f);m.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}}))),A.animations.push(m),t.targets.push(A)}else{var E=t.name||"anim"+n,m=new e.Animation(E,u,1,f);m.setKeys(d);for(var _=0;_<s.babylonAnimationTargets.length;_++){var y=s.babylonAnimationTargets[_];y.animations.push(m.clone()),t.targets.push(y)}}}};this._loadAccessorAsync(this._gltf.accessors[i.input],(function(e){l=e,d()})),this._loadAccessorAsync(this._gltf.accessors[i.output],(function(e){c=e,d()}))},n.prototype._loadBufferAsync=function(n,r){var o=this,a=this._gltf.buffers[n];if(this.addPendingData(a),a.loadedData)setTimeout((function(){r(a.loadedData),o.removePendingData(a)}));else if(t.GLTFUtils.IsBase64(a.uri)){var i=t.GLTFUtils.DecodeBase64(a.uri);a.loadedData=new Uint8Array(i),setTimeout((function(){r(a.loadedData),o.removePendingData(a)}))}else a.loadedObservable?a.loadedObservable.add((function(e){r(e.loadedData),o.removePendingData(e)})):(a.loadedObservable=new e.Observable,a.loadedObservable.add((function(e){r(e.loadedData),o.removePendingData(e)})),e.Tools.LoadFile(this._rootUrl+a.uri,(function(e){a.loadedData=new Uint8Array(e),a.loadedObservable.notifyObservers(a),a.loadedObservable=null}),(function(e){o._disposed||o._onProgress(e)}),this._babylonScene.database,!0,(function(e){o._disposed||(o._onError("Failed to load file '"+a.uri+"': "+e.status+" "+e.statusText),o.removePendingData(a))})))},n.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},n.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},n.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},n.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},n.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},n.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},n.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}},n.prototype._loadBufferViewAsync=function(e,n,r,o,a,i){var s=this;n+=e.byteOffset||0,this._loadBufferAsync(e.buffer,(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)}))},n.prototype._loadAccessorAsync=function(e,t){var n=this._gltf.bufferViews[e.bufferView],r=e.byteOffset||0,o=this._getByteStrideFromType(e),a=e.count*o;this._loadBufferViewAsync(n,r,a,o,e.componentType,t)},n.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}},Object.defineProperty(n.prototype,"blockPendingTracking",{set:function(e){this._blockPendingTracking=e},enumerable:!0,configurable:!0}),n.prototype.addPendingData=function(e){this._renderReady||this._renderPendingCount++,this.addLoaderPendingData(e)},n.prototype.removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._onRenderReady()),this.removeLoaderPendingData(e)},n.prototype.addLoaderNonBlockingPendingData=function(e){this._nonBlockingData||(this._nonBlockingData=new Array),this._nonBlockingData.push(e)},n.prototype.addLoaderPendingData=function(e){if(this._blockPendingTracking)return void this.addLoaderNonBlockingPendingData(e);this._loaderPendingCount++},n.prototype.removeLoaderPendingData=function(e){var t=this._nonBlockingData?this._nonBlockingData.indexOf(e):-1;-1!==t?this._nonBlockingData.splice(t,1):0==--this._loaderPendingCount&&this._onLoaderFirstLODComplete(),this._nonBlockingData&&0!==this._nonBlockingData.length||0!==this._loaderPendingCount||(this._onLoaderComplete(),this.dispose())},n.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},n.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=void 0===r.metallicFactor?1:r.metallicFactor,n.roughness=void 0===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))},n.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))},n.prototype.createPbrMaterial=function(t){var n=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);n.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=n},n.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))},n.prototype.loadMaterialAlphaProperties=function(t,n){var r=t.babylonMaterial,o=t.alphaMode||"OPAQUE";switch(o){case"OPAQUE":break;case"MASK":case"BLEND":n&&(r.alpha=n[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture="BLEND"===o);break;default:e.Tools.Warn("Invalid alpha mode '"+t.alphaMode+"'")}r.alphaCutOff=void 0===t.alphaCutoff?.5:t.alphaCutoff},n.prototype.loadTexture=function(n){var r=this,o=this._gltf.textures[n.index],a=n.texCoord||0;if(!o||void 0===o.source)return null;var i=this._gltf.images[o.source],s=void 0===o.sampler?{}:this._gltf.samplers[o.sampler],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._disposed||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._gltf.bufferViews[i.bufferView];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},n.Extensions={},n})();t.GLTFLoader=n,e.GLTFFileLoader.CreateGLTFLoaderV2=function(e){return new n(e)}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var 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: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:
  3. 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.loadMaterial=function(e,t,n){return!1},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._Extensions=[],e})();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.loadMaterial=function(e,t,n){if(!t.extensions)return!1;var r=t.extensions[this.name];if(!r)return!1;t.extensions[this.name]=void 0;var o=[t.index].concat(r.ids);e.addLoaderPendingData(t);for(var a=0;a<o.length;a++)e.addLoaderNonBlockingPendingData(a);return this.loadMaterialLOD(e,t,o,o.length-1,n),!0},n.prototype.loadMaterialLOD=function(t,r,o,a,i){var s=this,u=t.gltf.materials[o[a]];a!==o.length-1&&(t.blockPendingTracking=!0),t.loadMaterial(u,(function(u,l){if(i(u,l),t.removeLoaderPendingData(a),a===o.length-1&&t.removeLoaderPendingData(r),0===a)return void(t.blockPendingTracking=!1);t.executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(u.getActiveTextures(),(function(){setTimeout((function(){s.loadMaterialLOD(t,r,o,a-1,i)}),n.MinimalLODDelay)}))}))}))},n.MinimalLODDelay=250,n})(t.GLTFLoaderExtension);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){if(!t.extensions)return!1;var r=t.extensions[this.name];return!!r&&(e.createPbrMaterial(t),e.loadMaterialBaseProperties(t),this._loadSpecularGlossinessProperties(e,t,r),n(t.babylonMaterial,!0),!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={}));