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){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){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){if(t instanceof ArrayBuffer)return e._parseBinary(t,n);try{return{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=p(u,i))&&-1===l.indexOf(y)&&l.push(y);new e.Bone(d.jointName,a,y,M).id=i}}else e.Tools.Warn("Joint named "+r.jointNames[c]+" does not exist")}var b=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 T=d[d.type],E=new e.HemisphericLight(n.light,e.Vector3.Zero(),t.scene);E.name=n.name,T.color&&(E.diffuse=e.Color3.FromArray(T.color)),a=E}else if("directional"===d.type){var h=d[d.type],p=new e.DirectionalLight(n.light,e.Vector3.Zero(),t.scene);p.name=n.name,h.color&&(p.diffuse=e.Color3.FromArray(h.color)),a=p}else if("point"===d.type){var A=d[d.type],m=new e.PointLight(n.light,e.Vector3.Zero(),t.scene);m.name=n.name,A.color&&(m.diffuse=e.Color3.FromArray(A.color)),a=m}else if("spot"===d.type){var _=d[d.type],N=new e.SpotLight(n.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);N.name=n.name,_.color&&(N.diffuse=e.Color3.FromArray(_.color)),_.fallOfAngle&&(N.angle=_.fallOfAngle),_.fallOffExponent&&(N.exponent=_.fallOffExponent),a=N}}if(!n.jointName){if(n.babylonNode)return n.babylonNode;if(null===a){var M=new e.Mesh(n.name,t.scene);n.babylonNode=M,a=M}}if(null!==a){if(n.matrix&&a instanceof e.Mesh)v(a,n);else{var b=n.translation||[0,0,0],O=n.rotation||[0,0,0,1],x=n.scale||[1,1,1];L(a,e.Vector3.FromArray(b),e.Quaternion.FromArray(O),e.Vector3.FromArray(x))}a.updateCache(!0),n.babylonNode=a}return a},M=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;r0&&void 0===r[0].uri&&(n=r[0]),t.bin&&(n?n.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"):e.Tools.Warn("Unexpected BIN chunk"),n.loadedData=t.bin)},n.prototype._addRightHandToLeftHandRootTransform=function(){var t=new e.Mesh("root",this._babylonScene);t.scaling=new e.Vector3(1,1,-1),t.rotation.y=Math.PI;for(var n=this._gltf.nodes,r=0;re.byteLength)return void i._onError("Buffer access is out of range");var s=e.buffer;n+=e.byteOffset;var u;switch(o){case t.EComponentType.BYTE:u=new Int8Array(s,n,r);break;case t.EComponentType.UNSIGNED_BYTE:u=new Uint8Array(s,n,r);break;case t.EComponentType.SHORT:u=new Int16Array(s,n,r);break;case t.EComponentType.UNSIGNED_SHORT:u=new Uint16Array(s,n,r);break;case t.EComponentType.UNSIGNED_INT:u=new Uint32Array(s,n,r);break;case t.EComponentType.FLOAT:u=new Float32Array(s,n,r);break;default:return void i._onError("Invalid component type ("+o+")")}a(u)}))},n.prototype._loadAccessorAsync=function(e,t){var n=this._gltf.bufferViews[e.bufferView],r=e.byteOffset||0,o=e.count*this._getByteStrideFromType(e);this._loadBufferViewAsync(n,r,o,e.componentType,t)},n.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}},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++},n.prototype.removeLoaderPendingData=function(e){0==--this._loaderPendingCount&&this._onLoaderComplete()},n.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},n.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=void 0===r.metallicFactor?1:r.metallicFactor,n.roughness=void 0===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))},n.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))},n.prototype.createPbrMaterial=function(t){var n=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);n.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=n},n.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=!0,n.invertNormalMapY=!0,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))},n.prototype.loadMaterialAlphaProperties=function(t,n){var r=t.babylonMaterial,o=t.alphaMode||"OPAQUE";switch(o){case"OPAQUE":break;case"MASK":case"BLEND":n&&(r.alpha=n[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture="BLEND"===o);break;default:e.Tools.Warn("Invalid alpha mode '"+t.alphaMode+"'")}},n.prototype.loadTexture=function(n){var r=this,o=this._gltf.textures[n.index],a=n.texCoord||0;if(!o||void 0===o.source)return null;var i;if(o.babylonTextures){if(!(i=o.babylonTextures[a]))for(var s=0;s