12 |
- var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var r;!(function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"})(r=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}));!(function(e){e[e.Loading=0]="Loading",e[e.Ready=1]="Ready",e[e.Complete=2]="Complete"})(e.GLTFLoaderState||(e.GLTFLoaderState={}));var n=(function(){function n(){this.onParsedObservable=new e.Observable,this.coordinateSystemMode=t.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this._loader=null,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return Object.defineProperty(n.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"onExtensionLoaded",{set:function(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),n.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},n.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=a._parse(r);return a._loader=a._getLoader(i),a._loader.importMeshAsync(e,t,i,n,o)}))},n.prototype.loadAsync=function(e,t,r,n){var o=this;return Promise.resolve().then((function(){var a=o._parse(t);return o._loader=o._getLoader(a),o._loader.loadAsync(e,a,r,n)}))},n.prototype.loadAssetContainerAsync=function(t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=a._parse(r);return a._loader=a._getLoader(i),a._loader.importMeshAsync(null,t,i,n,o).then((function(r){var n=new e.AssetContainer(t);return Array.prototype.push.apply(n.meshes,r.meshes),Array.prototype.push.apply(n.particleSystems,r.particleSystems),Array.prototype.push.apply(n.skeletons,r.skeletons),n.removeAllFromScene(),n}))}))},n.prototype.canDirectLoad=function(e){return-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.onMeshLoadedObservable.add((function(e){return t.onMeshLoadedObservable.notifyObservers(e)})),u.onTextureLoadedObservable.add((function(e){return t.onTextureLoadedObservable.notifyObservers(e)})),u.onMaterialLoadedObservable.add((function(e){return t.onMaterialLoadedObservable.notifyObservers(e)})),u.onExtensionLoadedObservable.add((function(e){return t.onExtensionLoadedObservable.notifyObservers(e)})),u.onCompleteObservable.add((function(){t.onMeshLoadedObservable.clear(),t.onTextureLoadedObservable.clear(),t.onMaterialLoadedObservable.clear(),t.onCompleteObservable.notifyObservers(t),t.onCompleteObservable.clear()})),u},n._parseBinary=function(e){var t={Magic:1179937895},r=new o(e),a=r.readUint32();if(a!==t.Magic)throw new Error("Unexpected magic: "+a);var i=r.readUint32();switch(i){case 1:return n._parseV1(r);case 2:return n._parseV2(r)}throw new Error("Unsupported version: "+i)},n._parseV1=function(e){var t={JSON:0},r=e.readUint32();if(r!=e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o,a=e.readUint32(),i=e.readUint32();switch(i){case t.JSON:o=JSON.parse(n._decodeBufferToText(e.readUint8Array(a)));break;default:throw new Error("Unexpected content format: "+i)}var s=e.getLength()-e.getPosition();return{json:o,bin:e.readUint8Array(s)}},n._parseV2=function(e){var t={JSON:1313821514,BIN:5130562},r=e.readUint32();if(r!==e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==t.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(n._decodeBufferToText(e.readUint8Array(o))),i=null;e.getPosition()<e.getLength();){var s=e.readUint32();switch(e.readUint32()){case t.JSON:throw new Error("Unexpected JSON chunk");case t.BIN:i=e.readUint8Array(s);break;default:e.skipBytes(s)}}return{json:a,bin:i}},n._parseVersion=function(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};var t=(e+"").match(/^(\d+)\.(\d+)/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null},n._compareVersion=function(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0},n._decodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;n++)t+=String.fromCharCode(e[n]);return t},n.IncrementalLoading=!0,n.HomogeneousCoordinates=!1,n})();e.GLTFFileLoader=n;var o=(function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new n)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(){}return e.Assign=function(e){if(e)for(var t=0;t<e.length;t++)e[t]._index=t},e})();e.ArrayItem=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(){this._completePromises=new Array,this._disposed=!1,this._state=null,this._extensions={},this._defaultSampler={},this._requests=new Array,this.coordinateSystemMode=e.GLTFLoaderCoordinateSystemMode.AUTO,this.animationStartMode=e.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.onDisposeObservable=new e.Observable,this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable}return r._Register=function(t,n){if(r._Factories[t])return void e.Tools.Error("Extension with the name '"+t+"' already exists");r._Factories[t]=n,r._Names.push(t)},Object.defineProperty(r.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),r.prototype.dispose=function(){this._disposed||(this._disposed=!0,this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear(),this._clear())},r.prototype.importMeshAsync=function(e,t,r,n,o){var a=this;return Promise.resolve().then((function(){var i=null;if(e){var s={};if(a._gltf.nodes)for(var l=0,u=a._gltf.nodes;l<u.length;l++){var d=u[l];d.name&&(s[d.name]=d)}i=(e instanceof Array?e:[e]).map((function(e){var t=s[e];if(!t)throw new Error("Failed to find node "+e);return t}))}return a._loadAsync(i,t,r,n,o).then((function(){return{meshes:a._getMeshes(),particleSystems:[],skeletons:a._getSkeletons()}}))}))},r.prototype.loadAsync=function(e,t,r,n){return this._loadAsync(null,e,t,r,n)},r.prototype._loadAsync=function(t,n,o,a,i){var s=this;return Promise.resolve().then((function(){s._loadExtensions(),s._babylonScene=n,s._rootUrl=a,s._progressCallback=i,s._state=e.GLTFLoaderState.Loading,s._loadData(o),s._checkExtensions();var l=new Array;if(t)l.push(s._loadNodesAsync(t));else{var u=r._GetProperty("#/scene",s._gltf.scenes,s._gltf.scene||0);l.push(s._loadSceneAsync("#/scenes/"+u._index,u))}return s.compileMaterials&&l.push(s._compileMaterialsAsync()),s.compileShadowGenerators&&l.push(s._compileShadowGeneratorsAsync()),Promise.all(l).then((function(){s._state=e.GLTFLoaderState.Ready,s._startAnimations(),e.Tools.SetImmediate((function(){s._disposed||Promise.all(s._completePromises).then((function(){s._state=e.GLTFLoaderState.Complete,s.onCompleteObservable.notifyObservers(s),s.onCompleteObservable.clear(),s._clear()})).catch((function(t){e.Tools.Error("glTF Loader: "+t.message),s._clear()}))}))}))})).catch((function(t){throw e.Tools.Error("glTF Loader: "+t.message),s._clear(),t}))},r.prototype._loadExtensions=function(){for(var e=0,t=r._Names;e<t.length;e++){var n=t[e],o=r._Factories[n](this);this._extensions[n]=o,this.onExtensionLoadedObservable.notifyObservers(o)}this.onExtensionLoadedObservable.clear()},r.prototype._loadData=function(t){if(this._gltf=t.json,this._setupData(),t.bin){var r=this._gltf.buffers;if(r&&r[0]&&!r[0].uri){var n=r[0];(n.byteLength<t.bin.byteLength-3||n.byteLength>t.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),n._data=Promise.resolve(t.bin)}else e.Tools.Warn("Unexpected BIN chunk")}},r.prototype._setupData=function(){if(t.ArrayItem.Assign(this._gltf.accessors),t.ArrayItem.Assign(this._gltf.animations),t.ArrayItem.Assign(this._gltf.buffers),t.ArrayItem.Assign(this._gltf.bufferViews),t.ArrayItem.Assign(this._gltf.cameras),t.ArrayItem.Assign(this._gltf.images),t.ArrayItem.Assign(this._gltf.materials),t.ArrayItem.Assign(this._gltf.meshes),t.ArrayItem.Assign(this._gltf.nodes),t.ArrayItem.Assign(this._gltf.samplers),t.ArrayItem.Assign(this._gltf.scenes),t.ArrayItem.Assign(this._gltf.skins),t.ArrayItem.Assign(this._gltf.textures),this._gltf.nodes){for(var e={},r=0,n=this._gltf.nodes;r<n.length;r++){var o=n[r];if(o.children)for(var a=0,i=o.children;a<i.length;a++){var s=i[a];e[s]=o._index}}for(var l=this._createRootNode(),u=0,d=this._gltf.nodes;u<d.length;u++){var o=d[u],c=e[o._index];o._parent=void 0===c?l:this._gltf.nodes[c]}}},r.prototype._checkExtensions=function(){if(this._gltf.extensionsRequired)for(var e=0,t=this._gltf.extensionsRequired;e<t.length;e++){var r=t[e],n=this._extensions[r];if(!n||!n.enabled)throw new Error("Require extension "+r+" is not available")}},r.prototype._createRootNode=function(){this._rootBabylonMesh=new e.Mesh("__root__",this._babylonScene);var t={_babylonMesh:this._rootBabylonMesh};switch(this.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(t.rotation=[0,1,0,0],t.scale=[1,1,-1],r._LoadTransform(t,this._rootBabylonMesh));break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:throw new Error("Invalid coordinate system mode "+this.coordinateSystemMode)}return this.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh),t},r.prototype._loadNodesAsync=function(e){for(var t=new Array,r=0,n=e;r<n.length;r++){var o=n[r];t.push(this._loadNodeAsync("#/nodes/"+o._index,o))}return t.push(this._loadAnimationsAsync()),Promise.all(t).then((function(){}))},r.prototype._loadSceneAsync=function(e,n){var o=t.GLTFLoaderExtension._LoadSceneAsync(this,e,n);if(o)return o;for(var a=new Array,i=0,s=n.nodes;i<s.length;i++){var l=s[i],u=r._GetProperty(e+"/nodes/"+l,this._gltf.nodes,l);a.push(this._loadNodeAsync("#/nodes/"+u._index,u))}return a.push(this._loadAnimationsAsync()),Promise.all(a).then((function(){}))},r.prototype._getMeshes=function(){var e=new Array;e.push(this._rootBabylonMesh);var t=this._gltf.nodes;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];if(o._babylonMesh&&e.push(o._babylonMesh),o._primitiveBabylonMeshes)for(var a=0,i=o._primitiveBabylonMeshes;a<i.length;a++){var s=i[a];e.push(s)}}return e},r.prototype._getSkeletons=function(){var e=new Array,t=this._gltf.skins;if(t)for(var r=0,n=t;r<n.length;r++){var o=n[r];o._babylonSkeleton&&e.push(o._babylonSkeleton)}return e},r.prototype._startAnimations=function(){var t=this._gltf.animations;if(t)switch(this.animationStartMode){case e.GLTFLoaderAnimationStartMode.NONE:break;case e.GLTFLoaderAnimationStartMode.FIRST:var r=t[0];r._babylonAnimationGroup.start(!0);break;case e.GLTFLoaderAnimationStartMode.ALL:for(var n=0,o=t;n<o.length;n++){var r=o[n];r._babylonAnimationGroup.start(!0)}break;default:return void e.Tools.Error("Invalid animation start mode "+this.animationStartMode)}},r.prototype._loadNodeAsync=function(n,o){var a=t.GLTFLoaderExtension._LoadNodeAsync(this,n,o);if(a)return a;if(o._babylonMesh)throw new Error(n+": Invalid recursive node hierarchy");var i=new Array,s=new e.Mesh(o.name||"node"+o._index,this._babylonScene,o._parent._babylonMesh);if(o._babylonMesh=s,o._babylonAnimationTargets=o._babylonAnimationTargets||[],o._babylonAnimationTargets.push(s),r._LoadTransform(o,s),void 0!=o.mesh){var l=r._GetProperty(n+"/mesh",this._gltf.meshes,o.mesh);i.push(this._loadMeshAsync("#/meshes/"+l._index,o,l))}if(o.children)for(var u=0,d=o.children;u<d.length;u++){var c=d[u],h=r._GetProperty(n+"/children/"+c,this._gltf.nodes,c);i.push(this._loadNodeAsync("#/nodes/"+c,h))}return this.onMeshLoadedObservable.notifyObservers(s),Promise.all(i).then((function(){}))},r.prototype._loadMeshAsync=function(e,n,o){var a=new Array,i=o.primitives;if(!i||0===i.length)throw new Error(e+": Primitives are missing");t.ArrayItem.Assign(i);for(var s=0,l=i;s<l.length;s++){var u=l[s];a.push(this._loadPrimitiveAsync(e+"/primitives/"+u._index,n,o,u))}if(void 0!=n.skin){var d=r._GetProperty(e+"/skin",this._gltf.skins,n.skin);a.push(this._loadSkinAsync("#/skins/"+d._index,n,o,d))}return Promise.all(a).then((function(){if(n._primitiveBabylonMeshes)for(var e=0,t=n._primitiveBabylonMeshes;e<t.length;e++){var r=t[e];r._refreshBoundingInfo(!0)}}))},r.prototype._loadPrimitiveAsync=function(t,n,o,a){var i=this,s=new Array,l=new e.Mesh((o.name||n._babylonMesh.name)+"_"+a._index,this._babylonScene,n._babylonMesh);if(l.setEnabled(!1),n._primitiveBabylonMeshes=n._primitiveBabylonMeshes||[],n._primitiveBabylonMeshes[a._index]=l,this._createMorphTargets(t,n,o,a,l),s.push(this._loadVertexDataAsync(t,a,l).then((function(r){return new e.Geometry(l.name,i._babylonScene,r,!1,l),i._loadMorphTargetsAsync(t,a,l,r)}))),void 0==a.material)l.material=this._getDefaultMaterial();else{var u=r._GetProperty(t+"/material",this._gltf.materials,a.material);s.push(this._loadMaterialAsync("#/materials/"+u._index,u,l))}return this.onMeshLoadedObservable.notifyObservers(l),Promise.all(s).then((function(){l.setEnabled(!0)}))},r.prototype._loadVertexDataAsync=function(n,o,a){var i=this,s=t.GLTFLoaderExtension._LoadVertexDataAsync(this,n,o,a);if(s)return s;var l=o.attributes;if(!l)throw new Error(n+": Attributes are missing");if(void 0!=o.mode&&4!==o.mode)throw new Error(n+": Mode "+o.mode+" is not currently supported");var u=new Array,d=new e.VertexData;if(void 0==o.indices){var c=l.POSITION;if(void 0!=c){var h=r._GetProperty(n+"/attributes/POSITION",this._gltf.accessors,c);d.indices=new Uint32Array(h.count);for(var _=0;_<d.indices.length;_++)d.indices[_]=_}}else{var f=r._GetProperty(n+"/indices",this._gltf.accessors,o.indices);u.push(this._loadAccessorAsync("#/accessors/"+f._index,f).then((function(e){d.indices=e})))}var p=function(e,t){if(void 0!=l[e]){a._delayInfo=a._delayInfo||[],-1===a._delayInfo.indexOf(t)&&a._delayInfo.push(t);var o=r._GetProperty(n+"/attributes/"+e,i._gltf.accessors,l[e]);u.push(i._loadAccessorAsync("#/accessors/"+o._index,o).then((function(i){var s=r._ConvertToFloat32Array(n,o,i);"COLOR_0"===e&&(a.hasVertexAlpha=!0,"VEC3"===o.type&&(s=r._ConvertVec3ToVec4(n,s))),d.set(s,t)})))}};return p("POSITION",e.VertexBuffer.PositionKind),p("NORMAL",e.VertexBuffer.NormalKind),p("TANGENT",e.VertexBuffer.TangentKind),p("TEXCOORD_0",e.VertexBuffer.UVKind),p("TEXCOORD_1",e.VertexBuffer.UV2Kind),p("JOINTS_0",e.VertexBuffer.MatricesIndicesKind),p("WEIGHTS_0",e.VertexBuffer.MatricesWeightsKind),p("COLOR_0",e.VertexBuffer.ColorKind),Promise.all(u).then((function(){return d}))},r.prototype._createMorphTargets=function(t,r,n,o,a){if(o.targets){if(void 0==r._numMorphTargets)r._numMorphTargets=o.targets.length;else if(o.targets.length!==r._numMorphTargets)throw new Error(t+": Primitives do not have the same number of targets");a.morphTargetManager=new e.MorphTargetManager;for(var i=0;i<o.targets.length;i++){var s=r.weights?r.weights[i]:n.weights?n.weights[i]:0;a.morphTargetManager.addTarget(new e.MorphTarget("morphTarget"+i,s))}}},r.prototype._loadMorphTargetsAsync=function(e,t,r,n){if(!t.targets)return Promise.resolve();for(var o=new Array,a=r.morphTargetManager,i=0;i<a.numTargets;i++){var s=a.getTarget(i);o.push(this._loadMorphTargetVertexDataAsync(e+"/targets/"+i,n,t.targets[i],s))}return Promise.all(o).then((function(){}))},r.prototype._loadMorphTargetVertexDataAsync=function(e,t,n,o){var a=this,i=new Array,s=function(t,o){if(void 0!=n[t]){var s=r._GetProperty(e+"/"+t,a._gltf.accessors,n[t]);i.push(a._loadAccessorAsync("#/accessors/"+s._index,s).then((function(e){o(e)})))}};return s("POSITION",(function(e){if(t.positions){for(var r=0;r<e.length;r++)e[r]+=t.positions[r];o.setPositions(e)}})),s("NORMAL",(function(e){if(t.normals){for(var r=0;r<e.length;r++)e[r]+=t.normals[r];o.setNormals(e)}})),s("TANGENT",(function(e){if(t.tangents){for(var r=0,n=0;r<e.length;r++)e[r]+=t.tangents[n++],(r+1)%3==0&&n++;o.setTangents(e)}})),Promise.all(i).then((function(){}))},r._ConvertToFloat32Array=function(e,t,n){if(5126==t.componentType)return n;var o=1;if(t.normalized)switch(t.componentType){case 5121:o=1/255;break;case 5123:o=1/65535;break;default:throw new Error(e+": Invalid component type "+t.componentType)}for(var a=new Float32Array(t.count*r._GetNumComponents(e,t.type)),i=0;i<a.length;i++)a[i]=n[i]*o;return a},r._ConvertVec3ToVec4=function(e,t){for(var r=new Float32Array(t.length/3*4),n=0,o=0;o<r.length;o++)r[o]=(o+1)%4==0?1:t[n++];return r},r._LoadTransform=function(t,r){var n=e.Vector3.Zero(),o=e.Quaternion.Identity(),a=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(a,o,n)}else t.translation&&(n=e.Vector3.FromArray(t.translation)),t.rotation&&(o=e.Quaternion.FromArray(t.rotation)),t.scale&&(a=e.Vector3.FromArray(t.scale));r.position=n,r.rotationQuaternion=o,r.scaling=a},r.prototype._loadSkinAsync=function(t,r,n,o){var a=this,i=function(){for(var t=0,n=r._primitiveBabylonMeshes;t<n.length;t++){n[t].skeleton=o._babylonSkeleton}r._babylonMesh.parent=a._rootBabylonMesh,r._babylonMesh.position=e.Vector3.Zero(),r._babylonMesh.rotationQuaternion=e.Quaternion.Identity(),r._babylonMesh.scaling=e.Vector3.One()};return o._loaded?o._loaded.then((function(){i()})):o._loaded=this._loadSkinInverseBindMatricesDataAsync(t,o).then((function(r){var n="skeleton"+o._index,s=new e.Skeleton(o.name||n,n,a._babylonScene);o._babylonSkeleton=s,a._loadBones(t,o,r),i()}))},r.prototype._loadSkinInverseBindMatricesDataAsync=function(e,t){if(void 0==t.inverseBindMatrices)return Promise.resolve(null);var n=r._GetProperty(e+"/inverseBindMatrices",this._gltf.accessors,t.inverseBindMatrices);return this._loadAccessorAsync("#/accessors/"+n._index,n).then((function(e){return e}))},r.prototype._createBone=function(t,r,n,o,a,i){var s=new e.Bone(t.name||"joint"+t._index,r._babylonSkeleton,n,o,null,a,i);return t._babylonAnimationTargets=t._babylonAnimationTargets||[],t._babylonAnimationTargets.push(s),s},r.prototype._loadBones=function(e,t,n){for(var o={},a=0,i=t.joints;a<i.length;a++){var s=i[a],l=r._GetProperty(e+"/joints/"+s,this._gltf.nodes,s);this._loadBone(l,t,n,o)}},r.prototype._loadBone=function(t,r,n,o){var a=o[t._index];if(a)return a;var i=r.joints.indexOf(t._index),s=e.Matrix.Identity();n&&-1!==i&&(s=e.Matrix.FromArray(n,16*i),s.invertToRef(s));var l=null;return t._parent._babylonMesh!==this._rootBabylonMesh&&(l=this._loadBone(t._parent,r,n,o),s.multiplyToRef(l.getInvertedAbsoluteTransform(),s)),a=this._createBone(t,r,l,this._getNodeMatrix(t),s,i),o[t._index]=a,a},r.prototype._getNodeMatrix=function(t){return t.matrix?e.Matrix.FromArray(t.matrix):e.Matrix.Compose(t.scale?e.Vector3.FromArray(t.scale):e.Vector3.One(),t.rotation?e.Quaternion.FromArray(t.rotation):e.Quaternion.Identity(),t.translation?e.Vector3.FromArray(t.translation):e.Vector3.Zero())},r.prototype._loadAnimationsAsync=function(){var e=this._gltf.animations;if(!e)return Promise.resolve();for(var t=new Array,r=0;r<e.length;r++){var n=e[r];t.push(this._loadAnimationAsync("#/animations/"+r,n))}return Promise.all(t).then((function(){}))},r.prototype._loadAnimationAsync=function(r,n){var o=new e.AnimationGroup(n.name||"animation"+n._index,this._babylonScene);n._babylonAnimationGroup=o;var a=new Array;t.ArrayItem.Assign(n.channels),t.ArrayItem.Assign(n.samplers);for(var i=0,s=n.channels;i<s.length;i++){var l=s[i];a.push(this._loadAnimationChannelAsync(r+"/channels/"+l._index,r,n,l,o))}return Promise.all(a).then((function(){o.normalize()}))},r.prototype._loadAnimationChannelAsync=function(t,n,o,a,i){var s=r._GetProperty(t+"/target/node",this._gltf.nodes,a.target.node);if(!s._babylonMesh)return Promise.resolve();var l=r._GetProperty(t+"/sampler",o.samplers,a.sampler);return this._loadAnimationSamplerAsync(n+"/samplers/"+a.sampler,l).then((function(r){var n,o;switch(a.target.path){case"translation":n="position",o=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":n="rotationQuaternion",o=e.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":n="scaling",o=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":n="influence",o=e.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(t+": Invalid target path "+a.target.path)}var l,u=0;switch(n){case"position":l=function(){var t=e.Vector3.FromArray(r.output,u);return u+=3,t};break;case"rotationQuaternion":l=function(){var t=e.Quaternion.FromArray(r.output,u);return u+=4,t};break;case"scaling":l=function(){var t=e.Vector3.FromArray(r.output,u);return u+=3,t};break;case"influence":l=function(){for(var e=new Array(s._numMorphTargets),t=0;t<s._numMorphTargets;t++)e[t]=r.output[u++];return e}}var d;switch(r.interpolation){case"STEP":d=function(t){return{frame:r.input[t],value:l(),interpolation:e.AnimationKeyInterpolation.STEP}};break;case"LINEAR":d=function(e){return{frame:r.input[e],value:l()}};break;case"CUBICSPLINE":d=function(e){return{frame:r.input[e],inTangent:l(),value:l(),outTangent:l()}}}var c;if(1===r.input.length){var h=d(0);c=[{frame:h.frame,value:h.value},{frame:h.frame+1,value:h.value}]}else{c=new Array(r.input.length);for(var _=0;_<r.input.length;_++)c[_]=d(_)}if("influence"===n)for(var f=0;f<s._numMorphTargets;f++)!(function(t){var r=i.name+"_channel"+i.targetedAnimations.length,a=new e.Animation(r,n,1,o);a.setKeys(c.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[t]:void 0,value:e.value[t],outTangent:e.outTangent?e.outTangent[t]:void 0}})));for(var l=0,u=s._primitiveBabylonMeshes;l<u.length;l++){var d=u[l],h=d.morphTargetManager.getTarget(t);i.addTargetedAnimation(a,h)}})(f);else{var p=i.name+"_channel"+i.targetedAnimations.length,y=new e.Animation(p,n,1,o);if(y.setKeys(c),s._babylonAnimationTargets)for(var b=0,m=s._babylonAnimationTargets;b<m.length;b++){var v=m[b];i.addTargetedAnimation(y,v)}}}))},r.prototype._loadAnimationSamplerAsync=function(e,t){if(t._data)return t._data;var n=t.interpolation||"LINEAR";switch(n){case"STEP":case"LINEAR":case"CUBICSPLINE":break;default:throw new Error(e+": Invalid interpolation "+t.interpolation)}var o,a,i=r._GetProperty(e+"/input",this._gltf.accessors,t.input),s=r._GetProperty(e+"/output",this._gltf.accessors,t.output);return t._data=Promise.all([this._loadAccessorAsync("#/accessors/"+i._index,i).then((function(e){o=e})),this._loadAccessorAsync("#/accessors/"+s._index,s).then((function(e){a=e}))]).then((function(){return{input:o,interpolation:n,output:a}})),t._data},r.prototype._loadBufferAsync=function(e,t){if(t._data)return t._data;if(!t.uri)throw new Error(e+": Uri is missing");return t._data=this._loadUriAsync(e,t.uri),t._data},r.prototype._loadBufferViewAsync=function(e,t){if(t._data)return t._data;var n=r._GetProperty(e+"/buffer",this._gltf.buffers,t.buffer);return t._data=this._loadBufferAsync("#/buffers/"+n._index,n).then((function(r){try{return new Uint8Array(r.buffer,r.byteOffset+(t.byteOffset||0),t.byteLength)}catch(t){throw new Error(e+": "+t.message)}})),t._data},r.prototype._loadAccessorAsync=function(t,n){var o=this;if(n.sparse)throw new Error(t+": Sparse accessors are not currently supported");if(n._data)return n._data;var a=r._GetProperty(t+"/bufferView",this._gltf.bufferViews,n.bufferView);return n._data=this._loadBufferViewAsync("#/bufferViews/"+a._index,a).then((function(i){var s=r._GetNumComponents(t,n.type),l=n.byteOffset||0,u=a.byteStride;0===u&&e.Tools.Warn(t+": Byte stride of 0 is not valid");try{switch(n.componentType){case 5120:return o._buildArrayBuffer(Float32Array,i,l,n.count,s,u);case 5121:return o._buildArrayBuffer(Uint8Array,i,l,n.count,s,u);case 5122:return o._buildArrayBuffer(Int16Array,i,l,n.count,s,u);case 5123:return o._buildArrayBuffer(Uint16Array,i,l,n.count,s,u);case 5125:return o._buildArrayBuffer(Uint32Array,i,l,n.count,s,u);case 5126:return o._buildArrayBuffer(Float32Array,i,l,n.count,s,u);default:throw new Error(t+": Invalid component type "+n.componentType)}}catch(e){throw new Error(t+": "+e)}})),n._data},r.prototype._buildArrayBuffer=function(e,t,r,n,o,a){r+=t.byteOffset;var i=n*o;if(!a||a===o*e.BYTES_PER_ELEMENT)return new e(t.buffer,r,i);for(var s=a/e.BYTES_PER_ELEMENT,l=new e(t.buffer,r,s*n),u=new e(i),d=0,c=0;c<i;){for(var h=0;h<o;h++)u[c]=l[d+h],c++;d+=s}return u},r.prototype._getDefaultMaterial=function(){var t="__gltf_default",r=this._babylonScene.getMaterialByName(t);return r||(r=new e.PBRMaterial(t,this._babylonScene),r.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE,r.sideOrientation=this._babylonScene.useRightHandedSystem?e.Material.CounterClockWiseSideOrientation:e.Material.ClockWiseSideOrientation,r.metallic=1,r.roughness=1,this.onMaterialLoadedObservable.notifyObservers(r)),r},r.prototype._loadMaterialMetallicRoughnessPropertiesAsync=function(t,r){var n=new Array,o=r._babylonMaterial;o.metallic=1,o.roughness=1;var a=r.pbrMetallicRoughness;return a&&(a.baseColorFactor?(o.albedoColor=e.Color3.FromArray(a.baseColorFactor),o.alpha=a.baseColorFactor[3]):o.albedoColor=e.Color3.White(),o.metallic=void 0==a.metallicFactor?1:a.metallicFactor,o.roughness=void 0==a.roughnessFactor?1:a.roughnessFactor,a.baseColorTexture&&n.push(this._loadTextureAsync(t+"/baseColorTexture",a.baseColorTexture,(function(e){o.albedoTexture=e}))),a.metallicRoughnessTexture&&(n.push(this._loadTextureAsync(t+"/metallicRoughnessTexture",a.metallicRoughnessTexture,(function(e){o.metallicTexture=e}))),o.useMetallnessFromMetallicTextureBlue=!0,o.useRoughnessFromMetallicTextureGreen=!0,o.useRoughnessFromMetallicTextureAlpha=!1)),this._loadMaterialAlphaProperties(t,r),Promise.all(n).then((function(){}))},r.prototype._loadMaterialAsync=function(e,r,n){var o=t.GLTFLoaderExtension._LoadMaterialAsync(this,e,r,n);if(o)return o;if(r._babylonMeshes=r._babylonMeshes||[],r._babylonMeshes.push(n),r._loaded)return n.material=r._babylonMaterial,r._loaded;var a=new Array,i=this._createMaterial(r);return r._babylonMaterial=i,a.push(this._loadMaterialBasePropertiesAsync(e,r)),a.push(this._loadMaterialMetallicRoughnessPropertiesAsync(e,r)),this.onMaterialLoadedObservable.notifyObservers(i),n.material=i,r._loaded=Promise.all(a).then((function(){}))},r.prototype._createMaterial=function(t){var r=new e.PBRMaterial(t.name||"material"+t._index,this._babylonScene);return r.sideOrientation=this._babylonScene.useRightHandedSystem?e.Material.CounterClockWiseSideOrientation:e.Material.ClockWiseSideOrientation,r},r.prototype._loadMaterialBasePropertiesAsync=function(t,r){var n=new Array,o=r._babylonMaterial;return o.emissiveColor=r.emissiveFactor?e.Color3.FromArray(r.emissiveFactor):new e.Color3(0,0,0),r.doubleSided&&(o.backFaceCulling=!1,o.twoSidedLighting=!0),r.normalTexture&&(n.push(this._loadTextureAsync(t+"/normalTexture",r.normalTexture,(function(e){o.bumpTexture=e}))),o.invertNormalMapX=!this._babylonScene.useRightHandedSystem,o.invertNormalMapY=this._babylonScene.useRightHandedSystem,void 0!=r.normalTexture.scale&&(o.bumpTexture.level=r.normalTexture.scale)),r.occlusionTexture&&(n.push(this._loadTextureAsync(t+"/occlusionTexture",r.occlusionTexture,(function(e){o.ambientTexture=e}))),o.useAmbientInGrayScale=!0,void 0!=r.occlusionTexture.strength&&(o.ambientTextureStrength=r.occlusionTexture.strength)),r.emissiveTexture&&n.push(this._loadTextureAsync(t+"/emissiveTexture",r.emissiveTexture,(function(e){o.emissiveTexture=e}))),Promise.all(n).then((function(){}))},r.prototype._loadMaterialAlphaProperties=function(t,r){var n=r._babylonMaterial;switch(r.alphaMode||"OPAQUE"){case"OPAQUE":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHATEST,n.alphaCutOff=void 0==r.alphaCutoff?.5:r.alphaCutoff,n.alpha&&(0===n.alpha?n.alphaCutOff=1:n.alphaCutOff/=n.alpha,n.alpha=1),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHABLEND,n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(t+": Invalid alpha mode "+r.alphaMode)}},r.prototype._loadTextureAsync=function(t,n,o){var a=this,i=r._GetProperty(t+"/index",this._gltf.textures,n.index);t="#/textures/"+n.index
- ;var s=new Array,l=void 0==i.sampler?this._defaultSampler:r._GetProperty(t+"/sampler",this._gltf.samplers,i.sampler),u=this._loadSampler("#/samplers/"+l._index,l),d=new e.Deferred,c=new e.Texture(null,this._babylonScene,u.noMipMaps,!1,u.samplingMode,function(){a._disposed||d.resolve()},function(e,r){a._disposed||d.reject(new Error(t+": "+(r&&r.message)?r.message:e||"Failed to load texture"))});s.push(d.promise),c.name=i.name||"texture"+i._index,c.wrapU=u.wrapU,c.wrapV=u.wrapV,c.coordinatesIndex=n.texCoord||0;var h=r._GetProperty(t+"/source",this._gltf.images,i.source);return s.push(this._loadImageAsync("#/images/"+h._index,h).then((function(e){c.updateURL(e)}))),o(c),this.onTextureLoadedObservable.notifyObservers(c),Promise.all(s).then((function(){}))},r.prototype._loadSampler=function(e,t){return t._data||(t._data={noMipMaps:9728===t.minFilter||9729===t.minFilter,samplingMode:r._GetTextureSamplingMode(e,t.magFilter,t.minFilter),wrapU:r._GetTextureWrapMode(e,t.wrapS),wrapV:r._GetTextureWrapMode(e,t.wrapT)}),t._data},r.prototype._loadImageAsync=function(e,t){if(t._objectURL)return t._objectURL;var n;if(t.uri)n=this._loadUriAsync(e,t.uri);else{var o=r._GetProperty(e+"/bufferView",this._gltf.bufferViews,t.bufferView);n=this._loadBufferViewAsync("#/bufferViews/"+o._index,o)}return t._objectURL=n.then((function(e){return URL.createObjectURL(new Blob([e],{type:t.mimeType}))})),t._objectURL},r.prototype._loadUriAsync=function(n,o){var a=this,i=t.GLTFLoaderExtension._LoadUriAsync(this,n,o);if(i)return i;if(!r._ValidateUri(o))throw new Error(n+": Uri '"+o+"' is invalid");return e.Tools.IsBase64(o)?Promise.resolve(new Uint8Array(e.Tools.DecodeBase64(o))):new Promise(function(t,r){var i=e.Tools.LoadFile(a._rootUrl+o,(function(e){a._disposed||t(new Uint8Array(e))}),(function(t){if(!a._disposed)try{i&&a._state===e.GLTFLoaderState.Loading&&(i._lengthComputable=t.lengthComputable,i._loaded=t.loaded,i._total=t.total,a._onProgress())}catch(e){r(e)}}),a._babylonScene.database,!0,(function(t,i){a._disposed||r(new e.LoadFileError(n+": Failed to load '"+o+"'"+(t?": "+t.status+" "+t.statusText:""),t))}));a._requests.push(i)})},r.prototype._onProgress=function(){if(this._progressCallback){for(var t=!0,r=0,n=0,o=0,a=this._requests;o<a.length;o++){var i=a[o];if(void 0===i._lengthComputable||void 0===i._loaded||void 0===i._total)return;t=t&&i._lengthComputable,r+=i._loaded,n+=i._total}this._progressCallback(new e.SceneLoaderProgressEvent(t,r,t?n:0))}},r._GetProperty=function(e,t,r){if(!t||void 0==r||!t[r])throw new Error(e+": Failed to find index "+r);return t[r]},r._GetTextureWrapMode=function(t,r){switch(r=void 0==r?10497:r){case 33071:return e.Texture.CLAMP_ADDRESSMODE;case 33648:return e.Texture.MIRROR_ADDRESSMODE;case 10497:return e.Texture.WRAP_ADDRESSMODE;default:return e.Tools.Warn(t+": Invalid texture wrap mode "+r),e.Texture.WRAP_ADDRESSMODE}},r._GetTextureSamplingMode=function(t,r,n){if(r=void 0==r?9729:r,n=void 0==n?9987:n,9729===r)switch(n){case 9728:return e.Texture.LINEAR_NEAREST;case 9729:return e.Texture.LINEAR_LINEAR;case 9984:return e.Texture.LINEAR_NEAREST_MIPNEAREST;case 9985:return e.Texture.LINEAR_LINEAR_MIPNEAREST;case 9986:return e.Texture.LINEAR_NEAREST_MIPLINEAR;case 9987:return e.Texture.LINEAR_LINEAR_MIPLINEAR;default:return e.Tools.Warn(t+": Invalid texture minification filter "+n),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(9728!==r&&e.Tools.Warn(t+": Invalid texture magnification filter "+r),n){case 9728:return e.Texture.NEAREST_NEAREST;case 9729:return e.Texture.NEAREST_LINEAR;case 9984:return e.Texture.NEAREST_NEAREST_MIPNEAREST;case 9985:return e.Texture.NEAREST_LINEAR_MIPNEAREST;case 9986:return e.Texture.NEAREST_NEAREST_MIPLINEAR;case 9987:return e.Texture.NEAREST_LINEAR_MIPLINEAR;default:return e.Tools.Warn(t+": Invalid texture minification filter "+n),e.Texture.NEAREST_NEAREST_MIPNEAREST}},r._GetNumComponents=function(e,t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16}throw new Error(e+": Invalid type "+t)},r._ValidateUri=function(t){return e.Tools.IsBase64(t)||-1===t.indexOf("..")},r.prototype._compileMaterialsAsync=function(){var e=new Array;if(this._gltf.materials)for(var t=0,r=this._gltf.materials;t<r.length;t++){var n=r[t],o=n._babylonMaterial,a=n._babylonMeshes;if(o&&a)for(var i=0,s=a;i<s.length;i++){var l=s[i];e.push(o.forceCompilationAsync(l)),this.useClipPlane&&e.push(o.forceCompilationAsync(l,{clipPlane:!0}))}}return Promise.all(e).then((function(){}))},r.prototype._compileShadowGeneratorsAsync=function(){for(var e=new Array,t=this._babylonScene.lights,r=0,n=t;r<n.length;r++){var o=n[r],a=o.getShadowGenerator();a&&e.push(a.forceCompilationAsync())}return Promise.all(e).then((function(){}))},r.prototype._clear=function(){for(var e=0,t=this._requests;e<t.length;e++){t[e].abort()}if(this._requests.length=0,this._gltf&&this._gltf.images)for(var r=0,n=this._gltf.images;r<n.length;r++){var o=n[r];o._objectURL&&(o._objectURL.then((function(e){URL.revokeObjectURL(e)})),o._objectURL=void 0)}delete this._gltf,delete this._babylonScene,this._completePromises.length=0;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()},r.prototype._applyExtensions=function(e){for(var t=0,n=r._Names;t<n.length;t++){var o=n[t],a=this._extensions[o];if(a.enabled){var i=e(a);if(i)return i}}return null},r._Names=new Array,r._Factories={},r})();t.GLTFLoader=r,e.GLTFFileLoader.CreateGLTFLoaderV2=function(){return new r}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(e){this.enabled=!0,this._loader=e}return e.prototype.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){return null},e.prototype._loadUriAsync=function(e,t){return null},e.prototype._loadExtensionAsync=function(e,t,r){if(!t.extensions)return null;var n=t.extensions,o=n[this.name];if(!o)return null;delete n[this.name];try{return r(e+"/extensions/"+this.name,o)}finally{n[this.name]=o}},e._LoadSceneAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadSceneAsync(t,r)}))},e._LoadNodeAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadNodeAsync(t,r)}))},e._LoadVertexDataAsync=function(e,t,r,n){return e._applyExtensions((function(e){return e._loadVertexDataAsync(t,r,n)}))},e._LoadMaterialAsync=function(e,t,r,n){return e._applyExtensions((function(e){return e._loadMaterialAsync(t,r,n)}))},e._LoadUriAsync=function(e,t,r){return e._applyExtensions((function(e){return e._loadUriAsync(t,r)}))},e})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __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]=new e.Deferred);var o=n._loader._loadNodeAsync("#/nodes/"+r._index,r).then((function(){if(0!==t){i[t-1]._babylonMesh.setEnabled(!1)}if(t!==i.length-1){var e=i[t+1]._index;n._loadNodeSignals[e].resolve(),delete n._loadNodeSignals[e]}}));0===t?a=o:(n._loader._completePromises.push(o),n._loadingNodeLOD=null)})(s);return a}))},o.prototype._loadMaterialAsync=function(t,r,n){var o=this;return this._loadingNodeLOD?null:this._loadExtensionAsync(t,r,(function(t,a){for(var i,s=o._getLODs(t,r,o._loader._gltf.materials,a.ids),l=0;l<s.length;l++)!(function(t){var r=s[t];0!==t&&(o._loadingMaterialLOD=r,o._loadMaterialSignals[r._index]=new e.Deferred);var a=o._loader._loadMaterialAsync("#/materials/"+r._index,r,n).then((function(){if(t!==s.length-1){var e=s[t+1]._index;o._loadMaterialSignals[e].resolve(),delete o._loadMaterialSignals[e]}}));0===t?i=a:(o._loader._completePromises.push(a),o._loadingMaterialLOD=null)})(l);return i}))},o.prototype._loadUriAsync=function(e,t){var r=this;if(this._loadingMaterialLOD){var n=this._loadingMaterialLOD._index;return this._loadMaterialSignals[n].promise.then((function(){return r._loader._loadUriAsync(e,t)}))}if(this._loadingNodeLOD){var n=this._loadingNodeLOD._index;return this._loadNodeSignals[n].promise.then((function(){return r._loader._loadUriAsync(e,t)}))}return null},o.prototype._getLODs=function(e,r,n,o){if(this.maxLODsToLoad<=0)throw new Error("maxLODsToLoad must be greater than zero");for(var a=new Array,i=o.length-1;i>=0;i--)if(a.push(t.GLTFLoader._GetProperty(e+"/ids/"+o[i],n,o[i])),a.length===this.maxLODsToLoad)return a;return a.push(r),a},o})(t.GLTFLoaderExtension);r.MSFT_lod=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __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.DecoderUrl||(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 d=t.GLTFLoader._GetProperty(i,a._loader._gltf.bufferViews,s.bufferView);return a._loader._loadBufferViewAsync("#/bufferViews/"+d._index,d).then((function(t){try{return a._dracoCompression||(a._dracoCompression=new e.DracoCompression),a._dracoCompression.decodeMeshAsync(t,l)}catch(e){throw new Error(r+": "+e.message)}}))}))},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){var n=this;return this._loadExtensionAsync(e,t,(function(e,o){if(t._babylonMeshes=t._babylonMeshes||[],t._babylonMeshes.push(r),t._loaded)return r.material=t._babylonMaterial,t._loaded;var a=new Array,i=n._loader._createMaterial(t);return t._babylonMaterial=i,a.push(n._loader._loadMaterialBasePropertiesAsync(e,t)),a.push(n._loadSpecularGlossinessPropertiesAsync(n._loader,e,t,o)),n._loader.onMaterialLoadedObservable.notifyObservers(i),r.material=i,t._loaded=Promise.all(a).then((function(){}))}))},r.prototype._loadSpecularGlossinessPropertiesAsync=function(t,r,n,o){var a=new Array,i=n._babylonMaterial;return o.diffuseFactor?(i.albedoColor=e.Color3.FromArray(o.diffuseFactor),i.alpha=o.diffuseFactor[3]):i.albedoColor=e.Color3.White(),i.reflectivityColor=o.specularFactor?e.Color3.FromArray(o.specularFactor):e.Color3.White(),i.microSurface=void 0==o.glossinessFactor?1:o.glossinessFactor,o.diffuseTexture&&a.push(t._loadTextureAsync(r+"/diffuseTexture",o.diffuseTexture,(function(e){i.albedoTexture=e}))),o.specularGlossinessTexture&&(a.push(t._loadTextureAsync(r+"/specularGlossinessTexture",o.specularGlossinessTexture,(function(e){i.reflectivityTexture=e}))),i.reflectivityTexture.hasAlpha=!0,i.useMicroSurfaceFromReflectivityMapAlpha=!0),t._loadMaterialAlphaProperties(r,n),Promise.all(a).then((function(){}))},r})(t.GLTFLoaderExtension);r.KHR_materials_pbrSpecularGlossiness=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __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),d=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(d,e.Vector3.Forward(),a._loader._babylonScene);break;case n.POINT:s=new e.PointLight(d,e.Vector3.Zero(),a._loader._babylonScene);break;case n.SPOT:var c=u,h=c.outerConeAngle||Math.PI/4;s=new e.SpotLight(d,e.Vector3.Zero(),e.Vector3.Forward(),h,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={}));
|