babylon.glTFFileLoader.min.js 92 KB

123
  1. var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var r;!(function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"})(r=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}));!(function(e){e[e.LOADING=0]="LOADING",e[e.READY=1]="READY",e[e.COMPLETE=2]="COMPLETE"})(e.GLTFLoaderState||(e.GLTFLoaderState={}));var n=(function(){function n(){this.onParsedObservable=new e.Observable,this.coordinateSystemMode=t.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.transparencyAsCoverage=!1,this._normalizeAnimationGroupsToBeginAtZero=!0,this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCameraLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this._loader=null,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return Object.defineProperty(n.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onCameraLoaded",{set:function(e){this._onCameraLoadedObserver&&this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver),this._onCameraLoadedObserver=this.onCameraLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onExtensionLoaded",{set:function(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)},enumerable:!0,configurable:!0}),n.prototype.whenCompleteAsync=function(){var e=this;return new Promise(function(t){e.onCompleteObservable.add((function(){t()}),void 0,void 0,void 0,!0)})},Object.defineProperty(n.prototype,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),n.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCameraLoadedObservable.clear(),this.onCompleteObservable.clear(),this.onExtensionLoadedObservable.clear(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},n.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=a._parse(r);return a._loader=a._getLoader(i),a._loader.importMeshAsync(e,t,i,n,o)}))},n.prototype.loadAsync=function(e,t,r,n){var o=this;return Promise.resolve().then((function(){var a=o._parse(t);return o._loader=o._getLoader(a),o._loader.loadAsync(e,a,r,n)}))},n.prototype.loadAssetContainerAsync=function(t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=a._parse(r);return a._loader=a._getLoader(i),a._loader.importMeshAsync(null,t,i,n,o).then((function(r){var n=new e.AssetContainer(t);return Array.prototype.push.apply(n.meshes,r.meshes),Array.prototype.push.apply(n.particleSystems,r.particleSystems),Array.prototype.push.apply(n.skeletons,r.skeletons),Array.prototype.push.apply(n.animationGroups,r.animationGroups),n.removeAllFromScene(),n}))}))},n.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},n.prototype.createPlugin=function(){return new n},n.prototype._parse=function(e){var t;return t=e instanceof ArrayBuffer?n._parseBinary(e):{json:JSON.parse(e),bin:null},this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),t},n.prototype._getLoader=function(e){var t=this,r={major:2,minor:0},o=e.json.asset||{},a=n._parseVersion(o.version);if(!a)throw new Error("Invalid version: "+o.version);if(void 0!==o.minVersion){var i=n._parseVersion(o.minVersion);if(!i)throw new Error("Invalid minimum version: "+o.minVersion);if(n._compareVersion(i,r)>0)throw new Error("Incompatible minimum version: "+o.minVersion)}var s={1:n.CreateGLTFLoaderV1,2:n.CreateGLTFLoaderV2},l=s[a.major];if(!l)throw new Error("Unsupported version: "+o.version);var u=l();return u.coordinateSystemMode=this.coordinateSystemMode,u.animationStartMode=this.animationStartMode,u.compileMaterials=this.compileMaterials,u.useClipPlane=this.useClipPlane,u.compileShadowGenerators=this.compileShadowGenerators,u.transparencyAsCoverage=this.transparencyAsCoverage,u._normalizeAnimationGroupsToBeginAtZero=this._normalizeAnimationGroupsToBeginAtZero,u.preprocessUrlAsync=this.preprocessUrlAsync,u.onMeshLoadedObservable.add((function(e){return t.onMeshLoadedObservable.notifyObservers(e)})),u.onTextureLoadedObservable.add((function(e){return t.onTextureLoadedObservable.notifyObservers(e)})),u.onMaterialLoadedObservable.add((function(e){return t.onMaterialLoadedObservable.notifyObservers(e)})),u.onCameraLoadedObservable.add((function(e){return t.onCameraLoadedObservable.notifyObservers(e)})),u.onExtensionLoadedObservable.add((function(e){return t.onExtensionLoadedObservable.notifyObservers(e)})),u.onCompleteObservable.add((function(){t.onMeshLoadedObservable.clear(),t.onTextureLoadedObservable.clear(),t.onMaterialLoadedObservable.clear(),t.onCameraLoadedObservable.clear(),t.onExtensionLoadedObservable.clear(),t.onCompleteObservable.notifyObservers(t),t.onCompleteObservable.clear()})),u},n._parseBinary=function(e){var t={Magic:1179937895},r=new o(e),a=r.readUint32();if(a!==t.Magic)throw new Error("Unexpected magic: "+a);var i=r.readUint32();switch(i){case 1:return n._parseV1(r);case 2:return n._parseV2(r)}throw new Error("Unsupported version: "+i)},n._parseV1=function(e){var t={JSON:0},r=e.readUint32();if(r!=e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o,a=e.readUint32(),i=e.readUint32();switch(i){case t.JSON:o=JSON.parse(n._decodeBufferToText(e.readUint8Array(a)));break;default:throw new Error("Unexpected content format: "+i)}var s=e.getLength()-e.getPosition();return{json:o,bin:e.readUint8Array(s)}},n._parseV2=function(e){var t={JSON:1313821514,BIN:5130562},r=e.readUint32();if(r!==e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==t.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(n._decodeBufferToText(e.readUint8Array(o))),i=null;e.getPosition()<e.getLength();){var s=e.readUint32();switch(e.readUint32()){case t.JSON:throw new Error("Unexpected JSON chunk");case t.BIN:i=e.readUint8Array(s);break;default:e.skipBytes(s)}}return{json:a,bin:i}},n._parseVersion=function(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};var t=(e+"").match(/^(\d+)\.(\d+)/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null},n._compareVersion=function(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0},n._decodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;n++)t+=String.fromCharCode(e[n]);return t},n.IncrementalLoading=!0,n.HomogeneousCoordinates=!1,n})();e.GLTFFileLoader=n;var o=(function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new n)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.FLOAT=5126]="FLOAT"})(e.EComponentType||(e.EComponentType={}));!(function(e){e[e.FRAGMENT=35632]="FRAGMENT",e[e.VERTEX=35633]="VERTEX"})(e.EShaderType||(e.EShaderType={}));!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.INT=5124]="INT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT",e[e.FLOAT_VEC2=35664]="FLOAT_VEC2",e[e.FLOAT_VEC3=35665]="FLOAT_VEC3",e[e.FLOAT_VEC4=35666]="FLOAT_VEC4",e[e.INT_VEC2=35667]="INT_VEC2",e[e.INT_VEC3=35668]="INT_VEC3",e[e.INT_VEC4=35669]="INT_VEC4",e[e.BOOL=35670]="BOOL",e[e.BOOL_VEC2=35671]="BOOL_VEC2",e[e.BOOL_VEC3=35672]="BOOL_VEC3",e[e.BOOL_VEC4=35673]="BOOL_VEC4",e[e.FLOAT_MAT2=35674]="FLOAT_MAT2",e[e.FLOAT_MAT3=35675]="FLOAT_MAT3",e[e.FLOAT_MAT4=35676]="FLOAT_MAT4",e[e.SAMPLER_2D=35678]="SAMPLER_2D"})(e.EParameterType||(e.EParameterType={}));!(function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"})(e.ETextureWrapMode||(e.ETextureWrapMode={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9728]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"})(e.ETextureFilterType||(e.ETextureFilterType={}));!(function(e){e[e.ALPHA=6406]="ALPHA",e[e.RGB=6407]="RGB",e[e.RGBA=6408]="RGBA",e[e.LUMINANCE=6409]="LUMINANCE",e[e.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA"})(e.ETextureFormat||(e.ETextureFormat={}));!(function(e){e[e.FRONT=1028]="FRONT",e[e.BACK=1029]="BACK",e[e.FRONT_AND_BACK=1032]="FRONT_AND_BACK"})(e.ECullingType||(e.ECullingType={}));!(function(e){e[e.ZERO=0]="ZERO",e[e.ONE=1]="ONE",e[e.SRC_COLOR=768]="SRC_COLOR",e[e.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",e[e.DST_COLOR=774]="DST_COLOR",e[e.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.DST_ALPHA=772]="DST_ALPHA",e[e.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",e[e.CONSTANT_COLOR=32769]="CONSTANT_COLOR",e[e.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",e[e.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",e[e.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",e[e.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE"})(e.EBlendingFunction||(e.EBlendingFunction={}))})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r;!(function(e){e[e.IDENTIFIER=1]="IDENTIFIER",e[e.UNKNOWN=2]="UNKNOWN",e[e.END_OF_INPUT=3]="END_OF_INPUT"})(r||(r={}));var n=(function(){function e(e){this._pos=0,this.currentToken=r.UNKNOWN,this.currentIdentifier="",this.currentString="",this.isLetterOrDigitPattern=/^[a-zA-Z0-9]+$/,this._toParse=e,this._maxPos=e.length}return e.prototype.getNextToken=function(){if(this.isEnd())return r.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=r.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=r.IDENTIFIER,this.currentIdentifier=this.currentString;!this.isEnd()&&(this.isLetterOrDigitPattern.test(this.currentString=this.peek())||"_"===this.currentString);)this.currentIdentifier+=this.currentString,this.forward();return this.currentToken},e.prototype.peek=function(){return this._toParse[this._pos]},e.prototype.read=function(){return this._toParse[this._pos++]},e.prototype.forward=function(){this._pos++},e.prototype.isEnd=function(){return this._pos>=this._maxPos},e})(),o=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],a=["world","view","projection","worldView","worldViewProjection","mBones"],i=["translation","rotation","scale"],s=["position","rotationQuaternion","scaling"],l=function(e,t){for(var r in e){var n=e[r];t.buffers[r]=n,t.buffersCount++}},u=function(e,t){for(var r in e){var n=e[r];t.shaders[r]=n,t.shaderscount++}},c=function(e,t,r){for(var n in e){var o=e[n];r[t][n]=o}},d=function(e){if(e)for(var t=0;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},f=function(e){if("NORMAL"===e.semantic)return"normal";if("POSITION"===e.semantic)return"position";if("JOINT"===e.semantic)return"matricesIndices";if("WEIGHT"===e.semantic)return"matricesWeights";if("COLOR"===e.semantic)return"color";if(e.semantic&&-1!==e.semantic.indexOf("TEXCOORD_")){var t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}return null},h=function(r){for(var n in r.animations){var o=r.animations[n];if(o.channels&&o.samplers)for(var a=null,l=0;l<o.channels.length;l++){var u=o.channels[l],c=o.samplers[u.sampler];if(c){var d=null,f=null;o.parameters?(d=o.parameters[c.input],f=o.parameters[c.output]):(d=c.input,f=c.output);var h=t.GLTFUtils.GetBufferFromAccessor(r,r.accessors[d]),p=t.GLTFUtils.GetBufferFromAccessor(r,r.accessors[f]),_=u.target.id,m=r.scene.getNodeByID(_);if(null===m&&(m=r.scene.getNodeByName(_)),null!==m){var y=m instanceof e.Bone,A=u.target.path,v=i.indexOf(A);-1!==v&&(A=s[v]);var b=e.Animation.ANIMATIONTYPE_MATRIX;y||("rotationQuaternion"===A?(b=e.Animation.ANIMATIONTYPE_QUATERNION,m.rotationQuaternion=new e.Quaternion):b=e.Animation.ANIMATIONTYPE_VECTOR3);var T=null,g=[],L=0,E=!1;y&&a&&a.getKeys().length===h.length&&(T=a,E=!0),E||(T=new e.Animation(n,y?"_matrix":A,1,b,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var O=0;O<h.length;O++){var x=null;if("rotationQuaternion"===A?(x=e.Quaternion.FromArray([p[L],p[L+1],p[L+2],p[L+3]]),L+=4):(x=e.Vector3.FromArray([p[L],p[L+1],p[L+2]]),L+=3),y){var M=m,N=e.Vector3.Zero(),w=new e.Quaternion,S=e.Vector3.Zero(),F=M.getBaseMatrix();E&&a&&(F=a.getKeys()[O].value),F.decompose(S,w,N),"position"===A?N=x:"rotationQuaternion"===A?w=x:S=x,x=e.Matrix.Compose(S,w,N)}E?a&&(a.getKeys()[O].value=x):g.push({frame:h[O],value:x})}!E&&T&&(T.setKeys(g),m.animations.push(T)),a=T,r.scene.stopAnimation(m),r.scene.beginAnimation(m,0,h[h.length-1],!0,1)}else e.Tools.Warn("Creating animation named "+n+". But cannot find node named "+_+" to attach to")}}}},p=function(t){var r=null;if(t.translation||t.rotation||t.scale){var n=e.Vector3.FromArray(t.scale||[1,1,1]),o=e.Quaternion.FromArray(t.rotation||[0,0,0,1]),a=e.Vector3.FromArray(t.translation||[0,0,0]);r=e.Matrix.Compose(n,o,a)}else r=e.Matrix.FromArray(t.matrix);return r},_=function(t,r,n,o){for(var a=0;a<o.bones.length;a++)if(o.bones[a].name===n)return o.bones[a];var i=t.nodes;for(var s in i){var l=i[s];if(l.jointName)for(var u=l.children,a=0;a<u.length;a++){var c=t.nodes[u[a]];if(c.jointName&&c.jointName===n){var d=p(l),f=new e.Bone(l.name||"",o,_(t,r,l.jointName,o),d);return f.id=s,f}}}return null},m=function(e,t){for(var r=0;r<e.length;r++)for(var n=e[r],o=0;o<n.node.children.length;o++){var a=n.node.children[o];if(a===t)return n.bone}return null},y=function(e,t){var r=e.nodes,n=r[t];if(n)return{node:n,id:t};for(var o in r)if(n=r[o],n.jointName===t)return{node:n,id:o};return null},A=function(e,t){for(var r=0;r<e.jointNames.length;r++)if(e.jointNames[r]===t)return!0;return!1},v=function(t,r,n,o){for(var a in t.nodes){var i=t.nodes[a],s=a;if(i.jointName&&!A(n,i.jointName)){var l=p(i),u=new e.Bone(i.name||"",r,null,l);u.id=s,o.push({bone:u,node:i,id:s})}}for(var c=0;c<o.length;c++)for(var d=o[c],f=d.node.children,h=0;h<f.length;h++){for(var _=null,m=0;m<o.length;m++)if(o[m].id===f[h]){_=o[m];break}_&&(_.bone._parent=d.bone,d.bone.children.push(_.bone))}},b=function(t,r,n,o,a){if(o||(o=new e.Skeleton(r.name||"","",t.scene)),!r.babylonSkeleton)return o;var i=[],s=[];v(t,o,r,i),o.bones=[];for(var l=0;l<r.jointNames.length;l++){var u=y(t,r.jointNames[l]);if(u){var c=u.node;if(c){var a=u.id,d=t.scene.getBoneByID(a);if(d)o.bones.push(d);else{for(var f=!1,h=null,A=0;A<l;A++){var b=y(t,r.jointNames[A]);if(b){var T=b.node;if(T){var g=T.children;if(g){f=!1;for(var L=0;L<g.length;L++)if(g[L]===a){h=_(t,r,r.jointNames[A],o),f=!0;break}if(f)break}}else e.Tools.Warn("Joint named "+r.jointNames[A]+" does not exist when looking for parent")}}var E=p(c);!h&&i.length>0&&(h=m(i,a))&&-1===s.indexOf(h)&&s.push(h);new e.Bone(c.jointName||"",o,h,E).id=a}}else e.Tools.Warn("Joint named "+r.jointNames[l]+" does not exist")}}var O=o.bones;o.bones=[];for(var l=0;l<r.jointNames.length;l++){var u=y(t,r.jointNames[l]);if(u)for(var A=0;A<O.length;A++)if(O[A].id===u.id){o.bones.push(O[A]);break}}o.prepare();for(var l=0;l<s.length;l++)o.bones.push(s[l]);return o},T=function(r,n,o,a,i){if(i||(i=new e.Mesh(n.name||"",r.scene),i.id=a),!n.babylonNode)return i;for(var s=[],l=null,u=new Array,c=new Array,f=new Array,h=new Array,p=0;p<o.length;p++){var _=o[p],m=r.meshes[_];if(m)for(var y=0;y<m.primitives.length;y++){var A=new e.VertexData,v=m.primitives[y];v.mode;var b=v.attributes,T=null,g=null;for(var L in b)if(T=r.accessors[b[L]],g=t.GLTFUtils.GetBufferFromAccessor(r,T),"NORMAL"===L)A.normals=new Float32Array(g.length),A.normals.set(g);else if("POSITION"===L){if(e.GLTFFileLoader.HomogeneousCoordinates){A.positions=new Float32Array(g.length-g.length/4);for(var E=0;E<g.length;E+=4)A.positions[E]=g[E],A.positions[E+1]=g[E+1],A.positions[E+2]=g[E+2]}else A.positions=new Float32Array(g.length),A.positions.set(g);c.push(A.positions.length)}else if(-1!==L.indexOf("TEXCOORD_")){var O=Number(L.split("_")[1]),x=e.VertexBuffer.UVKind+(0===O?"":O+1),M=new Float32Array(g.length);M.set(g),d(M),A.set(M,x)}else"JOINT"===L?(A.matricesIndices=new Float32Array(g.length),A.matricesIndices.set(g)):"WEIGHT"===L?(A.matricesWeights=new Float32Array(g.length),A.matricesWeights.set(g)):"COLOR"===L&&(A.colors=new Float32Array(g.length),A.colors.set(g));if(T=r.accessors[v.indices])g=t.GLTFUtils.GetBufferFromAccessor(r,T),A.indices=new Int32Array(g.length),A.indices.set(g),h.push(A.indices.length);else{for(var N=[],E=0;E<A.positions.length/3;E++)N.push(E);A.indices=new Int32Array(N),h.push(A.indices.length)}l?l.merge(A):l=A;var w=r.scene.getMaterialByID(v.material);s.push(null===w?t.GLTFUtils.GetDefaultMaterial(r.scene):w),u.push(0===u.length?0:u[u.length-1]+c[c.length-2]),f.push(0===f.length?0:f[f.length-1]+h[h.length-2])}}var S;s.length>1?(S=new e.MultiMaterial("multimat"+a,r.scene),S.subMaterials=s):S=new e.StandardMaterial("multimat"+a,r.scene),1===s.length&&(S=s[0]),i.material||(i.material=S),new e.Geometry(a,r.scene,l,!1,i),i.computeWorldMatrix(!0),i.subMeshes=[];for(var F=0,p=0;p<o.length;p++){var _=o[p],m=r.meshes[_];if(m)for(var y=0;y<m.primitives.length;y++)m.primitives[y].mode,e.SubMesh.AddToMesh(F,u[F],c[F],f[F],h[F],i,i,!0),F++}return i},g=function(e,t,r,n){e.position&&(e.position=t),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=r),e.scaling&&(e.scaling=n)},L=function(t,r,n){if(r.matrix){var o=new e.Vector3(0,0,0),a=new e.Quaternion,i=new e.Vector3(0,0,0);e.Matrix.FromArray(r.matrix).decompose(i,a,o),g(t,o,a,i)}else r.translation&&r.rotation&&r.scale&&g(t,e.Vector3.FromArray(r.translation),e.Quaternion.FromArray(r.rotation),e.Vector3.FromArray(r.scale));t.computeWorldMatrix(!0)},E=function(t,r,n,o){var a=null;if(t.importOnlyMeshes&&(r.skin||r.meshes)&&t.importMeshesNames&&t.importMeshesNames.length>0&&-1===t.importMeshesNames.indexOf(r.name||""))return null;if(r.skin){if(r.meshes){var i=t.skins[r.skin],s=T(t,r,r.meshes,n,r.babylonNode);s.skeleton=t.scene.getLastSkeletonByID(r.skin),null===s.skeleton&&(s.skeleton=b(t,i,0,i.babylonSkeleton,r.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),a=s}}else if(r.meshes){var s=T(t,r,r.mesh?[r.mesh]:r.meshes,n,r.babylonNode);a=s}else if(!r.light||r.babylonNode||t.importOnlyMeshes){if(r.camera&&!r.babylonNode&&!t.importOnlyMeshes){var l=t.cameras[r.camera];if(l)if("orthographic"===l.type){var u=new e.FreeCamera(r.camera,e.Vector3.Zero(),t.scene,!1);u.name=r.name||"",u.mode=e.Camera.ORTHOGRAPHIC_CAMERA,u.attachControl(t.scene.getEngine().getRenderingCanvas()),a=u}else if("perspective"===l.type){var c=l[l.type],d=new e.FreeCamera(r.camera,e.Vector3.Zero(),t.scene,!1);d.name=r.name||"",d.attachControl(t.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(d.maxZ=c.zfar,d.minZ=c.znear),a=d}}}else{var f=t.lights[r.light];if(f)if("ambient"===f.type){var h=f[f.type],p=new e.HemisphericLight(r.light,e.Vector3.Zero(),t.scene);p.name=r.name||"",h.color&&(p.diffuse=e.Color3.FromArray(h.color)),a=p}else if("directional"===f.type){var _=f[f.type],m=new e.DirectionalLight(r.light,e.Vector3.Zero(),t.scene);m.name=r.name||"",_.color&&(m.diffuse=e.Color3.FromArray(_.color)),a=m}else if("point"===f.type){var y=f[f.type],A=new e.PointLight(r.light,e.Vector3.Zero(),t.scene);A.name=r.name||"",y.color&&(A.diffuse=e.Color3.FromArray(y.color)),a=A}else if("spot"===f.type){var v=f[f.type],E=new e.SpotLight(r.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);E.name=r.name||"",v.color&&(E.diffuse=e.Color3.FromArray(v.color)),v.fallOfAngle&&(E.angle=v.fallOfAngle),v.fallOffExponent&&(E.exponent=v.fallOffExponent),a=E}}if(!r.jointName){if(r.babylonNode)return r.babylonNode;if(null===a){var O=new e.Mesh(r.name||"",t.scene);r.babylonNode=O,a=O}}if(null!==a){if(r.matrix&&a instanceof e.Mesh)L(a,r);else{var x=r.translation||[0,0,0],M=r.rotation||[0,0,0,1],N=r.scale||[1,1,1];g(a,e.Vector3.FromArray(x),e.Quaternion.FromArray(M),e.Vector3.FromArray(N))}a.updateCache(!0),r.babylonNode=a}return a},O=function(e,t,r,n){void 0===n&&(n=!1);var o=e.nodes[t],a=null;if(n=!(e.importOnlyMeshes&&!n&&e.importMeshesNames)||(-1!==e.importMeshesNames.indexOf(o.name||"")||0===e.importMeshesNames.length),!o.jointName&&n&&null!==(a=E(e,o,t))&&(a.id=t,a.parent=r),o.children)for(var i=0;i<o.children.length;i++)O(e,o.children[i],a,n)},x=function(e){var t=e.currentScene;if(t)for(var r=0;r<t.nodes.length;r++)O(e,t.nodes[r],null);else for(var n in e.scenes){t=e.scenes[n];for(var r=0;r<t.nodes.length;r++)O(e,t.nodes[r],null)}h(e);for(var r=0;r<e.scene.skeletons.length;r++){var o=e.scene.skeletons[r];e.scene.beginAnimation(o,0,Number.MAX_VALUE,!0,1)}},M=function(e,r,n,o,a,i,s){var l=i.values||a.parameters;for(var u in n){var c=n[u],d=c.type;if(d===t.EParameterType.FLOAT_MAT2||d===t.EParameterType.FLOAT_MAT3||d===t.EParameterType.FLOAT_MAT4)if(!c.semantic||c.source||c.node){if(c.semantic&&(c.source||c.node)){var f=r.scene.getNodeByName(c.source||c.node||"");if(null===f&&(f=r.scene.getNodeByID(c.source||c.node||"")),null===f)continue;t.GLTFUtils.SetMatrix(r.scene,f,c,u,o.getEffect())}}else t.GLTFUtils.SetMatrix(r.scene,e,c,u,o.getEffect());else{var h=l[a.uniforms[u]];if(!h)continue;if(d===t.EParameterType.SAMPLER_2D){var p=r.textures[i.values?h:c.value].babylonTexture;if(null===p||void 0===p)continue;o.getEffect().setTexture(u,p)}else t.GLTFUtils.SetUniform(o.getEffect(),u,h,d)}}s(o)},N=function(e,r,n,o,a){var i=o.values||n.parameters,s=n.uniforms;for(var l in a){var u=a[l],c=u.type,d=i[s[l]];if(void 0===d&&(d=u.value),d){var f=function(e){return function(t){u.value&&e&&(r.setTexture(e,t),delete a[e])}};c===t.EParameterType.SAMPLER_2D?t.GLTFLoaderExtension.LoadTextureAsync(e,o.values?d:u.value,f(l),(function(){return f(null)})):u.value&&t.GLTFUtils.SetUniform(r,l,o.values?d:u.value,c)&&delete a[l]}}},w=function(e,t,r){return function(n,o){t.dispose(!0),r("Cannot compile program named "+e.name+". Error: "+o+". Default material will be applied")}},S=function(e,t,r,n,o,a){return function(i){N(e,t,r,n,o),t.onBind=function(i){M(i,e,o,t,r,n,a)}}},F=function(e,t,r){for(var n in t.uniforms){var i=t.uniforms[n],s=t.parameters[i];if(e.currentIdentifier===n&&s.semantic&&!s.source&&!s.node){var l=o.indexOf(s.semantic);if(-1!==l)return delete r[n],a[l]}}return e.currentIdentifier},B=function(e){for(var r in e.materials)t.GLTFLoaderExtension.LoadMaterialAsync(e,r,(function(e){}),(function(){}))},R=(function(){function i(){}return i.CreateRuntime=function(e,t,r){var n={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:t,rootUrl:r,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[]};return e.extensions&&c(e.extensions,"extensions",n),e.extensionsUsed&&c(e.extensionsUsed,"extensionsUsed",n),e.buffers&&l(e.buffers,n),e.bufferViews&&c(e.bufferViews,"bufferViews",n),e.accessors&&c(e.accessors,"accessors",n),e.meshes&&c(e.meshes,"meshes",n),e.lights&&c(e.lights,"lights",n),e.cameras&&c(e.cameras,"cameras",n),e.nodes&&c(e.nodes,"nodes",n),e.images&&c(e.images,"images",n),e.textures&&c(e.textures,"textures",n),e.shaders&&u(e.shaders,n),e.programs&&c(e.programs,"programs",n),e.samplers&&c(e.samplers,"samplers",n),e.techniques&&c(e.techniques,"techniques",n),e.materials&&c(e.materials,"materials",n),e.animations&&c(e.animations,"animations",n),e.skins&&c(e.skins,"skins",n),e.scenes&&(n.scenes=e.scenes),e.scene&&e.scenes&&(n.currentScene=e.scenes[e.scene]),n},i.LoadBufferAsync=function(t,r,n,o,a){var i=t.buffers[r];e.Tools.IsBase64(i.uri)?setTimeout((function(){return n(new Uint8Array(e.Tools.DecodeBase64(i.uri)))})):e.Tools.LoadFile(t.rootUrl+i.uri,(function(e){return n(new Uint8Array(e))}),a,void 0,!0,(function(e){e&&o(e.status+" "+e.statusText)}))},i.LoadTextureBufferAsync=function(t,r,n,o){var a=t.textures[r];if(!a||!a.source)return void o("");if(a.babylonTexture)return void n(null);var i=t.images[a.source];e.Tools.IsBase64(i.uri)?setTimeout((function(){return n(new Uint8Array(e.Tools.DecodeBase64(i.uri)))})):e.Tools.LoadFile(t.rootUrl+i.uri,(function(e){return n(new Uint8Array(e))}),void 0,void 0,!0,(function(e){e&&o(e.status+" "+e.statusText)}))},i.CreateTextureAsync=function(r,n,o,a,i){var s=r.textures[n];if(s.babylonTexture)return void a(s.babylonTexture);var l=r.samplers[s.sampler],u=l.minFilter===t.ETextureFilterType.NEAREST_MIPMAP_NEAREST||l.minFilter===t.ETextureFilterType.NEAREST_MIPMAP_LINEAR||l.minFilter===t.ETextureFilterType.LINEAR_MIPMAP_NEAREST||l.minFilter===t.ETextureFilterType.LINEAR_MIPMAP_LINEAR,c=e.Texture.BILINEAR_SAMPLINGMODE,d=new Blob([o]),f=URL.createObjectURL(d),h=function(){return URL.revokeObjectURL(f)},p=new e.Texture(f,r.scene,!u,!0,c,h,h);void 0!==l.wrapS&&(p.wrapU=t.GLTFUtils.GetWrapMode(l.wrapS)),void 0!==l.wrapT&&(p.wrapV=t.GLTFUtils.GetWrapMode(l.wrapT)),p.name=n,s.babylonTexture=p,a(p)},i.LoadShaderStringAsync=function(t,r,n,o){var a=t.shaders[r];if(e.Tools.IsBase64(a.uri)){var i=atob(a.uri.split(",")[1]);n&&n(i)}else e.Tools.LoadFile(t.rootUrl+a.uri,n,void 0,void 0,!1,(function(e){e&&o&&o(e.status+" "+e.statusText)}))},i.LoadMaterialAsync=function(i,s,l,u){var c=i.materials[s];if(!c.technique)return void(u&&u("No technique found."));var d=i.techniques[c.technique];if(!d){var h=new e.StandardMaterial(s,i.scene);return h.diffuseColor=new e.Color3(.5,.5,.5),h.sideOrientation=e.Material.CounterClockWiseSideOrientation,void l(h)}var p=i.programs[d.program],_=d.states,m=e.Effect.ShadersStore[p.vertexShader+"VertexShader"],y=e.Effect.ShadersStore[p.fragmentShader+"PixelShader"],A="",v="",b=new n(m),T=new n(y),g={},L=[],E=[],O=[];for(var x in d.uniforms){var M=d.uniforms[x],N=d.parameters[M];if(g[x]=N,!N.semantic||N.node||N.source)N.type===t.EParameterType.SAMPLER_2D?O.push(x):L.push(x);else{var B=o.indexOf(N.semantic);-1!==B?(L.push(a[B]),delete g[x]):L.push(x)}}for(var R in d.attributes){var P=d.attributes[R],I=d.parameters[P];I.semantic&&E.push(f(I))}for(;!b.isEnd()&&b.getNextToken();){var C=b.currentToken;if(C===r.IDENTIFIER){var G=!1;for(var R in d.attributes){var P=d.attributes[R],I=d.parameters[P];if(b.currentIdentifier===R&&I.semantic){A+=f(I),G=!0;break}}G||(A+=F(b,d,g))}else A+=b.currentString}for(;!T.isEnd()&&T.getNextToken();){var C=T.currentToken;C===r.IDENTIFIER?v+=F(T,d,g):v+=T.currentString}var V={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},D={attributes:E,uniforms:L,samplers:O,needAlphaBlending:_&&_.enable&&-1!==_.enable.indexOf(3042)};e.Effect.ShadersStore[p.vertexShader+s+"VertexShader"]=A,e.Effect.ShadersStore[p.fragmentShader+s+"PixelShader"]=v;var U=new e.ShaderMaterial(s,i.scene,V,D);if(U.onError=w(p,U,u),U.onCompiled=S(i,U,d,c,g,l),U.sideOrientation=e.Material.CounterClockWiseSideOrientation,_&&_.functions){var k=_.functions;k.cullFace&&k.cullFace[0]!==t.ECullingType.BACK&&(U.backFaceCulling=!1);var j=k.blendFuncSeparate;j&&(j[0]===t.EBlendingFunction.SRC_ALPHA&&j[1]===t.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&j[2]===t.EBlendingFunction.ONE&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_COMBINE:j[0]===t.EBlendingFunction.ONE&&j[1]===t.EBlendingFunction.ONE&&j[2]===t.EBlendingFunction.ZERO&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_ONEONE:j[0]===t.EBlendingFunction.SRC_ALPHA&&j[1]===t.EBlendingFunction.ONE&&j[2]===t.EBlendingFunction.ZERO&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_ADD:j[0]===t.EBlendingFunction.ZERO&&j[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&j[2]===t.EBlendingFunction.ONE&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_SUBTRACT:j[0]===t.EBlendingFunction.DST_COLOR&&j[1]===t.EBlendingFunction.ZERO&&j[2]===t.EBlendingFunction.ONE&&j[3]===t.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_MULTIPLY:j[0]===t.EBlendingFunction.SRC_ALPHA&&j[1]===t.EBlendingFunction.ONE_MINUS_SRC_COLOR&&j[2]===t.EBlendingFunction.ONE&&j[3]===t.EBlendingFunction.ONE&&(U.alphaMode=e.Engine.ALPHA_MAXIMIZED))}},i})();t.GLTFLoaderBase=R;var P=(function(){function r(){this.coordinateSystemMode=e.GLTFLoaderCoordinateSystemMode.AUTO,this.animationStartMode=e.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.transparencyAsCoverage=!1,this._normalizeAnimationGroupsToBeginAtZero=!0,this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCameraLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this.state=null}return r.RegisterExtension=function(t){if(r.Extensions[t.name])return void e.Tools.Error('Tool with the same name "'+t.name+'" already exists');r.Extensions[t.name]=t},r.prototype.dispose=function(){},r.prototype._importMeshAsync=function(r,n,o,a,i,s,l){var u=this;return n.useRightHandedSystem=!0,
  2. t.GLTFLoaderExtension.LoadRuntimeAsync(n,o,a,(function(t){t.importOnlyMeshes=!0,""===r?t.importMeshesNames=[]:"string"==typeof r?t.importMeshesNames=[r]:!r||r instanceof Array?(t.importMeshesNames=[],e.Tools.Warn("Argument meshesNames must be of type string or string[]")):t.importMeshesNames=[r],u._createNodes(t);var n=new Array,o=new Array;for(var a in t.nodes){var l=t.nodes[a];l.babylonNode instanceof e.AbstractMesh&&n.push(l.babylonNode)}for(var c in t.skins){var d=t.skins[c];d.babylonSkeleton instanceof e.Skeleton&&o.push(d.babylonSkeleton)}u._loadBuffersAsync(t,(function(){u._loadShadersAsync(t,(function(){B(t),x(t),!e.GLTFFileLoader.IncrementalLoading&&i&&i(n,o)}))}),s),e.GLTFFileLoader.IncrementalLoading&&i&&i(n,o)}),l),!0},r.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return new Promise(function(i,s){a._importMeshAsync(e,t,r,n,(function(e,t){i({meshes:e,particleSystems:[],skeletons:t,animationGroups:[]})}),o,(function(e){s(new Error(e))}))})},r.prototype._loadAsync=function(r,n,o,a,i,s){var l=this;r.useRightHandedSystem=!0,t.GLTFLoaderExtension.LoadRuntimeAsync(r,n,o,(function(r){t.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(r,(function(){l._createNodes(r),l._loadBuffersAsync(r,(function(){l._loadShadersAsync(r,(function(){B(r),x(r),e.GLTFFileLoader.IncrementalLoading||a()}))})),e.GLTFFileLoader.IncrementalLoading&&a()}),s)}),s)},r.prototype.loadAsync=function(e,t,r,n){var o=this;return new Promise(function(a,i){o._loadAsync(e,t,r,(function(){a()}),n,(function(e){i(new Error(e))}))})},r.prototype._loadShadersAsync=function(r,n){var o=!1,a=function(o,a){t.GLTFLoaderExtension.LoadShaderStringAsync(r,o,(function(i){i instanceof ArrayBuffer||(r.loadedShaderCount++,i&&(e.Effect.ShadersStore[o+(a.type===t.EShaderType.VERTEX?"VertexShader":"PixelShader")]=i),r.loadedShaderCount===r.shaderscount&&n())}),(function(){e.Tools.Error("Error when loading shader program named "+o+" located at "+a.uri)}))};for(var i in r.shaders){o=!0;var s=r.shaders[i];s?a.bind(this,i,s)():e.Tools.Error("No shader named: "+i)}o||n()},r.prototype._loadBuffersAsync=function(r,n,o){var a=!1,i=function(o,a){t.GLTFLoaderExtension.LoadBufferAsync(r,o,(function(t){r.loadedBufferCount++,t&&(t.byteLength!=r.buffers[o].byteLength&&e.Tools.Error("Buffer named "+o+" is length "+t.byteLength+". Expected: "+a.byteLength),r.loadedBufferViews[o]=t),r.loadedBufferCount===r.buffersCount&&n()}),(function(){e.Tools.Error("Error when loading buffer named "+o+" located at "+a.uri)}))};for(var s in r.buffers){a=!0;var l=r.buffers[s];l?i.bind(this,s,l)():e.Tools.Error("No buffer named: "+s)}a||n()},r.prototype._createNodes=function(e){var t=e.currentScene;if(t)for(var r=0;r<t.nodes.length;r++)O(e,t.nodes[r],null);else for(var n in e.scenes){t=e.scenes[n];for(var r=0;r<t.nodes.length;r++)O(e,t.nodes[r],null)}},r.Extensions={},r})();t.GLTFLoader=P,e.GLTFFileLoader.CreateGLTFLoaderV1=function(){return new P}})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(){}return r.SetMatrix=function(r,n,o,a,i){var s=null;if("MODEL"===o.semantic?s=n.getWorldMatrix():"PROJECTION"===o.semantic?s=r.getProjectionMatrix():"VIEW"===o.semantic?s=r.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===o.semantic?s=e.Matrix.Transpose(n.getWorldMatrix().multiply(r.getViewMatrix()).invert()):"MODELVIEW"===o.semantic?s=n.getWorldMatrix().multiply(r.getViewMatrix()):"MODELVIEWPROJECTION"===o.semantic?s=n.getWorldMatrix().multiply(r.getTransformMatrix()):"MODELINVERSE"===o.semantic?s=n.getWorldMatrix().invert():"VIEWINVERSE"===o.semantic?s=r.getViewMatrix().invert():"PROJECTIONINVERSE"===o.semantic?s=r.getProjectionMatrix().invert():"MODELVIEWINVERSE"===o.semantic?s=n.getWorldMatrix().multiply(r.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===o.semantic?s=n.getWorldMatrix().multiply(r.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===o.semantic&&(s=e.Matrix.Transpose(n.getWorldMatrix().invert())),s)switch(o.type){case t.EParameterType.FLOAT_MAT2:i.setMatrix2x2(a,e.Matrix.GetAsMatrix2x2(s));break;case t.EParameterType.FLOAT_MAT3:i.setMatrix3x3(a,e.Matrix.GetAsMatrix3x3(s));break;case t.EParameterType.FLOAT_MAT4:i.setMatrix(a,s)}},r.SetUniform=function(r,n,o,a){switch(a){case t.EParameterType.FLOAT:return r.setFloat(n,o),!0;case t.EParameterType.FLOAT_VEC2:return r.setVector2(n,e.Vector2.FromArray(o)),!0;case t.EParameterType.FLOAT_VEC3:return r.setVector3(n,e.Vector3.FromArray(o)),!0;case t.EParameterType.FLOAT_VEC4:return r.setVector4(n,e.Vector4.FromArray(o)),!0;default:return!1}},r.GetWrapMode=function(r){switch(r){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:default:return e.Texture.WRAP_ADDRESSMODE}},r.GetByteStrideFromType=function(e){switch(e.type){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 1}},r.GetTextureFilterMode=function(r){switch(r){case t.ETextureFilterType.LINEAR:case t.ETextureFilterType.LINEAR_MIPMAP_NEAREST:case t.ETextureFilterType.LINEAR_MIPMAP_LINEAR:return e.Texture.TRILINEAR_SAMPLINGMODE;case t.ETextureFilterType.NEAREST:case t.ETextureFilterType.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_SAMPLINGMODE;default:return e.Texture.BILINEAR_SAMPLINGMODE}},r.GetBufferFromBufferView=function(e,r,n,o,a){var n=r.byteOffset+n,i=e.loadedBufferViews[r.buffer];if(n+o>i.byteLength)throw new Error("Buffer access is out of range");var s=i.buffer;switch(n+=i.byteOffset,a){case t.EComponentType.BYTE:return new Int8Array(s,n,o);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,n,o);case t.EComponentType.SHORT:return new Int16Array(s,n,o);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,n,o);default:return new Float32Array(s,n,o)}},r.GetBufferFromAccessor=function(e,t){var n=e.bufferViews[t.bufferView],o=t.count*r.GetByteStrideFromType(t);return r.GetBufferFromBufferView(e,n,t.byteOffset,o,t.componentType)},r.DecodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;++n)t+=String.fromCharCode(e[n]);return t},r.GetDefaultMaterial=function(t){if(!r._DefaultMaterial){e.Effect.ShadersStore.GLTFDefaultMaterialVertexShader=["precision highp float;","","uniform mat4 worldView;","uniform mat4 projection;","","attribute vec3 position;","","void main(void)","{"," gl_Position = projection * worldView * vec4(position, 1.0);","}"].join("\n"),e.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");var n={vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},o={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};r._DefaultMaterial=new e.ShaderMaterial("GLTFDefaultMaterial",t,n,o),r._DefaultMaterial.setColor4("u_emission",new e.Color4(.5,.5,.5,1))}return r._DefaultMaterial},r._DefaultMaterial=null,r})();t.GLTFUtils=r})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function t(e){this._name=e}return Object.defineProperty(t.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),t.prototype.loadRuntimeAsync=function(e,t,r,n,o){return!1},t.prototype.loadRuntimeExtensionsAsync=function(e,t,r){return!1},t.prototype.loadBufferAsync=function(e,t,r,n,o){return!1},t.prototype.loadTextureBufferAsync=function(e,t,r,n){return!1},t.prototype.createTextureAsync=function(e,t,r,n,o){return!1},t.prototype.loadShaderStringAsync=function(e,t,r,n){return!1},t.prototype.loadMaterialAsync=function(e,t,r,n){return!1},t.LoadRuntimeAsync=function(r,n,o,a,i){t.ApplyExtensions((function(e){return e.loadRuntimeAsync(r,n,o,a,i)}),(function(){setTimeout((function(){a&&a(e.GLTFLoaderBase.CreateRuntime(n.json,r,o))}))}))},t.LoadRuntimeExtensionsAsync=function(e,r,n){t.ApplyExtensions((function(t){return t.loadRuntimeExtensionsAsync(e,r,n)}),(function(){setTimeout((function(){r()}))}))},t.LoadBufferAsync=function(r,n,o,a,i){t.ApplyExtensions((function(e){return e.loadBufferAsync(r,n,o,a,i)}),(function(){e.GLTFLoaderBase.LoadBufferAsync(r,n,o,a,i)}))},t.LoadTextureAsync=function(e,r,n,o){t.LoadTextureBufferAsync(e,r,(function(a){a&&t.CreateTextureAsync(e,r,a,n,o)}),o)},t.LoadShaderStringAsync=function(r,n,o,a){t.ApplyExtensions((function(e){return e.loadShaderStringAsync(r,n,o,a)}),(function(){e.GLTFLoaderBase.LoadShaderStringAsync(r,n,o,a)}))},t.LoadMaterialAsync=function(r,n,o,a){t.ApplyExtensions((function(e){return e.loadMaterialAsync(r,n,o,a)}),(function(){e.GLTFLoaderBase.LoadMaterialAsync(r,n,o,a)}))},t.LoadTextureBufferAsync=function(r,n,o,a){t.ApplyExtensions((function(e){return e.loadTextureBufferAsync(r,n,o,a)}),(function(){e.GLTFLoaderBase.LoadTextureBufferAsync(r,n,o,a)}))},t.CreateTextureAsync=function(r,n,o,a,i){t.ApplyExtensions((function(e){return e.createTextureAsync(r,n,o,a,i)}),(function(){e.GLTFLoaderBase.CreateTextureAsync(r,n,o,a,i)}))},t.ApplyExtensions=function(t,r){for(var n in e.GLTFLoader.Extensions){if(t(e.GLTFLoader.Extensions[n]))return}r()},t})();e.GLTFLoaderExtension=t})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(e){var t=(function(t){function r(){return t.call(this,"KHR_binary_glTF")||this}return __extends(r,t),r.prototype.loadRuntimeAsync=function(t,r,n,o,a){var i=r.json.extensionsUsed;return!(!i||-1===i.indexOf(this.name)||!r.bin)&&(this._bin=r.bin,o(e.GLTFLoaderBase.CreateRuntime(r.json,t,n)),!0)},r.prototype.loadBufferAsync=function(e,t,r,n){return-1!==e.extensionsUsed.indexOf(this.name)&&("binary_glTF"===t&&(r(this._bin),!0))},r.prototype.loadTextureBufferAsync=function(t,r,n,o){var a=t.textures[r],i=t.images[a.source];if(!(i.extensions&&this.name in i.extensions))return!1;var s=i.extensions[this.name],l=t.bufferViews[s.bufferView];return n(e.GLTFUtils.GetBufferFromBufferView(t,l,0,l.byteLength,e.EComponentType.UNSIGNED_BYTE)),!0},r.prototype.loadShaderStringAsync=function(t,r,n,o){var a=t.shaders[r];if(!(a.extensions&&this.name in a.extensions))return!1;var i=a.extensions[this.name],s=t.bufferViews[i.bufferView],l=e.GLTFUtils.GetBufferFromBufferView(t,s,0,s.byteLength,e.EComponentType.UNSIGNED_BYTE);return setTimeout((function(){var t=e.GLTFUtils.DecodeBufferToText(l);n(t)})),!0},r})(e.GLTFLoaderExtension);e.GLTFBinaryExtension=t,e.GLTFLoader.RegisterExtension(new t)})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(t){var r=(function(r){function n(){return r.call(this,"KHR_materials_common")||this}return __extends(n,r),n.prototype.loadRuntimeExtensionsAsync=function(t,r,n){if(!t.extensions)return!1;var o=t.extensions[this.name];if(!o)return!1;var a=o.lights;if(a)for(var i in a){var s=a[i];switch(s.type){case"ambient":var l=new e.HemisphericLight(s.name,new e.Vector3(0,1,0),t.scene),u=s.ambient;u&&(l.diffuse=e.Color3.FromArray(u.color||[1,1,1]));break;case"point":var c=new e.PointLight(s.name,new e.Vector3(10,10,10),t.scene),d=s.point;d&&(c.diffuse=e.Color3.FromArray(d.color||[1,1,1]));break;case"directional":var f=new e.DirectionalLight(s.name,new e.Vector3(0,-1,0),t.scene),h=s.directional;h&&(f.diffuse=e.Color3.FromArray(h.color||[1,1,1]));break;case"spot":var p=s.spot;if(p){var _=new e.SpotLight(s.name,new e.Vector3(0,10,0),new e.Vector3(0,-1,0),p.fallOffAngle||Math.PI,p.fallOffExponent||0,t.scene);_.diffuse=e.Color3.FromArray(p.color||[1,1,1])}break;default:e.Tools.Warn('GLTF Material Common extension: light type "'+s.type+"” not supported")}}return!1},n.prototype.loadMaterialAsync=function(t,r,n,o){var a=t.materials[r];if(!a||!a.extensions)return!1;var i=a.extensions[this.name];if(!i)return!1;var s=new e.StandardMaterial(r,t.scene);return s.sideOrientation=e.Material.CounterClockWiseSideOrientation,"CONSTANT"===i.technique&&(s.disableLighting=!0),s.backFaceCulling=void 0!==i.doubleSided&&!i.doubleSided,s.alpha=void 0===i.values.transparency?1:i.values.transparency,s.specularPower=void 0===i.values.shininess?0:i.values.shininess,"string"==typeof i.values.ambient?this._loadTexture(t,i.values.ambient,s,"ambientTexture",o):s.ambientColor=e.Color3.FromArray(i.values.ambient||[0,0,0]),"string"==typeof i.values.diffuse?this._loadTexture(t,i.values.diffuse,s,"diffuseTexture",o):s.diffuseColor=e.Color3.FromArray(i.values.diffuse||[0,0,0]),"string"==typeof i.values.emission?this._loadTexture(t,i.values.emission,s,"emissiveTexture",o):s.emissiveColor=e.Color3.FromArray(i.values.emission||[0,0,0]),"string"==typeof i.values.specular?this._loadTexture(t,i.values.specular,s,"specularTexture",o):s.specularColor=e.Color3.FromArray(i.values.specular||[0,0,0]),!0},n.prototype._loadTexture=function(e,r,n,o,a){t.GLTFLoaderBase.LoadTextureBufferAsync(e,r,(function(i){t.GLTFLoaderBase.CreateTextureAsync(e,r,i,(function(e){return n[o]=e}),a)}),a)},n})(t.GLTFLoaderExtension);t.GLTFMaterialsCommonExtension=r,t.GLTFLoader.RegisterExtension(new r)})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(){}return e.Assign=function(e){if(e)for(var t=0;t<e.length;t++)e[t]._index=t},e})();e._ArrayItem=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(){this._completePromises=new Array,this._disposed=!1,this._state=null,this._extensions={},this._defaultSampler={},this._defaultBabylonMaterials={},this._requests=new Array,this.coordinateSystemMode=e.GLTFLoaderCoordinateSystemMode.AUTO,this.animationStartMode=e.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.transparencyAsCoverage=!1,this._normalizeAnimationGroupsToBeginAtZero=!0,this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCameraLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable}return r._Register=function(t,n){if(r._ExtensionFactories[t])return void e.Tools.Error("Extension with the name '"+t+"' already exists");r._ExtensionFactories[t]=n,r._ExtensionNames.push(t)},Object.defineProperty(r.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),r.prototype.dispose=function(){this._disposed||(this._disposed=!0,this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this._clear())},r.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=null;if(e){var s={};if(a._gltf.nodes)for(var l=0,u=a._gltf.nodes;l<u.length;l++){var c=u[l];c.name&&(s[c.name]=c)}i=(e instanceof Array?e:[e]).map((function(e){var t=s[e];if(!t)throw new Error("Failed to find node '"+e+"'");return t}))}return a._loadAsync(i,t,r,n,o).then((function(){return{meshes:a._getMeshes(),particleSystems:[],skeletons:a._getSkeletons(),animationGroups:a._getAnimationGroups()}}))}))},r.prototype.loadAsync=function(e,t,r,n){return this._loadAsync(null,e,t,r,n)},r.prototype._loadAsync=function(t,n,o,a,i){var s=this;return Promise.resolve().then((function(){s._babylonScene=n,s._rootUrl=a,s._progressCallback=i,s._state=e.GLTFLoaderState.LOADING,s._loadData(o),s._loadExtensions(),s._checkExtensions();var l=new Array;if(t)l.push(s._loadNodesAsync(t));else{var u=r._GetProperty("#/scene",s._gltf.scenes,s._gltf.scene||0);l.push(s._loadSceneAsync("#/scenes/"+u._index,u))}s.compileMaterials&&l.push(s._compileMaterialsAsync()),s.compileShadowGenerators&&l.push(s._compileShadowGeneratorsAsync());var c=Promise.all(l).then((function(){s._state=e.GLTFLoaderState.READY,s._startAnimations()}));return c.then((function(){s._rootBabylonMesh.setEnabled(!0),e.Tools.SetImmediate((function(){s._disposed||Promise.all(s._completePromises).then((function(){s._state=e.GLTFLoaderState.COMPLETE,s.onCompleteObservable.notifyObservers(s),s.onCompleteObservable.clear(),s._clear()})).catch((function(t){e.Tools.Error("glTF Loader: "+t.message),s._clear()}))}))})),c})).catch((function(t){if(!s._disposed)throw e.Tools.Error("glTF Loader: "+t.message),s._clear(),t}))},r.prototype._loadData=function(t){if(this._gltf=t.json,this._setupData(),t.bin){var r=this._gltf.buffers;if(r&&r[0]&&!r[0].uri){var n=r[0];(n.byteLength<t.bin.byteLength-3||n.byteLength>t.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),n._data=Promise.resolve(t.bin)}else e.Tools.Warn("Unexpected BIN chunk")}},r.prototype._setupData=function(){if(t._ArrayItem.Assign(this._gltf.accessors),t._ArrayItem.Assign(this._gltf.animations),t._ArrayItem.Assign(this._gltf.buffers),t._ArrayItem.Assign(this._gltf.bufferViews),t._ArrayItem.Assign(this._gltf.cameras),t._ArrayItem.Assign(this._gltf.images),t._ArrayItem.Assign(this._gltf.materials),t._ArrayItem.Assign(this._gltf.meshes),t._ArrayItem.Assign(this._gltf.nodes),t._ArrayItem.Assign(this._gltf.samplers),t._ArrayItem.Assign(this._gltf.scenes),t._ArrayItem.Assign(this._gltf.skins),t._ArrayItem.Assign(this._gltf.textures),this._gltf.nodes){for(var e={},r=0,n=this._gltf.nodes;r<n.length;r++){var o=n[r];if(o.children)for(var a=0,i=o.children;a<i.length;a++){var s=i[a];e[s]=o._index}}for(var l=this._createRootNode(),u=0,c=this._gltf.nodes;u<c.length;u++){var o=c[u],d=e[o._index];o._parent=void 0===d?l:this._gltf.nodes[d]}}},r.prototype._loadExtensions=function(){for(var e=0,t=r._ExtensionNames;e<t.length;e++){var n=t[e],o=r._ExtensionFactories[n](this);this._extensions[n]=o,this.onExtensionLoadedObservable.notifyObservers(o)}this.onExtensionLoadedObservable.clear()},r.prototype._checkExtensions=function(){if(this._gltf.extensionsRequired)for(var e=0,t=this._gltf.extensionsRequired;e<t.length;e++){var r=t[e],n=this._extensions[r];if(!n||!n.enabled)throw new Error("Require extension "+r+" is not available")}},r.prototype._createRootNode=function(){this._rootBabylonMesh=new e.Mesh("__root__",this._babylonScene),this._rootBabylonMesh.setEnabled(!1);var t={_babylonMesh:this._rootBabylonMesh};switch(this.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(t.rotation=[0,1,0,0],t.scale=[1,1,-1],r._LoadTransform(t,this._rootBabylonMesh));break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:throw new Error("Invalid coordinate system mode ("+this.coordinateSystemMode+")")}return this.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh),t},r.prototype._loadNodesAsync=function(e){for(var t=new Array,r=0,n=e;r<n.length;r++){var o=n[r];t.push(this._loadNodeAsync("#/nodes/"+o._index,o))}return t.push(this._loadAnimationsAsync()),Promise.all(t).then((function(){}))},r.prototype._loadSceneAsync=function(e,n){var o=t.GLTFLoaderExtension._LoadSceneAsync(this,e,n);if(o)return o;for(var a=new Array,i=0,s=n.nodes;i<s.length;i++){var l=s[i],u=r._GetProperty(e+"/nodes/"+l,this._gltf.nodes,l);a.push(this._loadNodeAsync("#/nodes/"+u._index,u))}return a.push(this._loadAnimationsAsync()),Promise.all(a).then((function(){}))},r.prototype._forEachPrimitive=function(e,t){if(e._primitiveBabylonMeshes)for(var r=0,n=e._primitiveBabylonMeshes;r<n.length;r++){var o=n[r];t(o)}else t(e._babylonMesh)},r.prototype._getMeshes=function(){var e=new Array;e.push(this._rootBabylonMesh);var t=this._gltf.nodes;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];if(o._babylonMesh&&e.push(o._babylonMesh),o._primitiveBabylonMeshes)for(var a=0,i=o._primitiveBabylonMeshes;a<i.length;a++){var s=i[a];e.push(s)}}return e},r.prototype._getSkeletons=function(){var e=new Array,t=this._gltf.skins;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];o._babylonSkeleton&&e.push(o._babylonSkeleton)}return e},r.prototype._getAnimationGroups=function(){var e=new Array,t=this._gltf.animations;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];o._babylonAnimationGroup&&e.push(o._babylonAnimationGroup)}return e},r.prototype._startAnimations=function(){switch(this.animationStartMode){case e.GLTFLoaderAnimationStartMode.NONE:break;case e.GLTFLoaderAnimationStartMode.FIRST:var t=this._getAnimationGroups();0!==t.length&&t[0].start(!0);break;case e.GLTFLoaderAnimationStartMode.ALL:for(var t=this._getAnimationGroups(),r=0,n=t;r<n.length;r++){n[r].start(!0)}break;default:return void e.Tools.Error("Invalid animation start mode ("+this.animationStartMode+")")}},r.prototype._loadNodeAsync=function(n,o){var a=t.GLTFLoaderExtension._LoadNodeAsync(this,n,o);if(a)return a;if(o._babylonMesh)throw new Error(n+": Invalid recursive node hierarchy");var i=new Array,s=new e.Mesh(o.name||"node"+o._index,this._babylonScene,o._parent._babylonMesh);if(o._babylonMesh=s,r._LoadTransform(o,s),void 0!=o.mesh){var l=r._GetProperty(n+"/mesh",this._gltf.meshes,o.mesh);i.push(this._loadMeshAsync("#/meshes/"+l._index,o,l,s))}if(void 0!=o.camera){var u=r._GetProperty(n+"/camera",this._gltf.cameras,o.camera);this._loadCamera("#/cameras/"+u._index,u,s)}if(o.children)for(var c=0,d=o.children;c<d.length;c++){var f=d[c],h=r._GetProperty(n+"/children/"+f,this._gltf.nodes,f);i.push(this._loadNodeAsync("#/nodes/"+f,h))}return this.onMeshLoadedObservable.notifyObservers(s),Promise.all(i).then((function(){}))},r.prototype._loadMeshAsync=function(n,o,a,i){var s=this,l=new Array,u=a.primitives;if(!u||0===u.length)throw new Error(n+": Primitives are missing");if(t._ArrayItem.Assign(u),1===u.length){var c=u[0];l.push(this._loadPrimitiveAsync(n+"/primitives/"+c._index,o,a,c,i))}else{o._primitiveBabylonMeshes=[];for(var d=0,f=u;d<f.length;d++){var c=f[d],h=new e.Mesh((a.name||i.name)+"_"+c._index,this._babylonScene,i);o._primitiveBabylonMeshes.push(h),l.push(this._loadPrimitiveAsync(n+"/primitives/"+c._index,o,a,c,h)),this.onMeshLoadedObservable.notifyObservers(i)}}if(void 0!=o.skin){var p=r._GetProperty(n+"/skin",this._gltf.skins,o.skin);l.push(this._loadSkinAsync("#/skins/"+p._index,o,a,p))}return Promise.all(l).then((function(){s._forEachPrimitive(o,(function(e){e._refreshBoundingInfo(!0)}))}))},r.prototype._loadPrimitiveAsync=function(e,t,n,o,a){var i=this,s=new Array;this._createMorphTargets(e,t,n,o,a),s.push(this._loadVertexDataAsync(e,o,a).then((function(t){return i._loadMorphTargetsAsync(e,o,a,t).then((function(){t.applyToMesh(a)}))})));var l=r._GetDrawMode(e,o.mode);if(void 0==o.material)a.material=this._getDefaultMaterial(l);else{var u=r._GetProperty(e+"/material}",this._gltf.materials,o.material);s.push(this._loadMaterialAsync("#/materials/"+u._index,u,a,l,(function(e){a.material=e})))}return Promise.all(s).then((function(){}))},r.prototype._loadVertexDataAsync=function(n,o,a){var i=this,s=t.GLTFLoaderExtension._LoadVertexDataAsync(this,n,o,a);if(s)return s;var l=o.attributes;if(!l)throw new Error(n+": Attributes are missing");var u=new Array,c=new e.Geometry(a.name,this._babylonScene);if(void 0==o.indices)a.isUnIndexed=!0;else{var d=r._GetProperty(n+"/indices",this._gltf.accessors,o.indices);u.push(this._loadIndicesAccessorAsync("#/accessors/"+d._index,d).then((function(e){c.setIndices(e)})))}var f=function(e,t,o){if(void 0!=l[e]){a._delayInfo=a._delayInfo||[],-1===a._delayInfo.indexOf(t)&&a._delayInfo.push(t);var s=r._GetProperty(n+"/attributes/"+e,i._gltf.accessors,l[e]);u.push(i._loadVertexAccessorAsync("#/accessors/"+s._index,s,t).then((function(e){c.setVerticesBuffer(e,s.count)}))),o&&o(s)}};return f("POSITION",e.VertexBuffer.PositionKind),f("NORMAL",e.VertexBuffer.NormalKind),f("TANGENT",e.VertexBuffer.TangentKind),f("TEXCOORD_0",e.VertexBuffer.UVKind),f("TEXCOORD_1",e.VertexBuffer.UV2Kind),f("JOINTS_0",e.VertexBuffer.MatricesIndicesKind),f("WEIGHTS_0",e.VertexBuffer.MatricesWeightsKind),f("COLOR_0",e.VertexBuffer.ColorKind,(function(e){"VEC4"===e.type&&(a.hasVertexAlpha=!0)})),Promise.all(u).then((function(){return c}))},r.prototype._createMorphTargets=function(t,r,n,o,a){if(o.targets){if(void 0==r._numMorphTargets)r._numMorphTargets=o.targets.length;else if(o.targets.length!==r._numMorphTargets)throw new Error(t+": Primitives do not have the same number of targets");a.morphTargetManager=new e.MorphTargetManager;for(var i=0;i<o.targets.length;i++){var s=r.weights?r.weights[i]:n.weights?n.weights[i]:0;a.morphTargetManager.addTarget(new e.MorphTarget("morphTarget"+i,s))}}},r.prototype._loadMorphTargetsAsync=function(e,t,r,n){if(!t.targets)return Promise.resolve();for(var o=new Array,a=r.morphTargetManager,i=0;i<a.numTargets;i++){var s=a.getTarget(i);o.push(this._loadMorphTargetVertexDataAsync(e+"/targets/"+i,n,t.targets[i],s))}return Promise.all(o).then((function(){}))},r.prototype._loadMorphTargetVertexDataAsync=function(t,n,o,a){var i=this,s=new Array,l=function(e,a,l){if(void 0!=o[e]){var u=n.getVertexBuffer(a);if(u){var c=r._GetProperty(t+"/"+e,i._gltf.accessors,o[e]);s.push(i._loadFloatAccessorAsync("#/accessors/"+c._index,c).then((function(e){l(u,e)})))}}};return l("POSITION",e.VertexBuffer.PositionKind,(function(e,t){e.forEach(t.length,(function(e,r){t[r]+=e})),a.setPositions(t)})),l("NORMAL",e.VertexBuffer.NormalKind,(function(e,t){e.forEach(t.length,(function(e,r){t[r]+=e})),a.setNormals(t)})),l("TANGENT",e.VertexBuffer.TangentKind,(function(e,t){var r=0;e.forEach(t.length/3*4,(function(e,n){(n+1)%4!=0&&(t[r++]+=e)})),a.setTangents(t)})),Promise.all(s).then((function(){}))},r._LoadTransform=function(t,r){var n=e.Vector3.Zero(),o=e.Quaternion.Identity(),a=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(a,o,n)}else t.translation&&(n=e.Vector3.FromArray(t.translation)),t.rotation&&(o=e.Quaternion.FromArray(t.rotation)),t.scale&&(a=e.Vector3.FromArray(t.scale));r.position=n,r.rotationQuaternion=o,r.scaling=a},r.prototype._loadSkinAsync=function(t,r,n,o){var a=this,i=function(t){a._forEachPrimitive(r,(function(e){e.skeleton=t})),r._babylonMesh.parent=a._rootBabylonMesh,r._babylonMesh.position=e.Vector3.Zero(),r._babylonMesh.rotationQuaternion=e.Quaternion.Identity(),r._babylonMesh.scaling=e.Vector3.One()};if(o._loaded)return o._loaded.then((function(){i(o._babylonSkeleton)}));var s="skeleton"+o._index,l=new e.Skeleton(o.name||s,s,this._babylonScene);return o._babylonSkeleton=l,this._loadBones(t,o),i(l),o._loaded=this._loadSkinInverseBindMatricesDataAsync(t,o).then((function(e){a._updateBoneMatrices(l,e)}))},r.prototype._loadBones=function(e,t){for(var n={},o=0,a=t.joints;o<a.length;o++){var i=a[o],s=r._GetProperty(e+"/joints/"+i,this._gltf.nodes,i);this._loadBone(s,t,n)}},r.prototype._loadBone=function(t,r,n){var o=n[t._index];if(o)return o;var a=null;t._parent._babylonMesh!==this._rootBabylonMesh&&(a=this._loadBone(t._parent,r,n));var i=r.joints.indexOf(t._index);return o=new e.Bone(t.name||"joint"+t._index,r._babylonSkeleton,a,this._getNodeMatrix(t),null,null,i),n[t._index]=o,t._babylonBones=t._babylonBones||[],t._babylonBones.push(o),o},r.prototype._loadSkinInverseBindMatricesDataAsync=function(e,t){if(void 0==t.inverseBindMatrices)return Promise.resolve(null);var n=r._GetProperty(e+"/inverseBindMatrices",this._gltf.accessors,t.inverseBindMatrices);return this._loadFloatAccessorAsync("#/accessors/"+n._index,n)},r.prototype._updateBoneMatrices=function(t,r){for(var n=0,o=t.bones;n<o.length;n++){var a=o[n],i=e.Matrix.Identity(),s=a._index;r&&-1!==s&&(e.Matrix.FromArrayToRef(r,16*s,i),i.invertToRef(i));var l=a.getParent();l&&i.multiplyToRef(l.getInvertedAbsoluteTransform(),i),a.updateMatrix(i,!1,!1),a._updateDifferenceMatrix(void 0,!1)}},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._loadCamera=function(t,r,n){var o=new e.FreeCamera(r.name||"camera"+r._index,e.Vector3.Zero(),this._babylonScene,!1);switch(o.parent=n,o.rotation=new e.Vector3(0,Math.PI,0),r.type){case"perspective":var a=r.perspective;if(!a)throw new Error(t+": Camera perspective properties are missing");o.fov=a.yfov,o.minZ=a.znear,o.maxZ=a.zfar||Number.MAX_VALUE;break;case"orthographic":if(!r.orthographic)throw new Error(t+": Camera orthographic properties are missing");o.mode=e.Camera.ORTHOGRAPHIC_CAMERA,o.orthoLeft=-r.orthographic.xmag,o.orthoRight=r.orthographic.xmag,o.orthoBottom=-r.orthographic.ymag,o.orthoTop=r.orthographic.ymag,o.minZ=r.orthographic.znear,o.maxZ=r.orthographic.zfar;break;default:throw new Error(t+": Invalid camera type ("+r.type+")")}this.onCameraLoadedObservable.notifyObservers(o)},r.prototype._loadAnimationsAsync=function(){var e=this._gltf.animations;if(!e)return Promise.resolve();for(var t=new Array,r=0;r<e.length;r++){var n=e[r];t.push(this._loadAnimationAsync("#/animations/"+r,n))}return Promise.all(t).then((function(){}))},r.prototype._loadAnimationAsync=function(r,n){var o=this,a=new e.AnimationGroup(n.name||"animation"+n._index,this._babylonScene);n._babylonAnimationGroup=a;var i=new Array;t._ArrayItem.Assign(n.channels),t._ArrayItem.Assign(n.samplers);for(var s=0,l=n.channels;s<l.length;s++){var u=l[s];i.push(this._loadAnimationChannelAsync(r+"/channels/"+u._index,r,n,u,a))}return Promise.all(i).then((function(){a.normalize(o._normalizeAnimationGroupsToBeginAtZero?0:null)}))},r.prototype._loadAnimationChannelAsync=function(t,n,o,a,i){var s=this,l=r._GetProperty(t+"/target/node",this._gltf.nodes,a.target.node);if("weights"===a.target.path&&!l._numMorphTargets||"weights"!==a.target.path&&!l._babylonMesh)return Promise.resolve();if(void 0!=l.skin&&"weights"!==a.target.path)return Promise.resolve();var u=r._GetProperty(t+"/sampler",o.samplers,a.sampler);return this._loadAnimationSamplerAsync(n+"/samplers/"+a.sampler,u).then((function(r){var n,o;switch(a.target.path){case"translation":n="position",o=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":n="rotationQuaternion",o=e.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":n="scaling",o=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":n="influence",o=e.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(t+": Invalid target path ("+a.target.path+")")}var u,c=0;switch(n){case"position":u=function(){var t=e.Vector3.FromArray(r.output,c);return c+=3,t};break;case"rotationQuaternion":u=function(){var t=e.Quaternion.FromArray(r.output,c);return c+=4,t};break;case"scaling":u=function(){var t=e.Vector3.FromArray(r.output,c);return c+=3,t};break;case"influence":u=function(){for(var e=new Array(l._numMorphTargets),t=0;t<l._numMorphTargets;t++)e[t]=r.output[c++];return e}}var d;switch(r.interpolation){case"STEP":d=function(t){return{frame:r.input[t],value:u(),interpolation:e.AnimationKeyInterpolation.STEP}};break;case"LINEAR":d=function(e){return{frame:r.input[e],value:u()}};break;case"CUBICSPLINE":d=function(e){return{frame:r.input[e],inTangent:u(),value:u(),outTangent:u()}}}for(var f=new Array(r.input.length),h=0;h<r.input.length;h++)f[h]=d(h);if("influence"===n)for(var p=0;p<l._numMorphTargets;p++)!(function(t){var r=i.name+"_channel"+i.targetedAnimations.length,a=new e.Animation(r,n,1,o);a.setKeys(f.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}
  3. }))),s._forEachPrimitive(l,(function(e){var r=e.morphTargetManager.getTarget(t),n=a.clone();r.animations.push(n),i.addTargetedAnimation(n,r)}))})(p);else{var _=i.name+"_channel"+i.targetedAnimations.length,m=new e.Animation(_,n,1,o);if(m.setKeys(f),l._babylonBones){for(var y=[l._babylonMesh].concat(l._babylonBones),A=0,v=y;A<v.length;A++){v[A].animations.push(m)}i.addTargetedAnimation(m,y)}else l._babylonMesh.animations.push(m),i.addTargetedAnimation(m,l._babylonMesh)}}))},r.prototype._loadAnimationSamplerAsync=function(e,t){if(t._data)return t._data;var n=t.interpolation||"LINEAR";switch(n){case"STEP":case"LINEAR":case"CUBICSPLINE":break;default:throw new Error(e+": Invalid interpolation ("+t.interpolation+")")}var o=r._GetProperty(e+"/input",this._gltf.accessors,t.input),a=r._GetProperty(e+"/output",this._gltf.accessors,t.output);return t._data=Promise.all([this._loadFloatAccessorAsync("#/accessors/"+o._index,o),this._loadFloatAccessorAsync("#/accessors/"+a._index,a)]).then((function(e){var t=e[0],r=e[1];return{input:t,interpolation:n,output:r}})),t._data},r.prototype._loadBufferAsync=function(e,t){if(t._data)return t._data;if(!t.uri)throw new Error(e+": Uri is missing");return t._data=this._loadUriAsync(e,t.uri),t._data},r.prototype._loadBufferViewAsync=function(e,t){if(t._data)return t._data;var n=r._GetProperty(e+"/buffer",this._gltf.buffers,t.buffer);return t._data=this._loadBufferAsync("#/buffers/"+n._index,n).then((function(r){try{return new Uint8Array(r.buffer,r.byteOffset+(t.byteOffset||0),t.byteLength)}catch(t){throw new Error(e+": "+t.message)}})),t._data},r.prototype._loadIndicesAccessorAsync=function(e,t){if("SCALAR"!==t.type)throw new Error(e+": Invalid type "+t.type);if(5121!==t.componentType&&5123!==t.componentType&&5125!==t.componentType)throw new Error(e+": Invalid component type "+t.componentType);if(t._data)return t._data;var n=r._GetProperty(e+"/bufferView",this._gltf.bufferViews,t.bufferView);return t._data=this._loadBufferViewAsync("#/bufferViews/"+n._index,n).then((function(n){return r._GetTypedArray(e,t.componentType,n,t.byteOffset,t.count)})),t._data},r.prototype._loadFloatAccessorAsync=function(e,t){var n=this;if(5126!==t.componentType)throw new Error("Invalid component type "+t.componentType);if(t._data)return t._data;var o=r._GetNumComponents(e,t.type),a=o*t.count;if(void 0==t.bufferView)t._data=Promise.resolve(new Float32Array(a));else{var i=r._GetProperty(e+"/bufferView",this._gltf.bufferViews,t.bufferView);t._data=this._loadBufferViewAsync("#/bufferViews/"+i._index,i).then((function(n){return r._GetTypedArray(e,t.componentType,n,t.byteOffset,a)}))}if(t.sparse){var s=t.sparse;t._data=t._data.then((function(a){var i=r._GetProperty(e+"/sparse/indices/bufferView",n._gltf.bufferViews,s.indices.bufferView),l=r._GetProperty(e+"/sparse/values/bufferView",n._gltf.bufferViews,s.values.bufferView);return Promise.all([n._loadBufferViewAsync("#/bufferViews/"+i._index,i),n._loadBufferViewAsync("#/bufferViews/"+l._index,l)]).then((function(n){for(var i=n[0],l=n[1],u=r._GetTypedArray(e+"/sparse/indices",s.indices.componentType,i,s.indices.byteOffset,s.count),c=r._GetTypedArray(e+"/sparse/values",t.componentType,l,s.values.byteOffset,o*s.count),d=0,f=0;f<u.length;f++)for(var h=u[f]*o,p=0;p<o;p++)a[h++]=c[d++];return a}))}))}return t._data},r.prototype._loadVertexBufferViewAsync=function(t,r,n){var o=this;return r._babylonBuffer?r._babylonBuffer:(r._babylonBuffer=this._loadBufferViewAsync(t,r).then((function(t){return new e.Buffer(o._babylonScene.getEngine(),t,!1)})),r._babylonBuffer)},r.prototype._loadVertexAccessorAsync=function(t,n,o){var a=this;if(n._babylonVertexBuffer)return n._babylonVertexBuffer;if(n.sparse)n._babylonVertexBuffer=this._loadFloatAccessorAsync(t,n).then((function(t){return new e.VertexBuffer(a._babylonScene.getEngine(),t,o,!1)}));else{var i=r._GetProperty(t+"/bufferView",this._gltf.bufferViews,n.bufferView);n._babylonVertexBuffer=this._loadVertexBufferViewAsync("#/bufferViews/"+i._index,i,o).then((function(s){var l=r._GetNumComponents(t,n.type);return new e.VertexBuffer(a._babylonScene.getEngine(),s,o,!1,!1,i.byteStride,!1,n.byteOffset,l,n.componentType,n.normalized,!0)}))}return n._babylonVertexBuffer},r.prototype._getDefaultMaterial=function(t){var r=this._defaultBabylonMaterials[t];return r||(r=this._createMaterial("__gltf_default",t),r.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE,r.metallic=1,r.roughness=1,this.onMaterialLoadedObservable.notifyObservers(r)),r},r.prototype._loadMaterialMetallicRoughnessPropertiesAsync=function(t,r,n){var o=new Array;n.metallic=1,n.roughness=1;var a=r.pbrMetallicRoughness;return a&&(a.baseColorFactor?(n.albedoColor=e.Color3.FromArray(a.baseColorFactor),n.alpha=a.baseColorFactor[3]):n.albedoColor=e.Color3.White(),n.metallic=void 0==a.metallicFactor?1:a.metallicFactor,n.roughness=void 0==a.roughnessFactor?1:a.roughnessFactor,a.baseColorTexture&&o.push(this._loadTextureAsync(t+"/baseColorTexture",a.baseColorTexture,(function(e){n.albedoTexture=e}))),a.metallicRoughnessTexture&&(o.push(this._loadTextureAsync(t+"/metallicRoughnessTexture",a.metallicRoughnessTexture,(function(e){n.metallicTexture=e}))),n.useMetallnessFromMetallicTextureBlue=!0,n.useRoughnessFromMetallicTextureGreen=!0,n.useRoughnessFromMetallicTextureAlpha=!1)),this._loadMaterialAlphaProperties(t,r,n),Promise.all(o).then((function(){}))},r.prototype._loadMaterialAsync=function(e,r,n,o,a){var i=t.GLTFLoaderExtension._LoadMaterialAsync(this,e,r,n,o,a);if(i)return i;r._babylonData=r._babylonData||{};var s=r._babylonData[o];if(!s){var l=new Array,u=r.name||"materialSG_"+r._index,c=this._createMaterial(u,o);l.push(this._loadMaterialBasePropertiesAsync(e,r,c)),l.push(this._loadMaterialMetallicRoughnessPropertiesAsync(e,r,c)),this.onMaterialLoadedObservable.notifyObservers(c),s={material:c,meshes:[],loaded:Promise.all(l).then((function(){}))},r._babylonData[o]=s}return s.meshes.push(n),a(s.material),s.loaded},r.prototype._createMaterial=function(t,r){var n=new e.PBRMaterial(t,this._babylonScene);return n.sideOrientation=this._babylonScene.useRightHandedSystem?e.Material.CounterClockWiseSideOrientation:e.Material.ClockWiseSideOrientation,n.fillMode=r,n.enableSpecularAntiAliasing=!0,n.useRadianceOverAlpha=!this.transparencyAsCoverage,n.useSpecularOverAlpha=!this.transparencyAsCoverage,n},r.prototype._loadMaterialBasePropertiesAsync=function(t,r,n){var o=new Array;return n.emissiveColor=r.emissiveFactor?e.Color3.FromArray(r.emissiveFactor):new e.Color3(0,0,0),r.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),r.normalTexture&&(o.push(this._loadTextureAsync(t+"/normalTexture",r.normalTexture,(function(e){n.bumpTexture=e}))),n.invertNormalMapX=!this._babylonScene.useRightHandedSystem,n.invertNormalMapY=this._babylonScene.useRightHandedSystem,void 0!=r.normalTexture.scale&&(n.bumpTexture.level=r.normalTexture.scale)),r.occlusionTexture&&(o.push(this._loadTextureAsync(t+"/occlusionTexture",r.occlusionTexture,(function(e){n.ambientTexture=e}))),n.useAmbientInGrayScale=!0,void 0!=r.occlusionTexture.strength&&(n.ambientTextureStrength=r.occlusionTexture.strength)),r.emissiveTexture&&o.push(this._loadTextureAsync(t+"/emissiveTexture",r.emissiveTexture,(function(e){n.emissiveTexture=e}))),Promise.all(o).then((function(){}))},r.prototype._loadMaterialAlphaProperties=function(t,r,n){switch(r.alphaMode||"OPAQUE"){case"OPAQUE":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHATEST,n.alphaCutOff=void 0==r.alphaCutoff?.5:r.alphaCutoff,n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHABLEND,n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(t+": Invalid alpha mode ("+r.alphaMode+")")}},r.prototype._loadTextureAsync=function(t,n,o){var a=this,i=r._GetProperty(t+"/index",this._gltf.textures,n.index);t="#/textures/"+n.index;var s=new Array,l=void 0==i.sampler?this._defaultSampler:r._GetProperty(t+"/sampler",this._gltf.samplers,i.sampler),u=this._loadSampler("#/samplers/"+l._index,l),c=new e.Deferred,d=new e.Texture(null,this._babylonScene,u.noMipMaps,!1,u.samplingMode,function(){a._disposed||c.resolve()},function(e,r){a._disposed||c.reject(new Error(t+": "+(r&&r.message?r.message:e||"Failed to load texture")))});s.push(c.promise),d.name=i.name||"texture"+i._index,d.wrapU=u.wrapU,d.wrapV=u.wrapV,d.coordinatesIndex=n.texCoord||0;var f=r._GetProperty(t+"/source",this._gltf.images,i.source);return s.push(this._loadImageAsync("#/images/"+f._index,f).then((function(e){d.updateURL(e)}))),o(d),this.onTextureLoadedObservable.notifyObservers(d),Promise.all(s).then((function(){}))},r.prototype._loadSampler=function(e,t){return t._data||(t._data={noMipMaps:9728===t.minFilter||9729===t.minFilter,samplingMode:r._GetTextureSamplingMode(e,t.magFilter,t.minFilter),wrapU:r._GetTextureWrapMode(e,t.wrapS),wrapV:r._GetTextureWrapMode(e,t.wrapT)}),t._data},r.prototype._loadImageAsync=function(e,t){if(t._objectURL)return t._objectURL;var n;if(t.uri)n=this._loadUriAsync(e,t.uri);else{var o=r._GetProperty(e+"/bufferView",this._gltf.bufferViews,t.bufferView);n=this._loadBufferViewAsync("#/bufferViews/"+o._index,o)}return t._objectURL=n.then((function(e){return URL.createObjectURL(new Blob([e],{type:t.mimeType}))})),t._objectURL},r.prototype._loadUriAsync=function(n,o){var a=this,i=t.GLTFLoaderExtension._LoadUriAsync(this,n,o);if(i)return i;if(!r._ValidateUri(o))throw new Error(n+": Uri '"+o+"' is invalid");return e.Tools.IsBase64(o)?Promise.resolve(new Uint8Array(e.Tools.DecodeBase64(o))):this.preprocessUrlAsync(this._rootUrl+o).then((function(t){return new Promise(function(r,i){if(!a._disposed){var s=e.Tools.LoadFile(t,(function(e){a._disposed||r(new Uint8Array(e))}),(function(t){if(!a._disposed)try{s&&a._state===e.GLTFLoaderState.LOADING&&(s._lengthComputable=t.lengthComputable,s._loaded=t.loaded,s._total=t.total,a._onProgress())}catch(e){i(e)}}),a._babylonScene.database,!0,(function(t,r){a._disposed||i(new e.LoadFileError(n+": Failed to load '"+o+"'"+(t?": "+t.status+" "+t.statusText:""),t))}));a._requests.push(s)}})}))},r.prototype._onProgress=function(){if(this._progressCallback){for(var t=!0,r=0,n=0,o=0,a=this._requests;o<a.length;o++){var i=a[o];if(void 0===i._lengthComputable||void 0===i._loaded||void 0===i._total)return;t=t&&i._lengthComputable,r+=i._loaded,n+=i._total}this._progressCallback(new e.SceneLoaderProgressEvent(t,r,t?n:0))}},r._GetProperty=function(e,t,r){if(!t||void 0==r||!t[r])throw new Error(e+": Failed to find index ("+r+")");return t[r]},r._GetTextureWrapMode=function(t,r){switch(r=void 0==r?10497:r){case 33071:return e.Texture.CLAMP_ADDRESSMODE;case 33648:return e.Texture.MIRROR_ADDRESSMODE;case 10497:return e.Texture.WRAP_ADDRESSMODE;default:return e.Tools.Warn(t+": Invalid texture wrap mode ("+r+")"),e.Texture.WRAP_ADDRESSMODE}},r._GetTextureSamplingMode=function(t,r,n){if(r=void 0==r?9729:r,n=void 0==n?9987:n,9729===r)switch(n){case 9728:return e.Texture.LINEAR_NEAREST;case 9729:return e.Texture.LINEAR_LINEAR;case 9984:return e.Texture.LINEAR_NEAREST_MIPNEAREST;case 9985:return e.Texture.LINEAR_LINEAR_MIPNEAREST;case 9986:return e.Texture.LINEAR_NEAREST_MIPLINEAR;case 9987:return e.Texture.LINEAR_LINEAR_MIPLINEAR;default:return e.Tools.Warn(t+": Invalid texture minification filter ("+n+")"),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(9728!==r&&e.Tools.Warn(t+": Invalid texture magnification filter ("+r+")"),n){case 9728:return e.Texture.NEAREST_NEAREST;case 9729:return e.Texture.NEAREST_LINEAR;case 9984:return e.Texture.NEAREST_NEAREST_MIPNEAREST;case 9985:return e.Texture.NEAREST_LINEAR_MIPNEAREST;case 9986:return e.Texture.NEAREST_NEAREST_MIPLINEAR;case 9987:return e.Texture.NEAREST_LINEAR_MIPLINEAR;default:return e.Tools.Warn(t+": Invalid texture minification filter ("+n+")"),e.Texture.NEAREST_NEAREST_MIPNEAREST}},r._GetTypedArray=function(e,t,r,n,o){var a=r.buffer;n=r.byteOffset+(n||0);try{switch(t){case 5120:return new Int8Array(a,n,o);case 5121:return new Uint8Array(a,n,o);case 5122:return new Int16Array(a,n,o);case 5123:return new Uint16Array(a,n,o);case 5125:return new Uint32Array(a,n,o);case 5126:return new Float32Array(a,n,o);default:throw new Error("Invalid component type "+t)}}catch(t){throw new Error(e+": "+t)}},r._GetNumComponents=function(e,t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16}throw new Error(e+": Invalid type ("+t+")")},r._ValidateUri=function(t){return e.Tools.IsBase64(t)||-1===t.indexOf("..")},r._GetDrawMode=function(t,r){switch(void 0==r&&(r=4),r){case 0:return e.Material.PointListDrawMode;case 1:return e.Material.LineListDrawMode;case 2:return e.Material.LineLoopDrawMode;case 3:return e.Material.LineStripDrawMode;case 4:return e.Material.TriangleFillMode;case 5:return e.Material.TriangleStripDrawMode;case 6:return e.Material.TriangleFanDrawMode}throw new Error(t+": Invalid mesh primitive mode ("+r+")")},r.prototype._compileMaterialsAsync=function(){var e=new Array;if(this._gltf.materials)for(var t=0,r=this._gltf.materials;t<r.length;t++){var n=r[t];if(n._babylonData)for(var o in n._babylonData)for(var a=n._babylonData[o],i=0,s=a.meshes;i<s.length;i++){var l=s[i];l.computeWorldMatrix(!0);var u=a.material;e.push(u.forceCompilationAsync(l)),this.useClipPlane&&e.push(u.forceCompilationAsync(l,{clipPlane:!0}))}}return Promise.all(e).then((function(){}))},r.prototype._compileShadowGeneratorsAsync=function(){for(var e=new Array,t=this._babylonScene.lights,r=0,n=t;r<n.length;r++){var o=n[r],a=o.getShadowGenerator();a&&e.push(a.forceCompilationAsync())}return Promise.all(e).then((function(){}))},r.prototype._clear=function(){for(var e=0,t=this._requests;e<t.length;e++){t[e].abort()}if(this._requests.length=0,this._gltf&&this._gltf.images)for(var r=0,n=this._gltf.images;r<n.length;r++){var o=n[r];o._objectURL&&(o._objectURL.then((function(e){URL.revokeObjectURL(e)})),o._objectURL=void 0)}delete this._gltf,delete this._babylonScene,this._completePromises.length=0;for(var a in this._extensions)this._extensions[a].dispose();this._extensions={},delete this._rootBabylonMesh,delete this._progressCallback,this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCameraLoadedObservable.clear()},r.prototype._applyExtensions=function(e){for(var t=0,n=r._ExtensionNames;t<n.length;t++){var o=n[t],a=this._extensions[o];if(a.enabled){var i=e(a);if(i)return i}}return null},r._ExtensionNames=new Array,r._ExtensionFactories={},r})();t.GLTFLoader=r,e.GLTFFileLoader.CreateGLTFLoaderV2=function(){return new r}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(e){this.enabled=!0,this._loader=e}return e.prototype.dispose=function(){delete this._loader},e.prototype._loadSceneAsync=function(e,t){return null},e.prototype._loadNodeAsync=function(e,t){return null},e.prototype._loadVertexDataAsync=function(e,t,r){return null},e.prototype._loadMaterialAsync=function(e,t,r,n,o){return null},e.prototype._loadUriAsync=function(e,t){return null},e.prototype._loadExtensionAsync=function(e,t,r){if(!t.extensions)return null;var n=t.extensions,o=n[this.name];if(!o)return null;delete n[this.name];try{return r(e+"/extensions/"+this.name,o)}finally{n[this.name]=o}},e._LoadSceneAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadSceneAsync(t,r)}))},e._LoadNodeAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadNodeAsync(t,r)}))},e._LoadVertexDataAsync=function(e,t,r,n){return e._applyExtensions((function(e){return e._loadVertexDataAsync(t,r,n)}))},e._LoadMaterialAsync=function(e,t,r,n,o,a){return e._applyExtensions((function(e){return e._loadMaterialAsync(t,r,n,o,a)}))},e._LoadUriAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadUriAsync(t,r)}))},e})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(t){!(function(r){var n="MSFT_lod",o=(function(r){function o(){var e=null!==r&&r.apply(this,arguments)||this;return e.name=n,e.maxLODsToLoad=Number.MAX_VALUE,e._loadingNodeLOD=null,e._loadNodeSignals={},e._loadingMaterialLOD=null,e._loadMaterialSignals={},e}return __extends(o,r),o.prototype._loadNodeAsync=function(t,r){var n=this;return this._loadExtensionAsync(t,r,(function(t,o){for(var a,i=n._getLODs(t,r,n._loader._gltf.nodes,o.ids),s=0;s<i.length;s++)!(function(t){var r=i[t];0!==t&&(n._loadingNodeLOD=r,n._loadNodeSignals[r._index]||(n._loadNodeSignals[r._index]=new e.Deferred));var o=n._loader._loadNodeAsync("#/nodes/"+r._index,r).then((function(){if(0!==t){var e=i[t-1];e._babylonMesh&&(e._babylonMesh.dispose(!1,!0),delete e._babylonMesh)}if(t!==i.length-1){var r=i[t+1]._index;n._loadNodeSignals[r]&&(n._loadNodeSignals[r].resolve(),delete n._loadNodeSignals[r])}}));0===t?a=o:(n._loader._completePromises.push(o),n._loadingNodeLOD=null)})(s);return a}))},o.prototype._loadMaterialAsync=function(t,r,n,o,a){var i=this;return this._loadingNodeLOD?null:this._loadExtensionAsync(t,r,(function(t,s){for(var l,u=i._getLODs(t,r,i._loader._gltf.materials,s.ids),c=0;c<u.length;c++)!(function(t){var r=u[t];0!==t&&(i._loadingMaterialLOD=r,i._loadMaterialSignals[r._index]||(i._loadMaterialSignals[r._index]=new e.Deferred));var s=i._loader._loadMaterialAsync("#/materials/"+r._index,r,n,o,0===t?a:function(){}).then((function(){if(0!==t){var e=r._babylonData;a(e[o].material);var n=u[t-1]._babylonData;n[o]&&(n[o].material.dispose(),delete n[o])}if(t!==u.length-1){var s=u[t+1]._index;i._loadMaterialSignals[s]&&(i._loadMaterialSignals[s].resolve(),delete i._loadMaterialSignals[s])}}));0===t?l=s:(i._loader._completePromises.push(s),i._loadingMaterialLOD=null)})(c);return l}))},o.prototype._loadUriAsync=function(e,t){var r=this;if(this._loadingMaterialLOD){var n=this._loadingMaterialLOD._index;return this._loadMaterialSignals[n].promise.then((function(){return r._loader._loadUriAsync(e,t)}))}if(this._loadingNodeLOD){var n=this._loadingNodeLOD._index;return this._loadNodeSignals[n].promise.then((function(){return r._loader._loadUriAsync(e,t)}))}return null},o.prototype._getLODs=function(e,r,n,o){if(this.maxLODsToLoad<=0)throw new Error("maxLODsToLoad must be greater than zero");for(var a=new Array,i=o.length-1;i>=0;i--)if(a.push(t.GLTFLoader._GetProperty(e+"/ids/"+o[i],n,o[i])),a.length===this.maxLODsToLoad)return a;return a.push(r),a},o})(t.GLTFLoaderExtension);r.MSFT_lod=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(e){!(function(t){var r="MSFT_minecraftMesh",n=(function(e){function t(t){var n=e.call(this,t)||this;n.name=r,n._onMaterialLoaded=function(e){e.needAlphaBlending()&&(e.forceDepthWrite=!0,e.separateCullingPass=!0),e.backFaceCulling=e.forceDepthWrite,e.twoSidedLighting=!0};var o=t._gltf.meshes;if(o&&o.length)for(var a=0,i=o;a<i.length;a++){var s=i[a];if(s&&s.extras&&s.extras.MSFT_minecraftMesh){n._loader.onMaterialLoadedObservable.add(n._onMaterialLoaded);break}}return n}return __extends(t,e),t})(e.GLTFLoaderExtension);t.MSFT_minecraftMesh=n,e.GLTFLoader._Register(r,(function(e){return new n(e)}))})(e.Extensions||(e.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 r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(e){!(function(t){var r="MSFT_sRGBFactors",n=(function(e){function t(t){var n=e.call(this,t)||this;n.name=r,n._onMaterialLoaded=function(e){e.albedoTexture||e.albedoColor.toLinearSpaceToRef(e.albedoColor),e.reflectivityTexture||e.reflectivityColor.toLinearSpaceToRef(e.reflectivityColor)};var o=t._gltf.materials;if(o&&o.length)for(var a=0,i=o;a<i.length;a++){var s=i[a];if(s&&s.extras&&s.extras.MSFT_sRGBFactors){n._loader.onMaterialLoadedObservable.add(n._onMaterialLoaded);break}}return n}return __extends(t,e),t})(e.GLTFLoaderExtension);t.MSFT_sRGBFactors=n,e.GLTFLoader._Register(r,(function(e){return new n(e)}))})(e.Extensions||(e.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 r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(t){!(function(r){var n="KHR_draco_mesh_compression",o=(function(r){function o(t){var o=r.call(this,t)||this;return o.name=n,o._dracoCompression=null,e.DracoCompression.DecoderAvailable||(o.enabled=!1),o}return __extends(o,r),o.prototype.dispose=function(){this._dracoCompression&&this._dracoCompression.dispose(),r.prototype.dispose.call(this)},o.prototype._loadVertexDataAsync=function(r,n,o){var a=this;return this._loadExtensionAsync(r,n,(function(i,s){if(void 0!=n.mode){if(5!==n.mode&&4!==n.mode)throw new Error(r+": Unsupported mode "+n.mode);if(5===n.mode)throw new Error(r+": Mode "+n.mode+" is not currently supported")}var l={},u=function(e,t){var r=s.attributes[e];void 0!=r&&(o._delayInfo=o._delayInfo||[],-1===o._delayInfo.indexOf(t)&&o._delayInfo.push(t),l[t]=r)};u("POSITION",e.VertexBuffer.PositionKind),u("NORMAL",e.VertexBuffer.NormalKind),u("TANGENT",e.VertexBuffer.TangentKind),u("TEXCOORD_0",e.VertexBuffer.UVKind),u("TEXCOORD_1",e.VertexBuffer.UV2Kind),u("JOINTS_0",e.VertexBuffer.MatricesIndicesKind),u("WEIGHTS_0",e.VertexBuffer.MatricesWeightsKind),u("COLOR_0",e.VertexBuffer.ColorKind);var c=t.GLTFLoader._GetProperty(i,a._loader._gltf.bufferViews,s.bufferView);return c._dracoBabylonGeometry||(c._dracoBabylonGeometry=a._loader._loadBufferViewAsync("#/bufferViews/"+c._index,c).then((function(t){return a._dracoCompression||(a._dracoCompression=new e.DracoCompression),a._dracoCompression.decodeMeshAsync(t,l).then((function(t){var r=new e.Geometry(o.name,a._loader._babylonScene);return t.applyToGeometry(r),r})).catch((function(e){throw new Error(r+": "+e.message)}))}))),c._dracoBabylonGeometry}))},o})(t.GLTFLoaderExtension);r.KHR_draco_mesh_compression=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(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 r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(t){!(function(r){var n="KHR_materials_pbrSpecularGlossiness",o=(function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=n,e}return __extends(r,t),r.prototype._loadMaterialAsync=function(e,t,r,n,o){var a=this;return this._loadExtensionAsync(e,t,(function(i,s){t._babylonData=t._babylonData||{};var l=t._babylonData[n];if(!l){var u=new Array,c=t.name||"materialSG_"+t._index,d=a._loader._createMaterial(c,n);u.push(a._loader._loadMaterialBasePropertiesAsync(e,t,d)),u.push(a._loadSpecularGlossinessPropertiesAsync(i,t,s,d)),a._loader.onMaterialLoadedObservable.notifyObservers(d),l={material:d,meshes:[],loaded:Promise.all(u).then((function(){}))},t._babylonData[n]=l}return l.meshes.push(r),o(l.material),l.loaded}))},r.prototype._loadSpecularGlossinessPropertiesAsync=function(t,r,n,o){var a=new Array;return n.diffuseFactor?(o.albedoColor=e.Color3.FromArray(n.diffuseFactor),o.alpha=n.diffuseFactor[3]):o.albedoColor=e.Color3.White(),o.reflectivityColor=n.specularFactor?e.Color3.FromArray(n.specularFactor):e.Color3.White(),o.microSurface=void 0==n.glossinessFactor?1:n.glossinessFactor,n.diffuseTexture&&a.push(this._loader._loadTextureAsync(t+"/diffuseTexture",n.diffuseTexture,(function(e){o.albedoTexture=e}))),n.specularGlossinessTexture&&(a.push(this._loader._loadTextureAsync(t+"/specularGlossinessTexture",n.specularGlossinessTexture,(function(e){o.reflectivityTexture=e}))),o.reflectivityTexture.hasAlpha=!0,o.useMicroSurfaceFromReflectivityMapAlpha=!0),this._loader._loadMaterialAlphaProperties(t,r,o),Promise.all(a).then((function(){}))},r})(t.GLTFLoaderExtension);r.KHR_materials_pbrSpecularGlossiness=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(t){!(function(r){var n="KHR_materials_unlit",o=(function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=n,e}return __extends(r,t),r.prototype._loadMaterialAsync=function(e,t,r,n,o){var a=this;return this._loadExtensionAsync(e,t,(function(){t._babylonData=t._babylonData||{};var i=t._babylonData[n];if(!i){var s=t.name||"materialUnlit_"+t._index,l=a._loader._createMaterial(s,n);l.unlit=!0;var u=a._loadUnlitPropertiesAsync(e,t,l);a._loader.onMaterialLoadedObservable.notifyObservers(l),i={material:l,meshes:[],loaded:u},t._babylonData[n]=i}return i.meshes.push(r),o(i.material),i.loaded}))},r.prototype._loadUnlitPropertiesAsync=function(t,r,n){var o=new Array;n.metallic=1,n.roughness=1;var a=r.pbrMetallicRoughness;return a&&(a.baseColorFactor?(n.albedoColor=e.Color3.FromArray(a.baseColorFactor),n.alpha=a.baseColorFactor[3]):n.albedoColor=e.Color3.White(),a.baseColorTexture&&o.push(this._loader._loadTextureAsync(t+"/baseColorTexture",a.baseColorTexture,(function(e){n.albedoTexture=e})))),r.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),this._loader._loadMaterialAlphaProperties(t,r,n),Promise.all(o).then((function(){}))},r})(t.GLTFLoaderExtension);r.KHR_materials_unlit=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(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 r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){!(function(t){!(function(r){var n,o="KHR_lights";!(function(e){e.AMBIENT="ambient",e.DIRECTIONAL="directional",e.POINT="point",e.SPOT="spot"})(n||(n={}));var a=(function(r){function a(){var e=null!==r&&r.apply(this,arguments)||this;return e.name=o,e}return __extends(a,r),a.prototype._loadSceneAsync=function(r,o){var a=this;return this._loadExtensionAsync(r,o,(function(r,i){var s=a._loader._loadSceneAsync(r,o),l=t.GLTFLoader._GetProperty(r,a._lights,i.light);if(l.type!==n.AMBIENT)throw new Error(r+": Only ambient lights are allowed on a scene");return a._loader._babylonScene.ambientColor=l.color?e.Color3.FromArray(l.color):e.Color3.Black(),s}))},a.prototype._loadNodeAsync=function(r,o){var a=this;return this._loadExtensionAsync(r,o,(function(r,i){var s,l=a._loader._loadNodeAsync(r,o),u=t.GLTFLoader._GetProperty(r,a._lights,i.light),c=o._babylonMesh.name;switch(u.type){case n.AMBIENT:throw new Error(r+": Ambient lights are not allowed on a node");case n.DIRECTIONAL:s=new e.DirectionalLight(c,e.Vector3.Forward(),a._loader._babylonScene);break;case n.POINT:s=new e.PointLight(c,e.Vector3.Zero(),a._loader._babylonScene);break;case n.SPOT:var d=u,f=d.outerConeAngle||Math.PI/4;s=new e.SpotLight(c,e.Vector3.Zero(),e.Vector3.Forward(),f,2,a._loader._babylonScene);break;default:throw new Error(r+": Invalid light type ("+u.type+")")}return s.diffuse=u.color?e.Color3.FromArray(u.color):e.Color3.White(),s.intensity=void 0==u.intensity?1:u.intensity,s.parent=o._babylonMesh,l}))},Object.defineProperty(a.prototype,"_lights",{get:function(){var e=this._loader._gltf.extensions;if(!e||!e[this.name])throw new Error("#/extensions: '"+this.name+"' not found");return e[this.name].lights},enumerable:!0,configurable:!0}),a})(t.GLTFLoaderExtension);r.KHR_lights=a,t.GLTFLoader._Register(o,(function(e){return new a(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));