@mapvx/web-kit 1.2.0-develop.8 → 1.2.0-develop.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +8 -0
  2. package/dist/cjs/chunks/{DRACOLoader-2PTxnG0B.cjs → DRACOLoader-BXWDwLus.cjs} +2 -2
  3. package/dist/cjs/chunks/{GLTFLoader-Duo42nvB.cjs → GLTFLoader-Ie8s8u8H.cjs} +2 -2
  4. package/dist/cjs/chunks/{KTX2Loader-BFPRanfV.cjs → KTX2Loader-qXr_kxSW.cjs} +2 -2
  5. package/dist/cjs/chunks/{accessibility-B8B49hfP.cjs → accessibility--hZFITPu.cjs} +2 -2
  6. package/dist/cjs/chunks/{back_arrow-xE8LI3kf.cjs → back_arrow-D7QonpvS.cjs} +2 -2
  7. package/dist/cjs/chunks/{debug-hooks-Dy3VCEnb.cjs → debug-hooks-CUiqwo8b.cjs} +2 -2
  8. package/dist/cjs/chunks/{dist-CVKbkSUX.cjs → dist-CiVAEX5i.cjs} +2 -2
  9. package/dist/cjs/chunks/{dist-Dar77TD5.cjs → dist-DDS4P2yt.cjs} +2 -2
  10. package/dist/cjs/chunks/{dist-B_S2qDE8.cjs → dist-Dh7LsBxq.cjs} +2 -2
  11. package/dist/cjs/chunks/{expression-CqVJF7Up.cjs → expression-CO3CSbYd.cjs} +2 -2
  12. package/dist/cjs/chunks/{globe-viewport-Cy7fXEJR.cjs → globe-viewport-D1yIuqYX.cjs} +2 -2
  13. package/dist/cjs/chunks/{icon-origin-point-Bj3Liz0V.cjs → icon-origin-point-Bt8oX8FA.cjs} +2 -2
  14. package/dist/cjs/chunks/{meshopt_decoder.module-AyBTxqo4.cjs → meshopt_decoder.module-Bk6j-o8V.cjs} +2 -2
  15. package/dist/cjs/chunks/{repeat_icon-DzHJ0GL_.cjs → repeat_icon-BEd6gL1X.cjs} +2 -2
  16. package/dist/cjs/chunks/{rolldown-runtime-q6IekecT.cjs → rolldown-runtime-DJKPJnot.cjs} +2 -2
  17. package/dist/cjs/chunks/{shader-type-decoder-axsbbPco.cjs → shader-type-decoder-D5AGkPPj.cjs} +2 -2
  18. package/dist/cjs/chunks/{styles-Di9G-XQi.cjs → styles-DrSaht0q.cjs} +2 -2
  19. package/dist/cjs/chunks/{three.module-C0_ADYQD.cjs → three.module-Cb7BgQfP.cjs} +2 -2
  20. package/dist/cjs/chunks/{walking-D-LNDhrw.cjs → walking-ChGLFmdv.cjs} +2 -2
  21. package/dist/cjs/chunks/{webgl-544JMAWZ.cjs → webgl-C2jh1WTK.cjs} +2 -2
  22. package/dist/cjs/chunks/{webgl-device-CDnp7hBC.cjs → webgl-device-Dy1ruGCX.cjs} +2 -2
  23. package/dist/cjs/web-kit.cjs +5 -5
  24. package/dist/es/chunks/{DRACOLoader-DhHvfwrR.js → DRACOLoader-883EjV8X.js} +2 -2
  25. package/dist/es/chunks/{GLTFLoader-BXqFbldq.js → GLTFLoader-HXSQaGKT.js} +2 -2
  26. package/dist/es/chunks/{KTX2Loader-89MZe3TT.js → KTX2Loader-DVOYJ-4Y.js} +2 -2
  27. package/dist/es/chunks/{accessibility-C3tJdK9R.js → accessibility-D-deEbwV.js} +2 -2
  28. package/dist/es/chunks/{back_arrow-KlmFvv0H.js → back_arrow-DjhoWjXs.js} +2 -2
  29. package/dist/es/chunks/{debug-hooks-EAre0eyT.js → debug-hooks-DWy-ovrh.js} +2 -2
  30. package/dist/es/chunks/{dist-DfkvAQXI.js → dist-47_p4Yxg.js} +2 -2
  31. package/dist/es/chunks/{dist-CUomzeVc.js → dist-DOZVk2yA.js} +2 -2
  32. package/dist/es/chunks/{dist-B52Hz0u5.js → dist-DggqP-gQ.js} +2 -2
  33. package/dist/es/chunks/{expression-BArVovP1.js → expression-XgnkW6Sk.js} +2 -2
  34. package/dist/es/chunks/{globe-viewport-DSFQ1IgJ.js → globe-viewport-CwpYcu3c.js} +2 -2
  35. package/dist/es/chunks/{icon-origin-point-9EjzWJfO.js → icon-origin-point-JEEMojyJ.js} +2 -2
  36. package/dist/es/chunks/{meshopt_decoder.module-DGlvLcRK.js → meshopt_decoder.module-CVnL-WFq.js} +2 -2
  37. package/dist/es/chunks/{repeat_icon-zufPHs-C.js → repeat_icon-O8PH3s5h.js} +2 -2
  38. package/dist/es/chunks/{rolldown-runtime-BmU5BQeP.js → rolldown-runtime-Lq6Z3lw4.js} +2 -2
  39. package/dist/es/chunks/{shader-type-decoder-BgpYT6UO.js → shader-type-decoder-CpvFwfxh.js} +2 -2
  40. package/dist/es/chunks/{styles-DKa4saDJ.js → styles-CSDlMZd2.js} +2 -2
  41. package/dist/es/chunks/{three.module-y4zBSx1c.js → three.module-jU3YiRA7.js} +2 -2
  42. package/dist/es/chunks/{walking-7Vq5kU_k.js → walking-CeG7IOqk.js} +2 -2
  43. package/dist/es/chunks/{webgl-Cl-M1sFB.js → webgl-CW6td6sd.js} +2 -2
  44. package/dist/es/chunks/{webgl-device-DF-CxjIt.js → webgl-device-ChYrAvsE.js} +2 -2
  45. package/dist/es/web-kit.mjs +5 -5
  46. package/dist/iife/web-kit.iife.js +3 -3
  47. package/dist/sw/mvx-tiles-sw.js +582 -0
  48. package/dist/types/index.d.ts +2 -8
  49. package/package.json +2 -1
@@ -1,4 +1,4 @@
1
- /*! Web-kit v1.2.0-develop.8 | (c) 2026 MapVX */
2
- !function(){try{var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="3c39970b-aad7-472c-83a9-dfb8f93ed0a4",e._sentryDebugIdIdentifier="sentry-dbid-3c39970b-aad7-472c-83a9-dfb8f93ed0a4")}catch(e){}}();import{i as e,n as t,r as n,t as r}from"./rolldown-runtime-BmU5BQeP.js";import{C as i,E as a,S as s,T as o,_ as A,a as l,b as c,c as u,d as f,f as d,g as h,h as p,i as m,l as g,n as b,o as v,p as y,r as x,s as _,u as w,v as T,w as S,x as M,y as E}from"./dist-DfkvAQXI.js";import{A as C,At as I,D as R,Dt as P,Et as N,Ft as k,I as L,It as B,Lt as O,Mt as F,Nt as D,Ot as U,Pt as V,St as j,Tt as z,Ut as G,W as H,Wt as q,Xt as Q,Yt as K,Zt as W,_ as J,_n as $,at as X,bn as Y,bt as Z,cn as ee,ct as te,dn as ne,et as re,fn as ie,gn as ae,gt as se,hn as oe,in as Ae,jt as le,l as ce,ln as ue,mn as fe,nt as de,on as he,pn as pe,pt as me,rn as ge,s as be,sn as ve,tt as ye,un as xe,vn as _e,vt as we,xt as Te,yn as Se,yt as Me}from"./debug-hooks-EAre0eyT.js";import{a as Ee,c as Ce,d as Ie,f as Re,i as Pe,l as Ne,m as ke,o as Le,p as Be,r as Oe,s as Fe,t as De,u as Ue}from"./globe-viewport-DSFQ1IgJ.js";import{_ as Ve,b as je,c as ze,d as Ge,g as He,l as qe,s as Qe,u as Ke}from"./expression-BArVovP1.js";import{h as We,m as Je,p as $e,u as Xe}from"./shader-type-decoder-BgpYT6UO.js";import{h as Ye}from"./webgl-device-DF-CxjIt.js";async function Ze(e,t,n,r){return r._parse(e,t,n,r)}globalThis.probe||(globalThis.probe=We);var et=new Je({id:"@probe.gl/log"});var tt={};function nt(e={}){const t=e.useLocalLibraries??e.core?.useLocalLibraries,n=e.CDN??e.core?.CDN,r=e.modules;return{...void 0!==t?{useLocalLibraries:t}:{},...void 0!==n?{CDN:n}:{},...void 0!==r?{modules:r}:{}}}async function rt(e,t=null,n={},r=null){if(t){const i=n.modules?.[r||e];if(void 0!==i&&"string"!=typeof i)return i;e=function(e,t,n={},r=null){if(n?.core)throw new Error("loadLibrary: options.core must be pre-normalized");r=r||e;const i=n.modules||{};if("string"==typeof i[r])return i[r];if(!n.useLocalLibraries&&e.startsWith("http"))return e;if(!pe)return`modules/${t}/dist/libs/${r}`;if(n.CDN)return oe(n.CDN.startsWith("http")),`${n.CDN}/${t}@${ae}/dist/libs/${r}`;return fe?`../src/libs/${r}`:`modules/${t}/src/libs/${r}`}(e,t,n,r)}return tt[e]=tt[e]||async function(e){if(e.endsWith("wasm"))return await async function(e){const{readFileAsArrayBuffer:t}=globalThis.loaders||{};if(pe||!t||e.startsWith("http"))return await(await fetch(e)).arrayBuffer();try{return await t(e)}catch{if(e.includes("/dist/libs/"))return await t(e.replace("/dist/libs/","/src/libs/"));throw new Error(`Failed to load ArrayBuffer from ${e}`)}}(e);if(!pe){const{requireFromFile:n}=globalThis.loaders||{};try{const t=await(n?.(e));return t||!e.includes("/dist/libs/")?t:await(n?.(e.replace("/dist/libs/","/src/libs/")))}catch(t){if(e.includes("/dist/libs/"))try{return await(n?.(e.replace("/dist/libs/","/src/libs/")))}catch{}return console.error(t),null}}return fe?importScripts(e):function(e,t){if(!pe){const{requireFromString:n}=globalThis.loaders||{};return n?.(e,t)}if(fe)return eval.call(globalThis,e),null;const n=document.createElement("script");n.id=t;try{n.appendChild(document.createTextNode(e))}catch(Lr){n.text=e}return document.body.appendChild(n),null}(await async function(e){const{readFileAsText:t}=globalThis.loaders||{};if(pe||!t||e.startsWith("http"))return await(await fetch(e)).text();try{return await t(e)}catch{if(e.includes("/dist/libs/"))return await t(e.replace("/dist/libs/","/src/libs/"));throw new Error(`Failed to load text from ${e}`)}}(e),e)}(e),await tt[e]}function it(e,t,n){if(e.byteLength<=t+n)return"";const r=new DataView(e);let i="";for(let a=0;a<n;a++)i+=String.fromCharCode(r.getUint8(t+a));return i}function at(e){try{return JSON.parse(e)}catch(t){throw new Error(`Failed to parse JSON from data starting with "${function(e,t=5){return"string"==typeof e?e.slice(0,t):ArrayBuffer.isView(e)?it(e.buffer,e.byteOffset,t):e instanceof ArrayBuffer?it(e,0,t):""}(e)}"`)}}function st(e,t){return Y(e>=0),Y(t>0),e+(t-1)&~(t-1)}function ot(e,t,n){let r;if(e instanceof ArrayBuffer)r=new Uint8Array(e);else{const t=e.byteOffset,n=e.byteLength;r=new Uint8Array(e.buffer||e.arrayBuffer,t,n)}return t.set(r,n),n+st(r.byteLength,4)}var At={id:"request-scheduler",throttleRequests:!0,maxRequests:6,debounceTime:0},lt=class{props;stats;activeRequestCount=0;requestQueue=[];requestMap=/* @__PURE__ */new Map;updateTimer=null;constructor(e={}){this.props={...At,...e},this.stats=new ne({id:this.props.id}),this.stats.get("Queued Requests"),this.stats.get("Active Requests"),this.stats.get("Cancelled Requests"),this.stats.get("Queued Requests Ever"),this.stats.get("Active Requests Ever")}setProps(e){void 0!==e.throttleRequests&&(this.props.throttleRequests=e.throttleRequests),void 0!==e.maxRequests&&(this.props.maxRequests=e.maxRequests),void 0!==e.debounceTime&&(this.props.debounceTime=e.debounceTime)}scheduleRequest(e,t=()=>0){if(!this.props.throttleRequests)return Promise.resolve({done:()=>{}});if(this.requestMap.has(e))return this.requestMap.get(e);const n={handle:e,priority:0,getPriority:t},r=new Promise(e=>(n.resolve=e,n));return this.requestQueue.push(n),this.requestMap.set(e,r),this._issueNewRequests(),r}_issueRequest(e){const{handle:t,resolve:n}=e;let r=!1;const i=()=>{r||(r=!0,this.requestMap.delete(t),this.activeRequestCount--,null===this.updateTimer&&(this.updateTimer=setTimeout(()=>this._issueNewRequestsAsync(),0)))};return this.activeRequestCount++,n?n({done:i}):Promise.resolve({done:i})}_issueNewRequests(){null!==this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>this._issueNewRequestsAsync(),this.props.debounceTime)}_issueNewRequestsAsync(){null!==this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=null;const e=Math.max(this.props.maxRequests-this.activeRequestCount,0);if(0!==e){this._updateAllRequests();for(let t=0;t<e;++t){const e=this.requestQueue.shift();e&&this._issueRequest(e)}}}_updateAllRequests(){const e=this.requestQueue;for(let t=0;t<e.length;++t){const n=e[t];this._updateRequest(n)||(e.splice(t,1),this.requestMap.delete(n.handle),t--)}e.sort((e,t)=>e.priority-t.priority)}_updateRequest(e){return e.priority=e.getPriority(e.handle),!(e.priority<0)||(e.resolve(null),!1)}},ct=class e{static defaultOptions={core:{type:"auto",attributions:[],loadOptions:{},loaders:[]}};optionsType;options;data;url;loadOptions;fetch;_needsRefresh=!0;constructor(t,n,r){this.options=r?$({...r,core:e.defaultOptions},n):{...n},this.data=t,this.url="string"==typeof t?xe(t):"",this.loadOptions=function(e){const t={...e};e?.core&&(t.core={...e.core});const n="string"==typeof t.baseUri?t.baseUri:void 0,r="string"==typeof t.baseUrl?t.baseUrl:void 0;void 0===n&&void 0===r||(t.core||={},void 0===t.core.baseUrl&&(t.core.baseUrl=r??n),delete t.baseUri,delete t.baseUrl);return t}(this.options.core?.loadOptions),this.fetch=function(e){const t=e?.core?.fetch;if(t&&"function"==typeof t)return(e,n)=>t(e,n);const n=e?.fetch;return n&&"function"!=typeof n?e=>fetch(e,n):e=>fetch(e)}(this.loadOptions)}setProps(e){this.options=Object.assign(this.options,e),this.setNeedsRefresh()}setNeedsRefresh(){this._needsRefresh=!0}getNeedsRefresh(e=!0){const t=this._needsRefresh;return e&&(this._needsRefresh=!1),t}};var ut=class{static type="template";static testURL=e=>!1};function ft(e,t){return new Promise((n,r)=>{let i=!1;function a(e){i||(i=!0,r(e))}function s(e){if(!i){i=!0;try{n(t(e))}catch(a){r(a)}}}try{e(s,a)?.then(s,a)}catch(o){a(o)}})}function dt(e,t,n){const r=function(e){switch(e.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}(t.value),i=n||function(e){const t={};"byteOffset"in e&&(t.byteOffset=e.byteOffset.toString(10));"byteStride"in e&&(t.byteStride=e.byteStride.toString(10));"normalized"in e&&(t.normalized=e.normalized.toString());return t}(t);return{name:e,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:r}]},nullable:!1,metadata:i}}var ht=["image/png","image/jpeg","image/gif","image/webp","image/avif","image/tiff","image/svg","image/svg+xml","image/bmp","image/vnd.microsoft.icon"],pt=null;async function mt(){return pt||(pt=async function(){const e=/* @__PURE__ */new Set;for(const t of ht)(Se?await xt(t):vt(t))&&e.add(t);return e}()),await pt}var gt={};function bt(e){if(void 0===gt[e]){const t=Se?function(e){switch(e){case"image/avif":case"image/webp":return function(e){try{return 0===document.createElement("canvas").toDataURL(e).indexOf(`data:${e}`)}catch{return!1}}(e);default:return!0}}(e):vt(e);gt[e]=t}return gt[e]}function vt(e){const t=globalThis.loaders?.imageFormatsNode||["image/png","image/jpeg","image/gif"],n=globalThis.loaders?.parseImageNode;return Boolean(n)&&t.includes(e)}var yt={"image/avif":"data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=","image/webp":"data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA"};async function xt(e){const t=yt[e];return!t||await async function(e){return new Promise(t=>{const n=new Image;n.src=e,n.onload=()=>t(n.height>0),n.onerror=()=>t(!1)})}(t)}var _t,wt=class extends z{constructor(e=0,t=0){super(2),V(e)&&1===arguments.length?this.copy(e):(le.debug&&(P(e),P(t)),this[0]=e,this[1]=t)}set(e,t){return this[0]=e,this[1]=t,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this.check()}fromObject(e){return le.debug&&(P(e.x),P(e.y)),this[0]=e.x,this[1]=e.y,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e}get ELEMENTS(){return 2}horizontalAngle(){return Math.atan2(this.y,this.x)}verticalAngle(){return Math.atan2(this.x,this.y)}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return j(this,this,e),this.check()}transformAsVector(e){return se(this,this,e),this.check()}transformByMatrix3(e){return Te(this,this,e),this.check()}transformByMatrix2x3(e){return Z(this,this,e),this.check()}transformByMatrix2(e){return Me(this,this,e),this.check()}};!function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL1ROW0=3]="COL1ROW0",e[e.COL1ROW1=4]="COL1ROW1",e[e.COL1ROW2=5]="COL1ROW2",e[e.COL2ROW0=6]="COL2ROW0",e[e.COL2ROW1=7]="COL2ROW1",e[e.COL2ROW2=8]="COL2ROW2"}(_t||(_t={}));var Tt,St=Object.freeze([1,0,0,0,1,0,0,0,1]),Mt=class extends ye{static get IDENTITY(){return function(){Et||(Et=new Mt,Object.freeze(Et));return Et}()}static get ZERO(){return function(){Tt||(Tt=new Mt([0,0,0,0,0,0,0,0,0]),Object.freeze(Tt));return Tt}()}get ELEMENTS(){return 9}get RANK(){return 3}get INDICES(){return _t}constructor(e,...t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0),1===arguments.length&&Array.isArray(e)?this.copy(e):t.length>0?this.copy([e,...t]):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this.check()}identity(){return this.copy(St)}fromObject(e){return this.check()}fromQuaternion(e){return Ee(this,e),this.check()}set(e,t,n,r,i,a,s,o,A){return this[0]=e,this[1]=t,this[2]=n,this[3]=r,this[4]=i,this[5]=a,this[6]=s,this[7]=o,this[8]=A,this.check()}setRowMajor(e,t,n,r,i,a,s,o,A){return this[0]=e,this[1]=r,this[2]=s,this[3]=t,this[4]=i,this[5]=o,this[6]=n,this[7]=a,this[8]=A,this.check()}determinant(){return Pe(this)}transpose(){return Ie(this,this),this.check()}invert(){return Le(this,this),this.check()}multiplyLeft(e){return Fe(this,e,this),this.check()}multiplyRight(e){return Fe(this,this,e),this.check()}rotate(e){return Ce(this,this,e),this.check()}scale(e){return Array.isArray(e)?Ne(this,this,e):Ne(this,this,[e,e]),this.check()}translate(e){return Ue(this,this,e),this.check()}transform(e,t){let n;switch(e.length){case 2:n=Te(t||[-0,-0],e,this);break;case 3:n=me(t||[-0,-0,-0],e,this);break;case 4:n=we(t||[-0,-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return U(n,e.length),n}transformVector(e,t){return this.transform(e,t)}transformVector2(e,t){return this.transform(e,t)}transformVector3(e,t){return this.transform(e,t)}},Et=null;var Ct={props:{},uniforms:{},bindings:{},name:"skin",bindingLayout:[{name:"skin",group:0},{name:"skinJointMatrices",group:0,visibility:1}],dependencies:[],source:"\nstruct skinUniforms {\n jointMatrix: array<mat4x4<f32>, 64>,\n};\n\n@group(0) @binding(auto) var<uniform> skin: skinUniforms;\n\n#ifdef HAS_INSTANCED_SKIN\n@group(0) @binding(auto) var<storage, read> skinJointMatrices: array<mat4x4<f32>>;\n\nfn getInstancedSkinMatrix(\n weights: vec4f,\n joints: vec4u,\n instanceIndex: u32,\n jointsPerInstance: u32\n) -> mat4x4<f32> {\n let firstJoint = instanceIndex * jointsPerInstance;\n return (weights.x * skinJointMatrices[firstJoint + joints.x])\n + (weights.y * skinJointMatrices[firstJoint + joints.y])\n + (weights.z * skinJointMatrices[firstJoint + joints.z])\n + (weights.w * skinJointMatrices[firstJoint + joints.w]);\n}\n#endif\n\nfn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {\n return (weights.x * skin.jointMatrix[joints.x])\n + (weights.y * skin.jointMatrix[joints.y])\n + (weights.z * skin.jointMatrix[joints.z])\n + (weights.w * skin.jointMatrix[joints.w]);\n}\n",vs:"\nlayout(std140) uniform skinUniforms {\n mat4 jointMatrix[SKIN_MAX_JOINTS];\n} skin;\n\n#ifdef HAS_INSTANCED_SKIN\nuniform highp sampler2D skinJointMatrices;\n\nmat4 getInstancedJointMatrix(uint jointIndex, uint instanceIndex) {\n int firstColumn = int(jointIndex * 4u);\n int row = int(instanceIndex);\n return mat4(\n texelFetch(skinJointMatrices, ivec2(firstColumn, row), 0),\n texelFetch(skinJointMatrices, ivec2(firstColumn + 1, row), 0),\n texelFetch(skinJointMatrices, ivec2(firstColumn + 2, row), 0),\n texelFetch(skinJointMatrices, ivec2(firstColumn + 3, row), 0)\n );\n}\n\nmat4 getInstancedSkinMatrix(\n vec4 weights,\n uvec4 joints,\n uint instanceIndex,\n uint jointsPerInstance\n) {\n return (weights.x * getInstancedJointMatrix(joints.x, instanceIndex))\n + (weights.y * getInstancedJointMatrix(joints.y, instanceIndex))\n + (weights.z * getInstancedJointMatrix(joints.z, instanceIndex))\n + (weights.w * getInstancedJointMatrix(joints.w, instanceIndex));\n}\n#endif\n\nmat4 getSkinMatrix(vec4 weights, uvec4 joints) {\n return (weights.x * skin.jointMatrix[joints.x])\n + (weights.y * skin.jointMatrix[joints.y])\n + (weights.z * skin.jointMatrix[joints.z])\n + (weights.w * skin.jointMatrix[joints.w]);\n}\n\n",fs:"",defines:{SKIN_MAX_JOINTS:64},getUniforms:(e={},t)=>{const{jointMatrices:n,skinJointMatrices:r,scenegraphsFromGLTF:i,skinIndex:a=0,meshWorldMatrix:s}=e,o=r?{skinJointMatrices:r}:{};if(n)return{jointMatrix:It(n),...o};const A=i?.gltf?.skins?.[a];if(!A)return{jointMatrix:[],...o};const{inverseBindMatrices:l,joints:c,skeleton:u}=A,f=i.gltfNodeIndexToNodeMap,d=/* @__PURE__ */new Map,h=void 0===u?void 0:f?.get(u),p=h?[h]:i.scenes||[];for(const v of p)v.preorderTraversal((e,{worldMatrix:t})=>{d.set(e.id,t)});const m=s?new H(s).invert():null,g=/* @__PURE__ */new Float32Array(1024),b=l?.value;for(let v=0;v<Math.min(c.length,64);v++){const e=f?.get(c[v]);if(!e)continue;const t=d.get(e.id)||e.matrix,n=m?new H(m).multiplyRight(t):new H(t);b&&b.length>=16*(v+1)&&n.multiplyRight(new H(Array.from(b.slice(16*v,16*(v+1))))),g.set(n,16*v)}return{jointMatrix:g,...o}},uniformTypes:{jointMatrix:["mat4x4<f32>",64]}};function It(e){const t=/* @__PURE__ */new Float32Array(1024);return t.set(e instanceof Float32Array?e.subarray(0,t.length):e.slice(0,t.length)),t}var Rt={name:"gpuAnimation",props:{},uniforms:{},bindings:{},source:"\n#ifdef HAS_GPU_CROWD_ANIMATION\n@group(0) @binding(auto) var<storage, read> gpuAnimationFrames: array<vec4f>;\n\nfn readGPUAnimationFrame(frame: u32, offset: u32, frameStride: u32) -> vec4f {\n return gpuAnimationFrames[frame * frameStride + offset];\n}\n\nfn sampleGPUAnimationFrame(\n frames: vec4f,\n blend: vec4f,\n offset: u32,\n frameStride: u32\n) -> vec4f {\n let first = mix(\n readGPUAnimationFrame(u32(frames.x), offset, frameStride),\n readGPUAnimationFrame(u32(frames.y), offset, frameStride),\n frames.z\n );\n if (blend.w <= 0.0) {\n return first;\n }\n let second = mix(\n readGPUAnimationFrame(u32(blend.x), offset, frameStride),\n readGPUAnimationFrame(u32(blend.y), offset, frameStride),\n blend.z\n );\n return mix(first, second, blend.w);\n}\n\nfn sampleGPUAnimationMatrix(\n frames: vec4f,\n blend: vec4f,\n firstColumn: u32,\n frameStride: u32\n) -> mat4x4f {\n return mat4x4f(\n sampleGPUAnimationFrame(frames, blend, firstColumn, frameStride),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 1u, frameStride),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 2u, frameStride),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 3u, frameStride)\n );\n}\n\nfn getGPUAnimatedSkinMatrix(\n weights: vec4f,\n joints: vec4u,\n frames: vec4f,\n blend: vec4f,\n frameStride: u32\n) -> mat4x4f {\n return weights.x * sampleGPUAnimationMatrix(frames, blend, 4u + joints.x * 4u, frameStride)\n + weights.y * sampleGPUAnimationMatrix(frames, blend, 4u + joints.y * 4u, frameStride)\n + weights.z * sampleGPUAnimationMatrix(frames, blend, 4u + joints.z * 4u, frameStride)\n + weights.w * sampleGPUAnimationMatrix(frames, blend, 4u + joints.w * 4u, frameStride);\n}\n#endif\n\n#ifdef HAS_INSTANCED_MORPH\n@group(0) @binding(auto) var<storage, read> gpuMorphTargets: array<vec4f>;\n\n#ifndef HAS_GPU_CROWD_ANIMATION\n@group(0) @binding(auto) var<storage, read> gpuMorphWeights: array<vec4f>;\n#endif\n\nfn getGPUCrowdMorphWeight(\n instanceIndex: u32,\n targetIndex: u32,\n targetCount: u32,\n jointsPerInstance: u32,\n frames: vec4f,\n blend: vec4f,\n frameStride: u32\n) -> f32 {\n#ifdef HAS_GPU_CROWD_ANIMATION\n let offset = 4u + jointsPerInstance * 4u + targetIndex;\n return sampleGPUAnimationFrame(frames, blend, offset, frameStride).x;\n#else\n let packedCount = (targetCount + 3u) / 4u;\n let packedWeights = gpuMorphWeights[instanceIndex * packedCount + targetIndex / 4u];\n return packedWeights[targetIndex % 4u];\n#endif\n}\n\nfn getGPUCrowdMorphDelta(\n instanceIndex: u32,\n vertexIndex: u32,\n attributeIndex: u32,\n vertexCount: u32,\n targetCount: u32,\n jointsPerInstance: u32,\n frames: vec4f,\n blend: vec4f,\n frameStride: u32\n) -> vec3f {\n var result = vec3f(0.0);\n for (var targetIndex = 0u; targetIndex < targetCount; targetIndex++) {\n let weight = getGPUCrowdMorphWeight(\n instanceIndex,\n targetIndex,\n targetCount,\n jointsPerInstance,\n frames,\n blend,\n frameStride\n );\n let offset = (targetIndex * 3u + attributeIndex) * vertexCount + vertexIndex;\n result += gpuMorphTargets[offset].xyz * weight;\n }\n return result;\n}\n#endif\n",vs:"\n#ifdef HAS_GPU_CROWD_ANIMATION\nuniform highp sampler2D gpuAnimationFrames;\n\nvec4 sampleGPUAnimationFrame(vec4 frames, vec4 blend, int offset) {\n vec4 first = mix(\n texelFetch(gpuAnimationFrames, ivec2(offset, int(frames.x)), 0),\n texelFetch(gpuAnimationFrames, ivec2(offset, int(frames.y)), 0),\n frames.z\n );\n if (blend.w <= 0.0) {\n return first;\n }\n vec4 second = mix(\n texelFetch(gpuAnimationFrames, ivec2(offset, int(blend.x)), 0),\n texelFetch(gpuAnimationFrames, ivec2(offset, int(blend.y)), 0),\n blend.z\n );\n return mix(first, second, blend.w);\n}\n\nmat4 sampleGPUAnimationMatrix(vec4 frames, vec4 blend, int firstColumn) {\n return mat4(\n sampleGPUAnimationFrame(frames, blend, firstColumn),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 1),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 2),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 3)\n );\n}\n\nmat4 getGPUAnimatedSkinMatrix(vec4 weights, uvec4 joints, vec4 frames, vec4 blend) {\n return weights.x * sampleGPUAnimationMatrix(frames, blend, 4 + int(joints.x) * 4)\n + weights.y * sampleGPUAnimationMatrix(frames, blend, 4 + int(joints.y) * 4)\n + weights.z * sampleGPUAnimationMatrix(frames, blend, 4 + int(joints.z) * 4)\n + weights.w * sampleGPUAnimationMatrix(frames, blend, 4 + int(joints.w) * 4);\n}\n#endif\n\n#ifdef HAS_INSTANCED_MORPH\nuniform highp sampler2D gpuMorphTargets;\n\n#ifndef HAS_GPU_CROWD_ANIMATION\nuniform highp sampler2D gpuMorphWeights;\n#endif\n\nfloat getGPUCrowdMorphWeight(\n uint instanceIndex,\n uint targetIndex,\n uint jointsPerInstance,\n vec4 frames,\n vec4 blend\n) {\n#ifdef HAS_GPU_CROWD_ANIMATION\n int offset = 4 + int(jointsPerInstance) * 4 + int(targetIndex);\n return sampleGPUAnimationFrame(frames, blend, offset).x;\n#else\n vec4 packedWeights = texelFetch(\n gpuMorphWeights,\n ivec2(int(targetIndex / 4u), int(instanceIndex)),\n 0\n );\n return packedWeights[int(targetIndex % 4u)];\n#endif\n}\n\nvec3 getGPUCrowdMorphDelta(\n uint instanceIndex,\n uint vertexIndex,\n uint attributeIndex,\n uint targetCount,\n uint jointsPerInstance,\n vec4 frames,\n vec4 blend\n) {\n vec3 result = vec3(0.0);\n for (uint targetIndex = 0u; targetIndex < targetCount; targetIndex++) {\n float weight = getGPUCrowdMorphWeight(\n instanceIndex,\n targetIndex,\n jointsPerInstance,\n frames,\n blend\n );\n result += texelFetch(\n gpuMorphTargets,\n ivec2(int(vertexIndex), int(targetIndex * 3u + attributeIndex)),\n 0\n ).xyz * weight;\n }\n return result;\n}\n#endif\n",fs:"",bindingLayout:[{name:"gpuAnimationFrames",group:0,visibility:1},{name:"gpuMorphTargets",group:0,visibility:1},{name:"gpuMorphWeights",group:0,visibility:1}],getUniforms:(e={})=>e},Pt="#ifdef USE_IBL\nuniform samplerCube pbr_diffuseEnvSampler;\nuniform samplerCube pbr_specularEnvSampler;\nuniform sampler2D pbr_brdfLUT;\n#endif\n",Nt="layout(std140) uniform pbrProjectionUniforms {\n mat4 modelViewProjectionMatrix;\n mat4 modelMatrix;\n mat4 normalMatrix;\n vec3 camera;\n} pbrProjection;\n",kt={props:{},uniforms:{},defaultUniforms:{unlit:!1,baseColorMapEnabled:!1,baseColorFactor:[1,1,1,1],normalMapEnabled:!1,normalScale:1,emissiveMapEnabled:!1,emissiveFactor:[0,0,0],metallicRoughnessValues:[1,1],metallicRoughnessMapEnabled:!1,occlusionMapEnabled:!1,occlusionStrength:1,alphaCutoffEnabled:!1,alphaCutoff:.5,IBLenabled:!1,scaleIBLAmbient:[1,1],scaleDiffBaseMR:[0,0,0,0],scaleFGDSpec:[0,0,0,0],specularColorFactor:[1,1,1],specularIntensityFactor:1,specularColorMapEnabled:!1,specularIntensityMapEnabled:!1,ior:1.5,transmissionFactor:0,transmissionMapEnabled:!1,thicknessFactor:0,attenuationDistance:1e9,attenuationColor:[1,1,1],clearcoatFactor:0,clearcoatRoughnessFactor:0,clearcoatMapEnabled:!1,clearcoatRoughnessMapEnabled:!1,sheenColorFactor:[0,0,0],sheenRoughnessFactor:0,sheenColorMapEnabled:!1,sheenRoughnessMapEnabled:!1,iridescenceFactor:0,iridescenceIor:1.3,iridescenceThicknessRange:[100,400],iridescenceMapEnabled:!1,anisotropyStrength:0,anisotropyRotation:0,anisotropyDirection:[1,0],anisotropyMapEnabled:!1,emissiveStrength:1,dispersion:0,baseColorUVSet:0,baseColorUVTransform:[1,0,0,0,1,0,0,0,1],metallicRoughnessUVSet:0,metallicRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],normalUVSet:0,normalUVTransform:[1,0,0,0,1,0,0,0,1],occlusionUVSet:0,occlusionUVTransform:[1,0,0,0,1,0,0,0,1],emissiveUVSet:0,emissiveUVTransform:[1,0,0,0,1,0,0,0,1],specularColorUVSet:0,specularColorUVTransform:[1,0,0,0,1,0,0,0,1],specularIntensityUVSet:0,specularIntensityUVTransform:[1,0,0,0,1,0,0,0,1],transmissionUVSet:0,transmissionUVTransform:[1,0,0,0,1,0,0,0,1],thicknessUVSet:0,thicknessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatUVSet:0,clearcoatUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatRoughnessUVSet:0,clearcoatRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatNormalUVSet:0,clearcoatNormalUVTransform:[1,0,0,0,1,0,0,0,1],sheenColorUVSet:0,sheenColorUVTransform:[1,0,0,0,1,0,0,0,1],sheenRoughnessUVSet:0,sheenRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceUVSet:0,iridescenceUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceThicknessUVSet:0,iridescenceThicknessUVTransform:[1,0,0,0,1,0,0,0,1],anisotropyUVSet:0,anisotropyUVTransform:[1,0,0,0,1,0,0,0,1],bumpFactor:1,bumpMapEnabled:!1,diffuseTransmissionFactor:0,diffuseTransmissionMapEnabled:!1,diffuseTransmissionColorFactor:[1,1,1],diffuseTransmissionColorMapEnabled:!1,multiscatterColorFactor:[0,0,0],multiscatterColorMapEnabled:!1,scatterAnisotropy:0,bumpUVSet:0,bumpUVTransform:[1,0,0,0,1,0,0,0,1],diffuseTransmissionUVSet:0,diffuseTransmissionUVTransform:[1,0,0,0,1,0,0,0,1],diffuseTransmissionColorUVSet:0,diffuseTransmissionColorUVTransform:[1,0,0,0,1,0,0,0,1],multiscatterColorUVSet:0,multiscatterColorUVTransform:[1,0,0,0,1,0,0,0,1]},name:"pbrMaterial",firstBindingSlot:0,bindingLayout:[{name:"pbrMaterial",group:3},{name:"pbr_baseColorSampler",group:3},{name:"pbr_normalSampler",group:3},{name:"pbr_emissiveSampler",group:3},{name:"pbr_metallicRoughnessSampler",group:3},{name:"pbr_occlusionSampler",group:3},{name:"pbr_specularColorSampler",group:3},{name:"pbr_specularIntensitySampler",group:3},{name:"pbr_transmissionSampler",group:3},{name:"pbr_thicknessSampler",group:3},{name:"pbr_clearcoatSampler",group:3},{name:"pbr_clearcoatRoughnessSampler",group:3},{name:"pbr_clearcoatNormalSampler",group:3},{name:"pbr_sheenColorSampler",group:3},{name:"pbr_sheenRoughnessSampler",group:3},{name:"pbr_iridescenceSampler",group:3},{name:"pbr_iridescenceThicknessSampler",group:3},{name:"pbr_anisotropySampler",group:3},{name:"pbr_bumpSampler",group:3},{name:"pbr_diffuseTransmissionSampler",group:3},{name:"pbr_diffuseTransmissionColorSampler",group:3},{name:"pbr_multiscatterColorSampler",group:3}],dependencies:[S,{name:"ibl",firstBindingSlot:32,bindingLayout:[{name:"pbr_diffuseEnvSampler",group:2},{name:"pbr_specularEnvSampler",group:2},{name:"pbr_brdfLUT",group:2}],source:"#ifdef USE_IBL\n@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;\n@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;\n@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;\n@group(2) @binding(auto) var pbr_specularEnvSamplerSampler: sampler;\n@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;\n@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;\n#endif\n",vs:Pt,fs:Pt},{name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:"struct pbrProjectionUniforms {\n modelViewProjectionMatrix: mat4x4<f32>,\n modelMatrix: mat4x4<f32>,\n normalMatrix: mat4x4<f32>,\n camera: vec3<f32>\n};\n\n@group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;\n",vs:Nt,fs:Nt,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}}],source:"struct PBRFragmentInputs {\n pbr_vPosition: vec3f,\n pbr_vUV0: vec2f,\n pbr_vUV1: vec2f,\n pbr_vTBN: mat3x3f,\n pbr_vNormal: vec3f\n};\n\nvar<private> fragmentInputs: PBRFragmentInputs;\n\nfn pbr_setPositionNormalTangentUV(\n position: vec4f,\n normal: vec4f,\n tangent: vec4f,\n uv0: vec2f,\n uv1: vec2f\n)\n{\n var pos: vec4f = pbrProjection.modelMatrix * position;\n fragmentInputs.pbr_vPosition = pos.xyz / pos.w;\n fragmentInputs.pbr_vNormal = vec3f(0.0, 0.0, 1.0);\n fragmentInputs.pbr_vTBN = mat3x3f(\n vec3f(1.0, 0.0, 0.0),\n vec3f(0.0, 1.0, 0.0),\n vec3f(0.0, 0.0, 1.0)\n );\n fragmentInputs.pbr_vUV0 = vec2f(0.0, 0.0);\n fragmentInputs.pbr_vUV1 = uv1;\n\n#ifdef HAS_NORMALS\n let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);\n fragmentInputs.pbr_vNormal = normalW;\n#ifdef HAS_TANGENTS\n let tangentW: vec3f = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);\n let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;\n fragmentInputs.pbr_vTBN = mat3x3f(tangentW, bitangentW, normalW);\n#endif\n#endif\n\n#ifdef HAS_UV\n fragmentInputs.pbr_vUV0 = uv0;\n#endif\n}\n\nstruct pbrMaterialUniforms {\n // Material is unlit\n unlit: u32,\n\n // Base color map\n baseColorMapEnabled: u32,\n baseColorFactor: vec4f,\n\n normalMapEnabled : u32,\n normalScale: f32, // #ifdef HAS_NORMALMAP\n\n emissiveMapEnabled: u32,\n emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP\n\n metallicRoughnessValues: vec2f,\n metallicRoughnessMapEnabled: u32,\n\n occlusionMapEnabled: i32,\n occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP\n \n alphaCutoffEnabled: i32,\n alphaCutoff: f32, // #ifdef ALPHA_CUTOFF\n\n specularColorFactor: vec3f,\n specularIntensityFactor: f32,\n specularColorMapEnabled: i32,\n specularIntensityMapEnabled: i32,\n\n ior: f32,\n\n transmissionFactor: f32,\n transmissionMapEnabled: i32,\n\n thicknessFactor: f32,\n attenuationDistance: f32,\n attenuationColor: vec3f,\n\n clearcoatFactor: f32,\n clearcoatRoughnessFactor: f32,\n clearcoatMapEnabled: i32,\n clearcoatRoughnessMapEnabled: i32,\n\n sheenColorFactor: vec3f,\n sheenRoughnessFactor: f32,\n sheenColorMapEnabled: i32,\n sheenRoughnessMapEnabled: i32,\n\n iridescenceFactor: f32,\n iridescenceIor: f32,\n iridescenceThicknessRange: vec2f,\n iridescenceMapEnabled: i32,\n\n anisotropyStrength: f32,\n anisotropyRotation: f32,\n anisotropyDirection: vec2f,\n anisotropyMapEnabled: i32,\n\n emissiveStrength: f32,\n dispersion: f32,\n \n // IBL\n IBLenabled: i32,\n scaleIBLAmbient: vec2f, // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n scaleDiffBaseMR: vec4f,\n scaleFGDSpec: vec4f,\n // #endif\n\n baseColorUVSet: i32,\n baseColorUVTransform: mat3x3f,\n metallicRoughnessUVSet: i32,\n metallicRoughnessUVTransform: mat3x3f,\n normalUVSet: i32,\n normalUVTransform: mat3x3f,\n occlusionUVSet: i32,\n occlusionUVTransform: mat3x3f,\n emissiveUVSet: i32,\n emissiveUVTransform: mat3x3f,\n specularColorUVSet: i32,\n specularColorUVTransform: mat3x3f,\n specularIntensityUVSet: i32,\n specularIntensityUVTransform: mat3x3f,\n transmissionUVSet: i32,\n transmissionUVTransform: mat3x3f,\n thicknessUVSet: i32,\n thicknessUVTransform: mat3x3f,\n clearcoatUVSet: i32,\n clearcoatUVTransform: mat3x3f,\n clearcoatRoughnessUVSet: i32,\n clearcoatRoughnessUVTransform: mat3x3f,\n clearcoatNormalUVSet: i32,\n clearcoatNormalUVTransform: mat3x3f,\n sheenColorUVSet: i32,\n sheenColorUVTransform: mat3x3f,\n sheenRoughnessUVSet: i32,\n sheenRoughnessUVTransform: mat3x3f,\n iridescenceUVSet: i32,\n iridescenceUVTransform: mat3x3f,\n iridescenceThicknessUVSet: i32,\n iridescenceThicknessUVTransform: mat3x3f,\n anisotropyUVSet: i32,\n anisotropyUVTransform: mat3x3f,\n\n bumpFactor: f32,\n bumpMapEnabled: i32,\n diffuseTransmissionFactor: f32,\n diffuseTransmissionMapEnabled: i32,\n diffuseTransmissionColorFactor: vec3f,\n diffuseTransmissionColorMapEnabled: i32,\n multiscatterColorFactor: vec3f,\n multiscatterColorMapEnabled: i32,\n scatterAnisotropy: f32,\n\n bumpUVSet: i32,\n bumpUVTransform: mat3x3f,\n diffuseTransmissionUVSet: i32,\n diffuseTransmissionUVTransform: mat3x3f,\n diffuseTransmissionColorUVSet: i32,\n diffuseTransmissionColorUVTransform: mat3x3f,\n multiscatterColorUVSet: i32,\n multiscatterColorUVTransform: mat3x3f,\n}\n\n@group(3) @binding(auto) var<uniform> pbrMaterial : pbrMaterialUniforms;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\n@group(3) @binding(auto) var pbr_baseColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_baseColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_NORMALMAP\n@group(3) @binding(auto) var pbr_normalSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_normalSamplerSampler: sampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\n@group(3) @binding(auto) var pbr_emissiveSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_emissiveSamplerSampler: sampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\n@group(3) @binding(auto) var pbr_metallicRoughnessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_metallicRoughnessSamplerSampler: sampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\n@group(3) @binding(auto) var pbr_occlusionSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_occlusionSamplerSampler: sampler;\n#endif\n#ifdef HAS_SPECULARCOLORMAP\n@group(3) @binding(auto) var pbr_specularColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_specularColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_SPECULARINTENSITYMAP\n@group(3) @binding(auto) var pbr_specularIntensitySampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_specularIntensitySamplerSampler: sampler;\n#endif\n#ifdef HAS_TRANSMISSIONMAP\n@group(3) @binding(auto) var pbr_transmissionSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_transmissionSamplerSampler: sampler;\n#endif\n#ifdef HAS_THICKNESSMAP\n@group(3) @binding(auto) var pbr_thicknessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_thicknessSamplerSampler: sampler;\n#endif\n#ifdef HAS_CLEARCOATMAP\n@group(3) @binding(auto) var pbr_clearcoatSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_clearcoatSamplerSampler: sampler;\n#endif\n#ifdef HAS_CLEARCOATROUGHNESSMAP\n@group(3) @binding(auto) var pbr_clearcoatRoughnessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_clearcoatRoughnessSamplerSampler: sampler;\n#endif\n#ifdef HAS_CLEARCOATNORMALMAP\n@group(3) @binding(auto) var pbr_clearcoatNormalSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_clearcoatNormalSamplerSampler: sampler;\n#endif\n#ifdef HAS_SHEENCOLORMAP\n@group(3) @binding(auto) var pbr_sheenColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_sheenColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_SHEENROUGHNESSMAP\n@group(3) @binding(auto) var pbr_sheenRoughnessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_sheenRoughnessSamplerSampler: sampler;\n#endif\n#ifdef HAS_IRIDESCENCEMAP\n@group(3) @binding(auto) var pbr_iridescenceSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_iridescenceSamplerSampler: sampler;\n#endif\n#ifdef HAS_IRIDESCENCETHICKNESSMAP\n@group(3) @binding(auto) var pbr_iridescenceThicknessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_iridescenceThicknessSamplerSampler: sampler;\n#endif\n#ifdef HAS_ANISOTROPYMAP\n@group(3) @binding(auto) var pbr_anisotropySampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_anisotropySamplerSampler: sampler;\n#endif\n#ifdef HAS_BUMPMAP\n@group(3) @binding(auto) var pbr_bumpSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_bumpSamplerSampler: sampler;\n#endif\n#ifdef HAS_DIFFUSETRANSMISSIONMAP\n@group(3) @binding(auto) var pbr_diffuseTransmissionSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_diffuseTransmissionSamplerSampler: sampler;\n#endif\n#ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP\n@group(3) @binding(auto) var pbr_diffuseTransmissionColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_diffuseTransmissionColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_MULTISCATTERCOLORMAP\n@group(3) @binding(auto) var pbr_multiscatterColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_multiscatterColorSamplerSampler: sampler;\n#endif\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n NdotL: f32, // cos angle between normal and light direction\n NdotV: f32, // cos angle between normal and view direction\n NdotH: f32, // cos angle between normal and half vector\n LdotH: f32, // cos angle between light direction and half vector\n VdotH: f32, // cos angle between view direction and half vector\n perceptualRoughness: f32, // roughness value, as authored by the model creator (input to shader)\n metalness: f32, // metallic value at the surface\n reflectance0: vec3f, // full reflectance color (normal incidence angle)\n reflectance90: vec3f, // reflectance color at grazing angle\n alphaRoughness: f32, // roughness mapped to a more linear change in the roughness (proposed by [2])\n diffuseColor: vec3f, // color contribution from diffuse lighting\n specularColor: vec3f, // color contribution from specular lighting\n n: vec3f, // normal at surface point\n v: vec3f, // vector from surface point to camera\n l: vec3f, // direction from the surface toward the current light\n h: vec3f // half vector between the current light and camera\n};\n\nconst M_PI = 3.141592653589793;\nconst c_MinRoughness = 0.04;\n\n// Widen sub-pixel specular lobes using the screen-space normal footprint.\n// This is geometric specular antialiasing: the normal variance is converted\n// into an additional squared perceptual roughness before evaluating BRDFs.\nfn widenSpecularRoughness(perceptualRoughness: f32, normal: vec3f) -> f32 {\n let normalDerivativeX = dpdx(normal);\n let normalDerivativeY = dpdy(normal);\n let normalVariance =\n dot(normalDerivativeX, normalDerivativeX) +\n dot(normalDerivativeY, normalDerivativeY);\n let kernelRoughnessSquared = min(2.0 * normalVariance, 1.0);\n return clamp(\n sqrt(perceptualRoughness * perceptualRoughness + kernelRoughnessSquared),\n c_MinRoughness,\n 1.0\n );\n}\n\nfn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f\n{\n var linOut: vec3f = srgbIn.xyz;\n#ifdef MANUAL_SRGB\n let bLess: vec3f = step(vec3f(0.04045), srgbIn.xyz);\n linOut = mix(\n srgbIn.xyz / vec3f(12.92),\n pow((srgbIn.xyz + vec3f(0.055)) / vec3f(1.055), vec3f(2.4)),\n bLess\n );\n#ifdef SRGB_FAST_APPROXIMATION\n linOut = pow(srgbIn.xyz, vec3f(2.2));\n#endif\n#endif\n return vec4f(linOut, srgbIn.w);\n}\n\nfn getMaterialUV(uvSet: i32, uvTransform: mat3x3f) -> vec2f\n{\n var baseUV = fragmentInputs.pbr_vUV0;\n if (uvSet == 1) {\n baseUV = fragmentInputs.pbr_vUV1;\n }\n return (uvTransform * vec3f(baseUV, 1.0)).xy;\n}\n\n// Build the tangent basis from interpolated attributes or screen-space derivatives.\nfn getTBN(uv: vec2f) -> mat3x3f\n{\n let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);\n let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);\n let tex_dx: vec3f = dpdx(vec3f(uv, 0.0));\n let tex_dy: vec3f = dpdy(vec3f(uv, 0.0));\n var t: vec3f = (tex_dy.y * pos_dx - tex_dx.y * pos_dy) / (tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y);\n\n var ng: vec3f = cross(pos_dy, pos_dx);\n#ifdef HAS_NORMALS\n ng = normalize(fragmentInputs.pbr_vNormal);\n#endif\n t = normalize(t - ng * dot(ng, t));\n var b: vec3f = normalize(cross(ng, t));\n var tbn: mat3x3f = mat3x3f(t, b, ng);\n#ifdef HAS_TANGENTS\n tbn = fragmentInputs.pbr_vTBN;\n#endif\n\n return tbn;\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nfn getMappedNormal(\n normalSampler: texture_2d<f32>,\n normalSamplerBinding: sampler,\n tbn: mat3x3f,\n normalScale: f32,\n uv: vec2f\n) -> vec3f\n{\n let n = textureSample(normalSampler, normalSamplerBinding, uv).rgb;\n return normalize(tbn * ((2.0 * n - 1.0) * vec3f(normalScale, normalScale, 1.0)));\n}\n\nfn getNormal(tbn: mat3x3f, uv: vec2f) -> vec3f\n{\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n var n: vec3f = normalize(tbn[2].xyz);\n#ifdef HAS_NORMALMAP\n n = getMappedNormal(\n pbr_normalSampler,\n pbr_normalSamplerSampler,\n tbn,\n pbrMaterial.normalScale,\n uv\n );\n#endif\n\n#ifdef HAS_BUMPMAP\n let bumpUV = getMaterialUV(pbrMaterial.bumpUVSet, pbrMaterial.bumpUVTransform);\n let bumpTexelSize = 1.0 / vec2f(textureDimensions(pbr_bumpSampler, 0));\n let bumpHeight = textureSample(pbr_bumpSampler, pbr_bumpSamplerSampler, bumpUV).r;\n let bumpGradient = vec2f(\n textureSample(\n pbr_bumpSampler,\n pbr_bumpSamplerSampler,\n bumpUV + vec2f(bumpTexelSize.x, 0.0)\n ).r - bumpHeight,\n textureSample(\n pbr_bumpSampler,\n pbr_bumpSamplerSampler,\n bumpUV + vec2f(0.0, bumpTexelSize.y)\n ).r - bumpHeight\n );\n n = normalize(n - pbrMaterial.bumpFactor *\n (tbn[0] * bumpGradient.x + tbn[1] * bumpGradient.y));\n#endif\n\n return n;\n}\n\nfn getClearcoatNormal(tbn: mat3x3f, baseNormal: vec3f, uv: vec2f) -> vec3f\n{\n#ifdef HAS_CLEARCOATNORMALMAP\n return getMappedNormal(\n pbr_clearcoatNormalSampler,\n pbr_clearcoatNormalSamplerSampler,\n tbn,\n 1.0,\n uv\n );\n#else\n return baseNormal;\n#endif\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nfn getIBLContribution(pbrInfo: PBRInfo, n: vec3f, reflection: vec3f) -> vec3f\n{\n#ifdef USE_SCENE_ENVIRONMENT\n let maximumMipLevel = max(pbrScene.environmentMipCount - 1.0, 0.0);\n let rotationSine = sin(pbrScene.environmentRotation);\n let rotationCosine = cos(pbrScene.environmentRotation);\n let environmentRotation = mat2x2f(\n vec2f(rotationCosine, rotationSine),\n vec2f(-rotationSine, rotationCosine)\n );\n let rotatedNormal = environmentRotation * n.xz;\n let rotatedReflection = environmentRotation * reflection.xz;\n let environmentNormal = vec3f(rotatedNormal.x, n.y, rotatedNormal.y);\n let environmentReflection = vec3f(rotatedReflection.x, reflection.y, rotatedReflection.y);\n#else\n let maximumMipLevel = 9.0;\n let environmentNormal = n;\n let environmentReflection = reflection;\n#endif\n let lod = pbrInfo.perceptualRoughness * maximumMipLevel;\n // retrieve a scale and bias to F0. See [1], Figure 3\n let brdfSample = textureSampleLevel(\n pbr_brdfLUT,\n pbr_brdfLUTSampler,\n vec2f(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness),\n 0.0\n );\n let diffuseSample = textureSampleLevel(\n pbr_diffuseEnvSampler,\n pbr_diffuseEnvSamplerSampler,\n environmentNormal,\n 0.0\n );\n var specularSample = textureSampleLevel(\n pbr_specularEnvSampler,\n pbr_specularEnvSamplerSampler,\n environmentReflection,\n 0.0\n );\n#ifdef USE_TEX_LOD\n specularSample = textureSampleLevel(\n pbr_specularEnvSampler,\n pbr_specularEnvSamplerSampler,\n environmentReflection,\n lod\n );\n#endif\n\n#ifdef USE_SCENE_ENVIRONMENT\n let brdf = brdfSample.rgb;\n let diffuseLight = diffuseSample.rgb;\n let specularLight = specularSample.rgb;\n#else\n let brdf = SRGBtoLINEAR(brdfSample).rgb;\n let diffuseLight = SRGBtoLINEAR(diffuseSample).rgb;\n let specularLight = SRGBtoLINEAR(specularSample).rgb;\n#endif\n\n let diffuse = diffuseLight * pbrInfo.diffuseColor * pbrMaterial.scaleIBLAmbient.x;\n let specular =\n specularLight * (pbrInfo.specularColor * brdf.x + brdf.y) * pbrMaterial.scaleIBLAmbient.y;\n\n#ifdef USE_SCENE_ENVIRONMENT\n return (diffuse + specular) * max(pbrScene.environmentIntensity, 0.0);\n#else\n return diffuse + specular;\n#endif\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nfn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nfn specularReflection(pbrInfo: PBRInfo) -> vec3<f32> {\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {\n let NdotL: f32 = pbrInfo.NdotL;\n let NdotV: f32 = pbrInfo.NdotV;\n let r: f32 = pbrInfo.alphaRoughness;\n\n let attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n let attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {\n let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nfn maxComponent(value: vec3f) -> f32 {\n return max(max(value.r, value.g), value.b);\n}\n\nfn getDielectricF0(ior: f32) -> f32 {\n let clampedIor = max(ior, 1.0);\n let ratio = (clampedIor - 1.0) / (clampedIor + 1.0);\n return ratio * ratio;\n}\n\nfn normalizeDirection(direction: vec2f) -> vec2f {\n let directionLength = length(direction);\n if (directionLength > 0.0001) {\n return direction / directionLength;\n }\n\n return vec2f(1.0, 0.0);\n}\n\nfn rotateDirection(direction: vec2f, rotation: f32) -> vec2f {\n let s = sin(rotation);\n let c = cos(rotation);\n return vec2f(direction.x * c - direction.y * s, direction.x * s + direction.y * c);\n}\n\nfn encodeLinearSRGB(linearColor: vec3f) -> vec3f {\n let positiveColor = max(linearColor, vec3f(0.0));\n return select(\n positiveColor * 12.92,\n 1.055 * pow(positiveColor, vec3f(1.0 / 2.4)) - 0.055,\n positiveColor > vec3f(0.0031308)\n );\n}\n\nfn toneMapKhronosPBRNeutral(inputColor: vec3f) -> vec3f {\n let startCompression = 0.76;\n let darkestChannel = min(inputColor.r, min(inputColor.g, inputColor.b));\n let offset = select(\n 0.04,\n darkestChannel - 6.25 * darkestChannel * darkestChannel,\n darkestChannel < 0.08\n );\n var color = inputColor - vec3f(offset);\n let peak = maxComponent(color);\n if (peak < startCompression) {\n return color;\n }\n\n let compressionRange = 1.0 - startCompression;\n let compressedPeak = 1.0 - compressionRange * compressionRange /\n (peak + compressionRange - startCompression);\n color *= compressedPeak / max(peak, 0.0001);\n let desaturation = 1.0 - 1.0 / (0.15 * (peak - compressedPeak) + 1.0);\n return mix(color, vec3f(compressedPeak), desaturation);\n}\n\nfn applySceneColorManagement(sceneColor: vec3f) -> vec3f {\n#ifdef USE_SCENE_COLOR_MANAGEMENT\n var color = max(sceneColor, vec3f(0.0)) * max(pbrScene.exposure, 0.0);\n if (pbrScene.toneMapMode == 1) {\n color /= vec3f(1.0) + color;\n } else if (pbrScene.toneMapMode == 2) {\n color = toneMapKhronosPBRNeutral(color);\n } else if (pbrScene.toneMapMode == 3) {\n color = clamp(\n (color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14),\n vec3f(0.0),\n vec3f(1.0)\n );\n }\n if (pbrScene.outputEncoding == 0) {\n return color;\n }\n return encodeLinearSRGB(color);\n#else\n return pow(max(sceneColor, vec3f(0.0)), vec3f(1.0 / 2.2));\n#endif\n}\n\nfn dielectricSchlick(reflectance: f32, cosine: f32) -> f32 {\n return reflectance + (1.0 - reflectance) * pow(clamp(1.0 - cosine, 0.0, 1.0), 5.0);\n}\n\nfn evaluateIridescenceSensitivity(opticalPathDifference: f32, phaseShift: vec3f) -> vec3f {\n let phase = 2.0 * M_PI * opticalPathDifference * 1.0e-9;\n let sensitivity = vec3f(5.4856e-13, 4.4201e-13, 5.2481e-13);\n let position = vec3f(1.6810e6, 1.7953e6, 2.2084e6);\n let variance = vec3f(4.3278e9, 9.3046e9, 6.6121e9);\n var xyz = sensitivity * sqrt(2.0 * M_PI * variance) *\n cos(position * phase + phaseShift) * exp(-phase * phase * variance);\n xyz.x += 9.7470e-14 * sqrt(2.0 * M_PI * 4.5282e9) *\n cos(2.2399e6 * phase + phaseShift.x) * exp(-4.5282e9 * phase * phase);\n xyz /= 1.0685e-7;\n return mat3x3f(\n vec3f(3.2404542, -0.9692660, 0.0556434),\n vec3f(-1.5371385, 1.8760108, -0.2040259),\n vec3f(-0.4985314, 0.0415560, 1.0572252)\n ) * xyz;\n}\n\nfn getIridescenceTint(\n iridescence: f32,\n thickness: f32,\n NdotV: f32,\n baseReflectance: vec3f\n) -> vec3f {\n if (iridescence <= 0.0 || thickness <= 0.0) {\n return baseReflectance;\n }\n\n let filmIor = max(pbrMaterial.iridescenceIor, 1.0);\n let sineSquared = (1.0 - NdotV * NdotV) / (filmIor * filmIor);\n let cosineSquared = 1.0 - sineSquared;\n if (cosineSquared <= 0.0) {\n return mix(baseReflectance, vec3f(1.0), iridescence);\n }\n let filmCosine = sqrt(cosineSquared);\n let firstInterfaceReflectance = dielectricSchlick(getDielectricF0(filmIor), NdotV);\n let transmittedEnergy = 1.0 - firstInterfaceReflectance;\n let squareRootReflectance = sqrt(clamp(baseReflectance, vec3f(0.0), vec3f(0.9999)));\n let baseIor = (vec3f(1.0) + squareRootReflectance) /\n (vec3f(1.0) - squareRootReflectance);\n var secondInterfaceF0 = (baseIor - vec3f(filmIor)) / (baseIor + vec3f(filmIor));\n secondInterfaceF0 *= secondInterfaceF0;\n let secondInterfaceReflectance = secondInterfaceF0 +\n (vec3f(1.0) - secondInterfaceF0) * pow(1.0 - filmCosine, 5.0);\n let phaseShift = vec3f(M_PI) + select(\n vec3f(0.0),\n vec3f(M_PI),\n baseIor < vec3f(filmIor)\n );\n let opticalPathDifference = 2.0 * filmIor * thickness * filmCosine;\n let combinedReflectance = clamp(\n firstInterfaceReflectance * secondInterfaceReflectance,\n vec3f(0.00001),\n vec3f(0.9999)\n );\n let recurringAmplitude = sqrt(combinedReflectance);\n let interfaceResponse = transmittedEnergy * transmittedEnergy * secondInterfaceReflectance /\n (vec3f(1.0) - combinedReflectance);\n var reflectedSpectrum = vec3f(firstInterfaceReflectance) + interfaceResponse;\n var harmonicAmplitude = interfaceResponse - vec3f(transmittedEnergy);\n for (var harmonic = 1; harmonic <= 2; harmonic++) {\n harmonicAmplitude *= recurringAmplitude;\n reflectedSpectrum += harmonicAmplitude * 2.0 * evaluateIridescenceSensitivity(\n f32(harmonic) * opticalPathDifference,\n f32(harmonic) * phaseShift\n );\n }\n return mix(baseReflectance, clamp(reflectedSpectrum, vec3f(0.0), vec3f(1.0)), iridescence);\n}\n\nfn getVolumeAttenuation(thickness: f32) -> vec3f {\n if (thickness <= 0.0) {\n return vec3f(1.0);\n }\n\n let attenuationCoefficient =\n -log(max(pbrMaterial.attenuationColor, vec3f(0.0001))) /\n max(pbrMaterial.attenuationDistance, 0.0001);\n return exp(-attenuationCoefficient * thickness);\n}\n\n// KHR_materials_volume_scatter is an active draft. This evaluates a local,\n// thickness-aware single-scattering approximation rather than random walk.\nfn getDiffuseTransmissionAttenuation(\n pbrInfo: PBRInfo,\n multiscatterColor: vec3f,\n thickness: f32\n) -> vec3f {\n let volumeAttenuation = getVolumeAttenuation(thickness);\n let scatteringStrength = maxComponent(multiscatterColor);\n if (thickness <= 0.0 || scatteringStrength <= 0.0001) {\n return volumeAttenuation;\n }\n\n let anisotropy = clamp(pbrMaterial.scatterAnisotropy, -0.95, 0.95);\n let scatteringCosine = clamp(dot(-pbrInfo.v, pbrInfo.l), -1.0, 1.0);\n let phaseDenominator = max(\n 1.0 + anisotropy * anisotropy - 2.0 * anisotropy * scatteringCosine,\n 0.0001\n );\n let phaseWeight = clamp(\n (1.0 - anisotropy * anisotropy) / pow(phaseDenominator, 1.5),\n 0.0,\n 4.0\n );\n let scatteringDepth = thickness / max(pbrMaterial.attenuationDistance, 0.0001);\n let scatteringProbability = 1.0 - exp(-scatteringDepth);\n let scatteringColor = clamp(multiscatterColor, vec3f(0.0), vec3f(1.0));\n return mix(\n volumeAttenuation,\n volumeAttenuation * mix(vec3f(1.0), scatteringColor * phaseWeight, scatteringColor),\n scatteringProbability\n );\n}\n\nfn calculateDiffuseTransmissionLight(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n diffuseTransmissionColor: vec3f,\n diffuseTransmission: f32,\n multiscatterColor: vec3f,\n thickness: f32\n) -> vec3f {\n let oppositeHemisphere = max(dot(-pbrInfo.n, pbrInfo.l), 0.0);\n if (oppositeHemisphere <= 0.0 || diffuseTransmission <= 0.0) {\n return vec3f(0.0);\n }\n\n let nonReflectedEnergy = vec3f(1.0) - clamp(pbrInfo.reflectance0, vec3f(0.0), vec3f(1.0));\n let attenuatedColor = getDiffuseTransmissionAttenuation(\n pbrInfo,\n multiscatterColor,\n thickness\n );\n return lightColor * diffuseTransmissionColor * nonReflectedEnergy *\n attenuatedColor * (diffuseTransmission * oppositeHemisphere / M_PI);\n}\n\n#ifdef USE_IBL\nfn calculateDiffuseTransmissionIBL(\n pbrInfo: PBRInfo,\n diffuseTransmissionColor: vec3f,\n diffuseTransmission: f32,\n multiscatterColor: vec3f,\n thickness: f32\n) -> vec3f {\n if (diffuseTransmission <= 0.0) {\n return vec3f(0.0);\n }\n\n#ifdef USE_SCENE_ENVIRONMENT\n let rotationSine = sin(pbrScene.environmentRotation);\n let rotationCosine = cos(pbrScene.environmentRotation);\n let environmentRotation = mat2x2f(\n vec2f(rotationCosine, rotationSine),\n vec2f(-rotationSine, rotationCosine)\n );\n let rotatedNormal = environmentRotation * -pbrInfo.n.xz;\n let oppositeNormal = vec3f(rotatedNormal.x, -pbrInfo.n.y, rotatedNormal.y);\n let environmentColor = textureSampleLevel(\n pbr_diffuseEnvSampler,\n pbr_diffuseEnvSamplerSampler,\n oppositeNormal,\n 0.0\n ).rgb * max(pbrScene.environmentIntensity, 0.0);\n#else\n let environmentColor = SRGBtoLINEAR(\n textureSampleLevel(pbr_diffuseEnvSampler, pbr_diffuseEnvSamplerSampler, -pbrInfo.n, 0.0)\n ).rgb;\n#endif\n let nonReflectedEnergy = vec3f(1.0) - clamp(pbrInfo.reflectance0, vec3f(0.0), vec3f(1.0));\n return environmentColor * diffuseTransmissionColor * nonReflectedEnergy *\n getDiffuseTransmissionAttenuation(pbrInfo, multiscatterColor, thickness) *\n diffuseTransmission * pbrMaterial.scaleIBLAmbient.x;\n}\n#endif\n\n#ifdef USE_TRANSMISSION_FRAMEBUFFER\nfn sampleTransmittedSceneColor(\n position: vec3f,\n normal: vec3f,\n viewDirection: vec3f,\n thickness: f32,\n perceptualRoughness: f32,\n indexOfRefraction: f32\n) -> vec3f {\n let refractionDirection = refract(\n -viewDirection,\n normal,\n 1.0 / max(indexOfRefraction, 1.0)\n );\n let refractedPosition = position + refractionDirection * thickness;\n let clipPosition = pbrScene.projectionMatrix *\n pbrScene.viewMatrix * vec4f(refractedPosition, 1.0);\n var textureCoordinate = clipPosition.xy / max(clipPosition.w, 0.0001) * 0.5 + 0.5;\n textureCoordinate.y = 1.0 - textureCoordinate.y;\n textureCoordinate = clamp(textureCoordinate, vec2f(0.001), vec2f(0.999));\n\n let blurRadius = perceptualRoughness * perceptualRoughness * 8.0 /\n max(pbrScene.framebufferSize, vec2f(1.0));\n var sceneColor = textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate,\n 0.0\n ).rgb * 0.4;\n sceneColor += textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate + vec2f(blurRadius.x, 0.0),\n 0.0\n ).rgb * 0.15;\n sceneColor += textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate - vec2f(blurRadius.x, 0.0),\n 0.0\n ).rgb * 0.15;\n sceneColor += textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate + vec2f(0.0, blurRadius.y),\n 0.0\n ).rgb * 0.15;\n sceneColor += textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate - vec2f(0.0, blurRadius.y),\n 0.0\n ).rgb * 0.15;\n return max(sceneColor, vec3f(0.0));\n}\n\nfn getTransmittedSceneColor(\n position: vec3f,\n normal: vec3f,\n viewDirection: vec3f,\n thickness: f32,\n perceptualRoughness: f32\n) -> vec3f {\n if (pbrMaterial.dispersion <= 0.0) {\n return sampleTransmittedSceneColor(\n position,\n normal,\n viewDirection,\n thickness,\n perceptualRoughness,\n pbrMaterial.ior\n );\n }\n\n let halfSpread = (max(pbrMaterial.ior, 1.0) - 1.0) * 0.025 * pbrMaterial.dispersion;\n let indicesOfRefraction = max(\n vec3f(pbrMaterial.ior - halfSpread, pbrMaterial.ior, pbrMaterial.ior + halfSpread),\n vec3f(1.0)\n );\n return vec3f(\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.r\n ).r,\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.g\n ).g,\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.b\n ).b\n );\n}\n#endif\n\nfn createClearcoatPBRInfo(\n basePBRInfo: PBRInfo,\n clearcoatNormal: vec3f,\n clearcoatRoughness: f32\n) -> PBRInfo {\n let perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);\n let alphaRoughness = perceptualRoughness * perceptualRoughness;\n let NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);\n\n return PBRInfo(\n basePBRInfo.NdotL,\n NdotV,\n basePBRInfo.NdotH,\n basePBRInfo.LdotH,\n basePBRInfo.VdotH,\n perceptualRoughness,\n 0.0,\n vec3f(0.04),\n vec3f(1.0),\n alphaRoughness,\n vec3f(0.0),\n vec3f(0.04),\n clearcoatNormal,\n basePBRInfo.v,\n basePBRInfo.l,\n basePBRInfo.h\n );\n}\n\nfn calculateClearcoatContribution(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n clearcoatNormal: vec3f,\n clearcoatFactor: f32,\n clearcoatRoughness: f32\n) -> vec3f {\n if (clearcoatFactor <= 0.0) {\n return vec3f(0.0);\n }\n\n let clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);\n return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;\n}\n\n#ifdef USE_IBL\nfn calculateClearcoatIBLContribution(\n pbrInfo: PBRInfo,\n clearcoatNormal: vec3f,\n reflection: vec3f,\n clearcoatFactor: f32,\n clearcoatRoughness: f32\n) -> vec3f {\n if (clearcoatFactor <= 0.0) {\n return vec3f(0.0);\n }\n\n let clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);\n return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;\n}\n#endif\n\nfn calculateSheenContribution(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n sheenColor: vec3f,\n sheenRoughness: f32\n) -> vec3f {\n if (maxComponent(sheenColor) <= 0.0) {\n return vec3f(0.0);\n }\n\n let alpha = max(sheenRoughness * sheenRoughness, 0.0001);\n let inverseAlpha = 1.0 / alpha;\n let sineSquared = max(1.0 - pbrInfo.NdotH * pbrInfo.NdotH, 0.0);\n let distribution = (2.0 + inverseAlpha) * pow(sineSquared, inverseAlpha * 0.5) /\n (2.0 * M_PI);\n let visibility = 1.0 / max(\n 4.0 * (pbrInfo.NdotL + pbrInfo.NdotV - pbrInfo.NdotL * pbrInfo.NdotV),\n 0.0001\n );\n return pbrInfo.NdotL * lightColor * sheenColor * distribution * visibility *\n (1.0 - pbrInfo.metalness);\n}\n\nfn calculateAnisotropicLightColor(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n anisotropyTangent: vec3f,\n anisotropyStrength: f32\n) -> vec3f {\n if (anisotropyStrength <= 0.0) {\n return calculateFinalColor(pbrInfo, lightColor);\n }\n\n let anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));\n let tangentRoughness = mix(\n pbrInfo.alphaRoughness,\n 1.0,\n anisotropyStrength * anisotropyStrength\n );\n let bitangentRoughness = clamp(pbrInfo.alphaRoughness, 0.001, 1.0);\n let roughnessProduct = tangentRoughness * bitangentRoughness;\n let distributionVector = vec3f(\n bitangentRoughness * dot(anisotropyTangent, pbrInfo.h),\n tangentRoughness * dot(anisotropyBitangent, pbrInfo.h),\n roughnessProduct * pbrInfo.NdotH\n );\n let distributionFactor = roughnessProduct /\n max(dot(distributionVector, distributionVector), 0.000001);\n let distribution = roughnessProduct * distributionFactor * distributionFactor / M_PI;\n let viewMask = pbrInfo.NdotL * length(vec3f(\n tangentRoughness * dot(anisotropyTangent, pbrInfo.v),\n bitangentRoughness * dot(anisotropyBitangent, pbrInfo.v),\n pbrInfo.NdotV\n ));\n let lightMask = pbrInfo.NdotV * length(vec3f(\n tangentRoughness * dot(anisotropyTangent, pbrInfo.l),\n bitangentRoughness * dot(anisotropyBitangent, pbrInfo.l),\n pbrInfo.NdotL\n ));\n let visibility = clamp(0.5 / max(viewMask + lightMask, 0.000001), 0.0, 1.0);\n let fresnel = specularReflection(pbrInfo);\n let diffuseContribution = (vec3f(1.0) - fresnel) * diffuse(pbrInfo);\n return pbrInfo.NdotL * lightColor *\n (diffuseContribution + fresnel * distribution * visibility);\n}\n\nfn getAnisotropicReflection(\n pbrInfo: PBRInfo,\n anisotropyTangent: vec3f,\n anisotropyStrength: f32\n) -> vec3f {\n if (anisotropyStrength <= 0.0) {\n return -normalize(reflect(pbrInfo.v, pbrInfo.n));\n }\n let anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));\n var anisotropicNormal = normalize(cross(anisotropyBitangent, pbrInfo.v));\n anisotropicNormal = normalize(cross(anisotropicNormal, anisotropyBitangent));\n let bend = anisotropyStrength * (1.0 - pbrInfo.perceptualRoughness);\n return -normalize(reflect(pbrInfo.v, normalize(mix(pbrInfo.n, anisotropicNormal, bend))));\n}\n\nfn calculateMaterialLightColor(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n clearcoatNormal: vec3f,\n clearcoatFactor: f32,\n clearcoatRoughness: f32,\n sheenColor: vec3f,\n sheenRoughness: f32,\n anisotropyTangent: vec3f,\n anisotropyStrength: f32\n) -> vec3f {\n var color = calculateAnisotropicLightColor(\n pbrInfo,\n lightColor,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateClearcoatContribution(\n pbrInfo,\n lightColor,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness\n );\n color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);\n return color;\n}\n\nfn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {\n (*pbrInfo).NdotL = 1.0;\n (*pbrInfo).NdotH = 0.0;\n (*pbrInfo).LdotH = 0.0;\n (*pbrInfo).VdotH = 1.0;\n (*pbrInfo).l = (*pbrInfo).n;\n (*pbrInfo).h = (*pbrInfo).n;\n}\n\nfn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection: vec3<f32>) {\n let n = (*pbrInfo).n;\n let v = (*pbrInfo).v;\n let l = normalize(lightDirection); // Vector from surface point to light\n let h = normalize(l + v); // Half vector between both l and v\n\n (*pbrInfo).NdotL = clamp(dot(n, l), 0.001, 1.0);\n (*pbrInfo).NdotH = clamp(dot(n, h), 0.0, 1.0);\n (*pbrInfo).LdotH = clamp(dot(l, h), 0.0, 1.0);\n (*pbrInfo).VdotH = clamp(dot(v, h), 0.0, 1.0);\n (*pbrInfo).l = l;\n (*pbrInfo).h = h;\n}\n\nfn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {\n let light_direction = normalize(pointLight.position - fragmentInputs.pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nfn PBRInfo_setSpotLight(pbrInfo: ptr<function, PBRInfo>, spotLight: SpotLight) {\n let light_direction = normalize(spotLight.position - fragmentInputs.pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nfn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {\n // Calculate the shading terms for the microfacet specular shading model\n let F = specularReflection(pbrInfo);\n let G = geometricOcclusion(pbrInfo);\n let D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n let diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n let specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nfn pbr_filterColor(vertexColor: vec4<f32>) -> vec4<f32> {\n let baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);\n let metallicRoughnessUV = getMaterialUV(\n pbrMaterial.metallicRoughnessUVSet,\n pbrMaterial.metallicRoughnessUVTransform\n );\n let normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);\n let occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);\n let emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);\n let specularColorUV = getMaterialUV(\n pbrMaterial.specularColorUVSet,\n pbrMaterial.specularColorUVTransform\n );\n let specularIntensityUV = getMaterialUV(\n pbrMaterial.specularIntensityUVSet,\n pbrMaterial.specularIntensityUVTransform\n );\n let transmissionUV = getMaterialUV(\n pbrMaterial.transmissionUVSet,\n pbrMaterial.transmissionUVTransform\n );\n let thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);\n let clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);\n let clearcoatRoughnessUV = getMaterialUV(\n pbrMaterial.clearcoatRoughnessUVSet,\n pbrMaterial.clearcoatRoughnessUVTransform\n );\n let clearcoatNormalUV = getMaterialUV(\n pbrMaterial.clearcoatNormalUVSet,\n pbrMaterial.clearcoatNormalUVTransform\n );\n let sheenColorUV = getMaterialUV(\n pbrMaterial.sheenColorUVSet,\n pbrMaterial.sheenColorUVTransform\n );\n let sheenRoughnessUV = getMaterialUV(\n pbrMaterial.sheenRoughnessUVSet,\n pbrMaterial.sheenRoughnessUVTransform\n );\n let iridescenceUV = getMaterialUV(\n pbrMaterial.iridescenceUVSet,\n pbrMaterial.iridescenceUVTransform\n );\n let iridescenceThicknessUV = getMaterialUV(\n pbrMaterial.iridescenceThicknessUVSet,\n pbrMaterial.iridescenceThicknessUVTransform\n );\n let anisotropyUV = getMaterialUV(\n pbrMaterial.anisotropyUVSet,\n pbrMaterial.anisotropyUVTransform\n );\n let diffuseTransmissionUV = getMaterialUV(\n pbrMaterial.diffuseTransmissionUVSet,\n pbrMaterial.diffuseTransmissionUVTransform\n );\n let diffuseTransmissionColorUV = getMaterialUV(\n pbrMaterial.diffuseTransmissionColorUVSet,\n pbrMaterial.diffuseTransmissionColorUVTransform\n );\n let multiscatterColorUV = getMaterialUV(\n pbrMaterial.multiscatterColorUVSet,\n pbrMaterial.multiscatterColorUVTransform\n );\n\n // The albedo may be defined from a base texture or a flat color\n var baseColor: vec4<f32> = pbrMaterial.baseColorFactor * vertexColor;\n #ifdef HAS_BASECOLORMAP\n baseColor = SRGBtoLINEAR(\n textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, baseColorUV)\n ) * pbrMaterial.baseColorFactor * vertexColor;\n #endif\n\n #ifdef ALPHA_CUTOFF\n if (baseColor.a < pbrMaterial.alphaCutoff) {\n discard;\n }\n #endif\n\n var color = vec3<f32>(0.0, 0.0, 0.0);\n var transmission = 0.0;\n\n if (pbrMaterial.unlit != 0u) {\n color = baseColor.rgb;\n } else {\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n var perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;\n var metallic = pbrMaterial.metallicRoughnessValues.x;\n #ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n let mrSample = textureSample(\n pbr_metallicRoughnessSampler,\n pbr_metallicRoughnessSamplerSampler,\n metallicRoughnessUV\n );\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n #endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n let tbn = getTBN(normalUV);\n let n = getNormal(tbn, normalUV); // normal at surface point\n perceptualRoughness = widenSpecularRoughness(perceptualRoughness, n);\n let v = normalize(pbrProjection.camera - fragmentInputs.pbr_vPosition); // Vector from surface point to camera\n let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n var useExtendedPBR = false;\n #ifdef USE_MATERIAL_EXTENSIONS\n useExtendedPBR =\n pbrMaterial.specularColorMapEnabled != 0 ||\n pbrMaterial.specularIntensityMapEnabled != 0 ||\n abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||\n maxComponent(abs(pbrMaterial.specularColorFactor - vec3f(1.0))) > 0.0001 ||\n abs(pbrMaterial.ior - 1.5) > 0.0001 ||\n pbrMaterial.dispersion > 0.0001 ||\n pbrMaterial.transmissionMapEnabled != 0 ||\n pbrMaterial.transmissionFactor > 0.0001 ||\n pbrMaterial.diffuseTransmissionMapEnabled != 0 ||\n pbrMaterial.diffuseTransmissionColorMapEnabled != 0 ||\n pbrMaterial.diffuseTransmissionFactor > 0.0001 ||\n pbrMaterial.multiscatterColorMapEnabled != 0 ||\n maxComponent(pbrMaterial.multiscatterColorFactor) > 0.0001 ||\n pbrMaterial.clearcoatMapEnabled != 0 ||\n pbrMaterial.clearcoatRoughnessMapEnabled != 0 ||\n pbrMaterial.clearcoatFactor > 0.0001 ||\n pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||\n pbrMaterial.sheenColorMapEnabled != 0 ||\n pbrMaterial.sheenRoughnessMapEnabled != 0 ||\n maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||\n pbrMaterial.sheenRoughnessFactor > 0.0001 ||\n pbrMaterial.iridescenceMapEnabled != 0 ||\n pbrMaterial.iridescenceFactor > 0.0001 ||\n abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||\n abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||\n abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||\n pbrMaterial.anisotropyMapEnabled != 0 ||\n pbrMaterial.anisotropyStrength > 0.0001 ||\n abs(pbrMaterial.anisotropyRotation) > 0.0001 ||\n length(pbrMaterial.anisotropyDirection - vec2f(1.0, 0.0)) > 0.0001;\n #endif\n\n if (!useExtendedPBR) {\n let alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n let f0 = vec3<f32>(0.04);\n var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n let specularColor = mix(f0, baseColor.rgb, metallic);\n\n let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n let specularEnvironmentR0 = specularColor;\n let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;\n let reflection = -normalize(reflect(v, n));\n\n var pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v,\n n,\n n\n );\n\n #ifdef USE_LIGHTS\n PBRInfo_setAmbientLight(&pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting.ambientColor);\n\n for (var i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);\n }\n }\n\n for (var i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));\n let attenuation = getPointLightAttenuation(\n lighting_getPointLight(i),\n distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)\n );\n color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);\n }\n }\n\n for (var i = 0; i < lighting.spotLightCount; i++) {\n if (i < lighting.spotLightCount) {\n PBRInfo_setSpotLight(&pbrInfo, lighting_getSpotLight(i));\n let attenuation = getSpotLightAttenuation(\n lighting_getSpotLight(i),\n fragmentInputs.pbr_vPosition\n );\n color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);\n }\n }\n #endif\n\n #ifdef USE_IBL\n if (pbrMaterial.IBLenabled != 0) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n #endif\n\n #ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled != 0) {\n let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n #endif\n\n var emissive = pbrMaterial.emissiveFactor;\n #ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled != 0u) {\n emissive *= SRGBtoLINEAR(\n textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, emissiveUV)\n ).rgb;\n }\n #endif\n color += emissive * pbrMaterial.emissiveStrength;\n\n #ifdef PBR_DEBUG\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n #endif\n\n return vec4<f32>(applySceneColorManagement(color), baseColor.a);\n }\n\n var specularIntensity = pbrMaterial.specularIntensityFactor;\n #ifdef HAS_SPECULARINTENSITYMAP\n if (pbrMaterial.specularIntensityMapEnabled != 0) {\n specularIntensity *= textureSample(\n pbr_specularIntensitySampler,\n pbr_specularIntensitySamplerSampler,\n specularIntensityUV\n ).a;\n }\n #endif\n\n var specularFactor = pbrMaterial.specularColorFactor;\n #ifdef HAS_SPECULARCOLORMAP\n if (pbrMaterial.specularColorMapEnabled != 0) {\n specularFactor *= SRGBtoLINEAR(\n textureSample(\n pbr_specularColorSampler,\n pbr_specularColorSamplerSampler,\n specularColorUV\n )\n ).rgb;\n }\n #endif\n\n transmission = pbrMaterial.transmissionFactor;\n #ifdef HAS_TRANSMISSIONMAP\n if (pbrMaterial.transmissionMapEnabled != 0) {\n transmission *= textureSample(\n pbr_transmissionSampler,\n pbr_transmissionSamplerSampler,\n transmissionUV\n ).r;\n }\n #endif\n transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);\n var thickness = max(pbrMaterial.thicknessFactor, 0.0);\n #ifdef HAS_THICKNESSMAP\n thickness *= textureSample(\n pbr_thicknessSampler,\n pbr_thicknessSamplerSampler,\n thicknessUV\n ).g;\n #endif\n\n var diffuseTransmission = clamp(pbrMaterial.diffuseTransmissionFactor, 0.0, 1.0);\n #ifdef HAS_DIFFUSETRANSMISSIONMAP\n if (pbrMaterial.diffuseTransmissionMapEnabled != 0) {\n diffuseTransmission *= textureSample(\n pbr_diffuseTransmissionSampler,\n pbr_diffuseTransmissionSamplerSampler,\n diffuseTransmissionUV\n ).a;\n }\n #endif\n diffuseTransmission *= (1.0 - metallic) * (1.0 - transmission);\n var diffuseTransmissionColor = pbrMaterial.diffuseTransmissionColorFactor;\n #ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP\n if (pbrMaterial.diffuseTransmissionColorMapEnabled != 0) {\n diffuseTransmissionColor *= SRGBtoLINEAR(\n textureSample(\n pbr_diffuseTransmissionColorSampler,\n pbr_diffuseTransmissionColorSamplerSampler,\n diffuseTransmissionColorUV\n )\n ).rgb;\n }\n #endif\n var multiscatterColor = pbrMaterial.multiscatterColorFactor;\n #ifdef HAS_MULTISCATTERCOLORMAP\n if (pbrMaterial.multiscatterColorMapEnabled != 0) {\n multiscatterColor *= SRGBtoLINEAR(\n textureSample(\n pbr_multiscatterColorSampler,\n pbr_multiscatterColorSamplerSampler,\n multiscatterColorUV\n )\n ).rgb;\n }\n #endif\n\n var clearcoatFactor = pbrMaterial.clearcoatFactor;\n var clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;\n #ifdef HAS_CLEARCOATMAP\n if (pbrMaterial.clearcoatMapEnabled != 0) {\n clearcoatFactor *= textureSample(\n pbr_clearcoatSampler,\n pbr_clearcoatSamplerSampler,\n clearcoatUV\n ).r;\n }\n #endif\n #ifdef HAS_CLEARCOATROUGHNESSMAP\n if (pbrMaterial.clearcoatRoughnessMapEnabled != 0) {\n clearcoatRoughness *= textureSample(\n pbr_clearcoatRoughnessSampler,\n pbr_clearcoatRoughnessSamplerSampler,\n clearcoatRoughnessUV\n ).g;\n }\n #endif\n clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);\n clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);\n let clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);\n clearcoatRoughness = widenSpecularRoughness(clearcoatRoughness, clearcoatNormal);\n\n var sheenColor = pbrMaterial.sheenColorFactor;\n var sheenRoughness = pbrMaterial.sheenRoughnessFactor;\n #ifdef HAS_SHEENCOLORMAP\n if (pbrMaterial.sheenColorMapEnabled != 0) {\n sheenColor *= SRGBtoLINEAR(\n textureSample(\n pbr_sheenColorSampler,\n pbr_sheenColorSamplerSampler,\n sheenColorUV\n )\n ).rgb;\n }\n #endif\n #ifdef HAS_SHEENROUGHNESSMAP\n if (pbrMaterial.sheenRoughnessMapEnabled != 0) {\n sheenRoughness *= textureSample(\n pbr_sheenRoughnessSampler,\n pbr_sheenRoughnessSamplerSampler,\n sheenRoughnessUV\n ).a;\n }\n #endif\n sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);\n\n var iridescence = pbrMaterial.iridescenceFactor;\n #ifdef HAS_IRIDESCENCEMAP\n if (pbrMaterial.iridescenceMapEnabled != 0) {\n iridescence *= textureSample(\n pbr_iridescenceSampler,\n pbr_iridescenceSamplerSampler,\n iridescenceUV\n ).r;\n }\n #endif\n iridescence = clamp(iridescence, 0.0, 1.0);\n var iridescenceThickness = mix(\n pbrMaterial.iridescenceThicknessRange.x,\n pbrMaterial.iridescenceThicknessRange.y,\n 0.5\n );\n #ifdef HAS_IRIDESCENCETHICKNESSMAP\n iridescenceThickness = mix(\n pbrMaterial.iridescenceThicknessRange.x,\n pbrMaterial.iridescenceThicknessRange.y,\n textureSample(\n pbr_iridescenceThicknessSampler,\n pbr_iridescenceThicknessSamplerSampler,\n iridescenceThicknessUV\n ).g\n );\n #endif\n\n var anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);\n var anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);\n #ifdef HAS_ANISOTROPYMAP\n if (pbrMaterial.anisotropyMapEnabled != 0) {\n let anisotropySample = textureSample(\n pbr_anisotropySampler,\n pbr_anisotropySamplerSampler,\n anisotropyUV\n ).rgb;\n anisotropyStrength *= anisotropySample.b;\n let mappedDirection = anisotropySample.rg * 2.0 - 1.0;\n if (length(mappedDirection) > 0.0001) {\n anisotropyDirection = normalize(mappedDirection);\n }\n }\n #endif\n anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);\n var anisotropyTangent =\n normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);\n if (length(anisotropyTangent) < 0.0001) {\n anisotropyTangent = normalize(tbn[0]);\n }\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n let alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n let dielectricF0 = getDielectricF0(pbrMaterial.ior);\n var dielectricSpecularF0 = min(\n vec3f(dielectricF0) * specularFactor * specularIntensity,\n vec3f(1.0)\n );\n dielectricSpecularF0 = getIridescenceTint(\n iridescence,\n iridescenceThickness,\n NdotV,\n dielectricSpecularF0\n );\n var diffuseColor = baseColor.rgb * (vec3f(1.0) - dielectricSpecularF0);\n diffuseColor *= (1.0 - metallic) * (1.0 - transmission) * (1.0 - diffuseTransmission);\n var specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);\n\n let clearcoatViewFresnel = dielectricSchlick(\n 0.04,\n clamp(abs(dot(clearcoatNormal, v)), 0.0, 1.0)\n );\n let sheenDirectionalAlbedo = maxComponent(sheenColor) *\n (0.157 + 0.343 * (1.0 - NdotV)) * (1.0 - sheenRoughness * 0.5);\n let baseLayerEnergy = (1.0 - clearcoatFactor * clearcoatViewFresnel) *\n (1.0 - clamp(sheenDirectionalAlbedo, 0.0, 1.0));\n diffuseColor *= baseLayerEnergy;\n specularColor *= baseLayerEnergy;\n\n // Compute reflectance.\n let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflectance to 0%.\n let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n let specularEnvironmentR0 = specularColor;\n let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;\n let reflection = -normalize(reflect(v, n));\n\n var pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v,\n n,\n n\n );\n\n #ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(&pbrInfo);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting.ambientColor,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n\n // Apply directional light\n for (var i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getDirectionalLight(i).color,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getDirectionalLight(i).color,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n\n // Apply point light\n for (var i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));\n let attenuation = getPointLightAttenuation(\n lighting_getPointLight(i),\n distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)\n );\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getPointLight(i).color / attenuation,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getPointLight(i).color / attenuation,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n\n for (var i = 0; i < lighting.spotLightCount; i++) {\n if (i < lighting.spotLightCount) {\n PBRInfo_setSpotLight(&pbrInfo, lighting_getSpotLight(i));\n let attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), fragmentInputs.pbr_vPosition);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getSpotLight(i).color / attenuation,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getSpotLight(i).color / attenuation,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n #endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n #ifdef USE_IBL\n if (pbrMaterial.IBLenabled != 0) {\n color += getIBLContribution(\n pbrInfo,\n n,\n getAnisotropicReflection(pbrInfo, anisotropyTangent, anisotropyStrength)\n );\n color += calculateClearcoatIBLContribution(\n pbrInfo,\n clearcoatNormal,\n -normalize(reflect(v, clearcoatNormal)),\n clearcoatFactor,\n clearcoatRoughness\n );\n color += calculateDiffuseTransmissionIBL(\n pbrInfo,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;\n }\n #endif\n\n // Apply optional PBR terms for additional (optional) shading\n #ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled != 0) {\n let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n #endif\n\n var emissive = pbrMaterial.emissiveFactor;\n #ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled != 0u) {\n emissive *= SRGBtoLINEAR(\n textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, emissiveUV)\n ).rgb;\n }\n #endif\n color += emissive * pbrMaterial.emissiveStrength;\n\n if (transmission > 0.0) {\n #ifdef USE_TRANSMISSION_FRAMEBUFFER\n let dielectricFresnel = getDielectricF0(pbrMaterial.ior);\n let transmissionFresnel = dielectricFresnel +\n (1.0 - dielectricFresnel) * pow(1.0 - NdotV, 5.0);\n let transmittedColor = getTransmittedSceneColor(\n fragmentInputs.pbr_vPosition,\n n,\n v,\n thickness,\n perceptualRoughness\n );\n color += transmittedColor * getVolumeAttenuation(thickness) *\n transmission * (1.0 - transmissionFresnel);\n #else\n color = mix(color, color * getVolumeAttenuation(thickness), transmission);\n #endif\n }\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n #ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, pbr_scaleFGDSpec.x);\n // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);\n // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);\n // color = mix(color, specContrib, pbr_scaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n #endif\n }\n\n #ifdef USE_TRANSMISSION_FRAMEBUFFER\n let alpha = clamp(baseColor.a, 0.0, 1.0);\n #else\n let alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);\n #endif\n return vec4<f32>(applySceneColorManagement(color), alpha);\n}\n",vs:"out vec3 pbr_vPosition;\nout vec2 pbr_vUV0;\nout vec2 pbr_vUV1;\n\n#ifdef HAS_NORMALS\n# ifdef HAS_TANGENTS\nout mat3 pbr_vTBN;\n# else\nout vec3 pbr_vNormal;\n# endif\n#endif\n\nvoid pbr_setPositionNormalTangentUV(\n vec4 position,\n vec4 normal,\n vec4 tangent,\n vec2 uv0,\n vec2 uv1\n)\n{\n vec4 pos = pbrProjection.modelMatrix * position;\n pbr_vPosition = vec3(pos.xyz) / pos.w;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\n vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));\n vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));\n vec3 bitangentW = cross(normalW, tangentW) * tangent.w;\n pbr_vTBN = mat3(tangentW, bitangentW, normalW);\n#else // HAS_TANGENTS != 1\n pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));\n#endif\n#endif\n\n#ifdef HAS_UV\n pbr_vUV0 = uv0;\n#else\n pbr_vUV0 = vec2(0.,0.);\n#endif\n\n pbr_vUV1 = uv1;\n}\n",fs:"precision highp float;\n\nlayout(std140) uniform pbrMaterialUniforms {\n // Material is unlit\n bool unlit;\n\n // Base color map\n bool baseColorMapEnabled;\n vec4 baseColorFactor;\n\n bool normalMapEnabled; \n float normalScale; // #ifdef HAS_NORMALMAP\n\n bool emissiveMapEnabled;\n vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP\n\n vec2 metallicRoughnessValues;\n bool metallicRoughnessMapEnabled;\n\n bool occlusionMapEnabled;\n float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP\n \n bool alphaCutoffEnabled;\n float alphaCutoff; // #ifdef ALPHA_CUTOFF\n\n vec3 specularColorFactor;\n float specularIntensityFactor;\n bool specularColorMapEnabled;\n bool specularIntensityMapEnabled;\n\n float ior;\n\n float transmissionFactor;\n bool transmissionMapEnabled;\n\n float thicknessFactor;\n float attenuationDistance;\n vec3 attenuationColor;\n\n float clearcoatFactor;\n float clearcoatRoughnessFactor;\n bool clearcoatMapEnabled;\n bool clearcoatRoughnessMapEnabled;\n\n vec3 sheenColorFactor;\n float sheenRoughnessFactor;\n bool sheenColorMapEnabled;\n bool sheenRoughnessMapEnabled;\n\n float iridescenceFactor;\n float iridescenceIor;\n vec2 iridescenceThicknessRange;\n bool iridescenceMapEnabled;\n\n float anisotropyStrength;\n float anisotropyRotation;\n vec2 anisotropyDirection;\n bool anisotropyMapEnabled;\n\n float emissiveStrength;\n float dispersion;\n \n // IBL\n bool IBLenabled;\n vec2 scaleIBLAmbient; // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n vec4 scaleDiffBaseMR;\n vec4 scaleFGDSpec;\n // #endif\n\n int baseColorUVSet;\n mat3 baseColorUVTransform;\n int metallicRoughnessUVSet;\n mat3 metallicRoughnessUVTransform;\n int normalUVSet;\n mat3 normalUVTransform;\n int occlusionUVSet;\n mat3 occlusionUVTransform;\n int emissiveUVSet;\n mat3 emissiveUVTransform;\n int specularColorUVSet;\n mat3 specularColorUVTransform;\n int specularIntensityUVSet;\n mat3 specularIntensityUVTransform;\n int transmissionUVSet;\n mat3 transmissionUVTransform;\n int thicknessUVSet;\n mat3 thicknessUVTransform;\n int clearcoatUVSet;\n mat3 clearcoatUVTransform;\n int clearcoatRoughnessUVSet;\n mat3 clearcoatRoughnessUVTransform;\n int clearcoatNormalUVSet;\n mat3 clearcoatNormalUVTransform;\n int sheenColorUVSet;\n mat3 sheenColorUVTransform;\n int sheenRoughnessUVSet;\n mat3 sheenRoughnessUVTransform;\n int iridescenceUVSet;\n mat3 iridescenceUVTransform;\n int iridescenceThicknessUVSet;\n mat3 iridescenceThicknessUVTransform;\n int anisotropyUVSet;\n mat3 anisotropyUVTransform;\n\n float bumpFactor;\n bool bumpMapEnabled;\n float diffuseTransmissionFactor;\n bool diffuseTransmissionMapEnabled;\n vec3 diffuseTransmissionColorFactor;\n bool diffuseTransmissionColorMapEnabled;\n vec3 multiscatterColorFactor;\n bool multiscatterColorMapEnabled;\n float scatterAnisotropy;\n\n int bumpUVSet;\n mat3 bumpUVTransform;\n int diffuseTransmissionUVSet;\n mat3 diffuseTransmissionUVTransform;\n int diffuseTransmissionColorUVSet;\n mat3 diffuseTransmissionColorUVTransform;\n int multiscatterColorUVSet;\n mat3 multiscatterColorUVTransform;\n} pbrMaterial;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D pbr_baseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D pbr_normalSampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D pbr_emissiveSampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D pbr_metallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D pbr_occlusionSampler;\n#endif\n#ifdef HAS_SPECULARCOLORMAP\nuniform sampler2D pbr_specularColorSampler;\n#endif\n#ifdef HAS_SPECULARINTENSITYMAP\nuniform sampler2D pbr_specularIntensitySampler;\n#endif\n#ifdef HAS_TRANSMISSIONMAP\nuniform sampler2D pbr_transmissionSampler;\n#endif\n#ifdef HAS_THICKNESSMAP\nuniform sampler2D pbr_thicknessSampler;\n#endif\n#ifdef HAS_CLEARCOATMAP\nuniform sampler2D pbr_clearcoatSampler;\n#endif\n#ifdef HAS_CLEARCOATROUGHNESSMAP\nuniform sampler2D pbr_clearcoatRoughnessSampler;\n#endif\n#ifdef HAS_CLEARCOATNORMALMAP\nuniform sampler2D pbr_clearcoatNormalSampler;\n#endif\n#ifdef HAS_SHEENCOLORMAP\nuniform sampler2D pbr_sheenColorSampler;\n#endif\n#ifdef HAS_SHEENROUGHNESSMAP\nuniform sampler2D pbr_sheenRoughnessSampler;\n#endif\n#ifdef HAS_IRIDESCENCEMAP\nuniform sampler2D pbr_iridescenceSampler;\n#endif\n#ifdef HAS_IRIDESCENCETHICKNESSMAP\nuniform sampler2D pbr_iridescenceThicknessSampler;\n#endif\n#ifdef HAS_ANISOTROPYMAP\nuniform sampler2D pbr_anisotropySampler;\n#endif\n#ifdef HAS_BUMPMAP\nuniform sampler2D pbr_bumpSampler;\n#endif\n#ifdef HAS_DIFFUSETRANSMISSIONMAP\nuniform sampler2D pbr_diffuseTransmissionSampler;\n#endif\n#ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP\nuniform sampler2D pbr_diffuseTransmissionColorSampler;\n#endif\n#ifdef HAS_MULTISCATTERCOLORMAP\nuniform sampler2D pbr_multiscatterColorSampler;\n#endif\n// Inputs from vertex shader\n\nin vec3 pbr_vPosition;\nin vec2 pbr_vUV0;\nin vec2 pbr_vUV1;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nin mat3 pbr_vTBN;\n#else\nin vec3 pbr_vNormal;\n#endif\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n float NdotL; // cos angle between normal and light direction\n float NdotV; // cos angle between normal and view direction\n float NdotH; // cos angle between normal and half vector\n float LdotH; // cos angle between light direction and half vector\n float VdotH; // cos angle between view direction and half vector\n float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)\n float metalness; // metallic value at the surface\n vec3 reflectance0; // full reflectance color (normal incidence angle)\n vec3 reflectance90; // reflectance color at grazing angle\n float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])\n vec3 diffuseColor; // color contribution from diffuse lighting\n vec3 specularColor; // color contribution from specular lighting\n vec3 n; // normal at surface point\n vec3 v; // vector from surface point to camera\n vec3 l; // direction from the surface toward the current light\n vec3 h; // half vector between the current light and camera\n};\n\nconst float M_PI = 3.141592653589793;\nconst float c_MinRoughness = 0.04;\n\n// Widen sub-pixel specular lobes using the screen-space normal footprint.\n// This is geometric specular antialiasing: the normal variance is converted\n// into an additional squared perceptual roughness before evaluating BRDFs.\nfloat widenSpecularRoughness(float perceptualRoughness, vec3 normal)\n{\n vec3 normalDerivativeX = dFdx(normal);\n vec3 normalDerivativeY = dFdy(normal);\n float normalVariance =\n dot(normalDerivativeX, normalDerivativeX) +\n dot(normalDerivativeY, normalDerivativeY);\n float kernelRoughnessSquared = min(2.0 * normalVariance, 1.0);\n return clamp(\n sqrt(perceptualRoughness * perceptualRoughness + kernelRoughnessSquared),\n c_MinRoughness,\n 1.0\n );\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor);\n\nvec4 SRGBtoLINEAR(vec4 srgbIn)\n{\n#ifdef MANUAL_SRGB\n#ifdef SRGB_FAST_APPROXIMATION\n vec3 linOut = pow(srgbIn.xyz,vec3(2.2));\n#else // SRGB_FAST_APPROXIMATION\n vec3 bLess = step(vec3(0.04045),srgbIn.xyz);\n vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );\n#endif //SRGB_FAST_APPROXIMATION\n return vec4(linOut,srgbIn.w);;\n#else //MANUAL_SRGB\n return srgbIn;\n#endif //MANUAL_SRGB\n}\n\nvec2 getMaterialUV(int uvSet, mat3 uvTransform)\n{\n vec2 baseUV = uvSet == 1 ? pbr_vUV1 : pbr_vUV0;\n return (uvTransform * vec3(baseUV, 1.0)).xy;\n}\n\n// Build the tangent basis from interpolated attributes or screen-space derivatives.\nmat3 getTBN(vec2 uv)\n{\n#ifndef HAS_TANGENTS\n vec3 pos_dx = dFdx(pbr_vPosition);\n vec3 pos_dy = dFdy(pbr_vPosition);\n vec3 tex_dx = dFdx(vec3(uv, 0.0));\n vec3 tex_dy = dFdy(vec3(uv, 0.0));\n vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);\n\n#ifdef HAS_NORMALS\n vec3 ng = normalize(pbr_vNormal);\n#else\n vec3 ng = cross(pos_dx, pos_dy);\n#endif\n\n t = normalize(t - ng * dot(ng, t));\n vec3 b = normalize(cross(ng, t));\n mat3 tbn = mat3(t, b, ng);\n#else // HAS_TANGENTS\n mat3 tbn = pbr_vTBN;\n#endif\n\n return tbn;\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nvec3 getMappedNormal(sampler2D normalSampler, mat3 tbn, float normalScale, vec2 uv)\n{\n vec3 n = texture(normalSampler, uv).rgb;\n return normalize(tbn * ((2.0 * n - 1.0) * vec3(normalScale, normalScale, 1.0)));\n}\n\nvec3 getNormal(mat3 tbn, vec2 uv)\n{\n#ifdef HAS_NORMALMAP\n vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale, uv);\n#else\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n vec3 n = normalize(tbn[2].xyz);\n#endif\n\n#ifdef HAS_BUMPMAP\n vec2 bumpUV = getMaterialUV(pbrMaterial.bumpUVSet, pbrMaterial.bumpUVTransform);\n vec2 bumpTexelSize = 1.0 / vec2(textureSize(pbr_bumpSampler, 0));\n float bumpHeight = texture(pbr_bumpSampler, bumpUV).r;\n vec2 bumpGradient = vec2(\n texture(pbr_bumpSampler, bumpUV + vec2(bumpTexelSize.x, 0.0)).r - bumpHeight,\n texture(pbr_bumpSampler, bumpUV + vec2(0.0, bumpTexelSize.y)).r - bumpHeight\n );\n n = normalize(n - pbrMaterial.bumpFactor *\n (tbn[0] * bumpGradient.x + tbn[1] * bumpGradient.y));\n#endif\n\n return n;\n}\n\nvec3 getClearcoatNormal(mat3 tbn, vec3 baseNormal, vec2 uv)\n{\n#ifdef HAS_CLEARCOATNORMALMAP\n return getMappedNormal(pbr_clearcoatNormalSampler, tbn, 1.0, uv);\n#else\n return baseNormal;\n#endif\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nvec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)\n{\n#ifdef USE_SCENE_ENVIRONMENT\n float maximumMipLevel = max(pbrScene.environmentMipCount - 1.0, 0.0);\n float rotationSine = sin(pbrScene.environmentRotation);\n float rotationCosine = cos(pbrScene.environmentRotation);\n mat2 environmentRotation = mat2(rotationCosine, rotationSine, -rotationSine, rotationCosine);\n vec3 environmentNormal = vec3(environmentRotation * n.xz, n.y).xzy;\n vec3 environmentReflection = vec3(environmentRotation * reflection.xz, reflection.y).xzy;\n#else\n float maximumMipLevel = 9.0;\n vec3 environmentNormal = n;\n vec3 environmentReflection = reflection;\n#endif\n float lod = pbrInfo.perceptualRoughness * maximumMipLevel;\n // retrieve a scale and bias to F0. See [1], Figure 3\n vec4 brdfSample = texture(pbr_brdfLUT,\n vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness));\n vec4 diffuseSample = texture(pbr_diffuseEnvSampler, environmentNormal);\n\n#ifdef USE_TEX_LOD\n vec4 specularSample = textureLod(pbr_specularEnvSampler, environmentReflection, lod);\n#else\n vec4 specularSample = texture(pbr_specularEnvSampler, environmentReflection);\n#endif\n\n#ifdef USE_SCENE_ENVIRONMENT\n vec3 brdf = brdfSample.rgb;\n vec3 diffuseLight = diffuseSample.rgb;\n vec3 specularLight = specularSample.rgb;\n#else\n vec3 brdf = SRGBtoLINEAR(brdfSample).rgb;\n vec3 diffuseLight = SRGBtoLINEAR(diffuseSample).rgb;\n vec3 specularLight = SRGBtoLINEAR(specularSample).rgb;\n#endif\n\n vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;\n vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);\n\n // For presentation, this allows us to disable IBL terms\n diffuse *= pbrMaterial.scaleIBLAmbient.x;\n specular *= pbrMaterial.scaleIBLAmbient.y;\n\n#ifdef USE_SCENE_ENVIRONMENT\n return (diffuse + specular) * max(pbrScene.environmentIntensity, 0.0);\n#else\n return diffuse + specular;\n#endif\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nvec3 diffuse(PBRInfo pbrInfo)\n{\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nvec3 specularReflection(PBRInfo pbrInfo)\n{\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfloat geometricOcclusion(PBRInfo pbrInfo)\n{\n float NdotL = pbrInfo.NdotL;\n float NdotV = pbrInfo.NdotV;\n float r = pbrInfo.alphaRoughness;\n\n float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfloat microfacetDistribution(PBRInfo pbrInfo)\n{\n float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nfloat maxComponent(vec3 value)\n{\n return max(max(value.r, value.g), value.b);\n}\n\nfloat getDielectricF0(float ior)\n{\n float clampedIor = max(ior, 1.0);\n float ratio = (clampedIor - 1.0) / (clampedIor + 1.0);\n return ratio * ratio;\n}\n\nvec2 normalizeDirection(vec2 direction)\n{\n float directionLength = length(direction);\n return directionLength > 0.0001 ? direction / directionLength : vec2(1.0, 0.0);\n}\n\nvec2 rotateDirection(vec2 direction, float rotation)\n{\n float s = sin(rotation);\n float c = cos(rotation);\n return vec2(direction.x * c - direction.y * s, direction.x * s + direction.y * c);\n}\n\nvec3 encodeLinearSRGB(vec3 linearColor)\n{\n vec3 positiveColor = max(linearColor, vec3(0.0));\n return mix(\n positiveColor * 12.92,\n 1.055 * pow(positiveColor, vec3(1.0 / 2.4)) - 0.055,\n greaterThan(positiveColor, vec3(0.0031308))\n );\n}\n\nvec3 toneMapKhronosPBRNeutral(vec3 color)\n{\n const float startCompression = 0.76;\n float darkestChannel = min(color.r, min(color.g, color.b));\n float offset = darkestChannel < 0.08\n ? darkestChannel - 6.25 * darkestChannel * darkestChannel\n : 0.04;\n color -= vec3(offset);\n\n float peak = maxComponent(color);\n if (peak < startCompression) {\n return color;\n }\n\n float compressionRange = 1.0 - startCompression;\n float compressedPeak = 1.0 - compressionRange * compressionRange /\n (peak + compressionRange - startCompression);\n color *= compressedPeak / max(peak, 0.0001);\n float desaturation = 1.0 - 1.0 / (0.15 * (peak - compressedPeak) + 1.0);\n return mix(color, vec3(compressedPeak), desaturation);\n}\n\nvec3 applySceneColorManagement(vec3 sceneColor)\n{\n#ifdef USE_SCENE_COLOR_MANAGEMENT\n vec3 color = max(sceneColor, vec3(0.0)) * max(pbrScene.exposure, 0.0);\n if (pbrScene.toneMapMode == 1) {\n color /= vec3(1.0) + color;\n } else if (pbrScene.toneMapMode == 2) {\n color = toneMapKhronosPBRNeutral(color);\n } else if (pbrScene.toneMapMode == 3) {\n color = clamp(\n (color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14),\n vec3(0.0),\n vec3(1.0)\n );\n }\n return pbrScene.outputEncoding == 0 ? color : encodeLinearSRGB(color);\n#else\n return pow(max(sceneColor, vec3(0.0)), vec3(1.0 / 2.2));\n#endif\n}\n\nfloat dielectricSchlick(float reflectance, float cosine)\n{\n return reflectance + (1.0 - reflectance) * pow(clamp(1.0 - cosine, 0.0, 1.0), 5.0);\n}\n\nvec3 evaluateIridescenceSensitivity(float opticalPathDifference, vec3 phaseShift)\n{\n float phase = 2.0 * M_PI * opticalPathDifference * 1.0e-9;\n vec3 sensitivity = vec3(5.4856e-13, 4.4201e-13, 5.2481e-13);\n vec3 position = vec3(1.6810e6, 1.7953e6, 2.2084e6);\n vec3 variance = vec3(4.3278e9, 9.3046e9, 6.6121e9);\n vec3 xyz = sensitivity * sqrt(2.0 * M_PI * variance) *\n cos(position * phase + phaseShift) * exp(-phase * phase * variance);\n xyz.x += 9.7470e-14 * sqrt(2.0 * M_PI * 4.5282e9) *\n cos(2.2399e6 * phase + phaseShift.x) * exp(-4.5282e9 * phase * phase);\n xyz /= 1.0685e-7;\n return mat3(\n 3.2404542, -0.9692660, 0.0556434,\n -1.5371385, 1.8760108, -0.2040259,\n -0.4985314, 0.0415560, 1.0572252\n ) * xyz;\n}\n\nvec3 getIridescenceTint(float iridescence, float thickness, float NdotV, vec3 baseReflectance)\n{\n if (iridescence <= 0.0 || thickness <= 0.0) {\n return baseReflectance;\n }\n\n float filmIor = max(pbrMaterial.iridescenceIor, 1.0);\n float sineSquared = (1.0 - NdotV * NdotV) / (filmIor * filmIor);\n float cosineSquared = 1.0 - sineSquared;\n if (cosineSquared <= 0.0) {\n return mix(baseReflectance, vec3(1.0), iridescence);\n }\n float filmCosine = sqrt(cosineSquared);\n float firstInterfaceReflectance = dielectricSchlick(getDielectricF0(filmIor), NdotV);\n float transmittedEnergy = 1.0 - firstInterfaceReflectance;\n\n vec3 baseIor = (vec3(1.0) + sqrt(clamp(baseReflectance, vec3(0.0), vec3(0.9999)))) /\n (vec3(1.0) - sqrt(clamp(baseReflectance, vec3(0.0), vec3(0.9999))));\n vec3 secondInterfaceF0 = (baseIor - vec3(filmIor)) / (baseIor + vec3(filmIor));\n secondInterfaceF0 *= secondInterfaceF0;\n vec3 secondInterfaceReflectance = secondInterfaceF0 +\n (vec3(1.0) - secondInterfaceF0) * pow(1.0 - filmCosine, 5.0);\n vec3 phaseShift = vec3(M_PI);\n phaseShift += mix(vec3(0.0), vec3(M_PI), lessThan(baseIor, vec3(filmIor)));\n float opticalPathDifference = 2.0 * filmIor * thickness * filmCosine;\n vec3 combinedReflectance = clamp(\n firstInterfaceReflectance * secondInterfaceReflectance,\n vec3(0.00001),\n vec3(0.9999)\n );\n vec3 recurringAmplitude = sqrt(combinedReflectance);\n vec3 interfaceResponse = transmittedEnergy * transmittedEnergy * secondInterfaceReflectance /\n (vec3(1.0) - combinedReflectance);\n vec3 reflectedSpectrum = vec3(firstInterfaceReflectance) + interfaceResponse;\n vec3 harmonicAmplitude = interfaceResponse - vec3(transmittedEnergy);\n for (int harmonic = 1; harmonic <= 2; harmonic++) {\n harmonicAmplitude *= recurringAmplitude;\n reflectedSpectrum += harmonicAmplitude * 2.0 * evaluateIridescenceSensitivity(\n float(harmonic) * opticalPathDifference,\n float(harmonic) * phaseShift\n );\n }\n return mix(baseReflectance, clamp(reflectedSpectrum, vec3(0.0), vec3(1.0)), iridescence);\n}\n\nvec3 getVolumeAttenuation(float thickness)\n{\n if (thickness <= 0.0) {\n return vec3(1.0);\n }\n\n vec3 attenuationCoefficient =\n -log(max(pbrMaterial.attenuationColor, vec3(0.0001))) /\n max(pbrMaterial.attenuationDistance, 0.0001);\n return exp(-attenuationCoefficient * thickness);\n}\n\n// KHR_materials_volume_scatter is an active draft. This evaluates a local,\n// thickness-aware single-scattering approximation rather than random walk.\nvec3 getDiffuseTransmissionAttenuation(\n PBRInfo pbrInfo,\n vec3 multiscatterColor,\n float thickness\n)\n{\n vec3 volumeAttenuation = getVolumeAttenuation(thickness);\n float scatteringStrength = maxComponent(multiscatterColor);\n if (thickness <= 0.0 || scatteringStrength <= 0.0001) {\n return volumeAttenuation;\n }\n\n float anisotropy = clamp(pbrMaterial.scatterAnisotropy, -0.95, 0.95);\n float scatteringCosine = clamp(dot(-pbrInfo.v, pbrInfo.l), -1.0, 1.0);\n float phaseDenominator = max(\n 1.0 + anisotropy * anisotropy - 2.0 * anisotropy * scatteringCosine,\n 0.0001\n );\n float phaseWeight = clamp(\n (1.0 - anisotropy * anisotropy) / pow(phaseDenominator, 1.5),\n 0.0,\n 4.0\n );\n float scatteringDepth = thickness / max(pbrMaterial.attenuationDistance, 0.0001);\n float scatteringProbability = 1.0 - exp(-scatteringDepth);\n vec3 scatteringColor = clamp(multiscatterColor, vec3(0.0), vec3(1.0));\n return mix(\n volumeAttenuation,\n volumeAttenuation * mix(vec3(1.0), scatteringColor * phaseWeight, scatteringColor),\n scatteringProbability\n );\n}\n\nvec3 calculateDiffuseTransmissionLight(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 diffuseTransmissionColor,\n float diffuseTransmission,\n vec3 multiscatterColor,\n float thickness\n)\n{\n float oppositeHemisphere = max(dot(-pbrInfo.n, pbrInfo.l), 0.0);\n if (oppositeHemisphere <= 0.0 || diffuseTransmission <= 0.0) {\n return vec3(0.0);\n }\n\n vec3 nonReflectedEnergy = vec3(1.0) - clamp(pbrInfo.reflectance0, vec3(0.0), vec3(1.0));\n vec3 attenuatedColor = getDiffuseTransmissionAttenuation(\n pbrInfo,\n multiscatterColor,\n thickness\n );\n return lightColor * diffuseTransmissionColor * nonReflectedEnergy *\n attenuatedColor * (diffuseTransmission * oppositeHemisphere / M_PI);\n}\n\n#ifdef USE_IBL\nvec3 calculateDiffuseTransmissionIBL(\n PBRInfo pbrInfo,\n vec3 diffuseTransmissionColor,\n float diffuseTransmission,\n vec3 multiscatterColor,\n float thickness\n)\n{\n if (diffuseTransmission <= 0.0) {\n return vec3(0.0);\n }\n\n#ifdef USE_SCENE_ENVIRONMENT\n float rotationSine = sin(pbrScene.environmentRotation);\n float rotationCosine = cos(pbrScene.environmentRotation);\n mat2 environmentRotation = mat2(rotationCosine, rotationSine, -rotationSine, rotationCosine);\n vec3 oppositeNormal = vec3(environmentRotation * -pbrInfo.n.xz, -pbrInfo.n.y).xzy;\n vec3 environmentColor = texture(pbr_diffuseEnvSampler, oppositeNormal).rgb *\n max(pbrScene.environmentIntensity, 0.0);\n#else\n vec3 environmentColor = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, -pbrInfo.n)).rgb;\n#endif\n vec3 nonReflectedEnergy = vec3(1.0) - clamp(pbrInfo.reflectance0, vec3(0.0), vec3(1.0));\n return environmentColor * diffuseTransmissionColor * nonReflectedEnergy *\n getDiffuseTransmissionAttenuation(pbrInfo, multiscatterColor, thickness) *\n diffuseTransmission * pbrMaterial.scaleIBLAmbient.x;\n}\n#endif\n\n#ifdef USE_TRANSMISSION_FRAMEBUFFER\nvec3 sampleTransmittedSceneColor(\n vec3 position,\n vec3 normal,\n vec3 viewDirection,\n float thickness,\n float perceptualRoughness,\n float indexOfRefraction\n)\n{\n vec3 refractionDirection = refract(\n -viewDirection,\n normal,\n 1.0 / max(indexOfRefraction, 1.0)\n );\n vec3 refractedPosition = position + refractionDirection * thickness;\n vec4 clipPosition = pbrScene.projectionMatrix *\n pbrScene.viewMatrix * vec4(refractedPosition, 1.0);\n vec2 textureCoordinate = clipPosition.xy / max(clipPosition.w, 0.0001) * 0.5 + 0.5;\n textureCoordinate = clamp(textureCoordinate, vec2(0.001), vec2(0.999));\n\n vec2 blurRadius = perceptualRoughness * perceptualRoughness * 8.0 /\n max(pbrScene.framebufferSize, vec2(1.0));\n vec3 sceneColor = texture(pbr_transmissionFramebufferSampler, textureCoordinate).rgb * 0.4;\n sceneColor += texture(\n pbr_transmissionFramebufferSampler,\n textureCoordinate + vec2(blurRadius.x, 0.0)\n ).rgb * 0.15;\n sceneColor += texture(\n pbr_transmissionFramebufferSampler,\n textureCoordinate - vec2(blurRadius.x, 0.0)\n ).rgb * 0.15;\n sceneColor += texture(\n pbr_transmissionFramebufferSampler,\n textureCoordinate + vec2(0.0, blurRadius.y)\n ).rgb * 0.15;\n sceneColor += texture(\n pbr_transmissionFramebufferSampler,\n textureCoordinate - vec2(0.0, blurRadius.y)\n ).rgb * 0.15;\n return max(sceneColor, vec3(0.0));\n}\n\nvec3 getTransmittedSceneColor(\n vec3 position,\n vec3 normal,\n vec3 viewDirection,\n float thickness,\n float perceptualRoughness\n)\n{\n if (pbrMaterial.dispersion <= 0.0) {\n return sampleTransmittedSceneColor(\n position,\n normal,\n viewDirection,\n thickness,\n perceptualRoughness,\n pbrMaterial.ior\n );\n }\n\n float halfSpread = (max(pbrMaterial.ior, 1.0) - 1.0) * 0.025 * pbrMaterial.dispersion;\n vec3 indicesOfRefraction = max(\n vec3(pbrMaterial.ior - halfSpread, pbrMaterial.ior, pbrMaterial.ior + halfSpread),\n vec3(1.0)\n );\n return vec3(\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.r\n ).r,\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.g\n ).g,\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.b\n ).b\n );\n}\n#endif\n\nPBRInfo createClearcoatPBRInfo(PBRInfo basePBRInfo, vec3 clearcoatNormal, float clearcoatRoughness)\n{\n float perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n float NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);\n\n return PBRInfo(\n basePBRInfo.NdotL,\n NdotV,\n basePBRInfo.NdotH,\n basePBRInfo.LdotH,\n basePBRInfo.VdotH,\n perceptualRoughness,\n 0.0,\n vec3(0.04),\n vec3(1.0),\n alphaRoughness,\n vec3(0.0),\n vec3(0.04),\n clearcoatNormal,\n basePBRInfo.v,\n basePBRInfo.l,\n basePBRInfo.h\n );\n}\n\nvec3 calculateClearcoatContribution(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 clearcoatNormal,\n float clearcoatFactor,\n float clearcoatRoughness\n) {\n if (clearcoatFactor <= 0.0) {\n return vec3(0.0);\n }\n\n PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);\n return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;\n}\n\n#ifdef USE_IBL\nvec3 calculateClearcoatIBLContribution(\n PBRInfo pbrInfo,\n vec3 clearcoatNormal,\n vec3 reflection,\n float clearcoatFactor,\n float clearcoatRoughness\n) {\n if (clearcoatFactor <= 0.0) {\n return vec3(0.0);\n }\n\n PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);\n return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;\n}\n#endif\n\nvec3 calculateSheenContribution(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 sheenColor,\n float sheenRoughness\n) {\n if (maxComponent(sheenColor) <= 0.0) {\n return vec3(0.0);\n }\n\n float alpha = max(sheenRoughness * sheenRoughness, 0.0001);\n float inverseAlpha = 1.0 / alpha;\n float sineSquared = max(1.0 - pbrInfo.NdotH * pbrInfo.NdotH, 0.0);\n float distribution = (2.0 + inverseAlpha) * pow(sineSquared, inverseAlpha * 0.5) /\n (2.0 * M_PI);\n float visibility = 1.0 / max(\n 4.0 * (pbrInfo.NdotL + pbrInfo.NdotV - pbrInfo.NdotL * pbrInfo.NdotV),\n 0.0001\n );\n return pbrInfo.NdotL * lightColor * sheenColor * distribution * visibility *\n (1.0 - pbrInfo.metalness);\n}\n\nvec3 calculateAnisotropicLightColor(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 anisotropyTangent,\n float anisotropyStrength\n) {\n if (anisotropyStrength <= 0.0) {\n return calculateFinalColor(pbrInfo, lightColor);\n }\n\n vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));\n float tangentRoughness = mix(\n pbrInfo.alphaRoughness,\n 1.0,\n anisotropyStrength * anisotropyStrength\n );\n float bitangentRoughness = clamp(pbrInfo.alphaRoughness, 0.001, 1.0);\n float roughnessProduct = tangentRoughness * bitangentRoughness;\n vec3 distributionVector = vec3(\n bitangentRoughness * dot(anisotropyTangent, pbrInfo.h),\n tangentRoughness * dot(anisotropyBitangent, pbrInfo.h),\n roughnessProduct * pbrInfo.NdotH\n );\n float distributionFactor = roughnessProduct /\n max(dot(distributionVector, distributionVector), 0.000001);\n float distribution = roughnessProduct * distributionFactor * distributionFactor / M_PI;\n float viewMask = pbrInfo.NdotL * length(vec3(\n tangentRoughness * dot(anisotropyTangent, pbrInfo.v),\n bitangentRoughness * dot(anisotropyBitangent, pbrInfo.v),\n pbrInfo.NdotV\n ));\n float lightMask = pbrInfo.NdotV * length(vec3(\n tangentRoughness * dot(anisotropyTangent, pbrInfo.l),\n bitangentRoughness * dot(anisotropyBitangent, pbrInfo.l),\n pbrInfo.NdotL\n ));\n float visibility = clamp(0.5 / max(viewMask + lightMask, 0.000001), 0.0, 1.0);\n vec3 fresnel = specularReflection(pbrInfo);\n vec3 diffuseContribution = (vec3(1.0) - fresnel) * diffuse(pbrInfo);\n return pbrInfo.NdotL * lightColor *\n (diffuseContribution + fresnel * distribution * visibility);\n}\n\nvec3 getAnisotropicReflection(PBRInfo pbrInfo, vec3 anisotropyTangent, float anisotropyStrength)\n{\n if (anisotropyStrength <= 0.0) {\n return -normalize(reflect(pbrInfo.v, pbrInfo.n));\n }\n vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));\n vec3 anisotropicNormal = normalize(cross(anisotropyBitangent, pbrInfo.v));\n anisotropicNormal = normalize(cross(anisotropicNormal, anisotropyBitangent));\n float bend = anisotropyStrength * (1.0 - pbrInfo.perceptualRoughness);\n return -normalize(reflect(pbrInfo.v, normalize(mix(pbrInfo.n, anisotropicNormal, bend))));\n}\n\nvec3 calculateMaterialLightColor(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 clearcoatNormal,\n float clearcoatFactor,\n float clearcoatRoughness,\n vec3 sheenColor,\n float sheenRoughness,\n vec3 anisotropyTangent,\n float anisotropyStrength\n) {\n vec3 color = calculateAnisotropicLightColor(\n pbrInfo,\n lightColor,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateClearcoatContribution(\n pbrInfo,\n lightColor,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness\n );\n color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);\n return color;\n}\n\nvoid PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {\n pbrInfo.NdotL = 1.0;\n pbrInfo.NdotH = 0.0;\n pbrInfo.LdotH = 0.0;\n pbrInfo.VdotH = 1.0;\n pbrInfo.l = pbrInfo.n;\n pbrInfo.h = pbrInfo.n;\n}\n\nvoid PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {\n vec3 n = pbrInfo.n;\n vec3 v = pbrInfo.v;\n vec3 l = normalize(lightDirection); // Vector from surface point to light\n vec3 h = normalize(l+v); // Half vector between both l and v\n\n pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);\n pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);\n pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);\n pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);\n pbrInfo.l = l;\n pbrInfo.h = h;\n}\n\nvoid PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {\n vec3 light_direction = normalize(pointLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nvoid PBRInfo_setSpotLight(inout PBRInfo pbrInfo, SpotLight spotLight) {\n vec3 light_direction = normalize(spotLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {\n // Calculate the shading terms for the microfacet specular shading model\n vec3 F = specularReflection(pbrInfo);\n float G = geometricOcclusion(pbrInfo);\n float D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nvec4 pbr_filterColor(vec4 vertexColor)\n{\n vec2 baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);\n vec2 metallicRoughnessUV = getMaterialUV(\n pbrMaterial.metallicRoughnessUVSet,\n pbrMaterial.metallicRoughnessUVTransform\n );\n vec2 normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);\n vec2 occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);\n vec2 emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);\n vec2 specularColorUV = getMaterialUV(\n pbrMaterial.specularColorUVSet,\n pbrMaterial.specularColorUVTransform\n );\n vec2 specularIntensityUV = getMaterialUV(\n pbrMaterial.specularIntensityUVSet,\n pbrMaterial.specularIntensityUVTransform\n );\n vec2 transmissionUV = getMaterialUV(\n pbrMaterial.transmissionUVSet,\n pbrMaterial.transmissionUVTransform\n );\n vec2 thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);\n vec2 clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);\n vec2 clearcoatRoughnessUV = getMaterialUV(\n pbrMaterial.clearcoatRoughnessUVSet,\n pbrMaterial.clearcoatRoughnessUVTransform\n );\n vec2 clearcoatNormalUV = getMaterialUV(\n pbrMaterial.clearcoatNormalUVSet,\n pbrMaterial.clearcoatNormalUVTransform\n );\n vec2 sheenColorUV = getMaterialUV(\n pbrMaterial.sheenColorUVSet,\n pbrMaterial.sheenColorUVTransform\n );\n vec2 sheenRoughnessUV = getMaterialUV(\n pbrMaterial.sheenRoughnessUVSet,\n pbrMaterial.sheenRoughnessUVTransform\n );\n vec2 iridescenceUV = getMaterialUV(\n pbrMaterial.iridescenceUVSet,\n pbrMaterial.iridescenceUVTransform\n );\n vec2 iridescenceThicknessUV = getMaterialUV(\n pbrMaterial.iridescenceThicknessUVSet,\n pbrMaterial.iridescenceThicknessUVTransform\n );\n vec2 anisotropyUV = getMaterialUV(\n pbrMaterial.anisotropyUVSet,\n pbrMaterial.anisotropyUVTransform\n );\n vec2 diffuseTransmissionUV = getMaterialUV(\n pbrMaterial.diffuseTransmissionUVSet,\n pbrMaterial.diffuseTransmissionUVTransform\n );\n vec2 diffuseTransmissionColorUV = getMaterialUV(\n pbrMaterial.diffuseTransmissionColorUVSet,\n pbrMaterial.diffuseTransmissionColorUVTransform\n );\n vec2 multiscatterColorUV = getMaterialUV(\n pbrMaterial.multiscatterColorUVSet,\n pbrMaterial.multiscatterColorUVTransform\n );\n\n // The albedo may be defined from a base texture or a flat color\n#ifdef HAS_BASECOLORMAP\n vec4 baseColor =\n SRGBtoLINEAR(texture(pbr_baseColorSampler, baseColorUV)) *\n pbrMaterial.baseColorFactor * vertexColor;\n#else\n vec4 baseColor = pbrMaterial.baseColorFactor * vertexColor;\n#endif\n\n#ifdef ALPHA_CUTOFF\n if (baseColor.a < pbrMaterial.alphaCutoff) {\n discard;\n }\n#endif\n\n vec3 color = vec3(0, 0, 0);\n\n float transmission = 0.0;\n\n if(pbrMaterial.unlit){\n color.rgb = baseColor.rgb;\n }\n else{\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;\n float metallic = pbrMaterial.metallicRoughnessValues.x;\n#ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n vec4 mrSample = texture(pbr_metallicRoughnessSampler, metallicRoughnessUV);\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n#endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n mat3 tbn = getTBN(normalUV);\n vec3 n = getNormal(tbn, normalUV); // normal at surface point\n perceptualRoughness = widenSpecularRoughness(perceptualRoughness, n);\n vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera\n float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n#ifdef USE_MATERIAL_EXTENSIONS\n bool useExtendedPBR =\n pbrMaterial.specularColorMapEnabled ||\n pbrMaterial.specularIntensityMapEnabled ||\n abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||\n maxComponent(abs(pbrMaterial.specularColorFactor - vec3(1.0))) > 0.0001 ||\n abs(pbrMaterial.ior - 1.5) > 0.0001 ||\n pbrMaterial.dispersion > 0.0001 ||\n pbrMaterial.transmissionMapEnabled ||\n pbrMaterial.transmissionFactor > 0.0001 ||\n pbrMaterial.diffuseTransmissionMapEnabled ||\n pbrMaterial.diffuseTransmissionColorMapEnabled ||\n pbrMaterial.diffuseTransmissionFactor > 0.0001 ||\n pbrMaterial.multiscatterColorMapEnabled ||\n maxComponent(pbrMaterial.multiscatterColorFactor) > 0.0001 ||\n pbrMaterial.clearcoatMapEnabled ||\n pbrMaterial.clearcoatRoughnessMapEnabled ||\n pbrMaterial.clearcoatFactor > 0.0001 ||\n pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||\n pbrMaterial.sheenColorMapEnabled ||\n pbrMaterial.sheenRoughnessMapEnabled ||\n maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||\n pbrMaterial.sheenRoughnessFactor > 0.0001 ||\n pbrMaterial.iridescenceMapEnabled ||\n pbrMaterial.iridescenceFactor > 0.0001 ||\n abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||\n abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||\n abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||\n pbrMaterial.anisotropyMapEnabled ||\n pbrMaterial.anisotropyStrength > 0.0001 ||\n abs(pbrMaterial.anisotropyRotation) > 0.0001 ||\n length(pbrMaterial.anisotropyDirection - vec2(1.0, 0.0)) > 0.0001;\n#else\n bool useExtendedPBR = false;\n#endif\n\n if (!useExtendedPBR) {\n // Keep the baseline metallic-roughness implementation byte-for-byte equivalent in behavior.\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n vec3 f0 = vec3(0.04);\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v,\n n,\n n\n );\n\n#ifdef USE_LIGHTS\n PBRInfo_setAmbientLight(pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting.ambientColor);\n\n for(int i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);\n }\n }\n\n for(int i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));\n float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));\n color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);\n }\n }\n\n for(int i = 0; i < lighting.spotLightCount; i++) {\n if (i < lighting.spotLightCount) {\n PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));\n float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);\n color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);\n }\n }\n#endif\n\n#ifdef USE_IBL\n if (pbrMaterial.IBLenabled) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n#endif\n\n#ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled) {\n float ao = texture(pbr_occlusionSampler, occlusionUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n#endif\n\n vec3 emissive = pbrMaterial.emissiveFactor;\n#ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled) {\n emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;\n }\n#endif\n color += emissive * pbrMaterial.emissiveStrength;\n\n#ifdef PBR_DEBUG\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n#endif\n\n return vec4(applySceneColorManagement(color), baseColor.a);\n }\n\n float specularIntensity = pbrMaterial.specularIntensityFactor;\n#ifdef HAS_SPECULARINTENSITYMAP\n if (pbrMaterial.specularIntensityMapEnabled) {\n specularIntensity *= texture(pbr_specularIntensitySampler, specularIntensityUV).a;\n }\n#endif\n\n vec3 specularFactor = pbrMaterial.specularColorFactor;\n#ifdef HAS_SPECULARCOLORMAP\n if (pbrMaterial.specularColorMapEnabled) {\n specularFactor *= SRGBtoLINEAR(texture(pbr_specularColorSampler, specularColorUV)).rgb;\n }\n#endif\n\n transmission = pbrMaterial.transmissionFactor;\n#ifdef HAS_TRANSMISSIONMAP\n if (pbrMaterial.transmissionMapEnabled) {\n transmission *= texture(pbr_transmissionSampler, transmissionUV).r;\n }\n#endif\n transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);\n float thickness = max(pbrMaterial.thicknessFactor, 0.0);\n#ifdef HAS_THICKNESSMAP\n thickness *= texture(pbr_thicknessSampler, thicknessUV).g;\n#endif\n\n float diffuseTransmission = clamp(pbrMaterial.diffuseTransmissionFactor, 0.0, 1.0);\n#ifdef HAS_DIFFUSETRANSMISSIONMAP\n if (pbrMaterial.diffuseTransmissionMapEnabled) {\n diffuseTransmission *= texture(pbr_diffuseTransmissionSampler, diffuseTransmissionUV).a;\n }\n#endif\n diffuseTransmission *= (1.0 - metallic) * (1.0 - transmission);\n vec3 diffuseTransmissionColor = pbrMaterial.diffuseTransmissionColorFactor;\n#ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP\n if (pbrMaterial.diffuseTransmissionColorMapEnabled) {\n diffuseTransmissionColor *= SRGBtoLINEAR(\n texture(pbr_diffuseTransmissionColorSampler, diffuseTransmissionColorUV)\n ).rgb;\n }\n#endif\n vec3 multiscatterColor = pbrMaterial.multiscatterColorFactor;\n#ifdef HAS_MULTISCATTERCOLORMAP\n if (pbrMaterial.multiscatterColorMapEnabled) {\n multiscatterColor *= SRGBtoLINEAR(\n texture(pbr_multiscatterColorSampler, multiscatterColorUV)\n ).rgb;\n }\n#endif\n\n float clearcoatFactor = pbrMaterial.clearcoatFactor;\n float clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;\n#ifdef HAS_CLEARCOATMAP\n if (pbrMaterial.clearcoatMapEnabled) {\n clearcoatFactor *= texture(pbr_clearcoatSampler, clearcoatUV).r;\n }\n#endif\n#ifdef HAS_CLEARCOATROUGHNESSMAP\n if (pbrMaterial.clearcoatRoughnessMapEnabled) {\n clearcoatRoughness *= texture(pbr_clearcoatRoughnessSampler, clearcoatRoughnessUV).g;\n }\n#endif\n clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);\n clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);\n vec3 clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);\n clearcoatRoughness = widenSpecularRoughness(clearcoatRoughness, clearcoatNormal);\n\n vec3 sheenColor = pbrMaterial.sheenColorFactor;\n float sheenRoughness = pbrMaterial.sheenRoughnessFactor;\n#ifdef HAS_SHEENCOLORMAP\n if (pbrMaterial.sheenColorMapEnabled) {\n sheenColor *= SRGBtoLINEAR(texture(pbr_sheenColorSampler, sheenColorUV)).rgb;\n }\n#endif\n#ifdef HAS_SHEENROUGHNESSMAP\n if (pbrMaterial.sheenRoughnessMapEnabled) {\n sheenRoughness *= texture(pbr_sheenRoughnessSampler, sheenRoughnessUV).a;\n }\n#endif\n sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);\n\n float iridescence = pbrMaterial.iridescenceFactor;\n#ifdef HAS_IRIDESCENCEMAP\n if (pbrMaterial.iridescenceMapEnabled) {\n iridescence *= texture(pbr_iridescenceSampler, iridescenceUV).r;\n }\n#endif\n iridescence = clamp(iridescence, 0.0, 1.0);\n float iridescenceThickness = mix(\n pbrMaterial.iridescenceThicknessRange.x,\n pbrMaterial.iridescenceThicknessRange.y,\n 0.5\n );\n#ifdef HAS_IRIDESCENCETHICKNESSMAP\n iridescenceThickness = mix(\n pbrMaterial.iridescenceThicknessRange.x,\n pbrMaterial.iridescenceThicknessRange.y,\n texture(pbr_iridescenceThicknessSampler, iridescenceThicknessUV).g\n );\n#endif\n\n float anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);\n vec2 anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);\n#ifdef HAS_ANISOTROPYMAP\n if (pbrMaterial.anisotropyMapEnabled) {\n vec3 anisotropySample = texture(pbr_anisotropySampler, anisotropyUV).rgb;\n anisotropyStrength *= anisotropySample.b;\n vec2 mappedDirection = anisotropySample.rg * 2.0 - 1.0;\n if (length(mappedDirection) > 0.0001) {\n anisotropyDirection = normalize(mappedDirection);\n }\n }\n#endif\n anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);\n vec3 anisotropyTangent = normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);\n if (length(anisotropyTangent) < 0.0001) {\n anisotropyTangent = normalize(tbn[0]);\n }\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n float dielectricF0 = getDielectricF0(pbrMaterial.ior);\n vec3 dielectricSpecularF0 = min(\n vec3(dielectricF0) * specularFactor * specularIntensity,\n vec3(1.0)\n );\n dielectricSpecularF0 = getIridescenceTint(\n iridescence,\n iridescenceThickness,\n NdotV,\n dielectricSpecularF0\n );\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - dielectricSpecularF0);\n diffuseColor *= (1.0 - metallic) * (1.0 - transmission) * (1.0 - diffuseTransmission);\n vec3 specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);\n\n float clearcoatViewFresnel = dielectricSchlick(\n 0.04,\n clamp(abs(dot(clearcoatNormal, v)), 0.0, 1.0)\n );\n float sheenDirectionalAlbedo = maxComponent(sheenColor) *\n (0.157 + 0.343 * (1.0 - NdotV)) * (1.0 - sheenRoughness * 0.5);\n float baseLayerEnergy = (1.0 - clearcoatFactor * clearcoatViewFresnel) *\n (1.0 - clamp(sheenDirectionalAlbedo, 0.0, 1.0));\n diffuseColor *= baseLayerEnergy;\n specularColor *= baseLayerEnergy;\n\n // Compute reflectance.\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflecance to 0%.\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v,\n n,\n n\n );\n\n\n#ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(pbrInfo);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting.ambientColor,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n\n // Apply directional light\n for(int i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getDirectionalLight(i).color,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getDirectionalLight(i).color,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n\n // Apply point light\n for(int i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));\n float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getPointLight(i).color / attenuation,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getPointLight(i).color / attenuation,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n\n for(int i = 0; i < lighting.spotLightCount; i++) {\n if (i < lighting.spotLightCount) {\n PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));\n float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getSpotLight(i).color / attenuation,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getSpotLight(i).color / attenuation,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n#endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n#ifdef USE_IBL\n if (pbrMaterial.IBLenabled) {\n color += getIBLContribution(\n pbrInfo,\n n,\n getAnisotropicReflection(pbrInfo, anisotropyTangent, anisotropyStrength)\n );\n color += calculateClearcoatIBLContribution(\n pbrInfo,\n clearcoatNormal,\n -normalize(reflect(v, clearcoatNormal)),\n clearcoatFactor,\n clearcoatRoughness\n );\n color += calculateDiffuseTransmissionIBL(\n pbrInfo,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;\n }\n#endif\n\n // Apply optional PBR terms for additional (optional) shading\n#ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled) {\n float ao = texture(pbr_occlusionSampler, occlusionUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n#endif\n\n vec3 emissive = pbrMaterial.emissiveFactor;\n#ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled) {\n emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;\n }\n#endif\n color += emissive * pbrMaterial.emissiveStrength;\n\n if (transmission > 0.0) {\n#ifdef USE_TRANSMISSION_FRAMEBUFFER\n float dielectricFresnel = getDielectricF0(pbrMaterial.ior);\n float transmissionFresnel = dielectricFresnel +\n (1.0 - dielectricFresnel) * pow(1.0 - NdotV, 5.0);\n vec3 transmittedColor = getTransmittedSceneColor(\n pbr_vPosition,\n n,\n v,\n thickness,\n perceptualRoughness\n );\n color += transmittedColor * getVolumeAttenuation(thickness) *\n transmission * (1.0 - transmissionFresnel);\n#else\n color = mix(color, color * getVolumeAttenuation(thickness), transmission);\n#endif\n }\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n#ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, pbr_scaleFGDSpec.x);\n // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);\n // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);\n // color = mix(color, specContrib, pbr_scaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n#endif\n\n }\n\n#ifdef USE_TRANSMISSION_FRAMEBUFFER\n float alpha = clamp(baseColor.a, 0.0, 1.0);\n#else\n float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);\n#endif\n return vec4(applySceneColorManagement(color), alpha);\n}\n",defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,HAS_SPECULARCOLORMAP:!1,HAS_SPECULARINTENSITYMAP:!1,HAS_TRANSMISSIONMAP:!1,HAS_THICKNESSMAP:!1,HAS_CLEARCOATMAP:!1,HAS_CLEARCOATROUGHNESSMAP:!1,HAS_CLEARCOATNORMALMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_SHEENROUGHNESSMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_IRIDESCENCETHICKNESSMAP:!1,HAS_ANISOTROPYMAP:!1,HAS_BUMPMAP:!1,HAS_DIFFUSETRANSMISSIONMAP:!1,HAS_DIFFUSETRANSMISSIONCOLORMAP:!1,HAS_MULTISCATTERCOLORMAP:!1,USE_MATERIAL_EXTENSIONS:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:e=>e,uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",specularColorFactor:"vec3<f32>",specularIntensityFactor:"f32",specularColorMapEnabled:"i32",specularIntensityMapEnabled:"i32",ior:"f32",transmissionFactor:"f32",transmissionMapEnabled:"i32",thicknessFactor:"f32",attenuationDistance:"f32",attenuationColor:"vec3<f32>",clearcoatFactor:"f32",clearcoatRoughnessFactor:"f32",clearcoatMapEnabled:"i32",clearcoatRoughnessMapEnabled:"i32",sheenColorFactor:"vec3<f32>",sheenRoughnessFactor:"f32",sheenColorMapEnabled:"i32",sheenRoughnessMapEnabled:"i32",iridescenceFactor:"f32",iridescenceIor:"f32",iridescenceThicknessRange:"vec2<f32>",iridescenceMapEnabled:"i32",anisotropyStrength:"f32",anisotropyRotation:"f32",anisotropyDirection:"vec2<f32>",anisotropyMapEnabled:"i32",emissiveStrength:"f32",dispersion:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>",baseColorUVSet:"i32",baseColorUVTransform:"mat3x3<f32>",metallicRoughnessUVSet:"i32",metallicRoughnessUVTransform:"mat3x3<f32>",normalUVSet:"i32",normalUVTransform:"mat3x3<f32>",occlusionUVSet:"i32",occlusionUVTransform:"mat3x3<f32>",emissiveUVSet:"i32",emissiveUVTransform:"mat3x3<f32>",specularColorUVSet:"i32",specularColorUVTransform:"mat3x3<f32>",specularIntensityUVSet:"i32",specularIntensityUVTransform:"mat3x3<f32>",transmissionUVSet:"i32",transmissionUVTransform:"mat3x3<f32>",thicknessUVSet:"i32",thicknessUVTransform:"mat3x3<f32>",clearcoatUVSet:"i32",clearcoatUVTransform:"mat3x3<f32>",clearcoatRoughnessUVSet:"i32",clearcoatRoughnessUVTransform:"mat3x3<f32>",clearcoatNormalUVSet:"i32",clearcoatNormalUVTransform:"mat3x3<f32>",sheenColorUVSet:"i32",sheenColorUVTransform:"mat3x3<f32>",sheenRoughnessUVSet:"i32",sheenRoughnessUVTransform:"mat3x3<f32>",iridescenceUVSet:"i32",iridescenceUVTransform:"mat3x3<f32>",iridescenceThicknessUVSet:"i32",iridescenceThicknessUVTransform:"mat3x3<f32>",anisotropyUVSet:"i32",anisotropyUVTransform:"mat3x3<f32>",bumpFactor:"f32",bumpMapEnabled:"i32",diffuseTransmissionFactor:"f32",diffuseTransmissionMapEnabled:"i32",diffuseTransmissionColorFactor:"vec3<f32>",diffuseTransmissionColorMapEnabled:"i32",multiscatterColorFactor:"vec3<f32>",multiscatterColorMapEnabled:"i32",scatterAnisotropy:"f32",bumpUVSet:"i32",bumpUVTransform:"mat3x3<f32>",diffuseTransmissionUVSet:"i32",diffuseTransmissionUVTransform:"mat3x3<f32>",diffuseTransmissionColorUVSet:"i32",diffuseTransmissionColorUVTransform:"mat3x3<f32>",multiscatterColorUVSet:"i32",multiscatterColorUVTransform:"mat3x3<f32>"}},Lt=class{name;playing=!0;speed=1;startTime=0;constructor(e={}){this.name=e.name||"unnamed",Object.assign(this,e)}setTime(e){if(!this.playing)return;const t=(e/1e3-this.startTime)*this.speed;this.applyTime(t)}},Bt=class{clips;animations;constructor(e){this.clips=e,this.animations=e}animate(e){$e.warn(`${this.constructor.name}#animate is deprecated. Use ${this.constructor.name}#setTime instead`)(),this.setTime(e)}setTime(e){this.clips.forEach(t=>t.setTime(e))}getAnimations(){return this.clips}};function Ot(e,t,n){const r=Dt(e),i=Dt(t);let a=r.reduce((e,t,n)=>e+t*i[n],0);const s=a<0?-1:1;if(a=Math.min(Math.abs(a),1),a>.9995)return Dt(r.map((e,t)=>e+n*(i[t]*s-e)));const o=Math.acos(a),A=Math.sin(o),l=Math.sin((1-n)*o)/A,c=Math.sin(n*o)/A*s;return Dt(r.map((e,t)=>e*l+i[t]*c))}function Ft(e,t,n,r){const i=e["CUBICSPLINE"===t?3*n+1:n];return i?"quaternion"===r?Dt(i):[...i]:null}function Dt(e){const t=Math.hypot(...e);return t>0?e.map(e=>e/t):[0,0,0,1]}var Ut=class{name;times;values;interpolation;valueType;binding;constructor(e){this.name=e.name||e.binding.id||"unnamed",this.times=e.times,this.values=e.values,this.interpolation=e.interpolation||"LINEAR",this.valueType=e.valueType||"vector",this.binding=e.binding}get duration(){return this.times[this.times.length-1]||0}get sampler(){return{input:this.times,output:this.values,interpolation:this.interpolation}}evaluate(e){return function(e,t,n="vector"){const{input:r,output:i,interpolation:a="LINEAR"}=t;if(!r.length||!i.length||!Number.isFinite(e))return null;const s=r.length-1;if(e<=r[0]||0===s)return Ft(i,a,0,n);if(e>=r[s])return Ft(i,a,s,n);let o=0,A=s;for(;A-o>1;){const t=Math.floor((o+A)/2);r[t]<=e?o=t:A=t}const l=r[o],c=r[A]-l;if(c<=0||"STEP"===a)return Ft(i,a,o,n);const u=(e-l)/c;switch(a){case"LINEAR":{const e=i[o],t=i[A];return e&&t?"quaternion"===n?Ot(e,t,u):function(e,t,n){return e.map((e,r)=>(1-n)*e+n*t[r])}(e,t,u):null}case"CUBICSPLINE":{const e=i[3*o+1],t=i[3*o+2],r=i[3*A],a=i[3*A+1];if(!(e&&t&&r&&a))return null;const s=function(e,t,n,r,i,a){const s=a*a,o=s*a;return e.map((e,A)=>(2*o-3*s+1)*e+(o-2*s+a)*t[A]*i+(-2*o+3*s)*r[A]+(o-s)*n[A]*i)}(e,t,r,a,c,u);return"quaternion"===n?Dt(s):s}default:return null}}(e,this.sampler,this.valueType)}},Vt=class{name;tracks;duration;constructor(e){this.name=e.name||"unnamed",this.tracks=e.tracks,this.duration=e.duration??Math.max(0,...e.tracks.map(e=>e.duration))}},jt=class{clip;mixer;time=0;timeScale;weight;loop;repetitions;paused=!1;playing=!1;elapsedTime=0;fade=null;constructor(e,t,n={}){this.mixer=e,this.clip=t,this.loop=n.loop||"repeat",this.repetitions=n.repetitions??Number.POSITIVE_INFINITY,this.timeScale=n.timeScale??1,this.weight=n.weight??1}play(){return this.playing=!0,this.paused=!1,this}pause(){return this.paused=!0,this}resume(){return this.playing=!0,this.paused=!1,this}stop(){return this.playing=!1,this.paused=!1,this.fade=null,this.reset()}reset(){return this.elapsedTime=0,this.time=0,this}setTime(e){return this.elapsedTime=e,this.time=this.resolveLocalTime(e),this}setLoop(e,t=Number.POSITIVE_INFINITY){return this.loop=e,this.repetitions=t,this.time=this.resolveLocalTime(this.elapsedTime),this}setEffectiveWeight(e){return this.weight=Math.max(0,e),this.fade=null,this}setEffectiveTimeScale(e){return this.timeScale=e,this}fadeIn(e){return this.scheduleFade(1,e)}fadeOut(e){return this.scheduleFade(0,e)}crossFadeTo(e,t){return e.weight=0,e.play().fadeIn(t),this.fadeOut(t)}crossFadeFrom(e,t){return e.crossFadeTo(this,t),this}advance(e){this.playing&&!this.paused&&(this.advanceFade(Math.abs(e)),this.elapsedTime+=e*this.timeScale,this.time=this.resolveLocalTime(this.elapsedTime),this.hasFinished()&&(this.playing=!1))}get shouldApply(){return(this.playing||this.hasFinished())&&this.weight>0}scheduleFade(e,t){return t<=0?(this.weight=e,this.fade=null,this):(this.fade={duration:t,elapsedTime:0,startWeight:this.weight,endWeight:e},this)}advanceFade(e){if(!this.fade)return;this.fade.elapsedTime+=e;const t=Math.min(this.fade.elapsedTime/this.fade.duration,1);this.weight=this.fade.startWeight+(this.fade.endWeight-this.fade.startWeight)*t,1===t&&(this.fade=null)}hasFinished(){const e=this.clip.duration;return e<=0?"once"===this.loop:"once"===this.loop?this.elapsedTime>=e||this.elapsedTime<0:Number.isFinite(this.repetitions)&&Math.abs(this.elapsedTime)>=e*this.repetitions}resolveLocalTime(e){const t=this.clip.duration;if(t<=0)return 0;if("once"===this.loop)return Math.min(Math.max(e,0),t);if(Number.isFinite(this.repetitions)&&Math.abs(e)>=t*this.repetitions)return"ping-pong"===this.loop&&this.repetitions%2==0||e<0?0:t;const n=e>=0&&e<t?e:(e%t+t)%t;if("repeat"===this.loop)return n;const r=Math.floor(e/t);return 0===Math.abs(r%2)?n:t-n}},zt=class{time=0;timeScale=1;clips=/* @__PURE__ */new Map;actions=/* @__PURE__ */new Map;initialValues=/* @__PURE__ */new Map;constructor(e=[]){e.forEach(e=>this.addClip(e))}addClip(e){return this.clips.set(e.name,e),this}clipAction(e,t){const n="string"==typeof e?this.clips.get(e):e;if(!n)throw new Error(`Unknown animation clip: ${e}`);this.addClip(n);let r=this.actions.get(n);return r||(r=new jt(this,n,t),this.actions.set(n,r)),r}getAction(e){const t=this.clips.get(e);return t?this.actions.get(t):void 0}update(e){return this.advance(e),this.applyValues(),this}advance(e){const t=e*this.timeScale;return this.time+=t,this.actions.forEach(e=>e.advance(t)),this}setTime(e){return this.time=e,this.actions.forEach(t=>{t.paused||t.setTime(e*t.timeScale)}),this.applyValues(),this}stopAllAction(){return this.actions.forEach(e=>e.stop()),this}applyValues(){const e=/* @__PURE__ */new Map;this.actions.forEach(t=>{(t.shouldApply||t.playing&&0===t.weight)&&t.clip.tracks.forEach(n=>{const r=n.evaluate(t.time);if(!r)return;const i=n.binding.id||n.binding;if(!this.initialValues.has(i)){const e=n.binding.getValue?.();e&&this.initialValues.set(i,[...e])}if(0===t.weight&&!this.initialValues.has(i))return;const a=e.get(i);if(!a)return void e.set(i,{binding:n.binding,value:[...r],valueType:n.valueType,weight:t.weight});if(0===t.weight)return;const s=a.weight+t.weight,o=t.weight/s;a.value="quaternion"===n.valueType?Ot(a.value,r,o):a.value.map((e,t)=>e+(r[t]-e)*o),a.weight=s})}),e.forEach(({binding:e,value:t,valueType:n,weight:r},i)=>{const a=r<1?this.initialValues.get(i):void 0;a&&a.length===t.length&&(t="quaternion"===n?Ot(a,t,r):t.map((e,t)=>a[t]+(e-a[t])*r)),e.setValue(t)})}};function Gt(e){const t=e.value;if(t instanceof Float32Array)return t;const n=new Float32Array(t.length),r=Qt(t),i=t instanceof Int8Array||t instanceof Int16Array||t instanceof Int32Array;for(let a=0;a<t.length;a++){const s=Number(t[a]);n[a]=e.normalized&&r?i?Math.max(s/r,-1):s/r:s}return n}function Ht(e,t,n,r){const i={};for(const c of["POSITION","NORMAL","TANGENT"]){const e=t.attributes[c];e&&(i[c]=Gt(e))}const a=function(e,t,n){const r={};for(const i of["POSITION","NORMAL","TANGENT"]){const a=e[i];if(!a)continue;const s=new Float32Array(a),o="TANGENT"===i?4:3,A=Math.floor(a.length/o);for(let e=0;e<Math.min(t.length,n.length);e++){const r=n[e],a=t[e][i];if(!r||!a)continue;const l="TANGENT"===i&&a.length===4*A?4:3;for(let e=0;e<A;e++){const t=e*o,n=e*l;for(let e=0;e<3;e++)s[t+e]+=(a[n+e]||0)*r}}"POSITION"!==i&&Kt(s,o),r[i]=s}return r}(i,n,r),s={};for(const[c,u]of Object.entries(t.attributes))u&&(s[c]=u);for(const c of["POSITION","NORMAL","TANGENT"]){const e=a[c],t=s[c];e&&t&&(s[c]={...t,value:qt(t,e)})}const o=new E({id:t.id,topology:t.topology||"triangle-list",vertexCount:t.vertexCount,indices:t.indices,attributes:s,bufferLayout:t.bufferLayout}),A=T(o).attributes.geometry?.value,l=e._gpuGeometry?.attributes.geometry||e.bufferAttributes.geometry;if(A&&l)l.write(A);else for(const c of["POSITION","NORMAL","TANGENT"]){const t=a[c];if(t){const n="POSITION"===c?"positions":"NORMAL"===c?"normals":"TANGENT";e.bufferAttributes[n]?.write(t)}}}function qt(e,t){if(e.value instanceof Float32Array)return t;const n=e.value.slice(),r=Qt(n),i=n instanceof Int8Array||n instanceof Int16Array||n instanceof Int32Array;for(let a=0;a<t.length;a++){const s=t[a];n[a]=e.normalized&&r?Math.round(Math.max(i?-1:0,Math.min(1,s))*r):s}return n}function Qt(e){return e instanceof Int8Array?127:e instanceof Uint8Array||e instanceof Uint8ClampedArray?255:e instanceof Int16Array?32767:e instanceof Uint16Array?65535:e instanceof Int32Array?2147483647:e instanceof Uint32Array?4294967295:0}function Kt(e,t){for(let n=0;n<e.length;n+=t){const t=Math.hypot(e[n],e[n+1],e[n+2]);t>0&&(e[n]/=t,e[n+1]/=t,e[n+2]/=t)}}function Wt(e){const{joints:t,meshNode:n,worldMatrices:r,inverseBindMatrices:i,target:a}=e,s=t.length,o=a&&a.length===16*s?a:new Float32Array(16*s),A=n?r.get(n)||n.matrix:void 0,l=A?new H(A).invert():null;for(let c=0;c<s;c++){const e=t[c],n=r.get(e)||e.matrix,a=l?new H(l).multiplyRight(n):new H(n),s=16*c;if(i&&i.length>=s+16){const e=new H;for(let t=0;t<16;t++)e[t]=i[s+t];a.multiplyRight(e)}o.set(a,s)}return o}var Jt=class{device;modules;_materialBindingNames;_materialModuleNames;constructor(e,t={}){this.device=e,this.modules=t.modules||[];const n=new Ge(Object.fromEntries(this.modules.map(e=>[e.name,e])));this._materialBindingNames=function(e){const t=/* @__PURE__ */new Set;for(const n of Object.values(e.modules))for(const e of n.bindingLayout||[])3===e.group&&t.add(e.name);return t}(n),this._materialModuleNames=function(e){const t=/* @__PURE__ */new Set;for(const n of Object.values(e.modules))n.name&&n.bindingLayout?.some(e=>3===e.group&&e.name===n.name)&&t.add(n.name);return t}(n)}createMaterial(e={}){return new Xt(this.device,{...e,factory:this})}getBindingNames(){return Array.from(this._materialBindingNames)}ownsBinding(e){if(this._materialBindingNames.has(e))return!0;const t=$t(e);return!!t&&this._materialModuleNames.has(t)}ownsModule(e){return this._materialModuleNames.has(e)}getBindingsByGroup(e){return Object.keys(e).length>0?{3:e}:{}}};function $t(e){return e.endsWith("Uniforms")?e.slice(0,-8):null}var Xt=class{id;device;factory;shaderInputs;bindings={};_uniformStore;_bindGroupCacheToken={};_dynamicResourceGenerations={};constructor(e,t={}){this.id=t.id||Ve("material"),this.device=e,this.factory=t.factory||new Jt(e,{modules:t.modules||t.shaderInputs?.getModules()||[]});const n=Object.fromEntries((t.shaderInputs?.getModules()||this.factory.modules).map(e=>[e.name,e]));this.shaderInputs=t.shaderInputs||new Ge(n),this._uniformStore=new je(this.device,this.shaderInputs.modules);for(const[r,i]of Object.entries(this.shaderInputs.modules))if(this.ownsModule(r)&&He(i)){const e=this._uniformStore.getManagedUniformBuffer(r);this.bindings[`${r}Uniforms`]=e}this.updateShaderInputs(),t.bindings&&this._replaceOwnedBindings(t.bindings)}destroy(){this._uniformStore.destroy()}clone(e={}){const t=this.factory.createMaterial({id:e.id,shaderInputs:e.shaderInputs,bindings:{...this.getResourceBindings(),...e.bindings}});return e.shaderInputs||t.setProps(this.shaderInputs.getUniformValues()),e.moduleProps&&t.setProps(e.moduleProps),t.updateShaderInputs(),t}ownsBinding(e){return this.factory.ownsBinding(e)}ownsModule(e){return this.factory.ownsModule(e)}setProps(e){this.shaderInputs.setProps(e)}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e),this._setOwnedBindings(this.shaderInputs.getBindingValues())&&(this._bindGroupCacheToken={})}getResourceBindings(){const e={};for(const[t,n]of Object.entries(this.bindings))$t(t)||(e[t]=n);return e}getBindings(e={bindings:[]}){this._syncDynamicResourceGenerations();const t={},n=t;for(const[r,i]of Object.entries(this.bindings))if(A(i)){const t=h(e,r,{fallbackGroup:3}),a=t?i.resolveTextureBinding(t):null;a&&(n[r]=a)}else i instanceof Qe?n[r]=i.buffer:qe(i)?n[r]=Ke(i):n[r]=i;return this._syncDynamicResourceGenerations(),t}getBindingsByGroup(e={bindings:[]}){return this.factory.getBindingsByGroup(this.getBindings(e))}getBindGroupCacheKey(e){return this._syncDynamicResourceGenerations(),3===e?this._bindGroupCacheToken:null}getBindingsUpdateTimestamp(){let e=0;for(const t of Object.values(this.bindings))t instanceof Ye?e=Math.max(e,t.texture.updateTimestamp):t instanceof Xe||t instanceof G||t instanceof a||t instanceof Qe?e=Math.max(e,t.updateTimestamp):A(t)?e=t.isReady?Math.max(e,t.updateTimestamp):1/0:qe(t)&&(e=Math.max(e,(t.buffer,t.buffer.updateTimestamp)));return e}_replaceOwnedBindings(e){this._setOwnedBindings(e)&&(this._bindGroupCacheToken={})}_setOwnedBindings(e){let t=!1;for(const[n,r]of Object.entries(e))void 0!==r&&this.ownsBinding(n)&&this.bindings[n]!==r&&(this.bindings[n]=r,t=!0);return t}_syncDynamicResourceGenerations(){const e={};let t=!1;for(const[n,r]of Object.entries(this.bindings)){const i=Yt(r);null!==i&&(e[n]=i,this._dynamicResourceGenerations[n]!==i&&(t=!0))}Object.keys(e).length!==Object.keys(this._dynamicResourceGenerations).length&&(t=!0),this._dynamicResourceGenerations=e,t&&(this._bindGroupCacheToken={})}};function Yt(e){return A(e)?e.generation:ze(e)?.generation??null}var Zt={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function en(e){return e?Array.isArray(e)?e[0]??null:e:null}function tn(e){if(Q(e))return K(e);if("object"==typeof e&&"width"in e&&"height"in e)return{width:e.width,height:e.height};throw new Error("Unsupported mip-level data")}function nn(e){return"object"==typeof e&&null!==e&&"data"in e&&"width"in e&&"height"in e}function rn(e){return ArrayBuffer.isView(e)}function an(e){const{textureFormat:t,format:n}=e;if(t&&n&&t!==n)throw new Error(`Conflicting texture formats "${t}" and "${n}" provided for the same mip level`);return t??n}function sn(e){const t=Zt[e];if(void 0===t)throw new Error(`Invalid cube face: ${e}`);return t}function on(e,t){return 6*e+sn(t)}function An(e){throw new Error("setTexture1DData not supported in WebGL.")}function ln(e,t,n,r){const i=(a=t,Array.isArray(a)?a:[a]);var a;const s=e,o=[];for(let A=0;A<i.length;A++){const e=i[A];if(Q(e))o.push({type:"external-image",image:e,z:s,mipLevel:A});else if(nn(e))o.push({type:"texture-data",data:e,textureFormat:an(e),z:s,mipLevel:A});else{if(!rn(e)||!n)throw new Error("Unsupported 2D mip-level payload");o.push({type:"texture-data",data:{data:e,width:Math.max(1,n.width>>A),height:Math.max(1,n.height>>A),...r?{format:r}:{}},textureFormat:r,z:s,mipLevel:A})}}return o}function cn(e){const t=[];for(let n=0;n<e.length;n++)t.push(...ln(n,e[n]));return t}function un(e){const t=[];for(let n=0;n<e.length;n++)t.push(...ln(n,e[n]));return t}function fn(e){const t=[];for(const[n,r]of Object.entries(e)){const e=sn(n);t.push(...ln(e,r))}return t}function dn(e){const t=[];return e.forEach((e,n)=>{for(const[r,i]of Object.entries(e)){const e=on(n,r);t.push(...ln(e,i))}}),t}var hn=class e{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;generation=0;updateTimestamp;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error("Texture not initialized yet");return this._texture}get sampler(){if(!this._sampler)throw new Error("Sampler not initialized yet");return this._sampler}get view(){if(!this._view)throw new Error("View not initialized yet");return this._view}get[Symbol.toStringTag](){return"DynamicTexture"}toString(){const e=this._texture?.width??this.props.width??"?",t=this._texture?.height??this.props.height??"?";return`DynamicTexture:"${this.id}":${e}x${t}px:(${this.isReady?"ready":"loading..."})`}resolveTextureBinding(e){return this.isReady?this.texture:null}constructor(t,n){this.device=t;const r=Ve("dynamic-texture"),i=n;this.props={...e.defaultProps,id:r,...n,data:null},this.id=this.props.id,this.ready=new Promise((e,t)=>{this.resolveReady=e,this.rejectReady=t}),this.updateTimestamp=this.device.incrementTimestamp(),this.initAsync(i)}async initAsync(e){try{const t=await this._loadAllData(e);this._checkNotDestroyed();const n=t.data?function(e){if(!e.data)return[];const t=e.width&&e.height?{width:e.width,height:e.height}:void 0,n="format"in e?e.format:void 0;switch(e.dimension){case"1d":return An(e.data);case"2d":return ln(0,e.data,t,n);case"3d":return cn(e.data);case"2d-array":return un(e.data);case"cube":return fn(e.data);case"cube-array":return dn(e.data);default:throw new Error(`Unhandled dimension ${e.dimension}`)}}({...t,width:e.width,height:e.height,format:e.format}):[],r="format"in e&&void 0!==e.format,i="usage"in e&&void 0!==e.usage,a=()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};const e=function(e){const{dimension:t,data:n}=e;if(!n)return null;switch(t){case"1d":{const e=en(n);if(!e)return null;const{width:t}=tn(e);return{width:t,height:1}}case"2d":{if(ArrayBuffer.isView(n))return null;const e=en(n);return e?tn(e):null}case"3d":case"2d-array":{if(!Array.isArray(n)||0===n.length)return null;const e=en(n[0]);return e?tn(e):null}case"cube":{const e=Object.keys(n)[0]??null;if(!e)return null;const t=en(n[e]);return t?tn(t):null}case"cube-array":{if(!Array.isArray(n)||0===n.length)return null;const e=n[0],t=Object.keys(e)[0]??null;if(!t)return null;const r=en(e[t]);return r?tn(r):null}default:return null}}(t);return e||{width:this.props.width||1,height:this.props.height||1}},s=a();if(!s||s.width<=0||s.height<=0)throw new Error(`${this} size could not be determined or was zero`);const o=function(e,t,n,r){if(0===t.length)return{subresources:t,mipLevels:1,format:r.format,hasExplicitMipChain:!1};const i=/* @__PURE__ */new Map;for(const c of t){const e=i.get(c.z)??[];e.push(c),i.set(c.z,e)}const a=t.some(e=>e.mipLevel>0);let s=r.format,o=Number.POSITIVE_INFINITY;const A=[];for(const[c,u]of i){const t=[...u].sort((e,t)=>e.mipLevel-t.mipLevel),r=t[0];if(!r||0!==r.mipLevel)throw new Error(`DynamicTexture: slice ${c} is missing mip level 0`);const i=mn(e,r);if(i.width!==n.width||i.height!==n.height)throw new Error(`DynamicTexture: slice ${c} base level dimensions ${i.width}x${i.height} do not match expected ${n.width}x${n.height}`);const a=pn(r);if(a){if(s&&s!==a)throw new Error(`DynamicTexture: slice ${c} base level format "${a}" does not match texture format "${s}"`);s=a}const l=s&&e.isTextureFormatCompressed(s)?gn(e,i.width,i.height,s):e.getMipLevelCount(i.width,i.height);let f=0;for(let n=0;n<t.length;n++){const r=t[n];if(!r||r.mipLevel!==n)break;if(n>=l)break;const a=mn(e,r),o=Math.max(1,i.width>>n),c=Math.max(1,i.height>>n);if(a.width!==o||a.height!==c)break;const u=pn(r);if(u&&(s||(s=u),u!==s))break;f++,A.push(r)}o=Math.min(o,f)}const l=Number.isFinite(o)?Math.max(1,o):1;return{subresources:A.filter(e=>e.mipLevel<l),mipLevels:l,format:s,hasExplicitMipChain:a}}(this.device,n,s,{format:r?e.format:void 0}),A=o.format??this.props.format,l={...this.props,...s,format:A,mipLevels:1,data:void 0};this.device.isTextureFormatCompressed(A)&&!i&&(l.usage=G.SAMPLE|G.COPY_DST);const c=this.props.mipmaps&&!o.hasExplicitMipChain&&!this.device.isTextureFormatCompressed(A);if("webgpu"===this.device.type&&c){const e="3d"===this.props.dimension?G.SAMPLE|G.STORAGE|G.COPY_DST|G.COPY_SRC:G.SAMPLE|G.RENDER|G.COPY_DST|G.COPY_SRC;l.usage|=e}const u=this.device.getMipLevelCount(l.width,l.height),f=o.hasExplicitMipChain?o.mipLevels:"auto"===this.props.mipLevels?u:Math.max(1,Math.min(u,this.props.mipLevels??1)),d={...l,mipLevels:f};this._texture=this.device.createTexture(d),this._sampler=this.texture.sampler,this._view=this.texture.view,this._touchGeneration(),o.subresources.length&&this._setTextureSubresources(o.subresources),!this.props.mipmaps||o.hasExplicitMipChain||c||$e.warn(`${this} skipping auto-generated mipmaps for compressed texture format`)(),c&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),$e.info(1,`${this} created`)()}catch(Lr){const t=Lr instanceof Error?Lr:new Error(String(Lr));this.rejectReady(t)}}destroy(){this._texture&&(this._texture.destroy(),this._texture=null,this._sampler=null,this._view=null),this.isReady=!1,this.destroyed=!0}generateMipmaps(){"webgl"===this.device.type?(this.texture.generateMipmapsWebGL(),this._touch()):"webgpu"===this.device.type?(this.device.generateMipmapsWebGPU(this.texture),this._touch()):$e.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(e={}){this._checkReady();const t=e instanceof q?e:this.device.createSampler(e);this.texture.setSampler(t),this._sampler=t,this._touchGeneration()}async readBuffer(e={}){this.isReady||await this.ready;const t=e.width??this.texture.width,n=e.height??this.texture.height,r=e.depthOrArrayLayers??this.texture.depth,i=this.texture.computeMemoryLayout({width:t,height:n,depthOrArrayLayers:r}),a=this.device.createBuffer({byteLength:i.byteLength,usage:Xe.COPY_DST|Xe.MAP_READ});this.texture.readBuffer({...e,width:t,height:n,depthOrArrayLayers:r},a);const s=this.device.createFence();return await s.signaled,s.destroy(),a}async readAsync(e={}){this.isReady||await this.ready;const t=e.width??this.texture.width,n=e.height??this.texture.height,r=e.depthOrArrayLayers??this.texture.depth,i=this.texture.computeMemoryLayout({width:t,height:n,depthOrArrayLayers:r}),a=await this.readBuffer(e),s=await a.readAsync(0,i.byteLength);return a.destroy(),s.buffer instanceof ArrayBuffer?s.buffer:s.slice().buffer}resize(e){if(this._checkReady(),e.width===this.texture.width&&e.height===this.texture.height)return!1;const t=this.texture;return this._texture=t.clone(e),this._sampler=this.texture.sampler,this._view=this.texture.view,t.destroy(),this._touchGeneration(),$e.info(`${this} resized`),!0}getCubeFaceIndex(e){const t=Zt[e];if(void 0===t)throw new Error(`Invalid cube face: ${e}`);return t}getCubeArrayFaceIndex(e,t){return 6*e+this.getCubeFaceIndex(t)}setTexture1DData(e){if(this._checkReady(),"1d"!==this.texture.props.dimension)throw new Error(`${this} is not 1d`);const t=An();this._setTextureSubresources(t)}setTexture2DData(e,t=0){if(this._checkReady(),"2d"!==this.texture.props.dimension)throw new Error(`${this} is not 2d`);const n=ln(t,e);this._setTextureSubresources(n)}setTexture3DData(e){if("3d"!==this.texture.props.dimension)throw new Error(`${this} is not 3d`);const t=cn(e);this._setTextureSubresources(t)}setTextureArrayData(e){if("2d-array"!==this.texture.props.dimension)throw new Error(`${this} is not 2d-array`);const t=un(e);this._setTextureSubresources(t)}setTextureCubeData(e){if("cube"!==this.texture.props.dimension)throw new Error(`${this} is not cube`);const t=fn(e);this._setTextureSubresources(t)}setTextureCubeArrayData(e){if("cube-array"!==this.texture.props.dimension)throw new Error(`${this} is not cube-array`);const t=dn(e);this._setTextureSubresources(t)}_setTextureSubresources(e){for(const t of e){const{z:e,mipLevel:n}=t;switch(t.type){case"external-image":const{image:r,flipY:i}=t;this.texture.copyExternalImage({image:r,z:e,mipLevel:n,flipY:i});break;case"texture-data":const{data:a,textureFormat:s}=t;if(s&&s!==this.texture.format)throw new Error(`${this} mip level ${n} uses format "${s}" but texture format is "${this.texture.format}"`);this.texture.writeData(a.data,{x:0,y:0,z:e,width:a.width,height:a.height,depthOrArrayLayers:1,mipLevel:n});break;default:throw new Error("Unsupported 2D mip-level payload")}}e.length>0&&this._touch()}async _loadAllData(e){const t=await bn(e.data);return{dimension:e.dimension??"2d",data:t??null}}_checkNotDestroyed(){this.destroyed&&$e.warn(`${this} already destroyed`)}_checkReady(){this.isReady||$e.warn(`${this} Cannot perform this operation before ready`)}_touch(){this.updateTimestamp=this.device.incrementTimestamp()}_touchGeneration(){this.generation++,this._touch()}static defaultProps={...G.defaultProps,dimension:"2d",data:null,mipmaps:!1}};function pn(e){if("texture-data"===e.type)return e.textureFormat??an(e.data)}function mn(e,t){switch(t.type){case"external-image":return e.getExternalImageSize(t.image);case"texture-data":return{width:t.data.width,height:t.data.height};default:throw new Error("Unsupported texture subresource")}}function gn(e,t,n,r){const{blockWidth:i=1,blockHeight:a=1}=e.getTextureFormatInfo(r);let s=1;for(let o=1;;o++){const e=Math.max(1,t>>o),r=Math.max(1,n>>o);if(e<i||r<a)break;s++}return s}async function bn(e){if(e=await e,Array.isArray(e))return await Promise.all(e.map(bn));if(e&&"object"==typeof e&&e.constructor===Object){const t=e,n=await Promise.all(Object.values(t).map(bn)),r=Object.keys(t),i={};for(let e=0;e<r.length;e++)i[r[e]]=n[e];return i}return e}function vn(e,t){if(!e)throw new Error(t)}var yn=class{id;matrix=new H;display=!0;position=new de;rotation=new de;scale=new de(1,1,1);userData={};props={};constructor(e={}){const{id:t}=e;this.id=t||Ve(this.constructor.name),this._setScenegraphNodeProps(e)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(e){return this._setScenegraphNodeProps(e),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(e){return vn(3===e.length,"setPosition requires vector argument"),this.position=e,this}setRotation(e){return vn(3===e.length||4===e.length,"setRotation requires vector argument"),this.rotation=e,this}setScale(e){return vn(3===e.length,"setScale requires vector argument"),this.scale=e,this}setMatrix(e,t=!0){t?this.matrix.copy(e):this.matrix=e}setMatrixComponents(e){const{position:t,rotation:n,scale:r,update:i=!0}=e;return t&&this.setPosition(t),n&&this.setRotation(n),r&&this.setScale(r),i&&this.updateMatrix(),this}updateMatrix(){if(this.matrix.identity(),this.matrix.translate(this.position),4===this.rotation.length){const e=(new H).fromQuaternion(this.rotation);this.matrix.multiplyRight(e)}else this.matrix.rotateXYZ(this.rotation);return this.matrix.scale(this.scale),this}update({position:e,rotation:t,scale:n}={}){return e&&this.setPosition(e),t&&this.setRotation(t),n&&this.setScale(n),this.updateMatrix(),this}getCoordinateUniforms(e,t){t=t||this.matrix;const n=new H(e).multiplyRight(t),r=n.invert(),i=r.transpose();return{viewMatrix:e,modelMatrix:t,objectMatrix:t,worldMatrix:n,worldInverseMatrix:r,worldInverseTransposeMatrix:i}}_setScenegraphNodeProps(e){void 0!==e.display&&(this.display=e.display),e?.position&&this.setPosition(e.position),e?.rotation&&this.setRotation(e.rotation),e?.scale&&this.setScale(e.scale),this.updateMatrix(),e?.matrix&&this.setMatrix(e.matrix),Object.assign(this.props,e)}};function xn(e,t,n){const r=new H(n);for(let i=0;i<8;i++){const n=new de(t[1&i?1:0][0],t[2&i?1:0][1],t[4&i?1:0][2]);r.transformAsPoint(n,n);for(let t=0;t<3;t++)e[0][t]=Math.min(e[0][t],n[t]),e[1][t]=Math.max(e[1][t],n[t])}}function _n(e){return Number.isFinite(e[0][0])}var wn=class e extends yn{children;constructor(e={}){e=Array.isArray(e)?{children:e}:e;const{children:t=[]}=e;$e.assert(t.every(e=>e instanceof yn),"every child must an instance of ScenegraphNode"),super(e),this.children=t}getBounds(){const e=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((t,{worldMatrix:n})=>{const r=t.getBounds();if(!r)return;const i=new H(n).multiplyRight(t.matrix);xn(e,r,i)}),_n(e)?e:null}destroy(){this.children.forEach(e=>e.destroy()),this.removeAll(),super.destroy()}add(...e){for(const t of e)Array.isArray(t)?this.add(...t):this.children.push(t);return this}remove(e){const t=this.children,n=t.indexOf(e);return n>-1&&t.splice(n,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:n=new H}={}){if(!this.display)return;const r=new H(n).multiplyRight(this.matrix);for(const i of this.children)i.display&&(i instanceof e?i.traverse(t,{worldMatrix:r}):t(i,{worldMatrix:r}))}traverseDepthSorted(e,{viewMatrix:t,worldMatrix:n=new H,order:r="back-to-front"}){const i=new H(t),a=[];this.traverse((e,t)=>{const n=e.getBounds(),r=n?new de(n[0]).add(n[1]).divide([2,2,2]):new de,s=new H(t.worldMatrix).multiplyRight(e.matrix);s.transformAsPoint(r,r),i.transformAsPoint(r,r),a.push({node:e,context:{worldMatrix:s,bounds:n,depth:-r[2]},index:a.length})},{worldMatrix:new H(n)});const s="back-to-front"===r?-1:1;a.sort((e,t)=>s*(e.context.depth-t.context.depth)||e.index-t.index);for(const{node:o,context:A}of a)e(o,A)}preorderTraversal(t,{worldMatrix:n=new H}={}){const r=new H(n).multiplyRight(this.matrix);t(this,{worldMatrix:r});for(const i of this.children)i instanceof e?i.preorderTraversal(t,{worldMatrix:r}):t(i,{worldMatrix:r})}},Tn=class extends yn{model;instanceMatrices;bounds=null;managedResources;constructor(e){super(e),this.model=e.model,this.managedResources=e.managedResources||[],this.instanceMatrices=e.instanceMatrices||null,this.bounds=e.bounds?this.instanceMatrices?function(e,t){const n=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];for(const r of t)xn(n,e,r);return _n(n)?n:null}(e.bounds,this.instanceMatrices):e.bounds:null,this.setProps(e)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(e=>e.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(e){return this.model.draw(e)}};var Sn=class{static get componentName(){return Object.prototype.hasOwnProperty.call(this,"extensionName")?this.extensionName:""}constructor(e){e&&(this.opts=e)}equals(e){return this===e||this.constructor===e.constructor&&be(this.opts,e.opts,1)}getShaders(e){return null}getSubLayerProps(e){const{defaultProps:t}=e.constructor,n={updateTriggers:{}};for(const r in t)if(r in this.props){const e=t[r],i=this.props[r];n[r]=i,e&&"accessor"===e.type&&(n.updateTriggers[r]=this.props.updateTriggers[r],"function"==typeof i&&(n[r]=this.getSubLayerAccessor(i)))}return n}initializeState(e,t){}updateState(e,t){}onNeedsRedraw(e){}getNeedsPickingBuffer(e){return!1}draw(e,t){}finalizeState(e,t){}};function Mn(e,t,n=2,r,i="xy"){const a=t&&t.length,s=a?t[0]*n:e.length;let o=En(e,0,s,n,!0,r&&r[0],i);const A=[];if(!o||o.next===o.prev)return A;let l,c,u,f,d,h,p;if(a&&(o=function(e,t,n,r,i,a){const s=[];let o,A,l,c,u;for(o=0,A=t.length;o<A;o++)l=t[o]*r,c=o<A-1?t[o+1]*r:e.length,u=En(e,l,c,r,!1,i&&i[o+1],a),u===u.next&&(u.steiner=!0),s.push(Dn(u));for(s.sort(Ln),o=0;o<s.length;o++)n=Bn(s[o],n);return n}(e,t,o,n,r,i)),e.length>80*n){f=c=e[0],d=u=e[1];for(let t=n;t<s;t+=n)h=e[t],p=e[t+1],h<f&&(f=h),p<d&&(d=p),h>c&&(c=h),p>u&&(u=p);l=Math.max(c-f,u-d),l=0!==l?32767/l:0}return In(o,A,n,f,d,l,0),A}function En(e,t,n,r,i,a,s){let o,A;void 0===a&&(a=_(e,{start:t,end:n,size:r,plane:s}));let l=v[s[0]],c=v[s[1]];if(i===a<0)for(o=t;o<n;o+=r)A=Wn(o,e[o+l],e[o+c],A);else for(o=n-r;o>=t;o-=r)A=Wn(o,e[o+l],e[o+c],A);return A&&zn(A,A.next)&&(Jn(A),A=A.next),A}function Cn(e,t){if(!e)return e;t||(t=e);let n,r=e;do{if(n=!1,r.steiner||!zn(r,r.next)&&0!==jn(r.prev,r,r.next))r=r.next;else{if(Jn(r),r=t=r.prev,r===r.next)break;n=!0}}while(n||r!==t);return t}function In(e,t,n,r,i,a,s){if(!e)return;!s&&a&&function(e,t,n,r){let i=e;do{0===i.z&&(i.z=Fn(i.x,i.y,t,n,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==e);i.prevZ.nextZ=null,i.prevZ=null,function(e){let t,n,r,i,a,s,o,A,l=1;do{for(i=e,e=null,A=null,r=0;i;){for(r++,s=i,a=0,n=0;n<l&&(a++,s=s.nextZ,s);n++);for(o=l;a>0||o>0&&s;)0!==a&&(0===o||!s||i.z<=s.z)?(t=i,i=i.nextZ,a--):(t=s,s=s.nextZ,o--),A?A.nextZ=t:e=t,t.prevZ=A,A=t;i=s}A.nextZ=null,l*=2}while(r>1)}(i)}(e,r,i,a);let o,A,l=e;for(;e.prev!==e.next;)if(o=e.prev,A=e.next,a?Pn(e,r,i,a):Rn(e))t.push(o.i/n|0),t.push(e.i/n|0),t.push(A.i/n|0),Jn(e),e=A.next,l=A.next;else if((e=A)===l){s?1===s?In(e=Nn(Cn(e),t,n),t,n,r,i,a,2):2===s&&kn(e,t,n,r,i,a):In(Cn(e),t,n,r,i,a,1);break}}function Rn(e){const t=e.prev,n=e,r=e.next;if(jn(t,n,r)>=0)return!1;const i=t.x,a=n.x,s=r.x,o=t.y,A=n.y,l=r.y,c=i<a?i<s?i:s:a<s?a:s,u=o<A?o<l?o:l:A<l?A:l,f=i>a?i>s?i:s:a>s?a:s,d=o>A?o>l?o:l:A>l?A:l;let h=r.next;for(;h!==t;){if(h.x>=c&&h.x<=f&&h.y>=u&&h.y<=d&&Un(i,o,a,A,s,l,h.x,h.y)&&jn(h.prev,h,h.next)>=0)return!1;h=h.next}return!0}function Pn(e,t,n,r){const i=e.prev,a=e,s=e.next;if(jn(i,a,s)>=0)return!1;const o=i.x,A=a.x,l=s.x,c=i.y,u=a.y,f=s.y,d=o<A?o<l?o:l:A<l?A:l,h=c<u?c<f?c:f:u<f?u:f,p=o>A?o>l?o:l:A>l?A:l,m=c>u?c>f?c:f:u>f?u:f,g=Fn(d,h,t,n,r),b=Fn(p,m,t,n,r);let v=e.prevZ,y=e.nextZ;for(;v&&v.z>=g&&y&&y.z<=b;){if(v.x>=d&&v.x<=p&&v.y>=h&&v.y<=m&&v!==i&&v!==s&&Un(o,c,A,u,l,f,v.x,v.y)&&jn(v.prev,v,v.next)>=0)return!1;if(v=v.prevZ,y.x>=d&&y.x<=p&&y.y>=h&&y.y<=m&&y!==i&&y!==s&&Un(o,c,A,u,l,f,y.x,y.y)&&jn(y.prev,y,y.next)>=0)return!1;y=y.nextZ}for(;v&&v.z>=g;){if(v.x>=d&&v.x<=p&&v.y>=h&&v.y<=m&&v!==i&&v!==s&&Un(o,c,A,u,l,f,v.x,v.y)&&jn(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;y&&y.z<=b;){if(y.x>=d&&y.x<=p&&y.y>=h&&y.y<=m&&y!==i&&y!==s&&Un(o,c,A,u,l,f,y.x,y.y)&&jn(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function Nn(e,t,n){let r=e;do{const i=r.prev,a=r.next.next;!zn(i,a)&&Gn(i,r,r.next,a)&&Qn(i,a)&&Qn(a,i)&&(t.push(i.i/n|0),t.push(r.i/n|0),t.push(a.i/n|0),Jn(r),Jn(r.next),r=e=a),r=r.next}while(r!==e);return Cn(r)}function kn(e,t,n,r,i,a){let s=e;do{let e=s.next.next;for(;e!==s.prev;){if(s.i!==e.i&&Vn(s,e)){let o=Kn(s,e);return s=Cn(s,s.next),o=Cn(o,o.next),In(s,t,n,r,i,a,0),void In(o,t,n,r,i,a,0)}e=e.next}s=s.next}while(s!==e)}function Ln(e,t){return e.x-t.x}function Bn(e,t){const n=function(e,t){let n=t;const r=e.x,i=e.y;let a,s=-1/0;do{if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){const e=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(e<=r&&e>s&&(s=e,a=n.x<n.next.x?n:n.next,e===r))return a}n=n.next}while(n!==t);if(!a)return null;const o=a,A=a.x,l=a.y;let c,u=1/0;n=a;do{r>=n.x&&n.x>=A&&r!==n.x&&Un(i<l?r:s,i,A,l,i<l?s:r,i,n.x,n.y)&&(c=Math.abs(i-n.y)/(r-n.x),Qn(n,e)&&(c<u||c===u&&(n.x>a.x||n.x===a.x&&On(a,n)))&&(a=n,u=c)),n=n.next}while(n!==o);return a}(e,t);if(!n)return t;const r=Kn(n,e);return Cn(r,r.next),Cn(n,n.next)}function On(e,t){return jn(e.prev,e,t.prev)<0&&jn(t.next,e,e.next)<0}function Fn(e,t,n,r,i){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*i|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function Dn(e){let t=e,n=e;do{(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next}while(t!==e);return n}function Un(e,t,n,r,i,a,s,o){return(i-s)*(t-o)>=(e-s)*(a-o)&&(e-s)*(r-o)>=(n-s)*(t-o)&&(n-s)*(a-o)>=(i-s)*(r-o)}function Vn(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){let n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==t.i&&n.next.i!==t.i&&Gn(n,n.next,e,t))return!0;n=n.next}while(n!==e);return!1}(e,t)&&(Qn(e,t)&&Qn(t,e)&&function(e,t){let n=e,r=!1;const i=(e.x+t.x)/2,a=(e.y+t.y)/2;do{n.y>a!=n.next.y>a&&n.next.y!==n.y&&i<(n.next.x-n.x)*(a-n.y)/(n.next.y-n.y)+n.x&&(r=!r),n=n.next}while(n!==e);return r}(e,t)&&(jn(e.prev,e,t.prev)||jn(e,t.prev,t))||zn(e,t)&&jn(e.prev,e,e.next)>0&&jn(t.prev,t,t.next)>0)}function jn(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function zn(e,t){return e.x===t.x&&e.y===t.y}function Gn(e,t,n,r){const i=qn(jn(e,t,n)),a=qn(jn(e,t,r)),s=qn(jn(n,r,e)),o=qn(jn(n,r,t));return i!==a&&s!==o||(!(0!==i||!Hn(e,n,t))||(!(0!==a||!Hn(e,r,t))||(!(0!==s||!Hn(n,e,r))||!(0!==o||!Hn(n,t,r)))))}function Hn(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function qn(e){return e>0?1:e<0?-1:0}function Qn(e,t){return jn(e.prev,e,e.next)<0?jn(e,t,e.next)>=0&&jn(e,e.prev,t)>=0:jn(e,t,e.prev)<0||jn(e,e.next,t)<0}function Kn(e,t){const n=new $n(e.i,e.x,e.y),r=new $n(t.i,t.x,t.y),i=e.next,a=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function Wn(e,t,n,r){const i=new $n(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function Jn(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}Sn.defaultProps={},Sn.extensionName="LayerExtension";var $n=class{constructor(e,t,n){this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1,this.i=e,this.x=t,this.y=n}},Xn={...x.defaultProps},Yn=class extends f{indexToBounds(){return null}renderLayers(){const{elevationScale:e,extruded:t,wireframe:n,filled:r,stroked:i,lineWidthUnits:a,lineWidthScale:s,lineWidthMinPixels:o,lineWidthMaxPixels:A,lineAntialiasing:l,lineJointRounded:c,lineMiterLimit:u,lineDashJustified:f,getElevation:d,getFillColor:h,getLineColor:p,getLineWidth:m}=this.props,{updateTriggers:g,material:b,transitions:v}=this.props,y=this.getSubLayerClass("cell",x),{updateTriggers:_,...w}=this.indexToBounds()||{};return new y({filled:r,wireframe:n,extruded:t,elevationScale:e,stroked:i,lineWidthUnits:a,lineWidthScale:s,lineWidthMinPixels:o,lineWidthMaxPixels:A,lineAntialiasing:l,lineJointRounded:c,lineMiterLimit:u,lineDashJustified:f,material:b,transitions:v,getElevation:d,getFillColor:h,getLineColor:p,getLineWidth:m},this.getSubLayerProps({id:"cell",updateTriggers:g&&{..._,getElevation:g.getElevation,getFillColor:g.getFillColor,getLineColor:g.getLineColor,getLineWidth:g.getLineWidth}}),w)}};function Zn(){const e=/* @__PURE__ */new Float64Array(4);return e[0]=1,e[3]=1,e}function er(){/* @__PURE__ */
1
+ /*! Web-kit v1.2.0-develop.9 | (c) 2026 MapVX */
2
+ !function(){try{var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="7913ec21-9c19-4977-80c1-976dc2d1a7a8",e._sentryDebugIdIdentifier="sentry-dbid-7913ec21-9c19-4977-80c1-976dc2d1a7a8")}catch(e){}}();import{i as e,n as t,r as n,t as r}from"./rolldown-runtime-Lq6Z3lw4.js";import{C as i,E as a,S as s,T as o,_ as A,a as l,b as c,c as u,d as f,f as d,g as h,h as p,i as m,l as g,n as b,o as v,p as y,r as x,s as _,u as w,v as T,w as S,x as M,y as E}from"./dist-47_p4Yxg.js";import{A as C,At as I,D as R,Dt as P,Et as N,Ft as k,I as L,It as B,Lt as O,Mt as F,Nt as D,Ot as U,Pt as V,St as j,Tt as z,Ut as G,W as H,Wt as q,Xt as Q,Yt as K,Zt as W,_ as J,_n as $,at as X,bn as Y,bt as Z,cn as ee,ct as te,dn as ne,et as re,fn as ie,gn as ae,gt as se,hn as oe,in as Ae,jt as le,l as ce,ln as ue,mn as fe,nt as de,on as he,pn as pe,pt as me,rn as ge,s as be,sn as ve,tt as ye,un as xe,vn as _e,vt as we,xt as Te,yn as Se,yt as Me}from"./debug-hooks-DWy-ovrh.js";import{a as Ee,c as Ce,d as Ie,f as Re,i as Pe,l as Ne,m as ke,o as Le,p as Be,r as Oe,s as Fe,t as De,u as Ue}from"./globe-viewport-CwpYcu3c.js";import{_ as Ve,b as je,c as ze,d as Ge,g as He,l as qe,s as Qe,u as Ke}from"./expression-XgnkW6Sk.js";import{h as We,m as Je,p as $e,u as Xe}from"./shader-type-decoder-CpvFwfxh.js";import{h as Ye}from"./webgl-device-ChYrAvsE.js";async function Ze(e,t,n,r){return r._parse(e,t,n,r)}globalThis.probe||(globalThis.probe=We);var et=new Je({id:"@probe.gl/log"});var tt={};function nt(e={}){const t=e.useLocalLibraries??e.core?.useLocalLibraries,n=e.CDN??e.core?.CDN,r=e.modules;return{...void 0!==t?{useLocalLibraries:t}:{},...void 0!==n?{CDN:n}:{},...void 0!==r?{modules:r}:{}}}async function rt(e,t=null,n={},r=null){if(t){const i=n.modules?.[r||e];if(void 0!==i&&"string"!=typeof i)return i;e=function(e,t,n={},r=null){if(n?.core)throw new Error("loadLibrary: options.core must be pre-normalized");r=r||e;const i=n.modules||{};if("string"==typeof i[r])return i[r];if(!n.useLocalLibraries&&e.startsWith("http"))return e;if(!pe)return`modules/${t}/dist/libs/${r}`;if(n.CDN)return oe(n.CDN.startsWith("http")),`${n.CDN}/${t}@${ae}/dist/libs/${r}`;return fe?`../src/libs/${r}`:`modules/${t}/src/libs/${r}`}(e,t,n,r)}return tt[e]=tt[e]||async function(e){if(e.endsWith("wasm"))return await async function(e){const{readFileAsArrayBuffer:t}=globalThis.loaders||{};if(pe||!t||e.startsWith("http"))return await(await fetch(e)).arrayBuffer();try{return await t(e)}catch{if(e.includes("/dist/libs/"))return await t(e.replace("/dist/libs/","/src/libs/"));throw new Error(`Failed to load ArrayBuffer from ${e}`)}}(e);if(!pe){const{requireFromFile:n}=globalThis.loaders||{};try{const t=await(n?.(e));return t||!e.includes("/dist/libs/")?t:await(n?.(e.replace("/dist/libs/","/src/libs/")))}catch(t){if(e.includes("/dist/libs/"))try{return await(n?.(e.replace("/dist/libs/","/src/libs/")))}catch{}return console.error(t),null}}return fe?importScripts(e):function(e,t){if(!pe){const{requireFromString:n}=globalThis.loaders||{};return n?.(e,t)}if(fe)return eval.call(globalThis,e),null;const n=document.createElement("script");n.id=t;try{n.appendChild(document.createTextNode(e))}catch(Lr){n.text=e}return document.body.appendChild(n),null}(await async function(e){const{readFileAsText:t}=globalThis.loaders||{};if(pe||!t||e.startsWith("http"))return await(await fetch(e)).text();try{return await t(e)}catch{if(e.includes("/dist/libs/"))return await t(e.replace("/dist/libs/","/src/libs/"));throw new Error(`Failed to load text from ${e}`)}}(e),e)}(e),await tt[e]}function it(e,t,n){if(e.byteLength<=t+n)return"";const r=new DataView(e);let i="";for(let a=0;a<n;a++)i+=String.fromCharCode(r.getUint8(t+a));return i}function at(e){try{return JSON.parse(e)}catch(t){throw new Error(`Failed to parse JSON from data starting with "${function(e,t=5){return"string"==typeof e?e.slice(0,t):ArrayBuffer.isView(e)?it(e.buffer,e.byteOffset,t):e instanceof ArrayBuffer?it(e,0,t):""}(e)}"`)}}function st(e,t){return Y(e>=0),Y(t>0),e+(t-1)&~(t-1)}function ot(e,t,n){let r;if(e instanceof ArrayBuffer)r=new Uint8Array(e);else{const t=e.byteOffset,n=e.byteLength;r=new Uint8Array(e.buffer||e.arrayBuffer,t,n)}return t.set(r,n),n+st(r.byteLength,4)}var At={id:"request-scheduler",throttleRequests:!0,maxRequests:6,debounceTime:0},lt=class{props;stats;activeRequestCount=0;requestQueue=[];requestMap=/* @__PURE__ */new Map;updateTimer=null;constructor(e={}){this.props={...At,...e},this.stats=new ne({id:this.props.id}),this.stats.get("Queued Requests"),this.stats.get("Active Requests"),this.stats.get("Cancelled Requests"),this.stats.get("Queued Requests Ever"),this.stats.get("Active Requests Ever")}setProps(e){void 0!==e.throttleRequests&&(this.props.throttleRequests=e.throttleRequests),void 0!==e.maxRequests&&(this.props.maxRequests=e.maxRequests),void 0!==e.debounceTime&&(this.props.debounceTime=e.debounceTime)}scheduleRequest(e,t=()=>0){if(!this.props.throttleRequests)return Promise.resolve({done:()=>{}});if(this.requestMap.has(e))return this.requestMap.get(e);const n={handle:e,priority:0,getPriority:t},r=new Promise(e=>(n.resolve=e,n));return this.requestQueue.push(n),this.requestMap.set(e,r),this._issueNewRequests(),r}_issueRequest(e){const{handle:t,resolve:n}=e;let r=!1;const i=()=>{r||(r=!0,this.requestMap.delete(t),this.activeRequestCount--,null===this.updateTimer&&(this.updateTimer=setTimeout(()=>this._issueNewRequestsAsync(),0)))};return this.activeRequestCount++,n?n({done:i}):Promise.resolve({done:i})}_issueNewRequests(){null!==this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>this._issueNewRequestsAsync(),this.props.debounceTime)}_issueNewRequestsAsync(){null!==this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=null;const e=Math.max(this.props.maxRequests-this.activeRequestCount,0);if(0!==e){this._updateAllRequests();for(let t=0;t<e;++t){const e=this.requestQueue.shift();e&&this._issueRequest(e)}}}_updateAllRequests(){const e=this.requestQueue;for(let t=0;t<e.length;++t){const n=e[t];this._updateRequest(n)||(e.splice(t,1),this.requestMap.delete(n.handle),t--)}e.sort((e,t)=>e.priority-t.priority)}_updateRequest(e){return e.priority=e.getPriority(e.handle),!(e.priority<0)||(e.resolve(null),!1)}},ct=class e{static defaultOptions={core:{type:"auto",attributions:[],loadOptions:{},loaders:[]}};optionsType;options;data;url;loadOptions;fetch;_needsRefresh=!0;constructor(t,n,r){this.options=r?$({...r,core:e.defaultOptions},n):{...n},this.data=t,this.url="string"==typeof t?xe(t):"",this.loadOptions=function(e){const t={...e};e?.core&&(t.core={...e.core});const n="string"==typeof t.baseUri?t.baseUri:void 0,r="string"==typeof t.baseUrl?t.baseUrl:void 0;void 0===n&&void 0===r||(t.core||={},void 0===t.core.baseUrl&&(t.core.baseUrl=r??n),delete t.baseUri,delete t.baseUrl);return t}(this.options.core?.loadOptions),this.fetch=function(e){const t=e?.core?.fetch;if(t&&"function"==typeof t)return(e,n)=>t(e,n);const n=e?.fetch;return n&&"function"!=typeof n?e=>fetch(e,n):e=>fetch(e)}(this.loadOptions)}setProps(e){this.options=Object.assign(this.options,e),this.setNeedsRefresh()}setNeedsRefresh(){this._needsRefresh=!0}getNeedsRefresh(e=!0){const t=this._needsRefresh;return e&&(this._needsRefresh=!1),t}};var ut=class{static type="template";static testURL=e=>!1};function ft(e,t){return new Promise((n,r)=>{let i=!1;function a(e){i||(i=!0,r(e))}function s(e){if(!i){i=!0;try{n(t(e))}catch(a){r(a)}}}try{e(s,a)?.then(s,a)}catch(o){a(o)}})}function dt(e,t,n){const r=function(e){switch(e.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}(t.value),i=n||function(e){const t={};"byteOffset"in e&&(t.byteOffset=e.byteOffset.toString(10));"byteStride"in e&&(t.byteStride=e.byteStride.toString(10));"normalized"in e&&(t.normalized=e.normalized.toString());return t}(t);return{name:e,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:r}]},nullable:!1,metadata:i}}var ht=["image/png","image/jpeg","image/gif","image/webp","image/avif","image/tiff","image/svg","image/svg+xml","image/bmp","image/vnd.microsoft.icon"],pt=null;async function mt(){return pt||(pt=async function(){const e=/* @__PURE__ */new Set;for(const t of ht)(Se?await xt(t):vt(t))&&e.add(t);return e}()),await pt}var gt={};function bt(e){if(void 0===gt[e]){const t=Se?function(e){switch(e){case"image/avif":case"image/webp":return function(e){try{return 0===document.createElement("canvas").toDataURL(e).indexOf(`data:${e}`)}catch{return!1}}(e);default:return!0}}(e):vt(e);gt[e]=t}return gt[e]}function vt(e){const t=globalThis.loaders?.imageFormatsNode||["image/png","image/jpeg","image/gif"],n=globalThis.loaders?.parseImageNode;return Boolean(n)&&t.includes(e)}var yt={"image/avif":"data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=","image/webp":"data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA"};async function xt(e){const t=yt[e];return!t||await async function(e){return new Promise(t=>{const n=new Image;n.src=e,n.onload=()=>t(n.height>0),n.onerror=()=>t(!1)})}(t)}var _t,wt=class extends z{constructor(e=0,t=0){super(2),V(e)&&1===arguments.length?this.copy(e):(le.debug&&(P(e),P(t)),this[0]=e,this[1]=t)}set(e,t){return this[0]=e,this[1]=t,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this.check()}fromObject(e){return le.debug&&(P(e.x),P(e.y)),this[0]=e.x,this[1]=e.y,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e}get ELEMENTS(){return 2}horizontalAngle(){return Math.atan2(this.y,this.x)}verticalAngle(){return Math.atan2(this.x,this.y)}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return j(this,this,e),this.check()}transformAsVector(e){return se(this,this,e),this.check()}transformByMatrix3(e){return Te(this,this,e),this.check()}transformByMatrix2x3(e){return Z(this,this,e),this.check()}transformByMatrix2(e){return Me(this,this,e),this.check()}};!function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL1ROW0=3]="COL1ROW0",e[e.COL1ROW1=4]="COL1ROW1",e[e.COL1ROW2=5]="COL1ROW2",e[e.COL2ROW0=6]="COL2ROW0",e[e.COL2ROW1=7]="COL2ROW1",e[e.COL2ROW2=8]="COL2ROW2"}(_t||(_t={}));var Tt,St=Object.freeze([1,0,0,0,1,0,0,0,1]),Mt=class extends ye{static get IDENTITY(){return function(){Et||(Et=new Mt,Object.freeze(Et));return Et}()}static get ZERO(){return function(){Tt||(Tt=new Mt([0,0,0,0,0,0,0,0,0]),Object.freeze(Tt));return Tt}()}get ELEMENTS(){return 9}get RANK(){return 3}get INDICES(){return _t}constructor(e,...t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0),1===arguments.length&&Array.isArray(e)?this.copy(e):t.length>0?this.copy([e,...t]):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this.check()}identity(){return this.copy(St)}fromObject(e){return this.check()}fromQuaternion(e){return Ee(this,e),this.check()}set(e,t,n,r,i,a,s,o,A){return this[0]=e,this[1]=t,this[2]=n,this[3]=r,this[4]=i,this[5]=a,this[6]=s,this[7]=o,this[8]=A,this.check()}setRowMajor(e,t,n,r,i,a,s,o,A){return this[0]=e,this[1]=r,this[2]=s,this[3]=t,this[4]=i,this[5]=o,this[6]=n,this[7]=a,this[8]=A,this.check()}determinant(){return Pe(this)}transpose(){return Ie(this,this),this.check()}invert(){return Le(this,this),this.check()}multiplyLeft(e){return Fe(this,e,this),this.check()}multiplyRight(e){return Fe(this,this,e),this.check()}rotate(e){return Ce(this,this,e),this.check()}scale(e){return Array.isArray(e)?Ne(this,this,e):Ne(this,this,[e,e]),this.check()}translate(e){return Ue(this,this,e),this.check()}transform(e,t){let n;switch(e.length){case 2:n=Te(t||[-0,-0],e,this);break;case 3:n=me(t||[-0,-0,-0],e,this);break;case 4:n=we(t||[-0,-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return U(n,e.length),n}transformVector(e,t){return this.transform(e,t)}transformVector2(e,t){return this.transform(e,t)}transformVector3(e,t){return this.transform(e,t)}},Et=null;var Ct={props:{},uniforms:{},bindings:{},name:"skin",bindingLayout:[{name:"skin",group:0},{name:"skinJointMatrices",group:0,visibility:1}],dependencies:[],source:"\nstruct skinUniforms {\n jointMatrix: array<mat4x4<f32>, 64>,\n};\n\n@group(0) @binding(auto) var<uniform> skin: skinUniforms;\n\n#ifdef HAS_INSTANCED_SKIN\n@group(0) @binding(auto) var<storage, read> skinJointMatrices: array<mat4x4<f32>>;\n\nfn getInstancedSkinMatrix(\n weights: vec4f,\n joints: vec4u,\n instanceIndex: u32,\n jointsPerInstance: u32\n) -> mat4x4<f32> {\n let firstJoint = instanceIndex * jointsPerInstance;\n return (weights.x * skinJointMatrices[firstJoint + joints.x])\n + (weights.y * skinJointMatrices[firstJoint + joints.y])\n + (weights.z * skinJointMatrices[firstJoint + joints.z])\n + (weights.w * skinJointMatrices[firstJoint + joints.w]);\n}\n#endif\n\nfn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {\n return (weights.x * skin.jointMatrix[joints.x])\n + (weights.y * skin.jointMatrix[joints.y])\n + (weights.z * skin.jointMatrix[joints.z])\n + (weights.w * skin.jointMatrix[joints.w]);\n}\n",vs:"\nlayout(std140) uniform skinUniforms {\n mat4 jointMatrix[SKIN_MAX_JOINTS];\n} skin;\n\n#ifdef HAS_INSTANCED_SKIN\nuniform highp sampler2D skinJointMatrices;\n\nmat4 getInstancedJointMatrix(uint jointIndex, uint instanceIndex) {\n int firstColumn = int(jointIndex * 4u);\n int row = int(instanceIndex);\n return mat4(\n texelFetch(skinJointMatrices, ivec2(firstColumn, row), 0),\n texelFetch(skinJointMatrices, ivec2(firstColumn + 1, row), 0),\n texelFetch(skinJointMatrices, ivec2(firstColumn + 2, row), 0),\n texelFetch(skinJointMatrices, ivec2(firstColumn + 3, row), 0)\n );\n}\n\nmat4 getInstancedSkinMatrix(\n vec4 weights,\n uvec4 joints,\n uint instanceIndex,\n uint jointsPerInstance\n) {\n return (weights.x * getInstancedJointMatrix(joints.x, instanceIndex))\n + (weights.y * getInstancedJointMatrix(joints.y, instanceIndex))\n + (weights.z * getInstancedJointMatrix(joints.z, instanceIndex))\n + (weights.w * getInstancedJointMatrix(joints.w, instanceIndex));\n}\n#endif\n\nmat4 getSkinMatrix(vec4 weights, uvec4 joints) {\n return (weights.x * skin.jointMatrix[joints.x])\n + (weights.y * skin.jointMatrix[joints.y])\n + (weights.z * skin.jointMatrix[joints.z])\n + (weights.w * skin.jointMatrix[joints.w]);\n}\n\n",fs:"",defines:{SKIN_MAX_JOINTS:64},getUniforms:(e={},t)=>{const{jointMatrices:n,skinJointMatrices:r,scenegraphsFromGLTF:i,skinIndex:a=0,meshWorldMatrix:s}=e,o=r?{skinJointMatrices:r}:{};if(n)return{jointMatrix:It(n),...o};const A=i?.gltf?.skins?.[a];if(!A)return{jointMatrix:[],...o};const{inverseBindMatrices:l,joints:c,skeleton:u}=A,f=i.gltfNodeIndexToNodeMap,d=/* @__PURE__ */new Map,h=void 0===u?void 0:f?.get(u),p=h?[h]:i.scenes||[];for(const v of p)v.preorderTraversal((e,{worldMatrix:t})=>{d.set(e.id,t)});const m=s?new H(s).invert():null,g=/* @__PURE__ */new Float32Array(1024),b=l?.value;for(let v=0;v<Math.min(c.length,64);v++){const e=f?.get(c[v]);if(!e)continue;const t=d.get(e.id)||e.matrix,n=m?new H(m).multiplyRight(t):new H(t);b&&b.length>=16*(v+1)&&n.multiplyRight(new H(Array.from(b.slice(16*v,16*(v+1))))),g.set(n,16*v)}return{jointMatrix:g,...o}},uniformTypes:{jointMatrix:["mat4x4<f32>",64]}};function It(e){const t=/* @__PURE__ */new Float32Array(1024);return t.set(e instanceof Float32Array?e.subarray(0,t.length):e.slice(0,t.length)),t}var Rt={name:"gpuAnimation",props:{},uniforms:{},bindings:{},source:"\n#ifdef HAS_GPU_CROWD_ANIMATION\n@group(0) @binding(auto) var<storage, read> gpuAnimationFrames: array<vec4f>;\n\nfn readGPUAnimationFrame(frame: u32, offset: u32, frameStride: u32) -> vec4f {\n return gpuAnimationFrames[frame * frameStride + offset];\n}\n\nfn sampleGPUAnimationFrame(\n frames: vec4f,\n blend: vec4f,\n offset: u32,\n frameStride: u32\n) -> vec4f {\n let first = mix(\n readGPUAnimationFrame(u32(frames.x), offset, frameStride),\n readGPUAnimationFrame(u32(frames.y), offset, frameStride),\n frames.z\n );\n if (blend.w <= 0.0) {\n return first;\n }\n let second = mix(\n readGPUAnimationFrame(u32(blend.x), offset, frameStride),\n readGPUAnimationFrame(u32(blend.y), offset, frameStride),\n blend.z\n );\n return mix(first, second, blend.w);\n}\n\nfn sampleGPUAnimationMatrix(\n frames: vec4f,\n blend: vec4f,\n firstColumn: u32,\n frameStride: u32\n) -> mat4x4f {\n return mat4x4f(\n sampleGPUAnimationFrame(frames, blend, firstColumn, frameStride),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 1u, frameStride),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 2u, frameStride),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 3u, frameStride)\n );\n}\n\nfn getGPUAnimatedSkinMatrix(\n weights: vec4f,\n joints: vec4u,\n frames: vec4f,\n blend: vec4f,\n frameStride: u32\n) -> mat4x4f {\n return weights.x * sampleGPUAnimationMatrix(frames, blend, 4u + joints.x * 4u, frameStride)\n + weights.y * sampleGPUAnimationMatrix(frames, blend, 4u + joints.y * 4u, frameStride)\n + weights.z * sampleGPUAnimationMatrix(frames, blend, 4u + joints.z * 4u, frameStride)\n + weights.w * sampleGPUAnimationMatrix(frames, blend, 4u + joints.w * 4u, frameStride);\n}\n#endif\n\n#ifdef HAS_INSTANCED_MORPH\n@group(0) @binding(auto) var<storage, read> gpuMorphTargets: array<vec4f>;\n\n#ifndef HAS_GPU_CROWD_ANIMATION\n@group(0) @binding(auto) var<storage, read> gpuMorphWeights: array<vec4f>;\n#endif\n\nfn getGPUCrowdMorphWeight(\n instanceIndex: u32,\n targetIndex: u32,\n targetCount: u32,\n jointsPerInstance: u32,\n frames: vec4f,\n blend: vec4f,\n frameStride: u32\n) -> f32 {\n#ifdef HAS_GPU_CROWD_ANIMATION\n let offset = 4u + jointsPerInstance * 4u + targetIndex;\n return sampleGPUAnimationFrame(frames, blend, offset, frameStride).x;\n#else\n let packedCount = (targetCount + 3u) / 4u;\n let packedWeights = gpuMorphWeights[instanceIndex * packedCount + targetIndex / 4u];\n return packedWeights[targetIndex % 4u];\n#endif\n}\n\nfn getGPUCrowdMorphDelta(\n instanceIndex: u32,\n vertexIndex: u32,\n attributeIndex: u32,\n vertexCount: u32,\n targetCount: u32,\n jointsPerInstance: u32,\n frames: vec4f,\n blend: vec4f,\n frameStride: u32\n) -> vec3f {\n var result = vec3f(0.0);\n for (var targetIndex = 0u; targetIndex < targetCount; targetIndex++) {\n let weight = getGPUCrowdMorphWeight(\n instanceIndex,\n targetIndex,\n targetCount,\n jointsPerInstance,\n frames,\n blend,\n frameStride\n );\n let offset = (targetIndex * 3u + attributeIndex) * vertexCount + vertexIndex;\n result += gpuMorphTargets[offset].xyz * weight;\n }\n return result;\n}\n#endif\n",vs:"\n#ifdef HAS_GPU_CROWD_ANIMATION\nuniform highp sampler2D gpuAnimationFrames;\n\nvec4 sampleGPUAnimationFrame(vec4 frames, vec4 blend, int offset) {\n vec4 first = mix(\n texelFetch(gpuAnimationFrames, ivec2(offset, int(frames.x)), 0),\n texelFetch(gpuAnimationFrames, ivec2(offset, int(frames.y)), 0),\n frames.z\n );\n if (blend.w <= 0.0) {\n return first;\n }\n vec4 second = mix(\n texelFetch(gpuAnimationFrames, ivec2(offset, int(blend.x)), 0),\n texelFetch(gpuAnimationFrames, ivec2(offset, int(blend.y)), 0),\n blend.z\n );\n return mix(first, second, blend.w);\n}\n\nmat4 sampleGPUAnimationMatrix(vec4 frames, vec4 blend, int firstColumn) {\n return mat4(\n sampleGPUAnimationFrame(frames, blend, firstColumn),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 1),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 2),\n sampleGPUAnimationFrame(frames, blend, firstColumn + 3)\n );\n}\n\nmat4 getGPUAnimatedSkinMatrix(vec4 weights, uvec4 joints, vec4 frames, vec4 blend) {\n return weights.x * sampleGPUAnimationMatrix(frames, blend, 4 + int(joints.x) * 4)\n + weights.y * sampleGPUAnimationMatrix(frames, blend, 4 + int(joints.y) * 4)\n + weights.z * sampleGPUAnimationMatrix(frames, blend, 4 + int(joints.z) * 4)\n + weights.w * sampleGPUAnimationMatrix(frames, blend, 4 + int(joints.w) * 4);\n}\n#endif\n\n#ifdef HAS_INSTANCED_MORPH\nuniform highp sampler2D gpuMorphTargets;\n\n#ifndef HAS_GPU_CROWD_ANIMATION\nuniform highp sampler2D gpuMorphWeights;\n#endif\n\nfloat getGPUCrowdMorphWeight(\n uint instanceIndex,\n uint targetIndex,\n uint jointsPerInstance,\n vec4 frames,\n vec4 blend\n) {\n#ifdef HAS_GPU_CROWD_ANIMATION\n int offset = 4 + int(jointsPerInstance) * 4 + int(targetIndex);\n return sampleGPUAnimationFrame(frames, blend, offset).x;\n#else\n vec4 packedWeights = texelFetch(\n gpuMorphWeights,\n ivec2(int(targetIndex / 4u), int(instanceIndex)),\n 0\n );\n return packedWeights[int(targetIndex % 4u)];\n#endif\n}\n\nvec3 getGPUCrowdMorphDelta(\n uint instanceIndex,\n uint vertexIndex,\n uint attributeIndex,\n uint targetCount,\n uint jointsPerInstance,\n vec4 frames,\n vec4 blend\n) {\n vec3 result = vec3(0.0);\n for (uint targetIndex = 0u; targetIndex < targetCount; targetIndex++) {\n float weight = getGPUCrowdMorphWeight(\n instanceIndex,\n targetIndex,\n jointsPerInstance,\n frames,\n blend\n );\n result += texelFetch(\n gpuMorphTargets,\n ivec2(int(vertexIndex), int(targetIndex * 3u + attributeIndex)),\n 0\n ).xyz * weight;\n }\n return result;\n}\n#endif\n",fs:"",bindingLayout:[{name:"gpuAnimationFrames",group:0,visibility:1},{name:"gpuMorphTargets",group:0,visibility:1},{name:"gpuMorphWeights",group:0,visibility:1}],getUniforms:(e={})=>e},Pt="#ifdef USE_IBL\nuniform samplerCube pbr_diffuseEnvSampler;\nuniform samplerCube pbr_specularEnvSampler;\nuniform sampler2D pbr_brdfLUT;\n#endif\n",Nt="layout(std140) uniform pbrProjectionUniforms {\n mat4 modelViewProjectionMatrix;\n mat4 modelMatrix;\n mat4 normalMatrix;\n vec3 camera;\n} pbrProjection;\n",kt={props:{},uniforms:{},defaultUniforms:{unlit:!1,baseColorMapEnabled:!1,baseColorFactor:[1,1,1,1],normalMapEnabled:!1,normalScale:1,emissiveMapEnabled:!1,emissiveFactor:[0,0,0],metallicRoughnessValues:[1,1],metallicRoughnessMapEnabled:!1,occlusionMapEnabled:!1,occlusionStrength:1,alphaCutoffEnabled:!1,alphaCutoff:.5,IBLenabled:!1,scaleIBLAmbient:[1,1],scaleDiffBaseMR:[0,0,0,0],scaleFGDSpec:[0,0,0,0],specularColorFactor:[1,1,1],specularIntensityFactor:1,specularColorMapEnabled:!1,specularIntensityMapEnabled:!1,ior:1.5,transmissionFactor:0,transmissionMapEnabled:!1,thicknessFactor:0,attenuationDistance:1e9,attenuationColor:[1,1,1],clearcoatFactor:0,clearcoatRoughnessFactor:0,clearcoatMapEnabled:!1,clearcoatRoughnessMapEnabled:!1,sheenColorFactor:[0,0,0],sheenRoughnessFactor:0,sheenColorMapEnabled:!1,sheenRoughnessMapEnabled:!1,iridescenceFactor:0,iridescenceIor:1.3,iridescenceThicknessRange:[100,400],iridescenceMapEnabled:!1,anisotropyStrength:0,anisotropyRotation:0,anisotropyDirection:[1,0],anisotropyMapEnabled:!1,emissiveStrength:1,dispersion:0,baseColorUVSet:0,baseColorUVTransform:[1,0,0,0,1,0,0,0,1],metallicRoughnessUVSet:0,metallicRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],normalUVSet:0,normalUVTransform:[1,0,0,0,1,0,0,0,1],occlusionUVSet:0,occlusionUVTransform:[1,0,0,0,1,0,0,0,1],emissiveUVSet:0,emissiveUVTransform:[1,0,0,0,1,0,0,0,1],specularColorUVSet:0,specularColorUVTransform:[1,0,0,0,1,0,0,0,1],specularIntensityUVSet:0,specularIntensityUVTransform:[1,0,0,0,1,0,0,0,1],transmissionUVSet:0,transmissionUVTransform:[1,0,0,0,1,0,0,0,1],thicknessUVSet:0,thicknessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatUVSet:0,clearcoatUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatRoughnessUVSet:0,clearcoatRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatNormalUVSet:0,clearcoatNormalUVTransform:[1,0,0,0,1,0,0,0,1],sheenColorUVSet:0,sheenColorUVTransform:[1,0,0,0,1,0,0,0,1],sheenRoughnessUVSet:0,sheenRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceUVSet:0,iridescenceUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceThicknessUVSet:0,iridescenceThicknessUVTransform:[1,0,0,0,1,0,0,0,1],anisotropyUVSet:0,anisotropyUVTransform:[1,0,0,0,1,0,0,0,1],bumpFactor:1,bumpMapEnabled:!1,diffuseTransmissionFactor:0,diffuseTransmissionMapEnabled:!1,diffuseTransmissionColorFactor:[1,1,1],diffuseTransmissionColorMapEnabled:!1,multiscatterColorFactor:[0,0,0],multiscatterColorMapEnabled:!1,scatterAnisotropy:0,bumpUVSet:0,bumpUVTransform:[1,0,0,0,1,0,0,0,1],diffuseTransmissionUVSet:0,diffuseTransmissionUVTransform:[1,0,0,0,1,0,0,0,1],diffuseTransmissionColorUVSet:0,diffuseTransmissionColorUVTransform:[1,0,0,0,1,0,0,0,1],multiscatterColorUVSet:0,multiscatterColorUVTransform:[1,0,0,0,1,0,0,0,1]},name:"pbrMaterial",firstBindingSlot:0,bindingLayout:[{name:"pbrMaterial",group:3},{name:"pbr_baseColorSampler",group:3},{name:"pbr_normalSampler",group:3},{name:"pbr_emissiveSampler",group:3},{name:"pbr_metallicRoughnessSampler",group:3},{name:"pbr_occlusionSampler",group:3},{name:"pbr_specularColorSampler",group:3},{name:"pbr_specularIntensitySampler",group:3},{name:"pbr_transmissionSampler",group:3},{name:"pbr_thicknessSampler",group:3},{name:"pbr_clearcoatSampler",group:3},{name:"pbr_clearcoatRoughnessSampler",group:3},{name:"pbr_clearcoatNormalSampler",group:3},{name:"pbr_sheenColorSampler",group:3},{name:"pbr_sheenRoughnessSampler",group:3},{name:"pbr_iridescenceSampler",group:3},{name:"pbr_iridescenceThicknessSampler",group:3},{name:"pbr_anisotropySampler",group:3},{name:"pbr_bumpSampler",group:3},{name:"pbr_diffuseTransmissionSampler",group:3},{name:"pbr_diffuseTransmissionColorSampler",group:3},{name:"pbr_multiscatterColorSampler",group:3}],dependencies:[S,{name:"ibl",firstBindingSlot:32,bindingLayout:[{name:"pbr_diffuseEnvSampler",group:2},{name:"pbr_specularEnvSampler",group:2},{name:"pbr_brdfLUT",group:2}],source:"#ifdef USE_IBL\n@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;\n@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;\n@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;\n@group(2) @binding(auto) var pbr_specularEnvSamplerSampler: sampler;\n@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;\n@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;\n#endif\n",vs:Pt,fs:Pt},{name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:"struct pbrProjectionUniforms {\n modelViewProjectionMatrix: mat4x4<f32>,\n modelMatrix: mat4x4<f32>,\n normalMatrix: mat4x4<f32>,\n camera: vec3<f32>\n};\n\n@group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;\n",vs:Nt,fs:Nt,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}}],source:"struct PBRFragmentInputs {\n pbr_vPosition: vec3f,\n pbr_vUV0: vec2f,\n pbr_vUV1: vec2f,\n pbr_vTBN: mat3x3f,\n pbr_vNormal: vec3f\n};\n\nvar<private> fragmentInputs: PBRFragmentInputs;\n\nfn pbr_setPositionNormalTangentUV(\n position: vec4f,\n normal: vec4f,\n tangent: vec4f,\n uv0: vec2f,\n uv1: vec2f\n)\n{\n var pos: vec4f = pbrProjection.modelMatrix * position;\n fragmentInputs.pbr_vPosition = pos.xyz / pos.w;\n fragmentInputs.pbr_vNormal = vec3f(0.0, 0.0, 1.0);\n fragmentInputs.pbr_vTBN = mat3x3f(\n vec3f(1.0, 0.0, 0.0),\n vec3f(0.0, 1.0, 0.0),\n vec3f(0.0, 0.0, 1.0)\n );\n fragmentInputs.pbr_vUV0 = vec2f(0.0, 0.0);\n fragmentInputs.pbr_vUV1 = uv1;\n\n#ifdef HAS_NORMALS\n let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);\n fragmentInputs.pbr_vNormal = normalW;\n#ifdef HAS_TANGENTS\n let tangentW: vec3f = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);\n let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;\n fragmentInputs.pbr_vTBN = mat3x3f(tangentW, bitangentW, normalW);\n#endif\n#endif\n\n#ifdef HAS_UV\n fragmentInputs.pbr_vUV0 = uv0;\n#endif\n}\n\nstruct pbrMaterialUniforms {\n // Material is unlit\n unlit: u32,\n\n // Base color map\n baseColorMapEnabled: u32,\n baseColorFactor: vec4f,\n\n normalMapEnabled : u32,\n normalScale: f32, // #ifdef HAS_NORMALMAP\n\n emissiveMapEnabled: u32,\n emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP\n\n metallicRoughnessValues: vec2f,\n metallicRoughnessMapEnabled: u32,\n\n occlusionMapEnabled: i32,\n occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP\n \n alphaCutoffEnabled: i32,\n alphaCutoff: f32, // #ifdef ALPHA_CUTOFF\n\n specularColorFactor: vec3f,\n specularIntensityFactor: f32,\n specularColorMapEnabled: i32,\n specularIntensityMapEnabled: i32,\n\n ior: f32,\n\n transmissionFactor: f32,\n transmissionMapEnabled: i32,\n\n thicknessFactor: f32,\n attenuationDistance: f32,\n attenuationColor: vec3f,\n\n clearcoatFactor: f32,\n clearcoatRoughnessFactor: f32,\n clearcoatMapEnabled: i32,\n clearcoatRoughnessMapEnabled: i32,\n\n sheenColorFactor: vec3f,\n sheenRoughnessFactor: f32,\n sheenColorMapEnabled: i32,\n sheenRoughnessMapEnabled: i32,\n\n iridescenceFactor: f32,\n iridescenceIor: f32,\n iridescenceThicknessRange: vec2f,\n iridescenceMapEnabled: i32,\n\n anisotropyStrength: f32,\n anisotropyRotation: f32,\n anisotropyDirection: vec2f,\n anisotropyMapEnabled: i32,\n\n emissiveStrength: f32,\n dispersion: f32,\n \n // IBL\n IBLenabled: i32,\n scaleIBLAmbient: vec2f, // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n scaleDiffBaseMR: vec4f,\n scaleFGDSpec: vec4f,\n // #endif\n\n baseColorUVSet: i32,\n baseColorUVTransform: mat3x3f,\n metallicRoughnessUVSet: i32,\n metallicRoughnessUVTransform: mat3x3f,\n normalUVSet: i32,\n normalUVTransform: mat3x3f,\n occlusionUVSet: i32,\n occlusionUVTransform: mat3x3f,\n emissiveUVSet: i32,\n emissiveUVTransform: mat3x3f,\n specularColorUVSet: i32,\n specularColorUVTransform: mat3x3f,\n specularIntensityUVSet: i32,\n specularIntensityUVTransform: mat3x3f,\n transmissionUVSet: i32,\n transmissionUVTransform: mat3x3f,\n thicknessUVSet: i32,\n thicknessUVTransform: mat3x3f,\n clearcoatUVSet: i32,\n clearcoatUVTransform: mat3x3f,\n clearcoatRoughnessUVSet: i32,\n clearcoatRoughnessUVTransform: mat3x3f,\n clearcoatNormalUVSet: i32,\n clearcoatNormalUVTransform: mat3x3f,\n sheenColorUVSet: i32,\n sheenColorUVTransform: mat3x3f,\n sheenRoughnessUVSet: i32,\n sheenRoughnessUVTransform: mat3x3f,\n iridescenceUVSet: i32,\n iridescenceUVTransform: mat3x3f,\n iridescenceThicknessUVSet: i32,\n iridescenceThicknessUVTransform: mat3x3f,\n anisotropyUVSet: i32,\n anisotropyUVTransform: mat3x3f,\n\n bumpFactor: f32,\n bumpMapEnabled: i32,\n diffuseTransmissionFactor: f32,\n diffuseTransmissionMapEnabled: i32,\n diffuseTransmissionColorFactor: vec3f,\n diffuseTransmissionColorMapEnabled: i32,\n multiscatterColorFactor: vec3f,\n multiscatterColorMapEnabled: i32,\n scatterAnisotropy: f32,\n\n bumpUVSet: i32,\n bumpUVTransform: mat3x3f,\n diffuseTransmissionUVSet: i32,\n diffuseTransmissionUVTransform: mat3x3f,\n diffuseTransmissionColorUVSet: i32,\n diffuseTransmissionColorUVTransform: mat3x3f,\n multiscatterColorUVSet: i32,\n multiscatterColorUVTransform: mat3x3f,\n}\n\n@group(3) @binding(auto) var<uniform> pbrMaterial : pbrMaterialUniforms;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\n@group(3) @binding(auto) var pbr_baseColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_baseColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_NORMALMAP\n@group(3) @binding(auto) var pbr_normalSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_normalSamplerSampler: sampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\n@group(3) @binding(auto) var pbr_emissiveSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_emissiveSamplerSampler: sampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\n@group(3) @binding(auto) var pbr_metallicRoughnessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_metallicRoughnessSamplerSampler: sampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\n@group(3) @binding(auto) var pbr_occlusionSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_occlusionSamplerSampler: sampler;\n#endif\n#ifdef HAS_SPECULARCOLORMAP\n@group(3) @binding(auto) var pbr_specularColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_specularColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_SPECULARINTENSITYMAP\n@group(3) @binding(auto) var pbr_specularIntensitySampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_specularIntensitySamplerSampler: sampler;\n#endif\n#ifdef HAS_TRANSMISSIONMAP\n@group(3) @binding(auto) var pbr_transmissionSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_transmissionSamplerSampler: sampler;\n#endif\n#ifdef HAS_THICKNESSMAP\n@group(3) @binding(auto) var pbr_thicknessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_thicknessSamplerSampler: sampler;\n#endif\n#ifdef HAS_CLEARCOATMAP\n@group(3) @binding(auto) var pbr_clearcoatSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_clearcoatSamplerSampler: sampler;\n#endif\n#ifdef HAS_CLEARCOATROUGHNESSMAP\n@group(3) @binding(auto) var pbr_clearcoatRoughnessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_clearcoatRoughnessSamplerSampler: sampler;\n#endif\n#ifdef HAS_CLEARCOATNORMALMAP\n@group(3) @binding(auto) var pbr_clearcoatNormalSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_clearcoatNormalSamplerSampler: sampler;\n#endif\n#ifdef HAS_SHEENCOLORMAP\n@group(3) @binding(auto) var pbr_sheenColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_sheenColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_SHEENROUGHNESSMAP\n@group(3) @binding(auto) var pbr_sheenRoughnessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_sheenRoughnessSamplerSampler: sampler;\n#endif\n#ifdef HAS_IRIDESCENCEMAP\n@group(3) @binding(auto) var pbr_iridescenceSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_iridescenceSamplerSampler: sampler;\n#endif\n#ifdef HAS_IRIDESCENCETHICKNESSMAP\n@group(3) @binding(auto) var pbr_iridescenceThicknessSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_iridescenceThicknessSamplerSampler: sampler;\n#endif\n#ifdef HAS_ANISOTROPYMAP\n@group(3) @binding(auto) var pbr_anisotropySampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_anisotropySamplerSampler: sampler;\n#endif\n#ifdef HAS_BUMPMAP\n@group(3) @binding(auto) var pbr_bumpSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_bumpSamplerSampler: sampler;\n#endif\n#ifdef HAS_DIFFUSETRANSMISSIONMAP\n@group(3) @binding(auto) var pbr_diffuseTransmissionSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_diffuseTransmissionSamplerSampler: sampler;\n#endif\n#ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP\n@group(3) @binding(auto) var pbr_diffuseTransmissionColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_diffuseTransmissionColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_MULTISCATTERCOLORMAP\n@group(3) @binding(auto) var pbr_multiscatterColorSampler: texture_2d<f32>;\n@group(3) @binding(auto) var pbr_multiscatterColorSamplerSampler: sampler;\n#endif\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n NdotL: f32, // cos angle between normal and light direction\n NdotV: f32, // cos angle between normal and view direction\n NdotH: f32, // cos angle between normal and half vector\n LdotH: f32, // cos angle between light direction and half vector\n VdotH: f32, // cos angle between view direction and half vector\n perceptualRoughness: f32, // roughness value, as authored by the model creator (input to shader)\n metalness: f32, // metallic value at the surface\n reflectance0: vec3f, // full reflectance color (normal incidence angle)\n reflectance90: vec3f, // reflectance color at grazing angle\n alphaRoughness: f32, // roughness mapped to a more linear change in the roughness (proposed by [2])\n diffuseColor: vec3f, // color contribution from diffuse lighting\n specularColor: vec3f, // color contribution from specular lighting\n n: vec3f, // normal at surface point\n v: vec3f, // vector from surface point to camera\n l: vec3f, // direction from the surface toward the current light\n h: vec3f // half vector between the current light and camera\n};\n\nconst M_PI = 3.141592653589793;\nconst c_MinRoughness = 0.04;\n\n// Widen sub-pixel specular lobes using the screen-space normal footprint.\n// This is geometric specular antialiasing: the normal variance is converted\n// into an additional squared perceptual roughness before evaluating BRDFs.\nfn widenSpecularRoughness(perceptualRoughness: f32, normal: vec3f) -> f32 {\n let normalDerivativeX = dpdx(normal);\n let normalDerivativeY = dpdy(normal);\n let normalVariance =\n dot(normalDerivativeX, normalDerivativeX) +\n dot(normalDerivativeY, normalDerivativeY);\n let kernelRoughnessSquared = min(2.0 * normalVariance, 1.0);\n return clamp(\n sqrt(perceptualRoughness * perceptualRoughness + kernelRoughnessSquared),\n c_MinRoughness,\n 1.0\n );\n}\n\nfn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f\n{\n var linOut: vec3f = srgbIn.xyz;\n#ifdef MANUAL_SRGB\n let bLess: vec3f = step(vec3f(0.04045), srgbIn.xyz);\n linOut = mix(\n srgbIn.xyz / vec3f(12.92),\n pow((srgbIn.xyz + vec3f(0.055)) / vec3f(1.055), vec3f(2.4)),\n bLess\n );\n#ifdef SRGB_FAST_APPROXIMATION\n linOut = pow(srgbIn.xyz, vec3f(2.2));\n#endif\n#endif\n return vec4f(linOut, srgbIn.w);\n}\n\nfn getMaterialUV(uvSet: i32, uvTransform: mat3x3f) -> vec2f\n{\n var baseUV = fragmentInputs.pbr_vUV0;\n if (uvSet == 1) {\n baseUV = fragmentInputs.pbr_vUV1;\n }\n return (uvTransform * vec3f(baseUV, 1.0)).xy;\n}\n\n// Build the tangent basis from interpolated attributes or screen-space derivatives.\nfn getTBN(uv: vec2f) -> mat3x3f\n{\n let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);\n let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);\n let tex_dx: vec3f = dpdx(vec3f(uv, 0.0));\n let tex_dy: vec3f = dpdy(vec3f(uv, 0.0));\n var t: vec3f = (tex_dy.y * pos_dx - tex_dx.y * pos_dy) / (tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y);\n\n var ng: vec3f = cross(pos_dy, pos_dx);\n#ifdef HAS_NORMALS\n ng = normalize(fragmentInputs.pbr_vNormal);\n#endif\n t = normalize(t - ng * dot(ng, t));\n var b: vec3f = normalize(cross(ng, t));\n var tbn: mat3x3f = mat3x3f(t, b, ng);\n#ifdef HAS_TANGENTS\n tbn = fragmentInputs.pbr_vTBN;\n#endif\n\n return tbn;\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nfn getMappedNormal(\n normalSampler: texture_2d<f32>,\n normalSamplerBinding: sampler,\n tbn: mat3x3f,\n normalScale: f32,\n uv: vec2f\n) -> vec3f\n{\n let n = textureSample(normalSampler, normalSamplerBinding, uv).rgb;\n return normalize(tbn * ((2.0 * n - 1.0) * vec3f(normalScale, normalScale, 1.0)));\n}\n\nfn getNormal(tbn: mat3x3f, uv: vec2f) -> vec3f\n{\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n var n: vec3f = normalize(tbn[2].xyz);\n#ifdef HAS_NORMALMAP\n n = getMappedNormal(\n pbr_normalSampler,\n pbr_normalSamplerSampler,\n tbn,\n pbrMaterial.normalScale,\n uv\n );\n#endif\n\n#ifdef HAS_BUMPMAP\n let bumpUV = getMaterialUV(pbrMaterial.bumpUVSet, pbrMaterial.bumpUVTransform);\n let bumpTexelSize = 1.0 / vec2f(textureDimensions(pbr_bumpSampler, 0));\n let bumpHeight = textureSample(pbr_bumpSampler, pbr_bumpSamplerSampler, bumpUV).r;\n let bumpGradient = vec2f(\n textureSample(\n pbr_bumpSampler,\n pbr_bumpSamplerSampler,\n bumpUV + vec2f(bumpTexelSize.x, 0.0)\n ).r - bumpHeight,\n textureSample(\n pbr_bumpSampler,\n pbr_bumpSamplerSampler,\n bumpUV + vec2f(0.0, bumpTexelSize.y)\n ).r - bumpHeight\n );\n n = normalize(n - pbrMaterial.bumpFactor *\n (tbn[0] * bumpGradient.x + tbn[1] * bumpGradient.y));\n#endif\n\n return n;\n}\n\nfn getClearcoatNormal(tbn: mat3x3f, baseNormal: vec3f, uv: vec2f) -> vec3f\n{\n#ifdef HAS_CLEARCOATNORMALMAP\n return getMappedNormal(\n pbr_clearcoatNormalSampler,\n pbr_clearcoatNormalSamplerSampler,\n tbn,\n 1.0,\n uv\n );\n#else\n return baseNormal;\n#endif\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nfn getIBLContribution(pbrInfo: PBRInfo, n: vec3f, reflection: vec3f) -> vec3f\n{\n#ifdef USE_SCENE_ENVIRONMENT\n let maximumMipLevel = max(pbrScene.environmentMipCount - 1.0, 0.0);\n let rotationSine = sin(pbrScene.environmentRotation);\n let rotationCosine = cos(pbrScene.environmentRotation);\n let environmentRotation = mat2x2f(\n vec2f(rotationCosine, rotationSine),\n vec2f(-rotationSine, rotationCosine)\n );\n let rotatedNormal = environmentRotation * n.xz;\n let rotatedReflection = environmentRotation * reflection.xz;\n let environmentNormal = vec3f(rotatedNormal.x, n.y, rotatedNormal.y);\n let environmentReflection = vec3f(rotatedReflection.x, reflection.y, rotatedReflection.y);\n#else\n let maximumMipLevel = 9.0;\n let environmentNormal = n;\n let environmentReflection = reflection;\n#endif\n let lod = pbrInfo.perceptualRoughness * maximumMipLevel;\n // retrieve a scale and bias to F0. See [1], Figure 3\n let brdfSample = textureSampleLevel(\n pbr_brdfLUT,\n pbr_brdfLUTSampler,\n vec2f(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness),\n 0.0\n );\n let diffuseSample = textureSampleLevel(\n pbr_diffuseEnvSampler,\n pbr_diffuseEnvSamplerSampler,\n environmentNormal,\n 0.0\n );\n var specularSample = textureSampleLevel(\n pbr_specularEnvSampler,\n pbr_specularEnvSamplerSampler,\n environmentReflection,\n 0.0\n );\n#ifdef USE_TEX_LOD\n specularSample = textureSampleLevel(\n pbr_specularEnvSampler,\n pbr_specularEnvSamplerSampler,\n environmentReflection,\n lod\n );\n#endif\n\n#ifdef USE_SCENE_ENVIRONMENT\n let brdf = brdfSample.rgb;\n let diffuseLight = diffuseSample.rgb;\n let specularLight = specularSample.rgb;\n#else\n let brdf = SRGBtoLINEAR(brdfSample).rgb;\n let diffuseLight = SRGBtoLINEAR(diffuseSample).rgb;\n let specularLight = SRGBtoLINEAR(specularSample).rgb;\n#endif\n\n let diffuse = diffuseLight * pbrInfo.diffuseColor * pbrMaterial.scaleIBLAmbient.x;\n let specular =\n specularLight * (pbrInfo.specularColor * brdf.x + brdf.y) * pbrMaterial.scaleIBLAmbient.y;\n\n#ifdef USE_SCENE_ENVIRONMENT\n return (diffuse + specular) * max(pbrScene.environmentIntensity, 0.0);\n#else\n return diffuse + specular;\n#endif\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nfn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nfn specularReflection(pbrInfo: PBRInfo) -> vec3<f32> {\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {\n let NdotL: f32 = pbrInfo.NdotL;\n let NdotV: f32 = pbrInfo.NdotV;\n let r: f32 = pbrInfo.alphaRoughness;\n\n let attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n let attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {\n let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nfn maxComponent(value: vec3f) -> f32 {\n return max(max(value.r, value.g), value.b);\n}\n\nfn getDielectricF0(ior: f32) -> f32 {\n let clampedIor = max(ior, 1.0);\n let ratio = (clampedIor - 1.0) / (clampedIor + 1.0);\n return ratio * ratio;\n}\n\nfn normalizeDirection(direction: vec2f) -> vec2f {\n let directionLength = length(direction);\n if (directionLength > 0.0001) {\n return direction / directionLength;\n }\n\n return vec2f(1.0, 0.0);\n}\n\nfn rotateDirection(direction: vec2f, rotation: f32) -> vec2f {\n let s = sin(rotation);\n let c = cos(rotation);\n return vec2f(direction.x * c - direction.y * s, direction.x * s + direction.y * c);\n}\n\nfn encodeLinearSRGB(linearColor: vec3f) -> vec3f {\n let positiveColor = max(linearColor, vec3f(0.0));\n return select(\n positiveColor * 12.92,\n 1.055 * pow(positiveColor, vec3f(1.0 / 2.4)) - 0.055,\n positiveColor > vec3f(0.0031308)\n );\n}\n\nfn toneMapKhronosPBRNeutral(inputColor: vec3f) -> vec3f {\n let startCompression = 0.76;\n let darkestChannel = min(inputColor.r, min(inputColor.g, inputColor.b));\n let offset = select(\n 0.04,\n darkestChannel - 6.25 * darkestChannel * darkestChannel,\n darkestChannel < 0.08\n );\n var color = inputColor - vec3f(offset);\n let peak = maxComponent(color);\n if (peak < startCompression) {\n return color;\n }\n\n let compressionRange = 1.0 - startCompression;\n let compressedPeak = 1.0 - compressionRange * compressionRange /\n (peak + compressionRange - startCompression);\n color *= compressedPeak / max(peak, 0.0001);\n let desaturation = 1.0 - 1.0 / (0.15 * (peak - compressedPeak) + 1.0);\n return mix(color, vec3f(compressedPeak), desaturation);\n}\n\nfn applySceneColorManagement(sceneColor: vec3f) -> vec3f {\n#ifdef USE_SCENE_COLOR_MANAGEMENT\n var color = max(sceneColor, vec3f(0.0)) * max(pbrScene.exposure, 0.0);\n if (pbrScene.toneMapMode == 1) {\n color /= vec3f(1.0) + color;\n } else if (pbrScene.toneMapMode == 2) {\n color = toneMapKhronosPBRNeutral(color);\n } else if (pbrScene.toneMapMode == 3) {\n color = clamp(\n (color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14),\n vec3f(0.0),\n vec3f(1.0)\n );\n }\n if (pbrScene.outputEncoding == 0) {\n return color;\n }\n return encodeLinearSRGB(color);\n#else\n return pow(max(sceneColor, vec3f(0.0)), vec3f(1.0 / 2.2));\n#endif\n}\n\nfn dielectricSchlick(reflectance: f32, cosine: f32) -> f32 {\n return reflectance + (1.0 - reflectance) * pow(clamp(1.0 - cosine, 0.0, 1.0), 5.0);\n}\n\nfn evaluateIridescenceSensitivity(opticalPathDifference: f32, phaseShift: vec3f) -> vec3f {\n let phase = 2.0 * M_PI * opticalPathDifference * 1.0e-9;\n let sensitivity = vec3f(5.4856e-13, 4.4201e-13, 5.2481e-13);\n let position = vec3f(1.6810e6, 1.7953e6, 2.2084e6);\n let variance = vec3f(4.3278e9, 9.3046e9, 6.6121e9);\n var xyz = sensitivity * sqrt(2.0 * M_PI * variance) *\n cos(position * phase + phaseShift) * exp(-phase * phase * variance);\n xyz.x += 9.7470e-14 * sqrt(2.0 * M_PI * 4.5282e9) *\n cos(2.2399e6 * phase + phaseShift.x) * exp(-4.5282e9 * phase * phase);\n xyz /= 1.0685e-7;\n return mat3x3f(\n vec3f(3.2404542, -0.9692660, 0.0556434),\n vec3f(-1.5371385, 1.8760108, -0.2040259),\n vec3f(-0.4985314, 0.0415560, 1.0572252)\n ) * xyz;\n}\n\nfn getIridescenceTint(\n iridescence: f32,\n thickness: f32,\n NdotV: f32,\n baseReflectance: vec3f\n) -> vec3f {\n if (iridescence <= 0.0 || thickness <= 0.0) {\n return baseReflectance;\n }\n\n let filmIor = max(pbrMaterial.iridescenceIor, 1.0);\n let sineSquared = (1.0 - NdotV * NdotV) / (filmIor * filmIor);\n let cosineSquared = 1.0 - sineSquared;\n if (cosineSquared <= 0.0) {\n return mix(baseReflectance, vec3f(1.0), iridescence);\n }\n let filmCosine = sqrt(cosineSquared);\n let firstInterfaceReflectance = dielectricSchlick(getDielectricF0(filmIor), NdotV);\n let transmittedEnergy = 1.0 - firstInterfaceReflectance;\n let squareRootReflectance = sqrt(clamp(baseReflectance, vec3f(0.0), vec3f(0.9999)));\n let baseIor = (vec3f(1.0) + squareRootReflectance) /\n (vec3f(1.0) - squareRootReflectance);\n var secondInterfaceF0 = (baseIor - vec3f(filmIor)) / (baseIor + vec3f(filmIor));\n secondInterfaceF0 *= secondInterfaceF0;\n let secondInterfaceReflectance = secondInterfaceF0 +\n (vec3f(1.0) - secondInterfaceF0) * pow(1.0 - filmCosine, 5.0);\n let phaseShift = vec3f(M_PI) + select(\n vec3f(0.0),\n vec3f(M_PI),\n baseIor < vec3f(filmIor)\n );\n let opticalPathDifference = 2.0 * filmIor * thickness * filmCosine;\n let combinedReflectance = clamp(\n firstInterfaceReflectance * secondInterfaceReflectance,\n vec3f(0.00001),\n vec3f(0.9999)\n );\n let recurringAmplitude = sqrt(combinedReflectance);\n let interfaceResponse = transmittedEnergy * transmittedEnergy * secondInterfaceReflectance /\n (vec3f(1.0) - combinedReflectance);\n var reflectedSpectrum = vec3f(firstInterfaceReflectance) + interfaceResponse;\n var harmonicAmplitude = interfaceResponse - vec3f(transmittedEnergy);\n for (var harmonic = 1; harmonic <= 2; harmonic++) {\n harmonicAmplitude *= recurringAmplitude;\n reflectedSpectrum += harmonicAmplitude * 2.0 * evaluateIridescenceSensitivity(\n f32(harmonic) * opticalPathDifference,\n f32(harmonic) * phaseShift\n );\n }\n return mix(baseReflectance, clamp(reflectedSpectrum, vec3f(0.0), vec3f(1.0)), iridescence);\n}\n\nfn getVolumeAttenuation(thickness: f32) -> vec3f {\n if (thickness <= 0.0) {\n return vec3f(1.0);\n }\n\n let attenuationCoefficient =\n -log(max(pbrMaterial.attenuationColor, vec3f(0.0001))) /\n max(pbrMaterial.attenuationDistance, 0.0001);\n return exp(-attenuationCoefficient * thickness);\n}\n\n// KHR_materials_volume_scatter is an active draft. This evaluates a local,\n// thickness-aware single-scattering approximation rather than random walk.\nfn getDiffuseTransmissionAttenuation(\n pbrInfo: PBRInfo,\n multiscatterColor: vec3f,\n thickness: f32\n) -> vec3f {\n let volumeAttenuation = getVolumeAttenuation(thickness);\n let scatteringStrength = maxComponent(multiscatterColor);\n if (thickness <= 0.0 || scatteringStrength <= 0.0001) {\n return volumeAttenuation;\n }\n\n let anisotropy = clamp(pbrMaterial.scatterAnisotropy, -0.95, 0.95);\n let scatteringCosine = clamp(dot(-pbrInfo.v, pbrInfo.l), -1.0, 1.0);\n let phaseDenominator = max(\n 1.0 + anisotropy * anisotropy - 2.0 * anisotropy * scatteringCosine,\n 0.0001\n );\n let phaseWeight = clamp(\n (1.0 - anisotropy * anisotropy) / pow(phaseDenominator, 1.5),\n 0.0,\n 4.0\n );\n let scatteringDepth = thickness / max(pbrMaterial.attenuationDistance, 0.0001);\n let scatteringProbability = 1.0 - exp(-scatteringDepth);\n let scatteringColor = clamp(multiscatterColor, vec3f(0.0), vec3f(1.0));\n return mix(\n volumeAttenuation,\n volumeAttenuation * mix(vec3f(1.0), scatteringColor * phaseWeight, scatteringColor),\n scatteringProbability\n );\n}\n\nfn calculateDiffuseTransmissionLight(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n diffuseTransmissionColor: vec3f,\n diffuseTransmission: f32,\n multiscatterColor: vec3f,\n thickness: f32\n) -> vec3f {\n let oppositeHemisphere = max(dot(-pbrInfo.n, pbrInfo.l), 0.0);\n if (oppositeHemisphere <= 0.0 || diffuseTransmission <= 0.0) {\n return vec3f(0.0);\n }\n\n let nonReflectedEnergy = vec3f(1.0) - clamp(pbrInfo.reflectance0, vec3f(0.0), vec3f(1.0));\n let attenuatedColor = getDiffuseTransmissionAttenuation(\n pbrInfo,\n multiscatterColor,\n thickness\n );\n return lightColor * diffuseTransmissionColor * nonReflectedEnergy *\n attenuatedColor * (diffuseTransmission * oppositeHemisphere / M_PI);\n}\n\n#ifdef USE_IBL\nfn calculateDiffuseTransmissionIBL(\n pbrInfo: PBRInfo,\n diffuseTransmissionColor: vec3f,\n diffuseTransmission: f32,\n multiscatterColor: vec3f,\n thickness: f32\n) -> vec3f {\n if (diffuseTransmission <= 0.0) {\n return vec3f(0.0);\n }\n\n#ifdef USE_SCENE_ENVIRONMENT\n let rotationSine = sin(pbrScene.environmentRotation);\n let rotationCosine = cos(pbrScene.environmentRotation);\n let environmentRotation = mat2x2f(\n vec2f(rotationCosine, rotationSine),\n vec2f(-rotationSine, rotationCosine)\n );\n let rotatedNormal = environmentRotation * -pbrInfo.n.xz;\n let oppositeNormal = vec3f(rotatedNormal.x, -pbrInfo.n.y, rotatedNormal.y);\n let environmentColor = textureSampleLevel(\n pbr_diffuseEnvSampler,\n pbr_diffuseEnvSamplerSampler,\n oppositeNormal,\n 0.0\n ).rgb * max(pbrScene.environmentIntensity, 0.0);\n#else\n let environmentColor = SRGBtoLINEAR(\n textureSampleLevel(pbr_diffuseEnvSampler, pbr_diffuseEnvSamplerSampler, -pbrInfo.n, 0.0)\n ).rgb;\n#endif\n let nonReflectedEnergy = vec3f(1.0) - clamp(pbrInfo.reflectance0, vec3f(0.0), vec3f(1.0));\n return environmentColor * diffuseTransmissionColor * nonReflectedEnergy *\n getDiffuseTransmissionAttenuation(pbrInfo, multiscatterColor, thickness) *\n diffuseTransmission * pbrMaterial.scaleIBLAmbient.x;\n}\n#endif\n\n#ifdef USE_TRANSMISSION_FRAMEBUFFER\nfn sampleTransmittedSceneColor(\n position: vec3f,\n normal: vec3f,\n viewDirection: vec3f,\n thickness: f32,\n perceptualRoughness: f32,\n indexOfRefraction: f32\n) -> vec3f {\n let refractionDirection = refract(\n -viewDirection,\n normal,\n 1.0 / max(indexOfRefraction, 1.0)\n );\n let refractedPosition = position + refractionDirection * thickness;\n let clipPosition = pbrScene.projectionMatrix *\n pbrScene.viewMatrix * vec4f(refractedPosition, 1.0);\n var textureCoordinate = clipPosition.xy / max(clipPosition.w, 0.0001) * 0.5 + 0.5;\n textureCoordinate.y = 1.0 - textureCoordinate.y;\n textureCoordinate = clamp(textureCoordinate, vec2f(0.001), vec2f(0.999));\n\n let blurRadius = perceptualRoughness * perceptualRoughness * 8.0 /\n max(pbrScene.framebufferSize, vec2f(1.0));\n var sceneColor = textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate,\n 0.0\n ).rgb * 0.4;\n sceneColor += textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate + vec2f(blurRadius.x, 0.0),\n 0.0\n ).rgb * 0.15;\n sceneColor += textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate - vec2f(blurRadius.x, 0.0),\n 0.0\n ).rgb * 0.15;\n sceneColor += textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate + vec2f(0.0, blurRadius.y),\n 0.0\n ).rgb * 0.15;\n sceneColor += textureSampleLevel(\n pbr_transmissionFramebufferSampler,\n pbr_transmissionFramebufferSamplerSampler,\n textureCoordinate - vec2f(0.0, blurRadius.y),\n 0.0\n ).rgb * 0.15;\n return max(sceneColor, vec3f(0.0));\n}\n\nfn getTransmittedSceneColor(\n position: vec3f,\n normal: vec3f,\n viewDirection: vec3f,\n thickness: f32,\n perceptualRoughness: f32\n) -> vec3f {\n if (pbrMaterial.dispersion <= 0.0) {\n return sampleTransmittedSceneColor(\n position,\n normal,\n viewDirection,\n thickness,\n perceptualRoughness,\n pbrMaterial.ior\n );\n }\n\n let halfSpread = (max(pbrMaterial.ior, 1.0) - 1.0) * 0.025 * pbrMaterial.dispersion;\n let indicesOfRefraction = max(\n vec3f(pbrMaterial.ior - halfSpread, pbrMaterial.ior, pbrMaterial.ior + halfSpread),\n vec3f(1.0)\n );\n return vec3f(\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.r\n ).r,\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.g\n ).g,\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.b\n ).b\n );\n}\n#endif\n\nfn createClearcoatPBRInfo(\n basePBRInfo: PBRInfo,\n clearcoatNormal: vec3f,\n clearcoatRoughness: f32\n) -> PBRInfo {\n let perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);\n let alphaRoughness = perceptualRoughness * perceptualRoughness;\n let NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);\n\n return PBRInfo(\n basePBRInfo.NdotL,\n NdotV,\n basePBRInfo.NdotH,\n basePBRInfo.LdotH,\n basePBRInfo.VdotH,\n perceptualRoughness,\n 0.0,\n vec3f(0.04),\n vec3f(1.0),\n alphaRoughness,\n vec3f(0.0),\n vec3f(0.04),\n clearcoatNormal,\n basePBRInfo.v,\n basePBRInfo.l,\n basePBRInfo.h\n );\n}\n\nfn calculateClearcoatContribution(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n clearcoatNormal: vec3f,\n clearcoatFactor: f32,\n clearcoatRoughness: f32\n) -> vec3f {\n if (clearcoatFactor <= 0.0) {\n return vec3f(0.0);\n }\n\n let clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);\n return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;\n}\n\n#ifdef USE_IBL\nfn calculateClearcoatIBLContribution(\n pbrInfo: PBRInfo,\n clearcoatNormal: vec3f,\n reflection: vec3f,\n clearcoatFactor: f32,\n clearcoatRoughness: f32\n) -> vec3f {\n if (clearcoatFactor <= 0.0) {\n return vec3f(0.0);\n }\n\n let clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);\n return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;\n}\n#endif\n\nfn calculateSheenContribution(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n sheenColor: vec3f,\n sheenRoughness: f32\n) -> vec3f {\n if (maxComponent(sheenColor) <= 0.0) {\n return vec3f(0.0);\n }\n\n let alpha = max(sheenRoughness * sheenRoughness, 0.0001);\n let inverseAlpha = 1.0 / alpha;\n let sineSquared = max(1.0 - pbrInfo.NdotH * pbrInfo.NdotH, 0.0);\n let distribution = (2.0 + inverseAlpha) * pow(sineSquared, inverseAlpha * 0.5) /\n (2.0 * M_PI);\n let visibility = 1.0 / max(\n 4.0 * (pbrInfo.NdotL + pbrInfo.NdotV - pbrInfo.NdotL * pbrInfo.NdotV),\n 0.0001\n );\n return pbrInfo.NdotL * lightColor * sheenColor * distribution * visibility *\n (1.0 - pbrInfo.metalness);\n}\n\nfn calculateAnisotropicLightColor(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n anisotropyTangent: vec3f,\n anisotropyStrength: f32\n) -> vec3f {\n if (anisotropyStrength <= 0.0) {\n return calculateFinalColor(pbrInfo, lightColor);\n }\n\n let anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));\n let tangentRoughness = mix(\n pbrInfo.alphaRoughness,\n 1.0,\n anisotropyStrength * anisotropyStrength\n );\n let bitangentRoughness = clamp(pbrInfo.alphaRoughness, 0.001, 1.0);\n let roughnessProduct = tangentRoughness * bitangentRoughness;\n let distributionVector = vec3f(\n bitangentRoughness * dot(anisotropyTangent, pbrInfo.h),\n tangentRoughness * dot(anisotropyBitangent, pbrInfo.h),\n roughnessProduct * pbrInfo.NdotH\n );\n let distributionFactor = roughnessProduct /\n max(dot(distributionVector, distributionVector), 0.000001);\n let distribution = roughnessProduct * distributionFactor * distributionFactor / M_PI;\n let viewMask = pbrInfo.NdotL * length(vec3f(\n tangentRoughness * dot(anisotropyTangent, pbrInfo.v),\n bitangentRoughness * dot(anisotropyBitangent, pbrInfo.v),\n pbrInfo.NdotV\n ));\n let lightMask = pbrInfo.NdotV * length(vec3f(\n tangentRoughness * dot(anisotropyTangent, pbrInfo.l),\n bitangentRoughness * dot(anisotropyBitangent, pbrInfo.l),\n pbrInfo.NdotL\n ));\n let visibility = clamp(0.5 / max(viewMask + lightMask, 0.000001), 0.0, 1.0);\n let fresnel = specularReflection(pbrInfo);\n let diffuseContribution = (vec3f(1.0) - fresnel) * diffuse(pbrInfo);\n return pbrInfo.NdotL * lightColor *\n (diffuseContribution + fresnel * distribution * visibility);\n}\n\nfn getAnisotropicReflection(\n pbrInfo: PBRInfo,\n anisotropyTangent: vec3f,\n anisotropyStrength: f32\n) -> vec3f {\n if (anisotropyStrength <= 0.0) {\n return -normalize(reflect(pbrInfo.v, pbrInfo.n));\n }\n let anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));\n var anisotropicNormal = normalize(cross(anisotropyBitangent, pbrInfo.v));\n anisotropicNormal = normalize(cross(anisotropicNormal, anisotropyBitangent));\n let bend = anisotropyStrength * (1.0 - pbrInfo.perceptualRoughness);\n return -normalize(reflect(pbrInfo.v, normalize(mix(pbrInfo.n, anisotropicNormal, bend))));\n}\n\nfn calculateMaterialLightColor(\n pbrInfo: PBRInfo,\n lightColor: vec3f,\n clearcoatNormal: vec3f,\n clearcoatFactor: f32,\n clearcoatRoughness: f32,\n sheenColor: vec3f,\n sheenRoughness: f32,\n anisotropyTangent: vec3f,\n anisotropyStrength: f32\n) -> vec3f {\n var color = calculateAnisotropicLightColor(\n pbrInfo,\n lightColor,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateClearcoatContribution(\n pbrInfo,\n lightColor,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness\n );\n color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);\n return color;\n}\n\nfn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {\n (*pbrInfo).NdotL = 1.0;\n (*pbrInfo).NdotH = 0.0;\n (*pbrInfo).LdotH = 0.0;\n (*pbrInfo).VdotH = 1.0;\n (*pbrInfo).l = (*pbrInfo).n;\n (*pbrInfo).h = (*pbrInfo).n;\n}\n\nfn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection: vec3<f32>) {\n let n = (*pbrInfo).n;\n let v = (*pbrInfo).v;\n let l = normalize(lightDirection); // Vector from surface point to light\n let h = normalize(l + v); // Half vector between both l and v\n\n (*pbrInfo).NdotL = clamp(dot(n, l), 0.001, 1.0);\n (*pbrInfo).NdotH = clamp(dot(n, h), 0.0, 1.0);\n (*pbrInfo).LdotH = clamp(dot(l, h), 0.0, 1.0);\n (*pbrInfo).VdotH = clamp(dot(v, h), 0.0, 1.0);\n (*pbrInfo).l = l;\n (*pbrInfo).h = h;\n}\n\nfn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {\n let light_direction = normalize(pointLight.position - fragmentInputs.pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nfn PBRInfo_setSpotLight(pbrInfo: ptr<function, PBRInfo>, spotLight: SpotLight) {\n let light_direction = normalize(spotLight.position - fragmentInputs.pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nfn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {\n // Calculate the shading terms for the microfacet specular shading model\n let F = specularReflection(pbrInfo);\n let G = geometricOcclusion(pbrInfo);\n let D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n let diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n let specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nfn pbr_filterColor(vertexColor: vec4<f32>) -> vec4<f32> {\n let baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);\n let metallicRoughnessUV = getMaterialUV(\n pbrMaterial.metallicRoughnessUVSet,\n pbrMaterial.metallicRoughnessUVTransform\n );\n let normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);\n let occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);\n let emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);\n let specularColorUV = getMaterialUV(\n pbrMaterial.specularColorUVSet,\n pbrMaterial.specularColorUVTransform\n );\n let specularIntensityUV = getMaterialUV(\n pbrMaterial.specularIntensityUVSet,\n pbrMaterial.specularIntensityUVTransform\n );\n let transmissionUV = getMaterialUV(\n pbrMaterial.transmissionUVSet,\n pbrMaterial.transmissionUVTransform\n );\n let thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);\n let clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);\n let clearcoatRoughnessUV = getMaterialUV(\n pbrMaterial.clearcoatRoughnessUVSet,\n pbrMaterial.clearcoatRoughnessUVTransform\n );\n let clearcoatNormalUV = getMaterialUV(\n pbrMaterial.clearcoatNormalUVSet,\n pbrMaterial.clearcoatNormalUVTransform\n );\n let sheenColorUV = getMaterialUV(\n pbrMaterial.sheenColorUVSet,\n pbrMaterial.sheenColorUVTransform\n );\n let sheenRoughnessUV = getMaterialUV(\n pbrMaterial.sheenRoughnessUVSet,\n pbrMaterial.sheenRoughnessUVTransform\n );\n let iridescenceUV = getMaterialUV(\n pbrMaterial.iridescenceUVSet,\n pbrMaterial.iridescenceUVTransform\n );\n let iridescenceThicknessUV = getMaterialUV(\n pbrMaterial.iridescenceThicknessUVSet,\n pbrMaterial.iridescenceThicknessUVTransform\n );\n let anisotropyUV = getMaterialUV(\n pbrMaterial.anisotropyUVSet,\n pbrMaterial.anisotropyUVTransform\n );\n let diffuseTransmissionUV = getMaterialUV(\n pbrMaterial.diffuseTransmissionUVSet,\n pbrMaterial.diffuseTransmissionUVTransform\n );\n let diffuseTransmissionColorUV = getMaterialUV(\n pbrMaterial.diffuseTransmissionColorUVSet,\n pbrMaterial.diffuseTransmissionColorUVTransform\n );\n let multiscatterColorUV = getMaterialUV(\n pbrMaterial.multiscatterColorUVSet,\n pbrMaterial.multiscatterColorUVTransform\n );\n\n // The albedo may be defined from a base texture or a flat color\n var baseColor: vec4<f32> = pbrMaterial.baseColorFactor * vertexColor;\n #ifdef HAS_BASECOLORMAP\n baseColor = SRGBtoLINEAR(\n textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, baseColorUV)\n ) * pbrMaterial.baseColorFactor * vertexColor;\n #endif\n\n #ifdef ALPHA_CUTOFF\n if (baseColor.a < pbrMaterial.alphaCutoff) {\n discard;\n }\n #endif\n\n var color = vec3<f32>(0.0, 0.0, 0.0);\n var transmission = 0.0;\n\n if (pbrMaterial.unlit != 0u) {\n color = baseColor.rgb;\n } else {\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n var perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;\n var metallic = pbrMaterial.metallicRoughnessValues.x;\n #ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n let mrSample = textureSample(\n pbr_metallicRoughnessSampler,\n pbr_metallicRoughnessSamplerSampler,\n metallicRoughnessUV\n );\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n #endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n let tbn = getTBN(normalUV);\n let n = getNormal(tbn, normalUV); // normal at surface point\n perceptualRoughness = widenSpecularRoughness(perceptualRoughness, n);\n let v = normalize(pbrProjection.camera - fragmentInputs.pbr_vPosition); // Vector from surface point to camera\n let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n var useExtendedPBR = false;\n #ifdef USE_MATERIAL_EXTENSIONS\n useExtendedPBR =\n pbrMaterial.specularColorMapEnabled != 0 ||\n pbrMaterial.specularIntensityMapEnabled != 0 ||\n abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||\n maxComponent(abs(pbrMaterial.specularColorFactor - vec3f(1.0))) > 0.0001 ||\n abs(pbrMaterial.ior - 1.5) > 0.0001 ||\n pbrMaterial.dispersion > 0.0001 ||\n pbrMaterial.transmissionMapEnabled != 0 ||\n pbrMaterial.transmissionFactor > 0.0001 ||\n pbrMaterial.diffuseTransmissionMapEnabled != 0 ||\n pbrMaterial.diffuseTransmissionColorMapEnabled != 0 ||\n pbrMaterial.diffuseTransmissionFactor > 0.0001 ||\n pbrMaterial.multiscatterColorMapEnabled != 0 ||\n maxComponent(pbrMaterial.multiscatterColorFactor) > 0.0001 ||\n pbrMaterial.clearcoatMapEnabled != 0 ||\n pbrMaterial.clearcoatRoughnessMapEnabled != 0 ||\n pbrMaterial.clearcoatFactor > 0.0001 ||\n pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||\n pbrMaterial.sheenColorMapEnabled != 0 ||\n pbrMaterial.sheenRoughnessMapEnabled != 0 ||\n maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||\n pbrMaterial.sheenRoughnessFactor > 0.0001 ||\n pbrMaterial.iridescenceMapEnabled != 0 ||\n pbrMaterial.iridescenceFactor > 0.0001 ||\n abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||\n abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||\n abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||\n pbrMaterial.anisotropyMapEnabled != 0 ||\n pbrMaterial.anisotropyStrength > 0.0001 ||\n abs(pbrMaterial.anisotropyRotation) > 0.0001 ||\n length(pbrMaterial.anisotropyDirection - vec2f(1.0, 0.0)) > 0.0001;\n #endif\n\n if (!useExtendedPBR) {\n let alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n let f0 = vec3<f32>(0.04);\n var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n let specularColor = mix(f0, baseColor.rgb, metallic);\n\n let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n let specularEnvironmentR0 = specularColor;\n let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;\n let reflection = -normalize(reflect(v, n));\n\n var pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v,\n n,\n n\n );\n\n #ifdef USE_LIGHTS\n PBRInfo_setAmbientLight(&pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting.ambientColor);\n\n for (var i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);\n }\n }\n\n for (var i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));\n let attenuation = getPointLightAttenuation(\n lighting_getPointLight(i),\n distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)\n );\n color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);\n }\n }\n\n for (var i = 0; i < lighting.spotLightCount; i++) {\n if (i < lighting.spotLightCount) {\n PBRInfo_setSpotLight(&pbrInfo, lighting_getSpotLight(i));\n let attenuation = getSpotLightAttenuation(\n lighting_getSpotLight(i),\n fragmentInputs.pbr_vPosition\n );\n color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);\n }\n }\n #endif\n\n #ifdef USE_IBL\n if (pbrMaterial.IBLenabled != 0) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n #endif\n\n #ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled != 0) {\n let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n #endif\n\n var emissive = pbrMaterial.emissiveFactor;\n #ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled != 0u) {\n emissive *= SRGBtoLINEAR(\n textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, emissiveUV)\n ).rgb;\n }\n #endif\n color += emissive * pbrMaterial.emissiveStrength;\n\n #ifdef PBR_DEBUG\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n #endif\n\n return vec4<f32>(applySceneColorManagement(color), baseColor.a);\n }\n\n var specularIntensity = pbrMaterial.specularIntensityFactor;\n #ifdef HAS_SPECULARINTENSITYMAP\n if (pbrMaterial.specularIntensityMapEnabled != 0) {\n specularIntensity *= textureSample(\n pbr_specularIntensitySampler,\n pbr_specularIntensitySamplerSampler,\n specularIntensityUV\n ).a;\n }\n #endif\n\n var specularFactor = pbrMaterial.specularColorFactor;\n #ifdef HAS_SPECULARCOLORMAP\n if (pbrMaterial.specularColorMapEnabled != 0) {\n specularFactor *= SRGBtoLINEAR(\n textureSample(\n pbr_specularColorSampler,\n pbr_specularColorSamplerSampler,\n specularColorUV\n )\n ).rgb;\n }\n #endif\n\n transmission = pbrMaterial.transmissionFactor;\n #ifdef HAS_TRANSMISSIONMAP\n if (pbrMaterial.transmissionMapEnabled != 0) {\n transmission *= textureSample(\n pbr_transmissionSampler,\n pbr_transmissionSamplerSampler,\n transmissionUV\n ).r;\n }\n #endif\n transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);\n var thickness = max(pbrMaterial.thicknessFactor, 0.0);\n #ifdef HAS_THICKNESSMAP\n thickness *= textureSample(\n pbr_thicknessSampler,\n pbr_thicknessSamplerSampler,\n thicknessUV\n ).g;\n #endif\n\n var diffuseTransmission = clamp(pbrMaterial.diffuseTransmissionFactor, 0.0, 1.0);\n #ifdef HAS_DIFFUSETRANSMISSIONMAP\n if (pbrMaterial.diffuseTransmissionMapEnabled != 0) {\n diffuseTransmission *= textureSample(\n pbr_diffuseTransmissionSampler,\n pbr_diffuseTransmissionSamplerSampler,\n diffuseTransmissionUV\n ).a;\n }\n #endif\n diffuseTransmission *= (1.0 - metallic) * (1.0 - transmission);\n var diffuseTransmissionColor = pbrMaterial.diffuseTransmissionColorFactor;\n #ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP\n if (pbrMaterial.diffuseTransmissionColorMapEnabled != 0) {\n diffuseTransmissionColor *= SRGBtoLINEAR(\n textureSample(\n pbr_diffuseTransmissionColorSampler,\n pbr_diffuseTransmissionColorSamplerSampler,\n diffuseTransmissionColorUV\n )\n ).rgb;\n }\n #endif\n var multiscatterColor = pbrMaterial.multiscatterColorFactor;\n #ifdef HAS_MULTISCATTERCOLORMAP\n if (pbrMaterial.multiscatterColorMapEnabled != 0) {\n multiscatterColor *= SRGBtoLINEAR(\n textureSample(\n pbr_multiscatterColorSampler,\n pbr_multiscatterColorSamplerSampler,\n multiscatterColorUV\n )\n ).rgb;\n }\n #endif\n\n var clearcoatFactor = pbrMaterial.clearcoatFactor;\n var clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;\n #ifdef HAS_CLEARCOATMAP\n if (pbrMaterial.clearcoatMapEnabled != 0) {\n clearcoatFactor *= textureSample(\n pbr_clearcoatSampler,\n pbr_clearcoatSamplerSampler,\n clearcoatUV\n ).r;\n }\n #endif\n #ifdef HAS_CLEARCOATROUGHNESSMAP\n if (pbrMaterial.clearcoatRoughnessMapEnabled != 0) {\n clearcoatRoughness *= textureSample(\n pbr_clearcoatRoughnessSampler,\n pbr_clearcoatRoughnessSamplerSampler,\n clearcoatRoughnessUV\n ).g;\n }\n #endif\n clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);\n clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);\n let clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);\n clearcoatRoughness = widenSpecularRoughness(clearcoatRoughness, clearcoatNormal);\n\n var sheenColor = pbrMaterial.sheenColorFactor;\n var sheenRoughness = pbrMaterial.sheenRoughnessFactor;\n #ifdef HAS_SHEENCOLORMAP\n if (pbrMaterial.sheenColorMapEnabled != 0) {\n sheenColor *= SRGBtoLINEAR(\n textureSample(\n pbr_sheenColorSampler,\n pbr_sheenColorSamplerSampler,\n sheenColorUV\n )\n ).rgb;\n }\n #endif\n #ifdef HAS_SHEENROUGHNESSMAP\n if (pbrMaterial.sheenRoughnessMapEnabled != 0) {\n sheenRoughness *= textureSample(\n pbr_sheenRoughnessSampler,\n pbr_sheenRoughnessSamplerSampler,\n sheenRoughnessUV\n ).a;\n }\n #endif\n sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);\n\n var iridescence = pbrMaterial.iridescenceFactor;\n #ifdef HAS_IRIDESCENCEMAP\n if (pbrMaterial.iridescenceMapEnabled != 0) {\n iridescence *= textureSample(\n pbr_iridescenceSampler,\n pbr_iridescenceSamplerSampler,\n iridescenceUV\n ).r;\n }\n #endif\n iridescence = clamp(iridescence, 0.0, 1.0);\n var iridescenceThickness = mix(\n pbrMaterial.iridescenceThicknessRange.x,\n pbrMaterial.iridescenceThicknessRange.y,\n 0.5\n );\n #ifdef HAS_IRIDESCENCETHICKNESSMAP\n iridescenceThickness = mix(\n pbrMaterial.iridescenceThicknessRange.x,\n pbrMaterial.iridescenceThicknessRange.y,\n textureSample(\n pbr_iridescenceThicknessSampler,\n pbr_iridescenceThicknessSamplerSampler,\n iridescenceThicknessUV\n ).g\n );\n #endif\n\n var anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);\n var anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);\n #ifdef HAS_ANISOTROPYMAP\n if (pbrMaterial.anisotropyMapEnabled != 0) {\n let anisotropySample = textureSample(\n pbr_anisotropySampler,\n pbr_anisotropySamplerSampler,\n anisotropyUV\n ).rgb;\n anisotropyStrength *= anisotropySample.b;\n let mappedDirection = anisotropySample.rg * 2.0 - 1.0;\n if (length(mappedDirection) > 0.0001) {\n anisotropyDirection = normalize(mappedDirection);\n }\n }\n #endif\n anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);\n var anisotropyTangent =\n normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);\n if (length(anisotropyTangent) < 0.0001) {\n anisotropyTangent = normalize(tbn[0]);\n }\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n let alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n let dielectricF0 = getDielectricF0(pbrMaterial.ior);\n var dielectricSpecularF0 = min(\n vec3f(dielectricF0) * specularFactor * specularIntensity,\n vec3f(1.0)\n );\n dielectricSpecularF0 = getIridescenceTint(\n iridescence,\n iridescenceThickness,\n NdotV,\n dielectricSpecularF0\n );\n var diffuseColor = baseColor.rgb * (vec3f(1.0) - dielectricSpecularF0);\n diffuseColor *= (1.0 - metallic) * (1.0 - transmission) * (1.0 - diffuseTransmission);\n var specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);\n\n let clearcoatViewFresnel = dielectricSchlick(\n 0.04,\n clamp(abs(dot(clearcoatNormal, v)), 0.0, 1.0)\n );\n let sheenDirectionalAlbedo = maxComponent(sheenColor) *\n (0.157 + 0.343 * (1.0 - NdotV)) * (1.0 - sheenRoughness * 0.5);\n let baseLayerEnergy = (1.0 - clearcoatFactor * clearcoatViewFresnel) *\n (1.0 - clamp(sheenDirectionalAlbedo, 0.0, 1.0));\n diffuseColor *= baseLayerEnergy;\n specularColor *= baseLayerEnergy;\n\n // Compute reflectance.\n let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflectance to 0%.\n let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n let specularEnvironmentR0 = specularColor;\n let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;\n let reflection = -normalize(reflect(v, n));\n\n var pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v,\n n,\n n\n );\n\n #ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(&pbrInfo);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting.ambientColor,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n\n // Apply directional light\n for (var i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getDirectionalLight(i).color,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getDirectionalLight(i).color,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n\n // Apply point light\n for (var i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));\n let attenuation = getPointLightAttenuation(\n lighting_getPointLight(i),\n distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)\n );\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getPointLight(i).color / attenuation,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getPointLight(i).color / attenuation,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n\n for (var i = 0; i < lighting.spotLightCount; i++) {\n if (i < lighting.spotLightCount) {\n PBRInfo_setSpotLight(&pbrInfo, lighting_getSpotLight(i));\n let attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), fragmentInputs.pbr_vPosition);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getSpotLight(i).color / attenuation,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getSpotLight(i).color / attenuation,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n #endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n #ifdef USE_IBL\n if (pbrMaterial.IBLenabled != 0) {\n color += getIBLContribution(\n pbrInfo,\n n,\n getAnisotropicReflection(pbrInfo, anisotropyTangent, anisotropyStrength)\n );\n color += calculateClearcoatIBLContribution(\n pbrInfo,\n clearcoatNormal,\n -normalize(reflect(v, clearcoatNormal)),\n clearcoatFactor,\n clearcoatRoughness\n );\n color += calculateDiffuseTransmissionIBL(\n pbrInfo,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;\n }\n #endif\n\n // Apply optional PBR terms for additional (optional) shading\n #ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled != 0) {\n let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n #endif\n\n var emissive = pbrMaterial.emissiveFactor;\n #ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled != 0u) {\n emissive *= SRGBtoLINEAR(\n textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, emissiveUV)\n ).rgb;\n }\n #endif\n color += emissive * pbrMaterial.emissiveStrength;\n\n if (transmission > 0.0) {\n #ifdef USE_TRANSMISSION_FRAMEBUFFER\n let dielectricFresnel = getDielectricF0(pbrMaterial.ior);\n let transmissionFresnel = dielectricFresnel +\n (1.0 - dielectricFresnel) * pow(1.0 - NdotV, 5.0);\n let transmittedColor = getTransmittedSceneColor(\n fragmentInputs.pbr_vPosition,\n n,\n v,\n thickness,\n perceptualRoughness\n );\n color += transmittedColor * getVolumeAttenuation(thickness) *\n transmission * (1.0 - transmissionFresnel);\n #else\n color = mix(color, color * getVolumeAttenuation(thickness), transmission);\n #endif\n }\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n #ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, pbr_scaleFGDSpec.x);\n // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);\n // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);\n // color = mix(color, specContrib, pbr_scaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n #endif\n }\n\n #ifdef USE_TRANSMISSION_FRAMEBUFFER\n let alpha = clamp(baseColor.a, 0.0, 1.0);\n #else\n let alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);\n #endif\n return vec4<f32>(applySceneColorManagement(color), alpha);\n}\n",vs:"out vec3 pbr_vPosition;\nout vec2 pbr_vUV0;\nout vec2 pbr_vUV1;\n\n#ifdef HAS_NORMALS\n# ifdef HAS_TANGENTS\nout mat3 pbr_vTBN;\n# else\nout vec3 pbr_vNormal;\n# endif\n#endif\n\nvoid pbr_setPositionNormalTangentUV(\n vec4 position,\n vec4 normal,\n vec4 tangent,\n vec2 uv0,\n vec2 uv1\n)\n{\n vec4 pos = pbrProjection.modelMatrix * position;\n pbr_vPosition = vec3(pos.xyz) / pos.w;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\n vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));\n vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));\n vec3 bitangentW = cross(normalW, tangentW) * tangent.w;\n pbr_vTBN = mat3(tangentW, bitangentW, normalW);\n#else // HAS_TANGENTS != 1\n pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));\n#endif\n#endif\n\n#ifdef HAS_UV\n pbr_vUV0 = uv0;\n#else\n pbr_vUV0 = vec2(0.,0.);\n#endif\n\n pbr_vUV1 = uv1;\n}\n",fs:"precision highp float;\n\nlayout(std140) uniform pbrMaterialUniforms {\n // Material is unlit\n bool unlit;\n\n // Base color map\n bool baseColorMapEnabled;\n vec4 baseColorFactor;\n\n bool normalMapEnabled; \n float normalScale; // #ifdef HAS_NORMALMAP\n\n bool emissiveMapEnabled;\n vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP\n\n vec2 metallicRoughnessValues;\n bool metallicRoughnessMapEnabled;\n\n bool occlusionMapEnabled;\n float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP\n \n bool alphaCutoffEnabled;\n float alphaCutoff; // #ifdef ALPHA_CUTOFF\n\n vec3 specularColorFactor;\n float specularIntensityFactor;\n bool specularColorMapEnabled;\n bool specularIntensityMapEnabled;\n\n float ior;\n\n float transmissionFactor;\n bool transmissionMapEnabled;\n\n float thicknessFactor;\n float attenuationDistance;\n vec3 attenuationColor;\n\n float clearcoatFactor;\n float clearcoatRoughnessFactor;\n bool clearcoatMapEnabled;\n bool clearcoatRoughnessMapEnabled;\n\n vec3 sheenColorFactor;\n float sheenRoughnessFactor;\n bool sheenColorMapEnabled;\n bool sheenRoughnessMapEnabled;\n\n float iridescenceFactor;\n float iridescenceIor;\n vec2 iridescenceThicknessRange;\n bool iridescenceMapEnabled;\n\n float anisotropyStrength;\n float anisotropyRotation;\n vec2 anisotropyDirection;\n bool anisotropyMapEnabled;\n\n float emissiveStrength;\n float dispersion;\n \n // IBL\n bool IBLenabled;\n vec2 scaleIBLAmbient; // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n vec4 scaleDiffBaseMR;\n vec4 scaleFGDSpec;\n // #endif\n\n int baseColorUVSet;\n mat3 baseColorUVTransform;\n int metallicRoughnessUVSet;\n mat3 metallicRoughnessUVTransform;\n int normalUVSet;\n mat3 normalUVTransform;\n int occlusionUVSet;\n mat3 occlusionUVTransform;\n int emissiveUVSet;\n mat3 emissiveUVTransform;\n int specularColorUVSet;\n mat3 specularColorUVTransform;\n int specularIntensityUVSet;\n mat3 specularIntensityUVTransform;\n int transmissionUVSet;\n mat3 transmissionUVTransform;\n int thicknessUVSet;\n mat3 thicknessUVTransform;\n int clearcoatUVSet;\n mat3 clearcoatUVTransform;\n int clearcoatRoughnessUVSet;\n mat3 clearcoatRoughnessUVTransform;\n int clearcoatNormalUVSet;\n mat3 clearcoatNormalUVTransform;\n int sheenColorUVSet;\n mat3 sheenColorUVTransform;\n int sheenRoughnessUVSet;\n mat3 sheenRoughnessUVTransform;\n int iridescenceUVSet;\n mat3 iridescenceUVTransform;\n int iridescenceThicknessUVSet;\n mat3 iridescenceThicknessUVTransform;\n int anisotropyUVSet;\n mat3 anisotropyUVTransform;\n\n float bumpFactor;\n bool bumpMapEnabled;\n float diffuseTransmissionFactor;\n bool diffuseTransmissionMapEnabled;\n vec3 diffuseTransmissionColorFactor;\n bool diffuseTransmissionColorMapEnabled;\n vec3 multiscatterColorFactor;\n bool multiscatterColorMapEnabled;\n float scatterAnisotropy;\n\n int bumpUVSet;\n mat3 bumpUVTransform;\n int diffuseTransmissionUVSet;\n mat3 diffuseTransmissionUVTransform;\n int diffuseTransmissionColorUVSet;\n mat3 diffuseTransmissionColorUVTransform;\n int multiscatterColorUVSet;\n mat3 multiscatterColorUVTransform;\n} pbrMaterial;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D pbr_baseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D pbr_normalSampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D pbr_emissiveSampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D pbr_metallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D pbr_occlusionSampler;\n#endif\n#ifdef HAS_SPECULARCOLORMAP\nuniform sampler2D pbr_specularColorSampler;\n#endif\n#ifdef HAS_SPECULARINTENSITYMAP\nuniform sampler2D pbr_specularIntensitySampler;\n#endif\n#ifdef HAS_TRANSMISSIONMAP\nuniform sampler2D pbr_transmissionSampler;\n#endif\n#ifdef HAS_THICKNESSMAP\nuniform sampler2D pbr_thicknessSampler;\n#endif\n#ifdef HAS_CLEARCOATMAP\nuniform sampler2D pbr_clearcoatSampler;\n#endif\n#ifdef HAS_CLEARCOATROUGHNESSMAP\nuniform sampler2D pbr_clearcoatRoughnessSampler;\n#endif\n#ifdef HAS_CLEARCOATNORMALMAP\nuniform sampler2D pbr_clearcoatNormalSampler;\n#endif\n#ifdef HAS_SHEENCOLORMAP\nuniform sampler2D pbr_sheenColorSampler;\n#endif\n#ifdef HAS_SHEENROUGHNESSMAP\nuniform sampler2D pbr_sheenRoughnessSampler;\n#endif\n#ifdef HAS_IRIDESCENCEMAP\nuniform sampler2D pbr_iridescenceSampler;\n#endif\n#ifdef HAS_IRIDESCENCETHICKNESSMAP\nuniform sampler2D pbr_iridescenceThicknessSampler;\n#endif\n#ifdef HAS_ANISOTROPYMAP\nuniform sampler2D pbr_anisotropySampler;\n#endif\n#ifdef HAS_BUMPMAP\nuniform sampler2D pbr_bumpSampler;\n#endif\n#ifdef HAS_DIFFUSETRANSMISSIONMAP\nuniform sampler2D pbr_diffuseTransmissionSampler;\n#endif\n#ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP\nuniform sampler2D pbr_diffuseTransmissionColorSampler;\n#endif\n#ifdef HAS_MULTISCATTERCOLORMAP\nuniform sampler2D pbr_multiscatterColorSampler;\n#endif\n// Inputs from vertex shader\n\nin vec3 pbr_vPosition;\nin vec2 pbr_vUV0;\nin vec2 pbr_vUV1;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nin mat3 pbr_vTBN;\n#else\nin vec3 pbr_vNormal;\n#endif\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n float NdotL; // cos angle between normal and light direction\n float NdotV; // cos angle between normal and view direction\n float NdotH; // cos angle between normal and half vector\n float LdotH; // cos angle between light direction and half vector\n float VdotH; // cos angle between view direction and half vector\n float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)\n float metalness; // metallic value at the surface\n vec3 reflectance0; // full reflectance color (normal incidence angle)\n vec3 reflectance90; // reflectance color at grazing angle\n float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])\n vec3 diffuseColor; // color contribution from diffuse lighting\n vec3 specularColor; // color contribution from specular lighting\n vec3 n; // normal at surface point\n vec3 v; // vector from surface point to camera\n vec3 l; // direction from the surface toward the current light\n vec3 h; // half vector between the current light and camera\n};\n\nconst float M_PI = 3.141592653589793;\nconst float c_MinRoughness = 0.04;\n\n// Widen sub-pixel specular lobes using the screen-space normal footprint.\n// This is geometric specular antialiasing: the normal variance is converted\n// into an additional squared perceptual roughness before evaluating BRDFs.\nfloat widenSpecularRoughness(float perceptualRoughness, vec3 normal)\n{\n vec3 normalDerivativeX = dFdx(normal);\n vec3 normalDerivativeY = dFdy(normal);\n float normalVariance =\n dot(normalDerivativeX, normalDerivativeX) +\n dot(normalDerivativeY, normalDerivativeY);\n float kernelRoughnessSquared = min(2.0 * normalVariance, 1.0);\n return clamp(\n sqrt(perceptualRoughness * perceptualRoughness + kernelRoughnessSquared),\n c_MinRoughness,\n 1.0\n );\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor);\n\nvec4 SRGBtoLINEAR(vec4 srgbIn)\n{\n#ifdef MANUAL_SRGB\n#ifdef SRGB_FAST_APPROXIMATION\n vec3 linOut = pow(srgbIn.xyz,vec3(2.2));\n#else // SRGB_FAST_APPROXIMATION\n vec3 bLess = step(vec3(0.04045),srgbIn.xyz);\n vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );\n#endif //SRGB_FAST_APPROXIMATION\n return vec4(linOut,srgbIn.w);;\n#else //MANUAL_SRGB\n return srgbIn;\n#endif //MANUAL_SRGB\n}\n\nvec2 getMaterialUV(int uvSet, mat3 uvTransform)\n{\n vec2 baseUV = uvSet == 1 ? pbr_vUV1 : pbr_vUV0;\n return (uvTransform * vec3(baseUV, 1.0)).xy;\n}\n\n// Build the tangent basis from interpolated attributes or screen-space derivatives.\nmat3 getTBN(vec2 uv)\n{\n#ifndef HAS_TANGENTS\n vec3 pos_dx = dFdx(pbr_vPosition);\n vec3 pos_dy = dFdy(pbr_vPosition);\n vec3 tex_dx = dFdx(vec3(uv, 0.0));\n vec3 tex_dy = dFdy(vec3(uv, 0.0));\n vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);\n\n#ifdef HAS_NORMALS\n vec3 ng = normalize(pbr_vNormal);\n#else\n vec3 ng = cross(pos_dx, pos_dy);\n#endif\n\n t = normalize(t - ng * dot(ng, t));\n vec3 b = normalize(cross(ng, t));\n mat3 tbn = mat3(t, b, ng);\n#else // HAS_TANGENTS\n mat3 tbn = pbr_vTBN;\n#endif\n\n return tbn;\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nvec3 getMappedNormal(sampler2D normalSampler, mat3 tbn, float normalScale, vec2 uv)\n{\n vec3 n = texture(normalSampler, uv).rgb;\n return normalize(tbn * ((2.0 * n - 1.0) * vec3(normalScale, normalScale, 1.0)));\n}\n\nvec3 getNormal(mat3 tbn, vec2 uv)\n{\n#ifdef HAS_NORMALMAP\n vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale, uv);\n#else\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n vec3 n = normalize(tbn[2].xyz);\n#endif\n\n#ifdef HAS_BUMPMAP\n vec2 bumpUV = getMaterialUV(pbrMaterial.bumpUVSet, pbrMaterial.bumpUVTransform);\n vec2 bumpTexelSize = 1.0 / vec2(textureSize(pbr_bumpSampler, 0));\n float bumpHeight = texture(pbr_bumpSampler, bumpUV).r;\n vec2 bumpGradient = vec2(\n texture(pbr_bumpSampler, bumpUV + vec2(bumpTexelSize.x, 0.0)).r - bumpHeight,\n texture(pbr_bumpSampler, bumpUV + vec2(0.0, bumpTexelSize.y)).r - bumpHeight\n );\n n = normalize(n - pbrMaterial.bumpFactor *\n (tbn[0] * bumpGradient.x + tbn[1] * bumpGradient.y));\n#endif\n\n return n;\n}\n\nvec3 getClearcoatNormal(mat3 tbn, vec3 baseNormal, vec2 uv)\n{\n#ifdef HAS_CLEARCOATNORMALMAP\n return getMappedNormal(pbr_clearcoatNormalSampler, tbn, 1.0, uv);\n#else\n return baseNormal;\n#endif\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nvec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)\n{\n#ifdef USE_SCENE_ENVIRONMENT\n float maximumMipLevel = max(pbrScene.environmentMipCount - 1.0, 0.0);\n float rotationSine = sin(pbrScene.environmentRotation);\n float rotationCosine = cos(pbrScene.environmentRotation);\n mat2 environmentRotation = mat2(rotationCosine, rotationSine, -rotationSine, rotationCosine);\n vec3 environmentNormal = vec3(environmentRotation * n.xz, n.y).xzy;\n vec3 environmentReflection = vec3(environmentRotation * reflection.xz, reflection.y).xzy;\n#else\n float maximumMipLevel = 9.0;\n vec3 environmentNormal = n;\n vec3 environmentReflection = reflection;\n#endif\n float lod = pbrInfo.perceptualRoughness * maximumMipLevel;\n // retrieve a scale and bias to F0. See [1], Figure 3\n vec4 brdfSample = texture(pbr_brdfLUT,\n vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness));\n vec4 diffuseSample = texture(pbr_diffuseEnvSampler, environmentNormal);\n\n#ifdef USE_TEX_LOD\n vec4 specularSample = textureLod(pbr_specularEnvSampler, environmentReflection, lod);\n#else\n vec4 specularSample = texture(pbr_specularEnvSampler, environmentReflection);\n#endif\n\n#ifdef USE_SCENE_ENVIRONMENT\n vec3 brdf = brdfSample.rgb;\n vec3 diffuseLight = diffuseSample.rgb;\n vec3 specularLight = specularSample.rgb;\n#else\n vec3 brdf = SRGBtoLINEAR(brdfSample).rgb;\n vec3 diffuseLight = SRGBtoLINEAR(diffuseSample).rgb;\n vec3 specularLight = SRGBtoLINEAR(specularSample).rgb;\n#endif\n\n vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;\n vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);\n\n // For presentation, this allows us to disable IBL terms\n diffuse *= pbrMaterial.scaleIBLAmbient.x;\n specular *= pbrMaterial.scaleIBLAmbient.y;\n\n#ifdef USE_SCENE_ENVIRONMENT\n return (diffuse + specular) * max(pbrScene.environmentIntensity, 0.0);\n#else\n return diffuse + specular;\n#endif\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nvec3 diffuse(PBRInfo pbrInfo)\n{\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nvec3 specularReflection(PBRInfo pbrInfo)\n{\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfloat geometricOcclusion(PBRInfo pbrInfo)\n{\n float NdotL = pbrInfo.NdotL;\n float NdotV = pbrInfo.NdotV;\n float r = pbrInfo.alphaRoughness;\n\n float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfloat microfacetDistribution(PBRInfo pbrInfo)\n{\n float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nfloat maxComponent(vec3 value)\n{\n return max(max(value.r, value.g), value.b);\n}\n\nfloat getDielectricF0(float ior)\n{\n float clampedIor = max(ior, 1.0);\n float ratio = (clampedIor - 1.0) / (clampedIor + 1.0);\n return ratio * ratio;\n}\n\nvec2 normalizeDirection(vec2 direction)\n{\n float directionLength = length(direction);\n return directionLength > 0.0001 ? direction / directionLength : vec2(1.0, 0.0);\n}\n\nvec2 rotateDirection(vec2 direction, float rotation)\n{\n float s = sin(rotation);\n float c = cos(rotation);\n return vec2(direction.x * c - direction.y * s, direction.x * s + direction.y * c);\n}\n\nvec3 encodeLinearSRGB(vec3 linearColor)\n{\n vec3 positiveColor = max(linearColor, vec3(0.0));\n return mix(\n positiveColor * 12.92,\n 1.055 * pow(positiveColor, vec3(1.0 / 2.4)) - 0.055,\n greaterThan(positiveColor, vec3(0.0031308))\n );\n}\n\nvec3 toneMapKhronosPBRNeutral(vec3 color)\n{\n const float startCompression = 0.76;\n float darkestChannel = min(color.r, min(color.g, color.b));\n float offset = darkestChannel < 0.08\n ? darkestChannel - 6.25 * darkestChannel * darkestChannel\n : 0.04;\n color -= vec3(offset);\n\n float peak = maxComponent(color);\n if (peak < startCompression) {\n return color;\n }\n\n float compressionRange = 1.0 - startCompression;\n float compressedPeak = 1.0 - compressionRange * compressionRange /\n (peak + compressionRange - startCompression);\n color *= compressedPeak / max(peak, 0.0001);\n float desaturation = 1.0 - 1.0 / (0.15 * (peak - compressedPeak) + 1.0);\n return mix(color, vec3(compressedPeak), desaturation);\n}\n\nvec3 applySceneColorManagement(vec3 sceneColor)\n{\n#ifdef USE_SCENE_COLOR_MANAGEMENT\n vec3 color = max(sceneColor, vec3(0.0)) * max(pbrScene.exposure, 0.0);\n if (pbrScene.toneMapMode == 1) {\n color /= vec3(1.0) + color;\n } else if (pbrScene.toneMapMode == 2) {\n color = toneMapKhronosPBRNeutral(color);\n } else if (pbrScene.toneMapMode == 3) {\n color = clamp(\n (color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14),\n vec3(0.0),\n vec3(1.0)\n );\n }\n return pbrScene.outputEncoding == 0 ? color : encodeLinearSRGB(color);\n#else\n return pow(max(sceneColor, vec3(0.0)), vec3(1.0 / 2.2));\n#endif\n}\n\nfloat dielectricSchlick(float reflectance, float cosine)\n{\n return reflectance + (1.0 - reflectance) * pow(clamp(1.0 - cosine, 0.0, 1.0), 5.0);\n}\n\nvec3 evaluateIridescenceSensitivity(float opticalPathDifference, vec3 phaseShift)\n{\n float phase = 2.0 * M_PI * opticalPathDifference * 1.0e-9;\n vec3 sensitivity = vec3(5.4856e-13, 4.4201e-13, 5.2481e-13);\n vec3 position = vec3(1.6810e6, 1.7953e6, 2.2084e6);\n vec3 variance = vec3(4.3278e9, 9.3046e9, 6.6121e9);\n vec3 xyz = sensitivity * sqrt(2.0 * M_PI * variance) *\n cos(position * phase + phaseShift) * exp(-phase * phase * variance);\n xyz.x += 9.7470e-14 * sqrt(2.0 * M_PI * 4.5282e9) *\n cos(2.2399e6 * phase + phaseShift.x) * exp(-4.5282e9 * phase * phase);\n xyz /= 1.0685e-7;\n return mat3(\n 3.2404542, -0.9692660, 0.0556434,\n -1.5371385, 1.8760108, -0.2040259,\n -0.4985314, 0.0415560, 1.0572252\n ) * xyz;\n}\n\nvec3 getIridescenceTint(float iridescence, float thickness, float NdotV, vec3 baseReflectance)\n{\n if (iridescence <= 0.0 || thickness <= 0.0) {\n return baseReflectance;\n }\n\n float filmIor = max(pbrMaterial.iridescenceIor, 1.0);\n float sineSquared = (1.0 - NdotV * NdotV) / (filmIor * filmIor);\n float cosineSquared = 1.0 - sineSquared;\n if (cosineSquared <= 0.0) {\n return mix(baseReflectance, vec3(1.0), iridescence);\n }\n float filmCosine = sqrt(cosineSquared);\n float firstInterfaceReflectance = dielectricSchlick(getDielectricF0(filmIor), NdotV);\n float transmittedEnergy = 1.0 - firstInterfaceReflectance;\n\n vec3 baseIor = (vec3(1.0) + sqrt(clamp(baseReflectance, vec3(0.0), vec3(0.9999)))) /\n (vec3(1.0) - sqrt(clamp(baseReflectance, vec3(0.0), vec3(0.9999))));\n vec3 secondInterfaceF0 = (baseIor - vec3(filmIor)) / (baseIor + vec3(filmIor));\n secondInterfaceF0 *= secondInterfaceF0;\n vec3 secondInterfaceReflectance = secondInterfaceF0 +\n (vec3(1.0) - secondInterfaceF0) * pow(1.0 - filmCosine, 5.0);\n vec3 phaseShift = vec3(M_PI);\n phaseShift += mix(vec3(0.0), vec3(M_PI), lessThan(baseIor, vec3(filmIor)));\n float opticalPathDifference = 2.0 * filmIor * thickness * filmCosine;\n vec3 combinedReflectance = clamp(\n firstInterfaceReflectance * secondInterfaceReflectance,\n vec3(0.00001),\n vec3(0.9999)\n );\n vec3 recurringAmplitude = sqrt(combinedReflectance);\n vec3 interfaceResponse = transmittedEnergy * transmittedEnergy * secondInterfaceReflectance /\n (vec3(1.0) - combinedReflectance);\n vec3 reflectedSpectrum = vec3(firstInterfaceReflectance) + interfaceResponse;\n vec3 harmonicAmplitude = interfaceResponse - vec3(transmittedEnergy);\n for (int harmonic = 1; harmonic <= 2; harmonic++) {\n harmonicAmplitude *= recurringAmplitude;\n reflectedSpectrum += harmonicAmplitude * 2.0 * evaluateIridescenceSensitivity(\n float(harmonic) * opticalPathDifference,\n float(harmonic) * phaseShift\n );\n }\n return mix(baseReflectance, clamp(reflectedSpectrum, vec3(0.0), vec3(1.0)), iridescence);\n}\n\nvec3 getVolumeAttenuation(float thickness)\n{\n if (thickness <= 0.0) {\n return vec3(1.0);\n }\n\n vec3 attenuationCoefficient =\n -log(max(pbrMaterial.attenuationColor, vec3(0.0001))) /\n max(pbrMaterial.attenuationDistance, 0.0001);\n return exp(-attenuationCoefficient * thickness);\n}\n\n// KHR_materials_volume_scatter is an active draft. This evaluates a local,\n// thickness-aware single-scattering approximation rather than random walk.\nvec3 getDiffuseTransmissionAttenuation(\n PBRInfo pbrInfo,\n vec3 multiscatterColor,\n float thickness\n)\n{\n vec3 volumeAttenuation = getVolumeAttenuation(thickness);\n float scatteringStrength = maxComponent(multiscatterColor);\n if (thickness <= 0.0 || scatteringStrength <= 0.0001) {\n return volumeAttenuation;\n }\n\n float anisotropy = clamp(pbrMaterial.scatterAnisotropy, -0.95, 0.95);\n float scatteringCosine = clamp(dot(-pbrInfo.v, pbrInfo.l), -1.0, 1.0);\n float phaseDenominator = max(\n 1.0 + anisotropy * anisotropy - 2.0 * anisotropy * scatteringCosine,\n 0.0001\n );\n float phaseWeight = clamp(\n (1.0 - anisotropy * anisotropy) / pow(phaseDenominator, 1.5),\n 0.0,\n 4.0\n );\n float scatteringDepth = thickness / max(pbrMaterial.attenuationDistance, 0.0001);\n float scatteringProbability = 1.0 - exp(-scatteringDepth);\n vec3 scatteringColor = clamp(multiscatterColor, vec3(0.0), vec3(1.0));\n return mix(\n volumeAttenuation,\n volumeAttenuation * mix(vec3(1.0), scatteringColor * phaseWeight, scatteringColor),\n scatteringProbability\n );\n}\n\nvec3 calculateDiffuseTransmissionLight(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 diffuseTransmissionColor,\n float diffuseTransmission,\n vec3 multiscatterColor,\n float thickness\n)\n{\n float oppositeHemisphere = max(dot(-pbrInfo.n, pbrInfo.l), 0.0);\n if (oppositeHemisphere <= 0.0 || diffuseTransmission <= 0.0) {\n return vec3(0.0);\n }\n\n vec3 nonReflectedEnergy = vec3(1.0) - clamp(pbrInfo.reflectance0, vec3(0.0), vec3(1.0));\n vec3 attenuatedColor = getDiffuseTransmissionAttenuation(\n pbrInfo,\n multiscatterColor,\n thickness\n );\n return lightColor * diffuseTransmissionColor * nonReflectedEnergy *\n attenuatedColor * (diffuseTransmission * oppositeHemisphere / M_PI);\n}\n\n#ifdef USE_IBL\nvec3 calculateDiffuseTransmissionIBL(\n PBRInfo pbrInfo,\n vec3 diffuseTransmissionColor,\n float diffuseTransmission,\n vec3 multiscatterColor,\n float thickness\n)\n{\n if (diffuseTransmission <= 0.0) {\n return vec3(0.0);\n }\n\n#ifdef USE_SCENE_ENVIRONMENT\n float rotationSine = sin(pbrScene.environmentRotation);\n float rotationCosine = cos(pbrScene.environmentRotation);\n mat2 environmentRotation = mat2(rotationCosine, rotationSine, -rotationSine, rotationCosine);\n vec3 oppositeNormal = vec3(environmentRotation * -pbrInfo.n.xz, -pbrInfo.n.y).xzy;\n vec3 environmentColor = texture(pbr_diffuseEnvSampler, oppositeNormal).rgb *\n max(pbrScene.environmentIntensity, 0.0);\n#else\n vec3 environmentColor = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, -pbrInfo.n)).rgb;\n#endif\n vec3 nonReflectedEnergy = vec3(1.0) - clamp(pbrInfo.reflectance0, vec3(0.0), vec3(1.0));\n return environmentColor * diffuseTransmissionColor * nonReflectedEnergy *\n getDiffuseTransmissionAttenuation(pbrInfo, multiscatterColor, thickness) *\n diffuseTransmission * pbrMaterial.scaleIBLAmbient.x;\n}\n#endif\n\n#ifdef USE_TRANSMISSION_FRAMEBUFFER\nvec3 sampleTransmittedSceneColor(\n vec3 position,\n vec3 normal,\n vec3 viewDirection,\n float thickness,\n float perceptualRoughness,\n float indexOfRefraction\n)\n{\n vec3 refractionDirection = refract(\n -viewDirection,\n normal,\n 1.0 / max(indexOfRefraction, 1.0)\n );\n vec3 refractedPosition = position + refractionDirection * thickness;\n vec4 clipPosition = pbrScene.projectionMatrix *\n pbrScene.viewMatrix * vec4(refractedPosition, 1.0);\n vec2 textureCoordinate = clipPosition.xy / max(clipPosition.w, 0.0001) * 0.5 + 0.5;\n textureCoordinate = clamp(textureCoordinate, vec2(0.001), vec2(0.999));\n\n vec2 blurRadius = perceptualRoughness * perceptualRoughness * 8.0 /\n max(pbrScene.framebufferSize, vec2(1.0));\n vec3 sceneColor = texture(pbr_transmissionFramebufferSampler, textureCoordinate).rgb * 0.4;\n sceneColor += texture(\n pbr_transmissionFramebufferSampler,\n textureCoordinate + vec2(blurRadius.x, 0.0)\n ).rgb * 0.15;\n sceneColor += texture(\n pbr_transmissionFramebufferSampler,\n textureCoordinate - vec2(blurRadius.x, 0.0)\n ).rgb * 0.15;\n sceneColor += texture(\n pbr_transmissionFramebufferSampler,\n textureCoordinate + vec2(0.0, blurRadius.y)\n ).rgb * 0.15;\n sceneColor += texture(\n pbr_transmissionFramebufferSampler,\n textureCoordinate - vec2(0.0, blurRadius.y)\n ).rgb * 0.15;\n return max(sceneColor, vec3(0.0));\n}\n\nvec3 getTransmittedSceneColor(\n vec3 position,\n vec3 normal,\n vec3 viewDirection,\n float thickness,\n float perceptualRoughness\n)\n{\n if (pbrMaterial.dispersion <= 0.0) {\n return sampleTransmittedSceneColor(\n position,\n normal,\n viewDirection,\n thickness,\n perceptualRoughness,\n pbrMaterial.ior\n );\n }\n\n float halfSpread = (max(pbrMaterial.ior, 1.0) - 1.0) * 0.025 * pbrMaterial.dispersion;\n vec3 indicesOfRefraction = max(\n vec3(pbrMaterial.ior - halfSpread, pbrMaterial.ior, pbrMaterial.ior + halfSpread),\n vec3(1.0)\n );\n return vec3(\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.r\n ).r,\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.g\n ).g,\n sampleTransmittedSceneColor(\n position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.b\n ).b\n );\n}\n#endif\n\nPBRInfo createClearcoatPBRInfo(PBRInfo basePBRInfo, vec3 clearcoatNormal, float clearcoatRoughness)\n{\n float perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n float NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);\n\n return PBRInfo(\n basePBRInfo.NdotL,\n NdotV,\n basePBRInfo.NdotH,\n basePBRInfo.LdotH,\n basePBRInfo.VdotH,\n perceptualRoughness,\n 0.0,\n vec3(0.04),\n vec3(1.0),\n alphaRoughness,\n vec3(0.0),\n vec3(0.04),\n clearcoatNormal,\n basePBRInfo.v,\n basePBRInfo.l,\n basePBRInfo.h\n );\n}\n\nvec3 calculateClearcoatContribution(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 clearcoatNormal,\n float clearcoatFactor,\n float clearcoatRoughness\n) {\n if (clearcoatFactor <= 0.0) {\n return vec3(0.0);\n }\n\n PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);\n return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;\n}\n\n#ifdef USE_IBL\nvec3 calculateClearcoatIBLContribution(\n PBRInfo pbrInfo,\n vec3 clearcoatNormal,\n vec3 reflection,\n float clearcoatFactor,\n float clearcoatRoughness\n) {\n if (clearcoatFactor <= 0.0) {\n return vec3(0.0);\n }\n\n PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);\n return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;\n}\n#endif\n\nvec3 calculateSheenContribution(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 sheenColor,\n float sheenRoughness\n) {\n if (maxComponent(sheenColor) <= 0.0) {\n return vec3(0.0);\n }\n\n float alpha = max(sheenRoughness * sheenRoughness, 0.0001);\n float inverseAlpha = 1.0 / alpha;\n float sineSquared = max(1.0 - pbrInfo.NdotH * pbrInfo.NdotH, 0.0);\n float distribution = (2.0 + inverseAlpha) * pow(sineSquared, inverseAlpha * 0.5) /\n (2.0 * M_PI);\n float visibility = 1.0 / max(\n 4.0 * (pbrInfo.NdotL + pbrInfo.NdotV - pbrInfo.NdotL * pbrInfo.NdotV),\n 0.0001\n );\n return pbrInfo.NdotL * lightColor * sheenColor * distribution * visibility *\n (1.0 - pbrInfo.metalness);\n}\n\nvec3 calculateAnisotropicLightColor(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 anisotropyTangent,\n float anisotropyStrength\n) {\n if (anisotropyStrength <= 0.0) {\n return calculateFinalColor(pbrInfo, lightColor);\n }\n\n vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));\n float tangentRoughness = mix(\n pbrInfo.alphaRoughness,\n 1.0,\n anisotropyStrength * anisotropyStrength\n );\n float bitangentRoughness = clamp(pbrInfo.alphaRoughness, 0.001, 1.0);\n float roughnessProduct = tangentRoughness * bitangentRoughness;\n vec3 distributionVector = vec3(\n bitangentRoughness * dot(anisotropyTangent, pbrInfo.h),\n tangentRoughness * dot(anisotropyBitangent, pbrInfo.h),\n roughnessProduct * pbrInfo.NdotH\n );\n float distributionFactor = roughnessProduct /\n max(dot(distributionVector, distributionVector), 0.000001);\n float distribution = roughnessProduct * distributionFactor * distributionFactor / M_PI;\n float viewMask = pbrInfo.NdotL * length(vec3(\n tangentRoughness * dot(anisotropyTangent, pbrInfo.v),\n bitangentRoughness * dot(anisotropyBitangent, pbrInfo.v),\n pbrInfo.NdotV\n ));\n float lightMask = pbrInfo.NdotV * length(vec3(\n tangentRoughness * dot(anisotropyTangent, pbrInfo.l),\n bitangentRoughness * dot(anisotropyBitangent, pbrInfo.l),\n pbrInfo.NdotL\n ));\n float visibility = clamp(0.5 / max(viewMask + lightMask, 0.000001), 0.0, 1.0);\n vec3 fresnel = specularReflection(pbrInfo);\n vec3 diffuseContribution = (vec3(1.0) - fresnel) * diffuse(pbrInfo);\n return pbrInfo.NdotL * lightColor *\n (diffuseContribution + fresnel * distribution * visibility);\n}\n\nvec3 getAnisotropicReflection(PBRInfo pbrInfo, vec3 anisotropyTangent, float anisotropyStrength)\n{\n if (anisotropyStrength <= 0.0) {\n return -normalize(reflect(pbrInfo.v, pbrInfo.n));\n }\n vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));\n vec3 anisotropicNormal = normalize(cross(anisotropyBitangent, pbrInfo.v));\n anisotropicNormal = normalize(cross(anisotropicNormal, anisotropyBitangent));\n float bend = anisotropyStrength * (1.0 - pbrInfo.perceptualRoughness);\n return -normalize(reflect(pbrInfo.v, normalize(mix(pbrInfo.n, anisotropicNormal, bend))));\n}\n\nvec3 calculateMaterialLightColor(\n PBRInfo pbrInfo,\n vec3 lightColor,\n vec3 clearcoatNormal,\n float clearcoatFactor,\n float clearcoatRoughness,\n vec3 sheenColor,\n float sheenRoughness,\n vec3 anisotropyTangent,\n float anisotropyStrength\n) {\n vec3 color = calculateAnisotropicLightColor(\n pbrInfo,\n lightColor,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateClearcoatContribution(\n pbrInfo,\n lightColor,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness\n );\n color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);\n return color;\n}\n\nvoid PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {\n pbrInfo.NdotL = 1.0;\n pbrInfo.NdotH = 0.0;\n pbrInfo.LdotH = 0.0;\n pbrInfo.VdotH = 1.0;\n pbrInfo.l = pbrInfo.n;\n pbrInfo.h = pbrInfo.n;\n}\n\nvoid PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {\n vec3 n = pbrInfo.n;\n vec3 v = pbrInfo.v;\n vec3 l = normalize(lightDirection); // Vector from surface point to light\n vec3 h = normalize(l+v); // Half vector between both l and v\n\n pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);\n pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);\n pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);\n pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);\n pbrInfo.l = l;\n pbrInfo.h = h;\n}\n\nvoid PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {\n vec3 light_direction = normalize(pointLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nvoid PBRInfo_setSpotLight(inout PBRInfo pbrInfo, SpotLight spotLight) {\n vec3 light_direction = normalize(spotLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {\n // Calculate the shading terms for the microfacet specular shading model\n vec3 F = specularReflection(pbrInfo);\n float G = geometricOcclusion(pbrInfo);\n float D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nvec4 pbr_filterColor(vec4 vertexColor)\n{\n vec2 baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);\n vec2 metallicRoughnessUV = getMaterialUV(\n pbrMaterial.metallicRoughnessUVSet,\n pbrMaterial.metallicRoughnessUVTransform\n );\n vec2 normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);\n vec2 occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);\n vec2 emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);\n vec2 specularColorUV = getMaterialUV(\n pbrMaterial.specularColorUVSet,\n pbrMaterial.specularColorUVTransform\n );\n vec2 specularIntensityUV = getMaterialUV(\n pbrMaterial.specularIntensityUVSet,\n pbrMaterial.specularIntensityUVTransform\n );\n vec2 transmissionUV = getMaterialUV(\n pbrMaterial.transmissionUVSet,\n pbrMaterial.transmissionUVTransform\n );\n vec2 thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);\n vec2 clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);\n vec2 clearcoatRoughnessUV = getMaterialUV(\n pbrMaterial.clearcoatRoughnessUVSet,\n pbrMaterial.clearcoatRoughnessUVTransform\n );\n vec2 clearcoatNormalUV = getMaterialUV(\n pbrMaterial.clearcoatNormalUVSet,\n pbrMaterial.clearcoatNormalUVTransform\n );\n vec2 sheenColorUV = getMaterialUV(\n pbrMaterial.sheenColorUVSet,\n pbrMaterial.sheenColorUVTransform\n );\n vec2 sheenRoughnessUV = getMaterialUV(\n pbrMaterial.sheenRoughnessUVSet,\n pbrMaterial.sheenRoughnessUVTransform\n );\n vec2 iridescenceUV = getMaterialUV(\n pbrMaterial.iridescenceUVSet,\n pbrMaterial.iridescenceUVTransform\n );\n vec2 iridescenceThicknessUV = getMaterialUV(\n pbrMaterial.iridescenceThicknessUVSet,\n pbrMaterial.iridescenceThicknessUVTransform\n );\n vec2 anisotropyUV = getMaterialUV(\n pbrMaterial.anisotropyUVSet,\n pbrMaterial.anisotropyUVTransform\n );\n vec2 diffuseTransmissionUV = getMaterialUV(\n pbrMaterial.diffuseTransmissionUVSet,\n pbrMaterial.diffuseTransmissionUVTransform\n );\n vec2 diffuseTransmissionColorUV = getMaterialUV(\n pbrMaterial.diffuseTransmissionColorUVSet,\n pbrMaterial.diffuseTransmissionColorUVTransform\n );\n vec2 multiscatterColorUV = getMaterialUV(\n pbrMaterial.multiscatterColorUVSet,\n pbrMaterial.multiscatterColorUVTransform\n );\n\n // The albedo may be defined from a base texture or a flat color\n#ifdef HAS_BASECOLORMAP\n vec4 baseColor =\n SRGBtoLINEAR(texture(pbr_baseColorSampler, baseColorUV)) *\n pbrMaterial.baseColorFactor * vertexColor;\n#else\n vec4 baseColor = pbrMaterial.baseColorFactor * vertexColor;\n#endif\n\n#ifdef ALPHA_CUTOFF\n if (baseColor.a < pbrMaterial.alphaCutoff) {\n discard;\n }\n#endif\n\n vec3 color = vec3(0, 0, 0);\n\n float transmission = 0.0;\n\n if(pbrMaterial.unlit){\n color.rgb = baseColor.rgb;\n }\n else{\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;\n float metallic = pbrMaterial.metallicRoughnessValues.x;\n#ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n vec4 mrSample = texture(pbr_metallicRoughnessSampler, metallicRoughnessUV);\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n#endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n mat3 tbn = getTBN(normalUV);\n vec3 n = getNormal(tbn, normalUV); // normal at surface point\n perceptualRoughness = widenSpecularRoughness(perceptualRoughness, n);\n vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera\n float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n#ifdef USE_MATERIAL_EXTENSIONS\n bool useExtendedPBR =\n pbrMaterial.specularColorMapEnabled ||\n pbrMaterial.specularIntensityMapEnabled ||\n abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||\n maxComponent(abs(pbrMaterial.specularColorFactor - vec3(1.0))) > 0.0001 ||\n abs(pbrMaterial.ior - 1.5) > 0.0001 ||\n pbrMaterial.dispersion > 0.0001 ||\n pbrMaterial.transmissionMapEnabled ||\n pbrMaterial.transmissionFactor > 0.0001 ||\n pbrMaterial.diffuseTransmissionMapEnabled ||\n pbrMaterial.diffuseTransmissionColorMapEnabled ||\n pbrMaterial.diffuseTransmissionFactor > 0.0001 ||\n pbrMaterial.multiscatterColorMapEnabled ||\n maxComponent(pbrMaterial.multiscatterColorFactor) > 0.0001 ||\n pbrMaterial.clearcoatMapEnabled ||\n pbrMaterial.clearcoatRoughnessMapEnabled ||\n pbrMaterial.clearcoatFactor > 0.0001 ||\n pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||\n pbrMaterial.sheenColorMapEnabled ||\n pbrMaterial.sheenRoughnessMapEnabled ||\n maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||\n pbrMaterial.sheenRoughnessFactor > 0.0001 ||\n pbrMaterial.iridescenceMapEnabled ||\n pbrMaterial.iridescenceFactor > 0.0001 ||\n abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||\n abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||\n abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||\n pbrMaterial.anisotropyMapEnabled ||\n pbrMaterial.anisotropyStrength > 0.0001 ||\n abs(pbrMaterial.anisotropyRotation) > 0.0001 ||\n length(pbrMaterial.anisotropyDirection - vec2(1.0, 0.0)) > 0.0001;\n#else\n bool useExtendedPBR = false;\n#endif\n\n if (!useExtendedPBR) {\n // Keep the baseline metallic-roughness implementation byte-for-byte equivalent in behavior.\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n vec3 f0 = vec3(0.04);\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v,\n n,\n n\n );\n\n#ifdef USE_LIGHTS\n PBRInfo_setAmbientLight(pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting.ambientColor);\n\n for(int i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);\n }\n }\n\n for(int i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));\n float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));\n color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);\n }\n }\n\n for(int i = 0; i < lighting.spotLightCount; i++) {\n if (i < lighting.spotLightCount) {\n PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));\n float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);\n color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color / attenuation);\n }\n }\n#endif\n\n#ifdef USE_IBL\n if (pbrMaterial.IBLenabled) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n#endif\n\n#ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled) {\n float ao = texture(pbr_occlusionSampler, occlusionUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n#endif\n\n vec3 emissive = pbrMaterial.emissiveFactor;\n#ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled) {\n emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;\n }\n#endif\n color += emissive * pbrMaterial.emissiveStrength;\n\n#ifdef PBR_DEBUG\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n#endif\n\n return vec4(applySceneColorManagement(color), baseColor.a);\n }\n\n float specularIntensity = pbrMaterial.specularIntensityFactor;\n#ifdef HAS_SPECULARINTENSITYMAP\n if (pbrMaterial.specularIntensityMapEnabled) {\n specularIntensity *= texture(pbr_specularIntensitySampler, specularIntensityUV).a;\n }\n#endif\n\n vec3 specularFactor = pbrMaterial.specularColorFactor;\n#ifdef HAS_SPECULARCOLORMAP\n if (pbrMaterial.specularColorMapEnabled) {\n specularFactor *= SRGBtoLINEAR(texture(pbr_specularColorSampler, specularColorUV)).rgb;\n }\n#endif\n\n transmission = pbrMaterial.transmissionFactor;\n#ifdef HAS_TRANSMISSIONMAP\n if (pbrMaterial.transmissionMapEnabled) {\n transmission *= texture(pbr_transmissionSampler, transmissionUV).r;\n }\n#endif\n transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);\n float thickness = max(pbrMaterial.thicknessFactor, 0.0);\n#ifdef HAS_THICKNESSMAP\n thickness *= texture(pbr_thicknessSampler, thicknessUV).g;\n#endif\n\n float diffuseTransmission = clamp(pbrMaterial.diffuseTransmissionFactor, 0.0, 1.0);\n#ifdef HAS_DIFFUSETRANSMISSIONMAP\n if (pbrMaterial.diffuseTransmissionMapEnabled) {\n diffuseTransmission *= texture(pbr_diffuseTransmissionSampler, diffuseTransmissionUV).a;\n }\n#endif\n diffuseTransmission *= (1.0 - metallic) * (1.0 - transmission);\n vec3 diffuseTransmissionColor = pbrMaterial.diffuseTransmissionColorFactor;\n#ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP\n if (pbrMaterial.diffuseTransmissionColorMapEnabled) {\n diffuseTransmissionColor *= SRGBtoLINEAR(\n texture(pbr_diffuseTransmissionColorSampler, diffuseTransmissionColorUV)\n ).rgb;\n }\n#endif\n vec3 multiscatterColor = pbrMaterial.multiscatterColorFactor;\n#ifdef HAS_MULTISCATTERCOLORMAP\n if (pbrMaterial.multiscatterColorMapEnabled) {\n multiscatterColor *= SRGBtoLINEAR(\n texture(pbr_multiscatterColorSampler, multiscatterColorUV)\n ).rgb;\n }\n#endif\n\n float clearcoatFactor = pbrMaterial.clearcoatFactor;\n float clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;\n#ifdef HAS_CLEARCOATMAP\n if (pbrMaterial.clearcoatMapEnabled) {\n clearcoatFactor *= texture(pbr_clearcoatSampler, clearcoatUV).r;\n }\n#endif\n#ifdef HAS_CLEARCOATROUGHNESSMAP\n if (pbrMaterial.clearcoatRoughnessMapEnabled) {\n clearcoatRoughness *= texture(pbr_clearcoatRoughnessSampler, clearcoatRoughnessUV).g;\n }\n#endif\n clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);\n clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);\n vec3 clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);\n clearcoatRoughness = widenSpecularRoughness(clearcoatRoughness, clearcoatNormal);\n\n vec3 sheenColor = pbrMaterial.sheenColorFactor;\n float sheenRoughness = pbrMaterial.sheenRoughnessFactor;\n#ifdef HAS_SHEENCOLORMAP\n if (pbrMaterial.sheenColorMapEnabled) {\n sheenColor *= SRGBtoLINEAR(texture(pbr_sheenColorSampler, sheenColorUV)).rgb;\n }\n#endif\n#ifdef HAS_SHEENROUGHNESSMAP\n if (pbrMaterial.sheenRoughnessMapEnabled) {\n sheenRoughness *= texture(pbr_sheenRoughnessSampler, sheenRoughnessUV).a;\n }\n#endif\n sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);\n\n float iridescence = pbrMaterial.iridescenceFactor;\n#ifdef HAS_IRIDESCENCEMAP\n if (pbrMaterial.iridescenceMapEnabled) {\n iridescence *= texture(pbr_iridescenceSampler, iridescenceUV).r;\n }\n#endif\n iridescence = clamp(iridescence, 0.0, 1.0);\n float iridescenceThickness = mix(\n pbrMaterial.iridescenceThicknessRange.x,\n pbrMaterial.iridescenceThicknessRange.y,\n 0.5\n );\n#ifdef HAS_IRIDESCENCETHICKNESSMAP\n iridescenceThickness = mix(\n pbrMaterial.iridescenceThicknessRange.x,\n pbrMaterial.iridescenceThicknessRange.y,\n texture(pbr_iridescenceThicknessSampler, iridescenceThicknessUV).g\n );\n#endif\n\n float anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);\n vec2 anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);\n#ifdef HAS_ANISOTROPYMAP\n if (pbrMaterial.anisotropyMapEnabled) {\n vec3 anisotropySample = texture(pbr_anisotropySampler, anisotropyUV).rgb;\n anisotropyStrength *= anisotropySample.b;\n vec2 mappedDirection = anisotropySample.rg * 2.0 - 1.0;\n if (length(mappedDirection) > 0.0001) {\n anisotropyDirection = normalize(mappedDirection);\n }\n }\n#endif\n anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);\n vec3 anisotropyTangent = normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);\n if (length(anisotropyTangent) < 0.0001) {\n anisotropyTangent = normalize(tbn[0]);\n }\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n float dielectricF0 = getDielectricF0(pbrMaterial.ior);\n vec3 dielectricSpecularF0 = min(\n vec3(dielectricF0) * specularFactor * specularIntensity,\n vec3(1.0)\n );\n dielectricSpecularF0 = getIridescenceTint(\n iridescence,\n iridescenceThickness,\n NdotV,\n dielectricSpecularF0\n );\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - dielectricSpecularF0);\n diffuseColor *= (1.0 - metallic) * (1.0 - transmission) * (1.0 - diffuseTransmission);\n vec3 specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);\n\n float clearcoatViewFresnel = dielectricSchlick(\n 0.04,\n clamp(abs(dot(clearcoatNormal, v)), 0.0, 1.0)\n );\n float sheenDirectionalAlbedo = maxComponent(sheenColor) *\n (0.157 + 0.343 * (1.0 - NdotV)) * (1.0 - sheenRoughness * 0.5);\n float baseLayerEnergy = (1.0 - clearcoatFactor * clearcoatViewFresnel) *\n (1.0 - clamp(sheenDirectionalAlbedo, 0.0, 1.0));\n diffuseColor *= baseLayerEnergy;\n specularColor *= baseLayerEnergy;\n\n // Compute reflectance.\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflecance to 0%.\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v,\n n,\n n\n );\n\n\n#ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(pbrInfo);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting.ambientColor,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n\n // Apply directional light\n for(int i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getDirectionalLight(i).color,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getDirectionalLight(i).color,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n\n // Apply point light\n for(int i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));\n float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getPointLight(i).color / attenuation,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getPointLight(i).color / attenuation,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n\n for(int i = 0; i < lighting.spotLightCount; i++) {\n if (i < lighting.spotLightCount) {\n PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));\n float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);\n color += calculateMaterialLightColor(\n pbrInfo,\n lighting_getSpotLight(i).color / attenuation,\n clearcoatNormal,\n clearcoatFactor,\n clearcoatRoughness,\n sheenColor,\n sheenRoughness,\n anisotropyTangent,\n anisotropyStrength\n );\n color += calculateDiffuseTransmissionLight(\n pbrInfo,\n lighting_getSpotLight(i).color / attenuation,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n }\n }\n#endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n#ifdef USE_IBL\n if (pbrMaterial.IBLenabled) {\n color += getIBLContribution(\n pbrInfo,\n n,\n getAnisotropicReflection(pbrInfo, anisotropyTangent, anisotropyStrength)\n );\n color += calculateClearcoatIBLContribution(\n pbrInfo,\n clearcoatNormal,\n -normalize(reflect(v, clearcoatNormal)),\n clearcoatFactor,\n clearcoatRoughness\n );\n color += calculateDiffuseTransmissionIBL(\n pbrInfo,\n diffuseTransmissionColor,\n diffuseTransmission,\n multiscatterColor,\n thickness\n );\n color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;\n }\n#endif\n\n // Apply optional PBR terms for additional (optional) shading\n#ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled) {\n float ao = texture(pbr_occlusionSampler, occlusionUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n#endif\n\n vec3 emissive = pbrMaterial.emissiveFactor;\n#ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled) {\n emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;\n }\n#endif\n color += emissive * pbrMaterial.emissiveStrength;\n\n if (transmission > 0.0) {\n#ifdef USE_TRANSMISSION_FRAMEBUFFER\n float dielectricFresnel = getDielectricF0(pbrMaterial.ior);\n float transmissionFresnel = dielectricFresnel +\n (1.0 - dielectricFresnel) * pow(1.0 - NdotV, 5.0);\n vec3 transmittedColor = getTransmittedSceneColor(\n pbr_vPosition,\n n,\n v,\n thickness,\n perceptualRoughness\n );\n color += transmittedColor * getVolumeAttenuation(thickness) *\n transmission * (1.0 - transmissionFresnel);\n#else\n color = mix(color, color * getVolumeAttenuation(thickness), transmission);\n#endif\n }\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n#ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, pbr_scaleFGDSpec.x);\n // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);\n // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);\n // color = mix(color, specContrib, pbr_scaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n#endif\n\n }\n\n#ifdef USE_TRANSMISSION_FRAMEBUFFER\n float alpha = clamp(baseColor.a, 0.0, 1.0);\n#else\n float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);\n#endif\n return vec4(applySceneColorManagement(color), alpha);\n}\n",defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,HAS_SPECULARCOLORMAP:!1,HAS_SPECULARINTENSITYMAP:!1,HAS_TRANSMISSIONMAP:!1,HAS_THICKNESSMAP:!1,HAS_CLEARCOATMAP:!1,HAS_CLEARCOATROUGHNESSMAP:!1,HAS_CLEARCOATNORMALMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_SHEENROUGHNESSMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_IRIDESCENCETHICKNESSMAP:!1,HAS_ANISOTROPYMAP:!1,HAS_BUMPMAP:!1,HAS_DIFFUSETRANSMISSIONMAP:!1,HAS_DIFFUSETRANSMISSIONCOLORMAP:!1,HAS_MULTISCATTERCOLORMAP:!1,USE_MATERIAL_EXTENSIONS:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:e=>e,uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",specularColorFactor:"vec3<f32>",specularIntensityFactor:"f32",specularColorMapEnabled:"i32",specularIntensityMapEnabled:"i32",ior:"f32",transmissionFactor:"f32",transmissionMapEnabled:"i32",thicknessFactor:"f32",attenuationDistance:"f32",attenuationColor:"vec3<f32>",clearcoatFactor:"f32",clearcoatRoughnessFactor:"f32",clearcoatMapEnabled:"i32",clearcoatRoughnessMapEnabled:"i32",sheenColorFactor:"vec3<f32>",sheenRoughnessFactor:"f32",sheenColorMapEnabled:"i32",sheenRoughnessMapEnabled:"i32",iridescenceFactor:"f32",iridescenceIor:"f32",iridescenceThicknessRange:"vec2<f32>",iridescenceMapEnabled:"i32",anisotropyStrength:"f32",anisotropyRotation:"f32",anisotropyDirection:"vec2<f32>",anisotropyMapEnabled:"i32",emissiveStrength:"f32",dispersion:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>",baseColorUVSet:"i32",baseColorUVTransform:"mat3x3<f32>",metallicRoughnessUVSet:"i32",metallicRoughnessUVTransform:"mat3x3<f32>",normalUVSet:"i32",normalUVTransform:"mat3x3<f32>",occlusionUVSet:"i32",occlusionUVTransform:"mat3x3<f32>",emissiveUVSet:"i32",emissiveUVTransform:"mat3x3<f32>",specularColorUVSet:"i32",specularColorUVTransform:"mat3x3<f32>",specularIntensityUVSet:"i32",specularIntensityUVTransform:"mat3x3<f32>",transmissionUVSet:"i32",transmissionUVTransform:"mat3x3<f32>",thicknessUVSet:"i32",thicknessUVTransform:"mat3x3<f32>",clearcoatUVSet:"i32",clearcoatUVTransform:"mat3x3<f32>",clearcoatRoughnessUVSet:"i32",clearcoatRoughnessUVTransform:"mat3x3<f32>",clearcoatNormalUVSet:"i32",clearcoatNormalUVTransform:"mat3x3<f32>",sheenColorUVSet:"i32",sheenColorUVTransform:"mat3x3<f32>",sheenRoughnessUVSet:"i32",sheenRoughnessUVTransform:"mat3x3<f32>",iridescenceUVSet:"i32",iridescenceUVTransform:"mat3x3<f32>",iridescenceThicknessUVSet:"i32",iridescenceThicknessUVTransform:"mat3x3<f32>",anisotropyUVSet:"i32",anisotropyUVTransform:"mat3x3<f32>",bumpFactor:"f32",bumpMapEnabled:"i32",diffuseTransmissionFactor:"f32",diffuseTransmissionMapEnabled:"i32",diffuseTransmissionColorFactor:"vec3<f32>",diffuseTransmissionColorMapEnabled:"i32",multiscatterColorFactor:"vec3<f32>",multiscatterColorMapEnabled:"i32",scatterAnisotropy:"f32",bumpUVSet:"i32",bumpUVTransform:"mat3x3<f32>",diffuseTransmissionUVSet:"i32",diffuseTransmissionUVTransform:"mat3x3<f32>",diffuseTransmissionColorUVSet:"i32",diffuseTransmissionColorUVTransform:"mat3x3<f32>",multiscatterColorUVSet:"i32",multiscatterColorUVTransform:"mat3x3<f32>"}},Lt=class{name;playing=!0;speed=1;startTime=0;constructor(e={}){this.name=e.name||"unnamed",Object.assign(this,e)}setTime(e){if(!this.playing)return;const t=(e/1e3-this.startTime)*this.speed;this.applyTime(t)}},Bt=class{clips;animations;constructor(e){this.clips=e,this.animations=e}animate(e){$e.warn(`${this.constructor.name}#animate is deprecated. Use ${this.constructor.name}#setTime instead`)(),this.setTime(e)}setTime(e){this.clips.forEach(t=>t.setTime(e))}getAnimations(){return this.clips}};function Ot(e,t,n){const r=Dt(e),i=Dt(t);let a=r.reduce((e,t,n)=>e+t*i[n],0);const s=a<0?-1:1;if(a=Math.min(Math.abs(a),1),a>.9995)return Dt(r.map((e,t)=>e+n*(i[t]*s-e)));const o=Math.acos(a),A=Math.sin(o),l=Math.sin((1-n)*o)/A,c=Math.sin(n*o)/A*s;return Dt(r.map((e,t)=>e*l+i[t]*c))}function Ft(e,t,n,r){const i=e["CUBICSPLINE"===t?3*n+1:n];return i?"quaternion"===r?Dt(i):[...i]:null}function Dt(e){const t=Math.hypot(...e);return t>0?e.map(e=>e/t):[0,0,0,1]}var Ut=class{name;times;values;interpolation;valueType;binding;constructor(e){this.name=e.name||e.binding.id||"unnamed",this.times=e.times,this.values=e.values,this.interpolation=e.interpolation||"LINEAR",this.valueType=e.valueType||"vector",this.binding=e.binding}get duration(){return this.times[this.times.length-1]||0}get sampler(){return{input:this.times,output:this.values,interpolation:this.interpolation}}evaluate(e){return function(e,t,n="vector"){const{input:r,output:i,interpolation:a="LINEAR"}=t;if(!r.length||!i.length||!Number.isFinite(e))return null;const s=r.length-1;if(e<=r[0]||0===s)return Ft(i,a,0,n);if(e>=r[s])return Ft(i,a,s,n);let o=0,A=s;for(;A-o>1;){const t=Math.floor((o+A)/2);r[t]<=e?o=t:A=t}const l=r[o],c=r[A]-l;if(c<=0||"STEP"===a)return Ft(i,a,o,n);const u=(e-l)/c;switch(a){case"LINEAR":{const e=i[o],t=i[A];return e&&t?"quaternion"===n?Ot(e,t,u):function(e,t,n){return e.map((e,r)=>(1-n)*e+n*t[r])}(e,t,u):null}case"CUBICSPLINE":{const e=i[3*o+1],t=i[3*o+2],r=i[3*A],a=i[3*A+1];if(!(e&&t&&r&&a))return null;const s=function(e,t,n,r,i,a){const s=a*a,o=s*a;return e.map((e,A)=>(2*o-3*s+1)*e+(o-2*s+a)*t[A]*i+(-2*o+3*s)*r[A]+(o-s)*n[A]*i)}(e,t,r,a,c,u);return"quaternion"===n?Dt(s):s}default:return null}}(e,this.sampler,this.valueType)}},Vt=class{name;tracks;duration;constructor(e){this.name=e.name||"unnamed",this.tracks=e.tracks,this.duration=e.duration??Math.max(0,...e.tracks.map(e=>e.duration))}},jt=class{clip;mixer;time=0;timeScale;weight;loop;repetitions;paused=!1;playing=!1;elapsedTime=0;fade=null;constructor(e,t,n={}){this.mixer=e,this.clip=t,this.loop=n.loop||"repeat",this.repetitions=n.repetitions??Number.POSITIVE_INFINITY,this.timeScale=n.timeScale??1,this.weight=n.weight??1}play(){return this.playing=!0,this.paused=!1,this}pause(){return this.paused=!0,this}resume(){return this.playing=!0,this.paused=!1,this}stop(){return this.playing=!1,this.paused=!1,this.fade=null,this.reset()}reset(){return this.elapsedTime=0,this.time=0,this}setTime(e){return this.elapsedTime=e,this.time=this.resolveLocalTime(e),this}setLoop(e,t=Number.POSITIVE_INFINITY){return this.loop=e,this.repetitions=t,this.time=this.resolveLocalTime(this.elapsedTime),this}setEffectiveWeight(e){return this.weight=Math.max(0,e),this.fade=null,this}setEffectiveTimeScale(e){return this.timeScale=e,this}fadeIn(e){return this.scheduleFade(1,e)}fadeOut(e){return this.scheduleFade(0,e)}crossFadeTo(e,t){return e.weight=0,e.play().fadeIn(t),this.fadeOut(t)}crossFadeFrom(e,t){return e.crossFadeTo(this,t),this}advance(e){this.playing&&!this.paused&&(this.advanceFade(Math.abs(e)),this.elapsedTime+=e*this.timeScale,this.time=this.resolveLocalTime(this.elapsedTime),this.hasFinished()&&(this.playing=!1))}get shouldApply(){return(this.playing||this.hasFinished())&&this.weight>0}scheduleFade(e,t){return t<=0?(this.weight=e,this.fade=null,this):(this.fade={duration:t,elapsedTime:0,startWeight:this.weight,endWeight:e},this)}advanceFade(e){if(!this.fade)return;this.fade.elapsedTime+=e;const t=Math.min(this.fade.elapsedTime/this.fade.duration,1);this.weight=this.fade.startWeight+(this.fade.endWeight-this.fade.startWeight)*t,1===t&&(this.fade=null)}hasFinished(){const e=this.clip.duration;return e<=0?"once"===this.loop:"once"===this.loop?this.elapsedTime>=e||this.elapsedTime<0:Number.isFinite(this.repetitions)&&Math.abs(this.elapsedTime)>=e*this.repetitions}resolveLocalTime(e){const t=this.clip.duration;if(t<=0)return 0;if("once"===this.loop)return Math.min(Math.max(e,0),t);if(Number.isFinite(this.repetitions)&&Math.abs(e)>=t*this.repetitions)return"ping-pong"===this.loop&&this.repetitions%2==0||e<0?0:t;const n=e>=0&&e<t?e:(e%t+t)%t;if("repeat"===this.loop)return n;const r=Math.floor(e/t);return 0===Math.abs(r%2)?n:t-n}},zt=class{time=0;timeScale=1;clips=/* @__PURE__ */new Map;actions=/* @__PURE__ */new Map;initialValues=/* @__PURE__ */new Map;constructor(e=[]){e.forEach(e=>this.addClip(e))}addClip(e){return this.clips.set(e.name,e),this}clipAction(e,t){const n="string"==typeof e?this.clips.get(e):e;if(!n)throw new Error(`Unknown animation clip: ${e}`);this.addClip(n);let r=this.actions.get(n);return r||(r=new jt(this,n,t),this.actions.set(n,r)),r}getAction(e){const t=this.clips.get(e);return t?this.actions.get(t):void 0}update(e){return this.advance(e),this.applyValues(),this}advance(e){const t=e*this.timeScale;return this.time+=t,this.actions.forEach(e=>e.advance(t)),this}setTime(e){return this.time=e,this.actions.forEach(t=>{t.paused||t.setTime(e*t.timeScale)}),this.applyValues(),this}stopAllAction(){return this.actions.forEach(e=>e.stop()),this}applyValues(){const e=/* @__PURE__ */new Map;this.actions.forEach(t=>{(t.shouldApply||t.playing&&0===t.weight)&&t.clip.tracks.forEach(n=>{const r=n.evaluate(t.time);if(!r)return;const i=n.binding.id||n.binding;if(!this.initialValues.has(i)){const e=n.binding.getValue?.();e&&this.initialValues.set(i,[...e])}if(0===t.weight&&!this.initialValues.has(i))return;const a=e.get(i);if(!a)return void e.set(i,{binding:n.binding,value:[...r],valueType:n.valueType,weight:t.weight});if(0===t.weight)return;const s=a.weight+t.weight,o=t.weight/s;a.value="quaternion"===n.valueType?Ot(a.value,r,o):a.value.map((e,t)=>e+(r[t]-e)*o),a.weight=s})}),e.forEach(({binding:e,value:t,valueType:n,weight:r},i)=>{const a=r<1?this.initialValues.get(i):void 0;a&&a.length===t.length&&(t="quaternion"===n?Ot(a,t,r):t.map((e,t)=>a[t]+(e-a[t])*r)),e.setValue(t)})}};function Gt(e){const t=e.value;if(t instanceof Float32Array)return t;const n=new Float32Array(t.length),r=Qt(t),i=t instanceof Int8Array||t instanceof Int16Array||t instanceof Int32Array;for(let a=0;a<t.length;a++){const s=Number(t[a]);n[a]=e.normalized&&r?i?Math.max(s/r,-1):s/r:s}return n}function Ht(e,t,n,r){const i={};for(const c of["POSITION","NORMAL","TANGENT"]){const e=t.attributes[c];e&&(i[c]=Gt(e))}const a=function(e,t,n){const r={};for(const i of["POSITION","NORMAL","TANGENT"]){const a=e[i];if(!a)continue;const s=new Float32Array(a),o="TANGENT"===i?4:3,A=Math.floor(a.length/o);for(let e=0;e<Math.min(t.length,n.length);e++){const r=n[e],a=t[e][i];if(!r||!a)continue;const l="TANGENT"===i&&a.length===4*A?4:3;for(let e=0;e<A;e++){const t=e*o,n=e*l;for(let e=0;e<3;e++)s[t+e]+=(a[n+e]||0)*r}}"POSITION"!==i&&Kt(s,o),r[i]=s}return r}(i,n,r),s={};for(const[c,u]of Object.entries(t.attributes))u&&(s[c]=u);for(const c of["POSITION","NORMAL","TANGENT"]){const e=a[c],t=s[c];e&&t&&(s[c]={...t,value:qt(t,e)})}const o=new E({id:t.id,topology:t.topology||"triangle-list",vertexCount:t.vertexCount,indices:t.indices,attributes:s,bufferLayout:t.bufferLayout}),A=T(o).attributes.geometry?.value,l=e._gpuGeometry?.attributes.geometry||e.bufferAttributes.geometry;if(A&&l)l.write(A);else for(const c of["POSITION","NORMAL","TANGENT"]){const t=a[c];if(t){const n="POSITION"===c?"positions":"NORMAL"===c?"normals":"TANGENT";e.bufferAttributes[n]?.write(t)}}}function qt(e,t){if(e.value instanceof Float32Array)return t;const n=e.value.slice(),r=Qt(n),i=n instanceof Int8Array||n instanceof Int16Array||n instanceof Int32Array;for(let a=0;a<t.length;a++){const s=t[a];n[a]=e.normalized&&r?Math.round(Math.max(i?-1:0,Math.min(1,s))*r):s}return n}function Qt(e){return e instanceof Int8Array?127:e instanceof Uint8Array||e instanceof Uint8ClampedArray?255:e instanceof Int16Array?32767:e instanceof Uint16Array?65535:e instanceof Int32Array?2147483647:e instanceof Uint32Array?4294967295:0}function Kt(e,t){for(let n=0;n<e.length;n+=t){const t=Math.hypot(e[n],e[n+1],e[n+2]);t>0&&(e[n]/=t,e[n+1]/=t,e[n+2]/=t)}}function Wt(e){const{joints:t,meshNode:n,worldMatrices:r,inverseBindMatrices:i,target:a}=e,s=t.length,o=a&&a.length===16*s?a:new Float32Array(16*s),A=n?r.get(n)||n.matrix:void 0,l=A?new H(A).invert():null;for(let c=0;c<s;c++){const e=t[c],n=r.get(e)||e.matrix,a=l?new H(l).multiplyRight(n):new H(n),s=16*c;if(i&&i.length>=s+16){const e=new H;for(let t=0;t<16;t++)e[t]=i[s+t];a.multiplyRight(e)}o.set(a,s)}return o}var Jt=class{device;modules;_materialBindingNames;_materialModuleNames;constructor(e,t={}){this.device=e,this.modules=t.modules||[];const n=new Ge(Object.fromEntries(this.modules.map(e=>[e.name,e])));this._materialBindingNames=function(e){const t=/* @__PURE__ */new Set;for(const n of Object.values(e.modules))for(const e of n.bindingLayout||[])3===e.group&&t.add(e.name);return t}(n),this._materialModuleNames=function(e){const t=/* @__PURE__ */new Set;for(const n of Object.values(e.modules))n.name&&n.bindingLayout?.some(e=>3===e.group&&e.name===n.name)&&t.add(n.name);return t}(n)}createMaterial(e={}){return new Xt(this.device,{...e,factory:this})}getBindingNames(){return Array.from(this._materialBindingNames)}ownsBinding(e){if(this._materialBindingNames.has(e))return!0;const t=$t(e);return!!t&&this._materialModuleNames.has(t)}ownsModule(e){return this._materialModuleNames.has(e)}getBindingsByGroup(e){return Object.keys(e).length>0?{3:e}:{}}};function $t(e){return e.endsWith("Uniforms")?e.slice(0,-8):null}var Xt=class{id;device;factory;shaderInputs;bindings={};_uniformStore;_bindGroupCacheToken={};_dynamicResourceGenerations={};constructor(e,t={}){this.id=t.id||Ve("material"),this.device=e,this.factory=t.factory||new Jt(e,{modules:t.modules||t.shaderInputs?.getModules()||[]});const n=Object.fromEntries((t.shaderInputs?.getModules()||this.factory.modules).map(e=>[e.name,e]));this.shaderInputs=t.shaderInputs||new Ge(n),this._uniformStore=new je(this.device,this.shaderInputs.modules);for(const[r,i]of Object.entries(this.shaderInputs.modules))if(this.ownsModule(r)&&He(i)){const e=this._uniformStore.getManagedUniformBuffer(r);this.bindings[`${r}Uniforms`]=e}this.updateShaderInputs(),t.bindings&&this._replaceOwnedBindings(t.bindings)}destroy(){this._uniformStore.destroy()}clone(e={}){const t=this.factory.createMaterial({id:e.id,shaderInputs:e.shaderInputs,bindings:{...this.getResourceBindings(),...e.bindings}});return e.shaderInputs||t.setProps(this.shaderInputs.getUniformValues()),e.moduleProps&&t.setProps(e.moduleProps),t.updateShaderInputs(),t}ownsBinding(e){return this.factory.ownsBinding(e)}ownsModule(e){return this.factory.ownsModule(e)}setProps(e){this.shaderInputs.setProps(e)}updateShaderInputs(e){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(),e),this._setOwnedBindings(this.shaderInputs.getBindingValues())&&(this._bindGroupCacheToken={})}getResourceBindings(){const e={};for(const[t,n]of Object.entries(this.bindings))$t(t)||(e[t]=n);return e}getBindings(e={bindings:[]}){this._syncDynamicResourceGenerations();const t={},n=t;for(const[r,i]of Object.entries(this.bindings))if(A(i)){const t=h(e,r,{fallbackGroup:3}),a=t?i.resolveTextureBinding(t):null;a&&(n[r]=a)}else i instanceof Qe?n[r]=i.buffer:qe(i)?n[r]=Ke(i):n[r]=i;return this._syncDynamicResourceGenerations(),t}getBindingsByGroup(e={bindings:[]}){return this.factory.getBindingsByGroup(this.getBindings(e))}getBindGroupCacheKey(e){return this._syncDynamicResourceGenerations(),3===e?this._bindGroupCacheToken:null}getBindingsUpdateTimestamp(){let e=0;for(const t of Object.values(this.bindings))t instanceof Ye?e=Math.max(e,t.texture.updateTimestamp):t instanceof Xe||t instanceof G||t instanceof a||t instanceof Qe?e=Math.max(e,t.updateTimestamp):A(t)?e=t.isReady?Math.max(e,t.updateTimestamp):1/0:qe(t)&&(e=Math.max(e,(t.buffer,t.buffer.updateTimestamp)));return e}_replaceOwnedBindings(e){this._setOwnedBindings(e)&&(this._bindGroupCacheToken={})}_setOwnedBindings(e){let t=!1;for(const[n,r]of Object.entries(e))void 0!==r&&this.ownsBinding(n)&&this.bindings[n]!==r&&(this.bindings[n]=r,t=!0);return t}_syncDynamicResourceGenerations(){const e={};let t=!1;for(const[n,r]of Object.entries(this.bindings)){const i=Yt(r);null!==i&&(e[n]=i,this._dynamicResourceGenerations[n]!==i&&(t=!0))}Object.keys(e).length!==Object.keys(this._dynamicResourceGenerations).length&&(t=!0),this._dynamicResourceGenerations=e,t&&(this._bindGroupCacheToken={})}};function Yt(e){return A(e)?e.generation:ze(e)?.generation??null}var Zt={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function en(e){return e?Array.isArray(e)?e[0]??null:e:null}function tn(e){if(Q(e))return K(e);if("object"==typeof e&&"width"in e&&"height"in e)return{width:e.width,height:e.height};throw new Error("Unsupported mip-level data")}function nn(e){return"object"==typeof e&&null!==e&&"data"in e&&"width"in e&&"height"in e}function rn(e){return ArrayBuffer.isView(e)}function an(e){const{textureFormat:t,format:n}=e;if(t&&n&&t!==n)throw new Error(`Conflicting texture formats "${t}" and "${n}" provided for the same mip level`);return t??n}function sn(e){const t=Zt[e];if(void 0===t)throw new Error(`Invalid cube face: ${e}`);return t}function on(e,t){return 6*e+sn(t)}function An(e){throw new Error("setTexture1DData not supported in WebGL.")}function ln(e,t,n,r){const i=(a=t,Array.isArray(a)?a:[a]);var a;const s=e,o=[];for(let A=0;A<i.length;A++){const e=i[A];if(Q(e))o.push({type:"external-image",image:e,z:s,mipLevel:A});else if(nn(e))o.push({type:"texture-data",data:e,textureFormat:an(e),z:s,mipLevel:A});else{if(!rn(e)||!n)throw new Error("Unsupported 2D mip-level payload");o.push({type:"texture-data",data:{data:e,width:Math.max(1,n.width>>A),height:Math.max(1,n.height>>A),...r?{format:r}:{}},textureFormat:r,z:s,mipLevel:A})}}return o}function cn(e){const t=[];for(let n=0;n<e.length;n++)t.push(...ln(n,e[n]));return t}function un(e){const t=[];for(let n=0;n<e.length;n++)t.push(...ln(n,e[n]));return t}function fn(e){const t=[];for(const[n,r]of Object.entries(e)){const e=sn(n);t.push(...ln(e,r))}return t}function dn(e){const t=[];return e.forEach((e,n)=>{for(const[r,i]of Object.entries(e)){const e=on(n,r);t.push(...ln(e,i))}}),t}var hn=class e{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;generation=0;updateTimestamp;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error("Texture not initialized yet");return this._texture}get sampler(){if(!this._sampler)throw new Error("Sampler not initialized yet");return this._sampler}get view(){if(!this._view)throw new Error("View not initialized yet");return this._view}get[Symbol.toStringTag](){return"DynamicTexture"}toString(){const e=this._texture?.width??this.props.width??"?",t=this._texture?.height??this.props.height??"?";return`DynamicTexture:"${this.id}":${e}x${t}px:(${this.isReady?"ready":"loading..."})`}resolveTextureBinding(e){return this.isReady?this.texture:null}constructor(t,n){this.device=t;const r=Ve("dynamic-texture"),i=n;this.props={...e.defaultProps,id:r,...n,data:null},this.id=this.props.id,this.ready=new Promise((e,t)=>{this.resolveReady=e,this.rejectReady=t}),this.updateTimestamp=this.device.incrementTimestamp(),this.initAsync(i)}async initAsync(e){try{const t=await this._loadAllData(e);this._checkNotDestroyed();const n=t.data?function(e){if(!e.data)return[];const t=e.width&&e.height?{width:e.width,height:e.height}:void 0,n="format"in e?e.format:void 0;switch(e.dimension){case"1d":return An(e.data);case"2d":return ln(0,e.data,t,n);case"3d":return cn(e.data);case"2d-array":return un(e.data);case"cube":return fn(e.data);case"cube-array":return dn(e.data);default:throw new Error(`Unhandled dimension ${e.dimension}`)}}({...t,width:e.width,height:e.height,format:e.format}):[],r="format"in e&&void 0!==e.format,i="usage"in e&&void 0!==e.usage,a=()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};const e=function(e){const{dimension:t,data:n}=e;if(!n)return null;switch(t){case"1d":{const e=en(n);if(!e)return null;const{width:t}=tn(e);return{width:t,height:1}}case"2d":{if(ArrayBuffer.isView(n))return null;const e=en(n);return e?tn(e):null}case"3d":case"2d-array":{if(!Array.isArray(n)||0===n.length)return null;const e=en(n[0]);return e?tn(e):null}case"cube":{const e=Object.keys(n)[0]??null;if(!e)return null;const t=en(n[e]);return t?tn(t):null}case"cube-array":{if(!Array.isArray(n)||0===n.length)return null;const e=n[0],t=Object.keys(e)[0]??null;if(!t)return null;const r=en(e[t]);return r?tn(r):null}default:return null}}(t);return e||{width:this.props.width||1,height:this.props.height||1}},s=a();if(!s||s.width<=0||s.height<=0)throw new Error(`${this} size could not be determined or was zero`);const o=function(e,t,n,r){if(0===t.length)return{subresources:t,mipLevels:1,format:r.format,hasExplicitMipChain:!1};const i=/* @__PURE__ */new Map;for(const c of t){const e=i.get(c.z)??[];e.push(c),i.set(c.z,e)}const a=t.some(e=>e.mipLevel>0);let s=r.format,o=Number.POSITIVE_INFINITY;const A=[];for(const[c,u]of i){const t=[...u].sort((e,t)=>e.mipLevel-t.mipLevel),r=t[0];if(!r||0!==r.mipLevel)throw new Error(`DynamicTexture: slice ${c} is missing mip level 0`);const i=mn(e,r);if(i.width!==n.width||i.height!==n.height)throw new Error(`DynamicTexture: slice ${c} base level dimensions ${i.width}x${i.height} do not match expected ${n.width}x${n.height}`);const a=pn(r);if(a){if(s&&s!==a)throw new Error(`DynamicTexture: slice ${c} base level format "${a}" does not match texture format "${s}"`);s=a}const l=s&&e.isTextureFormatCompressed(s)?gn(e,i.width,i.height,s):e.getMipLevelCount(i.width,i.height);let f=0;for(let n=0;n<t.length;n++){const r=t[n];if(!r||r.mipLevel!==n)break;if(n>=l)break;const a=mn(e,r),o=Math.max(1,i.width>>n),c=Math.max(1,i.height>>n);if(a.width!==o||a.height!==c)break;const u=pn(r);if(u&&(s||(s=u),u!==s))break;f++,A.push(r)}o=Math.min(o,f)}const l=Number.isFinite(o)?Math.max(1,o):1;return{subresources:A.filter(e=>e.mipLevel<l),mipLevels:l,format:s,hasExplicitMipChain:a}}(this.device,n,s,{format:r?e.format:void 0}),A=o.format??this.props.format,l={...this.props,...s,format:A,mipLevels:1,data:void 0};this.device.isTextureFormatCompressed(A)&&!i&&(l.usage=G.SAMPLE|G.COPY_DST);const c=this.props.mipmaps&&!o.hasExplicitMipChain&&!this.device.isTextureFormatCompressed(A);if("webgpu"===this.device.type&&c){const e="3d"===this.props.dimension?G.SAMPLE|G.STORAGE|G.COPY_DST|G.COPY_SRC:G.SAMPLE|G.RENDER|G.COPY_DST|G.COPY_SRC;l.usage|=e}const u=this.device.getMipLevelCount(l.width,l.height),f=o.hasExplicitMipChain?o.mipLevels:"auto"===this.props.mipLevels?u:Math.max(1,Math.min(u,this.props.mipLevels??1)),d={...l,mipLevels:f};this._texture=this.device.createTexture(d),this._sampler=this.texture.sampler,this._view=this.texture.view,this._touchGeneration(),o.subresources.length&&this._setTextureSubresources(o.subresources),!this.props.mipmaps||o.hasExplicitMipChain||c||$e.warn(`${this} skipping auto-generated mipmaps for compressed texture format`)(),c&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),$e.info(1,`${this} created`)()}catch(Lr){const t=Lr instanceof Error?Lr:new Error(String(Lr));this.rejectReady(t)}}destroy(){this._texture&&(this._texture.destroy(),this._texture=null,this._sampler=null,this._view=null),this.isReady=!1,this.destroyed=!0}generateMipmaps(){"webgl"===this.device.type?(this.texture.generateMipmapsWebGL(),this._touch()):"webgpu"===this.device.type?(this.device.generateMipmapsWebGPU(this.texture),this._touch()):$e.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(e={}){this._checkReady();const t=e instanceof q?e:this.device.createSampler(e);this.texture.setSampler(t),this._sampler=t,this._touchGeneration()}async readBuffer(e={}){this.isReady||await this.ready;const t=e.width??this.texture.width,n=e.height??this.texture.height,r=e.depthOrArrayLayers??this.texture.depth,i=this.texture.computeMemoryLayout({width:t,height:n,depthOrArrayLayers:r}),a=this.device.createBuffer({byteLength:i.byteLength,usage:Xe.COPY_DST|Xe.MAP_READ});this.texture.readBuffer({...e,width:t,height:n,depthOrArrayLayers:r},a);const s=this.device.createFence();return await s.signaled,s.destroy(),a}async readAsync(e={}){this.isReady||await this.ready;const t=e.width??this.texture.width,n=e.height??this.texture.height,r=e.depthOrArrayLayers??this.texture.depth,i=this.texture.computeMemoryLayout({width:t,height:n,depthOrArrayLayers:r}),a=await this.readBuffer(e),s=await a.readAsync(0,i.byteLength);return a.destroy(),s.buffer instanceof ArrayBuffer?s.buffer:s.slice().buffer}resize(e){if(this._checkReady(),e.width===this.texture.width&&e.height===this.texture.height)return!1;const t=this.texture;return this._texture=t.clone(e),this._sampler=this.texture.sampler,this._view=this.texture.view,t.destroy(),this._touchGeneration(),$e.info(`${this} resized`),!0}getCubeFaceIndex(e){const t=Zt[e];if(void 0===t)throw new Error(`Invalid cube face: ${e}`);return t}getCubeArrayFaceIndex(e,t){return 6*e+this.getCubeFaceIndex(t)}setTexture1DData(e){if(this._checkReady(),"1d"!==this.texture.props.dimension)throw new Error(`${this} is not 1d`);const t=An();this._setTextureSubresources(t)}setTexture2DData(e,t=0){if(this._checkReady(),"2d"!==this.texture.props.dimension)throw new Error(`${this} is not 2d`);const n=ln(t,e);this._setTextureSubresources(n)}setTexture3DData(e){if("3d"!==this.texture.props.dimension)throw new Error(`${this} is not 3d`);const t=cn(e);this._setTextureSubresources(t)}setTextureArrayData(e){if("2d-array"!==this.texture.props.dimension)throw new Error(`${this} is not 2d-array`);const t=un(e);this._setTextureSubresources(t)}setTextureCubeData(e){if("cube"!==this.texture.props.dimension)throw new Error(`${this} is not cube`);const t=fn(e);this._setTextureSubresources(t)}setTextureCubeArrayData(e){if("cube-array"!==this.texture.props.dimension)throw new Error(`${this} is not cube-array`);const t=dn(e);this._setTextureSubresources(t)}_setTextureSubresources(e){for(const t of e){const{z:e,mipLevel:n}=t;switch(t.type){case"external-image":const{image:r,flipY:i}=t;this.texture.copyExternalImage({image:r,z:e,mipLevel:n,flipY:i});break;case"texture-data":const{data:a,textureFormat:s}=t;if(s&&s!==this.texture.format)throw new Error(`${this} mip level ${n} uses format "${s}" but texture format is "${this.texture.format}"`);this.texture.writeData(a.data,{x:0,y:0,z:e,width:a.width,height:a.height,depthOrArrayLayers:1,mipLevel:n});break;default:throw new Error("Unsupported 2D mip-level payload")}}e.length>0&&this._touch()}async _loadAllData(e){const t=await bn(e.data);return{dimension:e.dimension??"2d",data:t??null}}_checkNotDestroyed(){this.destroyed&&$e.warn(`${this} already destroyed`)}_checkReady(){this.isReady||$e.warn(`${this} Cannot perform this operation before ready`)}_touch(){this.updateTimestamp=this.device.incrementTimestamp()}_touchGeneration(){this.generation++,this._touch()}static defaultProps={...G.defaultProps,dimension:"2d",data:null,mipmaps:!1}};function pn(e){if("texture-data"===e.type)return e.textureFormat??an(e.data)}function mn(e,t){switch(t.type){case"external-image":return e.getExternalImageSize(t.image);case"texture-data":return{width:t.data.width,height:t.data.height};default:throw new Error("Unsupported texture subresource")}}function gn(e,t,n,r){const{blockWidth:i=1,blockHeight:a=1}=e.getTextureFormatInfo(r);let s=1;for(let o=1;;o++){const e=Math.max(1,t>>o),r=Math.max(1,n>>o);if(e<i||r<a)break;s++}return s}async function bn(e){if(e=await e,Array.isArray(e))return await Promise.all(e.map(bn));if(e&&"object"==typeof e&&e.constructor===Object){const t=e,n=await Promise.all(Object.values(t).map(bn)),r=Object.keys(t),i={};for(let e=0;e<r.length;e++)i[r[e]]=n[e];return i}return e}function vn(e,t){if(!e)throw new Error(t)}var yn=class{id;matrix=new H;display=!0;position=new de;rotation=new de;scale=new de(1,1,1);userData={};props={};constructor(e={}){const{id:t}=e;this.id=t||Ve(this.constructor.name),this._setScenegraphNodeProps(e)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(e){return this._setScenegraphNodeProps(e),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(e){return vn(3===e.length,"setPosition requires vector argument"),this.position=e,this}setRotation(e){return vn(3===e.length||4===e.length,"setRotation requires vector argument"),this.rotation=e,this}setScale(e){return vn(3===e.length,"setScale requires vector argument"),this.scale=e,this}setMatrix(e,t=!0){t?this.matrix.copy(e):this.matrix=e}setMatrixComponents(e){const{position:t,rotation:n,scale:r,update:i=!0}=e;return t&&this.setPosition(t),n&&this.setRotation(n),r&&this.setScale(r),i&&this.updateMatrix(),this}updateMatrix(){if(this.matrix.identity(),this.matrix.translate(this.position),4===this.rotation.length){const e=(new H).fromQuaternion(this.rotation);this.matrix.multiplyRight(e)}else this.matrix.rotateXYZ(this.rotation);return this.matrix.scale(this.scale),this}update({position:e,rotation:t,scale:n}={}){return e&&this.setPosition(e),t&&this.setRotation(t),n&&this.setScale(n),this.updateMatrix(),this}getCoordinateUniforms(e,t){t=t||this.matrix;const n=new H(e).multiplyRight(t),r=n.invert(),i=r.transpose();return{viewMatrix:e,modelMatrix:t,objectMatrix:t,worldMatrix:n,worldInverseMatrix:r,worldInverseTransposeMatrix:i}}_setScenegraphNodeProps(e){void 0!==e.display&&(this.display=e.display),e?.position&&this.setPosition(e.position),e?.rotation&&this.setRotation(e.rotation),e?.scale&&this.setScale(e.scale),this.updateMatrix(),e?.matrix&&this.setMatrix(e.matrix),Object.assign(this.props,e)}};function xn(e,t,n){const r=new H(n);for(let i=0;i<8;i++){const n=new de(t[1&i?1:0][0],t[2&i?1:0][1],t[4&i?1:0][2]);r.transformAsPoint(n,n);for(let t=0;t<3;t++)e[0][t]=Math.min(e[0][t],n[t]),e[1][t]=Math.max(e[1][t],n[t])}}function _n(e){return Number.isFinite(e[0][0])}var wn=class e extends yn{children;constructor(e={}){e=Array.isArray(e)?{children:e}:e;const{children:t=[]}=e;$e.assert(t.every(e=>e instanceof yn),"every child must an instance of ScenegraphNode"),super(e),this.children=t}getBounds(){const e=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((t,{worldMatrix:n})=>{const r=t.getBounds();if(!r)return;const i=new H(n).multiplyRight(t.matrix);xn(e,r,i)}),_n(e)?e:null}destroy(){this.children.forEach(e=>e.destroy()),this.removeAll(),super.destroy()}add(...e){for(const t of e)Array.isArray(t)?this.add(...t):this.children.push(t);return this}remove(e){const t=this.children,n=t.indexOf(e);return n>-1&&t.splice(n,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:n=new H}={}){if(!this.display)return;const r=new H(n).multiplyRight(this.matrix);for(const i of this.children)i.display&&(i instanceof e?i.traverse(t,{worldMatrix:r}):t(i,{worldMatrix:r}))}traverseDepthSorted(e,{viewMatrix:t,worldMatrix:n=new H,order:r="back-to-front"}){const i=new H(t),a=[];this.traverse((e,t)=>{const n=e.getBounds(),r=n?new de(n[0]).add(n[1]).divide([2,2,2]):new de,s=new H(t.worldMatrix).multiplyRight(e.matrix);s.transformAsPoint(r,r),i.transformAsPoint(r,r),a.push({node:e,context:{worldMatrix:s,bounds:n,depth:-r[2]},index:a.length})},{worldMatrix:new H(n)});const s="back-to-front"===r?-1:1;a.sort((e,t)=>s*(e.context.depth-t.context.depth)||e.index-t.index);for(const{node:o,context:A}of a)e(o,A)}preorderTraversal(t,{worldMatrix:n=new H}={}){const r=new H(n).multiplyRight(this.matrix);t(this,{worldMatrix:r});for(const i of this.children)i instanceof e?i.preorderTraversal(t,{worldMatrix:r}):t(i,{worldMatrix:r})}},Tn=class extends yn{model;instanceMatrices;bounds=null;managedResources;constructor(e){super(e),this.model=e.model,this.managedResources=e.managedResources||[],this.instanceMatrices=e.instanceMatrices||null,this.bounds=e.bounds?this.instanceMatrices?function(e,t){const n=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];for(const r of t)xn(n,e,r);return _n(n)?n:null}(e.bounds,this.instanceMatrices):e.bounds:null,this.setProps(e)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(e=>e.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(e){return this.model.draw(e)}};var Sn=class{static get componentName(){return Object.prototype.hasOwnProperty.call(this,"extensionName")?this.extensionName:""}constructor(e){e&&(this.opts=e)}equals(e){return this===e||this.constructor===e.constructor&&be(this.opts,e.opts,1)}getShaders(e){return null}getSubLayerProps(e){const{defaultProps:t}=e.constructor,n={updateTriggers:{}};for(const r in t)if(r in this.props){const e=t[r],i=this.props[r];n[r]=i,e&&"accessor"===e.type&&(n.updateTriggers[r]=this.props.updateTriggers[r],"function"==typeof i&&(n[r]=this.getSubLayerAccessor(i)))}return n}initializeState(e,t){}updateState(e,t){}onNeedsRedraw(e){}getNeedsPickingBuffer(e){return!1}draw(e,t){}finalizeState(e,t){}};function Mn(e,t,n=2,r,i="xy"){const a=t&&t.length,s=a?t[0]*n:e.length;let o=En(e,0,s,n,!0,r&&r[0],i);const A=[];if(!o||o.next===o.prev)return A;let l,c,u,f,d,h,p;if(a&&(o=function(e,t,n,r,i,a){const s=[];let o,A,l,c,u;for(o=0,A=t.length;o<A;o++)l=t[o]*r,c=o<A-1?t[o+1]*r:e.length,u=En(e,l,c,r,!1,i&&i[o+1],a),u===u.next&&(u.steiner=!0),s.push(Dn(u));for(s.sort(Ln),o=0;o<s.length;o++)n=Bn(s[o],n);return n}(e,t,o,n,r,i)),e.length>80*n){f=c=e[0],d=u=e[1];for(let t=n;t<s;t+=n)h=e[t],p=e[t+1],h<f&&(f=h),p<d&&(d=p),h>c&&(c=h),p>u&&(u=p);l=Math.max(c-f,u-d),l=0!==l?32767/l:0}return In(o,A,n,f,d,l,0),A}function En(e,t,n,r,i,a,s){let o,A;void 0===a&&(a=_(e,{start:t,end:n,size:r,plane:s}));let l=v[s[0]],c=v[s[1]];if(i===a<0)for(o=t;o<n;o+=r)A=Wn(o,e[o+l],e[o+c],A);else for(o=n-r;o>=t;o-=r)A=Wn(o,e[o+l],e[o+c],A);return A&&zn(A,A.next)&&(Jn(A),A=A.next),A}function Cn(e,t){if(!e)return e;t||(t=e);let n,r=e;do{if(n=!1,r.steiner||!zn(r,r.next)&&0!==jn(r.prev,r,r.next))r=r.next;else{if(Jn(r),r=t=r.prev,r===r.next)break;n=!0}}while(n||r!==t);return t}function In(e,t,n,r,i,a,s){if(!e)return;!s&&a&&function(e,t,n,r){let i=e;do{0===i.z&&(i.z=Fn(i.x,i.y,t,n,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==e);i.prevZ.nextZ=null,i.prevZ=null,function(e){let t,n,r,i,a,s,o,A,l=1;do{for(i=e,e=null,A=null,r=0;i;){for(r++,s=i,a=0,n=0;n<l&&(a++,s=s.nextZ,s);n++);for(o=l;a>0||o>0&&s;)0!==a&&(0===o||!s||i.z<=s.z)?(t=i,i=i.nextZ,a--):(t=s,s=s.nextZ,o--),A?A.nextZ=t:e=t,t.prevZ=A,A=t;i=s}A.nextZ=null,l*=2}while(r>1)}(i)}(e,r,i,a);let o,A,l=e;for(;e.prev!==e.next;)if(o=e.prev,A=e.next,a?Pn(e,r,i,a):Rn(e))t.push(o.i/n|0),t.push(e.i/n|0),t.push(A.i/n|0),Jn(e),e=A.next,l=A.next;else if((e=A)===l){s?1===s?In(e=Nn(Cn(e),t,n),t,n,r,i,a,2):2===s&&kn(e,t,n,r,i,a):In(Cn(e),t,n,r,i,a,1);break}}function Rn(e){const t=e.prev,n=e,r=e.next;if(jn(t,n,r)>=0)return!1;const i=t.x,a=n.x,s=r.x,o=t.y,A=n.y,l=r.y,c=i<a?i<s?i:s:a<s?a:s,u=o<A?o<l?o:l:A<l?A:l,f=i>a?i>s?i:s:a>s?a:s,d=o>A?o>l?o:l:A>l?A:l;let h=r.next;for(;h!==t;){if(h.x>=c&&h.x<=f&&h.y>=u&&h.y<=d&&Un(i,o,a,A,s,l,h.x,h.y)&&jn(h.prev,h,h.next)>=0)return!1;h=h.next}return!0}function Pn(e,t,n,r){const i=e.prev,a=e,s=e.next;if(jn(i,a,s)>=0)return!1;const o=i.x,A=a.x,l=s.x,c=i.y,u=a.y,f=s.y,d=o<A?o<l?o:l:A<l?A:l,h=c<u?c<f?c:f:u<f?u:f,p=o>A?o>l?o:l:A>l?A:l,m=c>u?c>f?c:f:u>f?u:f,g=Fn(d,h,t,n,r),b=Fn(p,m,t,n,r);let v=e.prevZ,y=e.nextZ;for(;v&&v.z>=g&&y&&y.z<=b;){if(v.x>=d&&v.x<=p&&v.y>=h&&v.y<=m&&v!==i&&v!==s&&Un(o,c,A,u,l,f,v.x,v.y)&&jn(v.prev,v,v.next)>=0)return!1;if(v=v.prevZ,y.x>=d&&y.x<=p&&y.y>=h&&y.y<=m&&y!==i&&y!==s&&Un(o,c,A,u,l,f,y.x,y.y)&&jn(y.prev,y,y.next)>=0)return!1;y=y.nextZ}for(;v&&v.z>=g;){if(v.x>=d&&v.x<=p&&v.y>=h&&v.y<=m&&v!==i&&v!==s&&Un(o,c,A,u,l,f,v.x,v.y)&&jn(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;y&&y.z<=b;){if(y.x>=d&&y.x<=p&&y.y>=h&&y.y<=m&&y!==i&&y!==s&&Un(o,c,A,u,l,f,y.x,y.y)&&jn(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function Nn(e,t,n){let r=e;do{const i=r.prev,a=r.next.next;!zn(i,a)&&Gn(i,r,r.next,a)&&Qn(i,a)&&Qn(a,i)&&(t.push(i.i/n|0),t.push(r.i/n|0),t.push(a.i/n|0),Jn(r),Jn(r.next),r=e=a),r=r.next}while(r!==e);return Cn(r)}function kn(e,t,n,r,i,a){let s=e;do{let e=s.next.next;for(;e!==s.prev;){if(s.i!==e.i&&Vn(s,e)){let o=Kn(s,e);return s=Cn(s,s.next),o=Cn(o,o.next),In(s,t,n,r,i,a,0),void In(o,t,n,r,i,a,0)}e=e.next}s=s.next}while(s!==e)}function Ln(e,t){return e.x-t.x}function Bn(e,t){const n=function(e,t){let n=t;const r=e.x,i=e.y;let a,s=-1/0;do{if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){const e=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(e<=r&&e>s&&(s=e,a=n.x<n.next.x?n:n.next,e===r))return a}n=n.next}while(n!==t);if(!a)return null;const o=a,A=a.x,l=a.y;let c,u=1/0;n=a;do{r>=n.x&&n.x>=A&&r!==n.x&&Un(i<l?r:s,i,A,l,i<l?s:r,i,n.x,n.y)&&(c=Math.abs(i-n.y)/(r-n.x),Qn(n,e)&&(c<u||c===u&&(n.x>a.x||n.x===a.x&&On(a,n)))&&(a=n,u=c)),n=n.next}while(n!==o);return a}(e,t);if(!n)return t;const r=Kn(n,e);return Cn(r,r.next),Cn(n,n.next)}function On(e,t){return jn(e.prev,e,t.prev)<0&&jn(t.next,e,e.next)<0}function Fn(e,t,n,r,i){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-n)*i|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-r)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function Dn(e){let t=e,n=e;do{(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next}while(t!==e);return n}function Un(e,t,n,r,i,a,s,o){return(i-s)*(t-o)>=(e-s)*(a-o)&&(e-s)*(r-o)>=(n-s)*(t-o)&&(n-s)*(a-o)>=(i-s)*(r-o)}function Vn(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){let n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==t.i&&n.next.i!==t.i&&Gn(n,n.next,e,t))return!0;n=n.next}while(n!==e);return!1}(e,t)&&(Qn(e,t)&&Qn(t,e)&&function(e,t){let n=e,r=!1;const i=(e.x+t.x)/2,a=(e.y+t.y)/2;do{n.y>a!=n.next.y>a&&n.next.y!==n.y&&i<(n.next.x-n.x)*(a-n.y)/(n.next.y-n.y)+n.x&&(r=!r),n=n.next}while(n!==e);return r}(e,t)&&(jn(e.prev,e,t.prev)||jn(e,t.prev,t))||zn(e,t)&&jn(e.prev,e,e.next)>0&&jn(t.prev,t,t.next)>0)}function jn(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function zn(e,t){return e.x===t.x&&e.y===t.y}function Gn(e,t,n,r){const i=qn(jn(e,t,n)),a=qn(jn(e,t,r)),s=qn(jn(n,r,e)),o=qn(jn(n,r,t));return i!==a&&s!==o||(!(0!==i||!Hn(e,n,t))||(!(0!==a||!Hn(e,r,t))||(!(0!==s||!Hn(n,e,r))||!(0!==o||!Hn(n,t,r)))))}function Hn(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function qn(e){return e>0?1:e<0?-1:0}function Qn(e,t){return jn(e.prev,e,e.next)<0?jn(e,t,e.next)>=0&&jn(e,e.prev,t)>=0:jn(e,t,e.prev)<0||jn(e,e.next,t)<0}function Kn(e,t){const n=new $n(e.i,e.x,e.y),r=new $n(t.i,t.x,t.y),i=e.next,a=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function Wn(e,t,n,r){const i=new $n(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function Jn(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}Sn.defaultProps={},Sn.extensionName="LayerExtension";var $n=class{constructor(e,t,n){this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1,this.i=e,this.x=t,this.y=n}},Xn={...x.defaultProps},Yn=class extends f{indexToBounds(){return null}renderLayers(){const{elevationScale:e,extruded:t,wireframe:n,filled:r,stroked:i,lineWidthUnits:a,lineWidthScale:s,lineWidthMinPixels:o,lineWidthMaxPixels:A,lineAntialiasing:l,lineJointRounded:c,lineMiterLimit:u,lineDashJustified:f,getElevation:d,getFillColor:h,getLineColor:p,getLineWidth:m}=this.props,{updateTriggers:g,material:b,transitions:v}=this.props,y=this.getSubLayerClass("cell",x),{updateTriggers:_,...w}=this.indexToBounds()||{};return new y({filled:r,wireframe:n,extruded:t,elevationScale:e,stroked:i,lineWidthUnits:a,lineWidthScale:s,lineWidthMinPixels:o,lineWidthMaxPixels:A,lineAntialiasing:l,lineJointRounded:c,lineMiterLimit:u,lineDashJustified:f,material:b,transitions:v,getElevation:d,getFillColor:h,getLineColor:p,getLineWidth:m},this.getSubLayerProps({id:"cell",updateTriggers:g&&{..._,getElevation:g.getElevation,getFillColor:g.getFillColor,getLineColor:g.getLineColor,getLineWidth:g.getLineWidth}}),w)}};function Zn(){const e=/* @__PURE__ */new Float64Array(4);return e[0]=1,e[3]=1,e}function er(){/* @__PURE__ */
3
3
  return new Float64Array(2)}function tr(e){const t=/* @__PURE__ */new Float64Array(2);return t[0]=e[0],t[1]=e[1],t}function nr(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e}function rr(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e}function ir(e,t){return e[0]=-t[0],e[1]=-t[1],e}function ar(e){return Math.hypot(e[0],e[1])}function sr(e,t,n,r){const i=t[0],a=t[1];return e[0]=i+r*(n[0]-i),e[1]=a+r*(n[1]-a),e}function or(e,t,n){const r=t[0],i=t[1];return e[0]=n[0]*r+n[2]*i,e[1]=n[1]*r+n[3]*i,e}function Ar(e,t,n){const r=t[0],i=t[1];return e[0]=n[0]*r+n[2]*i+n[4],e[1]=n[1]*r+n[3]*i+n[5],e}function lr(){/* @__PURE__ */
4
4
  return new Float64Array(3)}function cr(e,t,n){const r=/* @__PURE__ */new Float64Array(3);return r[0]=e,r[1]=t,r[2]=n,r}function ur(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e}function fr(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e}function dr(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e[2]=t[2]+n[2]*r,e}function hr(e,t){return Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2])}function pr(e,t){const n=t[0],r=t[1],i=t[2];let a=n*n+r*r+i*i;return a>0&&(a=1/Math.sqrt(a)),e[0]=t[0]*a,e[1]=t[1]*a,e[2]=t[2]*a,e}function mr(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function gr(e,t,n){const r=t[0],i=t[1],a=t[2],s=n[0],o=n[1],A=n[2];return e[0]=i*A-a*o,e[1]=a*s-r*A,e[2]=r*o-i*s,e}function br(e,t,n){const r=n[0],i=n[1],a=n[2],s=n[3],o=t[0],A=t[1],l=t[2];let c=i*l-a*A,u=a*o-r*l,f=r*A-i*o,d=i*f-a*u,h=a*c-r*f,p=r*u-i*c;const m=2*s;return c*=m,u*=m,f*=m,d*=2,h*=2,p*=2,e[0]=o+c+d,e[1]=A+u+h,e[2]=l+f+p,e}Yn.layerName="GeoCellLayer",Yn.defaultProps=Xn;var vr=(1+Math.sqrt(5))/2,yr=2*Math.PI/5,xr=Math.PI/5,_r=Math.PI/10,wr=2*Math.atan(vr),Tr=Math.PI-wr;Math.PI,Math.acos(-1/Math.sqrt(3-vr));var Sr=(Math.sqrt(5)-1)/2,Mr=3-Math.sqrt(5);Math.sqrt(3-vr);Math.sqrt(3);var Er=6371007.2;Math.PI;function Cr(e,t,n,r){const i=t[0]-e[0],a=t[1]-e[1],s=r[0]-n[0],o=r[1]-n[1],A=i*o-a*s;if(Math.abs(A)<1e-12)return!1;const l=n[0]-e[0],c=n[1]-e[1],u=(l*o-c*s)/A,f=(l*a-c*i)/A;return u>=0&&u<=1&&f>=0&&f<=1}var Ir=class e{constructor(e){this.vertices=e,this.isWindingCorrect()||this.vertices.reverse()}getArea(){let e=0;const t=this.vertices.length;for(let n=0;n<t;n++){const r=(n+1)%t;e+=(this.vertices[r][0]-this.vertices[n][0])*(this.vertices[r][1]+this.vertices[n][1])}return e}isWindingCorrect(){return this.getArea()>=0}getVertices(){return this.vertices}scale(e){for(const t of this.vertices)rr(t,t,e);return this}rotate180(){for(const e of this.vertices)ir(e,e);return this}reflectY(){for(const e of this.vertices)e[1]=-e[1];return this.vertices.reverse(),this}translate(e){for(const t of this.vertices)nr(t,t,e);return this}transform(e){for(const t of this.vertices)or(t,t,e);return this}transform2d(e){for(const t of this.vertices)Ar(t,t,e);return this}clone(){return new e(this.vertices.map(e=>tr(e)))}getCenter(){const e=this.vertices.length;return this.vertices.reduce((t,n)=>[t[0]+n[0]/e,t[1]+n[1]/e],[0,0])}containsPoint(e){if(!this.isWindingCorrect())throw new Error("Pentagon is not counter-clockwise");const t=this.vertices.length;let n=1;for(let r=0;r<t;r++){const i=this.vertices[r],a=this.vertices[(r+1)%t],s=i[0]-a[0],o=i[1]-a[1],A=e[0]-i[0],l=e[1]-i[1],c=s*l-o*A;if(c<0){const e=Math.sqrt(A*A+l*l);n=Math.min(n,c/e)}}return n}intersectsSegment(e,t){if(this.containsPoint(e)>0||this.containsPoint(t)>0)return!0;const n=this.vertices.length;for(let r=0;r<n;r++){if(Cr(e,t,this.vertices[r],this.vertices[(r+1)%n]))return!0}return!1}splitEdges(t){if(t<=1)return this;const n=[],r=this.vertices.length;for(let e=0;e<r;e++){const i=this.vertices[e],a=this.vertices[(e+1)%r];n.push(tr(i));for(let e=1;e<t;e++){const r=e/t,s=er();sr(s,i,a,r),n.push(s)}}return new e(n)}},Rr=[0,0],Pr=[0,1],Nr=[.7885966681787006,1.6149108024237764],kr=[1.6171013659387945,1.054928690397459],Lr=[Math.cos(_r),Math.sin(_r)],Br=2*ar(Nr)*Math.cos(xr),Or=xr-Math.atan2(Nr[1],Nr[0]),Fr=2*Sr/Br;[Rr,Pr,Nr,kr,Lr].forEach(e=>{rr(e,e,Fr),function(e,t,n,r){const i=t[0]-n[0],a=t[1]-n[1],s=Math.sin(r),o=Math.cos(r);e[0]=i*o-a*s+n[0],e[1]=i*s+a*o+n[1]}(e,e,[0,0],Or)});var Dr=new Ir([Rr,Pr,Nr,kr,Lr]),Ur=Math.atan2(Nr[1],Nr[0])-xr,Vr=Sr/Math.cos(xr),jr=Ur+xr,zr=[Vr*Math.cos(jr),Vr*Math.sin(jr)],Gr=Ur-xr,Hr=[Vr*Math.cos(Gr),Vr*Math.sin(Gr)],qr=new Ir([[0,0],zr,Hr]),Qr=[zr[0],zr[1],Hr[0],Hr[1]],Kr=new Float64Array([-.0022392098386786394,21308606513250217e-22,-2.559257686421274e-9,33701965267802837e-28,-4667545312611249e-30,667492870384816e-32]),Wr=new Float64Array([.0022392089963541657,28831978048607556e-22,5.08622073997266e-9,102018123778161e-25,21912872306767718e-30,49284235482523806e-33]),Jr=new class{applyCoefficients(e,t){const n=Math.sin(e),r=Math.cos(e),i=2*(r-n)*(r+n);let a,s;return a=i*t[5]+t[4],s=i*a+t[3],a=i*s-a+t[2],s=i*a-s+t[1],a=i*s-a+t[0],e+2*n*r*a}forward(e){return this.applyCoefficients(e,Kr)}inverse(e){return this.applyCoefficients(e,Wr)}};function $r(e){return e*(Math.PI/180)}function Xr(e){return e*(180/Math.PI)}function Yr(e){return[ar(e),Math.atan2(e[1],e[0])]}function Zr(e){const t=Math.atan2(e[1],e[0]),n=Math.sqrt(e[0]*e[0]+e[1]*e[1]);return[t,Math.atan2(n,e[2])]}function ei([e,t]){const n=Math.sin(t);return[n*Math.cos(e),n*Math.sin(e),Math.cos(t)]}function ti([e,t]){const n=$r(e+93),r=$r(t),i=Jr.forward(r);return[n,Math.PI/2-i]}function ni(e){return((e+180)%360+360)%360-180}function ri([e,t]){const n=ni(Xr(e)-93),r=Math.PI/2-t;return[n,Xr(Jr.inverse(r))]}lr(),cr(1,0,0),cr(0,1,0);var ii=Math.sqrt(5),ai=Math.sqrt(.2),si=Math.sqrt((1-ai)/2),oi=Math.sqrt((1+ai)/2),Ai=.5,li=Math.sqrt((2.5-ii)/10),ci=Math.sqrt((2.5+ii)/10),ui=Math.sqrt((1+ai)/8),fi=Math.sqrt((1-ai)/8),di=Math.sqrt((3-ii)/8),hi=Math.sqrt((3+ii)/8),pi=[[0,0],[si,0],[li,Ai],[-ui,di],[-ui,-di],[li,-Ai],[-oi,0],[-fi,-hi],[ci,-Ai],[ci,Ai],[-fi,hi],[0,0]].map(([e,t])=>[-t,e]).map((e,t)=>0===t?[0,0,0,1]:11===t?[0,-1,0,0]:[...e,0,t<6?oi:si]),mi=["vu","uw","vw","vw","vw"],gi=["wu","uw","vw","vu","uw"],bi=["wu","uv","wv","wu","uw"],vi=["vu","uv","wv","wu","uw"],yi=[mi,vi,bi,gi,bi,vi,bi,gi,gi,gi,vi,vi],xi=[4,2,3,2,0,4,3,2,2,0,3,0],_i=[0,1,2,4,3,5,7,8,6,11,10,9],wi=[];var Ti=0;function Si(e,t,n){if(Ti>11)throw new Error(`Too many origins: ${Ti}`);const r=function(){const e=/* @__PURE__ */new Float64Array(4);return e[3]=1,e}();var i,a;a=n,(i=r)[0]=-a[0],i[1]=-a[1],i[2]=-a[2],i[3]=a[3];const s={id:Ti,axis:e,axisCartesian:ei(e),quat:n,inverseQuat:r,angle:t,orientation:yi[Ti],firstQuintant:xi[Ti]};wi.push(s),Ti++}!function(){Si([0,0],0,pi[0]);for(let e=0;e<5;e++){const t=e*yr,n=t+xr;Si([t,Tr],xr,pi[e+1]),Si([n,Math.PI-Tr],xr,pi[(e+3)%5+6])}Si([0,Math.PI],0,pi[11])}(),wi.sort((e,t)=>_i.indexOf(e.id)-_i.indexOf(t.id)),wi.forEach((e,t)=>e.id=t);var Mi=class{forward([e,t]){return[Math.tan(t),e]}inverse([e,t]){return[t,Math.atan(e)]}};lr();function Ei(e,t,n){const r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+1+(t[0]*n[0]+t[1]*n[1]+t[2]*n[2])+(n[0]*e[0]+n[1]*e[1]+n[2]*e[2]);return 2*Math.atan2((a=t,s=n,(i=e)[0]*(a[1]*s[2]-a[2]*s[1])+i[1]*(a[2]*s[0]-a[0]*s[2])+i[2]*(a[0]*s[1]-a[1]*s[0])),r);var i,a,s}var Ci=lr(),Ii=lr(),Ri=er(),Pi=er(),Ni=class e{constructor(t){this.constants=e.computeConstants(t)}static computeConstants(e){const[t,n,r]=e,i=lr();gr(i,n,r);const a=mr(t,n),s=mr(t,r),o=mr(n,r),A=mr(t,i),l=s+o,c=a+1,u=l*l-c*c,f=2*c*(a*o-s),d=function(e,t,n,r,i,a){const s=/* @__PURE__ */new Float64Array(6);return s[0]=e,s[1]=t,s[2]=n,s[3]=r,s[4]=i,s[5]=a,s}(A*A-u,-f,-2*A*l,2*A*c,A*A+u,f);return{volumeABC:A,areaABC:Ei(t,n,r),AdotB:a,AdotC:s,alphaTransform:d}}forward(e,t,n){const[r,i,a]=t,{areaABC:s,volumeABC:o}=this.constants;gr(Ci,i,a);const A=mr(e,Ci);fr(Ii,e,o),dr(Ii,Ii,r,-A);const l=(c=Ii,Math.hypot(c[0],c[1],c[2]));var c;fr(Ii,Ii,l>0?1/l:1);const u=Math.max(0,Ei(r,i,Ii))/s,f=l/o*Math.sqrt((1+mr(r,Ii))/(1+mr(r,e)));return function(e,[t,n,r]){return[e[0]*t[0]+e[1]*n[0]+e[2]*r[0],e[0]*t[1]+e[1]*n[1]+e[2]*r[1]]}([1-f,f*(1-u),f*u],n)}inverse(e,t,n){const[r,i,a]=n,s=function(e,[t,n,r]){const i=[t[0]-r[0],t[1]-r[1]],a=[r[0]-n[0],r[1]-n[1]],s=[e[0]-r[0],e[1]-r[1]],o=a[0]*i[1]-a[1]*i[0],A=(a[0]*s[1]-a[1]*s[0])/o,l=(i[0]*s[1]-i[1]*s[0])/o;return[A,l,1-(A+l)]}(e,t),o=1-1e-14;if(s[0]>o)return r;if(s[1]>o)return i;if(s[2]>o)return a;const{AdotB:A,AdotC:l,alphaTransform:c,areaABC:u}=this.constants,f=mr(r,i),d=Math.abs(f-A)>Math.abs(f-l),h=d?a:i,p=d?i:a,m=d?s[1]:s[2],g=1-s[0],b=m/g*u;Ri[0]=Math.cos(b),Ri[1]=Math.sin(b),Ar(Pi,Ri,c),fr(Ii,h,Pi[0]),dr(Ii,Ii,p,Pi[1]),pr(Ii,Ii);const v=mr(r,Ii),y=1+g*g*(v-1),x=g*Math.sqrt((1+y)/(1+v)),_=y-v*x,w=lr();return fr(w,r,_),dr(w,w,Ii,x),w}},ki=[0,1,2,3,4].map(e=>{const t=Zn();return function(e,t){const n=Math.sin(t),r=Math.cos(t);e[0]=r,e[1]=n,e[2]=-n,e[3]=r}(t,yr*e),t}),Li=er(),Bi=er();[0,1,2,3].map(e=>{const t=Dr.clone();return 1&e&&t.rotate180(),2&e&&t.reflectY(),t.getCenter()});function Oi(e){const t=qr.clone();return t.transform(ki[e]),t}var Fi=new class{constructor(){if(this.vertices=[],this.addFaceCenters(),this.addVertices(),this.addMidpoints(),62!==this.vertices.length)throw new Error("Failed to construct CRS: vertices length is not 62");Object.freeze(this.vertices)}getCanonicalTriangle(){return[this.vertices[0],this.vertices[32],this.vertices[12]]}getVertex(e){for(const t of this.vertices)if(hr(e,t)<1e-5)return t;throw new Error("Failed to find vertex in CRS")}addFaceCenters(){wi.forEach(e=>this.add(ei(e.axis)))}addVertices(){const e=Math.atan(Mr);for(const t of wi)for(let n=0;n<5;n++){const r=ei([(2*n+1)*Math.PI/5+t.angle,e]);br(r,r,t.quat),this.add(r)}}addMidpoints(){const e=Math.atan(Sr);for(const t of wi)for(let n=0;n<5;n++){const r=ei([2*n*Math.PI/5+t.angle,e]);br(r,r,t.quat),this.add(r)}}add(e){const t=pr(lr(),e);return!this.vertices.find(e=>hr(t,e)<1e-5)&&(this.vertices.push(t),!0)}},Di={A:"PQAB",B:"B+++PQ---A",C:"P---RMb+++",M:"qQ+++C---b",P:"PpB---B+++",Q:"PQ---Cb+++",R:"b+++a---qQ"},Ui=Object.keys(Di);Ui.map(e=>e.toLowerCase());var Vi=e=>[...e].reverse().map(e=>"+"===e?"-":"-"===e?"+":(e=>e>="a"&&e<="z"?e.toUpperCase():e.toLowerCase())(e)).join("");function ji(e,t){let n="";for(const r of e){const e=r.toUpperCase();void 0!==t[r]?n+=t[r]:r!==e&&void 0!==t[e]?n+=Vi(t[e]):n+=r}return n}var zi=(e,t)=>({a:e.a+t.a,b:e.b+t.b}),Gi=e=>({a:-e.b,b:e.a+e.b}),Hi=(e,t)=>{let n=e;const r=(t%6+6)%6;for(let i=0;i<r;i++)n=Gi(n);return n},qi={E:{a:4,b:0},e:{a:4,b:0},S:{a:4,b:-2},s:{a:4,b:-2},U:{a:0,b:2},u:{a:0,b:2},D:{a:0,b:-2},d:{a:0,b:-2},T:{a:-4,b:0},t:{a:-4,b:0}},Qi=new Set(Object.keys(qi)),Ki={E:[{a:0,b:0},{a:4,b:0},{a:4,b:-4}],e:[{a:0,b:0},{a:4,b:0},{a:0,b:4}],S:[{a:0,b:0},{a:4,b:0},{a:4,b:-4}],s:[{a:4,b:-2},{a:0,b:2},{a:0,b:-2}],U:[{a:0,b:2},{a:0,b:-2},{a:4,b:-2}],u:[{a:0,b:0},{a:0,b:4},{a:-4,b:4}],D:[{a:0,b:2},{a:0,b:-2},{a:4,b:-2}],d:[{a:0,b:0},{a:0,b:-4},{a:-4,b:0}],T:[{a:0,b:-4},{a:-4,b:0},{a:-4,b:-4}],t:[{a:-4,b:4},{a:0,b:0},{a:0,b:4}]};function Wi(e,t,n){return Ki[e].map(e=>zi(t,Hi(e,n)))}function Ji(e,t,n){const[r,i,a]=Wi(e,t,n);return{a:r.a+i.a+a.a,b:r.b+i.b+a.b}}function $i(e,t,n,r){let i={...t},a=(n%6+6)%6;for(const s of e)"+"!==s?"-"!==s?Qi.has(s)&&(r?.(s,i,a),i=zi(i,Hi(qi[s],a))):a=(a+5)%6:a=(a+1)%6;return{pos:i,heading:a}}var Xi=1e-6;function Yi(e,t,n){const r=n?-1:1,i=[];for(let a=0;a<4;a++){const s=4*t+a,o=e.childToken[s],A=e.childFlip[s],l=e.childOffA[s],c=e.childOffB[s],u=e.fpEdges[2*o+(n^A)],f=[];for(let e=0;e<u.length;e+=4)f.push([3*l*r+u[e],3*c*r+u[e+1]]);i.push([a,f])}return i}function Zi(e){if(1===e.length)return{leaf:e[0][0]};for(const[,t]of e){const n=t.length;for(let r=0;r<n;r++){const[i,a]=t[r],[s,o]=t[(r+1)%n],A=o-a,l=-(s-i),c=-(A*i+l*a),u=[],f=[];let d=!0;for(const[t,n]of e){let e=1/0,r=-1/0;for(const[t,i]of n){const n=A*t+l*i+c;n<e&&(e=n),n>r&&(r=n)}if(e>=-Xi)u.push([t,n]);else{if(!(r<=Xi)){d=!1;break}f.push([t,n])}}if(d&&u.length&&f.length)return{nx:A,ny:l,c:c,pos:Zi(u),neg:Zi(f)}}}throw new Error("lsystem: no clean BSP split for child set")}function ea(e,t){if("leaf"in e)return;const n=[e.nx,e.ny,e.c];t.some(e=>e[0]===n[0]&&e[1]===n[1]&&e[2]===n[2])||t.push(n),ea(e.pos,t),ea(e.neg,t)}function ta(e,t,n){return"leaf"in e?e.leaf:ta(t>>n.findIndex(t=>t[0]===e.nx&&t[1]===e.ny&&t[2]===e.c)&1?e.pos:e.neg,t,n)}var na={S:0,D:1,E:2,T:3};function ra(e,t){const n=Object.keys(e),r=[...n,...n.map(e=>e.toLowerCase())],i=r.length,a={};function s(n,r){let i=n;for(let t=0;t<r;t++)i=ji(i,e);return ji(i,t)}r.forEach((e,t)=>a[e]=t);const o=e=>function(e){const t=$i(e,{a:0,b:0},0);return{disp:t.pos,dHeading:t.heading}}(s(e,1)).disp;function A(t){let n={a:0,b:0},r=0;const i=[];for(const a of t){if("+"===a){r=(r+1)%6;continue}if("-"===a){r=(r+5)%6;continue}if(void 0===e[a.toUpperCase()])continue;if(0!==r&&3!==r)throw new Error(`lsystem: non-180° turn (${60*r}°) before a child in rule "${t}"`);const s=3===r;i.push({token:a,offUnit:{...n},flip:s});const A=o(a);n=s?{a:n.a-A.a,b:n.b-A.b}:{a:n.a+A.a,b:n.b+A.b}}if(4!==i.length)throw new Error(`lsystem: rule "${t}" must have 4 children`);return i}const l={};for(const y of n)l[y]=A(e[y]);for(const y of n)l[y.toLowerCase()]=A(Vi(e[y]));const c=new Int32Array(4*i),u=new Uint8Array(4*i),f=new Float64Array(4*i),d=new Float64Array(4*i);for(const y of r){const e=l[y];for(let t=0;t<4;t++){const n=4*a[y]+t;c[n]=a[e[t].token],u[n]=e[t].flip?1:0,f[n]=e[t].offUnit.a,d[n]=e[t].offUnit.b}}function h(e){const t=[...new Map(e.map(e=>[`${e.a},${e.b}`,e])).values()].sort((e,t)=>e.a-t.a||e.b-t.b);if(t.length<3)return t;const n=(e,t,n)=>(t.a-e.a)*(n.b-e.b)-(t.b-e.b)*(n.a-e.a),r=[];for(const a of t){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],a)<=0;)r.pop();r.push(a)}const i=[];for(let a=t.length-1;a>=0;a--){const e=t[a];for(;i.length>=2&&n(i[i.length-2],i[i.length-1],e)<=0;)i.pop();i.push(e)}return r.slice(0,-1).concat(i.slice(0,-1))}const p=new Array(2*i);for(const y of r){const e=[];$i(s(y,1),{a:0,b:0},0,(t,n,r)=>e.push(...Wi(t,n,r)));const t=h(e);for(let n=0;n<2;n++){const e=n?-1:1,r=new Float64Array(4*t.length);for(let n=0;n<t.length;n++){const i=t[n],a=t[(n+1)%t.length];r[4*n]=3*e*i.a,r[4*n+1]=3*e*i.b,r[4*n+2]=e*(a.a-i.a),r[4*n+3]=e*(a.b-i.b)}p[2*a[y]+n]=r}}const m=new Float64Array(2*i*8),g=new Float64Array(2*i*48),b=new Uint8Array(2*i*4);for(const y of r){const e=s(y,1);for(let t=0;t<2;t++){const n=2*a[y]+t;let r=0;$i(e,{a:0,b:0},t?3:0,(e,t,i)=>{const a=Ji(e,t,i);m[8*n+2*r]=a.a,m[8*n+2*r+1]=a.b;const s=e.toUpperCase();if(void 0===na[s])throw new Error(`lsystem: no pentagon flavor for draw symbol ${e}`);b[4*n+r]=na[s]^(e===s?0:1)^1&i;let o=Wi(e,t,i);(o[1].a-o[0].a)*(o[2].b-o[0].b)-(o[1].b-o[0].b)*(o[2].a-o[0].a)<0&&(o=[o[0],o[2],o[1]]);for(let A=0;A<3;A++){const e=o[A],t=o[(A+1)%3],i=48*n+12*r+4*A;g[i]=3*e.a,g[i+1]=3*e.b,g[i+2]=t.a-e.a,g[i+3]=t.b-e.b}r++})}}const v={motifIdx:a,childToken:c,childFlip:u,childOffA:f,childOffB:d,fpEdges:p,leafSum:m,leafTri:g,leafFlavor:b,classSep:new Float64Array(2*i*9),classLut:new Uint8Array(2*i*8)};for(let y=0;y<i;y++)for(let e=0;e<2;e++){const t=2*y+e,n=Zi(Yi(v,y,e)),r=[];ea(n,r);for(let e=0;e<r.length;e++)v.classSep[9*t+3*e]=r[e][0],v.classSep[9*t+3*e+1]=r[e][1],v.classSep[9*t+3*e+2]=r[e][2];for(let e=0;e<8;e++)v.classLut[8*t+e]=ta(n,e,r)}return v}var ia=/* @__PURE__ */new Float64Array(32);for(let Hy=0;Hy<32;Hy++)ia[Hy]=2**Hy;var aa=/* @__PURE__ */new Float64Array(20);for(let Hy=0;Hy<20;Hy++)aa[Hy]=4**Hy;var sa=ra(Di,{A:"E",B:"+e-",C:"-e+",M:"T",P:"S",Q:"D",R:"+++D---"});sa.motifIdx.A,sa.motifIdx.A,sa.motifIdx.C,sa.motifIdx.C,sa.motifIdx.B,sa.motifIdx.B;var oa=ra({W:"W+++Z---WZ",Z:"Z+++W---ZW"},{W:"E",Z:"+e-"}),Aa=oa.motifIdx.W;function la(e){return Array.from({length:e.length},(t,n)=>e.indexOf(n))}var ca=[0,1,3,4,5,6,7,2],ua=[0,1,2,7,3,4,5,6];la(ca),la(ua);function fa(e,t,n,r,i){if(t<=0)return;const a=e[t]||0,s=e[t-1];let o=!0,A=!0;if(r!==(0===n[0]+n[1])?(o=1===a||2===a,A=1===a):(o=a<2,A=0===a),!o)return;const l=A?s:s+4,c=i[l];e[t-1]=c%4,e[t]=(a+4+Math.floor(c/4)-Math.floor(l/4))%4}function da(e,t){1===t?e[1]=-e[1]:3===t&&(e[0]=-e[0])}var ha={uv:{reverse:!1,invertJ:!1,flipIJ:!1},vu:{reverse:!0,invertJ:!1,flipIJ:!1},uw:{reverse:!1,invertJ:!1,flipIJ:!0},wu:{reverse:!0,invertJ:!1,flipIJ:!0},vw:{reverse:!0,invertJ:!0,flipIJ:!1},wv:{reverse:!1,invertJ:!0,flipIJ:!1}};function pa(e,t){return(-1===e[1]?1:0)|((e[0]+e[1]===0?0===t||3===t:2===t||3===t)?1:0)<<1}function ma(e,t,n){const r=1n<<BigInt(2*t),i=function(e,t){const n=[];let r=e;for(;r>0n||n.length<t;)n.push(Number(3n&r)),r>>=2n;return n}(n.reverse?r-1n-e:e,t),a=function(e,t,n){const r=n?ua:ca,i=[1,1];for(let a=e.length-1;a>=0;a--)fa(e,a,i,t,r),da(i,e[a]);return i}(i,n.invertJ,n.flipIJ),s=function(e,t,n,r){const{childToken:i,childFlip:a,childOffA:s,childOffB:o,leafSum:A,leafFlavor:l}=e,c=Number(67108863n&t),u=Number(t>>26n);let f=r,d=0,h=0,p=0;for(let b=n;b>=2;b--){const e=b-1,t=4*f+(e<13?c>>>(e<<1)&3:Math.floor(u/aa[e-13])%4),n=d?-ia[b-2]:ia[b-2];h+=s[t]*n,p+=o[t]*n,d^=a[t],f=i[t]}const m=n>=1?3&c:0,g=2*f+d;return{a:3*h+A[8*g+2*m],b:3*p+A[8*g+2*m+1],flavor:l[4*g+m]}}(oa,function(e){let t=0n;for(let n=e.length-1;n>=0;n--)t=t<<2n|BigInt(e[n]);return t}(i),t,Aa);let o=function(e,t){if((2*e+t)%12!=0||t%4!=0)throw new Error(`abToTriple: off-lattice corner sum (${e},${t})`);const n=(2*e+t-12)/12,r=(t+4)/4;for(const i of[0,1]){if((r+i)%3!=0)continue;const e=(r+i)/3,t=i-e;if((t+n)%2==0)return{x:e,y:(t+n)/2,z:(t-n)/2}}throw new Error(`abToTriple: no integer triple for (${e},${t})`)}(s.a,s.b);if(n.flipIJ&&(o={x:o.z,y:o.y,z:o.x}),n.invertJ){const e=ia[t]-1;o={x:o.y-e,y:o.x+e,z:o.z}}return{triple:o,flips:a,q:i.length>0?i[0]:0}}function ga(e){const t=function(e){if(0n===e)return-1;if(1n&e||4n==(7n&e)||16n==(31n&e))return 30;let t=29,n=e>>1n;if(0n===n)return-1;let r,i=Number(4294967295n&n);for(0===i?(n>>=32n,t-=16,r=Number(n)):r=i,65535&r||(r>>=16,t-=8),t>=6&&!(255&r)&&(r>>=8,t-=4),t>=4&&!(15&r)&&(r>>=4,t-=2);t>-1&&!(1&r);)t-=1,r>>=t<2?1:2;return t}(e);if(-1===t)return{origin:wi[0],segment:0,S:0n,resolution:t};let n=58n,r=0;if(30===t){const t=1n&e?1n:4n&e?3n:5n;n=58n+t,r=1n===t?0:3n===t?32:40}const i=Number(e>>n)+r;let a,s;if(0===t?(a=wi[i],s=0):(a=wi[Math.floor(i/5)],s=(i+a.firstQuintant)%5),!a)throw new Error(`Could not parse origin: ${i}`);if(t<2)return{origin:a,segment:s,S:0n,resolution:t};return{origin:a,segment:s,S:(e&(1n<<n)-1n)>>n-BigInt(2*(t-2+1)),resolution:t}}var ba=(e,t,n)=>({x:e,y:t,z:n}),va=(ba(0,0,1),ba(0,1,-1),ba(0,1,0),ba(1,-1,0),ba(1,0,0),ba(1,-1,1),ba(1,1,-1),ba(0,0,1),ba(0,1,-1),ba(0,1,0),ba(1,-1,0),ba(1,0,0),ba(1,-1,1),ba(1,1,-1),ba(0,0,-1),ba(0,-1,1),ba(0,-1,0),ba(-1,1,0),ba(-1,0,0),ba(-1,1,-1),ba(-1,-1,1),ba(0,0,-1),ba(0,-1,1),ba(0,-1,0),ba(-1,1,0),ba(-1,0,0),ba(-1,1,-1),ba(-1,-1,1),ba(-1,1,0),ba(0,-1,1),ba(0,0,1),ba(0,1,0),ba(1,0,0),ba(-1,1,1),ba(1,-1,1),ba(-1,1,0),ba(0,-1,1),ba(0,0,1),ba(0,1,0),ba(1,0,0),ba(-1,1,1),ba(1,-1,1),ba(1,-1,0),ba(0,1,-1),ba(0,0,-1),ba(0,-1,0),ba(-1,0,0),ba(1,-1,-1),ba(-1,1,-1),ba(1,-1,0),ba(0,1,-1),ba(0,0,-1),ba(0,-1,0),ba(-1,0,0),ba(1,-1,-1),ba(-1,1,-1),cr(0,0,1),(()=>{const e=[];for(let t=0;t<24;t++){const n=1.4*(t+1);e.push(cr(Math.cos(n),Math.sin(n),0))}})(),Zn(),new class{constructor(){this.faceTriangles=[],this.sphericalTriangles=[],this.equalArea=new Ni(Fi.getCanonicalTriangle()),this.gnomonic=new Mi}forward(e,t){return this.forwardCartesian(ei(e),t)}forwardCartesian(e,t){const n=wi[t],r=lr();br(r,e,n.inverseQuat);const i=Zr(r),a=this.gnomonic.forward(i);a[1]=a[1]-n.angle;const s=this.getFaceTriangleIndex(a),o=this.shouldReflect(a);let A=this.getFaceTriangle(s,o,!1),l=this.getSphericalTriangle(s,t,o);return this.equalArea.forward(e,l,A)}inverse(e,t){const n=Yr(e),r=this.getFaceTriangleIndex(n),i=this.shouldReflect(n),a=this.getFaceTriangle(r,i,!1),s=this.getSphericalTriangle(r,t,i);return Zr(this.equalArea.inverse(e,a,s))}shouldReflect(e){const[t,n]=e;return function([e,t]){return[e*Math.cos(t),e*Math.sin(t)]}([t,this.normalizeGamma(n)])[0]>Sr}getFaceTriangleIndex([e,t]){return(Math.floor(t/xr)+10)%10}getFaceTriangle(e,t=!1,n=!1){let r=e;return t&&(r+=n?20:10),this.faceTriangles[r]||(this.faceTriangles[r]=t?this._getReflectedFaceTriangle(e,n):this._getFaceTriangle(e),Object.freeze(this.faceTriangles[r])),this.faceTriangles[r]}_getFaceTriangle(e){const[t,n,r]=Oi(Math.floor((e+1)/2)%5).getVertices(),i=er();return sr(i,n,r,.5),e%2==0?[t,i,n]:[t,r,i]}_getReflectedFaceTriangle(e,t=!1){let[n,r,i]=this._getFaceTriangle(e).map(e=>tr(e));const a=e%2==0;var s,o,A,l;return ir(n,n),s=n,o=n,A=a?r:i,l=t?1+1/Math.cos(Tr):2,s[0]=o[0]+A[0]*l,s[1]=o[1]+A[1]*l,[n,i,r]}getSphericalTriangle(e,t,n=!1){let r=10*t+e;return n&&(r+=120),this.sphericalTriangles[r]||(this.sphericalTriangles[r]=this._getSphericalTriangle(e,t,n),Object.freeze(this.sphericalTriangles[r])),this.sphericalTriangles[r]}_getSphericalTriangle(e,t,n=!1){const r=wi[t];return this.getFaceTriangle(e,n,!0).map(e=>{const[t,n]=Yr(e),i=[t,n+r.angle],a=ei(this.gnomonic.inverse(i));return br(a,a,r.quat),Fi.getVertex(a)})}normalizeGamma(e){const t=e/yr;return(t-Math.round(t))*yr}});lr();function ya({S:e,segment:t,origin:n,resolution:r}){const{quintant:i,orientation:a}=function(e,t){const n=t.orientation,r=n===mi||n===gi?-1:1,i=(e-t.firstQuintant+5)%5,a=n[i];return{quintant:(t.firstQuintant+r*i+5)%5,orientation:a}}(t,n);if(1===r)return Oi(i);if(0===r)return function(){const e=[];for(const t of ki)e.push(or(er(),zr,t));return e.reverse(),new Ir(e)}();const s=r-2+1,{triple:o,flavor:A}=function(e,t,n="uv"){const r=ha[n],{triple:i,flips:a,q:s}=ma(e,t,r);return r.invertJ&&(a[0]=-a[0]),{triple:i,flavor:pa(a,s)}}(e,s,a);return function(e,t,n,r,i=!1){const a=(i?qr:Dr).clone();var s,o,A;return 1&r&&a.rotate180(),2&r&&a.reflectY(),s=Bi,o=n.x+n.y,A=-n.x+(1&r),s[0]=o,s[1]=A,or(Li,Bi,Qr),a.translate(Li),a.scale(1/2**e),a.transform(ki[t]),a}(s,i,o,A)}function xa(e,{closedRing:t=!0,segments:n="auto"}={closedRing:!0,segments:"auto"}){if(0n===e)return[];const{S:r,segment:i,origin:a,resolution:s}=ga(e);"auto"===n&&(n=Math.max(1,Math.pow(2,6-s)));const o=ya({S:r,segment:i,origin:a,resolution:s}).splitEdges(n).getVertices(),A=new Array(o.length);for(let c=0;c<o.length;c++)A[c]=ri(va.inverse(o[c],a.id));const l=function(e){const t=lr();for(let a=0;a<e.length;a++)ur(t,t,ei(ti(e[a])));pr(t,t);let[n,r]=ri(Zr(t));(r>89.99||r<-89.99)&&(n=e[0][0]),n=ni(n);const i=new Array(e.length);for(let a=0;a<e.length;a++){let t=e[a][0];const r=e[a][1];for(;t-n>180;)t-=360;for(;t-n<-180;)t+=360;i[a]=[t,r]}return i}(A);return t&&l.push(l[0]),l.reverse(),l}var _a=12742014.4/Math.sqrt(15),wa=new Array(31);wa[0]=12742014.4/Math.sqrt(3);for(let Hy=1;Hy<=30;Hy++)wa[Hy]=_a/(1<<Hy-1);(()=>{const e=[];for(let t=-1;t<=1;t++)for(let n=-1;n<=1;n++)for(let r=-1;r<=1;r++)0===t&&0===n&&0===r||e.push([t,n,r])})(),cr(0,0,1),cr(1,0,0),lr();var Ta=function(e){var t,n=void 0!==(e=e||{})?e:{},r={};for(t in n)n.hasOwnProperty(t)&&(r[t]=n[t]);var i,a=[],s="";"undefined"!=typeof document&&document.currentScript&&(s=document.currentScript.src),s=0!==s.indexOf("blob:")?s.substr(0,s.lastIndexOf("/")+1):"",i=function(e,t,n){var r=new XMLHttpRequest;r.open("GET",e,!0),r.responseType="arraybuffer",r.onload=function(){if(200==r.status||0==r.status&&r.response)t(r.response);else{var i=$(e);i?t(i.buffer):n()}},r.onerror=n,r.send(null)};var o=n.print||console.log.bind(console),A=n.printErr||console.warn.bind(console);for(t in r)r.hasOwnProperty(t)&&(n[t]=r[t]);r=null,n.arguments&&(a=n.arguments);var l=0;var c=!1;function u(e){var t,r=n["_"+e];return t="Cannot call unknown function "+e+", make sure it is exported",r||le("Assertion failed: "+t),r}function f(e,t,n,r,i){var a={string:function(e){var t=0;if(null!=e&&0!==e){var n=1+(e.length<<2);(function(e,t,n){(function(e,t,n,r){if(!(r>0))return 0;for(var i=n,a=n+r-1,s=0;s<e.length;++s){var o=e.charCodeAt(s);if(o>=55296&&o<=57343)o=65536+((1023&o)<<10)|1023&e.charCodeAt(++s);if(o<=127){if(n>=a)break;t[n++]=o}else if(o<=2047){if(n+1>=a)break;t[n++]=192|o>>6,t[n++]=128|63&o}else if(o<=65535){if(n+2>=a)break;t[n++]=224|o>>12,t[n++]=128|o>>6&63,t[n++]=128|63&o}else{if(n+3>=a)break;t[n++]=240|o>>18,t[n++]=128|o>>12&63,t[n++]=128|o>>6&63,t[n++]=128|63&o}}t[n]=0})(e,p,t,n)})(e,t=te(n),n)}return t},array:function(e){var t=te(e.length);return function(e,t){h.set(e,t)}(e,t),t}};var s=u(e),o=[],A=0;if(r)for(var l=0;l<r.length;l++){var c=a[n[l]];c?(0===A&&(A=re()),o[l]=c(r[l])):o[l]=r[l]}var f=s.apply(null,o);return f=function(e){return"string"===t?x(e):"boolean"===t?Boolean(e):e}(f),0!==A&&ne(A),f}var d,h,p,m,g,b,v,y="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function x(e,t){return e?function(e,t,n){for(var r=t+n,i=t;e[i]&&!(i>=r);)++i;if(i-t>16&&e.subarray&&y)return y.decode(e.subarray(t,i));for(var a="";t<i;){var s=e[t++];if(128&s){var o=63&e[t++];if(192!=(224&s)){var A=63&e[t++];if((s=224==(240&s)?(15&s)<<12|o<<6|A:(7&s)<<18|o<<12|A<<6|63&e[t++])<65536)a+=String.fromCharCode(s);else{var l=s-65536;a+=String.fromCharCode(55296|l>>10,56320|1023&l)}}else a+=String.fromCharCode((31&s)<<6|o)}else a+=String.fromCharCode(s)}return a}(p,e,t):""}function _(e,t){return e%t>0&&(e+=t-e%t),e}function w(e){d=e,n.HEAP8=h=new Int8Array(e),n.HEAP16=m=new Int16Array(e),n.HEAP32=g=new Int32Array(e),n.HEAPU8=p=new Uint8Array(e),n.HEAPU16=new Uint16Array(e),n.HEAPU32=new Uint32Array(e),n.HEAPF32=b=new Float32Array(e),n.HEAPF64=v=new Float64Array(e)}"undefined"!=typeof TextDecoder&&new TextDecoder("utf-16le");var T=n.TOTAL_MEMORY||33554432;function S(e){for(;e.length>0;){var t=e.shift();if("function"!=typeof t){var r=t.func;"number"==typeof r?void 0===t.arg?n.dynCall_v(r):n.dynCall_vi(r,t.arg):r(void 0===t.arg?null:t.arg)}else t()}}T=(d=n.buffer?n.buffer:new ArrayBuffer(T)).byteLength,w(d),g[7096]=5271296;var M=[],E=[],C=[],I=[];function R(e){M.unshift(e)}function P(e){I.unshift(e)}var N=Math.abs,k=Math.ceil,L=Math.floor,B=Math.min,O=0,F=null,D=null;n.preloadedImages={},n.preloadedAudios={};var U,V,j=null,z="data:application/octet-stream;base64,";function G(e){return String.prototype.startsWith?e.startsWith(z):0===e.indexOf(z)}j="data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAQAAAAIAAAADAAAABAAAAAUAAAAGAAAAAQAAAAQAAAADAAAABgAAAAUAAAACAAAAAAAAAAIAAAADAAAAAQAAAAQAAAAGAAAAAAAAAAUAAAADAAAABgAAAAQAAAAFAAAAAAAAAAEAAAACAAAABAAAAAUAAAAGAAAAAAAAAAIAAAADAAAAAQAAAAUAAAACAAAAAAAAAAEAAAADAAAABgAAAAQAAAAGAAAAAAAAAAUAAAACAAAAAQAAAAQAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAIAAAADAAAAAAAAAAAAAAACAAAAAAAAAAEAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAYAAAAAAAAABQAAAAAAAAAAAAAABAAAAAUAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAYAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAgAAAAMAAAAEAAAABQAAAAYAAAABAAAAAgAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAgAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAMAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAIAAAAEAAAABQAAAAYAAAAAAAAAAQAAAAIAAAADAAAABQAAAAYAAAAAAAAAAQAAAAIAAAADAAAABAAAAAYAAAAAAAAAAQAAAAIAAAADAAAABAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAYAAAAAAAAAAwAAAAIAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAFAAAABAAAAAAAAAABAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAYAAAAAAAAABAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAFAAAAAgAAAAQAAAADAAAACAAAAAEAAAAHAAAABgAAAAkAAAAAAAAAAwAAAAIAAAACAAAABgAAAAoAAAALAAAAAAAAAAEAAAAFAAAAAwAAAA0AAAABAAAABwAAAAQAAAAMAAAAAAAAAAQAAAB/AAAADwAAAAgAAAADAAAAAAAAAAwAAAAFAAAAAgAAABIAAAAKAAAACAAAAAAAAAAQAAAABgAAAA4AAAALAAAAEQAAAAEAAAAJAAAAAgAAAAcAAAAVAAAACQAAABMAAAADAAAADQAAAAEAAAAIAAAABQAAABYAAAAQAAAABAAAAAAAAAAPAAAACQAAABMAAAAOAAAAFAAAAAEAAAAHAAAABgAAAAoAAAALAAAAGAAAABcAAAAFAAAAAgAAABIAAAALAAAAEQAAABcAAAAZAAAAAgAAAAYAAAAKAAAADAAAABwAAAANAAAAGgAAAAQAAAAPAAAAAwAAAA0AAAAaAAAAFQAAAB0AAAADAAAADAAAAAcAAAAOAAAAfwAAABEAAAAbAAAACQAAABQAAAAGAAAADwAAABYAAAAcAAAAHwAAAAQAAAAIAAAADAAAABAAAAASAAAAIQAAAB4AAAAIAAAABQAAABYAAAARAAAACwAAAA4AAAAGAAAAIwAAABkAAAAbAAAAEgAAABgAAAAeAAAAIAAAAAUAAAAKAAAAEAAAABMAAAAiAAAAFAAAACQAAAAHAAAAFQAAAAkAAAAUAAAADgAAABMAAAAJAAAAKAAAABsAAAAkAAAAFQAAACYAAAATAAAAIgAAAA0AAAAdAAAABwAAABYAAAAQAAAAKQAAACEAAAAPAAAACAAAAB8AAAAXAAAAGAAAAAsAAAAKAAAAJwAAACUAAAAZAAAAGAAAAH8AAAAgAAAAJQAAAAoAAAAXAAAAEgAAABkAAAAXAAAAEQAAAAsAAAAtAAAAJwAAACMAAAAaAAAAKgAAAB0AAAArAAAADAAAABwAAAANAAAAGwAAACgAAAAjAAAALgAAAA4AAAAUAAAAEQAAABwAAAAfAAAAKgAAACwAAAAMAAAADwAAABoAAAAdAAAAKwAAACYAAAAvAAAADQAAABoAAAAVAAAAHgAAACAAAAAwAAAAMgAAABAAAAASAAAAIQAAAB8AAAApAAAALAAAADUAAAAPAAAAFgAAABwAAAAgAAAAHgAAABgAAAASAAAANAAAADIAAAAlAAAAIQAAAB4AAAAxAAAAMAAAABYAAAAQAAAAKQAAACIAAAATAAAAJgAAABUAAAA2AAAAJAAAADMAAAAjAAAALgAAAC0AAAA4AAAAEQAAABsAAAAZAAAAJAAAABQAAAAiAAAAEwAAADcAAAAoAAAANgAAACUAAAAnAAAANAAAADkAAAAYAAAAFwAAACAAAAAmAAAAfwAAACIAAAAzAAAAHQAAAC8AAAAVAAAAJwAAACUAAAAZAAAAFwAAADsAAAA5AAAALQAAACgAAAAbAAAAJAAAABQAAAA8AAAALgAAADcAAAApAAAAMQAAADUAAAA9AAAAFgAAACEAAAAfAAAAKgAAADoAAAArAAAAPgAAABwAAAAsAAAAGgAAACsAAAA+AAAALwAAAEAAAAAaAAAAKgAAAB0AAAAsAAAANQAAADoAAABBAAAAHAAAAB8AAAAqAAAALQAAACcAAAAjAAAAGQAAAD8AAAA7AAAAOAAAAC4AAAA8AAAAOAAAAEQAAAAbAAAAKAAAACMAAAAvAAAAJgAAACsAAAAdAAAARQAAADMAAABAAAAAMAAAADEAAAAeAAAAIQAAAEMAAABCAAAAMgAAADEAAAB/AAAAPQAAAEIAAAAhAAAAMAAAACkAAAAyAAAAMAAAACAAAAAeAAAARgAAAEMAAAA0AAAAMwAAAEUAAAA2AAAARwAAACYAAAAvAAAAIgAAADQAAAA5AAAARgAAAEoAAAAgAAAAJQAAADIAAAA1AAAAPQAAAEEAAABLAAAAHwAAACkAAAAsAAAANgAAAEcAAAA3AAAASQAAACIAAAAzAAAAJAAAADcAAAAoAAAANgAAACQAAABIAAAAPAAAAEkAAAA4AAAARAAAAD8AAABNAAAAIwAAAC4AAAAtAAAAOQAAADsAAABKAAAATgAAACUAAAAnAAAANAAAADoAAAB/AAAAPgAAAEwAAAAsAAAAQQAAACoAAAA7AAAAPwAAAE4AAABPAAAAJwAAAC0AAAA5AAAAPAAAAEgAAABEAAAAUAAAACgAAAA3AAAALgAAAD0AAAA1AAAAMQAAACkAAABRAAAASwAAAEIAAAA+AAAAKwAAADoAAAAqAAAAUgAAAEAAAABMAAAAPwAAAH8AAAA4AAAALQAAAE8AAAA7AAAATQAAAEAAAAAvAAAAPgAAACsAAABUAAAARQAAAFIAAABBAAAAOgAAADUAAAAsAAAAVgAAAEwAAABLAAAAQgAAAEMAAABRAAAAVQAAADEAAAAwAAAAPQAAAEMAAABCAAAAMgAAADAAAABXAAAAVQAAAEYAAABEAAAAOAAAADwAAAAuAAAAWgAAAE0AAABQAAAARQAAADMAAABAAAAALwAAAFkAAABHAAAAVAAAAEYAAABDAAAANAAAADIAAABTAAAAVwAAAEoAAABHAAAAWQAAAEkAAABbAAAAMwAAAEUAAAA2AAAASAAAAH8AAABJAAAANwAAAFAAAAA8AAAAWAAAAEkAAABbAAAASAAAAFgAAAA2AAAARwAAADcAAABKAAAATgAAAFMAAABcAAAANAAAADkAAABGAAAASwAAAEEAAAA9AAAANQAAAF4AAABWAAAAUQAAAEwAAABWAAAAUgAAAGAAAAA6AAAAQQAAAD4AAABNAAAAPwAAAEQAAAA4AAAAXQAAAE8AAABaAAAATgAAAEoAAAA7AAAAOQAAAF8AAABcAAAATwAAAE8AAABOAAAAPwAAADsAAABdAAAAXwAAAE0AAABQAAAARAAAAEgAAAA8AAAAYwAAAFoAAABYAAAAUQAAAFUAAABeAAAAZQAAAD0AAABCAAAASwAAAFIAAABgAAAAVAAAAGIAAAA+AAAATAAAAEAAAABTAAAAfwAAAEoAAABGAAAAZAAAAFcAAABcAAAAVAAAAEUAAABSAAAAQAAAAGEAAABZAAAAYgAAAFUAAABXAAAAZQAAAGYAAABCAAAAQwAAAFEAAABWAAAATAAAAEsAAABBAAAAaAAAAGAAAABeAAAAVwAAAFMAAABmAAAAZAAAAEMAAABGAAAAVQAAAFgAAABIAAAAWwAAAEkAAABjAAAAUAAAAGkAAABZAAAAYQAAAFsAAABnAAAARQAAAFQAAABHAAAAWgAAAE0AAABQAAAARAAAAGoAAABdAAAAYwAAAFsAAABJAAAAWQAAAEcAAABpAAAAWAAAAGcAAABcAAAAUwAAAE4AAABKAAAAbAAAAGQAAABfAAAAXQAAAE8AAABaAAAATQAAAG0AAABfAAAAagAAAF4AAABWAAAAUQAAAEsAAABrAAAAaAAAAGUAAABfAAAAXAAAAE8AAABOAAAAbQAAAGwAAABdAAAAYAAAAGgAAABiAAAAbgAAAEwAAABWAAAAUgAAAGEAAAB/AAAAYgAAAFQAAABnAAAAWQAAAG8AAABiAAAAbgAAAGEAAABvAAAAUgAAAGAAAABUAAAAYwAAAFAAAABpAAAAWAAAAGoAAABaAAAAcQAAAGQAAABmAAAAUwAAAFcAAABsAAAAcgAAAFwAAABlAAAAZgAAAGsAAABwAAAAUQAAAFUAAABeAAAAZgAAAGUAAABXAAAAVQAAAHIAAABwAAAAZAAAAGcAAABbAAAAYQAAAFkAAAB0AAAAaQAAAG8AAABoAAAAawAAAG4AAABzAAAAVgAAAF4AAABgAAAAaQAAAFgAAABnAAAAWwAAAHEAAABjAAAAdAAAAGoAAABdAAAAYwAAAFoAAAB1AAAAbQAAAHEAAABrAAAAfwAAAGUAAABeAAAAcwAAAGgAAABwAAAAbAAAAGQAAABfAAAAXAAAAHYAAAByAAAAbQAAAG0AAABsAAAAXQAAAF8AAAB1AAAAdgAAAGoAAABuAAAAYgAAAGgAAABgAAAAdwAAAG8AAABzAAAAbwAAAGEAAABuAAAAYgAAAHQAAABnAAAAdwAAAHAAAABrAAAAZgAAAGUAAAB4AAAAcwAAAHIAAABxAAAAYwAAAHQAAABpAAAAdQAAAGoAAAB5AAAAcgAAAHAAAABkAAAAZgAAAHYAAAB4AAAAbAAAAHMAAABuAAAAawAAAGgAAAB4AAAAdwAAAHAAAAB0AAAAZwAAAHcAAABvAAAAcQAAAGkAAAB5AAAAdQAAAH8AAABtAAAAdgAAAHEAAAB5AAAAagAAAHYAAAB4AAAAbAAAAHIAAAB1AAAAeQAAAG0AAAB3AAAAbwAAAHMAAABuAAAAeQAAAHQAAAB4AAAAeAAAAHMAAAByAAAAcAAAAHkAAAB3AAAAdgAAAHkAAAB0AAAAeAAAAHcAAAB1AAAAcQAAAHYAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAABAAAABQAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAACAAAABQAAAAEAAAAAAAAA/////wEAAAAAAAAAAwAAAAQAAAACAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAFAAAAAQAAAAAAAAAAAAAAAQAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAADAAAAAAAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAADAAAABQAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAEAAAABQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAABAAAAAwAAAAAAAAAAAAAAAQAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAQAAAAMAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAUAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAAABQAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAwAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAAAAAD/////AwAAAAAAAAAFAAAAAgAAAAAAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAADAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAAAAAABAAAAAwAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAADAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAADAAAAAwAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAUAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAwAAAAAAAAAAAAAA/////wMAAAAAAAAABQAAAAIAAAAAAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAwAAAAAAAAADAAAAAwAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAMAAAADAAAAAwAAAAMAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAUAAAABAAAAAAAAAP////8DAAAAAAAAAAUAAAACAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABAAAAAUAAAABAAAAAAAAAAMAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAIAAAAFAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAADAAAAAQAAAAAAAAABAAAAAAAAAAUAAAAAAAAAAAAAAAUAAAAFAAAAAAAAAAAAAAD/////AQAAAAAAAAADAAAABAAAAAIAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAUAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAFAAAAAAAAAAAAAAAFAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAUAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAEAAAD//////////wEAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAADAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAACAAAAAAAAAAAAAAABAAAAAgAAAAYAAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAcAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAKAAAAAgAAAAAAAAAAAAAAAQAAAAEAAAAFAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAACAAAAAAAAAAAAAAABAAAAAwAAAAcAAAAGAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAABwAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAADgAAAAIAAAAAAAAAAAAAAAEAAAAAAAAACQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAMAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAIAAAAAAAAAAAAAAAEAAAAEAAAACAAAAAoAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAACQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAgAAAAAAAAAAAAAAAQAAAAsAAAAPAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAOAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAIAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAABQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAgAAAAAAAAAAAAAAAQAAAAwAAAAQAAAADAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAPAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAADwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAACAAAAAAAAAAAAAAABAAAACgAAABMAAAAIAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAQAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAACQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAIAAAAAAAAAAAAAAAEAAAANAAAAEQAAAA0AAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAARAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEwAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAEAAAABAAAAAAAAAAAAAAAAAAAAEQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAA0AAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkAAAACAAAAAAAAAAAAAAABAAAADgAAABIAAAAPAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAADwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAASAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEwAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAABEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEgAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAABIAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAATAAAAAgAAAAAAAAAAAAAAAQAAAP//////////EwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAEgAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAASAAAAAAAAABgAAAAAAAAAIQAAAAAAAAAeAAAAAAAAACAAAAADAAAAMQAAAAEAAAAwAAAAAwAAADIAAAADAAAACAAAAAAAAAAFAAAABQAAAAoAAAAFAAAAFgAAAAAAAAAQAAAAAAAAABIAAAAAAAAAKQAAAAEAAAAhAAAAAAAAAB4AAAAAAAAABAAAAAAAAAAAAAAABQAAAAIAAAAFAAAADwAAAAEAAAAIAAAAAAAAAAUAAAAFAAAAHwAAAAEAAAAWAAAAAAAAABAAAAAAAAAAAgAAAAAAAAAGAAAAAAAAAA4AAAAAAAAACgAAAAAAAAALAAAAAAAAABEAAAADAAAAGAAAAAEAAAAXAAAAAwAAABkAAAADAAAAAAAAAAAAAAABAAAABQAAAAkAAAAFAAAABQAAAAAAAAACAAAAAAAAAAYAAAAAAAAAEgAAAAEAAAAKAAAAAAAAAAsAAAAAAAAABAAAAAEAAAADAAAABQAAAAcAAAAFAAAACAAAAAEAAAAAAAAAAAAAAAEAAAAFAAAAEAAAAAEAAAAFAAAAAAAAAAIAAAAAAAAABwAAAAAAAAAVAAAAAAAAACYAAAAAAAAACQAAAAAAAAATAAAAAAAAACIAAAADAAAADgAAAAEAAAAUAAAAAwAAACQAAAADAAAAAwAAAAAAAAANAAAABQAAAB0AAAAFAAAAAQAAAAAAAAAHAAAAAAAAABUAAAAAAAAABgAAAAEAAAAJAAAAAAAAABMAAAAAAAAABAAAAAIAAAAMAAAABQAAABoAAAAFAAAAAAAAAAEAAAADAAAAAAAAAA0AAAAFAAAAAgAAAAEAAAABAAAAAAAAAAcAAAAAAAAAGgAAAAAAAAAqAAAAAAAAADoAAAAAAAAAHQAAAAAAAAArAAAAAAAAAD4AAAADAAAAJgAAAAEAAAAvAAAAAwAAAEAAAAADAAAADAAAAAAAAAAcAAAABQAAACwAAAAFAAAADQAAAAAAAAAaAAAAAAAAACoAAAAAAAAAFQAAAAEAAAAdAAAAAAAAACsAAAAAAAAABAAAAAMAAAAPAAAABQAAAB8AAAAFAAAAAwAAAAEAAAAMAAAAAAAAABwAAAAFAAAABwAAAAEAAAANAAAAAAAAABoAAAAAAAAAHwAAAAAAAAApAAAAAAAAADEAAAAAAAAALAAAAAAAAAA1AAAAAAAAAD0AAAADAAAAOgAAAAEAAABBAAAAAwAAAEsAAAADAAAADwAAAAAAAAAWAAAABQAAACEAAAAFAAAAHAAAAAAAAAAfAAAAAAAAACkAAAAAAAAAKgAAAAEAAAAsAAAAAAAAADUAAAAAAAAABAAAAAQAAAAIAAAABQAAABAAAAAFAAAADAAAAAEAAAAPAAAAAAAAABYAAAAFAAAAGgAAAAEAAAAcAAAAAAAAAB8AAAAAAAAAMgAAAAAAAAAwAAAAAAAAADEAAAADAAAAIAAAAAAAAAAeAAAAAwAAACEAAAADAAAAGAAAAAMAAAASAAAAAwAAABAAAAADAAAARgAAAAAAAABDAAAAAAAAAEIAAAADAAAANAAAAAMAAAAyAAAAAAAAADAAAAAAAAAAJQAAAAMAAAAgAAAAAAAAAB4AAAADAAAAUwAAAAAAAABXAAAAAwAAAFUAAAADAAAASgAAAAMAAABGAAAAAAAAAEMAAAAAAAAAOQAAAAEAAAA0AAAAAwAAADIAAAAAAAAAGQAAAAAAAAAXAAAAAAAAABgAAAADAAAAEQAAAAAAAAALAAAAAwAAAAoAAAADAAAADgAAAAMAAAAGAAAAAwAAAAIAAAADAAAALQAAAAAAAAAnAAAAAAAAACUAAAADAAAAIwAAAAMAAAAZAAAAAAAAABcAAAAAAAAAGwAAAAMAAAARAAAAAAAAAAsAAAADAAAAPwAAAAAAAAA7AAAAAwAAADkAAAADAAAAOAAAAAMAAAAtAAAAAAAAACcAAAAAAAAALgAAAAMAAAAjAAAAAwAAABkAAAAAAAAAJAAAAAAAAAAUAAAAAAAAAA4AAAADAAAAIgAAAAAAAAATAAAAAwAAAAkAAAADAAAAJgAAAAMAAAAVAAAAAwAAAAcAAAADAAAANwAAAAAAAAAoAAAAAAAAABsAAAADAAAANgAAAAMAAAAkAAAAAAAAABQAAAAAAAAAMwAAAAMAAAAiAAAAAAAAABMAAAADAAAASAAAAAAAAAA8AAAAAwAAAC4AAAADAAAASQAAAAMAAAA3AAAAAAAAACgAAAAAAAAARwAAAAMAAAA2AAAAAwAAACQAAAAAAAAAQAAAAAAAAAAvAAAAAAAAACYAAAADAAAAPgAAAAAAAAArAAAAAwAAAB0AAAADAAAAOgAAAAMAAAAqAAAAAwAAABoAAAADAAAAVAAAAAAAAABFAAAAAAAAADMAAAADAAAAUgAAAAMAAABAAAAAAAAAAC8AAAAAAAAATAAAAAMAAAA+AAAAAAAAACsAAAADAAAAYQAAAAAAAABZAAAAAwAAAEcAAAADAAAAYgAAAAMAAABUAAAAAAAAAEUAAAAAAAAAYAAAAAMAAABSAAAAAwAAAEAAAAAAAAAASwAAAAAAAABBAAAAAAAAADoAAAADAAAAPQAAAAAAAAA1AAAAAwAAACwAAAADAAAAMQAAAAMAAAApAAAAAwAAAB8AAAADAAAAXgAAAAAAAABWAAAAAAAAAEwAAAADAAAAUQAAAAMAAABLAAAAAAAAAEEAAAAAAAAAQgAAAAMAAAA9AAAAAAAAADUAAAADAAAAawAAAAAAAABoAAAAAwAAAGAAAAADAAAAZQAAAAMAAABeAAAAAAAAAFYAAAAAAAAAVQAAAAMAAABRAAAAAwAAAEsAAAAAAAAAOQAAAAAAAAA7AAAAAAAAAD8AAAADAAAASgAAAAAAAABOAAAAAwAAAE8AAAADAAAAUwAAAAMAAABcAAAAAwAAAF8AAAADAAAAJQAAAAAAAAAnAAAAAwAAAC0AAAADAAAANAAAAAAAAAA5AAAAAAAAADsAAAAAAAAARgAAAAMAAABKAAAAAAAAAE4AAAADAAAAGAAAAAAAAAAXAAAAAwAAABkAAAADAAAAIAAAAAMAAAAlAAAAAAAAACcAAAADAAAAMgAAAAMAAAA0AAAAAAAAADkAAAAAAAAALgAAAAAAAAA8AAAAAAAAAEgAAAADAAAAOAAAAAAAAABEAAAAAwAAAFAAAAADAAAAPwAAAAMAAABNAAAAAwAAAFoAAAADAAAAGwAAAAAAAAAoAAAAAwAAADcAAAADAAAAIwAAAAAAAAAuAAAAAAAAADwAAAAAAAAALQAAAAMAAAA4AAAAAAAAAEQAAAADAAAADgAAAAAAAAAUAAAAAwAAACQAAAADAAAAEQAAAAMAAAAbAAAAAAAAACgAAAADAAAAGQAAAAMAAAAjAAAAAAAAAC4AAAAAAAAARwAAAAAAAABZAAAAAAAAAGEAAAADAAAASQAAAAAAAABbAAAAAwAAAGcAAAADAAAASAAAAAMAAABYAAAAAwAAAGkAAAADAAAAMwAAAAAAAABFAAAAAwAAAFQAAAADAAAANgAAAAAAAABHAAAAAAAAAFkAAAAAAAAANwAAAAMAAABJAAAAAAAAAFsAAAADAAAAJgAAAAAAAAAvAAAAAwAAAEAAAAADAAAAIgAAAAMAAAAzAAAAAAAAAEUAAAADAAAAJAAAAAMAAAA2AAAAAAAAAEcAAAAAAAAAYAAAAAAAAABoAAAAAAAAAGsAAAADAAAAYgAAAAAAAABuAAAAAwAAAHMAAAADAAAAYQAAAAMAAABvAAAAAwAAAHcAAAADAAAATAAAAAAAAABWAAAAAwAAAF4AAAADAAAAUgAAAAAAAABgAAAAAAAAAGgAAAAAAAAAVAAAAAMAAABiAAAAAAAAAG4AAAADAAAAOgAAAAAAAABBAAAAAwAAAEsAAAADAAAAPgAAAAMAAABMAAAAAAAAAFYAAAADAAAAQAAAAAMAAABSAAAAAAAAAGAAAAAAAAAAVQAAAAAAAABXAAAAAAAAAFMAAAADAAAAZQAAAAAAAABmAAAAAwAAAGQAAAADAAAAawAAAAMAAABwAAAAAwAAAHIAAAADAAAAQgAAAAAAAABDAAAAAwAAAEYAAAADAAAAUQAAAAAAAABVAAAAAAAAAFcAAAAAAAAAXgAAAAMAAABlAAAAAAAAAGYAAAADAAAAMQAAAAAAAAAwAAAAAwAAADIAAAADAAAAPQAAAAMAAABCAAAAAAAAAEMAAAADAAAASwAAAAMAAABRAAAAAAAAAFUAAAAAAAAAXwAAAAAAAABcAAAAAAAAAFMAAAAAAAAATwAAAAAAAABOAAAAAAAAAEoAAAADAAAAPwAAAAEAAAA7AAAAAwAAADkAAAADAAAAbQAAAAAAAABsAAAAAAAAAGQAAAAFAAAAXQAAAAEAAABfAAAAAAAAAFwAAAAAAAAATQAAAAEAAABPAAAAAAAAAE4AAAAAAAAAdQAAAAQAAAB2AAAABQAAAHIAAAAFAAAAagAAAAEAAABtAAAAAAAAAGwAAAAAAAAAWgAAAAEAAABdAAAAAQAAAF8AAAAAAAAAWgAAAAAAAABNAAAAAAAAAD8AAAAAAAAAUAAAAAAAAABEAAAAAAAAADgAAAADAAAASAAAAAEAAAA8AAAAAwAAAC4AAAADAAAAagAAAAAAAABdAAAAAAAAAE8AAAAFAAAAYwAAAAEAAABaAAAAAAAAAE0AAAAAAAAAWAAAAAEAAABQAAAAAAAAAEQAAAAAAAAAdQAAAAMAAABtAAAABQAAAF8AAAAFAAAAcQAAAAEAAABqAAAAAAAAAF0AAAAAAAAAaQAAAAEAAABjAAAAAQAAAFoAAAAAAAAAaQAAAAAAAABYAAAAAAAAAEgAAAAAAAAAZwAAAAAAAABbAAAAAAAAAEkAAAADAAAAYQAAAAEAAABZAAAAAwAAAEcAAAADAAAAcQAAAAAAAABjAAAAAAAAAFAAAAAFAAAAdAAAAAEAAABpAAAAAAAAAFgAAAAAAAAAbwAAAAEAAABnAAAAAAAAAFsAAAAAAAAAdQAAAAIAAABqAAAABQAAAFoAAAAFAAAAeQAAAAEAAABxAAAAAAAAAGMAAAAAAAAAdwAAAAEAAAB0AAAAAQAAAGkAAAAAAAAAdwAAAAAAAABvAAAAAAAAAGEAAAAAAAAAcwAAAAAAAABuAAAAAAAAAGIAAAADAAAAawAAAAEAAABoAAAAAwAAAGAAAAADAAAAeQAAAAAAAAB0AAAAAAAAAGcAAAAFAAAAeAAAAAEAAAB3AAAAAAAAAG8AAAAAAAAAcAAAAAEAAABzAAAAAAAAAG4AAAAAAAAAdQAAAAEAAABxAAAABQAAAGkAAAAFAAAAdgAAAAEAAAB5AAAAAAAAAHQAAAAAAAAAcgAAAAEAAAB4AAAAAQAAAHcAAAAAAAAAcgAAAAAAAABwAAAAAAAAAGsAAAAAAAAAZAAAAAAAAABmAAAAAAAAAGUAAAADAAAAUwAAAAEAAABXAAAAAwAAAFUAAAADAAAAdgAAAAAAAAB4AAAAAAAAAHMAAAAFAAAAbAAAAAEAAAByAAAAAAAAAHAAAAAAAAAAXAAAAAEAAABkAAAAAAAAAGYAAAAAAAAAdQAAAAAAAAB5AAAABQAAAHcAAAAFAAAAbQAAAAEAAAB2AAAAAAAAAHgAAAAAAAAAXwAAAAEAAABsAAAAAQAAAHIAAAAAAAAAGC1EVPsh+T8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgtRFT7Ifk/GC1EVPsh+T8AAAAAAAAAAAAAAAAAAAAAGC1EVPsh+T8AAAAAAAAAABgtRFT7IQlAGC1EVPsh+T8AAAAAAAAAAAAAAAAAAAAAGC1EVPshCUAAAAAAAAAAABgtRFT7Ifm/GC1EVPsh+T8AAAAAAAAAAAAAAAAAAAAAGC1EVPsh+b8AAAAAAAAAAAAAAAAAAAAAGC1EVPsh+b8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgtRFT7Ifm/GC1EVPsh+b8AAAAAAAAAAAAAAAAAAAAAGC1EVPsh+b8AAAAAAAAAABgtRFT7IQnAGC1EVPsh+b8AAAAAAAAAAAAAAAAAAAAAGC1EVPshCcAAAAAAAAAAABgtRFT7Ifk/GC1EVPsh+b8AAAAAAAAAAAAAAAAAAAAAGC1EVPsh+T8AAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAGAAAAAgAAAAUAAAABAAAABAAAAAAAAAAAAAAABQAAAAMAAAABAAAABgAAAAQAAAACAAAAAAAAAMpi5RexJsw/BlIKPVwR5T95Wyu0/QjnP5PjoT7YYcu/mBhKZ6zrwj8wRYS7NebuP3qW6geh+Ls/SLrixebL3r+pcyymN9XrPwmkNHp7xec/GWNMZVAA17+82s+x2BLiPwn2ytbJ9ek/LgEH1sMS1j8yp/2LhTfeP+SnWwtQBbu/d38gkp5X7z8ytsuHaADGPzUYObdf1+m/7IauECWhwz+cjSACjzniP76Z+wUhN9K/1+GEKzup67+/GYr/04baPw6idWOvsuc/ZedTWsRa5b/EJQOuRzi0v/OncYhHPes/h49PixY53j+i8wWfC03Nvw2idWOvsue/ZedTWsRa5T/EJQOuRzi0P/KncYhHPeu/iY9PixY53r+i8wWfC03NP9anWwtQBbs/d38gkp5X778ytsuHaADGvzUYObdf1+k/74auECWhw7+cjSACjzniv8CZ+wUhN9I/1uGEKzup6z+/GYr/04bavwmkNHp7xee/F2NMZVAA1z+82s+x2BLivwr2ytbJ9em/KwEH1sMS1r8yp/2LhTfev81i5RexJsy/BlIKPVwR5b95Wyu0/Qjnv5DjoT7YYcs/nBhKZ6zrwr8wRYS7Nebuv3OW6geh+Lu/SLrixebL3j+pcyymN9Xrv8rHIFfWehZAMBwUdlo0DECTUc17EOb2PxpVB1SWChdAzjbhb9pTDUDQhmdvECX5P9FlMKCC9+g/IIAzjELgE0DajDngMv8GQFhWDmDPjNs/y1guLh96EkAxPi8k7DIEQJCc4URlhRhA3eLKKLwkEECqpNAyTBD/P6xpjXcDiwVAFtl//cQm4z+Ibt3XKiYTQM7mCLUb3QdAoM1t8yVv7D8aLZv2Nk8UQEAJPV5nQwxAtSsfTCoE9z9TPjXLXIIWQBVanC5W9AtAYM3d7Adm9j++5mQz1FoWQBUThyaVBghAwH5muQsV7T89Q1qv82MUQJoWGOfNuBdAzrkClkmwDkDQjKq77t37Py+g0dtitsE/ZwAMTwVPEUBojepluNwBQGYbtuW+t9w/HNWIJs6MEkDTNuQUSlgEQKxktPP5TcQ/ixbLB8JjEUCwuWjXMQYCQAS/R09FkRdAowpiZjhhDkB7LmlczD/7P01iQmhhsAVAnrtTwDy84z/Z6jfQ2TgTQChOCXMnWwpAhrW3daoz8z/HYJvVPI4VQLT3ik5FcA5Angi7LOZd+z+NNVzDy5gXQBXdvVTFUA1AYNMgOeYe+T8+qHXGCwkXQKQTOKwa5AJA8gFVoEMW0T+FwzJyttIRQAEAAAD/////BwAAAP////8xAAAA/////1cBAAD/////YQkAAP////+nQQAA/////5HLAQD/////95AMAP/////B9lcAAAAAAAAAAAAAAAAAAgAAAP////8OAAAA/////2IAAAD/////rgIAAP/////CEgAA/////06DAAD/////IpcDAP/////uIRkA/////4LtrwAAAAAAAAAAAAAAAAAAAAAAAgAAAP//////////AQAAAAMAAAD//////////////////////////////////////////////////////////////////////////wEAAAAAAAAAAgAAAP///////////////wMAAAD//////////////////////////////////////////////////////////////////////////wEAAAAAAAAAAgAAAP///////////////wMAAAD//////////////////////////////////////////////////////////////////////////wEAAAAAAAAAAgAAAP///////////////wMAAAD//////////////////////////////////////////////////////////wIAAAD//////////wEAAAAAAAAA/////////////////////wMAAAD/////////////////////////////////////////////////////AwAAAP////////////////////8AAAAA/////////////////////wEAAAD///////////////8CAAAA////////////////////////////////AwAAAP////////////////////8AAAAA////////////////AgAAAAEAAAD/////////////////////////////////////////////////////AwAAAP////////////////////8AAAAA////////////////AgAAAAEAAAD/////////////////////////////////////////////////////AwAAAP////////////////////8AAAAA////////////////AgAAAAEAAAD/////////////////////////////////////////////////////AwAAAP////////////////////8AAAAA////////////////AgAAAAEAAAD/////////////////////////////////////////////////////AQAAAAIAAAD///////////////8AAAAA/////////////////////wMAAAD/////////////////////////////////////////////////////AQAAAAIAAAD///////////////8AAAAA/////////////////////wMAAAD/////////////////////////////////////////////////////AQAAAAIAAAD///////////////8AAAAA/////////////////////wMAAAD/////////////////////////////////////////////////////AQAAAAIAAAD///////////////8AAAAA/////////////////////wMAAAD///////////////////////////////8CAAAA////////////////AQAAAP////////////////////8AAAAA/////////////////////wMAAAD/////////////////////////////////////////////////////AwAAAP////////////////////8AAAAAAQAAAP//////////AgAAAP//////////////////////////////////////////////////////////AwAAAP///////////////wIAAAAAAAAAAQAAAP//////////////////////////////////////////////////////////////////////////AwAAAP///////////////wIAAAAAAAAAAQAAAP//////////////////////////////////////////////////////////////////////////AwAAAP///////////////wIAAAAAAAAAAQAAAP//////////////////////////////////////////////////////////////////////////AwAAAAEAAAD//////////wIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAgAAAAAAAAACAAAAAQAAAAEAAAACAAAAAgAAAAAAAAAFAAAABQAAAAAAAAACAAAAAgAAAAMAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAIAAAABAAAAAgAAAAIAAAACAAAAAAAAAAUAAAAGAAAAAAAAAAIAAAACAAAAAwAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAIAAAAAAAAAAgAAAAEAAAADAAAAAgAAAAIAAAAAAAAABQAAAAcAAAAAAAAAAgAAAAIAAAADAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAgAAAAAAAAACAAAAAQAAAAQAAAACAAAAAgAAAAAAAAAFAAAACAAAAAAAAAACAAAAAgAAAAMAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAACAAAAAAAAAAIAAAABAAAAAAAAAAIAAAACAAAAAAAAAAUAAAAJAAAAAAAAAAIAAAACAAAAAwAAAAUAAAAAAAAAAAAAAAAAAAAAAAAACgAAAAIAAAACAAAAAAAAAAMAAAAOAAAAAgAAAAAAAAACAAAAAwAAAAAAAAAAAAAAAgAAAAIAAAADAAAABgAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAgAAAAIAAAAAAAAAAwAAAAoAAAACAAAAAAAAAAIAAAADAAAAAQAAAAAAAAACAAAAAgAAAAMAAAAHAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAACAAAAAgAAAAAAAAADAAAACwAAAAIAAAAAAAAAAgAAAAMAAAACAAAAAAAAAAIAAAACAAAAAwAAAAgAAAAAAAAAAAAAAAAAAAAAAAAADQAAAAIAAAACAAAAAAAAAAMAAAAMAAAAAgAAAAAAAAACAAAAAwAAAAMAAAAAAAAAAgAAAAIAAAADAAAACQAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAgAAAAIAAAAAAAAAAwAAAA0AAAACAAAAAAAAAAIAAAADAAAABAAAAAAAAAACAAAAAgAAAAMAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAACAAAAAgAAAAAAAAADAAAABgAAAAIAAAAAAAAAAgAAAAMAAAAPAAAAAAAAAAIAAAACAAAAAwAAAAsAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAIAAAACAAAAAAAAAAMAAAAHAAAAAgAAAAAAAAACAAAAAwAAABAAAAAAAAAAAgAAAAIAAAADAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAgAAAAIAAAAAAAAAAwAAAAgAAAACAAAAAAAAAAIAAAADAAAAEQAAAAAAAAACAAAAAgAAAAMAAAANAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAACAAAAAgAAAAAAAAADAAAACQAAAAIAAAAAAAAAAgAAAAMAAAASAAAAAAAAAAIAAAACAAAAAwAAAA4AAAAAAAAAAAAAAAAAAAAAAAAACQAAAAIAAAACAAAAAAAAAAMAAAAFAAAAAgAAAAAAAAACAAAAAwAAABMAAAAAAAAAAgAAAAIAAAADAAAADwAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAgAAAAAAAAACAAAAAQAAABMAAAACAAAAAgAAAAAAAAAFAAAACgAAAAAAAAACAAAAAgAAAAMAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABEAAAACAAAAAAAAAAIAAAABAAAADwAAAAIAAAACAAAAAAAAAAUAAAALAAAAAAAAAAIAAAACAAAAAwAAABEAAAAAAAAAAAAAAAAAAAAAAAAAEgAAAAIAAAAAAAAAAgAAAAEAAAAQAAAAAgAAAAIAAAAAAAAABQAAAAwAAAAAAAAAAgAAAAIAAAADAAAAEgAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAgAAAAAAAAACAAAAAQAAABEAAAACAAAAAgAAAAAAAAAFAAAADQAAAAAAAAACAAAAAgAAAAMAAAATAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAACAAAAAAAAAAIAAAABAAAAEgAAAAIAAAACAAAAAAAAAAUAAAAOAAAAAAAAAAIAAAACAAAAAwAAAAIAAAABAAAAAAAAAAEAAAACAAAAAAAAAAAAAAACAAAAAQAAAAAAAAABAAAAAgAAAAEAAAAAAAAAAgAAAAAAAAAFAAAABAAAAAAAAAABAAAABQAAAAAAAAAAAAAABQAAAAQAAAAAAAAAAQAAAAUAAAAEAAAAAAAAAAUAAAAAAAAAAgAAAAEAAAAAAAAAAQAAAAIAAAAAAAAAAAAAAAIAAAABAAAAAAAAAAEAAAACAAAAAQAAAAAAAAACAAAAAgAAAAAAAAABAAAAAAAAAAAAAAAFAAAABAAAAAAAAAABAAAABQAAAAAAAAAAAAAABQAAAAQAAAAAAAAAAQAAAAUAAAAEAAAAAAAAAAUAAAAFAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAQAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAABAAAAAAAAAAABAAAAAAEAAAAAAAAAAAEAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAQAAAAAAAAAAAAEAAAAAAAAAAAAAOgehWlKfUEEz1zLi+JsiQa2og3wcMfVAWCbHorc0yEDi+Yn/Y6mbQJ11/mfsnG9At6bnG4UQQkBvMCQWKqUUQJVmwwswmOc/3hVgVBL3uj//qqOEOdGOPw/WDN4gnGE/H3ANkCUgND+AA8btKgAHPwTXBqJVSdo+XfRQAqsKrj4fc+zLYbSPQklEmCZHv2FCUP+uDso1NEKYtPhwphUHQptxnyFXYdpB7CddZAMmrkGAt1AxSTqBQUibBVdTsFNBSuX3MV+AJkFocv82SLf5QAqmgj7AY81A23VDSEnLoEDGEJVSeDFzQDYrqvBk70VA8U157pcRGUBWfEF+ZKbsP6phvycGBZRAJbod0OgwfkCp+L8jatBmQCjl3pGrPlFAfMWm114SOkButwtqS7UjQHQwbcjXyw1A8jnLuuyA9j9KwjL0VwHhPyotk0lcs8k/Q5PvEs9rsz+SfsOQEVqdPzUAKDojLoY/WJz/kcjCcD8YFu070FRZPyoLC2BdJEM/YOXQAuiMM0HIBz1bw3sdQdV46aaHRwZByatzjDPX8EDb3Jie8HXZQCJxj6ULP8NAUaG6uRAZrUCWdmou5/mVQLb9huRPm4BAhvoCHygZaUCuX/I3SPdSQC9/bC/1qTxAfKxsYQ6pJUCuslH+N14QQMS/cv7SvPg/Ol8maYKx4j8AAAAA/////wAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////////////////////////////wAAAAD/////AAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAA/////wAAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAP////8AAAAABQAAAAAAAAAAAAAAAAAAAAAAAAD/////BQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAA/////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP////////////////////////////////////8AAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////AAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////////////////////////////wAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAAAAAABAAAAAAAAAAUAAAABAAAAAQAAAAAAAAAAAAAAAQAAAAEAAAAAAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAEAAQAAAQEAAAAAAAEAAAABAAAAAQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAAAAAABAAAAAQAAAAEAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAKriWFiWZfg/Y2nmTbY/8z8MHSPSqmnjv6hnn18HR3c/quJYWJZl+D/jq5TzDdzyPwwdI9KqaeO/u0kC1eFSBECq4lhYlmX4P69pJmt7c/E/NnkJi6jSBsDESFlzKkr6P33ArMz7sfY/o2q2uqM08D+oZ59fB0d3PzEqCi3qrvK/kmm4ANp49D+4wS2wzhzvP9WJvyAnx+E/upcY75RVx7+95t+9y0T1P9L18g1caO0/k6CkRyVzAEBf99+e/GjxP6QMsuuLQ/U/PlP4Qr8q7j8Mb/GO2GMCwLl2K/DQIghAePiwytEp9D9UHrsuI/nqPzjMedJ+yuy/k6xgf58n/L+XoQtn22DzP2lzCnsYk+s/JhUSDI4P8z+8lFcBhgTcPxOqKRxEX/M/89MEdoPQ6j8OKQaXDob7vzWwNvblgAPAzGkxMcl88j9Nm4okPkbpP0vI89vxSgRAdac2Z6W2/T+6UFOMC3zyP/+2XEF3hug/QqhELwGKCMAwdlQerEoEQFcr/B+VnvE/hB1hfFzT5j8wdsE/Da64P0hIvnF/sOC/KH/hrXUg8T9bI5OQHaLlP+mYzla7td6/CtKG6iOm8b8FW3TV8oXwP8ORhtNuJ+c/q8JrTMz/AcC8PaUl+PUFwAXv9rkMT/A/m+sAswr15D+7hk/O3yvkP6c/yVsOHKI/qqAX9idJ8D/8hNz1KNPiP7xSXh3Ggvg/epbkiKr57T/23/LB1GLvP4GTTeNZi+M/W4TqlTheBcDupZgIdYUIQGwlcW3YZO8/tQvDXQ3H4j8Bt+sf9DkAQMdFie+nNvg/Z5Uh1wDX7j9h5X2d4KjhPxMJ1ZVT4Pa/evqB8xB//7+W183U9QLsPwzNxsC7AOA/af/LqCnK/r/lPceQ0FQDwHoY0nYIW+w/bHNSHrTg4D/DFcMAdabuv2sz5Ojhnve/FvLf01HN6z/tEDL2Hz/gP0bBv0KUhPA/pd7sEnMc4D8EGon4Lo7sP5NVbYtSON8/DAMC50odBkB+Z2J8MGYCQIhlM1gubOo/FssiPwWy4D8OIlGqRnkCQAd1vopp6f4/QS1keLLK6T9rfoBuT7LZP3KQbH5ugwjAjqVPXTmbBUBL/JxcqR3qP3oSeovuktg/Y6pRhJmqy7+0kwuU0Yjmv2wvsfFmQ+g/R98lJFqQ2T/IGb5gjLkCwK3mNff3kQbAqDznPFM86T+iiP0FfsvYP7fzKG6Mls0/h7+at2btzL8tsUTgk+LmP/YEIrTDINU/WmwKoVjA5L9aC02r6FHxvzzFCT/Qg+Y/nx0V97en0j8+1toJOm77P1kZ7h8KjfQ/GBbbqxgk5j9RGXM79G/SP+beHsWmweQ/9REi4eX0xD/V9s+kmMHkP+pb9yNs09A/c5ERjVDTAECqEr3OBCH7P14ILfMECOU/piRx4P8P0j+JYU//bfL0Pw62fw28B+w/l5YW2Ga45D9+CyKRbenOP5cH6fHy1/S/o/egk03++r91nTYRL/bjP3fHN6OJVdA/7xXQh1XLBcAB3g6tBdUIQKW2KnGYjeQ/SqIpagclyz8F9P3YgNL6v9H6NBsZ8QDAW2k5L5Qs4z/0axa1l6zLP1GE65Mu4wNAwfX+BYmWAEBBgJP90M3hP6/03qhPLdA/zqo5bJz2778/ESlPCTn1v7JkhGyvzuE/DM7sj5twwz/6xbXLavYGQH29RFRGkgNA7bOXVSJ54T9fEhTHO/TDP+8t+HMOiwDAxa0SbGTtA8Atii7y0mLgP4cecHFB3sM/uPUpyv+K7j8nktD1/WvhP2cWmi772d8/Fj7uU9kEvD8oKOESLzKmvwSdCqrHdNu/XCluGsvI3T929OW5md+uP9dP6rXcZNq/gXM+ggzL6b+eKjsPgJncP6i1e9aVu7E/2CnPNJyD1D/DnyGgSe+xvy8k7g9bp9s/nYmLvHn1sz9cFOwApH8IwGa6Mjy9cgZAJr95SiSW2z8rCkhOFvqdP3SIKmO/UwPAEy0zkN7bBsCds8Hg/13YP1zv413hVGi/FVtqixSn6L9XAPQGul3yv7SGu2BoCNk/n94bv7Maj79p13T6X9z3P45MPCW3WvI/rU/8/LRj1T9cgR6SXd+ZPymL2DstbPI/8s/pAkIz6z/fmoB+8efYPz2XyfWgYaa/6wys72AW/j8LZImhgrf3P729Zla/n9U/ySB8B3PBqL8O2nhevvbxv17+5A+n6fe/YrGIqEGB1T+wCEGbkhaxv989QHVE5wFAzd12PTu3/T9AHUPZY2DUP3SQDST0zq2/JCxAlIoj5T+Mhe1IJkrQP/cRpl8QhtU/amc4seFts79khiUSVaz3vxYfWtjPwf2/CHscxQqD0j/ctUBQ9my3v0POnFiyXv2/pjjn2Ju/AcDk45DwBhPRP/GjwlCrv7m/aT2ciwolBsAQOzHr/wUJQCzpq5UYvtI/gDCf3SlCwb+4i7S+mukEQBDA1f8mowFA2utnRN3KyT9T+9EYAVG6v9/IVZ0enrE/7NbRtdGfzr/8y8GpRz7LP3U0vTSk18e/JzHEcwiBB0AGm8Q7AJkEQNLciyt4Esk/gLou5zoQxr+RrOfM91oBwEzd36KybgTAgLou5zoQxj/S3IsreBLJv1gCch0OHO8/FD+RxSLN4j91NL00pNfHP/zLwalHPsu/nL7/By4Pyr8tSP5h7CPiv1P70RgBUbo/2utnRN3Kyb/KfllfCpUIwLkP5zj+NwdAgDCf3SlCwT8s6auVGL7Sv2aFPlaC4eC/XrS5UVH77b/xo8JQq7+5P+TjkPAGE9G/Q30/RYbn1z8FF/ISafuLv9y1QFD2bLc/CHscxQqD0r/fi+tPROX0P6vRc+19ie0/amc4seFtsz/3EaZfEIbVv77TYpahl/o/DDsu0CaC9D90kA0k9M6tP0AdQ9ljYNS/CCI0rxjZA8BgfCaLthgHwLAIQZuSFrE/YrGIqEGB1b8kvQ982+rsv4J8EWu7jPS/ySB8B3PBqD+9vWZWv5/VvwrAByWcJgBAxFujmE9a+j89l8n1oGGmP9+agH7x59i/N03cuJUt9L8X9v4GdIz6v1yBHpJd35m/rU/8/LRj1b8mz69sydf/vyu5idMqVQLAn94bv7Majz8AhrtgaAjZv+aCE66WZ/q/lA1Mgz/p/79c7+Nd4VRoP52zweD/Xdi/TJZpMTb4AkDLWZShPOb/PysKSE4W+p2/Jr95SiSW27/PkmbE7zjnP6UAiCDmMNI/nYmLvHn1s78vJO4PW6fbv5MWA2vqSrQ/V5WLwPB51b+otXvWlbuxv54qOw+Amdy/1keqzYeRBsApIEMHgZIIQHb05bmZ366/XCluGsvI3b8W44a9X9UFQEeQtDM4rwJAFj7uU9kEvL9nFpou+9nfv3Co+JcyyQhAcdkCX2KzBUCHHnBxQd7Dvy2KLvLSYuC/o6+5YTt/AcCHCNDW+8YEwF8SFMc79MO/7bOXVSJ54b9E/pfA2S3xPzD9xaBb0uQ/DM7sj5tww7+yZIRsr87hv7c4c0SEXNG/Tr79/9M+5r+v9N6oTy3Qv5uAk/3QzeG/XcI1OVQkAUAQSV9Z7Qr9P/RrFrWXrMu/W2k5L5Qs479Zo2IBM/vkv6FuipzkFvG/SqIpagcly7+ltipxmI3kv0pmis91cfc/gWQecsRh8D93xzejiVXQv3WdNhEv9uO/D7mgYy612j+PyVPNaT2jv34LIpFt6c6/l5YW2Ga45L+LUp+2A2z9P39i5xSpRfc/piRx4P8P0r9eCC3zBAjlv5n4OKmIUf2/jj/kUAwgAsDqW/cjbNPQv9X2z6SYweS/aTdljlWd8L94R8vZ8SL3v1EZczv0b9K/GBbbqxgk5r9XdfyikfEDwPILMvas0gfAnx0V97en0r88xQk/0IPmvxGErZ681fa/9kCaiOy2/b/2BCK0wyDVvy2xROCT4ua/+5EBLOXxA0B7p53+BnkAQKKI/QV+y9i/qDznPFM86b/snWGNkkgHwC+ByugkUwdAR98lJFqQ2b9sL7HxZkPovyJNGM67oek/HzNy6BqA1D96EnqL7pLYv0v8nFypHeq/axL/u1FnB0AkSEHvxn8DQGt+gG5Pstm/QS1keLLK6b/Sk/O6mtGzPxU8pLcPNty/FssiPwWy4L+IZTNYLmzqvw4szKfSouq/G+XJHY1a87+TVW2LUjjfvwQaifgujuy/3VARaoMl2L9NFodfK+/qv+0QMvYfP+C/FvLf01HN67+ETOQysd8AwH71iI/eGgXAbHNSHrTg4L96GNJ2CFvsv6BnExReeAFA5CakvxSl+j8MzcbAuwDgv5bXzdT1Auy/uVq8/8x58z+uvPMNqzTnP2HlfZ3gqOG/Z5Uh1wDX7r8PUbMSo2P7P9VfBrXlxPI/tQvDXQ3H4r9sJXFt2GTvvyDssGgO0PG/WxT/uE4N+r+Bk03jWYvjv/bf8sHUYu+/rUXN8hUe3j9m5HB1yZCzv/yE3PUo0+K/qqAX9idJ8L9mByqLMMH5v4kHC7KQowHAm+sAswr15L8F7/a5DE/wv2JLsGADFwTAKQjVGovZCMDDkYbTbifnvwVbdNXyhfC/malhH7yI7D+oevd0GWDZP1sjk5AdouW/KH/hrXUg8b8KWmrpQ0sFQAzEAF/pTgBAhB1hfFzT5r9XK/wflZ7xv18hRuqKXAjA/5rUd9v1BED/tlxBd4bov7pQU4wLfPK/4pnwn0T/sj/c277XPF3jv02biiQ+Rum/zGkxMcl88r8Yk0HhJVzjv62yUUFRjfS/89MEdoPQ6r8TqikcRF/zvxQxghHovfY/cfM1eFWE5j9pcwp7GJPrv5ehC2fbYPO/KUV2nGg0/795OhmUaqEFwFQeuy4j+eq/ePiwytEp9L8DuqWfW+8BQLytJylXHPY/PlP4Qr8q7r+kDLLri0P1vxT4ShWL+Oo/DMsWg0zlv7/S9fINXGjtv73m373LRPW/+xg/Gaxd8b94MdQEfW0AwLjBLbDOHO+/kmm4ANp49L+cShSMMbAEwKyjUgWirAdAo2q2uqM08L99wKzM+7H2v3RdlNBXFgnA8S9+ewyV/z+vaSZre3Pxv6riWFiWZfi/2J7VSZZ60j+LES81zPn3v+OrlPMN3PK/quJYWJZl+L/OZbufkEcEQLCNB/1lPOO/Y2nmTbY/87+q4lhYlmX4v7CNB/1lPOO/zmW7n5BHBEBwKD1Aa57LP/XsSsw7RbU/PMDPJGsfoD/TqningGKIPzFtCLYmb3I/qYfrJr7eWz9pQmleXRFFP0rWlJkA2i8/pCvcttgTGD9Dt8IWbjMCPyCG4GRlhOs+1JI2GhDN1D7ns8cGvXK/Pi8m8UTJxac+hNTfA2z4kT7GI8kjLyt7Pv//////HwAI//////8zEAj/////fzIgCP////9vMjAI/////2MyQAj///8/YjJQCP///zdiMmAI////M2IycAj//78zYjKACP//qzNiMpAI/3+rM2IyoAj/D6szYjKwCP8DqzNiMsAIvwOrM2Iy0AifA6szYjLgCJkDqzNiMvAI//////8/Dwj//////ysfCP////9/KS8I/////z8pPwj/////OSlPCP///z84KV8I////Dzgpbwj///8OOCl/CP//Hw44KY8I//8PDjgpnwj/fw0OOCmvCP8PDQ44Kb8I/w0NDjgpzwj/DA0OOCnfCMcMDQ44Ke8IxAwNDjgp/wgHAAAABwAAAAEAAAACAAAABAAAAAMAAAAAAAAAAAAAAAcAAAADAAAAAQAAAAIAAAAFAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAgAAAAEAAAADAAAADgAAAAYAAAALAAAAAgAAAAcAAAABAAAAGAAAAAUAAAAKAAAAAQAAAAYAAAAAAAAAJgAAAAcAAAAMAAAAAwAAAAgAAAACAAAAMQAAAAkAAAAOAAAAAAAAAAUAAAAEAAAAOgAAAAgAAAANAAAABAAAAAkAAAADAAAAPwAAAAsAAAAGAAAADwAAAAoAAAAQAAAASAAAAAwAAAAHAAAAEAAAAAsAAAARAAAAUwAAAAoAAAAFAAAAEwAAAA4AAAAPAAAAYQAAAA0AAAAIAAAAEQAAAAwAAAASAAAAawAAAA4AAAAJAAAAEgAAAA0AAAATAAAAdQAAAA8AAAATAAAAEQAAABIAAAAQAAAABgAAAAIAAAADAAAABQAAAAQAAAAAAAAAAAAAAAAAAAAGAAAAAgAAAAMAAAABAAAABQAAAAQAAAAAAAAAAAAAAAcAAAAFAAAAAwAAAAQAAAABAAAAAAAAAAIAAAAAAAAAAgAAAAMAAAABAAAABQAAAAQAAAAGAAAAAAAAAAAAAAAYLURU+yH5PxgtRFT7Ifm/GC1EVPshCUAYLURU+yEJwGFsZ29zLmMAaDNOZWlnaGJvclJvdGF0aW9ucwBjZWxsc1RvTXVsdGlQb2x5LmMAY2VsbFRvRWRnZUFyY3MAAAEDAgQABAMFAQJjYW5jZWxBcmNQYWlycwBjcmVhdGVTb3J0YWJsZUxvb3AAZGlyZWN0ZWRFZGdlLmMAZGlyZWN0ZWRFZGdlVG9Cb3VuZGFyeQBhZGphY2VudEZhY2VEaXJbdG1wRmlqay5mYWNlXVtmaWprLmZhY2VdID09IEtJAGZhY2VpamsuYwBfZmFjZUlqa1BlbnRUb0NlbGxCb3VuZGFyeQBhZGphY2VudEZhY2VEaXJbY2VudGVySUpLLmZhY2VdW2ZhY2UyXSA9PSBLSQBfZmFjZUlqa1RvQ2VsbEJvdW5kYXJ5AGgzSW5kZXguYwBjb21wYWN0Q2VsbHMAdmVjM1RvQ2VsbABjZWxsVG9DaGlsZFBvcwB2YWxpZGF0ZUNoaWxkUG9zAHJldkRpciAhPSBJTlZBTElEX0RJR0lUAGxvY2FsaWouYwBjZWxsVG9Mb2NhbElqawBiYXNlQ2VsbCAhPSBvcmlnaW5CYXNlQ2VsbAAhKG9yaWdpbk9uUGVudCAmJiBpbmRleE9uUGVudCkAYmFzZUNlbGwgPT0gb3JpZ2luQmFzZUNlbGwALi4vaW5jbHVkZS9jb29yZGlqay5oAF91cEFwN0NoZWNrZWQAX3VwQXA3ckNoZWNrZWQAYmFzZUNlbGwgIT0gSU5WQUxJRF9CQVNFX0NFTEwAbG9jYWxJamtUb0NlbGwAIV9pc0Jhc2VDZWxsUGVudGFnb24oYmFzZUNlbGwpAGJhc2VDZWxsUm90YXRpb25zID49IDAAZ3JpZFBhdGhDZWxsc0ludGVycG9sYXRlAHBvbHlmaWxsLmMAaXRlclN0ZXBQb2x5Z29uQ29tcGFjdAAwAHZlcnRleC5jAHZlcnRleFJvdGF0aW9ucwBjZWxsVG9WZXJ0ZXg=";function H(e){return e}function q(e){return e.replace(/\b__Z[\w\d_]+/g,function(e){return e===e?e:e+" ["+e+"]"})}function Q(){var e=/* @__PURE__ */new Error;if(!e.stack){try{throw new Error(0)}catch(Lr){e=Lr}if(!e.stack)return"(no stack trace available)"}return e.stack.toString()}function K(){return h.length}function W(e){try{var t=new ArrayBuffer(e);if(t.byteLength!=e)return;return new Int8Array(t).set(h),Y(t),w(t),1}catch(Lr){}}var J="function"==typeof atob?atob:function(e){var t,n,r,i,a,s,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",A="",l=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{t=o.indexOf(e.charAt(l++))<<2|(i=o.indexOf(e.charAt(l++)))>>4,n=(15&i)<<4|(a=o.indexOf(e.charAt(l++)))>>2,r=(3&a)<<6|(s=o.indexOf(e.charAt(l++))),A+=String.fromCharCode(t),64!==a&&(A+=String.fromCharCode(n)),64!==s&&(A+=String.fromCharCode(r))}while(l<e.length);return A};function $(e){if(G(e))return function(e){try{for(var t=J(e),n=new Uint8Array(t.length),r=0;r<t.length;++r)n[r]=t.charCodeAt(r);return n}catch(i){throw new Error("Converting base64 string to bytes failed.")}}(e.slice(z.length))}var X=function(e,t,n){var r=new e.Int8Array(n),i=new e.Int32Array(n);new e.Uint8Array(n),new e.Float32Array(n);var a=new e.Float64Array(n),s=0|t.o,o=0|t.p,A=e.Math.floor,l=e.Math.abs,c=e.Math.sqrt,u=e.Math.cos,f=e.Math.sin,d=e.Math.tan,h=e.Math.acos,p=e.Math.asin,m=e.Math.atan,g=e.Math.atan2,b=e.Math.ceil,v=e.Math.imul,y=e.Math.min,x=e.Math.max,_=e.Math.clz32,w=t.a,T=t.b,S=t.c,M=t.d,E=t.e,C=t.f,I=t.g,R=t.h,P=t.i,N=28416;function k(e,t,n,r){return 0|L(e|=0,t|=0,n|=0,r|=0,0)}function L(e,t,n,r,a){var s,o=0,A=0,l=0,c=0;if(s=N,N=N+16|0,A=s,!(0|B(e|=0,t|=0,n|=0,r|=0,a|=0)))return N=s,0|(r=0);do{if((0|n)>=0){if((0|n)>13780509){if(0|(o=0|We(15,A)))break;A=0|i[(l=A)>>2],l=0|i[l+4>>2]}else c=0|Ot(0|n,0|(o=((0|n)<0)<<31>>31),3,0),l=0|S(),o=0|Pt(0|n,0|o,1,0),o=0|Pt(0|(o=0|Ot(0|c,0|l,0|o,0|S())),0|S(),1,0),l=0|S(),i[A>>2]=o,i[A+4>>2]=l,A=o;if(Wt(0|r,0,A<<3),0|a){Wt(0|a,0,A<<2),o=0|O(e,t,n,r,a,A,l,0);break}(o=0|Ct(A,4))?(c=0|O(e,t,n,r,o,A,l,0),Et(o),o=c):o=13}else o=2}while(0);return N=s,0|(c=o)}function B(e,t,n,r,a){e|=0,t|=0,n|=0,r|=0,a|=0;var s,o,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0;if(o=N,N=N+16|0,m=o+8|0,i[(p=s=o)>>2]=e,i[p+4>>2]=t,(0|n)<0)return N=o,0|(m=2);if(i[(A=r)>>2]=e,i[A+4>>2]=t,(A=!!(0|a))&&(i[a>>2]=0),0|Se(e,t))return N=o,0|(m=9);i[m>>2]=0;e:do{if((0|n)>=1)if(A)for(d=1,f=0,h=0,p=1,A=e;;){if(!(f|h)){if(0|(A=0|F(A,t,4,m,s)))break e;if(0|Se(A=0|i[(t=s)>>2],t=0|i[t+4>>2])){A=9;break e}}if(0|(A=0|F(A,t,0|i[26864+(h<<2)>>2],m,s)))break e;if(A=0|i[(t=s)>>2],t=0|i[t+4>>2],i[(e=r+(d<<3)|0)>>2]=A,i[e+4>>2]=t,i[a+(d<<2)>>2]=p,l=(0|(e=f+1|0))==(0|p),u=6==(0|(c=h+1|0)),0|Se(A,t)){A=9;break e}if((0|(p=p+(u&l&1)|0))>(0|n)){A=0;break}d=d+1|0,f=l?0:e,h=l?u?0:c:h}else for(d=1,f=0,h=0,p=1,A=e;;){if(!(f|h)){if(0|(A=0|F(A,t,4,m,s)))break e;if(0|Se(A=0|i[(t=s)>>2],t=0|i[t+4>>2])){A=9;break e}}if(0|(A=0|F(A,t,0|i[26864+(h<<2)>>2],m,s)))break e;if(A=0|i[(t=s)>>2],t=0|i[t+4>>2],i[(e=r+(d<<3)|0)>>2]=A,i[e+4>>2]=t,l=(0|(e=f+1|0))==(0|p),u=6==(0|(c=h+1|0)),0|Se(A,t)){A=9;break e}if((0|(p=p+(u&l&1)|0))>(0|n)){A=0;break}d=d+1|0,f=l?0:e,h=l?u?0:c:h}else A=0}while(0);return N=o,0|(m=A)}function O(e,t,n,r,a,s,o,A){n|=0,r|=0,a|=0,A|=0;var l,c,u,f=0,d=0,h=0,p=0,m=0,g=0,b=0;if(u=N,N=N+16|0,l=u+8|0,c=u,f=0|Dt(0|(e|=0),0|(t|=0),0|(s|=0),0|(o|=0)),h=0|S(),!(!(0|(b=0|i[(g=p=r+(f<<3)|0)>>2]))&!(0|(g=0|i[g+4>>2]))|(d=(0|b)==(0|e)&(0|g)==(0|t))))do{f=0|Ft(0|(f=0|Pt(0|f,0|h,1,0)),0|S(),0|s,0|o),h=0|S(),d=(0|(g=0|i[(b=p=r+(f<<3)|0)>>2]))==(0|e)&(0|(b=0|i[b+4>>2]))==(0|t)}while(!(!(0|g)&!(0|b)|d));if(f=a+(f<<2)|0,d&&(0|i[f>>2])<=(0|A))return N=u,0|(b=0);if(i[(b=p)>>2]=e,i[b+4>>2]=t,i[f>>2]=A,(0|A)>=(0|n))return N=u,0|(b=0);switch(d=A+1|0,i[l>>2]=0,0|(f=0|F(e,t,2,l,c))){case 9:m=9;break;case 0:(f=0|O(0|i[(f=c)>>2],0|i[f+4>>2],n,r,a,s,o,d))||(m=9)}e:do{if(9==(0|m)){switch(i[l>>2]=0,0|(f=0|F(e,t,3,l,c))){case 9:break;case 0:if(0|(f=0|O(0|i[(f=c)>>2],0|i[f+4>>2],n,r,a,s,o,d)))break e;break;default:break e}switch(i[l>>2]=0,0|(f=0|F(e,t,1,l,c))){case 9:break;case 0:if(0|(f=0|O(0|i[(f=c)>>2],0|i[f+4>>2],n,r,a,s,o,d)))break e;break;default:break e}switch(i[l>>2]=0,0|(f=0|F(e,t,5,l,c))){case 9:break;case 0:if(0|(f=0|O(0|i[(f=c)>>2],0|i[f+4>>2],n,r,a,s,o,d)))break e;break;default:break e}switch(i[l>>2]=0,0|(f=0|F(e,t,4,l,c))){case 9:break;case 0:if(0|(f=0|O(0|i[(f=c)>>2],0|i[f+4>>2],n,r,a,s,o,d)))break e;break;default:break e}switch(i[l>>2]=0,0|(f=0|F(e,t,6,l,c))){case 9:break;case 0:if(0|(f=0|O(0|i[(f=c)>>2],0|i[f+4>>2],n,r,a,s,o,d)))break e;break;default:break e}return N=u,0|(b=0)}}while(0);return N=u,0|(b=f)}function F(e,t,n,r,a){e|=0,t|=0,a|=0;var s,o,A,l=0,c=0,u=0,f=0,d=0,h=0;if((n|=0)>>>0>6)return 0|(a=1);c=(0|i[(r|=0)>>2])%6|0,i[r>>2]=c;e:do{if((0|c)>0)for(l=0;;){switch(0|n){case 1:n=5;break;case 5:n=4;break;case 4:n=6;break;case 6:n=2;break;case 2:n=3;break;case 3:n=1}if((0|(l=l+1|0))==(0|c))break e}}while(0);if(A=0|Vt(0|e,0|t,45),S(),(o=127&A)>>>0>121)return 0|(a=5);s=0|Ce(e,t),l=0|Vt(0|e,0|t,52),S(),l&=15;e:do{if(l){for(;;){if(u=0|Vt(0|e,0|t,0|(c=3*(15-l|0)|0)),S(),7==(0|(u&=7))){t=5;break}if(h=!(0|Le(l)),l=l+-1|0,d=0|jt(7,0,0|c),t&=~S(),e=0|jt(0|i[(h?432:16)+(28*u|0)+(n<<2)>>2],0,0|c)|e&~d,t|=c=0|S(),!(n=0|i[(h?640:224)+(28*u|0)+(n<<2)>>2])){n=0;break e}if(!l){f=15;break e}}return 0|t}f=15}while(0);15==(0|f)&&(e|=0|jt(0|(h=0|i[848+(28*o|0)+(n<<2)>>2]),0,45),t=S()|-1040385&t,n=0|i[4272+(28*o|0)+(n<<2)>>2],127&~h||(h=0|jt(0|i[848+(28*o|0)+20>>2],0,45),t=S()|-1040385&t,n=0|i[4272+(28*o|0)+20>>2],e=0|Re(h|e,t),t=0|S(),i[r>>2]=1+(0|i[r>>2]))),u=0|Vt(0|e,0|t,45),S(),u&=127;e:do{if(0|G(u)){t:do{if(1==(0|Ce(e,t))){if((0|o)!=(0|u)){if(0|K(u,0|i[7696+(28*o|0)>>2])){e=0|Ne(e,t),c=1,t=0|S();break}M(27634,26928,533,26936)}switch(0|s){case 3:e=0|Re(e,t),t=0|S(),i[r>>2]=1+(0|i[r>>2]),c=0;break t;case 5:e=0|Ne(e,t),t=0|S(),i[r>>2]=5+(0|i[r>>2]),c=0;break t;case 0:return 0|(h=9);default:return 0|(h=1)}}else c=0}while(0);if((0|n)>0){l=0;do{e=0|Ie(e,t),t=0|S(),l=l+1|0}while((0|l)!=(0|n))}if((0|o)!=(0|u)){if(!(0|H(u))){if(!!(0|c)|5!=(0|Ce(e,t)))break;i[r>>2]=1+(0|i[r>>2]);break}switch(127&A){case 8:case 118:break e}3!=(0|Ce(e,t))&&(i[r>>2]=1+(0|i[r>>2]))}}else if((0|n)>0){l=0;do{e=0|Re(e,t),t=0|S(),l=l+1|0}while((0|l)!=(0|n))}}while(0);return i[r>>2]=((0|i[r>>2])+n|0)%6|0,i[(h=a)>>2]=e,i[h+4>>2]=t,0|(h=0)}function D(e,t,n,r){e|=0,t|=0,n|=0,r|=0;var a,s,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0;if(s=N,N=N+16|0,p=s+8|0,i[(h=a=s)>>2]=e,i[h+4>>2]=t,(0|n)<0)return N=s,0|(p=2);if(!n)return i[(p=r)>>2]=e,i[p+4>>2]=t,N=s,0|(p=0);i[p>>2]=0;e:do{if(0|Se(e,t))e=9;else{o=0,h=e;do{if(0|(e=0|F(h,t,4,p,a)))break e;if(o=o+1|0,0|Se(h=0|i[(t=a)>>2],t=0|i[t+4>>2])){e=9;break e}}while((0|o)<(0|n));i[(d=r)>>2]=h,i[d+4>>2]=t,d=n+-1|0,f=0,e=1;do{if(o=26864+(f<<2)|0,5==(0|f))for(l=0|i[o>>2],A=0,o=e;;){if(0|(e=0|F(0|i[(e=a)>>2],0|i[e+4>>2],l,p,a)))break e;if((0|A)!=(0|d)){if(c=0|i[(u=a)>>2],u=0|i[u+4>>2],i[(e=r+(o<<3)|0)>>2]=c,i[e+4>>2]=u,0|Se(c,u)){e=9;break e}e=o+1|0}else e=o;if((0|(A=A+1|0))>=(0|n))break;o=e}else for(l=a,u=0|i[o>>2],c=0,o=e,A=0|i[l>>2],l=0|i[l+4>>2];;){if(0|(e=0|F(A,l,u,p,a)))break e;if(A=0|i[(l=a)>>2],l=0|i[l+4>>2],i[(e=r+(o<<3)|0)>>2]=A,i[e+4>>2]=l,e=o+1|0,0|Se(A,l)){e=9;break e}if((0|(c=c+1|0))>=(0|n))break;o=e}f=f+1|0}while(f>>>0<6);e=(0|h)==(0|i[(e=a)>>2])&&(0|t)==(0|i[e+4>>2])?0:9}}while(0);return N=s,0|(p=e)}function U(e,t,n,r){e|=0,t|=0,r|=0;var a,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0;if(a=N,N=N+16|0,A=a,!(n|=0))return i[r>>2]=e,i[r+4>>2]=t,N=a,0|(r=0);do{if((0|n)>=0){if((0|n)>13780509){if(0|(s=0|We(15,A)))break;s=0|i[(o=A)>>2],o=0|i[o+4>>2]}else f=0|Ot(0|n,0|(s=((0|n)<0)<<31>>31),3,0),o=0|S(),s=0|Pt(0|n,0|s,1,0),s=0|Pt(0|(s=0|Ot(0|f,0|o,0|s,0|S())),0|S(),1,0),o=0|S(),i[(f=A)>>2]=s,i[f+4>>2]=o;if(u=0|Ct(s,8)){if(!(f=0|Ct(s,4))){Et(u),s=13;break}if(0|(s=0|O(e,t,n,u,f,s,o,0))){Et(u),Et(f);break}if(t=0|i[A>>2],(0|(A=0|i[A+4>>2]))>0|!(0|A)&t>>>0>0){s=0,l=0,c=0;do{!(0|(o=0|i[(e=u+(l<<3)|0)>>2]))&!(0|(e=0|i[e+4>>2]))||(0|i[f+(l<<2)>>2])!=(0|n)||(i[(d=r+(s<<3)|0)>>2]=o,i[d+4>>2]=e,s=s+1|0),l=0|Pt(0|l,0|c,1,0),c=0|S()}while((0|c)<(0|A)|(0|c)==(0|A)&l>>>0<t>>>0)}Et(u),Et(f),s=0}else s=13}else s=2}while(0);return N=a,0|(d=s)}function V(e,t,n,r){n|=0,r|=0;var a,s,o,A=0,l=0;for(o=N,N=N+16|0,a=o,s=o+8|0,A=(A=!(0|Se(e|=0,t|=0)))?1:2;;){if(i[s>>2]=0,!(0|F(e,t,A,s,a))&((0|i[(l=a)>>2])==(0|n)?(0|i[l+4>>2])==(0|r):0)){e=4;break}if((A=A+1|0)>>>0>=7){A=7,e=4;break}}return 4==(0|e)?(N=o,0|A):0}function j(e,t,n,r,s,o,A){t|=0,n|=0,r|=0,s|=0,o|=0,A|=0;var l,c,u,f,d,h,p,m,g,b,v=0,y=0,x=0,_=0,w=0,T=0,M=0,E=0,C=0,I=0,R=0,P=0,k=0,L=0,B=0,O=0,F=0,D=0,U=0;if(b=N,N=N+64|0,p=b+48|0,m=b+32|0,g=b+24|0,l=b+8|0,c=b,(0|(y=0|i[(e|=0)>>2]))<=0)return N=b,0|(B=0);for(u=e+4|0,f=p+8|0,d=m+8|0,h=l+8|0,v=0,k=0;;){P=(x=0|i[u>>2])+(k<<4)|0,i[p>>2]=i[P>>2],i[p+4>>2]=i[P+4>>2],i[p+8>>2]=i[P+8>>2],i[p+12>>2]=i[P+12>>2],(0|k)==(y+-1|0)?(i[m>>2]=i[x>>2],i[m+4>>2]=i[x+4>>2],i[m+8>>2]=i[x+8>>2],i[m+12>>2]=i[x+12>>2]):(P=x+(k+1<<4)|0,i[m>>2]=i[P>>2],i[m+4>>2]=i[P+4>>2],i[m+8>>2]=i[P+8>>2],i[m+12>>2]=i[P+12>>2]),y=0|re(p,m,r,g);e:do{if(y)x=0,v=y;else if(x=0|i[(y=g)>>2],(0|(y=0|i[y+4>>2]))>0|!(0|y)&x>>>0>0){R=0,P=0;t:for(;;){if(F=1/(+(x>>>0)+4294967296*+(0|y)),U=+a[p>>3],D=+((y=0|Nt(0|x,0|y,0|R,0|P))>>>0)+4294967296*+(0|S()),O=+(R>>>0)+4294967296*+(0|P),a[l>>3]=F*(U*D)+F*(+a[m>>3]*O),a[h>>3]=F*(+a[f>>3]*D)+F*(+a[d>>3]*O),0|(y=0|Be(l,r,c))){v=y;break}T=0|Dt(0|(C=0|i[(I=c)>>2]),0|(I=0|i[I+4>>2]),0|t,0|n),_=0|S(),x=0|i[(w=y=A+(T<<3)|0)>>2],w=0|i[w+4>>2];n:do{if(!(0|x)&!(0|w))L=y,B=16;else for(M=0,E=0;;){if((0|M)>(0|n)|(0|M)==(0|n)&E>>>0>t>>>0){v=1;break t}if((0|x)==(0|C)&(0|w)==(0|I))break n;if(T=0|Ft(0|(y=0|Pt(0|T,0|_,1,0)),0|S(),0|t,0|n),_=0|S(),E=0|Pt(0|E,0|M,1,0),M=0|S(),!(0|(x=0|i[(w=y=A+(T<<3)|0)>>2]))&!(0|(w=0|i[w+4>>2]))){L=y,B=16;break}}}while(0);if(16!=(0|B)||(B=0,!(0|C)&!(0|I))||(i[(E=L)>>2]=C,i[E+4>>2]=I,E=o+(i[s>>2]<<3)|0,i[E>>2]=C,i[E+4>>2]=I,E=0|Pt(0|i[(E=s)>>2],0|i[E+4>>2],1,0),C=0|S(),i[(I=s)>>2]=E,i[I+4>>2]=C),R=0|Pt(0|R,0|P,1,0),P=0|S(),x=0|i[(y=g)>>2],!((0|(y=0|i[y+4>>2]))>(0|P)|(0|y)==(0|P)&x>>>0>R>>>0)){x=1;break e}}x=0}else x=1}while(0);if(k=k+1|0,!x){B=21;break}if((0|k)>=(0|(y=0|i[e>>2]))){v=0,B=21;break}}return 21==(0|B)?(N=b,0|v):0}function z(e,t){t|=0;var n,r=0,s=0,o=0,A=0,l=0,c=0,d=0,h=0,p=0;if((0|(A=0|i[(e|=0)>>2]))<=0)return s=(o=0)+(s=12.566370614359172-(s=0)),o=(A=o<0)?s:o,a[t>>3]=o,0;if(n=0|i[e+4>>2],e=1!=(0|A)&1,l=.5*+a[n>>3]+.7853981633974483,o=.5*+a[n+(e<<4)>>3]+.7853981633974483,r=+f(+l)*+f(+o),s=+a[n+(e<<4)+8>>3]-+a[n+8>>3],r=(s=(r=-2*+g(+ +f(+s)*r,+(+u(+l)*+u(+o)+ +u(+s)*r)))+0)-r,1==(0|A))return o=(l=s)+(o=12.566370614359172-(o=r)),l=(A=l<0)?o:l,a[t>>3]=l,0;for(e=1,o=s;h=e,p=(0|(e=e+1|0))%(0|A)|0,d=.5*+a[n+(h<<4)>>3]+.7853981633974483,c=.5*+a[n+(p<<4)>>3]+.7853981633974483,s=+f(+d)*+f(+c),l=+a[n+(p<<4)+8>>3]-+a[n+(h<<4)+8>>3],r=(s=o+(r=-2*+g(+ +f(+l)*s,+(+u(+d)*+u(+c)+ +u(+l)*s))-r))-o-r,!((0|e)>=(0|A));)o=s;return d=s+(d=12.566370614359172-r),d=(p=s<0)?d:s,a[t>>3]=d,0}function G(e){return(e|=0)>>>0>121?0|(e=0):0|(e=0|i[7696+(28*e|0)+16>>2])}function H(e){return 4==(0|(e|=0))|117==(0|e)|0}function q(e){return 0|i[11120+(216*(0|i[(e|=0)>>2])|0)+(72*(0|i[e+4>>2])|0)+(24*(0|i[e+8>>2])|0)+(i[e+12>>2]<<3)>>2]}function Q(e){return 0|i[11120+(216*(0|i[(e|=0)>>2])|0)+(72*(0|i[e+4>>2])|0)+(24*(0|i[e+8>>2])|0)+(i[e+12>>2]<<3)+4>>2]}function K(e,t){return t|=0,(0|i[7696+(28*(e|=0)|0)+20>>2])==(0|t)?0|(t=1):0|(t=(0|i[7696+(28*e|0)+24>>2])==(0|t))}function W(e,t){return 0|i[848+(28*(e|=0)|0)+((t|=0)<<2)>>2]}function J(e,t){return t|=0,(0|i[848+(28*(e|=0)|0)>>2])==(0|t)?0|(t=0):(0|i[848+(28*e|0)+4>>2])==(0|t)?0|(t=1):(0|i[848+(28*e|0)+8>>2])==(0|t)?0|(t=2):(0|i[848+(28*e|0)+12>>2])==(0|t)?0|(t=3):(0|i[848+(28*e|0)+16>>2])==(0|t)?0|(t=4):(0|i[848+(28*e|0)+20>>2])==(0|t)?0|(t=5):0|((0|i[848+(28*e|0)+24>>2])==(0|t)?6:7)}function $(e){var t,n,r;return t=(r=+a[(e|=0)+16>>3])-(n=+a[e+24>>3]),+(r<n?t+6.283185307179586:t)}function X(e){return+(+a[(e|=0)>>3]-+a[e+8>>3])}function Y(e,t){e|=0;var n,r,i=0;return(i=+a[(t|=0)>>3])>=+a[e+8>>3]&&i<=+a[e>>3]?(n=+a[e+16>>3],i=+a[e+24>>3],t=(r=+a[t+8>>3])>=i,e=r<=n&1,n<i?t&&(e=1):t||(e=0),0|(t=!!(0|e))):0|(t=0)}function Z(e,t){t|=0;var n,r,i,s,o,A=0,l=0,c=0,u=0;return+a[(e|=0)>>3]<+a[t+8>>3]||+a[e+8>>3]>+a[t>>3]?0|(A=0):(i=(l=+a[e+16>>3])<(u=+a[(n=e+24|0)>>3]),c=(o=+a[(A=t+16|0)>>3])<(s=+a[(r=t+24|0)>>3]),t=u-o<s-l,e=i?c|t?1:2:0,t=c?i?1:t?2:1:0,(l=+qe(l,e))<+qe(+a[r>>3],t)||(u=+qe(+a[n>>3],e))>+qe(+a[A>>3],t)?0|(c=0):0|(c=1))}function ee(e,t){t|=0;var n,r,i,s,o,A=0,l=0,c=0,u=0;return+a[(e|=0)>>3]<+a[t>>3]||+a[e+8>>3]>+a[t+8>>3]?0|(A=0):(i=(s=+a[(A=e+16|0)>>3])<(l=+a[e+24>>3]),c=(u=+a[(n=t+16|0)>>3])<(o=+a[(r=t+24|0)>>3]),t=l-u<o-s,e=i?c|t?1:2:0,t=c?i?1:t?2:1:0,(l=+qe(l,e))<=+qe(+a[r>>3],t)?0|(c=(u=+qe(+a[A>>3],e))>=+qe(+a[n>>3],t)):0|(c=0))}function te(e,t){e|=0,t|=0;var n,r,s,o,A,l=0;s=N,N=N+176|0,i[(r=s)>>2]=4,l=+a[t>>3],a[r+8>>3]=l,o=+a[t+16>>3],a[r+16>>3]=o,a[r+24>>3]=l,l=+a[t+24>>3],a[r+32>>3]=l,A=+a[t+8>>3],a[r+40>>3]=A,a[r+48>>3]=l,a[r+56>>3]=A,a[r+64>>3]=o,n=(t=r+72|0)+96|0;do{i[t>>2]=0,t=t+4|0}while((0|t)<(0|n));Qt(0|e,0|r,168),N=s}function ne(e,t,n){e|=0,t|=0,n|=0;var r,o,c,u,f,d,h,p=0,m=0,g=0,v=0,x=0,_=0,w=0;d=N,N=N+288|0,f=d+264|0,v=d+96|0,m=(p=g=d)+96|0;do{i[p>>2]=0,p=p+4|0}while((0|p)<(0|m));return 0|(t=0|Ve(t,g))?(N=d,0|(_=t)):(De(g=0|i[(m=g)>>2],m=0|i[m+4>>2],f),Ue(g,m,v),u=+Qe(f,v+8|0),a[f>>3]=+a[e>>3],a[(m=f+8|0)>>3]=+a[e+16>>3],a[v>>3]=+a[e+8>>3],a[(g=v+8|0)>>3]=+a[e+24>>3],o=+Qe(f,v),w=+a[m>>3]-+a[g>>3],c=+l(+w),h=+a[f>>3]-+a[v>>3],r=+l(+h),!(0==w|0==h)&&(w=+Gt(+c,+r),w=+b(+o*o/+Ht(+w/+Ht(+c,+r),3)/(u*(2.59807621135*u)*.8)),a[s>>3]=w,x=~~w>>>0,_=+l(w)>=1?w>0?~~+y(+A(w/4294967296),4294967295)>>>0:~~+b((w-+(~~w>>>0))/4294967296)>>>0:0,2146435072&~i[s+4>>2])?(v=!(0|x)&!(0|_),i[(t=n)>>2]=v?1:x,i[t+4>>2]=v?0:_,t=0):t=1,N=d,0|(_=t))}function re(e,t,n,r){e|=0,t|=0,n|=0,r|=0;var o,c,u,f,d=0,h=0,p=0;f=N,N=N+288|0,c=f+264|0,u=f+96|0,o=(d=h=f)+96|0;do{i[d>>2]=0,d=d+4|0}while((0|d)<(0|o));return 0|(n=0|Ve(n,h))?(N=f,0|(r=n)):(De(d=0|i[(n=h)>>2],n=0|i[n+4>>2],c),Ue(d,n,u),p=+Qe(c,u+8|0),p=+b(+ +Qe(e,t)/(2*p)),a[s>>3]=p,n=~~p>>>0,d=+l(p)>=1?p>0?~~+y(+A(p/4294967296),4294967295)>>>0:~~+b((p-+(~~p>>>0))/4294967296)>>>0:0,2146435072&~i[s+4>>2]?(h=!(0|n)&!(0|d),i[r>>2]=h?1:n,i[r+4>>2]=h?0:d,N=f,0|(r=0)):(N=f,0|(r=1)))}function ie(e,t,n,s){e|=0,s|=0;var o,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0,w=0,T=0,E=0,C=0,I=0,R=0,P=0,k=0,L=0,B=0;if(o=N,N=N+224|0,P=o,E=o+48|0,(f=(0|(n|=0))>0|!(0|n)&(t|=0)>>>0>0)&(n>>>0>0|!(0|n)&t>>>0>17895697))return N=o,0|(B=14);if((0|n)<0)return N=o,0|(B=2);if(!(0|t)&!(0|n))return i[s>>2]=0,i[s+4>>2]=0,N=o,0|(B=0);for(A=0|ve(0|i[(A=e)>>2],0|i[A+4>>2]),c=0,u=0;;){if(!(0|xe(0|i[(B=l=e+(c<<3)|0)>>2],0|i[B+4>>2]))){A=5,k=159;break}if(B=(0|ve(0|i[(B=l)>>2],0|i[B+4>>2]))==(0|A),c=0|Pt(0|c,0|u,1,0),u=0|S(),!B){A=12,k=159;break}if(!((0|u)<(0|n)|(0|u)==(0|n)&c>>>0<t>>>0)){k=8;break}}if(8==(0|k)){do{if((0|n)>0|!(0|n)&t>>>0>1){if(!(c=0|Mt(A=t<<3)))return N=o,0|(B=13);for(Qt(0|c,0|e,0|A),gt(c,t,8,1),A=1,l=0;B=c+(A+-1<<3)|0,B=(0|i[(L=c+(A<<3)|0)>>2])==(0|i[B>>2])?(0|i[L+4>>2])==(0|i[B+4>>2]):0,A=0|Pt(0|A,0|l,1,0),l=0|S(),!B;)if(!((0|l)<(0|n)|(0|l)==(0|n)&A>>>0<t>>>0)){k=14;break}if(14==(0|k)){Et(c);break}return Et(c),N=o,0|(B=10)}}while(0);if(A=0|Ot(0|t,0|n,6,0),l=0|S(),f){c=0,u=0;do{A=0|Pt(0|A,0|l,0|(B=!!(0|Se(0|i[(B=e+(u<<3)|0)>>2],0|i[B+4>>2]))<<31>>31),((0|B)<0)<<31>>31),l=0|S(),u=0|Pt(0|u,0|c,1,0),c=0|S()}while((0|c)<(0|n)|(0|c)==(0|n)&u>>>0<t>>>0);T=A,w=l}else T=A,w=l;if(x=0|Ot(0|T,0|w,10,0),_=0|S(),!(L=0|Mt(T<<5)))return N=o,0|(B=13);if(!(B=0|Ct(x,4)))return Et(L),N=o,0|(B=13);e:do{if(f){for(oe(0|i[(R=e)>>2],0|i[R+4>>2],P),g=L,b=0,v=0,A=0,y=0;;){l=(f=!(0|i[(f=P)>>2])&!(0|i[f+4>>2]))?26990:26995,c=f?5:6,f=P+((1&f)<<3)|0,d=0|Pt(0|c,0|(u=0),-1,-1),h=0|S(),p=0,m=0;do{C=0|i[(I=f+(p<<3)|0)+4>>2],i[(R=g+(p<<5)|0)>>2]=i[I>>2],i[R+4>>2]=C,r[g+(p<<5)+9|0]=0,r[g+(p<<5)+8|0]=0,i[g+(p<<5)+20>>2]=g,i[(R=g+(p<<5)+24|0)>>2]=1,i[R+4>>2]=0,R=0|r[l+p|0],C=0|Dt(0|(C=0|Pt(0|d,0|h,0|p,0|m)),0|S(),0|c,0|u),S(),C=0|r[l+C|0],p=0|Pt(0|p,0|m,1,0),m=0|S(),I=0|r[l+((0|p)==(0|c)&(0|m)==(0|u)?0:p)|0],i[g+((R&=255)<<5)+16>>2]=g+((255&C)<<5),i[g+(R<<5)+12>>2]=g+((255&I)<<5)}while(m>>>0<u>>>0|(0|m)==(0|u)&p>>>0<c>>>0);if(b=0|Pt(0|b,0|v,1,0),v=0|S(),A=0|Pt(0|c,0|u,0|A,0|y),y=0|S(),!((0|v)<(0|n)|(0|v)==(0|n)&b>>>0<t>>>0))break e;0|oe(0|i[(R=e+(b<<3)|0)>>2],0|i[R+4>>2],P)||(g=L+(A<<5)|0)}M(27634,26956,108,26975)}}while(0);if((0|w)>0|!(0|w)&T>>>0>0){u=0,f=0;do{if(A=0|Vt(0|(c=0|i[(l=L+(u<<5)|0)>>2]),0|(l=0|i[l+4>>2]),30),A=0|Vt(0|(l=0|Ot(A^c|0,(0|S())^l,484763065,-1084733587)),0|(c=0|S()),27),l=0|Dt((A=0|Vt(0|(c=0|Ot(A^l|0,(0|S())^c,321982955,-1798288965)),0|(l=0|S()),31))^c|0,(0|S())^l,0|x,0|_),c=0|S(),0|i[(A=B+(l<<2)|0)>>2])do{l=0|Ft(0|(A=0|Pt(0|l,0|c,1,0)),0|S(),0|x,0|_),c=0|S(),A=B+(l<<2)|0}while(0|i[A>>2]);i[A>>2]=L+(u<<5),u=0|Pt(0|u,0|f,1,0),f=0|S()}while((0|f)<(0|w)|(0|f)==(0|w)&u>>>0<T>>>0);p=0,m=0;do{if(u=L+(p<<5)|0,!(0|r[(f=L+(p<<5)+9|0)|0])){if(0|le(0|i[(R=u)>>2],0|i[R+4>>2],P)){k=39;break}l=0|Vt(0|(d=0|i[(h=P)>>2]),0|(h=0|i[h+4>>2]),30),A=0|Vt(0|(l=0|Ot(l^d|0,(0|S())^h,484763065,-1084733587)),0|(c=0|S()),27),l=0|Dt((A=0|Vt(0|(c=0|Ot(A^l|0,(0|S())^c,321982955,-1798288965)),0|(l=0|S()),31))^c|0,(0|S())^l,0|x,0|_),c=0|S(),A=0|i[B+(l<<2)>>2];e:do{if(0|A){for(;(0|i[(R=A)>>2])!=(0|d)||(0|i[R+4>>2])!=(0|h);)if(l=0|Ft(0|(A=0|Pt(0|l,0|c,1,0)),0|S(),0|x,0|_),c=0|S(),!(A=0|i[B+(l<<2)>>2]))break e;r[f|0]=1,r[A+9|0]=1,l=A+16|0,i[16+(0|i[(R=L+(p<<5)+12|0)>>2])>>2]=i[l>>2],n=A+12|0,I=0|i[L+(p<<5)+16>>2],i[I+12>>2]=i[n>>2],i[16+(0|i[n>>2])>>2]=I,i[12+(0|i[l>>2])>>2]=i[R>>2],l=0|ae(u),R=0|ae(A),A=(I=(0|(n=0|i[(A=l+24|0)+4>>2]))<(0|(C=0|i[(I=R+24|0)+4>>2]))|((0|n)==(0|C)?(0|i[A>>2])>>>0<(0|i[I>>2])>>>0:0))?l:R,(0|(l=I?R:l))!=(0|A)&&(C=A+24|0,C=0|Pt(0|i[(I=R=l+24|0)>>2],0|i[I+4>>2],0|i[C>>2],0|i[C+4>>2]),I=0|S(),i[R>>2]=C,i[R+4>>2]=I,i[A+20>>2]=l)}}while(0)}p=0|Pt(0|p,0|m,1,0),m=0|S()}while((0|m)<(0|w)|(0|m)==(0|w)&p>>>0<T>>>0);39==(0|k)&&M(27634,26956,258,27001),A=0,l=0;do{r[L+(A<<5)+8|0]=0,A=0|Pt(0|A,0|l,1,0),l=0|S()}while((0|l)<(0|w)|(0|l)==(0|w)&A>>>0<T>>>0);for(d=0,c=0,f=0,h=0;;){if(A=L+(d<<5)|0,0|r[L+(d<<5)+8|0]||0|r[L+(d<<5)+9|0])u=f;else{l=0|i[(u=A)>>2],u=0|i[u+4>>2];do{r[A+8|0]=1,R=A=0|i[A+12>>2]}while((0|i[R>>2])!=(0|l)||(0|i[R+4>>2])!=(0|u));c=0|Pt(0|c,0|f,1,0),u=0|S()}if(d=0|Pt(0|d,0|h,1,0),!((0|(h=0|S()))<(0|w)|(0|h)==(0|w)&d>>>0<T>>>0))break;f=u}A=0,l=0;do{r[L+(A<<5)+8|0]=0,A=0|Pt(0|A,0|l,1,0),l=0|S()}while((0|l)<(0|w)|(0|l)==(0|w)&A>>>0<T>>>0);I=c,C=u,A=1}else I=0,C=0,A=0;R=0|Mt(24*I|0);e:do{if(0|R){t:do{if(A){e=0,x=0,n=0,t=0;n:for(;;){if(A=L+(e<<5)|0,0|r[L+(e<<5)+8|0]||0|r[L+(e<<5)+9|0])l=n,A=x;else{v=0|i[(y=A)>>2],y=0|i[y+4>>2],l=0,c=0;do{l=0|Pt(0|l,0|c,2,0),c=0|S(),_=A=0|i[A+12>>2]}while((0|i[_>>2])!=(0|v)||(0|i[_+4>>2])!=(0|y));if(!(b=0|Mt(l<<4)))break;l=v,c=y,g=0,m=0,u=0,f=0;do{if(0|Ae(l,c,E)){k=69;break n}if(p=((0|(h=(_=0|i[E>>2])+-1|0))<0)<<31>>31,(0|_)>1){c=u,d=0,l=f,u=0;do{f=E+8+(d<<4)|0,i[(_=b+(c<<4)|0)>>2]=i[f>>2],i[_+4>>2]=i[f+4>>2],i[_+8>>2]=i[f+8>>2],i[_+12>>2]=i[f+12>>2],c=0|Pt(0|c,0|l,1,0),l=0|S(),d=0|Pt(0|d,0|u,1,0),u=0|S()}while((0|u)<(0|p)|(0|u)==(0|p)&d>>>0<h>>>0);u=c,f=l}g=0|Pt(0|g,0|m,0|h,0|p),m=0|S(),r[A+8|0]=1,A=0|i[A+12>>2],l=0|i[(c=A)>>2],c=0|i[c+4>>2]}while(!((0|l)==(0|v)&(0|c)==(0|y)));if(!(l=0|It(b,g<<4))){k=75;break}y=0|ae(A),_=0|i[y+4>>2],i[(A=R+(24*n|0)|0)>>2]=i[y>>2],i[A+4>>2]=_,i[(A=R+(24*n|0)+16|0)>>2]=g,i[R+(24*n|0)+20>>2]=l,i[P>>2]=i[A>>2],i[P+4>>2]=i[A+4>>2],z(P,R+(24*n|0)+8|0),l=0|Pt(0|n,0|x,1,0),A=0|S()}if(e=0|Pt(0|e,0|t,1,0),!((0|(t=0|S()))<(0|w)|(0|t)==(0|w)&e>>>0<T>>>0))break t;x=A,n=l}if(69==(0|k)?M(27634,26956,351,27016):75==(0|k)&&Et(b),(0|x)>0|!(0|x)&n>>>0>0)for(u=0,f=0,A=n,c=x;(l=0|i[R+(24*u|0)+20>>2])?(Et(l),l=x,A=n):l=c,u=0|Pt(0|u,0|f,1,0),(0|(f=0|S()))<(0|l)|(0|f)==(0|l)&u>>>0<A>>>0;)c=l;Et(R);break e}}while(0);gt(R,I,24,2);t:do{if(!(0|I)&!(0|C)){if(0|(_=0|Mt(192))){if(i[_+16>>2]=0,i[_+20>>2]=0,i[(m=_+8|0)>>2]=3,A=0|Mt(48),i[(g=_+12|0)>>2]=A,0|A){i[A>>2]=i[3860],i[A+4>>2]=i[3861],i[A+8>>2]=i[3862],i[A+12>>2]=i[3863],i[(p=A+16|0)>>2]=i[3864],i[p+4>>2]=i[3865],i[p+8>>2]=i[3866],i[p+12>>2]=i[3867],i[(p=A+32|0)>>2]=i[3868],i[p+4>>2]=i[3869],i[p+8>>2]=i[3870],i[p+12>>2]=i[3871],i[P>>2]=i[m>>2],i[P+4>>2]=i[m+4>>2],z(P,_),i[_+40>>2]=0,i[_+44>>2]=0,i[(p=_+32|0)>>2]=3,A=0|Mt(48),i[(b=_+36|0)>>2]=A;do{if(A){if(i[A>>2]=i[3872],i[A+4>>2]=i[3873],i[A+8>>2]=i[3874],i[A+12>>2]=i[3875],i[(h=A+16|0)>>2]=i[3876],i[h+4>>2]=i[3877],i[h+8>>2]=i[3878],i[h+12>>2]=i[3879],i[(h=A+32|0)>>2]=i[3880],i[h+4>>2]=i[3881],i[h+8>>2]=i[3882],i[h+12>>2]=i[3883],i[P>>2]=i[p>>2],i[P+4>>2]=i[p+4>>2],z(P,_+24|0),i[_+64>>2]=0,i[_+68>>2]=0,i[(h=_+56|0)>>2]=3,A=0|Mt(48),i[(v=_+60|0)>>2]=A,!A){u=0,f=2;break}if(i[A>>2]=i[3884],i[A+4>>2]=i[3885],i[A+8>>2]=i[3886],i[A+12>>2]=i[3887],i[(d=A+16|0)>>2]=i[3888],i[d+4>>2]=i[3889],i[d+8>>2]=i[3890],i[d+12>>2]=i[3891],i[(d=A+32|0)>>2]=i[3892],i[d+4>>2]=i[3893],i[d+8>>2]=i[3894],i[d+12>>2]=i[3895],i[P>>2]=i[h>>2],i[P+4>>2]=i[h+4>>2],z(P,_+48|0),i[_+88>>2]=0,i[_+92>>2]=0,i[(d=_+80|0)>>2]=3,A=0|Mt(48),i[(y=_+84|0)>>2]=A,!A){u=0,f=3;break}if(i[A>>2]=i[3896],i[A+4>>2]=i[3897],i[A+8>>2]=i[3898],i[A+12>>2]=i[3899],i[(f=A+16|0)>>2]=i[3900],i[f+4>>2]=i[3901],i[f+8>>2]=i[3902],i[f+12>>2]=i[3903],i[(f=A+32|0)>>2]=i[3904],i[f+4>>2]=i[3905],i[f+8>>2]=i[3906],i[f+12>>2]=i[3907],i[P>>2]=i[d>>2],i[P+4>>2]=i[d+4>>2],z(P,_+72|0),i[_+112>>2]=0,i[_+116>>2]=0,i[(f=_+104|0)>>2]=3,A=0|Mt(48),i[(e=_+108|0)>>2]=A,!A){u=0,f=4;break}if(i[A>>2]=i[3908],i[A+4>>2]=i[3909],i[A+8>>2]=i[3910],i[A+12>>2]=i[3911],i[(u=A+16|0)>>2]=i[3912],i[u+4>>2]=i[3913],i[u+8>>2]=i[3914],i[u+12>>2]=i[3915],i[(u=A+32|0)>>2]=i[3916],i[u+4>>2]=i[3917],i[u+8>>2]=i[3918],i[u+12>>2]=i[3919],i[P>>2]=i[f>>2],i[P+4>>2]=i[f+4>>2],z(P,_+96|0),i[_+136>>2]=0,i[_+140>>2]=0,i[(u=_+128|0)>>2]=3,A=0|Mt(48),i[(t=_+132|0)>>2]=A,!A){u=0,f=5;break}if(i[A>>2]=i[3920],i[A+4>>2]=i[3921],i[A+8>>2]=i[3922],i[A+12>>2]=i[3923],i[(c=A+16|0)>>2]=i[3924],i[c+4>>2]=i[3925],i[c+8>>2]=i[3926],i[c+12>>2]=i[3927],i[(c=A+32|0)>>2]=i[3928],i[c+4>>2]=i[3929],i[c+8>>2]=i[3930],i[c+12>>2]=i[3931],i[P>>2]=i[u>>2],i[P+4>>2]=i[u+4>>2],z(P,_+120|0),i[_+160>>2]=0,i[_+164>>2]=0,i[(c=_+152|0)>>2]=3,A=0|Mt(48),i[(n=_+156|0)>>2]=A,!A){u=0,f=6;break}if(i[A>>2]=i[3932],i[A+4>>2]=i[3933],i[A+8>>2]=i[3934],i[A+12>>2]=i[3935],i[(l=A+16|0)>>2]=i[3936],i[l+4>>2]=i[3937],i[l+8>>2]=i[3938],i[l+12>>2]=i[3939],i[(l=A+32|0)>>2]=i[3940],i[l+4>>2]=i[3941],i[l+8>>2]=i[3942],i[l+12>>2]=i[3943],i[P>>2]=i[c>>2],i[P+4>>2]=i[c+4>>2],z(P,_+144|0),i[_+184>>2]=0,i[_+188>>2]=0,i[(l=_+176|0)>>2]=3,A=0|Mt(48),i[(x=_+180|0)>>2]=A,!A){u=0,f=7;break}if(i[A>>2]=i[3944],i[A+4>>2]=i[3945],i[A+8>>2]=i[3946],i[A+12>>2]=i[3947],i[(E=A+16|0)>>2]=i[3948],i[E+4>>2]=i[3949],i[E+8>>2]=i[3950],i[E+12>>2]=i[3951],i[(A=A+32|0)>>2]=i[3952],i[A+4>>2]=i[3953],i[A+8>>2]=i[3954],i[A+12>>2]=i[3955],i[P>>2]=i[l>>2],i[P+4>>2]=i[l+4>>2],z(P,_+168|0),gt(_,8,24,3),A=0|Mt(128),i[s+4>>2]=A,0|A){i[s>>2]=8,i[A>>2]=i[m>>2],i[A+4>>2]=i[m+4>>2],i[A+8>>2]=i[m+8>>2],i[A+12>>2]=i[m+12>>2],i[(k=A+16|0)>>2]=i[p>>2],i[k+4>>2]=i[p+4>>2],i[k+8>>2]=i[p+8>>2],i[k+12>>2]=i[p+12>>2],i[(k=A+32|0)>>2]=i[h>>2],i[k+4>>2]=i[h+4>>2],i[k+8>>2]=i[h+8>>2],i[k+12>>2]=i[h+12>>2],i[(k=A+48|0)>>2]=i[d>>2],i[k+4>>2]=i[d+4>>2],i[k+8>>2]=i[d+8>>2],i[k+12>>2]=i[d+12>>2],i[(k=A+64|0)>>2]=i[f>>2],i[k+4>>2]=i[f+4>>2],i[k+8>>2]=i[f+8>>2],i[k+12>>2]=i[f+12>>2],i[(k=A+80|0)>>2]=i[u>>2],i[k+4>>2]=i[u+4>>2],i[k+8>>2]=i[u+8>>2],i[k+12>>2]=i[u+12>>2],i[(k=A+96|0)>>2]=i[c>>2],i[k+4>>2]=i[c+4>>2],i[k+8>>2]=i[c+8>>2],i[k+12>>2]=i[c+12>>2],i[(k=A+112|0)>>2]=i[l>>2],i[k+4>>2]=i[l+4>>2],i[k+8>>2]=i[l+8>>2],i[k+12>>2]=i[l+12>>2],Et(_),k=158;break t}0|(A=0|i[g>>2])&&Et(A),0|(A=0|i[b>>2])&&Et(A),0|(A=0|i[v>>2])&&Et(A),0|(A=0|i[y>>2])&&Et(A),0|(A=0|i[e>>2])&&Et(A),0|(A=0|i[t>>2])&&Et(A),0|(A=0|i[n>>2])&&Et(A),0|(A=0|i[x>>2])&&Et(A),Et(_);break t}u=0,f=1}while(0);A=0,c=0;do{0|(l=0|i[_+(24*A|0)+12>>2])&&Et(l),A=0|Pt(0|A,0|c,1,0),c=0|S()}while(c>>>0<u>>>0|(0|c)==(0|u)&A>>>0<f>>>0)}Et(_),k=152}}else{if((0|C)>0|!(0|C)&I>>>0>0){c=0,u=0,f=0,l=0,A=0,d=0;do{P=u,k=f,l=0|Pt(0|l,0|A,1&((0|(u=0|i[(E=R+(24*c|0)|0)>>2]))!=(0|P)|(0|(f=0|i[E+4>>2]))!=(0|k)),0),A=0|S(),c=0|Pt(0|c,0|d,1,0),d=0|S()}while((0|d)<(0|C)|(0|d)==(0|C)&c>>>0<I>>>0);y=l,v=A}else y=0,v=0;if(e=0|Mt(24*y|0)){n:do{if((0|C)>=0){for(m=0,g=0,l=0,c=0,b=0,u=0;;){if((0|m)==(0|I)&(0|g)==(0|C)||(k=R+(24*m|0)|0,(0|i[(P=R+(24*l|0)|0)>>2])!=(0|i[k>>2])||(0|i[P+4>>2])!=(0|i[k+4>>2]))){if(h=R+(24*l|0)|0,p=0|Pt(0|(k=0|Nt(0|m,0|g,0|l,0|c)),0|(P=0|S()),-1,-1),c=0|S(),(0|P)>0|!(0|P)&k>>>0>1){if(!(A=0|Mt(p<<3)))break;f=0,d=0;do{k=f,f=0|Pt(0|f,0|d,1,0),d=0|S(),P=0|i[(E=h+(24*f|0)+16|0)+4>>2],i[(k=A+(k<<3)|0)>>2]=i[E>>2],i[k+4>>2]=P}while((0|d)<(0|c)|(0|d)==(0|c)&f>>>0<p>>>0)}else A=0;k=0|i[(P=R+(24*l|0)+16|0)+4>>2],i[(c=e+(24*u|0)+8|0)>>2]=i[P>>2],i[c+4>>2]=k,i[e+(24*u|0)+16>>2]=p,i[e+(24*u|0)+20>>2]=A,a[e+(24*u|0)>>3]=+a[R+(24*l|0)+8>>3],u=0|Pt(0|u,0|b,1,0),l=m,c=g,A=0|S()}else A=b;if(k=m,m=0|Pt(0|m,0|g,1,0),P=g,g=0|S(),!((0|P)<(0|C)|(0|P)==(0|C)&k>>>0<I>>>0))break n;b=A}if((0|b)>0|!(0|b)&u>>>0>0){A=0,c=0;do{0|(l=0|i[e+(24*A|0)+20>>2])&&Et(l),A=0|Pt(0|A,0|c,1,0),c=0|S()}while((0|c)<(0|b)|(0|c)==(0|b)&A>>>0<u>>>0)}Et(e),k=152;break t}}while(0);if(gt(e,y,24,3),A=0|Mt(y<<4),i[(c=s+4|0)>>2]=A,A){i[s>>2]=y;do{if((0|v)>0|!(0|v)&y>>>0>0){if(s=e+8|0,i[A>>2]=i[s>>2],i[A+4>>2]=i[s+4>>2],i[A+8>>2]=i[s+8>>2],i[A+12>>2]=i[s+12>>2],1==(0|y)&!(0|v))break;if(k=e+32|0,i[(s=A+16|0)>>2]=i[k>>2],i[s+4>>2]=i[k+4>>2],i[s+8>>2]=i[k+8>>2],i[s+12>>2]=i[k+12>>2],!((0|v)>0|!(0|v)&y>>>0>2))break;A=2,l=0;do{s=(0|i[c>>2])+(A<<4)|0,k=e+(24*A|0)+8|0,i[s>>2]=i[k>>2],i[s+4>>2]=i[k+4>>2],i[s+8>>2]=i[k+8>>2],i[s+12>>2]=i[k+12>>2],A=0|Pt(0|A,0|l,1,0),l=0|S()}while((0|l)<(0|v)|(0|l)==(0|v)&A>>>0<y>>>0)}}while(0);Et(e),k=158;break}if((0|v)>0|!(0|v)&y>>>0>0){A=0,c=0;do{0|(l=0|i[e+(24*A|0)+20>>2])&&Et(l),A=0|Pt(0|A,0|c,1,0),c=0|S()}while((0|c)<(0|v)|(0|c)==(0|v)&A>>>0<y>>>0)}Et(e),k=152;break}k=152}}while(0);if(158==(0|k))return Et(L),Et(B),Et(R),N=o,0|(B=0);if(152==(0|k)&&(0|C)>0|!(0|C)&I>>>0>0)for(u=0,f=0,A=I,c=C;(l=0|i[R+(24*u|0)+20>>2])?(Et(l),l=C,A=I):l=c,u=0|Pt(0|u,0|f,1,0),(0|(f=0|S()))<(0|l)|(0|f)==(0|l)&u>>>0<A>>>0;)c=l;return Et(R),Et(L),Et(B),N=o,0|(B=13)}}while(0);return Et(L),Et(B),N=o,0|(B=13)}return 159==(0|k)?(N=o,0|A):0}function ae(e){var t,n=0;return(0|(n=0|i[(t=(e|=0)+20|0)>>2]))==(0|e)?0|e:(n=0|ae(n),i[t>>2]=n,0|n)}function se(e,t){var n=0;switch(n=0|Vt(0|(e|=0),0|(t|=0),56),S(),7&n){case 0:case 7:return 0|(n=0)}return n=-2130706433&t|134217728,!0&268435456==(2013265920&t)?!0&16777216==(117440512&t)&!!(0|Se(e,n))?0|(n=0):0|(n=0|xe(e,n)):0|(n=0)}function oe(e,t,n){n|=0;var r,a=0;return r=!(0|Se(e|=0,t|=0)),t&=-2130706433,i[(a=n)>>2]=r?e:0,i[a+4>>2]=r?285212672|t:0,i[(a=n+8|0)>>2]=e,i[a+4>>2]=301989888|t,i[(a=n+16|0)>>2]=e,i[a+4>>2]=318767104|t,i[(a=n+24|0)>>2]=e,i[a+4>>2]=335544320|t,i[(a=n+32|0)>>2]=e,i[a+4>>2]=352321536|t,i[(n=n+40|0)>>2]=e,i[n+4>>2]=369098752|t,0}function Ae(e,t,n){n|=0;var r,a,s=0,o=0;return a=N,N=N+16|0,r=a,o=-2130706433&(t|=0)|134217728,!0&268435456==(2013265920&t)?(s=0|Vt(0|(e|=0),0|t,56),S(),s=0|function(e,t,n){e|=0,t|=0,n|=0;var r=0,a=0,s=0;if(s=N,N=N+16|0,a=s,r=0|Se(e,t),(n+-1|0)>>>0>5)return N=s,0|(a=-1);if(r=!!(0|r),1==(0|n)&r)return N=s,0|(a=-1);do{if(!(0|ht(e,t,a))){if(r){r=(5+(0|i[26416+(n<<2)>>2])-(0|i[a>>2])|0)%5|0;break}r=(6+(0|i[26448+(n<<2)>>2])-(0|i[a>>2])|0)%6|0;break}r=-1}while(0);return a=r,N=s,0|a}(e,o,7&s),-1==(0|s)?(i[n>>2]=0,N=a,0|(o=6)):(0|Fe(e,o,r)&&M(27634,27035,282,27050),t=0|Vt(0|e,0|t,52),S(),t&=15,0|Se(e,o)?de(r,t,s,2,n):ge(r,t,s,2,n),N=a,0|(o=0))):(N=a,0|(o=6))}function le(e,t,n){e|=0,n|=0;var r,a=0,s=0,o=0;return r=N,N=N+16|0,s=r,o=-2130706433&(t|=0)|134217728,!0&268435456==(2013265920&t)?(i[(a=r+8|0)>>2]=0,t=0|Vt(0|e,0|t,56),S(),0|(t=0|F(e,o,7&t,a,s))?(N=r,0|(n=t)):7==(0|(t=0|V(a=0|i[s>>2],s=0|i[s+4>>2],e,o)))?(N=r,0|(n=11)):(e=0|jt(0|t,0,56),o=-2130706433&s|S()|268435456,i[n>>2]=a|e,i[n+4>>2]=o,N=r,0|(n=0))):(N=r,0|(n=6))}function ce(e,t,n){e|=0,t|=0;var r,s,o=0,A=0,p=0,m=0,b=0,v=0,y=0,x=0,_=0,w=0,T=0,M=0,E=0,C=0,I=0,R=0,P=0;i[(n|=0)>>2]=0,y=+a[e>>3],x=+a[e+8>>3],v=+a[e+16>>3],A=0,p=5,o=5,e=0;do{(m=(T=+a[15888+(24*A|0)>>3]-y)*T+(w=+a[15888+(24*A|0)+8>>3]-x)*w+(m=+a[15888+(24*A|0)+16>>3]-v)*m)<o&&(i[n>>2]=A,p=m,e=A,o=m),A=A+1|0}while(20!=(0|A));if((p=+h(+(1-.5*p)))<1e-16)v=0,m=0;else{if(R=+a[16368+(24*e|0)>>3],C=+a[15888+(24*e|0)>>3],I=+a[15888+(24*e|0)+8>>3],m=C*(P=-((E=+a[15888+(24*e|0)+16>>3])+(0*C+0*I)))+0,T=I*P+0,m*=M=(M=+c(+((P=E*P+1)*P+(m*m+T*T))))>0?1/M:0,T*=M,M*=P,w=y+C*(P=-(y*C+x*I+v*E)),w*=x=(x=+c(+((y=v+E*P)*y+(w*w+(o=x+I*P)*o))))>0?1/x:0,o*=x,o=+He(R-+He(+g(+((x*=y)*(I*m-C*T)+(w*(E*T-I*M)+o*(C*M-E*m))),+(M*x+(m*w+T*o))))),m=0|Le(t)?+He(o+-.3334731722518321):o,o=2.618033988749896*+d(+p),(0|t)>0){e=0;do{o*=2.6457513110645907,e=e+1|0}while((0|e)!=(0|t))}v=+u(+m)*o,m=+f(+m)*o}t=n+4|0,i[(s=n+12|0)>>2]=0,p=1.1547005383792515*+l(+m),o=+l(+v)+.5*p,o-=+(0|(e=~~o)),p-=+(0|(A=~~p));do{if(o<.5){if(o<.3333333333333333){if(i[t>>2]=e,p<.5*(o+1)){i[n+8>>2]=A;break}A=A+1|0,i[n+8>>2]=A;break}if(A=(1&!(p<(P=1-o)))+A|0,i[n+8>>2]=A,P<=p&p<2*o){e=e+1|0,i[t>>2]=e;break}i[t>>2]=e;break}if(!(o<.6666666666666666)){if(e=e+1|0,i[t>>2]=e,p<.5*o){i[n+8>>2]=A;break}A=A+1|0,i[n+8>>2]=A;break}if(p<1-o){if(i[n+8>>2]=A,2*o-1<p){i[t>>2]=e;break}}else A=A+1|0,i[n+8>>2]=A;e=e+1|0,i[t>>2]=e}while(0);do{if(v<0){if(1&A){e=~~(+(0|e)-(2*(+((_=0|Nt(0|e,((0|e)<0)<<31>>31,0|(_=(A+1|0)/2|0),((0|_)<0)<<31>>31))>>>0)+4294967296*+(0|S()))+1)),i[t>>2]=e,_=t;break}e=~~(+(0|e)-2*(+((_=0|Nt(0|e,((0|e)<0)<<31>>31,0|(_=(0|A)/2|0),((0|_)<0)<<31>>31))>>>0)+4294967296*+(0|S()))),i[t>>2]=e,_=t;break}_=t}while(0);r=n+8|0,t=0-A|0,m<0?(n=e-((A<<1|1)/2|0)|0,i[_>>2]=n,i[r>>2]=t,A=t):n=e,e=A-n|0,t=0-n|0,(0|n)<0?(i[r>>2]=e,i[s>>2]=t,i[_>>2]=0,b=0):(e=A,b=n,t=0),n=b-e|0,A=t-e|0,(0|e)<0?(i[_>>2]=n,i[s>>2]=A,i[r>>2]=0,b=n,e=0):A=t,n=b-A|0,t=e-A|0,(0|A)<0?(i[_>>2]=n,i[r>>2]=t,i[s>>2]=0,A=0):(t=e,n=b),(0|(e=(0|A)<(0|(e=(0|t)<(0|n)?t:n))?A:e))<=0||(i[_>>2]=n-e,i[r>>2]=t-e,i[s>>2]=A-e)}function ue(e,t,n){t|=0,n|=0;var r,s,o,A;r=N,N=N+16|0,s=r,A=0|i[(e|=0)+12>>2],o=+((0|i[e+8>>2])-A|0),a[s>>3]=+((0|i[e+4>>2])-A|0)-.5*o,a[s+8>>3]=.8660254037844386*o,fe(s,0|i[e>>2],t,0,n),N=r}function fe(e,t,n,r,s){t|=0,n|=0,r|=0,s|=0;var o,A,l,d,h,p=0,b=0,v=0,y=0,x=0,_=0,w=0;if(p=+function(e){e|=0;var t=0,n=0;return n=+a[e>>3],t=+a[e+8>>3],+ +c(+(n*n+t*t))}(e|=0),p<1e-16)return t=15888+(24*t|0)|0,i[s>>2]=i[t>>2],i[s+4>>2]=i[t+4>>2],i[s+8>>2]=i[t+8>>2],i[s+12>>2]=i[t+12>>2],i[s+16>>2]=i[t+16>>2],void(i[s+20>>2]=i[t+20>>2]);if(b=+g(+ +a[e+8>>3],+ +a[e>>3]),(0|n)>0){e=0;do{p*=.37796447300922725,e=e+1|0}while((0|e)!=(0|n))}v=.3333333333333333*p,r?(n=!(0|Le(n)),p=+m(.381966011250105*(n?v:.37796447300922725*v))):(p=+m(.381966011250105*p),0|Le(n)&&(b=+He(b+.3334731722518321))),x=+He(+a[16368+(24*t|0)>>3]-b),v=+a[15888+(24*t|0)>>3],A=+a[15888+(24*t|0)+8>>3],y=v*(w=-((d=+a[15888+(24*t|0)+16>>3])+(0*v+0*A)))+0,b=A*w+0,y*=_=(_=+c(+((w=d*w+1)*w+(y*y+b*b))))>0?1/_:0,b*=_,_*=w,w=+u(+x),x=+f(+x),o=(h=+u(+p))*v+(l=+f(+p))*(w*y+x*(d*b-A*_)),p=h*A+l*(w*b+x*(v*_-d*y)),v=(v=+c(+((b=h*d+l*(w*_+x*(A*y-v*b)))*b+(o*o+p*p))))>0?1/v:0,a[s>>3]=o*v,a[s+8>>3]=p*v,a[s+16>>3]=b*v}function de(e,t,n,r,s){e|=0,t|=0,n|=0,r|=0,s|=0;var o,A,l,c,u,f,d,h,m,b,y,x,_,w,T,S,E,C,I,R,P,k,L,B,O,F,D,U=0,V=0,j=0,z=0,G=0,H=0,q=0,Q=0,K=0,W=0,J=0,$=0,X=0,Y=0,Z=0;if(D=N,N=N+256|0,K=D+224|0,B=D,O=D+208|0,F=D+192|0,C=D+168|0,I=D+152|0,R=D+136|0,P=D+120|0,k=D+104|0,L=D+80|0,i[(U=D+240|0)>>2]=t,i[K>>2]=i[e>>2],i[K+4>>2]=i[e+4>>2],i[K+8>>2]=i[e+8>>2],i[K+12>>2]=i[e+12>>2],he(K,U,B),i[s>>2]=0,(0|(K=r+n+(5==(0|r)&1)|0))<=(0|n))N=D;else{d=O+4|0,u=O+8|0,f=O+12|0,m=F+8|0,b=n+5|0,y=16848+((h=0|i[U>>2])<<2)|0,x=C+8|0,_=16928+(h<<2)|0,w=I+8|0,T=R+8|0,S=P+8|0,E=F+8|0,o=C+8|0,l=C+16|0,A=L+8|0,c=L+16|0,Q=n,r=0,V=0,j=0,z=0;e:for(;;){q=B+((0|Q)%5<<4)|0,i[O>>2]=i[q>>2],i[O+4>>2]=i[q+4>>2],i[O+8>>2]=i[q+8>>2],i[O+12>>2]=i[q+12>>2];do{}while(2==(0|pe(O,h,0,1)));if((0|Q)>(0|n)&!!(0|Le(t))){if(q=0|i[O>>2],e=0|i[d>>2],G=0|i[u>>2],U=0|i[f>>2],W=+(j-z|0),a[F>>3]=+(V-z|0)-.5*W,a[m>>3]=.8660254037844386*W,z=0|i[17008+(80*q|0)+(r<<2)>>2],H=0|i[18608+(80*q|0)+(20*z|0)>>2],(0|(j=0|i[18608+(80*q|0)+(20*z|0)+16>>2]))>0){V=0,r=G;do{r=(($=(0|(G=r+e-((Y=(0|(X=U+e|0))<0)?X:0)|0))<0)?0:G)-((U=(0|(J=U+r-(Y?X:0)-($?G:0)|0))<0)?J:0)|0,e=(e=(Y?0:X)-($?G:0)-(U?J:0)|0)-((G=(0|(U=(0|(J=U?0:J))<(0|(U=(0|r)<(0|e)?r:e))?J:U))>0)?U:0)|0,r=r-(G?U:0)|0,U=J-(G?U:0)|0,V=V+1|0}while((0|V)<(0|j))}else r=G;switch(Y=3*(0|i[y>>2])|0,J=(0|v(Y,0|i[18608+(80*q|0)+(20*z|0)+4>>2]))+e|0,G=(0|v(Y,0|i[18608+(80*q|0)+(20*z|0)+8>>2]))+r|0,Y=(0|v(Y,0|i[18608+(80*q|0)+(20*z|0)+12>>2]))+U|0,J=((z=(0|J)<0)?0:J)-(($=(0|(G=G-(z?J:0)|0))<0)?G:0)-((X=(0|(Y=Y+(z?0-J|0:0)+($?0-G|0:0)|0))<0)?Y:0)|0,W=+((G=($?0:G)-(X?Y:0)|0)-(($=(0|(X=(0|(Y=X?0:Y))<(0|(X=(0|G)<(0|J)?G:J))?Y:X))>0)?X:0)-(Y=Y-($?X:0)|0)|0),a[C>>3]=+(J-($?X:0)-Y|0)-.5*W,a[x>>3]=.8660254037844386*W,W=+(0|i[_>>2]),a[I>>3]=3*W,a[w>>3]=0,Z=-1.5*W,a[R>>3]=Z,a[T>>3]=2.598076211353316*W,a[P>>3]=Z,a[S>>3]=-2.598076211353316*W,0|i[17008+(80*H|0)+(q<<2)>>2]){case 1:e=R,r=I;break;case 3:e=P,r=R;break;case 2:e=I,r=P;break;default:e=12;break e}ft(F,C,r,e,k),fe(k,H,h,1,L),Y=0|i[s>>2],W=+p(+ +a[c>>3]),Z=+g(+ +a[A>>3],+ +a[L>>3]),a[s+8+(Y<<4)>>3]=W,a[s+8+(Y<<4)+8>>3]=Z,i[s>>2]=1+(0|i[s>>2])}if((0|Q)<(0|b)&&(Y=0|i[f>>2],W=+((0|i[u>>2])-Y|0),a[F>>3]=+((0|i[d>>2])-Y|0)-.5*W,a[E>>3]=.8660254037844386*W,fe(F,0|i[O>>2],h,1,C),Y=0|i[s>>2],W=+p(+ +a[l>>3]),Z=+g(+ +a[o>>3],+ +a[C>>3]),a[s+8+(Y<<4)>>3]=W,a[s+8+(Y<<4)+8>>3]=Z,i[s>>2]=1+(0|i[s>>2])),(0|(Q=Q+1|0))>=(0|K)){e=3;break}r=0|i[O>>2],V=0|i[d>>2],j=0|i[u>>2],z=0|i[f>>2]}3!=(0|e)?12==(0|e)&&M(27073,27120,599,27130):N=D}}function he(e,t,n){e|=0,t|=0,n|=0;var r,a,s,o,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0;o=N,N=N+128|0,l=o,u=20208,f=(c=A=o+64|0)+60|0;do{i[c>>2]=i[u>>2],c=c+4|0,u=u+4|0}while((0|c)<(0|f));u=20272,f=(c=l)+60|0;do{i[c>>2]=i[u>>2],c=c+4|0,u=u+4|0}while((0|c)<(0|f));p=(p=!(0|Le(0|i[t>>2])))?A:l,c=0|i[(s=e+4|0)>>2],A=0|i[(r=e+8|0)>>2],l=0|i[(a=e+12|0)>>2],u=A+(c<<1)|0,i[s>>2]=u,A=l+(A<<1)|0,i[r>>2]=A,c=(l<<1)+c|0,i[a>>2]=c,l=A-u|0,f=c-u|0,(0|u)<0&&(i[r>>2]=l,i[a>>2]=f,i[s>>2]=0,A=l,u=0,c=f),f=u-A|0,l=c-A|0,(0|A)<0?(i[s>>2]=f,i[a>>2]=l,i[r>>2]=0,A=0):(l=c,f=u),u=f-l|0,c=A-l|0,(0|l)<0?(i[s>>2]=u,i[r>>2]=c,i[a>>2]=0,l=0):(c=A,u=f),(0|(A=(0|l)<(0|(A=(0|c)<(0|u)?c:u))?l:A))>0&&(l=l-A|0,c=c-A|0,u=u-A|0,i[s>>2]=u,i[r>>2]=c,i[a>>2]=l),d=(c<<1)+u|0,f=l+(u<<1)|0,i[s>>2]=f,i[r>>2]=d,c=(l<<1)+c|0,i[a>>2]=c,A=d-f|0,l=c-f|0,(0|f)<0?(i[r>>2]=A,i[a>>2]=l,i[s>>2]=0,f=0,c=l):A=d,u=f-A|0,l=c-A|0,(0|A)<0?(i[s>>2]=u,i[a>>2]=l,i[r>>2]=0,f=u,A=0):l=c,u=f-l|0,c=A-l|0,(0|l)<0?(i[s>>2]=u,i[r>>2]=c,i[a>>2]=0,l=0):(c=A,u=f),(0|(A=(0|l)<(0|(A=(0|c)<(0|u)?c:u))?l:A))>0&&(i[s>>2]=u-A,i[r>>2]=c-A,i[a>>2]=l-A),0|Le(0|i[t>>2])&&(c=0|i[s>>2],A=(3*(u=0|i[r>>2])|0)+c|0,c=(l=0|i[a>>2])+(3*c|0)|0,i[s>>2]=c,i[r>>2]=A,u=(3*l|0)+u|0,i[a>>2]=u,l=A-c|0,f=u-c|0,(0|c)<0?(i[r>>2]=l,i[a>>2]=f,i[s>>2]=0,A=l,d=0):(d=c,f=u),c=d-A|0,l=f-A|0,(0|A)<0?(i[s>>2]=c,i[a>>2]=l,i[r>>2]=0,d=c,u=0):(u=A,l=f),c=d-l|0,A=u-l|0,(0|l)<0?(i[s>>2]=c,i[r>>2]=A,i[a>>2]=0,u=A,l=0):c=d,(0|(A=(0|l)<(0|(A=(0|u)<(0|c)?u:c))?l:A))>0&&(i[s>>2]=c-A,i[r>>2]=u-A,i[a>>2]=l-A),i[t>>2]=1+(0|i[t>>2])),i[n>>2]=i[e>>2],l=0|i[r>>2],A=0|i[a>>2],t=0|i[p+4>>2],h=0|i[p+8>>2],u=(0|i[p>>2])+(0|i[s>>2])|0,i[(d=n+4|0)>>2]=u,l=t+l|0,i[(t=n+8|0)>>2]=l,A=h+A|0,i[(h=n+12|0)>>2]=A,c=l-u|0,(0|u)<0&&(A=A-u|0,i[t>>2]=c,i[h>>2]=A,i[d>>2]=0,l=c,u=0),(0|l)<0&&(u=u-l|0,i[d>>2]=u,A=A-l|0,i[h>>2]=A,i[t>>2]=0,l=0),f=u-A|0,c=l-A|0,(0|A)<0?(i[d>>2]=f,i[t>>2]=c,i[h>>2]=0,u=f,A=0):c=l,(0|(l=(0|A)<(0|(l=(0|c)<(0|u)?c:u))?A:l))>0&&(i[d>>2]=u-l,i[t>>2]=c-l,i[h>>2]=A-l),i[n+16>>2]=i[e>>2],l=0|i[r>>2],A=0|i[a>>2],t=0|i[p+16>>2],h=0|i[p+20>>2],u=(0|i[p+12>>2])+(0|i[s>>2])|0,i[(d=n+20|0)>>2]=u,l=t+l|0,i[(t=n+24|0)>>2]=l,A=h+A|0,i[(h=n+28|0)>>2]=A,c=l-u|0,(0|u)<0&&(A=A-u|0,i[t>>2]=c,i[h>>2]=A,i[d>>2]=0,l=c,u=0),(0|l)<0&&(u=u-l|0,i[d>>2]=u,A=A-l|0,i[h>>2]=A,i[t>>2]=0,l=0),f=u-A|0,c=l-A|0,(0|A)<0?(i[d>>2]=f,i[t>>2]=c,i[h>>2]=0,u=f,A=0):c=l,(0|(l=(0|A)<(0|(l=(0|c)<(0|u)?c:u))?A:l))>0&&(i[d>>2]=u-l,i[t>>2]=c-l,i[h>>2]=A-l),i[n+32>>2]=i[e>>2],l=0|i[r>>2],A=0|i[a>>2],t=0|i[p+28>>2],h=0|i[p+32>>2],u=(0|i[p+24>>2])+(0|i[s>>2])|0,i[(d=n+36|0)>>2]=u,l=t+l|0,i[(t=n+40|0)>>2]=l,A=h+A|0,i[(h=n+44|0)>>2]=A,c=l-u|0,(0|u)<0&&(A=A-u|0,i[t>>2]=c,i[h>>2]=A,i[d>>2]=0,l=c,u=0),(0|l)<0&&(u=u-l|0,i[d>>2]=u,A=A-l|0,i[h>>2]=A,i[t>>2]=0,l=0),f=u-A|0,c=l-A|0,(0|A)<0?(i[d>>2]=f,i[t>>2]=c,i[h>>2]=0,u=f,A=0):c=l,(0|(l=(0|A)<(0|(l=(0|c)<(0|u)?c:u))?A:l))>0&&(i[d>>2]=u-l,i[t>>2]=c-l,i[h>>2]=A-l),i[n+48>>2]=i[e>>2],l=0|i[r>>2],A=0|i[a>>2],t=0|i[p+40>>2],h=0|i[p+44>>2],u=(0|i[p+36>>2])+(0|i[s>>2])|0,i[(d=n+52|0)>>2]=u,l=t+l|0,i[(t=n+56|0)>>2]=l,A=h+A|0,i[(h=n+60|0)>>2]=A,c=l-u|0,(0|u)<0&&(A=A-u|0,i[t>>2]=c,i[h>>2]=A,i[d>>2]=0,l=c,u=0),(0|l)<0&&(u=u-l|0,i[d>>2]=u,A=A-l|0,i[h>>2]=A,i[t>>2]=0,l=0),f=u-A|0,c=l-A|0,(0|A)<0?(i[d>>2]=f,i[t>>2]=c,i[h>>2]=0,u=f,A=0):c=l,(0|(l=(0|A)<(0|(l=(0|c)<(0|u)?c:u))?A:l))>0&&(i[d>>2]=u-l,i[t>>2]=c-l,i[h>>2]=A-l),i[n+64>>2]=i[e>>2],c=0|i[r>>2],A=0|i[a>>2],h=0|i[p+52>>2],d=0|i[p+56>>2],u=(0|i[p+48>>2])+(0|i[s>>2])|0,i[(t=n+68|0)>>2]=u,c=h+c|0,i[(h=n+72|0)>>2]=c,A=d+A|0,i[(d=n+76|0)>>2]=A,l=c-u|0,(0|u)<0?(A=A-u|0,i[h>>2]=l,i[d>>2]=A,i[t>>2]=0,c=0):(l=c,c=u),(0|l)<0&&(c=c-l|0,i[t>>2]=c,A=A-l|0,i[d>>2]=A,i[h>>2]=0,l=0),f=c-A|0,u=l-A|0,(0|A)<0?(i[t>>2]=f,i[h>>2]=u,i[d>>2]=0,c=f,A=0):u=l,(0|(l=(0|A)<(0|(l=(0|u)<(0|c)?u:c))?A:l))<=0||(i[t>>2]=c-l,i[h>>2]=u-l,i[d>>2]=A-l),N=o}function pe(e,t,n,r){e|=0,n|=0,r|=0;var a,s,o,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0;if(d=0|i[16928+((t|=0)<<2)>>2],d=(o=!!(0|r))?3*d|0:d,u=0|i[(s=e+4|0)>>2],l=0|i[(a=e+8|0)>>2],o){if((0|(A=l+u+(r=0|i[(c=e+12|0)>>2])|0))==(0|d))return 0|(d=1);f=c}else r=A=0|i[(f=e+12|0)>>2],A=l+u+A|0;if((0|A)<=(0|d))return 0|(d=0);do{if((0|r)>0){if(A=0|i[e>>2],(0|l)>0){A=18608+(80*A|0)+60|0,c=u;break}A=18608+(80*A|0)+40|0,n?(n=((h=(0|(n=l+(c=u-d|0)|0))<0)?0:n)-((u=(0|(l=r+l-(h?n:0)|0))<0)?l:0)-((c=(0|(r=r+c-(h?n:0)-(u?l:0)|0))<0)?r:0)|0,l=(l=(u?0:l)-(c?r:0)|0)-((u=(0|(c=(0|(r=c?0:r))<(0|(c=(0|l)<(0|n)?l:n))?r:c))>0)?c:0)|0,r=r-(u?c:0)|0,c=n-(u?c:0)+d|0,i[s>>2]=c,i[a>>2]=l,i[f>>2]=r):c=u}else A=18608+(80*(0|i[e>>2])|0)+20|0,c=u}while(0);if(i[e>>2]=i[A>>2],(0|(u=0|i[A+16>>2]))>0){n=0;do{(0|(e=(0|(r=(l=(0|(c=r+l-(b=(p=(0|(h=r+c|0))<0)?h:0)-(e=(g=(0|(m=l+c-b|0))<0)?m:0)|0))<0)?0:c))<(0|(e=(0|(l=(g?0:m)-(c=l?c:0)|0))<(0|(c=(p?0:h)-e-c|0))?l:c))?r:e))>0&&(c=c-e|0,l=l-e|0,r=r-e|0),n=n+1|0}while((0|n)<(0|u));i[s>>2]=c,i[a>>2]=l,i[f>>2]=r}return m=0|i[16848+(t<<2)>>2],g=0|v(m=o?3*m|0:m,0|i[A+8>>2]),b=0|v(m,0|i[A+12>>2]),c=(0|v(m,0|i[A+4>>2]))+c|0,i[s>>2]=c,l=g+l|0,i[a>>2]=l,r=b+r|0,i[f>>2]=r,A=l-c|0,(0|c)<0?(r=r-c|0,i[a>>2]=A,i[f>>2]=r,i[s>>2]=0,l=0):(A=l,l=c),(0|A)<0?(e=l-A|0,i[s>>2]=e,r=r-A|0,i[f>>2]=r,i[a>>2]=0,c=0):(e=l,c=A),l=e-r|0,A=c-r|0,(0|r)<0?(i[s>>2]=l,i[a>>2]=A,i[f>>2]=0,r=0):(A=c,l=e),(0|(c=(0|r)<(0|(c=(0|A)<(0|l)?A:l))?r:c))>0&&(l=l-c|0,A=A-c|0,r=r-c|0,i[s>>2]=l,i[a>>2]=A,i[f>>2]=r),o?0|(b=(A+l+r|0)==(0|d)?1:2):0|(b=2)}function me(e,t){e|=0,t|=0;var n=0;do{n=0|pe(e,t,0,1)}while(2==(0|n));return 0|n}function ge(e,t,n,r,s){e|=0,t|=0,n|=0,r|=0,s|=0;var o,A,l,c,u,f,d,h,m,b,v,y,x,_,w,T,S,E,C,I,R,P,k,L,B,O,F,D,U=0,V=0,j=0,z=0,G=0,H=0,q=0;if(D=N,N=N+272|0,V=D+240|0,B=D,O=D+224|0,F=D+208|0,C=D+184|0,I=D+168|0,R=D+152|0,P=D+136|0,k=D+120|0,L=D+96|0,i[(U=D+256|0)>>2]=t,i[V>>2]=i[e>>2],i[V+4>>2]=i[e+4>>2],i[V+8>>2]=i[e+8>>2],i[V+12>>2]=i[e+12>>2],be(V,U,B),i[s>>2]=0,(0|(E=r+n+(6==(0|r)&1)|0))<=(0|n))N=D;else{v=n+6|0,y=F+8|0,x=C+8|0,_=16928+((b=0|i[U>>2])<<2)|0,w=I+8|0,T=R+8|0,S=P+8|0,h=0|i[V>>2],u=O+4|0,f=O+8|0,d=O+12|0,m=F+8|0,o=C+8|0,l=C+16|0,A=L+8|0,c=L+16|0,V=0,j=n,r=-1;e:for(;;){if(e=B+((U=(0|j)%6|0)<<4)|0,i[O>>2]=i[e>>2],i[O+4>>2]=i[e+4>>2],i[O+8>>2]=i[e+8>>2],i[O+12>>2]=i[e+12>>2],e=V,V=0|pe(O,b,0,1),(0|j)>(0|n)&!!(0|Le(t))&&1!=(0|e)&(0|(z=0|i[O>>2]))!=(0|r)){switch(e=0|i[B+((q=(U+5|0)%6|0)<<4)+12>>2],G=+((0|i[B+(q<<4)+8>>2])-e|0),a[F>>3]=+((0|i[B+(q<<4)+4>>2])-e|0)-.5*G,a[y>>3]=.8660254037844386*G,e=0|i[B+(U<<4)+12>>2],G=+((0|i[B+(U<<4)+8>>2])-e|0),a[C>>3]=+((0|i[B+(U<<4)+4>>2])-e|0)-.5*G,a[x>>3]=.8660254037844386*G,G=+(0|i[_>>2]),a[I>>3]=3*G,a[w>>3]=0,H=-1.5*G,a[R>>3]=H,a[T>>3]=2.598076211353316*G,a[P>>3]=H,a[S>>3]=-2.598076211353316*G,0|i[17008+(80*h|0)+(((0|r)==(0|h)?z:r)<<2)>>2]){case 1:e=R,r=I;break;case 3:e=P,r=R;break;case 2:e=I,r=P;break;default:e=8;break e}ft(F,C,r,e,k),0|dt(F,k)||0|dt(C,k)||(fe(k,h,b,1,L),q=0|i[s>>2],G=+p(+ +a[c>>3]),H=+g(+ +a[A>>3],+ +a[L>>3]),a[s+8+(q<<4)>>3]=G,a[s+8+(q<<4)+8>>3]=H,i[s>>2]=1+(0|i[s>>2]))}if((0|j)<(0|v)&&(q=0|i[d>>2],G=+((0|i[f>>2])-q|0),a[F>>3]=+((0|i[u>>2])-q|0)-.5*G,a[m>>3]=.8660254037844386*G,fe(F,0|i[O>>2],b,1,C),q=0|i[s>>2],G=+p(+ +a[l>>3]),H=+g(+ +a[o>>3],+ +a[C>>3]),a[s+8+(q<<4)>>3]=G,a[s+8+(q<<4)+8>>3]=H,i[s>>2]=1+(0|i[s>>2])),(0|(j=j+1|0))>=(0|E)){e=3;break}r=0|i[O>>2]}3!=(0|e)?8==(0|e)&&M(27157,27120,766,27202):N=D}}function be(e,t,n){e|=0,t|=0,n|=0;var r,a,s,o,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0;o=N,N=N+160|0,l=o,u=20336,f=(c=A=o+80|0)+72|0;do{i[c>>2]=i[u>>2],c=c+4|0,u=u+4|0}while((0|c)<(0|f));u=20416,f=(c=l)+72|0;do{i[c>>2]=i[u>>2],c=c+4|0,u=u+4|0}while((0|c)<(0|f));m=(m=!(0|Le(0|i[t>>2])))?A:l,c=0|i[(s=e+4|0)>>2],A=0|i[(r=e+8|0)>>2],l=0|i[(a=e+12|0)>>2],u=A+(c<<1)|0,i[s>>2]=u,A=l+(A<<1)|0,i[r>>2]=A,c=(l<<1)+c|0,i[a>>2]=c,l=A-u|0,f=c-u|0,(0|u)<0&&(i[r>>2]=l,i[a>>2]=f,i[s>>2]=0,A=l,u=0,c=f),f=u-A|0,l=c-A|0,(0|A)<0?(i[s>>2]=f,i[a>>2]=l,i[r>>2]=0,A=0):(l=c,f=u),u=f-l|0,c=A-l|0,(0|l)<0?(i[s>>2]=u,i[r>>2]=c,i[a>>2]=0,l=0):(c=A,u=f),(0|(A=(0|l)<(0|(A=(0|c)<(0|u)?c:u))?l:A))>0&&(l=l-A|0,c=c-A|0,u=u-A|0,i[s>>2]=u,i[r>>2]=c,i[a>>2]=l),d=(c<<1)+u|0,f=l+(u<<1)|0,i[s>>2]=f,i[r>>2]=d,c=(l<<1)+c|0,i[a>>2]=c,A=d-f|0,l=c-f|0,(0|f)<0?(i[r>>2]=A,i[a>>2]=l,i[s>>2]=0,f=0,c=l):A=d,u=f-A|0,l=c-A|0,(0|A)<0?(i[s>>2]=u,i[a>>2]=l,i[r>>2]=0,f=u,A=0):l=c,u=f-l|0,c=A-l|0,(0|l)<0?(i[s>>2]=u,i[r>>2]=c,i[a>>2]=0,l=0):(c=A,u=f),(0|(A=(0|l)<(0|(A=(0|c)<(0|u)?c:u))?l:A))>0&&(i[s>>2]=u-A,i[r>>2]=c-A,i[a>>2]=l-A),0|Le(0|i[t>>2])&&(c=0|i[s>>2],A=(3*(u=0|i[r>>2])|0)+c|0,c=(l=0|i[a>>2])+(3*c|0)|0,i[s>>2]=c,i[r>>2]=A,u=(3*l|0)+u|0,i[a>>2]=u,l=A-c|0,f=u-c|0,(0|c)<0?(i[r>>2]=l,i[a>>2]=f,i[s>>2]=0,A=l,d=0):(d=c,f=u),c=d-A|0,l=f-A|0,(0|A)<0?(i[s>>2]=c,i[a>>2]=l,i[r>>2]=0,d=c,u=0):(u=A,l=f),c=d-l|0,A=u-l|0,(0|l)<0?(i[s>>2]=c,i[r>>2]=A,i[a>>2]=0,u=A,l=0):c=d,(0|(A=(0|l)<(0|(A=(0|u)<(0|c)?u:c))?l:A))>0&&(i[s>>2]=c-A,i[r>>2]=u-A,i[a>>2]=l-A),i[t>>2]=1+(0|i[t>>2])),d=0;do{i[n+(d<<4)>>2]=i[e>>2],l=0|i[r>>2],A=0|i[a>>2],h=0|i[m+(12*d|0)+4>>2],p=0|i[m+(12*d|0)+8>>2],u=(0|i[m+(12*d|0)>>2])+(0|i[s>>2])|0,i[(t=n+(d<<4)+4|0)>>2]=u,l=h+l|0,i[(h=n+(d<<4)+8|0)>>2]=l,A=p+A|0,i[(p=n+(d<<4)+12|0)>>2]=A,c=l-u|0,(0|u)<0&&(A=A-u|0,i[h>>2]=c,i[p>>2]=A,i[t>>2]=0,l=c,u=0),(0|l)<0&&(u=u-l|0,i[t>>2]=u,A=A-l|0,i[p>>2]=A,i[h>>2]=0,l=0),f=u-A|0,c=l-A|0,(0|A)<0?(i[t>>2]=f,i[h>>2]=c,i[p>>2]=0,u=f,A=0):c=l,(0|(l=(0|A)<(0|(l=(0|c)<(0|u)?c:u))?A:l))>0&&(i[t>>2]=u-l,i[h>>2]=c-l,i[p>>2]=A-l),d=d+1|0}while(6!=(0|d));N=o}function ve(e,t){return t=0|Vt(0|(e|=0),0|(t|=0),52),S(),15&t}function ye(e,t){return t=0|Vt(0|(e|=0),0|(t|=0),45),S(),127&t}function xe(e,t){e|=0;var n=0,i=0,a=0,s=0;return!0&134217728==(-16777216&(t|=0))?(i=0|Vt(0|e,0|t,52),S(),i&=15,n=0|Vt(0|e,0|t,45),S(),(n&=127)>>>0>121?0|(e=0):!(613566756&(s=0|jt(0|(a=0|Vt(0|e,0|t,0|(s=3*(15^i)|0))),0|S(),0|s))&(0|Nt(-1227133514,-1171,0|s,0|(a=0|S()))))&!(4681&a&S())&&15==(0|i)|!(0|(s=0|Vt(0|(0|jt(0|~e,0|~t,0|(s=19+(3*i|0)|0))),0|S(),0|s)))&!(0|S())?0|r[20496+n|0]?!(0|e)&!(0|(t&=8191))?0|(s=1):(s=0|zt(0|e,0|t,0),S(),0|!!((63-s|0)%3|0)):0|(s=1):0|(s=0)):0|(e=0)}function _e(e,t,n,r){e|=0,n|=0,r|=0;var a=0,s=0,o=0,A=0;if(a=0|jt(0|(t|=0),0,52),s=0|S(),n=0|jt(0|n,0,45),n=0|s|S()|134225919,(0|t)<1)return s=-1,r=n,i[(t=e)>>2]=s,void(i[(e=e+4|0)>>2]=r);for(s=1,a=-1;A=0|jt(7,0,0|(o=3*(15-s|0)|0)),n&=~S(),a=a&~A|(o=0|jt(0|r,0,0|o)),n=0|n|S(),(0|s)!=(0|t);)s=s+1|0;i[(o=A=e)>>2]=a,i[(A=A+4|0)>>2]=n}function we(e,t,n,r){n|=0,r|=0;var a=0,s=0;if(s=0|Vt(0|(e|=0),0|(t|=0),52),S(),n>>>0>15)return 0|(r=4);if((0|(s&=15))<(0|n))return 0|(r=12);if((0|s)==(0|n))return i[r>>2]=e,i[r+4>>2]=t,0|(r=0);if(a=0|jt(0|n,0,52),a|=e,e=S()|-15728641&t,(0|s)>(0|n))do{t=0|jt(7,0,3*(14-n|0)|0),n=n+1|0,a|=t,e=0|S()|e}while((0|n)<(0|s));return i[r>>2]=a,i[r+4>>2]=e,0|(r=0)}function Te(e,t,n,r){n|=0,r|=0;var a=0,s=0,o=0;if(s=0|Vt(0|(e|=0),0|(t|=0),52),S(),!((0|n)<16&(0|(s&=15))<=(0|n)))return 0|(r=4);a=n-s|0,n=0|Vt(0|e,0|t,45),S();e:do{if(0|G(127&n)){t:do{if(0|s){for(n=1;!((o=0|jt(7,0,3*(15-n|0)|0))&e|0)&!((0|S())&t);){if(!(n>>>0<s>>>0))break t;n=n+1|0}n=0|Ze(7,0,a,((0|a)<0)<<31>>31),a=0|S();break e}}while(0);n=0|Pt(0|(n=0|Ot(0|(n=0|Ze(7,0,a,((0|a)<0)<<31>>31)),0|S(),5,0)),0|S(),-5,-1),n=0|Pt(0|(n=0|Bt(0|n,0|S(),6,0)),0|S(),1,0),a=0|S()}else n=0|Ze(7,0,a,((0|a)<0)<<31>>31),a=0|S()}while(0);return i[(o=r)>>2]=n,i[o+4>>2]=a,0|(o=0)}function Se(e,t){var n=0,r=0,i=0;if(i=0|Vt(0|(e|=0),0|(t|=0),45),S(),!(0|G(127&i)))return 0|(i=0);i=0|Vt(0|e,0|t,52),S(),i&=15;e:do{if(i)for(r=1;;){if(n=0|Vt(0|e,0|t,3*(15-r|0)|0),S(),0|(n&=7))break e;if(!(r>>>0<i>>>0)){n=0;break}r=r+1|0}else n=0}while(0);return 0|(i=1&!(0|n))}function Me(e,t,n,r){return e|=0,t|=0,(0|(r|=0))<(0|(n|=0))?(r=e,T(0|(n=t)),0|r):(n=0|jt(-1,-1,3+(3*(r-n|0)|0)|0),r=0|jt(0|~n,0|~S(),3*(15-r|0)|0),n=~S()&t,r=~r&e,T(0|n),0|r)}function Ee(e,t,n,r){n|=0,r|=0;var a=0;return a=0|Vt(0|(e|=0),0|(t|=0),52),S(),(0|n)<16&(0|(a&=15))<=(0|n)?((0|a)<(0|n)&&(a=0|jt(-1,-1,3+(3*(n+-1-a|0)|0)|0),a=0|jt(0|~a,0|~S(),3*(15-n|0)|0),t=~S()&t,e&=~a),a=0|jt(0|n,0,52),n=-15728641&t|S(),i[r>>2]=e|a,i[r+4>>2]=n,0|(r=0)):0|(r=4)}function Ce(e,t){var n=0,r=0,i=0;if(i=0|Vt(0|(e|=0),0|(t|=0),52),S(),!(i&=15))return 0|(i=0);for(r=1;;){if(n=0|Vt(0|e,0|t,3*(15-r|0)|0),S(),0|(n&=7)){r=5;break}if(!(r>>>0<i>>>0)){n=0,r=5;break}r=r+1|0}return 5==(0|r)?0|n:0}function Ie(e,t){var n=0,r=0,i=0,a=0,s=0,o=0,A=0,l=0,c=0;if(c=0|Vt(0|(e|=0),0|(t|=0),52),S(),!(c&=15))return c=e,T(0|(l=t)),0|c;for(l=1,n=0;;){switch(a=e&~(o=0|jt(7,0,0|(r=3*(15-l|0)|0))),s=t&~(A=0|S()),e=0|Vt(0|e,0|t,0|r),S(),7&e){case 1:e=5;break;case 5:e=4;break;case 4:e=6;break;case 6:e=2;break;case 2:e=3;break;case 3:e=1;break;default:e&=7}e=(r=0|jt(0|e,0,0|r))|a,t=(i=0|S())|s;e:do{if(!n)if(!(r&o|0)&!(i&A|0))n=0;else if(s=0|Vt(0|e,0|t,52),S(),s&=15){n=1;t:for(;;){switch(A=0|Vt(0|e,0|t,3*(15-n|0)|0),S(),7&A){case 1:break t;case 0:break;default:n=1;break e}if(!(n>>>0<s>>>0)){n=1;break e}n=n+1|0}for(a=1;;){switch(n=0|Vt(0|e,0|t,0|(i=3*(15-a|0)|0)),S(),r=e&~(r=0|jt(7,0,0|i)),t&=~S(),7&n){case 1:e=5;break;case 5:e=4;break;case 4:e=6;break;case 6:e=2;break;case 2:e=3;break;case 3:e=1;break;default:e=7&n}if(e=0|jt(0|e,0,0|i),e|=r,t=0|S()|t,!(a>>>0<s>>>0)){n=1;break e}a=a+1|0}}else n=1}while(0);if(!(l>>>0<c>>>0))break;l=l+1|0}return T(0|t),0|e}function Re(e,t){var n=0,r=0,i=0,a=0,s=0;if(s=0|Vt(0|(e|=0),0|(t|=0),52),S(),!(s&=15))return s=e,T(0|(a=t)),0|s;for(a=1;;){switch(n=0|Vt(0|e,0|t,0|(i=3*(15-a|0)|0)),S(),r=e&~(r=0|jt(7,0,0|i)),t&=~S(),7&n){case 1:e=5;break;case 5:e=4;break;case 4:e=6;break;case 6:e=2;break;case 2:e=3;break;case 3:e=1;break;default:e=7&n}if(e=0|jt(0|e,0,0|i),e|=r,t=0|S()|t,!(a>>>0<s>>>0))break;a=a+1|0}return T(0|t),0|e}function Pe(e,t){var n=0,r=0,i=0,a=0,s=0,o=0,A=0,l=0,c=0;if(c=0|Vt(0|(e|=0),0|(t|=0),52),S(),!(c&=15))return c=e,T(0|(l=t)),0|c;for(l=1,n=0;;){switch(a=e&~(o=0|jt(7,0,0|(r=3*(15-l|0)|0))),s=t&~(A=0|S()),e=0|Vt(0|e,0|t,0|r),S(),7&e){case 1:e=3;break;case 3:e=2;break;case 2:e=6;break;case 6:e=4;break;case 4:e=5;break;case 5:e=1;break;default:e&=7}e=(r=0|jt(0|e,0,0|r))|a,t=(i=0|S())|s;e:do{if(!n)if(!(r&o|0)&!(i&A|0))n=0;else if(s=0|Vt(0|e,0|t,52),S(),s&=15){n=1;t:for(;;){switch(A=0|Vt(0|e,0|t,3*(15-n|0)|0),S(),7&A){case 1:break t;case 0:break;default:n=1;break e}if(!(n>>>0<s>>>0)){n=1;break e}n=n+1|0}for(a=1;;){switch(r=e&~(r=0|jt(7,0,0|(n=3*(15-a|0)|0))),i=t&~S(),e=0|Vt(0|e,0|t,0|n),S(),7&e){case 1:e=3;break;case 3:e=2;break;case 2:e=6;break;case 6:e=4;break;case 4:e=5;break;case 5:e=1;break;default:e&=7}if(e=0|jt(0|e,0,0|n),e|=r,t=0|S()|i,!(a>>>0<s>>>0)){n=1;break e}a=a+1|0}}else n=1}while(0);if(!(l>>>0<c>>>0))break;l=l+1|0}return T(0|t),0|e}function Ne(e,t){var n=0,r=0,i=0,a=0,s=0;if(s=0|Vt(0|(e|=0),0|(t|=0),52),S(),!(s&=15))return s=e,T(0|(a=t)),0|s;for(a=1;;){switch(n=e&~(n=0|jt(7,0,0|(r=3*(15-a|0)|0))),i=t&~S(),e=0|Vt(0|e,0|t,0|r),S(),7&e){case 1:e=3;break;case 3:e=2;break;case 2:e=6;break;case 6:e=4;break;case 4:e=5;break;case 5:e=1;break;default:e&=7}if(e=0|jt(0|e,0,0|r),e|=n,t=0|S()|i,!(a>>>0<s>>>0))break;a=a+1|0}return T(0|t),0|e}function ke(e,t){e|=0;var n,r=0,a=0,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0,w=0,M=0;if(n=N,N=N+16|0,x=n,jt(0|(t|=0),0,52),r=134225919|S(),!t)return(0|i[e+4>>2])>2||(0|i[e+8>>2])>2||(0|i[e+12>>2])>2?(x=0,T(0|(y=0)),N=n,0|x):(jt(0|q(e),0,45),y=0|S()|r,x=-1,T(0|y),N=n,0|x);i[x>>2]=i[e>>2],i[x+4>>2]=i[e+4>>2],i[x+8>>2]=i[e+8>>2],i[x+12>>2]=i[e+12>>2],y=x+4|0;e:do{if((0|t)>0)for(b=x+12|0,m=t,d=0|i[(g=x+8|0)>>2],h=0|i[b>>2],t=-1,f=0|i[x+4>>2];;){p=m,m=m+-1|0,e=f-h|0,a=d-h|0,1&p?(o=0|St(.14285714285714285*+((3*e|0)-a|0)),i[y>>2]=o,e=0|St(.14285714285714285*+((a<<1)+e|0)),i[g>>2]=e,i[b>>2]=0,a=e-o|0,s=0-o|0,(0|o)<0?(i[g>>2]=a,i[b>>2]=s,i[y>>2]=0,e=a,A=0):(A=o,s=0),o=A-e|0,a=s-e|0,(0|e)<0?(i[y>>2]=o,i[b>>2]=a,i[g>>2]=0,A=o,o=0):(a=s,o=e),e=A-a|0,s=o-a|0,(0|a)<0?(i[y>>2]=e,i[g>>2]=s,i[b>>2]=0,o=0):(s=o,e=A,o=a),(0|(a=(0|o)<(0|(a=(0|s)<(0|e)?s:e))?o:a))>0&&(o=o-a|0,s=s-a|0,e=e-a|0,i[y>>2]=e,i[g>>2]=s,i[b>>2]=o),c=(u=(0|(l=(0|(M=(l=(0|(a=(3*o|0)+e-((_=(0|(w=s+(3*e|0)|0))<0)?w:0)-((c=(0|(u=o+(3*s|0)-(_?w:0)|0))<0)?u:0)|0))<0)?0:a))<(0|(l=(0|(A=(c?0:u)-(l?a:0)|0))<(0|(a=(_?0:w)-(c?u:0)-(l?a:0)|0))?A:a))?M:l))>0)?l:0,A=A-(u?l:0)|0,l=M-(u?l:0)|0,u=o):(l=0|St(.14285714285714285*+((e<<1)+a|0)),i[y>>2]=l,s=0|St(.14285714285714285*+((3*a|0)-e|0)),i[g>>2]=s,i[b>>2]=0,a=s-l|0,e=0-l|0,(0|l)<0?(i[g>>2]=a,i[b>>2]=e,i[y>>2]=0,s=a,l=0):e=0,A=l-s|0,a=e-s|0,(0|s)<0?(i[y>>2]=A,i[b>>2]=a,i[g>>2]=0,o=a,s=0):(o=e,A=l),e=A-o|0,a=s-o|0,(0|o)<0?(i[y>>2]=e,i[g>>2]=a,i[b>>2]=0,s=a,o=0):e=A,(0|(a=(0|o)<(0|(a=(0|s)<(0|e)?s:e))?o:a))>0&&(o=o-a|0,s=s-a|0,e=e-a|0,i[y>>2]=e,i[g>>2]=s,i[b>>2]=o),c=(u=(0|(l=(0|(_=(l=(0|(a=(3*o|0)+s-((M=(0|(w=o+(3*e|0)|0))<0)?w:0)-((c=(0|(u=(3*s|0)+e-(M?w:0)|0))<0)?u:0)|0))<0)?0:a))<(0|(l=(0|(A=(c?0:u)-(l?a:0)|0))<(0|(a=(M?0:w)-(c?u:0)-(l?a:0)|0))?A:a))?_:l))>0)?l:0,A=A-(u?l:0)|0,l=_-(u?l:0)|0,u=o),l=(f=(0|(h=h-l+((o=(0|(a=f+(c-a)|0))<0)?0-a|0:0)+((A=(0|(c=d-A-(o?a:0)|0))<0)?0-c|0:0)|0))<0)?0:h,M=(A?0:c)-(f?h:0)|0,h=(h=(o?0:a)-(A?c:0)-(f?h:0)|0)-((c=(0|(f=(0|l)<(0|(f=(0|M)<(0|h)?M:h))?l:f))>0)?f:0)|0,a=t&~(a=0|jt(7,0,0|(A=3*(15-p|0)|0))),o=r&~S(),t=(t=(r=(0|(w=l-(c?f:0)-(w=(d=(0|h)<0)?h:0)+((_=(0|(M=M-(c?f:0)-w|0))<0)?0-M|0:0)|0))<0)?0:w)-(M=(0|(M=(0|t)<(0|(M=(0|(r=(_?0:M)-(w=r?w:0)|0))<(0|(w=(d?0:h)-(_?M:0)-w|0))?r:w))?t:M))>0?M:0)|0,r=r-M|0;t:do{switch(w-M|0){case 0:switch(0|r){case 0:t=0|t?1==(0|t)?1:7:0;break t;case 1:t=0|t?1==(0|t)?3:7:2;break t;default:v=36;break t}case 1:switch(0|r){case 0:t=0|t?1==(0|t)?5:7:4;break t;case 1:if(t){v=36;break t}t=6;break t;default:v=36;break t}default:v=36}}while(0);if(36==(0|v)&&(v=0,t=7),t=0|jt(0|t,0,0|A),t|=a,r=0|S()|o,(0|p)<=1)break e;d=s,h=u,f=e}else t=-1,e=0|i[y>>2]}while(0);e:do{if((0|e)<=2&&(0|i[x+8>>2])<=2&&(0|i[x+12>>2])<=2){if(t|=e=0|jt(0|(a=0|q(x)),0,45),e=S()|-1040385&r,c=0|Q(x),!(0|G(a))){if((0|c)<=0)break;for(l=0;;){A=0|Vt(0|t,0|e,52),S(),A&=15;t:do{if(A)for(o=1;;){switch(r=0|Vt(0|t,0|e,0|(s=3*(15-o|0)|0)),S(),t&=~(a=0|jt(7,0,0|s)),a=e&~S(),7&r){case 1:e=5;break;case 5:e=4;break;case 4:e=6;break;case 6:e=2;break;case 2:e=3;break;case 3:e=1;break;default:e=7&r}if(t|=e=0|jt(0|e,0,0|s),e=0|S()|a,!(o>>>0<A>>>0))break t;o=o+1|0}}while(0);if((0|(l=l+1|0))==(0|c))break e}}A=0|Vt(0|t,0|e,52),S(),A&=15;t:do{if(A){r=1;n:for(;;){switch(M=0|Vt(0|t,0|e,3*(15-r|0)|0),S(),7&M){case 1:break n;case 0:break;default:break t}if(!(r>>>0<A>>>0))break t;r=r+1|0}if(0|K(a,0|i[x>>2]))for(o=1;;){switch(a=t&~(a=0|jt(7,0,0|(r=3*(15-o|0)|0))),s=e&~S(),e=0|Vt(0|t,0|e,0|r),S(),7&e){case 1:e=3;break;case 3:e=2;break;case 2:e=6;break;case 6:e=4;break;case 4:e=5;break;case 5:e=1;break;default:e&=7}if(t=0|jt(0|e,0,0|r),t|=a,e=0|S()|s,!(o>>>0<A>>>0))break t;o=o+1|0}else for(o=1;;){switch(r=0|Vt(0|t,0|e,0|(s=3*(15-o|0)|0)),S(),t&=~(a=0|jt(7,0,0|s)),a=e&~S(),7&r){case 1:e=5;break;case 5:e=4;break;case 4:e=6;break;case 6:e=2;break;case 2:e=3;break;case 3:e=1;break;default:e=7&r}if(t|=e=0|jt(0|e,0,0|s),e=0|S()|a,!(o>>>0<A>>>0))break t;o=o+1|0}}}while(0);if((0|c)>0){r=0;do{t=0|Ie(t,e),e=0|S(),r=r+1|0}while((0|r)!=(0|c))}}else t=0,e=0}while(0);return M=t,T(0|(w=e)),N=n,0|M}function Le(e){return(0|(e|=0))%2|0}function Be(e,t,n){n|=0;var r,o,A,l,c=0,d=0,h=0,p=0,m=0;if(A=N,N=N+64|0,o=A+24|0,p=A+48|0,m=A,(t|=0)>>>0>15)return N=A,0|(m=4);if(r=+a[(e|=0)>>3],a[s>>3]=r,!(2146435072&~i[s+4>>2]))return N=A,0|(m=3);if(c=+a[e+8>>3],a[s>>3]=c,!(2146435072&~i[s+4>>2]))return N=A,0|(m=3);l=(d=+u(+r))*+u(+c),d*=+f(+c),c=+f(+r),a[m>>3]=l,a[m+8>>3]=d,a[m+16>>3]=c,a[s>>3]=l;do{if(2146435072&~i[s+4>>2]&&(a[s>>3]=c,e=0|i[s+4>>2],a[s>>3]=d,!(!(2146435072&~i[s+4>>2])|!0&!(2146435072&~e)))){if(i[o>>2]=i[m>>2],i[o+4>>2]=i[m+4>>2],i[o+8>>2]=i[m+8>>2],i[o+12>>2]=i[m+12>>2],i[o+16>>2]=i[m+16>>2],i[o+20>>2]=i[m+20>>2],ce(o,t,p),p=0|ke(p,t),m=0|S(),i[n>>2]=p,i[n+4>>2]=m,!(!(0|p)&!(0|m))){h=0;break}M(27634,27225,1073,27248)}else h=2}while(0);return N=A,0|(m=h)}function Oe(e,t,n){var r,a,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0;if(a=(n|=0)+4|0,p=0|Vt(0|(e|=0),0|(t|=0),52),S(),p&=15,h=0|Vt(0|e,0|t,45),S(),s=!(0|p),0|G(127&h)){if(s)return 0|(p=1);s=1}else{if(s)return 0|(p=0);s=0|i[a>>2]||0|i[n+8>>2]?1:1&!!(0|i[n+12>>2])}for(h=n+8|0,r=n+12|0,d=1,n=0|i[a>>2],l=0|i[h>>2],A=0|i[r>>2];o=3*n|0,c=3*l|0,f=3*A|0,1&d?(u=l+o|0,i[a>>2]=u,A=A+c|0,i[h>>2]=A,o=f+n|0,i[r>>2]=o,n=A-u|0,l=o-u|0,(0|u)<0?(i[h>>2]=n,i[r>>2]=l,i[a>>2]=0,c=0,o=l):(n=A,c=u),l=c-n|0,A=o-n|0,(0|n)<0?(i[a>>2]=l,i[r>>2]=A,i[h>>2]=0,c=l,o=0):(A=o,o=n),n=c-A|0,l=o-A|0,(0|A)<0?(i[a>>2]=n,i[h>>2]=l,i[r>>2]=0,A=0):(l=o,n=c),(0|(o=(0|A)<(0|(o=(0|l)<(0|n)?l:n))?A:o))>0&&(A=A-o|0,l=l-o|0,n=n-o|0,i[a>>2]=n,i[h>>2]=l,i[r>>2]=A)):(u=c+n|0,c=A+o|0,i[a>>2]=c,i[h>>2]=u,o=f+l|0,i[r>>2]=o,n=u-c|0,A=o-c|0,(0|c)<0?(i[h>>2]=n,i[r>>2]=A,i[a>>2]=0,c=0,o=A):n=u,l=c-n|0,A=o-n|0,(0|n)<0?(i[a>>2]=l,i[r>>2]=A,i[h>>2]=0,c=l,o=0):(A=o,o=n),n=c-A|0,l=o-A|0,(0|A)<0?(i[a>>2]=n,i[h>>2]=l,i[r>>2]=0,A=0):(l=o,n=c),(0|(o=(0|A)<(0|(o=(0|l)<(0|n)?l:n))?A:o))>0&&(A=A-o|0,l=l-o|0,n=n-o|0,i[a>>2]=n,i[h>>2]=l,i[r>>2]=A)),o=0|Vt(0|e,0|t,3*(15-d|0)|0),S(),((o&=7)+-1|0)>>>0<6&&(u=0|i[22032+(12*o|0)+4>>2],f=0|i[22032+(12*o|0)+8>>2],c=(0|i[22032+(12*o|0)>>2])+n|0,i[a>>2]=c,l=u+l|0,i[h>>2]=l,n=f+A|0,i[r>>2]=n,A=l-c|0,o=n-c|0,(0|c)<0&&(i[h>>2]=A,i[r>>2]=o,i[a>>2]=0,c=0,n=o,l=A),o=c-l|0,A=n-l|0,(0|l)<0?(i[a>>2]=o,i[r>>2]=A,i[h>>2]=0,c=o,l=0):A=n,n=c-A|0,o=l-A|0,(0|A)<0?(i[a>>2]=n,i[h>>2]=o,i[r>>2]=0,l=o,A=0):n=c,(0|(o=(0|A)<(0|(o=(0|l)<(0|n)?l:n))?A:o))>0&&(A=A-o|0,l=l-o|0,n=n-o|0,i[a>>2]=n,i[h>>2]=l,i[r>>2]=A)),d>>>0<p>>>0;)d=d+1|0;return 0|s}function Fe(e,t,n){n|=0;var r,a,s,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0;if(s=N,N=N+16|0,a=s,h=0|Vt(0|(e|=0),0|(t|=0),45),S(),(h&=127)>>>0>121)return i[n>>2]=0,i[n+4>>2]=0,i[n+8>>2]=0,i[n+12>>2]=0,N=s,0|(p=5);e:do{if(0|G(h)&&(u=0|Vt(0|e,0|t,52),S(),u&=15,0|u)){o=1;t:for(;;){switch(p=0|Vt(0|e,0|t,3*(15-o|0)|0),S(),7&p){case 5:break t;case 0:break;default:d=t;break e}if(!(o>>>0<u>>>0)){d=t;break e}o=o+1|0}for(c=1,o=t;;){switch(A=e&~(A=0|jt(7,0,0|(t=3*(15-c|0)|0))),l=o&~S(),o=0|Vt(0|e,0|o,0|t),S(),7&o){case 1:o=3;break;case 3:o=2;break;case 2:o=6;break;case 6:o=4;break;case 4:o=5;break;case 5:o=1;break;default:o&=7}if(e=0|jt(0|o,0,0|t),e|=A,o=0|S()|l,!(c>>>0<u>>>0)){d=o;break e}c=c+1|0}}else d=t}while(0);if(p=7696+(28*h|0)|0,i[n>>2]=i[p>>2],i[n+4>>2]=i[p+4>>2],i[n+8>>2]=i[p+8>>2],i[n+12>>2]=i[p+12>>2],!(0|Oe(e,d,n)))return N=s,0|(p=0);if(p=n+4|0,i[a>>2]=i[p>>2],i[a+4>>2]=i[p+4>>2],i[a+8>>2]=i[p+8>>2],f=0|Vt(0|e,0|d,52),S(),r=15&f,1&f?(l=0|i[p>>2],o=(3*(A=0|i[(u=n+8|0)>>2])|0)+l|0,l=(t=0|i[(f=n+12|0)>>2])+(3*l|0)|0,i[p>>2]=l,i[u>>2]=o,A=(3*t|0)+A|0,i[f>>2]=A,t=o-l|0,c=A-l|0,(0|l)<0&&(i[u>>2]=t,i[f>>2]=c,i[p>>2]=0,o=t,l=0,A=c),c=l-o|0,t=A-o|0,(0|o)<0?(i[p>>2]=c,i[f>>2]=t,i[u>>2]=0,o=0):(t=A,c=l),l=c-t|0,A=o-t|0,(0|t)<0?(i[p>>2]=l,i[u>>2]=A,i[f>>2]=0,t=0):(A=o,l=c),(0|(o=(0|t)<(0|(o=(0|A)<(0|l)?A:l))?t:o))>0&&(i[p>>2]=l-o,i[u>>2]=A-o,i[f>>2]=t-o),A=r+1|0):A=r,0|G(h)){e:do{if(r)for(t=1;;){if(o=0|Vt(0|e,0|d,3*(15-t|0)|0),S(),0|(o&=7))break e;if(!(t>>>0<r>>>0)){o=0;break}t=t+1|0}else o=0}while(0);o=4==(0|o)&1}else o=0;if(0|pe(n,A,o,0)){if(0|G(h))do{}while(0|pe(n,A,0,0));(0|A)!=(0|r)&&(e=0|i[(u=n+12|0)>>2],t=0|St(.14285714285714285*+(((o=(0|i[p>>2])-e|0)<<1)+(e=(0|i[(c=n+8|0)>>2])-e|0)|0)),i[p>>2]=t,o=0|St(.14285714285714285*+((3*e|0)-o|0)),i[c>>2]=o,i[u>>2]=0,e=o-t|0,A=0-t|0,(0|t)<0?(i[c>>2]=e,i[u>>2]=A,i[p>>2]=0,o=e,t=0):A=0,l=t-o|0,e=A-o|0,(0|o)<0?(i[p>>2]=l,i[u>>2]=e,i[c>>2]=0,t=l,o=0):e=A,l=t-e|0,A=o-e|0,(0|e)<0?(i[p>>2]=l,i[c>>2]=A,i[u>>2]=0,t=l,e=0):A=o,(0|(o=(0|e)<(0|(o=(0|A)<(0|t)?A:t))?e:o))>0&&(i[p>>2]=t-o,i[c>>2]=A-o,i[u>>2]=e-o))}else(0|A)!=(0|r)&&(i[p>>2]=i[a>>2],i[p+4>>2]=i[a+4>>2],i[p+8>>2]=i[a+8>>2]);return N=s,0|(p=0)}function De(e,t,n){n|=0;var r,i,s,o=0,A=0,l=0;return s=N,N=N+48|0,i=s,(o=0|Fe(e|=0,t|=0,r=s+24|0))?(N=s,0|o):(o=0|Vt(0|e,0|t,52),S(),ue(r,15&o,i),l=+p(+ +a[i+16>>3]),A=+g(+ +a[i+8>>3],+ +a[i>>3]),a[n>>3]=l,a[n+8>>3]=A,N=s,0|(o=0))}function Ue(e,t,n){n|=0;var r,i=0,a=0,s=0;if(r=N,N=N+16|0,0|(i=0|Fe(e|=0,t|=0,s=r)))return N=r,0|(s=i);i=0|Vt(0|e,0|t,45),S(),i=!(0|G(127&i)),a=0|Vt(0|e,0|t,52),S(),a&=15;e:do{if(!i){if(0|a)for(i=1;;){if(!(!((0|jt(7,0,3*(15-i|0)|0))&e|0)&!((0|S())&t)))break e;if(!(i>>>0<a>>>0))break;i=i+1|0}return de(s,a,0,5,n),N=r,0|0}}while(0);return ge(s,a,0,6,n),N=r,0|0}function Ve(e,t){t|=0;var n=0,r=0,a=0,s=0,o=0,A=0,l=0;if((e|=0)>>>0>15)return 0|(A=4);if(jt(0|e,0,52),A=134225919|S(),!e){n=0,r=0;do{0|G(r)&&(jt(0|r,0,45),o=0|A|S(),i[(e=t+(n<<3)|0)>>2]=-1,i[e+4>>2]=o,n=n+1|0),r=r+1|0}while(122!=(0|r));return 0|(n=0)}n=0,o=0;do{if(0|G(o)){for(jt(0|o,0,45),r=1,a=-1,s=0|A|S();a&=~(l=0|jt(7,0,3*(15-r|0)|0)),s&=~S(),(0|r)!=(0|e);)r=r+1|0;i[(l=t+(n<<3)|0)>>2]=a,i[l+4>>2]=s,n=n+1|0}o=o+1|0}while(122!=(0|o));return 0|(n=0)}function je(e,t,n,r){e|=0,r|=0;var a=0,s=0,o=0;a=0|Vt(0|(t|=0),0|(n|=0),52),S(),!(0|t)&!(0|n)|(0|r)>15|(0|(a&=15))>(0|r)?(s=-1,t=-1,n=0,a=0):(t=0|Me(t,n,a+1|0,r),o=-15728641&S(),n=0|jt(0|r,0,52),s=a,t=(t=!(0|Se(n|=t,o=0|o|S())))?-1:r,a=o),i[(o=e)>>2]=n,i[o+4>>2]=a,i[e+8>>2]=s,i[e+12>>2]=t}function ze(e,t,n,r){n|=0,r|=0;var a=0,s=0;return a=0|Vt(0|(e|=0),0|(t|=0),52),S(),a&=15,i[(s=r+8|0)>>2]=a,!(0|e)&!(0|t)|(0|n)>15|(0|a)>(0|n)?(i[(n=r)>>2]=0,i[n+4>>2]=0,i[s>>2]=-1,void(i[r+12>>2]=-1)):(e=0|Me(e,t,a+1|0,n),s=-15728641&S(),a=0|jt(0|n,0,52),a|=e,s=0|s|S(),i[(e=r)>>2]=a,i[e+4>>2]=s,e=r+12|0,0|Se(a,s)?void(i[e>>2]=n):void(i[e>>2]=-1))}function Ge(e){var t,n=0,r=0,a=0,s=0,o=0,A=0,l=0,c=0;if(!(!(0|(n=0|i[(r=e|=0)>>2]))&!(0|(r=0|i[r+4>>2]))||(a=0|Vt(0|n,0|r,52),S(),n=0|Pt(0|(l=0|jt(1,0,3*(15^(a&=15))|0)),0|S(),0|n,0|r),r=0|S(),i[(l=e)>>2]=n,i[l+4>>2]=r,(0|a)<(0|(A=0|i[(l=e+8|0)>>2]))))){for(t=e+12|0,o=a;;){if((0|o)==(0|A)){a=5;break}if(c=(0|o)==(0|i[t>>2]),a=0|Vt(0|n,0|r,0|(s=3*(15-o|0)|0)),S(),c&1==(0|(a&=7))&!0){a=7;break}if(!(7==(0|a)&!0)){a=10;break}if(n=0|Pt(0|n,0|r,0|(c=0|jt(1,0,0|s)),0|S()),r=0|S(),i[(c=e)>>2]=n,i[c+4>>2]=r,!((0|o)>(0|A))){a=10;break}o=o+-1|0}if(5==(0|a))return i[(c=e)>>2]=0,i[c+4>>2]=0,i[l>>2]=-1,void(i[t>>2]=-1);if(7==(0|a))return A=0|Pt(0|n,0|r,0|(A=0|jt(1,0,0|s)),0|S()),l=0|S(),i[(c=e)>>2]=A,i[c+4>>2]=l,void(i[t>>2]=o+-1)}}function He(e){var t;return t=(e=+e)<0?e+6.283185307179586:e,+(e>=6.283185307179586?t+-6.283185307179586:t)}function qe(e,t){switch(e=+e,0|(t|=0)){case 1:e=e<0?e+6.283185307179586:e;break;case 2:e=e>0?e+-6.283185307179586:e}return+e}function Qe(e,t){e|=0;var n,r,i,s=0;return r=+a[(t|=0)>>3],n=+a[e>>3],s=(i=+f(.5*(r-n)))*i+(s=+f(.5*(+a[t+8>>3]-+a[e+8>>3])))*(+u(+r)*+u(+n)*s),2*+g(+ +c(+s),+ +c(+(1-s)))*6371.007180918475}function Ke(e,t){return t|=0,(e|=0)>>>0>15?0|(t=4):(a[t>>3]=+a[20624+(e<<3)>>3],0|(t=0))}function We(e,t){t|=0;var n=0;return(e|=0)>>>0>15?0|(t=4):(n=0|Ot(0|(n=0|Ze(7,0,e,((0|e)<0)<<31>>31)),0|S(),120,0),e=0|S(),i[t>>2]=2|n,i[t+4>>2]=e,0|(t=0))}function Je(e,t,n,a,s){n|=0,a|=0,s|=0;var o,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0;if(o=N,N=N+16|0,v=o,d=0|Vt(0|(e|=0),0|(t|=0),52),S(),d&=15,m=0|Vt(0|n,0|a,52),S(),(0|d)!=(15&m))return N=o,0|(v=12);if(u=0|Vt(0|e,0|t,45),S(),u&=127,f=0|Vt(0|n,0|a,45),S(),u>>>0>121|(f&=127)>>>0>121)return N=o,0|(v=5);if(m=(0|u)!=(0|f)){if(7==(0|(l=0|J(u,f))))return N=o,0|(v=1);7==(0|(c=0|J(f,u)))?M(27291,27315,164,27325):(b=l,A=c)}else b=0,A=0;h=0|G(u),p=0|G(f),i[v>>2]=0,i[v+4>>2]=0,i[v+8>>2]=0,i[v+12>>2]=0;do{if(b){l=(0|(f=0|i[4272+(28*u|0)+(b<<2)>>2]))>0;e:do{if(p)if(l)for(u=0,c=n,l=a;;){switch(c=0|Pe(c,l),l=0|S(),0|A){case 5:case 1:A=3;break;case 3:A=2;break;case 2:A=6;break;case 6:A=4;break;case 4:A=5}if((0|(u=u+1|0))==(0|f)){f=A,u=c,c=l;break e}}else f=A,u=n,c=a;else if(l)for(u=0,c=n,l=a;;){switch(c=0|Ne(c,l),l=0|S(),0|A){case 1:A=3;break;case 3:A=2;break;case 2:A=6;break;case 6:A=4;break;case 4:A=5;break;case 5:A=1}if((0|(u=u+1|0))==(0|f)){f=A,u=c,c=l;break e}}else f=A,u=n,c=a}while(0);if(Oe(u,c,v),m||M(27340,27315,194,27325),(l=!!(0|h))&(A=!!(0|p))&&M(27367,27315,195,27325),l){if(7==(0|(A=0|Ce(e,t)))){A=5;break}if(0|r[21968+(7*A|0)+b|0]){A=1;break}m=p=0|i[21136+(28*A|0)+(b<<2)>>2]}else if(A){if(7==(0|(A=0|Ce(u,c)))){A=5;break}if(0|r[21968+(7*A|0)+f|0]){A=1;break}m=0,p=0|i[21136+(28*f|0)+(A<<2)>>2]}else m=0,p=0;if((m|p|0)>=0){if((0|p)>0){a=v+8|0,h=v+12|0,f=0,c=0|i[(n=v+4|0)>>2],l=0|i[a>>2],A=0|i[h>>2];do{(0|(u=(0|(A=(y=(0|(c=A+c-(y=(t=(0|(g=l+c|0))<0)?g:0)-(u=(e=(0|(l=A+l-y|0))<0)?l:0)|0))<0)?0:c))<(0|(u=(0|(l=(e?0:l)-(c=y?c:0)|0))<(0|(c=(t?0:g)-u-c|0))?l:c))?A:u))>0&&(c=c-u|0,l=l-u|0,A=A-u|0),f=f+1|0}while((0|f)!=(0|p));i[n>>2]=c,i[a>>2]=l,i[h>>2]=A}if((b+-1|0)>>>0<6?(A=0|i[22032+(12*b|0)>>2],c=0|i[22032+(12*b|0)+4>>2],A=A-(l=(0|(l=(0|(y=0|i[22032+(12*b|0)+8>>2]))<(0|(l=(0|c)<(0|A)?c:A))?y:l))>0?l:0)|0,c=c-l|0,l=y-l|0):(A=0,c=0,l=0),d)for(;;){if(u=3*A|0,f=3*c|0,n=3*l|0,0|Le(d)?(A=(y=(0|(l=(0|(b=(l=(0|(c=A+n-((e=(0|(t=u+c|0))<0)?t:0)-((g=(0|(y=f+l-(e?t:0)|0))<0)?y:0)|0))<0)?0:c))<(0|(l=(0|(u=(g?0:y)-(l?c:0)|0))<(0|(c=(e?0:t)-(g?y:0)-(l?c:0)|0))?u:c))?b:l))>0)?l:0,u=u-(y?l:0)|0,l=b-(y?l:0)|0):(A=(y=(0|(l=(0|(b=(l=(0|(c=n+c-((t=(0|(g=u+l|0))<0)?g:0)-((A=(0|(y=f+A-(t?g:0)|0))<0)?y:0)|0))<0)?0:c))<(0|(l=(0|(u=(A?0:y)-(l?c:0)|0))<(0|(c=(t?0:g)-(A?y:0)-(l?c:0)|0))?u:c))?b:l))>0)?l:0,u=u-(y?l:0)|0,l=b-(y?l:0)|0),A=c-A|0,!((0|d)>1)){c=u;break}d=d+-1|0,c=u}if((0|m)>0){u=0;do{l=(l=(A=(0|(b=A+l-((e=(0|(t=A+c|0))<0)?t:0)-((g=(0|(y=c+l-(e?t:0)|0))<0)?y:0)|0))<0)?0:b)-((y=(0|(A=(0|l)<(0|(A=(0|(c=(g?0:y)-(A?b:0)|0))<(0|(b=(e?0:t)-(g?y:0)-(A?b:0)|0))?c:b))?l:A))>0)?A:0)|0,c=c-(y?A:0)|0,A=b-(y?A:0)|0,u=u+1|0}while((0|u)!=(0|m))}n=v+4|0,b=0|i[(d=v+8|0)>>2],y=0|i[(a=v+12|0)>>2],u=(0|i[n>>2])+A|0,i[n>>2]=u,c=b+c|0,i[d>>2]=c,A=y+l|0,i[a>>2]=A,l=c-u|0,(0|u)<0?(A=A-u|0,i[d>>2]=l,i[a>>2]=A,i[n>>2]=0,c=0):(l=c,c=u),(0|l)<0&&(c=c-l|0,i[n>>2]=c,A=A-l|0,i[a>>2]=A,i[d>>2]=0,l=0),f=c-A|0,u=l-A|0,(0|A)<0?(i[n>>2]=f,i[d>>2]=u,i[a>>2]=0,c=f,A=0):u=l,(0|(l=(0|A)<(0|(l=(0|u)<(0|c)?u:c))?A:l))>0?(i[n>>2]=c-l,i[d>>2]=u-l,i[a>>2]=A-l,g=77):g=77}else A=5}else if(Oe(n,a,v),!!(0|h)&!!(0|p))if((0|f)!=(0|u)&&M(27398,27315,264,27325),7==(0|(l=0|Ce(e,t)))|7==(0|(A=0|Ce(n,a))))A=5;else if(0|r[21968+(7*l|0)+A|0])A=1;else if((0|(n=0|i[21136+(28*l|0)+(A<<2)>>2]))>0){a=v+8|0,h=v+12|0,f=0,c=0|i[(d=v+4|0)>>2],l=0|i[a>>2],A=0|i[h>>2];do{(0|(u=(0|(A=(e=(0|(c=A+c-(e=(g=(0|(b=l+c|0))<0)?b:0)-(u=(t=(0|(l=A+l-e|0))<0)?l:0)|0))<0)?0:c))<(0|(u=(0|(l=(t?0:l)-(c=e?c:0)|0))<(0|(c=(g?0:b)-u-c|0))?l:c))?A:u))>0&&(c=c-u|0,l=l-u|0,A=A-u|0),f=f+1|0}while((0|f)!=(0|n));i[d>>2]=c,i[a>>2]=l,i[h>>2]=A,g=77}else g=77;else g=77}while(0);return 77==(0|g)&&(A=v+4|0,i[s>>2]=i[A>>2],i[s+4>>2]=i[A+4>>2],i[s+8>>2]=i[A+8>>2],A=0),N=o,0|(y=A)}function $e(e,t,n,r){n|=0,r|=0;var a=0,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0,w=0,T=0,E=0;if(s=0|Vt(0|(e|=0),0|(t|=0),52),S(),s&=15,x=0|Vt(0|e,0|t,45),S(),(x&=127)>>>0>121)return 0|(r=5);if(g=0|G(x),jt(0|s,0,52),A=134225919|S(),i[(o=r)>>2]=-1,i[o+4>>2]=A,o=0|i[n>>2],A=0|i[n+4>>2],n=0|i[n+8>>2],!s){a=(a=(n=(0|(b=n-(b=(t=(0|o)<0)?o:0)+((g=(0|(y=A-b|0))<0)?0-y|0:0)|0))<0)?0:b)-(y=(0|(y=(0|a)<(0|(y=(0|(n=(g?0:y)-(b=n?b:0)|0))<(0|(b=(t?0:o)-(g?y:0)-b|0))?n:b))?a:y))>0?y:0)|0,n=n-y|0;e:do{switch(b-y|0){case 0:switch(0|n){case 0:if(a){a=1==(0|a)?1:7,v=11;break e}a=0;break e;case 1:if(a){a=1==(0|a)?3:7,v=11;break e}a=2;break e;default:return 0|(r=1)}case 1:switch(0|n){case 0:if(a){a=1==(0|a)?5:7,v=11;break e}a=4;break e;case 1:if(!a){a=6;break e}return 0|(a=1);default:return 0|(r=1)}default:return 0|(r=1)}}while(0);return 11==(0|v)&&7==(0|a)||127==(0|(a=0|W(x,a)))?0|(r=1):(y=0|jt(0|a,0,45),x=0|S(),x=-1040385&i[(v=r)+4>>2]|x,i[r>>2]=i[v>>2]|y,i[r+4>>2]=x,0|(r=0))}for(;;){if(m=s,s=s+-1|0,l=(p=o-n|0)>>>0>715827881|(h=A-n|0)>>>0>715827881,0|Le(m)){if(l){if(f=2147483647-p|0,d=-2147483648-p|0,(u=(0|p)>0)?(0|f)<(0|p):(0|d)>(0|p)){a=1,v=107;break}if(E=p<<1,u?(2147483647-E|0)<(0|p):(-2147483648-E|0)>(0|p)){a=1,v=107;break}if((0|h)>0?(2147483647-h|0)<(0|h):(-2147483648-h|0)>(0|h)){a=1,v=107;break}if(l=3*p|0,c=h<<1,(u?(0|f)<(0|c):(0|d)>(0|c))||((0|p)>-1?(-2147483648|l)>=(0|h):(-2147483648^l)<(0|h))){a=1,v=107;break}}else l=3*p|0,c=h<<1;if(f=0|St(.14285714285714285*+(l-h|0)),l=(c=(0|(u=0|St(.14285714285714285*+(c+p|0))))<(0|f))?f:u,(0|(c=c?u:f))<0){if(-2147483648==(0|c)||((0|l)>0?(2147483647-l|0)<(0|c):(-2147483648-l|0)>(0|c))){v=24;break}if((0|l)>-1?(-2147483648|l)>=(0|c):(-2147483648^l)<(0|c)){v=24;break}}d=((d=(0|f)<0)?0:f)-((w=(0|(h=u-(d?f:0)|0))<0)?h:0)-((p=(0|(_=(d?0-f|0:0)-(w?h:0)|0))<0)?_:0)|0,h=(w?0:h)-(p?_:0)|0,d=d-((w=(0|(p=(0|(_=p?0:_))<(0|(p=(0|h)<(0|d)?h:d))?_:p))>0)?p:0)|0,h=h-(w?p:0)|0,l=(E=(0|(u=(0|(T=(u=(0|(f=(3*(p=_-(w?p:0)|0)|0)+d-((_=(0|(w=(3*d|0)+h|0))<0)?w:0)-((l=(0|(E=(3*h|0)+p-(_?w:0)|0))<0)?E:0)|0))<0)?0:f))<(0|(u=(0|(c=(l?0:E)-(u?f:0)|0))<(0|(f=(_?0:w)-(l?E:0)-(u?f:0)|0))?c:f))?T:u))>0)?u:0,c=c-(E?u:0)|0,u=T-(E?u:0)|0}else{if(l){if((c=(0|p)>0)?(2147483647-p|0)<(0|p):(-2147483648-p|0)>(0|p)){a=1,v=107;break}if(l=p<<1,(u=(0|h)>0)?(2147483647-h|0)<(0|h):(-2147483648-h|0)>(0|h)){a=1,v=107;break}if(d=h<<1,u?(2147483647-d|0)<(0|h):(-2147483648-d|0)>(0|h)){a=1,v=107;break}if(c?(2147483647-l|0)<(0|h):(-2147483648-l|0)>(0|h)){a=1,v=107;break}if(c=3*h|0,(0|h)>-1?(-2147483648|c)>=(0|p):(-2147483648^c)<(0|p)){a=1,v=107;break}}else l=p<<1,c=3*h|0;if(f=0|St(.14285714285714285*+(l+h|0)),l=(c=(0|(u=0|St(.14285714285714285*+(c-p|0))))<(0|f))?f:u,(0|(c=c?u:f))<0){if(-2147483648==(0|c)||((0|l)>0?(2147483647-l|0)<(0|c):(-2147483648-l|0)>(0|c))){v=36;break}if((0|l)>-1?(-2147483648|l)>=(0|c):(-2147483648^l)<(0|c)){v=36;break}}d=((d=(0|f)<0)?0:f)-((T=(0|(h=u-(d?f:0)|0))<0)?h:0)-((p=(0|(E=(d?0-f|0:0)-(T?h:0)|0))<0)?E:0)|0,h=(T?0:h)-(p?E:0)|0,d=d-((T=(0|(p=(0|(E=p?0:E))<(0|(p=(0|h)<(0|d)?h:d))?E:p))>0)?p:0)|0,h=h-(T?p:0)|0,l=(_=(0|(u=(0|(w=(u=(0|(f=(3*(p=E-(T?p:0)|0)|0)+h-((E=(0|(T=(3*d|0)+p|0))<0)?T:0)-((l=(0|(_=(3*h|0)+d-(E?T:0)|0))<0)?_:0)|0))<0)?0:f))<(0|(u=(0|(c=(l?0:_)-(u?f:0)|0))<(0|(f=(E?0:T)-(l?_:0)-(u?f:0)|0))?c:f))?w:u))>0)?u:0,c=c-(_?u:0)|0,u=w-(_?u:0)|0}u=(o=(0|(_=n-u+((T=(0|(l=o+(l-f)|0))<0)?0-l|0:0)+((f=(0|(c=A-c-(T?l:0)|0))<0)?0-c|0:0)|0))<0)?0:_,E=(f?0:c)-(o?_:0)|0,_=(_=(T?0:l)-(f?c:0)-(o?_:0)|0)-((n=(0|(o=(0|u)<(0|(o=(0|E)<(0|_)?E:_))?u:o))>0)?o:0)|0,f=0|i[(c=r)>>2],c=0|i[c+4>>2],l=f&~(l=0|jt(7,0,0|(A=3*(15-m|0)|0))),c&=~S(),n=(n=(o=(0|(T=u-(n?o:0)-(T=(f=(0|_)<0)?_:0)+((w=(0|(E=E-(n?o:0)-T|0))<0)?0-E|0:0)|0))<0)?0:T)-(E=(0|(E=(0|n)<(0|(E=(0|(o=(w?0:E)-(T=o?T:0)|0))<(0|(T=(f?0:_)-(w?E:0)-T|0))?o:T))?n:E))>0?E:0)|0,o=o-E|0;e:do{switch(T-E|0){case 0:switch(0|o){case 0:n=0|n?1==(0|n)?1:7:0;break e;case 1:n=0|n?1==(0|n)?3:7:2;break e;default:v=45;break e}case 1:switch(0|o){case 0:n=0|n?1==(0|n)?5:7:4;break e;case 1:if(n){v=45;break e}n=6;break e;default:v=45;break e}default:v=45}}while(0);if(45==(0|v)&&(v=0,n=7),w=0|jt(0|n,0,0|A),T=0|S()|c,i[(E=r)>>2]=w|l,i[E+4>>2]=T,(0|m)<=1){v=47;break}o=d,A=h,n=p}if(24==(0|v))M(27634,27425,416,27447);else if(36==(0|v))M(27634,27425,464,27461);else{if(47==(0|v)){if((0|d)>1|(0|h)>1|(0|p)>1)return 0|(E=1);n=(n=(s=(0|(T=p-(T=(_=(0|d)<0)?d:0)+((w=(0|(E=h-T|0))<0)?0-E|0:0)|0))<0)?0:T)-(E=(0|(E=(0|n)<(0|(E=(0|(s=(w?0:E)-(T=s?T:0)|0))<(0|(T=(_?0:d)-(w?E:0)-T|0))?s:T))?n:E))>0?E:0)|0,s=s-E|0;e:do{switch(T-E|0){case 0:switch(0|s){case 0:s=0|n?1==(0|n)?1:7:0;break e;case 1:s=0|n?1==(0|n)?3:7:2;break e;default:v=55;break e}case 1:switch(0|s){case 0:s=0|n?1==(0|n)?5:7:4;break e;case 1:if(n){v=55;break e}s=6;break e;default:v=55;break e}default:v=55}}while(0);55==(0|v)&&(s=7),c=127==(0|(A=0|W(x,s)))?0:0|G(A);e:do{if(s){if(g){if(7==(0|(n=0|Ce(e,t))))return 0|(E=5);o=0|i[21344+(28*n|0)+(s<<2)>>2];t:do{if((0|o)>0)for(n=s,s=0;;){switch(0|n){case 1:n=5;break;case 5:n=4;break;case 4:n=6;break;case 6:n=2;break;case 2:n=3;break;case 3:n=1}if((0|(s=s+1|0))==(0|o))break t}else n=s}while(0);if(1==(0|n))return 0|(E=9);127==(0|(s=0|W(x,n)))&&M(27476,27315,415,27506),0|G(s)?M(27521,27315,416,27506):(a=s,y=o,b=n)}else a=A,y=0,b=s;if((0|(l=0|i[4272+(28*x|0)+(b<<2)>>2]))<=-1&&M(27552,27315,423,27506),!c){if((0|y)<0)return 0|(E=5);if(0|y){n=0,s=0|i[(o=r)>>2],o=0|i[o+4>>2];do{s=0|Re(s,o),o=0|S(),i[(E=r)>>2]=s,i[E+4>>2]=o,n=n+1|0}while((0|n)<(0|y))}if((0|l)<=0){v=104;break}for(n=0,s=0|i[(o=r)>>2],o=0|i[o+4>>2];;)if(s=0|Re(s,o),o=0|S(),i[(E=r)>>2]=s,i[E+4>>2]=o,(0|(n=n+1|0))==(0|l)){v=104;break e}}if(7==(0|(A=0|J(a,x)))&&M(27291,27315,432,27506),s=0|i[(n=r)>>2],n=0|i[n+4>>2],(0|l)>0){o=0;do{s=0|Re(s,n),n=0|S(),i[(E=r)>>2]=s,i[E+4>>2]=n,o=o+1|0}while((0|o)!=(0|l))}if(7==(0|(n=0|Ce(s,n)))&&M(27634,27315,444,27506),s=0|H(a),(0|(s=0|i[(s?21760:21552)+(28*A|0)+(n<<2)>>2]))<0&&M(27634,27315,458,27506),s){n=0,o=0|i[(A=r)>>2],A=0|i[A+4>>2];do{o=0|Ie(o,A),A=0|S(),i[(E=r)>>2]=o,i[E+4>>2]=A,n=n+1|0}while((0|n)<(0|s));v=104}else v=104}else if(!!(0|g)&!!(0|c)){if(7==(0|(a=0|Ce(e,t)))|7==(0|(n=0|Ce(0|i[(n=r)>>2],0|i[n+4>>2]))))return 0|(E=5);if((0|(n=0|i[21344+(28*a|0)+(n<<2)>>2]))<0)return 0|(E=5);if(n){a=0,s=0|i[(o=r)>>2],o=0|i[o+4>>2];do{s=0|Re(s,o),o=0|S(),i[(E=r)>>2]=s,i[E+4>>2]=o,a=a+1|0}while((0|a)<(0|n));a=A,v=104}else a=A,v=105}else a=A,v=104}while(0);return 104==(0|v)&&c&&(v=105),105==(0|v)&&1==(0|Ce(0|i[(E=r)>>2],0|i[E+4>>2]))?0|(E=9):(_=0|i[(T=r)>>2],T=-1040385&i[T+4>>2],w=0|jt(0|a,0,45),T=0|T|S(),i[(E=r)>>2]=_|w,i[E+4>>2]=T,0|(E=0))}if(107==(0|v))return 0|a}return 0}function Xe(e,t,n,r,a){n|=0,r|=0,a|=0;var s,o,A=0,l=0,c=0;return s=N,N=N+32|0,c=s,0|(A=0|Je(e|=0,t|=0,e,t,l=s+12|0))?(N=s,0|(c=A)):0|(e=0|Je(e,t,n,r,c))?(N=s,0|(c=e)):(t=(0|(n=(r=(o=(0|(e=(0|i[l>>2])-(0|i[c>>2])|0))<0)?0-e|0:0)+((0|i[l+4>>2])-(0|i[c+4>>2]))|0))<0,l=(l=(A=(0|(r=(0|i[l+8>>2])-(0|i[c+8>>2])+r+(t?0-n|0:0)|0))<0)?0:r)-(c=(0|(c=(0|l)<(0|(c=(0|(A=(t?0:n)-(r=A?r:0)|0))<(0|(r=(o?0:e)-(t?n:0)-r|0))?A:r))?l:c))>0?c:0)|0,A=A-c|0,l=(0|(c=(0|(c=r-c|0))>-1?c:0-c|0))>(0|(l=(0|(A=(0|A)>-1?A:0-A|0))>(0|(l=(0|l)>-1?l:0-l|0))?A:l))?c:l,i[(c=a)>>2]=l,i[c+4>>2]=((0|l)<0)<<31>>31,N=s,0|(c=0))}function Ye(e,t,n,r,a,s,o,A,c,u,f){e|=0,t|=0,n|=0,r|=0,a|=0,s|=0,o|=0,A|=0,c|=0,u|=0,f|=0;var d,h,p,m,g,b,v,y=0,x=0,_=0,w=0,T=0,E=0,C=0,I=0,R=0,P=0,k=0;if(v=N,N=N+48|0,x=v+12|0,b=v,i[(y=v+24|0)>>2]=0,i[y+4>>2]=0,i[y+8>>2]=0,i[x>>2]=0,i[x+4>>2]=0,i[x+8>>2]=0,0|Je(e,t,e,t,y)&&M(27634,27315,696,27575),0|Je(e,t,n,r,x)&&M(27634,27315,701,27575),n=(r=0|i[(T=y+8|0)>>2])-(0|i[y>>2])|0,i[y>>2]=n,r=(0|i[(P=y+4|0)>>2])-r|0,i[P>>2]=r,y=0-(P=r+n|0)|0,i[T>>2]=y,E=(C=0|i[(T=x+8|0)>>2])-(0|i[x>>2])|0,i[x>>2]=E,C=(0|i[(R=x+4|0)>>2])-C|0,i[R>>2]=C,R=C+E|0,i[T>>2]=0-R,m=(I=1/(+(a>>>0)+4294967296*+(0|s)))*+(E-n|0),g=I*+(C-r|0),I*=+(P-R|0),i[b>>2]=n,i[(R=b+4|0)>>2]=r,i[(P=b+8|0)>>2]=y,(0|s)<0)return N=v,0|(u=0);for(p=+(0|n),h=+(0|r),d=+(0|y),E=0,C=0;;){if(k=m*(w=+(E>>>0)+4294967296*+(0|C))+p,_=g*w+h,w=I*w+d,r=~~+qt(+k),y=~~+qt(+_),n=~~+qt(+w),(k=+l(+(+(0|r)-k)))>(_=+l(+(+(0|y)-_)))&k>(w=+l(+(+(0|n)-w)))?r=0-(x=n+y|0)|0:(x=0-r|0,_>w&&(y=x-n|0)),i[R>>2]=y,i[b>>2]=x,i[P>>2]=0,n=r+y|0,(0|r)>0?(i[R>>2]=n,i[P>>2]=r,i[b>>2]=0,x=0):(n=y,r=0),(0|n)<0?(y=x-n|0,i[b>>2]=y,r=r-n|0,i[P>>2]=r,i[R>>2]=0,x=y-r|0,n=0-r|0,(0|r)<0?(i[b>>2]=x,i[R>>2]=n,i[P>>2]=0,T=n,r=0):(T=0,x=y)):T=n,(0|(n=(0|r)<(0|(n=(0|T)<(0|x)?T:x))?r:n))>0&&(i[b>>2]=x-n,i[R>>2]=T-n,i[P>>2]=r-n),n=0|Pt(0|(n=0|Ot(0|E,0|C,0|u,0|f)),0|S(),0|A,0|c),S(),0|(n=0|$e(e,t,b,o+(n<<3)|0))){r=20;break}if(T=E,E=0|Pt(0|E,0|C,1,0),x=C,C=0|S(),!((0|x)<(0|s)|(0|x)==(0|s)&T>>>0<a>>>0)){n=0,r=20;break}}return 20==(0|r)?(N=v,0|n):0}function Ze(e,t,n,r){e|=0,t|=0;var i=0,a=0,s=0;if(!(0|(n|=0))&!(0|(r|=0)))return a=1,T(0|(i=0)),0|a;a=e,i=t,e=1,t=0;do{e=0|Ot(0|((s=!0&!(1&n))?1:a),0|(s?0:i),0|e,0|t),t=0|S(),n=0|Ut(0|n,0|r,1),r=0|S(),a=0|Ot(0|a,0|i,0|a,0|i),i=0|S()}while(!(!(0|n)&!(0|r)));return T(0|t),0|e}function et(e,t,n,r){n|=0,r|=0;var s,o=0,A=0,l=0,c=0,f=0,d=0;s=N,N=N+16|0,A=s,l=0|Vt(0|(e|=0),0|(t|=0),52),S(),l&=15;do{if(l){if(!(o=0|De(e,t,A))){f=+a[A>>3],c=1/+u(+f),d=+a[26032+(l<<3)>>3],a[n>>3]=f+d,a[n+8>>3]=f-d,f=+a[A+8>>3],c*=d,a[n+16>>3]=c+f,a[n+24>>3]=f-c;break}return N=s,0|(l=o)}if(o=0|Vt(0|e,0|t,45),S(),(o&=127)>>>0>121)return N=s,0|(l=5);A=22128+(o<<5)|0,i[n>>2]=i[A>>2],i[n+4>>2]=i[A+4>>2],i[n+8>>2]=i[A+8>>2],i[n+12>>2]=i[A+12>>2],i[n+16>>2]=i[A+16>>2],i[n+20>>2]=i[A+20>>2],i[n+24>>2]=i[A+24>>2],i[n+28>>2]=i[A+28>>2];break}while(0);return function(e,t){t=+t;var n,r,i,s,o,A,l,c=0,u=0;c=(s=+a[(i=16+(e|=0)|0)>>3])-(r=+a[(n=e+24|0)>>3]),c=s<r?c+6.283185307179586:c,u=+a[e>>3],c=.5*(c*t-c),u+=t=.5*((l=u-(A=+a[(o=e+8|0)>>3]))*t-l),a[e>>3]=u>1.5707963267948966?1.5707963267948966:u,t=A-t,a[o>>3]=t<-1.5707963267948966?-1.5707963267948966:t,t=(t=s+c)>3.141592653589793?t+-6.283185307179586:t,a[i>>3]=t<-3.141592653589793?t+6.283185307179586:t,t=(t=r-c)>3.141592653589793?t+-6.283185307179586:t,a[n>>3]=t<-3.141592653589793?t+6.283185307179586:t}(n,r?1.4:1.1),(0|i[(r=26160+(l<<3)|0)>>2])==(0|e)&&(0|i[r+4>>2])==(0|t)&&(a[n>>3]=1.5707963267948966),(0|i[(l=26288+(l<<3)|0)>>2])==(0|e)&&(0|i[l+4>>2])==(0|t)&&(a[n+8>>3]=-1.5707963267948966),1.5707963267948966!=+a[n>>3]&&-1.5707963267948966!=+a[n+8>>3]?(N=s,0|(l=0)):(a[n+16>>3]=3.141592653589793,a[n+24>>3]=-3.141592653589793,N=s,0|(l=0))}function tt(e,t,n,a){e|=0,t|=0,n|=0,a|=0;var s,o,A,l=0,c=0,u=0,f=0;A=N,N=N+48|0,s=A+40|0,o=A,_e(c=A+32|0,0,0,0),u=0|i[c>>2],c=0|i[c+4>>2];do{if(n>>>0<=15){if(0|(l=0|st(a))){i[(a=o)>>2]=0,i[a+4>>2]=0,i[o+8>>2]=l,i[o+12>>2]=-1,u=o+29|0,i[(a=o+16|0)>>2]=0,i[a+4>>2]=0,i[a+8>>2]=0,r[a+12|0]=0,r[u|0]=0|r[s|0],r[u+1|0]=0|r[s+1|0],r[u+2|0]=0|r[s+2|0];break}if(l=0|Ct(1+(0|i[t+8>>2])|0,32)){ot(t,l),i[(f=o)>>2]=u,i[f+4>>2]=c,i[o+8>>2]=0,i[o+12>>2]=n,i[o+16>>2]=a,i[o+20>>2]=t,i[o+24>>2]=l,r[o+28|0]=0,r[(u=o+29|0)|0]=0|r[s|0],r[u+1|0]=0|r[s+1|0],r[u+2|0]=0|r[s+2|0];break}i[(a=o)>>2]=0,i[a+4>>2]=0,i[o+8>>2]=13,i[o+12>>2]=-1,u=o+29|0,i[(a=o+16|0)>>2]=0,i[a+4>>2]=0,i[a+8>>2]=0,r[a+12|0]=0,r[u|0]=0|r[s|0],r[u+1|0]=0|r[s+1|0],r[u+2|0]=0|r[s+2|0];break}i[(u=o)>>2]=0,i[u+4>>2]=0,i[o+8>>2]=4,i[o+12>>2]=-1,f=o+29|0,i[(u=o+16|0)>>2]=0,i[u+4>>2]=0,i[u+8>>2]=0,r[u+12|0]=0,r[f|0]=0|r[s|0],r[f+1|0]=0|r[s+1|0],r[f+2|0]=0|r[s+2|0]}while(0);nt(o),i[e>>2]=i[o>>2],i[e+4>>2]=i[o+4>>2],i[e+8>>2]=i[o+8>>2],i[e+12>>2]=i[o+12>>2],i[e+16>>2]=i[o+16>>2],i[e+20>>2]=i[o+20>>2],i[e+24>>2]=i[o+24>>2],i[e+28>>2]=i[o+28>>2],N=A}function nt(e){var t,n,a,s,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0;if(s=N,N=N+336|0,t=s+168|0,n=s,!(0|(A=0|i[(l=e|=0)>>2]))&!(0|(l=0|i[l+4>>2])))N=s;else{if(0|r[(o=e+28|0)|0]?(A=0|rt(A,l),l=0|S()):r[o|0]=1,!(0|i[i[(a=e+20|0)>>2]>>2]))return 0|(A=0|i[(o=e+24|0)>>2])&&Et(A),i[(_=e)>>2]=0,i[_+4>>2]=0,i[e+8>>2]=0,i[a>>2]=0,i[e+12>>2]=-1,i[e+16>>2]=0,i[o>>2]=0,void(N=s);c=15&(o=0|i[(_=e+16|0)>>2]);e:do{if(!(0|A)&!(0|l))x=e+24|0;else{v=e+12|0,g=3==(0|c),m=255&o,h=3==(1|c),b=e+24|0,p=(c+-1|0)>>>0<3,f=3==(2|c),d=n+8|0;t:for(;;){if(u=0|Vt(0|A,0|l,52),S(),(0|(u&=15))==(0|i[v>>2])){switch(15&m){case 0:case 2:case 3:if(0|(c=0|De(A,l,t))){y=15;break t}if(0|At(0|i[a>>2],0|i[b>>2],t)){y=19;break t}}if(h&&(c=0|i[4+(0|i[a>>2])>>2],i[t>>2]=i[c>>2],i[t+4>>2]=i[c+4>>2],i[t+8>>2]=i[c+8>>2],i[t+12>>2]=i[c+12>>2],0|Y(26896,t))){if(0|Be(0|i[4+(0|i[a>>2])>>2],u,n)){y=25;break}if((0|i[(c=n)>>2])==(0|A)&&(0|i[c+4>>2])==(0|l)){y=29;break}}if(p){if(0|(c=0|Ue(A,l,t))){y=32;break}if(0|et(A,l,n,0)){y=36;break}if(f&&0|lt(0|i[a>>2],0|i[b>>2],t,n)){y=42;break}if(h&&0|ut(0|i[a>>2],0|i[b>>2],t,n)){y=42;break}}if(g){if(o=0|et(A,l,t,1),c=0|i[b>>2],0|o){y=45;break}if(0|Z(c,t)){if(te(n,t),0|ee(t,0|i[b>>2])){y=53;break}if(0|At(0|i[a>>2],0|i[b>>2],d)){y=53;break}if(0|ut(0|i[a>>2],0|i[b>>2],n,t)){y=53;break}}}}do{if((0|u)<(0|i[v>>2])){if(o=0|et(A,l,t,1),c=0|i[b>>2],0|o){y=58;break t}if(!(0|Z(c,t))){y=73;break}if(0|ee(0|i[b>>2],t)&&(te(n,t),0|lt(0|i[a>>2],0|i[b>>2],n,t))){y=65;break t}if(0|(A=0|Ee(A,l,u+1|0,n))){y=67;break t}A=0|i[(l=n)>>2],l=0|i[l+4>>2]}else y=73}while(0);if(73==(0|y)&&(y=0,A=0|rt(A,l),l=0|S()),!(0|A)&!(0|l)){x=b;break e}}switch(0|y){case 15:0|(o=0|i[b>>2])&&Et(o),i[(y=e)>>2]=0,i[y+4>>2]=0,i[a>>2]=0,i[v>>2]=-1,i[_>>2]=0,i[b>>2]=0,i[e+8>>2]=c,y=20;break;case 19:i[e>>2]=A,i[e+4>>2]=l,y=20;break;case 25:M(27634,27600,470,27611);break;case 29:case 42:return i[e>>2]=A,i[e+4>>2]=l,void(N=s);case 32:return 0|(o=0|i[b>>2])&&Et(o),i[(x=e)>>2]=0,i[x+4>>2]=0,i[a>>2]=0,i[v>>2]=-1,i[_>>2]=0,i[b>>2]=0,i[e+8>>2]=c,void(N=s);case 36:M(27634,27600,493,27611);break;case 45:0|c&&Et(c),i[(y=e)>>2]=0,i[y+4>>2]=0,i[a>>2]=0,i[v>>2]=-1,i[_>>2]=0,i[b>>2]=0,i[e+8>>2]=o,y=55;break;case 53:i[e>>2]=A,i[e+4>>2]=l,y=55;break;case 58:0|c&&Et(c),i[(y=e)>>2]=0,i[y+4>>2]=0,i[a>>2]=0,i[v>>2]=-1,i[_>>2]=0,i[b>>2]=0,i[e+8>>2]=o,y=71;break;case 65:i[e>>2]=A,i[e+4>>2]=l,y=71;break;case 67:return 0|(o=0|i[b>>2])&&Et(o),i[(x=e)>>2]=0,i[x+4>>2]=0,i[a>>2]=0,i[v>>2]=-1,i[_>>2]=0,i[b>>2]=0,i[e+8>>2]=A,void(N=s)}if(20==(0|y))return void(N=s);if(55==(0|y))return void(N=s);if(71==(0|y))return void(N=s)}}while(0);0|(o=0|i[x>>2])&&Et(o),i[(y=e)>>2]=0,i[y+4>>2]=0,i[e+8>>2]=0,i[a>>2]=0,i[e+12>>2]=-1,i[_>>2]=0,i[x>>2]=0,N=s}}function rt(e,t){var n,r=0,a=0,s=0,o=0,A=0,l=0,c=0,u=0,f=0;n=N,N=N+16|0,f=n,a=0|Vt(0|(e|=0),0|(t|=0),52),S(),a&=15,r=0|Vt(0|e,0|t,45),S();do{if(a){for(;r=0|jt(a+4095|0,0,52),s=S()|-15728641&t,r=r|e|(A=0|jt(7,0,0|(o=3*(15-a|0)|0))),s|=l=0|S(),c=0|Vt(0|e,0|t,0|o),S(),a=a+-1|0,!((c&=7)>>>0<6);){if(!a){u=4;break}t=s,e=r}if(4==(0|u)){r=0|Vt(0|r,0|s,45),S();break}return f=0|jt(((f=!(0|c)&!!(0|Se(r,s)))?2:1)+c|0,0,0|o),u=0|S()|t&~l,f|=e&~A,T(0|u),N=n,0|f}}while(0);return(r&=127)>>>0>120?(f=0,T(0|(u=0)),N=n,0|f):(_e(f,0,r+1|0,0),u=0|i[f+4>>2],f=0|i[f>>2],T(0|u),N=n,0|f)}function it(e,t,n){e|=0;var r,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0;if(!(0|Y(t|=0,n|=0)))return 0|(h=0);if(t=0|function(e){return+a[16+(e|=0)>>3]<+a[e+24>>3]|0}(t),s=+a[n>>3],o=t&(o=+a[n+8>>3])<0?o+6.283185307179586:o,(0|(h=0|i[e>>2]))<=0)return 0|(h=0);if(r=0|i[e+4>>2],t){t=0,d=o,n=-1,e=0;e:for(;;){for(f=e;l=+a[r+(f<<4)>>3],o=+a[r+(f<<4)+8>>3],A=+a[r+((e=(n+2|0)%(0|h)|0)<<4)>>3],c=+a[r+(e<<4)+8>>3],l>A?(u=l,l=c):(u=A,A=l,l=o,o=c),(s=s==A|s==u?s+2220446049250313e-31:s)<A|s>u;){if((0|(n=f+1|0))>=(0|h)){n=22;break e}e=f,f=n,n=e}if(((u=(c=l<0?l+6.283185307179586:l)+(s-A)/(u-A)*((l=o<0?o+6.283185307179586:o)-c))<0?u+6.283185307179586:u)>(d=c==d|l==d?d+-2220446049250313e-31:d)&&(t^=1),(0|(e=f+1|0))>=(0|h)){n=22;break}n=f}if(22==(0|n))return 0|t}else{t=0,d=o,n=-1,e=0;e:for(;;){for(f=e;l=+a[r+(f<<4)>>3],o=+a[r+(f<<4)+8>>3],A=+a[r+((e=(n+2|0)%(0|h)|0)<<4)>>3],c=+a[r+(e<<4)+8>>3],l>A?(u=l,l=c):(u=A,A=l,l=o,o=c),(s=s==A|s==u?s+2220446049250313e-31:s)<A|s>u;){if((0|(n=f+1|0))>=(0|h)){n=22;break e}e=f,f=n,n=e}if(l+(s-A)/(u-A)*(o-l)>(d=l==d|o==d?d+-2220446049250313e-31:d)&&(t^=1),(0|(e=f+1|0))>=(0|h)){n=22;break}n=f}if(22==(0|n))return 0|t}return 0}function at(e,t){t|=0;var n,r,s,o,A,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0;if(!(r=0|i[(e|=0)>>2]))return i[t>>2]=0,i[t+4>>2]=0,i[t+8>>2]=0,i[t+12>>2]=0,i[t+16>>2]=0,i[t+20>>2]=0,i[t+24>>2]=0,void(i[t+28>>2]=0);if(a[(s=t+8|0)>>3]=17976931348623157e292,a[(o=t+24|0)>>3]=17976931348623157e292,a[t>>3]=-17976931348623157e292,a[(A=t+16|0)>>3]=-17976931348623157e292,!((0|r)<=0)){for(n=0|i[e+4>>2],g=17976931348623157e292,b=-17976931348623157e292,v=0,e=-1,d=17976931348623157e292,h=17976931348623157e292,m=-17976931348623157e292,u=-17976931348623157e292,y=0;c=+a[n+(y<<4)>>3],p=+a[n+(y<<4)+8>>3],f=+a[n+(((0|(e=e+2|0))==(0|r)?0:e)<<4)+8>>3],c<d&&(a[s>>3]=c,d=c),p<h&&(a[o>>3]=p,h=p),c>m?a[t>>3]=c:c=m,p>u&&(a[A>>3]=p,u=p),g=p>0&p<g?p:g,b=p<0&p>b?p:b,v|=+l(+(p-f))>3.141592653589793,(0|(e=y+1|0))!=(0|r);)x=y,m=c,y=e,e=x;v&&(a[A>>3]=b,a[o>>3]=g)}}function st(e){return 0|((e|=0)>>>0<4?0:15)}function ot(e,t){t|=0;var n,r=0,s=0,o=0,A=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0,w=0,T=0,S=0,M=0;if(b=0|i[(e|=0)>>2]){if(a[(v=t+8|0)>>3]=17976931348623157e292,a[(y=t+24|0)>>3]=17976931348623157e292,a[t>>3]=-17976931348623157e292,a[(x=t+16|0)>>3]=-17976931348623157e292,(0|b)>0){for(o=0|i[e+4>>2],m=17976931348623157e292,g=-17976931348623157e292,s=0,r=-1,f=17976931348623157e292,d=17976931348623157e292,p=-17976931348623157e292,c=-17976931348623157e292,_=0;A=+a[o+(_<<4)>>3],h=+a[o+(_<<4)+8>>3],u=+a[o+(((0|(S=r+2|0))==(0|b)?0:S)<<4)+8>>3],A<f&&(a[v>>3]=A,f=A),h<d&&(a[y>>3]=h,d=h),A>p?a[t>>3]=A:A=p,h>c&&(a[x>>3]=h,c=h),m=h>0&h<m?h:m,g=h<0&h>g?h:g,s|=+l(+(h-u))>3.141592653589793,(0|(r=_+1|0))!=(0|b);)S=_,p=A,_=r,r=S;s&&(a[x>>3]=g,a[y>>3]=m)}}else i[t>>2]=0,i[t+4>>2]=0,i[t+8>>2]=0,i[t+12>>2]=0,i[t+16>>2]=0,i[t+20>>2]=0,i[t+24>>2]=0,i[t+28>>2]=0;if(!((0|(r=0|i[(S=e+8|0)>>2]))<=0)){n=e+12|0,T=0;do{if(o=0|i[n>>2],s=T,y=t+((T=T+1|0)<<5)|0,x=0|i[o+(s<<3)>>2]){if(a[(_=t+(T<<5)+8|0)>>3]=17976931348623157e292,a[(e=t+(T<<5)+24|0)>>3]=17976931348623157e292,a[y>>3]=-17976931348623157e292,a[(w=t+(T<<5)+16|0)>>3]=-17976931348623157e292,(0|x)>0){for(b=0|i[o+(s<<3)+4>>2],m=17976931348623157e292,g=-17976931348623157e292,o=0,s=-1,v=0,f=17976931348623157e292,d=17976931348623157e292,h=-17976931348623157e292,c=-17976931348623157e292;A=+a[b+(v<<4)>>3],p=+a[b+(v<<4)+8>>3],u=+a[b+(((0|(s=s+2|0))==(0|x)?0:s)<<4)+8>>3],A<f&&(a[_>>3]=A,f=A),p<d&&(a[e>>3]=p,d=p),A>h?a[y>>3]=A:A=h,p>c&&(a[w>>3]=p,c=p),m=p>0&p<m?p:m,g=p<0&p>g?p:g,o|=+l(+(p-u))>3.141592653589793,(0|(s=v+1|0))!=(0|x);)M=v,v=s,h=A,s=M;o&&(a[w>>3]=g,a[e>>3]=m)}}else i[y>>2]=0,i[y+4>>2]=0,i[y+8>>2]=0,i[y+12>>2]=0,i[y+16>>2]=0,i[y+20>>2]=0,i[y+24>>2]=0,i[y+28>>2]=0,r=0|i[S>>2]}while((0|T)<(0|r))}}function At(e,t,n){var r=0,a=0,s=0;if(!(0|it(e|=0,t|=0,n|=0)))return 0|(a=0);if((0|i[(a=e+8|0)>>2])<=0)return 0|(a=1);for(r=e+12|0,e=0;;){if(s=e,e=e+1|0,0|it((0|i[r>>2])+(s<<3)|0,t+(e<<5)|0,n)){e=0,r=6;break}if((0|e)>=(0|i[a>>2])){e=1,r=6;break}}return 6==(0|r)?0|e:0}function lt(e,t,n,r){r|=0;var a,s,o=0,A=0,l=0,c=0,u=0;if(s=N,N=N+16|0,a=s,!(0|it(e|=0,t|=0,l=(n|=0)+8|0)))return N=s,0|(c=0);c=e+8|0;e:do{if((0|i[c>>2])>0){for(A=e+12|0,o=0;;){if(u=o,o=o+1|0,0|it((0|i[A>>2])+(u<<3)|0,t+(o<<5)|0,l)){o=0;break}if((0|o)>=(0|i[c>>2]))break e}return N=s,0|o}}while(0);if(0|ct(e,t,n,r))return N=s,0|(u=0);i[a>>2]=i[n>>2],i[a+4>>2]=l,o=0|i[c>>2];e:do{if((0|o)>0)for(e=e+12|0,l=0,A=o;;){if(o=0|i[e>>2],(0|i[o+(l<<3)>>2])>0){if(0|it(a,r,0|i[o+(l<<3)+4>>2])){o=0;break e}if(o=l+1|0,0|ct((0|i[e>>2])+(l<<3)|0,t+(o<<5)|0,n,r)){o=0;break e}A=0|i[c>>2]}else o=l+1|0;if(!((0|o)<(0|A))){o=1;break}l=o}else o=1}while(0);return N=s,0|(u=o)}function ct(e,t,n,r){e|=0,n|=0;var s,o,A,l,c,u,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0,w=0,T=0,S=0,M=0;if(u=N,N=N+176|0,l=u+172|0,f=u+168|0,c=u,!(0|Z(t|=0,r|=0)))return N=u,0|(e=0);if(function(e,t,n,r){var s,o,A,l,c;t|=0,n|=0,r|=0,e=(o=+a[16+(e|=0)>>3])<(c=+a[e+24>>3]),s=(l=+a[t+16>>3])<(A=+a[t+24>>3]),t=c-l<A-o,i[n>>2]=e?s|t?1:2:0,i[r>>2]=s?e?1:t?2:1:0}(t,r,l,f),Qt(0|c,0|n,168),(0|i[n>>2])>0){t=0;do{_=+qe(+a[(S=c+8+(t<<4)+8|0)>>3],0|i[f>>2]),a[S>>3]=_,t=t+1|0}while((0|t)<(0|i[n>>2]))}o=+a[r>>3],A=+a[r+8>>3],_=+qe(+a[r+16>>3],0|i[f>>2]),s=+qe(+a[r+24>>3],0|i[f>>2]);e:do{if((0|i[e>>2])>0){if(r=e+4|0,(0|(f=0|i[c>>2]))<=0)for(t=0;;)if((0|(t=t+1|0))>=(0|i[e>>2])){t=0;break e}for(n=0;;){if(t=0|i[r>>2],y=+a[t+(n<<4)>>3],x=+qe(+a[t+(n<<4)+8>>3],0|i[l>>2]),t=0|i[r>>2],S=(0|(n=n+1|0))%(0|i[e>>2])|0,d=+a[t+(S<<4)>>3],h=+qe(+a[t+(S<<4)+8>>3],0|i[l>>2]),!(y>=o)|!(d>=o)&&!(y<=A)|!(d<=A)&&!(x<=s)|!(h<=s)&&!(x>=_)|!(h>=_)){v=d-y,g=h-x,t=0;do{if(M=t,S=(0|(t=t+1|0))==(0|f)?0:t,d=+a[c+8+(M<<4)+8>>3],h=+a[c+8+(S<<4)+8>>3]-d,p=+a[c+8+(M<<4)>>3],!(0==(b=v*h-g*(m=+a[c+8+(S<<4)>>3]-p))||(w=x-d,T=y-p,m=(w*m-h*T)/b,m<0|m>1))&&(b=(v*w-g*T)/b)>=0&b<=1){t=1;break e}}while((0|t)<(0|f))}if((0|n)>=(0|i[e>>2])){t=0;break}}}else t=0}while(0);return N=u,0|(M=t)}function ut(e,t,n,r){var a=0,s=0,o=0;if(0|ct(e|=0,t|=0,n|=0,r|=0))return 0|(s=1);if((0|i[(s=e+8|0)>>2])<=0)return 0|(s=0);for(a=e+12|0,e=0;;){if(o=e,e=e+1|0,0|ct((0|i[a>>2])+(o<<3)|0,t+(e<<5)|0,n,r)){e=1,a=6;break}if((0|e)>=(0|i[s>>2])){e=0,a=6;break}}return 6==(0|a)?0|e:0}function ft(e,t,n,r,i){t|=0,n|=0,r|=0,i|=0;var s,o,A,l,c,u,f,d=0;l=+a[(e|=0)>>3],A=+a[t>>3]-l,o=+a[e+8>>3],s=+a[t+8>>3]-o,u=+a[n>>3],d=((d=+a[r>>3]-u)*(o-(f=+a[n+8>>3]))-(l-u)*(c=+a[r+8>>3]-f))/(A*c-s*d),a[i>>3]=l+A*d,a[i+8>>3]=o+s*d}function dt(e,t){return t|=0,+l(+(+a[(e|=0)>>3]-+a[t>>3]))<1.1920928955078125e-7?0|(t=+l(+(+a[e+8>>3]-+a[t+8>>3]))<1.1920928955078125e-7):0|(t=0)}function ht(e,t,n){n|=0;var r,a,s,o,A=0,l=0,c=0,u=0;if(o=N,N=N+32|0,u=o,0|(A=0|Fe(e|=0,t|=0,a=o+16|0)))return N=o,0|(n=A);r=0|ye(e,t),s=0|Ce(e,t),function(e,t){e=7696+(28*(e|=0)|0)|0,i[(t|=0)>>2]=i[e>>2],i[t+4>>2]=i[e+4>>2],i[t+8>>2]=i[e+8>>2],i[t+12>>2]=i[e+12>>2]}(r,u),A=0|function(e,t){e|=0;var n=0,r=0;if((t|=0)>>>0>20)return-1;do{if((0|i[11120+(216*t|0)>>2])!=(0|e))if((0|i[11120+(216*t|0)+8>>2])!=(0|e))if((0|i[11120+(216*t|0)+16>>2])!=(0|e))if((0|i[11120+(216*t|0)+24>>2])!=(0|e))if((0|i[11120+(216*t|0)+32>>2])!=(0|e))if((0|i[11120+(216*t|0)+40>>2])!=(0|e))if((0|i[11120+(216*t|0)+48>>2])!=(0|e))if((0|i[11120+(216*t|0)+56>>2])!=(0|e))if((0|i[11120+(216*t|0)+64>>2])!=(0|e))if((0|i[11120+(216*t|0)+72>>2])!=(0|e))if((0|i[11120+(216*t|0)+80>>2])!=(0|e))if((0|i[11120+(216*t|0)+88>>2])!=(0|e))if((0|i[11120+(216*t|0)+96>>2])!=(0|e))if((0|i[11120+(216*t|0)+104>>2])!=(0|e))if((0|i[11120+(216*t|0)+112>>2])!=(0|e))if((0|i[11120+(216*t|0)+120>>2])!=(0|e))if((0|i[11120+(216*t|0)+128>>2])!=(0|e)){if((0|i[11120+(216*t|0)+136>>2])!=(0|e)){if((0|i[11120+(216*t|0)+144>>2])==(0|e)){e=0,n=2,r=0;break}if((0|i[11120+(216*t|0)+152>>2])==(0|e)){e=0,n=2,r=1;break}if((0|i[11120+(216*t|0)+160>>2])==(0|e)){e=0,n=2,r=2;break}if((0|i[11120+(216*t|0)+168>>2])==(0|e)){e=1,n=2,r=0;break}if((0|i[11120+(216*t|0)+176>>2])==(0|e)){e=1,n=2,r=1;break}if((0|i[11120+(216*t|0)+184>>2])==(0|e)){e=1,n=2,r=2;break}if((0|i[11120+(216*t|0)+192>>2])==(0|e)){e=2,n=2,r=0;break}if((0|i[11120+(216*t|0)+200>>2])==(0|e)){e=2,n=2,r=1;break}if((0|i[11120+(216*t|0)+208>>2])==(0|e)){e=2,n=2,r=2;break}return-1}e=2,n=1,r=2}else e=2,n=1,r=1;else e=2,n=1,r=0;else e=1,n=1,r=2;else e=1,n=1,r=1;else e=1,n=1,r=0;else e=0,n=1,r=2;else e=0,n=1,r=1;else e=0,n=1,r=0;else e=2,n=0,r=2;else e=2,n=0,r=1;else e=2,n=0,r=0;else e=1,n=0,r=2;else e=1,n=0,r=1;else e=1,n=0,r=0;else e=0,n=0,r=2;else e=0,n=0,r=1;else e=0,n=0,r=0}while(0);return 0|i[11120+(216*t|0)+(72*n|0)+(24*e|0)+(r<<3)+4>>2]}(r,0|i[a>>2]);do{if(0|G(r)){switch(0|r){case 4:l=0;break;case 14:l=1;break;case 24:l=2;break;case 38:l=3;break;case 49:l=4;break;case 58:l=5;break;case 63:l=6;break;case 72:l=7;break;case 83:l=8;break;case 97:l=9;break;case 107:l=10;break;case 117:l=11;break;default:M(27634,27636,75,27645)}if(c=0|i[26480+(24*l|0)+8>>2],t=0|i[26480+(24*l|0)+16>>2],(0|(e=0|i[a>>2]))!=(0|i[u>>2])&&(u=0|H(r))|(0|(e=0|i[a>>2]))==(0|t)&&(A=(A+1|0)%6|0),3==(0|s)&(0|e)==(0|t)){A=(A+5|0)%6|0;break}5==(0|s)&(0|e)==(0|c)&&(A=(A+1|0)%6|0)}}while(0);return i[n>>2]=A,N=o,0|(n=0)}function pt(e,t,n,r){n|=0,r|=0;var a,s,o,A,l,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0;if(l=N,N=N+32|0,y=l+24|0,A=l+20|0,o=l+8|0,s=l+16|0,a=l,h=(h=!(0|Se(e|=0,t|=0)))?6:5,m=0|Vt(0|e,0|t,52),S(),h>>>0<=n>>>0)return N=l,0|(r=2);!(g=!(0|(m&=15)))&&!((b=0|jt(7,0,3*(15^m)|0))&e|0)&!((0|S())&t)?c=n:u=4;e:do{if(4==(0|u)){if((0|((c=!!(0|Se(e,t)))?4:5))<(0|n))return N=l,0|(r=1);if(0|ht(e,t,y))return N=l,0|(r=1);if(u=(0|i[y>>2])+n|0,7==(0|(b=0|i[(c=c?26768+((0|u)%5<<2)|0:26800+((0|u)%6<<2)|0)>>2])))return N=l,0|(r=1);i[A>>2]=0,c=0|F(e,t,b,A,o);do{if(!c){if(p=0|i[(d=o)>>2],u=(f=(d=0|i[d+4>>2])>>>0<t>>>0|(0|d)==(0|t)&p>>>0<e>>>0)?p:e,f=f?d:t,!g&&!(p&(g=0|jt(7,0,3*(15^m)|0))|0)&!(d&(0|S())))c=n;else{if(d=(n+-1+h|0)%(0|h)|0,c=0|Se(e,t),(0|d)<0&&M(27634,27636,248,27661),(0|((h=!!(0|c))?4:5))<(0|d)&&M(27634,27636,248,27661),0|ht(e,t,y)&&M(27634,27636,248,27661),c=(0|i[y>>2])+d|0,7==(0|(d=0|i[(c=h?26768+((0|c)%5<<2)|0:26800+((0|c)%6<<2)|0)>>2]))&&M(27634,27636,248,27661),i[s>>2]=0,0|(c=0|F(e,t,d,s,a)))break;h=0|i[(p=a)>>2],p=0|i[p+4>>2];do{if(p>>>0<f>>>0|(0|p)==(0|f)&h>>>0<u>>>0){if(u=0|Se(h,p)?0|V(h,p,e,t):0|i[26864+(((0|i[s>>2])+(0|i[26832+(d<<2)>>2])|0)%6<<2)>>2],c=0|Se(h,p),(u+-1|0)>>>0>5){c=-1,u=h,f=p;break}if(1==(0|u)&(c=!!(0|c))){c=-1,u=h,f=p;break}do{if(!(0|ht(h,p,y))){if(c){c=(5+(0|i[26416+(u<<2)>>2])-(0|i[y>>2])|0)%5|0;break}c=(6+(0|i[26448+(u<<2)>>2])-(0|i[y>>2])|0)%6|0;break}c=-1}while(0);u=h,f=p}else c=n}while(0);p=0|i[(d=o)>>2],d=0|i[d+4>>2]}if((0|u)==(0|p)&(0|f)==(0|d)){if(e=(h=!!(0|Se(p,d)))?0|V(p,d,e,t):0|i[26864+(((0|i[A>>2])+(0|i[26832+(b<<2)>>2])|0)%6<<2)>>2],c=0|Se(p,d),(e+-1|0)>>>0<=5&&!(1==(0|e)&(v=!!(0|c))))do{if(!(0|ht(p,d,y))){if(v){c=(5+(0|i[26416+(e<<2)>>2])-(0|i[y>>2])|0)%5|0;break}c=(6+(0|i[26448+(e<<2)>>2])-(0|i[y>>2])|0)%6|0;break}c=-1}while(0);else c=-1;c=6==(0|(c=c+1|0))|h&5==(0|c)?0:c}t=f,e=u;break e}}while(0);return N=l,0|(r=c)}}while(0);return v=0|jt(0|c,0,56),y=S()|-2130706433&t|536870912,i[r>>2]=v|e,i[r+4>>2]=y,N=l,0|(r=0)}function mt(e,t){e|=0;var n,r,a=0,s=0;return r=N,N=N+16|0,n=r,!0&536870912==(2013265920&(t|=0))&&0|xe(e,a=-2130706433&t|134217728)?(s=0|Vt(0|e,0|t,56),S(),a=(s=!(0|pt(e,a,7&s,n)))&((0|i[(a=n)>>2])==(0|e)?(0|i[a+4>>2])==(0|t):0)&1,N=r,0|a):(N=r,0|(a=0))}function gt(e,t,n,r){e|=0,r|=0;var a,s,o,A=0,l=0,c=0,u=0,f=0,d=0;o=N,N=N+208|0,a=o,s=o+192|0,c=0|v(n|=0,t|=0),i[(u=s)>>2]=1,i[u+4>>2]=0;e:do{if(0|c){for(u=0-n|0,i[a+4>>2]=n,i[a>>2]=n,A=2,t=n,l=n;t=t+n+l|0,i[a+(A<<2)>>2]=t,t>>>0<c>>>0;)d=l,A=A+1|0,l=t,t=d;if((l=e+c+u|0)>>>0>e>>>0){c=l,A=1,t=1;do{do{if(3&~t){if((0|i[a+((t=A+-1|0)<<2)>>2])>>>0<(c-e|0)>>>0?bt(e,n,r,A,a):yt(e,n,r,s,A,0,a),1==(0|A)){xt(s,1),A=0;break}xt(s,t),A=1;break}bt(e,n,r,A,a),vt(s,2),A=A+2|0}while(0);t=1|i[s>>2],i[s>>2]=t,e=e+n|0}while(e>>>0<l>>>0)}else A=1,t=1;for(yt(e,n,r,s,A,0,a),l=s+4|0;;){if(1==(0|A)&1==(0|t)){if(!(0|i[l>>2]))break e;f=19}else(0|A)<2?f=19:(xt(s,2),d=A+-2|0,i[s>>2]=7^i[s>>2],vt(s,1),yt(e+(0-(0|i[a+(d<<2)>>2]))+u|0,n,r,s,A+-1|0,1,a),xt(s,1),t=1|i[s>>2],i[s>>2]=t,yt(e=e+u|0,n,r,s,d,1,a),A=d);19==(0|f)&&(f=0,vt(s,t=0|_t(s)),e=e+u|0,A=t+A|0,t=0|i[s>>2])}}}while(0);N=o}function bt(e,t,n,r,a){e|=0,t|=0,n|=0,r|=0,a|=0;var s,o,A=0,l=0,c=0,u=0,f=0;o=N,N=N+240|0,i[(s=o)>>2]=e;e:do{if((0|r)>1)for(f=0-t|0,c=e,A=r,r=1,l=e;;){if(e=(c=c+f|0)+(0-(0|i[a+((u=A+-2|0)<<2)>>2]))|0,(0|Xt[3&n](l,e))>-1&&(0|Xt[3&n](l,c))>-1)break e;if(l=s+(r<<2)|0,(0|Xt[3&n](e,c))>-1?(i[l>>2]=e,A=A+-1|0):(i[l>>2]=c,e=c,A=u),r=r+1|0,(0|A)<=1)break e;c=e,l=0|i[s>>2]}else r=1}while(0);Tt(t,s,r),N=o}function vt(e,t){var n,r=0,a=0;n=(e|=0)+4|0,(t|=0)>>>0>31?(a=0|i[n>>2],i[e>>2]=a,i[n>>2]=0,t=t+-32|0,r=0):(r=0|i[n>>2],a=0|i[e>>2]),i[e>>2]=r<<32-t|a>>>t,i[n>>2]=r>>>t}function yt(e,t,n,r,a,s,o){e|=0,t|=0,n|=0,a|=0,s|=0,o|=0;var A,l,c,u,f=0,d=0,h=0,p=0;u=N,N=N+240|0,l=u+232|0,c=u,p=0|i[(r|=0)>>2],i[l>>2]=p,d=0|i[r+4>>2],i[(A=l+4|0)>>2]=d,i[c>>2]=e;e:do{if(1!=(0|p)|!!(0|d)&&(h=0-t|0,f=e+(0-(0|i[o+(a<<2)>>2]))|0,(0|Xt[3&n](f,e))>=1))for(r=1,s=!(0|s),d=f;;){if(s&(0|a)>1){if(s=e+h|0,f=0|i[o+(a+-2<<2)>>2],(0|Xt[3&n](s,d))>-1){f=10;break e}if((0|Xt[3&n](s+(0-f)|0,d))>-1){f=10;break e}}if(s=r+1|0,i[c+(r<<2)>>2]=d,vt(l,p=0|_t(l)),a=p+a|0,!(1!=(0|i[l>>2])|!!(0|i[A>>2]))){r=s,e=d,f=10;break e}if(e=d+(0-(0|i[o+(a<<2)>>2]))|0,(0|Xt[3&n](e,0|i[c>>2]))<1){e=d,r=s,s=0,f=9;break}p=d,r=s,s=1,d=e,e=p}else r=1,f=9}while(0);9!=(0|f)||0|s||(f=10),10==(0|f)&&(Tt(t,c,r),bt(e,t,n,a,o)),N=u}function xt(e,t){var n,r=0,a=0;n=(e|=0)+4|0,(t|=0)>>>0>31?(a=0|i[e>>2],i[n>>2]=a,i[e>>2]=0,t=t+-32|0,r=0):(r=0|i[e>>2],a=0|i[n>>2]),i[n>>2]=r>>>(32-t|0)|a<<t,i[e>>2]=r<<t}function _t(e){var t=0;return(t=0|wt((0|i[(e|=0)>>2])-1|0))?0|t:0|(0|(t=0|wt(0|i[e+4>>2]))?t+32:0)}function wt(e){var t=0;if(e|=0)if(1&e)e=0;else for(t=e,e=0;e=e+1|0,!(2&t);)t>>>=1;else e=32;return 0|e}function Tt(e,t,n){e|=0,t|=0,n|=0;var r,a=0,s=0,o=0,A=0;r=N,N=N+256|0,a=r;e:do{if((0|n)>=2&&(o=t+(n<<2)|0,i[o>>2]=a,0|e))for(;;){s=e>>>0<256?e:256,Qt(0|a,0|i[t>>2],0|s),a=0;do{A=t+(a<<2)|0,a=a+1|0,Qt(0|i[A>>2],0|i[t+(a<<2)>>2],0|s),i[A>>2]=(0|i[A>>2])+s}while((0|a)!=(0|n));if(!(e=e-s|0))break e;a=0|i[o>>2]}}while(0);N=r}function St(e){return 0|+Jt(+(e=+e))}function Mt(e){e|=0;var t,n=0,r=0,a=0,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0;t=N,N=N+16|0,h=t;do{if(e>>>0<245){if(e=(u=e>>>0<11?16:e+11&-8)>>>3,3&(r=(d=0|i[6921])>>>e))return a=0|i[(r=(e=27724+((n=(1&r^1)+e|0)<<1<<2)|0)+8|0)>>2],(0|(o=0|i[(s=a+8|0)>>2]))==(0|e)?i[6921]=d&~(1<<n):(i[o+12>>2]=e,i[r>>2]=o),_=n<<3,i[a+4>>2]=3|_,i[(_=a+_+4|0)>>2]=1|i[_>>2],N=t,0|(_=s);if(u>>>0>(f=0|i[6923])>>>0){if(0|r)return n=((n=r<<e&((n=2<<e)|0-n))&0-n)-1|0,o=0|i[(e=(n=27724+((a=((r=(n>>>=l=n>>>12&16)>>>5&8)|l|(o=(n>>>=r)>>>2&4)|(e=(n>>>=o)>>>1&2)|(a=(n>>>=e)>>>1&1))+(n>>>a)|0)<<1<<2)|0)+8|0)>>2],(0|(r=0|i[(l=o+8|0)>>2]))==(0|n)?(e=d&~(1<<a),i[6921]=e):(i[r+12>>2]=n,i[e>>2]=r,e=d),A=(_=a<<3)-u|0,i[o+4>>2]=3|u,i[(s=o+u|0)+4>>2]=1|A,i[o+_>>2]=A,0|f&&(a=0|i[6926],r=27724+((n=f>>>3)<<1<<2)|0,e&(n=1<<n)?n=0|i[(e=r+8|0)>>2]:(i[6921]=e|n,n=r,e=r+8|0),i[e>>2]=a,i[n+12>>2]=a,i[a+8>>2]=n,i[a+12>>2]=r),i[6923]=A,i[6926]=s,N=t,0|(_=l);if(o=0|i[6922]){for(r=(o&0-o)-1|0,r=c=0|i[27988+(((a=(r>>>=s=r>>>12&16)>>>5&8)|s|(A=(r>>>=a)>>>2&4)|(l=(r>>>=A)>>>1&2)|(c=(r>>>=l)>>>1&1))+(r>>>c)<<2)>>2],l=c,c=(-8&i[c+4>>2])-u|0;(e=0|i[r+16>>2])||(e=0|i[r+20>>2]);)r=e,l=(s=(A=(-8&i[e+4>>2])-u|0)>>>0<c>>>0)?e:l,c=s?A:c;if((A=l+u|0)>>>0>l>>>0){s=0|i[l+24>>2],n=0|i[l+12>>2];do{if((0|n)==(0|l)){if(!(n=0|i[(e=l+20|0)>>2])&&!(n=0|i[(e=l+16|0)>>2])){r=0;break}for(;;)if(r=0|i[(a=n+20|0)>>2])n=r,e=a;else{if(!(r=0|i[(a=n+16|0)>>2]))break;n=r,e=a}i[e>>2]=0,r=n}else r=0|i[l+8>>2],i[r+12>>2]=n,i[n+8>>2]=r,r=n}while(0);do{if(0|s){if(n=0|i[l+28>>2],(0|l)==(0|i[(e=27988+(n<<2)|0)>>2])){if(i[e>>2]=r,!r){i[6922]=o&~(1<<n);break}}else if(i[((0|i[(_=s+16|0)>>2])==(0|l)?_:s+20)>>2]=r,!r)break;i[r+24>>2]=s,0|(n=0|i[l+16>>2])&&(i[r+16>>2]=n,i[n+24>>2]=r),0|(n=0|i[l+20>>2])&&(i[r+20>>2]=n,i[n+24>>2]=r)}}while(0);return c>>>0<16?(_=c+u|0,i[l+4>>2]=3|_,i[(_=l+_+4|0)>>2]=1|i[_>>2]):(i[l+4>>2]=3|u,i[A+4>>2]=1|c,i[A+c>>2]=c,0|f&&(a=0|i[6926],r=27724+((n=f>>>3)<<1<<2)|0,(n=1<<n)&d?n=0|i[(e=r+8|0)>>2]:(i[6921]=n|d,n=r,e=r+8|0),i[e>>2]=a,i[n+12>>2]=a,i[a+8>>2]=n,i[a+12>>2]=r),i[6923]=c,i[6926]=A),N=t,0|(_=l+8|0)}d=u}else d=u}else d=u}else if(e>>>0<=4294967231)if(u=-8&(e=e+11|0),a=0|i[6922]){s=0-u|0,c=(e>>>=8)?u>>>0>16777215?31:u>>>((c=14-((l=((g=e<<(d=(e+1048320|0)>>>16&8))+520192|0)>>>16&4)|d|(c=((g<<=l)+245760|0)>>>16&2))+(g<<c>>>15)|0)+7|0)&1|c<<1:0,r=0|i[27988+(c<<2)>>2];e:do{if(r)for(e=0,l=u<<(31==(0|c)?0:25-(c>>>1)|0),o=0;;){if((A=(-8&i[r+4>>2])-u|0)>>>0<s>>>0){if(!A){e=r,s=0,g=65;break e}e=r,s=A}if(o=!(0|(g=0|i[r+20>>2]))|(0|g)==(0|(r=0|i[r+16+(l>>>31<<2)>>2]))?o:g,!r){r=o,g=61;break}l<<=1}else r=0,e=0,g=61}while(0);if(61==(0|g)){if(!(0|r)&!(0|e)){if(!(e=((e=2<<c)|0-e)&a)){d=u;break}d=(e&0-e)-1|0,e=0,r=0|i[27988+(((o=(d>>>=A=d>>>12&16)>>>5&8)|A|(l=(d>>>=o)>>>2&4)|(c=(d>>>=l)>>>1&2)|(r=(d>>>=c)>>>1&1))+(d>>>r)<<2)>>2]}r?g=65:(l=e,A=s)}if(65==(0|g))for(o=r;;){if(s=(r=(d=(-8&i[o+4>>2])-u|0)>>>0<s>>>0)?d:s,e=r?o:e,(r=0|i[o+16>>2])||(r=0|i[o+20>>2]),!r){l=e,A=s;break}o=r}if(0|l&&A>>>0<((0|i[6923])-u|0)>>>0&&(f=l+u|0)>>>0>l>>>0){o=0|i[l+24>>2],n=0|i[l+12>>2];do{if((0|n)==(0|l)){if(!(n=0|i[(e=l+20|0)>>2])&&!(n=0|i[(e=l+16|0)>>2])){n=0;break}for(;;)if(r=0|i[(s=n+20|0)>>2])n=r,e=s;else{if(!(r=0|i[(s=n+16|0)>>2]))break;n=r,e=s}i[e>>2]=0}else _=0|i[l+8>>2],i[_+12>>2]=n,i[n+8>>2]=_}while(0);do{if(o){if(e=0|i[l+28>>2],(0|l)==(0|i[(r=27988+(e<<2)|0)>>2])){if(i[r>>2]=n,!n){a&=~(1<<e),i[6922]=a;break}}else if(i[((0|i[(_=o+16|0)>>2])==(0|l)?_:o+20)>>2]=n,!n)break;i[n+24>>2]=o,0|(e=0|i[l+16>>2])&&(i[n+16>>2]=e,i[e+24>>2]=n),(e=0|i[l+20>>2])&&(i[n+20>>2]=e,i[e+24>>2]=n)}}while(0);e:do{if(A>>>0<16)_=A+u|0,i[l+4>>2]=3|_,i[(_=l+_+4|0)>>2]=1|i[_>>2];else{if(i[l+4>>2]=3|u,i[f+4>>2]=1|A,i[f+A>>2]=A,n=A>>>3,A>>>0<256){r=27724+(n<<1<<2)|0,(e=0|i[6921])&(n=1<<n)?n=0|i[(e=r+8|0)>>2]:(i[6921]=e|n,n=r,e=r+8|0),i[e>>2]=f,i[n+12>>2]=f,i[f+8>>2]=n,i[f+12>>2]=r;break}if(n=27988+((r=(n=A>>>8)?A>>>0>16777215?31:A>>>((r=14-((y=((_=n<<(x=(n+1048320|0)>>>16&8))+520192|0)>>>16&4)|x|(r=((_<<=y)+245760|0)>>>16&2))+(_<<r>>>15)|0)+7|0)&1|r<<1:0)<<2)|0,i[f+28>>2]=r,i[(e=f+16|0)+4>>2]=0,i[e>>2]=0,!(a&(e=1<<r))){i[6922]=a|e,i[n>>2]=f,i[f+24>>2]=n,i[f+12>>2]=f,i[f+8>>2]=f;break}n=0|i[n>>2];t:do{if((-8&i[n+4>>2])!=(0|A)){for(a=A<<(31==(0|r)?0:25-(r>>>1)|0);e=0|i[(r=n+16+(a>>>31<<2)|0)>>2];){if((-8&i[e+4>>2])==(0|A)){n=e;break t}a<<=1,n=e}i[r>>2]=f,i[f+24>>2]=n,i[f+12>>2]=f,i[f+8>>2]=f;break e}}while(0);_=0|i[(x=n+8|0)>>2],i[_+12>>2]=f,i[x>>2]=f,i[f+8>>2]=_,i[f+12>>2]=n,i[f+24>>2]=0}}while(0);return N=t,0|(_=l+8|0)}d=u}else d=u;else d=-1}while(0);if((r=0|i[6923])>>>0>=d>>>0)return n=r-d|0,e=0|i[6926],n>>>0>15?(_=e+d|0,i[6926]=_,i[6923]=n,i[_+4>>2]=1|n,i[e+r>>2]=n,i[e+4>>2]=3|d):(i[6923]=0,i[6926]=0,i[e+4>>2]=3|r,i[(_=e+r+4|0)>>2]=1|i[_>>2]),N=t,0|(_=e+8|0);if((A=0|i[6924])>>>0>d>>>0)return y=A-d|0,i[6924]=y,x=(_=0|i[6927])+d|0,i[6927]=x,i[x+4>>2]=1|y,i[_+4>>2]=3|d,N=t,0|(_=_+8|0);if(0|i[7039]?e=0|i[7041]:(i[7041]=4096,i[7040]=4096,i[7042]=-1,i[7043]=-1,i[7044]=0,i[7032]=0,i[7039]=-16&h^1431655768,e=4096),l=d+48|0,(u=(o=e+(c=d+47|0)|0)&(s=0-e|0))>>>0<=d>>>0)return N=t,0|(_=0);if(0|(e=0|i[7031])&&(h=(f=0|i[7029])+u|0)>>>0<=f>>>0|h>>>0>e>>>0)return N=t,0|(_=0);e:do{if(4&i[7032])n=0,g=143;else{r=0|i[6927];t:do{if(r){for(a=28132;!((h=0|i[a>>2])>>>0<=r>>>0&&(h+(0|i[a+4>>2])|0)>>>0>r>>>0);){if(!(e=0|i[a+8>>2])){g=128;break t}a=e}if((n=o-A&s)>>>0<2147483647)if((0|(e=0|$t(0|n)))==((0|i[a>>2])+(0|i[a+4>>2])|0)){if(-1!=(0|e)){A=n,o=e,g=145;break e}}else a=e,g=136;else n=0}else g=128}while(0);do{if(128==(0|g))if(-1!=(0|(r=0|$t(0)))&&(n=r,m=(n=((m=(p=0|i[7040])+-1|0)&n|0?(m+n&0-p)-n|0:0)+u|0)+(p=0|i[7029])|0,n>>>0>d>>>0&n>>>0<2147483647)){if(0|(h=0|i[7031])&&m>>>0<=p>>>0|m>>>0>h>>>0){n=0;break}if((0|(e=0|$t(0|n)))==(0|r)){A=n,o=r,g=145;break e}a=e,g=136}else n=0}while(0);do{if(136==(0|g)){if(r=0-n|0,!(l>>>0>n>>>0&n>>>0<2147483647&-1!=(0|a))){if(-1==(0|a)){n=0;break}A=n,o=a,g=145;break e}if((e=c-n+(e=0|i[7041])&0-e)>>>0>=2147483647){A=n,o=a,g=145;break e}if(-1==(0|$t(0|e))){$t(0|r),n=0;break}A=e+n|0,o=a,g=145;break e}}while(0);i[7032]=4|i[7032],g=143}}while(0);if(143==(0|g)&&u>>>0<2147483647&&!(-1==(0|(y=0|$t(0|u)))|1^(v=(b=(m=0|$t(0))-y|0)>>>0>(d+40|0)>>>0)|y>>>0<m>>>0&-1!=(0|y)&-1!=(0|m)^1)&&(A=v?b:n,o=y,g=145),145==(0|g)){n=(0|i[7029])+A|0,i[7029]=n,n>>>0>(0|i[7030])>>>0&&(i[7030]=n),c=0|i[6927];e:do{if(c){for(n=28132;;){if((0|o)==((e=0|i[n>>2])+(r=0|i[n+4>>2])|0)){g=154;break}if(!(a=0|i[n+8>>2]))break;n=a}if(!(154!=(0|g)||(x=n+4|0,8&i[n+12>>2]))&&o>>>0>c>>>0&e>>>0<=c>>>0){i[x>>2]=r+A,x=c+(y=7&(y=c+8|0)?0-y&7:0)|0,y=(_=(0|i[6924])+A|0)-y|0,i[6927]=x,i[6924]=y,i[x+4>>2]=1|y,i[c+_+4>>2]=40,i[6928]=i[7043];break}for(o>>>0<(0|i[6925])>>>0&&(i[6925]=o),r=o+A|0,n=28132;;){if((0|i[n>>2])==(0|r)){g=162;break}if(!(e=0|i[n+8>>2]))break;n=e}if(162==(0|g)&&!(8&i[n+12>>2])){i[n>>2]=o,i[(f=n+4|0)>>2]=(0|i[f>>2])+A,u=(f=o+(7&(f=o+8|0)?0-f&7:0)|0)+d|0,l=(n=r+(7&(n=r+8|0)?0-n&7:0)|0)-f-d|0,i[f+4>>2]=3|d;t:do{if((0|c)==(0|n))_=(0|i[6924])+l|0,i[6924]=_,i[6927]=u,i[u+4>>2]=1|_;else{if((0|i[6926])==(0|n)){_=(0|i[6923])+l|0,i[6923]=_,i[6926]=u,i[u+4>>2]=1|_,i[u+_>>2]=_;break}if(1==(3&(e=0|i[n+4>>2]))){A=-8&e,a=e>>>3;n:do{if(e>>>0<256){if(e=0|i[n+8>>2],(0|(r=0|i[n+12>>2]))==(0|e)){i[6921]=i[6921]&~(1<<a);break}i[e+12>>2]=r,i[r+8>>2]=e;break}o=0|i[n+24>>2],e=0|i[n+12>>2];do{if((0|e)==(0|n)){if(e=0|i[(a=(r=n+16|0)+4|0)>>2])r=a;else if(!(e=0|i[r>>2])){e=0;break}for(;;)if(a=0|i[(s=e+20|0)>>2])e=a,r=s;else{if(!(a=0|i[(s=e+16|0)>>2]))break;e=a,r=s}i[r>>2]=0}else _=0|i[n+8>>2],i[_+12>>2]=e,i[e+8>>2]=_}while(0);if(!o)break;a=27988+((r=0|i[n+28>>2])<<2)|0;do{if((0|i[a>>2])==(0|n)){if(i[a>>2]=e,0|e)break;i[6922]=i[6922]&~(1<<r);break n}if(i[((0|i[(_=o+16|0)>>2])==(0|n)?_:o+20)>>2]=e,!e)break n}while(0);if(i[e+24>>2]=o,0|(a=0|i[(r=n+16|0)>>2])&&(i[e+16>>2]=a,i[a+24>>2]=e),!(r=0|i[r+4>>2]))break;i[e+20>>2]=r,i[r+24>>2]=e}while(0);n=n+A|0,s=A+l|0}else s=l;if(i[(n=n+4|0)>>2]=-2&i[n>>2],i[u+4>>2]=1|s,i[u+s>>2]=s,n=s>>>3,s>>>0<256){r=27724+(n<<1<<2)|0,(e=0|i[6921])&(n=1<<n)?n=0|i[(e=r+8|0)>>2]:(i[6921]=e|n,n=r,e=r+8|0),i[e>>2]=u,i[n+12>>2]=u,i[u+8>>2]=n,i[u+12>>2]=r;break}n=s>>>8;do{if(n){if(s>>>0>16777215){a=31;break}a=s>>>((a=14-((y=((_=n<<(x=(n+1048320|0)>>>16&8))+520192|0)>>>16&4)|x|(a=((_<<=y)+245760|0)>>>16&2))+(_<<a>>>15)|0)+7|0)&1|a<<1}else a=0}while(0);if(n=27988+(a<<2)|0,i[u+28>>2]=a,i[(e=u+16|0)+4>>2]=0,i[e>>2]=0,!((e=0|i[6922])&(r=1<<a))){i[6922]=e|r,i[n>>2]=u,i[u+24>>2]=n,i[u+12>>2]=u,i[u+8>>2]=u;break}n=0|i[n>>2];n:do{if((-8&i[n+4>>2])!=(0|s)){for(a=s<<(31==(0|a)?0:25-(a>>>1)|0);e=0|i[(r=n+16+(a>>>31<<2)|0)>>2];){if((-8&i[e+4>>2])==(0|s)){n=e;break n}a<<=1,n=e}i[r>>2]=u,i[u+24>>2]=n,i[u+12>>2]=u,i[u+8>>2]=u;break t}}while(0);_=0|i[(x=n+8|0)>>2],i[_+12>>2]=u,i[x>>2]=u,i[u+8>>2]=_,i[u+12>>2]=n,i[u+24>>2]=0}}while(0);return N=t,0|(_=f+8|0)}for(n=28132;!((e=0|i[n>>2])>>>0<=c>>>0&&(_=e+(0|i[n+4>>2])|0)>>>0>c>>>0);)n=0|i[n+8>>2];n=(e=(e=(s=_+-47|0)+(7&(e=s+8|0)?0-e&7:0)|0)>>>0<(s=c+16|0)>>>0?c:e)+8|0,x=o+(y=7&(y=o+8|0)?0-y&7:0)|0,y=(r=A+-40|0)-y|0,i[6927]=x,i[6924]=y,i[x+4>>2]=1|y,i[o+r+4>>2]=40,i[6928]=i[7043],i[(r=e+4|0)>>2]=27,i[n>>2]=i[7033],i[n+4>>2]=i[7034],i[n+8>>2]=i[7035],i[n+12>>2]=i[7036],i[7033]=o,i[7034]=A,i[7036]=0,i[7035]=n,n=e+24|0;do{x=n,i[(n=n+4|0)>>2]=7}while((x+8|0)>>>0<_>>>0);if((0|e)!=(0|c)){if(o=e-c|0,i[r>>2]=-2&i[r>>2],i[c+4>>2]=1|o,i[e>>2]=o,n=o>>>3,o>>>0<256){r=27724+(n<<1<<2)|0,(e=0|i[6921])&(n=1<<n)?n=0|i[(e=r+8|0)>>2]:(i[6921]=e|n,n=r,e=r+8|0),i[e>>2]=c,i[n+12>>2]=c,i[c+8>>2]=n,i[c+12>>2]=r;break}if(r=27988+((a=(n=o>>>8)?o>>>0>16777215?31:o>>>((a=14-((y=((_=n<<(x=(n+1048320|0)>>>16&8))+520192|0)>>>16&4)|x|(a=((_<<=y)+245760|0)>>>16&2))+(_<<a>>>15)|0)+7|0)&1|a<<1:0)<<2)|0,i[c+28>>2]=a,i[c+20>>2]=0,i[s>>2]=0,!((n=0|i[6922])&(e=1<<a))){i[6922]=n|e,i[r>>2]=c,i[c+24>>2]=r,i[c+12>>2]=c,i[c+8>>2]=c;break}n=0|i[r>>2];t:do{if((-8&i[n+4>>2])!=(0|o)){for(a=o<<(31==(0|a)?0:25-(a>>>1)|0);e=0|i[(r=n+16+(a>>>31<<2)|0)>>2];){if((-8&i[e+4>>2])==(0|o)){n=e;break t}a<<=1,n=e}i[r>>2]=c,i[c+24>>2]=n,i[c+12>>2]=c,i[c+8>>2]=c;break e}}while(0);_=0|i[(x=n+8|0)>>2],i[_+12>>2]=c,i[x>>2]=c,i[c+8>>2]=_,i[c+12>>2]=n,i[c+24>>2]=0}}else!(0|(_=0|i[6925]))|o>>>0<_>>>0&&(i[6925]=o),i[7033]=o,i[7034]=A,i[7036]=0,i[6930]=i[7039],i[6929]=-1,i[6934]=27724,i[6933]=27724,i[6936]=27732,i[6935]=27732,i[6938]=27740,i[6937]=27740,i[6940]=27748,i[6939]=27748,i[6942]=27756,i[6941]=27756,i[6944]=27764,i[6943]=27764,i[6946]=27772,i[6945]=27772,i[6948]=27780,i[6947]=27780,i[6950]=27788,i[6949]=27788,i[6952]=27796,i[6951]=27796,i[6954]=27804,i[6953]=27804,i[6956]=27812,i[6955]=27812,i[6958]=27820,i[6957]=27820,i[6960]=27828,i[6959]=27828,i[6962]=27836,i[6961]=27836,i[6964]=27844,i[6963]=27844,i[6966]=27852,i[6965]=27852,i[6968]=27860,i[6967]=27860,i[6970]=27868,i[6969]=27868,i[6972]=27876,i[6971]=27876,i[6974]=27884,i[6973]=27884,i[6976]=27892,i[6975]=27892,i[6978]=27900,i[6977]=27900,i[6980]=27908,i[6979]=27908,i[6982]=27916,i[6981]=27916,i[6984]=27924,i[6983]=27924,i[6986]=27932,i[6985]=27932,i[6988]=27940,i[6987]=27940,i[6990]=27948,i[6989]=27948,i[6992]=27956,i[6991]=27956,i[6994]=27964,i[6993]=27964,i[6996]=27972,i[6995]=27972,x=o+(y=7&(y=o+8|0)?0-y&7:0)|0,y=(_=A+-40|0)-y|0,i[6927]=x,i[6924]=y,i[x+4>>2]=1|y,i[o+_+4>>2]=40,i[6928]=i[7043]}while(0);if((n=0|i[6924])>>>0>d>>>0)return y=n-d|0,i[6924]=y,x=(_=0|i[6927])+d|0,i[6927]=x,i[x+4>>2]=1|y,i[_+4>>2]=3|d,N=t,0|(_=_+8|0)}return i[(_=27680)>>2]=12,N=t,0|(_=0)}function Et(e){var t=0,n=0,r=0,a=0,s=0,o=0,A=0,l=0;if(e|=0){n=e+-8|0,a=0|i[6925],l=n+(t=-8&(e=0|i[e+-4>>2]))|0;do{if(1&e)A=n,o=n;else{if(r=0|i[n>>2],!(3&e))return;if(s=r+t|0,(o=n+(0-r)|0)>>>0<a>>>0)return;if((0|i[6926])==(0|o)){if(3&~(t=0|i[(e=l+4|0)>>2])){A=o,t=s;break}return i[6923]=s,i[e>>2]=-2&t,i[o+4>>2]=1|s,void(i[o+s>>2]=s)}if(n=r>>>3,r>>>0<256){if(e=0|i[o+8>>2],(0|(t=0|i[o+12>>2]))==(0|e)){i[6921]=i[6921]&~(1<<n),A=o,t=s;break}i[e+12>>2]=t,i[t+8>>2]=e,A=o,t=s;break}a=0|i[o+24>>2],e=0|i[o+12>>2];do{if((0|e)==(0|o)){if(e=0|i[(n=(t=o+16|0)+4|0)>>2])t=n;else if(!(e=0|i[t>>2])){e=0;break}for(;;)if(n=0|i[(r=e+20|0)>>2])e=n,t=r;else{if(!(n=0|i[(r=e+16|0)>>2]))break;e=n,t=r}i[t>>2]=0}else A=0|i[o+8>>2],i[A+12>>2]=e,i[e+8>>2]=A}while(0);if(a){if(t=0|i[o+28>>2],(0|i[(n=27988+(t<<2)|0)>>2])==(0|o)){if(i[n>>2]=e,!e){i[6922]=i[6922]&~(1<<t),A=o,t=s;break}}else if(i[((0|i[(A=a+16|0)>>2])==(0|o)?A:a+20)>>2]=e,!e){A=o,t=s;break}i[e+24>>2]=a,0|(n=0|i[(t=o+16|0)>>2])&&(i[e+16>>2]=n,i[n+24>>2]=e),(t=0|i[t+4>>2])?(i[e+20>>2]=t,i[t+24>>2]=e,A=o,t=s):(A=o,t=s)}else A=o,t=s}}while(0);if(!(o>>>0>=l>>>0)&&1&(r=0|i[(e=l+4|0)>>2])){if(2&r)i[e>>2]=-2&r,i[A+4>>2]=1|t,i[o+t>>2]=t,a=t;else{if((0|i[6927])==(0|l)){if(l=(0|i[6924])+t|0,i[6924]=l,i[6927]=A,i[A+4>>2]=1|l,(0|A)!=(0|i[6926]))return;return i[6926]=0,void(i[6923]=0)}if((0|i[6926])==(0|l))return l=(0|i[6923])+t|0,i[6923]=l,i[6926]=o,i[A+4>>2]=1|l,void(i[o+l>>2]=l);a=(-8&r)+t|0,n=r>>>3;do{if(r>>>0<256){if(t=0|i[l+8>>2],(0|(e=0|i[l+12>>2]))==(0|t)){i[6921]=i[6921]&~(1<<n);break}i[t+12>>2]=e,i[e+8>>2]=t;break}s=0|i[l+24>>2],e=0|i[l+12>>2];do{if((0|e)==(0|l)){if(e=0|i[(n=(t=l+16|0)+4|0)>>2])t=n;else if(!(e=0|i[t>>2])){n=0;break}for(;;)if(n=0|i[(r=e+20|0)>>2])e=n,t=r;else{if(!(n=0|i[(r=e+16|0)>>2]))break;e=n,t=r}i[t>>2]=0,n=e}else n=0|i[l+8>>2],i[n+12>>2]=e,i[e+8>>2]=n,n=e}while(0);if(0|s){if(e=0|i[l+28>>2],(0|i[(t=27988+(e<<2)|0)>>2])==(0|l)){if(i[t>>2]=n,!n){i[6922]=i[6922]&~(1<<e);break}}else if(i[((0|i[(r=s+16|0)>>2])==(0|l)?r:s+20)>>2]=n,!n)break;i[n+24>>2]=s,0|(t=0|i[(e=l+16|0)>>2])&&(i[n+16>>2]=t,i[t+24>>2]=n),0|(e=0|i[e+4>>2])&&(i[n+20>>2]=e,i[e+24>>2]=n)}}while(0);if(i[A+4>>2]=1|a,i[o+a>>2]=a,(0|A)==(0|i[6926]))return void(i[6923]=a)}if(e=a>>>3,a>>>0<256)return n=27724+(e<<1<<2)|0,(t=0|i[6921])&(e=1<<e)?e=0|i[(t=n+8|0)>>2]:(i[6921]=t|e,e=n,t=n+8|0),i[t>>2]=A,i[e+12>>2]=A,i[A+8>>2]=e,void(i[A+12>>2]=n);e=27988+((r=(e=a>>>8)?a>>>0>16777215?31:a>>>((r=14-((s=((l=e<<(o=(e+1048320|0)>>>16&8))+520192|0)>>>16&4)|o|(r=((l<<=s)+245760|0)>>>16&2))+(l<<r>>>15)|0)+7|0)&1|r<<1:0)<<2)|0,i[A+28>>2]=r,i[A+20>>2]=0,i[A+16>>2]=0,t=0|i[6922],n=1<<r;e:do{if(t&n){e=0|i[e>>2];t:do{if((-8&i[e+4>>2])!=(0|a)){for(r=a<<(31==(0|r)?0:25-(r>>>1)|0);t=0|i[(n=e+16+(r>>>31<<2)|0)>>2];){if((-8&i[t+4>>2])==(0|a)){e=t;break t}r<<=1,e=t}i[n>>2]=A,i[A+24>>2]=e,i[A+12>>2]=A,i[A+8>>2]=A;break e}}while(0);l=0|i[(o=e+8|0)>>2],i[l+12>>2]=A,i[o>>2]=A,i[A+8>>2]=l,i[A+12>>2]=e,i[A+24>>2]=0}else i[6922]=t|n,i[e>>2]=A,i[A+24>>2]=e,i[A+12>>2]=A,i[A+8>>2]=A}while(0);if(l=(0|i[6929])-1|0,i[6929]=l,!(0|l)){for(e=28140;e=0|i[e>>2];)e=e+8|0;i[6929]=-1}}}}function Ct(e,t){t|=0;var n=0;return(e|=0)?(n=0|v(t,e),(t|e)>>>0>65535&&(n=((n>>>0)/(e>>>0)|0)==(0|t)?n:-1)):n=0,(e=0|Mt(n))&&3&i[e+-4>>2]?(Wt(0|e,0,0|n),0|e):0|e}function It(e,t){t|=0;var n=0,r=0;return(e|=0)?t>>>0>4294967231?(i[(t=27680)>>2]=12,0|(t=0)):(n=0|function(e,t){e|=0,t|=0;var n=0,r=0,a=0,s=0,o=0,A=0,l=0,c=0,u=0,f=0;if(u=e+4|0,f=0|i[u>>2],n=-8&f,A=e+n|0,!(3&f))return t>>>0<256?0|(e=0):n>>>0>=(t+4|0)>>>0&&(n-t|0)>>>0<=i[7041]<<1>>>0?0|e:0|(e=0);if(n>>>0>=t>>>0)return(n=n-t|0)>>>0<=15||(c=e+t|0,i[u>>2]=1&f|t|2,i[c+4>>2]=3|n,i[(f=A+4|0)>>2]=1|i[f>>2],Rt(c,n)),0|e;if((0|i[6927])==(0|A))return n=(c=(0|i[6924])+n|0)-t|0,r=e+t|0,c>>>0<=t>>>0?0|(e=0):(i[u>>2]=1&f|t|2,i[r+4>>2]=1|n,i[6927]=r,i[6924]=n,0|e);if((0|i[6926])==(0|A))return(r=(0|i[6923])+n|0)>>>0<t>>>0?0|(e=0):((n=r-t|0)>>>0>15?(c=e+t|0,r=e+r|0,i[u>>2]=1&f|t|2,i[c+4>>2]=1|n,i[r>>2]=n,i[(r=r+4|0)>>2]=-2&i[r>>2],r=c):(i[u>>2]=1&f|r|2,i[(r=e+r+4|0)>>2]=1|i[r>>2],r=0,n=0),i[6923]=n,i[6926]=r,0|e);if(r=0|i[A+4>>2],2&r)return 0|(e=0);if(l=(-8&r)+n|0,l>>>0<t>>>0)return 0|(e=0);c=l-t|0,a=r>>>3;do{if(r>>>0<256){if(r=0|i[A+8>>2],(0|(n=0|i[A+12>>2]))==(0|r)){i[6921]=i[6921]&~(1<<a);break}i[r+12>>2]=n,i[n+8>>2]=r;break}o=0|i[A+24>>2],n=0|i[A+12>>2];do{if((0|n)==(0|A)){if(n=0|i[(a=(r=A+16|0)+4|0)>>2])r=a;else if(!(n=0|i[r>>2])){a=0;break}for(;;)if(a=0|i[(s=n+20|0)>>2])n=a,r=s;else{if(!(a=0|i[(s=n+16|0)>>2]))break;n=a,r=s}i[r>>2]=0,a=n}else a=0|i[A+8>>2],i[a+12>>2]=n,i[n+8>>2]=a,a=n}while(0);if(0|o){if(n=0|i[A+28>>2],(0|i[(r=27988+(n<<2)|0)>>2])==(0|A)){if(i[r>>2]=a,!a){i[6922]=i[6922]&~(1<<n);break}}else if(i[((0|i[(s=o+16|0)>>2])==(0|A)?s:o+20)>>2]=a,!a)break;i[a+24>>2]=o,0|(r=0|i[(n=A+16|0)>>2])&&(i[a+16>>2]=r,i[r+24>>2]=a),0|(n=0|i[n+4>>2])&&(i[a+20>>2]=n,i[n+24>>2]=a)}}while(0);return c>>>0<16?(i[u>>2]=1&f|l|2,i[(f=e+l+4|0)>>2]=1|i[f>>2],0|e):(A=e+t|0,i[u>>2]=1&f|t|2,i[A+4>>2]=3|c,i[(f=e+l+4|0)>>2]=1|i[f>>2],Rt(A,c),0|e)}(e+-8|0,t>>>0<11?16:t+11&-8),0|n?0|(t=n+8|0):(n=0|Mt(t))?(Qt(0|n,0|e,0|((r=(-8&(r=0|i[e+-4>>2]))-(3&r?4:8)|0)>>>0<t>>>0?r:t)),Et(e),0|(t=n)):0|(t=0)):0|(t=0|Mt(t))}function Rt(e,t){var n=0,r=0,a=0,s=0,o=0,A=0;A=(e|=0)+(t|=0)|0,n=0|i[e+4>>2];do{if(1&n)o=e;else{if(a=0|i[e>>2],!(3&n))return;if(o=e+(0-a)|0,t=a+t|0,(0|i[6926])==(0|o)){if(3&~(n=0|i[(e=A+4|0)>>2]))break;return i[6923]=t,i[e>>2]=-2&n,i[o+4>>2]=1|t,void(i[A>>2]=t)}if(r=a>>>3,a>>>0<256){if(e=0|i[o+8>>2],(0|(n=0|i[o+12>>2]))==(0|e)){i[6921]=i[6921]&~(1<<r);break}i[e+12>>2]=n,i[n+8>>2]=e;break}s=0|i[o+24>>2],e=0|i[o+12>>2];do{if((0|e)==(0|o)){if(e=0|i[(r=(n=o+16|0)+4|0)>>2])n=r;else if(!(e=0|i[n>>2])){e=0;break}for(;;)if(r=0|i[(a=e+20|0)>>2])e=r,n=a;else{if(!(r=0|i[(a=e+16|0)>>2]))break;e=r,n=a}i[n>>2]=0}else a=0|i[o+8>>2],i[a+12>>2]=e,i[e+8>>2]=a}while(0);if(s){if(n=0|i[o+28>>2],(0|i[(r=27988+(n<<2)|0)>>2])==(0|o)){if(i[r>>2]=e,!e){i[6922]=i[6922]&~(1<<n);break}}else if(i[((0|i[(a=s+16|0)>>2])==(0|o)?a:s+20)>>2]=e,!e)break;i[e+24>>2]=s,0|(r=0|i[(n=o+16|0)>>2])&&(i[e+16>>2]=r,i[r+24>>2]=e),(n=0|i[n+4>>2])&&(i[e+20>>2]=n,i[n+24>>2]=e)}}}while(0);if(2&(r=0|i[(e=A+4|0)>>2]))i[e>>2]=-2&r,i[o+4>>2]=1|t,i[o+t>>2]=t,a=t;else{if((0|i[6927])==(0|A)){if(A=(0|i[6924])+t|0,i[6924]=A,i[6927]=o,i[o+4>>2]=1|A,(0|o)!=(0|i[6926]))return;return i[6926]=0,void(i[6923]=0)}if((0|i[6926])==(0|A))return A=(0|i[6923])+t|0,i[6923]=A,i[6926]=o,i[o+4>>2]=1|A,void(i[o+A>>2]=A);a=(-8&r)+t|0,n=r>>>3;do{if(r>>>0<256){if(e=0|i[A+8>>2],(0|(t=0|i[A+12>>2]))==(0|e)){i[6921]=i[6921]&~(1<<n);break}i[e+12>>2]=t,i[t+8>>2]=e;break}s=0|i[A+24>>2],t=0|i[A+12>>2];do{if((0|t)==(0|A)){if(t=0|i[(n=(e=A+16|0)+4|0)>>2])e=n;else if(!(t=0|i[e>>2])){n=0;break}for(;;)if(n=0|i[(r=t+20|0)>>2])t=n,e=r;else{if(!(n=0|i[(r=t+16|0)>>2]))break;t=n,e=r}i[e>>2]=0,n=t}else n=0|i[A+8>>2],i[n+12>>2]=t,i[t+8>>2]=n,n=t}while(0);if(0|s){if(t=0|i[A+28>>2],(0|i[(e=27988+(t<<2)|0)>>2])==(0|A)){if(i[e>>2]=n,!n){i[6922]=i[6922]&~(1<<t);break}}else if(i[((0|i[(r=s+16|0)>>2])==(0|A)?r:s+20)>>2]=n,!n)break;i[n+24>>2]=s,0|(e=0|i[(t=A+16|0)>>2])&&(i[n+16>>2]=e,i[e+24>>2]=n),0|(t=0|i[t+4>>2])&&(i[n+20>>2]=t,i[t+24>>2]=n)}}while(0);if(i[o+4>>2]=1|a,i[o+a>>2]=a,(0|o)==(0|i[6926]))return void(i[6923]=a)}if(t=a>>>3,a>>>0<256)return n=27724+(t<<1<<2)|0,(e=0|i[6921])&(t=1<<t)?t=0|i[(e=n+8|0)>>2]:(i[6921]=e|t,t=n,e=n+8|0),i[e>>2]=o,i[t+12>>2]=o,i[o+8>>2]=t,void(i[o+12>>2]=n);if(t=27988+((r=(t=a>>>8)?a>>>0>16777215?31:a>>>((r=14-((n=((A=t<<(s=(t+1048320|0)>>>16&8))+520192|0)>>>16&4)|s|(r=((A<<=n)+245760|0)>>>16&2))+(A<<r>>>15)|0)+7|0)&1|r<<1:0)<<2)|0,i[o+28>>2]=r,i[o+20>>2]=0,i[o+16>>2]=0,!((e=0|i[6922])&(n=1<<r)))return i[6922]=e|n,i[t>>2]=o,i[o+24>>2]=t,i[o+12>>2]=o,void(i[o+8>>2]=o);t=0|i[t>>2];e:do{if((-8&i[t+4>>2])!=(0|a)){for(r=a<<(31==(0|r)?0:25-(r>>>1)|0);e=0|i[(n=t+16+(r>>>31<<2)|0)>>2];){if((-8&i[e+4>>2])==(0|a)){t=e;break e}r<<=1,t=e}return i[n>>2]=o,i[o+24>>2]=t,i[o+12>>2]=o,void(i[o+8>>2]=o)}}while(0);A=0|i[(s=t+8|0)>>2],i[A+12>>2]=o,i[s>>2]=o,i[o+8>>2]=A,i[o+12>>2]=t,i[o+24>>2]=0}function Pt(e,t,n,r){return 0|(T((t|=0)+(r|=0)+((n=(e|=0)+(n|=0)>>>0)>>>0<e>>>0|0)>>>0|0),n)}function Nt(e,t,n,r){return 0|(T(0|(r=(t|=0)-(r|=0)-((n|=0)>>>0>(e|=0)>>>0|0)>>>0)),e-n>>>0)}function kt(e){return 0|((e|=0)?31-(0|_(e^e-1)):32)}function Lt(e,t,n,r,a){a|=0;var s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0;if(u=e|=0,o=n|=0,A=d=r|=0,!(c=l=t|=0))return s=!!(0|a),A?s?(i[a>>2]=0|e,i[a+4>>2]=0&t,a=0,0|(T(0|(d=0)),a)):(a=0,0|(T(0|(d=0)),a)):(s&&(i[a>>2]=(u>>>0)%(o>>>0),i[a+4>>2]=0),a=(u>>>0)/(o>>>0)>>>0,0|(T(0|(d=0)),a));s=!(0|A);do{if(o){if(!s){if((s=(0|_(0|A))-(0|_(0|c))|0)>>>0<=31){o=f=s+1|0,e=u>>>(f>>>0)&(t=s-31>>31)|c<<(A=31-s|0),t&=c>>>(f>>>0),s=0,A=u<<A;break}return a?(i[a>>2]=0|e,i[a+4>>2]=l|0&t,a=0,0|(T(0|(d=0)),a)):(a=0,0|(T(0|(d=0)),a))}if((s=o-1|0)&o|0){o=A=33+(0|_(0|o))-(0|_(0|c))|0,e=(f=32-A|0)-1>>31&c>>>((h=A-32|0)>>>0)|(c<<f|u>>>(A>>>0))&(t=h>>31),t&=c>>>(A>>>0),s=u<<(p=64-A|0)&(l=f>>31),A=(c<<p|u>>>(h>>>0))&l|u<<f&A-33>>31;break}return 0|a&&(i[a>>2]=s&u,i[a+4>>2]=0),1==(0|o)?(p=0|e,0|(T(0|(h=l|0&t)),p)):(h=c>>>((p=0|kt(0|o))>>>0)|0,p=c<<32-p|u>>>(p>>>0),0|(T(0|h),p))}if(s)return 0|a&&(i[a>>2]=(c>>>0)%(o>>>0),i[a+4>>2]=0),p=(c>>>0)/(o>>>0)>>>0,0|(T(0|(h=0)),p);if(!u)return 0|a&&(i[a>>2]=0,i[a+4>>2]=(c>>>0)%(A>>>0)),p=(c>>>0)/(A>>>0)>>>0,0|(T(0|(h=0)),p);if(!((s=A-1|0)&A))return 0|a&&(i[a>>2]=0|e,i[a+4>>2]=s&c|0&t),h=0,p=c>>>((0|kt(0|A))>>>0),0|(T(0|h),p);if((s=(0|_(0|A))-(0|_(0|c))|0)>>>0<=30){o=t=s+1|0,e=c<<(A=31-s|0)|u>>>(t>>>0),t=c>>>(t>>>0),s=0,A=u<<A;break}return a?(i[a>>2]=0|e,i[a+4>>2]=l|0&t,p=0,0|(T(0|(h=0)),p)):(p=0,0|(T(0|(h=0)),p))}while(0);if(o){c=0|Pt(0|(f=0|n),0|(u=d|0&r),-1,-1),n=0|S(),l=A,A=0;do{r=l,l=s>>>31|l<<1,s=A|s<<1,Nt(0|c,0|n,0|(r=e<<1|r>>>31),0|(d=e>>>31|t<<1)),A=1&(h=(p=0|S())>>31|((0|p)<0?-1:0)<<1),e=0|Nt(0|r,0|d,h&f|0,(((0|p)<0?-1:0)>>31|((0|p)<0?-1:0)<<1)&u),t=0|S(),o=o-1|0}while(0|o);c=l,l=0}else c=A,l=0,A=0;return o=0,0|a&&(i[a>>2]=e,i[a+4>>2]=t),p=s<<1&-2|A,0|(T(0|(h=(0|s)>>>31|(c|o)<<1|l)),p)}function Bt(e,t,n,r){n|=0;var i,a,s,o,A;return a=(r|=0)>>31|((0|r)<0?-1:0)<<1,i=((0|r)<0?-1:0)>>31|((0|r)<0?-1:0)<<1,s=0|Nt((A=(t|=0)>>31|((0|t)<0?-1:0)<<1)^(e|=0)|0,(o=((0|t)<0?-1:0)>>31|((0|t)<0?-1:0)<<1)^t|0,0|A,0|o),e=a^A,t=i^o,0|Nt((0|Lt(s,0|S(),0|Nt(a^n|0,i^r|0,0|a,0|i),0|S(),0))^e,(0|S())^t,0|e,0|t)}function Ot(e,t,n,r){t|=0,r|=0;var i,a;return n=0|function(e,t){var n,r,i,a=0;return e=((n=0|v(a=65535&(t|=0),i=65535&(e|=0)))>>>16)+(0|v(a,r=e>>>16))|0,t=0|v(a=t>>>16,i),0|(T((e>>>16)+(0|v(a,r))+(((65535&e)+t|0)>>>16)|0),e+t<<16|65535&n)}(i=e|=0,a=n|=0),e=0|S(),0|(T((0|v(t,a))+(0|v(r,i))+e|0&e),n)}function Ft(e,t,n,r){n|=0;var a,s,o,A,l,c;return a=N,N=N+16|0,A=0|a,c=(r|=0)>>31|((0|r)<0?-1:0)<<1,l=((0|r)<0?-1:0)>>31|((0|r)<0?-1:0)<<1,Lt(e=0|Nt((o=(t|=0)>>31|((0|t)<0?-1:0)<<1)^(e|=0)|0,(s=((0|t)<0?-1:0)>>31|((0|t)<0?-1:0)<<1)^t|0,0|o,0|s),t=0|S(),0|Nt(c^n|0,l^r|0,0|c,0|l),0|S(),A),r=0|Nt(i[A>>2]^o|0,i[A+4>>2]^s|0,0|o,0|s),n=0|S(),N=a,0|(T(0|n),r)}function Dt(e,t,n,r){var a,s;return s=N,N=N+16|0,Lt(e|=0,t|=0,n|=0,r|=0,a=0|s),N=s,0|(T(0|i[a+4>>2]),i[a>>2])}function Ut(e,t,n){return e|=0,t|=0,(0|(n|=0))<32?(T(t>>n|0),e>>>n|(t&(1<<n)-1)<<32-n):(T(0|((0|t)<0?-1:0)),t>>n-32)}function Vt(e,t,n){return e|=0,t|=0,(0|(n|=0))<32?(T(t>>>n|0),e>>>n|(t&(1<<n)-1)<<32-n):(T(0),t>>>n-32|0)}function jt(e,t,n){return e|=0,t|=0,(0|(n|=0))<32?(T(t<<n|(e&(1<<n)-1<<32-n)>>>32-n),e<<n):(T(e<<n-32),0)}function zt(e,t,n){return e|=0,32==(0|(t=0|_(t|=0)))&&(t=t+(0|_(e))|0),T(0),0|t}function Gt(e,t){return t=+t,(e=+e)!=e?+t:t!=t?+e:+x(+e,+t)}function Ht(e,t){return t=+t,(e=+e)!=e?+t:t!=t?+e:+y(+e,+t)}function qt(e){return(e=+e)>=0?+A(e+.5):+b(e-.5)}function Qt(e,t,n){e|=0,t|=0;var a,s,o=0;if((0|(n|=0))>=8192)return I(0|e,0|t,0|n),0|e;if(s=0|e,a=e+n|0,(3&e)==(3&t)){for(;3&e;){if(!n)return 0|s;r[e|0]=0|r[t|0],e=e+1|0,t=t+1|0,n=n-1|0}for(o=(n=-4&a)-64|0;(0|e)<=(0|o);)i[e>>2]=i[t>>2],i[e+4>>2]=i[t+4>>2],i[e+8>>2]=i[t+8>>2],i[e+12>>2]=i[t+12>>2],i[e+16>>2]=i[t+16>>2],i[e+20>>2]=i[t+20>>2],i[e+24>>2]=i[t+24>>2],i[e+28>>2]=i[t+28>>2],i[e+32>>2]=i[t+32>>2],i[e+36>>2]=i[t+36>>2],i[e+40>>2]=i[t+40>>2],i[e+44>>2]=i[t+44>>2],i[e+48>>2]=i[t+48>>2],i[e+52>>2]=i[t+52>>2],i[e+56>>2]=i[t+56>>2],i[e+60>>2]=i[t+60>>2],e=e+64|0,t=t+64|0;for(;(0|e)<(0|n);)i[e>>2]=i[t>>2],e=e+4|0,t=t+4|0}else for(n=a-4|0;(0|e)<(0|n);)r[e|0]=0|r[t|0],r[e+1|0]=0|r[t+1|0],r[e+2|0]=0|r[t+2|0],r[e+3|0]=0|r[t+3|0],e=e+4|0,t=t+4|0;for(;(0|e)<(0|a);)r[e|0]=0|r[t|0],e=e+1|0,t=t+1|0;return 0|s}function Kt(e,t,n){var i=0;if((0|(t|=0))<(0|(e|=0))&(0|e)<(t+(n|=0)|0)){for(i=e,t=t+n|0,e=e+n|0;(0|n)>0;)t=t-1|0,n=n-1|0,r[(e=e-1|0)|0]=0|r[t|0];e=i}else Qt(e,t,n);return 0|e}function Wt(e,t,n){t|=0;var a,s=0,o=0,A=0;if(a=(e|=0)+(n|=0)|0,t&=255,(0|n)>=67){for(;3&e;)r[e|0]=t,e=e+1|0;for(A=t|t<<8|t<<16|t<<24,o=(s=-4&a)-64|0;(0|e)<=(0|o);)i[e>>2]=A,i[e+4>>2]=A,i[e+8>>2]=A,i[e+12>>2]=A,i[e+16>>2]=A,i[e+20>>2]=A,i[e+24>>2]=A,i[e+28>>2]=A,i[e+32>>2]=A,i[e+36>>2]=A,i[e+40>>2]=A,i[e+44>>2]=A,i[e+48>>2]=A,i[e+52>>2]=A,i[e+56>>2]=A,i[e+60>>2]=A,e=e+64|0;for(;(0|e)<(0|s);)i[e>>2]=A,e=e+4|0}for(;(0|e)<(0|a);)r[e|0]=t,e=e+1|0;return a-n|0}function Jt(e){return(e=+e)>=0?+A(e+.5):+b(e-.5)}function $t(e){e|=0;var t,n,r;return r=0|C(),(0|e)>0&(0|(t=(n=0|i[o>>2])+e|0))<(0|n)|(0|t)<0?(P(0|t),E(12),-1):(0|t)>(0|r)&&!(0|R(0|t))?(E(12),-1):(i[o>>2]=t,0|n)}var Xt=[function(e,t){return w(0),0},function(e,t){t|=0;var n=0,r=0;return e=0|i[(r=e|=0)>>2],r=0|i[r+4>>2],t=0|i[(n=t)>>2],0|(r>>>0<(n=0|i[n+4>>2])>>>0|(0|r)==(0|n)&e>>>0<t>>>0?-1:1&(r>>>0>n>>>0|(0|r)==(0|n)&e>>>0>t>>>0))},function(e,t){t|=0;var n,r,s,o,A=0,l=0;return o=0|i[(l=e|=0)>>2],l=0|i[l+4>>2],s=0|i[(A=t)>>2],l>>>0<(A=0|i[A+4>>2])>>>0|(0|l)==(0|A)&o>>>0<s>>>0?0|(t=-1):l>>>0>A>>>0|(0|l)==(0|A)&o>>>0>s>>>0?0|(t=1):(r=+a[e+8>>3])<(n=+a[t+8>>3])?0|(t=-1):0|(t=r>n&1)},function(e,t){var n,r;return t|=0,0|((r=+a[(e|=0)>>3])>(n=+a[t>>3])?-1:r<n&1)}];return{___divdi3:Bt,___muldi3:Ot,___remdi3:Ft,___uremdi3:Dt,_areNeighborCells:function(e,t,n,r,a){a|=0;var s,o,A,l=0,c=0,u=0,f=0;if(A=N,N=N+64|0,o=A,s=A+56|0,!(!0&134217728==(2013265920&(t|=0))&!0&134217728==(2013265920&(r|=0))))return N=A,0|(a=5);if((0|(e|=0))==(0|(n|=0))&(0|t)==(0|r))return i[a>>2]=0,N=A,0|(a=0);if(c=0|Vt(0|e,0|t,52),S(),c&=15,f=0|Vt(0|n,0|r,52),S(),(0|c)!=(15&f))return N=A,0|(a=12);if(l=c+-1|0,c>>>0>1){we(e,t,l,o),we(n,r,l,s),u=0|i[(f=o)>>2],f=0|i[f+4>>2];e:do{if((0|u)==(0|i[s>>2])&&(0|f)==(0|i[s+4>>2])){l=0|Vt(0|e,0|t,0|(c=3*(15^c)|0)),S(),l&=7,c=0|Vt(0|n,0|r,0|c),S(),c&=7;do{if(!(0|l)|!(0|c))i[a>>2]=1,l=0;else if(7==(0|l))l=5;else{if(1==(0|l)|1==(0|c)&&0|Se(u,f)){l=5;break}if((0|i[15824+(l<<2)>>2])!=(0|c)&&(0|i[15856+(l<<2)>>2])!=(0|c))break e;i[a>>2]=1,l=0}}while(0);return N=A,0|(a=l)}}while(0)}c=(l=o)+56|0;do{i[l>>2]=0,l=l+4|0}while((0|l)<(0|c));return k(e,t,1,o),l=(0|i[(t=o)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+8|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+16|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+24|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+32|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)||(0|i[(t=o+40|0)>>2])==(0|n)&&(0|i[t+4>>2])==(0|r)?1:1&((0|i[(l=o+48|0)>>2])==(0|n)?(0|i[l+4>>2])==(0|r):0),i[a>>2]=l,N=A,0|(a=0)},_bitshift64Ashr:Ut,_bitshift64Lshr:Vt,_bitshift64Shl:jt,_calloc:Ct,_cellAreaKm2:function(e,t,n){n|=0;var r,s,o,A=0;return o=N,N=N+192|0,r=o+176|0,A=o+168|0,(e=0|Ue(e|=0,t|=0,s=o))?(N=o,0|(A=e)):(i[A>>2]=i[s>>2],i[A+4>>2]=s+8,i[r>>2]=i[A>>2],i[r+4>>2]=i[A+4>>2],z(r,n),a[n>>3]=40589732.49931477*+a[n>>3],N=o,0|(A=0))},_cellAreaM2:function(e,t,n){n|=0;var r,s,o,A=0;return o=N,N=N+192|0,r=o+176|0,A=o+168|0,(e=0|Ue(e|=0,t|=0,s=o))?(N=o,0|(A=e)):(i[A>>2]=i[s>>2],i[A+4>>2]=s+8,i[r>>2]=i[A>>2],i[r+4>>2]=i[A+4>>2],z(r,n),a[n>>3]=40589732.49931477*+a[n>>3]*1e6,N=o,0|(A=0))},_cellAreaRads2:function(e,t,n){n|=0;var r,a,s,o=0;return s=N,N=N+192|0,r=s+176|0,o=s+168|0,0|(e=0|Ue(e|=0,t|=0,a=s))?(N=s,0|(o=e)):(i[o>>2]=i[a>>2],i[o+4>>2]=a+8,i[r>>2]=i[o>>2],i[r+4>>2]=i[o+4>>2],z(r,n),N=s,0|(o=0))},_cellToBoundary:Ue,_cellToCenterChild:Ee,_cellToChildPos:function(e,t,n,r){n|=0,r|=0;var a,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0;if(a=N,N=N+16|0,b=a,v=0|Vt(0|(e|=0),0|(t|=0),52),S(),v&=15,n>>>0>15)return N=a,0|(v=4);if((0|v)<(0|n))return N=a,0|(v=12);if((0|v)!=(0|n))if(o=0|jt(0|n,0,52),o|=e,l=S()|-15728641&t,(0|v)>(0|n)){c=n;do{g=0|jt(7,0,3*(14-c|0)|0),c=c+1|0,o|=g,l=0|S()|l}while((0|c)<(0|v));g=o}else g=o;else g=e,l=t;m=0|Vt(0|g,0|l,45),S();e:do{if(0|G(127&m)){if(c=0|Vt(0|g,0|l,52),S(),0|(c&=15))for(o=1;;){if(!(!((m=0|jt(7,0,3*(15-o|0)|0))&g|0)&!((0|S())&l))){u=33;break e}if(!(o>>>0<c>>>0))break;o=o+1|0}if(i[(m=r)>>2]=0,i[m+4>>2]=0,(0|v)>(0|n)){for(m=-15728641&t,p=v;;){if(h=p,(p=p+-1|0)>>>0>15|(0|v)<(0|p)){u=19;break}if((0|v)!=(0|p))if(o=0|jt(0|p,0,52),o|=e,c=0|S()|m,(0|v)<(0|h))d=o;else{u=p;do{d=0|jt(7,0,3*(14-u|0)|0),u=u+1|0,o|=d,c=0|S()|c}while((0|u)<(0|v));d=o}else d=e,c=t;if(f=0|Vt(0|d,0|c,45),S(),0|G(127&f)){f=0|Vt(0|d,0|c,52),S(),f&=15;t:do{if(f)for(u=1;;){if(o=0|Vt(0|d,0|c,3*(15-u|0)|0),S(),0|(o&=7))break t;if(!(u>>>0<f>>>0)){o=0;break}u=u+1|0}else o=0}while(0);o=1&!(0|o)}else o=0;if(c=0|Vt(0|e,0|t,3*(15-h|0)|0),S(),7==(0|(c&=7))){s=5,u=42;break}if(1==(0|c)&(o=!!(0|o))){s=5,u=42;break}if(0|(d=c+((!!(0|c)&o)<<31>>31)|0)&&(u=0|Ze(7,0,u=v-h|0,((0|u)<0)<<31>>31),f=0|S(),o?(o=0|Pt(0|(o=0|Ot(0|u,0|f,5,0)),0|S(),-5,-1),o=0|Pt(0|(o=0|Bt(0|o,0|S(),6,0)),0|S(),1,0),c=0|S()):(o=u,c=f),h=0|Pt(0|o,0|c,0|(h=0|Ot(0|u,0|f,0|(h=d+-1|0),((0|h)<0)<<31>>31)),0|S()),f=0|Pt(0|h,0|(d=0|S()),0|i[(f=r)>>2],0|i[f+4>>2]),d=0|S(),i[(h=r)>>2]=f,i[h+4>>2]=d),(0|p)<=(0|n)){u=37;break}}if(19==(0|u))M(27634,27225,1407,27259);else{if(37==(0|u)){s=0|i[(A=r)+4>>2],A=0|i[A>>2];break}if(42==(0|u))return N=a,0|s}}else s=0,A=0}else u=33}while(0);e:do{if(33==(0|u)){if(i[(m=r)>>2]=0,i[m+4>>2]=0,(0|v)>(0|n)){for(o=v;;){if(s=0|Vt(0|e,0|t,3*(15-o|0)|0),S(),7==(0|(s&=7))){s=5;break}if(s=0|Ot(0|(A=0|Ze(7,0,A=v-o|0,((0|A)<0)<<31>>31)),0|S(),0|s,0),A=0|S(),A=0|Pt(0|i[(m=r)>>2],0|i[m+4>>2],0|s,0|A),s=0|S(),i[(m=r)>>2]=A,i[m+4>>2]=s,(0|(o=o+-1|0))<=(0|n))break e}return N=a,0|s}s=0,A=0}}while(0);return 0|Te(g,l,v,b)&&M(27634,27225,1367,27274),((0|s)>-1|-1==(0|s)&A>>>0>4294967295)&((0|(b=0|i[(v=b)+4>>2]))>(0|s)|((0|b)==(0|s)?(0|i[v>>2])>>>0>A>>>0:0))?(N=a,0|(v=0)):(M(27634,27225,1447,27259),0)},_cellToChildren:function(e,t,n,r){r|=0;var a,s,o=0,A=0;if(s=N,N=N+16|0,je(a=s,e|=0,t|=0,n|=0),!(0|(e=0|i[(t=a)>>2]))&!(0|(t=0|i[t+4>>2])))return N=s,0;o=0,n=0;do{i[(A=r+(o<<3)|0)>>2]=e,i[A+4>>2]=t,o=0|Pt(0|o,0|n,1,0),n=0|S(),Ge(a),e=0|i[(A=a)>>2],t=0|i[A+4>>2]}while(!(!(0|e)&!(0|t)));return N=s,0},_cellToChildrenSize:Te,_cellToLatLng:De,_cellToLocalIj:function(e,t,n,r,a,s){s|=0;var o,A=0;return o=N,N=N+16|0,A=o,0|(a|=0)?(N=o,0|(A=15)):((e=0|Je(e|=0,t|=0,n|=0,r|=0,A))||(a=0|i[A+4>>2],e=0|i[A+8>>2],i[s>>2]=(0|i[A>>2])-e,i[s+4>>2]=a-e,e=0),N=o,0|(A=e))},_cellToParent:we,_cellToVertex:pt,_cellToVertexes:function(e,t,n){n|=0;var r,a=0,s=0;return s=!(0|Se(e|=0,t|=0)),r=!(0|(a=0|pt(e,t,0,n))),s?r?0|(a=0|pt(e,t,1,n+8|0))||0|(a=0|pt(e,t,2,n+16|0))||0|(a=0|pt(e,t,3,n+24|0))||(a=0|pt(e,t,4,n+32|0))?0|(s=a):0|pt(e,t,5,n+40|0):0|(s=a):r?0|(a=0|pt(e,t,1,n+8|0))||0|(a=0|pt(e,t,2,n+16|0))||0|(a=0|pt(e,t,3,n+24|0))||0|(a=0|pt(e,t,4,n+32|0))?0|(s=a):(i[(s=n+40|0)>>2]=0,i[s+4>>2]=0,0|(s=0)):0|(s=a)},_cellsToDirectedEdge:function(e,t,n,r,a){return a|=0,7==(0|(n=0|V(e|=0,t|=0,n|=0,r|=0)))?0|(a=11):(r=0|jt(0|n,0,56),t=-2130706433&t|S()|268435456,i[a>>2]=e|r,i[a+4>>2]=t,0|(a=0))},_cellsToLinkedMultiPolygon:function(e,t,n){n|=0;var r,a,s=0,o=0,A=0,l=0,c=0;if(a=N,N=N+16|0,0|(e=0|ie(e|=0,t|=0,((0|t)<0)<<31>>31,A=a)))return N=a,0|(A=e);if(r=0|function(e,t){e|=0,t|=0;var n=0,r=0,a=0,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0;if(i[t>>2]=0,g=t+4|0,i[g>>2]=0,b=t+8|0,i[b>>2]=0,m=0|i[e>>2],(0|m)<=0)return 0|(t=0);p=e+4|0,e=t,h=0;e:for(;;){if(h){if(!(n=0|Ct(1,12))){n=5;break}i[e+8>>2]=n,e=n}if(l=0|i[p>>2],!(c=0|Ct(1,12))){e=13,n=37;break}if(r=0|i[(d=e+4|0)>>2],i[(0|r?r+8:e)>>2]=c,i[d>>2]=c,(0|(r=0|i[l+(h<<4)>>2]))<3){e=1,n=37;break}a=l+(h<<4)+4|0,s=c+4|0,n=0,o=0;do{if(A=o,!(o=0|Mt(24))){e=13,n=37;break e}Kt(0|o,(0|i[a>>2])+(n<<4)|0,16),i[o+16>>2]=0,A?i[A+16>>2]=o:i[c>>2]=o,i[s>>2]=o,n=n+1|0}while((0|n)<(0|r));if((0|(f=0|i[l+(h<<4)+8>>2]))>0){u=l+(h<<4)+12|0,l=0;do{if(r=0|i[u>>2],n=c,!(c=0|Ct(1,12))){e=13,n=37;break e}if(i[n+8>>2]=c,i[d>>2]=c,(0|(A=0|i[r+(l<<3)>>2]))<3){e=1,n=37;break e}r=r+(l<<3)+4|0,a=c+4|0,n=0,s=0;do{if(o=s,!(s=0|Mt(24))){e=13,n=37;break e}Kt(0|s,(0|i[r>>2])+(n<<4)|0,16),i[s+16>>2]=0,o?i[o+16>>2]=s:i[c>>2]=s,i[a>>2]=s,n=n+1|0}while((0|n)<(0|A));l=l+1|0}while((0|l)<(0|f))}if((0|(h=h+1|0))>=(0|m)){e=0,n=50;break}}if(5==(0|n)){if(!t)return 0|(t=13);for(r=1,a=t;;){if(0|(e=0|i[a>>2]))do{if(0|(n=0|i[e>>2]))do{m=n,n=0|i[n+16>>2],Et(m)}while(0|n);m=e,e=0|i[e+8>>2],Et(m)}while(0|e);if(e=a,a=0|i[a+8>>2],r?(i[t>>2]=0,i[g>>2]=0,i[b>>2]=0):Et(e),!a){e=13;break}r=0}return 0|e}if(37==(0|n)){if(!t)return 0|(t=e);for(a=1,s=t;;){if(0|(n=0|i[s>>2]))do{if(0|(r=0|i[n>>2]))do{m=r,r=0|i[r+16>>2],Et(m)}while(0|r);m=n,n=0|i[n+8>>2],Et(m)}while(0|n);if(n=s,s=0|i[s+8>>2],a?(i[t>>2]=0,i[g>>2]=0,i[b>>2]=0):Et(n),!s)break;a=0}return 0|e}if(50==(0|n))return 0|e;return 0}(A,n),n=A+4|0,(0|i[A>>2])>0){t=0;do{if(o=0|i[n>>2],Et(0|i[(s=o+(t<<4)+4|0)>>2]),i[s>>2]=0,i[o+(t<<4)>>2]=0,s=o+(t<<4)+8|0,o=o+(t<<4)+12|0,(0|i[s>>2])>0){e=0;do{l=0|i[o>>2],Et(0|i[(c=l+(e<<3)+4|0)>>2]),i[c>>2]=0,i[l+(e<<3)>>2]=0,e=e+1|0}while((0|e)<(0|i[s>>2]))}Et(0|i[o>>2]),i[o>>2]=0,i[s>>2]=0,t=t+1|0}while((0|t)<(0|i[A>>2]))}return Et(0|i[n>>2]),i[n>>2]=0,i[A>>2]=0,N=a,0|(c=r)},_childPosToCell:function(e,t,n,r,a,s){e|=0,t|=0,s|=0;var o,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0;if(o=N,N=N+16|0,A=o,(a|=0)>>>0>15)return N=o,0|(s=4);if(l=0|Vt(0|(n|=0),0|(r|=0),52),S(),(0|(l&=15))>(0|a))return N=o,0|(s=12);if(0|Te(n,r,a,A)&&M(27634,27225,1367,27274),!(((0|t)>-1|-1==(0|t)&e>>>0>4294967295)&((0|(u=0|i[(f=A)+4>>2]))>(0|t)|((0|u)==(0|t)?(0|i[f>>2])>>>0>e>>>0:0))))return N=o,0|(s=2);f=a-l|0,a=0|jt(0|a,0,52),c=S()|-15728641&r,i[(u=s)>>2]=a|n,i[u+4>>2]=c,u=0|Vt(0|n,0|r,45),S();e:do{if(0|G(127&u)){if(0|l)for(A=1;;){if(!(!((u=0|jt(7,0,3*(15-A|0)|0))&n|0)&!((0|S())&r)))break e;if(!(A>>>0<l>>>0))break;A=A+1|0}if((0|f)<1)return N=o,0|(s=0);for(u=15^l,r=-1,c=1,A=1;;){l=0|Ze(7,0,l=f-c|0,((0|l)<0)<<31>>31),n=0|S();do{if(A){if(A=0|Bt(0|(A=0|Pt(0|(A=0|Ot(0|l,0|n,5,0)),0|S(),-5,-1)),0|S(),6,0),(0|t)>(0|(a=0|S()))|(0|t)==(0|a)&e>>>0>A>>>0){t=0|Nt(0|(t=0|Pt(0|e,0|t,-1,-1)),0|S(),0|A,0|a),A=0|S(),p=0|i[(d=s)>>2],d=0|i[d+4>>2],h=0|jt(7,0,0|(m=3*(u+r|0)|0)),d&=~S(),m=0|jt(0|(a=0|Pt(0|(r=0|Bt(0|t,0|A,0|l,0|n)),0|(e=0|S()),2,0)),0|S(),0|m),d=0|S()|d,i[(a=s)>>2]=m|p&~h,i[a+4>>2]=d,e=0|Nt(0|t,0|A,0|(e=0|Ot(0|r,0|e,0|l,0|n)),0|S()),A=0,t=0|S();break}h=0|i[(m=s)>>2],m=0|i[m+4>>2],p=0|jt(7,0,3*(u+r|0)|0),m&=~S(),i[(A=s)>>2]=h&~p,i[A+4>>2]=m,A=1;break}a=0|i[(h=s)>>2],h=0|i[h+4>>2],d=0|jt(7,0,0|(r=3*(u+r|0)|0)),h&=~S(),r=0|jt(0|(m=0|Bt(0|e,0|t,0|l,0|n)),0|(A=0|S()),0|r),h=0|S()|h,i[(p=s)>>2]=r|a&~d,i[p+4>>2]=h,e=0|Nt(0|e,0|t,0|(A=0|Ot(0|m,0|A,0|l,0|n)),0|S()),A=0,t=0|S()}while(0);if(!((0|f)>(0|c))){t=0;break}r=~c,c=c+1|0}return N=o,0|t}}while(0);if((0|f)<1)return N=o,0|(m=0);for(a=15^l,A=1;;){if(p=0|Ze(7,0,p=f-A|0,((0|p)<0)<<31>>31),m=0|S(),n=0|i[(c=s)>>2],c=0|i[c+4>>2],r=0|jt(7,0,0|(l=3*(a-A|0)|0)),c&=~S(),l=0|jt(0|(d=0|Bt(0|e,0|t,0|p,0|m)),0|(h=0|S()),0|l),c=0|S()|c,i[(u=s)>>2]=l|n&~r,i[u+4>>2]=c,e=0|Nt(0|e,0|t,0|(m=0|Ot(0|d,0|h,0|p,0|m)),0|S()),t=0|S(),(0|f)<=(0|A)){t=0;break}A=A+1|0}return N=o,0|t},_compactCells:function(e,t,n,r){t|=0;var a,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0,w=0,T=0,E=0,C=0,I=0,R=0,P=0,N=0;if(!(0|(n|=0))&!(0|(r|=0)))return 0|(N=0);if(o=0|i[(s=e|=0)>>2],!0&!(15728640&(s=0|i[s+4>>2]))){if(!((0|r)>0|!(0|r)&n>>>0>0))return 0|(N=0);if(i[(N=t)>>2]=o,i[N+4>>2]=s,1==(0|n)&!(0|r))return 0|(N=0);s=1,o=0;do{P=0|i[(R=e+(s<<3)|0)+4>>2],i[(N=t+(s<<3)|0)>>2]=i[R>>2],i[N+4>>2]=P,s=0|Pt(0|s,0|o,1,0),o=0|S()}while((0|o)<(0|r)|(0|o)==(0|r)&s>>>0<n>>>0);return 0|(s=0)}if(!(P=0|Mt(a=n<<3)))return 0|(N=13);if(Qt(0|P,0|e,0|a),!(R=0|Ct(n,8)))return Et(P),0|(N=13);e:for(;;){C=0|Vt(0|(u=0|i[(s=P)>>2]),0|(s=0|i[s+4>>2]),52),S(),I=(C&=15)+-1|0,E=!!(0|C),T=(0|r)>0|!(0|r)&n>>>0>0;t:do{if(E&T){if(y=0|jt(0|I,0,52),x=0|S(),I>>>0>15){if(!(!(0|u)&!(0|s))){N=16;break e}for(o=0,e=0;;){if(o=0|Pt(0|o,0|e,1,0),!((0|(e=0|S()))<(0|r)|(0|e)==(0|r)&o>>>0<n>>>0))break t;if(!(!(0|(w=0|i[(A=P+(o<<3)|0)>>2]))&!(0|(A=0|i[A+4>>2])))){s=A,N=16;break e}}}for(l=u,e=s,o=0,A=0;;){if(!(!(0|l)&!(0|e))){if(!(!0&!(117440512&e))){N=21;break e}if(f=0|Vt(0|l,0|e,52),S(),(0|(f&=15))<(0|I)){s=12,N=27;break e}if((0|f)!=(0|I)&&(l|=y,e=-15728641&e|x,f>>>0>=C>>>0)){c=I;do{w=0|jt(7,0,3*(14-c|0)|0),c=c+1|0,l|=w,e=0|S()|e}while(c>>>0<f>>>0)}if(h=0|Dt(0|l,0|e,0|n,0|r),p=0|S(),!(!(0|(d=0|i[(f=c=R+(h<<3)|0)>>2]))&!(0|(f=0|i[f+4>>2])))){b=0,v=0;do{if((0|b)>(0|r)|(0|b)==(0|r)&v>>>0>n>>>0){N=31;break e}if((0|d)==(0|l)&(-117440513&f)==(0|e)){m=0|Vt(0|d,0|f,56),S(),g=(m&=7)+1|0,w=0|Vt(0|d,0|f,45),S();n:do{if(0|G(127&w)){if(d=0|Vt(0|d,0|f,52),S(),!(d&=15)){f=6;break}for(f=1;;){if(!(!((w=0|jt(7,0,3*(15-f|0)|0))&l|0)&!((0|S())&e))){f=7;break n}if(!(f>>>0<d>>>0)){f=6;break}f=f+1|0}}else f=7}while(0);if((m+2|0)>>>0>f>>>0){N=41;break e}w=0|jt(0|g,0,56),e=S()|-117440513&e,i[(_=c)>>2]=0,i[_+4>>2]=0,l|=w}else h=0|Ft(0|(h=0|Pt(0|h,0|p,1,0)),0|S(),0|n,0|r),p=0|S();v=0|Pt(0|v,0|b,1,0),b=0|S(),d=0|i[(f=c=R+(h<<3)|0)>>2],f=0|i[f+4>>2]}while(!(!(0|d)&!(0|f)))}i[(w=c)>>2]=l,i[w+4>>2]=e}if(o=0|Pt(0|o,0|A,1,0),!((0|(A=0|S()))<(0|r)|(0|A)==(0|r)&o>>>0<n>>>0))break t;l=0|i[(e=P+(o<<3)|0)>>2],e=0|i[e+4>>2]}}}while(0);if(w=0|Pt(0|n,0|r,5,0),(_=0|S())>>>0<0|!(0|_)&w>>>0<11){N=85;break}if(w=0|Bt(0|n,0|r,6,0),S(),!(w=0|Ct(w,8))){N=48;break}do{if(T){for(g=0,e=0,m=0,b=0;;){if(!(0|(o=0|i[(A=f=R+(g<<3)|0)>>2]))&!(0|(A=0|i[A+4>>2])))_=m;else{d=0|Vt(0|o,0|A,56),S(),l=(d&=7)+1|0,h=-117440513&A,_=0|Vt(0|o,0|A,45),S();t:do{if(0|G(127&_)){if(p=0|Vt(0|o,0|A,52),S(),0|(p&=15))for(c=1;;){if(!(!(o&(_=0|jt(7,0,3*(15-c|0)|0))|0)&!(h&(0|S()))))break t;if(!(c>>>0<p>>>0))break;c=c+1|0}o|=A=0|jt(0|l,0,56),A=0|S()|h,i[(l=f)>>2]=o,i[l+4>>2]=A,l=d+2|0}}while(0);7==(0|l)?(i[(_=w+(e<<3)|0)>>2]=o,i[_+4>>2]=-117440513&A,e=0|Pt(0|e,0|m,1,0),_=0|S()):_=m}if(g=0|Pt(0|g,0|b,1,0),!((0|(b=0|S()))<(0|r)|(0|b)==(0|r)&g>>>0<n>>>0))break;m=_}if(T){if(v=I>>>0>15,y=0|jt(0|I,0,52),x=0|S(),!E){for(o=0,c=0,l=0,A=0;!(0|u)&!(0|s)||(i[(I=t+(o<<3)|0)>>2]=u,i[I+4>>2]=s,o=0|Pt(0|o,0|c,1,0),c=0|S()),l=0|Pt(0|l,0|A,1,0),(0|(A=0|S()))<(0|r)|(0|A)==(0|r)&l>>>0<n>>>0;)u=0|i[(s=P+(l<<3)|0)>>2],s=0|i[s+4>>2];s=_;break}for(o=0,c=0,A=0,l=0;;){do{if(!(!(0|u)&!(0|s))){if(p=0|Vt(0|u,0|s,52),S(),v|(0|(p&=15))<(0|I)){N=80;break e}if((0|p)!=(0|I)){if(f=u|y,d=-15728641&s|x,p>>>0>=C>>>0){h=I;do{E=0|jt(7,0,3*(14-h|0)|0),h=h+1|0,f|=E,d=0|S()|d}while(h>>>0<p>>>0)}}else f=u,d=s;m=0|Dt(0|f,0|d,0|n,0|r),h=0,p=0,b=0|S();do{if((0|h)>(0|r)|(0|h)==(0|r)&p>>>0>n>>>0){N=81;break e}if((-117440513&(g=0|i[(E=R+(m<<3)|0)+4>>2]))==(0|d)&&(0|i[E>>2])==(0|f)){N=65;break}m=0|Ft(0|(E=0|Pt(0|m,0|b,1,0)),0|S(),0|n,0|r),b=0|S(),p=0|Pt(0|p,0|h,1,0),h=0|S(),E=R+(m<<3)|0}while((0|i[E>>2])!=(0|f)||(0|i[E+4>>2])!=(0|d));if(65==(0|N)&&(N=0,!0&100663296==(117440512&g)))break;i[(E=t+(o<<3)|0)>>2]=u,i[E+4>>2]=s,o=0|Pt(0|o,0|c,1,0),c=0|S()}}while(0);if(A=0|Pt(0|A,0|l,1,0),!((0|(l=0|S()))<(0|r)|(0|l)==(0|r)&A>>>0<n>>>0))break;u=0|i[(s=P+(A<<3)|0)>>2],s=0|i[s+4>>2]}s=_}else o=0,s=_}else o=0,e=0,s=0}while(0);if(Wt(0|R,0,0|a),Qt(0|P,0|w,e<<3),Et(w),!(0|e)&!(0|s)){N=89;break}t=t+(o<<3)|0,r=s,n=e}if(16==(0|N))!0&!(117440512&s)?(s=4,N=27):N=21;else if(31==(0|N))M(27634,27225,620,27235);else{if(41==(0|N))return Et(P),Et(R),0|(N=10);if(48==(0|N))return Et(P),Et(R),0|(N=13);80==(0|N)?M(27634,27225,711,27235):81==(0|N)?M(27634,27225,723,27235):85==(0|N)&&(Qt(0|t,0|P,n<<3),N=89)}return 21==(0|N)?(Et(P),Et(R),0|(N=5)):27==(0|N)?(Et(P),Et(R),0|(N=s)):89==(0|N)?(Et(P),Et(R),0|(N=0)):0},_constructCell:function(e,t,n,a){n|=0,a|=0;var s=0,o=0,A=0,l=0,c=0,u=0;if((e|=0)>>>0>15)return 0|(a=4);if((t|=0)>>>0>121)return 0|(a=17);A=0|jt(0|e,0,52),s=0|S(),l=0|jt(0|t,0,45),s=0|s|S()|134225919;e:do{if((0|e)>=1){for(l=1,A=!!(0|r[20496+t|0]),o=-1;;){if((t=0|i[n+(l+-1<<2)>>2])>>>0>6){s=18,t=10;break}if(!(!(0|t)|1^A)){if(1==(0|t)){s=19,t=10;break}A=0}if(c=0|jt(7,0,0|(u=3*(15-l|0)|0)),s&=~S(),o=(t=0|jt(0|t,((0|t)<0)<<31>>31,0|u))|o&~c,s=0|S()|s,!((0|l)<(0|e)))break e;l=l+1|0}if(10==(0|t))return 0|s}else o=-1}while(0);return i[(u=a)>>2]=o,i[u+4>>2]=s,0|(u=0)},_destroyLinkedMultiPolygon:function(e){var t,n,r=0,a=0,s=0,o=0,A=0;if(e|=0)for(t=e+4|0,n=e+8|0,s=1,o=e;;){if(0|(r=0|i[o>>2]))do{if(0|(a=0|i[r>>2]))do{A=a,a=0|i[a+16>>2],Et(A)}while(0|a);A=r,r=0|i[r+8>>2],Et(A)}while(0|r);if(r=o,o=0|i[o+8>>2],s?(i[e>>2]=0,i[t>>2]=0,i[n>>2]=0):Et(r),!o)break;s=0}},_directedEdgeToBoundary:Ae,_directedEdgeToCells:function(e,t,n){e|=0;var r,a,s,o=0;return r=N,N=N+16|0,o=r,!0&268435456==(2013265920&(t|=0))?(a=-2130706433&t|134217728,i[(s=n|=0)>>2]=e,i[s+4>>2]=a,i[o>>2]=0,t=0|Vt(0|e,0|t,56),S(),o=0|F(e,a,7&t,o,n+8|0),N=r,0|o):(N=r,0|(o=6))},_edgeLengthKm:function(e,t,n){n|=0;var r,s=0,o=0,A=0,l=0,d=0,h=0,p=0;if(r=N,N=N+176|0,0|(e=0|Ae(e|=0,t|=0,l=r)))return l=e,A=+a[n>>3],A*=6371.007180918475,a[n>>3]=A,N=r,0|l;if(a[n>>3]=0,(0|(e=0|i[l>>2]))<=1)return l=0,A=0,A*=6371.007180918475,a[n>>3]=A,N=r,0|l;t=e+-1|0,e=0,s=+a[l+8>>3],o=+a[l+16>>3],A=0;do{h=s,s=+a[l+8+((e=e+1|0)<<4)>>3],p=+f(.5*(s-h)),d=o,o=+a[l+8+(e<<4)+8>>3],d=p*p+(d=+f(.5*(o-d)))*(+u(+h)*+u(+s)*d),A+=2*+g(+ +c(+d),+ +c(+(1-d)))}while((0|e)!=(0|t));return a[n>>3]=A,l=0,p=A,p*=6371.007180918475,a[n>>3]=p,N=r,0|l},_edgeLengthM:function(e,t,n){n|=0;var r,s=0,o=0,A=0,l=0,d=0,h=0,p=0;if(r=N,N=N+176|0,0|(e=0|Ae(e|=0,t|=0,l=r)))return l=e,A=+a[n>>3],A*=6371.007180918475,A*=1e3,a[n>>3]=A,N=r,0|l;if(a[n>>3]=0,(0|(e=0|i[l>>2]))<=1)return l=0,A=0,A*=6371.007180918475,A*=1e3,a[n>>3]=A,N=r,0|l;t=e+-1|0,e=0,s=+a[l+8>>3],o=+a[l+16>>3],A=0;do{h=s,s=+a[l+8+((e=e+1|0)<<4)>>3],p=+f(.5*(s-h)),d=o,o=+a[l+8+(e<<4)+8>>3],d=p*p+(d=+f(.5*(o-d)))*(+u(+h)*+u(+s)*d),A+=2*+g(+ +c(+d),+ +c(+(1-d)))}while((0|e)!=(0|t));return a[n>>3]=A,l=0,p=A,p*=6371.007180918475,p*=1e3,a[n>>3]=p,N=r,0|l},_edgeLengthRads:function(e,t,n){n|=0;var r,s=0,o=0,A=0,l=0,d=0,h=0,p=0;if(r=N,N=N+176|0,0|(e=0|Ae(e|=0,t|=0,l=r)))return N=r,0|(l=e);if(a[n>>3]=0,(0|(e=0|i[l>>2]))<=1)return N=r,0|(l=0);t=e+-1|0,e=0,s=+a[l+8>>3],o=+a[l+16>>3],A=0;do{h=s,s=+a[l+8+((e=e+1|0)<<4)>>3],p=+f(.5*(s-h)),d=o,o=+a[l+8+(e<<4)+8>>3],d=p*p+(d=+f(.5*(o-d)))*(+u(+s)*+u(+h)*d),A+=2*+g(+ +c(+d),+ +c(+(1-d)))}while((0|e)<(0|t));return a[n>>3]=A,N=r,0|(l=0)},_emscripten_replace_memory:function(e){return r=new Int8Array(e),new Uint8Array(e),i=new Int32Array(e),new Float32Array(e),a=new Float64Array(e),n=e,!0},_free:Et,_getBaseCellNumber:ye,_getDirectedEdgeDestination:function(e,t,n){e|=0,t|=0,n|=0;var r,a,s=0;return r=N,N=N+16|0,i[(s=r)>>2]=0,!0&268435456==(2013265920&t)?(a=0|Vt(0|e,0|t,56),S(),s=0|F(e,-2130706433&t|134217728,7&a,s,n),N=r,0|s):(N=r,0|(s=6))},_getDirectedEdgeOrigin:function(e,t,n){return e|=0,n|=0,!0&268435456==(2013265920&(t|=0))?(i[n>>2]=e,i[n+4>>2]=-2130706433&t|134217728,0|(n=0)):0|(n=6)},_getHexagonAreaAvgKm2:Ke,_getHexagonAreaAvgM2:function(e,t){return t|=0,(e|=0)>>>0>15?0|(t=4):(a[t>>3]=+a[20752+(e<<3)>>3],0|(t=0))},_getHexagonEdgeLengthAvgKm:function(e,t){return t|=0,(e|=0)>>>0>15?0|(t=4):(a[t>>3]=+a[20880+(e<<3)>>3],0|(t=0))},_getHexagonEdgeLengthAvgM:function(e,t){return t|=0,(e|=0)>>>0>15?0|(t=4):(a[t>>3]=+a[21008+(e<<3)>>3],0|(t=0))},_getIcosahedronFaces:function e(t,n,r){r|=0;var a,s=0,o=0,A=0,l=0,c=0,u=0,f=0,d=0;a=N,N=N+128|0,f=a+112|0,A=a+96|0,d=a,o=0|Vt(0|(t|=0),0|(n|=0),52),S(),c=15&o,i[f>>2]=c,l=0|Vt(0|t,0|n,45),S(),l&=127;e:do{if(0|G(l)){if(0|c)for(s=1;;){if(!(!((u=0|jt(7,0,3*(15-s|0)|0))&t|0)&!((0|S())&n))){o=0;break e}if(!(s>>>0<c>>>0))break;s=s+1|0}if(!(1&o))return u=0|jt(c+1|0,0,52),d=S()|-15728641&n,d=0|e((u|t)&~(f=0|jt(7,0,3*(14-c|0)|0)),d&~S(),r),N=a,0|d;o=1}else o=0}while(0);if(!(s=0|Fe(t,n,A))){o?(he(A,f,d),u=5):(be(A,f,d),u=6);e:do{if(0|G(l))if(c)for(s=1;;){if(!(!((l=0|jt(7,0,3*(15-s|0)|0))&t|0)&!((0|S())&n))){t=2;break e}if(!(s>>>0<c>>>0)){t=5;break}s=s+1|0}else t=5;else t=2}while(0);Wt(0|r,-1,t<<2);e:do{if(o)for(A=0;;){if(me(l=d+(A<<4)|0,0|i[f>>2]),l=0|i[l>>2],-1==(0|(c=0|i[r>>2]))|(0|c)==(0|l))s=r;else{o=0;do{if((o=o+1|0)>>>0>=t>>>0){s=1;break e}c=0|i[(s=r+(o<<2)|0)>>2]}while(!(-1==(0|c)|(0|c)==(0|l)))}if(i[s>>2]=l,(A=A+1|0)>>>0>=u>>>0){s=0;break}}else for(A=0;;){if(pe(l=d+(A<<4)|0,0|i[f>>2],0,1),l=0|i[l>>2],-1==(0|(c=0|i[r>>2]))|(0|c)==(0|l))s=r;else{o=0;do{if((o=o+1|0)>>>0>=t>>>0){s=1;break e}c=0|i[(s=r+(o<<2)|0)>>2]}while(!(-1==(0|c)|(0|c)==(0|l)))}if(i[s>>2]=l,(A=A+1|0)>>>0>=u>>>0){s=0;break}}}while(0)}return N=a,0|(d=s)},_getIndexDigit:function(e,t,n,r){return r|=0,((n|=0)+-1|0)>>>0>14?0|(r=4):(n=0|Vt(0|(e|=0),0|(t|=0),3*(15-n|0)|0),S(),i[r>>2]=7&n,0|(r=0))},_getNumCells:We,_getPentagons:Ve,_getRes0Cells:function(e){e|=0;var t=0,n=0,r=0;t=0;do{jt(0|t,0,45),r=134225919|S(),i[(n=e+(t<<3)|0)>>2]=-1,i[n+4>>2]=r,t=t+1|0}while(122!=(0|t));return 0},_getResolution:ve,_greatCircleDistanceKm:Qe,_greatCircleDistanceM:function(e,t){e|=0;var n,r,i,s=0;return r=+a[(t|=0)>>3],n=+a[e>>3],s=(i=+f(.5*(r-n)))*i+(s=+f(.5*(+a[t+8>>3]-+a[e+8>>3])))*(+u(+r)*+u(+n)*s),2*+g(+ +c(+s),+ +c(+(1-s)))*6371.007180918475*1e3},_greatCircleDistanceRads:function(e,t){e|=0;var n,r,i,s=0;return r=+a[(t|=0)>>3],n=+a[e>>3],s=(i=+f(.5*(r-n)))*i+(s=+f(.5*(+a[t+8>>3]-+a[e+8>>3])))*(+u(+r)*+u(+n)*s),2*+g(+ +c(+s),+ +c(+(1-s)))},_gridDisk:k,_gridDiskDistances:L,_gridDistance:Xe,_gridPathCells:function(e,t,n,r,a){a|=0;var s,o,A=0,l=0;return o=N,N=N+16|0,0|(l=0|Xe(e|=0,t|=0,n|=0,r|=0,A=o))?(N=o,0|(a=l)):!(0|(A=0|i[(l=A)>>2]))&!(0|(l=0|i[l+4>>2]))?(i[a>>2]=e,i[a+4>>2]=t,N=o,0|(a=0)):(s=0|Ye(e,t,n,r,A,l,a,0,0,1,0))?(a=!(0|Ye(n,r,e,t,A,l,a,A,l,-1,-1)),N=o,0|(a=a?0:s)):(N=o,0|(a=0))},_gridPathCellsSize:function(e,t,n,r,a){a|=0;var s,o=0;return s=N,N=N+16|0,0|(e=0|Xe(e|=0,t|=0,n|=0,r|=0,o=s))?(N=s,0|(o=e)):(n=0|Pt(0|i[(n=o)>>2],0|i[n+4>>2],1,0),r=0|S(),i[(o=a)>>2]=n,i[o+4>>2]=r,N=s,0|(o=0))},_gridRing:function(e,t,n,r){return 0|D(e|=0,t|=0,n|=0,r|=0)?(Wt(0|r,0,48*n|0),0|(r=0|U(e,t,n,r))):0|(r=0)},_gridRingUnsafe:D,_i64Add:Pt,_i64Subtract:Nt,_isPentagon:Se,_isResClassIII:function(e,t){return t=0|Vt(0|(e|=0),0|(t|=0),52),S(),1&t},_isValidCell:xe,_isValidDirectedEdge:se,_isValidIndex:function(e,t){e|=0;var n=0,i=0,a=0,s=0;if(!0&134217728==(-16777216&(t|=0))&&(i=0|Vt(0|e,0|t,52),S(),i&=15,n=0|Vt(0|e,0|t,45),S(),(n&=127)>>>0<=121)&&!(613566756&(s=0|jt(0|(a=0|Vt(0|e,0|t,0|(s=3*(15^i)|0))),0|S(),0|s))&(0|Nt(-1227133514,-1171,0|s,0|(a=0|S()))))&!(4681&a&S())&&15==(0|i)|!(0|(s=0|Vt(0|(0|jt(0|~e,0|~t,0|(s=19+(3*i|0)|0))),0|S(),0|s)))&!(0|S())){if(!(0|r[20496+n|0]))return 0|(s=1);if(!(0|e)&!(0|(n=8191&t)))return 0|(s=1);if(s=0|zt(0|e,0|n,0),S(),(63-s|0)%3|0)return 0|(s=1)}return 0|se(e,t)?0|(s=1):0|(s=1&!!(0|mt(e,t)))},_isValidVertex:mt,_latLngToCell:Be,_llvm_ctlz_i64:zt,_llvm_maxnum_f64:Gt,_llvm_minnum_f64:Ht,_llvm_round_f64:qt,_localIjToCell:function(e,t,n,r,a){e|=0,t|=0,a|=0;var s,o,A,l=0,c=0,u=0,f=0;return A=N,N=N+16|0,f=A,0|(r|=0)?(N=A,0|(f=15)):(u=0|i[(n|=0)>>2],c=0|i[n+4>>2],i[f>>2]=u,i[(s=f+4|0)>>2]=c,i[(o=f+8|0)>>2]=0,r=(n=(0|c)<(0|u))?u:c,(0|(n=n?c:u))<0&&(-2147483648==(0|n)||((0|r)>0?(2147483647-r|0)<(0|n):(-2147483648-r|0)>(0|n))||((0|r)>-1?(-2147483648|r)>=(0|n):(-2147483648^r)<(0|n)))?r=1:l=5,5==(0|l)&&(r=c-u|0,l=0-u|0,(0|u)<0?(i[s>>2]=r,i[o>>2]=l,i[f>>2]=0,u=0):(r=c,l=0),c=u-r|0,n=l-r|0,(0|r)<0?(i[f>>2]=c,i[o>>2]=n,i[s>>2]=0,u=c,r=0):n=l,c=u-n|0,l=r-n|0,(0|n)<0?(i[f>>2]=c,i[s>>2]=l,i[o>>2]=0,n=0):(l=r,c=u),(0|(r=(0|n)<(0|(r=(0|l)<(0|c)?l:c))?n:r))>0&&(i[f>>2]=c-r,i[s>>2]=l-r,i[o>>2]=n-r),r=0|$e(e,t,f,a)),N=A,0|(f=r))},_malloc:Mt,_maxFaceCount:function(e,t,n){n|=0;var r=0,a=0;if(a=0|Vt(0|(e|=0),0|(t|=0),45),S(),!(0|G(127&a)))return a=2,i[n>>2]=a,0;if(a=0|Vt(0|e,0|t,52),S(),!(a&=15))return a=5,i[n>>2]=a,0;for(r=1;;){if(!(!((0|jt(7,0,3*(15-r|0)|0))&e|0)&!((0|S())&t))){r=2,e=6;break}if(!(r>>>0<a>>>0)){r=5,e=6;break}r=r+1|0}return 6==(0|e)?(i[n>>2]=r,0):0},_maxGridDiskSize:function(e,t){t|=0;var n=0,r=0,a=0;return(0|(e|=0))<0?0|(t=2):(0|e)>13780509?0|(t=0|We(15,t)):(a=0|Ot(0|e,0|(n=((0|e)<0)<<31>>31),3,0),r=0|S(),n=0|Pt(0|e,0|n,1,0),n=0|Pt(0|(n=0|Ot(0|a,0|r,0|n,0|S())),0|S(),1,0),e=0|S(),i[t>>2]=n,i[t+4>>2]=e,0|(t=0))},_maxPolygonToCellsSize:function(e,t,n,r){e|=0,t|=0,r|=0;var a,s=0,o=0,A=0,l=0,c=0;if(a=N,N=N+48|0,s=a+16|0,o=a+8|0,A=a,0|(n=0|st(n|=0)))return N=a,0|(A=n);if(l=0|i[(c=e)+4>>2],i[(n=o)>>2]=i[c>>2],i[n+4>>2]=l,at(o,s),!(n=0|ne(s,t,A))){if(t=0|i[o>>2],(0|(o=0|i[e+8>>2]))>0){s=0|i[e+12>>2],n=0;do{t=(0|i[s+(n<<3)>>2])+t|0,n=n+1|0}while((0|n)<(0|o))}s=0|i[(n=A)>>2],(0|(n=0|i[n+4>>2]))<(0|(o=((0|t)<0)<<31>>31))|(0|n)==(0|o)&s>>>0<t>>>0?(i[(n=A)>>2]=t,i[n+4>>2]=o,n=o):t=s,l=0|Pt(0|t,0|n,12,0),c=0|S(),i[(n=A)>>2]=l,i[n+4>>2]=c,i[(n=r)>>2]=l,i[n+4>>2]=c,n=0}return N=a,0|(c=n)},_maxPolygonToCellsSizeExperimental:function(e,t,n,s){t|=0,n|=0,s|=0;var o,A,c=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0;if(A=N,N=N+48|0,p=A+32|0,h=A+40|0,o=A,!(0|i[(e|=0)>>2]))return i[(m=s)>>2]=0,i[m+4>>2]=0,N=A,0|(m=0);_e(p,0,0,0),c=0|i[(d=p)>>2],d=0|i[d+4>>2];do{if(t>>>0>15)i[(m=o)>>2]=0,i[m+4>>2]=0,i[o+8>>2]=4,i[o+12>>2]=-1,n=o+29|0,i[(m=o+16|0)>>2]=0,i[m+4>>2]=0,i[m+8>>2]=0,r[m+12|0]=0,r[n|0]=0|r[h|0],r[n+1|0]=0|r[h+1|0],r[n+2|0]=0|r[h+2|0],n=4,m=9;else{if(0|(n=0|st(n))){i[(p=o)>>2]=0,i[p+4>>2]=0,i[o+8>>2]=n,i[o+12>>2]=-1,m=o+29|0,i[(p=o+16|0)>>2]=0,i[p+4>>2]=0,i[p+8>>2]=0,r[p+12|0]=0,r[m|0]=0|r[h|0],r[m+1|0]=0|r[h+1|0],r[m+2|0]=0|r[h+2|0],m=9;break}if(!(n=0|Ct(1+(0|i[e+8>>2])|0,32))){i[(m=o)>>2]=0,i[m+4>>2]=0,i[o+8>>2]=13,i[o+12>>2]=-1,n=o+29|0,i[(m=o+16|0)>>2]=0,i[m+4>>2]=0,i[m+8>>2]=0,r[m+12|0]=0,r[n|0]=0|r[h|0],r[n+1|0]=0|r[h+1|0],r[n+2|0]=0|r[h+2|0],n=13,m=9;break}ot(e,n),i[(b=o)>>2]=c,i[b+4>>2]=d,i[(d=o+8|0)>>2]=0,i[o+12>>2]=t,i[o+20>>2]=e,i[o+24>>2]=n,r[o+28|0]=0,r[(c=o+29|0)|0]=0|r[h|0],r[c+1|0]=0|r[h+1|0],r[c+2|0]=0|r[h+2|0],i[o+16>>2]=3,g=+X(n),g*=+$(n),f=+l(+ +a[n>>3]),f=g/+u(+ +Ht(+f,+ +l(+ +a[n+8>>3])))*6371.007180918475*6371.007180918475,n=0|i[(c=o+12|0)>>2];e:do{if((0|n)>0)do{if(Ke(n+-1|0,p),!(f/+a[p>>3]>10))break e;n=(b=0|i[c>>2])+-1|0,i[c>>2]=n}while((0|b)>1)}while(0);if(nt(o),i[(c=s)>>2]=0,i[c+4>>2]=0,!(!(0|(n=0|i[(c=o)>>2]))&!(0|(c=0|i[c+4>>2]))))do{Te(n,c,t,p),h=p,h=0|Pt(0|i[(e=s)>>2],0|i[e+4>>2],0|i[h>>2],0|i[h+4>>2]),e=0|S(),i[(b=s)>>2]=h,i[b+4>>2]=e,nt(o),n=0|i[(b=o)>>2],c=0|i[b+4>>2]}while(!(!(0|n)&!(0|c)));n=0|i[d>>2]}}while(0);return N=A,0|(b=n)},_memcpy:Qt,_memmove:Kt,_memset:Wt,_originToDirectedEdges:oe,_pentagonCount:function(){return 12},_polygonToCells:function(e,t,n,r){e|=0,t|=0,r|=0;var a,s,o,A,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0,b=0,v=0,y=0,x=0,_=0,w=0,T=0,M=0,E=0,C=0,I=0,R=0,P=0,k=0,L=0,F=0,D=0,U=0;if(A=N,N=N+112|0,a=A+80|0,d=A+72|0,s=A,o=A+56|0,0|(l=0|st(n|=0)))return N=A,0|(U=l);if(!(U=0|Mt(32+(i[(h=e+8|0)>>2]<<5)|0)))return N=A,0|(U=13);if(ot(e,U),!(l=0|st(n))){if(D=0|i[(F=e)+4>>2],i[(l=d)>>2]=i[F>>2],i[l+4>>2]=D,at(d,a),l=0|ne(a,t,s))F=0,D=0;else{if(l=0|i[d>>2],(0|(c=0|i[h>>2]))>0){u=0|i[e+12>>2],n=0;do{l=(0|i[u+(n<<3)>>2])+l|0,n=n+1|0}while((0|n)!=(0|c));n=l}else n=l;c=0|i[(l=s)>>2],(0|(l=0|i[l+4>>2]))<(0|(u=((0|n)<0)<<31>>31))|(0|l)==(0|u)&c>>>0<n>>>0?(i[(l=s)>>2]=n,i[l+4>>2]=u,l=u):n=c,F=0|Pt(0|n,0|l,12,0),D=0|S(),i[(l=s)>>2]=F,i[l+4>>2]=D,l=0}if(!l){if(!(n=0|Ct(F,8)))return Et(U),N=A,0|(U=13);if(!(f=0|Ct(F,8)))return Et(U),Et(n),N=A,0|(U=13);i[(k=a)>>2]=0,i[k+4>>2]=0,L=0|i[(k=e)+4>>2],i[(l=d)>>2]=i[k>>2],i[l+4>>2]=L,l=0|j(d,F,D,t,a,n,f);e:do{if(l)Et(n),Et(f),Et(U);else{t:do{if((0|i[h>>2])>0){for(u=e+12|0,c=0;l=0|j((0|i[u>>2])+(c<<3)|0,F,D,t,a,n,f),c=c+1|0,!(0|l);)if((0|c)>=(0|i[h>>2]))break t;Et(n),Et(f),Et(U);break e}}while(0);(0|D)>0|!(0|D)&F>>>0>0&&Wt(0|f,0,F<<3),k=0|i[(L=a)+4>>2];t:do{if((0|k)>0|!(0|k)&(0|i[L>>2])>>>0>0){I=n,R=f,P=n,k=f,L=n,l=n,M=n,E=f,C=f,n=f;n:for(;;){for(x=0,_=0,w=0,T=0,c=0,u=0;;){d=(f=s)+56|0;do{i[f>>2]=0,f=f+4|0}while((0|f)<(0|d));if(0|B(h=0|i[(t=I+(x<<3)|0)>>2],t=0|i[t+4>>2],1,s,0)){d=(f=s)+56|0;do{i[f>>2]=0,f=f+4|0}while((0|f)<(0|d));0|(f=0|Ct(7,4))&&(O(h,t,1,s,f,7,0,0),Et(f))}for(y=0;;){b=0|i[(v=s+(y<<3)|0)>>2],v=0|i[v+4>>2];r:do{if(!(0|b)&!(0|v))f=c,d=u;else{if(p=0|Dt(0|b,0|v,0|F,0|D),h=0|S(),!(!(0|(d=0|i[(t=f=r+(p<<3)|0)>>2]))&!(0|(t=0|i[t+4>>2])))){m=0,g=0;do{if((0|m)>(0|D)|(0|m)==(0|D)&g>>>0>F>>>0)break n;if((0|d)==(0|b)&(0|t)==(0|v)){f=c,d=u;break r}p=0|Ft(0|(f=0|Pt(0|p,0|h,1,0)),0|S(),0|F,0|D),h=0|S(),g=0|Pt(0|g,0|m,1,0),m=0|S(),d=0|i[(t=f=r+(p<<3)|0)>>2],t=0|i[t+4>>2]}while(!(!(0|d)&!(0|t)))}if(!(0|b)&!(0|v)){f=c,d=u;break}De(b,v,o),0|At(e,U,o)&&(g=0|Pt(0|c,0|u,1,0),u=0|S(),i[(m=f)>>2]=b,i[m+4>>2]=v,i[(c=R+(c<<3)|0)>>2]=b,i[c+4>>2]=v,c=g),f=c,d=u}}while(0);if((y=y+1|0)>>>0>=7)break;c=f,u=d}if(x=0|Pt(0|x,0|_,1,0),_=0|S(),w=0|Pt(0|w,0|T,1,0),T=0|S(),c=0|i[(u=a)>>2],!((0|T)<(0|(u=0|i[u+4>>2]))|(0|T)==(0|u)&w>>>0<c>>>0))break;c=f,u=d}if((0|u)>0|!(0|u)&c>>>0>0){c=0,u=0;do{i[(T=I+(c<<3)|0)>>2]=0,i[T+4>>2]=0,c=0|Pt(0|c,0|u,1,0),u=0|S(),w=0|i[(T=a)+4>>2]}while((0|u)<(0|w)|((0|u)==(0|w)?c>>>0<(0|i[T>>2])>>>0:0))}if(i[(T=a)>>2]=f,i[T+4>>2]=d,!((0|d)>0|!(0|d)&f>>>0>0))break t;y=n,x=C,_=L,w=E,T=R,n=M,C=l,E=P,M=y,l=x,L=k,k=_,P=w,R=I,I=T}Et(P),Et(k),Et(U),l=1;break e}l=f}while(0);Et(U),Et(n),Et(l),l=0}}while(0);return N=A,0|(U=l)}}return Et(U),N=A,0|(U=l)},_polygonToCellsExperimental:function(e,t,n,r,a,s){r|=0,a|=0,s|=0;var o,A,l,c=0,u=0,f=0,d=0,h=0,p=0,m=0,g=0;l=N,N=N+160|0,u=l+64|0,h=l+112|0,g=l,tt(d=l+80|0,e|=0,t|=0,n|=0),je(u,0|i[(f=d)>>2],0|i[f+4>>2],t),o=0|i[(f=u)>>2],f=0|i[f+4>>2],c=0|i[d+8>>2],i[(p=h+4|0)>>2]=i[d>>2],i[p+4>>2]=i[d+4>>2],i[p+8>>2]=i[d+8>>2],i[p+12>>2]=i[d+12>>2],i[p+16>>2]=i[d+16>>2],i[p+20>>2]=i[d+20>>2],i[p+24>>2]=i[d+24>>2],i[p+28>>2]=i[d+28>>2],i[(p=g)>>2]=o,i[p+4>>2]=f,i[(p=g+8|0)>>2]=c,t=h,n=(e=g+12|0)+36|0;do{i[e>>2]=i[t>>2],e=e+4|0,t=t+4|0}while((0|e)<(0|n));if(i[(h=g+48|0)>>2]=i[u>>2],i[h+4>>2]=i[u+4>>2],i[h+8>>2]=i[u+8>>2],i[h+12>>2]=i[u+12>>2],!(0|o)&!(0|f))return N=l,0|(g=c);n=g+16|0,A=g+24|0,d=g+28|0,c=0,u=0,t=o,e=f;do{if(!((0|c)<(0|a)|(0|c)==(0|a)&u>>>0<r>>>0)){m=4;break}if(f=u,u=0|Pt(0|u,0|c,1,0),c=0|S(),i[(f=s+(f<<3)|0)>>2]=t,i[f+4>>2]=e,Ge(h),!(0|(t=0|i[(e=h)>>2]))&!(0|(e=0|i[e+4>>2]))){if(nt(n),!(0|(e=0|i[(t=n)>>2]))&!(0|(t=0|i[t+4>>2]))){m=10;break}ze(e,t,0|i[d>>2],h),t=0|i[(e=h)>>2],e=0|i[e+4>>2]}i[(f=g)>>2]=t,i[f+4>>2]=e}while(!(!(0|t)&!(0|e)));return 4==(0|m)?(0|(t=0|i[(e=g+40|0)>>2])&&Et(t),i[(m=g+16|0)>>2]=0,i[m+4>>2]=0,i[A>>2]=0,i[g+36>>2]=0,i[d>>2]=-1,i[g+32>>2]=0,i[e>>2]=0,ze(0,0,0,h),i[g>>2]=0,i[g+4>>2]=0,i[p>>2]=0,N=l,0|(g=14)):(10==(0|m)&&(i[g>>2]=0,i[g+4>>2]=0,i[p>>2]=i[A>>2]),g=0|i[p>>2],N=l,0|g)},_readInt64AsDoubleFromPointer:function(e){return+(+((0|i[(e|=0)>>2])>>>0)+4294967296*+(0|i[e+4>>2]))},_res0CellCount:function(){return 122},_reverseDirectedEdge:le,_round:Jt,_sbrk:$t,_sizeOfCellBoundary:function(){return 168},_sizeOfCoordIJ:function(){return 8},_sizeOfGeoLoop:function(){return 8},_sizeOfGeoPolygon:function(){return 16},_sizeOfH3Index:function(){return 8},_sizeOfLatLng:function(){return 16},_sizeOfLinkedGeoPolygon:function(){return 12},_uncompactCells:function(e,t,n,r,a,s,o){e|=0,r|=0,a|=0,s|=0;var A,l=0,c=0,u=0,f=0,d=0,h=0,p=0,m=0;if(A=N,N=N+16|0,m=A,!((0|(n|=0))>0|!(0|n)&(t|=0)>>>0>0))return N=A,0|(m=0);if((0|(o|=0))>=16)return N=A,0|(m=12);h=0,p=0,d=0,l=0;e:for(;;){if(f=0|Vt(0|(c=0|i[(u=e+(h<<3)|0)>>2]),0|(u=0|i[u+4>>2]),52),S(),(15&f)>(0|o)){l=12,c=11;break}if(je(m,c,u,o),!(0|(u=0|i[(f=m)>>2]))&!(0|(f=0|i[f+4>>2])))c=d;else{c=d;do{if(!((0|l)<(0|s)|(0|l)==(0|s)&c>>>0<a>>>0)){c=10;break e}i[(d=r+(c<<3)|0)>>2]=u,i[d+4>>2]=f,c=0|Pt(0|c,0|l,1,0),l=0|S(),Ge(m),u=0|i[(d=m)>>2],f=0|i[d+4>>2]}while(!(!(0|u)&!(0|f)))}if(h=0|Pt(0|h,0|p,1,0),!((0|(p=0|S()))<(0|n)|(0|p)==(0|n)&h>>>0<t>>>0)){l=0,c=11;break}d=c}return 10==(0|c)?(N=A,0|(m=14)):11==(0|c)?(N=A,0|l):0},_uncompactCellsSize:function(e,t,n,r,a){e|=0,t|=0,n|=0,r|=0,a|=0;var s,o,A=0,l=0,c=0,u=0,f=0,d=0;o=N,N=N+16|0,s=o;e:do{if((0|n)>0|!(0|n)&t>>>0>0){for(f=0,l=0,A=0,d=0;;){if(!(!(0|(c=0|i[(u=e+(f<<3)|0)>>2]))&!(0|(u=0|i[u+4>>2]))||(u=!(0|Te(c,u,r,s)),l=0|Pt(0|i[(c=s)>>2],0|i[c+4>>2],0|l,0|A),A=0|S(),u))){A=12;break}if(f=0|Pt(0|f,0|d,1,0),!((0|(d=0|S()))<(0|n)|(0|d)==(0|n)&f>>>0<t>>>0))break e}return N=o,0|A}l=0,A=0}while(0);return i[a>>2]=l,i[a+4>>2]=A,N=o,0|(a=0)},_vertexToLatLng:function(e,t,n){n|=0;var r,a,s,o,A=0,l=0;return o=N,N=N+192|0,a=o,s=o+168|0,A=0|Vt(0|(e|=0),0|(t|=0),56),S(),A&=7,0|(r=0|Fe(e,l=-2130706433&t|134217728,s))?(N=o,0|(l=r)):(t=0|Vt(0|e,0|t,52),S(),t&=15,0|Se(e,l)?de(s,t,A,1,a):ge(s,t,A,1,a),l=a+8|0,i[n>>2]=i[l>>2],i[n+4>>2]=i[l+4>>2],i[n+8>>2]=i[l+8>>2],i[n+12>>2]=i[l+12>>2],N=o,0|(l=0))},dynCall_iii:function(e,t,n){return t|=0,n|=0,0|Xt[3&(e|=0)](0|t,0|n)},establishStackSpace:function(e,t){N=e|=0},stackAlloc:function(e){var t;return t=N,N=(N=N+(e|=0)|0)+15&-16,0|t},stackRestore:function(e){N=e|=0},stackSave:function(){return 0|N}}}({Math:Math,Int8Array:Int8Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Float32Array:Float32Array,Float64Array:Float64Array},{a:le,b:function(e){l=e},c:function(){return l},d:function(e,t,n,r){le("Assertion failed: "+x(e)+", at: "+[t?x(t):"unknown filename",n,r?x(r):"unknown function"])},e:function(e){return n.___errno_location&&(g[n.___errno_location()>>2]=e),e},f:K,g:function(e,t,n){p.set(p.subarray(t,t+n),e)},h:function(e){var t=K(),n=16777216,r=2130706432;if(e>r)return!1;for(var i=Math.max(t,16777216);i<e;)i=i<=536870912?_(2*i,n):Math.min(_((3*i+2147483648)/4,n),r);return!!W(i)},i:function(e){le("OOM")},j:H,k:q,l:W,m:Q,n:function(){var e=Q();return n.extraStackTrace&&(e+="\n"+n.extraStackTrace()),q(e)},o:28400,p:28384},d);n.___divdi3=X.___divdi3,n.___muldi3=X.___muldi3,n.___remdi3=X.___remdi3,n.___uremdi3=X.___uremdi3,n._areNeighborCells=X._areNeighborCells,n._bitshift64Ashr=X._bitshift64Ashr,n._bitshift64Lshr=X._bitshift64Lshr,n._bitshift64Shl=X._bitshift64Shl,n._calloc=X._calloc,n._cellAreaKm2=X._cellAreaKm2,n._cellAreaM2=X._cellAreaM2,n._cellAreaRads2=X._cellAreaRads2,n._cellToBoundary=X._cellToBoundary,n._cellToCenterChild=X._cellToCenterChild,n._cellToChildPos=X._cellToChildPos,n._cellToChildren=X._cellToChildren,n._cellToChildrenSize=X._cellToChildrenSize,n._cellToLatLng=X._cellToLatLng,n._cellToLocalIj=X._cellToLocalIj,n._cellToParent=X._cellToParent,n._cellToVertex=X._cellToVertex,n._cellToVertexes=X._cellToVertexes,n._cellsToDirectedEdge=X._cellsToDirectedEdge,n._cellsToLinkedMultiPolygon=X._cellsToLinkedMultiPolygon,n._childPosToCell=X._childPosToCell,n._compactCells=X._compactCells,n._constructCell=X._constructCell,n._destroyLinkedMultiPolygon=X._destroyLinkedMultiPolygon,n._directedEdgeToBoundary=X._directedEdgeToBoundary,n._directedEdgeToCells=X._directedEdgeToCells,n._edgeLengthKm=X._edgeLengthKm,n._edgeLengthM=X._edgeLengthM,n._edgeLengthRads=X._edgeLengthRads;var Y=n._emscripten_replace_memory=X._emscripten_replace_memory;n._free=X._free,n._getBaseCellNumber=X._getBaseCellNumber,n._getDirectedEdgeDestination=X._getDirectedEdgeDestination,n._getDirectedEdgeOrigin=X._getDirectedEdgeOrigin,n._getHexagonAreaAvgKm2=X._getHexagonAreaAvgKm2,n._getHexagonAreaAvgM2=X._getHexagonAreaAvgM2,n._getHexagonEdgeLengthAvgKm=X._getHexagonEdgeLengthAvgKm,n._getHexagonEdgeLengthAvgM=X._getHexagonEdgeLengthAvgM,n._getIcosahedronFaces=X._getIcosahedronFaces,n._getIndexDigit=X._getIndexDigit,n._getNumCells=X._getNumCells,n._getPentagons=X._getPentagons,n._getRes0Cells=X._getRes0Cells,n._getResolution=X._getResolution,n._greatCircleDistanceKm=X._greatCircleDistanceKm,n._greatCircleDistanceM=X._greatCircleDistanceM,n._greatCircleDistanceRads=X._greatCircleDistanceRads,n._gridDisk=X._gridDisk,n._gridDiskDistances=X._gridDiskDistances,n._gridDistance=X._gridDistance,n._gridPathCells=X._gridPathCells,n._gridPathCellsSize=X._gridPathCellsSize,n._gridRing=X._gridRing,n._gridRingUnsafe=X._gridRingUnsafe,n._i64Add=X._i64Add,n._i64Subtract=X._i64Subtract,n._isPentagon=X._isPentagon,n._isResClassIII=X._isResClassIII,n._isValidCell=X._isValidCell,n._isValidDirectedEdge=X._isValidDirectedEdge,n._isValidIndex=X._isValidIndex,n._isValidVertex=X._isValidVertex,n._latLngToCell=X._latLngToCell,n._llvm_ctlz_i64=X._llvm_ctlz_i64,n._llvm_maxnum_f64=X._llvm_maxnum_f64,n._llvm_minnum_f64=X._llvm_minnum_f64,n._llvm_round_f64=X._llvm_round_f64,n._localIjToCell=X._localIjToCell,n._malloc=X._malloc,n._maxFaceCount=X._maxFaceCount,n._maxGridDiskSize=X._maxGridDiskSize,n._maxPolygonToCellsSize=X._maxPolygonToCellsSize,n._maxPolygonToCellsSizeExperimental=X._maxPolygonToCellsSizeExperimental,n._memcpy=X._memcpy,n._memmove=X._memmove,n._memset=X._memset,n._originToDirectedEdges=X._originToDirectedEdges,n._pentagonCount=X._pentagonCount,n._polygonToCells=X._polygonToCells,n._polygonToCellsExperimental=X._polygonToCellsExperimental,n._readInt64AsDoubleFromPointer=X._readInt64AsDoubleFromPointer,n._res0CellCount=X._res0CellCount,n._reverseDirectedEdge=X._reverseDirectedEdge,n._round=X._round,n._sbrk=X._sbrk,n._sizeOfCellBoundary=X._sizeOfCellBoundary,n._sizeOfCoordIJ=X._sizeOfCoordIJ,n._sizeOfGeoLoop=X._sizeOfGeoLoop,n._sizeOfGeoPolygon=X._sizeOfGeoPolygon,n._sizeOfH3Index=X._sizeOfH3Index,n._sizeOfLatLng=X._sizeOfLatLng,n._sizeOfLinkedGeoPolygon=X._sizeOfLinkedGeoPolygon,n._uncompactCells=X._uncompactCells,n._uncompactCellsSize=X._uncompactCellsSize,n._vertexToLatLng=X._vertexToLatLng,n.establishStackSpace=X.establishStackSpace;var Z,ee,te=n.stackAlloc=X.stackAlloc,ne=n.stackRestore=X.stackRestore,re=n.stackSave=X.stackSave;if(n.dynCall_iii=X.dynCall_iii,n.asm=X,n.cwrap=function(e,t,n,r){var i=(n=n||[]).every(function(e){return"number"===e});return"string"!==t&&i&&!r?u(e):function(){return f(e,t,n,arguments)}},n.setValue=function(e,t,n,r){switch("*"===(n=n||"i8").charAt(n.length-1)&&(n="i32"),n){case"i1":case"i8":h[e|0]=t;break;case"i16":m[e>>1]=t;break;case"i32":g[e>>2]=t;break;case"i64":V=[t>>>0,(U=t,+N(U)>=1?U>0?(0|B(+L(U/4294967296),4294967295))>>>0:~~+k((U-+(~~U>>>0))/4294967296)>>>0:0)],g[e>>2]=V[0],g[e+4>>2]=V[1];break;case"float":b[e>>2]=t;break;case"double":v[e>>3]=t;break;default:le("invalid type for setValue: "+n)}},n.getValue=function(e,t,n){switch("*"===(t=t||"i8").charAt(t.length-1)&&(t="i32"),t){case"i1":case"i8":return h[e|0];case"i16":return m[e>>1];case"i32":case"i64":return g[e>>2];case"float":return b[e>>2];case"double":return v[e>>3];default:le("invalid type for getValue: "+t)}return null},j){G(j)||(Z=j,j=n.locateFile?n.locateFile(Z,s):s+Z),O++,n.monitorRunDependencies&&n.monitorRunDependencies(O);var ie=function(e){e.byteLength&&(e=new Uint8Array(e)),p.set(e,8),n.memoryInitializerRequest&&delete n.memoryInitializerRequest.response,function(){if(O--,n.monitorRunDependencies&&n.monitorRunDependencies(O),0==O&&(null!==F&&(clearInterval(F),F=null),D)){var e=D;D=null,e()}}()},ae=function(){i(j,ie,function(){throw"could not load memory initializer "+j})},se=$(j);if(se)ie(se.buffer);else if(n.memoryInitializerRequest){var oe=function(){var e=n.memoryInitializerRequest,t=e.response;if(200!==e.status&&0!==e.status){var r=$(n.memoryInitializerRequestURL);if(!r)return console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: "+e.status+", retrying "+j),void ae();t=r.buffer}ie(t)};n.memoryInitializerRequest.response?setTimeout(oe,0):n.memoryInitializerRequest.addEventListener("load",oe)}else ae()}function Ae(e){function t(){ee||(ee=!0,c||(S(E),S(C),n.onRuntimeInitialized&&n.onRuntimeInitialized(),function(){if(n.postRun)for("function"==typeof n.postRun&&(n.postRun=[n.postRun]);n.postRun.length;)P(n.postRun.shift());S(I)}()))}e=e||a,O>0||(!function(){if(n.preRun)for("function"==typeof n.preRun&&(n.preRun=[n.preRun]);n.preRun.length;)R(n.preRun.shift());S(M)}(),O>0||(n.setStatus?(n.setStatus("Running..."),setTimeout(function(){setTimeout(function(){n.setStatus("")},1),t()},1)):t()))}function le(e){throw n.onAbort&&n.onAbort(e),o(e+=""),A(e),c=!0,"abort("+e+"). Build with -s ASSERTIONS=1 for more info."}if(D=function e(){ee||Ae(),ee||(D=e)},n.run=Ae,n.abort=le,n.preInit)for("function"==typeof n.preInit&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.pop()();return Ae(),e}("object"==typeof Ta?Ta:{}),Sa="number",Ma={0:"Success",1:"The operation failed but a more specific error is not available",2:"Argument was outside of acceptable range",3:"Latitude or longitude arguments were outside of acceptable range",4:"Resolution argument was outside of acceptable range",5:"Cell argument was not valid",6:"Directed edge argument was not valid",7:"Undirected edge argument was not valid",8:"Vertex argument was not valid",9:"Pentagon distortion was encountered",10:"Duplicate input",11:"Cell arguments were not neighbors",12:"Cell arguments had incompatible resolutions",13:"Memory allocation failed",14:"Bounds of provided memory were insufficient",15:"Mode or flags argument was not valid",16:"Index argument was not valid",17:"Base cell number was outside of acceptable range",18:"Child indexing digits invalid",19:"Child indexing digits refer to a deleted subsequence"},Ea={1e3:"Unknown unit",1001:"Array length out of bounds",1002:"Got unexpected null value for H3 index"};function Ca(e,t,n){var r=n&&"value"in n,i=/* @__PURE__ */new Error((e[t]||"Unknown error")+" (code: "+t+(r?", value: "+n.value:"")+")");return i.code=t,i}function Ia(e,t){return Ca(Ma,e,2===arguments.length?{value:t}:{})}function Ra(e,t){return Ca(Ea,e,2===arguments.length?{value:t}:{})}function Pa(e){if(0!==e)throw Ia(e)}var Na={};[["sizeOfH3Index",Sa],["sizeOfLatLng",Sa],["sizeOfCellBoundary",Sa],["sizeOfGeoLoop",Sa],["sizeOfGeoPolygon",Sa],["sizeOfLinkedGeoPolygon",Sa],["sizeOfCoordIJ",Sa],["readInt64AsDoubleFromPointer",Sa],["isValidCell",Sa,[Sa,Sa]],["isValidIndex",Sa,[Sa,Sa]],["latLngToCell",Sa,[Sa,Sa,Sa,Sa]],["cellToLatLng",Sa,[Sa,Sa,Sa]],["cellToBoundary",Sa,[Sa,Sa,Sa]],["maxGridDiskSize",Sa,[Sa,Sa]],["gridDisk",Sa,[Sa,Sa,Sa,Sa]],["gridDiskDistances",Sa,[Sa,Sa,Sa,Sa,Sa]],["gridRing",Sa,[Sa,Sa,Sa,Sa]],["gridRingUnsafe",Sa,[Sa,Sa,Sa,Sa]],["maxPolygonToCellsSize",Sa,[Sa,Sa,Sa,Sa]],["polygonToCells",Sa,[Sa,Sa,Sa,Sa]],["maxPolygonToCellsSizeExperimental",Sa,[Sa,Sa,Sa,Sa]],["polygonToCellsExperimental",Sa,[Sa,Sa,Sa,Sa,Sa,Sa]],["cellsToLinkedMultiPolygon",Sa,[Sa,Sa,Sa]],["destroyLinkedMultiPolygon",null,[Sa]],["compactCells",Sa,[Sa,Sa,Sa,Sa]],["uncompactCells",Sa,[Sa,Sa,Sa,Sa,Sa,Sa]],["uncompactCellsSize",Sa,[Sa,Sa,Sa,Sa,Sa]],["isPentagon",Sa,[Sa,Sa]],["isResClassIII",Sa,[Sa,Sa]],["getBaseCellNumber",Sa,[Sa,Sa]],["getResolution",Sa,[Sa,Sa]],["getIndexDigit",Sa,[Sa,Sa,Sa]],["constructCell",Sa,[Sa,Sa,Sa,Sa]],["maxFaceCount",Sa,[Sa,Sa,Sa]],["getIcosahedronFaces",Sa,[Sa,Sa,Sa]],["cellToParent",Sa,[Sa,Sa,Sa,Sa]],["cellToChildren",Sa,[Sa,Sa,Sa,Sa]],["cellToCenterChild",Sa,[Sa,Sa,Sa,Sa]],["cellToChildrenSize",Sa,[Sa,Sa,Sa,Sa]],["cellToChildPos",Sa,[Sa,Sa,Sa,Sa]],["childPosToCell",Sa,[Sa,Sa,Sa,Sa,Sa,Sa]],["areNeighborCells",Sa,[Sa,Sa,Sa,Sa,Sa]],["cellsToDirectedEdge",Sa,[Sa,Sa,Sa,Sa,Sa]],["getDirectedEdgeOrigin",Sa,[Sa,Sa,Sa]],["getDirectedEdgeDestination",Sa,[Sa,Sa,Sa]],["isValidDirectedEdge",Sa,[Sa,Sa]],["directedEdgeToCells",Sa,[Sa,Sa,Sa]],["originToDirectedEdges",Sa,[Sa,Sa,Sa]],["directedEdgeToBoundary",Sa,[Sa,Sa,Sa]],["reverseDirectedEdge",Sa,[Sa,Sa,Sa]],["gridDistance",Sa,[Sa,Sa,Sa,Sa,Sa]],["gridPathCells",Sa,[Sa,Sa,Sa,Sa,Sa]],["gridPathCellsSize",Sa,[Sa,Sa,Sa,Sa,Sa]],["cellToLocalIj",Sa,[Sa,Sa,Sa,Sa,Sa,Sa]],["localIjToCell",Sa,[Sa,Sa,Sa,Sa,Sa]],["getHexagonAreaAvgM2",Sa,[Sa,Sa]],["getHexagonAreaAvgKm2",Sa,[Sa,Sa]],["getHexagonEdgeLengthAvgM",Sa,[Sa,Sa]],["getHexagonEdgeLengthAvgKm",Sa,[Sa,Sa]],["greatCircleDistanceM",Sa,[Sa,Sa]],["greatCircleDistanceKm",Sa,[Sa,Sa]],["greatCircleDistanceRads",Sa,[Sa,Sa]],["cellAreaM2",Sa,[Sa,Sa,Sa]],["cellAreaKm2",Sa,[Sa,Sa,Sa]],["cellAreaRads2",Sa,[Sa,Sa,Sa]],["edgeLengthM",Sa,[Sa,Sa,Sa]],["edgeLengthKm",Sa,[Sa,Sa,Sa]],["edgeLengthRads",Sa,[Sa,Sa,Sa]],["getNumCells",Sa,[Sa,Sa]],["getRes0Cells",Sa,[Sa]],["res0CellCount",Sa],["getPentagons",Sa,[Sa,Sa]],["pentagonCount",Sa],["cellToVertex",Sa,[Sa,Sa,Sa,Sa]],["cellToVertexes",Sa,[Sa,Sa,Sa]],["vertexToLatLng",Sa,[Sa,Sa,Sa]],["isValidVertex",Sa,[Sa,Sa]]].forEach(function(e){Na[e[0]]=Ta.cwrap.apply(Ta,e)});var ka=16,La=Na.sizeOfH3Index(),Ba=Na.sizeOfLatLng(),Oa=Na.sizeOfCellBoundary(),Fa=(Na.sizeOfGeoPolygon(),Na.sizeOfGeoLoop(),Na.sizeOfLinkedGeoPolygon()),Da=(Na.sizeOfCoordIJ(),"m"),Ua="km";Math.pow(2,32),Math.pow(2,31);var Va=/[^0-9a-fA-F]/;function ja(e){if(Array.isArray(e)&&2===e.length&&Number.isInteger(e[0])&&Number.isInteger(e[1]))return e;if("string"!=typeof e||Va.test(e))return[0,0];var t=parseInt(e.substring(0,e.length-8),ka);return[parseInt(e.substring(e.length-8),ka),t]}function za(e){if(e>=0)return e.toString(ka);var t=Ga(8,(e&=2147483647).toString(ka));return t=(parseInt(t[0],ka)+8).toString(ka)+t.substring(1)}function Ga(e,t){for(var n=e-t.length,r="",i=0;i<n;i++)r+="0";return r+=t}function Ha(e,t){void 0===t&&(t=0);var n=Ta.getValue(e+La*t,"i32"),r=Ta.getValue(e+La*t+4,"i32");return r?function(e,t){return za(t)+Ga(8,za(e))}(n,r):null}function qa(e,t,n){Ta.HEAPU32.set(ja(e),t/4+2*n)}function Qa(e){return 180*Ta.getValue(e,"double")/Math.PI}function Ka(e){return[Qa(e),Qa(e+8)]}function Wa(e){return[Qa(e+8),Qa(e)]}function Ja(e){var t=ja(e),n=t[0],r=t[1];return Boolean(Na.isPentagon(n,r))}function $a(e){var t=ja(e),n=t[0],r=t[1];return Na.isValidCell(n,r)?Na.getResolution(n,r):-1}function Xa(e,t,n){var r=Ta._malloc(Ba);Ta.HEAPF64.set([e,t].map(rs),r/8);var i=Ta._malloc(La);try{return Pa(Na.latLngToCell(r,n,i)),function(e){if(!e)throw Ra(1002);return e}(Ha(i))}finally{Ta._free(i),Ta._free(r)}}function Ya(e){var t=Ta._malloc(Ba),n=ja(e),r=n[0],i=n[1];try{return Pa(Na.cellToLatLng(r,i,t)),Ka(t)}finally{Ta._free(t)}}function Za(e,t){var n=Ta._malloc(Oa),r=ja(e),i=r[0],a=r[1];try{return Pa(Na.cellToBoundary(i,a,n)),function(e,t,n){for(var r=Ta.getValue(e,"i32"),i=e+8,a=[],s=t?Wa:Ka,o=0;o<2*r;o+=2)a.push(s(i+8*o));return n&&a.push(a[0]),a}(n,t,t)}finally{Ta._free(n)}}function es(e,t){if(!e||!e.length)return[];var n=e.length,r=Ta._calloc(n,La);!function(e,t){for(var n=t.length,r=0;r<n;r++)qa(t[r],e,r)}(r,e);var i=Ta._calloc(Fa);try{return Pa(Na.cellsToLinkedMultiPolygon(r,n,i)),function(e,t){for(var n,r,i,a,s=[],o=t?Wa:Ka;e;){for(s.push(n=[]),r=Ta.getValue(e,"i8*");r;){for(n.push(i=[]),a=Ta.getValue(r,"i8*");a;)i.push(o(a)),a=Ta.getValue(a+16,"i8*");t&&i.push(i[0]),r=Ta.getValue(r+8,"i8*")}e=Ta.getValue(e+8,"i8*")}return s}(i,t)}finally{Na.destroyLinkedMultiPolygon(i),Ta._free(i),Ta._free(r)}}function ts(e,t){var n,r=ja(e),i=r[0],a=r[1],s=ja(t),o=s[0],A=s[1],l=Ta._malloc(8);try{return Pa(Na.gridDistance(i,a,o,A,l)),n=l,Na.readInt64AsDoubleFromPointer(n)}finally{Ta._free(l)}}function ns(e,t){!function(e){if("number"!=typeof e||e<0||e>15||Math.floor(e)!==e)throw Ia(4,e)}(e);var n,r,i=Ta._malloc(8);try{switch(t){case Da:Pa(Na.getHexagonEdgeLengthAvgM(e,i));break;case Ua:Pa(Na.getHexagonEdgeLengthAvgKm(e,i));break;default:throw Ra(1e3,t)}return n=i,void 0===r&&(r=0),Ta.getValue(n+8*r,"double")}finally{Ta._free(i)}}function rs(e){return e*Math.PI/180}function is(e,t){t=void 0===t?e[0][0]:t;for(const n of e){const e=n[0]-t;e>180?n[0]-=360:e<-180&&(n[0]+=360)}}function as(e,t,n){const r=e(t,n),[i,a]=Ya(r);return[a,i]}function ss(e,t=1){const n=Za(e,!0);return 1!==t?function(e,t,n){const[r,i]=Ya(e),a=t.length;is(t,i);const s=t[0]===t[a-1]?a-1:a;for(let o=0;o<s;o++)t[o][0]=k(i,t[o][0],n),t[o][1]=k(r,t[o][1],n)}(e,n,t):is(n),n}function os(e){const t=new Float64Array(2*e.length);let n=0;for(const r of e)t[n++]=r[0],t[n++]=r[1];return t}var As=class extends Yn{indexToBounds(){const{data:e,getPentagon:t}=this.props;return{data:e,_normalize:!1,_windingOrder:"CCW",positionFormat:"XY",getPolygon:(e,n)=>{const r=t(e,n);return os(xa("string"==typeof r?BigInt(`0x${r}`):r,{closedRing:!0,segments:"auto"}))}}}};function ls(e){return"string"==typeof e?e.charAt(0).toLowerCase()+e.slice(1):e}function cs(e){if(Array.isArray(e))return e.map(e=>cs(e));if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[ls(n)]=cs(r);return t}return e}As.layerName="A5Layer",As.defaultProps={getPentagon:{type:"accessor",value:e=>e.pentagon}};var us=/* @__PURE__ */new RegExp("^[:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");var fs=function(e){const t=us.exec(e);return!(null==t)};var ds=["hasOwnProperty","toString","valueOf","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"],hs=["__proto__","constructor","prototype"],ps={allowBooleanAttributes:!1,unpairedTags:[]};function ms(e){return" "===e||"\t"===e||"\n"===e||"\r"===e}function gs(e,t){const n=t;for(;t<e.length;t++)if("?"==e[t]||" "==e[t]){const r=e.substr(n,t-n);if(t>5&&"xml"===r)return Ts("InvalidXml","XML declaration allowed only at the start of the document.",Es(e,t));if("?"==e[t]&&">"==e[t+1]){t++;break}continue}return t}function bs(e,t){if(e.length>t+5&&"-"===e[t+1]&&"-"===e[t+2]){for(t+=3;t<e.length;t++)if("-"===e[t]&&"-"===e[t+1]&&">"===e[t+2]){t+=2;break}}else if(e.length>t+8&&"D"===e[t+1]&&"O"===e[t+2]&&"C"===e[t+3]&&"T"===e[t+4]&&"Y"===e[t+5]&&"P"===e[t+6]&&"E"===e[t+7]){let n=1;for(t+=8;t<e.length;t++)if("<"===e[t])n++;else if(">"===e[t]&&(n--,0===n))break}else if(e.length>t+9&&"["===e[t+1]&&"C"===e[t+2]&&"D"===e[t+3]&&"A"===e[t+4]&&"T"===e[t+5]&&"A"===e[t+6]&&"["===e[t+7])for(t+=8;t<e.length;t++)if("]"===e[t]&&"]"===e[t+1]&&">"===e[t+2]){t+=2;break}return t}var vs='"',ys="'";function xs(e,t){let n="",r="",i=!1;for(;t<e.length;t++){if(e[t]===vs||e[t]===ys)""===r?r=e[t]:r!==e[t]||(r="");else if(">"===e[t]&&""===r){i=!0;break}n+=e[t]}return""===r&&{value:n,index:t,tagClosed:i}}function _s(e,t){const n=function(e){const t=[],n=e.length;let r=0;for(;r<n;){const i=r;for(;r<n&&ms(e[r]);)r++;if(r>=n)break;if("="===e[r]){r=i+1;continue}const a=e.slice(i,r),s=r;for(;r<n&&!ms(e[r])&&"="!==e[r];)r++;const o=e.slice(s,r);let A,l,c,u=r;for(;u<n&&ms(e[u]);)u++;u<n&&"="===e[u]&&(A=e.slice(r,u+1),r=u+1);let f=r;for(;f<n&&ms(e[f]);)f++;if(f<n&&('"'===e[f]||"'"===e[f])){const t=f+1,n=e.indexOf(e[f],t);-1!==n&&(l=e[f],c=e.slice(t,n),r=n+1)}const d={startIndex:i};d[1]=a,d[2]=o,d[3]=A,d[4]=void 0!==l||void 0,d[5]=l,d[6]=c,t.push(d)}return t}(e),r={};for(let i=0;i<n.length;i++){if(0===n[i][1].length)return Ts("InvalidAttr","Attribute '"+n[i][2]+"' has no space in starting.",Cs(n[i]));if(void 0!==n[i][3]&&void 0===n[i][4])return Ts("InvalidAttr","Attribute '"+n[i][2]+"' is without value.",Cs(n[i]));if(void 0===n[i][3]&&!t.allowBooleanAttributes)return Ts("InvalidAttr","boolean attribute '"+n[i][2]+"' is not allowed.",Cs(n[i]));const e=n[i][2];if(!Ss(e))return Ts("InvalidAttr","Attribute '"+e+"' is an invalid name.",Cs(n[i]));if(Object.prototype.hasOwnProperty.call(r,e))return Ts("InvalidAttr","Attribute '"+e+"' is repeated.",Cs(n[i]));r[e]=1}return!0}function ws(e,t){if(";"===e[++t])return-1;if("#"===e[t])return function(e,t){let n=/\d/;for("x"===e[t]&&(t++,n=/[\da-fA-F]/);t<e.length;t++){if(";"===e[t])return t;if(!e[t].match(n))break}return-1}(e,++t);let n=0;for(;t<e.length;t++,n++)if(!(e[t].match(/\w/)&&n<20)){if(";"===e[t])break;return-1}return t}function Ts(e,t,n){return{err:{code:e,msg:t,line:n.line||n,col:n.col}}}function Ss(e){return fs(e)}function Ms(e){return fs(e)}function Es(e,t){const n=e.substring(0,t).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function Cs(e){return e.startIndex+e[1].length}var Is={cent:"¢",pound:"£",curren:"¤",yen:"¥",euro:"€",dollar:"$",fnof:"ƒ",inr:"₹",af:"؋",birr:"ብር",peso:"₱",rub:"₽",won:"₩",yuan:"¥",cedil:"¸"},Rs={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'},Ps={nbsp:" ",copy:"©",reg:"®",trade:"™",mdash:"—",ndash:"–",hellip:"…",laquo:"«",raquo:"»",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",bull:"•",para:"¶",sect:"§",deg:"°",frac12:"½",frac14:"¼",frac34:"¾"},Ns=Object.freeze({ALLOW:"allow",BLOCK:"block",THROW:"throw"}),ks=/* @__PURE__ */new Set("!?\\\\/[]$%{}^&*()<>|+");function Ls(e){if("#"===e[0])throw new Error(`[EntityReplacer] Invalid character '#' in entity name: "${e}"`);for(const t of e)if(ks.has(t))throw new Error(`[EntityReplacer] Invalid character '${t}' in entity name: "${e}"`);return e}function Bs(...e){const t=Object.create(null);for(const n of e)if(n)for(const e of Object.keys(n)){const r=n[e];if("string"==typeof r)t[e]=r;else if(r&&"object"==typeof r&&void 0!==r.val){const n=r.val;"string"==typeof n&&(t[e]=n)}}return t}var Os="external",Fs="base",Ds="all";var Us=Object.freeze({allow:0,leave:1,remove:2,throw:3}),Vs=/* @__PURE__ */new Set([9,10,13]);var js=class{constructor(e={}){var t;this._limit=e.limit||{},this._maxTotalExpansions=this._limit.maxTotalExpansions||0,this._maxExpandedLength=this._limit.maxExpandedLength||0,this._postCheck="function"==typeof e.postCheck?e.postCheck:e=>e,this._limitTiers=(t=this._limit.applyLimitsTo??Os)&&t!==Os?t===Ds?/* @__PURE__ */new Set([Ds]):t===Fs?/* @__PURE__ */new Set([Fs]):Array.isArray(t)?new Set(t):/* @__PURE__ */new Set([Os]):/* @__PURE__ */new Set([Os]),this._numericAllowed=e.numericAllowed??!0,this._baseMap=Bs(Rs,e.namedEntities||null),this._externalMap=Object.create(null),this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this._removeSet=new Set(e.remove&&Array.isArray(e.remove)?e.remove:[]),this._leaveSet=new Set(e.leave&&Array.isArray(e.leave)?e.leave:[]);const n=function(e){if(!e)return{xmlVersion:1,onLevel:Us.allow,nullLevel:Us.remove};const t=1.1===e.xmlVersion?1.1:1,n=Us[e.onNCR]??Us.allow,r=Us[e.nullNCR]??Us.remove;return{xmlVersion:t,onLevel:n,nullLevel:Math.max(r,Us.remove)}}(e.ncr);this._ncrXmlVersion=n.xmlVersion,this._ncrOnLevel=n.onLevel,this._ncrNullLevel=n.nullLevel,this._onExternalEntity="function"==typeof e.onExternalEntity?e.onExternalEntity:null,this._onInputEntity="function"==typeof e.onInputEntity?e.onInputEntity:null}_applyRegistrationHook(e,t,n,r){if(!e)return!0;const i=e(t,n);if(i===Ns.BLOCK)return!1;if(i===Ns.THROW)throw new Error(`[EntityDecoder] Registration of ${r} entity "&${t};" was rejected by hook`);return!0}setExternalEntities(e){if(e)for(const r of Object.keys(e))Ls(r);if(!this._onExternalEntity)return void(this._externalMap=Bs(e));const t=Bs(e),n=Object.create(null);for(const[r,i]of Object.entries(t))this._applyRegistrationHook(this._onExternalEntity,r,i,"external")&&(n[r]=i);this._externalMap=n}addExternalEntity(e,t){Ls(e),"string"==typeof t&&-1===t.indexOf("&")&&this._applyRegistrationHook(this._onExternalEntity,e,t,"external")&&(this._externalMap[e]=t)}addInputEntities(e){if(this._totalExpansions=0,this._expandedLength=0,!this._onInputEntity)return void(this._inputMap=Bs(e));const t=Bs(e),n=Object.create(null);for(const[r,i]of Object.entries(t))this._applyRegistrationHook(this._onInputEntity,r,i,"input")&&(n[r]=i);this._inputMap=n}reset(){return this._inputMap=Object.create(null),this._totalExpansions=0,this._expandedLength=0,this}setXmlVersion(e){this._ncrXmlVersion=1.1===e?1.1:1}decode(e){if("string"!=typeof e||0===e.length)return e;if(-1===e.indexOf("&"))return e;const t=e,n=[],r=e.length;let i=0,a=0;const s=this._maxTotalExpansions>0,o=this._maxExpandedLength>0,A=s||o;for(;a<r;){if(38!==e.charCodeAt(a)){a++;continue}let t=a+1;for(;t<r&&59!==e.charCodeAt(t)&&t-a<=32;)t++;if(t>=r||59!==e.charCodeAt(t)){a++;continue}const l=e.slice(a+1,t);if(0===l.length){a++;continue}let c,u;if(this._removeSet.has(l))c="",void 0===u&&(u=Os);else{if(this._leaveSet.has(l)){a++;continue}if(35===l.charCodeAt(0)){const e=this._resolveNCR(l);if(void 0===e){a++;continue}c=e,u=Fs}else{const e=this._resolveName(l);c=e?.value,u=e?.tier}}if(void 0!==c){if(a>i&&n.push(e.slice(i,a)),n.push(c),i=t+1,a=i,A&&this._tierCounts(u)){if(s&&(this._totalExpansions++,this._totalExpansions>this._maxTotalExpansions))throw new Error(`[EntityReplacer] Entity expansion count limit exceeded: ${this._totalExpansions} > ${this._maxTotalExpansions}`);if(o){const e=c.length-(l.length+2);if(e>0&&(this._expandedLength+=e,this._expandedLength>this._maxExpandedLength))throw new Error(`[EntityReplacer] Expanded content length limit exceeded: ${this._expandedLength} > ${this._maxExpandedLength}`)}}}else a++}i<r&&n.push(e.slice(i));const l=0===n.length?e:n.join("");return this._postCheck(l,t)}_tierCounts(e){return!!this._limitTiers.has(Ds)||this._limitTiers.has(e)}_resolveName(e){return e in this._inputMap?{value:this._inputMap[e],tier:Os}:e in this._externalMap?{value:this._externalMap[e],tier:Os}:e in this._baseMap?{value:this._baseMap[e],tier:Fs}:void 0}_classifyNCR(e){return 0===e?this._ncrNullLevel:e>=55296&&e<=57343||1===this._ncrXmlVersion&&e>=1&&e<=31&&!Vs.has(e)?Us.remove:-1}_applyNCRAction(e,t,n){switch(e){case Us.allow:return String.fromCodePoint(n);case Us.remove:return"";case Us.leave:return;case Us.throw:throw new Error(`[EntityDecoder] Prohibited numeric character reference &${t}; (U+${n.toString(16).toUpperCase().padStart(4,"0")})`);default:return String.fromCodePoint(n)}}_resolveNCR(e){const t=e.charCodeAt(1);let n;if(n=120===t||88===t?parseInt(e.slice(2),16):parseInt(e.slice(1),10),Number.isNaN(n)||n<0||n>1114111)return;const r=this._classifyNCR(n);if(!this._numericAllowed&&r<Us.remove)return;const i=-1===r?this._ncrOnLevel:Math.max(this._ncrOnLevel,r);return this._applyNCRAction(i,e,n)}},zs=e=>ds.includes(e)?"__"+e:e,Gs={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0,unicode:!1},tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,entityDecoder:null,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(e,t,n){return e},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0,jPath:!0,onDangerousProperty:zs};function Hs(e,t){if("string"!=typeof e)return;const n=e.toLowerCase();if(ds.some(e=>n===e.toLowerCase()))throw new Error(`[SECURITY] Invalid ${t}: "${e}" is a reserved JavaScript keyword that could cause prototype pollution`);if(hs.some(e=>n===e.toLowerCase()))throw new Error(`[SECURITY] Invalid ${t}: "${e}" is a reserved JavaScript keyword that could cause prototype pollution`)}function qs(e,t){return"boolean"==typeof e?{enabled:e,maxEntitySize:1e4,maxExpansionDepth:1e4,maxTotalExpansions:1/0,maxExpandedLength:1e5,maxEntityCount:1e3,allowedTags:null,tagFilter:null,appliesTo:"all"}:"object"==typeof e&&null!==e?{enabled:!1!==e.enabled,maxEntitySize:Math.max(1,e.maxEntitySize??1e4),maxExpansionDepth:Math.max(1,e.maxExpansionDepth??1e4),maxTotalExpansions:Math.max(1,e.maxTotalExpansions??1/0),maxExpandedLength:Math.max(1,e.maxExpandedLength??1e5),maxEntityCount:Math.max(1,e.maxEntityCount??1e3),allowedTags:e.allowedTags??null,tagFilter:e.tagFilter??null,appliesTo:e.appliesTo??"all"}:qs(!0)}var Qs,Ks=function(e){const t=Object.assign({},Gs,e),n=[{value:t.attributeNamePrefix,name:"attributeNamePrefix"},{value:t.attributesGroupName,name:"attributesGroupName"},{value:t.textNodeName,name:"textNodeName"},{value:t.cdataPropName,name:"cdataPropName"},{value:t.commentPropName,name:"commentPropName"}];for(const{value:r,name:i}of n)r&&Hs(r,i);return null===t.onDangerousProperty&&(t.onDangerousProperty=zs),t.processEntities=qs(t.processEntities,t.htmlEntities),t.unpairedTagsSet=new Set(t.unpairedTags),t.stopNodes&&Array.isArray(t.stopNodes)&&(t.stopNodes=t.stopNodes.map(e=>"string"==typeof e&&e.startsWith("*.")?".."+e.substring(2):e)),t};Qs="function"!=typeof Symbol?"@@xmlMetadata":Symbol("XML Node Metadata");var Ws=class{constructor(e){this.tagname=e,this.child=[],this[":@"]=Object.create(null)}add(e,t){"__proto__"===e&&(e="#__proto__"),this.child.push({[e]:t})}addChild(e,t){"__proto__"===e.tagname&&(e.tagname="#__proto__"),e[":@"]&&Object.keys(e[":@"]).length>0?this.child.push({[e.tagname]:e.child,":@":e[":@"]}):this.child.push({[e.tagname]:e.child}),this.addStartIndex(t)}addStartIndex(e){void 0!==e&&(this.child[this.child.length-1][Qs]={startIndex:e})}addEndIndex(e){const t=this.child[this.child.length-1];void 0!==t&&void 0!==t[Qs]&&void 0===t[Qs].endIndex&&(t[Qs].endIndex=e)}static getMetaDataSymbol(){return Qs}},Js=":A-Za-z_À-ÖØ-öø-˿Ͱ-ͽͿ-҆҈-῿‌-‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�",$s=":A-Za-z_À-˿Ͱ-ͽͿ-҆҈-῿‌-‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�𐀀-󯿿",Xs=$s+"\\-\\.\\d·̀-ͯ҇‿-⁀",Ys=(e,t,n="")=>{const r=`[${e.replace(":","")}][${t.replace(":","")}]*`;return{name:new RegExp(`^[${e}][${t}]*$`,n),ncName:new RegExp(`^${r}$`,n),qName:new RegExp(`^${r}(?::${r})?$`,n),nmToken:new RegExp(`^[${t}]+$`,n),nmTokens:new RegExp(`^[${t}]+(?:\\s+[${t}]+)*$`,n)}},Zs=Ys(Js,Js+"\\-\\.\\d·̀-ͯ‿-⁀"),eo=Ys($s,Xs,"u"),to=Ys(":A-Za-z_",":A-Za-z_\\-\\.\\d"),no=(e,{xmlVersion:t="1.0",asciiOnly:n=!1}={})=>((e="1.0",t=!1)=>t?to:"1.1"===e?eo:Zs)(t,n).qName.test(e),ro=class{constructor(e,t){this.suppressValidationErr=!e,this.options=e,this.xmlVersion=t||1}setXmlVersion(e=1){this.xmlVersion=e}readDocType(e,t){const n=Object.create(null);let r=0;if("O"!==e[t+3]||"C"!==e[t+4]||"T"!==e[t+5]||"Y"!==e[t+6]||"P"!==e[t+7]||"E"!==e[t+8])throw new Error("Invalid Tag instead of DOCTYPE");{t+=9;let i=1,a=!1,s=!1,o=null,A="";for(;t<e.length;t++)if(null===o)if(a||s||'"'!==e[t]&&"'"!==e[t])if("<"!==e[t]||s)if(">"===e[t]){if(s?"-"===e[t-1]&&"-"===e[t-2]&&(s=!1,i--):i--,0===i)break}else"["===e[t]?a=!0:A+=e[t];else{if(a&&ao(e,"!ENTITY",t)){let i,a;if(t+=7,[i,a,t]=this.readEntityExp(e,t+1,this.suppressValidationErr),-1===a.indexOf("&")){if(!1!==this.options.enabled&&null!=this.options.maxEntityCount&&r>=this.options.maxEntityCount)throw new Error(`Entity count (${r+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);n[i]=a,r++}}else if(a&&ao(e,"!ELEMENT",t)){t+=8;const{index:n}=this.readElementExp(e,t+1);t=n}else if(a&&ao(e,"!ATTLIST",t))t+=8;else if(a&&ao(e,"!NOTATION",t)){t+=9;const{index:n}=this.readNotationExp(e,t+1,this.suppressValidationErr);t=n}else{if(!ao(e,"!--",t))throw new Error("Invalid DOCTYPE");s=!0}i++,A=""}else o=e[t],A+=e[t];else e[t]===o&&(o=null),A+=e[t];if(null!==o||0!==i)throw new Error("Unclosed DOCTYPE")}return{entities:n,i:t}}readEntityExp(e,t){const n=t=io(e,t);for(;t<e.length&&!/\s/.test(e[t])&&'"'!==e[t]&&"'"!==e[t];)t++;let r=e.substring(n,t);if(so(r,{xmlVersion:this.xmlVersion}),t=io(e,t),!this.suppressValidationErr){if("SYSTEM"===e.substring(t,t+6).toUpperCase())throw new Error("External entities are not supported");if("%"===e[t])throw new Error("Parameter entities are not supported")}let i="";if([t,i]=this.readIdentifierVal(e,t,"entity"),!1!==this.options.enabled&&null!=this.options.maxEntitySize&&i.length>this.options.maxEntitySize)throw new Error(`Entity "${r}" size (${i.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return[r,i,--t]}readNotationExp(e,t){const n=t=io(e,t);for(;t<e.length&&!/\s/.test(e[t]);)t++;let r=e.substring(n,t);!this.suppressValidationErr&&so(r,{xmlVersion:this.xmlVersion}),t=io(e,t);const i=e.substring(t,t+6).toUpperCase();if(!this.suppressValidationErr&&"SYSTEM"!==i&&"PUBLIC"!==i)throw new Error(`Expected SYSTEM or PUBLIC, found "${i}"`);t+=i.length,t=io(e,t);let a=null,s=null;if("PUBLIC"===i)[t,a]=this.readIdentifierVal(e,t,"publicIdentifier"),'"'!==e[t=io(e,t)]&&"'"!==e[t]||([t,s]=this.readIdentifierVal(e,t,"systemIdentifier"));else if("SYSTEM"===i&&([t,s]=this.readIdentifierVal(e,t,"systemIdentifier"),!this.suppressValidationErr&&!s))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:r,publicIdentifier:a,systemIdentifier:s,index:--t}}readIdentifierVal(e,t,n){let r="";const i=e[t];if('"'!==i&&"'"!==i)throw new Error(`Expected quoted string, found "${i}"`);const a=++t;for(;t<e.length&&e[t]!==i;)t++;if(r=e.substring(a,t),e[t]!==i)throw new Error(`Unterminated ${n} value`);return[++t,r]}readElementExp(e,t){const n=t=io(e,t);for(;t<e.length&&!/\s/.test(e[t]);)t++;let r=e.substring(n,t);if(!this.suppressValidationErr&&!no(r,{xmlVersion:this.xmlVersion}))throw new Error(`Invalid element name: "${r}"`);let i="";if("E"===e[t=io(e,t)]&&ao(e,"MPTY",t))t+=4;else if("A"===e[t]&&ao(e,"NY",t))t+=2;else if("("===e[t]){const n=++t;for(;t<e.length&&")"!==e[t];)t++;if(i=e.substring(n,t),")"!==e[t])throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${e[t]}"`);return{elementName:r,contentModel:i.trim(),index:t}}readAttlistExp(e,t){let n=t=io(e,t);for(;t<e.length&&!/\s/.test(e[t]);)t++;let r=e.substring(n,t);for(so(r,{xmlVersion:this.xmlVersion}),n=t=io(e,t);t<e.length&&!/\s/.test(e[t]);)t++;let i=e.substring(n,t);if(!so(i,{xmlVersion:this.xmlVersion}))throw new Error(`Invalid attribute name: "${i}"`);t=io(e,t);let a="";if("NOTATION"===e.substring(t,t+8).toUpperCase()){if(a="NOTATION","("!==e[t=io(e,t+=8)])throw new Error(`Expected '(', found "${e[t]}"`);t++;let n=[];for(;t<e.length&&")"!==e[t];){const r=t;for(;t<e.length&&"|"!==e[t]&&")"!==e[t];)t++;let i=e.substring(r,t);if(i=i.trim(),!so(i,{xmlVersion:this.xmlVersion}))throw new Error(`Invalid notation name: "${i}"`);n.push(i),"|"===e[t]&&(t++,t=io(e,t))}if(")"!==e[t])throw new Error("Unterminated list of notations");t++,a+=" ("+n.join("|")+")"}else{const n=t;for(;t<e.length&&!/\s/.test(e[t]);)t++;if(a+=e.substring(n,t),!this.suppressValidationErr&&!["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"].includes(a.toUpperCase()))throw new Error(`Invalid attribute type: "${a}"`)}t=io(e,t);let s="";return"#REQUIRED"===e.substring(t,t+8).toUpperCase()?(s="#REQUIRED",t+=8):"#IMPLIED"===e.substring(t,t+7).toUpperCase()?(s="#IMPLIED",t+=7):[t,s]=this.readIdentifierVal(e,t,"ATTLIST"),{elementName:r,attributeName:i,attributeType:a,defaultValue:s,index:t}}},io=(e,t)=>{for(;t<e.length&&/\s/.test(e[t]);)t++;return t};function ao(e,t,n){for(let r=0;r<t.length;r++)if(t[r]!==e[n+r+1])return!1;return!0}function so(e,t){if(no(e,{xmlVersion:t}))return e;throw new Error(`Invalid entity name ${e}`)}var oo=/* @__PURE__ */new Map,Ao=/* @__PURE__ */new Uint8Array(63904).fill(255);for(const Hy of[48,1632,1776,2406,2534,2662,2790,2918,3046,3174,3302,3430,3558,3664,3792,3872,4160,4240,6112,6160,6470,6608,6784,6800,6992,7088,7232,7248,65296,120782,120792,120802,120812,120822,66720,68912,69734,69872,69942,70096,70384,70736,70864,71248,71360,71472,71904,72016,72688,72784,73040,73120,73552,92768,92864,93008,123200,123632,124144,125264,130032])for(let e=0;e<10;e++){const t=Hy+e;t<=65535?Ao[t-1632]=e:oo.set(t,e)}var lo=/* @__PURE__ */new Set([8722,65293,65123]);var co=/^[-+]?0x[a-fA-F0-9]+$/,uo=/^0b[01]+$/,fo=/^0o[0-7]+$/,ho=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,po={hex:!0,binary:!1,octal:!1,leadingZeros:!0,decimalPoint:".",eNotation:!0,infinity:"original",unicode:!1};function mo(e,t={}){if(t=Object.assign({},po,t),!e||"string"!=typeof e)return e;let n=e.trim();if(0===n.length)return e;if(void 0!==t.skipLike&&t.skipLike.test(n))return e;if("0"===n)return 0;if(t.unicode&&(n=function(e){if("string"!=typeof e)return e;const t=e.length;if(0===t)return e;let n=-1;for(let i=0;i<t;i++){const r=e.charCodeAt(i);if(!(r>=48&&r<=57||45===r))if(r<1632){if(lo.has(r)){n=i;break}}else if(r>=55296&&r<=56319){if(i+1<t){const t=e.charCodeAt(i+1);if(t>=56320&&t<=57343){const e=65536+(r-55296<<10)+(t-56320);if(oo.has(e)){n=i;break}}}}else if(255!==Ao[r-1632]||lo.has(r)){n=i;break}}if(-1===n)return e;const r=[];n>0&&r.push(e.slice(0,n));for(let i=n;i<t;i++){const n=e.charCodeAt(i);if(n>=48&&n<=57||45===n){r.push(e[i]);continue}if(n<1632){r.push(lo.has(n)?"-":e[i]);continue}if(n>=55296&&n<=56319){if(i+1<t){const t=e.charCodeAt(i+1);if(t>=56320&&t<=57343){const e=65536+(n-55296<<10)+(t-56320),a=oo.get(e);if(void 0!==a){r.push(String.fromCharCode(a+48)),i++;continue}}}r.push(e[i]);continue}if(lo.has(n)){r.push("-");continue}const a=Ao[n-1632];r.push(255!==a?String.fromCharCode(a+48):e[i])}return r.join("")}(n),"0"===n))return 0;if(t.hex&&co.test(n))return bo(n,16);if(t.binary&&uo.test(n))return bo(n,2);if(t.octal&&fo.test(n))return bo(n,8);if(isFinite(n)){if(n.includes("e")||n.includes("E"))return function(e,t,n){if(!n.eNotation)return e;const r=t.match(go);if(r){let i=r[1]||"";const a=-1===r[3].indexOf("e")?"E":"e",s=r[2],o=i?t[s.length+1]===a:t[s.length]===a;return s.length>1&&o?e:(1!==s.length||!r[3].startsWith(`.${a}`)&&r[3][0]!==a)&&s.length>0?n.leadingZeros&&!o?Number(t):e:Number(t)}return e}(e,n,t);{const r=ho.exec(n);if(r){const i=r[1]||"",a=r[2];let s=function(e){if(e&&-1!==e.indexOf(".")){let t=e.length;for(;t>0&&48===e.charCodeAt(t-1);)t--;return"."===(e=e.slice(0,t))?e="0":"."===e[0]?e="0"+e:"."===e[e.length-1]&&(e=e.substring(0,e.length-1)),e}return e}(r[3]);const o=i?"."===n[a.length+1]:"."===n[a.length];if(!t.leadingZeros&&(a.length>1||1===a.length&&!o))return e;{const r=Number(n),o=String(r);if(0===r)return r;if(-1!==o.search(/[eE]/))return t.eNotation?r:e;if(-1!==n.indexOf("."))return"0"===o||o===s||o===`${i}${s}`?r:e;let A=a?s:n;return a?A===o||i+A===o?r:e:A===o||A===i+o?r:e}}return e}}{const r=Number(n);return Number.isNaN(r)?e:function(e,t,n){const r=t===1/0;switch(n.infinity.toLowerCase()){case"null":return null;case"infinity":return t;case"string":return r?"Infinity":"-Infinity";default:return e}}(e,r,t)}}var go=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function bo(e,t){const n=e.trim();if(2!==t&&8!==t||(e=n.substring(2)),parseInt)return parseInt(e,t);if(Number.parseInt)return Number.parseInt(e,t);if(window&&window.parseInt)return window.parseInt(e,t);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}var vo=class{constructor(e,t={},n){this.pattern=e,this.separator=t.separator||".",this.segments=this._parse(e),this.data=n,this._hasDeepWildcard=this.segments.some(e=>"deep-wildcard"===e.type),this._hasAttributeCondition=this.segments.some(e=>void 0!==e.attrName),this._hasPositionSelector=this.segments.some(e=>void 0!==e.position)}_parse(e){const t=[];let n=0,r="";for(;n<e.length;)e[n]===this.separator?n+1<e.length&&e[n+1]===this.separator?(r.trim()&&(t.push(this._parseSegment(r.trim())),r=""),t.push({type:"deep-wildcard"}),n+=2):(r.trim()&&t.push(this._parseSegment(r.trim())),r="",n++):(r+=e[n],n++);return r.trim()&&t.push(this._parseSegment(r.trim())),t}_parseSegment(e){const t={type:"tag"};let n=null,r=e;const i=e.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(i&&(r=i[1]+i[3],i[2])){const e=i[2].slice(1,-1);e&&(n=e)}let a,s,o=r;if(r.includes("::")){const t=r.indexOf("::");if(a=r.substring(0,t).trim(),o=r.substring(t+2).trim(),!a)throw new Error(`Invalid namespace in pattern: ${e}`)}let A=null;if(o.includes(":")){const e=o.lastIndexOf(":"),t=o.substring(0,e).trim(),n=o.substring(e+1).trim();["first","last","odd","even"].includes(n)||/^nth\(\d+\)$/.test(n)?(s=t,A=n):s=o}else s=o;if(!s)throw new Error(`Invalid segment pattern: ${e}`);if(t.tag=s,a&&(t.namespace=a),n)if(n.includes("=")){const e=n.indexOf("=");t.attrName=n.substring(0,e).trim(),t.attrValue=n.substring(e+1).trim()}else t.attrName=n.trim();if(A){const e=A.match(/^nth\((\d+)\)$/);e?(t.position="nth",t.positionValue=parseInt(e[1],10)):t.position=A}return t}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}},yo=class{constructor(){this._byDepthAndTag=/* @__PURE__ */new Map,this._wildcardByDepth=/* @__PURE__ */new Map,this._deepWildcards=[],this._deepByTerminalTag=/* @__PURE__ */new Map,this._patterns=/* @__PURE__ */new Set,this._sealed=!1}add(e){if(this._sealed)throw new TypeError("ExpressionSet is sealed. Create a new ExpressionSet to add more expressions.");if(this._patterns.has(e.pattern))return this;if(this._patterns.add(e.pattern),e.hasDeepWildcard()){const t=e.segments[e.segments.length-1];if(t&&"deep-wildcard"!==t.type&&"*"!==t.tag){const n=t.tag;this._deepByTerminalTag.has(n)||this._deepByTerminalTag.set(n,[]),this._deepByTerminalTag.get(n).push(e)}else this._deepWildcards.push(e);return this}const t=e.length,n=e.segments[e.segments.length-1]?.tag;if(n&&"*"!==n){const r=`${t}:${n}`;this._byDepthAndTag.has(r)||this._byDepthAndTag.set(r,[]),this._byDepthAndTag.get(r).push(e)}else this._wildcardByDepth.has(t)||this._wildcardByDepth.set(t,[]),this._wildcardByDepth.get(t).push(e);return this}addAll(e){for(const t of e)this.add(t);return this}has(e){return this._patterns.has(e.pattern)}get size(){return this._patterns.size}seal(){return this._sealed=!0,this}get isSealed(){return this._sealed}matchesAny(e){return null!==this.findMatch(e)}findMatch(e){const t=e.getDepth(),n=e.getCurrentTag(),r=`${t}:${n}`,i=this._byDepthAndTag.get(r);if(i)for(let o=0;o<i.length;o++)if(e.matches(i[o]))return i[o];const a=this._wildcardByDepth.get(t);if(a)for(let o=0;o<a.length;o++)if(e.matches(a[o]))return a[o];const s=this._deepByTerminalTag.get(n);if(s)for(let o=0;o<s.length;o++)if(e.matches(s[o]))return s[o];for(let o=0;o<this._deepWildcards.length;o++)if(e.matches(this._deepWildcards[o]))return this._deepWildcards[o];return null}},xo=class{constructor(e){this._matcher=e}get separator(){return this._matcher.separator}getCurrentTag(){const e=this._matcher.path;return e.length>0?e[e.length-1].tag:void 0}getCurrentNamespace(){const e=this._matcher.path;return e.length>0?e[e.length-1].namespace:void 0}getAttrValue(e){const t=this._matcher.path;if(0!==t.length)return t[t.length-1].values?.[e]}hasAttr(e){const t=this._matcher.path;if(0===t.length)return!1;const n=t[t.length-1];return void 0!==n.values&&e in n.values}getAnyParentAttr(e){return this._matcher.getAnyParentAttr(e)}hasAnyParentAttr(e){return this._matcher.hasAnyParentAttr(e)}getPosition(){const e=this._matcher.path;return 0===e.length?-1:e[e.length-1].position??0}getCounter(){const e=this._matcher.path;return 0===e.length?-1:e[e.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this._matcher.path.length}toString(e,t=!0){return this._matcher.toString(e,t)}toArray(){return this._matcher.path.map(e=>e.tag)}matches(e){return this._matcher.matches(e)}matchesAny(e){return e.matchesAny(this._matcher)}},_o=class{constructor(e={}){this.separator=e.separator||".",this.path=[],this.siblingStacks=[],this._pathStringCache=null,this._view=new xo(this),this._keptAttrs=[]}push(e,t=null,n=null,r=null){this._pathStringCache=null,this.path.length>0&&(this.path[this.path.length-1].values=void 0);const i=this.path.length;let a=this.siblingStacks[i];a||(a={counts:/* @__PURE__ */new Map,total:0},this.siblingStacks[i]=a);const s=n?`${n}:${e}`:e,o=a.counts.get(s)||0,A=a.total;a.counts.set(s,o+1),a.total++;const l={tag:e,position:A,counter:o};null!=n&&(l.namespace=n),null!=t&&(l.values=t),this.path.push(l);const c=this.path.length,u=null!==r?r.keep:null;if(null!=u&&u.length>0&&t)for(let f=0;f<u.length;f++){const e=u[f];void 0!==t[e]&&this._keptAttrs.push({depth:c,name:e,value:t[e]})}}pop(){if(0===this.path.length)return;this._pathStringCache=null;const e=this.path.pop();this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1);const t=this.path.length+1;for(;this._keptAttrs.length>0&&this._keptAttrs[this._keptAttrs.length-1].depth>=t;)this._keptAttrs.pop();return e}updateCurrent(e){if(this.path.length>0){const t=this.path[this.path.length-1];null!=e&&(t.values=e)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(e){if(0!==this.path.length)return this.path[this.path.length-1].values?.[e]}hasAttr(e){if(0===this.path.length)return!1;const t=this.path[this.path.length-1];return void 0!==t.values&&e in t.values}getAnyParentAttr(e){const t=this._keptAttrs;for(let n=t.length-1;n>=0;n--)if(t[n].name===e)return t[n].value}hasAnyParentAttr(e){const t=this._keptAttrs;for(let n=t.length-1;n>=0;n--)if(t[n].name===e)return!0;return!1}getPosition(){return 0===this.path.length?-1:this.path[this.path.length-1].position??0}getCounter(){return 0===this.path.length?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(e,t=!0){const n=e||this.separator;if(n===this.separator&&!0===t){if(null!==this._pathStringCache)return this._pathStringCache;const e=this.path.map(e=>e.namespace?`${e.namespace}:${e.tag}`:e.tag).join(n);return this._pathStringCache=e,e}return this.path.map(e=>t&&e.namespace?`${e.namespace}:${e.tag}`:e.tag).join(n)}toArray(){return this.path.map(e=>e.tag)}reset(){this._pathStringCache=null,this.path=[],this.siblingStacks=[],this._keptAttrs=[]}matches(e){const t=e.segments;return 0!==t.length&&(e.hasDeepWildcard()?this._matchWithDeepWildcard(t):this._matchSimple(t))}_matchSimple(e){if(this.path.length!==e.length)return!1;for(let t=0;t<e.length;t++)if(!this._matchSegment(e[t],this.path[t],t===this.path.length-1))return!1;return!0}_matchWithDeepWildcard(e){let t=this.path.length-1,n=e.length-1;for(;n>=0&&t>=0;){const r=e[n];if("deep-wildcard"===r.type){if(n--,n<0)return!0;const r=e[n];let i=!1;for(let e=t;e>=0;e--)if(this._matchSegment(r,this.path[e],e===this.path.length-1)){t=e-1,n--,i=!0;break}if(!i)return!1}else{if(!this._matchSegment(r,this.path[t],t===this.path.length-1))return!1;t--,n--}}return n<0}_matchSegment(e,t,n){if("*"!==e.tag&&e.tag!==t.tag)return!1;if(void 0!==e.namespace&&"*"!==e.namespace&&e.namespace!==t.namespace)return!1;if(void 0!==e.attrName){if(!n)return!1;if(!t.values||!(e.attrName in t.values))return!1;if(void 0!==e.attrValue&&String(t.values[e.attrName])!==String(e.attrValue))return!1}if(void 0!==e.position){if(!n)return!1;const r=t.counter??0;if("first"===e.position&&0!==r)return!1;if("odd"===e.position&&r%2!=1)return!1;if("even"===e.position&&r%2!=0)return!1;if("nth"===e.position&&r!==e.positionValue)return!1}return!0}matchesAny(e){return e.matchesAny(this)}snapshot(){return{path:this.path.map(e=>({...e})),siblingStacks:this.siblingStacks.map(e=>e?{counts:new Map(e.counts),total:e.total}:e),keptAttrs:this._keptAttrs.map(e=>({...e}))}}restore(e){this._pathStringCache=null,this.path=e.path.map(e=>({...e})),this.siblingStacks=e.siblingStacks.map(e=>e?{counts:new Map(e.counts),total:e.total}:e),this._keptAttrs=(e.keptAttrs||[]).map(e=>({...e}))}readOnly(){return this._view}},wo=[{id:"html-script-open",description:"<script opening tag",pattern:/<script[\s>/]/i},{id:"html-script-close",description:"<\/script closing tag",pattern:/<\/script[\s>]/i},{id:"html-javascript-protocol",description:"javascript: URI scheme (with optional whitespace/encoding)",pattern:/j[\t\n\r ]*a[\t\n\r ]*v[\t\n\r ]*a[\t\n\r ]*s[\t\n\r ]*c[\t\n\r ]*r[\t\n\r ]*i[\t\n\r ]*p[\t\n\r ]*t[\t\n\r ]*:/i},{id:"html-vbscript-protocol",description:"vbscript: URI scheme",pattern:/vbscript[\t\n\r ]*:/i},{id:"html-data-html",description:"data:text/html URI — can execute scripts in browsers",pattern:/data[\t\n\r ]*:[\t\n\r ]*text\/html/i},{id:"html-data-xhtml",description:"data:application/xhtml+xml URI",pattern:/data[\t\n\r ]*:[\t\n\r ]*application\/xhtml/i},{id:"html-data-svg",description:"data:image/svg+xml URI — can execute scripts",pattern:/data[\t\n\r ]*:[\t\n\r ]*image\/svg\+xml/i},{id:"html-inline-event-handler",description:"Inline event handler attributes: onclick=, onerror=, onload=, etc.",pattern:/\bon\w{1,30}\s*=/i},{id:"html-entity-obfuscated-script",description:"HTML-entity-encoded <script (e.g. &#x3C;script or &lt;script)",pattern:/(?:&#x0*3[Cc];?|&#0*60;?|&lt;)\s*script/i},{id:"html-entity-obfuscated-javascript",description:'HTML-entity-encoded javascript: (partial — catches common &#106; or &#x6a; for "j")',pattern:/(?:&#x0*6[Aa];?|&#0*106;?)\s*(?:&#x0*61;?|a)[\s\S]{0,80}script\s*:/i},{id:"html-style-expression",description:"CSS expression() — IE-era code execution in style attributes",pattern:/style[\s\S]{0,20}expression\s*\(/i},{id:"html-object-embed",description:"<object or <embed tags that can load active content",pattern:/<(?:object|embed)[\s>/]/i},{id:"html-base-tag",description:"<base href= — can hijack all relative URLs on a page",pattern:/<base[\s>]/i},{id:"html-meta-refresh",description:'<meta http-equiv="refresh" — can redirect users',pattern:/<meta[\s\S]{0,40}http-equiv[\s\S]{0,20}refresh/i},{id:"html-srcdoc",description:"srcdoc= attribute on iframes — embeds HTML that can run scripts",pattern:/srcdoc\s*=/i},{id:"html-iframe",description:"<iframe tag",pattern:/<iframe[\s>/]/i},{id:"html-form",description:"<form tag — can be used for phishing / credential harvesting injection",pattern:/<form[\s>/]/i}],To=[{id:"xml-cdata-injection",description:"CDATA section injection: <![CDATA[ breaks out of text node context",pattern:/<!\[CDATA\[/i},{id:"xml-cdata-close",description:"CDATA close sequence: ]]> can terminate an enclosing CDATA section",pattern:/\]\]>/},{id:"xml-processing-instruction",description:"XML processing instruction: <?xml-stylesheet or <?php etc.",pattern:/<\?(?:xml[\- ]|php|asp)/i},{id:"xml-doctype-injection",description:"DOCTYPE declaration embedded in content — can define entities",pattern:/<!DOCTYPE(?:[\s[]|$)/i},{id:"xml-entity-system",description:"SYSTEM keyword — used in external entity declarations (XXE)",pattern:/\bSYSTEM\s+["']/i},{id:"xml-entity-public",description:"PUBLIC keyword — used in external entity declarations (XXE)",pattern:/\bPUBLIC\s+["']/i},{id:"xml-entity-declaration",description:"<!ENTITY declaration — defines entities, potential XXE or entity expansion",pattern:/<!ENTITY[\s%]/i},{id:"xml-billion-laughs",description:"Entity reference chaining / billion laughs: repeated &eX; style references",pattern:/(?:&\w{1,20};){3,}/},{id:"xml-namespace-confusion",description:"xmlns: attribute injection — can redefine namespaces to confuse parsers",pattern:/\bxmlns(?::\w{1,40})?\s*=/i},{id:"xml-comment-injection",description:"\x3c!-- comment injection — can hide content from some parsers",pattern:/<!--/},{id:"xml-comment-close",description:"--\x3e closes an enclosing XML comment",pattern:/-->/},{id:"xml-pi-close",description:"?> closes an enclosing processing instruction",pattern:/\?>/}],So=[{id:"svg-script-element",description:"<script element inside SVG executes JavaScript",pattern:/<script[\s>/]/i},{id:"svg-xlink-href-javascript",description:"xlink:href with javascript: — classic SVG XSS via <a> or <use>",pattern:/xlink\s*:\s*href\s*=\s*["']?\s*javascript\s*:/i},{id:"svg-href-javascript",description:"href= with javascript: in SVG context (<a>, <animate>, etc.)",pattern:/href\s*=\s*["']?\s*javascript\s*:/i},{id:"svg-foreignobject",description:"<foreignObject embeds HTML inside SVG — can execute scripts",pattern:/<foreignObject[\s>/]/i},{id:"svg-use-external",description:"<use xlink:href or href pointing to external resource (non-fragment URL)",pattern:/<use[\s\S]{0,60}(?:xlink\s*:\s*)?href\s*=\s*(?:["'][^#]|[^"'#\s>])/i},{id:"svg-animate-href",description:'<animate attributeName="href" — can dynamically change href to javascript:',pattern:/<animate[\s\S]{0,80}attributeName\s*=\s*["'][\s]*href["']/i},{id:"svg-animate-xlinkhref",description:'<animate attributeName="xlink:href"',pattern:/<animate[\s\S]{0,80}attributeName\s*=\s*["'][\s]*xlink\s*:\s*href["']/i},{id:"svg-set-javascript",description:'<set to="javascript:..." — sets an attribute to a javascript: URI',pattern:/<set[\s\S]{0,80}to\s*=\s*["']?\s*javascript\s*:/i},{id:"svg-event-handler",description:"SVG-specific event handler attributes: onload=, onerror=, onactivate=, etc.",pattern:/\bon(?:load|error|activate|begin|end|repeat|focus|blur|click|mouse\w{1,20}|key\w{1,20})\s*=/i},{id:"svg-handler-generic",description:"Generic on* handler catch-all for SVG attributes",pattern:/\bon\w{1,30}\s*=/i},{id:"svg-filter-feimage",description:"<feImage href= — filter primitive that can load external resources",pattern:/<feImage[\s\S]{0,80}(?:xlink\s*:\s*)?href\s*=/i},{id:"svg-image-external",description:"<image xlink:href with http/https or javascript protocol",pattern:/<image[\s\S]{0,80}(?:xlink\s*:\s*)?href\s*=\s*["']?\s*(?:https?|javascript)\s*:/i},{id:"svg-style-javascript",description:"style= attribute containing javascript: (e.g. background:url(javascript:...))",pattern:/style\s*=[\s\S]{0,60}javascript\s*:/i}],Mo=[{id:"sql-block-comment-open",description:"SQL block comment open: /* ... */ — unusual in legitimate user text",pattern:/\/\*/},{id:"sql-union-select",description:"UNION SELECT — most common SQL injection aggregation attack",pattern:/\bUNION\s{1,20}(?:ALL\s{1,20})?SELECT\b/i},{id:"sql-drop-table",description:"DROP TABLE — destructive DDL injection",pattern:/\bDROP\s{1,20}TABLE\b/i},{id:"sql-drop-database",description:"DROP DATABASE — destructive DDL injection",pattern:/\bDROP\s{1,20}DATABASE\b/i},{id:"sql-insert-into",description:"INSERT INTO — data injection",pattern:/\bINSERT\s{1,20}INTO\b/i},{id:"sql-delete-from",description:"DELETE FROM — data deletion injection",pattern:/\bDELETE\s{1,20}FROM\b/i},{id:"sql-update-set",description:"UPDATE ... SET — data modification injection",pattern:/\bUPDATE\b[\s\S]{1,60}\bSET\b/i},{id:"sql-exec-xp",description:"EXEC xp_ — MSSQL extended stored procedure execution",pattern:/\bEXEC(?:UTE)?\s{1,20}xp_/i},{id:"sql-tautology-string",description:'Classic string tautology: \' OR \'1\'=\'1 or " OR "1"="1"',pattern:/'\s{0,10}OR\s{0,10}'[^']{0,20}'\s*=\s*'[^']{0,20}/i},{id:"sql-tautology-numeric",description:"Numeric tautology: OR 1=1",pattern:/\bOR\s{1,10}1\s*=\s*1\b/i},{id:"sql-always-true-zero",description:"Numeric tautology: OR 0=0",pattern:/\bOR\s{1,10}0\s*=\s*0\b/i},{id:"sql-sleep-benchmark",description:"Time-based blind injection: SLEEP() or BENCHMARK()",pattern:/\b(?:SLEEP|BENCHMARK)\s*\(/i},{id:"sql-waitfor-delay",description:"MSSQL time-based blind injection: WAITFOR DELAY",pattern:/\bWAITFOR\s{1,20}DELAY\b/i},{id:"sql-char-function",description:"CHAR() function — used to obfuscate injected strings",pattern:/\bCHAR\s*\(\s*\d{1,3}/i},{id:"sql-information-schema",description:"INFORMATION_SCHEMA — reconnaissance query for table/column enumeration",pattern:/\bINFORMATION_SCHEMA\b/i}],Eo=[{id:"shell-path-traversal-unix",description:"Unix path traversal: ../ — climbing the directory tree",pattern:/\.\.\//},{id:"shell-path-traversal-windows",description:"Windows path traversal: ..\\ — climbing the directory tree",pattern:/\.\.\\/},{id:"shell-path-traversal-encoded",description:"URL-encoded path traversal: %2e%2e or %2f variants",pattern:/%2e%2e|%2f\.\.|\.\.%2f/i},{id:"shell-null-byte",description:"Null byte injection: \\x00 or %00 — truncates strings in C-backed functions",pattern:/\x00|%00/},{id:"shell-semicolon",description:"Semicolon command separator: cmd1; cmd2",pattern:/;/},{id:"shell-pipe",description:"Pipe operator: cmd1 | cmd2",pattern:/\|/},{id:"shell-and-operator",description:"AND operator: cmd1 && cmd2",pattern:/&&/},{id:"shell-or-operator",description:"OR operator: cmd1 || cmd2",pattern:/\|\|/},{id:"shell-backtick",description:"Backtick command substitution: `cmd`",pattern:/`/},{id:"shell-dollar-paren",description:"Dollar-paren command substitution: $(cmd)",pattern:/\$\(/},{id:"shell-dollar-brace",description:"Dollar-brace variable expansion: ${var} — can be abused for injection",pattern:/\$\{/},{id:"shell-redirect-out",description:"Output redirection: cmd > file or cmd >> file",pattern:/>{1,2}/},{id:"shell-redirect-in",description:"Input redirection: cmd < file",pattern:/</},{id:"shell-newline-injection",description:"Newline injection: \\n or \\r — can inject new shell commands",pattern:/[\n\r]/},{id:"shell-glob-star",description:"Glob expansion: * or ? — can expand to unintended files",pattern:/[/\\][*?]/},{id:"shell-absolute-root",description:"Absolute root path injection: string starting with / or \\ (Windows UNC)",pattern:/^(?:\/|\\\\)/},{id:"shell-windows-drive",description:"Windows drive letter path injection: C:\\ or D:/",pattern:/^[a-zA-Z]:[/\\]/},{id:"shell-curl-wget",description:"curl/wget with URL or flags — can exfiltrate data or download payloads",pattern:/\b(?:curl|wget)\s+(?:https?:\/\/|ftp:\/\/|-)/i}],Co=[{id:"redos-nested-quantifier-plus",description:"Nested + quantifier inside a group with outer quantifier: (a+)+, (.+b)*, etc.",pattern:/\([^)]*\+[^)]*\)[+*]/},{id:"redos-nested-quantifier-star",description:"Nested * quantifier: (a*)* or (a*)+ — catastrophic backtracking",pattern:/\([^)]*\*[^)]*\)[*+]/},{id:"redos-nested-groups",description:"Doubly nested quantified groups: ((a+)+) — guaranteed catastrophic",pattern:/\(\([^)]{0,40}\)[+*]\)[+*]/},{id:"redos-alternation-overlap",description:"Overlapping alternation under quantifier: (a|a)+ — ambiguous NFA paths",pattern:/\(([^|()]{1,20})\|(?:\1)(?:\|[^|()]{1,20}){0,5}\)[+*?]{1,2}/},{id:"redos-star-plus-concat",description:"(x*x)+ pattern — triggers super-linear backtracking",pattern:/\([^)]{0,10}\*[^)]{0,10}\)[+*]/},{id:"redos-dot-star-greedy",description:"(.*){n,} or (.+){n,} — repeated greedy dot quantifiers",pattern:/\(\.[*+]\)\{?\d/},{id:"redos-large-repetition",description:"Very large fixed or range repetition count {1000,} or {1000,n} — denial of service via backtracking",pattern:/\{\d{4,}(?:,\d*)?\}/},{id:"redos-catastrophic-alternation",description:"Long alternation with many similar branches — polynomial backtracking risk",pattern:/\([^)]{0,200}(?:\|[^|)]{0,50}){9,}\)/}],Io="[\"'\\s]*:",Ro=[{id:"nosql-where-operator",description:"$where — executes arbitrary JavaScript server-side in MongoDB",pattern:new RegExp(`\\$where${Io}`,"i")},{id:"nosql-ne-operator",description:'$ne — "not equal" operator used to bypass equality checks',pattern:new RegExp(`\\$ne${Io}`,"i")},{id:"nosql-gt-operator",description:'$gt — "greater than" used to bypass password/value checks',pattern:new RegExp(`\\$gte?${Io}`,"i")},{id:"nosql-lt-operator",description:'$lt / $lte — "less than" bypass variants',pattern:new RegExp(`\\$lte?${Io}`,"i")},{id:"nosql-regex-operator",description:"$regex — can be used to extract data character by character (blind injection)",pattern:new RegExp(`\\$regex${Io}`,"i")},{id:"nosql-or-operator",description:"$or — logical OR; used to create always-true conditions",pattern:new RegExp(`\\$or${Io}\\s*\\[`,"i")},{id:"nosql-and-operator",description:"$and — logical AND operator injection",pattern:new RegExp(`\\$and${Io}\\s*\\[`,"i")},{id:"nosql-nor-operator",description:"$nor — logical NOR operator injection",pattern:new RegExp(`\\$nor${Io}\\s*\\[`,"i")},{id:"nosql-exists-operator",description:"$exists — can enumerate fields to determine schema",pattern:new RegExp(`\\$exists${Io}`,"i")},{id:"nosql-in-operator",description:"$in — matches any value in a list; can enumerate values",pattern:new RegExp(`\\$in${Io}\\s*\\[`,"i")},{id:"nosql-expr-operator",description:"$expr — allows aggregation expressions in queries (MongoDB 3.6+)",pattern:new RegExp(`\\$expr${Io}`,"i")},{id:"nosql-function-operator",description:"$function — executes arbitrary JavaScript in MongoDB 4.4+",pattern:new RegExp(`\\$function${Io}`,"i")},{id:"nosql-accumulator-operator",description:"$accumulator — custom aggregation with arbitrary JS execution",pattern:new RegExp(`\\$accumulator${Io}`,"i")},{id:"nosql-proto-pollution",description:"__proto__ — prototype pollution via object key injection",pattern:/__proto__/},{id:"nosql-constructor-prototype",description:"constructor.prototype — alternative prototype pollution vector (dot notation or JSON key)",pattern:/constructor[\s"':.,{\[]*prototype/i},{id:"nosql-proto-bracket",description:'["__proto__"] — bracket-notation prototype pollution',pattern:/\[["']__proto__["']\]/}],Po=[{id:"log-crlf-injection",description:"CRLF injection: literal \\r or \\n embeds fake log lines",pattern:/[\r\n]/},{id:"log-url-encoded-crlf",description:"URL-encoded CRLF: %0d, %0a, %0D, %0A — decoded by some log parsers",pattern:/%0[dDaA]/},{id:"log-unicode-newline",description:"Unicode newline variants: U+2028 (line separator), U+2029 (paragraph separator)",pattern:/[\u2028\u2029]/},{id:"log-log4shell-jndi",description:"Log4Shell: ${jndi:...} triggers remote code execution in Apache Log4j",pattern:/\$\{jndi\s*:/i},{id:"log-log4shell-obfuscated",description:"Obfuscated Log4Shell: ${::-j}... lookup-bypass prefix used to evade WAF detection",pattern:/\$\{::-/},{id:"log-log4j-lookup",description:"Log4j lookup syntax: ${env:...}, ${sys:...}, ${ctx:...} — data exfiltration",pattern:/\$\{(?:env|sys|ctx|main|map|sd|web|docker|k8s|spring)\s*:/i},{id:"log-ssti-double-brace",description:"SSTI double-brace: {{expression}} — Jinja2, Twig, Handlebars, etc.",pattern:/\{\{[\s\S]{0,80}\}\}/},{id:"log-ssti-hash-brace",description:"SSTI hash-brace: #{expression} — Thymeleaf, Velocity, Ruby ERB",pattern:/#\{[\s\S]{0,80}\}/},{id:"log-ssti-dollar-brace",description:"SSTI/EL injection: ${expression with operators or method calls} — JSP EL, Freemarker, SpEL",pattern:/\$\{[^}]*(?:\.|\(|\*|\+|\bclass\b|\bruntime\b|\bprocess\b|\bexec\b)[^}]{0,80}\}/i},{id:"log-ssti-percent-tag",description:"SSTI ERB/ASP tag: <%= expression %> — Ruby ERB, ASP",pattern:/<%=[\s\S]{0,80}%>/},{id:"log-null-byte",description:"Null byte: \\x00 or %00 — can truncate log entries in C-backed loggers",pattern:/\x00|%00/},{id:"log-ansi-escape",description:"ANSI escape sequence: ESC[ — can manipulate terminal output when logs are tailed",pattern:/\x1b\[/}],No=[...Mo,{id:"sql-line-comment",description:"SQL line comment: -- followed by whitespace or end of string",pattern:/--(?:\s|$)/},{id:"sql-stacked-query",description:"Stacked queries: semicolon immediately followed by a SQL keyword",pattern:/;\s{0,10}(?:SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER|EXEC)\b/i},{id:"sql-hex-encoding",description:"Hex-encoded string injection: 0x41414141 style (MySQL)",pattern:/\b0x[0-9a-f]{4,}/i}],ko=Object.freeze({colon:":",Tab:"\t",NewLine:"\n"}),Lo=/&(?:#[xX]0*([0-9a-fA-F]{1,6});?|#0*([0-9]{1,7});?|([a-zA-Z][a-zA-Z0-9]{1,15});)/g;wo.label="HTML",To.label="XML",So.label="SVG",wo.decodeEntities=!0,To.decodeEntities=!0,So.decodeEntities=!0,Mo.label="SQL",No.label="SQL-STRICT",Eo.label="SHELL",Co.label="REDOS",Ro.label="NOSQL",Po.label="LOG";Object.freeze({HTML:wo,XML:To,SVG:So,SQL:Mo,"SQL-STRICT":No,SHELL:Eo,REDOS:Co,NOSQL:Ro,LOG:Po});function Bo(e,t){if(!t.decodeEntities)return null;const n=-1===(r=e).indexOf("&")?r:r.replace(Lo,(e,t,n,r)=>{if(void 0!==r)return Object.prototype.hasOwnProperty.call(ko,r)?ko[r]:e;const i=void 0!==t?parseInt(t,16):parseInt(n,10);return!Number.isFinite(i)||i>1114111?e:String.fromCodePoint(i)});var r;return n===e?null:n}function Oo(e,t){const n=t.label??"CUSTOM",r=Bo(e,t);for(const i of t)if(i.pattern.test(e)||null!==r&&i.pattern.test(r))return{context:n,id:i.id,description:i.description,pattern:i.pattern};return null}function Fo(e,t){!function(e){if("string"!=typeof e)throw new TypeError("is-unsafe: first argument must be a string, got "+typeof e)}(e),function(e){if(!(e instanceof RegExp)){if(!Array.isArray(e))throw new TypeError("is-unsafe: second argument must be a PatternList (e.g. HTML), an array of PatternLists (e.g. [HTML, XML]), or a RegExp. Got: "+typeof e);if(0===e.length)throw new TypeError("is-unsafe: context must not be an empty array");if(Array.isArray(e[0]))for(const t of e)if(!Array.isArray(t)||0===t.length)throw new TypeError("is-unsafe: each context in the array must be a non-empty pattern array (PatternList)")}}(t);const{lists:n,regex:r}=function(e){return e instanceof RegExp?{lists:null,regex:e}:Array.isArray(e[0])?{lists:e,regex:null}:{lists:[e],regex:null}}(t);if(r)return r.test(e);for(const i of n)if(null!==Oo(e,i))return!0;return!1}function Do(e,t){if(!e)return{};const n=t.attributesGroupName?e[t.attributesGroupName]:e;if(!n)return{};const r={};for(const i in n)if(i.startsWith(t.attributeNamePrefix)){r[i.substring(t.attributeNamePrefix.length)]=n[i]}else r[i]=n[i];return r}function Uo(e){if(!e||"string"!=typeof e)return;const t=e.indexOf(":");if(-1!==t&&t>0){const n=e.substring(0,t);if("xmlns"!==n)return n}}var Vo=class{constructor(e,t){var n;this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.parseXml=qo,this.parseTextData=jo,this.resolveNameSpace=zo,this.buildAttributesMap=Ho,this.isItStopNode=$o,this.replaceEntitiesValue=Wo,this.readStopNodeData=eA,this.saveTextToParentTag=Jo,this.addChild=Ko,this.ignoreAttributesFn="function"==typeof(n=this.options.ignoreAttributes)?n:Array.isArray(n)?e=>{for(const t of n){if("string"==typeof t&&e===t)return!0;if(t instanceof RegExp&&t.test(e))return!0}}:()=>!1,this.entityExpansionCount=0,this.currentExpandedLength=0,this.doctypefound=!1;let r={...Rs};this.options.entityDecoder?this.entityDecoder=this.options.entityDecoder:("object"==typeof this.options.htmlEntities?r=this.options.htmlEntities:!0===this.options.htmlEntities&&(r={...Ps,...Is}),this.entityDecoder=new js({namedEntities:{...r,...t},numericAllowed:this.options.htmlEntities,limit:{maxTotalExpansions:this.options.processEntities.maxTotalExpansions,maxExpandedLength:this.options.processEntities.maxExpandedLength,applyLimitsTo:this.options.processEntities.appliesTo},onInputEntity:(e,t)=>Fo(t,[wo,To])?Ns.BLOCK:Ns.ALLOW})),this.matcher=new _o,this.readonlyMatcher=this.matcher.readOnly(),this.isCurrentNodeStopNode=!1,this.stopNodeExpressionsSet=new yo;const i=this.options.stopNodes;if(i&&i.length>0){for(let e=0;e<i.length;e++){const t=i[e];"string"==typeof t?this.stopNodeExpressionsSet.add(new vo(t)):t instanceof vo&&this.stopNodeExpressionsSet.add(t)}this.stopNodeExpressionsSet.seal()}}};function jo(e,t,n,r,i,a,s){const o=this.options;if(void 0!==e&&(o.trimValues&&!r&&(e=e.trim()),e.length>0)){s||(e=this.replaceEntitiesValue(e,t,n));const r=o.jPath?n.toString():n,A=o.tagValueProcessor(t,e,r,i,a);return null==A?e:typeof A!=typeof e||A!==e?A:o.trimValues||e.trim()===e?tA(e,o.parseTagValue,o.numberParseOptions):e}}function zo(e){if(this.options.removeNSPrefix){const t=e.split(":"),n="/"===e.charAt(0)?"/":"";if("xmlns"===t[0])return"";2===t.length&&(e=n+t[1])}return e}var Go=/* @__PURE__ */new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?","gm");function Ho(e,t,n,r=!1){const i=this.options;if(!0===r||!0!==i.ignoreAttributes&&"string"==typeof e){const r=function(e,t){const n=[];let r=t.exec(e);for(;r;){const i=[];i.startIndex=t.lastIndex-r[0].length;const a=r.length;for(let e=0;e<a;e++)i.push(r[e]);n.push(i),r=t.exec(e)}return n}(e,Go),a=r.length,s={},o=new Array(a);let A=!1;const l={};for(let e=0;e<a;e++){const t=this.resolveNameSpace(r[e][1]),a=r[e][4];if(t.length&&void 0!==a){let r=a;i.trimValues&&(r=r.trim()),r=this.replaceEntitiesValue(r,n,this.readonlyMatcher),o[e]=r,l[t]=r,A=!0}}A&&"object"==typeof t&&t.updateCurrent&&t.updateCurrent(l);const c=i.jPath?t.toString():this.readonlyMatcher;let u=!1;for(let e=0;e<a;e++){const t=this.resolveNameSpace(r[e][1]);if(this.ignoreAttributesFn(t,c))continue;let n=i.attributeNamePrefix+t;if(t.length)if(i.transformAttributeName&&(n=i.transformAttributeName(n)),n=rA(n,i),void 0!==r[e][4]){const r=o[e],a=i.attributeValueProcessor(t,r,c);s[n]=null==a?r:typeof a!=typeof r||a!==r?a:tA(r,i.parseAttributeValue,i.numberParseOptions),u=!0}else i.allowBooleanAttributes&&(s[n]=!0,u=!0)}if(!u)return;if(i.attributesGroupName&&!i.preserveOrder){const e={};return e[i.attributesGroupName]=s,e}return s}}var qo=function(e){const t=this.options,n=t.captureMetaData?[]:void 0;e=e.replace(/\r\n?/g,t.captureMetaData?(e,t)=>(2===e.length&&n.push(t-n.length),"\n"):"\n");const r=new Ws("!xml");let i=r,a="";this.matcher.reset(),this.entityDecoder.reset(),this.entityExpansionCount=0,this.currentExpandedLength=0,this.doctypefound=!1;const s=new ro(t.processEntities),o=e.length;for(let A=0;A<o;A++)if("<"===e[A]){const l=e.charCodeAt(A+1);if(47===l){const s=Xo(e,">",A,"Closing Tag is not closed.");let o=e.substring(A+2,s).trim();if(t.removeNSPrefix){const e=o.indexOf(":");-1!==e&&(o=o.substr(e+1))}o=nA(t.transformTagName,o,"",t).tagName,i&&(a=this.saveTextToParentTag(a,i,this.readonlyMatcher));const l=this.matcher.getCurrentTag();if(o&&t.unpairedTagsSet.has(o))throw new Error(`Unpaired tag can not be used as closing tag: </${o}>`);l&&t.unpairedTagsSet.has(l)&&(this.matcher.pop(),this.tagsNodeStack.pop()),this.matcher.pop(),this.isCurrentNodeStopNode=!1,i=this.tagsNodeStack.pop()||r,t.captureMetaData&&i&&i.addEndIndex(Qo(s+1,n)),a="",A=s}else if(63===l){let r=Zo(e,A,!1,"?>");if(!r)throw new Error("Pi Tag is not closed.");a=this.saveTextToParentTag(a,i,this.readonlyMatcher);const o=this.buildAttributesMap(r.tagExp,this.matcher,r.tagName,!0);if(o){const e=o[this.options.attributeNamePrefix+"version"];this.entityDecoder.setXmlVersion(Number(e)||1),s.setXmlVersion(Number(e)||1)}if(t.ignoreDeclaration&&"?xml"===r.tagName||t.ignorePiTags);else{const e=new Ws(r.tagName);e.add(t.textNodeName,""),r.tagName!==r.tagExp&&r.attrExpPresent&&!0!==t.ignoreAttributes&&(e[":@"]=o);const a=t.captureMetaData?Qo(A,n):A;this.addChild(i,e,this.readonlyMatcher,a),t.captureMetaData&&i.addEndIndex(Qo(r.closeIndex+2,n))}A=r.closeIndex+1}else if(33===l&&45===e.charCodeAt(A+2)&&45===e.charCodeAt(A+3)){const n=Xo(e,"--\x3e",A+4,"Comment is not closed.");if(t.commentPropName){const r=e.substring(A+4,n-2);a=this.saveTextToParentTag(a,i,this.readonlyMatcher),i.add(t.commentPropName,[{[t.textNodeName]:r}])}A=n}else if(33===l&&68===e.charCodeAt(A+2)){if(this.doctypefound)throw new Error("Multiple DOCTYPE declarations found.");this.doctypefound=!0;const t=s.readDocType(e,A);this.entityDecoder.addInputEntities(t.entities),A=t.i}else if(33===l&&91===e.charCodeAt(A+2)){const n=Xo(e,"]]>",A,"CDATA is not closed.")-2,r=e.substring(A+9,n);a=this.saveTextToParentTag(a,i,this.readonlyMatcher);let s=this.parseTextData(r,i.tagname,this.readonlyMatcher,!0,!1,!0,!0);null==s&&(s=""),t.cdataPropName?i.add(t.cdataPropName,[{[t.textNodeName]:r}]):i.add(t.textNodeName,s),A=n+2}else{let s=Zo(e,A,t.removeNSPrefix);if(!s){const t=e.substring(Math.max(0,A-50),Math.min(o,A+50));throw new Error(`readTagExp returned undefined at position ${A}. Context: "${t}"`)}let l=s.tagName;const c=s.rawTagName;let u=s.tagExp,f=s.attrExpPresent,d=s.closeIndex;if(({tagName:l,tagExp:u}=nA(t.transformTagName,l,u,t)),t.strictReservedNames&&(l===t.commentPropName||l===t.cdataPropName||l===t.textNodeName||l===t.attributesGroupName))throw new Error(`Invalid tag name: ${l}`);i&&a&&"!xml"!==i.tagname&&(a=this.saveTextToParentTag(a,i,this.readonlyMatcher,!1));const h=i;h&&t.unpairedTagsSet.has(h.tagname)&&(i=this.tagsNodeStack.pop(),this.matcher.pop());let p=!1;u.length>0&&u.lastIndexOf("/")===u.length-1&&(p=!0,"/"===l[l.length-1]?(l=l.substr(0,l.length-1),u=l):u=u.substr(0,u.length-1),f=l!==u);let m,g=null;m=Uo(c),l!==r.tagname&&this.matcher.push(l,{},m),l!==u&&f&&(g=this.buildAttributesMap(u,this.matcher,l),g&&Do(g,t)),l!==r.tagname&&(this.isCurrentNodeStopNode=this.isItStopNode());const b=t.captureMetaData?Qo(A,n):A;if(this.isCurrentNodeStopNode){let r="";if(p)A=s.closeIndex;else if(t.unpairedTagsSet.has(l))A=s.closeIndex;else{const t=this.readStopNodeData(e,c,d+1);if(!t)throw new Error(`Unexpected end of ${c}`);A=t.i,r=t.tagContent}const a=new Ws(l);g&&(a[":@"]=g),a.add(t.textNodeName,r),this.matcher.pop(),this.isCurrentNodeStopNode=!1,this.addChild(i,a,this.readonlyMatcher,b),t.captureMetaData&&i.addEndIndex(Qo(A+1,n))}else{if(p){({tagName:l,tagExp:u}=nA(t.transformTagName,l,u,t));const e=new Ws(l);g&&(e[":@"]=g),this.addChild(i,e,this.readonlyMatcher,b),t.captureMetaData&&i.addEndIndex(Qo(d+1,n)),this.matcher.pop(),this.isCurrentNodeStopNode=!1}else{if(t.unpairedTagsSet.has(l)){const e=new Ws(l);g&&(e[":@"]=g),this.addChild(i,e,this.readonlyMatcher,b),t.captureMetaData&&i.addEndIndex(Qo(s.closeIndex+1,n)),this.matcher.pop(),this.isCurrentNodeStopNode=!1,A=s.closeIndex;continue}{const e=new Ws(l);if(this.tagsNodeStack.length>t.maxNestedTags)throw new Error("Maximum nested tags exceeded");this.tagsNodeStack.push(i),g&&(e[":@"]=g),this.addChild(i,e,this.readonlyMatcher,b),i=e}}a="",A=d}}}else a+=e[A];return r.child};function Qo(e,t){let n=0,r=t.length;for(;n<r;){const i=Math.floor((n+r)/2);t[i]<e?n=i+1:r=i}return e+n}function Ko(e,t,n,r){this.options.captureMetaData||(r=void 0);const i=this.options.jPath?n.toString():n,a=this.options.updateTag(t.tagname,i,t[":@"]);!1===a||("string"==typeof a?(t.tagname=a,e.addChild(t,r)):e.addChild(t,r))}function Wo(e,t,n){const r=this.options.processEntities;if(!r||!r.enabled)return e;if(r.allowedTags){const i=this.options.jPath?n.toString():n;if(!(Array.isArray(r.allowedTags)?r.allowedTags.includes(t):r.allowedTags(t,i)))return e}if(r.tagFilter){const i=this.options.jPath?n.toString():n;if(!r.tagFilter(t,i))return e}return this.entityDecoder.decode(e)}function Jo(e,t,n,r){return e&&(void 0===r&&(r=0===t.child.length),void 0!==(e=this.parseTextData(e,t.tagname,n,!1,!!t[":@"]&&0!==Object.keys(t[":@"]).length,r))&&""!==e&&t.add(this.options.textNodeName,e),e=""),e}function $o(){return 0!==this.stopNodeExpressionsSet.size&&this.matcher.matchesAny(this.stopNodeExpressionsSet)}function Xo(e,t,n,r){const i=e.indexOf(t,n);if(-1===i)throw new Error(r);return i+t.length-1}function Yo(e,t,n,r){const i=e.indexOf(t,n);if(-1===i)throw new Error(r);return i}function Zo(e,t,n,r=">"){const i=function(e,t,n=">"){let r=0;const i=e.length,a=n.charCodeAt(0),s=n.length>1?n.charCodeAt(1):-1;let o="",A=t;for(let l=t;l<i;l++){const t=e.charCodeAt(l);if(r)t===r&&(r=0);else if(34===t||39===t)r=t;else if(t===a){if(-1===s)return o+=e.substring(A,l),{data:o,index:l};if(e.charCodeAt(l+1)===s)return o+=e.substring(A,l),{data:o,index:l}}else 9!==t||r||(o+=e.substring(A,l)+" ",A=l+1)}}(e,t+1,r);if(!i)return;let a=i.data;const s=i.index,o=a.search(/\s/);let A=a,l=!0;-1!==o&&(A=a.substring(0,o),a=a.substring(o+1).trimStart());const c=A;if(n){const e=A.indexOf(":");-1!==e&&(A=A.substr(e+1),l=A!==i.data.substr(e+1))}return{tagName:A,tagExp:a,closeIndex:s,attrExpPresent:l,rawTagName:c}}function eA(e,t,n){const r=n;let i=1,a=!1,s=-1;const o=e.length;for(;n<o;n++)if("<"===e[n]){const o=e.charCodeAt(n+1);if(47===o){const a=Yo(e,">",n,`${t} is not closed`);if(e.substring(n+2,a).trim()===t&&(i--,0===i))return{tagContent:e.substring(r,n),i:a};n=a}else if(63===o)n=Xo(e,"?>",n+1,"StopNode is not closed.");else if(33===o&&45===e.charCodeAt(n+2)&&45===e.charCodeAt(n+3))n=Xo(e,"--\x3e",n+3,"StopNode is not closed.");else if(33===o&&91===e.charCodeAt(n+2))n=Xo(e,"]]>",n,"StopNode is not closed.")-2;else{const r=a?void 0:Zo(e,n,!1);if(r)r.tagName===t&&"/"!==r.tagExp[r.tagExp.length-1]&&i++,n=r.closeIndex;else{if(a=!0,s<n&&(s=e.indexOf(">",n),-1===s))return;const r=e.indexOf("<",n+1);if(-1===r||r>s){const r=e.substring(n+1,s),a=r.search(/\s/);(-1===a?r:r.substring(0,a))===t&&"/"!==r[r.length-1]&&i++,n=s}}}}}function tA(e,t,n){if(t&&"string"==typeof e){const t=e.trim();return"true"===t||"false"!==t&&mo(e,n)}return function(e){return void 0!==e}(e)?e:""}function nA(e,t,n,r){if(e){const r=e(t);n===t&&(n=r),t=r}return{tagName:t=rA(t,r),tagExp:n}}function rA(e,t){if(hs.includes(e))throw new Error(`[SECURITY] Invalid name: "${e}" is a reserved JavaScript keyword that could cause prototype pollution`);return ds.includes(e)?t.onDangerousProperty(e):e}var iA=Ws.getMetaDataSymbol();function aA(e,t){if(!e||"object"!=typeof e)return{};if(!t)return e;const n={};for(const r in e)if(r.startsWith(t)){n[r.substring(t.length)]=e[r]}else n[r]=e[r];return n}function sA(e,t,n,r){return oA(e,t,n,r)}function oA(e,t,n,r){let i;const a={};for(let s=0;s<e.length;s++){const o=e[s],A=AA(o);if(void 0!==A&&A!==t.textNodeName){const e=aA(o[":@"]||{},t.attributeNamePrefix);n.push(A,e)}if(A===t.textNodeName)void 0===i?i=o[A]:i+=""+o[A];else{if(void 0===A)continue;if(o[A]){let e=oA(o[A],t,n,r);const i=cA(e,t);if(0===Object.keys(e).length&&t.alwaysCreateTextNode&&(e[t.textNodeName]=""),o[":@"]?lA(e,o[":@"],r,t):1!==Object.keys(e).length||void 0===e[t.textNodeName]||t.alwaysCreateTextNode?0===Object.keys(e).length&&(t.alwaysCreateTextNode?e[t.textNodeName]="":e=""):e=e[t.textNodeName],void 0!==o[iA]&&"object"==typeof e&&null!==e&&(e[iA]=o[iA]),void 0!==a[A]&&Object.prototype.hasOwnProperty.call(a,A))Array.isArray(a[A])||(a[A]=[a[A]]),a[A].push(e);else{const n=t.jPath?r.toString():r;t.isArray(A,n,i)?a[A]=[e]:a[A]=e}void 0!==A&&A!==t.textNodeName&&n.pop()}}}return"string"==typeof i?i.length>0&&(a[t.textNodeName]=i):void 0!==i&&(a[t.textNodeName]=i),a}function AA(e){const t=Object.keys(e);for(let n=0;n<t.length;n++){const e=t[n];if(":@"!==e)return e}}function lA(e,t,n,r){if(t){const i=Object.keys(t),a=i.length;for(let s=0;s<a;s++){const a=i[s],o=a.startsWith(r.attributeNamePrefix)?a.substring(r.attributeNamePrefix.length):a,A=r.jPath?n.toString()+"."+o:n;r.isArray(a,A,!0,!0)?e[a]=[t[a]]:e[a]=t[a]}}}function cA(e,t){const{textNodeName:n}=t,r=Object.keys(e).length;return 0===r||!(1!==r||!e[n]&&"boolean"!=typeof e[n]&&0!==e[n])}var uA=class{constructor(e){this.externalEntities={},this.options=Ks(e)}parse(e,t){if("string"!=typeof e&&e.toString)e=e instanceof Uint8Array&&("undefined"==typeof Buffer||!Buffer.isBuffer(e))?new TextDecoder("utf-8",{ignoreBOM:!0}).decode(e):e.toString();else if("string"!=typeof e)throw new Error("XML data is accepted in String or Bytes[] form.");if(t){!0===t&&(t={});const n=function(e,t){t=Object.assign({},ps,t);const n=[];let r=!1,i=!1;"\ufeff"===e[0]&&(e=e.substr(1));for(let a=0;a<e.length;a++)if("<"===e[a]&&"?"===e[a+1]){if(a+=2,a=gs(e,a),a.err)return a}else{if("<"!==e[a]){if(ms(e[a]))continue;return Ts("InvalidChar","char '"+e[a]+"' is not expected.",Es(e,a))}{let s=a;if(a++,"!"===e[a]){a=bs(e,a);continue}{let o=!1;"/"===e[a]&&(o=!0,a++);let A="";for(;a<e.length&&">"!==e[a]&&" "!==e[a]&&"\t"!==e[a]&&"\n"!==e[a]&&"\r"!==e[a];a++)A+=e[a];if(A=A.trim(),"/"===A[A.length-1]&&(A=A.substring(0,A.length-1),a--),!Ms(A)){let t;return t=0===A.trim().length?"Invalid space after '<'.":"Tag '"+A+"' is an invalid name.",Ts("InvalidTag",t,Es(e,a))}const l=xs(e,a);if(!1===l)return Ts("InvalidAttr","Attributes for '"+A+"' have open quote.",Es(e,a));let c=l.value;if(a=l.index,"/"===c[c.length-1]){const n=a-c.length;c=c.substring(0,c.length-1);const i=_s(c,t);if(!0!==i)return Ts(i.err.code,i.err.msg,Es(e,n+i.err.line));r=!0}else if(o){if(!l.tagClosed)return Ts("InvalidTag","Closing tag '"+A+"' doesn't have proper closing.",Es(e,a));if(c.trim().length>0)return Ts("InvalidTag","Closing tag '"+A+"' can't have attributes or invalid starting.",Es(e,s));if(0===n.length)return Ts("InvalidTag","Closing tag '"+A+"' has not been opened.",Es(e,s));{const t=n.pop();if(A!==t.tagName){let n=Es(e,t.tagStartPos);return Ts("InvalidTag","Expected closing tag '"+t.tagName+"' (opened in line "+n.line+", col "+n.col+") instead of closing tag '"+A+"'.",Es(e,s))}0==n.length&&(i=!0)}}else{const o=_s(c,t);if(!0!==o)return Ts(o.err.code,o.err.msg,Es(e,a-c.length+o.err.line));if(!0===i)return Ts("InvalidXml","Multiple possible root nodes found.",Es(e,a));-1!==t.unpairedTags.indexOf(A)||n.push({tagName:A,tagStartPos:s}),r=!0}for(a++;a<e.length;a++)if("<"===e[a]){if("!"===e[a+1]){a++,a=bs(e,a);continue}if("?"!==e[a+1])break;if(a=gs(e,++a),a.err)return a}else if("&"===e[a]){const t=ws(e,a);if(-1==t)return Ts("InvalidChar","char '&' is not expected.",Es(e,a));a=t}else if(!0===i&&!ms(e[a]))return Ts("InvalidXml","Extra text at the end",Es(e,a));"<"===e[a]&&a--}}}return r?1==n.length?Ts("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",Es(e,n[0].tagStartPos)):!(n.length>0)||Ts("InvalidXml","Invalid '"+JSON.stringify(n.map(e=>e.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1}):Ts("InvalidXml","Start tag expected.",1)}(e,t);if(!0!==n)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}const n=new Vo(this.options,this.externalEntities),r=n.parseXml(e);return this.options.preserveOrder||void 0===r?r:sA(r,this.options,n.matcher,n.readonlyMatcher)}addEntity(e,t){if(-1!==t.indexOf("&"))throw new Error("Entity value can't have '&'");if(-1!==e.indexOf("&")||-1!==e.indexOf(";"))throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if("&"===t)throw new Error("An entity with value '&' is not permitted");this.externalEntities[e]=t}static getMetaDataSymbol(){return Ws.getMetaDataSymbol()}};function fA(e,t){if(t?._parser&&"fast-xml-parser"!==t._parser)throw new Error(t?._parser);const n=function(e,t){return new uA({ignoreAttributes:!1,attributeNamePrefix:"",...t}).parse(e)}(e,{allowBooleanAttributes:!0,ignoreDeclaration:!0,removeNSPrefix:t?.removeNSPrefix,textNodeName:t?.textNodeName,isArray:(e,n,r,i)=>Boolean(t?.arrayPaths?.some(e=>n===e)),...t?._fastXML});return t?.uncapitalizeKeys?cs(n):n}var dA={dataType:null,batchType:null,name:"XML",id:"xml",module:"xml",version:"4.5.4",worker:!1,extensions:["xml"],mimeTypes:["application/xml","text/xml"],testText:function(e){return e.startsWith("<?xml")},options:{xml:{_parser:"fast-xml-parser",uncapitalizeKeys:!1,removeNSPrefix:!1,textNodeName:"value",arrayPaths:[]}},parse:async(e,t)=>fA((new TextDecoder).decode(e),{...dA.options.xml,...t?.xml}),parseTextSync:(e,t)=>fA(e,{...dA.options.xml,...t?.xml})};var hA={dataType:null,batchType:null,id:"wms-error",name:"WMS Error",module:"wms",version:"4.5.4",worker:!1,extensions:["xml"],mimeTypes:["application/vnd.ogc.se_xml","application/xml","text/xml"],testText:function(e){return e.startsWith("<?xml")},options:{wms:{throwOnError:!1}},parse:async(e,t)=>pA((new TextDecoder).decode(e),t),parseSync:(e,t)=>pA((new TextDecoder).decode(e),t),parseTextSync:(e,t)=>pA(e,t)};function pA(e,t){const n={...hA.options.wms,...t?.wms},r=function(e,t){const n=dA.parseTextSync?.(e,t),r=n?.ServiceExceptionReport?.ServiceException||n?.["ogc:ServiceExceptionReport"]?.["ogc:ServiceException"];return"string"==typeof r?r:r.value||r.code||"Unknown error"}(e,n),i=n.minimalErrors?r:`WMS Service error: ${r}`;if(n.throwOnError)throw new Error(i);return i}function mA(e){return Array.isArray(e)?e:e?[e]:[]}function gA(e){const t=mA(e);return t.length>0&&t.every(e=>"string"==typeof e)?t:[]}function bA(e,t=void 0){switch(typeof e){case"number":return e;case"string":return parseFloat(e);default:return}}function vA(e,t=void 0){switch(typeof e){case"number":return e;case"string":return parseInt(e,10);default:return}}function yA(e){switch(e){case"true":case"1":return!0;default:return!1}}function xA(e,t){const n=dA.parseTextSync?.(e,t),r=n.WMT_MS_Capabilities||n.WMS_Capabilities||n,i=function(e){const t={version:String(e.version||""),name:String(e.Service?.Name||"unnamed"),title:e.Service?.Title?String(e.Service?.Title):void 0,abstract:e.Service?.Abstract?String(e.Service?.Abstract):void 0,keywords:gA(e.Service?.KeywordList?.Keyword),fees:e.Service?.Fees?JSON.stringify(e.Service?.Fees):void 0,accessConstraints:e.Service?.AccessConstraints?JSON.stringify(e.Service?.AccessConstraints):void 0,layerLimit:vA(e.Service?.LayerLimit),maxWidth:vA(e.Service?.maxWidth),maxHeight:vA(e.Service?.maxHeight),layers:[],requests:_A(e.Capability?.Request),exceptions:wA(e.Exception)},n=mA(e.Capability?.Layer);for(const r of n)t.layers.push(TA(r));for(const[r,i]of Object.entries(t))void 0===i&&delete t[r];return t}(r);if(t?.inheritedLayerProps)for(const a of i.layers)SA(a,null);return t?.includeRawJSON&&(i.json=r),t?.includeXMLText&&(i.xml=e),i}function _A(e){const t={};for(const[n,r]of Object.entries(e||{}))t[n]={mimeTypes:gA(r?.Format)};return t}function wA(e){if(mA(e?.Format).length>0)return{mimeTypes:gA(e)}}function TA(e){const t={title:String(e?.Title||""),name:e?.Name&&String(e?.Name),abstract:e?.Name&&String(e?.Abstract),keywords:gA(e.KeywordList?.Keyword)},n=e?.CRS||e?.SRS;n&&Array.isArray(n)&&n.every(e=>"string"==typeof e)&&(t.crs=n);let r=e?.EX_GeographicBoundingBox&&function(e){const{westBoundLongitude:t,northBoundLatitude:n,eastBoundLongitude:r,southBoundLatitude:i}=e;return[[t,i],[r,n]]}(e?.EX_GeographicBoundingBox);r&&(t.geographicBoundingBox=r),r=e?.LatLonBoundingBox&&function(e){const{minx:t,miny:n,maxx:r,maxy:i}=e;return[[t,n],[r,i]]}(e?.LatLonBoundingBox),r&&(t.geographicBoundingBox=r);const i=e?.BoundingBox&&(a=e?.BoundingBox,mA(a).map(e=>function(e){const{CRS:t,SRS:n,minx:r,miny:i,maxx:a,maxy:s,resx:o,resy:A}=e,l={crs:t||n,boundingBox:[[bA(r),bA(i)],[bA(a),bA(s)]]};return o&&(l.xResolution=o),A&&(l.yResolution=A),l}(e)));var a;i&&i.length>0&&(t.boundingBoxes=i);const s=mA(e?.Dimension).map(e=>function(e){const{name:t,units:n,value:r}=e,i={name:t,units:n,extent:r};e.unitSymbol&&(i.unitSymbol=e.unitSymbol);e.default&&(i.defaultValue=e.default);e.multipleValues&&(i.multipleValues=yA(e.multipleValues));e.nearestValue&&(i.nearestValue=yA(e.nearestValue));e.current&&(i.current=yA(e.current));return i}(e));s.length&&(t.dimensions=s),e?.opaque&&(t.opaque=yA(e?.opaque)),e?.cascaded&&(t.cascaded=yA(e?.cascaded)),e?.queryable&&(t.queryable=yA(e?.queryable));const o=mA(e?.Layer),A=[];for(const l of o)A.push(TA(l));A.length>0&&(t.layers=A);for(const[l,c]of Object.entries(t))void 0===c&&delete t[l];return t}function SA(e,t){t?.geographicBoundingBox&&!e.geographicBoundingBox&&(e.geographicBoundingBox=[...t.geographicBoundingBox]),t?.crs&&!e.crs&&(e.crs=[...t.crs]),t?.boundingBoxes&&!e.boundingBoxes&&(e.boundingBoxes=[...t.boundingBoxes]),t?.dimensions&&!e.dimensions&&(e.dimensions=[...t.dimensions]);for(const n of e.layers||[])SA(n,e)}var MA={dataType:null,batchType:null,id:"wms-capabilities",name:"WMS Capabilities",module:"wms",version:"4.5.4",worker:!1,extensions:["xml"],mimeTypes:["application/vnd.ogc.wms_xml","application/xml","text/xml"],testText:function(e){return e.startsWith("<?xml")},options:{wms:{}},parse:async(e,t)=>xA((new TextDecoder).decode(e),t?.wms),parseTextSync:(e,t)=>xA(e,t?.wms)};function EA(e,t){const n=(dA.parseTextSync?.(e,t)).FeatureInfoResponse?.FIELDS||[];return{features:(Array.isArray(n)?n:[n]).map(e=>function(e){return{attributes:e||{},type:"",bounds:{bottom:0,top:0,left:0,right:0}}}(e))}}var CA={...MA,dataType:null,id:"wms-feature-info",name:"WMS FeatureInfo",parse:async(e,t)=>EA((new TextDecoder).decode(e),t),parseTextSync:(e,t)=>EA(e,t)};function IA(e,t){return dA.parseTextSync?.(e,t)}var RA={...MA,dataType:null,id:"wms-layer-description",name:"WMS DescribeLayer",parse:async(e,t)=>IA((new TextDecoder).decode(e),t),parseTextSync:(e,t)=>IA(e,t)},PA={name:"Web Map Service (OGC WMS)",id:"wms",module:"wms",version:"0.0.0",extensions:[],mimeTypes:[],type:"wms",fromUrl:!0,fromBlob:!1,defaultOptions:{wms:{}},testURL:e=>e.toLowerCase().includes("wms"),createDataSource:(e,t)=>new NA(e,t)},NA=class extends ct{substituteCRS84;flipCRS;wmsParameters;vendorParameters;capabilities=null;constructor(e,t){super(e,t,PA.defaultOptions),this.substituteCRS84=t.wms?.substituteCRS84??!1,this.flipCRS=["EPSG:4326"],this.wmsParameters={layers:void 0,query_layers:void 0,styles:void 0,version:"1.3.0",crs:"EPSG:4326",format:"image/png",info_format:"text/plain",transparent:void 0,time:void 0,elevation:void 0,...t.wmsParameters,...t.wms?.wmsParameters},this.vendorParameters=t.wms?.vendorParameters||t.vendorParameters||{}}async getMetadata(){const e=await this.getCapabilities();return this.normalizeMetadata(e)}async getImage(e){const{boundingBox:t,bbox:n,...r}=e,i={bbox:t?[...t[0],...t[1]]:n,...r};return await this.getMap(i)}normalizeMetadata(e){return e}async getCapabilities(e,t){const n=this.getCapabilitiesURL(e,t),r=await this.fetch(n),i=await r.arrayBuffer();this._checkResponse(r,i);const a=await MA.parse(i,this.loadOptions);return this.capabilities=a,a}async getMap(e,t){const n=this.getMapURL(e,t),r=await this.fetch(n),i=await r.arrayBuffer();this._checkResponse(r,i);try{return await Re.parse(i,this.loadOptions)}catch{throw this._parseError(i)}}async getFeatureInfo(e,t){const n=this.getFeatureInfoURL(e,t),r=await this.fetch(n),i=await r.arrayBuffer();return this._checkResponse(r,i),await CA.parse(i,this.loadOptions)}async getFeatureInfoText(e,t){const n=this.getFeatureInfoURL(e,t),r=await this.fetch(n),i=await r.arrayBuffer();return this._checkResponse(r,i),(new TextDecoder).decode(i)}async describeLayer(e,t){const n=this.describeLayerURL(e,t),r=await this.fetch(n),i=await r.arrayBuffer();return this._checkResponse(r,i),await RA.parse(i,this.loadOptions)}async getLegendGraphic(e,t){const n=this.getLegendGraphicURL(e,t),r=await this.fetch(n),i=await r.arrayBuffer();this._checkResponse(r,i);try{return await Re.parse(i,this.loadOptions)}catch{throw this._parseError(i)}}getCapabilitiesURL(e,t){const n={version:this.wmsParameters.version,...e};return this._getWMSUrl("GetCapabilities",n,t)}getMapURL(e,t){e=this._getWMS130Parameters(e);const n={version:this.wmsParameters.version,format:this.wmsParameters.format,transparent:this.wmsParameters.transparent,time:this.wmsParameters.time,elevation:this.wmsParameters.elevation,layers:this.wmsParameters.layers,styles:this.wmsParameters.styles,crs:this.wmsParameters.crs,...e};return this._getWMSUrl("GetMap",n,t)}getFeatureInfoURL(e,t){e=this._getWMS130Parameters(e);const{boundingBox:n,bbox:r}=e;e.bbox=n?[...n[0],...n[1]]:r;const i={version:this.wmsParameters.version,info_format:this.wmsParameters.info_format,layers:this.wmsParameters.layers,query_layers:this.wmsParameters.query_layers,styles:this.wmsParameters.styles,crs:this.wmsParameters.crs,...e};return this._getWMSUrl("GetFeatureInfo",i,t)}describeLayerURL(e,t){const n={version:this.wmsParameters.version,...e};return this._getWMSUrl("DescribeLayer",n,t)}getLegendGraphicURL(e,t){const n={version:this.wmsParameters.version,...e};return this._getWMSUrl("GetLegendGraphic",n,t)}_parseWMSUrl(e){const[t,n]=e.split("?"),r=n.split("&"),i={};for(const a of r){const[e,t]=a.split("=");i[e]=t}return{url:t,parameters:i}}_getWMSUrl(e,t,n){let r=this.url,i=!0;const a={service:"WMS",version:t.version,request:e,...t,...this.vendorParameters,...n},s=["transparent","time","elevation"];for(const[o,A]of Object.entries(a))s.includes(o)&&!A||(r+=i?"?":"&",i=!1,r+=this._getURLParameter(o,A,t));return encodeURI(r)}_getWMS130Parameters(e){const t={...e};return t.srs&&(t.crs=t.crs||t.srs,delete t.srs),t}_getURLParameter(e,t,n){switch(e){case"crs":"1.3.0"!==n.version?e="srs":this.substituteCRS84&&"EPSG:4326"===t&&(t="CRS:84");break;case"srs":"1.3.0"===n.version&&(e="crs");break;case"bbox":const r=this._flipBoundingBox(t,n);r&&(t=r);break;case"x":"1.3.0"===n.version&&(e="i");break;case"y":"1.3.0"===n.version&&(e="j")}return e=e.toUpperCase(),Array.isArray(t)?`${e}=${t.join(",")}`:`${e}=${t?String(t):""}`}_flipBoundingBox(e,t){if(!Array.isArray(e)||4!==e.length)return null;const n=e;return"1.3.0"===t.version&&this.flipCRS.includes(t.crs||"")&&!(this.substituteCRS84&&"EPSG:4326"===t.crs)?[n[1],n[0],n[3],n[2]]:n}async _fetchArrayBuffer(e){const t=await this.fetch(e),n=await t.arrayBuffer();return this._checkResponse(t,n),n}_checkResponse(e,t){const n=e.headers["content-type"];if(!e.ok||hA.mimeTypes.includes(n)){const e=$(this.loadOptions,{wms:{throwOnError:!0}}),n=hA.parseSync?.(t,e);throw new Error(n)}}_parseError(e){const t=hA.parseSync?.(e,this.options.core?.loadOptions);return new Error(t)}},kA=6378137*Math.PI;function LA(e){const t=R(e);return t[0]=(t[0]/256-1)*kA,t[1]=(t[1]/256-1)*kA,t}var BA={id:"imagery-layer",data:"",serviceType:"auto",srs:"auto",layers:{type:"array",compare:!0,value:[]},onMetadataLoad:{type:"function",value:()=>{}},onMetadataLoadError:{type:"function",value:console.error},onImageLoadStart:{type:"function",value:()=>{}},onImageLoad:{type:"function",value:()=>{}},onImageLoadError:{type:"function",compare:!1,value:(e,t)=>console.error(t,e)}},OA=class extends f{get isLoaded(){return 0===this.state?.loadCounter&&super.isLoaded}shouldUpdateState(){return!0}initializeState(){this.state._nextRequestId=0,this.state.lastRequestId=-1,this.state.loadCounter=0}updateState({changeFlags:e,props:t,oldProps:n}){const{viewport:r}=this.context;e.dataChanged||t.serviceType!==n.serviceType?(this.state.imageSource=this._createImageSource(t),this._loadMetadata(),this.debounce(()=>this.loadImage(r,"image source changed"),0)):be(t.layers,n.layers,1)?e.viewportChanged&&this.debounce(()=>this.loadImage(r,"viewport changed")):this.debounce(()=>this.loadImage(r,"layers changed"),0)}finalizeState(){}renderLayers(){const{bounds:e,image:t,lastRequestParameters:n}=this.state;return t&&new g({...this.getSubLayerProps({id:"bitmap"}),_imageCoordinateSystem:"EPSG:4326"===n.srs?L.LNGLAT:L.CARTESIAN,bounds:e,image:t})}async getFeatureInfoText(e,t){const{lastRequestParameters:n}=this.state;return n?await(this.state.imageSource.getFeatureInfoText?.({...n,query_layers:n.layers,x:e,y:t,info_format:"application/vnd.ogc.gml"})):""}_createImageSource(e){if(e.data instanceof ut)return e.data;if("string"==typeof e.data)return function(e,t,n){const r=n?.core?.type||n.type||"auto",i="auto"===r?function(e,t){for(const n of t)if(n.testURL&&n.testURL(e))return n;return null}(e,t):function(e,t){for(const n of t)if(n.type===e)return n;return null}(r,t);if(!i)throw new Error("Not a valid source type");return i.createDataSource(e,n)}(e.data,[PA],{core:{type:e.serviceType,loadOptions:e.loadOptions}});throw new Error("invalid image source in props.data")}async _loadMetadata(){const{imageSource:e}=this.state;try{this.state.loadCounter++;const t=await e.getMetadata();this.state.imageSource===e&&this.getCurrentLayer()?.props.onMetadataLoad(t)}catch(t){this.getCurrentLayer()?.props.onMetadataLoadError(t)}finally{this.state.loadCounter--}}async loadImage(e,t){const{layers:n,serviceType:r}=this.props;if("wms"===r&&0===n.length)return;const i=e.getBounds(),{width:a,height:s}=e,o=this.getRequestId();let{srs:A}=this.props;"auto"===A&&(A=e.resolution?"EPSG:4326":"EPSG:3857");const l={width:a,height:s,boundingBox:[[i[0],i[1]],[i[2],i[3]]],layers:n,crs:A};"EPSG:3857"===A&&(l.boundingBox=[LA([i[0],i[1]]),LA([i[2],i[3]])]);try{this.state.loadCounter++,this.props.onImageLoadStart(o);const e=await this.state.imageSource.getImage(l);this.state.lastRequestId<o&&(this.getCurrentLayer()?.props.onImageLoad(o),this.setState({image:e,bounds:i,lastRequestParameters:l,lastRequestId:o}))}catch(c){this.raiseError(c,"Load image"),this.getCurrentLayer()?.props.onImageLoadError(o,c)}finally{this.state.loadCounter--}}getRequestId(){return this.state._nextRequestId++}debounce(e,t=500){clearTimeout(this.state._timeoutId),this.state._timeoutId=setTimeout(()=>e(),t)}};OA.layerName="WMSLayer",OA.defaultProps=BA;var FA=class extends w{};FA.layerName="GreatCircleLayer",FA.defaultProps={getHeight:{type:"accessor",value:0},greatCircle:!0};var DA=/* @__PURE__ */r((e,t,r)=>{!function(e,r){"function"==typeof define&&define.amd?define([],r):"function"==typeof n&&"object"==typeof t&&t&&t.exports?t.exports=r():(e.dcodeIO=e.dcodeIO||{}).Long=r()}(r,function(){function e(e,t,n){this.low=0|e,this.high=0|t,this.unsigned=!!n}function t(e){return!0===(e&&e.__isLong__)}e.prototype.__isLong__,Object.defineProperty(e.prototype,"__isLong__",{value:!0,enumerable:!1,configurable:!1}),e.isLong=t;var n={},r={};function i(e,t){var i,a,o;return t?(o=0<=(e>>>=0)&&e<256)&&(a=r[e])?a:(i=s(e,(0|e)<0?-1:0,!0),o&&(r[e]=i),i):(o=-128<=(e|=0)&&e<128)&&(a=n[e])?a:(i=s(e,e<0?-1:0,!1),o&&(n[e]=i),i)}function a(e,t){if(isNaN(e)||!isFinite(e))return t?p:h;if(t){if(e<0)return p;if(e>=u)return y}else{if(e<=-f)return x;if(e+1>=f)return v}return e<0?a(-e,t).neg():s(e%c|0,e/c|0,t)}function s(t,n,r){return new e(t,n,r)}e.fromInt=i,e.fromNumber=a,e.fromBits=s;var o=Math.pow;function A(e,t,n){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return h;if("number"==typeof t?(n=t,t=!1):t=!!t,(n=n||10)<2||36<n)throw RangeError("radix");var r;if((r=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===r)return A(e.substring(1),t,n).neg();for(var i=a(o(n,8)),s=h,l=0;l<e.length;l+=8){var c=Math.min(8,e.length-l),u=parseInt(e.substring(l,l+c),n);if(c<8){var f=a(o(n,c));s=s.mul(f).add(a(u))}else s=(s=s.mul(i)).add(a(u))}return s.unsigned=t,s}function l(t){return t instanceof e?t:"number"==typeof t?a(t):"string"==typeof t?A(t):s(t.low,t.high,t.unsigned)}e.fromString=A,e.fromValue=l;var c=4294967296,u=c*c,f=u/2,d=i(1<<24),h=i(0);e.ZERO=h;var p=i(0,!0);e.UZERO=p;var m=i(1);e.ONE=m;var g=i(1,!0);e.UONE=g;var b=i(-1);e.NEG_ONE=b;var v=s(-1,2147483647,!1);e.MAX_VALUE=v;var y=s(-1,-1,!0);e.MAX_UNSIGNED_VALUE=y;var x=s(0,-2147483648,!1);e.MIN_VALUE=x;var _=e.prototype;return _.toInt=function(){return this.unsigned?this.low>>>0:this.low},_.toNumber=function(){return this.unsigned?(this.high>>>0)*c+(this.low>>>0):this.high*c+(this.low>>>0)},_.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(x)){var t=a(e),n=this.div(t),r=n.mul(t).sub(this);return n.toString(e)+r.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var i=a(o(e,6),this.unsigned),s=this,A="";;){var l=s.div(i),c=(s.sub(l.mul(i)).toInt()>>>0).toString(e);if((s=l).isZero())return c+A;for(;c.length<6;)c="0"+c;A=""+c+A}},_.getHighBits=function(){return this.high},_.getHighBitsUnsigned=function(){return this.high>>>0},_.getLowBits=function(){return this.low},_.getLowBitsUnsigned=function(){return this.low>>>0},_.getNumBitsAbs=function(){if(this.isNegative())return this.eq(x)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&!(e&1<<t);t--);return 0!=this.high?t+33:t+1},_.isZero=function(){return 0===this.high&&0===this.low},_.isNegative=function(){return!this.unsigned&&this.high<0},_.isPositive=function(){return this.unsigned||this.high>=0},_.isOdd=function(){return!(1&~this.low)},_.isEven=function(){return!(1&this.low)},_.equals=function(e){return t(e)||(e=l(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},_.eq=_.equals,_.notEquals=function(e){return!this.eq(e)},_.neq=_.notEquals,_.lessThan=function(e){return this.comp(e)<0},_.lt=_.lessThan,_.lessThanOrEqual=function(e){return this.comp(e)<=0},_.lte=_.lessThanOrEqual,_.greaterThan=function(e){return this.comp(e)>0},_.gt=_.greaterThan,_.greaterThanOrEqual=function(e){return this.comp(e)>=0},_.gte=_.greaterThanOrEqual,_.compare=function(e){if(t(e)||(e=l(e)),this.eq(e))return 0;var n=this.isNegative(),r=e.isNegative();return n&&!r?-1:!n&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},_.comp=_.compare,_.negate=function(){return!this.unsigned&&this.eq(x)?x:this.not().add(m)},_.neg=_.negate,_.add=function(e){t(e)||(e=l(e));var n=this.high>>>16,r=65535&this.high,i=this.low>>>16,a=65535&this.low,o=e.high>>>16,A=65535&e.high,c=e.low>>>16,u=0,f=0,d=0,h=0;return d+=(h+=a+(65535&e.low))>>>16,f+=(d+=i+c)>>>16,u+=(f+=r+A)>>>16,u+=n+o,s((d&=65535)<<16|(h&=65535),(u&=65535)<<16|(f&=65535),this.unsigned)},_.subtract=function(e){return t(e)||(e=l(e)),this.add(e.neg())},_.sub=_.subtract,_.multiply=function(e){if(this.isZero())return h;if(t(e)||(e=l(e)),e.isZero())return h;if(this.eq(x))return e.isOdd()?x:h;if(e.eq(x))return this.isOdd()?x:h;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(d)&&e.lt(d))return a(this.toNumber()*e.toNumber(),this.unsigned);var n=this.high>>>16,r=65535&this.high,i=this.low>>>16,o=65535&this.low,A=e.high>>>16,c=65535&e.high,u=e.low>>>16,f=65535&e.low,p=0,m=0,g=0,b=0;return g+=(b+=o*f)>>>16,m+=(g+=i*f)>>>16,g&=65535,m+=(g+=o*u)>>>16,p+=(m+=r*f)>>>16,m&=65535,p+=(m+=i*u)>>>16,m&=65535,p+=(m+=o*c)>>>16,p+=n*f+r*u+i*c+o*A,s((g&=65535)<<16|(b&=65535),(p&=65535)<<16|(m&=65535),this.unsigned)},_.mul=_.multiply,_.divide=function(e){if(t(e)||(e=l(e)),e.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?p:h;var n,r,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return p;if(e.gt(this.shru(1)))return g;i=p}else{if(this.eq(x))return e.eq(m)||e.eq(b)?x:e.eq(x)?m:(n=this.shr(1).div(e).shl(1)).eq(h)?e.isNegative()?m:b:(r=this.sub(e.mul(n)),i=n.add(r.div(e)));if(e.eq(x))return this.unsigned?p:h;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();i=h}for(r=this;r.gte(e);){n=Math.max(1,Math.floor(r.toNumber()/e.toNumber()));for(var s=Math.ceil(Math.log(n)/Math.LN2),A=s<=48?1:o(2,s-48),c=a(n),u=c.mul(e);u.isNegative()||u.gt(r);)u=(c=a(n-=A,this.unsigned)).mul(e);c.isZero()&&(c=m),i=i.add(c),r=r.sub(u)}return i},_.div=_.divide,_.modulo=function(e){return t(e)||(e=l(e)),this.sub(this.div(e).mul(e))},_.mod=_.modulo,_.not=function(){return s(~this.low,~this.high,this.unsigned)},_.and=function(e){return t(e)||(e=l(e)),s(this.low&e.low,this.high&e.high,this.unsigned)},_.or=function(e){return t(e)||(e=l(e)),s(this.low|e.low,this.high|e.high,this.unsigned)},_.xor=function(e){return t(e)||(e=l(e)),s(this.low^e.low,this.high^e.high,this.unsigned)},_.shiftLeft=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?s(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):s(0,this.low<<e-32,this.unsigned)},_.shl=_.shiftLeft,_.shiftRight=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?s(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):s(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},_.shr=_.shiftRight,_.shiftRightUnsigned=function(e){if(t(e)&&(e=e.toInt()),0===(e&=63))return this;var n=this.high;return e<32?s(this.low>>>e|n<<32-e,n>>>e,this.unsigned):s(32===e?n:n>>>e-32,0,this.unsigned)},_.shru=_.shiftRightUnsigned,_.toSigned=function(){return this.unsigned?s(this.low,this.high,!1):this},_.toUnsigned=function(){return this.unsigned?this:s(this.low,this.high,!0)},_.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},_.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255]},_.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24&255,e>>>16&255,e>>>8&255,255&e,t>>>24&255,t>>>16&255,t>>>8&255,255&t]},e})}),UA=/* @__PURE__ */e(DA(),1),VA=180/Math.PI;function jA(e,t,n){const r=1<<t;return[(e[0]+n[0])/r,(e[1]+n[1])/r]}function zA(e){return e>=.5?1/3*(4*e*e-1):1/3*(1-4*(1-e)*(1-e))}function GA(e){return[zA(e[0]),zA(e[1])]}function HA(e,[t,n]){switch(e){case 0:return[1,t,n];case 1:return[-t,1,n];case 2:return[-t,-n,1];case 3:return[-1,-n,-t];case 4:return[n,-1,-t];case 5:return[n,t,-1];default:throw new Error("Invalid face")}}function qA([e,t,n]){const r=Math.atan2(n,Math.sqrt(e*e+t*t));return[Math.atan2(t,e)*VA,r*VA]}function QA(e,t,n,r){if(0===r){1===n&&(t[0]=e-1-t[0],t[1]=e-1-t[1]);const r=t[0];t[0]=t[1],t[1]=r}}function KA(e){if("string"==typeof e){if(e.indexOf("/")>0)return e;e=function(e){const t=e.padEnd(16,"0");return UA.default.fromString(t,16)}(e)}return function(e){let t=UA.default.fromString(e,!0,10).toString(2);for(;t.length<64;)t="0"+t;const n=t.lastIndexOf("1"),r=t.substring(0,3),i=t.substring(3,n),a=i.length/2,s=UA.default.fromString(r,!0,2).toString(10);let o=UA.default.fromString(i,!0,2).toString(4);for(;o.length<a;)o="0"+o;return`${s}/${o}`}(e.toString())}function WA(e){return function({face:e,ij:t,level:n}){const r=[[0,0],[0,1],[1,1],[1,0],[0,0]],i=Math.max(1,Math.ceil(100*Math.pow(2,-n))),a=new Float64Array(4*i*2+2);let s=0,o=0;for(let A=0;A<4;A++){const l=r[A].slice(0),c=r[A+1],u=(c[0]-l[0])/i,f=(c[1]-l[1])/i;for(let r=0;r<i;r++){l[0]+=u,l[1]+=f;const r=qA(HA(e,GA(jA(t,n,l))));Math.abs(r[1])>89.999&&(r[0]=o);const i=r[0]-o;r[0]+=i>180?-360:i<-180?360:0,a[s++]=r[0],a[s++]=r[1],o=r[0]}}return a[s++]=a[0],a[s++]=a[1],a}(function(e){const t=e.split("/"),n=parseInt(t[0],10),r=t[1],i=r.length,a=[0,0];let s;for(let o=i-1;o>=0;o--){s=i-o;const e=r[o];let t=0,n=0;"1"===e?n=1:"2"===e?(t=1,n=1):"3"===e&&(t=1);const A=Math.pow(2,s-1);QA(A,a,t,n),a[0]+=A*t,a[1]+=A*n}if(n%2==1){const e=a[0];a[0]=a[1],a[1]=e}return{face:n,ij:a,level:s}}(KA(e)))}var JA=class extends Yn{indexToBounds(){const{data:e,getS2Token:t}=this.props;return{data:e,_normalize:!1,positionFormat:"XY",getPolygon:(e,n)=>WA(t(e,n))}}};JA.layerName="S2Layer",JA.defaultProps={getS2Token:{type:"accessor",value:e=>e.token}};function $A(e,t=1){const[n,r]=function(e,t){let n=0,r=0,i=1<<e.length;const a=i/512;for(let s=0;s<e.length;s++){i>>=1;const t=parseInt(e[s]);t%2&&(n|=i),t>1&&(r|=i)}return[[n/a,512-r/a],[(n+t)/a,512-(r+t)/a]]}(e,t),[i,a]=C(n),[s,o]=C(r);return[s,a,s,o,i,o,i,a,s,a]}var XA=class extends Yn{indexToBounds(){const{data:e,extruded:t,getQuadkey:n}=this.props,r=t?.99:1;return{data:e,_normalize:!1,positionFormat:"XY",getPolygon:(e,t)=>$A(n(e,t),r),updateTriggers:{getPolygon:r}}}};XA.layerName="QuadkeyLayer",XA.defaultProps={getQuadkey:{type:"accessor",value:e=>e.quadkey}};var YA=class{constructor(e){this.index=e,this.isVisible=!1,this.isSelected=!1,this.parent=null,this.children=[],this.content=null,this._loader=void 0,this._abortController=null,this._loaderId=0,this._isLoaded=!1,this._isCancelled=!1,this._needsReload=!1}get bbox(){return this._bbox}set bbox(e){this._bbox||(this._bbox=e,this.boundingBox="west"in e?[[e.west,e.south],[e.east,e.north]]:[[e.left,e.top],[e.right,e.bottom]])}get data(){return this.isLoading&&this._loader?this._loader.then(()=>this.data):this.content}get isLoaded(){return this._isLoaded&&!this._needsReload}get isLoading(){return Boolean(this._loader)&&!this._isCancelled}get needsReload(){return this._needsReload||this._isCancelled}get byteLength(){const e=this.content?this.content.byteLength:0;return Number.isFinite(e)||console.error("byteLength not defined in tile data"),e}async _loadData({getData:e,getRequestPriority:t,requestScheduler:n,onLoad:r,onError:i}){const{index:a,id:s,bbox:o,userData:A,zoom:l}=this,c=this._loaderId;this._abortController=new AbortController;const{signal:u}=this._abortController,f=await n.scheduleRequest(this,t);if(!f)return void(this._isCancelled=!0);if(this._isCancelled)return void f.done();let d,h=null;try{h=await e({index:a,id:s,bbox:o,userData:A,zoom:l,signal:u})}catch(p){d=p||!0}finally{f.done()}c===this._loaderId&&(this._loader=void 0,this.content=h,!this._isCancelled||h?(this._isLoaded=!0,this._isCancelled=!1,d?i(d,this):r(this)):this._isLoaded=!1)}loadData(e){return this._isLoaded=!1,this._isCancelled=!1,this._needsReload=!1,this._loaderId++,this._loader=this._loadData(e),this._loader}setNeedsReload(){this.isLoading&&(this.abort(),this._loader=void 0),this._needsReload=!0}abort(){this.isLoaded||(this._isCancelled=!0,this._abortController?.abort())}},ZA=-1,el=0,tl=1,nl=new de,rl=new de,il=class e{constructor(e=[0,0,0],t=[0,0,0],n){n=n||nl.copy(e).add(t).scale(.5),this.center=new de(n),this.halfDiagonal=new de(t).subtract(this.center),this.minimum=new de(e),this.maximum=new de(t)}clone(){return new e(this.minimum,this.maximum,this.center)}equals(e){return this===e||Boolean(e)&&this.minimum.equals(e.minimum)&&this.maximum.equals(e.maximum)}transform(e){return this.center.transformAsPoint(e),this.halfDiagonal.transform(e),this.minimum.transform(e),this.maximum.transform(e),this}intersectPlane(e){const{halfDiagonal:t}=this,n=rl.from(e.normal),r=t.x*Math.abs(n.x)+t.y*Math.abs(n.y)+t.z*Math.abs(n.z),i=this.center.dot(n)+e.distance;return i-r>0?tl:i+r<0?ZA:el}distanceTo(e){return Math.sqrt(this.distanceSquaredTo(e))}distanceSquaredTo(e){const t=nl.from(e).subtract(this.center),{halfDiagonal:n}=this;let r,i=0;return r=Math.abs(t.x)-n.x,r>0&&(i+=r*r),r=Math.abs(t.y)-n.y,r>0&&(i+=r*r),r=Math.abs(t.z)-n.z,r>0&&(i+=r*r),i}},al=new de,sl=new de,ol=class e{constructor(e=[0,0,0],t=0){this.radius=-0,this.center=new de,this.fromCenterRadius(e,t)}fromCenterRadius(e,t){return this.center.from(e),this.radius=t,this}fromCornerPoints(e,t){return t=al.from(t),this.center=(new de).from(e).add(t).scale(.5),this.radius=this.center.distance(t),this}equals(e){return this===e||Boolean(e)&&this.center.equals(e.center)&&this.radius===e.radius}clone(){return new e(this.center,this.radius)}union(e){const t=this.center,n=this.radius,r=e.center,i=e.radius,a=al.copy(r).subtract(t),s=a.magnitude();if(n>=s+i)return this.clone();if(i>=s+n)return e.clone();const o=.5*(n+s+i);return sl.copy(a).scale((-n+o)/s).add(t),this.center.copy(sl),this.radius=o,this}expand(e){const t=al.from(e).subtract(this.center).magnitude();return t>this.radius&&(this.radius=t),this}transform(e){this.center.transform(e);const t=re(al,e);return this.radius=Math.max(t[0],Math.max(t[1],t[2]))*this.radius,this}distanceSquaredTo(e){const t=this.distanceTo(e);return t*t}distanceTo(e){const t=al.from(e).subtract(this.center);return Math.max(0,t.len()-this.radius)}intersectPlane(e){const t=this.center,n=this.radius,r=e.normal.dot(t)+e.distance;return r<-n?ZA:r<n?el:tl}},Al=new de,ll=new de,cl=new de,ul=new de,fl=new de,dl=new de,hl=new de,pl=0,ml=1,gl=2,bl=3,vl=4,yl=5,xl=6,_l=7,wl=8,Tl=class e{constructor(e=[0,0,0],t=[0,0,0,0,0,0,0,0,0]){this.center=(new de).from(e),this.halfAxes=new Mt(t)}get halfSize(){const e=this.halfAxes.getColumn(0),t=this.halfAxes.getColumn(1),n=this.halfAxes.getColumn(2);return[new de(e).len(),new de(t).len(),new de(n).len()]}get quaternion(){const e=this.halfAxes.getColumn(0),t=this.halfAxes.getColumn(1),n=this.halfAxes.getColumn(2),r=new de(e).normalize(),i=new de(t).normalize(),a=new de(n).normalize();return(new Oe).fromMatrix3(new Mt([...r,...i,...a]))}fromCenterHalfSizeQuaternion(e,t,n){const r=new Oe(n),i=(new Mt).fromQuaternion(r);return i[0]=i[0]*t[0],i[1]=i[1]*t[0],i[2]=i[2]*t[0],i[3]=i[3]*t[1],i[4]=i[4]*t[1],i[5]=i[5]*t[1],i[6]=i[6]*t[2],i[7]=i[7]*t[2],i[8]=i[8]*t[2],this.center=(new de).from(e),this.halfAxes=i,this}clone(){return new e(this.center,this.halfAxes)}equals(e){return this===e||Boolean(e)&&this.center.equals(e.center)&&this.halfAxes.equals(e.halfAxes)}getBoundingSphere(e=new ol){const t=this.halfAxes,n=t.getColumn(0,cl),r=t.getColumn(1,ul),i=t.getColumn(2,fl),a=Al.copy(n).add(r).add(i);return e.center.copy(this.center),e.radius=a.magnitude(),e}intersectPlane(e){const t=this.center,n=e.normal,r=this.halfAxes,i=n.x,a=n.y,s=n.z,o=Math.abs(i*r[pl]+a*r[ml]+s*r[gl])+Math.abs(i*r[bl]+a*r[vl]+s*r[yl])+Math.abs(i*r[xl]+a*r[_l]+s*r[wl]),A=n.dot(t)+e.distance;return A<=-o?ZA:A>=o?tl:el}distanceTo(e){return Math.sqrt(this.distanceSquaredTo(e))}distanceSquaredTo(e){const t=ll.from(e).subtract(this.center),n=this.halfAxes,r=n.getColumn(0,cl),i=n.getColumn(1,ul),a=n.getColumn(2,fl),s=r.magnitude(),o=i.magnitude(),A=a.magnitude();r.normalize(),i.normalize(),a.normalize();let l,c=0;return l=Math.abs(t.dot(r))-s,l>0&&(c+=l*l),l=Math.abs(t.dot(i))-o,l>0&&(c+=l*l),l=Math.abs(t.dot(a))-A,l>0&&(c+=l*l),c}computePlaneDistances(e,t,n=[-0,-0]){let r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const a=this.center,s=this.halfAxes,o=s.getColumn(0,cl),A=s.getColumn(1,ul),l=s.getColumn(2,fl),c=dl.copy(o).add(A).add(l).add(a),u=hl.copy(c).subtract(e);let f=t.dot(u);return r=Math.min(f,r),i=Math.max(f,i),c.copy(a).add(o).add(A).subtract(l),u.copy(c).subtract(e),f=t.dot(u),r=Math.min(f,r),i=Math.max(f,i),c.copy(a).add(o).subtract(A).add(l),u.copy(c).subtract(e),f=t.dot(u),r=Math.min(f,r),i=Math.max(f,i),c.copy(a).add(o).subtract(A).subtract(l),u.copy(c).subtract(e),f=t.dot(u),r=Math.min(f,r),i=Math.max(f,i),a.copy(c).subtract(o).add(A).add(l),u.copy(c).subtract(e),f=t.dot(u),r=Math.min(f,r),i=Math.max(f,i),a.copy(c).subtract(o).add(A).subtract(l),u.copy(c).subtract(e),f=t.dot(u),r=Math.min(f,r),i=Math.max(f,i),a.copy(c).subtract(o).subtract(A).add(l),u.copy(c).subtract(e),f=t.dot(u),r=Math.min(f,r),i=Math.max(f,i),a.copy(c).subtract(o).subtract(A).subtract(l),u.copy(c).subtract(e),f=t.dot(u),r=Math.min(f,r),i=Math.max(f,i),n[0]=r,n[1]=i,n}transform(e){this.center.transformAsPoint(e);const t=this.halfAxes.getColumn(0,cl);t.transformAsPoint(e);const n=this.halfAxes.getColumn(1,ul);n.transformAsPoint(e);const r=this.halfAxes.getColumn(2,fl);return r.transformAsPoint(e),this.halfAxes=new Mt([...t,...n,...r]),this}getTransform(){throw new Error("not implemented")}},Sl=new de,Ml=new de,El=class e{constructor(e=[0,0,1],t=0){this.normal=new de,this.distance=-0,this.fromNormalDistance(e,t)}fromNormalDistance(e,t){return N(Number.isFinite(t)),this.normal.from(e).normalize(),this.distance=t,this}fromPointNormal(e,t){e=Sl.from(e),this.normal.from(t).normalize();const n=-this.normal.dot(e);return this.distance=n,this}fromCoefficients(e,t,n,r){return this.normal.set(e,t,n),N(D(this.normal.len(),1)),this.distance=r,this}clone(){return new e(this.normal,this.distance)}equals(e){return D(this.distance,e.distance)&&D(this.normal,e.normal)}getPointDistance(e){return this.normal.dot(e)+this.distance}transform(e){const t=Ml.copy(this.normal).transformAsVector(e).normalize(),n=this.normal.scale(-this.distance).transform(e);return this.fromPointNormal(n,t)}projectPointOntoPlane(e,t=[0,0,0]){const n=Sl.from(e),r=this.getPointDistance(n),i=Ml.copy(this.normal).scale(r);return n.subtract(i).to(t)}},Cl=[new de([1,0,0]),new de([0,1,0]),new de([0,0,1])],Il=new de,Rl=new de,Pl=class e{constructor(e=[]){this.planes=e}fromBoundingSphere(e){this.planes.length=2*Cl.length;const t=e.center,n=e.radius;let r=0;for(const i of Cl){let e=this.planes[r],a=this.planes[r+1];e||(e=this.planes[r]=new El),a||(a=this.planes[r+1]=new El);const s=Il.copy(i).scale(-n).add(t);e.fromPointNormal(s,i);const o=Il.copy(i).scale(n).add(t),A=Rl.copy(i).negate();a.fromPointNormal(o,A),r+=2}return this}computeVisibility(e){let t=tl;for(const n of this.planes)switch(e.intersectPlane(n)){case ZA:return ZA;case el:t=el}return t}computeVisibilityWithPlaneMask(t,n){if(N(Number.isFinite(n),"parentPlaneMask is required."),n===e.MASK_OUTSIDE||n===e.MASK_INSIDE)return n;let r=e.MASK_INSIDE;const i=this.planes;for(let a=0;a<this.planes.length;++a){const s=a<31?1<<a:0;if(a<31&&0===(n&s))continue;const o=i[a],A=t.intersectPlane(o);if(A===ZA)return e.MASK_OUTSIDE;A===el&&(r|=s)}return r}};Pl.MASK_OUTSIDE=4294967295,Pl.MASK_INSIDE=0,Pl.MASK_INDETERMINATE=2147483647;new de,new de,new de,new de,new de,new de,new de,new de,new de,new de,new de,new de,new de,new de,new de,new de,new de;var Nl=new Mt,kl=new Mt,Ll=new Mt,Bl=new Mt,Ol=new Mt;function Fl(e,t={}){let n=0,r=0;const i=kl,a=Ll;i.identity(),a.copy(e);const s=1e-20*function(e){let t=0;for(let n=0;n<9;++n){const r=e[n];t+=r*r}return Math.sqrt(t)}(a);for(;r<10&&Vl(a)>s;)jl(a,Bl),Ol.copy(Bl).transpose(),a.multiplyRight(Bl),a.multiplyLeft(Ol),i.multiplyRight(Bl),++n>2&&(++r,n=0);return t.unitary=i.toTarget(t.unitary),t.diagonal=a.toTarget(t.diagonal),t}var Dl=[1,0,0],Ul=[2,2,1];function Vl(e){let t=0;for(let n=0;n<3;++n){const r=e[Nl.getElementIndex(Ul[n],Dl[n])];t+=2*r*r}return Math.sqrt(t)}function jl(e,t){let n=0,r=1;for(let A=0;A<3;++A){const t=Math.abs(e[Nl.getElementIndex(Ul[A],Dl[A])]);t>n&&(r=A,n=t)}const i=Dl[r],a=Ul[r];let s=1,o=0;if(Math.abs(e[Nl.getElementIndex(a,i)])>1e-15){const t=(e[Nl.getElementIndex(a,a)]-e[Nl.getElementIndex(i,i)])/2/e[Nl.getElementIndex(a,i)];let n;n=t<0?-1/(-t+Math.sqrt(1+t*t)):1/(t+Math.sqrt(1+t*t)),s=1/Math.sqrt(1+n*n),o=n*s}return Mt.IDENTITY.to(t),t[Nl.getElementIndex(i,i)]=t[Nl.getElementIndex(a,a)]=s,t[Nl.getElementIndex(a,i)]=o,t[Nl.getElementIndex(i,a)]=-o,t}var zl=new de,Gl=new de,Hl=new de,ql=new de,Ql=new de,Kl=new Mt,Wl={diagonal:new Mt,unitary:new Mt};function Jl(e,t=new Tl){if(!e||0===e.length)return t.halfAxes=new Mt([0,0,0,0,0,0,0,0,0]),t.center=new de,t;const n=e.length,r=new de(0,0,0);for(const S of e)r.add(S);const i=1/n;r.multiplyByScalar(i);let a=0,s=0,o=0,A=0,l=0,c=0;for(const S of e){const e=zl.copy(S).subtract(r);a+=e.x*e.x,s+=e.x*e.y,o+=e.x*e.z,A+=e.y*e.y,l+=e.y*e.z,c+=e.z*e.z}a*=i,s*=i,o*=i,A*=i,l*=i,c*=i;const u=Kl;u[0]=a,u[1]=s,u[2]=o,u[3]=s,u[4]=A,u[5]=l,u[6]=o,u[7]=l,u[8]=c;const{unitary:f}=Fl(u,Wl),d=t.halfAxes.copy(f);let h=d.getColumn(0,Hl),p=d.getColumn(1,ql),m=d.getColumn(2,Ql),g=-Number.MAX_VALUE,b=-Number.MAX_VALUE,v=-Number.MAX_VALUE,y=Number.MAX_VALUE,x=Number.MAX_VALUE,_=Number.MAX_VALUE;for(const S of e)zl.copy(S),g=Math.max(zl.dot(h),g),b=Math.max(zl.dot(p),b),v=Math.max(zl.dot(m),v),y=Math.min(zl.dot(h),y),x=Math.min(zl.dot(p),x),_=Math.min(zl.dot(m),_);h=h.multiplyByScalar(.5*(y+g)),p=p.multiplyByScalar(.5*(x+b)),m=m.multiplyByScalar(.5*(_+v)),t.center.copy(h).add(p).add(m);const w=Gl.set(g-y,b-x,v-_).multiplyByScalar(.5),T=new Mt([w[0],0,0,0,w[1],0,0,0,w[2]]);return t.halfAxes.multiplyRight(T),t}var $l=512,Xl=[[.5,.5],[0,0],[0,1],[1,0],[1,1]],Yl=Xl.concat([[0,.5],[.5,0],[1,.5],[.5,1]]),Zl=Yl.concat([[.25,.5],[.75,.5]]),ec=class e{constructor(e,t,n){this.x=e,this.y=t,this.z=n}get children(){if(!this._children){const t=2*this.x,n=2*this.y,r=this.z+1;this._children=[new e(t,n,r),new e(t,n+1,r),new e(t+1,n,r),new e(t+1,n+1,r)]}return this._children}update(e){const{viewport:t,cullingVolume:n,elevationBounds:r,minZ:i,maxZ:a,bounds:s,offset:o,project:A}=e,l=this.getBoundingVolume(r,o,A);if(s&&!this.insideBounds(s))return!1;if(n.computeVisibility(l)<0)return!1;if(A&&this.beyondHorizon(t.cameraPosition,A,r[1]))return!1;if(!this.childVisible){let{z:e}=this;if(e<a&&e>=i){const n=l.distanceTo(t.cameraPosition)*t.scale/t.height;e+=Math.floor(Math.log2(n))}if(e>=a)return this.selected=!0,!0}this.selected=!1,this.childVisible=!0;for(const c of this.children)c.update(e);return!0}getSelected(e=[]){if(this.selected&&e.push(this),this._children)for(const t of this._children)t.getSelected(e);return e}beyondHorizon(e,t,n){const r=e[0],i=e[1],a=e[2],s=Math.sqrt(r*r+i*i+a*a),o=180*Math.atan2(r,-i)/Math.PI,A=180*Math.asin(a/s)/Math.PI,[l,c]=lc(this.x,this.y,this.z),[u,f]=lc(this.x+1,this.y+1,this.z),d=(l+u)/2,h=d+((o-d+540)%360-180),p=t([Math.max(l,Math.min(h,u)),Math.max(f,Math.min(A,c)),n]);return p[0]*r+p[1]*i+p[2]*a<=p[0]*p[0]+p[1]*p[1]+p[2]*p[2]}insideBounds([e,t,n,r]){const i=Math.pow(2,this.z),a=$l/i;return this.x*a<n&&this.y*a<r&&(this.x+1)*a>e&&(this.y+1)*a>t}getBoundingVolume(e,t,n){if(n){const t=this.z<1?Zl:this.z<2?Yl:Xl,r=[];for(const i of t){const t=lc(this.x+i[0],this.y+i[1],this.z);t[2]=e[0],r.push(n(t)),e[0]!==e[1]&&(t[2]=e[1],r.push(n(t)))}return Jl(r)}const r=Math.pow(2,this.z),i=$l/r,a=this.x*i+t*$l,s=$l-(this.y+1)*i;return new il([a,s,e[0]],[a+i,s+i,e[1]])}};var tc=512,nc=[-1/0,-1/0,1/0,1/0],rc={type:"object",value:null,validate:(e,t)=>t.optional&&null===e||"string"==typeof e||Array.isArray(e)&&e.every(e=>"string"==typeof e),equal:(e,t)=>{if(e===t)return!0;if(!Array.isArray(e)||!Array.isArray(t))return!1;const n=e.length;if(n!==t.length)return!1;for(let r=0;r<n;r++)if(e[r]!==t[r])return!1;return!0}};function ic(e,t){const n=[t.transformAsPoint([e[0],e[1]]),t.transformAsPoint([e[2],e[1]]),t.transformAsPoint([e[0],e[3]]),t.transformAsPoint([e[2],e[3]])];return[Math.min(...n.map(e=>e[0])),Math.min(...n.map(e=>e[1])),Math.max(...n.map(e=>e[0])),Math.max(...n.map(e=>e[1]))]}function ac(e,t){if(!e||!e.length)return null;const{index:n,id:r}=t;if(Array.isArray(e)){const t=(i=r,Math.abs(i.split("").reduce((e,t)=>(e<<5)-e+t.charCodeAt(0)|0,0))%e.length);e=e[t]}var i;let a=e;for(const s of Object.keys(n)){const e=new RegExp(`{${s}}`,"g");a=a.replace(e,String(n[s]))}return Number.isInteger(n.y)&&Number.isInteger(n.z)&&(a=a.replace(/\{-y\}/g,String(Math.pow(2,n.z)-n.y-1))),a}function sc({viewport:e,z:t,cullRect:n}){return(e.subViewports||[e]).map(e=>oc(e,t||0,n))}function oc(e,t,n){if(!Array.isArray(t)){const r=n.x-e.x,i=n.y-e.y,{width:a,height:s}=n,o={targetZ:t},A=e.unproject([r,i],o),l=e.unproject([r+a,i],o),c=e.unproject([r,i+s],o),u=e.unproject([r+a,i+s],o);return[Math.min(A[0],l[0],c[0],u[0]),Math.min(A[1],l[1],c[1],u[1]),Math.max(A[0],l[0],c[0],u[0]),Math.max(A[1],l[1],c[1],u[1])]}const r=oc(e,t[0],n),i=oc(e,t[1],n);return[Math.min(r[0],i[0]),Math.min(r[1],i[1]),Math.max(r[2],i[2]),Math.max(r[3],i[3])]}function Ac(e,t){return Math.pow(2,e)*tc/t}function lc(e,t,n){const r=Ac(n,tc),i=e/r*360-180,a=Math.PI-2*Math.PI*t/r;return[i,180/Math.PI*Math.atan(.5*(Math.exp(a)-Math.exp(-a)))]}function cc(e,t,n,r){const i=Ac(n,r);return[e/i*tc,t/i*tc]}function uc(e,t,n,r,i=tc){if(e.isGeospatial){const[e,i]=lc(t,n,r),[a,s]=lc(t+1,n+1,r);return{west:e,north:i,east:a,south:s}}const[a,s]=cc(t,n,r,i),[o,A]=cc(t+1,n+1,r,i);return{left:a,top:s,right:o,bottom:A}}function fc(e,t,n,r,i){const[a,s,o,A]=function(e,t,n){return n?ic(e,n).map(e=>e*t/tc):e.map(e=>e*t/tc)}(function(e,t,n){let r;if(t&&2===t.length){const[n,i]=t,a=e.getBounds({z:n}),s=e.getBounds({z:i});r=[Math.min(a[0],s[0]),Math.min(a[1],s[1]),Math.max(a[2],s[2]),Math.max(a[3],s[3])]}else r=e.getBounds();return e.isGeospatial?[Math.max(r[0],n[0]),Math.max(r[1],n[1]),Math.min(r[2],n[2]),Math.min(r[3],n[3])]:[Math.max(Math.min(r[0],n[2]),n[0]),Math.max(Math.min(r[1],n[3]),n[1]),Math.min(Math.max(r[2],n[0]),n[2]),Math.min(Math.max(r[3],n[1]),n[3])]}(e,null,r),Ac(t,n),i),l=[];for(let c=Math.floor(a);c<o;c++)for(let e=Math.floor(s);e<A;e++)l.push({x:c,y:e,z:t});return l}function dc({viewport:e,maxZoom:t,minZoom:n,zRange:r,extent:i,tileSize:a=tc,modelMatrix:s,modelMatrixInverse:o,zoomOffset:A=0,visibleMinZoom:l,visibleMaxZoom:c}){let u=e.isGeospatial?Math.round(e.zoom+Math.log2(tc/a)+A):Math.ceil(e.zoom+A);if("number"==typeof n&&Number.isFinite(n)&&u<n){if(!i)return[];u=n}if("number"==typeof t&&Number.isFinite(t)&&u>t&&(u=t),null!=l&&e.zoom<l)return[];if(null!=c&&e.zoom>c)return[];let f=i;return s&&o&&i&&!e.isGeospatial&&(f=ic(i,s)),e.isGeospatial?function(e,t,n,r){const i=e instanceof De?e.projectPosition:null,a=Object.values(e.getFrustumPlanes()).map(({normal:e,distance:t})=>new El(e.clone().negate(),t)),s=new Pl(a),o=e.distanceScales.unitsPerMeter[2],A=n&&n[0]*o||0,l=n&&n[1]*o||0,c=e instanceof J&&e.pitch<=60?t:0;if(r){const[e,t,n,i]=r,a=R([e,i]),s=R([n,t]);r=[a[0],$l-a[1],s[0],$l-s[1]]}const u=new ec(0,0,0),f={viewport:e,project:i,cullingVolume:s,elevationBounds:[A,l],minZ:c,maxZ:t,bounds:r,offset:0};if(u.update(f),e instanceof J&&e.subViewports&&e.subViewports.length>1){for(f.offset=-1;u.update(f)&&!(--f.offset<-3););for(f.offset=1;u.update(f)&&!(++f.offset>3););}return u.getSelected()}(e,u,r,i):fc(e,u,a,f||nc,o)}function hc(e,t){if(e===t)return!0;if(Array.isArray(e)){const n=e.length;if(!t||t.length!==n)return!1;for(let r=0;r<n;r++)if(e[r]!==t[r])return!1;return!0}return!1}var pc="never",mc="no-overlap",gc="best-available",bc=99999999,vc={[gc]:function(e){for(const t of e)t.state=0;for(const t of e)t.isSelected&&!_c(t)&&wc(t);for(const t of e)t.isVisible=Boolean(2&t.state)},[mc]:function(e){for(const n of e)n.state=0;for(const n of e)n.isSelected&&_c(n);const t=Array.from(e).sort((e,t)=>e.zoom-t.zoom);for(const n of t)if(n.isVisible=Boolean(2&n.state),n.children&&(n.isVisible||1&n.state))for(const e of n.children)e.state=1;else n.isSelected&&wc(n)},[pc]:()=>{}},yc={extent:null,tileSize:512,maxZoom:null,minZoom:null,maxCacheSize:null,maxCacheByteSize:null,refinementStrategy:"best-available",zRange:null,maxRequests:6,debounceTime:0,zoomOffset:0,visibleMinZoom:null,visibleMaxZoom:null,onTileLoad:()=>{},onTileUnload:()=>{},onTileError:()=>{}},xc=class{constructor(e){this._getCullBounds=function(e){let t,n={};return r=>{for(const i in r)if(!hc(r[i],n[i])){t=e(r),n=r;break}return t}}(sc),this.opts={...yc,...e},this.setOptions(this.opts),this.onTileLoad=e=>{this.opts.onTileLoad?.(e),null!==this.opts.maxCacheByteSize&&(this._cacheByteSize+=e.byteLength,this._resizeCache())},this._requestScheduler=new lt({throttleRequests:this.opts.maxRequests>0||this.opts.debounceTime>0,maxRequests:this.opts.maxRequests,debounceTime:this.opts.debounceTime}),this._cache=/* @__PURE__ */new Map,this._tiles=[],this._dirty=!1,this._cacheByteSize=0,this._viewport=null,this._zRange=null,this._selectedTiles=null,this._frameNumber=0,this._modelMatrix=new H,this._modelMatrixInverse=new H}get tiles(){return this._tiles}get selectedTiles(){return this._selectedTiles}get isLoaded(){return null!==this._selectedTiles&&this._selectedTiles.every(e=>e.isLoaded)}get needsReload(){return null!==this._selectedTiles&&this._selectedTiles.some(e=>e.needsReload)}setOptions(e){Object.assign(this.opts,e),Number.isFinite(e.maxZoom)&&(this._maxZoom=Math.floor(e.maxZoom)),Number.isFinite(e.minZoom)&&(this._minZoom=Math.ceil(e.minZoom)),this._viewport=null}finalize(){for(const e of this._cache.values())e.isLoading&&e.abort();this._cache.clear(),this._tiles=[],this._selectedTiles=null}reloadAll(){for(const e of this._cache.keys()){const t=this._cache.get(e);this._selectedTiles&&this._selectedTiles.includes(t)?t.setNeedsReload():this._cache.delete(e)}}update(e,{zRange:t,modelMatrix:n}={zRange:null,modelMatrix:null}){const r=n?new H(n):new H,i=!r.equals(this._modelMatrix);if(this._viewport&&e.equals(this._viewport)&&D(this._zRange,t)&&!i)this.needsReload&&(this._selectedTiles=this._selectedTiles.map(e=>this._getTile(e.index,!0)));else{i&&(this._modelMatrixInverse=r.clone().invert(),this._modelMatrix=r),this._viewport=e,this._zRange=t;const n=this.getTileIndices({viewport:e,maxZoom:this._maxZoom,minZoom:this._minZoom,zRange:t,modelMatrix:this._modelMatrix,modelMatrixInverse:this._modelMatrixInverse});this._selectedTiles=n.map(e=>this._getTile(e,!0)),this._dirty&&this._rebuildTree()}const a=this.updateTileStates();return this._pruneRequests(),this._dirty&&this._resizeCache(),a&&this._frameNumber++,this._frameNumber}isTileVisible(e,t,n){if(!e.isVisible)return!1;if(t&&this._viewport){const r=this._getCullBounds({viewport:this._viewport,z:this._zRange,cullRect:t});let{bbox:i}=e;for(const[e,t,a,s]of r){let r;if("west"in i)r=i.west<a&&i.east>e&&i.south<s&&i.north>t;else{if(n&&!H.IDENTITY.equals(n)){const[e,t,r,a]=ic([i.left,i.top,i.right,i.bottom],n);i={left:e,top:t,right:r,bottom:a}}const o=Math.min(i.top,i.bottom),A=Math.max(i.top,i.bottom);r=i.left<a&&i.right>e&&o<s&&A>t}if(r)return!0}return!1}return!0}getTileIndices({viewport:e,maxZoom:t,minZoom:n,zRange:r,modelMatrix:i,modelMatrixInverse:a}){const{tileSize:s,extent:o,zoomOffset:A,visibleMinZoom:l,visibleMaxZoom:c}=this.opts;return dc({viewport:e,maxZoom:t,minZoom:n,zRange:r,tileSize:s,extent:o,modelMatrix:i,modelMatrixInverse:a,zoomOffset:A,visibleMinZoom:l,visibleMaxZoom:c})}getTileId(e){return`${e.x}-${e.y}-${e.z}`}getTileZoom(e){return e.z}getTileMetadata(e){const{tileSize:t}=this.opts;return{bbox:uc(this._viewport,e.x,e.y,e.z,t)}}getParentIndex(e){return{x:Math.floor(e.x/2),y:Math.floor(e.y/2),z:e.z-1}}updateTileStates(){const e=this.opts.refinementStrategy||"best-available",t=new Array(this._cache.size);let n=0;for(const r of this._cache.values())t[n++]=r.isVisible,r.isSelected=!1,r.isVisible=!1;for(const r of this._selectedTiles)r.isSelected=!0,r.isVisible=!0;("function"==typeof e?e:vc[e])(Array.from(this._cache.values())),n=0;for(const r of this._cache.values())if(t[n++]!==r.isVisible)return!0;return!1}_getRequestPriority(e){if(!e.isSelected&&!e.isVisible)return-1;const t=this._getTileDistancePriority(e);return e.isSelected?0+t:1e8+t}_getTileDistancePriority(e){const{width:t,height:n}=this._viewport||{};if(!this._viewport||!t||!n)return 0;try{const r=this._getTileScreenCorners(e.bbox),i=[t/2,n/2];if(4===r.length){if(this._isPointInPolygon(i,r))return 0;const e=r.reduce((e,t,n)=>{const a=r[(n+1)%r.length];return Math.min(e,this._getPointToSegmentDistanceSquared(i,t,a))},Number.MAX_SAFE_INTEGER);return Math.min(e,bc)}}catch{}return bc}_getTileScreenCorners(e){return("west"in e?[[e.west,e.south],[e.east,e.south],[e.east,e.north],[e.west,e.north]]:[[e.left,e.top],[e.right,e.top],[e.right,e.bottom],[e.left,e.bottom]]).map(e=>this._viewport.project(e)).filter(([e,t])=>Number.isFinite(e)&&Number.isFinite(t))}_isPointInPolygon(e,t){let n=!1;const[r,i]=e;for(let a=0,s=t.length-1;a<t.length;s=a++){const[e,o]=t[a],[A,l]=t[s];o>i!=l>i&&r<(A-e)*(i-o)/(l-o)+e&&(n=!n)}return n}_getPointToSegmentDistanceSquared(e,t,n){const[r,i]=e,[a,s]=t,[o,A]=n,l=o-a,c=A-s,u=l*l+c*c,f=u?Math.max(0,Math.min(1,((r-a)*l+(i-s)*c)/u)):0,d=r-(a+f*l),h=i-(s+f*c);return d*d+h*h}_pruneRequests(){const{maxRequests:e=0}=this.opts,t=[];let n=0;for(const r of this._cache.values())r.isLoading&&(n++,r.isSelected||r.isVisible||t.push(r));for(;e>0&&n>e&&t.length>0;)t.shift().abort(),n--}_rebuildTree(){const{_cache:e}=this;for(const t of e.values())t.parent=null,t.children&&(t.children.length=0);for(const t of e.values()){const e=this._getNearestAncestor(t);t.parent=e,e?.children&&e.children.push(t)}}_resizeCache(){const{_cache:e,opts:t}=this,n=t.maxCacheSize??(null!==t.maxCacheByteSize?1/0:5*this.selectedTiles.length),r=t.maxCacheByteSize??1/0;if(e.size>n||this._cacheByteSize>r){for(const[i,a]of e)if(a.isVisible||a.isSelected||(this._cacheByteSize-=null!==t.maxCacheByteSize?a.byteLength:0,e.delete(i),this.opts.onTileUnload?.(a)),e.size<=n&&this._cacheByteSize<=r)break;this._rebuildTree(),this._dirty=!0}this._dirty&&(this._tiles=Array.from(this._cache.values()).sort((e,t)=>e.zoom-t.zoom),this._dirty=!1)}_getTile(e,t){const n=this.getTileId(e);let r=this._cache.get(n),i=!1;return!r&&t?(r=new YA(e),Object.assign(r,this.getTileMetadata(r.index)),Object.assign(r,{id:n,zoom:this.getTileZoom(r.index)}),i=!0,this._cache.set(n,r),this._dirty=!0):r&&r.needsReload&&(i=!0),r&&i&&r.loadData({getData:this.opts.getTileData,getRequestPriority:this._getRequestPriority.bind(this),requestScheduler:this._requestScheduler,onLoad:this.onTileLoad,onError:this.opts.onTileError}),r}_getNearestAncestor(e){const{_minZoom:t=0}=this;let n=e.index;for(;this.getTileZoom(n)>t;){n=this.getParentIndex(n);const e=this._getTile(n);if(e)return e}return null}};function _c(e){let t=e;for(;t;){if(t.isLoaded||t.content)return t.state|=2,!0;t=t.parent}return!1}function wc(e){for(const t of e.children)t.isLoaded||t.content?t.state|=2:wc(t)}var Tc={TilesetClass:xc,data:{type:"data",value:[]},dataComparator:rc.equal,renderSubLayers:{type:"function",value:e=>new b(e)},getTileData:{type:"function",optional:!0,value:null},onViewportLoad:{type:"function",optional:!0,value:null},onTileLoad:{type:"function",value:e=>{}},onTileUnload:{type:"function",value:e=>{}},onTileError:{type:"function",value:e=>console.error(e)},extent:{type:"array",optional:!0,value:null,compare:!0},tileSize:512,maxZoom:null,minZoom:0,maxCacheSize:null,maxCacheByteSize:null,refinementStrategy:gc,zRange:null,maxRequests:6,debounceTime:0,zoomOffset:0,visibleMinZoom:null,visibleMaxZoom:null},Sc=class extends f{initializeState(){this.state={tileset:null,isLoaded:!1}}finalizeState(){this.state?.tileset?.finalize()}get isLoaded(){return Boolean(this.state?.tileset?.selectedTiles?.every(e=>e.isLoaded&&(!e.content||!e.layers||e.layers.every(e=>e.isLoaded))))}shouldUpdateState({changeFlags:e}){return e.somethingChanged}updateState({changeFlags:e}){let{tileset:t}=this.state;const n=e.propsOrDataChanged||e.updateTriggersChanged,r=e.dataChanged||e.updateTriggersChanged&&(e.updateTriggersChanged.all||e.updateTriggersChanged.getTileData);t?n&&(t.setOptions(this._getTilesetOptions()),r?t.reloadAll():t.tiles.forEach(e=>{e.layers=null})):(t=new this.props.TilesetClass(this._getTilesetOptions()),this.setState({tileset:t})),this._updateTileset()}_getTilesetOptions(){const{tileSize:e,maxCacheSize:t,maxCacheByteSize:n,refinementStrategy:r,extent:i,maxZoom:a,minZoom:s,maxRequests:o,debounceTime:A,zoomOffset:l,visibleMinZoom:c,visibleMaxZoom:u}=this.props;return{maxCacheSize:t,maxCacheByteSize:n,maxZoom:a,minZoom:s,tileSize:e,refinementStrategy:r,extent:i,maxRequests:o,debounceTime:A,zoomOffset:l,visibleMinZoom:c,visibleMaxZoom:u,getTileData:this.getTileData.bind(this),onTileLoad:this._onTileLoad.bind(this),onTileError:this._onTileError.bind(this),onTileUnload:this._onTileUnload.bind(this)}}_updateTileset(){const e=this.state.tileset,{zRange:t,modelMatrix:n}=this.props,r=e.update(this.context.viewport,{zRange:t,modelMatrix:n}),{isLoaded:i}=e,a=this.state.isLoaded!==i,s=this.state.frameNumber!==r;i&&(a||s)&&this._onViewportLoad(),s&&this.setState({frameNumber:r}),this.state.isLoaded=i}_onViewportLoad(){const{tileset:e}=this.state,{onViewportLoad:t}=this.props;t&&t(e.selectedTiles)}_onTileLoad(e){this.props.onTileLoad(e),e.layers=null,this.setNeedsUpdate()}_onTileError(e,t){this.props.onTileError(e),t.layers=null,this.setNeedsUpdate()}_onTileUnload(e){this.props.onTileUnload(e)}getTileData(e){const{data:t,getTileData:n,fetch:r}=this.props,{signal:i}=e;return e.url="string"==typeof t||Array.isArray(t)?ac(t,e):null,n?n(e):r&&e.url?r(e.url,{propName:"data",layer:this,signal:i}):null}renderSubLayers(e){return this.props.renderSubLayers(e)}getSubLayerPropsByTile(e){return null}getPickingInfo(e){const t=e.sourceLayer,n=t.props.tile,r=e.info;return r.picked&&(r.tile=n),r.sourceTile=n,r.sourceTileSubLayer=t,r}_updateAutoHighlight(e){e.sourceTileSubLayer.updateAutoHighlight(e)}renderLayers(){const{visibleMinZoom:e,visibleMaxZoom:t,minZoom:n,extent:r}=this.props,i=this.context.viewport.zoom;if(null!=e&&i<e||null!=t&&i>t||null!=n&&!r&&i<n){for(const e of this.state.tileset.tiles)e.layers=null;return[]}return this.state.tileset.tiles.map(e=>{const t=this.getSubLayerPropsByTile(e);if(e.isLoaded||e.content)if(e.layers)t&&e.layers[0]&&Object.keys(t).some(n=>e.layers[0].props[n]!==t[n])&&(e.layers=e.layers.map(e=>e.clone(t)));else{const n=this.renderSubLayers({...this.props,...this.getSubLayerProps({id:e.id,updateTriggers:this.props.updateTriggers}),data:e.content,_offset:0,tile:e});e.layers=ce(n,Boolean).map(n=>n.clone({tile:e,...t}))}else;return e.layers})}filterSubLayer({layer:e,cullRect:t}){const{tile:n}=e.props,{modelMatrix:r}=this.props;return this.state.tileset.isTileVisible(n,t,r?new H(r):null)}};Sc.defaultProps=Tc,Sc.layerName="TileLayer";var Mc="layout(std140) uniform tripsUniforms {\n bool fadeTrail;\n float trailLength;\n float currentTime;\n} trips;\n",Ec={name:"trips",source:"struct TripsUniforms {\n fadeTrail: f32,\n trailLength: f32,\n currentTime: f32,\n};\n\n@group(0) @binding(auto)\nvar<uniform> trips: TripsUniforms;\n",vs:Mc,fs:Mc,uniformTypes:{fadeTrail:"f32",trailLength:"f32",currentTime:"f32"}};function Cc(e,t=e.length,n=!1){const r=new Float32Array(2*t);if(0===e.length)return r;const i=t>e.length,a=n?e.length:Math.max(e.length-1,1);for(let s=0;s<t;s++){const t=i?s%a:Math.min(s,e.length-1),n=i?(t+1)%a:Math.min(t+1,e.length-1);r[2*s]=e[t],r[2*s+1]=e[n]}return r}var Ic={" @location(12) rowIndexes: u32,":"\n @location(13) instanceTimestamps: vec2<f32>,"," @location(5) vJointType: f32,":"\n @location(6) vTime: f32,"," attributes.instanceColors.a * layer.opacity\n );":"\n\n varyings.vTime = mix(\n attributes.instanceTimestamps.x,\n attributes.instanceTimestamps.y,\n varyings.vPathPosition.y / varyings.vPathLength\n );\n\n if (trips.fadeTrail > 0.5) {\n varyings.vColor.a *=\n 1.0 - (trips.currentTime - varyings.vTime) / trips.trailLength;\n }"," // DECKGL_FILTER_COLOR":"\n if (\n varyings.vTime > trips.currentTime ||\n (trips.fadeTrail > 0.5 && varyings.vTime < trips.currentTime - trips.trailLength)\n ) {\n discard;\n }"},Rc={"vs:#decl":"in float instanceTimestamps;\nin float instanceNextTimestamps;\nout float vTime;\n","vs:#main-end":"vTime = instanceTimestamps + (instanceNextTimestamps - instanceTimestamps) * vPathPosition.y / vPathLength;\n","fs:#decl":"in float vTime;\n","fs:DECKGL_FILTER_COLOR":"if(vTime > trips.currentTime || (trips.fadeTrail && (vTime < trips.currentTime - trips.trailLength))) {\n discard;\n}\nif(trips.fadeTrail) {\n color.a *= 1.0 - (trips.currentTime - vTime) / trips.trailLength;\n}\n"},Pc=class extends m{getShaders(){const e=super.getShaders();return e.inject="webgpu"===this.context.device.type?Ic:Rc,e.modules=[...e.modules,Ec],e}initializeState(){super.initializeState(),this.getAttributeManager().addInstanced({..."webgpu"===this.context.device.type?{instanceTimestamps:{size:2,accessor:"getTimestamps",update:this.calculateWebGPUTimestamps,bufferGroup:"path-instance-data"}}:{timestamps:{size:1,accessor:"getTimestamps",shaderAttributes:{instanceTimestamps:{vertexOffset:0},instanceNextTimestamps:{vertexOffset:1}}}}})}calculateWebGPUTimestamps(e,{data:t,props:n}){const{pathTesselator:r}=this.state,{instanceCount:i,vertexStarts:a}=r,s=new Float32Array(2*i),{iterable:o,objectInfo:A}=y(t);for(const l of o){A.index++;const e=a[A.index],t=a[A.index+1]??i;if(t<=e)continue;const r=n.getTimestamps?.(l,A)??[];s.set(Cc(r,t-e,"loop"===n._pathType),2*e)}e.startIndices=a,e.value=s}draw(e){const{fadeTrail:t,trailLength:n,currentTime:r}=this.props,i={fadeTrail:t,trailLength:n,currentTime:r};this.state.model.shaderInputs.setProps({trips:i}),super.draw(e)}};Pc.layerName="TripsLayer",Pc.defaultProps={fadeTrail:!0,trailLength:{type:"number",value:120,min:0},currentTime:{type:"number",value:0,min:0},getTimestamps:{type:"accessor",value:e=>e.timestamps}};var Nc={...x.defaultProps,highPrecision:"auto",coverage:{type:"number",min:0,max:1,value:1},centerHexagon:null,getHexagon:{type:"accessor",value:e=>e.hexagon},extruded:!0},kc=class e extends f{initializeState(){e._checkH3Lib(),this.state={edgeLengthKM:0,resolution:-1}}shouldUpdateState({changeFlags:e}){return this._shouldUseHighPrecision()?e.propsOrDataChanged:e.somethingChanged}updateState({props:e,changeFlags:t}){if(!0!==e.highPrecision&&(t.dataChanged||t.updateTriggersChanged&&t.updateTriggersChanged.getHexagon)){const e=this._calculateH3DataProps();this.setState(e)}this._updateVertices(this.context.viewport)}_calculateH3DataProps(){let e=-1,t=!1,n=!1;const{iterable:r,objectInfo:i}=y(this.props.data);for(const a of r){i.index++;const r=this.props.getHexagon(a,i),s=$a(r);if(e<0){if(e=s,!this.props.highPrecision)break}else if(e!==s){n=!0;break}if(Ja(r)){t=!0;break}}return{resolution:e,edgeLengthKM:e>=0?ns(e,"km"):0,hasMultipleRes:n,hasPentagon:t}}_shouldUseHighPrecision(){if("auto"===this.props.highPrecision){const{resolution:e,hasPentagon:t,hasMultipleRes:n}=this.state,{viewport:r}=this.context;return Boolean(r?.resolution)||n||t||e>=0&&e<=5}return this.props.highPrecision}_updateVertices(e){if(this._shouldUseHighPrecision())return;const{resolution:t,edgeLengthKM:n,centerHex:r}=this.state;if(t<0)return;const i=this.props.centerHexagon||Xa(e.latitude,e.longitude,t);if(r===i)return;if(r)try{if(ts(r,i)*n<10)return}catch{}const{unitsPerMeter:a}=e.distanceScales;let s=ss(i);const[o,A]=Ya(i),[l,c]=e.projectFlat([A,o]);s=s.map(t=>{const n=e.projectFlat(t);return[(n[0]-l)/a[0],(n[1]-c)/a[1]]}),this.setState({centerHex:i,vertices:s})}renderLayers(){return this._shouldUseHighPrecision()?this._renderPolygonLayer():this._renderColumnLayer()}_getForwardProps(){const{elevationScale:e,material:t,coverage:n,extruded:r,wireframe:i,stroked:a,filled:s,lineWidthUnits:o,lineWidthScale:A,lineWidthMinPixels:l,lineWidthMaxPixels:c,getFillColor:u,getElevation:f,getLineColor:d,getLineWidth:h,transitions:p,updateTriggers:m}=this.props;return{elevationScale:e,extruded:r,coverage:n,wireframe:i,stroked:a,filled:s,lineWidthUnits:o,lineWidthScale:A,lineWidthMinPixels:l,lineWidthMaxPixels:c,material:t,getElevation:f,getFillColor:u,getLineColor:d,getLineWidth:h,transitions:p,updateTriggers:{getFillColor:m.getFillColor,getElevation:m.getElevation,getLineColor:m.getLineColor,getLineWidth:m.getLineWidth}}}_renderPolygonLayer(){const{data:e,getHexagon:t,updateTriggers:n,coverage:r}=this.props,i=this.getSubLayerClass("hexagon-cell-hifi",x),a=this._getForwardProps();return a.updateTriggers.getPolygon=function(e,t){let n;return n=null==e?t:"object"==typeof e?{...e,coverage:t}:{getHexagon:e,coverage:t},n}(n.getHexagon,r),new i(a,this.getSubLayerProps({id:"hexagon-cell-hifi",updateTriggers:a.updateTriggers}),{data:e,_normalize:!1,_windingOrder:"CCW",positionFormat:"XY",getPolygon:(e,n)=>os(ss(t(e,n),r))})}_renderColumnLayer(){const{data:e,getHexagon:t,updateTriggers:n}=this.props,r=this.getSubLayerClass("hexagon-cell",l),i=this._getForwardProps();return i.updateTriggers.getPosition=n.getHexagon,new r(i,this.getSubLayerProps({id:"hexagon-cell",flatShading:!0,updateTriggers:i.updateTriggers}),{data:e,diskResolution:6,radius:1,vertices:this.state.vertices,getPosition:as.bind(null,t)})}};kc.defaultProps=Nc,kc.layerName="H3HexagonLayer",kc._checkH3Lib=()=>{};var Lc=class extends Yn{initializeState(){kc._checkH3Lib()}updateState({props:e,changeFlags:t}){if(t.dataChanged||t.updateTriggersChanged&&t.updateTriggersChanged.getHexagons){const{data:t,getHexagons:n}=e,r=[],{iterable:i,objectInfo:a}=y(t);for(const e of i){a.index++;const t=es(n(e,a),!0);for(const n of t){for(const e of n)is(e);r.push(this.getSubLayerRow({polygon:n},e,a.index))}}this.setState({polygons:r})}}indexToBounds(){const{getElevation:e,getFillColor:t,getLineColor:n,getLineWidth:r}=this.props;return{data:this.state.polygons,getPolygon:e=>e.polygon,getElevation:this.getSubLayerAccessor(e),getFillColor:this.getSubLayerAccessor(t),getLineColor:this.getSubLayerAccessor(n),getLineWidth:this.getSubLayerAccessor(r)}}};Lc.layerName="H3ClusterLayer",Lc.defaultProps={getHexagons:{type:"accessor",value:e=>e.hexagons}};var Bc=Math.PI/180,Oc=/* @__PURE__ */new Float32Array(16),Fc=/* @__PURE__ */new Float32Array(12);function Dc(e,t,n){const r=t[0]*Bc,i=t[1]*Bc,a=t[2]*Bc,s=Math.sin(a),o=Math.sin(r),A=Math.sin(i),l=Math.cos(a),c=Math.cos(r),u=Math.cos(i),f=n[0],d=n[1],h=n[2];e[0]=f*u*c,e[1]=f*A*c,e[2]=f*-o,e[3]=d*(-A*l+u*o*s),e[4]=d*(u*l+A*o*s),e[5]=d*c*s,e[6]=h*(A*s+u*o*l),e[7]=h*(-u*s+A*o*l),e[8]=h*c*l}function Uc(e){return e[0]=e[0],e[1]=e[1],e[2]=e[2],e[3]=e[4],e[4]=e[5],e[5]=e[6],e[6]=e[8],e[7]=e[9],e[8]=e[10],e[9]=e[12],e[10]=e[13],e[11]=e[14],e.subarray(0,12)}var Vc={size:12,accessor:["getOrientation","getScale","getTranslation","getTransformMatrix"],shaderAttributes:{instanceModelMatrixCol0:{size:3,elementOffset:0},instanceModelMatrixCol1:{size:3,elementOffset:3},instanceModelMatrixCol2:{size:3,elementOffset:6},instanceTranslation:{size:3,elementOffset:9}},update(e,{startRow:t,endRow:n}){const{data:r,getOrientation:i,getScale:a,getTranslation:s,getTransformMatrix:o}=this.props,A=Array.isArray(o),l=A&&16===o.length,c=Array.isArray(a),u=Array.isArray(i),f=Array.isArray(s),d=l||!A&&Boolean(o(r[0]));e.constant=d?l:u&&c&&f;const h=e.value;if(e.constant){let t;d?(Oc.set(o),t=Uc(Oc)):(t=Fc,Dc(t,i,a),t.set(s,9)),e.value=new Float32Array(t)}else{let A=t*e.size;const{iterable:p,objectInfo:m}=y(r,t,n);for(const e of p){let t;if(m.index++,d)Oc.set(l?o:o(e,m)),t=Uc(Oc);else{t=Fc;Dc(t,u?i:i(e,m),c?a:a(e,m)),t.set(f?s:s(e,m),9)}h[A++]=t[0],h[A++]=t[1],h[A++]=t[2],h[A++]=t[3],h[A++]=t[4],h[A++]=t[5],h[A++]=t[6],h[A++]=t[7],h[A++]=t[8],h[A++]=t[9],h[A++]=t[10],h[A++]=t[11]}}}};function jc(e,t){return"cartesian"===t||"meter-offsets"===t||"default"===t&&!e.isGeospatial}var zc="layout(std140) uniform simpleMeshUniforms {\n float sizeScale;\n bool composeModelMatrix;\n bool hasTexture;\n bool flatShading;\n} simpleMesh;\n",Gc={name:"simpleMesh",source:"struct SimpleMeshUniforms {\n sizeScale: f32,\n composeModelMatrix: f32,\n hasTexture: f32,\n flatShading: f32,\n};\n\n@group(0) @binding(auto) var<uniform> simpleMesh: SimpleMeshUniforms;\n@group(0) @binding(auto) var simpleMeshTexture: texture_2d<f32>;\n@group(0) @binding(auto) var simpleMeshTextureSampler: sampler;\n",vs:zc,fs:zc,uniformTypes:{sizeScale:"f32",composeModelMatrix:"f32",hasTexture:"f32",flatShading:"f32"}};function Hc(e){const t=e.positions||e.POSITION;ge.assert(t,'no "postions" or "POSITION" attribute in mesh');const n=t.value.length/t.size;let r=e.COLOR_0||e.colors;r||(r={size:3,value:new Float32Array(3*n).fill(1)});let i=e.NORMAL||e.normals;i||(i={size:3,value:new Float32Array(3*n).fill(0)});let a=e.TEXCOORD_0||e.texCoords;return a||(a={size:2,value:new Float32Array(2*n).fill(0)}),{positions:t,colors:r,normals:i,texCoords:a}}function qc(e){return e instanceof E?(e.attributes=Hc(e.attributes),e):e.attributes?new E({...e,topology:"triangle-list",attributes:Hc(e.attributes)}):new E({topology:"triangle-list",attributes:Hc(e)})}var Qc=class extends d{getShaders(){return super.getShaders({vs:"#version 300 es\n#define SHADER_NAME simple-mesh-layer-vs\nin vec3 positions;\nin vec3 normals;\nin vec3 colors;\nin vec2 texCoords;\nin vec3 instancePositions;\nin vec3 instancePositions64Low;\nin vec4 instanceColors;\nin vec3 instanceModelMatrixCol0;\nin vec3 instanceModelMatrixCol1;\nin vec3 instanceModelMatrixCol2;\nin vec3 instanceTranslation;\nout vec2 vTexCoord;\nout vec3 cameraPosition;\nout vec3 normals_commonspace;\nout vec4 position_commonspace;\nout vec4 vColor;\nvoid main(void) {\ngeometry.worldPosition = instancePositions;\ngeometry.uv = texCoords;\ngeometry.pickingColor = picking_getPickingColorFromInstanceID();\nvTexCoord = texCoords;\ncameraPosition = project.cameraPosition;\nvColor = vec4(colors * instanceColors.rgb, instanceColors.a);\nmat3 instanceModelMatrix = mat3(instanceModelMatrixCol0, instanceModelMatrixCol1, instanceModelMatrixCol2);\nvec3 pos = (instanceModelMatrix * positions) * simpleMesh.sizeScale + instanceTranslation;\nif (simpleMesh.composeModelMatrix) {\nDECKGL_FILTER_SIZE(pos, geometry);\nnormals_commonspace = project_normal(instanceModelMatrix * normals);\ngeometry.worldPosition += pos;\ngl_Position = project_position_to_clipspace(pos + instancePositions, instancePositions64Low, vec3(0.0), position_commonspace);\ngeometry.position = position_commonspace;\n}\nelse {\npos = project_size(pos);\nDECKGL_FILTER_SIZE(pos, geometry);\ngl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, pos, position_commonspace);\ngeometry.position = position_commonspace;\nnormals_commonspace = project_normal(instanceModelMatrix * normals);\n}\ngeometry.normal = normals_commonspace;\nDECKGL_FILTER_GL_POSITION(gl_Position, geometry);\nDECKGL_FILTER_COLOR(vColor, geometry);\n}\n",fs:"#version 300 es\n#define SHADER_NAME simple-mesh-layer-fs\nprecision highp float;\nuniform sampler2D sampler;\nin vec2 vTexCoord;\nin vec3 cameraPosition;\nin vec3 normals_commonspace;\nin vec4 position_commonspace;\nin vec4 vColor;\nout vec4 fragColor;\nvoid main(void) {\ngeometry.uv = vTexCoord;\nvec3 normal;\nif (simpleMesh.flatShading) {\nnormal = normalize(cross(dFdx(position_commonspace.xyz), dFdy(position_commonspace.xyz)));\n} else {\nnormal = normals_commonspace;\n}\nvec4 color = simpleMesh.hasTexture ? texture(sampler, vTexCoord) : vColor;\nDECKGL_FILTER_COLOR(color, geometry);\nvec3 lightColor = lighting_getLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal);\nfragColor = vec4(lightColor, color.a * layer.opacity);\n}\n",source:"struct Attributes {\n @builtin(instance_index) instanceIndex: u32,\n @location(0) positions: vec3<f32>,\n @location(1) normals: vec3<f32>,\n @location(2) colors: vec3<f32>,\n @location(3) texCoords: vec2<f32>,\n @location(4) instancePositions: vec3<f32>,\n @location(5) instancePositions64Low: vec3<f32>,\n @location(6) instanceColors: vec4<f32>,\n @location(7) instanceModelMatrixCol0: vec3<f32>,\n @location(8) instanceModelMatrixCol1: vec3<f32>,\n @location(9) instanceModelMatrixCol2: vec3<f32>,\n @location(10) instanceTranslation: vec3<f32>,\n};\n\nstruct Varyings {\n @builtin(position) position: vec4<f32>,\n @location(0) color: vec4<f32>,\n @location(1) texCoords: vec2<f32>,\n @location(2) normal: vec3<f32>,\n @location(3) positionCommon: vec3<f32>,\n @location(4) pickingColor: vec3<f32>,\n};\n\n@vertex\nfn vertexMain(attributes: Attributes) -> Varyings {\n var varyings: Varyings;\n\n geometry.worldPosition = attributes.instancePositions;\n geometry.uv = attributes.texCoords;\n geometry.pickingColor = picking_getPickingColorFromIndex(attributes.instanceIndex);\n\n let instanceModelMatrix = mat3x3<f32>(\n attributes.instanceModelMatrixCol0,\n attributes.instanceModelMatrixCol1,\n attributes.instanceModelMatrixCol2\n );\n let meshPosition =\n (instanceModelMatrix * attributes.positions) * simpleMesh.sizeScale +\n attributes.instanceTranslation;\n\n if (simpleMesh.composeModelMatrix > 0.5) {\n geometry.normal = project_normal(instanceModelMatrix * attributes.normals);\n geometry.worldPosition += meshPosition;\n let projected = project_position_to_clipspace_and_commonspace(\n attributes.instancePositions + meshPosition,\n attributes.instancePositions64Low,\n vec3<f32>(0.0)\n );\n geometry.position = projected.commonPosition;\n varyings.position = projected.clipPosition;\n } else {\n let projected = project_position_to_clipspace_and_commonspace(\n attributes.instancePositions,\n attributes.instancePositions64Low,\n project_size_vec3(meshPosition)\n );\n geometry.position = projected.commonPosition;\n geometry.normal = project_normal(instanceModelMatrix * attributes.normals);\n varyings.position = projected.clipPosition;\n }\n\n varyings.color = vec4<f32>(\n attributes.colors * attributes.instanceColors.rgb,\n attributes.instanceColors.a\n );\n varyings.texCoords = attributes.texCoords;\n varyings.normal = geometry.normal;\n varyings.positionCommon = geometry.position.xyz;\n varyings.pickingColor = geometry.pickingColor;\n return varyings;\n}\n\n@fragment\nfn fragmentMain(varyings: Varyings) -> @location(0) vec4<f32> {\n geometry.uv = varyings.texCoords;\n\n if (picking.isActive > 0.5) {\n if (!picking_isColorValid(varyings.pickingColor)) {\n discard;\n }\n return vec4<f32>(varyings.pickingColor, 1.0);\n }\n\n var color = varyings.color;\n if (simpleMesh.hasTexture > 0.5) {\n color = textureSample(simpleMeshTexture, simpleMeshTextureSampler, varyings.texCoords);\n }\n\n var normal = varyings.normal;\n if (simpleMesh.flatShading > 0.5) {\n // WebGPU's screen-space Y axis reverses the derivative orientation used by GLSL flat shading.\n normal = normalize(cross(dpdy(varyings.positionCommon), dpdx(varyings.positionCommon)));\n }\n\n color = vec4<f32>(\n lighting_getLightColor2(color.rgb, project.cameraPosition, varyings.positionCommon, normal),\n color.a * layer.opacity\n );\n\n if (picking.isHighlightActive > 0.5) {\n let highlightedColor = picking_normalizeColor(picking.highlightedObjectColor);\n if (picking_isColorZero(abs(varyings.pickingColor - highlightedColor))) {\n let blendedAlpha = picking.highlightColor.a + color.a * (1.0 - picking.highlightColor.a);\n if (blendedAlpha > 0.0) {\n color = vec4<f32>(\n mix(color.rgb, picking.highlightColor.rgb, picking.highlightColor.a / blendedAlpha),\n blendedAlpha\n );\n }\n }\n }\n\n return deckgl_premultiplied_alpha(color);\n}\n",modules:[M,s,i,c,Gc]})}getBounds(){if(this.props._instanced)return super.getBounds();let e=this.state.positionBounds;if(e)return e;const{mesh:t}=this.props;if(!t)return null;if(e=t.header?.boundingBox,!e){const{attributes:n}=qc(t);n.POSITION=n.POSITION||n.positions,e=function(e){let t=1/0,n=1/0,r=1/0,i=-1/0,a=-1/0,s=-1/0;const o=e.POSITION?e.POSITION.value:[],A=o&&o.length;for(let l=0;l<A;l+=3){const e=o[l],A=o[l+1],c=o[l+2];t=e<t?e:t,n=A<n?A:n,r=c<r?c:r,i=e>i?e:i,a=A>a?A:a,s=c>s?c:s}return[[t,n,r],[i,a,s]]}(n)}return this.state.positionBounds=e,e}initializeState(){this.getAttributeManager().addInstanced({instancePositions:{transition:!0,type:"float64",fp64:this.use64bitPositions(),size:3,accessor:"getPosition"},instanceColors:{type:"unorm8",transition:!0,size:this.props.colorFormat.length,accessor:"getColor",defaultValue:[0,0,0,255]},instanceModelMatrix:Vc}),this.setState({emptyTexture:this.context.device.createTexture({data:/* @__PURE__ */new Uint8Array(4),width:1,height:1})})}updateState(e){super.updateState(e);const{props:t,oldProps:n,changeFlags:r}=e;if(t.mesh!==n.mesh||r.extensionsChanged){if(this.state.positionBounds=null,this.state.model?.destroy(),t.mesh){this.state.model=this.getModel(t.mesh);const e=t.mesh.attributes||t.mesh;this.setState({hasNormals:Boolean(e.NORMAL||e.normals)})}this.getAttributeManager().invalidateAll()}t.texture!==n.texture&&t.texture instanceof G&&this.setTexture(t.texture),this.state.model&&this.state.model.setTopology(this.props.wireframe?"line-strip":"triangle-list")}finalizeState(e){super.finalizeState(e),this.state.emptyTexture.delete()}draw({uniforms:e}){const{model:t}=this.state;if(!t)return;const{viewport:n,renderPass:r}=this.context,{sizeScale:i,coordinateSystem:a,_instanced:s}=this.props,o={sizeScale:i,composeModelMatrix:!s||jc(n,a),flatShading:!this.state.hasNormals};t.shaderInputs.setProps({simpleMesh:o}),t.draw(r)}get isLoaded(){return Boolean(this.state?.model&&super.isLoaded)}getModel(e){const t=new p(this.context.device,{...this.getShaders(),id:this.props.id,bufferLayout:this.getAttributeManager().getBufferLayouts(),geometry:qc(e),isInstanced:!0});return t.shaderInputs.setProps({simpleMesh:this.getTextureProps(this.props.texture)}),t}setTexture(e){const{model:t}=this.state;t&&t.shaderInputs.setProps({simpleMesh:this.getTextureProps(e)})}getTextureProps(e){const t=e||this.state.emptyTexture;return{..."webgpu"===this.context.device.type?{simpleMeshTexture:t}:{sampler:t},hasTexture:Boolean(e)}}};Qc.defaultProps={mesh:{type:"object",value:null,async:!0},texture:{type:"image",value:null,async:!0},sizeScale:{type:"number",value:1,min:0},_instanced:!0,wireframe:!1,material:!0,getPosition:{type:"accessor",value:e=>e.position},getColor:{type:"accessor",value:[0,0,0,255]},getOrientation:{type:"accessor",value:[0,0,0]},getScale:{type:"accessor",value:[1,1,1]},getTranslation:{type:"accessor",value:[0,0,0]},getTransformMatrix:{type:"accessor",value:[]},textureParameters:{type:"object",ignore:!0,value:null}},Qc.layerName="SimpleMeshLayer";var Kc;function Wc(e,t){const n=t.materialFactory||new Jt(e,{modules:[kt]}),r={...t.parsedPPBRMaterial.uniforms};delete r.camera;const i=Object.fromEntries(Object.entries({...r,...t.parsedPPBRMaterial.bindings}).filter(([e,t])=>n.ownsBinding(e)&&function(e){return e instanceof Xe||e instanceof hn||e instanceof q||e instanceof G||e instanceof Ye}(t))),a=n.createMaterial({id:t.id,bindings:i});return a.setProps({pbrMaterial:r}),a}function Jc(e,t){const{id:n,geometry:r,parsedPPBRMaterial:i,vertexCount:a,modelOptions:s={},instanceMatrices:o,morphTargets:A=[]}=t,l=s.userData?.gltfAnimatedCrowd;if(l&&o)throw new Error("Nested glTF crowd instancing is unsupported");$e.info(4,"createGLTFModel defines: ",i.defines)();const c=[],u={},f=[],d=[],h=[],m=Boolean(l?.gpuAnimation);if(o||l)for(let p=0;p<4;p++){const t=new Float32Array(4*(l?.capacity||o?.length||0));o?.forEach((e,n)=>{for(let r=0;r<4;r++)t[4*n+r]=e[4*p+r]});const r=`instanceModelMatrixCol${p}`,i=e.createBuffer({id:`${n||"gltf"}-${r}`,data:t,usage:Xe.VERTEX|Xe.COPY_DST});u[r]=i,f.push({name:r,format:"float32x4",stepMode:"instance"}),c.push(i),d.push(i),h.push(t)}let g,b,v,y;if(l&&m){g=new Float32Array(4*l.capacity),v=new Float32Array(4*l.capacity);for(const[t,r]of[["instanceAnimationFrames",g],["instanceAnimationBlend",v]]){const i=e.createBuffer({id:`${n||"gltf"}-${t}`,data:r,usage:Xe.VERTEX|Xe.COPY_DST});u[t]=i,f.push({name:t,format:"float32x4",stepMode:"instance"}),c.push(i),"instanceAnimationFrames"===t?b=i:y=i}}const x=Boolean(i.defines.HAS_SKIN),_=Boolean(l&&x&&!m);let w,T;l&&_&&(T=new Float32Array(l.capacity*l.jointsPerInstance*16),w="webgpu"===e.type?e.createBuffer({id:`${n||"gltf"}-crowd-joint-matrices`,byteLength:T.byteLength,usage:Xe.STORAGE|Xe.COPY_DST}):e.createTexture({id:`${n||"gltf"}-crowd-joint-matrices`,format:"rgba32float",width:4*l.jointsPerInstance,height:l.capacity,usage:G.SAMPLE|G.COPY_DST,sampler:{minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}}),c.push(w));const S=l?A.length:0,M=Math.floor((r.attributes.POSITION?.value.length||0)/3);let E,C,I;if(l&&S>0&&M>0){const t=new Float32Array(3*S*M*4);for(const[e,n]of A.entries())for(const[r,i]of["POSITION","NORMAL","TANGENT"].entries()){const a=n[i];if(!a)continue;const s="TANGENT"===i&&a.length===4*M?4:3;for(let n=0;n<M;n++){const i=4*((3*e+r)*M+n),o=n*s;t[i]=a[o]||0,t[i+1]=a[o+1]||0,t[i+2]=a[o+2]||0}}if(E=$c(e,`${n||"gltf"}-crowd-morph-targets`,t,M,3*S),c.push(E),!m){const t=Math.ceil(S/4);C=new Float32Array(l.capacity*t*4),I=$c(e,`${n||"gltf"}-crowd-morph-weights`,C,t,l.capacity),c.push(I)}}const R=x&&l?l.jointsPerInstance:0,P=4+4*R+S;let N,k;l?.gpuAnimation&&(k=new Float32Array(l.gpuAnimation.frameCount*P*4),N=$c(e,`${n||"gltf"}-crowd-animation-frames`,k,P,l.gpuAnimation.frameCount),c.push(N));let L="\nstruct VertexInputs {\n @location(0) positions: vec3f,\n#ifdef HAS_NORMALS\n @location(1) normals: vec3f,\n#endif\n#ifdef HAS_TANGENTS\n @location(2) TANGENT: vec4f,\n#endif\n#ifdef HAS_UV\n @location(3) texCoords: vec2f,\n#endif\n#ifdef HAS_UV_1\n @location(4) texCoords1: vec2f,\n#endif\n#ifdef HAS_SKIN\n @location(5) JOINTS_0: vec4u,\n @location(6) WEIGHTS_0: vec4f,\n#endif\n#ifdef HAS_GLTF_INSTANCING\n @location(8) instanceModelMatrixCol0: vec4f,\n @location(9) instanceModelMatrixCol1: vec4f,\n @location(10) instanceModelMatrixCol2: vec4f,\n @location(11) instanceModelMatrixCol3: vec4f,\n @builtin(instance_index) instanceIndex: u32,\n#endif\n#ifdef HAS_GPU_CROWD_ANIMATION\n @location(12) instanceAnimationFrames: vec4f,\n @location(13) instanceAnimationBlend: vec4f,\n#endif\n#ifdef HAS_INSTANCED_MORPH\n @builtin(vertex_index) vertexIndex: u32,\n#endif\n};\n\nstruct FragmentInputs {\n @builtin(position) position: vec4f,\n @location(0) pbrPosition: vec3f,\n @location(1) pbrUV0: vec2f,\n @location(2) pbrUV1: vec2f,\n @location(3) pbrNormal: vec3f,\n#ifdef HAS_TANGENTS\n @location(4) pbrTangent: vec4f,\n#endif\n};\n\n#ifdef HAS_GLTF_INSTANCING\nfn getGLTFInstanceNormalMatrix(matrix: mat3x3f) -> mat3x3f {\n let firstCofactor = cross(matrix[1], matrix[2]);\n let inverseDeterminant = 1.0 / dot(matrix[0], firstCofactor);\n return mat3x3f(\n firstCofactor,\n cross(matrix[2], matrix[0]),\n cross(matrix[0], matrix[1])\n ) * inverseDeterminant;\n}\n#endif\n\n@vertex\nfn vertexMain(inputs: VertexInputs) -> FragmentInputs {\n var outputs: FragmentInputs;\n var position = vec4f(inputs.positions, 1.0);\n var normal = vec3f(0.0, 0.0, 1.0);\n var tangent = vec4f(1.0, 0.0, 0.0, 1.0);\n var uv0 = vec2f(0.0, 0.0);\n var uv1 = vec2f(0.0, 0.0);\n\n#ifdef HAS_NORMALS\n normal = inputs.normals;\n#endif\n#ifdef HAS_UV\n uv0 = inputs.texCoords;\n#endif\n#ifdef HAS_UV_1\n uv1 = inputs.texCoords1;\n#endif\n#ifdef HAS_TANGENTS\n tangent = inputs.TANGENT;\n#endif\n\n#ifdef HAS_INSTANCED_MORPH\n var animationFrames = vec4f(0.0);\n var animationBlend = vec4f(0.0);\n#ifdef HAS_GPU_CROWD_ANIMATION\n animationFrames = inputs.instanceAnimationFrames;\n animationBlend = inputs.instanceAnimationBlend;\n#endif\n position = vec4f(\n position.xyz + getGPUCrowdMorphDelta(\n inputs.instanceIndex,\n inputs.vertexIndex,\n 0u,\n u32(CROWD_MORPH_VERTEX_COUNT),\n u32(CROWD_MORPH_TARGET_COUNT),\n u32(CROWD_ANIMATION_JOINT_COUNT),\n animationFrames,\n animationBlend,\n u32(CROWD_ANIMATION_FRAME_STRIDE)\n ),\n 1.0\n );\n#ifdef HAS_NORMALS\n normal = normalize(normal + getGPUCrowdMorphDelta(\n inputs.instanceIndex,\n inputs.vertexIndex,\n 1u,\n u32(CROWD_MORPH_VERTEX_COUNT),\n u32(CROWD_MORPH_TARGET_COUNT),\n u32(CROWD_ANIMATION_JOINT_COUNT),\n animationFrames,\n animationBlend,\n u32(CROWD_ANIMATION_FRAME_STRIDE)\n ));\n#endif\n#ifdef HAS_TANGENTS\n tangent = vec4f(normalize(tangent.xyz + getGPUCrowdMorphDelta(\n inputs.instanceIndex,\n inputs.vertexIndex,\n 2u,\n u32(CROWD_MORPH_VERTEX_COUNT),\n u32(CROWD_MORPH_TARGET_COUNT),\n u32(CROWD_ANIMATION_JOINT_COUNT),\n animationFrames,\n animationBlend,\n u32(CROWD_ANIMATION_FRAME_STRIDE)\n )), tangent.w);\n#endif\n#endif\n\n#ifdef HAS_SKIN\n#ifdef HAS_GPU_CROWD_ANIMATION\n let skinMatrix = getGPUAnimatedSkinMatrix(\n inputs.WEIGHTS_0,\n inputs.JOINTS_0,\n inputs.instanceAnimationFrames,\n inputs.instanceAnimationBlend,\n u32(CROWD_ANIMATION_FRAME_STRIDE)\n );\n#else\n#ifdef HAS_INSTANCED_SKIN\n let skinMatrix = getInstancedSkinMatrix(\n inputs.WEIGHTS_0,\n inputs.JOINTS_0,\n inputs.instanceIndex,\n u32(CROWD_JOINTS_PER_INSTANCE)\n );\n#else\n let skinMatrix = getSkinMatrix(inputs.WEIGHTS_0, inputs.JOINTS_0);\n#endif\n#endif\n position = skinMatrix * position;\n normal = normalize((skinMatrix * vec4f(normal, 0.0)).xyz);\n#ifdef HAS_TANGENTS\n tangent = vec4f(normalize((skinMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w);\n#endif\n#endif\n\n#ifdef HAS_GLTF_INSTANCING\n var instanceMatrix = mat4x4f(\n inputs.instanceModelMatrixCol0,\n inputs.instanceModelMatrixCol1,\n inputs.instanceModelMatrixCol2,\n inputs.instanceModelMatrixCol3\n );\n#ifdef HAS_GPU_CROWD_ANIMATION\n instanceMatrix *= sampleGPUAnimationMatrix(\n inputs.instanceAnimationFrames,\n inputs.instanceAnimationBlend,\n 0u,\n u32(CROWD_ANIMATION_FRAME_STRIDE)\n );\n#endif\n position = instanceMatrix * position;\n normal = normalize(getGLTFInstanceNormalMatrix(mat3x3f(\n instanceMatrix[0].xyz,\n instanceMatrix[1].xyz,\n instanceMatrix[2].xyz\n )) * normal);\n#ifdef HAS_TANGENTS\n tangent = vec4f(normalize((instanceMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w);\n#endif\n#endif\n\n let worldPosition = pbrProjection.modelMatrix * position;\n\n#ifdef HAS_NORMALS\n normal = normalize((pbrProjection.normalMatrix * vec4f(normal, 0.0)).xyz);\n#endif\n#ifdef HAS_TANGENTS\n let worldTangent = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);\n outputs.pbrTangent = vec4f(worldTangent, tangent.w);\n#endif\n\n outputs.position = pbrProjection.modelViewProjectionMatrix * position;\n outputs.pbrPosition = worldPosition.xyz / worldPosition.w;\n outputs.pbrUV0 = uv0;\n outputs.pbrUV1 = uv1;\n outputs.pbrNormal = normal;\n return outputs;\n}\n\n@fragment\nfn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {\n fragmentInputs.pbr_vPosition = inputs.pbrPosition;\n fragmentInputs.pbr_vUV0 = inputs.pbrUV0;\n fragmentInputs.pbr_vUV1 = inputs.pbrUV1;\n fragmentInputs.pbr_vNormal = inputs.pbrNormal;\n#ifdef HAS_TANGENTS\n let tangent = normalize(inputs.pbrTangent.xyz);\n let bitangent = normalize(cross(inputs.pbrNormal, tangent)) * inputs.pbrTangent.w;\n fragmentInputs.pbr_vTBN = mat3x3f(tangent, bitangent, inputs.pbrNormal);\n#endif\n return pbr_filterColor(vec4f(1.0));\n}\n";for(const[p,j]of[["CROWD_JOINTS_PER_INSTANCE",l?.jointsPerInstance||0],["CROWD_MORPH_VERTEX_COUNT",M],["CROWD_MORPH_TARGET_COUNT",S],["CROWD_ANIMATION_JOINT_COUNT",R],["CROWD_ANIMATION_FRAME_STRIDE",P]])L=L.replaceAll(`u32(${p})`,`u32(${j})`);const B={id:n,source:L,vs:"#version 300 es\n\n // in vec4 POSITION;\n in vec4 positions;\n\n #ifdef HAS_NORMALS\n // in vec4 NORMAL;\n in vec4 normals;\n #endif\n\n #ifdef HAS_TANGENTS\n in vec4 TANGENT;\n #endif\n\n #ifdef HAS_UV\n // in vec2 TEXCOORD_0;\n in vec2 texCoords;\n #endif\n\n #ifdef HAS_UV_1\n in vec2 texCoords1;\n #endif\n\n #ifdef HAS_SKIN\n in uvec4 JOINTS_0;\n in vec4 WEIGHTS_0;\n #endif\n\n #ifdef HAS_GLTF_INSTANCING\n in vec4 instanceModelMatrixCol0;\n in vec4 instanceModelMatrixCol1;\n in vec4 instanceModelMatrixCol2;\n in vec4 instanceModelMatrixCol3;\n #endif\n\n #ifdef HAS_GPU_CROWD_ANIMATION\n in vec4 instanceAnimationFrames;\n in vec4 instanceAnimationBlend;\n #endif\n\n void main(void) {\n vec4 _NORMAL = vec4(0.);\n vec4 _TANGENT = vec4(0.);\n vec2 _TEXCOORD_0 = vec2(0.);\n vec2 _TEXCOORD_1 = vec2(0.);\n\n #ifdef HAS_NORMALS\n _NORMAL = normals;\n #endif\n\n #ifdef HAS_TANGENTS\n _TANGENT = TANGENT;\n #endif\n\n #ifdef HAS_UV\n _TEXCOORD_0 = texCoords;\n #endif\n\n #ifdef HAS_UV_1\n _TEXCOORD_1 = texCoords1;\n #endif\n\n vec4 pos = positions;\n\n #ifdef HAS_INSTANCED_MORPH\n vec4 animationFrames = vec4(0.0);\n vec4 animationBlend = vec4(0.0);\n #ifdef HAS_GPU_CROWD_ANIMATION\n animationFrames = instanceAnimationFrames;\n animationBlend = instanceAnimationBlend;\n #endif\n pos.xyz += getGPUCrowdMorphDelta(\n uint(gl_InstanceID),\n uint(gl_VertexID),\n 0u,\n uint(CROWD_MORPH_TARGET_COUNT),\n uint(CROWD_ANIMATION_JOINT_COUNT),\n animationFrames,\n animationBlend\n );\n #ifdef HAS_NORMALS\n _NORMAL.xyz = normalize(_NORMAL.xyz + getGPUCrowdMorphDelta(\n uint(gl_InstanceID),\n uint(gl_VertexID),\n 1u,\n uint(CROWD_MORPH_TARGET_COUNT),\n uint(CROWD_ANIMATION_JOINT_COUNT),\n animationFrames,\n animationBlend\n ));\n #endif\n #ifdef HAS_TANGENTS\n _TANGENT.xyz = normalize(_TANGENT.xyz + getGPUCrowdMorphDelta(\n uint(gl_InstanceID),\n uint(gl_VertexID),\n 2u,\n uint(CROWD_MORPH_TARGET_COUNT),\n uint(CROWD_ANIMATION_JOINT_COUNT),\n animationFrames,\n animationBlend\n ));\n #endif\n #endif\n\n #ifdef HAS_SKIN\n #ifdef HAS_GPU_CROWD_ANIMATION\n mat4 skinMat = getGPUAnimatedSkinMatrix(\n WEIGHTS_0,\n JOINTS_0,\n instanceAnimationFrames,\n instanceAnimationBlend\n );\n #else\n #ifdef HAS_INSTANCED_SKIN\n mat4 skinMat = getInstancedSkinMatrix(\n WEIGHTS_0,\n JOINTS_0,\n uint(gl_InstanceID),\n uint(CROWD_JOINTS_PER_INSTANCE)\n );\n #else\n mat4 skinMat = getSkinMatrix(WEIGHTS_0, JOINTS_0);\n #endif\n #endif\n pos = skinMat * pos;\n _NORMAL = skinMat * _NORMAL;\n _TANGENT = vec4((skinMat * vec4(_TANGENT.xyz, 0.)).xyz, _TANGENT.w);\n #endif\n\n #ifdef HAS_GLTF_INSTANCING\n mat4 instanceMatrix = mat4(\n instanceModelMatrixCol0,\n instanceModelMatrixCol1,\n instanceModelMatrixCol2,\n instanceModelMatrixCol3\n );\n #ifdef HAS_GPU_CROWD_ANIMATION\n instanceMatrix *= sampleGPUAnimationMatrix(\n instanceAnimationFrames,\n instanceAnimationBlend,\n 0\n );\n #endif\n pos = instanceMatrix * pos;\n _NORMAL = vec4(normalize(transpose(inverse(mat3(instanceMatrix))) * _NORMAL.xyz), 0.0);\n _TANGENT = vec4(normalize(mat3(instanceMatrix) * _TANGENT.xyz), _TANGENT.w);\n #endif\n\n pbr_setPositionNormalTangentUV(pos, _NORMAL, _TANGENT, _TEXCOORD_0, _TEXCOORD_1);\n gl_Position = pbrProjection.modelViewProjectionMatrix * pos;\n }\n",fs:"#version 300 es\n out vec4 fragmentColor;\n\n void main(void) {\n vec3 pos = pbr_vPosition;\n fragmentColor = pbr_filterColor(vec4(1.0));\n }\n",geometry:r,topology:r.topology,vertexCount:a,modules:[kt,Ct,...l?[Rt]:[]],...s,...o||l?{attributes:{...s.attributes,...u},bufferLayout:[...s.bufferLayout||[],...f],instanceCount:o?.length||0,isInstanced:!0}:{},defines:{...i.defines,...s.defines,...o||l?{HAS_GLTF_INSTANCING:!0}:{},..._?{HAS_INSTANCED_SKIN:!0,CROWD_JOINTS_PER_INSTANCE:l.jointsPerInstance}:{},...m?{HAS_GPU_CROWD_ANIMATION:!0,CROWD_ANIMATION_FRAME_STRIDE:P}:{},...E?{HAS_INSTANCED_MORPH:!0,CROWD_MORPH_TARGET_COUNT:S}:{},...l?{CROWD_ANIMATION_JOINT_COUNT:R}:{}},parameters:{depthWriteEnabled:!0,depthCompare:"less",depthFormat:"depth24plus",cullMode:"back",...i.parameters,...s.parameters}},O=t.material||Wc(e,{id:n?`${n}-material`:void 0,parsedPPBRMaterial:i});B.material=O;const F=new p(e,B),D={...i.uniforms,...s.uniforms,...i.bindings,...s.bindings},U=function(e,t,n){const r=/* @__PURE__ */new Map;for(const a of e){for(const e of Object.keys(a.uniformTypes||{}))r.set(e,a.name);for(const e of a.bindingLayout||[])r.set(e.name,a.name)}const i={};for(const[a,s]of Object.entries(n)){if(void 0===s)continue;const e=r.get(a);e&&!t.ownsModule(e)&&(i[e]||={},i[e][a]=s)}return i}(F.shaderInputs.getModules(),O,D);F.shaderInputs.setProps(U),w&&F.shaderInputs.setProps({skin:{jointMatrices:[],skinJointMatrices:w}}),(N||E||I)&&F.shaderInputs.setProps({gpuAnimation:{...N?{gpuAnimationFrames:N}:{},...E?{gpuMorphTargets:E}:{},...I?{gpuMorphWeights:I}:{}}});const V=new Tn({managedResources:c,model:F,bounds:t.bounds,instanceMatrices:o});return l&&(V.userData.gltfAnimatedCrowd={transformBuffers:d,transformColumns:h,skinJointMatrices:w,jointMatrices:T,jointsPerInstance:l.jointsPerInstance,morphTargetCount:S,morphTargetData:E,morphWeights:C,morphWeightData:I,animationFrames:N,animationFrameValues:k,animationFrameStride:P,animationJointCount:R,animationParameters:g,animationParameterBuffer:b,animationBlend:v,animationBlendBuffer:y}),V}function $c(e,t,n,r,i){if("webgpu"===e.type)return e.createBuffer({id:t,data:n,usage:Xe.STORAGE|Xe.COPY_DST});const a=e.createTexture({id:t,format:"rgba32float",width:r,height:i,usage:G.SAMPLE|G.COPY_DST,sampler:{minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}});return a.writeData(n,{width:r,height:i}),a}function Xc(e,t,n){if(!e)return[...n];const r=e.value;return n.map((n,i)=>{const a=r[t*e.size+i];return void 0===a?n:e.normalized?e.value instanceof Int8Array?Math.max(a/127,-1):e.value instanceof Int16Array?Math.max(a/32767,-1):e.value instanceof Uint8Array?a/255:e.value instanceof Uint16Array?a/65535:a:a})}function Yc(e){switch(e){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":return 4;default:return 1}}function Zc(e,t){e.userData.morphWeights=[...t];const n=e.userData.morphMeshes||[];for(const r of n)r.preorderTraversal(e=>{if(!(e instanceof Tn))return;const n=e.userData.morphTargets;n&&(Ht(e.model,n.geometry,n.targets,t),e.userData.morphWeights=[...t])})}function eu(e){switch(e){case Kc.POINTS:return"point-list";case Kc.LINES:return"line-list";case Kc.LINE_STRIP:return"line-strip";case Kc.TRIANGLES:return"triangle-list";case Kc.TRIANGLE_STRIP:return"triangle-strip";default:throw new Error(String(e))}}!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[e.ONE=1]="ONE",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.FUNC_ADD=32774]="FUNC_ADD",e[e.LINEAR=9729]="LINEAR",e[e.NEAREST=9728]="NEAREST",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[e.TEXTURE_MAG_FILTER=10240]="TEXTURE_MAG_FILTER",e[e.TEXTURE_MIN_FILTER=10241]="TEXTURE_MIN_FILTER",e[e.TEXTURE_WRAP_S=10242]="TEXTURE_WRAP_S",e[e.TEXTURE_WRAP_T=10243]="TEXTURE_WRAP_T",e[e.REPEAT=10497]="REPEAT",e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.UNPACK_FLIP_Y_WEBGL=37440]="UNPACK_FLIP_Y_WEBGL"}(Kc||(Kc={}));var tu=[ru("baseColor","pbr_baseColorSampler","baseColorTexture",["pbrMetallicRoughness","baseColorTexture"]),ru("metallicRoughness","pbr_metallicRoughnessSampler","metallicRoughnessTexture",["pbrMetallicRoughness","metallicRoughnessTexture"]),ru("normal","pbr_normalSampler","normalTexture",["normalTexture"]),ru("occlusion","pbr_occlusionSampler","occlusionTexture",["occlusionTexture"]),ru("emissive","pbr_emissiveSampler","emissiveTexture",["emissiveTexture"]),ru("specularColor","pbr_specularColorSampler","KHR_materials_specular.specularColorTexture",["extensions","KHR_materials_specular","specularColorTexture"]),ru("specularIntensity","pbr_specularIntensitySampler","KHR_materials_specular.specularTexture",["extensions","KHR_materials_specular","specularTexture"]),ru("transmission","pbr_transmissionSampler","KHR_materials_transmission.transmissionTexture",["extensions","KHR_materials_transmission","transmissionTexture"]),ru("thickness","pbr_thicknessSampler","KHR_materials_volume.thicknessTexture",["extensions","KHR_materials_volume","thicknessTexture"]),ru("clearcoat","pbr_clearcoatSampler","KHR_materials_clearcoat.clearcoatTexture",["extensions","KHR_materials_clearcoat","clearcoatTexture"]),ru("clearcoatRoughness","pbr_clearcoatRoughnessSampler","KHR_materials_clearcoat.clearcoatRoughnessTexture",["extensions","KHR_materials_clearcoat","clearcoatRoughnessTexture"]),ru("clearcoatNormal","pbr_clearcoatNormalSampler","KHR_materials_clearcoat.clearcoatNormalTexture",["extensions","KHR_materials_clearcoat","clearcoatNormalTexture"]),ru("sheenColor","pbr_sheenColorSampler","KHR_materials_sheen.sheenColorTexture",["extensions","KHR_materials_sheen","sheenColorTexture"]),ru("sheenRoughness","pbr_sheenRoughnessSampler","KHR_materials_sheen.sheenRoughnessTexture",["extensions","KHR_materials_sheen","sheenRoughnessTexture"]),ru("iridescence","pbr_iridescenceSampler","KHR_materials_iridescence.iridescenceTexture",["extensions","KHR_materials_iridescence","iridescenceTexture"]),ru("iridescenceThickness","pbr_iridescenceThicknessSampler","KHR_materials_iridescence.iridescenceThicknessTexture",["extensions","KHR_materials_iridescence","iridescenceThicknessTexture"]),ru("anisotropy","pbr_anisotropySampler","KHR_materials_anisotropy.anisotropyTexture",["extensions","KHR_materials_anisotropy","anisotropyTexture"]),ru("bump","pbr_bumpSampler","EXT_materials_bump.bumpTexture",["extensions","EXT_materials_bump","bumpTexture"]),ru("diffuseTransmission","pbr_diffuseTransmissionSampler","KHR_materials_diffuse_transmission.diffuseTransmissionTexture",["extensions","KHR_materials_diffuse_transmission","diffuseTransmissionTexture"]),ru("diffuseTransmissionColor","pbr_diffuseTransmissionColorSampler","KHR_materials_diffuse_transmission.diffuseTransmissionColorTexture",["extensions","KHR_materials_diffuse_transmission","diffuseTransmissionColorTexture"]),ru("multiscatterColor","pbr_multiscatterColorSampler","KHR_materials_volume_scatter.multiscatterColorTexture",["extensions","KHR_materials_volume_scatter","multiscatterColorTexture"])],nu=new Map(tu.map(e=>[e.slot,e]));function ru(e,t,n,r){return{slot:e,binding:t,displayName:n,pathSegments:r,colorSpace:"baseColor"===e||"emissive"===e||"specularColor"===e||"sheenColor"===e||"diffuseTransmissionColor"===e||"multiscatterColor"===e?"srgb":"linear",uvSetUniform:`${e}UVSet`,uvTransformUniform:`${e}UVTransform`}}function iu(e){const t=nu.get(e);if(!t)throw new Error(`Unknown PBR texture transform slot ${e}`);return t}function au(e){const t=e?.extensions?.KHR_texture_transform;return{offset:t?.offset?[t.offset[0],t.offset[1]]:[0,0],rotation:t?.rotation??0,scale:t?.scale?[t.scale[0],t.scale[1]]:[1,1]}}function su(e){return(e?.extensions?.KHR_texture_transform)?.texCoord??e?.texCoord??0}function ou(e){const t=(new Mt).set(1,0,0,0,1,0,e.offset[0],e.offset[1],1),n=(new Mt).set(Math.cos(e.rotation),Math.sin(e.rotation),0,-Math.sin(e.rotation),Math.cos(e.rotation),0,0,0,1),r=(new Mt).set(e.scale[0],0,0,0,e.scale[1],0,0,0,1);return Array.from(t.multiplyRight(n).multiplyRight(r))}function Au(e,t){const n=new Mt(ou(e)),r=new Mt(ou(t)),i=new Mt(n).invert();return Array.from(r.multiplyRight(i))}function lu(e={}){const t=e.wrapS??e.parameters?.[Kc.TEXTURE_WRAP_S],n=e.wrapT??e.parameters?.[Kc.TEXTURE_WRAP_T],r=e.magFilter??e.parameters?.[Kc.TEXTURE_MAG_FILTER],i=e.minFilter??e.parameters?.[Kc.TEXTURE_MIN_FILTER],a=cu(t),s=cu(n),o=function(e){switch(e){case Kc.NEAREST:return"nearest";case Kc.LINEAR:return"linear";default:return}}(r);return{...a?{addressModeU:a}:{},...s?{addressModeV:s}:{},...o?{magFilter:o}:{},...uu(i)}}function cu(e){switch(e){case Kc.CLAMP_TO_EDGE:return"clamp-to-edge";case Kc.REPEAT:return"repeat";case Kc.MIRRORED_REPEAT:return"mirror-repeat";default:return}}function uu(e){switch(e){case Kc.NEAREST:return{minFilter:"nearest"};case Kc.LINEAR:return{minFilter:"linear"};case Kc.NEAREST_MIPMAP_NEAREST:return{minFilter:"nearest",mipmapFilter:"nearest"};case Kc.LINEAR_MIPMAP_NEAREST:return{minFilter:"linear",mipmapFilter:"nearest"};case Kc.NEAREST_MIPMAP_LINEAR:return{minFilter:"nearest",mipmapFilter:"linear"};case Kc.LINEAR_MIPMAP_LINEAR:return{minFilter:"linear",mipmapFilter:"linear"};default:return{}}}var fu={NORMAL:["NORMAL","normals"],TANGENT:["TANGENT"],TEXCOORD_0:["TEXCOORD_0","texCoords"],TEXCOORD_1:["TEXCOORD_1","texCoords1"],JOINTS_0:["JOINTS_0"],WEIGHTS_0:["WEIGHTS_0"],COLOR_0:["COLOR_0","colors"]};function du(e,t,n,r){const i={defines:{MANUAL_SRGB:!0},bindings:{},uniforms:{camera:[0,0,0],metallicRoughnessValues:[1,1]},parameters:{},glParameters:{},generatedTextures:[]};i.defines.USE_TEX_LOD=!0;const{imageBasedLightingEnvironment:a}=r;return a&&(i.bindings.pbr_diffuseEnvSampler=a.diffuseEnvSampler.texture,i.bindings.pbr_specularEnvSampler=a.specularEnvSampler.texture,i.bindings.pbr_brdfLUT=a.brdfLutTexture.texture,i.uniforms.IBLenabled=!0,i.uniforms.scaleIBLAmbient=[1,1]),r?.pbrDebug&&(i.defines.PBR_DEBUG=!0,i.uniforms.scaleDiffBaseMR=[0,0,0,0],i.uniforms.scaleFGDSpec=[0,0,0,0]),pu(n,"NORMAL")&&(i.defines.HAS_NORMALS=!0),pu(n,"TANGENT")&&r?.useTangents&&(i.defines.HAS_TANGENTS=!0),pu(n,"TEXCOORD_0")&&(i.defines.HAS_UV=!0),pu(n,"TEXCOORD_1")&&(i.defines.HAS_UV_1=!0),pu(n,"JOINTS_0")&&pu(n,"WEIGHTS_0")&&(i.defines.HAS_SKIN=!0),pu(n,"COLOR_0")&&(i.defines.HAS_COLORS=!0),r?.imageBasedLightingEnvironment&&(i.defines.USE_IBL=!0),r?.lights&&(i.defines.USE_LIGHTS=!0),t&&(!1!==r.validateAttributes&&function(e,t){const n=hu(e,0);n.length>0&&!pu(t,"TEXCOORD_0")&&$e.warn(`glTF material uses ${n.join(", ")} but primitive is missing TEXCOORD_0; textured shading will sample the default UV coordinates`)();const r=hu(e,1);r.length>0&&!pu(t,"TEXCOORD_1")&&$e.warn(`glTF material uses ${r.join(", ")} with TEXCOORD_1 but primitive is missing TEXCOORD_1; those textures will be skipped`)();if(Boolean(e.unlit||e.extensions?.KHR_materials_unlit)||pu(t,"NORMAL"))return;const i=e.normalTexture?"lit PBR shading with normalTexture":"lit PBR shading";$e.warn(`glTF primitive is missing NORMAL while using ${i}; shading will fall back to geometric normals`)()}(t,n),function(e,t,n,r,i){n.uniforms.unlit=Boolean(t.unlit||t.extensions?.KHR_materials_unlit),t.pbrMetallicRoughness&&function(e,t,n,r,i){t.baseColorTexture&&gu(e,t.baseColorTexture,"pbr_baseColorSampler",n,{featureOptions:{define:"HAS_BASECOLORMAP",enabledUniformName:"baseColorMapEnabled"},gltf:i,attributes:r,textureTransformSlot:"baseColor"});n.uniforms.baseColorFactor=t.baseColorFactor||[1,1,1,1],t.metallicRoughnessTexture&&gu(e,t.metallicRoughnessTexture,"pbr_metallicRoughnessSampler",n,{featureOptions:{define:"HAS_METALROUGHNESSMAP",enabledUniformName:"metallicRoughnessMapEnabled"},gltf:i,attributes:r,textureTransformSlot:"metallicRoughness"});const{metallicFactor:a=1,roughnessFactor:s=1}=t;n.uniforms.metallicRoughnessValues=[a,s]}(e,t.pbrMetallicRoughness,n,r,i);if(t.normalTexture){gu(e,t.normalTexture,"pbr_normalSampler",n,{featureOptions:{define:"HAS_NORMALMAP",enabledUniformName:"normalMapEnabled"},gltf:i,attributes:r,textureTransformSlot:"normal"});const{scale:a=1}=t.normalTexture;n.uniforms.normalScale=a}if(t.occlusionTexture){gu(e,t.occlusionTexture,"pbr_occlusionSampler",n,{featureOptions:{define:"HAS_OCCLUSIONMAP",enabledUniformName:"occlusionMapEnabled"},gltf:i,attributes:r,textureTransformSlot:"occlusion"});const{strength:a=1}=t.occlusionTexture;n.uniforms.occlusionStrength=a}n.uniforms.emissiveFactor=t.emissiveFactor||[0,0,0],t.emissiveTexture&&gu(e,t.emissiveTexture,"pbr_emissiveSampler",n,{featureOptions:{define:"HAS_EMISSIVEMAP",enabledUniformName:"emissiveMapEnabled"},gltf:i,attributes:r,textureTransformSlot:"emissive"});switch(function(e,t,n,r,i={}){if(!t)return;(function(e){return Boolean(e.KHR_materials_specular||e.KHR_materials_ior||e.EXT_materials_bump||e.KHR_materials_transmission||e.KHR_materials_diffuse_transmission||e.KHR_materials_volume||e.KHR_materials_volume_scatter||e.KHR_materials_dispersion||e.KHR_materials_clearcoat||e.KHR_materials_sheen||e.KHR_materials_iridescence||e.KHR_materials_anisotropy)})(t)&&(n.defines.USE_MATERIAL_EXTENSIONS=!0);(function(e,t,n,r,i={}){if(!t)return;t.specularColorFactor&&(n.uniforms.specularColorFactor=t.specularColorFactor);void 0!==t.specularFactor&&(n.uniforms.specularIntensityFactor=t.specularFactor);t.specularColorTexture&&gu(e,t.specularColorTexture,"pbr_specularColorSampler",n,{featureOptions:{define:"HAS_SPECULARCOLORMAP",enabledUniformName:"specularColorMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"specularColor"});t.specularTexture&&gu(e,t.specularTexture,"pbr_specularIntensitySampler",n,{featureOptions:{define:"HAS_SPECULARINTENSITYMAP",enabledUniformName:"specularIntensityMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"specularIntensity"})})(e,t.KHR_materials_specular,n,r,i),function(e,t){void 0!==e?.ior&&(t.uniforms.ior=e.ior)}(t.KHR_materials_ior,n),function(e,t,n,r,i={}){if(!t)return;n.uniforms.bumpFactor=Math.max(t.bumpFactor??1,0),t.bumpTexture&&gu(e,t.bumpTexture,"pbr_bumpSampler",n,{featureOptions:{define:"HAS_BUMPMAP",enabledUniformName:"bumpMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"bump"})}(e,t.EXT_materials_bump,n,r,i),function(e,t,n,r,i={}){if(!t)return;void 0!==t.transmissionFactor&&(n.uniforms.transmissionFactor=t.transmissionFactor);t.transmissionTexture&&gu(e,t.transmissionTexture,"pbr_transmissionSampler",n,{featureOptions:{define:"HAS_TRANSMISSIONMAP",enabledUniformName:"transmissionMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"transmission"});((t.transmissionFactor??0)>0||t.transmissionTexture)&&($e.warn("KHR_materials_transmission uses a premultiplied-alpha blending approximation and may require mesh sorting")(),function(e){e.parameters.blend=!0,e.parameters.depthWriteEnabled=!1,e.parameters.blendColorOperation="add",e.parameters.blendColorSrcFactor="one",e.parameters.blendColorDstFactor="one-minus-src-alpha",e.parameters.blendAlphaOperation="add",e.parameters.blendAlphaSrcFactor="one",e.parameters.blendAlphaDstFactor="one-minus-src-alpha",e.glParameters.blend=!0,e.glParameters.depthMask=!1,e.glParameters.blendEquation=Kc.FUNC_ADD,e.glParameters.blendFunc=[Kc.ONE,Kc.ONE_MINUS_SRC_ALPHA,Kc.ONE,Kc.ONE_MINUS_SRC_ALPHA]}(n))}(e,t.KHR_materials_transmission,n,r,i),function(e,t,n,r,i={}){if(!t)return;n.uniforms.diffuseTransmissionFactor=Math.min(Math.max(t.diffuseTransmissionFactor??0,0),1),n.uniforms.diffuseTransmissionColorFactor=t.diffuseTransmissionColorFactor||[1,1,1],t.diffuseTransmissionTexture&&gu(e,t.diffuseTransmissionTexture,"pbr_diffuseTransmissionSampler",n,{featureOptions:{define:"HAS_DIFFUSETRANSMISSIONMAP",enabledUniformName:"diffuseTransmissionMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"diffuseTransmission"});t.diffuseTransmissionColorTexture&&gu(e,t.diffuseTransmissionColorTexture,"pbr_diffuseTransmissionColorSampler",n,{featureOptions:{define:"HAS_DIFFUSETRANSMISSIONCOLORMAP",enabledUniformName:"diffuseTransmissionColorMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"diffuseTransmissionColor"})}(e,t.KHR_materials_diffuse_transmission,n,r,i),function(e,t,n,r,i={}){if(!t)return;void 0!==t.thicknessFactor&&(n.uniforms.thicknessFactor=t.thicknessFactor);t.thicknessTexture&&gu(e,t.thicknessTexture,"pbr_thicknessSampler",n,{featureOptions:{define:"HAS_THICKNESSMAP"},gltf:r,attributes:i,textureTransformSlot:"thickness"});void 0!==t.attenuationDistance&&(n.uniforms.attenuationDistance=t.attenuationDistance);t.attenuationColor&&(n.uniforms.attenuationColor=t.attenuationColor)}(e,t.KHR_materials_volume,n,r,i),function(e,t,n,r,i,a={}){if(!t||!n)return;r.uniforms.multiscatterColorFactor=t.multiscatterColorFactor||t.multiscatterColor||[0,0,0],r.uniforms.scatterAnisotropy=Math.min(Math.max(t.scatterAnisotropy??0,-.999),.999),t.multiscatterColorTexture&&gu(e,t.multiscatterColorTexture,"pbr_multiscatterColorSampler",r,{featureOptions:{define:"HAS_MULTISCATTERCOLORMAP",enabledUniformName:"multiscatterColorMapEnabled"},gltf:i,attributes:a,textureTransformSlot:"multiscatterColor"})}(e,t.KHR_materials_volume_scatter,t.KHR_materials_volume,n,r,i),function(e,t){void 0!==e?.dispersion&&(t.uniforms.dispersion=Math.max(e.dispersion,0))}(t.KHR_materials_dispersion,n),function(e,t,n,r,i={}){if(!t)return;void 0!==t.clearcoatFactor&&(n.uniforms.clearcoatFactor=t.clearcoatFactor);void 0!==t.clearcoatRoughnessFactor&&(n.uniforms.clearcoatRoughnessFactor=t.clearcoatRoughnessFactor);t.clearcoatTexture&&gu(e,t.clearcoatTexture,"pbr_clearcoatSampler",n,{featureOptions:{define:"HAS_CLEARCOATMAP",enabledUniformName:"clearcoatMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"clearcoat"});t.clearcoatRoughnessTexture&&gu(e,t.clearcoatRoughnessTexture,"pbr_clearcoatRoughnessSampler",n,{featureOptions:{define:"HAS_CLEARCOATROUGHNESSMAP",enabledUniformName:"clearcoatRoughnessMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"clearcoatRoughness"});t.clearcoatNormalTexture&&gu(e,t.clearcoatNormalTexture,"pbr_clearcoatNormalSampler",n,{featureOptions:{define:"HAS_CLEARCOATNORMALMAP"},gltf:r,attributes:i,textureTransformSlot:"clearcoatNormal"})}(e,t.KHR_materials_clearcoat,n,r,i),function(e,t,n,r,i={}){if(!t)return;t.sheenColorFactor&&(n.uniforms.sheenColorFactor=t.sheenColorFactor);void 0!==t.sheenRoughnessFactor&&(n.uniforms.sheenRoughnessFactor=t.sheenRoughnessFactor);t.sheenColorTexture&&gu(e,t.sheenColorTexture,"pbr_sheenColorSampler",n,{featureOptions:{define:"HAS_SHEENCOLORMAP",enabledUniformName:"sheenColorMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"sheenColor"});t.sheenRoughnessTexture&&gu(e,t.sheenRoughnessTexture,"pbr_sheenRoughnessSampler",n,{featureOptions:{define:"HAS_SHEENROUGHNESSMAP",enabledUniformName:"sheenRoughnessMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"sheenRoughness"})}(e,t.KHR_materials_sheen,n,r,i),function(e,t,n,r,i={}){if(!t)return;void 0!==t.iridescenceFactor&&(n.uniforms.iridescenceFactor=t.iridescenceFactor);void 0!==t.iridescenceIor&&(n.uniforms.iridescenceIor=t.iridescenceIor);void 0===t.iridescenceThicknessMinimum&&void 0===t.iridescenceThicknessMaximum||(n.uniforms.iridescenceThicknessRange=[t.iridescenceThicknessMinimum??100,t.iridescenceThicknessMaximum??400]);t.iridescenceTexture&&gu(e,t.iridescenceTexture,"pbr_iridescenceSampler",n,{featureOptions:{define:"HAS_IRIDESCENCEMAP",enabledUniformName:"iridescenceMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"iridescence"});t.iridescenceThicknessTexture&&gu(e,t.iridescenceThicknessTexture,"pbr_iridescenceThicknessSampler",n,{featureOptions:{define:"HAS_IRIDESCENCETHICKNESSMAP"},gltf:r,attributes:i,textureTransformSlot:"iridescenceThickness"})}(e,t.KHR_materials_iridescence,n,r,i),function(e,t,n,r,i={}){if(!t)return;void 0!==t.anisotropyStrength&&(n.uniforms.anisotropyStrength=t.anisotropyStrength);void 0!==t.anisotropyRotation&&(n.uniforms.anisotropyRotation=t.anisotropyRotation);t.anisotropyTexture&&gu(e,t.anisotropyTexture,"pbr_anisotropySampler",n,{featureOptions:{define:"HAS_ANISOTROPYMAP",enabledUniformName:"anisotropyMapEnabled"},gltf:r,attributes:i,textureTransformSlot:"anisotropy"})}(e,t.KHR_materials_anisotropy,n,r,i),function(e,t){void 0!==e?.emissiveStrength&&(t.uniforms.emissiveStrength=e.emissiveStrength)}(t.KHR_materials_emissive_strength,n)}(e,t.extensions,n,i,r),t.alphaMode||"OPAQUE"){case"OPAQUE":break;case"MASK":{const{alphaCutoff:e=.5}=t;n.defines.ALPHA_CUTOFF=!0,n.uniforms.alphaCutoffEnabled=!0,n.uniforms.alphaCutoff=e;break}case"BLEND":$e.warn("glTF BLEND alphaMode might not work well because it requires mesh sorting")(),function(e){e.parameters.blend=!0,e.parameters.blendColorOperation="add",e.parameters.blendColorSrcFactor="src-alpha",e.parameters.blendColorDstFactor="one-minus-src-alpha",e.parameters.blendAlphaOperation="add",e.parameters.blendAlphaSrcFactor="one",e.parameters.blendAlphaDstFactor="one-minus-src-alpha",e.glParameters.blend=!0,e.glParameters.blendEquation=Kc.FUNC_ADD,e.glParameters.blendFunc=[Kc.SRC_ALPHA,Kc.ONE_MINUS_SRC_ALPHA,Kc.ONE,Kc.ONE_MINUS_SRC_ALPHA]}(n)}}(e,t,i,n,r.gltf)),i}function hu(e,t){const n=[];for(const r of tu){const i=mu(e,r.pathSegments);i&&(su(i)===t&&n.push(r.displayName))}return n}function pu(e,t){return fu[t].some(t=>Boolean(e[t]))}function mu(e,t){let n=e;for(const r of t)if(n=n?.[r],!n)return null;return n}function gu(e,t,n,r,i={}){const{featureOptions:a={},gltf:s,attributes:o={},textureTransformSlot:A}=i,{define:l,enabledUniformName:c}=a,u=su(t);if(u>1)return void $e.warn(`Skipping ${String(n)} because ${u} is not supported; only TEXCOORD_0 and TEXCOORD_1 are currently available`)();if(1===u&&!pu(o,"TEXCOORD_1"))return void $e.warn(`Skipping ${String(n)} because it requires TEXCOORD_1 but the primitive does not provide TEXCOORD_1`)();const f=function(e,t){if(e.texture||void 0===e.index||!t?.textures)return e;const n=t.textures[e.index];return n?"texture"in n&&n.texture?{...n,...e,texture:n.texture}:"source"in n?{...e,texture:n}:e:e}(t,s),d=f.texture?.source?.image;if(!d)return void $e.warn(`Skipping unresolved glTF texture for ${String(n)}`)();const h=function(e,t,n){if("compressed"in t)return function(e,t,n){let r;r=Array.isArray(t.data)&&t.data[0]?.data?t.data:"mipmaps"in t&&Array.isArray(t.mipmaps)?t.mipmaps:[];if(0===r.length||!r[0]?.data)return $e.warn("createCompressedTexture: compressed image has no valid mip levels, creating fallback")(),bu(e,n);const i=r[0],a=i.width??t.width??0,s=i.height??t.height??0;if(a<=0||s<=0)return $e.warn("createCompressedTexture: base level has invalid dimensions, creating fallback")(),bu(e,n);const o=vu(i);if(!o)return $e.warn("createCompressedTexture: compressed image has no textureFormat, creating fallback")(),bu(e,n);if(!e.isTextureFormatSupported(o))return $e.warn(`createCompressedTexture: ${e.type} device does not support '${o}', creating fallback`)(),bu(e,n);const A=function(e,t,n){const{blockWidth:r=1,blockHeight:i=1}=W.getInfo(n);let a=1;for(let s=1;;s++){const n=Math.max(1,e>>s),o=Math.max(1,t>>s);if(n<r||o<i)break;a++}return a}(a,s,o),l=Math.min(r.length,A);let c=1;for(let f=1;f<l;f++){const e=r[f];if(!e.data||e.width<=0||e.height<=0){$e.warn(`createCompressedTexture: mip level ${f} has invalid data/dimensions, truncating`)();break}const t=vu(e);if(t&&t!==o){$e.warn(`createCompressedTexture: mip level ${f} format '${t}' differs from base '${o}', truncating`)();break}const n=Math.max(1,a>>f),i=Math.max(1,s>>f);if(e.width!==n||e.height!==i){$e.warn(`createCompressedTexture: mip level ${f} dimensions ${e.width}x${e.height} don't match expected ${n}x${i}, truncating`)();break}c++}const u=e.createTexture({...n,format:o,usage:G.TEXTURE|G.COPY_DST,width:a,height:s,mipLevels:c,data:i.data});for(let f=1;f<c;f++)u.writeData(r[f].data,{width:r[f].width,height:r[f].height,mipLevel:f});return u}(e,t,{id:n.id,sampler:n.sampler});const r=void 0!==n.width&&void 0!==n.height?{width:n.width,height:n.height}:e.getExternalImageSize(t),i="nearest"===n.sampler.mipmapFilter||"linear"===n.sampler.mipmapFilter,a=i?e.getMipLevelCount(r.width,r.height):1,s=e.createTexture({id:n.id,sampler:n.sampler,width:r.width,height:r.height,mipLevels:a,...i?{usage:G.SAMPLE|G.RENDER|G.COPY_DST|G.COPY_SRC}:{},...n.colorSpace?{format:"srgb"===n.colorSpace?"rgba8unorm-srgb":"rgba8unorm"}:{},data:t});a>1&&("webgl"===e.type?s.generateMipmapsWebGL():"webgpu"===e.type&&e.generateMipmapsWebGPU(s));return s}(e,d,{id:f.uniformName||f.id,sampler:{addressModeU:"repeat",addressModeV:"repeat",minFilter:"linear",magFilter:"linear",...lu(f.texture.sampler)}});if(r.bindings[n]=h,l&&(r.defines[l]=!0),c&&(r.uniforms[c]=!0),A){const e=iu(A);r.uniforms[e.uvSetUniform]=u,r.uniforms[e.uvTransformUniform]=ou(au(t))}r.generatedTextures.push(h)}function bu(e,t){return e.createTexture({...t,format:"rgba8unorm",width:1,height:1,mipLevels:1})}function vu(e){return e.textureFormat}var yu={modelOptions:{},pbrDebug:!1,imageBasedLightingEnvironment:void 0,lights:!0,useTangents:!1,useByteColors:!0,strictExtensions:!1};function xu(e,t,n={}){const r=/* @__PURE__ */new Set,i={...yu,...n,generatedTextures:r},a=new Jt(e,{modules:[kt]}),s=(t.materials||[]).map((n,r)=>Wc(e,{id:Tu(n,r),parsedPPBRMaterial:_u(e,n,{},{...i,gltf:t,validateAttributes:!1}),materialFactory:a})),o=/* @__PURE__ */new Map;(t.materials||[]).forEach((e,t)=>{o.set(e.id,s[t])});const A=/* @__PURE__ */new Map;t.meshes.forEach((n,r)=>{const a=wu(e,n,t,o,i);A.set(n.id,a)});const l=/* @__PURE__ */new Map,c=/* @__PURE__ */new Map,u=/* @__PURE__ */new Set,f=/* @__PURE__ */new Set,d=/* @__PURE__ */new Set;return t.nodes.forEach((e,t)=>{const n=function(e,t){return new wn({id:t.name||t.id,children:[],matrix:t.matrix,display:!1!==t.extensions?.KHR_node_visibility?.visible,position:t.translation,rotation:t.rotation,scale:t.scale})}(0,e);l.set(t,n),c.set(e.id,n)}),t.nodes.forEach((n,r)=>{if(l.get(r).add((n.children??[]).map(({id:e})=>{const t=c.get(e);if(!t)throw new Error(`Cannot find child ${e} of node ${r}`);return t})),n.mesh){const a=n.mesh,s=function(e,t){const n=t.extensions?.EXT_mesh_gpu_instancing?.attributes;if(!n||"object"!=typeof n)return null;const r={};let i;for(const[s,o]of Object.entries(n)){const t="number"==typeof o?e.accessors[o]:o;if(!t||!ArrayBuffer.isView(t.value))throw new Error(`Invalid glTF instance accessor for ${s}`);if(void 0!==i&&t.count!==i)throw new Error("glTF instance attributes must have matching accessor counts");i=t.count,r[s]={value:t.value,size:t.components||Yc(t.type),count:t.count,normalized:Boolean(t.normalized)}}const a=[];for(let s=0;s<(i||0);s++){const e=Xc(r.TRANSLATION,s,[0,0,0]),t=Xc(r.ROTATION,s,[0,0,0,1]),n=Xc(r.SCALE,s,[1,1,1]),i=Math.hypot(...t);if(i>0)for(let r=0;r<t.length;r++)t[r]/=i;a.push((new H).translate(e).multiplyRight((new H).fromQuaternion(t)).scale(n))}return{matrices:a,attributes:r}}(t,n),c=a.primitives.some(e=>Boolean(e.targets?.length)),h=s||c&&u.has(a.id)?wu(e,a,t,o,i,s||void 0):A.get(a.id);if(!h)throw new Error(`Cannot find mesh child ${n.mesh.id} of node ${r}`);const p=l.get(r),m=A.get(a.id),g=f.has(a.id)&&(void 0!==n.skin||d.has(a.id))&&h===m?wu(e,a,t,o,i):h;if(p.add(g),p.userData.gltfMesh=g,f.add(a.id),void 0!==n.skin&&d.add(a.id),c){u.add(a.id);const e=a.primitives.find(e=>e.targets?.length)?.targets?.length||0,t=n.weights||a.weights||new Array(e).fill(0);p.userData.morphMeshes=[g],i.modelOptions?.userData?.gltfAnimatedCrowd?p.userData.morphWeights=[...t]:Zc(p,t)}}}),{scenes:t.scenes.map(e=>{const t=(e.nodes||[]).map(({id:t})=>{const n=c.get(t);if(!n)throw new Error(`Cannot find child ${t} of scene ${e.name||e.id}`);return n});return new wn({id:e.name||e.id,children:t})}),materials:s,gltfMeshIdToNodeMap:A,gltfNodeIdToNodeMap:c,gltfNodeIndexToNodeMap:l,generatedTextures:r}}function _u(e,t,n,r){const i=du(e,t,n,r);for(const a of i.generatedTextures)r.generatedTextures.add(a);return i}function wu(e,t,n,r,i,a){const s=(t.primitives||[]).map((s,o)=>function({device:e,gltfPrimitive:t,primitiveIndex:n,gltfMesh:r,gltf:i,gltfMaterialIdToMaterialMap:a,options:s,instancing:o}){const A=t.name||`${r.name||r.id}-primitive-${n}`,l=function(e){let t=1/0;for(const n of Object.values(e))if(n){const{value:e,size:r,components:i}=n,a=r??i;void 0!==e?.length&&a>=1&&(t=Math.min(t,e.length/a))}if(!Number.isFinite(t))throw new Error("Could not determine vertex count from attributes");return t}(t.attributes),c=function(e,t,n){const r={};for(const[i,a]of Object.entries(t.attributes)){const{components:e,size:n,value:s,normalized:o}=a,A="POSITION"===i||"NORMAL"===i||"TANGENT"===i,l=Boolean(t.targets?.length&&A);r[i]={size:n??e,value:l?Gt({value:s,normalized:o}):s,normalized:!l&&o}}return new E({id:e,topology:n.topology,indices:n.indices??t.indices?.value,attributes:r})}(A,t,function(e,t,n){if(e!==Kc.LINE_LOOP&&e!==Kc.TRIANGLE_FAN)return{topology:eu(e)};const r=t?.length??n,i=e===Kc.LINE_LOOP?r>=2?2*r:0:r>=3?3*(r-2):0,a=new(t instanceof Uint32Array||!t&&n>65536?Uint32Array:Uint16Array)(i),s=e=>t?.[e]??e;if(e===Kc.LINE_LOOP){for(let e=0;e<r;e++)a[2*e]=s(e),a[2*e+1]=s((e+1)%r);return{topology:"line-list",indices:a}}for(let o=0;o<r-2;o++)a[3*o]=s(0),a[3*o+1]=s(o+1),a[3*o+2]=s(o+2);return{topology:"triangle-list",indices:a}}(t.mode??4,t.indices?.value,l)),u=c.vertexCount,f=function(e,t,n){if(!e.targets?.length)return;const r={};for(const i of["POSITION","NORMAL","TANGENT"]){const e=n.attributes[i]?.value;e instanceof Float32Array&&(r[i]=new Float32Array(e))}return{geometry:n,baseAttributes:r,targets:e.targets.map(e=>{const n={};for(const r of["POSITION","NORMAL","TANGENT"]){const i=e[r],a="number"==typeof i?t.accessors[i]:i;a?.value&&ArrayBuffer.isView(a.value)&&(n[r]=Gt(a))}return n})}}(t,i,c),d=_u(e,t.material,c.attributes,{...s,gltf:i}),h=Jc(e,{id:A,geometry:c,material:t.material&&a.get(t.material.id)||null,parsedPPBRMaterial:d,modelOptions:s.modelOptions,vertexCount:u,bounds:[t.attributes.POSITION.min,t.attributes.POSITION.max],instanceMatrices:o?.matrices,morphTargets:f?.targets});o&&(h.userData.gltfInstancing=o);const p=t.extensions?.KHR_materials_variants?.mappings||[];if(p.length){const t=/* @__PURE__ */new Map;for(const n of p){const r="number"==typeof n.material?i.materials[n.material]:n.material,o=r&&a.get(r.id);if(!o)continue;const A=_u(e,r,c.attributes,{...s,gltf:i});for(const e of n.variants||[])t.set(e,{material:o,parameters:{...h.model.parameters,...A.parameters,depthWriteEnabled:"BLEND"!==r.alphaMode,cullMode:r.doubleSided?"none":"back"}})}h.userData.gltfMaterialVariants={defaultMaterial:h.model.material,defaultParameters:{...h.model.parameters},mappings:t}}f&&(h.userData.morphTargets=f);return h}({device:e,gltfPrimitive:s,primitiveIndex:o,gltfMesh:t,gltf:n,gltfMaterialIdToMaterialMap:r,options:i,instancing:a}));return new wn({id:t.name||t.id,children:s})}function Tu(e,t){return e.name||e.id||`material-${t}`}function Su(e,t={}){const n=t.lightDefinitions||e.lights||e.extensions?.KHR_lights_punctual?.lights;if(!n||!Array.isArray(n)||0===n.length)return[];const r=[],i=function(e){const t=/* @__PURE__ */new Map;for(const n of e)for(const e of n.children||[])t.set(e.id,n);return t}(e.nodes||[]),a=/* @__PURE__ */new Map;for(const s of e.nodes||[]){if(!Mu(s,i,t.nodeVisibility))continue;const e=s.light??s.extensions?.KHR_lights_punctual?.light;if("number"!=typeof e||t.nodeIdentifiers&&!t.nodeIdentifiers.has(s.id))continue;const o=n[e];if(!o)continue;const A=Eu(o.color||[1,1,1],t.useByteColors??!0),l=o.intensity??1,c=o.range,u=Pu(s,i,a);switch(o.type){case"directional":r.push(Iu(u,A,l));break;case"point":r.push(Cu(u,A,l,c));break;case"spot":r.push(Ru(u,A,l,c,o.spot))}}return r}function Mu(e,t,n){let r=e;for(;r;){const e=n?.get(r.id);if(e?!e.display:!1===r.extensions?.KHR_node_visibility?.visible)return!1;r=t.get(r.id)}return!0}function Eu(e,t){return t?e.map(e=>255*e):o(e,!1)}function Cu(e,t,n,r){let i=[1,0,0];return void 0!==r&&r>0&&(i=[1,0,1/(r*r)]),{type:"point",position:Nu(e),color:t,intensity:n,attenuation:i}}function Iu(e,t,n){return{type:"directional",direction:ku(e),color:t,intensity:n}}function Ru(e,t,n,r,i={}){let a=[1,0,0];return void 0!==r&&r>0&&(a=[1,0,1/(r*r)]),{type:"spot",position:Nu(e),direction:ku(e),color:t,intensity:n,attenuation:a,innerConeAngle:i.innerConeAngle??0,outerConeAngle:i.outerConeAngle??Math.PI/4}}function Pu(e,t,n){const r=n.get(e.id);if(r)return r;const i=function(e){if(e.matrix)return new H(e.matrix);const t=new H;e.translation&&t.translate(e.translation);e.rotation&&t.multiplyRight((new H).fromQuaternion(e.rotation));e.scale&&t.scale(e.scale);return t}(e),a=t.get(e.id),s=a?new H(Pu(a,t,n)).multiplyRight(i):i;return n.set(e.id,s),s}function Nu(e){return e.transformAsPoint([0,0,0])}function ku(e){return e.transformDirection([0,0,-1])}var Lu=class extends Lt{animation;gltfNodeIdToNodeMap;onVisibilityChange;cameras;lightDefinitions;onLightChange;materials;clip;mixer;action;materialTextureTransformState=/* @__PURE__ */new Map;constructor(e){if(super({name:e.animation.name||"unnamed"}),this.animation=e.animation,this.gltfNodeIdToNodeMap=e.gltfNodeIdToNodeMap,this.onVisibilityChange=e.onVisibilityChange,this.cameras=e.cameras||[],this.lightDefinitions=e.lightDefinitions||[],this.onLightChange=e.onLightChange,this.materials=e.materials||[],this.animation.name||="unnamed",this.name=this.animation.name,this.animation.channels.some(e=>"material"===e.type||"textureTransform"===e.type)&&!this.materials.length)throw new Error(`Animation ${this.animation.name} targets materials, but GLTFAnimator was created without a materials array`);this.mixer=e.mixer||new zt,this.clip=new Vt({name:this.name,tracks:this.animation.channels.map(e=>this.createAnimationTrack(e))}),this.action=this.mixer.clipAction(this.clip).play()}applyTime(e){this.action.setTime(e),this.mixer.update(0)}createAnimationTrack(e){const t=function(e){switch(e){case"STEP":case"LINEAR":case"CUBICSPLINE":return e;default:throw new Error(`Unsupported animation interpolation: ${e}`)}}(e.sampler.interpolation);if("node"===e.type)return new Ut({name:`${e.targetNodeId}.${e.path}`,times:e.sampler.input,values:e.sampler.output,interpolation:t,valueType:"rotation"===e.path?"quaternion":"vector",binding:{id:`node:${e.targetNodeId}:${e.path}`,getValue:()=>this.getNodeAnimationValue(e.targetNodeId,e.path),setValue:t=>this.applyNodeAnimationValue(e.targetNodeId,e.path,t)}});if("camera"===e.type||"light"===e.type)return new Ut({name:e.pointer,times:e.sampler.input,values:e.sampler.output,interpolation:t,binding:{id:e.pointer,getValue:()=>this.getSceneAnimationValue(e),setValue:t=>this.applySceneAnimationValue(e,t)}});const n=this.materials[e.targetMaterialIndex];if(!n)throw new Error(`Cannot find animation target material ${e.targetMaterialIndex} for ${e.pointer}`);return new Ut({name:e.pointer,times:e.sampler.input,values:e.sampler.output,interpolation:t,binding:{id:e.pointer,getValue:"material"===e.type?()=>function(e,t){const n=e.shaderInputs.getUniformValues().pbrMaterial?.[t.property];return Array.isArray(n)?void 0===t.component?[...n]:[n[t.component]]:"number"==typeof n?[n]:[]}(n,e):void 0,setValue:t=>{"material"===e.type?function(e,t,n){const r=void 0!==t.component?{[t.property]:Fu(Ou(e,t.property),t.component,n[0])}:{[t.property]:1===n.length?n[0]:n};e.setProps({pbrMaterial:r})}(n,e,t):function(e,t,n,r){const i=iu(t.textureSlot),a=function(e,t,n){const r=e.get(t)||{};let i=r[n.textureSlot];i||(i={offset:[...n.baseTransform.offset],rotation:n.baseTransform.rotation,scale:[...n.baseTransform.scale]},r[n.textureSlot]=i,e.set(t,r));return i}(r,e,t);switch(t.path){case"offset":void 0!==t.component?a.offset[t.component]=n[0]:a.offset=[n[0],n[1]];break;case"rotation":a.rotation=n[0];break;case"scale":void 0!==t.component?a.scale[t.component]=n[0]:a.scale=[n[0],n[1]]}e.setProps({pbrMaterial:{[i.uvTransformUniform]:Au(t.baseTransform,a)}})}(n,e,t,this.materialTextureTransformState)}}})}getNodeAnimationValue(e,t){const n=this.getTargetNode(e);switch(t){case"translation":return Array.from(n.position);case"rotation":return Array.from(n.rotation);case"scale":return Array.from(n.scale);case"weights":return Array.from(n.userData.morphWeights||[]);case"visibility":return[n.display?1:0];default:return[]}}applyNodeAnimationValue(e,t,n){const r=this.getTargetNode(e);switch(t){case"translation":r.setPosition(n).updateMatrix();break;case"rotation":r.setRotation(n).updateMatrix();break;case"scale":r.setScale(n).updateMatrix();break;case"weights":Zc(r,n);break;case"visibility":r.setProps({display:0!==n[0]}),this.onVisibilityChange?.();break;default:$e.warn(`Bad animation path ${t}`)()}}getTargetNode(e){const t=this.gltfNodeIdToNodeMap.get(e);if(!t)throw new Error(`Cannot find animation target node ${e}`);return t}getSceneAnimationValue(e){if("camera"===e.type){const t=this.cameras[e.targetCameraIndex]?.[e.projection]?.[e.property];return"number"==typeof t?[t]:[]}const t=this.lightDefinitions[e.targetLightIndex],n="innerConeAngle"===e.property||"outerConeAngle"===e.property?t?.spot?.[e.property]:t?.[e.property];return Array.isArray(n)?void 0===e.component?[...n]:[n[e.component]]:"number"==typeof n?[n]:[]}applySceneAnimationValue(e,t){if("camera"===e.type){const n=this.cameras[e.targetCameraIndex];return void(n?.[e.projection]&&(n[e.projection][e.property]=t[0]))}const n=this.lightDefinitions[e.targetLightIndex];if(n){if("innerConeAngle"===e.property||"outerConeAngle"===e.property)n.spot||={},n.spot[e.property]=t[0];else if(void 0!==e.component){const r=[...n[e.property]||[1,1,1]];r[e.component]=t[0],n[e.property]=r}else n[e.property]=1===t.length?t[0]:[...t];this.onLightChange?.()}}},Bu=class extends Bt{mixer;activeClip;onUpdate;previousTimeSeconds;constructor(e){const t=new zt;super(e.animations.map((n,r)=>{const i=n.name||`Animation-${r}`;return new Lu({gltfNodeIdToNodeMap:e.gltfNodeIdToNodeMap,onVisibilityChange:e.onVisibilityChange,cameras:e.cameras,lightDefinitions:e.lightDefinitions,onLightChange:e.onLightChange,materials:e.materials,mixer:t,animation:{name:i,channels:n.channels}})})),this.mixer=t,this.onUpdate=e.onUpdate,this.activeClip=this.clips[0]?.name,!1===e.autoplay?this.clips.forEach(e=>{e.playing=!1,e.action.stop()}):"first"===e.autoplay&&this.activeClip&&this.selectClip(this.activeClip)}setUpdateHandler(e){return this.onUpdate=e,this}setTime(e){const t=e/1e3,n=void 0===this.previousTimeSeconds?0:t-this.previousTimeSeconds;this.previousTimeSeconds=t;const r=n*this.mixer.timeScale;this.clips.forEach(e=>{if(!e.playing)return void e.action.stop();if(e.action.paused)return;e.action.resume();const n=Math.max(0,t-e.startTime)*e.speed;e.action.setTime(n-r*e.action.timeScale)}),this.mixer.update(n),this.onUpdate?.()}update(e){this.mixer.update(e),this.onUpdate?.()}selectClip(e,t={}){const n=this.clips.find(t=>t.name===e);if(!n)throw new Error(`Unknown animation clip: ${e}`);const r=this.clips.find(e=>e.name===this.activeClip),i=t.crossFadeDuration||0;for(const a of this.clips)a===n||i>0&&a===r||(a.playing=!1,a.action.stop());return n.playing=!0,i>0&&r&&r!==n?(r.playing=!0,r.action.crossFadeTo(n.action,i)):n.action.reset().setEffectiveWeight(1).play(),this.activeClip=e,n}};function Ou(e,t){const n=e.shaderInputs.getUniformValues().pbrMaterial?.[t];return Array.isArray(n)?[...n]:[]}function Fu(e,t,n){const r=[...e];return r[t]=n,r}var Du=class{bindings;scenes;constructor(e){this.scenes=e.scenes,this.bindings=function(e){const{gltf:t,gltfNodeIndexToNodeMap:n}=e,r=[],i=t.skins||[],a=/* @__PURE__ */new Set;for(const s of e.scenes)s.preorderTraversal(e=>{e instanceof wn&&a.add(e)});for(const[s,o]of t.nodes.entries()){const e=o.skin;if(void 0===e||!o.mesh)continue;const A=Uu(t,e),l=i[A],c=n.get(s);if(!l||!c||!a.has(c))continue;const u=l.joints.flatMap(e=>{const t=n.get(e);return t?[t]:[]});if(u.length!==l.joints.length)continue;const f=o.mesh,d=c.userData.gltfMesh,h=d instanceof wn?d:c.children.find(e=>e instanceof wn&&e.id===(f.name||f.id));if(!(h instanceof wn))continue;const p=h.children.flatMap(e=>e instanceof Tn?[e]:[]),m=l.inverseBindMatrices?.value;r.push({nodeIndex:s,skinIndex:A,node:c,joints:u,...m instanceof Float32Array?{inverseBindMatrices:m}:{},jointMatrices:new Float32Array(16*u.length),models:p})}return r}(e),this.update()}update(){if(0===this.bindings.length)return;const e=/* @__PURE__ */new Map;for(const t of this.scenes)t.preorderTraversal((t,{worldMatrix:n})=>{t instanceof wn&&e.set(t,new H(n))});for(const t of this.bindings){Wt({joints:t.joints,meshNode:t.node,worldMatrices:e,inverseBindMatrices:t.inverseBindMatrices,target:t.jointMatrices});for(const e of t.models)e.model.shaderInputs.setProps({skin:{jointMatrices:t.jointMatrices}})}}getBinding(e){return this.bindings.find(t=>"number"==typeof e?t.nodeIndex===e:t.node===e)}};function Uu(e,t){return"number"==typeof t?t:(e.skins||[]).findIndex(n=>{if(n===t||t.id&&n.id===t.id)return!0;if(n.joints.length!==t.joints?.length||!n.joints.every((e,n)=>e===t.joints?.[n]))return!1;if("number"==typeof t.inverseBindMatrices){const r=e.accessors[t.inverseBindMatrices];return!n.inverseBindMatrices||n.inverseBindMatrices===r}return!0})}var Vu={supportLevel:"none",standardStatus:"unknown",comment:"Not currently listed in the luma.gl glTF extension support registry."},ju={KHR_draco_mesh_compression:{supportLevel:"built-in",standardStatus:"ratified",comment:"Decoded by loaders.gl before luma.gl builds the scenegraph."},EXT_meshopt_compression:{supportLevel:"built-in",standardStatus:"ratified",comment:"EXT meshopt-compressed buffer views are decoded by loaders.gl before rendering."},KHR_meshopt_compression:{supportLevel:"none",standardStatus:"release-candidate",comment:"The installed loaders.gl GLTFLoader supports EXT_meshopt_compression, not the KHR release candidate."},KHR_mesh_quantization:{supportLevel:"built-in",standardStatus:"ratified",comment:"Loader-materialized quantized accessors retain their typed values and normalization."},EXT_mesh_features:{supportLevel:"loader-only",standardStatus:"ratified",comment:"Feature identifiers are decoded by loaders.gl; automatic rendering and picking are application-owned."},EXT_structural_metadata:{supportLevel:"loader-only",standardStatus:"ratified",comment:"Structural metadata is decoded by loaders.gl; automatic rendering and querying are application-owned."},KHR_lights_punctual:{supportLevel:"built-in",standardStatus:"ratified",comment:"Parsed into luma.gl Light objects."},KHR_materials_unlit:{supportLevel:"built-in",standardStatus:"ratified",comment:"Unlit materials bypass the default lighting path."},KHR_materials_emissive_strength:{supportLevel:"built-in",standardStatus:"ratified",comment:"Applied by the stock PBR shader."},KHR_texture_basisu:{supportLevel:"built-in",standardStatus:"ratified",comment:"BasisU / KTX2 textures pass through when the device supports them."},KHR_texture_transform:{supportLevel:"built-in",standardStatus:"ratified",comment:"Per-slot UV transforms and animated pointers are applied at runtime; avoid duplicate legacy loader-side baking."},EXT_texture_webp:{supportLevel:"loader-only",standardStatus:"ratified",comment:"Texture source is resolved during load; final support depends on browser and device decode support."},EXT_texture_avif:{supportLevel:"none",standardStatus:"ratified",comment:"The image loader can decode supported AVIF images, but GLTFLoader does not select EXT_texture_avif sources."},KHR_materials_specular:{supportLevel:"built-in",standardStatus:"ratified",comment:"The stock shader now applies specular factors and textures to the dielectric F0 term."},KHR_materials_ior:{supportLevel:"built-in",standardStatus:"ratified",comment:"The stock shader now drives dielectric reflectance from the glTF IOR value."},KHR_materials_transmission:{supportLevel:"built-in",standardStatus:"ratified",comment:"The stock shader now applies transmission to the base layer and exposes transparency through alpha, without a scene-color refraction buffer."},KHR_materials_volume:{supportLevel:"built-in",standardStatus:"ratified",comment:"Thickness and attenuation now tint transmitted light in the stock shader."},KHR_materials_clearcoat:{supportLevel:"built-in",standardStatus:"ratified",comment:"The stock shader now adds a secondary clearcoat specular lobe."},KHR_materials_sheen:{supportLevel:"built-in",standardStatus:"ratified",comment:"The stock shader now adds a sheen lobe for cloth-like materials."},KHR_materials_iridescence:{supportLevel:"built-in",standardStatus:"ratified",comment:"The stock shader now tints specular response with a view-dependent thin-film iridescence approximation."},KHR_materials_anisotropy:{supportLevel:"built-in",standardStatus:"ratified",comment:"The stock shader now shapes highlights and IBL response with an anisotropy-direction approximation."},KHR_materials_pbrSpecularGlossiness:{supportLevel:"loader-only",standardStatus:"archived",comment:"Extension data can be loaded, but it is not translated into the default metallic-roughness material path."},KHR_materials_variants:{supportLevel:"parsed-and-wired",standardStatus:"ratified",comment:"Primitive material variants can be selected and restored on the generated scenegraph."},EXT_mesh_gpu_instancing:{supportLevel:"built-in",standardStatus:"ratified",comment:"Accessor-backed instance transforms use one instanced draw per source primitive."},KHR_node_visibility:{supportLevel:"parsed-and-wired",standardStatus:"ratified",comment:"Recursive node visibility controls rendered geometry, punctual lights, and animation."},KHR_animation_pointer:{supportLevel:"parsed-and-wired",standardStatus:"ratified",comment:"Node transforms, morph weights and visibility, material factors, texture transforms, camera projections, and punctual lights are wired to runtime updates."},EXT_materials_bump:{supportLevel:"built-in",standardStatus:"draft",comment:"The experimental bump-map draft perturbs the canonical surface normal from a linear height texture."},KHR_materials_diffuse_transmission:{supportLevel:"built-in",standardStatus:"release-candidate",comment:"The Khronos release candidate adds energy-conserving back-lit diffuse transmission and independent color/factor textures."},KHR_materials_dispersion:{supportLevel:"parsed-and-wired",standardStatus:"ratified",comment:"The canonical PBR shader separates red, green, and blue transmission using wavelength-dependent refraction."},KHR_materials_volume_scatter:{supportLevel:"parsed-and-wired",standardStatus:"draft",comment:"The unratified volume-scattering draft is approximated per surface; random-walk and screen-space diffusion are not implemented."},KHR_xmp:{supportLevel:"none",standardStatus:"archived",comment:"Metadata payloads remain in the loaded glTF, but luma.gl does not interpret them."},KHR_xmp_json_ld:{supportLevel:"none",standardStatus:"ratified",comment:"Metadata is preserved in the glTF, but luma.gl does not interpret it."},EXT_lights_image_based:{supportLevel:"none",standardStatus:"multi-vendor",comment:"Use loadPBREnvironment() or custom environment setup instead."},EXT_texture_video:{supportLevel:"none",standardStatus:"multi-vendor",comment:"Video textures are not created automatically by the stock pipeline."},MSFT_lod:{supportLevel:"parsed-and-wired",standardStatus:"vendor",comment:"Node levels are parsed and selected by opt-in animated crowds; material LOD and GPU-driven selection are not implemented."}};function zu(e,t){const n=Array.from(function(e){const t=e,n=/* @__PURE__ */new Set;qu(n,e.extensionsUsed),qu(n,e.extensionsRequired),qu(n,t.extensionsRemoved),qu(n,Object.keys(e.extensions||{})),(t.lights?.length||(e.nodes||[]).some(e=>"light"in e))&&n.add("KHR_lights_punctual");(e.materials||[]).some(e=>{const t=e;return t.unlit||t.extensions?.KHR_materials_unlit})&&n.add("KHR_materials_unlit");return n}(e)).sort(),r=new Set(e.extensionsRequired||[]),i=n.map(n=>{const i=ju[n]||Vu,a=function(e,t,n,r){if("KHR_texture_basisu"!==e||!r)return t;const i=function(e){const t=[];for(const n of e.textures||[]){const e=n?.source?.image;if(!e?.compressed)continue;const r=Array.isArray(e.data)?e.data[0]:Array.isArray(e.mipmaps)?e.mipmaps[0]:void 0;t.push(r?.textureFormat??null)}return t}(n).find(e=>null===e||!r.isTextureFormatSupported(e));return void 0===i?t:{supportLevel:"none",comment:null===i?`The ${r.type} device cannot use a BasisU texture whose transcoded GPU format is missing.`:`The ${r.type} device does not support the transcoded BasisU texture format '${i}'.`}}(n,i,e,t);return[n,{extensionName:n,required:r.has(n),supported:(s=a.supportLevel,"built-in"===s||"parsed-and-wired"===s),supportLevel:a.supportLevel,standardStatus:i.standardStatus,comment:a.comment}];var s});return new Map(i)}function Gu(e,t){const n=function(e,t){return Array.from(zu(e,t).values()).filter(e=>e.required&&!e.supported)}(e,t);if(n.length)throw new Error(`Unsupported required glTF extensions: ${n.map(e=>e.extensionName).join(", ")}`)}function Hu(e){return ju[e]||null}function qu(e,t=[]){for(const n of t)e.add(n)}function Qu(e){const t=e.animations||[],n=/* @__PURE__ */new Map,r=/* @__PURE__ */new Map;return t.flatMap((t,i)=>{const a=t.name||`Animation-${i}`,s=/* @__PURE__ */new Map,o=t.channels.flatMap(({sampler:i,target:a})=>{const o=function(e,t){let n;if("weights"===t.path)n=t.node;else{if("pointer"!==t.path)return;{const e=t.extensions?.KHR_animation_pointer?.pointer,r="string"==typeof e?/^\/nodes\/(\d+)\/weights$/.exec(e):null;if(!r)return;n=Number(r[1])}}const r=e.nodes[n??0],i="number"==typeof r?.mesh?e.meshes[r.mesh]:r?.mesh;return r?.weights?.length||i?.weights?.length||i?.primitives?.[0]?.targets?.length||1}(e,a),A=`${i}:${o??0}`;let l=s.get(A);if(!l){const a=t.samplers[i];if(!a)throw new Error(`Cannot find animation sampler ${i}`);const{input:c,interpolation:u="LINEAR",output:f}=a,d=function(e,t){if(t.has(e))return t.get(e);const{value:n,components:r}=Zu(e);ef(1===r,"accessorToJsArray1D must have exactly 1 component");const i=Array.from(n);return t.set(e,i),i}(e.accessors[c],n),h=function(e,t){if(t.has(e))return t.get(e);const{value:n,components:r}=Zu(e);ef(r>=1,"accessorToJsArray2D must have at least 1 component");const i=[];for(let a=0;a<n.length;a+=r)i.push(Array.from(n.slice(a,a+r)));return t.set(e,i),i}(e.accessors[f],r);l={input:d,interpolation:u,output:void 0!==o?Ku(h,d.length,u,o):h},s.set(A,l)}const c=function(e,t,n){if("pointer"===t.path)return function(e,t,n){const r=t.extensions?.KHR_animation_pointer?.pointer;if("string"!=typeof r||!r.startsWith("/"))return $e.warn("KHR_animation_pointer channel is missing a valid JSON pointer and will be skipped")(),null;const i=function(e){return e.slice(1).split("/").map(e=>e.replace(/~1/g,"/").replace(/~0/g,"~"))}(r);switch(i[0]){case"nodes":return function(e,t,n,r){const i=5===t.length&&"extensions"===t[2]&&"KHR_node_visibility"===t[3]&&"visible"===t[4];if(3!==t.length&&!i)return Yu(r,"node pointers must target transforms, morph weights, or KHR_node_visibility.visible"),null;const a=Number(t[1]),s=e.nodes[a];if(!Number.isInteger(a)||!s)return $e.warn(`KHR_animation_pointer target ${r} references a missing node and will be skipped`)(),null;if(i&&"STEP"!==n.interpolation)return Yu(r,"boolean visibility animation requires STEP interpolation"),null;const o=i?"visibility":Wu(t[2]);if(!o)return Yu(r,`node property "${t[2]}" has no runtime animation mapping`),null;return{type:"node",sampler:n,targetNodeId:s.id,path:o}}(e,i,n,r);case"materials":return function(e,t,n,r){if(t.length<3)return Yu(r,"material pointers must include a material index and target property path"),null;const i=Number(t[1]),a=e.materials[i];if(!Number.isInteger(i)||!a)return $e.warn(`KHR_animation_pointer target ${r} references a missing material and will be skipped`)(),null;const s=function(e,t){const n=function(e,t){const n=t.lastIndexOf("extensions");if(n<0||"KHR_texture_transform"!==t[n+1]||n<1)return{reason:"not-a-texture-transform-target"};const r=function(e){return tu.find(t=>t.pathSegments.length===e.length&&t.pathSegments.every((t,n)=>e[n]===t))||null}(t.slice(0,n));if(!r)return{reason:$u(t.slice(0,n))};const i=function(e,t){let n=e;for(const r of t)if(n=n?.[r],!n)return null;return n}(e,r.pathSegments);if(!i)return{reason:`texture-transform target "${t.slice(0,n).join("/")}" does not exist on the referenced material`};const a=t[n+2];if("texCoord"===a)return{reason:"animated KHR_texture_transform.texCoord is unsupported because texCoord selection is structural, not a runtime float/vector update"};if("offset"!==a&&"rotation"!==a&&"scale"!==a)return{reason:`KHR_texture_transform property "${a}" is not animatable; supported properties are offset, rotation, and scale`};const s=t[n+3];if(t.length>n+4)return{reason:`KHR_texture_transform.${a} does not support nested property paths`};let o;if(void 0!==s){if(o=Number(s),"rotation"===a)return{reason:"KHR_texture_transform.rotation does not support component indices"};if(!Number.isInteger(o)||o<0||o>1)return{reason:`KHR_texture_transform.${a} component index "${s}" is invalid; only 0 and 1 are supported`}}return{type:"textureTransform",textureSlot:r.slot,path:a,component:o,baseTransform:au(i)}}(e,t);if(!("reason"in n))return n;if("not-a-texture-transform-target"!==n.reason)return n;switch(t.join("/")){case"pbrMetallicRoughness/baseColorFactor":return e.pbrMetallicRoughness?{type:"material",property:"baseColorFactor"}:{reason:Ju(t)};case"pbrMetallicRoughness/metallicFactor":return e.pbrMetallicRoughness?{type:"material",property:"metallicRoughnessValues",component:0}:{reason:Ju(t)};case"pbrMetallicRoughness/roughnessFactor":return e.pbrMetallicRoughness?{type:"material",property:"metallicRoughnessValues",component:1}:{reason:Ju(t)};case"normalTexture/scale":return e.normalTexture?{type:"material",property:"normalScale"}:{reason:Ju(t)};case"occlusionTexture/strength":return e.occlusionTexture?{type:"material",property:"occlusionStrength"}:{reason:Ju(t)};case"emissiveFactor":return{type:"material",property:"emissiveFactor"};case"alphaCutoff":return{type:"material",property:"alphaCutoff"};case"extensions/KHR_materials_specular/specularFactor":return e.extensions?.KHR_materials_specular?{type:"material",property:"specularIntensityFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_specular/specularColorFactor":return e.extensions?.KHR_materials_specular?{type:"material",property:"specularColorFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_ior/ior":return e.extensions?.KHR_materials_ior?{type:"material",property:"ior"}:{reason:Ju(t)};case"extensions/EXT_materials_bump/bumpFactor":return e.extensions?.EXT_materials_bump?{type:"material",property:"bumpFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_diffuse_transmission/diffuseTransmissionFactor":return e.extensions?.KHR_materials_diffuse_transmission?{type:"material",property:"diffuseTransmissionFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_diffuse_transmission/diffuseTransmissionColorFactor":return e.extensions?.KHR_materials_diffuse_transmission?{type:"material",property:"diffuseTransmissionColorFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_volume_scatter/multiscatterColorFactor":case"extensions/KHR_materials_volume_scatter/multiscatterColor":return e.extensions?.KHR_materials_volume_scatter?{type:"material",property:"multiscatterColorFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_volume_scatter/scatterAnisotropy":return e.extensions?.KHR_materials_volume_scatter?{type:"material",property:"scatterAnisotropy"}:{reason:Ju(t)};case"extensions/KHR_materials_dispersion/dispersion":return e.extensions?.KHR_materials_dispersion?{type:"material",property:"dispersion"}:{reason:Ju(t)};case"extensions/KHR_materials_transmission/transmissionFactor":return e.extensions?.KHR_materials_transmission?{type:"material",property:"transmissionFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_volume/thicknessFactor":return e.extensions?.KHR_materials_volume?{type:"material",property:"thicknessFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_volume/attenuationDistance":return e.extensions?.KHR_materials_volume?{type:"material",property:"attenuationDistance"}:{reason:Ju(t)};case"extensions/KHR_materials_volume/attenuationColor":return e.extensions?.KHR_materials_volume?{type:"material",property:"attenuationColor"}:{reason:Ju(t)};case"extensions/KHR_materials_clearcoat/clearcoatFactor":return e.extensions?.KHR_materials_clearcoat?{type:"material",property:"clearcoatFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":return e.extensions?.KHR_materials_clearcoat?{type:"material",property:"clearcoatRoughnessFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_sheen/sheenColorFactor":return e.extensions?.KHR_materials_sheen?{type:"material",property:"sheenColorFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_sheen/sheenRoughnessFactor":return e.extensions?.KHR_materials_sheen?{type:"material",property:"sheenRoughnessFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_iridescence/iridescenceFactor":return e.extensions?.KHR_materials_iridescence?{type:"material",property:"iridescenceFactor"}:{reason:Ju(t)};case"extensions/KHR_materials_iridescence/iridescenceIor":return e.extensions?.KHR_materials_iridescence?{type:"material",property:"iridescenceIor"}:{reason:Ju(t)};case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":return e.extensions?.KHR_materials_iridescence?{type:"material",property:"iridescenceThicknessRange",component:0}:{reason:Ju(t)};case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":return e.extensions?.KHR_materials_iridescence?{type:"material",property:"iridescenceThicknessRange",component:1}:{reason:Ju(t)};case"extensions/KHR_materials_anisotropy/anisotropyStrength":return e.extensions?.KHR_materials_anisotropy?{type:"material",property:"anisotropyStrength"}:{reason:Ju(t)};case"extensions/KHR_materials_anisotropy/anisotropyRotation":return e.extensions?.KHR_materials_anisotropy?{type:"material",property:"anisotropyRotation"}:{reason:Ju(t)};case"extensions/KHR_materials_emissive_strength/emissiveStrength":return e.extensions?.KHR_materials_emissive_strength?{type:"material",property:"emissiveStrength"}:{reason:Ju(t)};default:return{reason:Ju(t)}}}(a,t.slice(2));if("reason"in s)return Yu(r,s.reason),null;return{sampler:n,pointer:r,targetMaterialIndex:i,...s}}(e,i,n,r);case"cameras":return function(e,t,n,r){const i=Number(t[1]),a=e.cameras?.[i],s=t[2],o=t[3];if(4!==t.length||!Number.isInteger(i)||!a||"perspective"!==s&&"orthographic"!==s||a.type!==s||!("perspective"===s?["aspectRatio","yfov","znear","zfar"]:["xmag","ymag","znear","zfar"]).includes(o))return Yu(r,"camera pointers must target a supported projection property"),null;return{type:"camera",sampler:n,pointer:r,targetCameraIndex:i,projection:s,property:o}}(e,i,n,r);case"extensions":if("KHR_lights_punctual"===i[1])return function(e,t,n,r){const i=Number(t[3]),a=e.lights||e.extensions?.KHR_lights_punctual?.lights,s="spot"===t[4],o=s?t[5]:t[4],A=s||"color"!==o?void 0:t[5],l=["color","intensity","range","innerConeAngle","outerConeAngle"],c=s||void 0!==A?6:5;if("lights"!==t[2]||t.length!==c||!Number.isInteger(i)||!Array.isArray(a)||!a[i]||!l.includes(o)||s&&"innerConeAngle"!==o&&"outerConeAngle"!==o||void 0!==A&&(!/^[0-2]$/.test(A)||"color"!==o))return Yu(r,"punctual-light pointers must target supported typed light properties"),null;return{type:"light",sampler:n,pointer:r,targetLightIndex:i,property:o,...void 0===A?{}:{component:Number(A)}}}(e,i,n,r)}return Yu(r,`top-level target "${i[0]}" has no runtime animation mapping`),null}(e,t,n);const r=Wu(t.path);if(!r)return null;const i=e.nodes[t.node??0];if(!i)throw new Error(`Cannot find animation target ${t.node}`);return{type:"node",sampler:n,targetNodeId:i.id,path:r}}(e,a,l);return c?[c]:[]});return o.length?[{name:a,channels:o}]:[]})}function Ku(e,t,n,r){const i="CUBICSPLINE"===n?3:1,a=e.length/(Math.max(t,1)*i),s=r>1?r:Number.isInteger(a)&&a>1?a:r;if(s<=1)return e;const o=e.flat(),A=[];for(let l=0;l<o.length;l+=s)A.push(o.slice(l,l+s));return A}function Wu(e){switch(e){case"translation":case"rotation":case"scale":case"weights":return e;default:return null}}function Ju(e){const t=Xu(e);if(t){const e=Hu(t);if("none"===e?.supportLevel)return`${t} is referenced by this pointer, but ${e.comment.charAt(0).toLowerCase()}${e.comment.slice(1)}`}return`no runtime target exists for material property "${e.join("/")}"`}function $u(e){const t=Xu(e);if(t){const e=Hu(t);if("none"===e?.supportLevel)return`${t} is referenced by this pointer, but ${e.comment.charAt(0).toLowerCase()}${e.comment.slice(1)}`}return`texture-transform target "${e.join("/")}" has no runtime texture-slot mapping`}function Xu(e){const t=e.indexOf("extensions"),n=e[t+1];return t>=0&&n?n:null}function Yu(e,t){$e.warn(`KHR_animation_pointer target ${e} will be skipped because ${t}`)()}function Zu(e){if(e.value)return{value:e.value,components:e.components};const t=e.bufferView?.data;ef(void 0!==t),ef(5126===e.componentType);const n="SCALAR"===e.type?1:Number(e.type.slice(3));return{value:new Float32Array(t.buffer,t.byteOffset+(e.byteOffset||0),e.count*n),components:n}}function ef(e,t){if(!e)throw new Error(t)}var tf=class{variants;names;activeVariant=null;modelNodes;constructor(e,t){const n=e.extensions?.KHR_materials_variants?.variants||[];this.variants=n.map((e,t)=>({name:e.name||`Variant-${t}`,index:t})),this.names=this.variants.map(e=>e.name);const r=/* @__PURE__ */new Set;for(const i of t)i.preorderTraversal(e=>{e instanceof Tn&&e.userData.gltfMaterialVariants&&r.add(e)});this.modelNodes=Array.from(r)}selectVariant(e){const t=this.variants.find(t=>t.name===e);if(!t)throw new Error(`Unknown glTF material variant: ${e}`);for(const n of this.modelNodes){const e=n.userData.gltfMaterialVariants,r=e.mappings.get(t.index);n.model.setMaterial(r?.material||e.defaultMaterial),n.model.setParameters(r?.parameters||e.defaultParameters)}this.activeVariant=e}resetVariant(){for(const e of this.modelNodes){const t=e.userData.gltfMaterialVariants;e.model.setMaterial(t.defaultMaterial),e.model.setParameters(t.defaultParameters)}this.activeVariant=null}};function nf(e,t,n){n?.strictExtensions&&Gu(t,e);const{scenes:r,materials:i,gltfMeshIdToNodeMap:a,gltfNodeIdToNodeMap:s,gltfNodeIndexToNodeMap:o,generatedTextures:A}=xu(e,t,n),l=Qu(t),c=(t.lights||t.extensions?.KHR_lights_punctual?.lights||[]).map(e=>({...e,...Array.isArray(e.color)?{color:[...e.color]}:{},...e.spot?{spot:{...e.spot}}:{}})),u=(t.cameras||[]).map(e=>{const t={...e};return e.perspective&&(t.perspective={...e.perspective}),e.orthographic&&(t.orthographic={...e.orthographic}),t}),f={useByteColors:n?.useByteColors??!0,nodeVisibility:s,lightDefinitions:c},d=Su(t,f),h=()=>{d.splice(0,d.length,...Su(t,f))},p=new Bu({onVisibilityChange:h,cameras:u,lightDefinitions:c,onLightChange:h,animations:l,gltfNodeIdToNodeMap:s,materials:i}),m=new tf(t,r),g=zu(t,e),b=r.map(e=>rf(e.getBounds())),v=function(e){let t=null;for(const n of e)if(n.bounds)if(t)for(let e=0;e<3;e++)t[0][e]=Math.min(t[0][e],n.bounds[0][e]),t[1][e]=Math.max(t[1][e],n.bounds[1][e]);else t=[[...n.bounds[0]],[...n.bounds[1]]];return rf(t)}(b),y=new Du({gltf:t,scenes:r,gltfNodeIndexToNodeMap:o});p.setUpdateHandler(()=>y.update());let x=!1;return{scenes:r,materials:i,variants:m,cameras:u,animator:p,animations:l,lights:d,extensionSupport:g,sceneBounds:b,modelBounds:v,gltfMeshIdToNodeMap:a,gltfNodeIdToNodeMap:s,gltfNodeIndexToNodeMap:o,skins:y,gltf:t,destroy:()=>{if(x)return;x=!0;const e=/* @__PURE__ */new Set([...r,...a.values(),...s.values()]),t=/* @__PURE__ */new Set,n=new Set(i);for(const r of e)r.preorderTraversal(e=>{e instanceof Tn&&(t.add(e),e.model?.material&&n.add(e.model.material))});for(const r of t)r.destroy();for(const r of e)r.destroy();for(const r of n)r.destroy();for(const r of A)r.destroy();A.clear()}}}function rf(e){if(!e)return{bounds:null,center:[0,0,0],size:[0,0,0],radius:.5,recommendedOrbitDistance:1};const t=[[e[0][0],e[0][1],e[0][2]],[e[1][0],e[1][1],e[1][2]]],n=[t[1][0]-t[0][0],t[1][1]-t[0][1],t[1][2]-t[0][2]],r=[t[0][0]+.5*n[0],t[0][1]+.5*n[1],t[0][2]+.5*n[2]],i=.5*Math.max(n[0],n[1],n[2]),a=Math.max(.5*Math.hypot(n[0],n[1],n[2]),.001);return{bounds:t,center:r,size:n,radius:a,recommendedOrbitDistance:Math.max(Math.max(i,.001)/Math.tan(Math.PI/6)*1.15,1.1*a)}}var af=function(){var e=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),t=new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);if("object"!=typeof WebAssembly)return{supported:!1};var n,r=WebAssembly.validate(e)?a("b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuixkbbebeeddddilve9Weeeviebeoweuecj:Gdkr;Neqo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949WbwY9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVJ9V29VVbDl79IV9Rbqq:I9Dklbzik94evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaeai86b:q:W:cjbaecitab8Piw83i:q:G:cjbaecefgecjd9hmbkk:SBlEud97dur978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnalTmbcuhoaiRbbgrc;WeGc:Ge9hmbarcsGgwce0mbc9:hoalcufadcd4cbawEgDadfgrcKcaawEgqaraq0Egk6mbaialfgxar9RhodnadTgmmbavaoad;8qbbkaicefhPcj;abad9Uc;WFbGcjdadca0EhsdndndnadTmbaoadfhzcbhHinaeaH9nmdaxaP9RaD6miabaHad2fgOavcjdfasaeaH9RaHasfae6EgAaAcsfgoc9WGgCSEhXaPaDfhQaocl4cifcd4hLavcj;cbfaCcetfhKavcj;cbfaCci2fhYavcj;cbfaCfh8AcbhEaoc;ab6h3incbh5dnawTmbaPaEcd4fRbbh5kcbh8Eavcj;cbfh8Findndndndna5a8Ecet4ciGgoc9:fPdebdkaxaQ9RaC6mwdnaCTmbavcj;cbfa8EaC2faQaC;8qbbkaQaAfhQxdkaCTmeavcj;cbfa8EaC2fcbaC;8kbxekaxaQ9RaL6moaoclVcbawEhraQaLfhocbhidna3mbaxao9Rc;Gb6mbcbhlina8FalfhidndndndndndnaQalco4fRbbgqciGarfPDbedibledibkaipxbbbbbbbbbbbbbbbbpklbxlkaiaopbblaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLgacdp:meaapmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9oghpxiiiiiiiiiiiiiiiip8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Nggcitpbi:q:G:cjbagRb:q:W:cjbggpsaap5e9cjF;8;4;W;G;ab9:9cU1:Ng8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spklbagaoclffa8JRb:q:W:cjbfhoxikaiaopbbwaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLpxssssssssssssssssp9oghpxssssssssssssssssp8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Nggcitpbi:q:G:cjbagRb:q:W:cjbggpsaap5e9cjF;8;4;W;G;ab9:9cU1:Ng8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spklbagaocwffa8JRb:q:W:cjbfhoxdkaiaopbbbpklbaoczfhoxekaiaopbbdaoRbbggcitpbi:q:G:cjbagRb:q:W:cjbggpsaoRbeg8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPpklbagaocdffa8JRb:q:W:cjbfhokdndndndndndnaqcd4ciGarfPDbedibledibkaiczfpxbbbbbbbbbbbbbbbbpklbxlkaiczfaopbblaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLgacdp:meaapmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9oghpxiiiiiiiiiiiiiiiip8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Nggcitpbi:q:G:cjbagRb:q:W:cjbggpsaap5e9cjF;8;4;W;G;ab9:9cU1:Ng8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spklbagaoclffa8JRb:q:W:cjbfhoxikaiczfaopbbwaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLpxssssssssssssssssp9oghpxssssssssssssssssp8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Nggcitpbi:q:G:cjbagRb:q:W:cjbggpsaap5e9cjF;8;4;W;G;ab9:9cU1:Ng8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spklbagaocwffa8JRb:q:W:cjbfhoxdkaiczfaopbbbpklbaoczfhoxekaiczfaopbbdaoRbbggcitpbi:q:G:cjbagRb:q:W:cjbggpsaoRbeg8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPpklbagaocdffa8JRb:q:W:cjbfhokdndndndndndnaqcl4ciGarfPDbedibledibkaicafpxbbbbbbbbbbbbbbbbpklbxlkaicafaopbblaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLgacdp:meaapmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9oghpxiiiiiiiiiiiiiiiip8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Nggcitpbi:q:G:cjbagRb:q:W:cjbggpsaap5e9cjF;8;4;W;G;ab9:9cU1:Ng8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spklbagaoclffa8JRb:q:W:cjbfhoxikaicafaopbbwaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLpxssssssssssssssssp9oghpxssssssssssssssssp8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Nggcitpbi:q:G:cjbagRb:q:W:cjbggpsaap5e9cjF;8;4;W;G;ab9:9cU1:Ng8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spklbagaocwffa8JRb:q:W:cjbfhoxdkaicafaopbbbpklbaoczfhoxekaicafaopbbdaoRbbggcitpbi:q:G:cjbagRb:q:W:cjbggpsaoRbeg8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPpklbagaocdffa8JRb:q:W:cjbfhokdndndndndndnaqco4arfPDbedibledibkaic8Wfpxbbbbbbbbbbbbbbbbpklbxlkaic8Wfaopbblaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLgacdp:meaapmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9oghpxiiiiiiiiiiiiiiiip8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Ngicitpbi:q:G:cjbaiRb:q:W:cjbgipsaap5e9cjF;8;4;W;G;ab9:9cU1:Ngqcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spklbaiaoclffaqRb:q:W:cjbfhoxikaic8Wfaopbbwaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLpxssssssssssssssssp9oghpxssssssssssssssssp8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Ngicitpbi:q:G:cjbaiRb:q:W:cjbgipsaap5e9cjF;8;4;W;G;ab9:9cU1:Ngqcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spklbaiaocwffaqRb:q:W:cjbfhoxdkaic8Wfaopbbbpklbaoczfhoxekaic8WfaopbbdaoRbbgicitpbi:q:G:cjbaiRb:q:W:cjbgipsaoRbegqcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPpklbaiaocdffaqRb:q:W:cjbfhokalc;abfhialcjefaC0meaihlaxao9Rc;Fb0mbkkdnaiaC9pmbaici4hlinaxao9RcK6mwa8FaifhqdndndndndndnaQaico4fRbbalcoG4ciGarfPDbedibledibkaqpxbbbbbbbbbbbbbbbbpkbbxlkaqaopbblaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLgacdp:meaapmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9oghpxiiiiiiiiiiiiiiiip8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Nggcitpbi:q:G:cjbagRb:q:W:cjbggpsaap5e9cjF;8;4;W;G;ab9:9cU1:Ng8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spkbbagaoclffa8JRb:q:W:cjbfhoxikaqaopbbwaopbbbgaclp:meaapmbzeHdOiAlCvXoQrLpxssssssssssssssssp9oghpxssssssssssssssssp8Jgap5b9cjF;8;4;W;G;ab9:9cU1:Nggcitpbi:q:G:cjbagRb:q:W:cjbggpsaap5e9cjF;8;4;W;G;ab9:9cU1:Ng8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPahaap9spkbbagaocwffa8JRb:q:W:cjbfhoxdkaqaopbbbpkbbaoczfhoxekaqaopbbdaoRbbggcitpbi:q:G:cjbagRb:q:W:cjbggpsaoRbeg8Jcitpbi:q:G:cjbp9UpmbedilvorzHOACXQLpPpkbbagaocdffa8JRb:q:W:cjbfhokalcdfhlaiczfgiaC6mbkkaohQaoTmoka8FaCfh8Fa8Ecefg8Ecl9hmbkdndndndnawTmbazaEcd4fRbbglciGPlbedwbkaCTmdaXaEfhlavaEfpbdbh8Kcbhoinalavcj;cbfaofpblbg8La8Aaofpblbg8MpmbzeHdOiAlCvXoQrLg8NaKaofpblbgyaYaofpblbg8PpmbzeHdOiAlCvXoQrLgIpmbezHdiOAlvCXorQLgacep9Taapxeeeeeeeeeeeeeeeeghp9op9Hp9rgaa8Kp9Ug8Kp9Abbbaladfgla8Kaaaapmlvorlvorlvorlvorp9Ug8Kp9Abbbaladfgla8KaaaapmwDqkwDqkwDqkwDqkp9Ug8Kp9Abbbaladfgla8KaaaapmxmPsxmPsxmPsxmPsp9Ug8Kp9Abbbaladfgla8Ka8NaIpmwDKYqk8AExm35Ps8E8Fgacep9Taaahp9op9Hp9rgap9Ug8Kp9Abbbaladfgla8Kaaaapmlvorlvorlvorlvorp9Ug8Kp9Abbbaladfgla8KaaaapmwDqkwDqkwDqkwDqkp9Ug8Kp9Abbbaladfgla8KaaaapmxmPsxmPsxmPsxmPsp9Ug8Kp9Abbbaladfgla8Ka8La8MpmwKDYq8AkEx3m5P8Es8Fg8Laya8PpmwKDYq8AkEx3m5P8Es8Fg8MpmbezHdiOAlvCXorQLgacep9Taaahp9op9Hp9rgap9Ug8Kp9Abbbaladfgla8Kaaaapmlvorlvorlvorlvorp9Ug8Kp9Abbbaladfgla8KaaaapmwDqkwDqkwDqkwDqkp9Ug8Kp9Abbbaladfgla8KaaaapmxmPsxmPsxmPsxmPsp9Ug8Kp9Abbbaladfgla8Ka8La8MpmwDKYqk8AExm35Ps8E8Fgacep9Taaahp9op9Hp9rgap9Ughp9Abbbaladfglahaaaapmlvorlvorlvorlvorp9Ughp9AbbbaladfglahaaaapmwDqkwDqkwDqkwDqkp9Ughp9AbbbaladfglahaaaapmxmPsxmPsxmPsxmPsp9Ug8Kp9AbbbaladfhlaoczfgoaC6mbxikkaCTmeaXaEfhlavaEfpbdbh8Kcbhoinalavcj;cbfaofpblbg8La8Aaofpblbg8MpmbzeHdOiAlCvXoQrLg8NaKaofpblbgyaYaofpblbg8PpmbzeHdOiAlCvXoQrLgIpmbezHdiOAlvCXorQLgacep:neaapxebebebebebebebebghp9op:bep9rgaa8Kp:oeg8Kp9Abbbaladfgla8Kaaaapmlvorlvorlvorlvorp:oeg8Kp9Abbbaladfgla8KaaaapmwDqkwDqkwDqkwDqkp:oeg8Kp9Abbbaladfgla8KaaaapmxmPsxmPsxmPsxmPsp:oeg8Kp9Abbbaladfgla8Ka8NaIpmwDKYqk8AExm35Ps8E8Fgacep:neaaahp9op:bep9rgap:oeg8Kp9Abbbaladfgla8Kaaaapmlvorlvorlvorlvorp:oeg8Kp9Abbbaladfgla8KaaaapmwDqkwDqkwDqkwDqkp:oeg8Kp9Abbbaladfgla8KaaaapmxmPsxmPsxmPsxmPsp:oeg8Kp9Abbbaladfgla8Ka8La8MpmwKDYq8AkEx3m5P8Es8Fg8Laya8PpmwKDYq8AkEx3m5P8Es8Fg8MpmbezHdiOAlvCXorQLgacep:neaaahp9op:bep9rgap:oeg8Kp9Abbbaladfgla8Kaaaapmlvorlvorlvorlvorp:oeg8Kp9Abbbaladfgla8KaaaapmwDqkwDqkwDqkwDqkp:oeg8Kp9Abbbaladfgla8KaaaapmxmPsxmPsxmPsxmPsp:oeg8Kp9Abbbaladfgla8Ka8La8MpmwDKYqk8AExm35Ps8E8Fgacep:neaaahp9op:bep9rgap:oeghp9Abbbaladfglahaaaapmlvorlvorlvorlvorp:oeghp9AbbbaladfglahaaaapmwDqkwDqkwDqkwDqkp:oeghp9AbbbaladfglahaaaapmxmPsxmPsxmPsxmPsp:oeg8Kp9AbbbaladfhlaoczfgoaC6mbxdkkaCTmbaXaEfhrcbhocbalcl4gl9Rc8FGhiavaEfpbdbhhinaravcj;cbfaofpblbg8Ka8Aaofpblbg8LpmbzeHdOiAlCvXoQrLg8MaKaofpblbg8NaYaofpblbgypmbzeHdOiAlCvXoQrLg8PpmbezHdiOAlvCXorQLgaaip:Reaaalp:Tep9qgaahp9rghp9Abbbaradfgrahaaaapmlvorlvorlvorlvorp9rghp9AbbbaradfgrahaaaapmwDqkwDqkwDqkwDqkp9rghp9AbbbaradfgrahaaaapmxmPsxmPsxmPsxmPsp9rghp9Abbbaradfgraha8Ma8PpmwDKYqk8AExm35Ps8E8Fgaaip:Reaaalp:Tep9qgap9rghp9Abbbaradfgrahaaaapmlvorlvorlvorlvorp9rghp9AbbbaradfgrahaaaapmwDqkwDqkwDqkwDqkp9rghp9AbbbaradfgrahaaaapmxmPsxmPsxmPsxmPsp9rghp9Abbbaradfgraha8Ka8LpmwKDYq8AkEx3m5P8Es8Fg8Ka8NaypmwKDYq8AkEx3m5P8Es8Fg8LpmbezHdiOAlvCXorQLgaaip:Reaaalp:Tep9qgap9rghp9Abbbaradfgrahaaaapmlvorlvorlvorlvorp9rghp9AbbbaradfgrahaaaapmwDqkwDqkwDqkwDqkp9rghp9AbbbaradfgrahaaaapmxmPsxmPsxmPsxmPsp9rghp9Abbbaradfgraha8Ka8LpmwDKYqk8AExm35Ps8E8Fgaaip:Reaaalp:Tep9qgap9rghp9Abbbaradfgrahaaaapmlvorlvorlvorlvorp9rghp9AbbbaradfgrahaaaapmwDqkwDqkwDqkwDqkp9rghp9AbbbaradfgrahaaaapmxmPsxmPsxmPsxmPsp9rghp9AbbbaradfhraoczfgoaC6mbkkaEclfgEad6mbkdnaXavcjdf9hmbaAad2goTmbaOavcjdfao;8qbbkdnammbavaXaAcufad2fad;8qbbkaAaHfhHc9:hoaQhPaQmbxlkkaeTmbaDalfhrcbhocuhlinaralaD9RglfaD6mdasaeao9Raoasfae6Eaofgoae6mbkaial9RhPkcbc99axaP9RakSEhoxekc9:hokavcj;kbf8Kjjjjbaokwbz:bjjjbkpPesu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnalaeci9UgrcHf6mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgwce0mbavc;abfcFecje;8kbav9cu83iUav9cu83i8Wav9cu83iyav9cu83iaav9cu83iKav9cu83izav9cu83iwav9cu83ibaialfc9WfhDaicefgiarfhqdndnaeci9pmbaqhexekcmcsawceSEhkcbhxcbhmaqhecbhlcbhoindndnaiRbbgrc;Ve0mbavc;abfaoarcu7gPcl4fcsGcitfgwydlhsawydbhzdndnarcsGgwak9pmbavalaPfcsGcdtfydbaxawEhraxawTgHfhxxekdnaeaD9nmbc9:hoxokdndnawcsSmbcehHamawcetfcWfhrxekaecefhrae8SbbgwcFeGhPdndnawcu9mmbarhexekaecvfheaPcFbGhPcrhwdninar8SbbgHcFbGawtaPVhPaHcu9kmearcefhrawcrfgwc8J9hmbxdkkarcefhekcehHaPce4cbaPceG9R7amfhrkarhmkavc;abfaocitfgwarBdbawasBdlavalcdtfarBdbavc;abfaocefcsGcitfgwazBdbawarBdlaocdfhoaHalfhldnadcd9hmbabar87elabas87edabaz87ebabcofhbxdkabarBdwabasBdlabazBdbabcxfhbxekdnarcpe0mbavalaDarcsGfRbbgwcl4gP9RcsGcdtfydbaxcefgsaPEhravalaw9RcsGcdtfydbasaPTgzfgsawcsGgPEhwaPThPdndnadcd9hmbabaw87elabar87edabax87ebcohHxekabawBdwabarBdlabaxBdbcxhHkavalcdtfaxBdbavc;abfaocitfgOarBdbaOaxBdlavalcefglcsGcdtfarBdbavc;abfaocefcsGcitfgOawBdbaOarBdlavalazfglcsGcdtfawBdbavc;abfaocdfcsGcitfgraxBdbarawBdlaocifhoabaHfhbalaPfhlasaPfhxxekdnaeaD9nmbc9:hoxlkaxcbaeRbbgwEgHarc;:eSgrfhsawcsGhOdndnawcl4gAmbascefhzxekashzavalaA9RcsGcdtfydbhskdndnaOmbazcefhxxekazhxavalaw9RcsGcdtfydbhzkdndnarTmbaecefhrxekaecdfhrae8SbegPcFeGhwdnaPcu9kmbaecofhHawcFbGhwcrhedninar8SbbgPcFbGaetawVhwaPcu9kmearcefhraecrfgec8J9hmbkaHhrxekarcefhrkawce4cbawceG9R7amfgmhHkdndnaAcsSmbarhwxekarcefhwar8SbbgecFeGhPdnaecu9kmbarcvfhsaPcFbGhPcrhedninaw8SbbgrcFbGaetaPVhParcu9kmeawcefhwaecrfgec8J9hmbkashwxekawcefhwkaPce4cbaPceG9R7amfgmhskdndnaOcsSmbawhexekawcefheaw8SbbgrcFeGhPdnarcu9kmbawcvfhzaPcFbGhPcrhrdninae8SbbgwcFbGartaPVhPawcu9kmeaecefhearcrfgrc8J9hmbkazhexekaecefhekaPce4cbaPceG9R7amfgmhzkdndnadcd9hmbabaz87elabas87edabaH87ebcohrxekabazBdwabasBdlabaHBdbcxhrkavc;abfaocitfgwasBdbawaHBdlavalcdtfaHBdbavc;abfaocefcsGcitfgwazBdbawasBdlavalcefglcsGcdtfasBdbavc;abfaocdfcsGcitfgwaHBdbawazBdlavalaATaAcsSVfglcsGcdtfazBdbalaOTaOcsSVfhlaocifhoabarfhbkaocsGhoalcsGhlaicefgiaq6mbkkcbc99aeaDSEhokavc;aef8Kjjjjbaok:clevu8Jjjjjbcz9Rhvdnalaecvf9pmbc9:skdnaiRbbc;:eGc;qeSmbcuskav9cb83iwaicefhoaialfc98fhrdnaeTmbdnadcdSmbcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcdtfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgiBdbalaiBdbawcefgwae9hmbxdkkcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcetfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgi87ebalaiBdbawcefgwae9hmbkkcbc99aoarSEk;Toio97eue97aec98Ghedndnadcl9hmbaeTmecbhdinababpbbbgicKp:RecKp:Sep;6eglaicwp:RecKp:Sep;6ealp;Geaiczp:RecKp:Sep;6egvp;Gep;Kep;Legopxbbbbbbbbbbbbbbbbp:2egralpxbbbjbbbjbbbjbbbjgwp9op9rp;Keglpxbb;:9cbb;:9cbb;:9cbb;:9calalp;Meaoaop;Meavaravawp9op9rp;Keglalp;Mep;Kep;Kep;Jep;Negvp;Mepxbbn0bbn0bbn0bbn0grp;KepxFbbbFbbbFbbbFbbbp9oaipxbbbFbbbFbbbFbbbFp9op9qalavp;Mearp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaoavp;Mearp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbabczfhbadclfgdae6mbxdkkaeTmbcbhdinabczfgDaDpbbbgipxbbbbbbFFbbbbbbFFgwp9oabpbbbgoaipmbediwDqkzHOAKY8AEgvczp:Reczp:Sep;6eglaoaipmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eavczp:Sep;6egvp;Gealp;Gep;Kep;Legipxbbbbbbbbbbbbbbbbp:2egralpxbbbjbbbjbbbjbbbjgqp9op9rp;Keglpxb;:FSb;:FSb;:FSb;:FSalalp;Meaiaip;Meavaravaqp9op9rp;Keglalp;Mep;Kep;Kep;Jep;Negvp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbp9oaiavp;Mearp;Keczp:Rep9qgialavp;Mearp;KepxFFbbFFbbFFbbFFbbp9oglpmwDKYqk8AExm35Ps8E8Fp9qpkbbabaoawp9oaialpmbezHdiOAlvCXorQLp9qpkbbabcafhbadclfgdae6mbkkk;2ileue97euo97dnaec98GgiTmbcbheinabcKfpx:ji:1S:ji:1S:ji:1S:ji:1SabpbbbglabczfgvpbbbgopmlvorxmPsCXQL358E8Fgrczp:Segwpxibbbibbbibbbibbbp9qp;6egDp;NegqaDaDp;MegDaDp;KealaopmbediwDqkzHOAKY8AEgDczp:Reczp:Sep;6eglalp;MeaDczp:Sep;6egoaop;Mearczp:Reczp:Sep;6egrarp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jep;Mepxbbn0bbn0bbn0bbn0gDp;KepxFFbbFFbbFFbbFFbbgkp9oaqaop;MeaDp;Keczp:Rep9qgoaqalp;MeaDp;Keakp9oaqarp;MeaDp;Keczp:Rep9qgDpmwDKYqk8AExm35Ps8E8Fglp5eawclp:RegqpEi:T:j83ibavalp5baqpEd:T:j83ibabcwfaoaDpmbezHdiOAlvCXorQLgDp5eaqpEe:T:j83ibabaDp5baqpEb:T:j83ibabcafhbaeclfgeai6mbkkkuee97dnadcd4ae2c98GgeTmbcbhdinababpbbbgicwp:Recwp:Sep;6eaicep:SepxbbjFbbjFbbjFbbjFp9opxbbjZbbjZbbjZbbjZp:Uep;Mepkbbabczfhbadclfgdae6mbkkk:Sodw97euaec98Ghedndnadcl9hmbaeTmecbhdinabpxbbuJbbuJbbuJbbuJabpbbbgicKp:TeglaicYp:Tep9qgvcdp:Teavp9qgvclp:Teavp9qgop;6ep;Negvaicwp:RecKp:SegraipxFbbbFbbbFbbbFbbbgwp9ogDp:Uep;6ep;Mepxbbn0bbn0bbn0bbn0gqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9oavaDarp:Xeaiczp:RecKp:Segip:Uep;6ep;Meaqp;Keawp9op9qavaDaraip:Uep:Xep;6ep;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qavaoalcep:Rep9oalpxebbbebbbebbbebbbp9op9qp;6ep;Meaqp;KecKp:Rep9qpkbbabczfhbadclfgdae6mbxdkkaeTmbcbhdinabczfgkpxbFu9hbFu9hbFu9hbFu9habpbbbglakpbbbgrpmlvorxmPsCXQL358E8Fgvczp:TegqavcHp:Tep9qgicdp:Teaip9qgiclp:Teaip9qgicwp:Teaip9qgop;6ep;NegialarpmbediwDqkzHOAKY8AEgDpxFFbbFFbbFFbbFFbbglp9ograDczp:Segwp:Ueavczp:Reczp:SegDp:Xep;6ep;Mepxbbn0bbn0bbn0bbn0gvp;Kealp9oaiarawaDp:Uep:Xep;6ep;Meavp;Keczp:Rep9qgwaiaoaqcep:Rep9oaqpxebbbebbbebbbebbbp9op9qp;6ep;Meavp;Keczp:ReaiaDarp:Uep;6ep;Meavp;Kealp9op9qgipmwDKYqk8AExm35Ps8E8FpkbbabawaipmbezHdiOAlvCXorQLpkbbabcafhbadclfgdae6mbkkk9teiucbcbydj:G:cjbgeabcifc98GfgbBdj:G:cjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkxebcj:Gdklz:zbb"):a("b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuixkbeeeddddillviebeoweuecj:Gdkr;Neqo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949WboY9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVJ9V29VVbrl79IV9Rbwq;X8:kdbk:kYi5ud9:du8Jjjjjbcjq9Rgv8Kjjjjbc9:hodnalTmbcuhoaiRbbgrc;WeGc:Ge9hmbarcsGgwce0mbc9:hoalcufadcd4cbawEgDadfgrcKcaawEgqaraq0Egk6mbaicefhxcj;abad9Uc;WFbGcjdadca0EhmaialfgPar9Rgoadfhsavaoadz:jjjjbgzceVhHcbhOdndninaeaO9nmeaPax9RaD6mdamaeaO9RaOamfgoae6EgAcsfglc9WGhCaAcethXaxaDfhiaOaeaoaeao6E9RhQalcl4cifcd4hLazcjdfaAfhKcbhYabaOad2fg8AhEaHh3incbh5dnawTmbaxaYcd4fRbbh5kcbh8Eazcjdfhqinaih8Fdndndndna5a8Ecet4ciGgoc9:fPdebdkaPa8F9RaA6mrazcjdfa8EaA2fa8FaAz:jjjjb8Aa8FaAfhixdkazcjdfa8EaA2fcbaAz:kjjjb8Aa8FhixekaPa8F9RaL6mva8FaLfhidnaCTmbaPai9RcK6mbaocdtc:q:G:cjbfcj:G:cjbawEhaczhrcbhlinargoc9Wfghaqfhrdndndndndndnaaa8Fahco4fRbbalcoG4ciGcdtfydbPDbedvivvvlvkar9cb83bwar9cb83bbxlkarcbaiRbdai8Xbb9c:c:qj:bw9:9c:q;c1:I1e:d9c:b:c:e1z9:gg9cjjjjjz:dg8J9qE86bbaqaofgrcGfcbaicdfa8J9c8N1:NfghRbbag9cjjjjjw:dg8J9qE86bbarcVfcbaha8J9c8M1:NfghRbbag9cjjjjjl:dg8J9qE86bbarc7fcbaha8J9c8L1:NfghRbbag9cjjjjjd:dg8J9qE86bbarctfcbaha8J9c8K1:NfghRbbag9cjjjjje:dg8J9qE86bbarc91fcbaha8J9c8J1:NfghRbbag9cjjjj;ab:dg8J9qE86bbarc4fcbaha8J9cg1:NfghRbbag9cjjjja:dg8J9qE86bbarc93fcbaha8J9ch1:NfghRbbag9cjjjjz:dgg9qE86bbarc94fcbahag9ca1:NfghRbbai8Xbe9c:c:qj:bw9:9c:q;c1:I1e:d9c:b:c:e1z9:gg9cjjjjjz:dg8J9qE86bbarc95fcbaha8J9c8N1:NfgiRbbag9cjjjjjw:dg8J9qE86bbarc96fcbaia8J9c8M1:NfgiRbbag9cjjjjjl:dg8J9qE86bbarc97fcbaia8J9c8L1:NfgiRbbag9cjjjjjd:dg8J9qE86bbarc98fcbaia8J9c8K1:NfgiRbbag9cjjjjje:dg8J9qE86bbarc99fcbaia8J9c8J1:NfgiRbbag9cjjjj;ab:dg8J9qE86bbarc9:fcbaia8J9cg1:NfgiRbbag9cjjjja:dg8J9qE86bbarcufcbaia8J9ch1:NfgiRbbag9cjjjjz:dgg9qE86bbaiag9ca1:NfhixikaraiRblaiRbbghco4g8Ka8KciSg8KE86bbaqaofgrcGfaiclfa8Kfg8KRbbahcl4ciGg8La8LciSg8LE86bbarcVfa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc7fa8Ka8Lfg8KRbbahciGghahciSghE86bbarctfa8Kahfg8KRbbaiRbeghco4g8La8LciSg8LE86bbarc91fa8Ka8Lfg8KRbbahcl4ciGg8La8LciSg8LE86bbarc4fa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc93fa8Ka8Lfg8KRbbahciGghahciSghE86bbarc94fa8Kahfg8KRbbaiRbdghco4g8La8LciSg8LE86bbarc95fa8Ka8Lfg8KRbbahcl4ciGg8La8LciSg8LE86bbarc96fa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc97fa8Ka8Lfg8KRbbahciGghahciSghE86bbarc98fa8KahfghRbbaiRbigico4g8Ka8KciSg8KE86bbarc99faha8KfghRbbaicl4ciGg8Ka8KciSg8KE86bbarc9:faha8KfghRbbaicd4ciGg8Ka8KciSg8KE86bbarcufaha8KfgrRbbaiciGgiaiciSgiE86bbaraifhixdkaraiRbwaiRbbghcl4g8Ka8KcsSg8KE86bbaqaofgrcGfaicwfa8Kfg8KRbbahcsGghahcsSghE86bbarcVfa8KahfghRbbaiRbeg8Kcl4g8La8LcsSg8LE86bbarc7faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarctfaha8KfghRbbaiRbdg8Kcl4g8La8LcsSg8LE86bbarc91faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc4faha8KfghRbbaiRbig8Kcl4g8La8LcsSg8LE86bbarc93faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc94faha8KfghRbbaiRblg8Kcl4g8La8LcsSg8LE86bbarc95faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc96faha8KfghRbbaiRbvg8Kcl4g8La8LcsSg8LE86bbarc97faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc98faha8KfghRbbaiRbog8Kcl4g8La8LcsSg8LE86bbarc99faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc9:faha8KfghRbbaiRbrgicl4g8Ka8KcsSg8KE86bbarcufaha8KfgrRbbaicsGgiaicsSgiE86bbaraifhixekarai8Pbw83bwarai8Pbb83bbaiczfhikdnaoaC9pmbalcdfhlaoczfhraPai9RcL0mekkaoaC6moaimexokaCmva8FTmvkaqaAfhqa8Ecefg8Ecl9hmbkdndndndnawTmbasaYcd4fRbbgociGPlbedrbkaATmdazaYfh8Fazcjdfhhcbh8EaEhaina8FRbbhraahocbhlinaoahalfRbbgqce4cbaqceG9R7arfgr86bbaoadfhoaAalcefgl9hmbkaacefhaa8Fcefh8FahaAfhha8Ecefg8Ecl9hmbxikkaATmeazaYfhaazcjdfhhcbhoceh8EaKh8FinaEaofhlaa8Vbbhrcbhoinala8FaofRbbcwtahaofRbbgqVc;:FiGce4cbaqceG9R7arfgr87bbaladfhlaQaocefgofmbka8FaXfh8FcdhoaacdfhaahaXfhha8EceGhlcbh8EalmbxdkkaATmbaocl4h8EazaYfRbbhqcwhoa3hlinalRbbaotaqVhqalcefhlaocwfgoca9hmbkcbhhaEh8FaKhainazcjdfahfRbbhrcwhoaahlinalRbbaotarVhralaAfhlaocwfgoca9hmbkara8E94aq7hqcbhoa8Fhlinalaqao486bbalcefhlaocwfgoca9hmbka8Fadfh8FaacefhaahcefghaA9hmbkkaEclfhEa3clfh3aYclfgYad6mbkaza8AaAcufad2fadz:jjjjb8AaAaOfhOaihxaimbkc9:hoxdkcbc99aPax9RakSEhoxekc9:hokavcjqf8Kjjjjbaok:bsesu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnalaeci9UgrcHf6mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgwce0mbavc;abfcFecjez:kjjjb8Aav9cu83iUav9cu83i8Wav9cu83iyav9cu83iaav9cu83iKav9cu83izav9cu83iwav9cu83ibaialfc9WfhDaicefgiarfhqdndnaeci9pmbaqhexekcmcsawceSEhkcbhxcbhmaqhecbhlcbhoindndnaiRbbgrc;Ve0mbavc;abfaoarcu7gPcl4fcsGcitfgwydlhsawydbhzdndnarcsGgwak9pmbavalaPfcsGcdtfydbaxawEhraxawTgHfhxxekdnaeaD9nmbc9:hoxokdndnawcsSmbcehHamawcetfcWfhrxekaecefhrae8SbbgwcFeGhPdndnawcu9mmbarhexekaecvfheaPcFbGhPcrhwdninar8SbbgHcFbGawtaPVhPaHcu9kmearcefhrawcrfgwc8J9hmbxdkkarcefhekcehHaPce4cbaPceG9R7amfhrkarhmkavc;abfaocitfgwarBdbawasBdlavalcdtfarBdbavc;abfaocefcsGcitfgwazBdbawarBdlaocdfhoaHalfhldnadcd9hmbabar87elabas87edabaz87ebabcofhbxdkabarBdwabasBdlabazBdbabcxfhbxekdnarcpe0mbavalaDarcsGfRbbgwcl4gP9RcsGcdtfydbaxcefgsaPEhravalaw9RcsGcdtfydbasaPTgzfgsawcsGgPEhwaPThPdndnadcd9hmbabaw87elabar87edabax87ebcohHxekabawBdwabarBdlabaxBdbcxhHkavalcdtfaxBdbavc;abfaocitfgOarBdbaOaxBdlavalcefglcsGcdtfarBdbavc;abfaocefcsGcitfgOawBdbaOarBdlavalazfglcsGcdtfawBdbavc;abfaocdfcsGcitfgraxBdbarawBdlaocifhoabaHfhbalaPfhlasaPfhxxekdnaeaD9nmbc9:hoxlkaxcbaeRbbgwEgHarc;:eSgrfhsawcsGhOdndnawcl4gAmbascefhzxekashzavalaA9RcsGcdtfydbhskdndnaOmbazcefhxxekazhxavalaw9RcsGcdtfydbhzkdndnarTmbaecefhrxekaecdfhrae8SbegPcFeGhwdnaPcu9kmbaecofhHawcFbGhwcrhedninar8SbbgPcFbGaetawVhwaPcu9kmearcefhraecrfgec8J9hmbkaHhrxekarcefhrkawce4cbawceG9R7amfgmhHkdndnaAcsSmbarhwxekarcefhwar8SbbgecFeGhPdnaecu9kmbarcvfhsaPcFbGhPcrhedninaw8SbbgrcFbGaetaPVhParcu9kmeawcefhwaecrfgec8J9hmbkashwxekawcefhwkaPce4cbaPceG9R7amfgmhskdndnaOcsSmbawhexekawcefheaw8SbbgrcFeGhPdnarcu9kmbawcvfhzaPcFbGhPcrhrdninae8SbbgwcFbGartaPVhPawcu9kmeaecefhearcrfgrc8J9hmbkazhexekaecefhekaPce4cbaPceG9R7amfgmhzkdndnadcd9hmbabaz87elabas87edabaH87ebcohrxekabazBdwabasBdlabaHBdbcxhrkavc;abfaocitfgwasBdbawaHBdlavalcdtfaHBdbavc;abfaocefcsGcitfgwazBdbawasBdlavalcefglcsGcdtfasBdbavc;abfaocdfcsGcitfgwaHBdbawazBdlavalaATaAcsSVfglcsGcdtfazBdbalaOTaOcsSVfhlaocifhoabarfhbkaocsGhoalcsGhlaicefgiaq6mbkkcbc99aeaDSEhokavc;aef8Kjjjjbaok:clevu8Jjjjjbcz9Rhvdnalaecvf9pmbc9:skdnaiRbbc;:eGc;qeSmbcuskav9cb83iwaicefhoaialfc98fhrdnaeTmbdnadcdSmbcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcdtfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgiBdbalaiBdbawcefgwae9hmbxdkkcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcetfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgi87ebalaiBdbawcefgwae9hmbkkcbc99aoarSEk:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk:4ioiue99dud99dud99dnaeTmbcbhiabhlindndnal8Uebgv:YgoJ:ji:1Salcof8UebgrciVgw:Y:vgDNJbbbZJbbb:;avcu9kEMgq:lJbbb9p9DTmbaq:Ohkxekcjjjj94hkkalclf8Uebhvalcdf8UebhxalarcefciGcetfak87ebdndnax:YgqaDNJbbbZJbbb:;axcu9kEMgm:lJbbb9p9DTmbam:Ohxxekcjjjj94hxkabaiarciGgkfcd7cetfax87ebdndnav:YgmaDNJbbbZJbbb:;avcu9kEMgP:lJbbb9p9DTmbaP:Ohvxekcjjjj94hvkalarcufciGcetfav87ebdndnawaw2:ZgPaPMaoaoN:taqaqN:tamamN:tgoJbbbbaoJbbbb9GE:raDNJbbbZMgD:lJbbb9p9DTmbaD:Ohrxekcjjjj94hrkalakcetfar87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2gdTmbinababydbgecwtcw91:Yaece91cjjj98Gcjjj;8if::NUdbabclfhbadcufgdmbkkk:Tvirud99eudndnadcl9hmbaeTmeindndnabRbbgiabcefgl8Sbbgvabcdfgo8Sbbgrf9R:YJbbuJabcifgwRbbgdce4adVgDcd4aDVgDcl4aDVgD:Z:vgqNJbbbZMgk:lJbbb9p9DTmbak:Ohxxekcjjjj94hxkaoax86bbdndnaraif:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohoxekcjjjj94hokalao86bbdndnavaifar9R:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohixekcjjjj94hikabai86bbdndnaDadcetGadceGV:ZaqNJbbbZMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkawad86bbabclfhbaecufgembxdkkaeTmbindndnab8Vebgiabcdfgl8Uebgvabclfgo8Uebgrf9R:YJbFu9habcofgw8Vebgdce4adVgDcd4aDVgDcl4aDVgDcw4aDVgD:Z:vgqNJbbbZMgk:lJbbb9p9DTmbak:Ohxxekcjjjj94hxkaoax87ebdndnaraif:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohoxekcjjjj94hokalao87ebdndnavaifar9R:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohixekcjjjj94hikabai87ebdndnaDadcetGadceGV:ZaqNJbbbZMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkawad87ebabcwfhbaecufgembkkk9teiucbcbyd:K:G:cjbgeabcifc98GfgbBd:K:G:cjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaeczfheaiczfhiadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkk83dbcj:Gdk8Kbbbbdbbblbbbwbbbbbbbebbbdbbblbbbwbbbbc:K:Gdkl8W:qbb"),i=WebAssembly.instantiate(r,{}).then(function(e){(n=e.instance).exports.__wasm_call_ctors()});function a(e){for(var n=new Uint8Array(e.length),r=0;r<e.length;++r){var i=e.charCodeAt(r);n[r]=i>96?i-97:i>64?i-39:i+4}var a=0;for(r=0;r<e.length;++r)n[a++]=n[r]<60?t[n[r]]:64*(n[r]-60)+n[++r];return n.buffer.slice(0,a)}function s(e,t,n,r,i,a,s){var o=e.exports.sbrk,A=r+3&-4,l=o(A*i),c=o(a.length),u=new Uint8Array(e.exports.memory.buffer);u.set(a,c);var f=t(l,r,i,c,a.length);if(0==f&&s&&s(l,A,i),n.set(u.subarray(l,l+r*i)),o(l-o(0)),0!=f)throw new Error("Malformed buffer data: "+f)}var o={NONE:"",OCTAHEDRAL:"meshopt_decodeFilterOct",QUATERNION:"meshopt_decodeFilterQuat",EXPONENTIAL:"meshopt_decodeFilterExp",COLOR:"meshopt_decodeFilterColor"},A={ATTRIBUTES:"meshopt_decodeVertexBuffer",TRIANGLES:"meshopt_decodeIndexBuffer",INDICES:"meshopt_decodeIndexSequence"},l=[],c=0;function u(e){var t={object:new Worker(e),pending:0,requests:{}};return t.object.onmessage=function(e){var n=e.data;t.pending-=n.count,t.requests[n.id][n.action](n.value),delete t.requests[n.id]},t}function f(e){var t=e.data;self.ready.then(function(e){if(!t.id)return self.close();try{var n=new Uint8Array(t.count*t.size);s(e,e.exports[t.mode],n,t.count,t.size,t.source,e.exports[t.filter]),self.postMessage({id:t.id,count:t.count,action:"resolve",value:n},[n.buffer])}catch(r){self.postMessage({id:t.id,count:t.count,action:"reject",value:r})}})}return{ready:i,supported:!0,useWorkers:function(e){!function(e){for(var t="self.ready = WebAssembly.instantiate(new Uint8Array(["+new Uint8Array(r)+"]), {}).then(function(result) { result.instance.exports.__wasm_call_ctors(); return result.instance; });self.onmessage = "+f.name+";"+s.toString()+f.toString(),n=new Blob([t],{type:"text/javascript"}),i=URL.createObjectURL(n),a=l.length;a<e;++a)l[a]=u(i);for(a=e;a<l.length;++a)l[a].object.postMessage({});l.length=e,URL.revokeObjectURL(i)}(e)},decodeVertexBuffer:function(e,t,r,i,a){s(n,n.exports.meshopt_decodeVertexBuffer,e,t,r,i,n.exports[o[a]])},decodeIndexBuffer:function(e,t,r,i){s(n,n.exports.meshopt_decodeIndexBuffer,e,t,r,i)},decodeIndexSequence:function(e,t,r,i){s(n,n.exports.meshopt_decodeIndexSequence,e,t,r,i)},decodeGltfBuffer:function(e,t,r,i,a,l){s(n,n.exports[A[a]],e,t,r,i,n.exports[o[l]])},decodeGltfBufferAsync:function(e,t,r,a,u){return l.length>0?function(e,t,n,r,i){for(var a=l[0],s=1;s<l.length;++s)l[s].pending<a.pending&&(a=l[s]);return new Promise(function(s,o){var A=new Uint8Array(n),l=++c;a.pending+=e,a.requests[l]={resolve:s,reject:o},a.object.postMessage({id:l,count:e,size:t,source:A,mode:r,filter:i},[A.buffer])})}(e,t,r,A[a],o[u]):i.then(function(){var i=new Uint8Array(e*t);return s(n,n.exports[A[a]],i,e,t,r,n.exports[o[u]]),i})}}}();function sf(e,t){if(!e)throw new Error(t||"assert failed: gltf")}var of={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Af={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},lf=["SCALAR","VEC2","VEC3","VEC4"],cf=/* @__PURE__ */new Map([[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126],[Float64Array,5130]]),uf={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},ff={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},df={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function hf(e){return lf[e-1]||lf[0]}function pf(e){const t=cf.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}function mf(e,t){const n=df[e.componentType],r=uf[e.type],i=ff[e.componentType],a=e.count*r,s=e.count*r*i;return sf(s>=0&&s<=t.byteLength),{ArrayType:n,length:a,byteLength:s,componentByteSize:Af[e.componentType],numberOfComponentsInElement:of[e.type]}}function gf(e){let{images:t,bufferViews:n}=e;t=t||[],n=n||[];const r=t.map(e=>e.bufferView);n=n.filter(e=>!r.includes(e));const i=n.reduce((e,t)=>e+t.byteLength,0),a=t.reduce((e,t)=>{const{width:n,height:r}=t.image;return e+n*r},0);return i+Math.ceil(4*a*1.33)}var bf=class{gltf;sourceBuffers;byteLength;constructor(e){this.gltf={json:e?.json||{asset:{version:"2.0",generator:"loaders.gl"},buffers:[],extensions:{},extensionsRequired:[],extensionsUsed:[]},buffers:e?.buffers||[],images:e?.images||[]},this.sourceBuffers=[],this.byteLength=0,this.gltf.buffers&&this.gltf.buffers[0]&&(this.byteLength=this.gltf.buffers[0].byteLength,this.sourceBuffers=[this.gltf.buffers[0]])}get json(){return this.gltf.json}getApplicationData(e){return this.json[e]}getExtraData(e){return(this.json.extras||{})[e]}hasExtension(e){const t=this.getUsedExtensions().find(t=>t===e),n=this.getRequiredExtensions().find(t=>t===e);return"string"==typeof t||"string"==typeof n}getExtension(e){const t=this.getUsedExtensions().find(t=>t===e),n=this.json.extensions||{};return t?n[e]:null}getRequiredExtension(e){return this.getRequiredExtensions().find(t=>t===e)?this.getExtension(e):null}getRequiredExtensions(){return this.json.extensionsRequired||[]}getUsedExtensions(){return this.json.extensionsUsed||[]}getRemovedExtensions(){return this.json.extensionsRemoved||[]}getObjectExtension(e,t){return(e.extensions||{})[t]}getScene(e){return this.getObject("scenes",e)}getNode(e){return this.getObject("nodes",e)}getSkin(e){return this.getObject("skins",e)}getMesh(e){return this.getObject("meshes",e)}getMaterial(e){return this.getObject("materials",e)}getAccessor(e){return this.getObject("accessors",e)}getTexture(e){return this.getObject("textures",e)}getSampler(e){return this.getObject("samplers",e)}getImage(e){return this.getObject("images",e)}getBufferView(e){return this.getObject("bufferViews",e)}getBuffer(e){return this.getObject("buffers",e)}getObject(e,t){if("object"==typeof t)return t;const n=this.json[e]&&this.json[e][t];if(!n)throw new Error(`glTF file error: Could not find ${e}[${t}]`);return n}getTypedArrayForBufferView(e){const t=(e=this.getBufferView(e)).buffer,n=this.gltf.buffers[t];sf(n);const r=(e.byteOffset||0)+n.byteOffset;return new Uint8Array(n.arrayBuffer,r,e.byteLength)}getTypedArrayForAccessor(e){const t=this.getAccessor(e);return function(e,t,n){const r="number"==typeof n?e.accessors?.[n]:n;if(!r)throw new Error(`No gltf accessor ${JSON.stringify(n)}`);const i=e.bufferViews?.[r.bufferView||0];if(!i)throw new Error(`No gltf buffer view for accessor ${i}`);const{arrayBuffer:a,byteOffset:s}=t[i.buffer],o=(s||0)+(r.byteOffset||0)+(i.byteOffset||0),{ArrayType:A,length:l,componentByteSize:c,numberOfComponentsInElement:u}=mf(r,i),f=c*u,d=i.byteStride||f;if(void 0===i.byteStride||i.byteStride===f)return new A(a,o,l);const h=new A(l);for(let p=0;p<r.count;p++){const e=new A(a,o+p*d,u);h.set(e,p*u)}return h}(this.gltf.json,this.gltf.buffers,t)}getTypedArrayForImageData(e){e=this.getAccessor(e);const t=this.getBufferView(e.bufferView),n=this.getBuffer(t.buffer).data,r=t.byteOffset||0;return new Uint8Array(n,r,t.byteLength)}addApplicationData(e,t){return this.json[e]=t,this}addExtraData(e,t){return this.json.extras=this.json.extras||{},this.json.extras[e]=t,this}addObjectExtension(e,t,n){return e.extensions=e.extensions||{},e.extensions[t]=n,this.registerUsedExtension(t),this}setObjectExtension(e,t,n){(e.extensions||{})[t]=n}removeObjectExtension(e,t){const n=e?.extensions||{};if(n[t]){this.json.extensionsRemoved=this.json.extensionsRemoved||[];const e=this.json.extensionsRemoved;e.includes(t)||e.push(t)}delete n[t]}addExtension(e,t={}){return sf(t),this.json.extensions=this.json.extensions||{},this.json.extensions[e]=t,this.registerUsedExtension(e),t}addRequiredExtension(e,t={}){return sf(t),this.addExtension(e,t),this.registerRequiredExtension(e),t}registerUsedExtension(e){this.json.extensionsUsed=this.json.extensionsUsed||[],this.json.extensionsUsed.find(t=>t===e)||this.json.extensionsUsed.push(e)}registerRequiredExtension(e){this.registerUsedExtension(e),this.json.extensionsRequired=this.json.extensionsRequired||[],this.json.extensionsRequired.find(t=>t===e)||this.json.extensionsRequired.push(e)}removeExtension(e){if(this.json.extensions?.[e]){this.json.extensionsRemoved=this.json.extensionsRemoved||[];const t=this.json.extensionsRemoved;t.includes(e)||t.push(e)}this.json.extensions&&delete this.json.extensions[e],this.json.extensionsRequired&&this._removeStringFromArray(this.json.extensionsRequired,e),this.json.extensionsUsed&&this._removeStringFromArray(this.json.extensionsUsed,e)}setDefaultScene(e){this.json.scene=e}addScene(e){const{nodeIndices:t}=e;return this.json.scenes=this.json.scenes||[],this.json.scenes.push({nodes:t}),this.json.scenes.length-1}addNode(e){const{meshIndex:t,matrix:n}=e;this.json.nodes=this.json.nodes||[];const r={mesh:t};return n&&(r.matrix=n),this.json.nodes.push(r),this.json.nodes.length-1}addMesh(e){const{attributes:t,indices:n,material:r,mode:i=4}=e,a={primitives:[{attributes:this._addAttributes(t),mode:i}]};if(n){const e=this._addIndices(n);a.primitives[0].indices=e}return Number.isFinite(r)&&(a.primitives[0].material=r),this.json.meshes=this.json.meshes||[],this.json.meshes.push(a),this.json.meshes.length-1}addPointCloud(e){const t={primitives:[{attributes:this._addAttributes(e),mode:0}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(t),this.json.meshes.length-1}addImage(e,t){const n=Be(e),r=t||n?.mimeType,i={bufferView:this.addBufferView(e),mimeType:r};return this.json.images=this.json.images||[],this.json.images.push(i),this.json.images.length-1}addBufferView(e,t=0,n=this.byteLength){const r=e.byteLength;sf(Number.isFinite(r)),this.sourceBuffers=this.sourceBuffers||[],this.sourceBuffers.push(e);const i={buffer:t,byteOffset:n,byteLength:r};return this.byteLength+=st(r,4),this.json.bufferViews=this.json.bufferViews||[],this.json.bufferViews.push(i),this.json.bufferViews.length-1}addAccessor(e,t){const n={bufferView:e,type:hf(t.size),componentType:t.componentType,count:t.count,max:t.max,min:t.min};return this.json.accessors=this.json.accessors||[],this.json.accessors.push(n),this.json.accessors.length-1}addBinaryBuffer(e,t={size:3}){const n=this.addBufferView(e);let r={min:t.min,max:t.max};r.min&&r.max||(r=this._getAccessorMinMax(e,t.size));const i={size:t.size,componentType:pf(e),count:Math.round(e.length/t.size),min:r.min,max:r.max};return this.addAccessor(n,Object.assign(i,t))}addTexture(e){const{imageIndex:t}=e,n={source:t};return this.json.textures=this.json.textures||[],this.json.textures.push(n),this.json.textures.length-1}addMaterial(e){return this.json.materials=this.json.materials||[],this.json.materials.push(e),this.json.materials.length-1}createBinaryChunk(){const e=this.byteLength,t=new ArrayBuffer(e),n=new Uint8Array(t);let r=0;for(const i of this.sourceBuffers||[])r=ot(i,n,r);this.json?.buffers?.[0]?this.json.buffers[0].byteLength=e:this.json.buffers=[{byteLength:e}],this.gltf.binary=t,this.sourceBuffers=[t],this.gltf.buffers=[{arrayBuffer:t,byteOffset:0,byteLength:t.byteLength}]}_removeStringFromArray(e,t){let n=!0;for(;n;){const r=e.indexOf(t);r>-1?e.splice(r,1):n=!1}}_addAttributes(e={}){const t={};for(const n in e){const r=e[n];t[this._getGltfAttributeName(n)]=this.addBinaryBuffer(r.value,r)}return t}_addIndices(e){return this.addBinaryBuffer(e,{size:1})}_getGltfAttributeName(e){switch(e.toLowerCase()){case"position":case"positions":case"vertices":return"POSITION";case"normal":case"normals":return"NORMAL";case"color":case"colors":return"COLOR_0";case"texcoord":case"texcoords":return"TEXCOORD_0";default:return e}}_getAccessorMinMax(e,t){const n={min:null,max:null};if(e.length<t)return n;n.min=[],n.max=[];const r=e.subarray(0,t);for(const i of r)n.min.push(i),n.max.push(i);for(let i=t;i<e.length;i+=t)for(let r=0;r<t;r++)n.min[0+r]=Math.min(n.min[0+r],e[i+r]),n.max[0+r]=Math.max(n.max[0+r],e[i+r]);return n}};function vf(e){return(e%1+1)%1}var yf={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16,BOOLEAN:1,STRING:1,ENUM:1},xf={INT8:Int8Array,UINT8:Uint8Array,INT16:Int16Array,UINT16:Uint16Array,INT32:Int32Array,UINT32:Uint32Array,INT64:BigInt64Array,UINT64:BigUint64Array,FLOAT32:Float32Array,FLOAT64:Float64Array},_f={INT8:1,UINT8:1,INT16:2,UINT16:2,INT32:4,UINT32:4,INT64:8,UINT64:8,FLOAT32:4,FLOAT64:8};function wf(e,t){return _f[t]*yf[e]}function Tf(e,t,n,r){if("UINT8"!==n&&"UINT16"!==n&&"UINT32"!==n&&"UINT64"!==n)return null;const i=Sf(e.getTypedArrayForBufferView(t),"SCALAR",n,r+1);return i instanceof BigInt64Array||i instanceof BigUint64Array?null:i}function Sf(e,t,n,r=1){const i=xf[n],a=_f[n],s=r*yf[t],o=s*a;let A=e.buffer,l=e.byteOffset;return l%a!==0&&(A=new Uint8Array(A).slice(l,l+o).buffer,l=0),new i(ue(A),l,s)}function Mf(e,t,n){const r=`TEXCOORD_${t.texCoord||0}`,i=n.attributes[r],a=e.getTypedArrayForAccessor(i),s=e.gltf.json,o=t.index,A=s.textures?.[o]?.source;if(void 0!==A){const n=s.images?.[A]?.mimeType,r=e.gltf.images?.[A];if(r&&void 0!==r.width){const e=[];for(let i=0;i<a.length;i+=2){const s=Cf(r,n,a,i,t.channels);e.push(s)}return e}}return[]}function Ef(e,t,n,r,i){if(!n?.length)return;const a=[];for(const c of n){let e=r.findIndex(e=>e===c);-1===e&&(e=r.push(c)-1),a.push(e)}const s=new Uint32Array(a),o=e.gltf.buffers.push({arrayBuffer:s.buffer,byteOffset:s.byteOffset,byteLength:s.byteLength})-1,A=e.addBufferView(s,o,0),l=e.addAccessor(A,{size:1,componentType:pf(s),count:s.length});i.attributes[t]=l}function Cf(e,t,n,r,i=[0]){const a={r:{offset:0,shift:0},g:{offset:1,shift:8},b:{offset:2,shift:16},a:{offset:3,shift:24}},s=n[r],o=n[r+1];let A=1;!t||-1===t.indexOf("image/jpeg")&&-1===t.indexOf("image/png")||(A=4);const l=function(e,t,n,r=1){const i=n.width,a=vf(e)*(i-1),s=Math.round(a),o=n.height,A=vf(t)*(o-1),l=Math.round(A),c=n.components?n.components:r;return(l*i+s)*c}(s,o,e,A);let c=0;for(const u of i){const t="number"==typeof u?Object.values(a)[u]:a[u],n=l+t.offset,r=ke(e);if(r.data.length<=n)throw new Error(`${r.data.length} <= ${n}`);c|=r.data[n]<<t.shift}return c}function If(e,t,n,r,i){const a=[];for(let s=0;s<t;s++){const t=n[s],o=n[s+1]-n[s];if(o+t>r)break;const A=t/i,l=o/i;a.push(e.slice(A,A+l))}return a}function Rf(e,t,n){const r=[];for(let i=0;i<t;i++){const t=i*n;r.push(e.slice(t,t+n))}return r}function Pf(e,t,n,r){if(n)throw new Error("Not implemented - arrayOffsets for strings is specified");if(r){const n=[],i=new TextDecoder("utf8");let a=0;for(let s=0;s<e;s++){const e=r[s+1]-r[s];if(e+a<=t.length){const r=t.subarray(a,e+a),s=i.decode(r);n.push(s),a+=e}}return n}return[]}var Nf=/* @__PURE__ */t({createExtMeshFeatures:()=>Df,decode:()=>Bf,encode:()=>Of,name:()=>Lf}),kf="EXT_mesh_features",Lf=kf;async function Bf(e,t){!function(e,t){const n=e.gltf.json;if(!n.meshes)return;for(const r of n.meshes)for(const n of r.primitives)Ff(e,n,t)}(new bf(e),t)}function Of(e,t){const n=new bf(e);return function(e){const t=e.gltf.json.meshes;if(!t)return;for(const n of t)for(const t of n.primitives)Uf(e,t)}(n),n.createBinaryChunk(),n.gltf}function Ff(e,t,n){if(!n?.gltf?.loadBuffers)return;const r=(t.extensions?.[kf])?.featureIds;if(r)for(const i of r){let r;if(void 0!==i.attribute){const n=`_FEATURE_ID_${i.attribute}`,a=t.attributes[n];r=e.getTypedArrayForAccessor(a)}else r=void 0!==i.texture&&n?.gltf?.loadImages?Mf(e,i.texture,t):[];i.data=r}}function Df(e,t,n,r){t.extensions||(t.extensions={});let i=t.extensions[kf];i||(i={featureIds:[]},t.extensions[kf]=i);const{featureIds:a}=i,s={featureCount:n.length,propertyTable:r,data:n};a.push(s),e.addObjectExtension(t,kf,i)}function Uf(e,t){const n=t.extensions?.[kf];if(!n)return;const r=n.featureIds;r.forEach((n,i)=>{if(n.data){const{accessorKey:a,index:s}=function(e){const t="_FEATURE_ID_",n=Object.keys(e).filter(e=>0===e.indexOf(t));let r=-1;for(const i of n){const e=Number(i.substring(12));e>r&&(r=e)}return r++,{accessorKey:`${t}${r}`,index:r}}(t.attributes),o=new Uint32Array(n.data);r[i]={featureCount:o.length,propertyTable:n.propertyTable,attribute:s},e.gltf.buffers.push({arrayBuffer:o.buffer,byteOffset:o.byteOffset,byteLength:o.byteLength});const A=e.addBufferView(o),l=e.addAccessor(A,{size:1,componentType:pf(o),count:o.length});t.attributes[a]=l}})}var Vf=/* @__PURE__ */t({createExtStructuralMetadata:()=>ed,decode:()=>Gf,encode:()=>Hf,name:()=>zf}),jf="EXT_structural_metadata",zf=jf;async function Gf(e,t){!function(e,t){if(!t.gltf?.loadBuffers)return;const n=e.getExtension(jf);if(!n)return;t.gltf?.loadImages&&function(e,t){const n=t.propertyTextures,r=e.gltf.json;if(n&&r.meshes)for(const i of r.meshes)for(const r of i.primitives)Qf(e,n,r,t)}(e,n);!function(e,t){const n=t.schema;if(!n)return;const r=n.classes,i=t.propertyTables;if(r&&i)for(const a in r){const t=qf(i,a);t&&Wf(e,n,t)}}(e,n)}(new bf(e),t)}function Hf(e,t){const n=new bf(e);return function(e){const t=e.getExtension(jf);if(!t)return;if(t.propertyTables)for(const n of t.propertyTables){const r=n.class,i=t.schema?.classes?.[r];n.properties&&i&&Zf(n,i,e)}}(n),n.createBinaryChunk(),n.gltf}function qf(e,t){for(const n of e)if(n.class===t)return n;return null}function Qf(e,t,n,r){if(!t)return;const i=(n.extensions?.[jf])?.propertyTextures;if(i)for(const a of i){Kf(e,t[a],n,r)}}function Kf(e,t,n,r){if(!t.properties)return;r.dataAttributeNames||(r.dataAttributeNames=[]);const i=t.class;for(const a in t.properties){const s=`${i}_${a}`,o=t.properties?.[a];if(!o)continue;o.data||(o.data=[]);const A=o.data,l=Mf(e,o,n);null!==l&&(Ef(e,s,l,A,n),o.data=A,r.dataAttributeNames.push(s))}}function Wf(e,t,n){const r=t.classes?.[n.class];if(!r)throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${n.class}`);const i=n.count;for(const a in r.properties){const s=r.properties[a],o=n.properties?.[a];o&&(o.data=Jf(e,t,s,i,o))}}function Jf(e,t,n,r,i){let a=[];const s=i.values,o=e.getTypedArrayForBufferView(s),A=function(e,t,n,r){return t.array&&void 0===t.count&&void 0!==n.arrayOffsets?Tf(e,n.arrayOffsets,n.arrayOffsetType||"UINT32",r):null}(e,n,i,r),l=function(e,t,n){return void 0!==t.stringOffsets?Tf(e,t.stringOffsets,t.stringOffsetType||"UINT32",n):null}(e,i,r);switch(n.type){case"SCALAR":case"VEC2":case"VEC3":case"VEC4":case"MAT2":case"MAT3":case"MAT4":a=function(e,t,n,r){const i=e.array,a=e.count,s=wf(e.type,e.componentType),o=n.byteLength/s;let A;A=e.componentType?Sf(n,e.type,e.componentType,o):n;if(i)return r?If(A,t,r,n.length,s):a?Rf(A,t,a):[];return A}(n,r,o,A);break;case"BOOLEAN":throw new Error(`Not implemented - classProperty.type=${n.type}`);case"STRING":a=Pf(r,o,A,l);break;case"ENUM":a=function(e,t,n,r,i){const a=t.enumType;if(!a)throw new Error("Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM");const s=e.enums?.[a];if(!s)throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${a}`);const o=s.valueType||"UINT16",A=wf(t.type,o),l=r.byteLength/A;let c=Sf(r,t.type,o,l);c||(c=r);if(t.array){if(i)return function(e){const{valuesData:t,numberOfElements:n,arrayOffsets:r,valuesDataBytesLength:i,elementSize:a,enumEntry:s}=e,o=[];for(let A=0;A<n;A++){const e=r[A],n=r[A+1]-r[A];if(n+e>i)break;const l=$f(t,e/a,n/a,s);o.push(l)}return o}({valuesData:c,numberOfElements:n,arrayOffsets:i,valuesDataBytesLength:r.length,elementSize:A,enumEntry:s});const e=t.count;return e?function(e,t,n,r){const i=[];for(let a=0;a<t;a++){const t=$f(e,n*a,n,r);i.push(t)}return i}(c,n,e,s):[]}return $f(c,0,n,s)}(t,n,r,o,A);break;default:throw new Error(`Unknown classProperty type ${n.type}`)}return a}function $f(e,t,n,r){const i=[];for(let a=0;a<n;a++)if(e instanceof BigInt64Array||e instanceof BigUint64Array)i.push("");else{const n=Xf(r,e[t+a]);n?i.push(n.name):i.push("")}return i}function Xf(e,t){for(const n of e.values)if(n.value===t)return n;return null}var Yf="schemaClassId";function Zf(e,t,n){for(const r in e.properties){const i=e.properties[r].data;if(i){const a=t.properties[r];if(a){const t=td(i,a,n);e.properties[r]=t}}}}function ed(e,t,n=Yf){let r=e.getExtension(jf);r||(r=e.addExtension(jf)),r.schema=function(e,t,n){const r=n??{id:"schema_id"},i={properties:{}};for(const a of e){const e={type:a.elementType,componentType:a.componentType};i.properties[a.name]=e}return r.classes={},r.classes[t]=i,r}(t,n,r.schema);const i=function(e,t,n){const r={class:t,count:0};let i=0;const a=n.classes?.[t];for(const s of e){if(0===i&&(i=s.values.length),i!==s.values.length&&s.values.length)throw new Error("Illegal values in attributes");a?.properties[s.name]&&(r.properties||(r.properties={}),r.properties[s.name]={values:0,data:s.values})}return r.count=i,r}(t,n,r.schema);return r.propertyTables||(r.propertyTables=[]),r.propertyTables.push(i)-1}function td(e,t,n){const r={values:0};if("STRING"===t.type){const{stringData:t,stringOffsets:i}=function(e){const t=new TextEncoder,n=[];let r=0;for(const o of e){const e=t.encode(o);r+=e.length,n.push(e)}const i=new Uint8Array(r),a=[];let s=0;for(const o of n)i.set(o,s),a.push(s),s+=o.length;return a.push(s),{stringData:i,stringOffsets:new Uint32Array(a)}}(e);r.stringOffsets=rd(i,n),r.values=rd(t,n)}else"SCALAR"===t.type&&t.componentType&&(r.values=rd(function(e,t){const n=[];for(const i of e)n.push(Number(i));const r=nd[t];if(!r)throw new Error("Illegal component type");return new r(n)}(e,t.componentType),n));return r}var nd={INT8:Int8Array,UINT8:Uint8Array,INT16:Int16Array,UINT16:Uint16Array,INT32:Int32Array,UINT32:Uint32Array,INT64:Int32Array,UINT64:Uint32Array,FLOAT32:Float32Array,FLOAT64:Float64Array};function rd(e,t){return t.gltf.buffers.push({arrayBuffer:ue(e.buffer),byteOffset:e.byteOffset,byteLength:e.byteLength}),t.addBufferView(e)}var id=/* @__PURE__ */t({decode:()=>od,name:()=>sd}),ad="EXT_feature_metadata",sd=ad;async function od(e,t){!function(e,t){if(!t.gltf?.loadBuffers)return;const n=e.getExtension(ad);if(!n)return;t.gltf?.loadImages&&function(e,t){const n=t.schema;if(!n)return;const r=n.classes,{featureTextures:i}=t;if(r&&i)for(const a in r){const t=r[a],n=ld(i,a);n&&ud(e,n,t)}}(e,n);!function(e,t){const n=t.schema;if(!n)return;const r=n.classes,i=t.featureTables;if(r&&i)for(const a in r){const t=Ad(i,a);t&&cd(e,n,t)}}(e,n)}(new bf(e),t)}function Ad(e,t){for(const n in e){const r=e[n];if(r.class===t)return r}return null}function ld(e,t){for(const n in e){const r=e[n];if(r.class===t)return r}return null}function cd(e,t,n){if(!n.class)return;const r=t.classes?.[n.class];if(!r)throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${n.class}`);const i=n.count;for(const a in r.properties){const s=r.properties[a],o=n.properties?.[a];o&&(o.data=fd(e,t,s,i,o))}}function ud(e,t,n){const r=t.class;for(const i in n.properties){const n=t?.properties?.[i];n&&(n.data=dd(e,n,r))}}function fd(e,t,n,r,i){let a=[];const s=i.bufferView,o=e.getTypedArrayForBufferView(s),A=function(e,t,n,r){return"ARRAY"===t.type&&void 0===t.componentCount&&void 0!==n.arrayOffsetBufferView?Tf(e,n.arrayOffsetBufferView,n.offsetType||"UINT32",r):null}(e,n,i,r),l=function(e,t,n,r){return void 0!==n.stringOffsetBufferView?Tf(e,n.stringOffsetBufferView,n.offsetType||"UINT32",r):null}(e,0,i,r);return"STRING"===n.type||"STRING"===n.componentType?a=Pf(r,o,A,l):function(e){const t=["UINT8","INT16","UINT16","INT32","UINT32","INT64","UINT64","FLOAT32","FLOAT64"];return t.includes(e.type)||void 0!==e.componentType&&t.includes(e.componentType)}(n)&&(a=function(e,t,n,r){const i="ARRAY"===e.type,a=e.componentCount,s="SCALAR",o=e.componentType||e.type,A=wf(s,o),l=n.byteLength/A,c=Sf(n,s,o,l);if(i)return r?If(c,t,r,n.length,A):a?Rf(c,t,a):[];return c}(n,r,o,A)),a}function dd(e,t,n){const r=e.gltf.json;if(!r.meshes)return[];const i=[];for(const a of r.meshes)for(const r of a.primitives)hd(e,n,t,i,r);return i}function hd(e,t,n,r,i){const a=Mf(e,{channels:n.channels,...n.texture},i);a&&Ef(e,t,a,r,i)}var pd,md,gd="basis_transcoder.js",bd="basis_transcoder.wasm",vd="basis_encoder.js",yd="basis_encoder.wasm";async function xd(e){var t;t=e.modules,globalThis.loaders||={},globalThis.loaders.modules||={},Object.assign(globalThis.loaders.modules,t);const n=function(e){return globalThis.loaders?.modules?.[e]||null}("basis");return n||(pd||=async function(e){let t=null,n=null;return[t,n]=await Promise.all([await rt(gd,"textures",e),await rt(bd,"textures",e)]),t=t||globalThis.BASIS,await function(e,t){const n={};t&&(n.wasmBinary=t);return ft(()=>e(n),e=>{const{BasisFile:t,initializeBasis:n}=e;return n(),{BasisFile:t}})}(t,n)}(e),await pd)}async function _d(e){const t=e.modules||{};return t.basisEncoder?t.basisEncoder:(md=md||async function(e){let t=null,n=null;return[t,n]=await Promise.all([await rt(vd,"textures",e),await rt(yd,"textures",e)]),t=t||globalThis.BASIS,await function(e,t){const n={};t&&(n.wasmBinary=t);return ft(()=>e(n),e=>{const{BasisFile:t,KTX2File:n,BasisEncoder:r,initializeBasis:i}=e;return i(),{BasisFile:t,KTX2File:n,BasisEncoder:r}})}(t,n)}(e),await md)}var wd=["","WEBKIT_","MOZ_"],Td={WEBGL_compressed_texture_s3tc:["bc1-rgb-unorm-webgl","bc1-rgba-unorm","bc2-rgba-unorm","bc3-rgba-unorm"],WEBGL_compressed_texture_s3tc_srgb:["bc1-rgb-unorm-srgb-webgl","bc1-rgba-unorm-srgb","bc2-rgba-unorm-srgb","bc3-rgba-unorm-srgb"],EXT_texture_compression_rgtc:["bc4-r-unorm","bc4-r-snorm","bc5-rg-unorm","bc5-rg-snorm"],EXT_texture_compression_bptc:["bc6h-rgb-ufloat","bc6h-rgb-float","bc7-rgba-unorm","bc7-rgba-unorm-srgb"],WEBGL_compressed_texture_etc1:["etc1-rgb-unorm-webgl"],WEBGL_compressed_texture_etc:["etc2-rgb8unorm","etc2-rgb8unorm-srgb","etc2-rgb8a1unorm","etc2-rgb8a1unorm-srgb","etc2-rgba8unorm","etc2-rgba8unorm-srgb","eac-r11unorm","eac-r11snorm","eac-rg11unorm","eac-rg11snorm"],WEBGL_compressed_texture_pvrtc:["pvrtc-rgb4unorm-webgl","pvrtc-rgba4unorm-webgl","pvrtc-rgb2unorm-webgl","pvrtc-rgba2unorm-webgl"],WEBGL_compressed_texture_atc:["atc-rgb-unorm-webgl","atc-rgba-unorm-webgl","atc-rgbai-unorm-webgl"],WEBGL_compressed_texture_astc:["astc-4x4-unorm","astc-4x4-unorm-srgb","astc-5x4-unorm","astc-5x4-unorm-srgb","astc-5x5-unorm","astc-5x5-unorm-srgb","astc-6x5-unorm","astc-6x5-unorm-srgb","astc-6x6-unorm","astc-6x6-unorm-srgb","astc-8x5-unorm","astc-8x5-unorm-srgb","astc-8x6-unorm","astc-8x6-unorm-srgb","astc-8x8-unorm","astc-8x8-unorm-srgb","astc-10x5-unorm","astc-10x5-unorm-srgb","astc-10x6-unorm","astc-10x6-unorm-srgb","astc-10x8-unorm","astc-10x8-unorm-srgb","astc-10x10-unorm","astc-10x10-unorm-srgb","astc-12x10-unorm","astc-12x10-unorm-srgb","astc-12x12-unorm","astc-12x12-unorm-srgb"]},Sd=null;function Md(e){if(!Sd){e=e||function(){try{return document.createElement("canvas").getContext("webgl")}catch(e){return null}}()||void 0,Sd=/* @__PURE__ */new Set;for(const t of wd)for(const n in Td)if(e&&e.getExtension(`${t}${n}`))for(const e of Td[n])Sd.add(e)}return Sd}var Ed=[171,75,84,88,32,50,48,187,13,10,26,10];var Cd=Promise.resolve(),Id={etc1:{basisFormat:0,compressed:!0,format:36196,textureFormat:"etc1-rgb-unorm-webgl"},etc2:{basisFormat:1,compressed:!0,format:37493,textureFormat:"etc2-rgba8unorm"},bc1:{basisFormat:2,compressed:!0,format:33776,textureFormat:"bc1-rgb-unorm-webgl"},bc3:{basisFormat:3,compressed:!0,format:33779,textureFormat:"bc3-rgba-unorm"},bc4:{basisFormat:4,compressed:!0,format:36283,textureFormat:"bc4-r-unorm"},bc5:{basisFormat:5,compressed:!0,format:36285,textureFormat:"bc5-rg-unorm"},"bc7-m6-opaque-only":{basisFormat:6,compressed:!0,format:36492,textureFormat:"bc7-rgba-unorm"},"bc7-m5":{basisFormat:6,compressed:!0,format:36492,textureFormat:"bc7-rgba-unorm"},"pvrtc1-4-rgb":{basisFormat:8,compressed:!0,format:35840,textureFormat:"pvrtc-rgb4unorm-webgl"},"pvrtc1-4-rgba":{basisFormat:9,compressed:!0,format:35842,textureFormat:"pvrtc-rgba4unorm-webgl"},"astc-4x4":{basisFormat:10,compressed:!0,format:37808,textureFormat:"astc-4x4-unorm"},"atc-rgb":{basisFormat:11,compressed:!0,format:35986,textureFormat:"atc-rgb-unorm-webgl"},"atc-rgba-interpolated-alpha":{basisFormat:12,compressed:!0,format:34798,textureFormat:"atc-rgbai-unorm-webgl"},rgba32:{basisFormat:13,compressed:!1,format:32856,textureFormat:"rgba8unorm"},rgb565:{basisFormat:14,compressed:!1,format:36194,textureFormat:"rgb565unorm-webgl"},bgr565:{basisFormat:15,compressed:!1,format:36194,textureFormat:"rgb565unorm-webgl"},rgba4444:{basisFormat:16,compressed:!1,format:32854,textureFormat:"rgba4unorm-webgl"}};Object.freeze(Object.keys(Id));function Rd(e,t,n){const r=new e(new Uint8Array(t));try{if(!r.startTranscoding())throw new Error("Failed to start basis transcoding");const e=r.getNumImages(),t=[];for(let i=0;i<e;i++){const e=r.getNumLevels(i),a=[];for(let t=0;t<e;t++)a.push(Pd(r,i,t,n));t.push(a)}return t}finally{r.close(),r.delete()}}function Pd(e,t,n,r){const i=e.getImageWidth(t,n),a=e.getImageHeight(t,n),s=e.getHasAlpha(),{compressed:o,format:A,basisFormat:l,textureFormat:c}=Ld(r,s),u=e.getImageTranscodedSizeInBytes(t,n,l),f=new Uint8Array(u);if(!e.transcodeImage(f,t,n,l,0,0))throw new Error("failed to start Basis transcoding");return{shape:"texture-level",width:i,height:a,data:f,compressed:o,...void 0!==A?{format:A}:{},...void 0!==c?{textureFormat:c}:{},hasAlpha:s}}function Nd(e,t,n){const r=new e(new Uint8Array(t));try{if(!r.startTranscoding())throw new Error("failed to start KTX2 transcoding");const e=r.getLevels(),t=[];for(let i=0;i<e;i++)t.push(kd(r,i,n));return[t]}finally{r.close(),r.delete()}}function kd(e,t,n){const{alphaFlag:r,height:i,width:a}=e.getImageLevelInfo(t,0,0),{compressed:s,format:o,basisFormat:A,textureFormat:l}=Ld(n,r),c=e.getImageTranscodedSizeInBytes(t,0,0,A),u=new Uint8Array(c);if(!e.transcodeImage(u,t,0,0,A,0,-1,-1))throw new Error("Failed to transcode KTX2 image");return{shape:"texture-level",width:a,height:i,data:u,compressed:s,...void 0!==o?{format:o}:{},...void 0!==l?{textureFormat:l}:{},levelSize:c,hasAlpha:r}}function Ld(e,t){let n=e.basis?.format||"auto";"auto"===n&&(n=e.basis?.supportedTextureFormats?Bd(e.basis.supportedTextureFormats):Bd()),"object"==typeof n&&(n=t?n.alpha:n.noAlpha);const r=n.toLowerCase(),i=Id[r];if(!i)throw new Error(`Unknown Basis format ${n}`);return i}function Bd(e=Md()){const t=new Set(e);return Od(t,["astc-4x4-unorm","astc-4x4-unorm-srgb"])?"astc-4x4":Od(t,["bc7-rgba-unorm","bc7-rgba-unorm-srgb"])?{alpha:"bc7-m5",noAlpha:"bc7-m6-opaque-only"}:Od(t,["bc1-rgb-unorm-webgl","bc1-rgb-unorm-srgb-webgl","bc1-rgba-unorm","bc1-rgba-unorm-srgb","bc2-rgba-unorm","bc2-rgba-unorm-srgb","bc3-rgba-unorm","bc3-rgba-unorm-srgb"])?{alpha:"bc3",noAlpha:"bc1"}:Od(t,["pvrtc-rgb4unorm-webgl","pvrtc-rgba4unorm-webgl","pvrtc-rgb2unorm-webgl","pvrtc-rgba2unorm-webgl"])?{alpha:"pvrtc1-4-rgba",noAlpha:"pvrtc1-4-rgb"}:Od(t,["etc2-rgb8unorm","etc2-rgb8unorm-srgb","etc2-rgb8a1unorm","etc2-rgb8a1unorm-srgb","etc2-rgba8unorm","etc2-rgba8unorm-srgb","eac-r11unorm","eac-r11snorm","eac-rg11unorm","eac-rg11snorm"])?"etc2":t.has("etc1-rgb-unorm-webgl")?"etc1":Od(t,["atc-rgb-unorm-webgl","atc-rgba-unorm-webgl","atc-rgbai-unorm-webgl"])?{alpha:"atc-rgba-interpolated-alpha",noAlpha:"atc-rgb"}:"rgb565"}function Od(e,t){return t.some(t=>e.has(t))}var Fd={...{dataType:null,batchType:null,name:"Basis",id:"basis",module:"textures",version:"4.5.4",worker:!0,extensions:["basis","ktx2"],mimeTypes:["application/octet-stream","image/ktx2"],tests:["sB"],binary:!0,options:{basis:{format:"auto",containerFormat:"auto",module:"transcoder"}}},parse:async function(e,t={}){const n=nt(t);return await async function(e){const t=Cd;let n;Cd=new Promise(e=>{n=e}),await t;try{return await e()}finally{n()}}(async()=>{if(!t.basis?.containerFormat||"auto"===t.basis.containerFormat){if(function(e){const t=new Uint8Array(e);return!(t.byteLength<Ed.length||t[0]!==Ed[0]||t[1]!==Ed[1]||t[2]!==Ed[2]||t[3]!==Ed[3]||t[4]!==Ed[4]||t[5]!==Ed[5]||t[6]!==Ed[6]||t[7]!==Ed[7]||t[8]!==Ed[8]||t[9]!==Ed[9]||t[10]!==Ed[10]||t[11]!==Ed[11])}(e))return Nd((await _d(n)).KTX2File,e,t);const{BasisFile:r}=await xd(n);return Rd(r,e,t)}if("encoder"===t.basis.module){const r=await _d(n);return"ktx2"===t.basis.containerFormat?Nd(r.KTX2File,e,t):Rd(r.BasisFile,e,t)}{const{BasisFile:r}=await xd(n);return Rd(r,e,t)}})}},Dd=!0,Ud=1735152710,Vd=1313821514,jd=5130562;function zd(e,t,n=0,r={}){const i=new DataView(t),a=function(e,t=0){return`${String.fromCharCode(e.getUint8(t+0))}${String.fromCharCode(e.getUint8(t+1))}${String.fromCharCode(e.getUint8(t+2))}${String.fromCharCode(e.getUint8(t+3))}`}(i,n+0),s=i.getUint32(n+4,Dd),o=i.getUint32(n+8,Dd);switch(Object.assign(e,{header:{byteOffset:n,byteLength:o,hasBinChunk:!1},type:a,version:s,json:{},binChunks:[]}),n+=12,e.version){case 1:return function(e,t,n){Y(e.header.byteLength>20);const r=t.getUint32(n+0,Dd),i=t.getUint32(n+4,Dd);return n+=8,Y(0===i),Gd(e,t,n,r),n+=r,n+=Hd(e,t,n,e.header.byteLength),n}(e,i,n);case 2:return function(e,t,n,r){return Y(e.header.byteLength>20),function(e,t,n,r){for(;n+8<=e.header.byteLength;){const i=t.getUint32(n+0,Dd),a=t.getUint32(n+4,Dd);switch(n+=8,a){case Vd:Gd(e,t,n,i);break;case jd:Hd(e,t,n,i);break;case 0:r.strict||Gd(e,t,n,i);break;case 1:r.strict||Hd(e,t,n,i)}n+=st(i,4)}}(e,t,n,r),n+e.header.byteLength}(e,i,n,{});default:throw new Error(`Invalid GLB version ${e.version}. Only supports version 1 and 2.`)}}function Gd(e,t,n,r){const i=new Uint8Array(t.buffer,n,r),a=new TextDecoder("utf8").decode(i);return e.json=JSON.parse(a),st(r,4)}function Hd(e,t,n,r){return e.header.hasBinChunk=!0,e.binChunks.push({byteOffset:n,byteLength:r,arrayBuffer:t.buffer}),st(r,4)}function qd(e,t,n){if(e.startsWith("data:")||e.startsWith("http:")||e.startsWith("https:"))return e;const r=n?.baseUrl||function(e){if(!e)return;if(e.endsWith("/"))return e;const t=e.lastIndexOf("/");return t>=0?e.slice(0,t+1):""}(t?.core?.baseUrl);if(!r)throw new Error(`'baseUrl' must be provided to resolve relative url ${e}`);return r.endsWith("/")?`${r}${e}`:`${r}/${e}`}async function Qd(e,t,n){if(!t.gltf?.decompressMeshes||!t.gltf.loadBuffers)return;!function(e){const t=e.bufferViews||[];for(let r=0;r<t.length;r++){const e=t[r].extensions;if(e?.KHR_meshopt_compression&&e.EXT_meshopt_compression)throw new Error(`glTF bufferView ${r} cannot use both KHR_meshopt_compression and EXT_meshopt_compression.`)}const n=e.buffers||[];for(let r=0;r<n.length;r++){const e=n[r].extensions;if(e?.KHR_meshopt_compression&&e.EXT_meshopt_compression)throw new Error(`glTF buffer ${r} cannot use both KHR_meshopt_compression and EXT_meshopt_compression.`)}}(e.json);const r=new bf(e),i=e.json.bufferViews||[],a=i.map(e=>async function(e,t,n){const r=e.getObjectExtension(t,n);if(!r)return;const{byteOffset:i=0,byteLength:a,byteStride:s,count:o,mode:A,filter:l="NONE",buffer:c}=r,u=e.gltf.buffers[c],f=e.gltf.buffers[t.buffer],d=new Uint8Array(u.arrayBuffer,u.byteOffset+i,a),h=new Uint8Array(f.arrayBuffer,f.byteOffset+(t.byteOffset||0),t.byteLength);await async function(e,t,n,r,i,a="NONE"){await af.ready,af.decodeGltfBuffer(e,t,n,r,i,function(e){return"string"==typeof e?e:["NONE","OCTAHEDRAL","QUATERNION","EXPONENTIAL","COLOR"][e]}(a))}(h,o,s,d,A,l)}(r,e,n));await Promise.all(a);for(const s of i)r.removeObjectExtension(s,n);for(const s of e.json.buffers||[])r.removeObjectExtension(s,n);r.removeExtension(n)}var Kd=/* @__PURE__ */t({decode:()=>Jd,name:()=>Wd}),Wd="EXT_meshopt_compression";async function Jd(e,t){await Qd(e,t,Wd)}var $d=/* @__PURE__ */t({decode:()=>Yd,name:()=>Xd}),Xd="KHR_meshopt_compression";async function Yd(e,t){await Qd(e,t,Xd)}var Zd=/* @__PURE__ */t({name:()=>th,preprocess:()=>nh}),eh="EXT_texture_webp",th=eh;function nh(e,t){const n=new bf(e);if(!bt("image/webp")){if(n.getRequiredExtensions().includes(eh))throw new Error(`gltf: Required extension ${eh} not supported by browser`);return}const{json:r}=n;for(const i of r.textures||[]){const e=n.getObjectExtension(i,eh);e&&(i.source=e.source),n.removeObjectExtension(i,eh)}n.removeExtension(eh)}var rh=/* @__PURE__ */t({name:()=>ah,preprocess:()=>sh}),ih="EXT_texture_avif",ah=ih;async function sh(e,t){const n=new bf(e);if(!(await mt()).has("image/avif")){if(n.getRequiredExtensions().includes(ih))throw new Error(`gltf: Required extension ${ih} not supported by browser`);return}const{json:r}=n;for(const i of r.textures||[]){const e=n.getObjectExtension(i,ih);e&&(i.source=e.source),n.removeObjectExtension(i,ih)}n.removeExtension(ih)}var oh=/* @__PURE__ */t({name:()=>lh,preprocess:()=>ch}),Ah="KHR_texture_basisu",lh=Ah;function ch(e,t){const n=new bf(e),{json:r}=n;for(const i of r.textures||[]){const e=n.getObjectExtension(i,Ah);e&&(i.source=e.source,n.removeObjectExtension(i,Ah))}n.removeExtension(Ah)}var uh,fh="https://www.gstatic.com/draco/versioned/decoders/1.5.6",dh="draco_wasm_wrapper.js",hh="draco_decoder.wasm",ph="draco_decoder.js",mh="draco_encoder.js",gh={[dh]:`${fh}/${dh}`,[hh]:`${fh}/${hh}`,[ph]:`${fh}/${ph}`,[mh]:`https://raw.githubusercontent.com/google/draco/1.4.1/javascript/${mh}`};async function bh(e={},t){const n=e.modules||{};return n.draco3d?uh||=ft(()=>n.draco3d.createDecoderModule({}),e=>({draco:e})):uh||=async function(e,t){let n,r;if("js"===t)n=await rt(gh[ph],"draco",e,ph);else try{[n,r]=await Promise.all([await rt(gh[dh],"draco",e,dh),await rt(gh[hh],"draco",e,hh)])}catch{n=null,r=null}n=vh(n,"DracoDecoderModule"),n=n||globalThis.DracoDecoderModule,n||pe||([n,r]=await Promise.all([await rt(gh[dh],"draco",{...e,useLocalLibraries:!0},dh),await rt(gh[hh],"draco",{...e,useLocalLibraries:!0},hh)]),n=vh(n,"DracoDecoderModule"),n=n||globalThis.DracoDecoderModule);return await function(e,t){if("function"!=typeof e)throw new Error("DracoDecoderModule could not be loaded");const n={};t&&(n.wasmBinary=t);return ft(t=>e({...n,onModuleLoaded:t}),e=>({draco:e}))}(n,r)}(e,t),await uh}function vh(e,t){if(e&&"object"==typeof e){if(e.default)return e.default;if(e[t])return e[t]}return e}function yh(e,t,n){return dt(e,t,n?xh(n.metadata):void 0)}function xh(e){Object.entries(e);const t={};for(const n in e)t[`${n}.string`]=JSON.stringify(e[n]);return t}var _h={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},wh={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array},Th=class{draco;decoder;metadataQuerier;constructor(e){this.draco=e,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}destroy(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}parseSync(e,t={}){const n=new this.draco.DecoderBuffer;n.Init(new Int8Array(e),e.byteLength),this._disableAttributeTransforms(t);const r=this.decoder.GetEncodedGeometryType(n),i=r===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let e;switch(r){case this.draco.TRIANGULAR_MESH:e=this.decoder.DecodeBufferToMesh(n,i);break;case this.draco.POINT_CLOUD:e=this.decoder.DecodeBufferToPointCloud(n,i);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!e.ok()||!i.ptr){const t=`DRACO decompression failed: ${e.error_msg()}`;throw new Error(t)}const a=this._getDracoLoaderData(i,r,t),s=this._getMeshData(i,a,t),o=function(e){let t=1/0,n=1/0,r=1/0,i=-1/0,a=-1/0,s=-1/0;const o=e.POSITION?e.POSITION.value:[],A=o&&o.length;for(let l=0;l<A;l+=3){const e=o[l],A=o[l+1],c=o[l+2];t=e<t?e:t,n=A<n?A:n,r=c<r?c:r,i=e>i?e:i,a=A>a?A:a,s=c>s?c:s}return[[t,n,r],[i,a,s]]}(s.attributes),A=function(e,t,n){const r=xh(t.metadata),i=[],a=function(e){const t={};for(const n in e){const r=e[n];t[r.name||"undefined"]=r}return t}(t.attributes);for(const s in e){const t=yh(s,e[s],a[s]);i.push(t)}if(n){const e=yh("indices",n);i.push(e)}return{fields:i,metadata:r}}(s.attributes,a,s.indices);return{loader:"draco",loaderData:a,header:{vertexCount:i.num_points(),boundingBox:o},...s,schema:A}}finally{this.draco.destroy(n),i&&this.draco.destroy(i)}}_getDracoLoaderData(e,t,n){const r=this._getTopLevelMetadata(e),i=this._getDracoAttributes(e,n);return{geometry_type:t,num_attributes:e.num_attributes(),num_points:e.num_points(),num_faces:e instanceof this.draco.Mesh?e.num_faces():0,metadata:r,attributes:i}}_getDracoAttributes(e,t){const n={};for(let r=0;r<e.num_attributes();r++){const i=this.decoder.GetAttribute(e,r),a=this._getAttributeMetadata(e,r);n[i.unique_id()]={unique_id:i.unique_id(),attribute_type:i.attribute_type(),data_type:i.data_type(),num_components:i.num_components(),byte_offset:i.byte_offset(),byte_stride:i.byte_stride(),normalized:i.normalized(),attribute_index:r,metadata:a};const s=this._getQuantizationTransform(i,t);s&&(n[i.unique_id()].quantization_transform=s);const o=this._getOctahedronTransform(i,t);o&&(n[i.unique_id()].octahedron_transform=o)}return n}_getMeshData(e,t,n){const r=this._getMeshAttributes(t,e,n);if(!r.POSITION)throw new Error("DRACO: No position attribute found.");if(e instanceof this.draco.Mesh){if("triangle-strip"===n.topology)return{topology:"triangle-strip",mode:4,attributes:r,indices:{value:this._getTriangleStripIndices(e),size:1}};return{topology:"triangle-list",mode:5,attributes:r,indices:{value:this._getTriangleListIndices(e),size:1}}}return{topology:"point-list",mode:0,attributes:r}}_getMeshAttributes(e,t,n){const r={};for(const i of Object.values(e.attributes)){const e=this._deduceAttributeName(i,n);i.name=e;const a=this._getAttributeValues(t,i);if(a){const{value:t,size:n}=a;r[e]={value:t,size:n,byteOffset:i.byte_offset,byteStride:i.byte_stride,normalized:i.normalized}}}return r}_getTriangleListIndices(e){const t=3*e.num_faces(),n=4*t,r=this.draco._malloc(n);try{return this.decoder.GetTrianglesUInt32Array(e,n,r),new Uint32Array(this.draco.HEAPF32.buffer,r,t).slice()}finally{this.draco._free(r)}}_getTriangleStripIndices(e){const t=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(e,t),function(e){const t=e.size(),n=new Int32Array(t);for(let r=0;r<t;r++)n[r]=e.GetValue(r);return n}(t)}finally{this.draco.destroy(t)}}_getAttributeValues(e,t){const n=wh[t.data_type];if(!n)return console.warn(`DRACO: Unsupported attribute type ${t.data_type}`),null;const r=t.num_components,i=e.num_points()*r,a=i*n.BYTES_PER_ELEMENT,s=function(e,t){switch(t){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32;default:return e.DT_INVALID}}(this.draco,n);let o;const A=this.draco._malloc(a);try{const r=this.decoder.GetAttribute(e,t.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,r,s,a,A),o=new n(this.draco.HEAPF32.buffer,A,i).slice()}finally{this.draco._free(A)}return{value:o,size:r}}_deduceAttributeName(e,t){const n=e.unique_id;for(const[a,s]of Object.entries(t.extraAttributes||{}))if(s===n)return a;const r=e.attribute_type;for(const a in _h)if(this.draco[a]===r)return _h[a];const i=t.attributeNameEntry||"name";return e.metadata[i]?e.metadata[i].string:`CUSTOM_ATTRIBUTE_${n}`}_getTopLevelMetadata(e){const t=this.decoder.GetMetadata(e);return this._getDracoMetadata(t)}_getAttributeMetadata(e,t){const n=this.decoder.GetAttributeMetadata(e,t);return this._getDracoMetadata(n)}_getDracoMetadata(e){if(!e||!e.ptr)return{};const t={},n=this.metadataQuerier.NumEntries(e);for(let r=0;r<n;r++){const n=this.metadataQuerier.GetEntryName(e,r);t[n]=this._getDracoMetadataField(e,n)}return t}_getDracoMetadataField(e,t){const n=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(e,t,n);const r=function(e){const t=e.size(),n=new Int32Array(t);for(let r=0;r<t;r++)n[r]=e.GetValue(r);return n}(n);return{int:this.metadataQuerier.GetIntEntry(e,t),string:this.metadataQuerier.GetStringEntry(e,t),double:this.metadataQuerier.GetDoubleEntry(e,t),intArray:r}}finally{this.draco.destroy(n)}}_disableAttributeTransforms(e){const{quantizedAttributes:t=[],octahedronAttributes:n=[]}=e,r=[...t,...n];for(const i of r)this.decoder.SkipAttributeTransform(this.draco[i])}_getQuantizationTransform(e,t){const{quantizedAttributes:n=[]}=t,r=e.attribute_type();if(n.map(e=>this.decoder[e]).includes(r)){const t=new this.draco.AttributeQuantizationTransform;try{if(t.InitFromAttribute(e))return{quantization_bits:t.quantization_bits(),range:t.range(),min_values:new Float32Array([1,2,3]).map(e=>t.min_value(e))}}finally{this.draco.destroy(t)}}return null}_getOctahedronTransform(e,t){const{octahedronAttributes:n=[]}=t,r=e.attribute_type();if(n.map(e=>this.decoder[e]).includes(r)){const t=new this.draco.AttributeQuantizationTransform;try{if(t.InitFromAttribute(e))return{quantization_bits:t.quantization_bits()}}finally{this.draco.destroy(t)}}return null}};var Sh={...{dataType:null,batchType:null,name:"Draco",id:"draco",module:"draco",version:"4.5.4",worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:{draco:{decoderType:"object"==typeof WebAssembly?"wasm":"js",extraAttributes:{},attributeNameEntry:void 0}}},parse:async function(e,t){const{draco:n}=await bh(nt(t),t?.draco?.decoderType||"wasm"),r=new Th(n);try{return r.parseSync(e,t?.draco)}finally{r.destroy()}}};function Mh(e){const{buffer:t,size:n,count:r}=function(e){let t=e,n=1,r=0;e&&e.value&&(t=e.value,n=e.size||1);t&&(ArrayBuffer.isView(t)||(t=function(e,t,n=!1){return e?Array.isArray(e)?new t(e):!n||e instanceof t?e:new t(e):null}(t,Float32Array)),r=t.length/n);return{buffer:t,size:n,count:r}}(e);return{value:t,size:n,byteOffset:0,count:r,type:hf(n),componentType:pf(t)}}var Eh=/* @__PURE__ */t({decode:()=>Ph,encode:()=>Nh,name:()=>Ih,preprocess:()=>Rh}),Ch="KHR_draco_mesh_compression",Ih=Ch;function Rh(e,t,n){const r=new bf(e);for(const i of Bh(r))r.getObjectExtension(i,Ch)}async function Ph(e,t,n){if(!t?.gltf?.decompressMeshes)return;const r=new bf(e),i=[];for(const a of Bh(r))r.getObjectExtension(a,Ch)&&i.push(kh(r,a,t,n));await Promise.all(i),r.removeExtension(Ch)}function Nh(e,t={}){const n=new bf(e);for(const r of n.json.meshes||[])Lh(r,t),n.addRequiredExtension(Ch)}async function kh(e,t,n,r){const i=e.getObjectExtension(t,Ch);if(!i)return;const a=e.getTypedArrayForBufferView(i.bufferView),s=ie(a.buffer,a.byteOffset),o={...n};delete o["3d-tiles"];const A=await Ze(s,Sh,o,r),l=function(e){const t={};for(const n in e){const r=e[n];"indices"!==n&&(t[n]=Mh(r))}return t}(A.attributes);for(const[c,u]of Object.entries(l))if(c in t.attributes){const n=t.attributes[c],r=e.getAccessor(n);r?.min&&r?.max&&(u.min=r.min,u.max=r.max)}t.attributes=l,A.indices&&(t.indices=Mh(A.indices)),e.removeObjectExtension(t,Ch),function(e){if(!e.attributes&&Object.keys(e.attributes).length>0)throw new Error("glTF: Empty primitive detected: Draco decompression failure?")}(t)}function Lh(e,t,n=4,r,i){if(!r.DracoWriter)throw new Error("options.gltf.DracoWriter not provided");const a=r.DracoWriter.encodeSync({attributes:e}),s=i?.parseSync?.({attributes:e}),o=r._addFauxAttributes(s.attributes),A=r.addBufferView(a);return{primitives:[{attributes:o,mode:n,extensions:{[Ch]:{bufferView:A,attributes:o}}}]}}function*Bh(e){for(const t of e.json.meshes||[])for(const e of t.primitives)yield e}var Oh=/* @__PURE__ */t({decode:()=>zh,name:()=>Dh}),Fh="KHR_texture_transform",Dh=Fh,Uh=new de,Vh=new Mt,jh=new Mt;async function zh(e,t){const n=new bf(e);if(!n.hasExtension(Fh)||!t.gltf?.loadBuffers)return;const r=e.json.materials||[];for(let i=0;i<r.length;i++)Gh(i,e,n);r.some(e=>Hh(e).length>0)||n.removeExtension(Fh)}function Gh(e,t,n){const r=t.json.materials?.[e],i=Hh(r),a=/* @__PURE__ */new Map;let s=function(e){let t=-1;for(const n of e.json.meshes||[])for(const e of n.primitives)for(const n of Object.keys(e.attributes)){const e=/^TEXCOORD_(\d+)$/.exec(n);e&&(t=Math.max(t,Number(e[1])))}return t+1}(t);for(const o of i){const r=o.extensions?.[Fh];if(r){const i=r.texCoord??o.texCoord??0,A=qh(i,r);let l=a.get(A);if(!l){if(l={sourceTexCoord:i,texCoord:s,matrix:Wh(r)},!Qh(t,e,l))continue;s++,a.set(A,l)}o.texCoord=l.texCoord,n.removeObjectExtension(o,Fh),o.extensions&&0===Object.keys(o.extensions).length&&delete o.extensions}}}function Hh(e){if(!e||"object"!=typeof e)return[];const t=e,n=[],r=t.extensions;Number.isFinite(t.index)&&r?.[Fh]&&n.push(t);for(const[i,a]of Object.entries(t))"extras"!==i&&n.push(...Hh(a));return n}function qh(e,t){const{offset:n=[0,0],rotation:r=0,scale:i=[1,1]}=t;return JSON.stringify([e,n,r,i])}function Qh(e,t,n){const r=[],i=e.json.meshes||[];for(const a of i)for(const e of a.primitives){const n=e.material;Number.isFinite(n)&&t===n&&r.push(e)}if(0===r.length||r.some(t=>!function(e,t,n){const r=t.attributes[`TEXCOORD_${n}`];if(!Number.isFinite(r))return!1;const i=e.json.accessors?.[r];if(!i||void 0===i.bufferView||i.sparse)return!1;const a=e.json.bufferViews?.[i.bufferView];return Boolean(a&&e.buffers[a.buffer])}(e,t,n.sourceTexCoord)))return!1;for(const a of r)Kh(e,a,n);return!0}function Kh(e,t,n){const{sourceTexCoord:r,texCoord:i,matrix:a}=n,s=t.attributes[`TEXCOORD_${r}`];if(Number.isFinite(s)){const n=e.json.accessors?.[s];if(n&&void 0!==n.bufferView){const r=e.json.bufferViews?.[n.bufferView];if(r){const{arrayBuffer:s,byteOffset:o}=e.buffers[r.buffer],A=(o||0)+(n.byteOffset||0)+(r.byteOffset||0),{ArrayType:l,length:c}=mf(n,r),u=Af[n.componentType],f=of[n.type],d=r.byteStride||u*f,h=new Float32Array(c);for(let e=0;e<n.count;e++){const t=new l(s,A+e*d,2);Uh.set(t[0],t[1],1),Uh.transformByMatrix3(a),h.set([Uh[0],Uh[1]],e*f)}!function(e,t,n,r,i){r.buffers.push({arrayBuffer:ue(i.buffer),byteOffset:0,byteLength:i.buffer.byteLength}),r.json.bufferViews=r.json.bufferViews||[];const a=r.json.bufferViews;a.push({buffer:r.buffers.length-1,byteLength:i.buffer.byteLength,byteOffset:0});const s=r.json.accessors;if(!s)return;s.push({bufferView:a?.length-1,byteOffset:0,componentType:5126,count:t.count,type:"VEC2"}),n.attributes[`TEXCOORD_${e}`]=s.length-1}(i,n,t,e,h)}}}}function Wh(e){const{offset:t=[0,0],rotation:n=0,scale:r=[1,1]}=e,i=(new Mt).set(1,0,0,0,1,0,t[0],t[1],1),a=Vh.set(Math.cos(n),Math.sin(n),0,-Math.sin(n),Math.cos(n),0,0,0,1),s=jh.set(r[0],0,0,0,r[1],0,0,0,1);return i.multiplyRight(a).multiplyRight(s)}var Jh=/* @__PURE__ */t({decode:()=>Yh,encode:()=>Zh,name:()=>Xh}),$h="KHR_lights_punctual",Xh=$h;async function Yh(e){const t=new bf(e),{json:n}=t,r=t.getExtension($h);r&&(t.json.lights=r.lights,t.removeExtension($h));for(const i of n.nodes||[]){const e=t.getObjectExtension(i,$h);e&&(i.light=e.light),t.removeObjectExtension(i,$h)}}async function Zh(e){const t=new bf(e),{json:n}=t;if(n.lights){const e=t.addExtension($h);sf(!e.lights),e.lights=n.lights,delete n.lights}if(t.json.lights){for(const e of t.json.lights){const n=e.node;t.addObjectExtension(n,$h,e)}delete t.json.lights}}var ep=/* @__PURE__ */t({decode:()=>rp,encode:()=>ip,name:()=>np}),tp="KHR_materials_unlit",np=tp;async function rp(e){const t=new bf(e),{json:n}=t;for(const r of n.materials||[])r.extensions&&r.extensions.KHR_materials_unlit&&(r.unlit=!0),t.removeObjectExtension(r,tp);t.removeExtension(tp)}function ip(e){const t=new bf(e),{json:n}=t;if(t.materials)for(const r of n.materials||[])r.unlit&&(delete r.unlit,t.addObjectExtension(r,tp,{}),t.addExtension(tp))}var ap=/* @__PURE__ */t({decode:()=>Ap,encode:()=>lp,name:()=>op}),sp="KHR_techniques_webgl",op=sp;async function Ap(e){const t=new bf(e),{json:n}=t,r=t.getExtension(sp);if(r){const e=function(e,t){const{programs:n=[],shaders:r=[],techniques:i=[]}=e,a=new TextDecoder;return r.forEach(e=>{if(!Number.isFinite(e.bufferView))throw new Error("KHR_techniques_webgl: no shader code");e.code=a.decode(t.getTypedArrayForBufferView(e.bufferView))}),n.forEach(e=>{e.fragmentShader=r[e.fragmentShader],e.vertexShader=r[e.vertexShader]}),i.forEach(e=>{e.program=n[e.program]}),i}(r,t);for(const r of n.materials||[]){const n=t.getObjectExtension(r,sp);n&&(r.technique=Object.assign({},n,e[n.technique]),r.technique.values=cp(r.technique,t)),t.removeObjectExtension(r,sp)}t.removeExtension(sp)}}async function lp(e,t){}function cp(e,t){const n=Object.assign({},e.values);return Object.keys(e.uniforms||{}).forEach(t=>{e.uniforms[t].value&&!(t in n)&&(n[t]=e.uniforms[t].value)}),Object.keys(n).forEach(e=>{"object"==typeof n[e]&&void 0!==n[e].index&&(n[e].texture=t.getTexture(n[e].index))}),n}var up=[Vf,Nf,$d,Kd,rh,Zd,oh,Eh,Jh,ep,ap,Oh,id];function fp(e,t){const n=t?.gltf?.excludeExtensions||{};return!(e in n&&!n[e])}var dp="KHR_binary_glTF";var hp={accessors:"accessor",animations:"animation",buffers:"buffer",bufferViews:"bufferView",images:"image",materials:"material",meshes:"mesh",nodes:"node",samplers:"sampler",scenes:"scene",skins:"skin",textures:"texture"},pp={accessor:"accessors",animations:"animation",buffer:"buffers",bufferView:"bufferViews",image:"images",material:"materials",mesh:"meshes",node:"nodes",sampler:"samplers",scene:"scenes",skin:"skins",texture:"textures"},mp=class{idToIndexMap={animations:{},accessors:{},buffers:{},bufferViews:{},images:{},materials:{},meshes:{},nodes:{},samplers:{},scenes:{},skins:{},textures:{}};json;normalize(e,t){this.json=e.json;const n=e.json;switch(n.asset&&n.asset.version){case"2.0":return;case void 0:case"1.0":break;default:return void console.warn(`glTF: Unknown version ${n.asset.version}`)}if(!t.normalize)throw new Error("glTF v1 is not supported.");console.warn("Converting glTF v1 to glTF v2 format. This is experimental and may fail."),this._addAsset(n),this._convertTopLevelObjectsToArrays(n),function(e){const t=new bf(e),{json:n}=t;for(const r of n.images||[]){const e=t.getObjectExtension(r,dp);e&&Object.assign(r,e),t.removeObjectExtension(r,dp)}n.buffers&&n.buffers[0]&&delete n.buffers[0].uri,t.removeExtension(dp)}(e),this._convertObjectIdsToArrayIndices(n),this._updateObjects(n),this._updateMaterial(n)}_addAsset(e){e.asset=e.asset||{},e.asset.version="2.0",e.asset.generator=e.asset.generator||"Normalized to glTF 2.0 by loaders.gl"}_convertTopLevelObjectsToArrays(e){for(const t in hp)this._convertTopLevelObjectToArray(e,t)}_convertTopLevelObjectToArray(e,t){const n=e[t];if(n&&!Array.isArray(n)){e[t]=[];for(const r in n){const i=n[r];i.id=i.id||r;const a=e[t].length;e[t].push(i),this.idToIndexMap[t][r]=a}}}_convertObjectIdsToArrayIndices(e){for(const t in hp)this._convertIdsToIndices(e,t);"scene"in e&&(e.scene=this._convertIdToIndex(e.scene,"scene"));for(const t of e.textures)this._convertTextureIds(t);for(const t of e.meshes)this._convertMeshIds(t);for(const t of e.nodes)this._convertNodeIds(t);for(const t of e.scenes)this._convertSceneIds(t)}_convertTextureIds(e){e.source&&(e.source=this._convertIdToIndex(e.source,"image"))}_convertMeshIds(e){for(const t of e.primitives){const{attributes:e,indices:n,material:r}=t;for(const t in e)e[t]=this._convertIdToIndex(e[t],"accessor");n&&(t.indices=this._convertIdToIndex(n,"accessor")),r&&(t.material=this._convertIdToIndex(r,"material"))}}_convertNodeIds(e){e.children&&(e.children=e.children.map(e=>this._convertIdToIndex(e,"node"))),e.meshes&&(e.meshes=e.meshes.map(e=>this._convertIdToIndex(e,"mesh")))}_convertSceneIds(e){e.nodes&&(e.nodes=e.nodes.map(e=>this._convertIdToIndex(e,"node")))}_convertIdsToIndices(e,t){e[t]||(console.warn(`gltf v1: json doesn't contain attribute ${t}`),e[t]=[]);for(const n of e[t])for(const e in n){const t=n[e];n[e]=this._convertIdToIndex(t,e)}}_convertIdToIndex(e,t){const n=pp[t];if(n in this.idToIndexMap){const r=this.idToIndexMap[n][e];if(!Number.isFinite(r))throw new Error(`gltf v1: failed to resolve ${t} with id ${e}`);return r}return e}_updateObjects(e){for(const t of this.json.buffers)delete t.type}_updateMaterial(e){for(const t of e.materials){t.pbrMetallicRoughness={baseColorFactor:[1,1,1,1],metallicFactor:1,roughnessFactor:1};const n=t.values?.tex||t.values?.texture2d_0||t.values?.diffuseTex,r=e.textures.findIndex(e=>e.id===n);-1!==r&&(t.pbrMetallicRoughness.baseColorTexture={index:r})}}};async function gp(e,t,n=0,r,i){return function(e,t,n,r){r.core?.baseUrl&&(e.baseUri=r.core?.baseUrl);t instanceof ArrayBuffer&&!function(e,t=0,n={}){const r=new DataView(e),{magic:i=Ud}=n,a=r.getUint32(t,!1);return a===i||a===Ud}(t,n,r.glb)&&(t=(new TextDecoder).decode(t));if("string"==typeof t)e.json=at(t);else if(t instanceof ArrayBuffer){const i={};n=zd(i,t,n,r.glb),sf("glTF"===i.type,`Invalid GLB magic string ${i.type}`),e._glb=i,e.json=i.json}else sf(!1,"GLTF: must be ArrayBuffer or string");const i=e.json.buffers||[];if(e.buffers=new Array(i.length).fill(null),e._glb&&e._glb.header.hasBinChunk){const{binChunks:t}=e._glb;e.buffers[0]={arrayBuffer:t[0].arrayBuffer,byteOffset:t[0].byteOffset,byteLength:t[0].byteLength}}const a=e.json.images||[];e.images=new Array(a.length).fill({})}(e,t,n,r),function(e,t={}){(new mp).normalize(e,t)}(e,{normalize:r?.gltf?.normalize}),await async function(e,t={},n){const r=up.filter(e=>fp(e.name,t));for(const i of r)await(i.preprocess?.(e,t,n))}(e,r,i),r?.gltf?.loadBuffers&&e.json.buffers&&await async function(e,t,n){const r=e.json.buffers||[];for(let i=0;i<r.length;++i){const a=r[i];if(a.uri){const{fetch:r}=n;sf(r);const s=qd(a.uri,t,n),o=await((await(n?.fetch?.(s)))?.arrayBuffer?.());e.buffers[i]={arrayBuffer:o,byteOffset:0,byteLength:o.byteLength},delete a.uri}else null===e.buffers[i]&&(e.buffers[i]={arrayBuffer:new ArrayBuffer(a.byteLength),byteOffset:0,byteLength:a.byteLength})}}(e,r,i),r?.gltf?.loadImages&&await async function(e,t,n){const r=function(e){const t=/* @__PURE__ */new Set,n=e.json.textures||[];for(const r of n)void 0!==r.source&&t.add(r.source);return Array.from(t).sort()}(e),i=e.json.images||[],a=[];for(const s of r)a.push(bp(e,i[s],s,t,n));return await Promise.all(a)}(e,r,i),await async function(e,t={},n){const r=up.filter(e=>fp(e.name,t));for(const i of r)await(i.decode?.(e,t,n))}(e,r,i),e}async function bp(e,t,n,r,i){let a;if(t.uri&&!t.hasOwnProperty("bufferView")){const e=qd(t.uri,r,i),{fetch:n}=i;a=await(await n(e)).arrayBuffer(),t.bufferView={data:a}}if(Number.isFinite(t.bufferView)){const n=function(e,t,n){const r=e.bufferViews[n];sf(r);const i=t[r.buffer];sf(i);const a=(r.byteOffset||0)+i.byteOffset;return new Uint8Array(i.arrayBuffer,a,r.byteLength)}(e.json,e.buffers,t.bufferView);a=ie(n.buffer,n.byteOffset,n.byteLength)}sf(a,"glTF image has no data");const s=function(e,t){const n=e.basis,r=n?.format;return{...e,core:{...e.core,mimeType:t},basis:{...n,format:r&&"auto"!==r?r:Bd(n?.supportedTextureFormats)}}}(r,t.mimeType);let o=await Ze(a,[Re,Fd],s,i);o&&o[0]&&(o={compressed:!0,mipmaps:!1,width:o[0].width,height:o[0].height,data:o[0]}),e.images=e.images||[],e.images[n]=o}var vp={dataType:null,batchType:null,name:"glTF",id:"gltf",module:"gltf",version:"4.5.4",extensions:["gltf","glb"],mimeTypes:["model/gltf+json","model/gltf-binary"],text:!0,binary:!0,tests:["glTF"],parse:async function(e,t={},n){const r={...vp.options,...t};r.gltf={...vp.options.gltf,...r.gltf};const i=t?.glb?.byteOffset||0;return await gp({},e,i,r,n)},options:{gltf:{normalize:!0,loadBuffers:!0,loadImages:!0,decompressMeshes:!0}}};var yp={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},xp={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},_p=10240,wp=10241,Tp=10242,Sp=10243,Mp=10497,Ep=9729,Cp=9986,Ip={magFilter:_p,minFilter:wp,wrapS:Tp,wrapT:Sp},Rp={[_p]:Ep,[wp]:Cp,[Tp]:Mp,[Sp]:Mp};var Pp=class{baseUri="";jsonUnprocessed;json;buffers=[];images=[];postProcess(e,t={}){const{json:n,buffers:r=[],images:i=[]}=e,{baseUri:a=""}=e;return sf(n),this.baseUri=a,this.buffers=r,this.images=i,this.jsonUnprocessed=n,this.json=this._resolveTree(e.json,t),this.json}_resolveTree(e,t={}){const n={...e};return this.json=n,e.bufferViews&&(n.bufferViews=e.bufferViews.map((e,t)=>this._resolveBufferView(e,t))),e.images&&(n.images=e.images.map((e,t)=>this._resolveImage(e,t))),e.samplers&&(n.samplers=e.samplers.map((e,t)=>this._resolveSampler(e,t))),e.textures&&(n.textures=e.textures.map((e,t)=>this._resolveTexture(e,t))),e.accessors&&(n.accessors=e.accessors.map((e,t)=>this._resolveAccessor(e,t))),e.materials&&(n.materials=e.materials.map((e,t)=>this._resolveMaterial(e,t))),e.meshes&&(n.meshes=e.meshes.map((e,t)=>this._resolveMesh(e,t))),e.nodes&&(n.nodes=e.nodes.map((e,t)=>this._resolveNode(e,t)),n.nodes=n.nodes.map((e,t)=>this._resolveNodeChildren(e))),e.skins&&(n.skins=e.skins.map((e,t)=>this._resolveSkin(e,t))),e.scenes&&(n.scenes=e.scenes.map((e,t)=>this._resolveScene(e,t))),"number"==typeof this.json.scene&&n.scenes&&(n.scene=n.scenes[this.json.scene]),n}getScene(e){return this._get(this.json.scenes,e)}getNode(e){return this._get(this.json.nodes,e)}getSkin(e){return this._get(this.json.skins,e)}getMesh(e){return this._get(this.json.meshes,e)}getMaterial(e){return this._get(this.json.materials,e)}getAccessor(e){return this._get(this.json.accessors,e)}getCamera(e){return this._get(this.json.cameras,e)}getTexture(e){return this._get(this.json.textures,e)}getSampler(e){return this._get(this.json.samplers,e)}getImage(e){return this._get(this.json.images,e)}getBufferView(e){return this._get(this.json.bufferViews,e)}getBuffer(e){return this._get(this.json.buffers,e)}_get(e,t){if("object"==typeof t)return t;const n=e&&e[t];return n||console.warn(`glTF file error: Could not find ${e}[${t}]`),n}_resolveScene(e,t){return{...e,id:e.id||`scene-${t}`,nodes:(e.nodes||[]).map(e=>this.getNode(e))}}_resolveNode(e,t){const n={...e,id:e?.id||`node-${t}`};return void 0!==e.mesh&&(n.mesh=this.getMesh(e.mesh)),void 0!==e.camera&&(n.camera=this.getCamera(e.camera)),void 0!==e.skin&&(n.skin=this.getSkin(e.skin)),void 0!==e.meshes&&e.meshes.length&&(n.mesh=e.meshes.reduce((e,t)=>{const n=this.getMesh(t);return e.id=n.id,e.primitives=e.primitives.concat(n.primitives),e},{primitives:[]})),n}_resolveNodeChildren(e){return e.children&&(e.children=e.children.map(e=>this.getNode(e))),e}_resolveSkin(e,t){const n="number"==typeof e.inverseBindMatrices?this.getAccessor(e.inverseBindMatrices):void 0;return{...e,id:e.id||`skin-${t}`,inverseBindMatrices:n}}_resolveMesh(e,t){const n={...e,id:e.id||`mesh-${t}`,primitives:[]};return e.primitives&&(n.primitives=e.primitives.map((e,t)=>{const r={...e,attributes:{},indices:void 0,material:void 0},i=e.attributes;for(const n in i)r.attributes[n]=this.getAccessor(i[n]);return void 0!==e.indices&&(r.indices=this.getAccessor(e.indices)),void 0!==e.material&&(r.material=this.getMaterial(e.material)),function(e,t,n){if(2!==e.mode&&6!==e.mode)return e;const r=e.indices?.value,i=e.indices?.count??function(e){const t=Object.values(e.attributes)[0];return sf(t,"glTF primitive must define at least one attribute"),t.count}(e),a=function(e,t){if(!e)return Math.max(0,t-1);let n=0;for(let r=0;r<t;r++)n=Math.max(n,Number(e[r]));return n}(r,i),s=a<=65535?Uint16Array:Uint32Array,o=2===e.mode?function(e,t,n){if(t<2)return new n(0);const r=new n(2*t);for(let i=0;i<t;i++)r[2*i]=kp(e,i),r[2*i+1]=kp(e,(i+1)%t);return r}(r,i,s):function(e,t,n){const r=Math.max(0,t-2),i=new n(3*r);for(let a=0;a<r;a++)i[3*a]=kp(e,0),i[3*a+1]=kp(e,a+1),i[3*a+2]=kp(e,a+2);return i}(r,i,s);return e.mode=2===e.mode?1:4,e.indices={id:`${t}-primitive-${n}-portable-indices`,components:1,bytesPerComponent:s.BYTES_PER_ELEMENT,bytesPerElement:s.BYTES_PER_ELEMENT,componentType:s===Uint16Array?5123:5125,normalized:!1,count:o.length,type:"SCALAR",min:o.length?[Np(o)]:void 0,max:o.length?[a]:void 0,value:o},e}(r,n.id,t)})),n}_resolveMaterial(e,t){const n={...e,id:e.id||`material-${t}`};if(n.normalTexture&&(n.normalTexture={...n.normalTexture},n.normalTexture.texture=this.getTexture(n.normalTexture.index)),n.occlusionTexture&&(n.occlusionTexture={...n.occlusionTexture},n.occlusionTexture.texture=this.getTexture(n.occlusionTexture.index)),n.emissiveTexture&&(n.emissiveTexture={...n.emissiveTexture},n.emissiveTexture.texture=this.getTexture(n.emissiveTexture.index)),n.emissiveFactor||(n.emissiveFactor=n.emissiveTexture?[1,1,1]:[0,0,0]),n.pbrMetallicRoughness){n.pbrMetallicRoughness={...n.pbrMetallicRoughness};const e=n.pbrMetallicRoughness;e.baseColorTexture&&(e.baseColorTexture={...e.baseColorTexture},e.baseColorTexture.texture=this.getTexture(e.baseColorTexture.index)),e.metallicRoughnessTexture&&(e.metallicRoughnessTexture={...e.metallicRoughnessTexture},e.metallicRoughnessTexture.texture=this.getTexture(e.metallicRoughnessTexture.index))}return n}_resolveAccessor(e,t){const n=(r=e.componentType,xp[r]);var r;const i=(a=e.type,yp[a]);var a;const s=n*i,o={...e,id:e.id||`accessor-${t}`,bytesPerComponent:n,components:i,bytesPerElement:s,value:void 0,bufferView:void 0,sparse:void 0};if(void 0!==e.bufferView&&(o.bufferView=this.getBufferView(e.bufferView)),o.bufferView){const e=o.bufferView.buffer,{ArrayType:t,byteLength:n}=mf(o,o.bufferView),r=(o.bufferView.byteOffset||0)+(o.byteOffset||0)+e.byteOffset;let i=ee(e.arrayBuffer,r,n);o.bufferView.byteStride&&(i=this._getValueFromInterleavedBuffer(e,r,o.bufferView.byteStride,o.bytesPerElement,o.count)),o.value=new t(i)}else{const{ArrayType:e}=mf(o,{byteLength:o.count*o.bytesPerElement});o.value=new e(o.count*o.components)}return e.sparse&&this._applySparseAccessor(o,e.sparse),o}_applySparseAccessor(e,t){const n=function(e){switch(e){case 5121:return Uint8Array;case 5123:return Uint16Array;case 5125:return Uint32Array;default:throw new Error(`Invalid glTF sparse index component type ${e}`)}}(t.indices.componentType),r=this._getTypedArrayFromBufferView(n,this.getBufferView(t.indices.bufferView),t.indices.byteOffset||0,t.count),i=e.value.constructor,a=this._getTypedArrayFromBufferView(i,this.getBufferView(t.values.bufferView),t.values.byteOffset||0,t.count*e.components);for(let s=0;s<t.count;s++){const t=Number(r[s]);sf(Number.isInteger(t)&&t>=0&&t<e.count,"glTF sparse accessor index is out of bounds");for(let n=0;n<e.components;n++){const r=t*e.components+n,i=s*e.components+n;Reflect.set(e.value,r,a[i])}}}_getTypedArrayFromBufferView(e,t,n,r){const i=r*e.BYTES_PER_ELEMENT;sf(n+i<=t.byteLength,"glTF sparse accessor data exceeds its buffer view");const a=t.buffer,s=a.byteOffset+(t.byteOffset||0)+n;return new e(ee(a.arrayBuffer,s,i))}_getValueFromInterleavedBuffer(e,t,n,r,i){const a=new Uint8Array(i*r);for(let s=0;s<i;s++){const i=t+s*n;a.set(new Uint8Array(e.arrayBuffer.slice(i,i+r)),s*r)}return a.buffer}_resolveTexture(e,t){return{...e,id:e.id||`texture-${t}`,sampler:"number"==typeof e.sampler?this.getSampler(e.sampler):{id:"default-sampler",parameters:Rp},source:"number"==typeof e.source?this.getImage(e.source):void 0}}_resolveSampler(e,t){const n={id:e.id||`sampler-${t}`,...e,parameters:{}};for(const r in n){const e=this._enumSamplerParameter(r);void 0!==e&&(n.parameters[e]=n[r])}return n}_enumSamplerParameter(e){return Ip[e]}_resolveImage(e,t){const n={...e,id:e.id||`image-${t}`,image:null,bufferView:void 0!==e.bufferView?this.getBufferView(e.bufferView):void 0},r=this.images[t];return r&&(n.image=r),n}_resolveBufferView(e,t){const n=e.buffer,r=this.buffers[n].arrayBuffer;let i=this.buffers[n].byteOffset||0;return e.byteOffset&&(i+=e.byteOffset),{id:`bufferView-${t}`,...e,buffer:this.buffers[n],data:new Uint8Array(r,i,e.byteLength)}}_resolveCamera(e,t){const n={...e,id:e.id||`camera-${t}`};return n.perspective,n.orthographic,n}};function Np(e){let t=1/0;for(const n of e)t=Math.min(t,n);return t}function kp(e,t){return e?Number(e[t]):t}function Lp(e,t){return(new Pp).postProcess(e,t)}async function Bp(e){const t=[];return e.scenes.forEach(e=>{e.traverse(e=>{})}),await async function(e){for(;e();)await new Promise(e=>requestAnimationFrame(e))}(()=>t.some(e=>!e.loaded))}var Op="layout(std140) uniform scenegraphUniforms {\n float sizeScale;\n float sizeMinPixels;\n float sizeMaxPixels;\n mat4 sceneModelMatrix;\n float composeModelMatrix;\n} scenegraph;\n",Fp={name:"scenegraph",source:"struct ScenegraphUniforms {\n sizeScale: f32,\n sizeMinPixels: f32,\n sizeMaxPixels: f32,\n sceneModelMatrix: mat4x4<f32>,\n composeModelMatrix: f32,\n};\n\n@group(0) @binding(auto)\nvar<uniform> scenegraph: ScenegraphUniforms;\n",vs:Op,fs:Op,uniformTypes:{sizeScale:"f32",sizeMinPixels:"f32",sizeMaxPixels:"f32",sceneModelMatrix:"mat4x4<f32>",composeModelMatrix:"f32"}},Dp=kt.source.replace(/fn pbr_setPositionNormalTangentUV\([\s\S]*?\n}\n/,"fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)\n{\n fragmentInputs.pbr_vPosition = position.xyz;\n fragmentInputs.pbr_vNormal = normal.xyz;\n fragmentInputs.pbr_vTBN = mat3x3f(\n vec3f(1.0, 0.0, 0.0),\n vec3f(0.0, 1.0, 0.0),\n vec3f(0.0, 0.0, 1.0)\n );\n fragmentInputs.pbr_vUV0 = uv;\n fragmentInputs.pbr_vUV1 = uv;\n}\n").replace(/pbrProjection\.camera/g,"project.cameraPosition"),Up={...kt,dependencies:[S],source:Dp},Vp=[255,255,255,255],jp={scenegraph:{type:"object",value:null,async:!0},getScene:e=>e&&e.scenes?"object"==typeof e.scene?e.scene:e.scenes[e.scene||0]:e,getAnimator:e=>e&&e.animator,_animations:null,onFirstDraw:{type:"function",value:()=>{}},sizeScale:{type:"number",value:1,min:0},sizeMinPixels:{type:"number",min:0,value:0},sizeMaxPixels:{type:"number",min:0,value:Number.MAX_SAFE_INTEGER},getPosition:{type:"accessor",value:e=>e.position},getColor:{type:"accessor",value:Vp},_lighting:"flat",_imageBasedLightingEnvironment:void 0,getOrientation:{type:"accessor",value:[0,0,0]},getScale:{type:"accessor",value:[1,1,1]},getTranslation:{type:"accessor",value:[0,0,0]},getTransformMatrix:{type:"accessor",value:[]},loaders:[vp]},zp=class extends d{getShaders(){const e={};let t;const n="webgpu"===this.context.device?.type;"pbr"===this.props._lighting?(t=n?Up:kt,e.LIGHTING_PBR=1):t=n?Up:{name:"pbrMaterial"};const r=[M,s,c,Fp,t];return super.getShaders({defines:e,vs:"#version 300 es\n#define SHADER_NAME scenegraph-layer-vertex-shader\nin vec3 instancePositions;\nin vec3 instancePositions64Low;\nin vec4 instanceColors;\nin vec3 instanceModelMatrixCol0;\nin vec3 instanceModelMatrixCol1;\nin vec3 instanceModelMatrixCol2;\nin vec3 instanceTranslation;\nin vec3 positions;\n#ifdef HAS_UV\nin vec2 texCoords;\n#endif\n#ifdef LIGHTING_PBR\n#ifdef HAS_NORMALS\nin vec3 normals;\n#endif\n#endif\nout vec4 vColor;\n#ifndef LIGHTING_PBR\n#ifdef HAS_UV\nout vec2 vTEXCOORD_0;\n#endif\n#endif\nvoid main(void) {\n#if defined(HAS_UV) && !defined(LIGHTING_PBR)\nvTEXCOORD_0 = texCoords;\ngeometry.uv = texCoords;\n#endif\ngeometry.worldPosition = instancePositions;\ngeometry.pickingColor = picking_getPickingColorFromInstanceID();\nmat3 instanceModelMatrix = mat3(instanceModelMatrixCol0, instanceModelMatrixCol1, instanceModelMatrixCol2);\nvec3 normal = vec3(0.0, 0.0, 1.0);\n#ifdef LIGHTING_PBR\n#ifdef HAS_NORMALS\nnormal = instanceModelMatrix * (scenegraph.sceneModelMatrix * vec4(normals, 0.0)).xyz;\n#endif\n#endif\nfloat originalSize = project_size_to_pixel(scenegraph.sizeScale);\nfloat clampedSize = clamp(originalSize, scenegraph.sizeMinPixels, scenegraph.sizeMaxPixels);\nfloat sizeRatio = originalSize == 0.0 ? 0.0 : clampedSize / originalSize;\nvec3 pos = (instanceModelMatrix * (scenegraph.sceneModelMatrix * vec4(positions, 1.0)).xyz) * scenegraph.sizeScale * sizeRatio + instanceTranslation;\nif(scenegraph.composeModelMatrix > 0.5) {\nDECKGL_FILTER_SIZE(pos, geometry);\ngeometry.normal = project_normal(normal);\ngeometry.worldPosition += pos;\ngl_Position = project_position_to_clipspace(pos + instancePositions, instancePositions64Low, vec3(0.0), geometry.position);\n}\nelse {\npos = project_size(pos);\nDECKGL_FILTER_SIZE(pos, geometry);\ngl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, pos, geometry.position);\ngeometry.normal = project_normal(normal);\n}\nDECKGL_FILTER_GL_POSITION(gl_Position, geometry);\n#ifdef LIGHTING_PBR\npbr_vPosition = geometry.position.xyz;\n#ifdef HAS_NORMALS\npbr_vNormal = geometry.normal;\n#endif\n#ifdef HAS_UV\npbr_vUV0 = texCoords;\n#else\npbr_vUV0 = vec2(0., 0.);\n#endif\npbr_vUV1 = vec2(0., 0.);\ngeometry.uv = pbr_vUV0;\n#endif\nvColor = instanceColors;\nDECKGL_FILTER_COLOR(vColor, geometry);\n}\n",fs:"#version 300 es\n#define SHADER_NAME scenegraph-layer-fragment-shader\nin vec4 vColor;\nout vec4 fragColor;\n#ifndef LIGHTING_PBR\n#if defined(HAS_UV) && defined(HAS_BASECOLORMAP)\nin vec2 vTEXCOORD_0;\nuniform sampler2D pbr_baseColorSampler;\n#endif\n#endif\nvoid main(void) {\n#ifdef LIGHTING_PBR\nfragColor = pbr_filterColor(vColor);\ngeometry.uv = pbr_vUV0;\n#else\n#if defined(HAS_UV) && defined(HAS_BASECOLORMAP)\nfragColor = vColor * texture(pbr_baseColorSampler, vTEXCOORD_0);\ngeometry.uv = vTEXCOORD_0;\n#else\nfragColor = vColor;\n#endif\n#endif\nfragColor.a *= layer.opacity;\nDECKGL_FILTER_COLOR(fragColor, geometry);\n}\n",source:"struct VertexInputs {\n @location(0) positions: vec3<f32>,\n#ifdef HAS_NORMALS\n @location(1) normals: vec3<f32>,\n#endif\n#ifdef HAS_UV\n @location(3) texCoords: vec2<f32>,\n#endif\n @location(6) instancePositions: vec3<f32>,\n @location(7) instancePositions64Low: vec3<f32>,\n @location(8) instanceColors: vec4<f32>,\n @location(10) instanceModelMatrixCol0: vec3<f32>,\n @location(11) instanceModelMatrixCol1: vec3<f32>,\n @location(12) instanceModelMatrixCol2: vec3<f32>,\n @location(13) instanceTranslation: vec3<f32>,\n};\n\nstruct FragmentInputs {\n @builtin(position) position: vec4<f32>,\n @location(0) vColor: vec4<f32>,\n @location(1) vTexCoord: vec2<f32>,\n @location(2) pbrPosition: vec3<f32>,\n @location(3) pbrUV: vec2<f32>,\n @location(4) pbrNormal: vec3<f32>,\n @location(5) pickingColor: vec3<f32>,\n};\n\n@vertex\nfn vertexMain(\n inputs: VertexInputs,\n @builtin(instance_index) instanceIndex: u32\n) -> FragmentInputs {\n var outputs: FragmentInputs;\n\n geometry.worldPosition = inputs.instancePositions;\n geometry.pickingColor = picking_getPickingColorFromIndex(instanceIndex);\n\n var vertexPosition = inputs.positions;\n var texCoord = vec2<f32>(0.0, 0.0);\n var normal = vec3<f32>(0.0, 0.0, 1.0);\n\n#ifdef HAS_UV\n texCoord = inputs.texCoords;\n#endif\n#ifdef HAS_NORMALS\n normal = inputs.normals;\n#endif\n\n geometry.uv = texCoord;\n\n let instanceModelMatrix = mat3x3<f32>(\n inputs.instanceModelMatrixCol0,\n inputs.instanceModelMatrixCol1,\n inputs.instanceModelMatrixCol2\n );\n\n let scenePosition = (scenegraph.sceneModelMatrix * vec4<f32>(vertexPosition, 1.0)).xyz;\n let worldNormal = instanceModelMatrix * (scenegraph.sceneModelMatrix * vec4<f32>(normal, 0.0)).xyz;\n\n let originalSize = project_meter_size_to_pixel(scenegraph.sizeScale);\n let clampedSize = clamp(originalSize, scenegraph.sizeMinPixels, scenegraph.sizeMaxPixels);\n let sizeRatio = select(0.0, clampedSize / originalSize, originalSize > 0.0);\n\n let pos =\n (instanceModelMatrix * scenePosition) * scenegraph.sizeScale * sizeRatio +\n inputs.instanceTranslation;\n\n if (scenegraph.composeModelMatrix > 0.5) {\n geometry.normal = project_normal(worldNormal);\n geometry.worldPosition = inputs.instancePositions + pos;\n geometry.position = vec4<f32>(\n project_position_vec3_f64(inputs.instancePositions + pos, inputs.instancePositions64Low),\n 1.0\n );\n } else {\n let sizeAdjustedPos = project_size_vec3(pos);\n // Scenegraph offsets are east/north/up in globe mode. Use project32's helper so it can\n // rotate the offset onto the local tangent plane before producing the common position.\n let projectResult = project_position_to_clipspace_and_commonspace(\n inputs.instancePositions,\n inputs.instancePositions64Low,\n sizeAdjustedPos\n );\n geometry.position = projectResult.commonPosition;\n geometry.normal = project_normal(worldNormal);\n }\n\n outputs.position = project_common_position_to_clipspace(geometry.position);\n outputs.vColor = inputs.instanceColors;\n outputs.vTexCoord = texCoord;\n outputs.pbrPosition = geometry.position.xyz;\n outputs.pbrUV = texCoord;\n outputs.pbrNormal = geometry.normal;\n outputs.pickingColor = geometry.pickingColor;\n return outputs;\n}\n\n@fragment\nfn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {\n fragmentGeometry.uv = inputs.vTexCoord;\n\n if (picking.isActive > 0.5) {\n if (!picking_isColorValid(inputs.pickingColor)) {\n discard;\n }\n return vec4<f32>(inputs.pickingColor, 1.0);\n }\n\n var fragColor = inputs.vColor;\n\n#ifdef LIGHTING_PBR\n fragmentInputs.pbr_vPosition = inputs.pbrPosition;\n // scenegraphPbrMaterial uses the indexed UV fields from the current PBR module.\n fragmentInputs.pbr_vUV0 = inputs.pbrUV;\n fragmentInputs.pbr_vUV1 = vec2<f32>(0.0);\n fragmentInputs.pbr_vNormal = inputs.pbrNormal;\n // Vertex color is part of the material base color and must be applied before lighting.\n fragColor = pbr_filterColor(fragColor);\n#else\n#ifdef HAS_BASECOLORMAP\n fragColor =\n fragColor *\n textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, inputs.vTexCoord);\n#endif\n#endif\n\n fragColor.a *= layer.opacity;\n\n if (picking.isHighlightActive > 0.5) {\n let highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);\n if (picking_isColorZero(abs(inputs.pickingColor - highlightedObjectColor))) {\n let highlightAlpha = picking.highlightColor.a;\n let blendedAlpha = highlightAlpha + fragColor.a * (1.0 - highlightAlpha);\n if (blendedAlpha > 0.0) {\n let highlightRatio = highlightAlpha / blendedAlpha;\n fragColor = vec4<f32>(\n mix(fragColor.rgb, picking.highlightColor.rgb, highlightRatio),\n blendedAlpha\n );\n }\n }\n }\n\n return deckgl_premultiplied_alpha(fragColor);\n}\n",modules:r})}initializeState(){const e=this.getAttributeManager(),t="webgpu"!==this.context.device.type;e.addInstanced({instancePositions:{size:3,type:"float64",fp64:this.use64bitPositions(),accessor:"getPosition",transition:t},instanceColors:{type:"unorm8",size:this.props.colorFormat.length,accessor:"getColor",defaultValue:Vp,transition:t},instanceModelMatrix:Vc})}updateState(e){super.updateState(e);const{props:t,oldProps:n}=e;t.scenegraph!==n.scenegraph?this._updateScenegraph():t._animations!==n._animations&&this._applyAnimationsProp(this.state.animator,t._animations)}finalizeState(e){super.finalizeState(e),this._destroyScenegraphAssets()}get isLoaded(){return Boolean(this.state?.scenegraph&&super.isLoaded)}_updateScenegraph(){const e=this.props,{device:t}=this.context;let n=null;if(e.scenegraph instanceof yn)n={scenes:[e.scenegraph]};else if(e.scenegraph&&"object"==typeof e.scenegraph){const r=e.scenegraph,i=nf(t,r.json?Lp(r):r,this._getModelOptions());n=i,Bp(i).then(()=>this.setNeedsRedraw()).catch(e=>{this.raiseError(e,"loading glTF")})}const r={layer:this,device:this.context.device},i=e.getScene(n,r),a=e.getAnimator(n,r);if(i instanceof wn){this._destroyScenegraphAssets(),this._applyAnimationsProp(a,e._animations);const t=[];i.traverse(e=>{e instanceof Tn&&t.push(e.model)}),this.setState({scenegraph:i,animator:a,materials:n?.materials||null,models:t,firstDrawSignaled:!1}),this.getAttributeManager().invalidateAll()}else null!==i&&ge.warn("invalid scenegraph:",i)()}_destroyScenegraphAssets(){this.state.scenegraph?.destroy(),this.state.materials?.forEach(e=>e.destroy()),this.state.scenegraph=null,this.state.animator=null,this.state.materials=null,this.state.models=[]}_applyAnimationsProp(e,t){if(!e||!t)return;const n=e.getAnimations();Object.keys(t).sort().forEach(e=>{const r=t[e];if("*"===e)n.forEach(e=>{Object.assign(e,r)});else if(Number.isFinite(Number(e))){const t=Number(e);t>=0&&t<n.length?Object.assign(n[t],r):ge.warn(`animation ${e} not found`)()}else{const t=n.find(({animation:t})=>t.name===e);t?Object.assign(t,r):ge.warn(`animation ${e} not found`)()}})}_getModelOptions(){const{_imageBasedLightingEnvironment:e}=this.props;let t;e&&(t="function"==typeof e?e({device:this.context.device,gl:this.context.gl,layer:this}):e);const n="webgpu"===this.context.device.type?{depthWriteEnabled:!0,depthCompare:"less-equal"}:void 0;return{imageBasedLightingEnvironment:t,modelOptions:{id:this.props.id,isInstanced:!0,bufferLayout:this.getAttributeManager().getBufferLayouts(),parameters:n,...this.getShaders()},useTangents:!1}}draw({context:e}){if(!this.state.scenegraph)return;this.props._animations&&this.state.animator&&(this.state.animator.setTime(e.timeline.getTime()),this.setNeedsRedraw());const{viewport:t,renderPass:n}=this.context,{sizeScale:r,sizeMinPixels:i,sizeMaxPixels:a,coordinateSystem:s}=this.props,o={camera:t.cameraPosition},A=this.getNumInstances();this.state.scenegraph.traverse((e,{worldMatrix:l})=>{if(e instanceof Tn){const{model:c}=e;c.setInstanceCount(A);const u={sizeScale:r,sizeMinPixels:i,sizeMaxPixels:a,composeModelMatrix:jc(t,s)?1:0,sceneModelMatrix:l};c.shaderInputs.setProps({pbrProjection:o,scenegraph:u}),c.draw(n)}}),this.state.firstDrawSignaled||(this.state.firstDrawSignaled=!0,this.props.onFirstDraw?.())}};zp.defaultProps=jp,zp.layerName="ScenegraphLayer";var Gp="layout(std140) uniform meshUniforms {\n bool pickFeatureIds;\n} mesh;\n",Hp={name:"mesh",vs:Gp,fs:Gp,source:"struct MeshUniforms {\n pickFeatureIds: f32,\n};\n\n@group(0) @binding(auto) var<uniform> mesh: MeshUniforms;\n",uniformTypes:{pickFeatureIds:"f32"}},qp=kt.source.replace(/fn pbr_setPositionNormalTangentUV\([\s\S]*?\n}\n/,"fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)\n{\n fragmentInputs.pbr_vPosition = position.xyz;\n fragmentInputs.pbr_vNormal = normal.xyz;\n fragmentInputs.pbr_vTBN = mat3x3f(\n vec3f(1.0, 0.0, 0.0),\n vec3f(0.0, 1.0, 0.0),\n vec3f(0.0, 0.0, 1.0)\n );\n fragmentInputs.pbr_vUV0 = uv;\n fragmentInputs.pbr_vUV1 = uv;\n}\n").replace(/pbrProjection\.camera/g,"project.cameraPosition"),Qp={...kt,source:qp};var Kp=class extends Qc{getShaders(){const e=super.getShaders();return{...e,vs:"#version 300 es\n#define SHADER_NAME simple-mesh-layer-vs\nin vec3 positions;\nin vec3 normals;\nin vec3 colors;\nin vec2 texCoords;\nin vec4 uvRegions;\nin float rowIndexes;\nin vec4 instanceColors;\nin vec3 instanceModelMatrixCol0;\nin vec3 instanceModelMatrixCol1;\nin vec3 instanceModelMatrixCol2;\nout vec2 vTexCoord;\nout vec3 cameraPosition;\nout vec3 normals_commonspace;\nout vec4 position_commonspace;\nout vec4 vColor;\nvec2 applyUVRegion(vec2 uv) {\n#ifdef HAS_UV_REGIONS\nreturn fract(uv) * (uvRegions.zw - uvRegions.xy) + uvRegions.xy;\n#else\nreturn uv;\n#endif\n}\nvoid main(void) {\nvec2 uv = applyUVRegion(texCoords);\ngeometry.uv = uv;\nif (mesh.pickFeatureIds) {\ngeometry.pickingColor = picking_getPickingColorFromIndex(rowIndexes);\n} else {\ngeometry.pickingColor = picking_getPickingColorFromInstanceID();\n}\nmat3 instanceModelMatrix = mat3(instanceModelMatrixCol0, instanceModelMatrixCol1, instanceModelMatrixCol2);\nvTexCoord = uv;\ncameraPosition = project.cameraPosition;\nvColor = vec4(colors * instanceColors.rgb, instanceColors.a);\nvec3 pos = (instanceModelMatrix * positions) * simpleMesh.sizeScale;\nvec3 projectedPosition = project_position(positions);\nposition_commonspace = vec4(projectedPosition, 1.0);\ngl_Position = project_common_position_to_clipspace(position_commonspace);\ngeometry.position = position_commonspace;\nnormals_commonspace = project_normal(instanceModelMatrix * normals);\ngeometry.normal = normals_commonspace;\nDECKGL_FILTER_GL_POSITION(gl_Position, geometry);\n#ifdef MODULE_PBRMATERIAL\npbr_vPosition = geometry.position.xyz;\n#ifdef HAS_NORMALS\npbr_vNormal = geometry.normal;\n#endif\n#ifdef HAS_UV\npbr_vUV0 = uv;\n#else\npbr_vUV0 = vec2(0., 0.);\n#endif\npbr_vUV1 = vec2(0., 0.);\ngeometry.uv = pbr_vUV0;\n#endif\nDECKGL_FILTER_COLOR(vColor, geometry);\n}\n",fs:"#version 300 es\n#define SHADER_NAME simple-mesh-layer-fs\nprecision highp float;\nuniform sampler2D sampler;\nin vec2 vTexCoord;\nin vec3 cameraPosition;\nin vec3 normals_commonspace;\nin vec4 position_commonspace;\nin vec4 vColor;\nout vec4 fragColor;\nvoid main(void) {\n#ifdef MODULE_PBRMATERIAL\nfragColor = vColor * pbr_filterColor(vec4(0));\ngeometry.uv = pbr_vUV0;\nfragColor.a *= layer.opacity;\n#else\ngeometry.uv = vTexCoord;\nvec3 normal;\nif (simpleMesh.flatShading) {\nnormal = normalize(cross(dFdx(position_commonspace.xyz), dFdy(position_commonspace.xyz)));\n} else {\nnormal = normals_commonspace;\n}\nvec4 color = simpleMesh.hasTexture ? texture(sampler, vTexCoord) : vColor;\nvec3 lightColor = lighting_getLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal);\nfragColor = vec4(lightColor, color.a * layer.opacity);\n#endif\nDECKGL_FILTER_COLOR(fragColor, geometry);\n}\n",source:"struct VertexInputs {\n @location(0) positions: vec3<f32>,\n#ifdef HAS_NORMALS\n @location(1) normals: vec3<f32>,\n#endif\n @location(2) colors: vec4<f32>,\n#ifdef HAS_UV\n @location(3) texCoords: vec2<f32>,\n#endif\n#ifdef HAS_UV_REGIONS\n @location(4) uvRegions: vec4<f32>,\n#endif\n#ifdef HAS_FEATURE_IDS\n @location(5) rowIndexes: u32,\n#endif\n @location(6) instanceColors: vec4<f32>,\n @location(7) instanceModelMatrixCol0: vec3<f32>,\n @location(8) instanceModelMatrixCol1: vec3<f32>,\n @location(9) instanceModelMatrixCol2: vec3<f32>,\n};\n\nstruct FragmentInputs {\n @builtin(position) position: vec4<f32>,\n @location(0) color: vec4<f32>,\n @location(1) texCoord: vec2<f32>,\n @location(2) pbrPosition: vec3<f32>,\n @location(3) pbrNormal: vec3<f32>,\n @location(4) pickingColor: vec3<f32>,\n};\n\nfn applyUVRegion(uv: vec2<f32>, uvRegion: vec4<f32>) -> vec2<f32> {\n#ifdef HAS_UV_REGIONS\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md\n return fract(uv) * (uvRegion.zw - uvRegion.xy) + uvRegion.xy;\n#else\n return uv;\n#endif\n}\n\n@vertex\nfn vertexMain(\n inputs: VertexInputs,\n @builtin(instance_index) instanceIndex: u32\n) -> FragmentInputs {\n var outputs: FragmentInputs;\n var texCoord = vec2<f32>(0.0);\n var normal = vec3<f32>(0.0, 0.0, 1.0);\n var uvRegion = vec4<f32>(0.0);\n\n#ifdef HAS_UV\n texCoord = inputs.texCoords;\n#endif\n#ifdef HAS_NORMALS\n normal = inputs.normals;\n#endif\n#ifdef HAS_UV_REGIONS\n uvRegion = inputs.uvRegions;\n#endif\n\n texCoord = applyUVRegion(texCoord, uvRegion);\n geometry.uv = texCoord;\n#ifdef HAS_FEATURE_IDS\n geometry.pickingColor = picking_getPickingColorFromIndex(inputs.rowIndexes);\n#else\n geometry.pickingColor = picking_getPickingColorFromIndex(instanceIndex);\n#endif\n\n let instanceModelMatrix = mat3x3<f32>(\n inputs.instanceModelMatrixCol0,\n inputs.instanceModelMatrixCol1,\n inputs.instanceModelMatrixCol2\n );\n let commonPosition = vec4<f32>(project_position_vec3_f32(inputs.positions), 1.0);\n\n geometry.position = commonPosition;\n geometry.normal = project_normal(instanceModelMatrix * normal);\n\n outputs.position = project_common_position_to_clipspace(commonPosition);\n outputs.color = vec4<f32>(\n inputs.colors.rgb * inputs.instanceColors.rgb,\n inputs.instanceColors.a\n );\n outputs.texCoord = texCoord;\n outputs.pbrPosition = commonPosition.xyz;\n outputs.pbrNormal = geometry.normal;\n outputs.pickingColor = geometry.pickingColor;\n return outputs;\n}\n\n@fragment\nfn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {\n fragmentGeometry.uv = inputs.texCoord;\n\n if (picking.isActive > 0.5) {\n if (!picking_isColorValid(inputs.pickingColor)) {\n discard;\n }\n return vec4<f32>(inputs.pickingColor, 1.0);\n }\n\n fragmentInputs.pbr_vPosition = inputs.pbrPosition;\n fragmentInputs.pbr_vUV0 = inputs.texCoord;\n fragmentInputs.pbr_vUV1 = vec2<f32>(0.0);\n fragmentInputs.pbr_vNormal = inputs.pbrNormal;\n\n var color = inputs.color * pbr_filterColor(vec4<f32>(0.0));\n color.a *= layer.opacity;\n\n if (picking.isHighlightActive > 0.5) {\n let highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);\n if (picking_isColorZero(abs(inputs.pickingColor - highlightedObjectColor))) {\n let highlightAlpha = picking.highlightColor.a;\n let blendedAlpha = highlightAlpha + color.a * (1.0 - highlightAlpha);\n if (blendedAlpha > 0.0) {\n color = vec4<f32>(\n mix(color.rgb, picking.highlightColor.rgb, highlightAlpha / blendedAlpha),\n blendedAlpha\n );\n }\n }\n }\n\n return deckgl_premultiplied_alpha(color);\n}\n",modules:[...e.modules,Qp,Hp]}}initializeState(){const{featureIds:e}=this.props;super.initializeState();const t=this.getAttributeManager();e&&t.add({rowIndexes:{type:"uint32",size:1,noAlloc:!0,update:this.calculateFeatureIdsPickingIndexes}})}updateState(e){super.updateState(e);const{props:t,oldProps:n}=e;t.pbrMaterial!==n.pbrMaterial&&this.updatePbrMaterialUniforms(t.pbrMaterial)}draw(e){const{featureIds:t}=this.props,{model:n}=this.state;if(!n)return;const r={pickFeatureIds:Boolean(t)},i={camera:this.context.viewport.cameraPosition};n.shaderInputs.setProps({pbrProjection:i,mesh:r}),super.draw(e)}getModel(e){const{id:t}=this.props,n=this.parseMaterial(this.props.pbrMaterial,e);this.setState({parsedPBRMaterial:n});const r=this.getShaders();return function(e){const t=e.positions||e.POSITION,n=t.value.length/t.size;e.COLOR_0||e.colors||(e.colors={size:4,value:new Uint8Array(4*n).fill(255),normalized:!0})}(e.attributes),new p(this.context.device,{...this.getShaders(),id:t,geometry:e,bufferLayout:this.getAttributeManager().getBufferLayouts(),defines:{...r.defines,...n?.defines,HAS_UV_REGIONS:e.attributes.uvRegions?1:0,HAS_FEATURE_IDS:this.props.featureIds?1:0},parameters:n?.parameters,isInstanced:!0})}updatePbrMaterialUniforms(e){const{model:t}=this.state;if(t){const{mesh:n}=this.props,r=this.parseMaterial(e,n);this.setState({parsedPBRMaterial:r});const{pbr_baseColorSampler:i}=r.bindings,{emptyTexture:a}=this.state,s=i||a,o={..."webgpu"===this.context.device.type?{simpleMeshTexture:s}:{sampler:s},hasTexture:Boolean(i)},{camera:A,...l}={...r.bindings,...r.uniforms};t.shaderInputs.setProps({simpleMesh:o,pbrMaterial:l})}}parseMaterial(e,t){const n=Boolean(e.pbrMetallicRoughness&&e.pbrMetallicRoughness.baseColorTexture);return du(this.context.device,{unlit:n,...e},{NORMAL:t.attributes.normals,TEXCOORD_0:t.attributes.texCoords},{pbrDebug:!1,lights:!0,useTangents:!1})}calculateFeatureIdsPickingIndexes(e){const t=this.props.featureIds;e.value=new Uint32Array(t)}finalizeState(e){super.finalizeState(e),this.state.parsedPBRMaterial?.generatedTextures.forEach(e=>e.destroy()),this.setState({parsedPBRMaterial:null})}};Kp.layerName="MeshLayer",Kp.defaultProps={pbrMaterial:{type:"object",value:null},featureIds:{type:"array",value:null,optional:!0}};var Wp=6378137,Jp=6378137,$p=6356752.314245179;Math.max(Wp,Jp,$p);function Xp(e){return e}new de;function Yp(e,t=[]){return function(e,t=[],n=Xp){return"longitude"in e?(t[0]=n(e.longitude),t[1]=n(e.latitude),t[2]=e.height):"x"in e?(t[0]=n(e.x),t[1]=n(e.y),t[2]=e.z):(t[0]=n(e[0]),t[1]=n(e[1]),t[2]=e[2]),t}(e,t,le._cartographicRadians?Xp:O)}function Zp(e,t){return function(e,t,n=Xp){return"longitude"in t?(t.longitude=n(e[0]),t.latitude=n(e[1]),t.height=e[2]):"x"in t?(t.x=n(e[0]),t.y=n(e[1]),t.z=e[2]):(t[0]=n(e[0]),t[1]=n(e[1]),t[2]=e[2]),t}(e,t,le._cartographicRadians?Xp:B)}var em=new de,tm={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},nm={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},rm={east:new de,north:new de,up:new de,west:new de,south:new de,down:new de},im=new de,am=new de,sm=new de;function om(e,t,n,r,i,a){const s=tm[t]&&tm[t][n];let o,A,l;N(s&&(!r||r===s));const c=em.copy(i);if(D(c.x,0,1e-14)&&D(c.y,0,1e-14)){const e=Math.sign(c.z);o=im.fromArray(nm[t]),"east"!==t&&"west"!==t&&o.scale(e),A=am.fromArray(nm[n]),"east"!==n&&"west"!==n&&A.scale(e),l=sm.fromArray(nm[r]),"east"!==r&&"west"!==r&&l.scale(e)}else{const{up:i,east:a,north:s}=rm;a.set(-c.y,c.x,0).normalize(),e.geodeticSurfaceNormal(c,i),s.copy(i).cross(a);const{down:u,west:f,south:d}=rm;u.copy(i).scale(-1),f.copy(a).scale(-1),d.copy(s).scale(-1),o=rm[t],A=rm[n],l=rm[r]}return a[0]=o.x,a[1]=o.y,a[2]=o.z,a[3]=0,a[4]=A.x,a[5]=A.y,a[6]=A.z,a[7]=0,a[8]=l.x,a[9]=l.y,a[10]=l.z,a[11]=0,a[12]=c.x,a[13]=c.y,a[14]=c.z,a[15]=1,a}var Am=new de,lm=new de,cm=new de;var um=new de,fm=new de,dm=new de,hm=new de,pm=new de,mm=new de,gm=class{constructor(e=0,t=0,n=0){this.centerToleranceSquared=.1,N(e>=0),N(t>=0),N(n>=0),this.radii=new de(e,t,n),this.radiiSquared=new de(e*e,t*t,n*n),this.radiiToTheFourth=new de(e*e*e*e,t*t*t*t,n*n*n*n),this.oneOverRadii=new de(0===e?0:1/e,0===t?0:1/t,0===n?0:1/n),this.oneOverRadiiSquared=new de(0===e?0:1/(e*e),0===t?0:1/(t*t),0===n?0:1/(n*n)),this.minimumRadius=Math.min(e,t,n),this.maximumRadius=Math.max(e,t,n),0!==this.radiiSquared.z&&(this.squaredXOverSquaredZ=this.radiiSquared.x/this.radiiSquared.z),Object.freeze(this)}equals(e){return this===e||Boolean(e&&this.radii.equals(e.radii))}toString(){return this.radii.toString()}cartographicToCartesian(e,t=[0,0,0]){const n=fm,r=dm,[,,i]=e;this.geodeticSurfaceNormalCartographic(e,n),r.copy(this.radiiSquared).scale(n);const a=Math.sqrt(n.dot(r));return r.scale(1/a),n.scale(i),r.add(n),r.to(t)}cartesianToCartographic(e,t=[0,0,0]){mm.from(e);const n=this.scaleToGeodeticSurface(mm,hm);if(!n)return;const r=this.geodeticSurfaceNormal(n,fm),i=pm;i.copy(mm).subtract(n);return Zp([Math.atan2(r.y,r.x),Math.asin(r.z),Math.sign(X(i,mm))*te(i)],t)}eastNorthUpToFixedFrame(e,t=new H){return om(this,"east","north","up",e,t)}localFrameToFixedFrame(e,t,n,r,i=new H){return om(this,e,t,n,r,i)}geocentricSurfaceNormal(e,t=[0,0,0]){return um.from(e).normalize().to(t)}geodeticSurfaceNormalCartographic(e,t=[0,0,0]){const n=Yp(e),r=n[0],i=n[1],a=Math.cos(i);return um.set(a*Math.cos(r),a*Math.sin(r),Math.sin(i)).normalize(),um.to(t)}geodeticSurfaceNormal(e,t=[0,0,0]){return um.from(e).scale(this.oneOverRadiiSquared).normalize().to(t)}scaleToGeodeticSurface(e,t){return function(e,t,n=[]){const{oneOverRadii:r,oneOverRadiiSquared:i,centerToleranceSquared:a}=t;Am.from(e);const s=Am.x,o=Am.y,A=Am.z,l=r.x,c=r.y,u=r.z,f=s*s*l*l,d=o*o*c*c,h=A*A*u*u,p=f+d+h,m=Math.sqrt(1/p);if(!Number.isFinite(m))return;const g=lm;if(g.copy(e).scale(m),p<a)return g.to(n);const b=i.x,v=i.y,y=i.z,x=cm;x.set(g.x*b*2,g.y*v*2,g.z*y*2);let _,w,T,S,M=(1-m)*Am.len()/(.5*x.len()),E=0;do{M-=E,_=1/(1+M*b),w=1/(1+M*v),T=1/(1+M*y);const e=_*_,t=w*w,n=T*T;S=f*e+d*t+h*n-1,E=S/(-2*(f*(e*_)*b+d*(t*w)*v+h*(n*T)*y))}while(Math.abs(S)>1e-12);return Am.scale([_,w,T]).to(n)}(e,this,t)}scaleToGeocentricSurface(e,t=[0,0,0]){hm.from(e);const n=hm.x,r=hm.y,i=hm.z,a=this.oneOverRadiiSquared,s=1/Math.sqrt(n*n*a.x+r*r*a.y+i*i*a.z);return hm.multiplyScalar(s).to(t)}transformPositionToScaledSpace(e,t=[0,0,0]){return hm.from(e).scale(this.oneOverRadii).to(t)}transformPositionFromScaledSpace(e,t=[0,0,0]){return hm.from(e).scale(this.radii).to(t)}getSurfaceNormalIntersectionWithZAxis(e,t=0,n=[0,0,0]){N(D(this.radii.x,this.radii.y,1e-15)),N(this.radii.z>0),hm.from(e);const r=hm.z*(1-this.squaredXOverSquaredZ);if(!(Math.abs(r)>=this.radii.z-t))return hm.set(0,0,r).to(n)}};gm.WGS84=new gm(Wp,Jp,$p);var bm=class{item;previous;next;constructor(e,t,n){this.item=e,this.previous=t,this.next=n}},vm=class{head=null;tail=null;_length=0;get length(){return this._length}add(e){const t=new bm(e,this.tail,null);return this.tail?(this.tail.next=t,this.tail=t):(this.head=t,this.tail=t),++this._length,t}remove(e){e&&(e.previous&&e.next?(e.previous.next=e.next,e.next.previous=e.previous):e.previous?(e.previous.next=null,this.tail=e.previous):e.next?(e.next.previous=null,this.head=e.next):(this.head=null,this.tail=null),e.next=null,e.previous=null,--this._length)}splice(e,t){e!==t&&(this.remove(t),this._insert(e,t))}_insert(e,t){const n=e.next;e.next=t,this.tail===e?this.tail=t:n.previous=t,t.next=n,t.previous=e,++this._length}},ym=class{_list;_sentinel;_trimTiles;constructor(){this._list=new vm,this._sentinel=this._list.add("sentinel"),this._trimTiles=!1}reset(){this._list.splice(this._list.tail,this._sentinel)}touch(e){const t=e._cacheNode;t&&this._list.splice(this._sentinel,t)}add(e,t,n){t._cacheNode||(t._cacheNode=this._list.add(t),n&&n(e,t))}unloadTile(e,t,n){const r=t._cacheNode;r&&(this._list.remove(r),t._cacheNode=null,n&&n(e,t))}unloadTiles(e,t){const n=this._trimTiles;this._trimTiles=!1;const r=this._list,i=1024*e.maximumMemoryUsage*1024,a=this._sentinel;let s=r.head;for(;s!==a&&(e.gpuMemoryUsageInBytes>i||n);){const n=s.item;s=s.next,this.unloadTile(e,n,t)}}trim(){this._trimTiles=!0}};function xm(e,t){Y(e),Y(t);const{rtcCenter:n,gltfUpAxis:r}=t,{computedTransform:i,boundingVolume:{center:a}}=e;let s=new H(i);switch(n&&s.translate(n),r){case"Z":break;case"Y":const e=(new H).rotateX(Math.PI/2);s=s.multiplyRight(e);break;case"X":const t=(new H).rotateY(-Math.PI/2);s=s.multiplyRight(t)}t.isQuantized&&s.translate(t.quantizedVolumeOffset).scale(t.quantizedVolumeScale);const o=new de(a);t.cartesianModelMatrix=s,t.cartesianOrigin=o;const A=gm.WGS84.cartesianToCartographic(o,new de);t.cartographicModelMatrix=gm.WGS84.eastNorthUpToFixedFrame(o).invert().multiplyRight(s),t.cartographicOrigin=A;const l=function(e){const t=e.gltf;if(!t)return null;const n="number"==typeof t.scene?t.scene:0,r=(t.scenes?.[n])?.nodes?.[0];if(!r?.matrix)return null;const i=r.matrix;return i[12]*i[12]+i[13]*i[13]+i[14]*i[14]<=_m?null:r}(t);l&&(t.cartesianModelMatrix=new H(s).multiplyRight(l.matrix),t.cartographicModelMatrix.multiplyRight(l.matrix),l.matrix=H.IDENTITY),t.coordinateSystem||(t.modelMatrix=t.cartographicModelMatrix)}var _m=1e6**2;var wm=new de,Tm=new de,Sm=new Pl([new El,new El,new El,new El,new El,new El]);function Mm(e,t){const{cameraDirection:n,cameraUp:r,height:i}=e,{metersPerUnit:a}=e.distanceScales,s=Cm(e,e.center),o=gm.WGS84.eastNorthUpToFixedFrame(s),A=e.unprojectPosition(e.cameraPosition),l=gm.WGS84.cartographicToCartesian(A,new de),c=new de(o.transformAsVector(new de(n).scale(a))).normalize(),u=new de(o.transformAsVector(new de(r).scale(a))).normalize();!function(e){const t=e.getFrustumPlanes(),n=Em(t.near,e.cameraPosition),r=Cm(e,n),i=Cm(e,e.cameraPosition,Tm);let a=0;Sm.planes[a++].fromPointNormal(r,wm.copy(r).subtract(i));for(const s in t){if("near"===s)continue;const i=Cm(e,Em(t[s],n,Tm),Tm);Sm.planes[a++].fromPointNormal(i,wm.copy(r).subtract(i))}}(e);const f=e.constructor,{longitude:d,latitude:h,width:p,bearing:m,zoom:g}=e;return{camera:{position:l,direction:c,up:u},viewport:e,topDownViewport:new f({longitude:d,latitude:h,height:i,width:p,bearing:m,zoom:g,pitch:0}),height:i,cullingVolume:Sm,frameNumber:t,sseDenominator:1.15}}function Em(e,t,n=new de){const r=e.normal.dot(t);return n.copy(e.normal).scale(e.distance-r).add(t),n}function Cm(e,t,n=new de){const r=e.unprojectPosition(t);return gm.WGS84.cartographicToCartesian(r,n)}var Im=6356752.314245179,Rm=new de;function Pm(e,t){if(e instanceof Tl){const{halfAxes:n}=e,r=function(e){e.getColumn(0,Rm);const t=e.getColumn(1),n=e.getColumn(2);return Rm.add(t).add(n).len()}(n);return Math.log2(Im/(r+t[2]))}if(e instanceof ol){const{radius:n}=e;return Math.log2(Im/(n+t[2]))}if(e.width&&e.height){const{width:t,height:n}=e;return(Math.log2(6378137/t)+Math.log2(6378137/n))/2}return 1}function Nm(e,t,n){gm.WGS84.cartographicToCartesian([e.xmax,e.ymax,e.zmax],Rm);const r=Math.sqrt(Math.pow(Rm[0]-n[0],2)+Math.pow(Rm[1]-n[1],2)+Math.pow(Rm[2]-n[2],2));return Math.log2(Im/(r+t[2]))}var km,Lm,Bm,Om,Fm=0,Dm=1,Um=3,Vm=4,jm=5;!function(e){e[e.ADD=1]="ADD",e[e.REPLACE=2]="REPLACE"}(km||(km={})),function(e){e.EMPTY="empty",e.SCENEGRAPH="scenegraph",e.POINTCLOUD="pointcloud",e.MESH="mesh"}(Lm||(Lm={})),function(e){e.I3S="I3S",e.TILES3D="TILES3D"}(Bm||(Bm={})),function(e){e.GEOMETRIC_ERROR="geometricError",e.MAX_SCREEN_THRESHOLD="maxScreenThreshold"}(Om||(Om={}));var zm=1;function Gm(e){return null!=e}var Hm=new de,qm=new de,Qm=new de,Km=new de,Wm=new de,Jm=new de,$m=new de,Xm=new de;function Ym(e,t,n){if(Y(e,"3D Tile: boundingVolume must be defined"),e.box)return eg(e.box,t,n);if(e.region)return function(e){const[t,n,r,i,a,s]=e,o=gm.WGS84.cartographicToCartesian([F(t),F(i),a],Qm),A=gm.WGS84.cartographicToCartesian([F(r),F(n),s],Km),l=(new de).addVectors(o,A).multiplyByScalar(.5);return gm.WGS84.cartesianToCartographic(l,Wm),gm.WGS84.cartographicToCartesian([F(r),Wm[1],Wm[2]],Jm),gm.WGS84.cartographicToCartesian([Wm[0],F(i),Wm[2]],$m),gm.WGS84.cartographicToCartesian([Wm[0],Wm[1],s],Xm),eg([...l,...Jm.subtract(l),...$m.subtract(l),...Xm.subtract(l)],new H)}(e.region);if(e.sphere)return function(e,t,n){const r=new de(e[0],e[1],e[2]);t.transform(r,r);const i=t.getScale(qm),a=Math.max(Math.max(i[0],i[1]),i[2]),s=e[3]*a;if(Gm(n))return n.center=r,n.radius=s,n;return new ol(r,s)}(e.sphere,t,n);throw new Error("3D Tile: boundingVolume must contain a sphere, region, or box")}function Zm(e,t){if(e.box)return function(e){const t=tg(),{halfAxes:n}=e,r=new de(n.getColumn(0)),i=new de(n.getColumn(1)),a=new de(n.getColumn(2));for(let s=0;s<2;s++){for(let n=0;n<2;n++){for(let n=0;n<2;n++)Hm.copy(e.center),Hm.add(r),Hm.add(i),Hm.add(a),ng(t,Hm),a.negate();i.negate()}r.negate()}return t}(t);if(e.region){const[t,n,r,i,a,s]=e.region;return[[F(t),F(n),a],[F(r),F(i),s]]}if(e.sphere)return function(e){const t=tg(),{center:n,radius:r}=e,i=gm.WGS84.scaleToGeodeticSurface(n,Hm);let a;a=i?gm.WGS84.geodeticSurfaceNormal(i):new de(0,0,1);let s=new de(a[2],-a[1],0);s.len()>0?s.normalize():s=new de(0,1,0);const o=s.clone().cross(a);for(const A of[s,o,a]){qm.copy(A).scale(r);for(let e=0;e<2;e++)Hm.copy(n),Hm.add(qm),ng(t,Hm),qm.negate()}return t}(t);throw new Error("Unkown boundingVolume type")}function eg(e,t,n){const r=new de(e[0],e[1],e[2]);t.transform(r,r);let i=[];if(10===e.length){const t=e.slice(3,6),n=new Oe;n.fromArray(e,6);const r=new de([1,0,0]),a=new de([0,1,0]),s=new de([0,0,1]);r.transformByQuaternion(n),r.scale(t[0]),a.transformByQuaternion(n),a.scale(t[1]),s.transformByQuaternion(n),s.scale(t[2]),i=[...r.toArray(),...a.toArray(),...s.toArray()]}else i=[...e.slice(3,6),...e.slice(6,9),...e.slice(9,12)];const a=t.transformAsVector(i.slice(0,3)),s=t.transformAsVector(i.slice(3,6)),o=t.transformAsVector(i.slice(6,9)),A=new Mt([a[0],a[1],a[2],s[0],s[1],s[2],o[0],o[1],o[2]]);return Gm(n)?(n.center=r,n.halfAxes=A,n):new Tl(r,A)}function tg(){return[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]]}function ng(e,t){gm.WGS84.cartesianToCartographic(t,Hm),e[0][0]=Math.min(e[0][0],Hm[0]),e[0][1]=Math.min(e[0][1],Hm[1]),e[0][2]=Math.min(e[0][2],Hm[2]),e[1][0]=Math.max(e[1][0],Hm[0]),e[1][1]=Math.max(e[1][1],Hm[1]),e[1][2]=Math.max(e[1][2],Hm[2])}new de,new de,new H,new de,new de,new de;function rg(e,t){if(e.dynamicScreenSpaceError&&e.dynamicScreenSpaceErrorComputedDensity){const n=e.dynamicScreenSpaceErrorComputedDensity,r=e.dynamicScreenSpaceErrorFactor;return function(e,t){const n=e*t;return 1-Math.exp(-n*n)}(t,n)*r}return 0}var ig=new de,ag=new de,sg=new de,og=new de,Ag=new de,lg=new H,cg=new H;function ug(e,t){const{topDownViewport:n}=t,r=e.header.mbs[1],i=e.header.mbs[0],a=e.header.mbs[2],s=e.header.mbs[3],o=[...e.boundingVolume.center],A=n.unprojectPosition(n.cameraPosition);gm.WGS84.cartographicToCartesian(A,ig),ag.copy(ig).subtract(o).normalize(),gm.WGS84.eastNorthUpToFixedFrame(o,lg),cg.copy(lg).invert(),sg.copy(ig).transform(cg);const l=Math.sqrt(sg[0]*sg[0]+sg[1]*sg[1]),c=l*l/sg[2];og.copy([sg[0],sg[1],c]);const u=og.transform(lg).subtract(o).normalize(),f=ag.cross(u).normalize().scale(s).add(o),d=gm.WGS84.cartesianToCartographic(f),h=n.project([i,r,a]),p=n.project(d);return Ag.copy(h).subtract(p).magnitude()}var fg=class{_map=/* @__PURE__ */new Map;_array;_length;constructor(e=0){this._array=new Array(e),this._length=e}get length(){return this._length}set length(e){this._length=e,e>this._array.length&&(this._array.length=e)}get values(){return this._array}get(e){return Y(e<this._array.length),this._array[e]}set(e,t){Y(e>=0),e>=this.length&&(this.length=e+1),this._map.has(this._array[e])&&this._map.delete(this._array[e]),this._array[e]=t,this._map.set(t,e)}delete(e){const t=this._map.get(e);t>=0&&(this._array.splice(t,1),this._map.delete(e),this.length--)}peek(){return this._array[this._length-1]}push(e){if(!this._map.has(e)){const t=this.length++;this._array[t]=e,this._map.set(e,t)}}pop(){const e=this._array[--this.length];return this._map.delete(e),e}reserve(e){Y(e>=0),e>this._array.length&&(this._array.length=e)}resize(e){Y(e>=0),this.length=e}trim(e){null==e&&(e=this.length),this._array.length=e}reset(){this._array=[],this._map=/* @__PURE__ */new Map,this._length=0}find(e){return this._map.has(e)}},dg={loadSiblings:!1,skipLevelOfDetail:!1,updateTransforms:!0,onTraversalEnd:()=>{},viewportTraversersMap:{},basePath:""},hg=class{options;root=null;selectedTiles={};requestedTiles={};emptyTiles={};lastUpdate=/* @__PURE__ */(new Date).getTime();updateDebounceTime=1e3;_traversalStack=new fg;_emptyTraversalStack=new fg;_frameNumber=null;traversalFinished(e){return!0}constructor(e){this.options={...dg,...e}}traverse(e,t,n){this.root=e,this.options={...this.options,...n},this.reset(),this.updateTile(e,t),this._frameNumber=t.frameNumber,this.executeTraversal(e,t)}reset(){this.requestedTiles={},this.selectedTiles={},this.emptyTiles={},this._traversalStack.reset(),this._emptyTraversalStack.reset()}executeTraversal(e,t){const n=this._traversalStack;for(e._selectionDepth=1,n.push(e);n.length>0;){const e=n.pop();let r=!1;this.canTraverse(e,t)&&(this.updateChildTiles(e,t),r=this.updateAndPushChildren(e,t,n,e.hasRenderContent?e._selectionDepth+1:e._selectionDepth));const i=e.parent,a=Boolean(!i||i._shouldRefine),s=!r;e.hasRenderContent?e.refine===km.ADD?(this.loadTile(e,t),this.selectTile(e,t)):e.refine===km.REPLACE&&(this.loadTile(e,t),s&&this.selectTile(e,t)):(this.emptyTiles[e.id]=e,this.loadTile(e,t),s&&this.selectTile(e,t)),this.touchTile(e,t),e._shouldRefine=r&&a}const r=/* @__PURE__ */(new Date).getTime();(this.traversalFinished(t)||r-this.lastUpdate>this.updateDebounceTime)&&(this.lastUpdate=r,this.options.onTraversalEnd(t))}updateChildTiles(e,t){const n=e.children;for(const r of n)this.updateTile(r,t)}updateAndPushChildren(e,t,n,r){const{loadSiblings:i,skipLevelOfDetail:a}=this.options,s=e.children;s.sort(this.compareDistanceToCamera.bind(this));const o=e.refine===km.REPLACE&&e.hasRenderContent&&!a;let A=!1,l=!0;for(const c of s)if(c._selectionDepth=r,c.isVisibleAndInRequestVolume?(n.find(c)&&n.delete(c),n.push(c),A=!0):(o||i)&&(this.loadTile(c,t),this.touchTile(c,t)),o){let e;if(e=!!c._inRequestVolume&&(c.hasRenderContent?c.contentAvailable:this.executeEmptyTraversal(c,t)),l=l&&e,!l)return!1}return A||(l=!1),l}updateTile(e,t){this.updateTileVisibility(e,t)}selectTile(e,t){this.shouldSelectTile(e)&&(e._selectedFrame=t.frameNumber,this.selectedTiles[e.id]=e)}loadTile(e,t){this.shouldLoadTile(e)&&(e._requestedFrame=t.frameNumber,e._priority=e._getPriority(),this.requestedTiles[e.id]=e)}touchTile(e,t){e.tileset._cache.touch(e),e._touchedFrame=t.frameNumber}canTraverse(e,t){return!!e.hasChildren&&(e.hasTilesetContent?!e.contentExpired:this.shouldRefine(e,t))}shouldLoadTile(e){return e.hasUnloadedContent||e.contentExpired}shouldSelectTile(e){return e.contentAvailable&&!this.options.skipLevelOfDetail}shouldRefine(e,t,n=!1){let r=e._screenSpaceError;return n&&(r=e.getScreenSpaceError(t,!0)),r>e.tileset.memoryAdjustedScreenSpaceError}updateTileVisibility(e,t){const n=[];if(this.options.viewportTraversersMap)for(const r in this.options.viewportTraversersMap)this.options.viewportTraversersMap[r]===t.viewport.id&&n.push(r);else n.push(t.viewport.id);e.updateVisibility(t,n)}compareDistanceToCamera(e,t){return e._distanceToCamera-t._distanceToCamera}anyChildrenVisible(e,t){let n=!1;for(const r of e.children)r.updateVisibility(t),n=n||r.isVisibleAndInRequestVolume;return n}executeEmptyTraversal(e,t){let n=!0;const r=this._emptyTraversalStack;for(r.push(e);r.length>0;){const e=r.pop(),i=!e.hasRenderContent&&this.canTraverse(e,t),a=!e.hasRenderContent&&0===e.children.length;if(i||e.contentAvailable||a||(n=!1),this.updateTile(e,t),e.isVisibleAndInRequestVolume||(this.loadTile(e,t),this.touchTile(e,t)),i){const t=e.children;for(const e of t)r.push(e)}}return e.hasEmptyContent||n}},pg=new de;var mg=class{tileset;header;id;url;parent;refine;type;contentUrl;lodMetricType="geometricError";lodMetricValue=0;boundingVolume=null;content=null;contentState=Fm;gpuMemoryUsageInBytes=0;children=[];depth=0;viewportIds=[];transform=new H;extensions=null;implicitTiling=null;userData={};computedTransform;hasEmptyContent=!1;hasTilesetContent=!1;traverser=new hg({});_cacheNode=null;_frameNumber=null;_expireDate=null;_expiredContent=null;_boundingBox=void 0;_distanceToCamera=0;_screenSpaceError=0;_visibilityPlaneMask;_visible=void 0;_contentBoundingVolume;_viewerRequestVolume;_initialTransform=new H;_priority=0;_selectedFrame=0;_requestedFrame=0;_selectionDepth=0;_touchedFrame=0;_centerZDepth=0;_shouldRefine=!1;_stackLength=0;_visitedFrame=0;_inRequestVolume=!1;_lodJudge=null;tileDrawn=!0;constructor(e,t,n,r=""){this.header=t,this.tileset=e,this.id=r||t.id,this.url=t.url,this.parent=n,this.refine=this._getRefine(t.refine),this.type=t.type,this.contentUrl=t.contentUrl,this._initializeLodMetric(t),this._initializeTransforms(t),this._initializeBoundingVolumes(t),this._initializeContent(t),this._initializeRenderingState(t),Object.seal(this)}destroy(){this.header=null}isDestroyed(){return null===this.header}get selected(){return this._selectedFrame===this.tileset._frameNumber}get isVisible(){return this._visible}get isVisibleAndInRequestVolume(){return this._visible&&this._inRequestVolume}get hasRenderContent(){return!this.hasEmptyContent&&!this.hasTilesetContent}get hasChildren(){return this.children.length>0||this.header.children&&this.header.children.length>0}get contentReady(){return this.contentState===Um||this.hasEmptyContent}get contentAvailable(){return Boolean(this.contentReady&&this.hasRenderContent||this._expiredContent&&!this.contentFailed)}get hasUnloadedContent(){return this.hasRenderContent&&this.contentUnloaded}get contentUnloaded(){return this.contentState===Fm}get contentExpired(){return this.contentState===Vm}get contentFailed(){return this.contentState===jm}get distanceToCamera(){return this._distanceToCamera}get screenSpaceError(){return this._screenSpaceError}get boundingBox(){return this._boundingBox||(this._boundingBox=Zm(this.header.boundingVolume,this.boundingVolume)),this._boundingBox}getScreenSpaceError(e,t){switch(this.tileset.type){case Bm.I3S:return ug(this,e);case Bm.TILES3D:return function(e,t,n){const r=e.tileset,i=e.parent&&e.parent.lodMetricValue||e.lodMetricValue,a=n?i:e.lodMetricValue;if(0===a)return 0;const s=Math.max(e._distanceToCamera,1e-7),{height:o,sseDenominator:A}=t,{viewDistanceScale:l}=r.options;let c=a*o*(l||1)/(s*A);return c-=rg(r,s),c}(this,e,t);default:throw new Error("Unsupported tileset type")}}unselect(){this._selectedFrame=0}_getGpuMemoryUsageInBytes(){return this.content.gpuMemoryUsageInBytes||this.content.byteLength||0}_getPriority(){const e=this.tileset._traverser,{skipLevelOfDetail:t}=e.options,n=this.refine===km.ADD||t;if(n&&!this.isVisible&&void 0!==this._visible)return-1;if(this.tileset._frameNumber-this._touchedFrame>=1)return-1;if(this.contentState===Fm)return-1;const r=this.parent,i=!r||n&&0!==this._screenSpaceError&&!r.hasTilesetContent?this._screenSpaceError:r._screenSpaceError,a=e.root?e.root._screenSpaceError:0;return Math.max(a-i,0)}async loadContent(){if(this.hasEmptyContent)return!1;if(this.content)return!0;this.contentExpired&&(this._expireDate=null),this.contentState=Dm;const e=await this.tileset._requestScheduler.scheduleRequest(this.id,this._getPriority.bind(this));if(!e)return this.contentState=Fm,!1;try{const e=this.tileset.getTileUrl(this.contentUrl),t=this.tileset.loader,n=this.tileset.loadOptions[t.id]||{},r={...this.tileset.loadOptions,[t.id]:{...n,isTileset:"json"===this.type,...this._getLoaderSpecificOptions(t.id)}};return this.content=await Ae(e,t,r),this.tileset.options.contentLoader&&await this.tileset.options.contentLoader(this),this._isTileset()&&this.tileset._initializeTileHeaders(this.content,this),this.contentState=Um,this._onContentLoaded(),!0}catch(t){throw this.contentState=jm,t}finally{e.done()}}unloadContent(){return this.content&&this.content.destroy&&this.content.destroy(),this.content=null,this.header.content&&this.header.content.destroy&&this.header.content.destroy(),this.header.content=null,this.contentState=Fm,this.tileDrawn=!0,!0}updateVisibility(e,t){if(this._frameNumber===e.frameNumber)return;const n=this.parent,r=n?n._visibilityPlaneMask:Pl.MASK_INDETERMINATE;if(this.tileset._traverser.options.updateTransforms){const e=n?n.computedTransform:this.tileset.modelMatrix;this._updateTransform(e)}this._distanceToCamera=this.distanceToTile(e),this._screenSpaceError=this.getScreenSpaceError(e,!1),this._visibilityPlaneMask=this.visibility(e,r),this._visible=this._visibilityPlaneMask!==Pl.MASK_OUTSIDE,this._inRequestVolume=this.insideViewerRequestVolume(e),this._frameNumber=e.frameNumber,this.viewportIds=t}visibility(e,t){const{cullingVolume:n}=e,{boundingVolume:r}=this;return n.computeVisibilityWithPlaneMask(r,t)}contentVisibility(){return!0}distanceToTile(e){const t=this.boundingVolume;return Math.sqrt(Math.max(t.distanceSquaredTo(e.camera.position),0))}cameraSpaceZDepth({camera:e}){const t=this.boundingVolume;return pg.subVectors(t.center,e.position),e.direction.dot(pg)}insideViewerRequestVolume(e){const t=this._viewerRequestVolume;return!t||t.distanceSquaredTo(e.camera.position)<=0}updateExpiration(){if(null!=this._expireDate&&this.contentReady&&!this.hasEmptyContent){const e=Date.now();Date.lessThan(this._expireDate,e)&&(this.contentState=Vm,this._expiredContent=this.content)}}get extras(){return this.header.extras}_initializeLodMetric(e){"lodMetricType"in e?this.lodMetricType=e.lodMetricType:(this.lodMetricType=this.parent&&this.parent.lodMetricType||this.tileset.lodMetricType,console.warn("3D Tile: Required prop lodMetricType is undefined. Using parent lodMetricType")),"lodMetricValue"in e?this.lodMetricValue=e.lodMetricValue:(this.lodMetricValue=this.parent&&this.parent.lodMetricValue||this.tileset.lodMetricValue,console.warn("3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue"))}_initializeTransforms(e){this.transform=e.transform?new H(e.transform):new H;const t=this.parent,n=this.tileset,r=t&&t.computedTransform?t.computedTransform.clone():n.modelMatrix.clone();this.computedTransform=new H(r).multiplyRight(this.transform);const i=t&&t._initialTransform?t._initialTransform.clone():new H;this._initialTransform=new H(i).multiplyRight(this.transform)}_initializeBoundingVolumes(e){this._contentBoundingVolume=null,this._viewerRequestVolume=null,this._updateBoundingVolume(e)}_initializeContent(e){this.content={_tileset:this.tileset,_tile:this},this.hasEmptyContent=!0,this.contentState=Fm,this.hasTilesetContent=!1,e.contentUrl&&(this.content=null,this.hasEmptyContent=!1)}_initializeRenderingState(e){this.depth=e.level||(this.parent?this.parent.depth+1:0),this._shouldRefine=!1,this._distanceToCamera=0,this._centerZDepth=0,this._screenSpaceError=0,this._visibilityPlaneMask=Pl.MASK_INDETERMINATE,this._visible=void 0,this._inRequestVolume=!1,this._stackLength=0,this._selectionDepth=0,this._frameNumber=0,this._touchedFrame=0,this._visitedFrame=0,this._selectedFrame=0,this._requestedFrame=0,this._priority=0}_getRefine(e){return e||this.parent&&this.parent.refine||km.REPLACE}_isTileset(){return-1!==this.contentUrl.indexOf(".json")}_onContentLoaded(){switch(this.content&&this.content.type){case"vctr":case"geom":this.tileset._traverser.disableSkipLevelOfDetail=!0}this._isTileset()?this.hasTilesetContent=!0:this.gpuMemoryUsageInBytes=this._getGpuMemoryUsageInBytes()}_updateBoundingVolume(e){this.boundingVolume=Ym(e.boundingVolume,this.computedTransform,this.boundingVolume);const t=e.content;t&&(t.boundingVolume&&(this._contentBoundingVolume=Ym(t.boundingVolume,this.computedTransform,this._contentBoundingVolume)),e.viewerRequestVolume&&(this._viewerRequestVolume=Ym(e.viewerRequestVolume,this.computedTransform,this._viewerRequestVolume)))}_updateTransform(e=new H){const t=e.clone().multiplyRight(this.transform);t.equals(this.computedTransform)||(this.computedTransform=t,this._updateBoundingVolume(this.header))}_getLoaderSpecificOptions(e){return"i3s"===e?{...this.tileset.options.i3s,_tileOptions:{attributeUrls:this.header.attributeUrls,textureUrl:this.header.textureUrl,textureFormat:this.header.textureFormat,textureLoaderOptions:this.header.textureLoaderOptions,materialDefinition:this.header.materialDefinition,isDracoGeometry:this.header.isDracoGeometry,mbs:this.header.mbs},_tilesetOptions:{store:this.tileset.tileset.store,attributeStorageInfo:this.tileset.tileset.attributeStorageInfo,fields:this.tileset.tileset.fields},isTileHeader:!1}:{assetGltfUpAxis:(t=this.tileset.tileset).asset&&t.asset.gltfUpAxis||"Y"};var t}},gg=class extends hg{compareDistanceToCamera(e,t){return 0===t._distanceToCamera&&0===e._distanceToCamera?t._centerZDepth-e._centerZDepth:t._distanceToCamera-e._distanceToCamera}updateTileVisibility(e,t){if(super.updateTileVisibility(e,t),!e.isVisibleAndInRequestVolume)return;const n=e.children.length>0;if(e.hasTilesetContent&&n){const n=e.children[0];return this.updateTileVisibility(n,t),void(e._visible=n._visible)}if(this.meetsScreenSpaceErrorEarly(e,t))return void(e._visible=!1);const r=e.refine===km.REPLACE,i=e._optimChildrenWithinParent===zm;r&&i&&n&&!this.anyChildrenVisible(e,t)&&(e._visible=!1)}meetsScreenSpaceErrorEarly(e,t){const{parent:n}=e;return!(!n||n.hasTilesetContent||n.refine!==km.ADD)&&!this.shouldRefine(e,t,!0)}},bg=class{frameNumberMap=/* @__PURE__ */new Map;register(e,t){const n=this.frameNumberMap.get(e)||/* @__PURE__ */new Map,r=n.get(t)||0;n.set(t,r+1),this.frameNumberMap.set(e,n)}deregister(e,t){const n=this.frameNumberMap.get(e);if(!n)return;const r=n.get(t)||1;n.set(t,r-1)}isZero(e,t){return 0===(this.frameNumberMap.get(e)?.get(t)||0)}},vg="REQUESTED",yg="COMPLETED",xg="ERROR",_g=class{_statusMap;pendingTilesRegister=new bg;constructor(){this._statusMap={}}add(e,t,n,r){if(!this._statusMap[t]){const{frameNumber:i,viewport:{id:a}}=r;this._statusMap[t]={request:e,callback:n,key:t,frameState:r,status:vg},this.pendingTilesRegister.register(a,i),e().then(e=>{this._statusMap[t].status=yg;const{frameNumber:n,viewport:{id:i}}=this._statusMap[t].frameState;this.pendingTilesRegister.deregister(i,n),this._statusMap[t].callback(e,r)}).catch(e=>{this._statusMap[t].status=xg;const{frameNumber:r,viewport:{id:i}}=this._statusMap[t].frameState;this.pendingTilesRegister.deregister(i,r),n(e)})}}update(e,t){if(this._statusMap[e]){const{frameNumber:n,viewport:{id:r}}=this._statusMap[e].frameState;this.pendingTilesRegister.deregister(r,n);const{frameNumber:i,viewport:{id:a}}=t;this.pendingTilesRegister.register(a,i),this._statusMap[e].frameState=t}}find(e){return this._statusMap[e]}hasPendingTiles(e,t){return!this.pendingTilesRegister.isZero(e,t)}},wg=class extends hg{_tileManager;constructor(e){super(e),this._tileManager=new _g}traversalFinished(e){return!this._tileManager.hasPendingTiles(e.viewport.id,this._frameNumber||0)}shouldRefine(e,t){return e._lodJudge=function(e,t){if(0===e.lodMetricValue||isNaN(e.lodMetricValue))return"DIG";const n=2*ug(e,t);return n<2?"OUT":!e.header.children||n<=e.lodMetricValue?"DRAW":e.header.children?"DIG":"OUT"}(e,t),"DIG"===e._lodJudge}updateChildTiles(e,t){const n=e.header.children||[],r=e.children,i=e.tileset;for(const a of n){const n=`${a.id}-${t.viewport.id}`,s=r&&r.find(e=>e.id===n);if(s)s&&this.updateTile(s,t);else{let r=()=>this._loadTile(a.id,i);this._tileManager.find(n)?this._tileManager.update(n,t):(i.tileset.nodePages&&(r=()=>i.tileset.nodePagesTile.formTileFromNodePages(a.id)),this._tileManager.add(r,n,t=>this._onTileLoad(t,e,n),t))}}return!1}async _loadTile(e,t){const{loader:n}=t,r=t.getTileUrl(`${t.url}/nodes/${e}`),i={...t.loadOptions,i3s:{...t.loadOptions.i3s,isTileHeader:!0}};return await Ae(r,n,i)}_onTileLoad(e,t,n){const r=new mg(t.tileset,e,t,n);t.children.push(r);const i=this._tileManager.find(r.id).frameState;this.updateTile(r,i),this._frameNumber===i.frameNumber&&(this.traversalFinished(i)||/* @__PURE__ */(new Date).getTime()-this.lastUpdate>this.updateDebounceTime)&&this.executeTraversal(r,i)}},Tg={description:"",ellipsoid:gm.WGS84,modelMatrix:new H,throttleRequests:!0,maxRequests:64,maximumMemoryUsage:32,memoryCacheOverflow:1,maximumTilesSelected:0,debounceTime:0,onTileLoad:()=>{},onTileUnload:()=>{},onTileError:()=>{},onTraversalComplete:e=>e,onUpdate:()=>{},contentLoader:void 0,viewDistanceScale:1,maximumScreenSpaceError:8,memoryAdjustedScreenSpaceError:!1,loadTiles:!0,updateTransforms:!0,viewportTraversersMap:null,loadOptions:{fetch:{}},attributions:[],basePath:"",i3s:{}},Sg="Tiles In Tileset(s)",Mg="Tiles In Memory",Eg="Tiles In View",Cg="Tiles To Render",Ig="Tiles Loaded",Rg="Tiles Loading",Pg="Tiles Unloaded",Ng="Failed Tile Loads",kg="Points/Vertices",Lg="Tile Memory Use",Bg="Maximum Screen Space Error",Og=class{options;loadOptions;type;tileset;loader;url;basePath;modelMatrix;ellipsoid;lodMetricType;lodMetricValue;refine;root=null;roots={};asset={};description="";properties;extras=null;attributions={};credits={};stats;contentFormats={draco:!1,meshopt:!1,dds:!1,ktx2:!1};cartographicCenter=null;cartesianCenter=null;zoom=1;boundingVolume=null;dynamicScreenSpaceErrorComputedDensity=0;maximumMemoryUsage=32;gpuMemoryUsageInBytes=0;memoryAdjustedScreenSpaceError=0;_cacheBytes=0;_cacheOverflowBytes=0;_frameNumber=0;_queryParams={};_extensionsUsed=[];_tiles={};_pendingCount=0;selectedTiles=[];traverseCounter=0;geometricError=0;lastUpdatedVieports=null;_requestedTiles=[];_emptyTiles=[];frameStateData={};_traverser;_cache=new ym;_requestScheduler;_heldTiles=/* @__PURE__ */new Set;updatePromise=null;tilesetInitializationPromise;constructor(e,t){this.options={...Tg,...t},this.tileset=e,this.loader=e.loader,this.type=e.type,this.url=e.url,this.basePath=e.basePath||he(this.url),this.modelMatrix=this.options.modelMatrix,this.ellipsoid=this.options.ellipsoid,this.lodMetricType=e.lodMetricType,this.lodMetricValue=e.lodMetricValue,this.refine=e.root.refine,this.loadOptions=this.options.loadOptions||{},this._traverser=this._initializeTraverser(),this._requestScheduler=new lt({throttleRequests:this.options.throttleRequests,maxRequests:this.options.maxRequests}),this.memoryAdjustedScreenSpaceError=this.options.maximumScreenSpaceError,this._cacheBytes=1024*this.options.maximumMemoryUsage*1024,this._cacheOverflowBytes=1024*this.options.memoryCacheOverflow*1024,this.stats=new ne({id:this.url}),this._initializeStats(),this.tilesetInitializationPromise=this._initializeTileSet(e)}destroy(){this._destroy()}isLoaded(){return 0===this._pendingCount&&0!==this._frameNumber&&0===this._requestedTiles.length}get tiles(){return Object.values(this._tiles)}get frameNumber(){return this._frameNumber}get queryParams(){return new URLSearchParams(this._queryParams).toString()}setProps(e){this.options={...this.options,...e}}getTileUrl(e){if(e.startsWith("data:"))return e;let t=e;return this.queryParams.length&&(t=`${e}${e.includes("?")?"&":"?"}${this.queryParams}`),t}hasExtension(e){return Boolean(this._extensionsUsed.indexOf(e)>-1)}update(e=null){this.tilesetInitializationPromise.then(()=>{!e&&this.lastUpdatedVieports?e=this.lastUpdatedVieports:this.lastUpdatedVieports=e,e&&this.doUpdate(e)})}async selectTiles(e=null){return await this.tilesetInitializationPromise,e&&(this.lastUpdatedVieports=e),this.updatePromise||(this.updatePromise=new Promise(e=>{setTimeout(()=>{this.lastUpdatedVieports&&this.doUpdate(this.lastUpdatedVieports),e(this._frameNumber),this.updatePromise=null},this.options.debounceTime)})),this.updatePromise}adjustScreenSpaceError(){this.gpuMemoryUsageInBytes<this._cacheBytes?this.memoryAdjustedScreenSpaceError=Math.max(this.memoryAdjustedScreenSpaceError/1.02,this.options.maximumScreenSpaceError):this.gpuMemoryUsageInBytes>this._cacheBytes+this._cacheOverflowBytes&&(this.memoryAdjustedScreenSpaceError*=1.02)}doUpdate(e){if("loadTiles"in this.options&&!this.options.loadTiles)return;if(this.traverseCounter>0)return;const t=e instanceof Array?e:[e];this._cache.reset(),this._frameNumber++,this.traverseCounter=t.length;const n=[];for(const r of t){const e=r.id;this._needTraverse(e)?n.push(e):this.traverseCounter--}for(const r of t){const e=r.id;if(this.roots[e]||(this.roots[e]=this._initializeTileHeaders(this.tileset,null)),!n.includes(e))continue;const t=Mm(r,this._frameNumber);this._traverser.traverse(this.roots[e],t,this.options)}}_needTraverse(e){let t=e;return this.options.viewportTraversersMap&&(t=this.options.viewportTraversersMap[e]),t===e}_onTraversalEnd(e){const t=e.viewport.id;this.frameStateData[t]||(this.frameStateData[t]={selectedTiles:[],_requestedTiles:[],_emptyTiles:[]});const n=this.frameStateData[t],r=Object.values(this._traverser.selectedTiles),[i,a]=function(e,t,n){if(0===n||e.length<=n)return[e,[]];const r=[],{longitude:i,latitude:a}=t.viewport;for(const[l,c]of e.entries()){const[e,t]=c.header.mbs,n=Math.abs(i-e),s=Math.abs(a-t),o=Math.sqrt(s*s+n*n);r.push([l,o])}const s=r.sort((e,t)=>e[1]-t[1]),o=[];for(let l=0;l<n;l++)o.push(e[s[l][0]]);const A=[];for(let l=n;l<s.length;l++)A.push(e[s[l][0]]);return[o,A]}(r,e,this.options.maximumTilesSelected);n.selectedTiles=i;for(const s of a)s.unselect();n._requestedTiles=Object.values(this._traverser.requestedTiles),n._emptyTiles=Object.values(this._traverser.emptyTiles),this.traverseCounter--,this.traverseCounter>0||this._updateTiles()}_updateTiles(){const e=this.selectedTiles;this.selectedTiles=[],this._requestedTiles=[],this._emptyTiles=[];for(const r in this.frameStateData){const e=this.frameStateData[r];this.selectedTiles=this.selectedTiles.concat(e.selectedTiles),this._requestedTiles=this._requestedTiles.concat(e._requestedTiles),this._emptyTiles=this._emptyTiles.concat(e._emptyTiles)}this.selectedTiles=this.options.onTraversalComplete(this.selectedTiles);const t=new Set(this.selectedTiles.map(e=>e.id));let n=0;if(this.selectedTiles.some(e=>!e.tileDrawn)){for(const e of t)this._heldTiles.add(e);for(const e of this._heldTiles){if(t.has(e))continue;const r=this._tiles[e];r&&r.contentAvailable?(r._selectedFrame=this._frameNumber,this.selectedTiles.push(r),n++):this._heldTiles.delete(e)}}else this._heldTiles=t;n>0&&setTimeout(()=>{this.selectTiles()},0);for(const r of this.selectedTiles)this._tiles[r.id]=r;this._loadTiles(),this._unloadTiles(),this._updateStats(),this._tilesChanged(e,this.selectedTiles)&&this.options.onUpdate()}_tilesChanged(e,t){if(e.length!==t.length)return!0;const n=new Set(e.map(e=>e.id)),r=new Set(t.map(e=>e.id));let i=e.filter(e=>!r.has(e.id)).length>0;return i=i||t.filter(e=>!n.has(e.id)).length>0,i}_loadTiles(){this._requestedTiles.sort((e,t)=>e._priority-t._priority);for(const e of this._requestedTiles)e.contentUnloaded&&this._loadTile(e)}_unloadTiles(){this._cache.unloadTiles(this,(e,t)=>e._unloadTile(t))}_updateStats(){let e=0,t=0;for(const n of this.selectedTiles)n.contentAvailable&&n.content&&(e++,n.content.pointCount?t+=n.content.pointCount:t+=n.content.vertexCount);this.stats.get(Eg).count=this.selectedTiles.length,this.stats.get(Cg).count=e,this.stats.get(kg).count=t,this.stats.get(Bg).count=this.memoryAdjustedScreenSpaceError}async _initializeTileSet(e){this.type===Bm.I3S&&(this.calculateViewPropsI3S(),e.root=await e.root),this.root=this._initializeTileHeaders(e,null),this.type===Bm.TILES3D&&(this._initializeTiles3DTileset(e),this.calculateViewPropsTiles3D()),this.type===Bm.I3S&&this._initializeI3STileset()}calculateViewPropsI3S(){const e=this.tileset.fullExtent;if(e){const{xmin:t,xmax:n,ymin:r,ymax:i,zmin:a,zmax:s}=e;return this.cartographicCenter=new de(t+(n-t)/2,r+(i-r)/2,a+(s-a)/2),this.cartesianCenter=new de,gm.WGS84.cartographicToCartesian(this.cartographicCenter,this.cartesianCenter),void(this.zoom=Nm(e,this.cartographicCenter,this.cartesianCenter))}const t=this.tileset.store?.extent;if(t){const[e,n,r,i]=t;return this.cartographicCenter=new de(e+(r-e)/2,n+(i-n)/2,0),this.cartesianCenter=new de,gm.WGS84.cartographicToCartesian(this.cartographicCenter,this.cartesianCenter),void(this.zoom=function(e,t,n){const[r,i,a,s]=e;return Nm({xmin:r,xmax:a,ymin:i,ymax:s,zmin:0,zmax:0},t,n)}(t,this.cartographicCenter,this.cartesianCenter))}console.warn("Extent is not defined in the tileset header"),this.cartographicCenter=new de,this.zoom=1}calculateViewPropsTiles3D(){const e=this.root,{center:t}=e.boundingVolume;if(!t)return console.warn("center was not pre-calculated for the root tile"),this.cartographicCenter=new de,void(this.zoom=1);0!==t[0]||0!==t[1]||0!==t[2]?(this.cartographicCenter=new de,gm.WGS84.cartesianToCartographic(t,this.cartographicCenter)):this.cartographicCenter=new de(0,0,-gm.WGS84.radii[0]),this.cartesianCenter=t,this.zoom=Pm(e.boundingVolume,this.cartographicCenter)}_initializeStats(){this.stats.get(Sg),this.stats.get(Rg),this.stats.get(Mg),this.stats.get(Eg),this.stats.get(Cg),this.stats.get(Ig),this.stats.get(Pg),this.stats.get(Ng),this.stats.get(kg),this.stats.get(Lg,"memory"),this.stats.get(Bg)}_initializeTileHeaders(e,t){const n=new mg(this,e.root,t);if(t&&(t.children.push(n),n.depth=t.depth+1),this.type===Bm.TILES3D){const e=[];for(e.push(n);e.length>0;){const t=e.pop();this.stats.get(Sg).incrementCount();const n=t.header.children||[];for(const r of n){const n=new mg(this,r,t);if(n.contentUrl?.includes("?session=")){const e=new URL(n.contentUrl).searchParams.get("session");e&&(this._queryParams.session=e)}t.children.push(n),n.depth=t.depth+1,e.push(n)}}}return n}_initializeTraverser(){let e;switch(this.type){case Bm.TILES3D:e=gg;break;case Bm.I3S:e=wg;break;default:e=hg}return new e({basePath:this.basePath,onTraversalEnd:this._onTraversalEnd.bind(this)})}_destroyTileHeaders(e){this._destroySubtree(e)}async _loadTile(e){let t;try{this._onStartTileLoading(),t=await e.loadContent()}catch(n){this._onTileLoadError(e,n instanceof Error?n:/* @__PURE__ */new Error("load failed"))}finally{this._onEndTileLoading(),this._onTileLoad(e,t)}}_onTileLoadError(e,t){this.stats.get(Ng).incrementCount();const n=t.message||t.toString(),r=e.url;console.error(`A 3D tile failed to load: ${e.url} ${n}`),this.options.onTileError(e,n,r)}_onTileLoad(e,t){if(t){if(this.type===Bm.I3S){const e=this.tileset?.nodePagesTile?.nodesInNodePages||0;this.stats.get(Sg).reset(),this.stats.get(Sg).addCount(e)}e&&e.content&&xm(e,e.content),this.updateContentTypes(e),this._addTileToCache(e),this.options.onTileLoad(e)}}updateContentTypes(e){if(this.type===Bm.I3S)switch(e.header.isDracoGeometry&&(this.contentFormats.draco=!0),e.header.textureFormat){case"dds":this.contentFormats.dds=!0;break;case"ktx2":this.contentFormats.ktx2=!0}else if(this.type===Bm.TILES3D){const{extensionsRemoved:t=[]}=e.content?.gltf||{};t.includes("KHR_draco_mesh_compression")&&(this.contentFormats.draco=!0),t.includes("EXT_meshopt_compression")&&(this.contentFormats.meshopt=!0),t.includes("KHR_texture_basisu")&&(this.contentFormats.ktx2=!0)}}_onStartTileLoading(){this._pendingCount++,this.stats.get(Rg).incrementCount()}_onEndTileLoading(){this._pendingCount--,this.stats.get(Rg).decrementCount()}_addTileToCache(e){this._cache.add(this,e,t=>t._updateCacheStats(e))}_updateCacheStats(e){this.stats.get(Ig).incrementCount(),this.stats.get(Mg).incrementCount(),this.gpuMemoryUsageInBytes+=e.gpuMemoryUsageInBytes||0,this.stats.get(Lg).count=this.gpuMemoryUsageInBytes,this.options.memoryAdjustedScreenSpaceError&&this.adjustScreenSpaceError()}_unloadTile(e){this.gpuMemoryUsageInBytes-=e.gpuMemoryUsageInBytes||0,this.stats.get(Mg).decrementCount(),this.stats.get(Pg).incrementCount(),this.stats.get(Lg).count=this.gpuMemoryUsageInBytes,this.options.onTileUnload(e),e.unloadContent()}_destroy(){const e=[];for(this.root&&e.push(this.root);e.length>0;){const t=e.pop();for(const n of t.children)e.push(n);this._destroyTile(t)}this.root=null}_destroySubtree(e){const t=e,n=[];for(n.push(t);n.length>0;){e=n.pop();for(const t of e.children)n.push(t);e!==t&&this._destroyTile(e)}t.children=[]}_destroyTile(e){this._cache.unloadTile(this,e),this._unloadTile(e),e.destroy()}_initializeTiles3DTileset(e){if(e.queryString){const t=new URLSearchParams(e.queryString),n=Object.fromEntries(t.entries());this._queryParams={...this._queryParams,...n}}if(this.asset=e.asset,!this.asset)throw new Error("Tileset must have an asset property.");if("0.0"!==this.asset.version&&"1.0"!==this.asset.version&&"1.1"!==this.asset.version)throw new Error("The tileset must be 3D Tiles version either 0.0 or 1.0 or 1.1.");"tilesetVersion"in this.asset&&(this._queryParams.v=this.asset.tilesetVersion),this.credits={attributions:this.options.attributions||[]},this.description=this.options.description||"",this.properties=e.properties,this.geometricError=e.geometricError,this._extensionsUsed=e.extensionsUsed||[],this.extras=e.extras}_initializeI3STileset(){const e=this.loadOptions.i3s;e&&"object"==typeof e&&"token"in e&&(this._queryParams.token=e.token)}},Fg="4.5.4",Dg={COMPOSITE:"cmpt",POINT_CLOUD:"pnts",BATCHED_3D_MODEL:"b3dm",INSTANCED_3D_MODEL:"i3dm",GEOMETRY:"geom",VECTOR:"vect",GLTF:"glTF"};Object.keys(Dg);function Ug(e,t,n){Y(e instanceof ArrayBuffer);const r=new TextDecoder("utf8"),i=new Uint8Array(e,t,n);return r.decode(i)}var Vg={BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,DOUBLE:5130},jg={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,...Vg},zg={[Vg.DOUBLE]:Float64Array,[Vg.FLOAT]:Float32Array,[Vg.UNSIGNED_SHORT]:Uint16Array,[Vg.UNSIGNED_INT]:Uint32Array,[Vg.UNSIGNED_BYTE]:Uint8Array,[Vg.BYTE]:Int8Array,[Vg.SHORT]:Int16Array,[Vg.INT]:Int32Array},Gg={DOUBLE:Vg.DOUBLE,FLOAT:Vg.FLOAT,UNSIGNED_SHORT:Vg.UNSIGNED_SHORT,UNSIGNED_INT:Vg.UNSIGNED_INT,UNSIGNED_BYTE:Vg.UNSIGNED_BYTE,BYTE:Vg.BYTE,SHORT:Vg.SHORT,INT:Vg.INT},Hg="Failed to convert GL type",qg=class e{static fromTypedArray(e){e=ArrayBuffer.isView(e)?e.constructor:e;for(const t in zg)if(zg[t]===e)return t;throw new Error(Hg)}static fromName(e){const t=Gg[e];if(!t)throw new Error(Hg);return t}static getArrayType(e){switch(e){case Vg.UNSIGNED_SHORT_5_6_5:case Vg.UNSIGNED_SHORT_4_4_4_4:case Vg.UNSIGNED_SHORT_5_5_5_1:return Uint16Array;default:const t=zg[e];if(!t)throw new Error(Hg);return t}}static getByteSize(t){return e.getArrayType(t).BYTES_PER_ELEMENT}static validate(t){return Boolean(e.getArrayType(t))}static createTypedArray(t,n,r=0,i){void 0===i&&(i=(n.byteLength-r)/e.getByteSize(t));const a=ArrayBuffer.isView(n)?n.buffer:n;return new(e.getArrayType(t))(a,r,i)}};function Qg(e,t=[0,0,0]){const n=e>>11&31,r=e>>5&63,i=31&e;return t[0]=n<<3,t[1]=r<<2,t[2]=i<<3,t}new wt,new de,new wt,new wt;function Kg(e,t=255){return I(e,0,t)/t*2-1}function Wg(e){return e<0?-1:1}function Jg(e,t,n,r){if(function(e,t){if(!e)throw new Error(`math.gl assertion failed. ${t}`)}(r),e<0||e>n||t<0||t>n)throw new Error(`x and y must be unsigned normalized integers between 0 and ${n}`);if(r.x=Kg(e,n),r.y=Kg(t,n),r.z=1-(Math.abs(r.x)+Math.abs(r.y)),r.z<0){const e=r.x;r.x=(1-Math.abs(r.y))*Wg(e),r.y=(1-Math.abs(e))*Wg(r.y)}return r.normalize()}function $g(e,t,n){return Jg(e,t,255,n)}var Xg=class{json;buffer;featuresLength=0;_cachedTypedArrays={};constructor(e,t){this.json=e,this.buffer=t}getExtension(e){return this.json.extensions&&this.json.extensions[e]}hasProperty(e){return Boolean(this.json[e])}getGlobalProperty(e,t=jg.UNSIGNED_INT,n=1){const r=this.json[e];return r&&Number.isFinite(r.byteOffset)?this._getTypedArrayFromBinary(e,t,n,1,r.byteOffset):r}getPropertyArray(e,t,n){const r=this.json[e];return r&&Number.isFinite(r.byteOffset)?("componentType"in r&&(t=qg.fromName(r.componentType)),this._getTypedArrayFromBinary(e,t,n,this.featuresLength,r.byteOffset)):this._getTypedArrayFromArray(e,t,r)}getProperty(e,t,n,r,i){const a=this.json[e];if(!a)return a;const s=this.getPropertyArray(e,t,n);if(1===n)return s[r];for(let o=0;o<n;++o)i[o]=s[n*r+o];return i}_getTypedArrayFromBinary(e,t,n,r,i){const a=this._cachedTypedArrays;let s=a[e];return s||(s=qg.createTypedArray(t,this.buffer.buffer,this.buffer.byteOffset+i,r*n),a[e]=s),s}_getTypedArrayFromArray(e,t,n){const r=this._cachedTypedArrays;let i=r[e];if(!i){if(ArrayBuffer.isView(n)){const e=n.byteOffset,r=n.byteLength/qg.getByteSize(t);i=qg.createTypedArray(t,n.buffer,e,r)}else i=n instanceof ArrayBuffer?qg.createTypedArray(t,n):new(qg.getArrayType(t))(n);r[e]=i}return i}},Yg={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Zg={SCALAR:(e,t)=>e[t],VEC2:(e,t)=>[e[2*t+0],e[2*t+1]],VEC3:(e,t)=>[e[3*t+0],e[3*t+1],e[3*t+2]],VEC4:(e,t)=>[e[4*t+0],e[4*t+1],e[4*t+2],e[4*t+3]],MAT2:(e,t)=>[e[4*t+0],e[4*t+1],e[4*t+2],e[4*t+3]],MAT3:(e,t)=>[e[9*t+0],e[9*t+1],e[9*t+2],e[9*t+3],e[9*t+4],e[9*t+5],e[9*t+6],e[9*t+7],e[9*t+8]],MAT4:(e,t)=>[e[16*t+0],e[16*t+1],e[16*t+2],e[16*t+3],e[16*t+4],e[16*t+5],e[16*t+6],e[16*t+7],e[16*t+8],e[16*t+9],e[16*t+10],e[16*t+11],e[16*t+12],e[16*t+13],e[16*t+14],e[16*t+15]]},eb={SCALAR:(e,t,n)=>{t[n]=e},VEC2:(e,t,n)=>{t[2*n+0]=e[0],t[2*n+1]=e[1]},VEC3:(e,t,n)=>{t[3*n+0]=e[0],t[3*n+1]=e[1],t[3*n+2]=e[2]},VEC4:(e,t,n)=>{t[4*n+0]=e[0],t[4*n+1]=e[1],t[4*n+2]=e[2],t[4*n+3]=e[3]},MAT2:(e,t,n)=>{t[4*n+0]=e[0],t[4*n+1]=e[1],t[4*n+2]=e[2],t[4*n+3]=e[3]},MAT3:(e,t,n)=>{t[9*n+0]=e[0],t[9*n+1]=e[1],t[9*n+2]=e[2],t[9*n+3]=e[3],t[9*n+4]=e[4],t[9*n+5]=e[5],t[9*n+6]=e[6],t[9*n+7]=e[7],t[9*n+8]=e[8],t[9*n+9]=e[9]},MAT4:(e,t,n)=>{t[16*n+0]=e[0],t[16*n+1]=e[1],t[16*n+2]=e[2],t[16*n+3]=e[3],t[16*n+4]=e[4],t[16*n+5]=e[5],t[16*n+6]=e[6],t[16*n+7]=e[7],t[16*n+8]=e[8],t[16*n+9]=e[9],t[16*n+10]=e[10],t[16*n+11]=e[11],t[16*n+12]=e[12],t[16*n+13]=e[13],t[16*n+14]=e[14],t[16*n+15]=e[15]}};var tb=e=>void 0!==e;function nb(e,t,n){if(!t)return null;let r=e.getExtension("3DTILES_batch_table_hierarchy");const i=t.HIERARCHY;return i&&(console.warn("3D Tile Parser: HIERARCHY is deprecated. Use 3DTILES_batch_table_hierarchy."),t.extensions=t.extensions||{},t.extensions["3DTILES_batch_table_hierarchy"]=i,r=i),r?function(e,t){let n,r,i;const a=e.instancesLength,s=e.classes;let o,A=e.classIds,l=e.parentCounts,c=e.parentIds,u=a;tb(A.byteOffset)&&(A.componentType=defaultValue(A.componentType,GL.UNSIGNED_SHORT),A.type=AttributeType.SCALAR,i=getBinaryAccessor(A),A=i.createArrayBufferView(t.buffer,t.byteOffset+A.byteOffset,a));if(tb(l))for(tb(l.byteOffset)&&(l.componentType=defaultValue(l.componentType,GL.UNSIGNED_SHORT),l.type=AttributeType.SCALAR,i=getBinaryAccessor(l),l=i.createArrayBufferView(t.buffer,t.byteOffset+l.byteOffset,a)),o=new Uint16Array(a),u=0,n=0;n<a;++n)o[n]=u,u+=l[n];tb(c)&&tb(c.byteOffset)&&(c.componentType=defaultValue(c.componentType,GL.UNSIGNED_SHORT),c.type=AttributeType.SCALAR,i=getBinaryAccessor(c),c=i.createArrayBufferView(t.buffer,t.byteOffset+c.byteOffset,u));const f=s.length;for(n=0;n<f;++n){const e=s[n].length,r=s[n].instances,i=getBinaryProperties(e,r,t);s[n].instances=combine(i,r)}const d=new Array(f).fill(0),h=new Uint16Array(a);for(n=0;n<a;++n)r=A[n],h[n]=d[r],++d[r];const p={classes:s,classIds:A,classIndexes:h,parentCounts:l,parentIndexes:o,parentIds:c};return function(e){const t=e.classIds.length;for(let n=0;n<t;++n)ib(e,n,stack)}(p),p}(r,n):null}function rb(e,t,n){if(!e)return;const r=e.parentCounts;return e.parentIds?n(e,t):r>0?function(e,t,n){const r=e.classIds,i=e.parentCounts,a=e.parentIds,s=e.parentIndexes,o=r.length,A=scratchVisited;A.length=Math.max(A.length,o);const l=++marker,c=scratchStack;c.length=0,c.push(t);for(;c.length>0;){if(A[t=c.pop()]===l)continue;A[t]=l;const r=n(e,t);if(tb(r))return r;const o=i[t],u=s[t];for(let e=0;e<o;++e){const n=a[u+e];n!==t&&c.push(n)}}return null}(e,t,n):function(e,t,n){let r=!0;for(;r;){const i=n(e,t);if(tb(i))return i;const a=e.parentIds[t];r=a!==t,t=a}throw new Error("traverseHierarchySingleParent")}(e,t,n)}function ib(e,t,n){const r=e.parentCounts,i=e.parentIds,a=e.parentIndexes,s=e.classIds.length;if(!tb(i))return;assert(t<s,`Parent index ${t} exceeds the total number of instances: ${s}`),assert(-1===n.indexOf(t),"Circular dependency detected in the batch table hierarchy."),n.push(t);const o=tb(r)?r[t]:1,A=tb(r)?a[t]:t;for(let l=0;l<o;++l){const r=i[A+l];r!==t&&ib(e,r,n)}n.pop(t)}function ab(e){return null!=e}var sb=(e,t)=>e,ob={HIERARCHY:!0,extensions:!0,extras:!0},Ab=class{json;binary;featureCount;_extensions;_properties;_binaryProperties;_hierarchy;constructor(e,t,n,r={}){Y(n>=0),this.json=e||{},this.binary=t,this.featureCount=n,this._extensions=this.json?.extensions||{},this._properties={};for(const i in this.json)ob[i]||(this._properties[i]=this.json[i]);this._binaryProperties=this._initializeBinaryProperties(),r["3DTILES_batch_table_hierarchy"]&&(this._hierarchy=nb(this,this.json,this.binary))}getExtension(e){return this.json&&this.json.extensions&&this.json.extensions[e]}memorySizeInBytes(){return 0}isClass(e,t){return this._checkBatchId(e),Y("string"==typeof t,t),!!this._hierarchy&&ab(rb(this._hierarchy,e,(e,n)=>{const r=e.classIds[n];return e.classes[r].name===t}))}isExactClass(e,t){return Y("string"==typeof t,t),this.getExactClassName(e)===t}getExactClassName(e){if(this._checkBatchId(e),this._hierarchy){const t=this._hierarchy.classIds[e];return this._hierarchy.classes[t].name}}hasProperty(e,t){return this._checkBatchId(e),Y("string"==typeof t,t),ab(this._properties[t])||this._hasPropertyInHierarchy(e,t)}getPropertyNames(e,t){this._checkBatchId(e),(t=ab(t)?t:[]).length=0;const n=Object.keys(this._properties);return t.push(...n),this._hierarchy&&this._getPropertyNamesInHierarchy(e,t),t}getProperty(e,t){if(this._checkBatchId(e),Y("string"==typeof t,t),this._binaryProperties){const n=this._binaryProperties[t];if(ab(n))return this._getBinaryProperty(n,e)}const n=this._properties[t];if(ab(n))return sb(n[e]);if(this._hierarchy){const n=this._getHierarchyProperty(e,t);if(ab(n))return n}}setProperty(e,t,n){const r=this.featureCount;if(this._checkBatchId(e),Y("string"==typeof t,t),this._binaryProperties){const r=this._binaryProperties[t];if(r)return void this._setBinaryProperty(r,e,n)}if(this._hierarchy&&this._setHierarchyProperty(this,e,t,n))return;let i=this._properties[t];ab(i)||(this._properties[t]=new Array(r),i=this._properties[t]),i[e]=sb(n)}_checkBatchId(e){if(!(e>=0&&e<this.featureCount))throw new Error("batchId not in range [0, featureCount - 1].")}_getBinaryProperty(e,t){return e.unpack(e.typedArray,t)}_setBinaryProperty(e,t,n){e.pack(n,e.typedArray,t)}_initializeBinaryProperties(){let e=null;for(const t in this._properties){const n=this._properties[t],r=this._initializeBinaryProperty(t,n);r&&(e=e||{},e[t]=r)}return e}_initializeBinaryProperty(e,t){if("byteOffset"in t){const n=t;Y(this.binary,`Property ${e} requires a batch table binary.`),Y(n.type,`Property ${e} requires a type.`);const r=function(e,t,n,r){const{componentType:i}=e;Y(e.componentType);const a="string"==typeof i?qg.fromName(i):i,s=Yg[e.type],o=Zg[e.type],A=eb[e.type];return n+=e.byteOffset,{values:qg.createTypedArray(a,t,n,s*r),type:a,size:s,unpacker:o,packer:A}}(n,this.binary.buffer,0|this.binary.byteOffset,this.featureCount);return{typedArray:r.values,componentCount:r.size,unpack:r.unpacker,pack:r.packer}}return null}_hasPropertyInHierarchy(e,t){return!!this._hierarchy&&ab(rb(this._hierarchy,e,(e,n)=>{const r=e.classIds[n];return ab(e.classes[r].instances[t])}))}_getPropertyNamesInHierarchy(e,t){rb(this._hierarchy,e,(e,n)=>{const r=e.classIds[n],i=e.classes[r].instances;for(const a in i)i.hasOwnProperty(a)&&-1===t.indexOf(a)&&t.push(a)})}_getHierarchyProperty(e,t){return rb(this._hierarchy,e,(e,n)=>{const r=e.classIds[n],i=e.classes[r],a=e.classIndexes[n],s=i.instances[t];return ab(s)?ab(s.typedArray)?this._getBinaryProperty(s,a):sb(s[a]):null})}_setHierarchyProperty(e,t,n,r){return ab(rb(this._hierarchy,t,(e,i)=>{const a=e.classIds[i],s=e.classes[a],o=e.classIndexes[i],A=s.instances[n];return!!ab(A)&&(Y(i===t,`Inherited property "${n}" is read-only.`),ab(A.typedArray)?this._setBinaryProperty(A,o,r):A[o]=sb(r),!0)}))}};function lb(e,t,n=0){const r=new DataView(t);if(e.magic=r.getUint32(n,!0),n+=4,e.version=r.getUint32(n,!0),n+=4,e.byteLength=r.getUint32(n,!0),n+=4,1!==e.version)throw new Error(`3D Tile Version ${e.version} not supported`);return n}var cb="b3dm tile in legacy format.";function ub(e,t,n){const r=new DataView(t);let i;e.header=e.header||{};let a=r.getUint32(n,!0);n+=4;let s=r.getUint32(n,!0);n+=4;let o=r.getUint32(n,!0);n+=4;let A=r.getUint32(n,!0);return n+=4,o>=570425344?(n-=8,i=a,o=s,A=0,a=0,s=0,console.warn(cb)):A>=570425344&&(n-=4,i=o,o=a,A=s,a=0,s=0,console.warn(cb)),e.header.featureTableJsonByteLength=a,e.header.featureTableBinaryByteLength=s,e.header.batchTableJsonByteLength=o,e.header.batchTableBinaryByteLength=A,e.header.batchLength=i,n}function fb(e,t,n,r){return n=function(e,t,n){const{featureTableJsonByteLength:r,featureTableBinaryByteLength:i,batchLength:a}=e.header||{};if(e.featureTableJson={BATCH_LENGTH:a||0},r&&r>0){const i=Ug(t,n,r);e.featureTableJson=JSON.parse(i)}return n+=r||0,e.featureTableBinary=new Uint8Array(t,n,i),n+=i||0,n}(e,t,n),n=function(e,t,n){const{batchTableJsonByteLength:r,batchTableBinaryByteLength:i}=e.header||{};if(r&&r>0){const a=Ug(t,n,r);e.batchTableJson=JSON.parse(a),n+=r,i&&i>0&&(e.batchTableBinary=new Uint8Array(t,n,i),e.batchTableBinary=new Uint8Array(e.batchTableBinary),n+=i)}return n}(e,t,n),n}function db(e,t,n){if(!(t||e&&e.batchIds&&n))return null;const{batchIds:r,isRGB565:i,pointCount:a=0}=e;if(r&&n){const e=new Uint8ClampedArray(3*a);for(let t=0;t<a;t++){const i=r[t],a=n.getProperty(i,"dimensions").map(e=>255*e);e[3*t]=a[0],e[3*t+1]=a[1],e[3*t+2]=a[2]}return{type:jg.UNSIGNED_BYTE,value:e,size:3,normalized:!0}}if(t&&i){const e=new Uint8ClampedArray(3*a);for(let n=0;n<a;n++){const r=Qg(t[n]);e[3*n]=r[0],e[3*n+1]=r[1],e[3*n+2]=r[2]}return{type:jg.UNSIGNED_BYTE,value:e,size:3,normalized:!0}}return t&&t.length===3*a?{type:jg.UNSIGNED_BYTE,value:t,size:3,normalized:!0}:{type:jg.UNSIGNED_BYTE,value:t||/* @__PURE__ */new Uint8ClampedArray,size:4,normalized:!0}}var hb=new de;function pb(e,t,n){return e.isQuantized?n["3d-tiles"]&&n["3d-tiles"].decodeQuantizedPositions?(e.isQuantized=!1,function(e,t){const n=new de,r=new Float32Array(3*e.pointCount);for(let i=0;i<e.pointCount;i++)n.set(t[3*i],t[3*i+1],t[3*i+2]).scale(1/e.quantizedRange).multiply(e.quantizedVolumeScale).add(e.quantizedVolumeOffset).toArray(r,3*i);return r}(e,t)):{type:jg.UNSIGNED_SHORT,value:t,size:3,normalized:!0}:t}async function mb(e,t,n,r,i){n=fb(e,t,n=ub(e,t,n=lb(e,t,n))),function(e){e.attributes={positions:null,colors:null,normals:null,batchIds:null},e.isQuantized=!1,e.isTranslucent=!1,e.isRGB565=!1,e.isOctEncoded16P=!1}(e);const{featureTable:a,batchTable:s}=function(e){const t=new Xg(e.featureTableJson,e.featureTableBinary),n=t.getGlobalProperty("POINTS_LENGTH");if(!Number.isFinite(n))throw new Error("POINTS_LENGTH must be defined");return t.featuresLength=n,e.featuresLength=n,e.pointsLength=n,e.pointCount=n,e.rtcCenter=t.getGlobalProperty("RTC_CENTER",jg.FLOAT,3),{featureTable:t,batchTable:gb(e,t)}}(e);return await async function(e,t,n,r,i){let a,s,o;const A=e.batchTableJson&&e.batchTableJson.extensions&&e.batchTableJson.extensions["3DTILES_draco_point_compression"];A&&(o=A.properties);const l=t.getExtension("3DTILES_draco_point_compression");if(l){s=l.properties;const t=l.byteOffset,n=l.byteLength;if(!s||!Number.isFinite(t)||!n)throw new Error("Draco properties, byteOffset, and byteLength must be defined");a=(e.featureTableBinary||[]).slice(t,t+n),e.hasPositions=Number.isFinite(s.POSITION),e.hasColors=Number.isFinite(s.RGB)||Number.isFinite(s.RGBA),e.hasNormals=Number.isFinite(s.NORMAL),e.hasBatchIds=Number.isFinite(s.BATCH_ID),e.isTranslucent=Number.isFinite(s.RGBA)}return!a||await async function(e,t,n,r){if(!r)return;const i={...n,draco:{...n?.draco,extraAttributes:t.batchTableProperties||{}}};delete i["3d-tiles"];const a=await Ze(t.buffer,Sh,i,r),s=a.attributes.POSITION&&a.attributes.POSITION.value,o=a.attributes.COLOR_0&&a.attributes.COLOR_0.value,A=a.attributes.NORMAL&&a.attributes.NORMAL.value,l=a.attributes.BATCH_ID&&a.attributes.BATCH_ID.value,c=s&&a.attributes.POSITION.value.quantization,u=A&&a.attributes.NORMAL.value.quantization;if(c){const t=a.POSITION.data.quantization,n=t.range;e.quantizedVolumeScale=new de(n,n,n),e.quantizedVolumeOffset=new de(t.minValues),e.quantizedRange=(1<<t.quantizationBits)-1,e.isQuantizedDraco=!0}u&&(e.octEncodedRange=(1<<a.NORMAL.data.quantization.quantizationBits)-1,e.isOctEncodedDraco=!0);const f={};if(t.batchTableProperties)for(const d of Object.keys(t.batchTableProperties))a.attributes[d]&&a.attributes[d].value&&(f[d.toLowerCase()]=a.attributes[d].value);e.attributes={positions:s,colors:db(e,o,void 0),normals:A,batchIds:l,...f}}(e,{buffer:a,properties:{...s,...o},featureTableProperties:s,batchTableProperties:o,dequantizeInShader:!1},r,i)}(e,a,0,r,i),function(e,t,n){if(e.attributes=e.attributes||{positions:null,colors:null,normals:null,batchIds:null},!e.attributes.positions)if(t.hasProperty("POSITION"))e.attributes.positions=t.getPropertyArray("POSITION",jg.FLOAT,3);else if(t.hasProperty("POSITION_QUANTIZED")){const r=t.getPropertyArray("POSITION_QUANTIZED",jg.UNSIGNED_SHORT,3);if(e.isQuantized=!0,e.quantizedRange=65535,e.quantizedVolumeScale=t.getGlobalProperty("QUANTIZED_VOLUME_SCALE",jg.FLOAT,3),!e.quantizedVolumeScale)throw new Error("QUANTIZED_VOLUME_SCALE must be defined for quantized positions.");if(e.quantizedVolumeOffset=t.getGlobalProperty("QUANTIZED_VOLUME_OFFSET",jg.FLOAT,3),!e.quantizedVolumeOffset)throw new Error("QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.");e.attributes.positions=pb(e,r,n)}if(!e.attributes.positions)throw new Error("Either POSITION or POSITION_QUANTIZED must be defined.")}(e,a,r),function(e,t,n){if(e.attributes=e.attributes||{positions:null,colors:null,normals:null,batchIds:null},!e.attributes.colors){let r=null;t.hasProperty("RGBA")?(r=t.getPropertyArray("RGBA",jg.UNSIGNED_BYTE,4),e.isTranslucent=!0):t.hasProperty("RGB")?r=t.getPropertyArray("RGB",jg.UNSIGNED_BYTE,3):t.hasProperty("RGB565")&&(r=t.getPropertyArray("RGB565",jg.UNSIGNED_SHORT,1),e.isRGB565=!0),e.attributes.colors=db(e,r,n)}t.hasProperty("CONSTANT_RGBA")&&(e.constantRGBA=t.getGlobalProperty("CONSTANT_RGBA",jg.UNSIGNED_BYTE,4))}(e,a,s),function(e,t){if(e.attributes=e.attributes||{positions:null,colors:null,normals:null,batchIds:null},!e.attributes.normals){let n=null;t.hasProperty("NORMAL")?n=t.getPropertyArray("NORMAL",jg.FLOAT,3):t.hasProperty("NORMAL_OCT16P")&&(n=t.getPropertyArray("NORMAL_OCT16P",jg.UNSIGNED_BYTE,2),e.isOctEncoded16P=!0),e.attributes.normals=function(e,t){if(!t)return null;if(e.isOctEncoded16P){const n=new Float32Array(3*(e.pointsLength||0));for(let r=0;r<(e.pointsLength||0);r++)$g(t[2*r],t[2*r+1],hb),hb.toArray(n,3*r);return{type:jg.FLOAT,size:2,value:n}}return{type:jg.FLOAT,size:2,value:t}}(e,n)}}(e,a),n}function gb(e,t){let n=null;if(!e.batchIds&&t.hasProperty("BATCH_ID")&&(e.batchIds=t.getPropertyArray("BATCH_ID",jg.UNSIGNED_SHORT,1),e.batchIds)){const r=t.getGlobalProperty("BATCH_LENGTH");if(!r)throw new Error("Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.");const{batchTableJson:i,batchTableBinary:a}=e;n=new Ab(i,a,r)}return n}var bb=0,vb=1;function yb(e,t,n,r){e.rotateYtoZ=!0;const i=(e.byteOffset||0)+(e.byteLength||0)-n;if(0===i)throw new Error("glTF byte length must be greater than 0.");return e.gltfUpAxis=r?.["3d-tiles"]&&r["3d-tiles"].assetGltfUpAxis?r["3d-tiles"].assetGltfUpAxis:"Y",e.gltfArrayBuffer=ie(t,n,i),e.gltfByteOffset=0,e.gltfByteLength=i,n%4==0||console.warn(`${e.type}: embedded glb is not aligned to a 4-byte boundary.`),(e.byteOffset||0)+(e.byteLength||0)}async function xb(e,t,n,r){const i=n?.["3d-tiles"]||{};if(function(e,t){switch(t){case bb:if(e.gltfArrayBuffer){const t=new Uint8Array(e.gltfArrayBuffer,e.gltfByteOffset);e.gltfUrl=(new TextDecoder).decode(t).replace(/[\s\0]+$/,"")}delete e.gltfArrayBuffer,delete e.gltfByteOffset,delete e.gltfByteLength;break;case vb:break;default:throw new Error("b3dm: Illegal glTF format field")}}(e,t),i.loadGLTF){if(!r)return;if(e.gltfUrl){const{fetch:t}=r;e.gltfArrayBuffer=await(await t(e.gltfUrl,n?.core)).arrayBuffer(),e.gltfByteOffset=0}if(e.gltfArrayBuffer){const t=await Ze(e.gltfArrayBuffer,vp,n,r);e.gltf=Lp(t),e.gpuMemoryUsageInBytes=gf(e.gltf),delete e.gltfArrayBuffer,delete e.gltfByteOffset,delete e.gltfByteLength}}}async function _b(e,t,n,r,i){n=function(e,t,n,r){return n=lb(e,t,n),n=ub(e,t,n),n=fb(e,t,n),n=yb(e,t,n,r),e.rtcCenter=new Xg(e.featureTableJson,e.featureTableBinary).getGlobalProperty("RTC_CENTER",jg.FLOAT,3),n}(e,t,n,r),await xb(e,vb,r,i);const a=e?.gltf?.extensions;return a&&a.CESIUM_RTC&&(e.rtcCenter=a.CESIUM_RTC.center),n}async function wb(e,t,n,r,i){return n=function(e,t,n,r){if(n=lb(e,t,n),1!==e.version)throw new Error(`Instanced 3D Model version ${e.version} is not supported`);if(n=ub(e,t,n),e.gltfFormat=new DataView(t).getUint32(n,!0),n+=4,n=fb(e,t,n),n=yb(e,t,n,r),!e?.header?.featureTableJsonByteLength||0===e.header.featureTableJsonByteLength)throw new Error("i3dm parser: featureTableJsonByteLength is zero.");const i=new Xg(e.featureTableJson,e.featureTableBinary),a=i.getGlobalProperty("INSTANCES_LENGTH");if(i.featuresLength=a,!Number.isFinite(a))throw new Error("i3dm parser: INSTANCES_LENGTH must be defined");return e.eastNorthUp=i.getGlobalProperty("EAST_NORTH_UP"),e.rtcCenter=i.getGlobalProperty("RTC_CENTER",jg.FLOAT,3),function(e,t,n,r){const i=new Array(r),a=new de;new de,new de,new de;const s=new Mt,o=new Oe,A=new de,l={},c=new H,u=[],f=[],d=[],h=[];for(let p=0;p<r;p++){let n;if(t.hasProperty("POSITION"))n=t.getProperty("POSITION",jg.FLOAT,3,p,a);else if(t.hasProperty("POSITION_QUANTIZED")){n=t.getProperty("POSITION_QUANTIZED",jg.UNSIGNED_SHORT,3,p,a);const e=t.getGlobalProperty("QUANTIZED_VOLUME_OFFSET",jg.FLOAT,3);if(!e)throw new Error("i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.");const r=t.getGlobalProperty("QUANTIZED_VOLUME_SCALE",jg.FLOAT,3);if(!r)throw new Error("i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.");const i=65535;for(let t=0;t<3;t++)n[t]=n[t]/i*r[t]+e[t]}if(!n)throw new Error("i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.");if(a.copy(n),l.translation=a,e.normalUp=t.getProperty("NORMAL_UP",jg.FLOAT,3,p,u),e.normalRight=t.getProperty("NORMAL_RIGHT",jg.FLOAT,3,p,f),e.normalUp){if(!e.normalRight)throw new Error("i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.");e.hasCustomOrientation=!0}else{if(e.octNormalUp=t.getProperty("NORMAL_UP_OCT32P",jg.UNSIGNED_SHORT,2,p,u),e.octNormalRight=t.getProperty("NORMAL_RIGHT_OCT32P",jg.UNSIGNED_SHORT,2,p,f),e.octNormalUp){if(!e.octNormalRight)throw new Error("i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P");throw new Error("i3dm: oct-encoded orientation not implemented")}e.eastNorthUp?(gm.WGS84.eastNorthUpToFixedFrame(a,c),c.getRotationMatrix3(s)):s.identity()}o.fromMatrix3(s),l.rotation=o,A.set(1,1,1);const r=t.getProperty("SCALE",jg.FLOAT,1,p,d);Number.isFinite(r)&&A.multiplyByScalar(r);const m=t.getProperty("SCALE_NON_UNIFORM",jg.FLOAT,3,p,u);m&&A.scale(m),l.scale=A;let g=t.getProperty("BATCH_ID",jg.UNSIGNED_SHORT,1,p,h);void 0===g&&(g=p);const b=(new H).fromQuaternion(l.rotation);c.identity(),c.translate(l.translation),c.multiplyRight(b),c.scale(l.scale);const v=c.clone();i[p]={modelMatrix:v,batchId:g}}e.instances=i}(e,i,new Ab(e.batchTableJson,e.batchTableBinary,a),a),n}(e,t,n,r),await xb(e,e.gltfFormat||0,r,i),n}async function Tb(e,t=0,n,r,i={shape:"tile3d"}){switch(i.byteOffset=t,i.type=function(e,t=0){const n=new DataView(e);return`${String.fromCharCode(n.getUint8(t+0))}${String.fromCharCode(n.getUint8(t+1))}${String.fromCharCode(n.getUint8(t+2))}${String.fromCharCode(n.getUint8(t+3))}`}(e,t),i.type){case Dg.COMPOSITE:return await async function(e,t,n,r,i,a){for(n=lb(e,t,n),e.tilesLength=new DataView(t).getUint32(n,!0),n+=4,e.tiles=[];e.tiles.length<e.tilesLength&&(e.byteLength||0)-n>12;){const s={shape:"tile3d"};e.tiles.push(s),n=await a(t,n,r,i,s)}return n}(i,e,t,n,r,Tb);case Dg.BATCHED_3D_MODEL:return await _b(i,e,t,n,r);case Dg.GLTF:return await async function(e,t,n,r){if(e.rotateYtoZ=!0,e.gltfUpAxis=n?.["3d-tiles"]?.assetGltfUpAxis?n["3d-tiles"].assetGltfUpAxis:"Y",n?.["3d-tiles"]?.loadGLTF){if(!r)return t.byteLength;const i=await Ze(t,vp,n,r);e.gltf=Lp(i),e.gpuMemoryUsageInBytes=gf(e.gltf)}else e.gltfArrayBuffer=t;return t.byteLength}(i,e,n,r);case Dg.INSTANCED_3D_MODEL:return await wb(i,e,t,n,r);case Dg.POINT_CLOUD:return await mb(i,e,t,n,r);default:throw new Error(`3DTileLoader: unknown type ${i.type}`)}}async function Sb(e,t,n,r){const i=Number.isFinite(t.bitstream)?t.bitstream:t.bufferView;if("number"!=typeof i)return;const a=e.bufferViews[i],s=e.buffers[a.buffer];if(!r?.baseUrl)throw new Error("Url is not provided");if(!r.fetch)throw new Error("fetch is not provided");if(s.uri){const e=`${r?.baseUrl||""}/${s.uri}`,n=await(await r.fetch(e)).arrayBuffer();return void(t.explicitBitstream=new Uint8Array(n,a.byteOffset,a.byteLength))}const o=e.buffers.slice(0,a.buffer).reduce((e,t)=>e+t.byteLength,0);t.explicitBitstream=new Uint8Array(n.slice(o,o+s.byteLength),a.byteOffset,a.byteLength)}function Mb(e){const t=new DataView(e);return t.getUint32(0,!0)+2**32*t.getUint32(4,!0)}var Eb={dataType:null,batchType:null,id:"3d-tiles-subtree",name:"3D Tiles Subtree",module:"3d-tiles",version:Fg,extensions:["subtree"],mimeTypes:["application/octet-stream"],tests:["subtree"],parse:async function(e,t,n){if(1952609651!==new Uint32Array(e.slice(0,4))[0])throw new Error("Wrong subtree file magic number");if(1!==new Uint32Array(e.slice(4,8))[0])throw new Error("Wrong subtree file verson, must be 1");const r=Mb(e.slice(8,16)),i=new Uint8Array(e,24,r),a=new TextDecoder("utf8").decode(i),s=JSON.parse(a),o=Mb(e.slice(16,24));let A=/* @__PURE__ */new ArrayBuffer(0);if(o&&(A=e.slice(24+r)),await Sb(s,s.tileAvailability,A,n),Array.isArray(s.contentAvailability))for(const l of s.contentAvailability)await Sb(s,l,A,n);else await Sb(s,s.contentAvailability,A,n);return await Sb(s,s.childSubtreeAvailability,A,n),s},options:{}},Cb=null;try{Cb=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}function Ib(e,t,n){this.low=0|e,this.high=0|t,this.unsigned=!!n}function Rb(e){return!0===(e&&e.__isLong__)}function Pb(e){var t=Math.clz32(e&-e);return e?31-t:t}Ib.prototype.__isLong__,Object.defineProperty(Ib.prototype,"__isLong__",{value:!0}),Ib.isLong=Rb;var Nb={},kb={};function Lb(e,t){var n,r,i;return t?(i=0<=(e>>>=0)&&e<256)&&(r=kb[e])?r:(n=Ob(e,0,!0),i&&(kb[e]=n),n):(i=-128<=(e|=0)&&e<128)&&(r=Nb[e])?r:(n=Ob(e,e<0?-1:0,!1),i&&(Nb[e]=n),n)}function Bb(e,t){if(isNaN(e))return t?qb:Hb;if(t){if(e<0)return qb;if(e>=jb)return $b}else{if(e<=-zb)return Xb;if(e+1>=zb)return Jb}return e<0?Bb(-e,t).neg():Ob(e%Vb|0,e/Vb|0,t)}function Ob(e,t,n){return new Ib(e,t,n)}Ib.fromInt=Lb,Ib.fromNumber=Bb,Ib.fromBits=Ob;var Fb=Math.pow;function Db(e,t,n){if(0===e.length)throw Error("empty string");if("number"==typeof t?(n=t,t=!1):t=!!t,"NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return t?qb:Hb;if((n=n||10)<2||36<n)throw RangeError("radix");var r;if((r=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===r)return Db(e.substring(1),t,n).neg();for(var i=Bb(Fb(n,8)),a=Hb,s=0;s<e.length;s+=8){var o=Math.min(8,e.length-s),A=parseInt(e.substring(s,s+o),n);if(o<8){var l=Bb(Fb(n,o));a=a.mul(l).add(Bb(A))}else a=(a=a.mul(i)).add(Bb(A))}return a.unsigned=t,a}function Ub(e,t){return"number"==typeof e?Bb(e,t):"string"==typeof e?Db(e,t):Ob(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}Ib.fromString=Db,Ib.fromValue=Ub;var Vb=4294967296,jb=Vb*Vb,zb=jb/2,Gb=Lb(1<<24),Hb=Lb(0);Ib.ZERO=Hb;var qb=Lb(0,!0);Ib.UZERO=qb;var Qb=Lb(1);Ib.ONE=Qb;var Kb=Lb(1,!0);Ib.UONE=Kb;var Wb=Lb(-1);Ib.NEG_ONE=Wb;var Jb=Ob(-1,2147483647,!1);Ib.MAX_VALUE=Jb;var $b=Ob(-1,-1,!0);Ib.MAX_UNSIGNED_VALUE=$b;var Xb=Ob(0,-2147483648,!1);Ib.MIN_VALUE=Xb;var Yb=Ib.prototype;Yb.toInt=function(){return this.unsigned?this.low>>>0:this.low},Yb.toNumber=function(){return this.unsigned?(this.high>>>0)*Vb+(this.low>>>0):this.high*Vb+(this.low>>>0)},Yb.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(Xb)){var t=Bb(e),n=this.div(t),r=n.mul(t).sub(this);return n.toString(e)+r.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var i=Bb(Fb(e,6),this.unsigned),a=this,s="";;){var o=a.div(i),A=(a.sub(o.mul(i)).toInt()>>>0).toString(e);if((a=o).isZero())return A+s;for(;A.length<6;)A="0"+A;s=""+A+s}},Yb.getHighBits=function(){return this.high},Yb.getHighBitsUnsigned=function(){return this.high>>>0},Yb.getLowBits=function(){return this.low},Yb.getLowBitsUnsigned=function(){return this.low>>>0},Yb.getNumBitsAbs=function(){if(this.isNegative())return this.eq(Xb)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&!(e&1<<t);t--);return 0!=this.high?t+33:t+1},Yb.isSafeInteger=function(){var e=this.high>>21;return!e||!this.unsigned&&(-1===e&&!(0===this.low&&-2097152===this.high))},Yb.isZero=function(){return 0===this.high&&0===this.low},Yb.eqz=Yb.isZero,Yb.isNegative=function(){return!this.unsigned&&this.high<0},Yb.isPositive=function(){return this.unsigned||this.high>=0},Yb.isOdd=function(){return!(1&~this.low)},Yb.isEven=function(){return!(1&this.low)},Yb.equals=function(e){return Rb(e)||(e=Ub(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},Yb.eq=Yb.equals,Yb.notEquals=function(e){return!this.eq(e)},Yb.neq=Yb.notEquals,Yb.ne=Yb.notEquals,Yb.lessThan=function(e){return this.comp(e)<0},Yb.lt=Yb.lessThan,Yb.lessThanOrEqual=function(e){return this.comp(e)<=0},Yb.lte=Yb.lessThanOrEqual,Yb.le=Yb.lessThanOrEqual,Yb.greaterThan=function(e){return this.comp(e)>0},Yb.gt=Yb.greaterThan,Yb.greaterThanOrEqual=function(e){return this.comp(e)>=0},Yb.gte=Yb.greaterThanOrEqual,Yb.ge=Yb.greaterThanOrEqual,Yb.compare=function(e){if(Rb(e)||(e=Ub(e)),this.eq(e))return 0;var t=this.isNegative(),n=e.isNegative();return t&&!n?-1:!t&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},Yb.comp=Yb.compare,Yb.negate=function(){return!this.unsigned&&this.eq(Xb)?Xb:this.not().add(Qb)},Yb.neg=Yb.negate,Yb.add=function(e){Rb(e)||(e=Ub(e));var t=this.high>>>16,n=65535&this.high,r=this.low>>>16,i=65535&this.low,a=e.high>>>16,s=65535&e.high,o=e.low>>>16,A=0,l=0,c=0,u=0;return c+=(u+=i+(65535&e.low))>>>16,l+=(c+=r+o)>>>16,A+=(l+=n+s)>>>16,A+=t+a,Ob((c&=65535)<<16|(u&=65535),(A&=65535)<<16|(l&=65535),this.unsigned)},Yb.subtract=function(e){return Rb(e)||(e=Ub(e)),this.add(e.neg())},Yb.sub=Yb.subtract,Yb.multiply=function(e){if(this.isZero())return this;if(Rb(e)||(e=Ub(e)),Cb)return Ob(Cb.mul(this.low,this.high,e.low,e.high),Cb.get_high(),this.unsigned);if(e.isZero())return this.unsigned?qb:Hb;if(this.eq(Xb))return e.isOdd()?Xb:Hb;if(e.eq(Xb))return this.isOdd()?Xb:Hb;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(Gb)&&e.lt(Gb))return Bb(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,n=65535&this.high,r=this.low>>>16,i=65535&this.low,a=e.high>>>16,s=65535&e.high,o=e.low>>>16,A=65535&e.low,l=0,c=0,u=0,f=0;return u+=(f+=i*A)>>>16,c+=(u+=r*A)>>>16,u&=65535,c+=(u+=i*o)>>>16,l+=(c+=n*A)>>>16,c&=65535,l+=(c+=r*o)>>>16,c&=65535,l+=(c+=i*s)>>>16,l+=t*A+n*o+r*s+i*a,Ob((u&=65535)<<16|(f&=65535),(l&=65535)<<16|(c&=65535),this.unsigned)},Yb.mul=Yb.multiply,Yb.divide=function(e){if(Rb(e)||(e=Ub(e)),e.isZero())throw Error("division by zero");if(Cb)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?Ob((this.unsigned?Cb.div_u:Cb.div_s)(this.low,this.high,e.low,e.high),Cb.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?qb:Hb;var t,n,r;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return qb;if(e.gt(this.shru(1)))return Kb;r=qb}else{if(this.eq(Xb))return e.eq(Qb)||e.eq(Wb)?Xb:e.eq(Xb)?Qb:(t=this.shr(1).div(e).shl(1)).eq(Hb)?e.isNegative()?Qb:Wb:(n=this.sub(e.mul(t)),r=t.add(n.div(e)));if(e.eq(Xb))return this.unsigned?qb:Hb;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=Hb}for(n=this;n.gte(e);){t=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var i=Math.ceil(Math.log(t)/Math.LN2),a=i<=48?1:Fb(2,i-48),s=Bb(t),o=s.mul(e);o.isNegative()||o.gt(n);)o=(s=Bb(t-=a,this.unsigned)).mul(e);s.isZero()&&(s=Qb),r=r.add(s),n=n.sub(o)}return r},Yb.div=Yb.divide,Yb.modulo=function(e){return Rb(e)||(e=Ub(e)),Cb?Ob((this.unsigned?Cb.rem_u:Cb.rem_s)(this.low,this.high,e.low,e.high),Cb.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},Yb.mod=Yb.modulo,Yb.rem=Yb.modulo,Yb.not=function(){return Ob(~this.low,~this.high,this.unsigned)},Yb.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},Yb.clz=Yb.countLeadingZeros,Yb.countTrailingZeros=function(){return this.low?Pb(this.low):Pb(this.high)+32},Yb.ctz=Yb.countTrailingZeros,Yb.and=function(e){return Rb(e)||(e=Ub(e)),Ob(this.low&e.low,this.high&e.high,this.unsigned)},Yb.or=function(e){return Rb(e)||(e=Ub(e)),Ob(this.low|e.low,this.high|e.high,this.unsigned)},Yb.xor=function(e){return Rb(e)||(e=Ub(e)),Ob(this.low^e.low,this.high^e.high,this.unsigned)},Yb.shiftLeft=function(e){return Rb(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Ob(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):Ob(0,this.low<<e-32,this.unsigned)},Yb.shl=Yb.shiftLeft,Yb.shiftRight=function(e){return Rb(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Ob(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):Ob(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},Yb.shr=Yb.shiftRight,Yb.shiftRightUnsigned=function(e){return Rb(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Ob(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):Ob(32===e?this.high:this.high>>>e-32,0,this.unsigned)},Yb.shru=Yb.shiftRightUnsigned,Yb.shr_u=Yb.shiftRightUnsigned,Yb.rotateLeft=function(e){var t;return Rb(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?Ob(this.high,this.low,this.unsigned):e<32?(t=32-e,Ob(this.low<<e|this.high>>>t,this.high<<e|this.low>>>t,this.unsigned)):(t=32-(e-=32),Ob(this.high<<e|this.low>>>t,this.low<<e|this.high>>>t,this.unsigned))},Yb.rotl=Yb.rotateLeft,Yb.rotateRight=function(e){var t;return Rb(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?Ob(this.high,this.low,this.unsigned):e<32?(t=32-e,Ob(this.high<<t|this.low>>>e,this.low<<t|this.high>>>e,this.unsigned)):(t=32-(e-=32),Ob(this.low<<t|this.high>>>e,this.high<<t|this.low>>>e,this.unsigned))},Yb.rotr=Yb.rotateRight,Yb.toSigned=function(){return this.unsigned?Ob(this.low,this.high,!1):this},Yb.toUnsigned=function(){return this.unsigned?this:Ob(this.low,this.high,!0)},Yb.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},Yb.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},Yb.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},Ib.fromBytes=function(e,t,n){return n?Ib.fromBytesLE(e,t):Ib.fromBytesBE(e,t)},Ib.fromBytesLE=function(e,t){return new Ib(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},Ib.fromBytesBE=function(e,t){return new Ib(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)},"function"==typeof BigInt&&(Ib.fromBigInt=function(e,t){return Ob(Number(BigInt.asIntN(32,e)),Number(BigInt.asIntN(32,e>>BigInt(32))),t)},Ib.fromValue=function(e,t){return"bigint"==typeof e?Ib.fromBigInt(e,t):Ub(e,t)},Yb.toBigInt=function(){var e=BigInt(this.low>>>0);return BigInt(this.unsigned?this.high>>>0:this.high)<<BigInt(32)|e});function Zb(e){"X"===e&&(e="");const t=e.padEnd(16,"0");return Ib.fromString(t,!0,16)}var ev=180/Math.PI;function tv(e,t,n){const r=1<<t;return[(e[0]+n[0])/r,(e[1]+n[1])/r]}function nv(e){return e>=.5?1/3*(4*e*e-1):1/3*(1-4*(1-e)*(1-e))}function rv(e){return[nv(e[0]),nv(e[1])]}function iv(e,[t,n]){switch(e){case 0:return[1,t,n];case 1:return[-t,1,n];case 2:return[-t,-n,1];case 3:return[-1,-n,-t];case 4:return[n,-1,-t];case 5:return[n,t,-1];default:throw new Error("Invalid face")}}function av([e,t,n]){const r=Math.atan2(n,Math.sqrt(e*e+t*t));return[Math.atan2(t,e)*ev,r*ev]}function sv(e,t,n,r){if(0===r){1===n&&(t[0]=e-1-t[0],t[1]=e-1-t[1]);const r=t[0];t[0]=t[1],t[1]=r}}function ov(e){const{face:t,ij:n,level:r}=e,i=[[0,0],[0,1],[1,1],[1,0],[0,0]],a=Math.max(1,Math.ceil(100*Math.pow(2,-r))),s=new Float64Array(4*a*2+2);let o=0,A=0;for(let l=0;l<4;l++){const e=i[l].slice(0),c=i[l+1],u=(c[0]-e[0])/a,f=(c[1]-e[1])/a;for(let i=0;i<a;i++){e[0]+=u,e[1]+=f;const i=av(iv(t,rv(tv(n,r,e))));Math.abs(i[1])>89.999&&(i[0]=A);const a=i[0]-A;i[0]+=a>180?-360:a<-180?360:0,s[o++]=i[0],s[o++]=i[1],A=i[0]}}return s[o++]=s[0],s[o++]=s[1],s}function Av(e){const t=function(e){if(e.indexOf("/")>0)return e;const t=Zb(e);return function(e){if(e.isZero())return"";let t=e.toString(2);for(;t.length<64;)t="0"+t;const n=t.lastIndexOf("1"),r=t.substring(0,3),i=t.substring(3,n),a=i.length/2,s=Ib.fromString(r,!0,2).toString(10);let o="";if(0!==a)for(o=Ib.fromString(i,!0,2).toString(4);o.length<a;)o="0"+o;return`${s}/${o}`}(t)}(e);return function(e){if(0===e.length)throw new Error(`Invalid Hilbert quad key ${e}`);const t=e.split("/"),n=parseInt(t[0],10),r=t[1],i=r.length;let a=0;const s=[0,0];for(let o=i-1;o>=0;o--){a=i-o;const e=r[o];let t=0,n=0;"1"===e?n=1:"2"===e?(t=1,n=1):"3"===e&&(t=1);const A=Math.pow(2,a-1);sv(A,s,t,n),s[0]+=A*t,s[1]+=A*n}if(n%2==1){const e=s[0];s[0]=s[1],s[1]=e}return{face:n,ij:s,level:a}}(t)}function lv(e){return function(e){const t=rv(tv(e.ij,e.level,[.5,.5]));return av(iv(e.face,t))}(Av(e))}function cv(e){if(e.length%2!=0)throw new Error("Invalid corners");const t=[],n=[];for(let r=0;r<e.length;r+=2)t.push(e[r]),n.push(e[r+1]);return t.sort((e,t)=>e-t),n.sort((e,t)=>e-t),{west:t[0],east:t[t.length-1],north:n[n.length-1],south:n[0]}}function uv(e,t){const n=t?.minimumHeight||0,r=t?.maximumHeight||0,i=function(e){let t;if(2===e.face||5===e.face){let n=null,r=0;for(let t=0;t<4;t++){const i=ov(Av(`${e.face}/${t}`));null==n&&(n=new Float64Array(4*i.length)),n.set(i,r),r+=i.length}t=cv(n)}else t=cv(ov(e));return t}(Av(e)),a=i.west,s=i.south,o=i.east,A=i.north,l=[];return l.push(new de(a,A,n)),l.push(new de(o,A,n)),l.push(new de(o,s,n)),l.push(new de(a,s,n)),l.push(new de(a,A,r)),l.push(new de(o,A,r)),l.push(new de(o,s,r)),l.push(new de(a,s,r)),l}function fv(e){const t=e.token,n={minimumHeight:e.minimumHeight,maximumHeight:e.maximumHeight},r=uv(t,n),i=lv(t),a=i[0],s=i[1],o=gm.WGS84.cartographicToCartesian([a,s,n.maximumHeight]),A=new de(o[0],o[1],o[2]);r.push(A);const l=Jl(r);return[...l.center,...l.halfAxes]}var dv={QUADTREE:4,OCTREE:8};function hv(e,t,n){if(e?.box){const r=function(e,t){const n=function(e){return e.and(e.not().add(1))}(e).shiftRightUnsigned(2);return e.add(Ib.fromNumber(2*t+1-4).multiply(n))}(Zb(e.s2VolumeInfo.token),t),i=function(e){if(e.isZero())return"X";let t=e.countTrailingZeros();t=(t-t%4)/4;const n=t;t*=4;const r=e.shiftRightUnsigned(t).toString(16).replace(/0+$/,"");return Array(17-n-r.length).join("0")+r}(r),a={...e.s2VolumeInfo};if(a.token=i,"OCTREE"===n){const t=e.s2VolumeInfo,n=t.maximumHeight-t.minimumHeight,r=n/2,i=t.minimumHeight+n/2;t.minimumHeight=i-r,t.maximumHeight=i+r}return{box:fv(a),s2VolumeInfo:a}}}async function pv(e){const{subtree:t,subtreeData:n={level:0,x:0,y:0,z:0},parentData:r={mortonIndex:0,localLevel:-1,localX:0,localY:0,localZ:0},childIndex:i=0,implicitOptions:a,loaderOptions:s,s2VolumeBox:o}=e,{subdivisionScheme:A,subtreeLevels:l,maximumLevel:c,contentUrlTemplate:u,subtreesUriTemplate:f,basePath:d}=a,h={children:[],lodMetricValue:0,contentUrl:""};if("number"!=typeof c||!Number.isFinite(c))return et.once(`Missing 'maximumLevel' or 'availableLevels' property. The subtree ${u} won't be loaded...`),h;const p=r.localLevel+1,m=n.level+p;if(m>c)return h;const g=dv[A],b=Math.log2(g),v=1&i,y=i>>1&1,x=i>>2&1,_=gv(r.localX,v,1),w=gv(r.localY,y,1),T=gv(r.localZ,x,1),S=gv(n.x,_,p),M=gv(n.y,w,p),E=gv(n.z,T,p),C=gv(r.mortonIndex,i,b);let I,R,P,N;if(p===l&&mv(t.childSubtreeAvailability,C)){const e=bv(`${d}/${f}`,m,S,M,E);I=await Ae(e,Eb,s),N=0,R={level:m,x:S,y:M,z:E},P={mortonIndex:0,localLevel:0,localX:0,localY:0,localZ:0}}else I=t,N=(g**p-1)/(g-1)+C,R=n,P={mortonIndex:C,localLevel:p,localX:_,localY:w,localZ:T};if(!mv(I.tileAvailability,N))return h;mv(I.contentAvailability,N)&&(h.contentUrl=bv(u,m,S,M,E));for(let k=0;k<g;k++){const e=hv(o,k,A),t=await pv({subtree:I,subtreeData:R,parentData:P,childIndex:k,implicitOptions:a,loaderOptions:s,s2VolumeBox:e});(t.contentUrl||t.children.length)&&h.children.push(t)}return h.contentUrl||h.children.length?function(e,t,n,r){const{basePath:i,refine:a,getRefine:s,lodMetricType:o,getTileType:A,rootLodMetricValue:l,rootBoundingVolume:c}=n,u=e.contentUrl&&e.contentUrl.replace(`${i}/`,""),f=l/2**t.level,d=function(e,t,n){if(e.region){const{level:r,x:i,y:a,z:s}=t,[o,A,l,c,u,f]=e.region,d=2**r,h=(l-o)/d,[p,m]=[o+h*i,o+h*(i+1)],g=(c-A)/d,[b,v]=[A+g*a,A+g*(a+1)];let y,x;if("OCTREE"===n){const e=(f-u)/d;[y,x]=[u+e*s,u+e*(s+1)]}else[y,x]=[u,f];return{region:[p,b,m,v,y,x]}}if(e.box)return e;throw new Error(`Unsupported bounding volume type ${JSON.stringify(e)}`)}(r?.box?{box:r.box}:c,t,n.subdivisionScheme);return{children:e.children,contentUrl:e.contentUrl,content:{uri:u},id:e.contentUrl,refine:s(a),type:A(e),lodMetricType:o,lodMetricValue:f,geometricError:f,transform:e.transform,boundingVolume:d}}(h,{level:m,x:S,y:M,z:E},a,o):h}function mv(e,t){let n;return Array.isArray(e)?(n=e[0],e.length>1&&et.once('Not supported extension "3DTILES_multiple_contents" has been detected')):n=e,"constant"in n?Boolean(n.constant):!!n.explicitBitstream&&function(e,t){const n=Math.floor(e/8),r=e%8;return 1==(t[n]>>r&1)}(t,n.explicitBitstream)}function gv(e,t,n){return(e<<n)+t}function bv(e,t,n,r,i){const a=function(e){const t={};for(const n in e)t[`{${n}}`]=e[n];return t}({level:t,x:n,y:r,z:i});return e.replace(/{level}|{x}|{y}|{z}/gi,e=>a[e])}function vv(e,t=""){if(!t)return Lm.EMPTY;const n=t.split("?")[0].split(".").pop();switch(n){case"pnts":return Lm.POINTCLOUD;case"i3dm":case"b3dm":case"glb":case"gltf":return Lm.SCENEGRAPH;default:return n||Lm.EMPTY}}function yv(e){switch(e){case"REPLACE":case"replace":return km.REPLACE;case"ADD":case"add":return km.ADD;default:return e}}function xv(e,t){if(/^[a-z][0-9a-z+.-]*:/i.test(t)){const n=new URL(e,`${t}/`);return decodeURI(n.toString())}return e.startsWith("/")?e:ve(t,e)}function _v(e,t){if(!e)return null;let n;if(e.content){const r=e.content.uri||e.content?.url;void 0!==r&&(n=xv(r,t))}return{...e,id:n,contentUrl:n,lodMetricType:Om.GEOMETRIC_ERROR,lodMetricValue:e.geometricError,transformMatrix:e.transform,type:vv(0,n),refine:yv(e.refine)}}async function wv(e,t,n,r,i){const{subdivisionScheme:a,maximumLevel:s,availableLevels:o,subtreeLevels:A,subtrees:{uri:l}}=r,c=xv(bv(l,0,0,0,0),n),u=await Ae(c,Eb,i),f=e.content?.uri,d=f?xv(f,n):"",h=t?.root?.refine,p=e.geometricError,m=e.boundingVolume.extensions?.["3DTILES_bounding_volume_S2"];m&&(e.boundingVolume={box:fv(m),s2VolumeInfo:m});const g=e.boundingVolume;return await async function(e,t,n,r,i){if(!e)return null;const{children:a,contentUrl:s}=await pv({subtree:n,implicitOptions:r,loaderOptions:i});let o,A=null;s&&(o=s,A={uri:s.replace(`${t}/`,"")});return{...e,id:o,contentUrl:o,lodMetricType:Om.GEOMETRIC_ERROR,lodMetricValue:e.geometricError,transformMatrix:e.transform,type:vv(0,o),refine:yv(e.refine),content:A||e.content,children:a}}(e,n,u,{contentUrlTemplate:d,subtreesUriTemplate:l,subdivisionScheme:a,subtreeLevels:A,maximumLevel:Number.isFinite(o)?o-1:s,refine:h,basePath:n,lodMetricType:Om.GEOMETRIC_ERROR,rootLodMetricValue:p,rootBoundingVolume:g,getTileType:vv,getRefine:yv},i)}function Tv(e){return e?.extensions?.["3DTILES_implicit_tiling"]||e?.implicitTiling}var Sv={dataType:null,batchType:null,id:"3d-tiles",name:"3D Tiles",module:"3d-tiles",version:Fg,extensions:["cmpt","pnts","b3dm","i3dm"],mimeTypes:["application/octet-stream"],tests:["cmpt","pnts","b3dm","i3dm"],parse:async function(e,t={},n){const r=t["3d-tiles"]||{};let i;i="auto"===r.isTileset?n?.url&&-1!==n.url.indexOf(".json"):r.isTileset;return i?async function(e,t,n){const r=JSON.parse((new TextDecoder).decode(e)),i=n?.url||"",a=function(e){return he(e)}(i),s=await async function(e,t,n){let r=null;const i=Tv(e.root);r=i&&e.root?await wv(e.root,e,t,i,n):_v(e.root,t);const a=[];for(a.push(r);a.length>0;){const r=a.pop()||{},i=r.children||[],s=[];for(const o of i){const r=Tv(o);let i;i=r?await wv(o,e,t,r,n):_v(o,t),i&&(s.push(i),a.push(i))}r.children=s}return r}(r,a,t||{});return{...r,shape:"tileset3d",loader:Sv,url:i,queryString:n?.queryString||"",basePath:a,root:s||r.root,type:Bm.TILES3D,lodMetricType:Om.GEOMETRIC_ERROR,lodMetricValue:r.root?.geometricError||0}}(e,t,n):async function(e,t,n){const r={content:{shape:"tile3d",featureIds:null}};return await Tb(e,0,t,n,r.content),r.content}(e,t,n)},options:{"3d-tiles":{loadGLTF:!0,decodeQuantizedPositions:!1,isTileset:"auto",assetGltfUpAxis:null}}};var Mv=[0],Ev={[-1]:L.DEFAULT,0:L.CARTESIAN,1:L.LNGLAT,2:L.METER_OFFSETS,3:L.LNGLAT_OFFSETS};function Cv(e){return"number"==typeof e?Ev[e]??e:e}var Iv={getPointColor:{type:"accessor",value:[0,0,0,255]},pointSize:1,data:"",loader:Sv,onTilesetLoad:{type:"function",value:e=>{}},onTileLoad:{type:"function",value:e=>{}},onTileUnload:{type:"function",value:e=>{}},onTileError:{type:"function",value:(e,t,n)=>{}},_getMeshColor:{type:"function",value:e=>[255,255,255]}},Rv=class extends f{initializeState(){"onTileLoadFail"in this.props&&ge.removed("onTileLoadFail","onTileError")(),this.state={layerMap:{},tileset3d:null,activeViewports:{},lastUpdatedViewports:null}}get isLoaded(){return Boolean(this.state?.tileset3d?.isLoaded()&&super.isLoaded)}shouldUpdateState({changeFlags:e}){return e.somethingChanged}updateState({props:e,oldProps:t,changeFlags:n}){if(e.data&&e.data!==t.data&&this._loadTileset(e.data),n.viewportChanged){const{activeViewports:e}=this.state;Object.keys(e).length&&(this._updateTileset(e),this.state.lastUpdatedViewports=e,this.state.activeViewports={})}if(n.propsChanged){const{layerMap:e}=this.state;for(const t in e)e[t].needsUpdate=!0}}finalizeState(e){this.state.tileset3d?.destroy(),this.state.tileset3d=null,this.state.layerMap={},this.state.activeViewports={},this.state.lastUpdatedViewports=null,super.finalizeState(e)}activateViewport(e){const{activeViewports:t,lastUpdatedViewports:n}=this.state;this.internalState.viewport=e,t[e.id]=e;const r=n?.[e.id];r&&e.equals(r)||(this.setChangeFlags({viewportChanged:!0}),this.setNeedsUpdate())}getPickingInfo({info:e,sourceLayer:t}){const n=t&&t.props.tile;return e.picked&&(e.object=n),e.sourceTile=n,e}filterSubLayer({layer:e,viewport:t,cullRect:n,isPicking:r}){const{tile:i}=e.props,{id:a}=t;if(!i.selected||!i.viewportIds.includes(a))return!1;if(r&&n&&i.content?.cartographicOrigin){const[e,r]=t.project(i.content.cartographicOrigin),a=n.x+n.width/2,s=n.y+n.height/2,o=Math.max(t.width,t.height)/4,A=e-a,l=r-s;if(A*A+l*l>o*o)return!1}return!0}_updateAutoHighlight(e){const t=e.sourceTile,n=this.state.layerMap[t?.id];n&&n.layer&&n.layer.updateAutoHighlight(e)}async _loadTileset(e){const t=this.props.loadOptions||{},n=this.props.loaders?.length?this.props.loaders:this.props.loader,r=Array.isArray(n)?n[0]:n,{tileset:i,...a}=t,s={loadOptions:{...a},...i};let o=e;if("preload"in r&&"function"==typeof r.preload){const n=await r.preload(e,t);n.url&&(o=n.url),n.headers&&(s.loadOptions.core={...s.loadOptions.core,fetch:{...s.loadOptions.core?.fetch,headers:n.headers}}),Object.assign(s,n)}const A=await Ae(o,r,s.loadOptions),l=new Og(A,{onTileLoad:this._onTileLoad.bind(this),onTileUnload:this._onTileUnload.bind(this),onTileError:this.props.onTileError,onUpdate:()=>this.setNeedsUpdate(),...s});this.setState({tileset3d:l,layerMap:{}}),this._updateTileset(this.state.activeViewports),this.props.onTilesetLoad(l)}_onTileLoad(e){const{lastUpdatedViewports:t}=this.state;e.tileDrawn=!1,this.props.onTileLoad(e),this._updateTileset(t),this.setNeedsUpdate()}_onTileUnload(e){delete this.state.layerMap[e.id],this.props.onTileUnload(e)}_updateTileset(e){if(!e)return;const{tileset3d:t}=this.state,{timeline:n}=this.context,r=Object.keys(e).length;n&&r&&t&&t.selectTiles(Object.values(e)).then(e=>{this.state.frameNumber!==e&&this.setState({frameNumber:e})})}_getSubLayer(e,t){if(!e.content)return null;switch(e.type){case Lm.POINTCLOUD:return this._makePointCloudLayer(e,t);case Lm.SCENEGRAPH:return this._make3DModelLayer(e);case Lm.MESH:return this._makeSimpleMeshLayer(e,t);default:throw new Error(`Tile3DLayer: Failed to render layer of type ${e.content.type}`)}}_makePointCloudLayer(e,t){const{attributes:n,pointCount:r,constantRGBA:i,cartographicOrigin:a,modelMatrix:s}=e.content,{positions:o,normals:A,colors:l}=n;if(!o)return null;const c=t&&t.props.data||{header:{vertexCount:r},attributes:{POSITION:o,NORMAL:A,COLOR_0:l}},{pointSize:f,getPointColor:d}=this.props;return new(this.getSubLayerClass("pointcloud",u))({pointSize:f},this.getSubLayerProps({id:"pointcloud"}),{id:`${this.id}-pointcloud-${e.id}`,tile:e,data:c,coordinateSystem:L.METER_OFFSETS,coordinateOrigin:a,modelMatrix:s,getColor:i||d,_offset:0})}_make3DModelLayer(e){const{gltf:t,instances:n,cartographicOrigin:r,modelMatrix:i}=e.content;return new(this.getSubLayerClass("scenegraph",zp))({_lighting:"pbr"},this.getSubLayerProps({id:"scenegraph"}),{id:`${this.id}-scenegraph-${e.id}`,tile:e,data:n||Mv,scenegraph:t,coordinateSystem:L.METER_OFFSETS,coordinateOrigin:r,modelMatrix:i,getTransformMatrix:e=>e.modelMatrix,getPosition:[0,0,0],_offset:0,onFirstDraw:()=>{e.tileDrawn=!0}})}_makeSimpleMeshLayer(e,t){const{attributes:n,indices:r,modelMatrix:i,cartographicOrigin:a,coordinateSystem:s=L.METER_OFFSETS,material:o,featureIds:A}=e.content,{_getMeshColor:l}=this.props,c=t&&t.props.mesh||new E({topology:"triangle-list",attributes:Pv(n),indices:r});return new(this.getSubLayerClass("mesh",Kp))(this.getSubLayerProps({id:"mesh"}),{id:`${this.id}-mesh-${e.id}`,tile:e,mesh:c,data:Mv,getColor:l(e),pbrMaterial:o,modelMatrix:i,coordinateOrigin:a,coordinateSystem:Cv(s),featureIds:A,_offset:0})}renderLayers(){const{tileset3d:e,layerMap:t}=this.state;return e?e.tiles.map(e=>{const n=t[e.id]=t[e.id]||{tile:e};let{layer:r}=n;return e.selected&&(r?n.needsUpdate&&(r=this._getSubLayer(e,r),n.needsUpdate=!1):r=this._getSubLayer(e)),n.layer=r,r}).filter(Boolean):null}};function Pv(e){const t={};return t.positions={...e.positions,value:new Float32Array(e.positions.value)},e.normals&&(t.normals=e.normals),e.texCoords&&(t.texCoords=e.texCoords),e.colors&&(t.colors=e.colors),e.uvRegions&&(t.uvRegions=e.uvRegions),t}Rv.defaultProps=Iv,Rv.layerName="Tile3DLayer";var Nv={dataType:null,batchType:null,name:"Terrain",id:"terrain",module:"terrain",version:"4.5.4",worker:!0,extensions:["png","pngraw","jpg","jpeg","gif","webp","bmp"],mimeTypes:["image/png","image/jpeg","image/gif","image/webp","image/bmp"],options:{terrain:{tesselator:"auto",bounds:void 0,meshMaxError:10,elevationDecoder:{rScaler:1,gScaler:0,bScaler:0,offset:0},skirtHeight:void 0}}},kv=[1],Lv={...Sc.defaultProps,elevationData:rc,texture:{...rc,optional:!0},meshMaxError:{type:"number",value:4},bounds:{type:"array",value:null,optional:!0,compare:!0},color:{type:"color",value:[255,255,255]},elevationDecoder:{type:"object",value:{rScaler:1,gScaler:0,bScaler:0,offset:0}},workerUrl:"",wireframe:!1,material:!0,loaders:[Nv]};function Bv(e){return Array.isArray(e)?e.join(";"):e||""}var Ov=class extends f{updateState({props:e,oldProps:t}){const n=e.elevationData!==t.elevationData;if(n){const{elevationData:t}=e,n=t&&(Array.isArray(t)||Fv(t));this.setState({isTiled:n})}const r=n||e.meshMaxError!==t.meshMaxError||e.elevationDecoder!==t.elevationDecoder||e.bounds!==t.bounds;if(!this.state.isTiled&&r){const t=this.loadTerrain(e);this.setState({terrain:t})}e.workerUrl&&ge.removed("workerUrl","loadOptions.terrain.workerUrl")()}loadTerrain({elevationData:e,bounds:t,elevationDecoder:n,meshMaxError:r,signal:i}){if(!e)return null;const a=function(e){return!Number.isFinite(e)||e<=0?1:Math.max(e,1)}(r);let s=this.getLoadOptions();s={...s,terrain:{skirtHeight:this.state.isTiled?2*a:0,...s?.terrain,bounds:t,meshMaxError:a,elevationDecoder:n}};const{fetch:o}=this.props;return o(e,{propName:"elevationData",layer:this,loadOptions:s,signal:i})}getTiledTerrainData(e){const{elevationData:t,fetch:n,texture:r,elevationDecoder:i,meshMaxError:a}=this.props,{viewport:s}=this.context,o=ac(t,e),A=r&&ac(r,e),{signal:l}=e;let c=[0,0],u=[0,0];if(s.isGeospatial){const t=e.bbox;c=s.projectFlat([t.west,t.south]),u=s.projectFlat([t.east,t.north])}else{const t=e.bbox;c=[t.left,t.bottom],u=[t.right,t.top]}const f=function(e,t,n){const r=(e[2]-e[0])/t*1,i=(e[3]-e[1])/t*1,a=[e[0]-r,e[1]-i,e[2]+r,e[3]+i];return n?[Math.max(a[0],-180),Math.max(a[1],-90),Math.min(a[2],180),Math.min(a[3],90)]:a}([c[0],c[1],u[0],u[1]],this.props.tileSize,s instanceof De),d=this.loadTerrain({elevationData:o,bounds:f,elevationDecoder:i,meshMaxError:a,signal:l}),h=A?n(A,{propName:"texture",layer:this,loaders:[],signal:l}).catch(e=>null):Promise.resolve(null);return Promise.all([d,h])}renderSubLayers(e){const t=this.getSubLayerClass("mesh",Qc),{color:n,wireframe:r,material:i}=this.props,{data:a}=e;if(!a)return null;const[s,o]=a,{viewport:A}=this.context,l=A instanceof De,c=s?.header?.boundingBox,u=c&&c.every(([e,t])=>e>=-180&&e<=180&&t>=-90&&t<=90),f=l&&u?L.LNGLAT:L.CARTESIAN;return new t(e,{data:kv,mesh:s,texture:o,_instanced:!1,coordinateSystem:f,getPosition:e=>[0,0,0],getColor:n,wireframe:r,material:i})}onViewportLoad(e){if(!e)return;const{zRange:t}=this.state,n=e.map(e=>e.content).filter(Boolean).map(e=>e[0].header.boundingBox.map(e=>e[2]));if(0===n.length)return;const r=Math.min(...n.map(e=>e[0])),i=Math.max(...n.map(e=>e[1]));(!t||r<t[0]||i>t[1])&&this.setState({zRange:[r,i]})}renderLayers(){const{color:e,material:t,elevationData:n,texture:r,wireframe:i,meshMaxError:a,elevationDecoder:s,tileSize:o,maxZoom:A,minZoom:l,extent:c,maxRequests:u,onTileLoad:f,onTileUnload:d,onTileError:h,maxCacheSize:p,maxCacheByteSize:m,refinementStrategy:g,zoomOffset:b}=this.props;return this.state.isTiled?new Sc(this.getSubLayerProps({id:"tiles"}),{getTileData:this.getTiledTerrainData.bind(this),renderSubLayers:this.renderSubLayers.bind(this),updateTriggers:{getTileData:{elevationData:Bv(n),texture:Bv(r),meshMaxError:a,elevationDecoder:s,projectionMode:this.context.viewport.projectionMode,zoomOffset:b}},onViewportLoad:this.onViewportLoad.bind(this),zRange:this.state.zRange||null,tileSize:o,maxZoom:A,minZoom:l,extent:c,maxRequests:u,onTileLoad:f,onTileUnload:d,onTileError:h,maxCacheSize:p,maxCacheByteSize:m,refinementStrategy:g,zoomOffset:b}):n?new(this.getSubLayerClass("mesh",Qc))(this.getSubLayerProps({id:"mesh"}),{data:kv,mesh:this.state.terrain,texture:r,_instanced:!1,getPosition:e=>[0,0,0],getColor:e,material:t,wireframe:i}):null}};Ov.defaultProps=Lv,Ov.layerName="TerrainLayer";var Fv=e=>e.includes("{x}")&&(e.includes("{y}")||e.includes("{-y}")),Dv="\nlayout(std140) uniform clipUniforms {\n vec4 bounds;\n} clip;\n\nbool clip_isInBounds(vec2 position) {\n return position.x >= clip.bounds[0] && position.y >= clip.bounds[1] && position.x < clip.bounds[2] && position.y < clip.bounds[3];\n}\n",Uv={name:"clip",vs:Dv,uniformTypes:{bounds:"vec4<f32>"}},Vv={"vs:#decl":"\nout float clip_isVisible;\n","vs:DECKGL_FILTER_GL_POSITION":"\n clip_isVisible = float(clip_isInBounds(geometry.worldPosition.xy));\n","fs:#decl":"\nin float clip_isVisible;\n","fs:DECKGL_FILTER_COLOR":"\n if (clip_isVisible < 0.5) discard;\n"},jv={name:"clip",fs:Dv,uniformTypes:{bounds:"vec4<f32>"}},zv={"vs:#decl":"\nout vec2 clip_commonPosition;\n","vs:DECKGL_FILTER_GL_POSITION":"\n clip_commonPosition = geometry.position.xy;\n","fs:#decl":"\nin vec2 clip_commonPosition;\n","fs:DECKGL_FILTER_COLOR":"\n if (!clip_isInBounds(clip_commonPosition)) discard;\n"},Gv=class extends Sn{getShaders(){let e="instancePositions"in this.getAttributeManager().attributes;return void 0!==this.props.clipByInstance&&(e=Boolean(this.props.clipByInstance)),this.state.clipByInstance=e,"webgpu"===this.context.device.type?{}:e?{modules:[Uv],inject:Vv}:{modules:[jv],inject:zv}}draw(){const{clipBounds:e}=this.props,t={};if(this.state.clipByInstance)t.bounds=e;else{const n=this.projectPosition([e[0],e[1],0]),r=this.projectPosition([e[2],e[3],0]);t.bounds=[Math.min(n[0],r[0]),Math.min(n[1],r[1]),Math.max(n[0],r[0]),Math.max(n[1],r[1])]}"webgpu"===this.context.device.type&&(t.enabled=!0,t.mode=this.state.clipByInstance?"instance":"geometry"),this.setShaderModuleProps({clip:t})}};function Hv(e,t,n){switch(e.type){case"Point":return function(e,t,n){const{positions:r}=e,i=Qv(r,t,n);return i.length>1?{type:"MultiPoint",coordinates:i}:{type:"Point",coordinates:i[0]}}(e,t,n);case"LineString":return function(e,t=-1/0,n=1/0){const{positions:r}=e,i=e.pathIndices.value.filter(e=>e>=t&&e<=n);if(!(i.length>2))return{type:"LineString",coordinates:Qv(r,i[0],i[1])};const a=[];for(let s=0;s<i.length-1;s++){const e=Qv(r,i[s],i[s+1]);a.push(e)}return{type:"MultiLineString",coordinates:a}}(e,t,n);case"Polygon":return qv(e,t,n);default:throw new Error(`Unsupported geometry type: ${e?.type}`)}}function qv(e,t=-1/0,n=1/0){const{positions:r}=e,i=e.polygonIndices.value.filter(e=>e>=t&&e<=n),a=e.primitivePolygonIndices.value.filter(e=>e>=t&&e<=n);if(!(i.length>2)){const e=[];for(let t=0;t<a.length-1;t++){const n=Qv(r,a[t],a[t+1]);e.push(n)}return{type:"Polygon",coordinates:e}}const s=[];for(let o=0;o<i.length-1;o++){const t=qv(e,i[o],i[o+1]).coordinates;s.push(t)}return{type:"MultiPolygon",coordinates:s}}function Qv(e,t,n){t=t||0,n=n||e.value.length/e.size;const r=[];for(let i=t;i<n;i++){const t=Array();for(let n=i*e.size;n<(i+1)*e.size;n++)t.push(Number(e.value[n]));r.push(t)}return r}function Kv(e,t,n){const r=function(e){const t={};for(const n of e)if(n.properties)for(const e in n.properties){const r=n.properties[e];t[e]=ty(r,t[e])}return t}(e),i=Object.keys(r).filter(e=>r[e]!==Array);return function(e,t,n){const{pointPositionsCount:r,pointFeaturesCount:i,linePositionsCount:a,linePathsCount:s,lineFeaturesCount:o,polygonPositionsCount:A,polygonObjectsCount:l,polygonRingsCount:c,polygonFeaturesCount:u,propArrayTypes:f,coordLength:d}=t,{numericPropKeys:h=[],PositionDataType:p=Float32Array,triangulate:m=!0}=n,g=e[0]&&"id"in e[0],b=e.length>65535?Uint32Array:Uint16Array,v={type:"Point",positions:new p(r*d),globalFeatureIds:new b(r),featureIds:i>65535?new Uint32Array(r):new Uint16Array(r),numericProps:{},properties:[],fields:[]},y={type:"LineString",pathIndices:a>65535?new Uint32Array(s+1):new Uint16Array(s+1),positions:new p(a*d),globalFeatureIds:new b(a),featureIds:o>65535?new Uint32Array(a):new Uint16Array(a),numericProps:{},properties:[],fields:[]},x={type:"Polygon",polygonIndices:A>65535?new Uint32Array(l+1):new Uint16Array(l+1),primitivePolygonIndices:A>65535?new Uint32Array(c+1):new Uint16Array(c+1),positions:new p(A*d),globalFeatureIds:new b(A),featureIds:u>65535?new Uint32Array(A):new Uint16Array(A),numericProps:{},properties:[],fields:[]};m&&(x.triangles=[]);for(const w of[v,y,x])for(const e of h){const t=f[e];w.numericProps[e]=new t(w.positions.length/d)}y.pathIndices[s]=a,x.polygonIndices[l]=A,x.primitivePolygonIndices[c]=A;const _={pointPosition:0,pointFeature:0,linePosition:0,linePath:0,lineFeature:0,polygonPosition:0,polygonObject:0,polygonRing:0,polygonFeature:0,feature:0};for(const w of e){const e=w.geometry,t=w.properties||{};switch(e.type){case"Point":Wv(e,v,_,d,t),v.properties.push(ey(t,h)),g&&v.fields.push({id:w.id}),_.pointFeature++;break;case"LineString":Jv(e,y,_,d,t),y.properties.push(ey(t,h)),g&&y.fields.push({id:w.id}),_.lineFeature++;break;case"Polygon":$v(e,x,_,d,t),x.properties.push(ey(t,h)),g&&x.fields.push({id:w.id}),_.polygonFeature++;break;default:throw new Error("Invalid geometry type")}_.feature++}return function(e,t,n,r){const i={shape:"binary-feature-collection",points:{...e,positions:{value:e.positions,size:r},globalFeatureIds:{value:e.globalFeatureIds,size:1},featureIds:{value:e.featureIds,size:1},numericProps:Yv(e.numericProps,1)},lines:{...t,positions:{value:t.positions,size:r},pathIndices:{value:t.pathIndices,size:1},globalFeatureIds:{value:t.globalFeatureIds,size:1},featureIds:{value:t.featureIds,size:1},numericProps:Yv(t.numericProps,1)},polygons:{...n,positions:{value:n.positions,size:r},polygonIndices:{value:n.polygonIndices,size:1},primitivePolygonIndices:{value:n.primitivePolygonIndices,size:1},globalFeatureIds:{value:n.globalFeatureIds,size:1},featureIds:{value:n.featureIds,size:1},numericProps:Yv(n.numericProps,1)}};i.polygons&&n.triangles&&(i.polygons.triangles={value:new Uint32Array(n.triangles),size:1});return i}(v,y,x,d)}(e,{propArrayTypes:r,...t},{numericPropKeys:n&&n.numericPropKeys||i,PositionDataType:n?n.PositionDataType:Float32Array,triangulate:!n||n.triangulate})}function Wv(e,t,n,r,i){t.positions.set(e.data,n.pointPosition*r);const a=e.data.length/r;Zv(t,i,n.pointPosition,a),t.globalFeatureIds.fill(n.feature,n.pointPosition,n.pointPosition+a),t.featureIds.fill(n.pointFeature,n.pointPosition,n.pointPosition+a),n.pointPosition+=a}function Jv(e,t,n,r,i){t.positions.set(e.data,n.linePosition*r);const a=e.data.length/r;Zv(t,i,n.linePosition,a),t.globalFeatureIds.fill(n.feature,n.linePosition,n.linePosition+a),t.featureIds.fill(n.lineFeature,n.linePosition,n.linePosition+a);for(let s=0,o=e.indices.length;s<o;++s){const i=e.indices[s],a=s===o-1?e.data.length:e.indices[s+1];t.pathIndices[n.linePath++]=n.linePosition,n.linePosition+=(a-i)/r}}function $v(e,t,n,r,i){t.positions.set(e.data,n.polygonPosition*r);const a=e.data.length/r;Zv(t,i,n.polygonPosition,a),t.globalFeatureIds.fill(n.feature,n.polygonPosition,n.polygonPosition+a),t.featureIds.fill(n.polygonFeature,n.polygonPosition,n.polygonPosition+a);for(let s=0,o=e.indices.length;s<o;++s){const i=n.polygonPosition;t.polygonIndices[n.polygonObject++]=i;const a=e.areas[s],o=e.indices[s],A=e.indices[s+1];for(let s=0,l=o.length;s<l;++s){const i=o[s],a=s===l-1?void 0===A?e.data.length:A[0]:o[s+1];t.primitivePolygonIndices[n.polygonRing++]=n.polygonPosition,n.polygonPosition+=(a-i)/r}Xv(t,a,o,{startPosition:i,endPosition:n.polygonPosition,coordLength:r})}}function Xv(e,t,n,{startPosition:r,endPosition:i,coordLength:a}){if(!e.triangles)return;const s=r*a,o=i*a,A=e.positions.subarray(s,o),l=n[0],c=Mn(A,n.slice(1).map(e=>(e-l)/a),a,t);for(let u=0,f=c.length;u<f;++u)e.triangles.push(r+c[u])}function Yv(e,t){const n={};for(const r in e)n[r]={value:e[r],size:t};return n}function Zv(e,t,n,r){for(const i in e.numericProps)if(i in t){const a=t[i];e.numericProps[i].fill(a,n,n+r)}}function ey(e,t){const n={};for(const r in e)t.includes(r)||(n[r]=e[r]);return n}function ty(e,t){return t!==Array&&Number.isFinite(e)?t===Float64Array||Math.fround(e)!==e?Float64Array:Float32Array:Array}function ny(e,t){const n=t?.globalFeatureId;return void 0!==n?function(e,t){const n=ry(e);for(const r of n){let e=0,n=r.featureIds.value[0];for(let i=0;i<r.featureIds.value.length;i++){const a=r.featureIds.value[i];if(a!==n){if(t===r.globalFeatureIds.value[e])return iy(r,e,i);e=i,n=a}}if(t===r.globalFeatureIds.value[e])return iy(r,e,r.featureIds.value.length)}throw new Error(`featureId:${t} not found`)}(e,n):function(e,t){return function(e){const t=[];for(const n of e){if(0===n.featureIds.value.length)continue;let e=0,r=n.featureIds.value[0];for(let i=0;i<n.featureIds.value.length;i++){const a=n.featureIds.value[i];a!==r&&(t.push(iy(n,e,i)),e=i,r=a)}t.push(iy(n,e,n.featureIds.value.length))}return t}(ry(e,t))}(e,t?.type)}function ry(e,t){const n=[];return e.points&&(e.points.type="Point",n.push(e.points)),e.lines&&(e.lines.type="LineString",n.push(e.lines)),e.polygons&&(e.polygons.type="Polygon",n.push(e.polygons)),n}function iy(e,t,n){return{type:"Feature",geometry:Hv(e,t,n),properties:sy(e,t,n),...ay(e,t,n)}}function ay(e,t=0,n){return e.fields&&e.fields[e.featureIds.value[t]]}function sy(e,t=0,n){const r=Object.assign({},e.properties[e.featureIds.value[t]]);for(const i in e.numericProps)r[i]=e.numericProps[i].value[t];return r}Gv.defaultProps={clipBounds:[0,0,1,1],clipByInstance:void 0},Gv.extensionName="ClipExtension";var oy=/* @__PURE__ */r(e=>{e.read=function(e,t,n,r,i){var a,s,o=8*i-r-1,A=(1<<o)-1,l=A>>1,c=-7,u=n?i-1:0,f=n?-1:1,d=e[t+u];for(u+=f,a=d&(1<<-c)-1,d>>=-c,c+=o;c>0;a=256*a+e[t+u],u+=f,c-=8);for(s=a&(1<<-c)-1,a>>=-c,c+=r;c>0;s=256*s+e[t+u],u+=f,c-=8);if(0===a)a=1-l;else{if(a===A)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,r),a-=l}return(d?-1:1)*s*Math.pow(2,a-r)},e.write=function(e,t,n,r,i,a){var s,o,A,l=8*a-i-1,c=(1<<l)-1,u=c>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:a-1,h=r?1:-1,p=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,s=c):(s=Math.floor(Math.log(t)/Math.LN2),t*(A=Math.pow(2,-s))<1&&(s--,A*=2),(t+=s+u>=1?f/A:f*Math.pow(2,1-u))*A>=2&&(s++,A/=2),s+u>=c?(o=0,s=c):s+u>=1?(o=(t*A-1)*Math.pow(2,i),s+=u):(o=t*Math.pow(2,u-1)*Math.pow(2,i),s=0));i>=8;e[n+d]=255&o,d+=h,o/=256,i-=8);for(s=s<<i|o,l+=i;l>0;e[n+d]=255&s,d+=h,s/=256,l-=8);e[n+d-h]|=128*p}}),Ay=/* @__PURE__ */r((e,t)=>{t.exports=r;var n=oy();function r(e){this.buf=ArrayBuffer.isView&&ArrayBuffer.isView(e)?e:new Uint8Array(e||0),this.pos=0,this.type=0,this.length=this.buf.length}r.Varint=0,r.Fixed64=1,r.Bytes=2,r.Fixed32=5;var i=4294967296,a=1/i,s="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8");function o(e){return e.type===r.Bytes?e.readVarint()+e.pos:e.pos+1}function A(e,t,n){return n?4294967296*t+(e>>>0):4294967296*(t>>>0)+(e>>>0)}function l(e,t,n){var r=t<=16383?1:t<=2097151?2:t<=268435455?3:Math.floor(Math.log(t)/(7*Math.LN2));n.realloc(r);for(var i=n.pos-1;i>=e;i--)n.buf[i+r]=n.buf[i]}function c(e,t){for(var n=0;n<e.length;n++)t.writeVarint(e[n])}function u(e,t){for(var n=0;n<e.length;n++)t.writeSVarint(e[n])}function f(e,t){for(var n=0;n<e.length;n++)t.writeFloat(e[n])}function d(e,t){for(var n=0;n<e.length;n++)t.writeDouble(e[n])}function h(e,t){for(var n=0;n<e.length;n++)t.writeBoolean(e[n])}function p(e,t){for(var n=0;n<e.length;n++)t.writeFixed32(e[n])}function m(e,t){for(var n=0;n<e.length;n++)t.writeSFixed32(e[n])}function g(e,t){for(var n=0;n<e.length;n++)t.writeFixed64(e[n])}function b(e,t){for(var n=0;n<e.length;n++)t.writeSFixed64(e[n])}function v(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16)+16777216*e[t+3]}function y(e,t,n){e[n]=t,e[n+1]=t>>>8,e[n+2]=t>>>16,e[n+3]=t>>>24}function x(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16)+(e[t+3]<<24)}r.prototype={destroy:function(){this.buf=null},readFields:function(e,t,n){for(n=n||this.length;this.pos<n;){var r=this.readVarint(),i=r>>3,a=this.pos;this.type=7&r,e(i,t,this),this.pos===a&&this.skip(r)}return t},readMessage:function(e,t){return this.readFields(e,t,this.readVarint()+this.pos)},readFixed32:function(){var e=v(this.buf,this.pos);return this.pos+=4,e},readSFixed32:function(){var e=x(this.buf,this.pos);return this.pos+=4,e},readFixed64:function(){var e=v(this.buf,this.pos)+v(this.buf,this.pos+4)*i;return this.pos+=8,e},readSFixed64:function(){var e=v(this.buf,this.pos)+x(this.buf,this.pos+4)*i;return this.pos+=8,e},readFloat:function(){var e=n.read(this.buf,this.pos,!0,23,4);return this.pos+=4,e},readDouble:function(){var e=n.read(this.buf,this.pos,!0,52,8);return this.pos+=8,e},readVarint:function(e){var t,n=this.buf,r=n[this.pos++];return t=127&r,r<128?t:(t|=(127&(r=n[this.pos++]))<<7,r<128?t:(t|=(127&(r=n[this.pos++]))<<14,r<128?t:(t|=(127&(r=n[this.pos++]))<<21,r<128?t:function(e,t,n){var r,i=n.buf,a=i[n.pos++];if(r=(112&a)>>4,a<128)return A(e,r,t);if(a=i[n.pos++],r|=(127&a)<<3,a<128)return A(e,r,t);if(a=i[n.pos++],r|=(127&a)<<10,a<128)return A(e,r,t);if(a=i[n.pos++],r|=(127&a)<<17,a<128)return A(e,r,t);if(a=i[n.pos++],r|=(127&a)<<24,a<128)return A(e,r,t);if(a=i[n.pos++],r|=(1&a)<<31,a<128)return A(e,r,t);throw new Error("Expected varint not more than 10 bytes")}(t|=(15&(r=n[this.pos]))<<28,e,this))))},readVarint64:function(){return this.readVarint(!0)},readSVarint:function(){var e=this.readVarint();return e%2==1?(e+1)/-2:e/2},readBoolean:function(){return Boolean(this.readVarint())},readString:function(){var e=this.readVarint()+this.pos,t=this.pos;return this.pos=e,e-t>=12&&s?function(e,t,n){return s.decode(e.subarray(t,n))}(this.buf,t,e):function(e,t,n){var r="",i=t;for(;i<n;){var a,s,o,A=e[i],l=null,c=A>239?4:A>223?3:A>191?2:1;if(i+c>n)break;1===c?A<128&&(l=A):2===c?128==(192&(a=e[i+1]))&&(l=(31&A)<<6|63&a)<=127&&(l=null):3===c?(a=e[i+1],s=e[i+2],128==(192&a)&&128==(192&s)&&((l=(15&A)<<12|(63&a)<<6|63&s)<=2047||l>=55296&&l<=57343)&&(l=null)):4===c&&(a=e[i+1],s=e[i+2],o=e[i+3],128==(192&a)&&128==(192&s)&&128==(192&o)&&((l=(15&A)<<18|(63&a)<<12|(63&s)<<6|63&o)<=65535||l>=1114112)&&(l=null)),null===l?(l=65533,c=1):l>65535&&(l-=65536,r+=String.fromCharCode(l>>>10&1023|55296),l=56320|1023&l),r+=String.fromCharCode(l),i+=c}return r}(this.buf,t,e)},readBytes:function(){var e=this.readVarint()+this.pos,t=this.buf.subarray(this.pos,e);return this.pos=e,t},readPackedVarint:function(e,t){if(this.type!==r.Bytes)return e.push(this.readVarint(t));var n=o(this);for(e=e||[];this.pos<n;)e.push(this.readVarint(t));return e},readPackedSVarint:function(e){if(this.type!==r.Bytes)return e.push(this.readSVarint());var t=o(this);for(e=e||[];this.pos<t;)e.push(this.readSVarint());return e},readPackedBoolean:function(e){if(this.type!==r.Bytes)return e.push(this.readBoolean());var t=o(this);for(e=e||[];this.pos<t;)e.push(this.readBoolean());return e},readPackedFloat:function(e){if(this.type!==r.Bytes)return e.push(this.readFloat());var t=o(this);for(e=e||[];this.pos<t;)e.push(this.readFloat());return e},readPackedDouble:function(e){if(this.type!==r.Bytes)return e.push(this.readDouble());var t=o(this);for(e=e||[];this.pos<t;)e.push(this.readDouble());return e},readPackedFixed32:function(e){if(this.type!==r.Bytes)return e.push(this.readFixed32());var t=o(this);for(e=e||[];this.pos<t;)e.push(this.readFixed32());return e},readPackedSFixed32:function(e){if(this.type!==r.Bytes)return e.push(this.readSFixed32());var t=o(this);for(e=e||[];this.pos<t;)e.push(this.readSFixed32());return e},readPackedFixed64:function(e){if(this.type!==r.Bytes)return e.push(this.readFixed64());var t=o(this);for(e=e||[];this.pos<t;)e.push(this.readFixed64());return e},readPackedSFixed64:function(e){if(this.type!==r.Bytes)return e.push(this.readSFixed64());var t=o(this);for(e=e||[];this.pos<t;)e.push(this.readSFixed64());return e},skip:function(e){var t=7&e;if(t===r.Varint)for(;this.buf[this.pos++]>127;);else if(t===r.Bytes)this.pos=this.readVarint()+this.pos;else if(t===r.Fixed32)this.pos+=4;else{if(t!==r.Fixed64)throw new Error("Unimplemented type: "+t);this.pos+=8}},writeTag:function(e,t){this.writeVarint(e<<3|t)},realloc:function(e){for(var t=this.length||16;t<this.pos+e;)t*=2;if(t!==this.length){var n=new Uint8Array(t);n.set(this.buf),this.buf=n,this.length=t}},finish:function(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)},writeFixed32:function(e){this.realloc(4),y(this.buf,e,this.pos),this.pos+=4},writeSFixed32:function(e){this.realloc(4),y(this.buf,e,this.pos),this.pos+=4},writeFixed64:function(e){this.realloc(8),y(this.buf,-1&e,this.pos),y(this.buf,Math.floor(e*a),this.pos+4),this.pos+=8},writeSFixed64:function(e){this.realloc(8),y(this.buf,-1&e,this.pos),y(this.buf,Math.floor(e*a),this.pos+4),this.pos+=8},writeVarint:function(e){(e=+e||0)>268435455||e<0?function(e,t){var n,r;e>=0?(n=e%4294967296|0,r=e/4294967296|0):(r=~(-e/4294967296),4294967295^(n=~(-e%4294967296))?n=n+1|0:(n=0,r=r+1|0));if(e>=0x10000000000000000||e<-0x10000000000000000)throw new Error("Given varint doesn't fit into 10 bytes");t.realloc(10),function(e,t,n){n.buf[n.pos++]=127&e|128,e>>>=7,n.buf[n.pos++]=127&e|128,e>>>=7,n.buf[n.pos++]=127&e|128,e>>>=7,n.buf[n.pos++]=127&e|128,e>>>=7,n.buf[n.pos]=127&e}(n,0,t),function(e,t){var n=(7&e)<<4;if(t.buf[t.pos++]|=n|((e>>>=3)?128:0),!e)return;if(t.buf[t.pos++]=127&e|((e>>>=7)?128:0),!e)return;if(t.buf[t.pos++]=127&e|((e>>>=7)?128:0),!e)return;if(t.buf[t.pos++]=127&e|((e>>>=7)?128:0),!e)return;if(t.buf[t.pos++]=127&e|((e>>>=7)?128:0),!e)return;t.buf[t.pos++]=127&e}(r,t)}(e,this):(this.realloc(4),this.buf[this.pos++]=127&e|(e>127?128:0),e<=127||(this.buf[this.pos++]=127&(e>>>=7)|(e>127?128:0),e<=127||(this.buf[this.pos++]=127&(e>>>=7)|(e>127?128:0),e<=127||(this.buf[this.pos++]=e>>>7&127))))},writeSVarint:function(e){this.writeVarint(e<0?2*-e-1:2*e)},writeBoolean:function(e){this.writeVarint(Boolean(e))},writeString:function(e){e=String(e),this.realloc(4*e.length),this.pos++;var t=this.pos;this.pos=function(e,t,n){for(var r,i,a=0;a<t.length;a++){if((r=t.charCodeAt(a))>55295&&r<57344){if(!i){r>56319||a+1===t.length?(e[n++]=239,e[n++]=191,e[n++]=189):i=r;continue}if(r<56320){e[n++]=239,e[n++]=191,e[n++]=189,i=r;continue}r=i-55296<<10|r-56320|65536,i=null}else i&&(e[n++]=239,e[n++]=191,e[n++]=189,i=null);r<128?e[n++]=r:(r<2048?e[n++]=r>>6|192:(r<65536?e[n++]=r>>12|224:(e[n++]=r>>18|240,e[n++]=r>>12&63|128),e[n++]=r>>6&63|128),e[n++]=63&r|128)}return n}(this.buf,e,this.pos);var n=this.pos-t;n>=128&&l(t,n,this),this.pos=t-1,this.writeVarint(n),this.pos+=n},writeFloat:function(e){this.realloc(4),n.write(this.buf,e,this.pos,!0,23,4),this.pos+=4},writeDouble:function(e){this.realloc(8),n.write(this.buf,e,this.pos,!0,52,8),this.pos+=8},writeBytes:function(e){var t=e.length;this.writeVarint(t),this.realloc(t);for(var n=0;n<t;n++)this.buf[this.pos++]=e[n]},writeRawMessage:function(e,t){this.pos++;var n=this.pos;e(t,this);var r=this.pos-n;r>=128&&l(n,r,this),this.pos=n-1,this.writeVarint(r),this.pos+=r},writeMessage:function(e,t,n){this.writeTag(e,r.Bytes),this.writeRawMessage(t,n)},writePackedVarint:function(e,t){t.length&&this.writeMessage(e,c,t)},writePackedSVarint:function(e,t){t.length&&this.writeMessage(e,u,t)},writePackedBoolean:function(e,t){t.length&&this.writeMessage(e,h,t)},writePackedFloat:function(e,t){t.length&&this.writeMessage(e,f,t)},writePackedDouble:function(e,t){t.length&&this.writeMessage(e,d,t)},writePackedFixed32:function(e,t){t.length&&this.writeMessage(e,p,t)},writePackedSFixed32:function(e,t){t.length&&this.writeMessage(e,m,t)},writePackedFixed64:function(e,t){t.length&&this.writeMessage(e,g,t)},writePackedSFixed64:function(e,t){t.length&&this.writeMessage(e,b,t)},writeBytesField:function(e,t){this.writeTag(e,r.Bytes),this.writeBytes(t)},writeFixed32Field:function(e,t){this.writeTag(e,r.Fixed32),this.writeFixed32(t)},writeSFixed32Field:function(e,t){this.writeTag(e,r.Fixed32),this.writeSFixed32(t)},writeFixed64Field:function(e,t){this.writeTag(e,r.Fixed64),this.writeFixed64(t)},writeSFixed64Field:function(e,t){this.writeTag(e,r.Fixed64),this.writeSFixed64(t)},writeVarintField:function(e,t){this.writeTag(e,r.Varint),this.writeVarint(t)},writeSVarintField:function(e,t){this.writeTag(e,r.Varint),this.writeSVarint(t)},writeStringField:function(e,t){this.writeTag(e,r.Bytes),this.writeString(t)},writeFloatField:function(e,t){this.writeTag(e,r.Fixed32),this.writeFloat(t)},writeDoubleField:function(e,t){this.writeTag(e,r.Fixed64),this.writeDouble(t)},writeBooleanField:function(e,t){this.writeVarintField(e,Boolean(t))}}});function ly(e){let t=0;for(let n,r,i=0,a=e.length-1;i<e.length;a=i++)n=e[i],r=e[a],t+=(r[0]-n[0])*(n[1]+r[1]);return t}function cy(e,t){if(Array.isArray(e[0])){for(const n of e)cy(n,t);return}const n=e;n[0]/=t,n[1]/=t}function uy(e,t){for(let n=0;n<e.length;++n)e[n]/=t}function fy(e,t,n){if("number"!=typeof e[0][0]){for(const r of e)fy(r,t,n);return}const r=n*Math.pow(2,t.z),i=n*t.x,a=n*t.y;for(let s=0;s<e.length;s++){const t=e[s];t[0]=360*(t[0]+i)/r-180;const n=180-360*(t[1]+a)/r;t[1]=360/Math.PI*Math.atan(Math.exp(n*Math.PI/180))-90}}var dy=class{properties;extent;type;id;_pbf;_geometry;_keys;_values;_geometryInfo;static types=["Unknown","Point","LineString","Polygon"];constructor(e,t,n,r,i,a){this.properties={},this.extent=n,this.type=0,this.id=null,this._pbf=e,this._geometry=-1,this._keys=r,this._values=i,this._geometryInfo=a,e.readFields(py,this,t)}toGeoJSONFeature(e,t){const n=this.loadGeometry();return hy(this,n,"wgs84"===e?e=>fy(e,t,this.extent):cy)}toBinaryFeature(e,t){const n=this.loadFlatGeometry();return"wgs84"===e?this._toBinaryCoordinates(n,e=>function(e,t,n){const{x:r,y:i,z:a}=t,s=n*Math.pow(2,a),o=n*r,A=n*i;for(let l=0,c=e.length;l<c;l+=2){e[l]=360*(e[l]+o)/s-180;const t=180-360*(e[l+1]+A)/s;e[l+1]=360/Math.PI*Math.atan(Math.exp(t*Math.PI/180))-90}}(e,t,this.extent)):this._toBinaryCoordinates(n,uy)}bbox(){const e=this._pbf;e.pos=this._geometry;const t=e.readVarint()+e.pos;let n=1,r=0,i=0,a=0,s=1/0,o=-1/0,A=1/0,l=-1/0;for(;e.pos<t;){if(r<=0){const t=e.readVarint();n=7&t,r=t>>3}if(r--,1===n||2===n)i+=e.readSVarint(),a+=e.readSVarint(),i<s&&(s=i),i>o&&(o=i),a<A&&(A=a),a>l&&(l=a);else if(7!==n)throw new Error(`unknown command ${n}`)}return[s,A,o,l]}_toBinaryCoordinates(e,t){let n;t(e.data,this.extent);switch(this.type){case 1:this._geometryInfo.pointFeaturesCount++,this._geometryInfo.pointPositionsCount+=e.indices.length,n={type:"Point",...e};break;case 2:this._geometryInfo.lineFeaturesCount++,this._geometryInfo.linePathsCount+=e.indices.length,this._geometryInfo.linePositionsCount+=e.data.length/2,n={type:"LineString",...e};break;case 3:n=function(e){const t=e.indices.length,n="Polygon";if(t<=1)return{type:n,data:e.data,areas:[[_(e.data)]],indices:[e.indices]};const r=[],i=[];let a,s=[],o=[],A=0;for(let l,c,u=0;u<t;u++){c=e.indices[u]-A,l=e.indices[u+1]-A||e.data.length;const t=e.data.slice(c,l),n=_(t);if(0===n){const t=e.data.slice(0,c),n=e.data.slice(l);e.data=t.concat(n),A+=l-c;continue}void 0===a&&(a=n<0),a===n<0?(o.length&&(r.push(s),i.push(o)),o=[c],s=[n]):(s.push(n),o.push(c))}return s&&r.push(s),o.length&&i.push(o),{type:n,areas:r,indices:i,data:e.data}}(e),this._geometryInfo.polygonFeaturesCount++,this._geometryInfo.polygonObjectsCount+=n.indices.length;for(const e of n.indices)this._geometryInfo.polygonRingsCount+=e.length;this._geometryInfo.polygonPositionsCount+=n.data.length/2;break;default:throw new Error(`Invalid geometry type: ${this.type}`)}const r={type:"Feature",geometry:n,properties:this.properties};return null!==this.id&&(r.id=this.id),r}loadGeometry(){const e=this._pbf;e.pos=this._geometry;const t=e.readVarint()+e.pos;let n=1,r=0,i=0,a=0;const s=[];let o;for(;e.pos<t;){if(r<=0){const t=e.readVarint();n=7&t,r=t>>3}switch(r--,n){case 1:case 2:i+=e.readSVarint(),a+=e.readSVarint(),1===n&&(o&&s.push(o),o=[]),o&&o.push([i,a]);break;case 7:o&&o.push(o[0].slice());break;default:throw new Error(`unknown command ${n}`)}}return o&&s.push(o),s}loadFlatGeometry(){const e=this._pbf;e.pos=this._geometry;const t=e.readVarint()+e.pos;let n,r=1,i=0,a=0,s=0,o=0;const A=[],l=[];for(;e.pos<t;)if(i<=0&&(n=e.readVarint(),r=7&n,i=n>>3),i--,1===r||2===r)a+=e.readSVarint(),s+=e.readSVarint(),1===r&&A.push(o),l.push(a,s),o+=2;else{if(7!==r)throw new Error(`unknown command ${r}`);if(o>0){const e=A[A.length-1];l.push(l[e],l[e+1]),o+=2}}return{data:l,indices:A}}};function hy(e,t,n){let r,i,a,s=dy.types[e.type];switch(e.type){case 1:const s=[];for(r=0;r<t.length;r++)s[r]=t[r][0];a=s,n(a,e.extent);break;case 2:for(a=t,r=0;r<a.length;r++)n(a[r],e.extent);break;case 3:for(a=function(e){const t=e.length;if(t<=1)return[e];const n=[];let r,i;for(let a=0;a<t;a++){const t=ly(e[a]);0!==t&&(void 0===i&&(i=t<0),i===t<0?(r&&n.push(r),r=[e[a]]):r&&r.push(e[a]))}return r&&n.push(r),n}(t),r=0;r<a.length;r++)for(i=0;i<a[r].length;i++)n(a[r][i],e.extent);break;default:throw new Error("illegal vector tile type")}1===a.length?a=a[0]:s=`Multi${s}`;const o={type:"Feature",geometry:{type:s,coordinates:a},properties:e.properties};return null!==e.id&&(o.id=e.id),o}function py(e,t,n){t&&n&&(1===e?t.id=n.readVarint():2===e?function(e,t){const n=e.readVarint()+e.pos;for(;e.pos<n;){const n=t._keys[e.readVarint()],r=t._values[e.readVarint()];t.properties[n]=r}}(n,t):3===e?t.type=n.readVarint():4===e&&(t._geometry=n.pos))}var my=class{version;name;extent;length;_pbf;_keys;_values;_features;constructor(e,t){this.version=1,this.name="",this.extent=4096,this.length=0,this._pbf=e,this._keys=[],this._values=[],this._features=[],e.readFields(gy,this,t),this.length=this._features.length}getGeoJSONFeature(e){if(e<0||e>=this._features.length)throw new Error("feature index out of bounds");this._pbf.pos=this._features[e];const t=this._pbf.readVarint()+this._pbf.pos;return new dy(this._pbf,t,this.extent,this._keys,this._values)}getBinaryFeature(e,t){if(e<0||e>=this._features.length)throw new Error("feature index out of bounds");this._pbf.pos=this._features[e];const n=this._pbf.readVarint()+this._pbf.pos;return new dy(this._pbf,n,this.extent,this._keys,this._values,t)}};function gy(e,t,n){t&&n&&(15===e?t.version=n.readVarint():1===e?t.name=n.readString():5===e?t.extent=n.readVarint():2===e?t._features.push(n.pos):3===e?t._keys.push(n.readString()):4===e&&t._values.push(function(e){let t=null;const n=e.readVarint()+e.pos;for(;e.pos<n;){const n=e.readVarint()>>3;t=1===n?e.readString():2===n?e.readFloat():3===n?e.readDouble():4===n?e.readVarint64():5===n?e.readVarint():6===n?e.readSVarint():7===n?e.readBoolean():null}return t}(n)))}var by=class{layers;constructor(e,t){this.layers=e.readFields(vy,{},t)}};function vy(e,t,n){if(3===e&&n){const e=new my(n,n.readVarint()+n.pos);e.length&&t&&(t[e.name]=e)}}var yy=/* @__PURE__ */e(Ay(),1);function xy(e,t){const n=function(e){if(!e?.mvt)throw new Error("mvt options required");if("wgs84"===e.mvt?.coordinates&&!e.mvt.tileIndex)throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");e.gis&&_e.warn('MVTLoader: "options.gis" is deprecated, use "options.mvt.shape" instead')();return e.mvt}(t),r=t?.gis?.format||t?.mvt?.shape||t?.shape;switch(r){case"columnar-table":return{shape:"columnar-table",data:_y(e,n)};case"geojson-table":return{shape:"geojson-table",type:"FeatureCollection",features:wy(e,n)};case"geojson":return wy(e,n);case"binary-geometry":case"binary":return _y(e,n);default:throw new Error(r||"undefined shape")}}function _y(e,t){const[n,r]=function(e,t){const n=[],r={coordLength:2,pointPositionsCount:0,pointFeaturesCount:0,linePositionsCount:0,linePathsCount:0,lineFeaturesCount:0,polygonPositionsCount:0,polygonObjectsCount:0,polygonRingsCount:0,polygonFeaturesCount:0};if(e.byteLength<=0)return[n,r];const i=new by(new yy.default(e));return(t&&Array.isArray(t.layers)?t.layers:Object.keys(i.layers)).forEach(e=>{const a=i.layers[e];if(a)for(let i=0;i<a.length;i++){const s=Sy(a.getBinaryFeature(i,r),t,e);n.push(s)}}),[n,r]}(e,t),i=Kv(n,r);return i.byteLength=e.byteLength,i}function wy(e,t){if(e.byteLength<=0)return[];const n=[],r=new by(new yy.default(e));return(Array.isArray(t.layers)?t.layers:Object.keys(r.layers)).forEach(e=>{const i=r.layers[e];if(i)for(let r=0;r<i.length;r++){const a=Ty(i.getGeoJSONFeature(r),t,e);n.push(a)}}),n}function Ty(e,t,n){const r=e.toGeoJSONFeature(t.coordinates||"local",t.tileIndex);return t.layerProperty&&(r.properties||={},r.properties[t.layerProperty]=n),r}function Sy(e,t,n){const r=e.toBinaryFeature(t.coordinates||"local",t.tileIndex);return t.layerProperty&&r.properties&&(r.properties[t.layerProperty]=n),r}var My={name:"Mapbox Vector Tile",id:"mvt",module:"mvt",extensions:["mvt","pbf"],mimeTypes:["application/vnd.mapbox-vector-tile","application/x-protobuf"],category:"geometry",dataType:null,batchType:null,version:"4.5.4",worker:!0,options:{mvt:{shape:"geojson",coordinates:"local",layerProperty:"layerName",layers:void 0,tileIndex:void 0}}},Ey={Point:Cy,MultiPoint:function(e,t,n){return Iy(e,t,n)},LineString:Ry,MultiLineString:function(e,t,n){return e.map(e=>Ry(e,t,n))},Polygon:Py,MultiPolygon:function(e,t,n){return e.map(e=>Py(e,t,n))}};function Cy([e,t],[n,r],i){const a=k(n[0],r[0],e),s=k(n[1],r[1],t);return i.unprojectFlat([a,s])}function Iy(e,t,n){return e.map(e=>Cy(e,t,n))}function Ry(e,t,n){return Iy(e,t,n)}function Py(e,t,n){return e.map(e=>Iy(e,t,n))}var Ny=["points","lines","polygons"];function ky(e,t,n,r){const i=e.featureIds.value;if(!i.length)return-1;let a=0,s=i[i.length-1]+1;if(r){const t=function(e,t){if(!e.__layers){const t={},{properties:n}=e;for(let e=0;e<n.length;e++){const{layerName:r}=n[e];r&&(t[r]?t[r][1]=e:t[r]=[e,e])}e.__layers=t}return e.__layers[t]}(e,r);if(!t)return-1;a=t[0],s=t[1]+1}let o=-1;if(t in e.numericProps){const r=e.numericProps[t].value.findIndex((e,t)=>e===n&&i[t]>=a&&i[t]<s);return r>=0?e.globalFeatureIds.value[r]:-1}return t?o=Ly(e.properties,e=>e[t]===n,a,s):e.fields&&(o=Ly(e.fields,e=>e.id===n,a,s)),o>=0?function(e,t){if(!e.__ids){const t=[],n=e.featureIds.value,r=e.globalFeatureIds.value;for(let e=0;e<n.length;e++)t[n[e]]=r[e];e.__ids=t}return e.__ids[t]}(e,o):-1}function Ly(e,t,n,r){for(let i=n;i<r;i++)if(t(e[i],i))return i;return-1}var By={...b.defaultProps,data:rc,onDataLoad:{type:"function",value:null,optional:!0,compare:!1},uniqueIdProperty:"",highlightedFeatureId:null,loaders:[My],binary:!0},Oy=class extends Sc{initializeState(){super.initializeState();const e=void 0===this.context.viewport.resolution&&this.props.binary;this.setState({binary:e,data:null,tileJSON:null,hoveredFeatureId:null,hoveredFeatureLayerName:null})}get isLoaded(){return Boolean(this.state?.data&&super.isLoaded)}updateState({props:e,oldProps:t,context:n,changeFlags:r}){r.dataChanged&&this._updateTileData(),this.state?.data&&(super.updateState({props:e,oldProps:t,context:n,changeFlags:r}),this._setWGS84PropertyForTiles());const{highlightColor:i}=e;i!==t.highlightColor&&Array.isArray(i)&&this.setState({highlightColor:i})}async _updateTileData(){let e=this.props.data,t=null;if("string"!=typeof e||/(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))/.test(e))e&&"object"==typeof e&&"tilejson"in e&&(t=e);else{const{onDataLoad:r,fetch:i}=this.props;this.setState({data:null,tileJSON:null});try{t=await i(e,{propName:"data",layer:this,loaders:[]})}catch(n){this.raiseError(n,"loading TileJSON"),e=null}r&&r(t,{propName:"data",layer:this})}t&&(e=t.tiles),this.setState({data:e,tileJSON:t})}_getTilesetOptions(){const e=super._getTilesetOptions(),t=this.state.tileJSON,{minZoom:n,maxZoom:r}=this.props;return t&&(Number.isFinite(t.minzoom)&&t.minzoom>n&&(e.minZoom=t.minzoom),Number.isFinite(t.maxzoom)&&(!Number.isFinite(r)||t.maxzoom<r)&&(e.maxZoom=t.maxzoom)),e}renderLayers(){return this.state?.data?super.renderLayers():null}getTileData(e){const{data:t,binary:n}=this.state,{index:r,signal:i}=e,a=ac(t,e);if(!a)return Promise.reject("Invalid URL");let s=this.getLoadOptions();const{fetch:o}=this.props;return s={...s,core:{...s?.core,mimeType:"application/x-protobuf"},mvt:{...s?.mvt,shape:n?"binary":"geojson",coordinates:this.context.viewport.resolution?"wgs84":"local",tileIndex:r}},o(a,{propName:"data",layer:this,loadOptions:s,signal:i})}renderSubLayers(e){const{x:t,y:n,z:r}=e.tile.index,i=Math.pow(2,r),a=512/i,s=-a,o=512*t/i,A=512*(1-n/i),l=(new H).scale([a,s,1]);e.autoHighlight=!1,this.context.viewport.resolution||(e.modelMatrix=l,e.coordinateOrigin=[o,A,0],e.coordinateSystem=L.CARTESIAN,e.extensions=[...e.extensions||[],new Gv]);const c=super.renderSubLayers(e);return!this.state.binary||c instanceof b||ge.warn("renderSubLayers() must return GeoJsonLayer when using binary:true")(),c}_updateAutoHighlight(e){const{uniqueIdProperty:t}=this.props,{hoveredFeatureId:n,hoveredFeatureLayerName:r}=this.state,i=e.object;let a=null,s=null;i&&(a=Fy(i,t),s=Dy(i));let{highlightColor:o}=this.props;"function"==typeof o&&(o=o(e)),n===a&&r===s||this.setState({highlightColor:o,hoveredFeatureId:a,hoveredFeatureLayerName:s})}_isWGS84(){return Boolean(this.context.viewport.resolution)}getPickingInfo(e){const t=super.getPickingInfo(e);if(this.state.binary&&-1!==t.index){const{data:n}=e.sourceLayer.props;t.object=ny(n,{globalFeatureId:t.index})}return t.object&&!this._isWGS84()&&(t.object=Vy(t.object,t.tile.bbox,this.context.viewport)),t}getSubLayerPropsByTile(e){return{highlightedObjectIndex:this.getHighlightedObjectIndex(e),highlightColor:this.state.highlightColor}}getHighlightedObjectIndex(e){const{hoveredFeatureId:t,hoveredFeatureLayerName:n,binary:r}=this.state,{uniqueIdProperty:i,highlightedFeatureId:a}=this.props,s=e.content,o=Uy(a);if(!Uy(t)&&!o)return-1;const A=o?a:t;return Array.isArray(s)?s.findIndex(e=>{const t=Fy(e,i)===A,r=o||Dy(e)===n;return t&&r}):s&&r?function(e,t,n,r){for(const i of Ny){const a=e[i]&&ky(e[i],t,n,r);if(a>=0)return a}return-1}(s,i,A,o?"":n):-1}_pickObjects(e){const{deck:t,viewport:n}=this.context,r=n.width,i=n.height,a=n.x,s=n.y,o=[this.id];return t.pickObjects({x:a,y:s,width:r,height:i,layerIds:o,maxObjects:e})}getRenderedFeatures(e=null){const t=this._pickObjects(e),n=/* @__PURE__ */new Set,r=[];for(const i of t){const e=Fy(i.object,this.props.uniqueIdProperty);void 0===e?r.push(i.object):n.has(e)||(n.add(e),r.push(i.object))}return r}_setWGS84PropertyForTiles(){const e="dataInWGS84";this.state.tileset.selectedTiles.forEach(t=>{t.hasOwnProperty(e)||Object.defineProperty(t,e,{get:()=>{if(!t.content)return null;if(this.state.binary&&Array.isArray(t.content)&&!t.content.length)return[];const{bbox:e}=t;return void 0===t._contentWGS84&&function(e){return Number.isFinite(e.west)&&Number.isFinite(e.north)&&Number.isFinite(e.east)&&Number.isFinite(e.south)}(e)&&(t._contentWGS84=(this.state.binary?ny(t.content):t.content).map(t=>Vy(t,e,this.context.viewport))),t._contentWGS84}})})}};function Fy(e,t){return e.properties&&t?e.properties[t]:"id"in e?e.id:void 0}function Dy(e){return e.properties?.layerName||null}function Uy(e){return null!=e&&""!==e}function Vy(e,t,n){const r={...e,geometry:{type:e.geometry.type}};return Object.defineProperty(r.geometry,"coordinates",{get:()=>function(e,t,n){const r=[n.projectFlat([t.west,t.north]),n.projectFlat([t.east,t.south])];return{...e,coordinates:Ey[e.type](e.coordinates,r,n)}}(e.geometry,t,n).coordinates}),r}Oy.layerName="MVTLayer",Oy.defaultProps=By;var jy={};for(let Hy=0;Hy<32;Hy++)jy["0123456789bcdefghjkmnpqrstuvwxyz".charAt(Hy)]=Hy;function zy(e){const[t,n,r,i]=function(e){let t,n=!0,r=90,i=-90,a=180,s=-180,o=0;for(let A=0,l=e.length;A<l;A++){const l=e[A].toLowerCase();o=jy[l];for(let e=4;e>=0;e--){const A=o>>e&1;n?(t=(a+s)/2,1===A?s=t:a=t):(t=(r+i)/2,1===A?i=t:r=t),n=!n}}return[i,s,r,a]}(e);return[i,r,i,t,n,t,n,r,i,r]}var Gy=class extends Yn{indexToBounds(){const{data:e,getGeohash:t}=this.props;return{data:e,_normalize:!1,positionFormat:"XY",getPolygon:(e,n)=>zy(t(e,n))}}};Gy.layerName="GeohashLayer",Gy.defaultProps={getGeohash:{type:"accessor",value:e=>e.geohash}};export{As as A5Layer,Gy as GeohashLayer,FA as GreatCircleLayer,Lc as H3ClusterLayer,kc as H3HexagonLayer,Oy as MVTLayer,XA as QuadkeyLayer,JA as S2Layer,Ov as TerrainLayer,Rv as Tile3DLayer,Sc as TileLayer,Pc as TripsLayer,Yn as _GeoCellLayer,YA as _Tile2DHeader,xc as _Tileset2D,OA as _WMSLayer,ac as _getURLFromTemplate};