babylon.glTF2FileLoader.min.js 38 KB

12
  1. var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.PASS_THROUGH=1]="PASS_THROUGH",e[e.FORCE_RIGHT_HANDED=2]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var r=(function(){function e(){this.coordinateSystemMode=t.AUTO,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null)},e.prototype.importMeshAsync=function(t,r,n,a,o,i,s){var l=e._parse(n,s);l&&(this.onParsed&&this.onParsed(l),this._loader=this._getLoader(l,s),this._loader&&this._loader.importMeshAsync(t,r,l,a,o,i,s))},e.prototype.loadAsync=function(t,r,n,a,o,i){var s=e._parse(r,i);if(s&&(this.onParsed&&this.onParsed(s),this._loader=this._getLoader(s,i),this._loader))return this._loader.loadAsync(t,s,n,a,o,i)},e.prototype.canDirectLoad=function(e){return e.indexOf("scene")!==-1&&e.indexOf("node")!==-1},e._parse=function(t,r){try{return t instanceof ArrayBuffer?e._parseBinary(t,r):{json:JSON.parse(t),bin:null}}catch(e){return r(e.message),null}},e.prototype._getLoader=function(t,r){var n={major:2,minor:0},a=t.json.asset||{},o=e._parseVersion(a.version);if(!o)return r("Invalid version: "+a.version),null;if(void 0!==a.minVersion){var i=e._parseVersion(a.minVersion);if(!i)return r("Invalid minimum version: "+a.minVersion),null;if(e._compareVersion(i,n)>0)return r("Incompatible minimum version: "+a.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},l=s[o.major];return l?l(this):(r("Unsupported version: "+a.version),null)},e._parseBinary=function(t,r){var a={Magic:1179937895},o=new n(t),i=o.readUint32();if(i!==a.Magic)return r("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return e._parseV1(o,r);case 2:return e._parseV2(o,r)}return r("Unsupported version: "+s),null},e._parseV1=function(t,r){var n={JSON:0},a=t.readUint32();if(a!=t.getLength())return r("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o,i=t.readUint32(),s=t.readUint32();switch(s){case n.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(i)));break;default:return r("Unexpected content format: "+s),null}var l=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(l)}},e._parseV2=function(t,r){var n={JSON:1313821514,BIN:5130562},a=t.readUint32();if(a!==t.getLength())return r("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o=t.readUint32();if(t.readUint32()!==n.JSON)return r("First chunk format is not JSON"),null;for(var i=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),s=null;t.getPosition()<t.getLength();){var l=t.readUint32();switch(t.readUint32()){case n.JSON:return r("Unexpected JSON chunk"),null;case n.BIN:s=t.readUint8Array(l);break;default:t.skipBytes(l)}}return{json:i,bin:s}},e._parseVersion=function(e){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.HomogeneousCoordinates=!1,e.IncrementalLoading=!0,e})();e.GLTFFileLoader=r;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 r)})(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._renderReady=!1,this._requests=new Array,this._renderReadyObservable=new e.Observable,this._renderPendingCount=0,this._loaderPendingCount=0,this._loaderTrackers=new Array,this._parent=t}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.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,a=this._gltf.textures;n<a.length;n++){var o=a[n];o.url&&URL.revokeObjectURL(o.url)}this._gltf=void 0,this._babylonScene=void 0,this._parent=void 0,this._rootUrl=void 0,this._defaultMaterial=void 0,this._rootNode=void 0,this._successCallback=void 0,this._progressCallback=void 0,this._errorCallback=void 0,this._renderReady=!1,this._requests=void 0,this._renderReadyObservable=void 0,this._renderPendingCount=0,this._loaderPendingCount=0,this._loaderTrackers=void 0}},n.prototype.importMeshAsync=function(e,t,r,n,a,o,i){var s=this;this._loadAsync(e,t,r,n,(function(){a(s._getMeshes(),null,s._getSkeletons())}),o,i)},n.prototype.loadAsync=function(e,t,r,n,a,o){this._loadAsync(null,e,t,r,n,a,o)},n.prototype._loadAsync=function(e,r,n,a,o,i,s){var l=this;this._tryCatchOnError((function(){l._loadData(n),l._babylonScene=r,l._rootUrl=a,l._successCallback=o,l._progressCallback=i,l._errorCallback=s,t.GLTFUtils.AssignIndices(l._gltf.accessors),t.GLTFUtils.AssignIndices(l._gltf.animations),t.GLTFUtils.AssignIndices(l._gltf.buffers),t.GLTFUtils.AssignIndices(l._gltf.bufferViews),t.GLTFUtils.AssignIndices(l._gltf.images),t.GLTFUtils.AssignIndices(l._gltf.materials),t.GLTFUtils.AssignIndices(l._gltf.meshes),t.GLTFUtils.AssignIndices(l._gltf.nodes),t.GLTFUtils.AssignIndices(l._gltf.scenes),t.GLTFUtils.AssignIndices(l._gltf.skins),t.GLTFUtils.AssignIndices(l._gltf.textures),l._addPendingData(l),l._loadDefaultScene(e),l._loadAnimations(),l._removePendingData(l)}))},n.prototype._onError=function(t){this._disposed||(e.Tools.Error("glTF Loader: "+t),this._errorCallback&&this._errorCallback(t),this.dispose())},n.prototype._onProgress=function(e){this._disposed||this._progressCallback&&this._progressCallback(e)},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,t.bin){var r=this._gltf.buffers;if(r&&r[0]&&!r[0].uri){var n=r[0];n.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),n.loadedData=t.bin}else e.Tools.Warn("Unexpected BIN chunk")}},n.prototype._getMeshes=function(){var e=[this._rootNode.babylonMesh],t=this._gltf.nodes;if(t)for(var r=0,n=t;r<n.length;r++){var a=n[r];a.babylonMesh&&e.push(a.babylonMesh)}return e},n.prototype._getSkeletons=function(){var t=new Array,r=this._gltf.skins;if(r)for(var n=0,a=r;n<a.length;n++){var o=a[n];o.babylonSkeleton instanceof e.Skeleton&&t.push(o.babylonSkeleton)}return t},n.prototype._getAnimationTargets=function(){var e=new Array,t=this._gltf.animations;if(t)for(var r=0,n=t;r<n.length;r++){var a=n[r];e.push.apply(e,a.targets)}return e},n.prototype._startAnimations=function(){for(var e=0,t=this._getAnimationTargets();e<t.length;e++){var r=t[e];this._babylonScene.beginAnimation(r,0,Number.MAX_VALUE,!0)}},n.prototype._loadDefaultScene=function(e){var r=t.GLTFUtils.GetArrayItem(this._gltf.scenes,this._gltf.scene||0);if(!r)throw new Error("Failed to find scene "+(this._gltf.scene||0));this._loadScene("#/scenes/"+r.index,r,e)},n.prototype._loadScene=function(r,n,a){switch(this._rootNode={babylonMesh:new e.Mesh("__root__",this._babylonScene)},this._parent.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(this._rootNode.babylonMesh.rotation=new e.Vector3(0,Math.PI,0),this._rootNode.babylonMesh.scaling=new e.Vector3(1,1,-1));break;case e.GLTFLoaderCoordinateSystemMode.PASS_THROUGH: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+")")}var o=n.nodes;if(this._traverseNodes(r,o,(function(e,t){return e.parent=t,!0}),this._rootNode),a){a instanceof Array||(a=[a]);var i=new Array;this._traverseNodes(r,o,(function(e){return a.indexOf(e.name)===-1||(i.push(e.index),!1)}),this._rootNode),o=i}for(var s=0,l=o;s<l.length;s++){var u=l[s],d=t.GLTFUtils.GetArrayItem(this._gltf.nodes,u);if(!d)throw new Error(r+": Failed to find node "+u);this._loadNode("#/nodes/"+u,d)}this._rootNode.babylonMesh.setEnabled(!1)},n.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=t.GLTFUtils.GetArrayItem(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?n.parent.babylonMesh:null,n.babylonAnimationTargets=n.babylonAnimationTargets||[],n.babylonAnimationTargets.push(n.babylonMesh),null!=n.skin){var o=t.GLTFUtils.GetArrayItem(this._gltf.skins,n.skin);if(!o)throw new Error(r+": Failed to find skin "+n.skin);n.babylonMesh.skeleton=this._loadSkin("#/skins/"+n.skin,o)}if(n.camera,n.children)for(var i=0,s=n.children;i<s.length;i++){var l=s[i],u=t.GLTFUtils.GetArrayItem(this._gltf.nodes,l);if(!u)throw new Error(r+": Failed to find child node "+l);this._loadNode("#/nodes/"+l,u)}}},n.prototype._loadMesh=function(r,n,a){var o=this;n.babylonMesh.name=n.babylonMesh.name||a.name;var i=a.primitives;if(!i||0===i.length)throw new Error(r+": Primitives are missing");this._createMorphTargets(r,n,a),this._loadAllVertexDataAsync(r,a,(function(){o._loadMorphTargets(r,n,a);for(var t=new e.VertexData,s=0,l=i;s<l.length;s++){var u=l[s];t.merge(u.vertexData)}new e.Geometry(n.babylonMesh.name,o._babylonScene,t,!1,n.babylonMesh),n.babylonMesh.subMeshes=[];for(var d=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,d,_,c,p,n.babylonMesh),d+=_,c+=p}}));var s=new e.MultiMaterial(n.babylonMesh.name,this._babylonScene);n.babylonMesh.material=s;for(var l=s.subMaterials,u=this,d=0;d<i.length;d++)!(function(e){var a=i[e];if(null==a.material)l[e]=u._getDefaultMaterial();else{var s=t.GLTFUtils.GetArrayItem(u._gltf.materials,a.material);if(!s)throw new Error(r+": Failed to find material "+a.material);u._loadMaterial("#/materials/"+s.index,s,(function(t,r){r&&o._parent.onMaterialLoaded&&o._parent.onMaterialLoaded(t),o._parent.onBeforeMaterialReadyAsync?(o._addLoaderPendingData(s),o._parent.onBeforeMaterialReadyAsync(t,n.babylonMesh,null!=l[e],(function(){o._tryCatchOnError((function(){l[e]=t,o._removeLoaderPendingData(s)}))}))):l[e]=t}))}})(d)},n.prototype._loadAllVertexDataAsync=function(e,t,r){for(var n=t.primitives,a=n.length,o=this,i=0;i<n.length;i++)!(function(i){var s=n[i];o._loadVertexDataAsync(e+"/primitive/"+i,t,s,(function(e){s.vertexData=e,0==--a&&r()}))})(i)},n.prototype._loadVertexDataAsync=function(r,n,a,o){var i=this,s=a.attributes;if(!s)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 l=new e.VertexData,u=Object.keys(s).length,d=this;for(var c in s)!(function(n){var c=t.GLTFUtils.GetArrayItem(d._gltf.accessors,s[n]);if(!c)throw new Error(r+": Failed to find attribute '"+n+"' accessor "+s[n]);d._loadAccessorAsync("#/accessors/"+c.index,c,(function(s){switch(n){case"NORMAL":l.normals=s;break;case"POSITION":l.positions=s;break;case"TANGENT":l.tangents=s;break;case"TEXCOORD_0":l.uvs=s;break;case"TEXCOORD_1":l.uvs2=s;break;case"JOINTS_0":l.matricesIndices=new Float32Array(Array.prototype.slice.apply(s));break;case"WEIGHTS_0":l.matricesWeights=s;break;case"COLOR_0":l.colors=s;break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+n+"'")}if(0==--u)if(null==a.indices){l.indices=new Uint32Array(l.positions.length/3);for(var d=0;d<l.indices.length;d++)l.indices[d]=d;o(l)}else{var c=t.GLTFUtils.GetArrayItem(i._gltf.accessors,a.indices);if(!c)throw new Error(r+": Failed to find indices accessor "+a.indices);i._loadAccessorAsync("#/accessors/"+c.index,c,(function(e){l.indices=e,o(l)}))}}))})(c)},n.prototype._createMorphTargets=function(t,r,n){var a=n.primitives,o=a[0].targets;if(o){for(var i=0,s=a;i<s.length;i++){var l=s[i];if(!l.targets||l.targets.length!=o.length)throw new Error(t+": All primitives are required to list the same number of targets")}var u=new e.MorphTargetManager;r.babylonMesh.morphTargetManager=u;for(var d=0;d<o.length;d++){var c=r.weights?r.weights[d]:n.weights?n.weights[d]:0;u.addTarget(new e.MorphTarget("morphTarget"+d,c))}}},n.prototype._loadMorphTargets=function(t,r,n){var a=r.babylonMesh.morphTargetManager;a&&this._loadAllMorphTargetVertexDataAsync(t,r,n,(function(){for(var t=a.numTargets,r=0;r<t;r++){for(var o=new e.VertexData,i=0,s=n.primitives;i<s.length;i++){var l=s[i];o.merge(l.targetsVertexData[r],{tangentLength:3})}var u=a.getTarget(r);u.setNormals(o.normals),u.setPositions(o.positions),u.setTangents(o.tangents)}}))},n.prototype._loadAllMorphTargetVertexDataAsync=function(e,t,r,n){for(var a=r.primitives.length*t.babylonMesh.morphTargetManager.numTargets,o=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){o._loadMorphTargetVertexDataAsync(e+"/targets/"+i,t.vertexData,r[i],(function(e){t.targetsVertexData[i]=e,0==--a&&n()}))})(i)})(l)}},n.prototype._loadMorphTargetVertexDataAsync=function(r,n,a,o){var i=new e.VertexData,s=Object.keys(a).length,l=this;for(var u in a)!(function(u){var d=t.GLTFUtils.GetArrayItem(l._gltf.accessors,a[u]);if(!d)throw new Error(r+": Failed to find attribute '"+u+"' accessor "+a[u]);l._loadAccessorAsync("#/accessors/"+d.index,d,(function(t){var r=t;switch(u){case"NORMAL":for(var a=0;a<r.length;a++)r[a]+=n.normals[a];i.normals=r;break;case"POSITION":for(var a=0;a<r.length;a++)r[a]+=n.positions[a];i.positions=r;break;case"TANGENT":for(var a=0,l=0;a<r.length;a++,l++)r[a]+=n.tangents[l],(a+1)%3==0&&l++;i.tangents=r;break;default:e.Tools.Warn("Ignoring unrecognized attribute '"+u+"'")}0==--s&&o(i)}))})(u)},n.prototype._loadTransform=function(t){var r=e.Vector3.Zero(),n=e.Quaternion.Identity(),a=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(a,n,r)}else t.translation&&(r=e.Vector3.FromArray(t.translation)),t.rotation&&(n=e.Quaternion.FromArray(t.rotation)),t.scale&&(a=e.Vector3.FromArray(t.scale));t.babylonMesh.position=r,t.babylonMesh.rotationQuaternion=n,t.babylonMesh.scaling=a},n.prototype._loadSkin=function(r,n){var a=this,o="skeleton"+n.index;if(n.babylonSkeleton=new e.Skeleton(n.name||o,o,this._babylonScene),null==n.inverseBindMatrices)this._loadBones(r,n,null);else{var i=t.GLTFUtils.GetArrayItem(this._gltf.accessors,n.inverseBindMatrices);if(!i)throw new Error(r+": Failed to find inverse bind matrices attribute "+n.inverseBindMatrices);this._loadAccessorAsync("#/accessors/"+i.index,i,(function(e){a._loadBones(r,n,e)}))}return n.babylonSkeleton},n.prototype._createBone=function(t,r,n,a,o,i){var s=new e.Bone(t.name||"bone"+t.index,r.babylonSkeleton,n,a,null,o,i);return t.babylonBones=t.babylonBones||{},t.babylonBones[r.index]=s,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(s),s},n.prototype._loadBones=function(e,r,n){for(var a={},o=0,i=r.joints;o<i.length;o++){var s=i[o],l=t.GLTFUtils.GetArrayItem(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find joint "+s);this._loadBone(l,r,n,a)}},n.prototype._loadBone=function(t,r,n,a){var o=a[t.index];if(o)return o;var i=r.joints.indexOf(t.index),s=e.Matrix.Identity();n&&i!==-1&&(s=e.Matrix.FromArray(n,16*i),s.invertToRef(s));var l;return t.index!==r.skeleton&&t.parent!==this._rootNode&&(l=this._loadBone(t.parent,r,n,a),s.multiplyToRef(l.getInvertedAbsoluteTransform(),s)),o=this._createBone(t,r,l,this._getNodeMatrix(t),s,i),a[t.index]=o,o},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,r,n,a){void 0===a&&(a=null);for(var o=0,i=r;o<i.length;o++){var s=i[o],l=t.GLTFUtils.GetArrayItem(this._gltf.nodes,s);if(!l)throw new Error(e+": Failed to find node "+s);this._traverseNode(e,l,n,a)}},n.prototype._traverseNode=function(e,r,n,a){void 0===a&&(a=null),t.GLTFLoaderExtension.TraverseNode(this,e,r,n,a)||n(r,a)&&r.children&&this._traverseNodes(e,r.children,n,r)},n.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e)for(var r=0;r<e.length;r++)for(var n=e[r],a="#/animations/"+r,o=0;o<n.channels.length;o++){var i=t.GLTFUtils.GetArrayItem(n.channels,o);if(!i)throw new Error(a+": Failed to find channel "+o);var s=t.GLTFUtils.GetArrayItem(n.samplers,i.sampler);if(!s)throw new Error(a+": Failed to find sampler "+i.sampler);this._loadAnimationChannel(n,a+"/channels/"+o,i,a+"/samplers/"+i.sampler,s)}},n.prototype._loadAnimationChannel=function(r,n,a,o,i){var s=t.GLTFUtils.GetArrayItem(this._gltf.nodes,a.target.node);if(!s)throw new Error(n+": Failed to find target node "+a.target.node);var l,u;switch(a.target.path){case"translation":l="position",u=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"rotation":l="rotationQuaternion",u=e.Animation.ANIMATIONTYPE_QUATERNION;break;case"scale":l="scaling",u=e.Animation.ANIMATIONTYPE_VECTOR3;break;case"weights":l="influence",u=e.Animation.ANIMATIONTYPE_FLOAT;break;default:throw new Error(n+": Invalid target path '"+a.target.path+"'")}var d,c,f=function(){if(d&&c){var t,n=0;switch(l){case"position":t=function(){var t=e.Vector3.FromArray(c,n);return n+=3,t};break;case"rotationQuaternion":t=function(){var t=e.Quaternion.FromArray(c,n);return n+=4,t};break;case"scaling":t=function(){var t=e.Vector3.FromArray(c,n);return n+=3,t};break;case"influence":t=function(){for(var e=s.babylonMesh.morphTargetManager.numTargets,t=new Array(e),r=0;r<e;r++)t[r]=c[n++];return t}}var a;switch(i.interpolation){case"LINEAR":a=function(e){return{frame:d[e],value:t()}};break;case"CUBICSPLINE":a=function(e){return{frame:d[e],inTangent:t(),value:t(),outTangent:t()}};break;default:throw new Error(o+": Invalid interpolation '"+i.interpolation+"'")}for(var f=new Array(d.length),h=0;h<d.length;h++)f[h]=a(h);if(r.targets=r.targets||[],"influence"===l)for(var _=s.babylonMesh.morphTargetManager,p=0;p<_.numTargets;p++)!(function(t){var n=_.getTarget(t),a=(r.name||"anim"+r.index)+"_"+t,o=new e.Animation(a,l,1,u);o.setKeys(f.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[t]:void 0,value:e.value[t],outTangent:e.outTangent?e.outTangent[t]:void 0}}))),n.animations.push(o),r.targets.push(n)})(p);else{var y=r.name||"anim"+r.index,T=new e.Animation(y,l,1,u);T.setKeys(f);for(var A=0,b=s.babylonAnimationTargets;A<b.length;A++){var g=b[A];g.animations.push(T.clone()),r.targets.push(g)}}}},h=t.GLTFUtils.GetArrayItem(this._gltf.accessors,i.input);if(!h)throw new Error(o+": Failed to find input accessor "+i.input);this._loadAccessorAsync("#/accessors/"+h.index,h,(function(e){d=e,f()}));var _=t.GLTFUtils.GetArrayItem(this._gltf.accessors,i.output);if(!_)throw new Error(o+": Failed to find output accessor "+i.output);this._loadAccessorAsync("#/accessors/"+_.index,_,(function(e){c=e,f()}))},n.prototype._loadBufferAsync=function(r,n,a){var o=this;if(this._addPendingData(n),n.loadedData)a(n.loadedData),this._removePendingData(n);else if(n.loadedObservable)n.loadedObservable.add((function(e){a(e.loadedData),o._removePendingData(e)}));else{if(!n.uri)throw new Error(r+": Uri is missing");if(t.GLTFUtils.IsBase64(n.uri)){var i=t.GLTFUtils.DecodeBase64(n.uri);n.loadedData=new Uint8Array(i),a(n.loadedData),this._removePendingData(n)}else n.loadedObservable=new e.Observable,n.loadedObservable.add((function(e){a(e.loadedData),o._removePendingData(e)})),this._loadUri(r,n.uri,(function(e){n.loadedData=e,n.loadedObservable.notifyObservers(n),n.loadedObservable=null}))}},n.prototype._loadBufferViewAsync=function(e,r,n){var a=this,o=t.GLTFUtils.GetArrayItem(this._gltf.buffers,r.buffer);if(!o)throw new Error(e+": Failed to find buffer "+r.buffer);this._loadBufferAsync("#/buffers/"+o.index,o,(function(t){if(!a._disposed){var o;try{o=new Uint8Array(t.buffer,t.byteOffset+(r.byteOffset||0),r.byteLength)}catch(t){throw new Error(e+": "+t.message)}n(o)}}))},n.prototype._loadAccessorAsync=function(e,r,n){var a=this;if(r.sparse)throw new Error(e+": Sparse accessors are not currently supported");if(r.normalized)throw new Error(e+": Normalized accessors are not currently supported");var o=t.GLTFUtils.GetArrayItem(this._gltf.bufferViews,r.bufferView);if(!o)throw new Error(e+": Failed to find buffer view "+r.bufferView);this._loadBufferViewAsync("#/bufferViews/"+o.index,o,(function(i){var s=a._getNumComponentsOfType(r.type);if(0===s)throw new Error(e+": Invalid type ("+r.type+")");var l;try{switch(r.componentType){case t.EComponentType.BYTE:l=a._buildArrayBuffer(Float32Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.UNSIGNED_BYTE:l=a._buildArrayBuffer(Uint8Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.SHORT:l=a._buildArrayBuffer(Int16Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.UNSIGNED_SHORT:l=a._buildArrayBuffer(Uint16Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.UNSIGNED_INT:l=a._buildArrayBuffer(Uint32Array,i,r.byteOffset,r.count,s,o.byteStride);break;case t.EComponentType.FLOAT:l=a._buildArrayBuffer(Float32Array,i,r.byteOffset,r.count,s,o.byteStride);break;default:throw new Error(e+": Invalid component type ("+r.componentType+")")}}catch(t){throw new Error(e+": "+t)}n(l)}))},n.prototype._getNumComponentsOfType=function(e){switch(e){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}return 0},n.prototype._buildArrayBuffer=function(e,t,r,n,a,o){r=t.byteOffset+(r||0);var i=n*a;if(null==o||o===a*e.BYTES_PER_ELEMENT)return new e(t.buffer,r,i);for(var s=o/e.BYTES_PER_ELEMENT,l=new e(t.buffer,r,s*n),u=new e(i),d=0,c=0;c<i;){for(var f=0;f<a;f++)u[c]=l[d+f],c++;d+=s}return u},n.prototype._addPendingData=function(e){this._renderReady||this._renderPendingCount++,this._addLoaderPendingData(e)},n.prototype._removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._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,a=new r(function(){n._loaderTrackers.splice(n._loaderTrackers.indexOf(a)),t()});this._loaderTrackers.push(a),this._addLoaderPendingData(a),e(),this._removeLoaderPendingData(a)},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(r,n){var a=n.babylonMaterial;a.metallic=1,a.roughness=1;var o=n.pbrMetallicRoughness;if(o){if(a.albedoColor=o.baseColorFactor?e.Color3.FromArray(o.baseColorFactor):new e.Color3(1,1,1),a.metallic=null==o.metallicFactor?1:o.metallicFactor,a.roughness=null==o.roughnessFactor?1:o.roughnessFactor,o.baseColorTexture){var i=t.GLTFUtils.GetArrayItem(this._gltf.textures,o.baseColorTexture.index);if(!i)throw new Error(r+": Failed to find base color texture "+o.baseColorTexture.index);a.albedoTexture=this._loadTexture("#/textures/"+i.index,i,o.baseColorTexture.texCoord)}if(o.metallicRoughnessTexture){var i=t.GLTFUtils.GetArrayItem(this._gltf.textures,o.metallicRoughnessTexture.index);if(!i)throw new Error(r+": Failed to find metallic roughness texture "+o.metallicRoughnessTexture.index);a.metallicTexture=this._loadTexture("#/textures/"+i.index,i,o.metallicRoughnessTexture.texCoord),a.useMetallnessFromMetallicTextureBlue=!0,a.useRoughnessFromMetallicTextureGreen=!0,a.useRoughnessFromMetallicTextureAlpha=!1}this._loadMaterialAlphaProperties(r,n,o.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(r,n){var a=n.babylonMaterial;if(a.emissiveColor=n.emissiveFactor?e.Color3.FromArray(n.emissiveFactor):new e.Color3(0,0,0),n.doubleSided&&(a.backFaceCulling=!1,a.twoSidedLighting=!0),n.normalTexture){var o=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.normalTexture.index);if(!o)throw new Error(r+": Failed to find normal texture "+n.normalTexture.index);a.bumpTexture=this._loadTexture("#/textures/"+o.index,o,n.normalTexture.texCoord),a.invertNormalMapX=!this._babylonScene.useRightHandedSystem,a.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=n.normalTexture.scale&&(a.bumpTexture.level=n.normalTexture.scale)}if(n.occlusionTexture){var o=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.occlusionTexture.index);if(!o)throw new Error(r+": Failed to find occlusion texture "+n.occlusionTexture.index);a.ambientTexture=this._loadTexture("#/textures/"+o.index,o,n.occlusionTexture.texCoord),a.useAmbientInGrayScale=!0,null!=n.occlusionTexture.strength&&(a.ambientTextureStrength=n.occlusionTexture.strength)}if(n.emissiveTexture){var o=t.GLTFUtils.GetArrayItem(this._gltf.textures,n.emissiveTexture.index);if(!o)throw new Error(r+": Failed to find emissive texture "+n.emissiveTexture.index);a.emissiveTexture=this._loadTexture("#/textures/"+o.index,o,n.emissiveTexture.texCoord)}},n.prototype._loadMaterialAlphaProperties=function(e,t,r){var n=t.babylonMaterial;switch(t.alphaMode||"OPAQUE"){case"OPAQUE":break;case"MASK":n.alphaCutOff=null==t.alphaCutoff?.5:t.alphaCutoff,r&&(0==r[3]?n.alphaCutOff=1:n.alphaCutOff/=r[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":r&&(n.alpha=r[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(e+": Invalid alpha mode '"+t.alphaMode+"'")}},n.prototype._loadTexture=function(r,n,a){var o=this,i=null==n.sampler?{}:t.GLTFUtils.GetArrayItem(this._gltf.samplers,n.sampler);if(!i)throw new Error(r+": Failed to find sampler "+n.sampler);var s=i.minFilter===t.ETextureMinFilter.NEAREST||i.minFilter===t.ETextureMinFilter.LINEAR,l=t.GLTFUtils.GetTextureSamplingMode(i.magFilter,i.minFilter);this._addPendingData(n);var u=new e.Texture(null,this._babylonScene,s,!1,l,function(){o._tryCatchOnError((function(){o._removePendingData(n)}))},function(e){o._tryCatchOnError((function(){throw new Error(r+": "+e)}))});if(n.url)u.updateURL(n.url);else if(n.dataReadyObservable)n.dataReadyObservable.add((function(e){u.updateURL(e.url)}));else{n.dataReadyObservable=new e.Observable,n.dataReadyObservable.add((function(e){u.updateURL(e.url)}));var d=t.GLTFUtils.GetArrayItem(this._gltf.images,n.source);if(!d)throw new Error(r+": Failed to find source "+n.source);this._loadImage("#/images/"+d.index,d,(function(e){n.url=URL.createObjectURL(new Blob([e],{type:d.mimeType})),n.dataReadyObservable.notifyObservers(n)}))}return u.coordinatesIndex=a||0,u.wrapU=t.GLTFUtils.GetTextureWrapMode(i.wrapS),u.wrapV=t.GLTFUtils.GetTextureWrapMode(i.wrapT),u.name=n.name||"texture"+n.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(u),u},n.prototype._loadImage=function(e,r,n){if(r.uri)t.GLTFUtils.IsBase64(r.uri)?n(new Uint8Array(t.GLTFUtils.DecodeBase64(r.uri))):this._loadUri(e,r.uri,n);else{var a=t.GLTFUtils.GetArrayItem(this._gltf.bufferViews,r.bufferView);if(!a)throw new Error(e+": Failed to find buffer view "+r.bufferView);this._loadBufferViewAsync("#/bufferViews/"+a.index,a,n)}},n.prototype._loadUri=function(r,n,a){var o=this;if(!t.GLTFUtils.ValidateUri(n))throw new Error(r+": Uri '"+n+"' is invalid");var i=e.Tools.LoadFile(this._rootUrl+n,(function(e){o._tryCatchOnError((function(){a(new Uint8Array(e))}))}),(function(e){o._tryCatchOnError((function(){o._onProgress(e)}))}),this._babylonScene.database,!0,(function(e){o._tryCatchOnError((function(){throw new Error(r+": Failed to load '"+n+"'"+(e?": "+e.status+" "+e.statusText:""))}))}));i&&this._requests.push(i)},n.prototype._tryCatchOnError=function(e){try{e()}catch(e){this._onError(e.message)}},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(t){var r=(function(){function r(){}return r.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},r.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),r=t.length,n=new Uint8Array(new ArrayBuffer(r)),a=0;a<r;a++)n[a]=t.charCodeAt(a);return n.buffer},r.ValidateUri=function(e){return e.indexOf("..")===-1},r.AssignIndices=function(e){if(e)for(var t=0;t<e.length;t++)e[t].index=t},r.GetArrayItem=function(e,t){return e&&e[t]?e[t]:null},r.GetTextureWrapMode=function(r){switch(r=void 0===r?t.ETextureWrapMode.REPEAT:r){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE
  2. ;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:return e.Texture.WRAP_ADDRESSMODE;default:return e.Tools.Warn("Invalid texture wrap mode ("+r+")"),e.Texture.WRAP_ADDRESSMODE}},r.GetTextureSamplingMode=function(r,n){if(r=void 0===r?t.ETextureMagFilter.LINEAR:r,n=void 0===n?t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:n,r===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("Invalid texture minification filter ("+n+")"),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(r!==t.ETextureMagFilter.NEAREST&&e.Tools.Warn("Invalid texture magnification filter ("+r+")"),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("Invalid texture minification filter ("+n+")"),e.Texture.NEAREST_NEAREST_MIPNEAREST}},r})();t.GLTFUtils=r})(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,a){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){var r=this;if(!e.extensions)return!1;var n=e.extensions[this.name];return!!n&&(e.extensions[this.name]=void 0,t(n,(function(){e.extensions[r.name]=n})),!0)},e.TraverseNode=function(e,t,r,n,a){return this._ApplyExtensions((function(o){return o._traverseNode(e,t,r,n,a)}))},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(a){return a._loadMaterial(e,t,r,n)}))},e._ApplyExtensions=function(t){var r=e._Extensions;if(!r)return!1;for(var n=0,a=r;n<a.length;n++){var o=a[n];if(o.enabled&&t(o))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(){return null!==r&&r.apply(this,arguments)||this}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,a,o){return this._loadExtension(n,(function(i,s){for(var l=i.ids.length-1;l>=0;l--){var u=t.GLTFUtils.GetArrayItem(e._gltf.nodes,i.ids[l]);if(!u)throw new Error(r+": Failed to find node "+i.ids[l]);e._traverseNode(r,u,a,o)}e._traverseNode(r,n,a,o),s()}))},n.prototype._loadNode=function(e,t,r){var n=this;return this._loadExtension(r,(function(a,o){var i=[r.index].concat(a.ids).map((function(t){return e._gltf.nodes[t]}));e._addLoaderPendingData(r),n._loadNodeLOD(e,t,i,i.length-1,(function(){e._removeLoaderPendingData(r),o()}))}))},n.prototype._loadNodeLOD=function(e,t,r,a,o){var i=this;e._whenAction((function(){e._loadNode(t,r[a])}),(function(){if(a!==r.length-1){r[a+1].babylonMesh.setEnabled(!1)}if(0===a)return void o();setTimeout((function(){e._tryCatchOnError((function(){i._loadNodeLOD(e,t,r,a-1,o)}))}),n.MinimalLODDelay)}))},n.prototype._loadMaterial=function(e,t,r,n){var a=this;return this._loadExtension(r,(function(o,i){var s=[r.index].concat(o.ids).map((function(t){return e._gltf.materials[t]}));e._addLoaderPendingData(r),a._loadMaterialLOD(e,t,s,s.length-1,n,(function(){r.extensions[a.name]=o,e._removeLoaderPendingData(r),i()}))}))},n.prototype._loadMaterialLOD=function(t,r,a,o,i,s){var l=this;t._loadMaterial(r,a[o],(function(u,d){if(i(u,d),0===o)return void s();t._executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(u.getActiveTextures(),(function(){setTimeout((function(){t._tryCatchOnError((function(){l._loadMaterialLOD(t,r,a,o-1,i,s)}))}),n.MinimalLODDelay)}))}))}))},n.MinimalLODDelay=250,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 a=this;return this._loadExtension(r,(function(o,i){e._createPbrMaterial(r),e._loadMaterialBaseProperties(t,r),a._loadSpecularGlossinessProperties(e,t,r,o),n(r.babylonMaterial,!0)}))},n.prototype._loadSpecularGlossinessProperties=function(r,n,a,o){var i=a.babylonMaterial;if(i.albedoColor=o.diffuseFactor?e.Color3.FromArray(o.diffuseFactor):new e.Color3(1,1,1),i.reflectivityColor=o.specularFactor?e.Color3.FromArray(o.specularFactor):new e.Color3(1,1,1),i.microSurface=null==o.glossinessFactor?1:o.glossinessFactor,o.diffuseTexture){var s=t.GLTFUtils.GetArrayItem(r._gltf.textures,o.diffuseTexture.index);if(!s)throw new Error(n+": Failed to find diffuse texture "+o.diffuseTexture.index);i.albedoTexture=r._loadTexture("textures["+s.index+"]",s,o.diffuseTexture.texCoord)}if(o.specularGlossinessTexture){var s=t.GLTFUtils.GetArrayItem(r._gltf.textures,o.specularGlossinessTexture.index);if(!s)throw new Error(n+": Failed to find diffuse texture "+o.specularGlossinessTexture.index);i.reflectivityTexture=r._loadTexture("textures["+s.index+"]",s,o.specularGlossinessTexture.texCoord),i.reflectivityTexture.hasAlpha=!0,i.useMicroSurfaceFromReflectivityMapAlpha=!0}r._loadMaterialAlphaProperties(n,a,o.diffuseFactor)},n})(t.GLTFLoaderExtension);r.KHRMaterialsPbrSpecularGlossiness=n,t.GLTFLoader.RegisterExtension(new n)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));