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 n=(function(){function e(){this.coordinateSystemMode=t.AUTO,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.importMeshAsync=function(t,n,r,o,a,i,s){var u=e._parse(r,s);if(u){this.onParsed&&this.onParsed(u);var l=this._getLoader(u,s);l&&l.importMeshAsync(t,n,u,o,a,i,s)}},e.prototype.loadAsync=function(t,n,r,o,a,i){var s=e._parse(n,i);if(s){this.onParsed&&this.onParsed(s);var u=this._getLoader(s,i);if(u)return u.loadAsync(t,s,r,o,a,i)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e._parse=function(t,n){try{return t instanceof ArrayBuffer?e._parseBinary(t,n):{json:JSON.parse(t),bin:null}}catch(e){return n(e.message),null}},e.prototype._getLoader=function(t,n){var r={major:2,minor:0},o=t.json.asset||{},a=e._parseVersion(o.version);if(!a)return n("Invalid version: "+o.version),null;if(void 0!==o.minVersion){var i=e._parseVersion(o.minVersion);if(!i)return n("Invalid minimum version: "+o.minVersion),null;if(e._compareVersion(i,r)>0)return n("Incompatible minimum version: "+o.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},u=s[a.major];return u?u(this):(n("Unsupported version: "+o.version),null)},e._parseBinary=function(t,n){var o={Magic:1179937895},a=new r(t),i=a.readUint32();if(i!==o.Magic)return n("Unexpected magic: "+i),null;var s=a.readUint32();switch(s){case 1:return e._parseV1(a,n);case 2:return e._parseV2(a,n)}return n("Unsupported version: "+s),null},e._parseV1=function(t,n){var r={JSON:0},o=t.readUint32();if(o!=t.getLength())return n("Length in header does not match actual data length: "+o+" != "+t.getLength()),null;var a,i=t.readUint32(),s=t.readUint32();switch(s){case r.JSON:a=JSON.parse(e._decodeBufferToText(t.readUint8Array(i)));break;default:return n("Unexpected content format: "+s),null}var u=t.getLength()-t.getPosition();return{json:a,bin:t.readUint8Array(u)}},e._parseV2=function(t,n){var r={JSON:1313821514,BIN:5130562},o=t.readUint32();if(o!==t.getLength())return n("Length in header does not match actual data length: "+o+" != "+t.getLength()),null;var a=t.readUint32(),i=t.readUint32();if(i!==r.JSON)return n("First chunk format is not JSON"),null;for(var s=JSON.parse(e._decodeBufferToText(t.readUint8Array(a))),u=null;t.getPosition()t.major?1:e.majort.minor?1:e.minor=this._maxPos},e})(),o=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],a=["world","view","projection","worldView","worldViewProjection","mBones"],i=["translation","rotation","scale"],s=["position","rotationQuaternion","scaling"],u=function(e,t){for(var n in e){var r=e[n];t.buffers[n]=r,t.buffersCount++}},l=function(e,t){for(var n in e){var r=e[n];t.shaders[n]=r,t.shaderscount++}},c=function(e,t,n){for(var r in e){var o=e[r];n[t][r]=o}},f=function(e){if(e)for(var t=0;t0&&(y=T(u,i))&&-1===l.indexOf(y)&&l.push(y);new e.Bone(d.jointName,a,y,b).id=i}}else e.Tools.Warn("Joint named "+r.jointNames[c]+" does not exist")}var M=a.bones;a.bones=[];for(var c=0;c0&&-1===t.importMeshesNames.indexOf(n.name))return null;if(n.skin){if(n.meshes){var i=t.skins[n.skin],s=g(t,n,n.meshes,r,n.babylonNode);s.skeleton=t.scene.getLastSkeletonByID(n.skin),null===s.skeleton&&(s.skeleton=y(t,i,0,i.babylonSkeleton,n.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),a=s}}else if(n.meshes){var s=g(t,n,n.mesh?[n.mesh]:n.meshes,r,n.babylonNode);a=s}else if(!n.light||n.babylonNode||t.importOnlyMeshes){if(n.camera&&!n.babylonNode&&!t.importOnlyMeshes){var u=t.cameras[n.camera];if(u)if("orthographic"===u.type){var l=(u[u.type],new e.FreeCamera(n.camera,e.Vector3.Zero(),t.scene));l.name=n.name,l.mode=e.Camera.ORTHOGRAPHIC_CAMERA,l.attachControl(t.scene.getEngine().getRenderingCanvas()),a=l}else if("perspective"===u.type){var c=u[u.type],f=new e.FreeCamera(n.camera,e.Vector3.Zero(),t.scene);f.name=n.name,f.attachControl(t.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(f.maxZ=c.zfar,f.minZ=c.znear),a=f}}}else{var d=t.lights[n.light];if(d)if("ambient"===d.type){var h=d[d.type],_=new e.HemisphericLight(n.light,e.Vector3.Zero(),t.scene);_.name=n.name,h.color&&(_.diffuse=e.Color3.FromArray(h.color)),a=_}else if("directional"===d.type){var p=d[d.type],T=new e.DirectionalLight(n.light,e.Vector3.Zero(),t.scene);T.name=n.name,p.color&&(T.diffuse=e.Color3.FromArray(p.color)),a=T}else if("point"===d.type){var A=d[d.type],E=new e.PointLight(n.light,e.Vector3.Zero(),t.scene);E.name=n.name,A.color&&(E.diffuse=e.Color3.FromArray(A.color)),a=E}else if("spot"===d.type){var m=d[d.type],N=new e.SpotLight(n.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);N.name=n.name,m.color&&(N.diffuse=e.Color3.FromArray(m.color)),m.fallOfAngle&&(N.angle=m.fallOfAngle),m.fallOffExponent&&(N.exponent=m.fallOffExponent),a=N}}if(!n.jointName){if(n.babylonNode)return n.babylonNode;if(null===a){var b=new e.Mesh(n.name,t.scene);n.babylonNode=b,a=b}}if(null!==a){if(n.matrix&&a instanceof e.Mesh)L(a,n);else{var M=n.translation||[0,0,0],x=n.rotation||[0,0,0,1],O=n.scale||[1,1,1];v(a,e.Vector3.FromArray(M),e.Quaternion.FromArray(x),e.Vector3.FromArray(O))}a.updateCache(!0),n.babylonNode=a}return a},b=function(e,t,n,r){var o=e.nodes[t],a=null;if(r=!(e.importOnlyMeshes&&!r)||(-1!==e.importMeshesNames.indexOf(o.name)||0===e.importMeshesNames.length),!o.jointName&&r&&null!==(a=N(e,o,t))&&(a.id=t,a.parent=n),o.children)for(var i=0;ii.byteLength)throw new Error("Buffer access is out of range");var s=i.buffer;switch(r+=i.byteOffset,a){case t.EComponentType.BYTE:return new Int8Array(s,r,o);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,r,o);case t.EComponentType.SHORT:return new Int16Array(s,r,o);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,r,o);default:return new Float32Array(s,r,o)}},n.GetBufferFromAccessor=function(e,t){var r=e.bufferViews[t.bufferView],o=t.count*n.GetByteStrideFromType(t);return n.GetBufferFromBufferView(e,r,t.byteOffset,o,t.componentType)},n.DecodeBufferToText=function(e){for(var t="",n=e.byteLength,r=0;ru.byteLength)return void s._onError("Buffer access is out of range");var l=u.buffer;n+=u.byteOffset;var c;switch(a){case t.EComponentType.BYTE:c=s._buildInt8ArrayBuffer(l,n,r,e.byteStride,o);break;case t.EComponentType.UNSIGNED_BYTE:c=s._buildUint8ArrayBuffer(l,n,r,e.byteStride,o);break;case t.EComponentType.SHORT:c=s._buildInt16ArrayBuffer(l,n,r,e.byteStride,o);break;case t.EComponentType.UNSIGNED_SHORT:c=s._buildUint16ArrayBuffer(l,n,r,e.byteStride,o);break;case t.EComponentType.UNSIGNED_INT:c=s._buildUint32ArrayBuffer(l,n,r,e.byteStride,o);break;case t.EComponentType.FLOAT:c=s._buildFloat32ArrayBuffer(l,n,r,e.byteStride,o);break;default:return void s._onError("Invalid component type ("+a+")")}i(c)}))},r.prototype._loadAccessorAsync=function(e,t){var n=this._getArrayItem(this._gltf.bufferViews,e.bufferView,"Buffer view");if(n){var r=e.byteOffset||0,o=this._getByteStrideFromType(e),a=e.count*o;this._loadBufferViewAsync(n,r,a,o,e.componentType,t)}},r.prototype._getByteStrideFromType=function(e){switch(e.type){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;default:return this._onError("Invalid accessor type ("+e.type+")"),0}},r.prototype._addPendingData=function(e){this._renderReady||this._renderPendingCount++,this._addLoaderPendingData(e)},r.prototype._removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._onRenderReady()),this._removeLoaderPendingData(e)},r.prototype._addLoaderPendingData=function(e){this._loaderPendingCount++,this._loaderTrackers.forEach((function(t){return t._addPendingData(e)}))},r.prototype._removeLoaderPendingData=function(e){this._loaderTrackers.forEach((function(t){return t._removePendingData(e)})),0==--this._loaderPendingCount&&this._onComplete()},r.prototype._whenAction=function(e,t){var r=this,o=new n(function(){r._loaderTrackers.splice(r._loaderTrackers.indexOf(o)),t()});this._loaderTrackers.push(o),this._addLoaderPendingData(o),e(),this._removeLoaderPendingData(o)},r.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",n=this._babylonScene.getMaterialByName(t);n||(n=new e.PBRMaterial(t,this._babylonScene),n.sideOrientation=e.Material.CounterClockWiseSideOrientation,n.metallic=1,n.roughness=1),this._defaultMaterial=n}return this._defaultMaterial},r.prototype._loadMaterialMetallicRoughnessProperties=function(t){var n=t.babylonMaterial;n.metallic=1,n.roughness=1;var r=t.pbrMetallicRoughness;r&&(n.albedoColor=r.baseColorFactor?e.Color3.FromArray(r.baseColorFactor):new e.Color3(1,1,1),n.metallic=null==r.metallicFactor?1:r.metallicFactor,n.roughness=null==r.roughnessFactor?1:r.roughnessFactor,r.baseColorTexture&&(n.albedoTexture=this._loadTexture(r.baseColorTexture)),r.metallicRoughnessTexture&&(n.metallicTexture=this._loadTexture(r.metallicRoughnessTexture),n.useMetallnessFromMetallicTextureBlue=!0,n.useRoughnessFromMetallicTextureGreen=!0,n.useRoughnessFromMetallicTextureAlpha=!1),this._loadMaterialAlphaProperties(t,r.baseColorFactor))},r.prototype._loadMaterial=function(e,n){if(e.babylonMaterial)return void n(e.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,n)||(this._createPbrMaterial(e),this._loadMaterialBaseProperties(e),this._loadMaterialMetallicRoughnessProperties(e),n(e.babylonMaterial,!0))},r.prototype._createPbrMaterial=function(t){var n=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);n.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=n},r.prototype._loadMaterialBaseProperties=function(t){var n=t.babylonMaterial;n.emissiveColor=t.emissiveFactor?e.Color3.FromArray(t.emissiveFactor):new e.Color3(0,0,0),t.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),t.normalTexture&&(n.bumpTexture=this._loadTexture(t.normalTexture),n.invertNormalMapX=!this._babylonScene.useRightHandedSystem,n.invertNormalMapY=this._babylonScene.useRightHandedSystem,void 0!==t.normalTexture.scale&&(n.bumpTexture.level=t.normalTexture.scale)),t.occlusionTexture&&(n.ambientTexture=this._loadTexture(t.occlusionTexture),n.useAmbientInGrayScale=!0,void 0!==t.occlusionTexture.strength&&(n.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&(n.emissiveTexture=this._loadTexture(t.emissiveTexture))},r.prototype._loadMaterialAlphaProperties=function(e,t){var n=e.babylonMaterial;switch(e.alphaMode||"OPAQUE"){case"OPAQUE":break;case"MASK":n.alphaCutOff=null==e.alphaCutoff?.5:e.alphaCutoff,t&&(0==t[3]?n.alphaCutOff=1:n.alphaCutOff/=t[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0);break;case"BLEND":t&&(n.alpha=t[3]),n.albedoTexture&&(n.albedoTexture.hasAlpha=!0,n.useAlphaFromAlbedoTexture=!0);break;default:return void this._onError("Invalid alpha mode '"+e.alphaMode+"'")}},r.prototype._loadTexture=function(n){var r=this,o=this._getArrayItem(this._gltf.textures,n.index,"Texture");if(!o)return null;var a=n.texCoord||0,i=this._getArrayItem(this._gltf.images,o.source,"Texture ("+n.index+") source");if(!i)return null;var s=null==o.sampler?{}:this._getArrayItem(this._gltf.samplers,o.sampler,"Texture ("+n.index+") sampler");if(s){var u=s.minFilter===t.ETextureMinFilter.NEAREST||s.minFilter===t.ETextureMinFilter.LINEAR,l=t.GLTFUtils.GetTextureSamplingMode(s.magFilter,s.minFilter);this._addPendingData(o);var c=new e.Texture(null,this._babylonScene,u,!1,l,function(){r._disposed||r._removePendingData(o)},function(){r._disposed||(r._onError("Failed to load texture '"+i.uri+"'"),r._removePendingData(o))});if(o.url)c.updateURL(o.url);else if(o.dataReadyObservable)o.dataReadyObservable.add((function(e){c.updateURL(e.url)}));else{o.dataReadyObservable=new e.Observable,o.dataReadyObservable.add((function(e){c.updateURL(e.url)}));var f=function(e){o.url=URL.createObjectURL(new Blob([e],{type:i.mimeType})),o.dataReadyObservable.notifyObservers(o)};if(i.uri)t.GLTFUtils.IsBase64(i.uri)?f(new Uint8Array(t.GLTFUtils.DecodeBase64(i.uri))):e.Tools.LoadFile(this._rootUrl+i.uri,f,(function(e){r._onProgress(e)}),this._babylonScene.database,!0,(function(e){r._onError("Failed to load file '"+i.uri+"': "+e.status+" "+e.statusText)}));else{var d=this._getArrayItem(this._gltf.bufferViews,i.bufferView,"Texture ("+n.index+") source ("+o.source+") buffer view");if(!d)return;this._loadBufferViewAsync(d,0,d.byteLength,1,t.EComponentType.UNSIGNED_BYTE,f)}}return c.coordinatesIndex=a,c.wrapU=t.GLTFUtils.GetTextureWrapMode(s.wrapS),c.wrapV=t.GLTFUtils.GetTextureWrapMode(s.wrapT),c.name=o.name||"texture"+n.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(c),c}},r.prototype._getArrayItem=function(e,t,n){return e&&e[t]?e[t]:(this._onError(n+" index ("+t+") was not found"),null)},r})();r.Extensions={},t.GLTFLoader=r,e.GLTFFileLoader.CreateGLTFLoaderV2=function(e){return new r(e)}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var n=(function(){function n(){}return n.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},n.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),n=t.length,r=new Uint8Array(new ArrayBuffer(n)),o=0;o=0;i--)e._traverseNode(o.ids[i],n,r);e._traverseNode(t,n,r),a()}))},n.prototype._loadNode=function(e,t){var n=this;return this._loadExtension(t,(function(r,o){var a=[t.index].concat(r.ids).map((function(t){return e._gltf.nodes[t]}));e._addLoaderPendingData(t),n._loadNodeLOD(e,a,a.length-1,(function(){e._removeLoaderPendingData(t),o()}))}))},n.prototype._loadNodeLOD=function(e,t,r,o){var a=this;e._whenAction((function(){e._loadNode(t[r])}),(function(){if(r!==t.length-1){t[r+1].babylonMesh.setEnabled(!1)}if(0===r)return void o();setTimeout((function(){a._loadNodeLOD(e,t,r-1,o)}),n.MinimalLODDelay)}))},n.prototype._loadMaterial=function(e,t,n){var r=this;return this._loadExtension(t,(function(o,a){var i=[t.index].concat(o.ids).map((function(t){return e._gltf.materials[t]}));e._addLoaderPendingData(t),r._loadMaterialLOD(e,i,i.length-1,n,(function(){t.extensions[r.name]=o,e._removeLoaderPendingData(t),a()}))}))},n.prototype._loadMaterialLOD=function(t,r,o,a,i){var s=this;t._loadMaterial(r[o],(function(u,l){if(a(u,l),0===o)return void i();t._executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(u.getActiveTextures(),(function(){setTimeout((function(){s._loadMaterialLOD(t,r,o-1,a,i)}),n.MinimalLODDelay)}))}))}))},n})(t.GLTFLoaderExtension);r.MinimalLODDelay=250,n.MSFTLOD=r,t.GLTFLoader.RegisterExtension(new r)})(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 n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}})(),BABYLON;!(function(e){!(function(t){!(function(n){var r=(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),Object.defineProperty(n.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),n.prototype._loadMaterial=function(e,t,n){var r=this;return this._loadExtension(t,(function(o,a){e._createPbrMaterial(t),e._loadMaterialBaseProperties(t),r._loadSpecularGlossinessProperties(e,t,o),n(t.babylonMaterial,!0)}))},n.prototype._loadSpecularGlossinessProperties=function(t,n,r){var o=n.babylonMaterial;o.albedoColor=r.diffuseFactor?e.Color3.FromArray(r.diffuseFactor):new e.Color3(1,1,1),o.reflectivityColor=r.specularFactor?e.Color3.FromArray(r.specularFactor):new e.Color3(1,1,1),o.microSurface=void 0===r.glossinessFactor?1:r.glossinessFactor,r.diffuseTexture&&(o.albedoTexture=t._loadTexture(r.diffuseTexture)),r.specularGlossinessTexture&&(o.reflectivityTexture=t._loadTexture(r.specularGlossinessTexture),o.reflectivityTexture.hasAlpha=!0,o.useMicroSurfaceFromReflectivityMapAlpha=!0),t._loadMaterialAlphaProperties(n,r.diffuseFactor)},n})(t.GLTFLoaderExtension);n.KHRMaterialsPbrSpecularGlossiness=r,t.GLTFLoader.RegisterExtension(new r)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));