babylon.glTF2FileLoader.min.js 23 KB

1
  1. var BABYLON;!(function(e){var t=(function(){function t(){this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return t.prototype.importMeshAsync=function(e,r,n,a,o,i){var s=t._parse(n),l=this._getLoader(s);if(!l)return void i();l.importMeshAsync(e,r,s,a,o,i)},t.prototype.loadAsync=function(e,r,n,a,o){var i=t._parse(r),s=this._getLoader(i);return s?s.loadAsync(e,i,n,a,o):void o()},t.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},t._parse=function(e){return e instanceof ArrayBuffer?t._parseBinary(e):{json:JSON.parse(e),bin:null}},t.prototype._getLoader=function(r){var n={major:2,minor:0},a=r.json.asset||{},o=t._parseVersion(a.version);if(!o)return e.Tools.Error("Invalid version"),null;var i=t._parseVersion(a.minVersion);if(i&&t._compareVersion(i,n)>0)return e.Tools.Error("Incompatible version"),null;var s={1:t.GLTFLoaderV1,2:t.GLTFLoaderV2},l=s[o.major];return void 0===l?(e.Tools.Error("Unsupported version"),null):null===l?(e.Tools.Error("v"+o.major+" loader is not available"),null):l},t._parseBinary=function(n){var a={Magic:1179937895},o=new r(n),i=o.readUint32();if(i!==a.Magic)return e.Tools.Error("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return t._parseV1(o);case 2:return t._parseV2(o)}return e.Tools.Error("Unsupported version: "+s),null},t._parseV1=function(r){var n={JSON:0},a=r.readUint32();if(a!=r.getLength())return e.Tools.Error("Length in header does not match actual data length: "+a+" != "+r.getLength()),null;var o,i=r.readUint32(),s=r.readUint32();switch(s){case n.JSON:o=JSON.parse(t._decodeBufferToText(r.readUint8Array(i)));break;default:return e.Tools.Error("Unexpected content format: "+s),null}var l=r.getLength()-r.getPosition();return{json:o,bin:r.readUint8Array(l)}},t._parseV2=function(r){var n={JSON:1313821514,BIN:5130562},a=r.readUint32();if(a!==r.getLength())return e.Tools.Error("Length in header does not match actual data length: "+a+" != "+r.getLength()),null;var o=r.readUint32(),i=r.readUint32();if(i!==n.JSON)return e.Tools.Error("First chunk format is not JSON"),null;for(var s=JSON.parse(t._decodeBufferToText(r.readUint8Array(o))),l=null;r.getPosition()<r.getLength();)switch(o=r.readUint32(),i=r.readUint32()){case n.JSON:return e.Tools.Error("Unexpected JSON chunk"),null;case n.BIN:l=r.readUint8Array(o);break;default:r.skipBytes(o)}return{json:s,bin:l}},t._parseVersion=function(e){if(!e)return null;var t=e.split(".");if(0===t.length)return null;var r=parseInt(t[0]);if(r>1&&2!=t.length)return null;parseInt(t[1]);return{major:r,minor:parseInt(t[0])}},t._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},t._decodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;++n)t+=String.fromCharCode(e[n]);return t},t})();t.GLTFLoaderV1=null,t.GLTFLoaderV2=null,t.HomogeneousCoordinates=!1,t.IncrementalLoading=!0,e.GLTFFileLoader=t;var r=(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.RegisterPlugin(new t)})(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 r(){}return r.RegisterExtension=function(t){if(r.Extensions[t.name])return void e.Tools.Error("Extension with the same name '"+t.name+"' already exists");this.Extensions[t.name]=t},r.LoadMaterial=function(t){return e.GLTFFileLoader.GLTFLoaderV2._loadMaterial(t)},r.LoadCoreMaterial=function(t){return e.GLTFFileLoader.GLTFLoaderV2._loadCoreMaterial(t)},r.LoadCommonMaterialProperties=function(t){return e.GLTFFileLoader.GLTFLoaderV2._loadCommonMaterialProperties(t)},r.LoadAlphaProperties=function(t){return e.GLTFFileLoader.GLTFLoaderV2._loadAlphaProperties(t)},r.LoadTexture=function(t){return e.GLTFFileLoader.GLTFLoaderV2._loadTexture(t)},r.prototype.importMeshAsync=function(t,r,n,a,o,i){var s=this;this._loadAsync(t,r,n,a,(function(){for(var t=[],r=0;r<s._gltf.nodes.length;r++){var n=s._gltf.nodes[r];n.babylonNode instanceof e.AbstractMesh&&t.push(n.babylonNode)}for(var a=[],r=0;r<s._gltf.skins.length;r++){var i=s._gltf.skins[r];i.babylonSkeleton instanceof e.Skeleton&&a.push(i.babylonSkeleton)}o(t,null,a)}),i)},r.prototype.loadAsync=function(e,t,r,n,a){this._loadAsync(null,e,t,r,n,a)},r.prototype._loadAsync=function(t,r,n,a,o,i){var s=this;r.useRightHandedSystem=!0,this._clear(),this._loadData(n),this._babylonScene=r,this._rootUrl=a,this._onLoaded=function(){s._showMeshes(),s._startFirstAnimation(),0===s._errors.length?o():(s._errors.forEach((function(t){return e.Tools.Error(t)})),i()),s._clear()},this._addPendingData(this),this._loadScene(t),this._loadAnimations(),this._removePendingData(this)},r.prototype._loadData=function(t){this._gltf=t.json;var r,n=this._gltf.buffers;n.length>0&&void 0===n[0].uri&&(r=n[0]),t.bin&&(r?r.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+r.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"):e.Tools.Warn("Unexpected BIN chunk"),r.loadedData=t.bin)},r.prototype._showMeshes=function(){for(var t=this._gltf.nodes,r=0;r<t.length;r++){var n=t[r];n.babylonNode instanceof e.Mesh&&(n.babylonNode.isVisible=!0)}},r.prototype._startFirstAnimation=function(){var e=this._gltf.animations;if(e)for(var t=e[0],r=0;r<t.targets.length;r++)this._babylonScene.beginAnimation(t.targets[r],0,Number.MAX_VALUE,!0)},r.prototype._clear=function(){if(this._gltf=void 0,this._pendingCount=0,this._onLoaded=void 0,this._errors=[],this._babylonScene=void 0,this._rootUrl=void 0,this._defaultMaterial=void 0,this._gltf&&this._gltf.textures)for(var e=0;e<this._gltf.textures.length;e++){var t=this._gltf.textures[e];t.blobURL&&URL.revokeObjectURL(t.blobURL)}},r.prototype._loadScene=function(e){var t=this,r=this._gltf.scenes[this._gltf.scene||0];this._traverseScene(e,r,(function(e){return t._loadSkin(e)})),this._traverseScene(e,r,(function(e,r){return t._loadMesh(e,r)}))},r.prototype._loadSkin=function(t){var r=this;if(t.babylonNode)return!1;if(void 0!==t.skin){var n=this._gltf.skins[t.skin],a="skeleton"+t.skin;n.babylonSkeleton=new e.Skeleton(n.name||a,a,this._babylonScene);for(var o=0;o<n.joints.length;o++){var i=n.joints[o],s=this._gltf.nodes[i];s.babylonNode=new e.Bone(s.name||"bone"+i,n.babylonSkeleton)}if(void 0===n.skeleton)throw new Error("Not implemented");if(void 0===n.inverseBindMatrices)throw new Error("Not implemented");var l=this._gltf.accessors[n.inverseBindMatrices];this._loadAccessorAsync(l,(function(e){r._traverseNode(null,n.skeleton,(function(t,a){return r._updateBone(t,a,n,e)}))}))}return!0},r.prototype._updateBone=function(t,r,n,a){var o=n.joints.indexOf(t.index);if(-1===o)throw new Error("Not implemented");var i=t.babylonNode,s=e.Matrix.FromArray(a,16*o);return s.invertToRef(s),r&&(i.setParent(r.babylonNode,!1),s.multiplyToRef(i.getParent().getInvertedAbsoluteTransform(),s)),i.updateMatrix(s),!0},r.prototype._loadMesh=function(t,r){if(t.babylonNode){if(t.babylonNode instanceof e.Bone&&void 0!==t.mesh)throw new Error("Not implemented");return!1}var n=new e.Mesh(t.name||"mesh"+t.index,this._babylonScene);if(n.isVisible=!1,this._loadTransform(t,n),void 0!==t.mesh){var a=this._gltf.meshes[t.mesh];this._loadMeshData(t,a,n)}if(n.parent=r?r.babylonNode:null,t.babylonNode=n,void 0!==t.skin){var o=this._gltf.skins[t.skin];n.skeleton=o.babylonSkeleton}return t.camera,!0},r.prototype._loadMeshData=function(r,n,a){var o=this;a.name=n.name||a.name,a.subMeshes=[];var i=new e.MultiMaterial(a.name,this._babylonScene);a.material=i;var s=new e.Geometry(a.name,this._babylonScene,null,!1,a),l=new e.VertexData;l.positions=[],l.indices=[];for(var u=0,c=n.primitives.length,d=0;d<c;d++){var f=n.primitives[d];if(f.mode&&f.mode!==t.EMeshPrimitiveMode.TRIANGLES)throw new Error("Not implemented");this._createMorphTargets(r,n,f,a),this._loadVertexDataAsync(f,(function(r){o._loadMorphTargetsData(n,f,r,a);var d=(new e.SubMesh(i.subMaterials.length,l.positions.length,r.positions.length,l.indices.length,r.indices.length,a),void 0===f.material?o._getDefaultMaterial():t.GLTFLoaderExtension.LoadMaterial(f.material));i.subMaterials.push(d),l.merge(r),++u===c&&s.setAllVerticesData(l,!1)}))}},r.prototype._loadVertexDataAsync=function(t,r){var n=this,a=t.attributes;if(!a)return void this._errors.push("Primitive has no attributes");var o,i=new e.VertexData,s=0,l=Object.keys(a).length,u=this;for(var c in a)!(function(c){o=u._gltf.accessors[a[c]],u._loadAccessorAsync(o,(function(a){switch(c){case"NORMAL":i.normals=a;break;case"POSITION":i.positions=a;break;case"TANGENT":i.tangents=a;break;case"TEXCOORD_0":i.uvs=a;break;case"TEXCOORD_1":i.uvs2=a;break;case"JOINTS_0":i.matricesIndices=new Float32Array(Array.prototype.slice.apply(a));break;case"WEIGHTS_0":i.matricesWeights=a;break;case"COLOR_0":i.colors=a;break;default:e.Tools.Warn("Ignoring unrecognized semantic '"+c+"'")}if(++s===l){var o=n._gltf.accessors[t.indices];o?n._loadAccessorAsync(o,(function(e){i.indices=e,r(i)})):(i.indices=new Uint32Array(i.positions.length/3),i.indices.forEach((function(e,t){return i.indices[t]=t})),r(i))}}))})(c)},r.prototype._createMorphTargets=function(t,r,n,a){var o=n.targets;if(o){a.morphTargetManager||(a.morphTargetManager=new e.MorphTargetManager);for(var i=0;i<o.length;i++){var s=t.weights?t.weights[i]:r.weights?r.weights[i]:0;a.morphTargetManager.addTarget(new e.MorphTarget("morphTarget"+i,s))}}},r.prototype._loadMorphTargetsData=function(t,r,n,a){var o=r.targets;if(o)for(var i,s,l=this,u=0;u<o.length;u++)!(function(){var t=a.morphTargetManager.getTarget(u);i=o[u];for(var r in i)!(function(r){s=l._gltf.accessors[i[r]],l._loadAccessorAsync(s,(function(a){s.name&&(t.name=s.name);var o=a;switch(r){case"NORMAL":o.forEach((function(e,t){return o[t]+=n.normals[t]})),t.setNormals(o);break;case"POSITION":o.forEach((function(e,t){return o[t]+=n.positions[t]})),t.setPositions(o);break;case"TANGENT":for(var i=0,l=0;i<o.length;i++,l++)o[i]+=n.tangents[l],(i+1)%3==0&&l++;t.setTangents(o);break;default:e.Tools.Warn("Ignoring unrecognized semantic '"+r+"'")}}))})(r)})()},r.prototype._loadTransform=function(t,r){var n=e.Vector3.Zero(),a=e.Quaternion.Identity(),o=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(o,a,n)}else t.translation&&(n=e.Vector3.FromArray(t.translation)),t.rotation&&(a=e.Quaternion.FromArray(t.rotation)),t.scale&&(o=e.Vector3.FromArray(t.scale));r.position=n,r.rotationQuaternion=a,r.scaling=o},r.prototype._traverseScene=function(e,t,r){var n=t.nodes;if(n)for(var a=0;a<n.length;a++)this._traverseNode(e,n[a],r)},r.prototype._traverseNode=function(e,t,r,n){void 0===n&&(n=null);var a=this._gltf.nodes[t];if(e){if(!e.indexOf(a.name))return;e=null}if(a.index=t,r(a,n)&&a.children)for(var o=0;o<a.children.length;o++)this._traverseNode(e,a.children[o],r,a)},r.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e&&0!==e.length)for(var t=0;t<e.length;t++)for(var r=e[t],n=0;n<r.channels.length;n++)this._loadAnimationChannel(r,t,n)},r.prototype._loadAnimationChannel=function(t,r,n){var a=t.channels[n],o=a.sampler,i=t.samplers[o],s=this._gltf.nodes[a.target.node].babylonNode;if(!s)return void e.Tools.Warn("Animation channel target node ("+a.target.node+") does not exist");var l={translation:"position",rotation:"rotationQuaternion",scale:"scaling",weights:"influence"}[a.target.path];if(!l)return void e.Tools.Warn("Animation channel target path '"+a.target.path+"' is not valid");var u,c,d={position:e.Animation.ANIMATIONTYPE_VECTOR3,rotationQuaternion:e.Animation.ANIMATIONTYPE_QUATERNION,scaling:e.Animation.ANIMATIONTYPE_VECTOR3,influence:e.Animation.ANIMATIONTYPE_FLOAT}[l],f=function(){if(u&&c){for(var n=0,a={position:function(){var t=e.Vector3.FromArray(c,n);return n+=3,t},rotationQuaternion:function(){var t=e.Quaternion.FromArray(c,n);return n+=4,t},scaling:function(){var t=e.Vector3.FromArray(c,n);return n+=3,t},influence:function(){for(var e=s.morphTargetManager.numTargets,t=new Array(e),r=0;r<e;r++)t[r]=c[n++];return t}}[l],o={LINEAR:function(e){return{frame:u[e],value:a()}},CUBICSPLINE:function(e){return{frame:u[e],inTangent:a(),value:a(),outTangent:a()}}}[i.interpolation],f=new Array(u.length),h=0;h<u.length;h++)f[h]=o(h);if(t.targets=t.targets||[],"influence"===l)for(var T=s,b=0;b<T.morphTargetManager.numTargets;b++){var p=T.morphTargetManager.getTarget(b),_=(t.name||"anim"+r)+"_"+b,y=new e.Animation(_,l,1,d);y.setKeys(f.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[b]:void 0,value:e.value[b],outTangent:e.outTangent?e.outTangent[b]:void 0}}))),p.animations.push(y),t.targets.push(p)}else{var _=t.name||"anim"+r,y=new e.Animation(_,l,1,d);y.setKeys(f),s.animations.push(y),t.targets.push(s)}}};this._loadAccessorAsync(this._gltf.accessors[i.input],(function(e){u=e,f()})),this._loadAccessorAsync(this._gltf.accessors[i.output],(function(e){c=e,f()}))},r.prototype._loadBufferAsync=function(r,n){var a=this,o=this._gltf.buffers[r];if(this._addPendingData(o),o.loadedData)setTimeout((function(){n(o.loadedData),a._removePendingData(o)}));else if(t.GLTFUtils.IsBase64(o.uri)){var i=t.GLTFUtils.DecodeBase64(o.uri);o.loadedData=new Uint8Array(i),setTimeout((function(){n(o.loadedData),a._removePendingData(o)}))}else o.loadedObservable?o.loadedObservable.add((function(e){n(e.loadedData),a._removePendingData(e)})):(o.loadedObservable=new e.Observable,o.loadedObservable.add((function(e){n(e.loadedData),a._removePendingData(e)})),e.Tools.LoadFile(this._rootUrl+o.uri,(function(e){o.loadedData=new Uint8Array(e),o.loadedObservable.notifyObservers(o),o.loadedObservable=null}),null,null,!0,(function(e){a._errors.push("Failed to load file '"+o.uri+"': "+e.statusText+"("+e.status+")"),a._removePendingData(o)})))},r.prototype._loadBufferViewAsync=function(e,r,n,a,o){var i=this;r+=e.byteOffset||0,this._loadBufferAsync(e.buffer,(function(e){if(r+n>e.byteLength)return void i._errors.push("Buffer access is out of range");var s=e.buffer;r+=e.byteOffset;var l;switch(a){case t.EComponentType.BYTE:l=new Int8Array(s,r,n);break;case t.EComponentType.UNSIGNED_BYTE:l=new Uint8Array(s,r,n);break;case t.EComponentType.SHORT:l=new Int16Array(s,r,n);break;case t.EComponentType.UNSIGNED_SHORT:l=new Uint16Array(s,r,n);break;case t.EComponentType.UNSIGNED_INT:l=new Uint32Array(s,r,n);break;case t.EComponentType.FLOAT:l=new Float32Array(s,r,n);break;default:return void i._errors.push("Invalid component type ("+a+")")}o(l)}))},r.prototype._loadAccessorAsync=function(e,r){var n=this._gltf.bufferViews[e.bufferView],a=e.byteOffset||0,o=e.count*t.GLTFUtils.GetByteStrideFromType(e);this._loadBufferViewAsync(n,a,o,e.componentType,r)},r.prototype._addPendingData=function(e){this._pendingCount++},r.prototype._removePendingData=function(e){0==--this._pendingCount&&this._onLoaded()},r.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},r.prototype._loadMaterial=function(t){var r=this._gltf.materials,n=r?r[t]:null;return n?(n.babylonMaterial=new e.PBRMaterial(n.name||"mat"+t,this._babylonScene),n.babylonMaterial.sideOrientation=e.Material.CounterClockWiseSideOrientation,n.babylonMaterial.useScalarInLinearSpace=!0,n):(e.Tools.Warn("Material index ("+t+") does not exist"),null)},r.prototype._loadCoreMaterial=function(t){var r=this._loadMaterial(t);if(!r)return null;this._loadCommonMaterialProperties(r),r.babylonMaterial.metallic=1,r.babylonMaterial.roughness=1;var n=r.pbrMetallicRoughness;return n?(r.babylonMaterial.albedoColor=n.baseColorFactor?e.Color3.FromArray(n.baseColorFactor):new e.Color3(1,1,1),r.babylonMaterial.metallic=void 0===n.metallicFactor?1:n.metallicFactor,r.babylonMaterial.roughness=void 0===n.roughnessFactor?1:n.roughnessFactor,n.baseColorTexture&&(r.babylonMaterial.albedoTexture=this._loadTexture(n.baseColorTexture),this._loadAlphaProperties(r)),n.metallicRoughnessTexture&&(r.babylonMaterial.metallicTexture=this._loadTexture(n.metallicRoughnessTexture),r.babylonMaterial.useMetallnessFromMetallicTextureBlue=!0,r.babylonMaterial.useRoughnessFromMetallicTextureGreen=!0,r.babylonMaterial.useRoughnessFromMetallicTextureAlpha=!1),r.babylonMaterial):void 0},r.prototype._loadCommonMaterialProperties=function(t){t.babylonMaterial.useEmissiveAsIllumination=!(!t.emissiveFactor&&!t.emissiveTexture),t.babylonMaterial.emissiveColor=t.emissiveFactor?e.Color3.FromArray(t.emissiveFactor):new e.Color3(0,0,0),t.doubleSided&&(t.babylonMaterial.backFaceCulling=!1,t.babylonMaterial.twoSidedLighting=!0),t.normalTexture&&(t.babylonMaterial.bumpTexture=this._loadTexture(t.normalTexture),void 0!==t.normalTexture.scale&&(t.babylonMaterial.bumpTexture.level=t.normalTexture.scale)),t.occlusionTexture&&(t.babylonMaterial.ambientTexture=this._loadTexture(t.occlusionTexture),t.babylonMaterial.useAmbientInGrayScale=!0,void 0!==t.occlusionTexture.strength&&(t.babylonMaterial.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&(t.babylonMaterial.emissiveTexture=this._loadTexture(t.emissiveTexture))},r.prototype._loadAlphaProperties=function(t){switch(t.alphaMode||"OPAQUE"){case"OPAQUE":break;case"MASK":t.babylonMaterial.albedoTexture.hasAlpha=!0,t.babylonMaterial.useAlphaFromAlbedoTexture=!1,t.babylonMaterial.alphaMode=e.Engine.ALPHA_DISABLE;break;case"BLEND":t.babylonMaterial.albedoTexture.hasAlpha=!0,t.babylonMaterial.useAlphaFromAlbedoTexture=!0,t.babylonMaterial.alphaMode=e.Engine.ALPHA_COMBINE;break;default:e.Tools.Error("Invalid alpha mode '"+t.alphaMode+"'")}},r.prototype._loadTexture=function(r){var n=this,a=this._gltf.textures[r.index],o=r.texCoord||0;if(!a||void 0===a.source)return null;var i;if(a.babylonTextures){if(!(i=a.babylonTextures[o]))for(var s=0;s<a.babylonTextures.length;s++)if(i=a.babylonTextures[s]){i=i.clone(),i.coordinatesIndex=o;break}return i}var l,u=this._gltf.images[a.source];if(u.uri)if(t.GLTFUtils.IsBase64(u.uri)){var c=new Uint8Array(t.GLTFUtils.DecodeBase64(u.uri));a.blobURL=URL.createObjectURL(new Blob([c],{type:u.mimeType})),l=a.blobURL}else l=this._rootUrl+u.uri;else{var d=this._gltf.bufferViews[u.bufferView];this._loadBufferViewAsync(d,0,d.byteLength,t.EComponentType.UNSIGNED_BYTE,(function(e){a.blobURL=URL.createObjectURL(new Blob([e],{type:u.mimeType})),a.babylonTextures[o].updateURL(a.blobURL)}))}var f=void 0===a.sampler?{}:this._gltf.samplers[a.sampler],h=f.minFilter===t.ETextureMinFilter.NEAREST||f.minFilter===t.ETextureMinFilter.LINEAR,T=t.GLTFUtils.GetTextureFilterMode(f.minFilter);this._addPendingData(a);var i=new e.Texture(l,this._babylonScene,h,!1,T,function(){n._removePendingData(a)},function(){n._errors.push("Failed to load texture '"+u.uri+"'"),n._removePendingData(a)});return i.coordinatesIndex=o,i.wrapU=t.GLTFUtils.GetWrapMode(f.wrapS),i.wrapV=t.GLTFUtils.GetWrapMode(f.wrapT),i.name=a.name,a.babylonTextures=a.babylonTextures||[],a.babylonTextures[o]=i,i},r})();r.Extensions={},t.GLTFLoader=r,e.GLTFFileLoader.GLTFLoaderV2=new r})(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.GetWrapMode=function(r){switch(r){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:default:return e.Texture.WRAP_ADDRESSMODE}},r.GetByteStrideFromType=function(e){switch(e.type){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 1}},r.GetTextureFilterMode=function(r){switch(r){case t.ETextureMinFilter.LINEAR:case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.TRILINEAR_SAMPLINGMODE;case t.ETextureMinFilter.NEAREST:case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_SAMPLINGMODE;default:return e.Texture.BILINEAR_SAMPLINGMODE}},r.DecodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;n<r;++n)t+=String.fromCharCode(e[n]);return t},r})();t.GLTFUtils=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function t(e){this.enabled=!0,this._name=e}return Object.defineProperty(t.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),t.prototype.loadMaterial=function(e){return null},t.LoadMaterial=function(t){for(var r in e.GLTFLoader.Extensions){var n=e.GLTFLoader.Extensions[r];if(n.enabled){var a=n.loadMaterial(t);if(a)return a}}return e.GLTFLoader.LoadCoreMaterial(t)},t})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(r){function n(){return r.call(this,"KHR_materials_pbrSpecularGlossiness")||this}return __extends(n,r),n.prototype.loadMaterial=function(r){var n=t.GLTFLoader.LoadMaterial(r);if(!n||!n.extensions)return null;var a=n.extensions[this.name];return a?(t.GLTFLoader.LoadCommonMaterialProperties(n),n.babylonMaterial.albedoColor=a.diffuseFactor?e.Color3.FromArray(a.diffuseFactor):new e.Color3(1,1,1),n.babylonMaterial.reflectivityColor=a.specularFactor?e.Color3.FromArray(a.specularFactor):new e.Color3(1,1,1),n.babylonMaterial.microSurface=void 0===a.glossinessFactor?1:a.glossinessFactor,a.diffuseTexture&&(n.babylonMaterial.albedoTexture=t.GLTFLoader.LoadTexture(a.diffuseTexture),t.GLTFLoader.LoadAlphaProperties(n)),a.specularGlossinessTexture&&(n.babylonMaterial.reflectivityTexture=t.GLTFLoader.LoadTexture(a.specularGlossinessTexture),n.babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha=!0),n.babylonMaterial):null},n})(t.GLTFLoaderExtension);t.GLTFMaterialsPbrSpecularGlossinessExtension=r,t.GLTFLoader.RegisterExtension(new r)})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));