babylon.glTF2FileLoader.min.js 49 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={}));var o=(function(){function o(){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(o.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),o.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()},o.prototype.importMeshAsync=function(t,r,o,n,a,i,s){try{var l=this._parse(o);this._loader=this._getLoader(l),this._loader.importMeshAsync(t,r,l,n,a,i,s)}catch(t){s?s(t.message,t):e.Tools.Error(t.message)}},o.prototype.loadAsync=function(t,r,o,n,a,i){try{var s=this._parse(r);this._loader=this._getLoader(s),this._loader.loadAsync(t,s,o,n,a,i)}catch(t){i?i(t.message,t):e.Tools.Error(t.message)}},o.prototype.loadAssetsAsync=function(t,r,o,n,a,i){try{var s=this._parse(r);this._loader=this._getLoader(s),this._loader.importMeshAsync(null,t,s,o,(function(r,o,a){var i=new e.AssetContainer(t);Array.prototype.push.apply(i.meshes,r),Array.prototype.push.apply(i.particleSystems,o),Array.prototype.push.apply(i.skeletons,a),i.removeAllFromScene(),n(i)}),a,i)}catch(t){i?i(t.message,t):e.Tools.Error(t.message)}},o.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},o.prototype.createPlugin=function(){return new o},o.prototype._parse=function(e){var t;return t=e instanceof ArrayBuffer?o._parseBinary(e):{json:JSON.parse(e),bin:null},this.onParsedObservable.notifyObservers(t),t},o.prototype._getLoader=function(e){var t=this,r={major:2,minor:0},n=e.json.asset||{},a=o._parseVersion(n.version);if(!a)throw new Error("Invalid version: "+n.version);if(void 0!==n.minVersion){var i=o._parseVersion(n.minVersion);if(!i)throw new Error("Invalid minimum version: "+n.minVersion);if(o._compareVersion(i,r)>0)throw new Error("Incompatible minimum version: "+n.minVersion)}var s={1:o.CreateGLTFLoaderV1,2:o.CreateGLTFLoaderV2},l=s[a.major];if(!l)throw new Error("Unsupported version: "+n.version);var d=l();return d.coordinateSystemMode=this.coordinateSystemMode,d.animationStartMode=this.animationStartMode,d.compileMaterials=this.compileMaterials,d.useClipPlane=this.useClipPlane,d.compileShadowGenerators=this.compileShadowGenerators,d.onMeshLoadedObservable.add((function(e){return t.onMeshLoadedObservable.notifyObservers(e)})),d.onTextureLoadedObservable.add((function(e){return t.onTextureLoadedObservable.notifyObservers(e)})),d.onMaterialLoadedObservable.add((function(e){return t.onMaterialLoadedObservable.notifyObservers(e)})),d.onCompleteObservable.add((function(){return t.onCompleteObservable.notifyObservers(t)})),d},o._parseBinary=function(e){var t={Magic:1179937895},r=new n(e),a=r.readUint32();if(a!==t.Magic)throw new Error("Unexpected magic: "+a);var i=r.readUint32();switch(i){case 1:return o._parseV1(r);case 2:return o._parseV2(r)}throw new Error("Unsupported version: "+i)},o._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 n,a=e.readUint32(),i=e.readUint32();switch(i){case t.JSON:n=JSON.parse(o._decodeBufferToText(e.readUint8Array(a)));break;default:throw new Error("Unexpected content format: "+i)}var s=e.getLength()-e.getPosition();return{json:n,bin:e.readUint8Array(s)}},o._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 n=e.readUint32();if(e.readUint32()!==t.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(o._decodeBufferToText(e.readUint8Array(n))),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}},o._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},o._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},o._decodeBufferToText=function(e){for(var t="",r=e.byteLength,o=0;o<r;o++)t+=String.fromCharCode(e[o]);return t},o.IncrementalLoading=!0,o.HomogeneousCoordinates=!1,o})();e.GLTFFileLoader=o;var n=(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 o)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT"})(e.EComponentType||(e.EComponentType={}));!(function(e){e[e.POINTS=0]="POINTS",e[e.LINES=1]="LINES",e[e.LINE_LOOP=2]="LINE_LOOP",e[e.LINE_STRIP=3]="LINE_STRIP",e[e.TRIANGLES=4]="TRIANGLES",e[e.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",e[e.TRIANGLE_FAN=6]="TRIANGLE_FAN"})(e.EMeshPrimitiveMode||(e.EMeshPrimitiveMode={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR"})(e.ETextureMagFilter||(e.ETextureMagFilter={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"})(e.ETextureMinFilter||(e.ETextureMinFilter={}));!(function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"})(e.ETextureWrapMode||(e.ETextureWrapMode={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function e(e){this._pendingCount=0,this._callback=e}return e.prototype._addPendingData=function(e){this._pendingCount++},e.prototype._removePendingData=function(e){0==--this._pendingCount&&this._callback()},e})(),o=(function(){function o(){this._disposed=!1,this._defaultSampler={},this._renderReady=!1,this._requests=new Array,this._renderReadyObservable=new e.Observable,this._renderPendingCount=0,this._loaderPendingCount=0,this._loaderTrackers=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}return o.RegisterExtension=function(r){if(o.Extensions[r.name])return void e.Tools.Error("Extension with the same name '"+r.name+"' already exists");o.Extensions[r.name]=r,t.GLTFLoaderExtension._Extensions.push(r)},o.prototype.dispose=function(){this._disposed||(this._disposed=!0,this._abortRequests(),this._releaseResources(),this.onDisposeObservable.notifyObservers(this))},o.prototype.importMeshAsync=function(e,t,r,o,n,a,i){var s=this;this._loadAsync(e,t,r,o,(function(){n&&n(s._getMeshes(),[],s._getSkeletons())}),a,i)},o.prototype.loadAsync=function(e,t,r,o,n,a){this._loadAsync(null,e,t,r,o,n,a)},o.prototype._loadAsync=function(e,t,r,o,n,a,i){var s=this;this._babylonScene=t,this._rootUrl=o,this._successCallback=n,this._progressCallback=a,this._errorCallback=i,this._tryCatchOnError((function(){s._loadData(r),s._addPendingData(s),s._loadDefaultScene(e),s._loadAnimations(),s._removePendingData(s)}))},o.prototype._onProgress=function(){if(this._progressCallback){for(var t=!0,r=0,o=0,n=0,a=this._requests;n<a.length;n++){var i=a[n];if(void 0===i._lengthComputable||void 0===i._loaded||void 0===i._total)return;t=t&&i._lengthComputable,r+=i._loaded,o+=i._total}this._progressCallback(new e.SceneLoaderProgressEvent(t,r,t?o:0))}},o.prototype._executeWhenRenderReady=function(e){this._renderReady?e():this._renderReadyObservable.add(e)},o.prototype._onRenderReady=function(){this._rootNode.babylonMesh.setEnabled(!0),this._startAnimations(),this._successCallback&&this._successCallback(),this._renderReadyObservable.notifyObservers(this)},o.prototype._onComplete=function(){this._abortRequests(),this._releaseResources(),this.onCompleteObservable.notifyObservers(this)},o.prototype._loadData=function(r){if(this._gltf=r.json,o._AssignIndices(this._gltf.accessors),o._AssignIndices(this._gltf.animations),o._AssignIndices(this._gltf.buffers),o._AssignIndices(this._gltf.bufferViews),o._AssignIndices(this._gltf.images),o._AssignIndices(this._gltf.materials),o._AssignIndices(this._gltf.meshes),o._AssignIndices(this._gltf.nodes),o._AssignIndices(this._gltf.samplers),o._AssignIndices(this._gltf.scenes),o._AssignIndices(this._gltf.skins),o._AssignIndices(this._gltf.textures),t.GLTFLoaderExtension.LoadRoot(this,"#/",this._gltf),r.bin){var n=this._gltf.buffers;if(n&&n[0]&&!n[0].uri){var a=n[0];(a.byteLength<r.bin.byteLength-3||a.byteLength>r.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+a.byteLength+") from JSON does not match chunk length ("+r.bin.byteLength+")"),a.loadedData=r.bin}else e.Tools.Warn("Unexpected BIN chunk")}},o.prototype._getMeshes=function(){var e=new Array;e.push(this._rootNode.babylonMesh);var t=this._gltf.nodes;if(t)for(var r=0,o=t;r<o.length;r++){var n=o[r];n.babylonMesh&&e.push(n.babylonMesh)}return e},o.prototype._getSkeletons=function(){var e=new Array,t=this._gltf.skins;if(t)for(var r=0,o=t;r<o.length;r++){var n=o[r];n.babylonSkeleton&&e.push(n.babylonSkeleton)}return e},o.prototype._startAnimations=function(){var t=this._gltf.animations;if(t){for(var r=0,o=t;r<o.length;r++){var n=o[r];n.babylonAnimationGroup.normalize()}switch(this.animationStartMode){case e.GLTFLoaderAnimationStartMode.NONE:break;case e.GLTFLoaderAnimationStartMode.FIRST:var n=t[0];n.babylonAnimationGroup.start(!0);break;case e.GLTFLoaderAnimationStartMode.ALL:for(var a=0,i=t;a<i.length;a++){var n=i[a];n.babylonAnimationGroup.start(!0)}break;default:return void e.Tools.Error("Invalid animation start mode "+this.animationStartMode)}}},o.prototype._loadDefaultScene=function(e){var t=o._GetProperty(this._gltf.scenes,this._gltf.scene||0);if(!t)throw new Error("Failed to find scene "+(this._gltf.scene||0));this._loadScene("#/scenes/"+t.index,t,e)},o.prototype._loadScene=function(r,n,a){var i=this;switch(t.GLTFLoaderExtension.LoadScene(this,r,n),this._rootNode={babylonMesh:new e.Mesh("__root__",this._babylonScene)},this.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(this._rootNode.rotation=[0,1,0,0],this._rootNode.scale=[1,1,-1],this._loadTransform(this._rootNode));break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:return void e.Tools.Error("Invalid coordinate system mode "+this.coordinateSystemMode)}this.onMeshLoadedObservable.notifyObservers(this._rootNode.babylonMesh);var s=n.nodes;if(this._traverseNodes(r,s,(function(e,t){return e.parent=t,!0}),this._rootNode),a){a instanceof Array||(a=[a]);var l=new Array;this._traverseNodes(r,s,(function(e){return-1===a.indexOf(e.name)||(l.push(e.index),e.parent=i._rootNode,!1)}),this._rootNode),s=l}for(var d=0,u=s;d<u.length;d++){var c=u[d],f=o._GetProperty(this._gltf.nodes,c);if(!f)throw new Error(r+": Failed to find node "+c);this._loadNode("#/nodes/"+c,f)}this._rootNode.babylonMesh.setEnabled(!1)},o.prototype._loadNode=function(r,n){if(!t.GLTFLoaderExtension.LoadNode(this,r,n)){if(n.babylonMesh=new e.Mesh(n.name||"mesh"+n.index,this._babylonScene),this._loadTransform(n),null!=n.mesh){var a=o._GetProperty(this._gltf.meshes,n.mesh);if(!a)throw new Error(r+": Failed to find mesh "+n.mesh);this._loadMesh("#/meshes/"+n.mesh,n,a)}if(n.babylonMesh.parent=n.parent.babylonMesh,n.babylonAnimationTargets=n.babylonAnimationTargets||[],n.babylonAnimationTargets.push(n.babylonMesh),null!=n.skin){var i=o._GetProperty(this._gltf.skins,n.skin);if(!i)throw new Error(r+": Failed to find skin "+n.skin);this._loadSkinAsync("#/skins/"+n.skin,i,(function(){n.babylonMesh.skeleton=i.babylonSkeleton,n.babylonMesh._refreshBoundingInfo(!0)})),n.babylonMesh.parent=this._rootNode.babylonMesh,n.babylonMesh.position=e.Vector3.Zero(),n.babylonMesh.rotationQuaternion=e.Quaternion.Identity(),n.babylonMesh.scaling=e.Vector3.One()}if(n.camera,n.children)for(var s=0,l=n.children;s<l.length;s++){var d=l[s],u=o._GetProperty(this._gltf.nodes,d);if(!u)throw new Error(r+": Failed to find child node "+d);this._loadNode("#/nodes/"+d,u)}this.onMeshLoadedObservable.notifyObservers(n.babylonMesh)}},o.prototype._loadMesh=function(t,r,n){var a=this,i=n.primitives;if(!i||0===i.length)throw new Error(t+": Primitives are missing");if(this._createMorphTargets(t,r,n),this._loadAllVertexDataAsync(t,n,(function(){a._loadMorphTargets(t,r,n);for(var o=new e.VertexData,s=0,l=i;s<l.length;s++){var d=l[s];o.merge(d.vertexData)}r.babylonMesh.hasVertexAlpha=n.hasVertexAlpha,new e.Geometry(r.babylonMesh.name,a._babylonScene,o,!1,r.babylonMesh),r.babylonMesh.subMeshes=[];for(var u=0,c=0,f=0;f<i.length;f++){var h=i[f].vertexData,p=h.positions.length,_=h.indices.length;e.SubMesh.AddToMesh(f,u,p,c,_,r.babylonMesh),u+=p,c+=_}})),1===i.length){var s=i[0];if(null==s.material)r.babylonMesh.material=this._getDefaultMaterial();else{var l=o._GetProperty(this._gltf.materials,s.material);if(!l)throw new Error(t+": Failed to find material "+s.material);this._loadMaterial("#/materials/"+l.index,l,(function(e,t){t&&a.onMaterialLoadedObservable.notifyObservers(e),r.babylonMesh.material=e}))}}else{var d=new e.MultiMaterial(r.babylonMesh.name,this._babylonScene);r.babylonMesh.material=d;for(var u=d.subMaterials,c=this,f=0;f<i.length;f++)!(function(e){var r=i[e];if(null==r.material)u[e]=c._getDefaultMaterial();else{var n=o._GetProperty(c._gltf.materials,r.material);if(!n)throw new Error(t+": Failed to find material "+r.material);c._loadMaterial("#/materials/"+n.index,n,(function(t,r){r&&a.onMaterialLoadedObservable.notifyObservers(t),u[e]=t}))}})(f)}},o.prototype._loadAllVertexDataAsync=function(e,t,r){for(var o=t.primitives,n=o.length,a=this,i=0;i<o.length;i++)!(function(i){var s=o[i];a._loadVertexDataAsync(e+"/primitive/"+i,t,s,(function(e){s.vertexData=e,0==--n&&r()}))})(i)},o.prototype._convertToFloat4TextureCoordArray=function(e,r,o){if(o.componentType==t.EComponentType.FLOAT)return r;var n=r,a=1;switch(o.componentType){case t.EComponentType.UNSIGNED_BYTE:a=1/255;break;case t.EComponentType.UNSIGNED_SHORT:a=1/65535;break;default:throw new Error(e+": Invalid component type ("+o.componentType+")")}for(var i=new Float32Array(2*o.count),s=0;s<i.length;++s)i[s]=n[s]*a;return i},o.prototype._convertToFloat4ColorArray=function(e,r,n){var a=o._GetNumComponents(e,n.type);if(4===a&&n.componentType===t.EComponentType.FLOAT)return r;var i=r,s=1;switch(n.componentType){case t.EComponentType.FLOAT:s=1;break;case t.EComponentType.UNSIGNED_BYTE:s=1/255;break;case t.EComponentType.UNSIGNED_SHORT:s=1/65535;break;default:throw new Error(e+": Invalid component type ("+n.componentType+")")}var l=new Float32Array(4*n.count);if(4===a)for(var d=0;d<l.length;++d)l[d]=i[d]*s;else for(var u=0,d=0;d<l.length;++d)l[d]=(d+1)%4==0?1:i[u++]*s;return l},o.prototype._loadVertexDataAsync=function(r,n,a,i){var s=this,l=a.attributes;if(!l)throw new Error(r+": Attributes are missing");if(a.mode&&a.mode!==t.EMeshPrimitiveMode.TRIANGLES)throw new Error(r+": Mode "+a.mode+" is not currently supported");var d=new e.VertexData,u=Object.keys(l).length,c=this;for(var f in l)!(function(t){var f=o._GetProperty(c._gltf.accessors,l[t]);if(!f)throw new Error(r+": Failed to find attribute '"+t+"' accessor "+l[t]);c._loadAccessorAsync("#/accessors/"+f.index,f,(function(l){switch(t){case"POSITION":d.positions=l;break;case"NORMAL":d.normals=l;break;case"TANGENT":d.tangents=l;break;case"TEXCOORD_0":d.uvs=s._convertToFloat4TextureCoordArray(r,l,f);break;case"TEXCOORD_1":d.uvs2=s._convertToFloat4TextureCoordArray(r,l,f);break;case"JOINTS_0":d.matricesIndices=new Float32Array(Array.prototype.slice.apply(l));break;case"WEIGHTS_0":d.matricesWeights=l;break;case"COLOR_0":d.colors=s._convertToFloat4ColorArray(r,l,f);var c=4===o._GetNumComponents(r,f.type);!n.hasVertexAlpha&&c&&(n.hasVertexAlpha=c);break;default:e.Tools.Warn(r+": Ignoring unrecognized attribute '"+t+"'")}if(0==--u)if(null==a.indices){d.indices=new Uint32Array(d.positions.length/3);for(var h=0;h<d.indices.length;h++)d.indices[h]=h;i(d)}else{var p=o._GetProperty(s._gltf.accessors,a.indices);if(!p)throw new Error(r+": Failed to find indices accessor "+a.indices);s._loadAccessorAsync("#/accessors/"+p.index,p,(function(e){d.indices=e,i(d)}))}}))})(f)},o.prototype._createMorphTargets=function(t,r,o){var n=o.primitives,a=n[0].targets;if(a){for(var i=0,s=n;i<s.length;i++){var l=s[i];if(!l.targets||l.targets.length!=a.length)throw new Error(t+": All primitives are required to list the same number of targets")}var d=new e.MorphTargetManager;r.babylonMesh.morphTargetManager=d;for(var u=0;u<a.length;u++){var c=r.weights?r.weights[u]:o.weights?o.weights[u]:0;d.addTarget(new e.MorphTarget("morphTarget"+u,c))}}},o.prototype._loadMorphTargets=function(t,r,o){var n=r.babylonMesh.morphTargetManager;n&&this._loadAllMorphTargetVertexDataAsync(t,r,o,(function(){for(var r=n.numTargets,a=0;a<r;a++){for(var i=new e.VertexData,s=0,l=o.primitives;s<l.length;s++){var d=l[s];i.merge(d.targetsVertexData[a],{tangentLength:3})}if(!i.positions)throw new Error(t+": Positions are missing");var u=n.getTarget(a);u.setPositions(i.positions),u.setNormals(i.normals),u.setTangents(i.tangents)}}))},o.prototype._loadAllMorphTargetVertexDataAsync=function(e,t,r,o){for(var n=r.primitives.length*t.babylonMesh.morphTargetManager.numTargets,a=this,i=0,s=r.primitives;i<s.length;i++){var l=s[i];!(function(t){var r=t.targets;t.targetsVertexData=new Array(r.length);for(var i=0;i<r.length;i++)!(function(i){a._loadMorphTargetVertexDataAsync(e+"/targets/"+i,t.vertexData,r[i],(function(e){t.targetsVertexData[i]=e,0==--n&&o()}))})(i)})(l)}},o.prototype._loadMorphTargetVertexDataAsync=function(t,r,n,a){var i=new e.VertexData,s=Object.keys(n).length,l=this;for(var d in n)!(function(d){var u=o._GetProperty(l._gltf.accessors,n[d]);if(!u)throw new Error(t+": Failed to find attribute '"+d+"' accessor "+n[d]);l._loadAccessorAsync("#/accessors/"+u.index,u,(function(o){var n=o;switch(d){case"POSITION":for(var l=0;l<n.length;l++)n[l]+=r.positions[l];i.positions=n;break;case"NORMAL":for(var l=0;l<n.length;l++)n[l]+=r.normals[l];i.normals=n;break;case"TANGENT":for(var l=0,u=0;l<n.length;l++,u++)n[l]+=r.tangents[u],(l+1)%3==0&&u++;i.tangents=n;break;default:e.Tools.Warn(t+": Ignoring unrecognized attribute '"+d+"'")}0==--s&&a(i)}))})(d)},o.prototype._loadTransform=function(t){var r=e.Vector3.Zero(),o=e.Quaternion.Identity(),n=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(n,o,r)}else t.translation&&(r=e.Vector3.FromArray(t.translation)),t.rotation&&(o=e.Quaternion.FromArray(t.rotation)),t.scale&&(n=e.Vector3.FromArray(t.scale));t.babylonMesh.position=r,t.babylonMesh.rotationQuaternion=o,t.babylonMesh.scaling=n},o.prototype._loadSkinAsync=function(t,r,n){var a=this;if(r.babylonSkeleton)return void n();var i="skeleton"+r.index;if(r.babylonSkeleton=new e.Skeleton(r.name||i,i,this._babylonScene),null==r.inverseBindMatrices)this._loadBones(t,r,null),n();else{var s=o._GetProperty(this._gltf.accessors,r.inverseBindMatrices);if(!s)throw new Error(t+": Failed to find inverse bind matrices attribute "+r.inverseBindMatrices);this._loadAccessorAsync("#/accessors/"+s.index,s,(function(e){a._loadBones(t,r,e),n()}))}},o.prototype._createBone=function(t,r,o,n,a,i){var s=new e.Bone(t.name||"bone"+t.index,r.babylonSkeleton,o,n,null,a,i);return t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(s),s},o.prototype._loadBones=function(e,t,r){for(var n={},a=0,i=t.joints;a<i.length;a++){var s=i[a],l=o._GetProperty(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find joint "+s);this._loadBone(l,t,r,n)}},o.prototype._loadBone=function(t,r,o,n){var a=n[t.index];if(a)return a;var i=r.joints.indexOf(t.index),s=e.Matrix.Identity();o&&-1!==i&&(s=e.Matrix.FromArray(o,16*i),s.invertToRef(s));var l=null;return t.parent!==this._rootNode&&(l=this._loadBone(t.parent,r,o,n),s.multiplyToRef(l.getInvertedAbsoluteTransform(),s)),a=this._createBone(t,r,l,this._getNodeMatrix(t),s,i),n[t.index]=a,a},o.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())},o.prototype._traverseNodes=function(e,t,r,n){for(var a=0,i=t;a<i.length;a++){var s=i[a],l=o._GetProperty(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find node "+s);this._traverseNode(e,l,r,n)}},o.prototype._traverseNode=function(e,r,o,n){t.GLTFLoaderExtension.TraverseNode(this,e,r,o,n)||o(r,n)&&r.children&&this._traverseNodes(e,r.children,o,r)},o.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e)for(var t=0;t<e.length;t++){var r=e[t];this._loadAnimation("#/animations/"+t,r)}},o.prototype._loadAnimation=function(t,r){r.babylonAnimationGroup=new e.AnimationGroup(r.name||"animation"+r.index,this._babylonScene);for(var n=0;n<r.channels.length;n++){var a=o._GetProperty(r.channels,n);if(!a)throw new Error(t+": Failed to find channel "+n);var i=o._GetProperty(r.samplers,a.sampler);if(!i)throw new Error(t+": Failed to find sampler "+a.sampler);this._loadAnimationChannel(r,t+"/channels/"+n,a,t+"/samplers/"+a.sampler,i)}},o.prototype._loadAnimationChannel=function(t,r,n,a,i){var s=o._GetProperty(this._gltf.nodes,n.target.node);if(!s)throw new Error(r+": Failed to find target node "+n.target.node);var l,d;switch(n.target.path){case"translation":l="position",d=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":l="rotationQuaternion",d=e.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":l="scaling",d=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":l="influence",d=e.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(r+": Invalid target path "+n.target.path)}var u,c,f=function(){if(u&&c){var r,o=0;switch(l){case"position":r=function(){var t=e.Vector3.FromArray(c,o);return o+=3,t};break;case"rotationQuaternion":r=function(){var t=e.Quaternion.FromArray(c,o);return o+=4,t};break;case"scaling":r=function(){var t=e.Vector3.FromArray(c,o);return o+=3,t};break;case"influence":r=function(){for(var e=s.babylonMesh.morphTargetManager.numTargets,t=new Array(e),r=0;r<e;r++)t[r]=c[o++];return t}}i.interpolation=i.interpolation||"LINEAR";var n;switch(i.interpolation){case"STEP":n=function(t){return{frame:u[t],value:r(),interpolation:e.AnimationKeyInterpolation.STEP}};break;case"LINEAR":n=function(e){return{frame:u[e],value:r()}};break;case"CUBICSPLINE":n=function(e){return{frame:u[e],inTangent:r(),value:r(),outTangent:r()}};break;default:throw new Error(a+": Invalid interpolation "+i.interpolation)}var f;if(1===u.length){var h=n(0);f=[{frame:h.frame,value:h.value},{frame:h.frame+1,value:h.value}]}else{f=new Array(u.length);for(var p=0;p<u.length;p++)f[p]=n(p)}if("influence"===l)for(var _=s.babylonMesh.morphTargetManager,b=0;b<_.numTargets;b++)!(function(r){var o=_.getTarget(r),n=t.babylonAnimationGroup.name+"_channel"+t.babylonAnimationGroup.targetedAnimations.length,a=new e.Animation(n,l,1,d);a.setKeys(f.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[r]:void 0,value:e.value[r],outTangent:e.outTangent?e.outTangent[r]:void 0}}))),t.babylonAnimationGroup.addTargetedAnimation(a,o)})(b);else{var y=t.babylonAnimationGroup.name+"_channel"+t.babylonAnimationGroup.targetedAnimations.length,v=new e.Animation(y,l,1,d);if(v.setKeys(f),s.babylonAnimationTargets)for(var m=0,T=s.babylonAnimationTargets;m<T.length;m++){var g=T[m];t.babylonAnimationGroup.addTargetedAnimation(v,g)}}}},h=o._GetProperty(this._gltf.accessors,i.input);if(!h)throw new Error(a+": Failed to find input accessor "+i.input);this._loadAccessorAsync("#/accessors/"+h.index,h,(function(e){u=e,f()}));var p=o._GetProperty(this._gltf.accessors,i.output);if(!p)throw new Error(a+": Failed to find output accessor "+i.output);this._loadAccessorAsync("#/accessors/"+p.index,p,(function(e){c=e,f()}))},o.prototype._loadBufferAsync=function(t,r,o){var n=this;if(this._addPendingData(r),r.loadedData)o(r.loadedData),this._removePendingData(r);else if(r.loadedObservable)r.loadedObservable.add((function(e){o(e.loadedData),n._removePendingData(e)}));else{if(!r.uri)throw new Error(t+": Uri is missing");r.loadedObservable=new e.Observable,r.loadedObservable.add((function(e){o(e.loadedData),n._removePendingData(e)})),this._loadUriAsync(t,r.uri,(function(e){r.loadedData=e,r.loadedObservable.notifyObservers(r),r.loadedObservable=void 0}))}},o.prototype._loadBufferViewAsync=function(e,t,r){var n=o._GetProperty(this._gltf.buffers,t.buffer);if(!n)throw new Error(e+": Failed to find buffer "+t.buffer);this._loadBufferAsync("#/buffers/"+n.index,n,(function(o){var n;try{n=new Uint8Array(o.buffer,o.byteOffset+(t.byteOffset||0),t.byteLength)}catch(t){throw new Error(e+": "+t.message)}r(n)}))},o.prototype._loadAccessorAsync=function(r,n,a){var i=this;if(n.sparse)throw new Error(r+": Sparse accessors are not currently supported");var s=o._GetProperty(this._gltf.bufferViews,n.bufferView);if(!s)throw new Error(r+": Failed to find buffer view "+n.bufferView);this._loadBufferViewAsync("#/bufferViews/"+s.index,s,(function(l){var d,u=o._GetNumComponents(r,n.type),c=n.byteOffset||0,f=s.byteStride;0===f&&e.Tools.Warn(r+": Byte stride of 0 is not valid");try{switch(n.componentType){case t.EComponentType.BYTE:d=i._buildArrayBuffer(Float32Array,l,c,n.count,u,f);break;case t.EComponentType.UNSIGNED_BYTE:d=i._buildArrayBuffer(Uint8Array,l,c,n.count,u,f);break;case t.EComponentType.SHORT:d=i._buildArrayBuffer(Int16Array,l,c,n.count,u,f);break;case t.EComponentType.UNSIGNED_SHORT:d=i._buildArrayBuffer(Uint16Array,l,c,n.count,u,f);break;case t.EComponentType.UNSIGNED_INT:d=i._buildArrayBuffer(Uint32Array,l,c,n.count,u,f);break;case t.EComponentType.FLOAT:d=i._buildArrayBuffer(Float32Array,l,c,n.count,u,f);break;default:throw new Error(r+": Invalid component type "+n.componentType)}}catch(e){throw new Error(r+": "+e)}a(d)}))},o.prototype._buildArrayBuffer=function(e,t,r,o,n,a){r+=t.byteOffset;var i=o*n;if(!a||a===n*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*o),d=new e(i),u=0,c=0;c<i;){for(var f=0;f<n;f++)d[c]=l[u+f],c++;u+=s}return d},o.prototype._addPendingData=function(e){this._renderReady||this._renderPendingCount++,this._addLoaderPendingData(e)},o.prototype._removePendingData=function(e){var t=this;this._renderReady||0==--this._renderPendingCount&&(this._addLoaderPendingData(this),this._compileMaterialsAsync((function(){t._compileShadowGeneratorsAsync((function(){t._removeLoaderPendingData(t),t._renderReady=!0,t._onRenderReady()}))}))),this._removeLoaderPendingData(e)},o.prototype._addLoaderPendingData=function(e){this._loaderPendingCount++;for(var t=0,r=this._loaderTrackers;t<r.length;t++){r[t]._addPendingData(e)}},o.prototype._removeLoaderPendingData=function(e){for(var t=0,r=this._loaderTrackers;t<r.length;t++){r[t]._removePendingData(e)}0==--this._loaderPendingCount&&this._onComplete()},o.prototype._whenAction=function(e,t){var o=this,n=new r(function(){o._loaderTrackers.splice(o._loaderTrackers.indexOf(n),1),t()});this._loaderTrackers.push(n),this._addLoaderPendingData(n),e(),this._removeLoaderPendingData(n)},o.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",r=this._babylonScene.getMaterialByName(t);r||(r=new e.PBRMaterial(t,this._babylonScene),r.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE,r.sideOrientation=e.Material.ClockWiseSideOrientation,r.metallic=1,r.roughness=1),this._defaultMaterial=r}return this._defaultMaterial},o.prototype._loadMaterialMetallicRoughnessProperties=function(t,r){var n=r.babylonMaterial;n.metallic=1,n.roughness=1;var a=r.pbrMetallicRoughness;if(a){if(n.albedoColor=a.baseColorFactor?e.Color3.FromArray(a.baseColorFactor):new e.Color3(1,1,1),n.metallic=null==a.metallicFactor?1:a.metallicFactor,n.roughness=null==a.roughnessFactor?1:a.roughnessFactor,a.baseColorTexture){var i=o._GetProperty(this._gltf.textures,a.baseColorTexture.index);if(!i)throw new Error(t+": Failed to find base color texture "+a.baseColorTexture.index);n.albedoTexture=this._loadTexture("#/textures/"+i.index,i,a.baseColorTexture.texCoord)}if(a.metallicRoughnessTexture){var i=o._GetProperty(this._gltf.textures,a.metallicRoughnessTexture.index);if(!i)throw new Error(t+": Failed to find metallic roughness texture "+a.metallicRoughnessTexture.index);n.metallicTexture=this._loadTexture("#/textures/"+i.index,i,a.metallicRoughnessTexture.texCoord),n.useMetallnessFromMetallicTextureBlue=!0,n.useRoughnessFromMetallicTextureGreen=!0,
  2. n.useRoughnessFromMetallicTextureAlpha=!1}this._loadMaterialAlphaProperties(t,r,a.baseColorFactor)}},o.prototype._loadMaterial=function(e,r,o){if(r.babylonMaterial)return void o(r.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,r,o)||(this._createPbrMaterial(r),this._loadMaterialBaseProperties(e,r),this._loadMaterialMetallicRoughnessProperties(e,r),o(r.babylonMaterial,!0))},o.prototype._createPbrMaterial=function(t){var r=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);r.sideOrientation=e.Material.ClockWiseSideOrientation,t.babylonMaterial=r},o.prototype._loadMaterialBaseProperties=function(t,r){var n=r.babylonMaterial;if(n.emissiveColor=r.emissiveFactor?e.Color3.FromArray(r.emissiveFactor):new e.Color3(0,0,0),r.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),r.normalTexture){var a=o._GetProperty(this._gltf.textures,r.normalTexture.index);if(!a)throw new Error(t+": Failed to find normal texture "+r.normalTexture.index);n.bumpTexture=this._loadTexture("#/textures/"+a.index,a,r.normalTexture.texCoord),n.invertNormalMapX=!this._babylonScene.useRightHandedSystem,n.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=r.normalTexture.scale&&(n.bumpTexture.level=r.normalTexture.scale)}if(r.occlusionTexture){var a=o._GetProperty(this._gltf.textures,r.occlusionTexture.index);if(!a)throw new Error(t+": Failed to find occlusion texture "+r.occlusionTexture.index);n.ambientTexture=this._loadTexture("#/textures/"+a.index,a,r.occlusionTexture.texCoord),n.useAmbientInGrayScale=!0,null!=r.occlusionTexture.strength&&(n.ambientTextureStrength=r.occlusionTexture.strength)}if(r.emissiveTexture){var a=o._GetProperty(this._gltf.textures,r.emissiveTexture.index);if(!a)throw new Error(t+": Failed to find emissive texture "+r.emissiveTexture.index);n.emissiveTexture=this._loadTexture("#/textures/"+a.index,a,r.emissiveTexture.texCoord)}},o.prototype._loadMaterialAlphaProperties=function(t,r,o){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=null==r.alphaCutoff?.5:r.alphaCutoff,o&&(0==o[3]?n.alphaCutOff=1:n.alphaCutOff/=o[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":n.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHABLEND,o&&(n.alpha=o[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(t+": Invalid alpha mode "+r.alphaMode)}},o.prototype._loadTexture=function(t,r,n){var a=this,i=void 0==r.sampler?this._defaultSampler:o._GetProperty(this._gltf.samplers,r.sampler);if(!i)throw new Error(t+": Failed to find sampler "+r.sampler);this._loadSampler("#/samplers/"+i.index,i),this._addPendingData(r);var s=new e.Texture(null,this._babylonScene,i.noMipMaps,!1,i.samplingMode,function(){a._tryCatchOnError((function(){a._removePendingData(r)}))},function(e){a._tryCatchOnError((function(){throw new Error(t+": "+e)}))});if(r.url)s.updateURL(r.url);else if(r.dataReadyObservable)r.dataReadyObservable.add((function(e){s.updateURL(e.url)}));else{r.dataReadyObservable=new e.Observable,r.dataReadyObservable.add((function(e){s.updateURL(e.url)}));var l=o._GetProperty(this._gltf.images,r.source);if(!l)throw new Error(t+": Failed to find source "+r.source);this._loadImageAsync("#/images/"+l.index,l,(function(e){r.url=URL.createObjectURL(new Blob([e],{type:l.mimeType})),r.dataReadyObservable.notifyObservers(r),r.dataReadyObservable=void 0}))}return s.coordinatesIndex=n||0,s.wrapU=i.wrapU,s.wrapV=i.wrapV,s.name=r.name||"texture"+r.index,this.onTextureLoadedObservable.notifyObservers(s),s},o.prototype._loadSampler=function(e,r){void 0==r.noMipMaps&&(r.noMipMaps=r.minFilter===t.ETextureMinFilter.NEAREST||r.minFilter===t.ETextureMinFilter.LINEAR,r.samplingMode=o._GetTextureSamplingMode(e,r.magFilter,r.minFilter),r.wrapU=o._GetTextureWrapMode(e,r.wrapS),r.wrapV=o._GetTextureWrapMode(e,r.wrapT))},o.prototype._loadImageAsync=function(e,t,r){if(t.uri)this._loadUriAsync(e,t.uri,r);else{var n=o._GetProperty(this._gltf.bufferViews,t.bufferView);if(!n)throw new Error(e+": Failed to find buffer view "+t.bufferView);this._loadBufferViewAsync("#/bufferViews/"+n.index,n,r)}},o.prototype._loadUriAsync=function(r,o,n){var a=this;if(t.GLTFUtils.IsBase64(o))return void n(new Uint8Array(t.GLTFUtils.DecodeBase64(o)));if(!t.GLTFUtils.ValidateUri(o))throw new Error(r+": Uri '"+o+"' is invalid");var i=e.Tools.LoadFile(this._rootUrl+o,(function(e){a._tryCatchOnError((function(){n(new Uint8Array(e))}))}),(function(e){a._tryCatchOnError((function(){i&&!a._renderReady&&(i._lengthComputable=e.lengthComputable,i._loaded=e.loaded,i._total=e.total,a._onProgress())}))}),this._babylonScene.database,!0,(function(t,n){a._tryCatchOnError((function(){throw new e.LoadFileError(r+": Failed to load '"+o+"'"+(t?": "+t.status+" "+t.statusText:""),t)}))}));this._requests.push(i)},o.prototype._tryCatchOnError=function(t){if(!this._disposed)try{t()}catch(t){e.Tools.Error("glTF Loader: "+t.message),this._errorCallback&&this._errorCallback(t.message,t),this.dispose()}},o._AssignIndices=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},o._GetProperty=function(e,t){return e&&void 0!=t&&e[t]?e[t]:null},o._GetTextureWrapMode=function(r,o){switch(o=void 0==o?t.ETextureWrapMode.REPEAT:o){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:return e.Texture.WRAP_ADDRESSMODE;default:return e.Tools.Warn(r+": Invalid texture wrap mode "+o),e.Texture.WRAP_ADDRESSMODE}},o._GetTextureSamplingMode=function(r,o,n){if(o=void 0==o?t.ETextureMagFilter.LINEAR:o,n=void 0==n?t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:n,o===t.ETextureMagFilter.LINEAR)switch(n){case t.ETextureMinFilter.NEAREST:return e.Texture.LINEAR_NEAREST;case t.ETextureMinFilter.LINEAR:return e.Texture.LINEAR_LINEAR;case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.LINEAR_NEAREST_MIPNEAREST;case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return e.Texture.LINEAR_LINEAR_MIPNEAREST;case t.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return e.Texture.LINEAR_NEAREST_MIPLINEAR;case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.LINEAR_LINEAR_MIPLINEAR;default:return e.Tools.Warn(r+": Invalid texture minification filter "+n),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(o!==t.ETextureMagFilter.NEAREST&&e.Tools.Warn(r+": Invalid texture magnification filter "+o),n){case t.ETextureMinFilter.NEAREST:return e.Texture.NEAREST_NEAREST;case t.ETextureMinFilter.LINEAR:return e.Texture.NEAREST_LINEAR;case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_NEAREST_MIPNEAREST;case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return e.Texture.NEAREST_LINEAR_MIPNEAREST;case t.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return e.Texture.NEAREST_NEAREST_MIPLINEAR;case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.NEAREST_LINEAR_MIPLINEAR;default:return e.Tools.Warn(r+": Invalid texture minification filter "+n),e.Texture.NEAREST_NEAREST_MIPNEAREST}},o._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)},o.prototype._compileMaterialAsync=function(e,t,r){var o=this;this.useClipPlane?e.forceCompilation(t,(function(){e.forceCompilation(t,(function(){o._tryCatchOnError(r)}),{clipPlane:!0})})):e.forceCompilation(t,(function(){o._tryCatchOnError(r)}))},o.prototype._compileMaterialsAsync=function(t){if(!this.compileMaterials||!this._gltf.materials)return void t();for(var r=this._getMeshes(),o=0,n=0,a=r;n<a.length;n++){var i=a[n];if(i.material instanceof e.MultiMaterial)for(var s=0,l=i.material.subMaterials;s<l.length;s++){var d=l[s];d&&o++}else i.material&&o++}if(0===o)return void t();for(var u=0,c=r;u<c.length;u++){var i=c[u];if(i.material instanceof e.MultiMaterial)for(var f=0,h=i.material.subMaterials;f<h.length;f++){var d=h[f];d&&this._compileMaterialAsync(d,i,(function(){0==--o&&t()}))}else i.material&&this._compileMaterialAsync(i.material,i,(function(){0==--o&&t()}))}},o.prototype._compileShadowGeneratorsAsync=function(e){var t=this;if(!this.compileShadowGenerators)return void e();for(var r=this._babylonScene.lights,o=0,n=0,a=r;n<a.length;n++){var i=a[n],s=i.getShadowGenerator();s&&o++}if(0===o)return void e();for(var l=0,d=r;l<d.length;l++){var i=d[l],s=i.getShadowGenerator();s&&s.forceCompilation((function(){0==--o&&t._tryCatchOnError(e)}))}},o.prototype._abortRequests=function(){for(var e=0,t=this._requests;e<t.length;e++){t[e].abort()}this._requests.length=0},o.prototype._releaseResources=function(){if(this._gltf.textures)for(var e=0,t=this._gltf.textures;e<t.length;e++){var r=t[e];r.url&&(URL.revokeObjectURL(r.url),r.url=void 0)}},o.Extensions={},o})();t.GLTFLoader=o,e.GLTFFileLoader.CreateGLTFLoaderV2=function(){return new o}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(){}return e.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},e.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),r=t.length,o=new Uint8Array(new ArrayBuffer(r)),n=0;n<r;n++)o[n]=t.charCodeAt(n);return o.buffer},e.ValidateUri=function(e){return-1===e.indexOf("..")},e})();e.GLTFUtils=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(){this.enabled=!0}return e.prototype._traverseNode=function(e,t,r,o,n){return!1},e.prototype._loadNode=function(e,t,r){return!1},e.prototype._loadRoot=function(e,t,r){return!1},e.prototype._loadScene=function(e,t,r){return!1},e.prototype._loadMaterial=function(e,t,r,o){return!1},e.prototype._loadExtension=function(e,t,r){var o=this;if(!t.extensions)return!1;var n=t.extensions[this.name];return!!n&&(t.extensions[this.name]=void 0,r(e+"extensions/"+this.name,n,(function(){t.extensions[o.name]=n})),!0)},e.TraverseNode=function(e,t,r,o,n){return this._ApplyExtensions((function(a){return a._traverseNode(e,t,r,o,n)}))},e.LoadRoot=function(e,t,r){return this._ApplyExtensions((function(o){return o._loadRoot(e,t,r)}))},e.LoadScene=function(e,t,r){return this._ApplyExtensions((function(o){return o._loadScene(e,t,r)}))},e.LoadNode=function(e,t,r){return this._ApplyExtensions((function(o){return o._loadNode(e,t,r)}))},e.LoadMaterial=function(e,t,r,o){return this._ApplyExtensions((function(n){return n._loadMaterial(e,t,r,o)}))},e._ApplyExtensions=function(t){var r=e._Extensions;if(!r)return!1;for(var o=0,n=r;o<n.length;o++){var a=n[o];if(a.enabled&&t(a))return!0}return!1},e._Extensions=[],e})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function o(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}})(),BABYLON;!(function(e){!(function(t){!(function(r){var o=(function(r){function o(){var e=null!==r&&r.apply(this,arguments)||this;return e.Delay=250,e}return __extends(o,r),Object.defineProperty(o.prototype,"name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),o.prototype._traverseNode=function(e,r,o,n,a){return this._loadExtension(r,o,(function(r,i,s){for(var l=i.ids.length-1;l>=0;l--){var d=t.GLTFLoader._GetProperty(e._gltf.nodes,i.ids[l]);if(!d)throw new Error(r+": Failed to find node "+i.ids[l]);e._traverseNode(r,d,n,a)}e._traverseNode(r,o,n,a),s()}))},o.prototype._loadNode=function(e,r,o){var n=this;return this._loadExtension(r,o,(function(r,a,i){for(var s=[o],l=0,d=a.ids;l<d.length;l++){var u=d[l],c=t.GLTFLoader._GetProperty(e._gltf.nodes,u);if(!c)throw new Error(r+": Failed to find node "+u);s.push(c)}e._addLoaderPendingData(o),n._loadNodeLOD(e,r,s,s.length-1,(function(){e._removeLoaderPendingData(o),i()}))}))},o.prototype._loadNodeLOD=function(e,t,r,o,n){var a=this;e._whenAction((function(){e._loadNode(t,r[o])}),(function(){if(o!==r.length-1){r[o+1].babylonMesh.setEnabled(!1)}if(0===o)return void n();setTimeout((function(){e._tryCatchOnError((function(){a._loadNodeLOD(e,t,r,o-1,n)}))}),a.Delay)}))},o.prototype._loadMaterial=function(e,r,o,n){var a=this;return this._loadExtension(r,o,(function(r,i,s){for(var l=[o],d=0,u=i.ids;d<u.length;d++){var c=u[d],f=t.GLTFLoader._GetProperty(e._gltf.materials,c);if(!f)throw new Error(r+": Failed to find material "+c);l.push(f)}e._addLoaderPendingData(o),a._loadMaterialLOD(e,r,l,l.length-1,n,(function(){e._removeLoaderPendingData(o),s()}))}))},o.prototype._loadMaterialLOD=function(t,r,o,n,a,i){var s=this;t._loadMaterial(r,o[n],(function(l,d){n===o.length-1?(a(l,d),t._executeWhenRenderReady((function(){s._loadMaterialLOD(t,r,o,n-1,a,i)}))):e.BaseTexture.WhenAllReady(l.getActiveTextures(),(function(){a(l,d),0===n?i():setTimeout((function(){t._tryCatchOnError((function(){s._loadMaterialLOD(t,r,o,n-1,a,i)}))}),s.Delay)}))}))},o})(t.GLTFLoaderExtension);r.MSFTLOD=o,t.GLTFLoader.RegisterExtension(new o)})(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 o(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}})(),BABYLON;!(function(e){!(function(t){!(function(r){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_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),o.prototype._loadMaterial=function(e,t,r,o){var n=this;return this._loadExtension(t,r,(function(t,a,i){e._createPbrMaterial(r),e._loadMaterialBaseProperties(t,r),n._loadSpecularGlossinessProperties(e,t,r,a),o(r.babylonMaterial,!0),i()}))},o.prototype._loadSpecularGlossinessProperties=function(r,o,n,a){var i=n.babylonMaterial;if(i.albedoColor=a.diffuseFactor?e.Color3.FromArray(a.diffuseFactor):new e.Color3(1,1,1),i.reflectivityColor=a.specularFactor?e.Color3.FromArray(a.specularFactor):new e.Color3(1,1,1),i.microSurface=null==a.glossinessFactor?1:a.glossinessFactor,a.diffuseTexture){var s=t.GLTFLoader._GetProperty(r._gltf.textures,a.diffuseTexture.index);if(!s)throw new Error(o+": Failed to find diffuse texture "+a.diffuseTexture.index);i.albedoTexture=r._loadTexture("textures["+s.index+"]",s,a.diffuseTexture.texCoord)}if(a.specularGlossinessTexture){var s=t.GLTFLoader._GetProperty(r._gltf.textures,a.specularGlossinessTexture.index);if(!s)throw new Error(o+": Failed to find diffuse texture "+a.specularGlossinessTexture.index);i.reflectivityTexture=r._loadTexture("textures["+s.index+"]",s,a.specularGlossinessTexture.texCoord),i.reflectivityTexture.hasAlpha=!0,i.useMicroSurfaceFromReflectivityMapAlpha=!0}r._loadMaterialAlphaProperties(o,n,a.diffuseFactor)},o})(t.GLTFLoaderExtension);r.KHRMaterialsPbrSpecularGlossiness=o,t.GLTFLoader.RegisterExtension(new o)})(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 o(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}})(),BABYLON;!(function(e){!(function(t){!(function(r){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.applyCommonProperties=function(e,t){t.color?e.diffuse.copyFromFloats(t.color[0],t.color[1],t.color[2]):e.diffuse.copyFromFloats(1,1,1),void 0!==t.intensity?e.intensity=t.intensity:e.intensity=1},o.prototype._loadScene=function(e,t,r){return this._loadExtension(t,r,(function(t,r,o){if(r.light>=0&&e._gltf.extensions){var n=e._gltf.extensions.KHR_lights.lights[r.light];if("ambient"!==n.type)return;var a=n.color?n.color:[1,1,1];e._babylonScene.ambientColor.copyFromFloats(a[0],a[1],a[2])}o()}))},o.prototype._loadNode=function(r,o,n){var a=this;return this._loadExtension(o,n,(function(o,i,s){if(i.light>=0&&r._gltf.extensions){var l=r._gltf.extensions.KHR_lights.lights[i.light],d=n.name||"Light",u=void 0;u=n.matrix?e.Matrix.FromArray(n.matrix):e.Matrix.Identity();var c=new e.Vector3(0,0,1);if("directional"==l.type||"spot"==l.type){var f=u.getRotationMatrix();e.Vector3.TransformCoordinatesToRef(c,f,c)}var h=void 0;if("directional"==l.type)h=new e.DirectionalLight(d,c,r._babylonScene);else{var p=u.getTranslation();if("spot"==l.type){var _=l.spot&&l.spot.outerConeAngle?l.spot.outerConeAngle:Math.PI/2;h=new e.SpotLight(d,p,c,_,2,r._babylonScene)}else h=new e.PointLight(d,p,r._babylonScene)}if(a.applyCommonProperties(h,l),i.babylonLight=h,i.babylonLight.parent=n.parent?n.parent.babylonMesh:null,n.children)for(var b=0,y=n.children;b<y.length;b++){var v=y[b],m=t.GLTFLoader._GetProperty(r._gltf.nodes,v);if(!m)throw new Error(o+": Failed to find child node "+v);r._loadNode("#/nodes/"+v,m)}}s()}))},o.prototype._loadRoot=function(e,t,r){return this._loadExtension(t,r,(function(e,t,r){t.lights.forEach((function(e,t){e.index=t})),r()}))},o})(t.GLTFLoaderExtension);r.KHRLights=o,t.GLTFLoader.RegisterExtension(new o)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));