babylon.glTF2FileLoader.min.js 44 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.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._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,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"loaderExtensions",{get:function(){return this._loader?this._loader.extensions:null},enumerable:!0,configurable:!0}),n.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this.onParsedObservable.clear(),this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCompleteObservable.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),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.onCompleteObservable.add((function(){return t.onCompleteObservable.notifyObservers(t)})),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.onCompleteObservable=new e.Observable;for(var t=0,n=r._Names;t<n.length;t++){var o=n[t],a=r._Factories[o](this);this._extensions[o]=a}}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}),Object.defineProperty(r.prototype,"extensions",{get:function(){return this.extensions},enumerable:!0,configurable:!0}),r.prototype.dispose=function(){this._disposed||(this._disposed=!0,this._abortRequests(),this._releaseResources(),this.onDisposeObservable.notifyObservers(this))},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()}}))}))},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);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(){Promise.all(s._completePromises).then((function(){s._releaseResources(),s._state=e.GLTFLoaderState.Complete,s.onCompleteObservable.notifyObservers(s)})).catch((function(t){e.Tools.Error("glTF Loader: "+t.message),s.dispose()}))}))})).catch((function(t){throw e.Tools.Error("glTF Loader: "+t.message),s.dispose(),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._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];o._babylonMesh&&e.push(o._babylonMesh)}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,c=o.children;u<c.length;u++){var d=c[u],h=r._GetProperty(n+"/children/"+d,this._gltf.nodes,d);i.push(this._loadNodeAsync("#/nodes/"+d,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 c=r._GetProperty(e+"/skin",this._gltf.skins,n.skin);a.push(this._loadSkinAsync("#/skins/"+c._index,n,o,c))}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 Promise.all(s).then((function(){l.setEnabled(!0)}))},r.prototype._loadVertexDataAsync=function(t,n,o){var a=this,i=n.attributes;if(!i)throw new Error(t+": Attributes are missing");if(n.mode&&4!==n.mode)throw new Error(t+": Mode "+n.mode+" is not currently supported");var s=new Array,l=new e.VertexData;if(void 0==n.indices){var u=i.POSITION;if(void 0!=u){var c=r._GetProperty(t+"/attributes/POSITION",this._gltf.accessors,u);l.indices=new Uint32Array(c.count);for(var d=0;d<l.indices.length;d++)l.indices[d]=d}}else{var h=r._GetProperty(t+"/indices",this._gltf.accessors,n.indices);s.push(this._loadAccessorAsync("#/accessors/"+h._index,h).then((function(e){l.indices=e})))}var _=function(e,n){if(void 0!=i[e]){o._delayInfo=o._delayInfo||[],-1===o._delayInfo.indexOf(n)&&o._delayInfo.push(n);var u=r._GetProperty(t+"/attributes/"+e,a._gltf.accessors,i[e]);s.push(a._loadAccessorAsync("#/accessors/"+u._index,u).then((function(a){var i=r._ConvertToFloat32Array(t,u,a);"COLOR_0"===e&&(o.hasVertexAlpha=!0,"VEC3"===u.type&&(i=r._ConvertVec3ToVec4(t,i))),l.set(i,n)})))}};return _("POSITION",e.VertexBuffer.PositionKind),_("NORMAL",e.VertexBuffer.NormalKind),_("TANGENT",e.VertexBuffer.TangentKind),_("TEXCOORD_0",e.VertexBuffer.UVKind),_("TEXCOORD_1",e.VertexBuffer.UV2Kind),_("JOINTS_0",e.VertexBuffer.MatricesIndicesKind),_("WEIGHTS_0",e.VertexBuffer.MatricesWeightsKind),_("COLOR_0",e.VertexBuffer.ColorKind),Promise.all(s).then((function(){return l}))},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?(i(),o._loaded):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 c;switch(r.interpolation){case"STEP":c=function(t){return{frame:r.input[t],value:l(),interpolation:e.AnimationKeyInterpolation.STEP}};break;case"LINEAR":c=function(e){return{frame:r.input[e],value:l()}};break;case"CUBICSPLINE":c=function(e){return{frame:r.input[e],inTangent:l(),value:l(),outTangent:l()}}}var d;if(1===r.input.length){var h=c(0);d=[{frame:h.frame,value:h.value},{frame:h.frame+1,value:h.value}]}else{d=new Array(r.input.length);for(var _=0;_<r.input.length;_++)d[_]=c(_)}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(d.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[t]:void 0,value:e.value[t],outTangent:e.outTangent?e.outTangent[t]:void 0}})));for(var l=0,u=s._primitiveBabylonMeshes;l<u.length;l++){var c=u[l],h=c.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(d),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),c=0,d=0;d<i;){for(var h=0;h<o;h++)u[d]=l[c+h],d++;c+=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=r._GetProperty(t+"/index",this._gltf.textures,n.index);t="#/textures/"+n.index;var i=new Array,s=void 0==a.sampler?this._defaultSampler:r._GetProperty(t+"/sampler",this._gltf.samplers,a.sampler),l=this._loadSampler("#/samplers/"+s._index,s),u=new e.Deferred,c=new e.Texture(null,this._babylonScene,l.noMipMaps,!1,l.samplingMode,function(){u.resolve()},function(e,r){u.reject(new Error(t+": "+(r&&r.message)?r.message:e||"Failed to load texture"))});i.push(u.promise),c.name=a.name||"texture"+a._index,c.wrapU=l.wrapU,c.wrapV=l.wrapV,c.coordinatesIndex=n.texCoord||0;var d=r._GetProperty(t+"/source",this._gltf.images,a.source);return i.push(this._loadImageAsync("#/images/"+d._index,d).then((function(e){c.updateURL(e)}))),o(c),this.onTextureLoadedObservable.notifyObservers(c),Promise.all(i).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
  2. ;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){t(new Uint8Array(e))}),(function(t){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,a){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._abortRequests=function(){for(var e=0,t=this._requests;e<t.length;e++){t[e].abort()}this._requests.length=0},r.prototype._releaseResources=function(){if(this._gltf.images)for(var e=0,t=this._gltf.images;e<t.length;e++){var r=t[e];r._objectURL&&(r._objectURL.then((function(e){URL.revokeObjectURL(e)})),r._objectURL=void 0)}},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._loadSceneAsync=function(e,t){return null},e.prototype._loadNodeAsync=function(e,t){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){var n=this;if(!t.extensions)return null;var o=t.extensions,a=o[this._name];return a?(delete o[this._name],r(e+"extensions/"+this._name,a).then((function(){o[n._name]=a}))):null},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._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=(function(r){function n(){var e=null!==r&&r.apply(this,arguments)||this;return e._loadingNodeLOD=null,e._loadNodeSignals={},e._loadingMaterialLOD=null,e._loadMaterialSignals={},e}return __extends(n,r),Object.defineProperty(n.prototype,"_name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),n.prototype._loadNodeAsync=function(t,r){var o=this;return this._loadExtensionAsync(t,r,(function(t,a){for(var i,s=n._GetLODs(t,r,o._loader._gltf.nodes,a.ids),l=0;l<s.length;l++)!(function(t){var r=s[t];0!==t&&(o._loadingNodeLOD=r,o._loadNodeSignals[r._index]=new e.Deferred);var n=o._loader._loadNodeAsync("#/nodes/"+r._index,r).then((function(){if(0!==t){s[t-1]._babylonMesh.setEnabled(!1)}if(t!==s.length-1){var e=s[t+1]._index;o._loadNodeSignals[e].resolve(),delete o._loadNodeSignals[e]}}));0===t?i=n:(o._loader._completePromises.push(n),o._loadingNodeLOD=null)})(l);return i}))},n.prototype._loadMaterialAsync=function(t,r,o){var a=this;return this._loadExtensionAsync(t,r,(function(t,i){for(var s,l=n._GetLODs(t,r,a._loader._gltf.materials,i.ids),u=0;u<l.length;u++)!(function(t){var r=l[t];0!==t&&(a._loadingMaterialLOD=r,a._loadMaterialSignals[r._index]=new e.Deferred);var n=a._loader._loadMaterialAsync("#/materials/"+r._index,r,o).then((function(){if(t!==l.length-1){var e=l[t+1]._index;a._loadMaterialSignals[e].resolve(),delete a._loadMaterialSignals[e]}}));0===t?s=n:(a._loader._completePromises.push(n),a._loadingMaterialLOD=null)})(u);return s}))},n.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},n._GetLODs=function(e,r,n,o){for(var a=[r],i=0,s=o;i<s.length;i++){var l=s[i];a.push(t.GLTFLoader._GetProperty(e+"/ids/"+l,n,l))}return a.reverse()},n})(t.GLTFLoaderExtension);r.MSFTLOD=n,t.GLTFLoader._Register("MSFT_lod",(function(e){return new n(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(){return null!==t&&t.apply(this,arguments)||this}return __extends(r,t),Object.defineProperty(r.prototype,"_name",{get:function(){return n},enumerable:!0,configurable:!0}),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.KHRMaterialsPbrSpecularGlossiness=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;!(function(e){e.AMBIENT="ambient",e.DIRECTIONAL="directional",e.POINT="point",e.SPOT="spot"})(n||(n={}));var o=(function(r){function o(){return null!==r&&r.apply(this,arguments)||this}return __extends(o,r),Object.defineProperty(o.prototype,"_name",{get:function(){return"KHR_lights"},enumerable:!0,configurable:!0}),o.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}))},o.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,h=d.outerConeAngle||Math.PI/4;s=new e.SpotLight(c,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(o.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}),o})(t.GLTFLoaderExtension);r.KHRLights=o,t.GLTFLoader._Register("KHR_lights",(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));