12 |
- var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var r;!(function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"})(r=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}));var n=(function(){function e(){this.coordinateSystemMode=t.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.dispose=function(){this._loader&&this._loader.dispose()},e.prototype.importMeshAsync=function(t,r,n,o,a,i,s){try{var l=e._parse(n);this.onParsed&&this.onParsed(l),this._loader=this._getLoader(l),this._loader.importMeshAsync(t,r,l,o,a,i,s)}catch(e){s(e.message)}},e.prototype.loadAsync=function(t,r,n,o,a,i){try{var s=e._parse(r);this.onParsed&&this.onParsed(s),this._loader=this._getLoader(s),this._loader.loadAsync(t,s,n,o,a,i)}catch(e){i(e.message)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e.prototype.createPlugin=function(){return new e},e._parse=function(t){return t instanceof ArrayBuffer?e._parseBinary(t):{json:JSON.parse(t),bin:null}},e.prototype._getLoader=function(t){var r={major:2,minor:0},n=t.json.asset||{},o=e._parseVersion(n.version);if(!o)throw new Error("Invalid version: "+n.version);if(void 0!==n.minVersion){var a=e._parseVersion(n.minVersion);if(!a)throw new Error("Invalid minimum version: "+n.minVersion);if(e._compareVersion(a,r)>0)throw new Error("Incompatible minimum version: "+n.minVersion)}var i={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},s=i[o.major];if(!s)throw new Error("Unsupported version: "+n.version);return s(this)},e._parseBinary=function(t){var r={Magic:1179937895},n=new o(t),a=n.readUint32();if(a!==r.Magic)throw new Error("Unexpected magic: "+a);var i=n.readUint32();switch(i){case 1:return e._parseV1(n);case 2:return e._parseV2(n)}throw new Error("Unsupported version: "+i)},e._parseV1=function(t){var r={JSON:0},n=t.readUint32();if(n!=t.getLength())throw new Error("Length in header does not match actual data length: "+n+" != "+t.getLength());var o,a=t.readUint32(),i=t.readUint32();switch(i){case r.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(a)));break;default:throw new Error("Unexpected content format: "+i)}var s=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(s)}},e._parseV2=function(t){var r={JSON:1313821514,BIN:5130562},n=t.readUint32();if(n!==t.getLength())throw new Error("Length in header does not match actual data length: "+n+" != "+t.getLength());var o=t.readUint32();if(t.readUint32()!==r.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),i=null;t.getPosition()<t.getLength();){var s=t.readUint32();switch(t.readUint32()){case r.JSON:throw new Error("Unexpected JSON chunk");case r.BIN:i=t.readUint8Array(s);break;default:t.skipBytes(s)}}return{json:a,bin:i}},e._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},e._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},e._decodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;n++)t+=String.fromCharCode(e[n]);return t},e.IncrementalLoading=!0,e.HomogeneousCoordinates=!1,e})();e.GLTFFileLoader=n;var o=(function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new n)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){!(function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.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})(),n=(function(){function n(t){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._parent=t,n._progressEventFactory||("function"==typeof window.ProgressEvent?n._progressEventFactory=n._createProgressEventByConstructor:n._progressEventFactory=n._createProgressEventByDocument)}return n.RegisterExtension=function(r){if(n.Extensions[r.name])return void e.Tools.Error("Extension with the same name '"+r.name+"' already exists");n.Extensions[r.name]=r,t.GLTFLoaderExtension._Extensions.push(r)},n._createProgressEventByConstructor=function(e,t){return new ProgressEvent(e,t)},n._createProgressEventByDocument=function(e,t){var r=document.createEvent("ProgressEvent");return r.initProgressEvent(e,!1,!1,t.lengthComputable,t.loaded,t.total),r},n.prototype.dispose=function(){if(!this._disposed){this._disposed=!0;for(var e=0,t=this._requests;e<t.length;e++){var r=t[e];r.readyState!==(XMLHttpRequest.DONE||4)&&r.abort()}if(this._gltf.textures)for(var n=0,o=this._gltf.textures;n<o.length;n++){var a=o[n];a.url&&URL.revokeObjectURL(a.url)}}},n.prototype.importMeshAsync=function(e,t,r,n,o,a,i){var s=this;this._loadAsync(e,t,r,n,(function(){o(s._getMeshes(),[],s._getSkeletons())}),a,i)},n.prototype.loadAsync=function(e,t,r,n,o,a){this._loadAsync(null,e,t,r,n,o,a)},n.prototype._loadAsync=function(e,t,r,n,o,a,i){var s=this;this._tryCatchOnError((function(){s._loadData(r),s._babylonScene=t,s._rootUrl=n,s._successCallback=o,s._progressCallback=a,s._errorCallback=i,s._addPendingData(s),s._loadDefaultScene(e),s._loadAnimations(),s._removePendingData(s)}))},n.prototype._onProgress=function(){if(this._progressCallback){for(var e=0,t=0,r=0,o=this._requests;r<o.length;r++){var a=o[r];if(!a._loaded||!a._total)return;e+=a._loaded,t+=a._total}this._progressCallback(n._progressEventFactory("GLTFLoaderProgress",{lengthComputable:!0,loaded:e,total:t}))}},n.prototype._executeWhenRenderReady=function(e){this._renderReady?e():this._renderReadyObservable.add(e)},n.prototype._onRenderReady=function(){this._rootNode.babylonMesh.setEnabled(!0),this._startAnimations(),this._successCallback(),this._renderReadyObservable.notifyObservers(this)},n.prototype._onComplete=function(){this._parent.onComplete&&this._parent.onComplete(),this.dispose()},n.prototype._loadData=function(t){if(this._gltf=t.json,n._AssignIndices(this._gltf.accessors),n._AssignIndices(this._gltf.animations),n._AssignIndices(this._gltf.buffers),n._AssignIndices(this._gltf.bufferViews),n._AssignIndices(this._gltf.images),n._AssignIndices(this._gltf.materials),n._AssignIndices(this._gltf.meshes),n._AssignIndices(this._gltf.nodes),n._AssignIndices(this._gltf.samplers),n._AssignIndices(this._gltf.scenes),n._AssignIndices(this._gltf.skins),n._AssignIndices(this._gltf.textures),t.bin){var r=this._gltf.buffers;if(r&&r[0]&&!r[0].uri){var o=r[0];(o.byteLength<t.bin.byteLength-3||o.byteLength>t.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+o.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),o.loadedData=t.bin}else e.Tools.Warn("Unexpected BIN chunk")}},n.prototype._getMeshes=function(){var e=new Array;e.push(this._rootNode.babylonMesh);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},n.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},n.prototype._startAnimations=function(){var t=this._gltf.animations;if(t)switch(this._parent.animationStartMode){case e.GLTFLoaderAnimationStartMode.NONE:break;case e.GLTFLoaderAnimationStartMode.FIRST:for(var r=t[0],n=0,o=r.targets;n<o.length;n++){var a=o[n];this._babylonScene.beginAnimation(a,0,Number.MAX_VALUE,!0)}break;case e.GLTFLoaderAnimationStartMode.ALL:for(var i=0,s=t;i<s.length;i++)for(var r=s[i],l=0,d=r.targets;l<d.length;l++){var a=d[l];this._babylonScene.beginAnimation(a,0,Number.MAX_VALUE,!0)}break;default:return void e.Tools.Error("Invalid animation start mode "+this._parent.animationStartMode)}},n.prototype._loadDefaultScene=function(e){var t=n._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)},n.prototype._loadScene=function(t,r,o){var a=this;switch(this._rootNode={babylonMesh:new e.Mesh("__root__",this._babylonScene)},this._parent.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._parent.coordinateSystemMode)}this._parent.onMeshLoaded&&this._parent.onMeshLoaded(this._rootNode.babylonMesh);var i=r.nodes;if(this._traverseNodes(t,i,(function(e,t){return e.parent=t,!0}),this._rootNode),o){o instanceof Array||(o=[o]);var s=new Array;this._traverseNodes(t,i,(function(e){return-1===o.indexOf(e.name)||(s.push(e.index),e.parent=a._rootNode,!1)}),this._rootNode),i=s}for(var l=0,d=i;l<d.length;l++){var u=d[l],c=n._GetProperty(this._gltf.nodes,u);if(!c)throw new Error(t+": Failed to find node "+u);this._loadNode("#/nodes/"+u,c)}this._rootNode.babylonMesh.setEnabled(!1)},n.prototype._loadNode=function(r,o){if(!t.GLTFLoaderExtension.LoadNode(this,r,o)){if(o.babylonMesh=new e.Mesh(o.name||"mesh"+o.index,this._babylonScene),o.babylonMesh.hasVertexAlpha=!0,this._loadTransform(o),null!=o.mesh){var a=n._GetProperty(this._gltf.meshes,o.mesh);if(!a)throw new Error(r+": Failed to find mesh "+o.mesh);this._loadMesh("#/meshes/"+o.mesh,o,a)}if(o.babylonMesh.parent=o.parent.babylonMesh,o.babylonAnimationTargets=o.babylonAnimationTargets||[],o.babylonAnimationTargets.push(o.babylonMesh),null!=o.skin){var i=n._GetProperty(this._gltf.skins,o.skin);if(!i)throw new Error(r+": Failed to find skin "+o.skin);this._loadSkinAsync("#/skins/"+o.skin,i,(function(){o.babylonMesh.skeleton=i.babylonSkeleton,o.babylonMesh._refreshBoundingInfo(!0)})),o.babylonMesh.parent=this._rootNode.babylonMesh,o.babylonMesh.position=e.Vector3.Zero(),o.babylonMesh.rotationQuaternion=e.Quaternion.Identity(),o.babylonMesh.scaling=e.Vector3.One()}if(o.camera,o.children)for(var s=0,l=o.children;s<l.length;s++){var d=l[s],u=n._GetProperty(this._gltf.nodes,d);if(!u)throw new Error(r+": Failed to find child node "+d);this._loadNode("#/nodes/"+d,u)}this._parent.onMeshLoaded&&this._parent.onMeshLoaded(o.babylonMesh)}},n.prototype._loadMesh=function(t,r,o){var a=this,i=o.primitives;if(!i||0===i.length)throw new Error(t+": Primitives are missing");if(this._createMorphTargets(t,r,o),this._loadAllVertexDataAsync(t,o,(function(){a._loadMorphTargets(t,r,o);for(var n=new e.VertexData,s=0,l=i;s<l.length;s++){var d=l[s];n.merge(d.vertexData)}new e.Geometry(r.babylonMesh.name,a._babylonScene,n,!1,r.babylonMesh),r.babylonMesh.subMeshes=[];for(var u=0,c=0,f=0;f<i.length;f++){var h=i[f].vertexData,_=h.positions.length,p=h.indices.length;e.SubMesh.AddToMesh(f,u,_,c,p,r.babylonMesh),u+=_,c+=p}})),1===i.length){var s=i[0];if(null==s.material)r.babylonMesh.material=this._getDefaultMaterial();else{var l=n._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._parent.onMaterialLoaded&&a._parent.onMaterialLoaded(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 o=n._GetProperty(c._gltf.materials,r.material);if(!o)throw new Error(t+": Failed to find material "+r.material);c._loadMaterial("#/materials/"+o.index,o,(function(t,r){r&&a._parent.onMaterialLoaded&&a._parent.onMaterialLoaded(t),u[e]=t}))}})(f)}},n.prototype._loadAllVertexDataAsync=function(e,t,r){for(var n=t.primitives,o=n.length,a=this,i=0;i<n.length;i++)!(function(i){var s=n[i];a._loadVertexDataAsync(e+"/primitive/"+i,t,s,(function(e){s.vertexData=e,0==--o&&r()}))})(i)},n.prototype._convertToFloat4TextureCoordArray=function(e,r,n){if(n.componentType==t.EComponentType.FLOAT)return r;var o=r,a=1;switch(n.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 ("+n.componentType+")")}for(var i=new Float32Array(2*n.count),s=0;s<i.length;++s)i[s]=o[s]*a;return i},n.prototype._convertToFloat4ColorArray=function(e,r,o){var a=n._GetNumComponents(e,o.type);if(4===a&&o.componentType===t.EComponentType.FLOAT)return r;var i=r,s=1;switch(o.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 ("+o.componentType+")")}var l=new Float32Array(4*o.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},n.prototype._loadVertexDataAsync=function(r,o,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 o=n._GetProperty(c._gltf.accessors,l[t]);if(!o)throw new Error(r+": Failed to find attribute '"+t+"' accessor "+l[t]);c._loadAccessorAsync("#/accessors/"+o.index,o,(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,o);break;case"TEXCOORD_1":d.uvs2=s._convertToFloat4TextureCoordArray(r,l,o);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,o);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 c=0;c<d.indices.length;c++)d.indices[c]=c;i(d)}else{var f=n._GetProperty(s._gltf.accessors,a.indices);if(!f)throw new Error(r+": Failed to find indices accessor "+a.indices);s._loadAccessorAsync("#/accessors/"+f.index,f,(function(e){d.indices=e,i(d)}))}}))})(f)},n.prototype._createMorphTargets=function(t,r,n){var o=n.primitives,a=o[0].targets;if(a){for(var i=0,s=o;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]:n.weights?n.weights[u]:0;d.addTarget(new e.MorphTarget("morphTarget"+u,c))}}},n.prototype._loadMorphTargets=function(t,r,n){var o=r.babylonMesh.morphTargetManager;o&&this._loadAllMorphTargetVertexDataAsync(t,r,n,(function(){for(var r=o.numTargets,a=0;a<r;a++){for(var i=new e.VertexData,s=0,l=n.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=o.getTarget(a);u.setPositions(i.positions),u.setNormals(i.normals),u.setTangents(i.tangents)}}))},n.prototype._loadAllMorphTargetVertexDataAsync=function(e,t,r,n){for(var o=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==--o&&n()}))})(i)})(l)}},n.prototype._loadMorphTargetVertexDataAsync=function(t,r,o,a){var i=new e.VertexData,s=Object.keys(o).length,l=this;for(var d in o)!(function(d){var u=n._GetProperty(l._gltf.accessors,o[d]);if(!u)throw new Error(t+": Failed to find attribute '"+d+"' accessor "+o[d]);l._loadAccessorAsync("#/accessors/"+u.index,u,(function(n){var o=n;switch(d){case"POSITION":for(var l=0;l<o.length;l++)o[l]+=r.positions[l];i.positions=o;break;case"NORMAL":for(var l=0;l<o.length;l++)o[l]+=r.normals[l];i.normals=o;break;case"TANGENT":for(var l=0,u=0;l<o.length;l++,u++)o[l]+=r.tangents[u],(l+1)%3==0&&u++;i.tangents=o;break;default:e.Tools.Warn(t+": Ignoring unrecognized attribute '"+d+"'")}0==--s&&a(i)}))})(d)},n.prototype._loadTransform=function(t){var r=e.Vector3.Zero(),n=e.Quaternion.Identity(),o=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(o,n,r)}else t.translation&&(r=e.Vector3.FromArray(t.translation)),t.rotation&&(n=e.Quaternion.FromArray(t.rotation)),t.scale&&(o=e.Vector3.FromArray(t.scale));t.babylonMesh.position=r,t.babylonMesh.rotationQuaternion=n,t.babylonMesh.scaling=o},n.prototype._loadSkinAsync=function(t,r,o){var a=this;if(r.babylonSkeleton)return void o();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),o();else{var s=n._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),o()}))}},n.prototype._createBone=function(t,r,n,o,a,i){var s=new e.Bone(t.name||"bone"+t.index,r.babylonSkeleton,n,o,null,a,i);return t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(s),s},n.prototype._loadBones=function(e,t,r){for(var o={},a=0,i=t.joints;a<i.length;a++){var s=i[a],l=n._GetProperty(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find joint "+s);this._loadBone(l,t,r,o)}},n.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!==this._rootNode&&(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},n.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())},n.prototype._traverseNodes=function(e,t,r,o){for(var a=0,i=t;a<i.length;a++){var s=i[a],l=n._GetProperty(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find node "+s);this._traverseNode(e,l,r,o)}},n.prototype._traverseNode=function(e,r,n,o){t.GLTFLoaderExtension.TraverseNode(this,e,r,n,o)||n(r,o)&&r.children&&this._traverseNodes(e,r.children,n,r)},n.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)}},n.prototype._loadAnimation=function(e,t){t.targets=[];for(var r=0;r<t.channels.length;r++){var o=n._GetProperty(t.channels,r);if(!o)throw new Error(e+": Failed to find channel "+r);var a=n._GetProperty(t.samplers,o.sampler);if(!a)throw new Error(e+": Failed to find sampler "+o.sampler);this._loadAnimationChannel(t,e+"/channels/"+r,o,e+"/samplers/"+o.sampler,a)}},n.prototype._loadAnimationChannel=function(t,r,o,a,i){var s=n._GetProperty(this._gltf.nodes,o.target.node);if(!s)throw new Error(r+": Failed to find target node "+o.target.node);var l,d;switch(o.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 "+o.target.path)}var u,c,f=function(){if(u&&c){var r,n=0;switch(l){case"position":r=function(){var t=e.Vector3.FromArray(c,n);return n+=3,t};break;case"rotationQuaternion":r=function(){var t=e.Quaternion.FromArray(c,n);return n+=4,t};break;case"scaling":r=function(){var t=e.Vector3.FromArray(c,n);return n+=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[n++];return t}}var o;switch(i.interpolation){case"LINEAR":o=function(e){return{frame:u[e],value:r()}};break;case"CUBICSPLINE":o=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=o(0);f=[{frame:h.frame,value:h.value},{frame:h.frame+1,value:h.value}]}else{f=new Array(u.length);for(var _=0;_<u.length;_++)f[_]=o(_)}if("influence"===l)for(var p=s.babylonMesh.morphTargetManager,y=0;y<p.numTargets;y++)!(function(r){var n=p.getTarget(r),o=(t.name||"anim"+t.index)+"_"+r,a=new e.Animation(o,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}}))),n.animations.push(a),t.targets.push(n)})(y);else{var E=t.name||"anim"+t.index,T=new e.Animation(E,l,1,d);if(T.setKeys(f),s.babylonAnimationTargets)for(var g=0,m=s.babylonAnimationTargets;g<m.length;g++){var A=m[g];A.animations.push(T.clone()),t.targets.push(A)}}}},h=n._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 _=n._GetProperty(this._gltf.accessors,i.output);if(!_)throw new Error(a+": Failed to find output accessor "+i.output);this._loadAccessorAsync("#/accessors/"+_.index,_,(function(e){c=e,f()}))},n.prototype._loadBufferAsync=function(t,r,n){var o=this;if(this._addPendingData(r),r.loadedData)n(r.loadedData),this._removePendingData(r);else if(r.loadedObservable)r.loadedObservable.add((function(e){n(e.loadedData),o._removePendingData(e)}));else{if(!r.uri)throw new Error(t+": Uri is missing");r.loadedObservable=new e.Observable,r.loadedObservable.add((function(e){n(e.loadedData),o._removePendingData(e)})),this._loadUriAsync(t,r.uri,(function(e){r.loadedData=e,r.loadedObservable.notifyObservers(r),r.loadedObservable=void 0}))}},n.prototype._loadBufferViewAsync=function(e,t,r){var o=n._GetProperty(this._gltf.buffers,t.buffer);if(!o)throw new Error(e+": Failed to find buffer "+t.buffer);this._loadBufferAsync("#/buffers/"+o.index,o,(function(n){var o;try{o=new Uint8Array(n.buffer,n.byteOffset+(t.byteOffset||0),t.byteLength)}catch(t){throw new Error(e+": "+t.message)}r(o)}))},n.prototype._loadAccessorAsync=function(r,o,a){var i=this;if(o.sparse)throw new Error(r+": Sparse accessors are not currently supported");var s=n._GetProperty(this._gltf.bufferViews,o.bufferView);if(!s)throw new Error(r+": Failed to find buffer view "+o.bufferView);this._loadBufferViewAsync("#/bufferViews/"+s.index,s,(function(l){var d,u=n._GetNumComponents(r,o.type),c=o.byteOffset||0,f=s.byteStride;0===f&&e.Tools.Warn(r+": Byte stride of 0 is not valid");try{switch(o.componentType){case t.EComponentType.BYTE:d=i._buildArrayBuffer(Float32Array,l,c,o.count,u,f);break;case t.EComponentType.UNSIGNED_BYTE:d=i._buildArrayBuffer(Uint8Array,l,c,o.count,u,f);break;case t.EComponentType.SHORT:d=i._buildArrayBuffer(Int16Array,l,c,o.count,u,f);break;case t.EComponentType.UNSIGNED_SHORT:d=i._buildArrayBuffer(Uint16Array,l,c,o.count,u,f);break;case t.EComponentType.UNSIGNED_INT:d=i._buildArrayBuffer(Uint32Array,l,c,o.count,u,f);break;case t.EComponentType.FLOAT:d=i._buildArrayBuffer(Float32Array,l,c,o.count,u,f);break;default:throw new Error(r+": Invalid component type "+o.componentType)}}catch(e){throw new Error(r+": "+e)}a(d)}))},n.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),d=new e(i),u=0,c=0;c<i;){for(var f=0;f<o;f++)d[c]=l[u+f],c++;u+=s}return d},n.prototype._addPendingData=function(e){this._renderReady||this._renderPendingCount++,this._addLoaderPendingData(e)},n.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)},n.prototype._addLoaderPendingData=function(e){this._loaderPendingCount++;for(var t=0,r=this._loaderTrackers;t<r.length;t++){r[t]._addPendingData(e)}},n.prototype._removeLoaderPendingData=function(e){for(var t=0,r=this._loaderTrackers;t<r.length;t++){r[t]._removePendingData(e)}0==--this._loaderPendingCount&&this._onComplete()},n.prototype._whenAction=function(e,t){var n=this,o=new r(function(){n._loaderTrackers.splice(n._loaderTrackers.indexOf(o),1),t()});this._loaderTrackers.push(o),this._addLoaderPendingData(o),e(),this._removeLoaderPendingData(o)},n.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",r=this._babylonScene.getMaterialByName(t);r||(r=new e.PBRMaterial(t,this._babylonScene),r.sideOrientation=e.Material.CounterClockWiseSideOrientation,r.metallic=1,r.roughness=1),this._defaultMaterial=r}return this._defaultMaterial},n.prototype._loadMaterialMetallicRoughnessProperties=function(t,r){var o=r.babylonMaterial;o.metallic=1,o.roughness=1;var a=r.pbrMetallicRoughness;if(a){if(o.albedoColor=a.baseColorFactor?e.Color3.FromArray(a.baseColorFactor):new e.Color3(1,1,1),o.metallic=null==a.metallicFactor?1:a.metallicFactor,o.roughness=null==a.roughnessFactor?1:a.roughnessFactor,a.baseColorTexture){var i=n._GetProperty(this._gltf.textures,a.baseColorTexture.index);if(!i)throw new Error(t+": Failed to find base color texture "+a.baseColorTexture.index);o.albedoTexture=this._loadTexture("#/textures/"+i.index,i,a.baseColorTexture.texCoord)}if(a.metallicRoughnessTexture){var i=n._GetProperty(this._gltf.textures,a.metallicRoughnessTexture.index);if(!i)throw new Error(t+": Failed to find metallic roughness texture "+a.metallicRoughnessTexture.index);o.metallicTexture=this._loadTexture("#/textures/"+i.index,i,a.metallicRoughnessTexture.texCoord),o.useMetallnessFromMetallicTextureBlue=!0,o.useRoughnessFromMetallicTextureGreen=!0,o.useRoughnessFromMetallicTextureAlpha=!1}this._loadMaterialAlphaProperties(t,r,a.baseColorFactor)}},n.prototype._loadMaterial=function(e,r,n){if(r.babylonMaterial)return void n(r.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,r,n)||(this._createPbrMaterial(r),this._loadMaterialBaseProperties(e,r),this._loadMaterialMetallicRoughnessProperties(e,r),n(r.babylonMaterial,!0))},n.prototype._createPbrMaterial=function(t){var r=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);r.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=r},n.prototype._loadMaterialBaseProperties=function(t,r){var o=r.babylonMaterial;if(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){var a=n._GetProperty(this._gltf.textures,r.normalTexture.index);if(!a)throw new Error(t+": Failed to find normal texture "+r.normalTexture.index);o.bumpTexture=this._loadTexture("#/textures/"+a.index,a,r.normalTexture.texCoord),o.invertNormalMapX=!this._babylonScene.useRightHandedSystem,o.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=r.normalTexture.scale&&(o.bumpTexture.level=r.normalTexture.scale)}if(r.occlusionTexture){var a=n._GetProperty(this._gltf.textures,r.occlusionTexture.index);if(!a)throw new Error(t+": Failed to find occlusion texture "+r.occlusionTexture.index);o.ambientTexture=this._loadTexture("#/textures/"+a.index,a,r.occlusionTexture.texCoord),o.useAmbientInGrayScale=!0,null!=r.occlusionTexture.strength&&(o.ambientTextureStrength=r.occlusionTexture.strength)}if(r.emissiveTexture){var a=n._GetProperty(this._gltf.textures,r.emissiveTexture.index);if(!a)throw new Error(t+": Failed to find emissive texture "+r.emissiveTexture.index);o.emissiveTexture=this._loadTexture("#/textures/"+a.index,a,r.emissiveTexture.texCoord)}},n.prototype._loadMaterialAlphaProperties=function(t,r,n){var o=r.babylonMaterial;switch(r.alphaMode||"OPAQUE"){case"OPAQUE":o.transparencyMode=e.PBRMaterial.PBRMATERIAL_OPAQUE;break;case"MASK":o.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHATEST,o.alphaCutOff=null==r.alphaCutoff?.5:r.alphaCutoff,n&&(0==n[3]?o.alphaCutOff=1:o.alphaCutOff/=n[3]),o.albedoTexture&&(o.albedoTexture.hasAlpha=!0);break;case"BLEND":o.transparencyMode=e.PBRMaterial.PBRMATERIAL_ALPHABLEND,n&&(o.alpha=n[3]),o.albedoTexture&&(o.albedoTexture.hasAlpha=!0,o.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(t+": Invalid alpha mode "+r.alphaMode)}},n.prototype._loadTexture=function(t,r,o){var a=this,i=void 0==r.sampler?this._defaultSampler:n._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=n._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=o||0,s.wrapU=i.wrapU,s.wrapV=i.wrapV,
- s.name=r.name||"texture"+r.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(s),s},n.prototype._loadSampler=function(e,r){void 0==r.noMipMaps&&(r.noMipMaps=r.minFilter===t.ETextureMinFilter.NEAREST||r.minFilter===t.ETextureMinFilter.LINEAR,r.samplingMode=n._GetTextureSamplingMode(e,r.magFilter,r.minFilter),r.wrapU=n._GetTextureWrapMode(e,r.wrapS),r.wrapV=n._GetTextureWrapMode(e,r.wrapT))},n.prototype._loadImageAsync=function(e,t,r){if(t.uri)this._loadUriAsync(e,t.uri,r);else{var o=n._GetProperty(this._gltf.bufferViews,t.bufferView);if(!o)throw new Error(e+": Failed to find buffer view "+t.bufferView);this._loadBufferViewAsync("#/bufferViews/"+o.index,o,r)}},n.prototype._loadUriAsync=function(r,n,o){var a=this;if(t.GLTFUtils.IsBase64(n))return void o(new Uint8Array(t.GLTFUtils.DecodeBase64(n)));if(!t.GLTFUtils.ValidateUri(n))throw new Error(r+": Uri '"+n+"' is invalid");var i=e.Tools.LoadFile(this._rootUrl+n,(function(e){a._tryCatchOnError((function(){o(new Uint8Array(e))}))}),(function(e){a._tryCatchOnError((function(){i&&!a._renderReady&&(i._loaded=e.loaded,i._total=e.total,a._onProgress())}))}),this._babylonScene.database,!0,(function(e){a._tryCatchOnError((function(){throw new Error(r+": Failed to load '"+n+"'"+(e?": "+e.status+" "+e.statusText:""))}))}));i&&(i._loaded=null,i._total=null,this._requests.push(i))},n.prototype._tryCatchOnError=function(t){if(!this._disposed)try{t()}catch(t){e.Tools.Error("glTF Loader: "+t.message),this._errorCallback&&this._errorCallback(t.message),this.dispose()}},n._AssignIndices=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},n._GetProperty=function(e,t){return e&&void 0!=t&&e[t]?e[t]:null},n._GetTextureWrapMode=function(r,n){switch(n=void 0==n?t.ETextureWrapMode.REPEAT:n){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 "+n),e.Texture.WRAP_ADDRESSMODE}},n._GetTextureSamplingMode=function(r,n,o){if(n=void 0==n?t.ETextureMagFilter.LINEAR:n,o=void 0==o?t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:o,n===t.ETextureMagFilter.LINEAR)switch(o){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 "+o),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(n!==t.ETextureMagFilter.NEAREST&&e.Tools.Warn(r+": Invalid texture magnification filter "+n),o){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 "+o),e.Texture.NEAREST_NEAREST_MIPNEAREST}},n._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)},n.prototype._compileMaterialAsync=function(e,t,r){var n=this;this._parent.useClipPlane?e.forceCompilation(t,(function(){e.forceCompilation(t,(function(){n._tryCatchOnError(r)}),{clipPlane:!0})})):e.forceCompilation(t,(function(){n._tryCatchOnError(r)}))},n.prototype._compileMaterialsAsync=function(t){if(!this._parent.compileMaterials||!this._gltf.materials)return void t();for(var r=this._getMeshes(),n=0,o=0,a=r;o<a.length;o++){var i=a[o];if(i.material instanceof e.MultiMaterial)for(var s=0,l=i.material.subMaterials;s<l.length;s++){var d=l[s];d&&n++}else i.material&&n++}if(0===n)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==--n&&t()}))}else i.material&&this._compileMaterialAsync(i.material,i,(function(){0==--n&&t()}))}},n.prototype._compileShadowGeneratorsAsync=function(e){var t=this;if(!this._parent.compileShadowGenerators)return void e();for(var r=this._babylonScene.lights,n=0,o=0,a=r;o<a.length;o++){var i=a[o],s=i.getShadowGenerator();s&&n++}if(0===n)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==--n&&t._tryCatchOnError(e)}))}},n.Extensions={},n})();t.GLTFLoader=n,e.GLTFFileLoader.CreateGLTFLoaderV2=function(e){return new n(e)}})(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,n=new Uint8Array(new ArrayBuffer(r)),o=0;o<r;o++)n[o]=t.charCodeAt(o);return n.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,n,o){return!1},e.prototype._loadNode=function(e,t,r){return!1},e.prototype._loadMaterial=function(e,t,r,n){return!1},e.prototype._loadExtension=function(e,t,r){var n=this;if(!t.extensions)return!1;var o=t.extensions[this.name];return!!o&&(t.extensions[this.name]=void 0,r(e+"extensions/"+this.name,o,(function(){t.extensions[n.name]=o})),!0)},e.TraverseNode=function(e,t,r,n,o){return this._ApplyExtensions((function(a){return a._traverseNode(e,t,r,n,o)}))},e.LoadNode=function(e,t,r){return this._ApplyExtensions((function(n){return n._loadNode(e,t,r)}))},e.LoadMaterial=function(e,t,r,n){return this._ApplyExtensions((function(o){return o._loadMaterial(e,t,r,n)}))},e._ApplyExtensions=function(t){var r=e._Extensions;if(!r)return!1;for(var n=0,o=r;n<o.length;n++){var a=o[n];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 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.Delay=250,e}return __extends(n,r),Object.defineProperty(n.prototype,"name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),n.prototype._traverseNode=function(e,r,n,o,a){return this._loadExtension(r,n,(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,o,a)}e._traverseNode(r,n,o,a),s()}))},n.prototype._loadNode=function(e,r,n){var o=this;return this._loadExtension(r,n,(function(r,a,i){for(var s=[n],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(n),o._loadNodeLOD(e,r,s,s.length-1,(function(){e._removeLoaderPendingData(n),i()}))}))},n.prototype._loadNodeLOD=function(e,t,r,n,o){var a=this;e._whenAction((function(){e._loadNode(t,r[n])}),(function(){if(n!==r.length-1){r[n+1].babylonMesh.setEnabled(!1)}if(0===n)return void o();setTimeout((function(){e._tryCatchOnError((function(){a._loadNodeLOD(e,t,r,n-1,o)}))}),a.Delay)}))},n.prototype._loadMaterial=function(e,r,n,o){var a=this;return this._loadExtension(r,n,(function(r,i,s){for(var l=[n],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(n),a._loadMaterialLOD(e,r,l,l.length-1,o,(function(){e._removeLoaderPendingData(n),s()}))}))},n.prototype._loadMaterialLOD=function(t,r,n,o,a,i){var s=this;t._loadMaterial(r,n[o],(function(l,d){o===n.length-1?(a(l,d),t._executeWhenRenderReady((function(){s._loadMaterialLOD(t,r,n,o-1,a,i)}))):e.BaseTexture.WhenAllReady(l.getActiveTextures(),(function(){a(l,d),0===o?i():setTimeout((function(){t._tryCatchOnError((function(){s._loadMaterialLOD(t,r,n,o-1,a,i)}))}),s.Delay)}))}))},n})(t.GLTFLoaderExtension);r.MSFTLOD=n,t.GLTFLoader.RegisterExtension(new n)})(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(r){function n(){return null!==r&&r.apply(this,arguments)||this}return __extends(n,r),Object.defineProperty(n.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),n.prototype._loadMaterial=function(e,t,r,n){var o=this;return this._loadExtension(t,r,(function(t,a,i){e._createPbrMaterial(r),e._loadMaterialBaseProperties(t,r),o._loadSpecularGlossinessProperties(e,t,r,a),n(r.babylonMaterial,!0),i()}))},n.prototype._loadSpecularGlossinessProperties=function(r,n,o,a){var i=o.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(n+": 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(n+": 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(n,o,a.diffuseFactor)},n})(t.GLTFLoaderExtension);r.KHRMaterialsPbrSpecularGlossiness=n,t.GLTFLoader.RegisterExtension(new n)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));
|