babylon.glTF2FileLoader.min.js 56 KB

12
  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){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],_=r._GetProperty(n+"/children/"+f,this._gltf.nodes,f);i.push(this._loadNodeAsync("#/nodes/"+f,_))}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],_=new e.Mesh((a.name||i.name)+"_"+c._index,this._babylonScene,i);o._primitiveBabylonMeshes.push(_),l.push(this._loadPrimitiveAsync(n+"/primitives/"+c._index,o,a,c,_)),this.onMeshLoadedObservable.notifyObservers(i)}}if(void 0!=o.skin){var h=r._GetProperty(n+"/skin",this._gltf.skins,o.skin);l.push(this._loadSkinAsync("#/skins/"+h._index,o,a,h))}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),_=0;_<r.input.length;_++)f[_]=d(_);if("influence"===n)for(var h=0;h<l._numMorphTargets;h++)!(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}}))),s._forEachPrimitive(l,(function(e){var r=e.morphTargetManager.getTarget(t),n=a.clone();r.animations.push(n),i.addTargetedAnimation(n,r)}))})(h);else{var p=i.name+"_channel"+i.targetedAnimations.length,y=new e.Animation(p,n,1,o);if(y.setKeys(f),l._babylonBones){for(var b=[l._babylonMesh].concat(l._babylonBones),m=0,v=b;m<v.length;m++){v[m].animations.push(y)}i.addTargetedAnimation(y,b)}else l._babylonMesh.animations.push(y),i.addTargetedAnimation(y,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 _=u[f]*o,h=0;h<o;h++)a[_++]=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),
  2. 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={}));