@loaders.gl/tiles 5.0.0-alpha.1 → 5.0.0-alpha.2
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.
- package/LICENSE +14 -3
- package/dist/dist.dev.js +2396 -274
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +2763 -337
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/point-cloud/point-cloud-tile.d.ts.map +1 -1
- package/dist/point-cloud/point-cloud-tile.js +3 -0
- package/dist/point-cloud/point-cloud-tile.js.map +1 -1
- package/dist/point-cloud/point-cloud-tileset.d.ts.map +1 -1
- package/dist/point-cloud/point-cloud-tileset.js +3 -0
- package/dist/point-cloud/point-cloud-tileset.js.map +1 -1
- package/dist/point-cloud/types.d.ts.map +1 -1
- package/dist/point-cloud/types.js +3 -0
- package/dist/point-cloud/types.js.map +1 -1
- package/dist/raster-set.d.ts +35 -29
- package/dist/raster-set.d.ts.map +1 -1
- package/dist/raster-set.js +7 -1
- package/dist/raster-set.js.map +1 -1
- package/dist/tileset-3d/common/tile-3d.d.ts +98 -3
- package/dist/tileset-3d/common/tile-3d.d.ts.map +1 -1
- package/dist/tileset-3d/common/tile-3d.js +229 -15
- package/dist/tileset-3d/common/tile-3d.js.map +1 -1
- package/dist/tileset-3d/common/tileset-3d.d.ts +143 -3
- package/dist/tileset-3d/common/tileset-3d.d.ts.map +1 -1
- package/dist/tileset-3d/common/tileset-3d.js +257 -16
- package/dist/tileset-3d/common/tileset-3d.js.map +1 -1
- package/dist/tileset-3d/common/tileset-cache.d.ts +11 -1
- package/dist/tileset-3d/common/tileset-cache.d.ts.map +1 -1
- package/dist/tileset-3d/common/tileset-cache.js +11 -3
- package/dist/tileset-3d/common/tileset-cache.js.map +1 -1
- package/dist/tileset-3d/common/tileset-source.d.ts +18 -0
- package/dist/tileset-3d/common/tileset-source.d.ts.map +1 -1
- package/dist/tileset-3d/common/tileset-source.js.map +1 -1
- package/dist/tileset-3d/common/tileset-traverser.d.ts +13 -0
- package/dist/tileset-3d/common/tileset-traverser.d.ts.map +1 -1
- package/dist/tileset-3d/common/tileset-traverser.js +28 -1
- package/dist/tileset-3d/common/tileset-traverser.js.map +1 -1
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts +111 -0
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.js +340 -0
- package/dist/tileset-3d/format-3d-tiles/implicit-tiling.js.map +1 -0
- package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.d.ts +92 -3
- package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.d.ts.map +1 -1
- package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.js +211 -13
- package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.js.map +1 -1
- package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.d.ts +36 -0
- package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.d.ts.map +1 -1
- package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.js +66 -0
- package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.js.map +1 -1
- package/dist/tileset-3d/format-i3s/i3s-pending-tiles-register.d.ts.map +1 -1
- package/dist/tileset-3d/format-i3s/i3s-pending-tiles-register.js +3 -0
- package/dist/tileset-3d/format-i3s/i3s-pending-tiles-register.js.map +1 -1
- package/dist/tileset-3d/format-i3s/i3s-tile-manager.d.ts.map +1 -1
- package/dist/tileset-3d/format-i3s/i3s-tile-manager.js +3 -0
- package/dist/tileset-3d/format-i3s/i3s-tile-manager.js.map +1 -1
- package/dist/tileset-3d/format-i3s/i3s-tileset-traverser.d.ts.map +1 -1
- package/dist/tileset-3d/format-i3s/i3s-tileset-traverser.js +3 -0
- package/dist/tileset-3d/format-i3s/i3s-tileset-traverser.js.map +1 -1
- package/dist/tileset-3d/helpers/3d-tiles-options.d.ts.map +1 -1
- package/dist/tileset-3d/helpers/3d-tiles-options.js +3 -0
- package/dist/tileset-3d/helpers/3d-tiles-options.js.map +1 -1
- package/dist/tileset-3d/helpers/bounding-volume.d.ts.map +1 -1
- package/dist/tileset-3d/helpers/bounding-volume.js +1 -0
- package/dist/tileset-3d/helpers/bounding-volume.js.map +1 -1
- package/dist/tileset-3d/helpers/frame-state.d.ts +59 -1
- package/dist/tileset-3d/helpers/frame-state.d.ts.map +1 -1
- package/dist/tileset-3d/helpers/frame-state.js +84 -9
- package/dist/tileset-3d/helpers/frame-state.js.map +1 -1
- package/dist/tileset-3d/helpers/tiles-3d-lod.d.ts +61 -9
- package/dist/tileset-3d/helpers/tiles-3d-lod.d.ts.map +1 -1
- package/dist/tileset-3d/helpers/tiles-3d-lod.js +198 -93
- package/dist/tileset-3d/helpers/tiles-3d-lod.js.map +1 -1
- package/dist/tileset-3d/helpers/tiles-3d-request-priority.d.ts +134 -0
- package/dist/tileset-3d/helpers/tiles-3d-request-priority.d.ts.map +1 -0
- package/dist/tileset-3d/helpers/tiles-3d-request-priority.js +179 -0
- package/dist/tileset-3d/helpers/tiles-3d-request-priority.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/doubly-linked-list.d.ts.map +1 -1
- package/dist/utils/doubly-linked-list.js +1 -0
- package/dist/utils/doubly-linked-list.js.map +1 -1
- package/dist/utils/managed-array.d.ts.map +1 -1
- package/dist/utils/managed-array.js +1 -0
- package/dist/utils/managed-array.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +19 -0
- package/src/point-cloud/point-cloud-tile.ts +4 -0
- package/src/point-cloud/point-cloud-tileset.ts +4 -0
- package/src/point-cloud/types.ts +4 -0
- package/src/raster-set.ts +81 -43
- package/src/tileset-3d/common/tile-3d.ts +285 -21
- package/src/tileset-3d/common/tileset-3d.ts +368 -17
- package/src/tileset-3d/common/tileset-cache.ts +15 -7
- package/src/tileset-3d/common/tileset-source.ts +21 -0
- package/src/tileset-3d/common/tileset-traverser.ts +29 -1
- package/src/tileset-3d/format-3d-tiles/implicit-tiling.ts +534 -0
- package/src/tileset-3d/format-3d-tiles/tiles-3d-source.ts +266 -13
- package/src/tileset-3d/format-3d-tiles/tileset-3d-traverser.ts +77 -0
- package/src/tileset-3d/format-i3s/i3s-pending-tiles-register.ts +4 -0
- package/src/tileset-3d/format-i3s/i3s-tile-manager.ts +4 -0
- package/src/tileset-3d/format-i3s/i3s-tileset-traverser.ts +4 -0
- package/src/tileset-3d/helpers/3d-tiles-options.ts +4 -0
- package/src/tileset-3d/helpers/bounding-volume.ts +2 -0
- package/src/tileset-3d/helpers/frame-state.ts +139 -11
- package/src/tileset-3d/helpers/tiles-3d-lod.ts +291 -112
- package/src/tileset-3d/helpers/tiles-3d-request-priority.ts +301 -0
- package/src/types.ts +6 -0
- package/src/utils/doubly-linked-list.ts +2 -0
- package/src/utils/managed-array.ts +2 -0
package/dist/dist.min.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
5
|
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
6
|
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
|
-
"use strict";var __exports__=(()=>{var An=Object.create;var ee=Object.defineProperty;var On=Object.getOwnPropertyDescriptor;var Pn=Object.getOwnPropertyNames;var Nn=Object.getPrototypeOf,Ln=Object.prototype.hasOwnProperty;var In=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),qt=(e,t)=>{for(var s in t)ee(e,s,{get:t[s],enumerable:!0})},te=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Pn(t))!Ln.call(e,n)&&n!==s&&ee(e,n,{get:()=>t[n],enumerable:!(r=On(t,n))||r.enumerable});return e},se=(e,t,s)=>(te(e,t,"default"),s&&te(s,t,"default")),vn=(e,t,s)=>(s=e!=null?An(Nn(e)):{},te(t||!e||!e.__esModule?ee(s,"default",{value:e,enumerable:!0}):s,e)),zn=e=>te(ee({},"__esModule",{value:!0}),e);var Us=In((ka,Ds)=>{Ds.exports=globalThis.loaders});var Kt={};qt(Kt,{I3SSource:()=>ze,ImageSet:()=>It,IndexedArchiveTilesetSource:()=>be,LOD_METRIC_TYPE:()=>Pt,PointCloudTile:()=>zt,PointCloudTileset:()=>De,RasterSet:()=>vt,STRATEGY_DEFAULT:()=>Qt,STRATEGY_NEVER:()=>qs,STRATEGY_REPLACE:()=>Vs,SharedTile2DHeader:()=>Mt,TILESET_TYPE:()=>J,TILE_CONTENT_STATE:()=>W,TILE_REFINEMENT:()=>Z,TILE_TYPE:()=>Ce,Tile3D:()=>tt,Tiles3DSource:()=>Ne,Tileset2D:()=>yt,Tileset3D:()=>we,TilesetCache:()=>Ot,TilesetTraverser:()=>nt,calculateTransformProps:()=>_e,createBoundingVolume:()=>Nt,getFrameState:()=>Ee,getLodStatus:()=>Oe,isTileset3DSource:()=>Re});se(Kt,vn(Us(),1));var qn=1/Math.PI*180,Vn=1/180*Math.PI,Dn={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Dn}};var q=globalThis.mathgl.config;function Fe(e,{precision:t=q.precision}={}){return e=Un(e),`${parseFloat(e.toPrecision(t))}`}function et(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Be(e){return Fs(e)}function ke(e){return $(e)}function Fs(e,t){return Bs(e,s=>s*Vn,t)}function $(e,t){return Bs(e,s=>s*qn,t)}function X(e,t,s){let r=q.EPSILON;s&&(q.EPSILON=s);try{if(e===t)return!0;if(et(e)&&et(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;++n)if(!X(e[n],t[n]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=q.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{q.EPSILON=r}}function Un(e){return Math.round(e/q.EPSILON)*q.EPSILON}function Fn(e){return e.clone?e.clone():new Array(e.length)}function Bs(e,t,s){if(et(e)){let r=e;s=s||Fn(r);for(let n=0;n<s.length&&n<r.length;++n){let i=typeof e=="number"?e:e[n];s[n]=t(i,n,s)}return s}return t(e)}var ht=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,s=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=t[r+s];return this.check()}toArray(t=[],s=0){for(let r=0;r<this.ELEMENTS;++r)t[s+r]=this[r];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:et(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(q)}formatString(t){let s="";for(let r=0;r<this.ELEMENTS;++r)s+=(r>0?", ":"")+Fe(this[r],t);return`${t.printTypes?this.constructor.name:""}[${s}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let s=0;s<this.ELEMENTS;++s)if(!X(this[s],t[s]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let s=0;s<this.ELEMENTS;++s)if(this[s]!==t[s])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,s,r){if(r===void 0)return this.lerp(this,t,s);for(let n=0;n<this.ELEMENTS;++n){let i=t[n],o=typeof s=="number"?s:s[n];this[n]=i+r*(o-i)}return this.check()}min(t){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(t[s],this[s]);return this.check()}max(t){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.max(t[s],this[s]);return this.check()}clamp(t,s){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t[r]),s[r]);return this.check()}add(...t){for(let s of t)for(let r=0;r<this.ELEMENTS;++r)this[r]+=s[r];return this.check()}subtract(...t){for(let s of t)for(let r=0;r<this.ELEMENTS;++r)this[r]-=s[r];return this.check()}scale(t){if(typeof t=="number")for(let s=0;s<this.ELEMENTS;++s)this[s]*=t;else for(let s=0;s<this.ELEMENTS&&s<t.length;++s)this[s]*=t[s];return this.check()}multiplyByScalar(t){for(let s=0;s<this.ELEMENTS;++s)this[s]*=t;return this.check()}check(){if(q.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let s=0;s<this.ELEMENTS;++s)t=t&&Number.isFinite(this[s]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let s=0;s<this.ELEMENTS;++s)this[s]=t;return this.check()}addScalar(t){for(let s=0;s<this.ELEMENTS;++s)this[s]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let s=0;s<this.ELEMENTS;++s)this[s]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,s){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t),s);return this.check()}get elements(){return this}};function Bn(e,t){if(e.length!==t)return!1;for(let s=0;s<e.length;++s)if(!Number.isFinite(e[s]))return!1;return!0}function N(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function lt(e,t,s=""){if(q.debug&&!Bn(e,t))throw new Error(`math.gl: ${s} some fields set to invalid numbers'`);return e}function F(e,t){if(!e)throw new Error(`math.gl assertion ${t}`)}var St=class extends ht{get x(){return this[0]}set x(t){this[0]=N(t)}get y(){return this[1]}set y(t){this[1]=N(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let s=0;s<this.ELEMENTS;++s)t+=this[s]*this[s];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let s=0;for(let r=0;r<this.ELEMENTS;++r){let n=this[r]-t[r];s+=n*n}return N(s)}dot(t){let s=0;for(let r=0;r<this.ELEMENTS;++r)s+=this[r]*t[r];return N(s)}normalize(){let t=this.magnitude();if(t!==0)for(let s=0;s<this.ELEMENTS;++s)this[s]/=t;return this.check()}multiply(...t){for(let s of t)for(let r=0;r<this.ELEMENTS;++r)this[r]*=s[r];return this.check()}divide(...t){for(let s of t)for(let r=0;r<this.ELEMENTS;++r)this[r]/=s[r];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return F(t>=0&&t<this.ELEMENTS,"index is out of range"),N(this[t])}setComponent(t,s){return F(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=s,this.check()}addVectors(t,s){return this.copy(t).add(s)}subVectors(t,s){return this.copy(t).subtract(s)}multiplyVectors(t,s){return this.copy(t).multiply(s)}addScaledVector(t,s){return this.add(new this.constructor(t).multiplyScalar(s))}};var V=typeof Float32Array<"u"?Float32Array:Array,Vt=Math.random;function Et(e){return e>=0?Math.round(e):e%.5===0?Math.floor(e):Math.round(e)}var Ja=Math.PI/180;function kn(){let e=new V(2);return V!=Float32Array&&(e[0]=0,e[1]=0),e}function ks(e,t,s){let r=t[0],n=t[1];return e[0]=s[0]*r+s[3]*n+s[6],e[1]=s[1]*r+s[4]*n+s[7],e}function Ws(e,t,s){let r=t[0],n=t[1];return e[0]=s[0]*r+s[4]*n+s[12],e[1]=s[1]*r+s[5]*n+s[13],e}var tc=function(){let e=kn();return function(t,s,r,n,i,o){let a,c;for(s||(s=2),r||(r=0),n?c=Math.min(n*s+r,t.length):c=t.length,a=r;a<c;a+=s)e[0]=t[a],e[1]=t[a+1],i(e,e,o),t[a]=e[0],t[a+1]=e[1];return t}}();function Ys(e,t,s){let r=t[0],n=t[1],i=s[3]*r+s[7]*n||1;return e[0]=(s[0]*r+s[4]*n)/i,e[1]=(s[1]*r+s[5]*n)/i,e}function re(e,t,s){let r=t[0],n=t[1],i=t[2],o=s[3]*r+s[7]*n+s[11]*i||1;return e[0]=(s[0]*r+s[4]*n+s[8]*i)/o,e[1]=(s[1]*r+s[5]*n+s[9]*i)/o,e[2]=(s[2]*r+s[6]*n+s[10]*i)/o,e}function Gs(e,t,s){let r=t[0],n=t[1];return e[0]=s[0]*r+s[2]*n,e[1]=s[1]*r+s[3]*n,e[2]=t[2],e}function Zs(e,t,s){let r=t[0],n=t[1];return e[0]=s[0]*r+s[2]*n,e[1]=s[1]*r+s[3]*n,e[2]=t[2],e[3]=t[3],e}function ne(e,t,s){let r=t[0],n=t[1],i=t[2];return e[0]=s[0]*r+s[3]*n+s[6]*i,e[1]=s[1]*r+s[4]*n+s[7]*i,e[2]=s[2]*r+s[5]*n+s[8]*i,e[3]=t[3],e}var gt={};qt(gt,{add:()=>Zn,angle:()=>je,bezier:()=>ii,ceil:()=>jn,clone:()=>Wn,copy:()=>Yn,create:()=>ie,cross:()=>pt,dist:()=>fi,distance:()=>Hs,div:()=>mi,divide:()=>Qs,dot:()=>Dt,equals:()=>li,exactEquals:()=>hi,floor:()=>$n,forEach:()=>gi,fromValues:()=>oe,hermite:()=>ni,inverse:()=>ei,len:()=>$e,length:()=>js,lerp:()=>si,max:()=>Qn,min:()=>Xn,mul:()=>ui,multiply:()=>Xs,negate:()=>ti,normalize:()=>We,random:()=>oi,rotateX:()=>Ye,rotateY:()=>Ge,rotateZ:()=>Ze,round:()=>Hn,scale:()=>Kn,scaleAndAdd:()=>Jn,set:()=>Gn,slerp:()=>ri,sqrDist:()=>pi,sqrLen:()=>xi,squaredDistance:()=>Ks,squaredLength:()=>Js,str:()=>ci,sub:()=>di,subtract:()=>$s,transformMat3:()=>Ut,transformMat4:()=>xt,transformQuat:()=>Ft,zero:()=>ai});function ie(){let e=new V(3);return V!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Wn(e){let t=new V(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function js(e){let t=e[0],s=e[1],r=e[2];return Math.sqrt(t*t+s*s+r*r)}function oe(e,t,s){let r=new V(3);return r[0]=e,r[1]=t,r[2]=s,r}function Yn(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Gn(e,t,s,r){return e[0]=t,e[1]=s,e[2]=r,e}function Zn(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e}function $s(e,t,s){return e[0]=t[0]-s[0],e[1]=t[1]-s[1],e[2]=t[2]-s[2],e}function Xs(e,t,s){return e[0]=t[0]*s[0],e[1]=t[1]*s[1],e[2]=t[2]*s[2],e}function Qs(e,t,s){return e[0]=t[0]/s[0],e[1]=t[1]/s[1],e[2]=t[2]/s[2],e}function jn(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e}function $n(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e}function Xn(e,t,s){return e[0]=Math.min(t[0],s[0]),e[1]=Math.min(t[1],s[1]),e[2]=Math.min(t[2],s[2]),e}function Qn(e,t,s){return e[0]=Math.max(t[0],s[0]),e[1]=Math.max(t[1],s[1]),e[2]=Math.max(t[2],s[2]),e}function Hn(e,t){return e[0]=Et(t[0]),e[1]=Et(t[1]),e[2]=Et(t[2]),e}function Kn(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}function Jn(e,t,s,r){return e[0]=t[0]+s[0]*r,e[1]=t[1]+s[1]*r,e[2]=t[2]+s[2]*r,e}function Hs(e,t){let s=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return Math.sqrt(s*s+r*r+n*n)}function Ks(e,t){let s=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return s*s+r*r+n*n}function Js(e){let t=e[0],s=e[1],r=e[2];return t*t+s*s+r*r}function ti(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e}function ei(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e}function We(e,t){let s=t[0],r=t[1],n=t[2],i=s*s+r*r+n*n;return i>0&&(i=1/Math.sqrt(i)),e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e}function Dt(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function pt(e,t,s){let r=t[0],n=t[1],i=t[2],o=s[0],a=s[1],c=s[2];return e[0]=n*c-i*a,e[1]=i*o-r*c,e[2]=r*a-n*o,e}function si(e,t,s,r){let n=t[0],i=t[1],o=t[2];return e[0]=n+r*(s[0]-n),e[1]=i+r*(s[1]-i),e[2]=o+r*(s[2]-o),e}function ri(e,t,s,r){let n=Math.acos(Math.min(Math.max(Dt(t,s),-1),1)),i=Math.sin(n),o=Math.sin((1-r)*n)/i,a=Math.sin(r*n)/i;return e[0]=o*t[0]+a*s[0],e[1]=o*t[1]+a*s[1],e[2]=o*t[2]+a*s[2],e}function ni(e,t,s,r,n,i){let o=i*i,a=o*(2*i-3)+1,c=o*(i-2)+i,h=o*(i-1),l=o*(3-2*i);return e[0]=t[0]*a+s[0]*c+r[0]*h+n[0]*l,e[1]=t[1]*a+s[1]*c+r[1]*h+n[1]*l,e[2]=t[2]*a+s[2]*c+r[2]*h+n[2]*l,e}function ii(e,t,s,r,n,i){let o=1-i,a=o*o,c=i*i,h=a*o,l=3*i*a,d=3*c*o,u=c*i;return e[0]=t[0]*h+s[0]*l+r[0]*d+n[0]*u,e[1]=t[1]*h+s[1]*l+r[1]*d+n[1]*u,e[2]=t[2]*h+s[2]*l+r[2]*d+n[2]*u,e}function oi(e,t){t=t===void 0?1:t;let s=Vt()*2*Math.PI,r=Vt()*2-1,n=Math.sqrt(1-r*r)*t;return e[0]=Math.cos(s)*n,e[1]=Math.sin(s)*n,e[2]=r*t,e}function xt(e,t,s){let r=t[0],n=t[1],i=t[2],o=s[3]*r+s[7]*n+s[11]*i+s[15];return o=o||1,e[0]=(s[0]*r+s[4]*n+s[8]*i+s[12])/o,e[1]=(s[1]*r+s[5]*n+s[9]*i+s[13])/o,e[2]=(s[2]*r+s[6]*n+s[10]*i+s[14])/o,e}function Ut(e,t,s){let r=t[0],n=t[1],i=t[2];return e[0]=r*s[0]+n*s[3]+i*s[6],e[1]=r*s[1]+n*s[4]+i*s[7],e[2]=r*s[2]+n*s[5]+i*s[8],e}function Ft(e,t,s){let r=s[0],n=s[1],i=s[2],o=s[3],a=t[0],c=t[1],h=t[2],l=n*h-i*c,d=i*a-r*h,u=r*c-n*a,m=n*u-i*d,x=i*l-r*u,g=r*d-n*l,p=o*2;return l*=p,d*=p,u*=p,m*=2,x*=2,g*=2,e[0]=a+l+m,e[1]=c+d+x,e[2]=h+u+g,e}function Ye(e,t,s,r){let n=[],i=[];return n[0]=t[0]-s[0],n[1]=t[1]-s[1],n[2]=t[2]-s[2],i[0]=n[0],i[1]=n[1]*Math.cos(r)-n[2]*Math.sin(r),i[2]=n[1]*Math.sin(r)+n[2]*Math.cos(r),e[0]=i[0]+s[0],e[1]=i[1]+s[1],e[2]=i[2]+s[2],e}function Ge(e,t,s,r){let n=[],i=[];return n[0]=t[0]-s[0],n[1]=t[1]-s[1],n[2]=t[2]-s[2],i[0]=n[2]*Math.sin(r)+n[0]*Math.cos(r),i[1]=n[1],i[2]=n[2]*Math.cos(r)-n[0]*Math.sin(r),e[0]=i[0]+s[0],e[1]=i[1]+s[1],e[2]=i[2]+s[2],e}function Ze(e,t,s,r){let n=[],i=[];return n[0]=t[0]-s[0],n[1]=t[1]-s[1],n[2]=t[2]-s[2],i[0]=n[0]*Math.cos(r)-n[1]*Math.sin(r),i[1]=n[0]*Math.sin(r)+n[1]*Math.cos(r),i[2]=n[2],e[0]=i[0]+s[0],e[1]=i[1]+s[1],e[2]=i[2]+s[2],e}function je(e,t){let s=e[0],r=e[1],n=e[2],i=t[0],o=t[1],a=t[2],c=Math.sqrt((s*s+r*r+n*n)*(i*i+o*o+a*a)),h=c&&Dt(e,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}function ai(e){return e[0]=0,e[1]=0,e[2]=0,e}function ci(e){return`vec3(${e[0]}, ${e[1]}, ${e[2]})`}function hi(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function li(e,t){let s=e[0],r=e[1],n=e[2],i=t[0],o=t[1],a=t[2];return Math.abs(s-i)<=1e-6*Math.max(1,Math.abs(s),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-a)<=1e-6*Math.max(1,Math.abs(n),Math.abs(a))}var di=$s,ui=Xs,mi=Qs,fi=Hs,pi=Ks,$e=js,xi=Js,gi=function(){let e=ie();return function(t,s,r,n,i,o){let a,c;for(s||(s=3),r||(r=0),n?c=Math.min(n*s+r,t.length):c=t.length,a=r;a<c;a+=s)e[0]=t[a],e[1]=t[a+1],e[2]=t[a+2],i(e,e,o),t[a]=e[0],t[a+1]=e[1],t[a+2]=e[2];return t}}();var Xe=[0,0,0],ae,f=class extends St{static get ZERO(){return ae||(ae=new f(0,0,0),Object.freeze(ae)),ae}constructor(t=0,s=0,r=0){super(-0,-0,-0),arguments.length===1&&et(t)?this.copy(t):(q.debug&&(N(t),N(s),N(r)),this[0]=t,this[1]=s,this[2]=r)}set(t,s,r){return this[0]=t,this[1]=s,this[2]=r,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return q.debug&&(N(t.x),N(t.y),N(t.z)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this.check()}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t}get ELEMENTS(){return 3}get z(){return this[2]}set z(t){this[2]=N(t)}angle(t){return je(this,t)}cross(t){return pt(this,this,t),this.check()}rotateX({radians:t,origin:s=Xe}){return Ye(this,this,s,t),this.check()}rotateY({radians:t,origin:s=Xe}){return Ge(this,this,s,t),this.check()}rotateZ({radians:t,origin:s=Xe}){return Ze(this,this,s,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return xt(this,this,t),this.check()}transformAsVector(t){return re(this,this,t),this.check()}transformByMatrix3(t){return Ut(this,this,t),this.check()}transformByMatrix2(t){return Gs(this,this,t),this.check()}transformByQuaternion(t){return Ft(this,this,t),this.check()}};var ce,wt=class extends St{static get ZERO(){return ce||(ce=new wt(0,0,0,0),Object.freeze(ce)),ce}constructor(t=0,s=0,r=0,n=0){super(-0,-0,-0,-0),et(t)&&arguments.length===1?this.copy(t):(q.debug&&(N(t),N(s),N(r),N(n)),this[0]=t,this[1]=s,this[2]=r,this[3]=n)}set(t,s,r,n){return this[0]=t,this[1]=s,this[2]=r,this[3]=n,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}fromObject(t){return q.debug&&(N(t.x),N(t.y),N(t.z),N(t.w)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t.w=this[3],t}get ELEMENTS(){return 4}get z(){return this[2]}set z(t){this[2]=N(t)}get w(){return this[3]}set w(t){this[3]=N(t)}transform(t){return xt(this,this,t),this.check()}transformByMatrix3(t){return ne(this,this,t),this.check()}transformByMatrix2(t){return Zs(this,this,t),this.check()}transformByQuaternion(t){return Ft(this,this,t),this.check()}applyMatrix4(t){return t.transform(this,this),this}};var bt=class extends ht{toString(){let t="[";if(q.printRowMajor){t+="row-major:";for(let s=0;s<this.RANK;++s)for(let r=0;r<this.RANK;++r)t+=` ${this[r*this.RANK+s]}`}else{t+="column-major:";for(let s=0;s<this.ELEMENTS;++s)t+=` ${this[s]}`}return t+="]",t}getElementIndex(t,s){return s*this.RANK+t}getElement(t,s){return this[s*this.RANK+t]}setElement(t,s,r){return this[s*this.RANK+t]=N(r),this}getColumn(t,s=new Array(this.RANK).fill(-0)){let r=t*this.RANK;for(let n=0;n<this.RANK;++n)s[n]=this[r+n];return s}setColumn(t,s){let r=t*this.RANK;for(let n=0;n<this.RANK;++n)this[r+n]=s[n];return this}};function tr(){let e=new V(9);return V!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[5]=0,e[6]=0,e[7]=0),e[0]=1,e[4]=1,e[8]=1,e}function er(e,t){if(e===t){let s=t[1],r=t[2],n=t[5];e[1]=t[3],e[2]=t[6],e[3]=s,e[5]=t[7],e[6]=r,e[7]=n}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8];return e}function sr(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],d=l*o-a*h,u=-l*i+a*c,m=h*i-o*c,x=s*d+r*u+n*m;return x?(x=1/x,e[0]=d*x,e[1]=(-l*r+n*h)*x,e[2]=(a*r-n*o)*x,e[3]=u*x,e[4]=(l*s-n*c)*x,e[5]=(-a*s+n*i)*x,e[6]=m*x,e[7]=(-h*s+r*c)*x,e[8]=(o*s-r*i)*x,e):null}function rr(e){let t=e[0],s=e[1],r=e[2],n=e[3],i=e[4],o=e[5],a=e[6],c=e[7],h=e[8];return t*(h*i-o*c)+s*(-h*n+o*a)+r*(c*n-i*a)}function Qe(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],d=t[8],u=s[0],m=s[1],x=s[2],g=s[3],p=s[4],_=s[5],E=s[6],M=s[7],T=s[8];return e[0]=u*r+m*o+x*h,e[1]=u*n+m*a+x*l,e[2]=u*i+m*c+x*d,e[3]=g*r+p*o+_*h,e[4]=g*n+p*a+_*l,e[5]=g*i+p*c+_*d,e[6]=E*r+M*o+T*h,e[7]=E*n+M*a+T*l,e[8]=E*i+M*c+T*d,e}function nr(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],d=t[8],u=s[0],m=s[1];return e[0]=r,e[1]=n,e[2]=i,e[3]=o,e[4]=a,e[5]=c,e[6]=u*r+m*o+h,e[7]=u*n+m*a+l,e[8]=u*i+m*c+d,e}function ir(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],d=t[8],u=Math.sin(s),m=Math.cos(s);return e[0]=m*r+u*o,e[1]=m*n+u*a,e[2]=m*i+u*c,e[3]=m*o-u*r,e[4]=m*a-u*n,e[5]=m*c-u*i,e[6]=h,e[7]=l,e[8]=d,e}function He(e,t,s){let r=s[0],n=s[1];return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=n*t[3],e[4]=n*t[4],e[5]=n*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function or(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=s+s,a=r+r,c=n+n,h=s*o,l=r*o,d=r*a,u=n*o,m=n*a,x=n*c,g=i*o,p=i*a,_=i*c;return e[0]=1-d-x,e[3]=l-_,e[6]=u+p,e[1]=l+_,e[4]=1-h-x,e[7]=m-g,e[2]=u-p,e[5]=m+g,e[8]=1-h-d,e}var Ke;(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"})(Ke||(Ke={}));var Ti=Object.freeze([1,0,0,0,1,0,0,0,1]),D=class extends bt{static get IDENTITY(){return yi()}static get ZERO(){return Mi()}get ELEMENTS(){return 9}get RANK(){return 3}get INDICES(){return Ke}constructor(t,...s){super(-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):s.length>0?this.copy([t,...s]):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this.check()}identity(){return this.copy(Ti)}fromObject(t){return this.check()}fromQuaternion(t){return or(this,t),this.check()}set(t,s,r,n,i,o,a,c,h){return this[0]=t,this[1]=s,this[2]=r,this[3]=n,this[4]=i,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this.check()}setRowMajor(t,s,r,n,i,o,a,c,h){return this[0]=t,this[1]=n,this[2]=a,this[3]=s,this[4]=i,this[5]=c,this[6]=r,this[7]=o,this[8]=h,this.check()}determinant(){return rr(this)}transpose(){return er(this,this),this.check()}invert(){return sr(this,this),this.check()}multiplyLeft(t){return Qe(this,t,this),this.check()}multiplyRight(t){return Qe(this,this,t),this.check()}rotate(t){return ir(this,this,t),this.check()}scale(t){return Array.isArray(t)?He(this,this,t):He(this,this,[t,t]),this.check()}translate(t){return nr(this,this,t),this.check()}transform(t,s){let r;switch(t.length){case 2:r=ks(s||[-0,-0],t,this);break;case 3:r=Ut(s||[-0,-0,-0],t,this);break;case 4:r=ne(s||[-0,-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return lt(r,t.length),r}transformVector(t,s){return this.transform(t,s)}transformVector2(t,s){return this.transform(t,s)}transformVector3(t,s){return this.transform(t,s)}},he,le=null;function Mi(){return he||(he=new D([0,0,0,0,0,0,0,0,0]),Object.freeze(he)),he}function yi(){return le||(le=new D,Object.freeze(le)),le}var kt={};qt(kt,{add:()=>Zi,adjoint:()=>Ci,clone:()=>Ei,copy:()=>Ri,create:()=>Si,decompose:()=>Vi,determinant:()=>es,equals:()=>Qi,exactEquals:()=>Xi,frob:()=>Gi,fromQuat:()=>cs,fromQuat2:()=>vi,fromRotation:()=>Pi,fromRotationTranslation:()=>cr,fromRotationTranslationScale:()=>Di,fromRotationTranslationScaleOrigin:()=>Ui,fromScaling:()=>Oi,fromTranslation:()=>Ai,fromValues:()=>wi,fromXRotation:()=>Ni,fromYRotation:()=>Li,fromZRotation:()=>Ii,frustum:()=>hs,getRotation:()=>qi,getScaling:()=>hr,getTranslation:()=>zi,identity:()=>ar,invert:()=>ts,lookAt:()=>us,mul:()=>Hi,multiply:()=>Bt,multiplyScalar:()=>ji,multiplyScalarAndAdd:()=>$i,ortho:()=>ds,orthoNO:()=>dr,orthoZO:()=>ki,perspective:()=>ls,perspectiveFromFieldOfView:()=>Bi,perspectiveNO:()=>lr,perspectiveZO:()=>Fi,rotate:()=>ns,rotateX:()=>is,rotateY:()=>os,rotateZ:()=>as,scale:()=>rs,set:()=>bi,str:()=>Yi,sub:()=>Ki,subtract:()=>ur,targetTo:()=>Wi,translate:()=>ss,transpose:()=>Je});function Si(){let e=new V(16);return V!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Ei(e){let t=new V(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Ri(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function wi(e,t,s,r,n,i,o,a,c,h,l,d,u,m,x,g){let p=new V(16);return p[0]=e,p[1]=t,p[2]=s,p[3]=r,p[4]=n,p[5]=i,p[6]=o,p[7]=a,p[8]=c,p[9]=h,p[10]=l,p[11]=d,p[12]=u,p[13]=m,p[14]=x,p[15]=g,p}function bi(e,t,s,r,n,i,o,a,c,h,l,d,u,m,x,g,p){return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e[4]=i,e[5]=o,e[6]=a,e[7]=c,e[8]=h,e[9]=l,e[10]=d,e[11]=u,e[12]=m,e[13]=x,e[14]=g,e[15]=p,e}function ar(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Je(e,t){if(e===t){let s=t[1],r=t[2],n=t[3],i=t[6],o=t[7],a=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=s,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=i,e[11]=t[14],e[12]=n,e[13]=o,e[14]=a}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function ts(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],d=t[9],u=t[10],m=t[11],x=t[12],g=t[13],p=t[14],_=t[15],E=s*a-r*o,M=s*c-n*o,T=s*h-i*o,S=r*c-n*a,y=r*h-i*a,O=n*h-i*c,w=l*g-d*x,C=l*p-u*x,R=l*_-m*x,I=d*p-u*g,v=d*_-m*g,z=u*_-m*p,A=E*z-M*v+T*I+S*R-y*C+O*w;return A?(A=1/A,e[0]=(a*z-c*v+h*I)*A,e[1]=(n*v-r*z-i*I)*A,e[2]=(g*O-p*y+_*S)*A,e[3]=(u*y-d*O-m*S)*A,e[4]=(c*R-o*z-h*C)*A,e[5]=(s*z-n*R+i*C)*A,e[6]=(p*T-x*O-_*M)*A,e[7]=(l*O-u*T+m*M)*A,e[8]=(o*v-a*R+h*w)*A,e[9]=(r*R-s*v-i*w)*A,e[10]=(x*y-g*T+_*E)*A,e[11]=(d*T-l*y-m*E)*A,e[12]=(a*C-o*I-c*w)*A,e[13]=(s*I-r*C+n*w)*A,e[14]=(g*M-x*S-p*E)*A,e[15]=(l*S-d*M+u*E)*A,e):null}function Ci(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],d=t[9],u=t[10],m=t[11],x=t[12],g=t[13],p=t[14],_=t[15],E=s*a-r*o,M=s*c-n*o,T=s*h-i*o,S=r*c-n*a,y=r*h-i*a,O=n*h-i*c,w=l*g-d*x,C=l*p-u*x,R=l*_-m*x,I=d*p-u*g,v=d*_-m*g,z=u*_-m*p;return e[0]=a*z-c*v+h*I,e[1]=n*v-r*z-i*I,e[2]=g*O-p*y+_*S,e[3]=u*y-d*O-m*S,e[4]=c*R-o*z-h*C,e[5]=s*z-n*R+i*C,e[6]=p*T-x*O-_*M,e[7]=l*O-u*T+m*M,e[8]=o*v-a*R+h*w,e[9]=r*R-s*v-i*w,e[10]=x*y-g*T+_*E,e[11]=d*T-l*y-m*E,e[12]=a*C-o*I-c*w,e[13]=s*I-r*C+n*w,e[14]=g*M-x*S-p*E,e[15]=l*S-d*M+u*E,e}function es(e){let t=e[0],s=e[1],r=e[2],n=e[3],i=e[4],o=e[5],a=e[6],c=e[7],h=e[8],l=e[9],d=e[10],u=e[11],m=e[12],x=e[13],g=e[14],p=e[15],_=t*o-s*i,E=t*a-r*i,M=s*a-r*o,T=h*x-l*m,S=h*g-d*m,y=l*g-d*x,O=t*y-s*S+r*T,w=i*y-o*S+a*T,C=h*M-l*E+d*_,R=m*M-x*E+g*_;return c*O-n*w+p*C-u*R}function Bt(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],d=t[8],u=t[9],m=t[10],x=t[11],g=t[12],p=t[13],_=t[14],E=t[15],M=s[0],T=s[1],S=s[2],y=s[3];return e[0]=M*r+T*a+S*d+y*g,e[1]=M*n+T*c+S*u+y*p,e[2]=M*i+T*h+S*m+y*_,e[3]=M*o+T*l+S*x+y*E,M=s[4],T=s[5],S=s[6],y=s[7],e[4]=M*r+T*a+S*d+y*g,e[5]=M*n+T*c+S*u+y*p,e[6]=M*i+T*h+S*m+y*_,e[7]=M*o+T*l+S*x+y*E,M=s[8],T=s[9],S=s[10],y=s[11],e[8]=M*r+T*a+S*d+y*g,e[9]=M*n+T*c+S*u+y*p,e[10]=M*i+T*h+S*m+y*_,e[11]=M*o+T*l+S*x+y*E,M=s[12],T=s[13],S=s[14],y=s[15],e[12]=M*r+T*a+S*d+y*g,e[13]=M*n+T*c+S*u+y*p,e[14]=M*i+T*h+S*m+y*_,e[15]=M*o+T*l+S*x+y*E,e}function ss(e,t,s){let r=s[0],n=s[1],i=s[2],o,a,c,h,l,d,u,m,x,g,p,_;return t===e?(e[12]=t[0]*r+t[4]*n+t[8]*i+t[12],e[13]=t[1]*r+t[5]*n+t[9]*i+t[13],e[14]=t[2]*r+t[6]*n+t[10]*i+t[14],e[15]=t[3]*r+t[7]*n+t[11]*i+t[15]):(o=t[0],a=t[1],c=t[2],h=t[3],l=t[4],d=t[5],u=t[6],m=t[7],x=t[8],g=t[9],p=t[10],_=t[11],e[0]=o,e[1]=a,e[2]=c,e[3]=h,e[4]=l,e[5]=d,e[6]=u,e[7]=m,e[8]=x,e[9]=g,e[10]=p,e[11]=_,e[12]=o*r+l*n+x*i+t[12],e[13]=a*r+d*n+g*i+t[13],e[14]=c*r+u*n+p*i+t[14],e[15]=h*r+m*n+_*i+t[15]),e}function rs(e,t,s){let r=s[0],n=s[1],i=s[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function ns(e,t,s,r){let n=r[0],i=r[1],o=r[2],a=Math.sqrt(n*n+i*i+o*o),c,h,l,d,u,m,x,g,p,_,E,M,T,S,y,O,w,C,R,I,v,z,A,j;return a<1e-6?null:(a=1/a,n*=a,i*=a,o*=a,h=Math.sin(s),c=Math.cos(s),l=1-c,d=t[0],u=t[1],m=t[2],x=t[3],g=t[4],p=t[5],_=t[6],E=t[7],M=t[8],T=t[9],S=t[10],y=t[11],O=n*n*l+c,w=i*n*l+o*h,C=o*n*l-i*h,R=n*i*l-o*h,I=i*i*l+c,v=o*i*l+n*h,z=n*o*l+i*h,A=i*o*l-n*h,j=o*o*l+c,e[0]=d*O+g*w+M*C,e[1]=u*O+p*w+T*C,e[2]=m*O+_*w+S*C,e[3]=x*O+E*w+y*C,e[4]=d*R+g*I+M*v,e[5]=u*R+p*I+T*v,e[6]=m*R+_*I+S*v,e[7]=x*R+E*I+y*v,e[8]=d*z+g*A+M*j,e[9]=u*z+p*A+T*j,e[10]=m*z+_*A+S*j,e[11]=x*z+E*A+y*j,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function is(e,t,s){let r=Math.sin(s),n=Math.cos(s),i=t[4],o=t[5],a=t[6],c=t[7],h=t[8],l=t[9],d=t[10],u=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*n+h*r,e[5]=o*n+l*r,e[6]=a*n+d*r,e[7]=c*n+u*r,e[8]=h*n-i*r,e[9]=l*n-o*r,e[10]=d*n-a*r,e[11]=u*n-c*r,e}function os(e,t,s){let r=Math.sin(s),n=Math.cos(s),i=t[0],o=t[1],a=t[2],c=t[3],h=t[8],l=t[9],d=t[10],u=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*n-h*r,e[1]=o*n-l*r,e[2]=a*n-d*r,e[3]=c*n-u*r,e[8]=i*r+h*n,e[9]=o*r+l*n,e[10]=a*r+d*n,e[11]=c*r+u*n,e}function as(e,t,s){let r=Math.sin(s),n=Math.cos(s),i=t[0],o=t[1],a=t[2],c=t[3],h=t[4],l=t[5],d=t[6],u=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*n+h*r,e[1]=o*n+l*r,e[2]=a*n+d*r,e[3]=c*n+u*r,e[4]=h*n-i*r,e[5]=l*n-o*r,e[6]=d*n-a*r,e[7]=u*n-c*r,e}function Ai(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function Oi(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Pi(e,t,s){let r=s[0],n=s[1],i=s[2],o=Math.sqrt(r*r+n*n+i*i),a,c,h;return o<1e-6?null:(o=1/o,r*=o,n*=o,i*=o,c=Math.sin(t),a=Math.cos(t),h=1-a,e[0]=r*r*h+a,e[1]=n*r*h+i*c,e[2]=i*r*h-n*c,e[3]=0,e[4]=r*n*h-i*c,e[5]=n*n*h+a,e[6]=i*n*h+r*c,e[7]=0,e[8]=r*i*h+n*c,e[9]=n*i*h-r*c,e[10]=i*i*h+a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)}function Ni(e,t){let s=Math.sin(t),r=Math.cos(t);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=r,e[6]=s,e[7]=0,e[8]=0,e[9]=-s,e[10]=r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Li(e,t){let s=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=0,e[2]=-s,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=s,e[9]=0,e[10]=r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Ii(e,t){let s=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=s,e[2]=0,e[3]=0,e[4]=-s,e[5]=r,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function cr(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=r+r,c=n+n,h=i+i,l=r*a,d=r*c,u=r*h,m=n*c,x=n*h,g=i*h,p=o*a,_=o*c,E=o*h;return e[0]=1-(m+g),e[1]=d+E,e[2]=u-_,e[3]=0,e[4]=d-E,e[5]=1-(l+g),e[6]=x+p,e[7]=0,e[8]=u+_,e[9]=x-p,e[10]=1-(l+m),e[11]=0,e[12]=s[0],e[13]=s[1],e[14]=s[2],e[15]=1,e}function vi(e,t){let s=new V(3),r=-t[0],n=-t[1],i=-t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],d=r*r+n*n+i*i+o*o;return d>0?(s[0]=(a*o+l*r+c*i-h*n)*2/d,s[1]=(c*o+l*n+h*r-a*i)*2/d,s[2]=(h*o+l*i+a*n-c*r)*2/d):(s[0]=(a*o+l*r+c*i-h*n)*2,s[1]=(c*o+l*n+h*r-a*i)*2,s[2]=(h*o+l*i+a*n-c*r)*2),cr(e,t,s),e}function zi(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function hr(e,t){let s=t[0],r=t[1],n=t[2],i=t[4],o=t[5],a=t[6],c=t[8],h=t[9],l=t[10];return e[0]=Math.sqrt(s*s+r*r+n*n),e[1]=Math.sqrt(i*i+o*o+a*a),e[2]=Math.sqrt(c*c+h*h+l*l),e}function qi(e,t){let s=new V(3);hr(s,t);let r=1/s[0],n=1/s[1],i=1/s[2],o=t[0]*r,a=t[1]*n,c=t[2]*i,h=t[4]*r,l=t[5]*n,d=t[6]*i,u=t[8]*r,m=t[9]*n,x=t[10]*i,g=o+l+x,p=0;return g>0?(p=Math.sqrt(g+1)*2,e[3]=.25*p,e[0]=(d-m)/p,e[1]=(u-c)/p,e[2]=(a-h)/p):o>l&&o>x?(p=Math.sqrt(1+o-l-x)*2,e[3]=(d-m)/p,e[0]=.25*p,e[1]=(a+h)/p,e[2]=(u+c)/p):l>x?(p=Math.sqrt(1+l-o-x)*2,e[3]=(u-c)/p,e[0]=(a+h)/p,e[1]=.25*p,e[2]=(d+m)/p):(p=Math.sqrt(1+x-o-l)*2,e[3]=(a-h)/p,e[0]=(u+c)/p,e[1]=(d+m)/p,e[2]=.25*p),e}function Vi(e,t,s,r){t[0]=r[12],t[1]=r[13],t[2]=r[14];let n=r[0],i=r[1],o=r[2],a=r[4],c=r[5],h=r[6],l=r[8],d=r[9],u=r[10];s[0]=Math.sqrt(n*n+i*i+o*o),s[1]=Math.sqrt(a*a+c*c+h*h),s[2]=Math.sqrt(l*l+d*d+u*u);let m=1/s[0],x=1/s[1],g=1/s[2],p=n*m,_=i*x,E=o*g,M=a*m,T=c*x,S=h*g,y=l*m,O=d*x,w=u*g,C=p+T+w,R=0;return C>0?(R=Math.sqrt(C+1)*2,e[3]=.25*R,e[0]=(S-O)/R,e[1]=(y-E)/R,e[2]=(_-M)/R):p>T&&p>w?(R=Math.sqrt(1+p-T-w)*2,e[3]=(S-O)/R,e[0]=.25*R,e[1]=(_+M)/R,e[2]=(y+E)/R):T>w?(R=Math.sqrt(1+T-p-w)*2,e[3]=(y-E)/R,e[0]=(_+M)/R,e[1]=.25*R,e[2]=(S+O)/R):(R=Math.sqrt(1+w-p-T)*2,e[3]=(_-M)/R,e[0]=(y+E)/R,e[1]=(S+O)/R,e[2]=.25*R),e}function Di(e,t,s,r){let n=t[0],i=t[1],o=t[2],a=t[3],c=n+n,h=i+i,l=o+o,d=n*c,u=n*h,m=n*l,x=i*h,g=i*l,p=o*l,_=a*c,E=a*h,M=a*l,T=r[0],S=r[1],y=r[2];return e[0]=(1-(x+p))*T,e[1]=(u+M)*T,e[2]=(m-E)*T,e[3]=0,e[4]=(u-M)*S,e[5]=(1-(d+p))*S,e[6]=(g+_)*S,e[7]=0,e[8]=(m+E)*y,e[9]=(g-_)*y,e[10]=(1-(d+x))*y,e[11]=0,e[12]=s[0],e[13]=s[1],e[14]=s[2],e[15]=1,e}function Ui(e,t,s,r,n){let i=t[0],o=t[1],a=t[2],c=t[3],h=i+i,l=o+o,d=a+a,u=i*h,m=i*l,x=i*d,g=o*l,p=o*d,_=a*d,E=c*h,M=c*l,T=c*d,S=r[0],y=r[1],O=r[2],w=n[0],C=n[1],R=n[2],I=(1-(g+_))*S,v=(m+T)*S,z=(x-M)*S,A=(m-T)*y,j=(1-(u+_))*y,mt=(p+E)*y,ft=(x+M)*O,Ue=(p-E)*O,Jt=(1-(u+g))*O;return e[0]=I,e[1]=v,e[2]=z,e[3]=0,e[4]=A,e[5]=j,e[6]=mt,e[7]=0,e[8]=ft,e[9]=Ue,e[10]=Jt,e[11]=0,e[12]=s[0]+w-(I*w+A*C+ft*R),e[13]=s[1]+C-(v*w+j*C+Ue*R),e[14]=s[2]+R-(z*w+mt*C+Jt*R),e[15]=1,e}function cs(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=s+s,a=r+r,c=n+n,h=s*o,l=r*o,d=r*a,u=n*o,m=n*a,x=n*c,g=i*o,p=i*a,_=i*c;return e[0]=1-d-x,e[1]=l+_,e[2]=u-p,e[3]=0,e[4]=l-_,e[5]=1-h-x,e[6]=m+g,e[7]=0,e[8]=u+p,e[9]=m-g,e[10]=1-h-d,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function hs(e,t,s,r,n,i,o){let a=1/(s-t),c=1/(n-r),h=1/(i-o);return e[0]=i*2*a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i*2*c,e[6]=0,e[7]=0,e[8]=(s+t)*a,e[9]=(n+r)*c,e[10]=(o+i)*h,e[11]=-1,e[12]=0,e[13]=0,e[14]=o*i*2*h,e[15]=0,e}function lr(e,t,s,r,n){let i=1/Math.tan(t/2);if(e[0]=i/s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,n!=null&&n!==1/0){let o=1/(r-n);e[10]=(n+r)*o,e[14]=2*n*r*o}else e[10]=-1,e[14]=-2*r;return e}var ls=lr;function Fi(e,t,s,r,n){let i=1/Math.tan(t/2);if(e[0]=i/s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,n!=null&&n!==1/0){let o=1/(r-n);e[10]=n*o,e[14]=n*r*o}else e[10]=-1,e[14]=-r;return e}function Bi(e,t,s,r){let n=Math.tan(t.upDegrees*Math.PI/180),i=Math.tan(t.downDegrees*Math.PI/180),o=Math.tan(t.leftDegrees*Math.PI/180),a=Math.tan(t.rightDegrees*Math.PI/180),c=2/(o+a),h=2/(n+i);return e[0]=c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=h,e[6]=0,e[7]=0,e[8]=-((o-a)*c*.5),e[9]=(n-i)*h*.5,e[10]=r/(s-r),e[11]=-1,e[12]=0,e[13]=0,e[14]=r*s/(s-r),e[15]=0,e}function dr(e,t,s,r,n,i,o){let a=1/(t-s),c=1/(r-n),h=1/(i-o);return e[0]=-2*a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*h,e[11]=0,e[12]=(t+s)*a,e[13]=(n+r)*c,e[14]=(o+i)*h,e[15]=1,e}var ds=dr;function ki(e,t,s,r,n,i,o){let a=1/(t-s),c=1/(r-n),h=1/(i-o);return e[0]=-2*a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=h,e[11]=0,e[12]=(t+s)*a,e[13]=(n+r)*c,e[14]=i*h,e[15]=1,e}function us(e,t,s,r){let n,i,o,a,c,h,l,d,u,m,x=t[0],g=t[1],p=t[2],_=r[0],E=r[1],M=r[2],T=s[0],S=s[1],y=s[2];return Math.abs(x-T)<1e-6&&Math.abs(g-S)<1e-6&&Math.abs(p-y)<1e-6?ar(e):(d=x-T,u=g-S,m=p-y,n=1/Math.sqrt(d*d+u*u+m*m),d*=n,u*=n,m*=n,i=E*m-M*u,o=M*d-_*m,a=_*u-E*d,n=Math.sqrt(i*i+o*o+a*a),n?(n=1/n,i*=n,o*=n,a*=n):(i=0,o=0,a=0),c=u*a-m*o,h=m*i-d*a,l=d*o-u*i,n=Math.sqrt(c*c+h*h+l*l),n?(n=1/n,c*=n,h*=n,l*=n):(c=0,h=0,l=0),e[0]=i,e[1]=c,e[2]=d,e[3]=0,e[4]=o,e[5]=h,e[6]=u,e[7]=0,e[8]=a,e[9]=l,e[10]=m,e[11]=0,e[12]=-(i*x+o*g+a*p),e[13]=-(c*x+h*g+l*p),e[14]=-(d*x+u*g+m*p),e[15]=1,e)}function Wi(e,t,s,r){let n=t[0],i=t[1],o=t[2],a=r[0],c=r[1],h=r[2],l=n-s[0],d=i-s[1],u=o-s[2],m=l*l+d*d+u*u;m>0&&(m=1/Math.sqrt(m),l*=m,d*=m,u*=m);let x=c*u-h*d,g=h*l-a*u,p=a*d-c*l;return m=x*x+g*g+p*p,m>0&&(m=1/Math.sqrt(m),x*=m,g*=m,p*=m),e[0]=x,e[1]=g,e[2]=p,e[3]=0,e[4]=d*p-u*g,e[5]=u*x-l*p,e[6]=l*g-d*x,e[7]=0,e[8]=l,e[9]=d,e[10]=u,e[11]=0,e[12]=n,e[13]=i,e[14]=o,e[15]=1,e}function Yi(e){return`mat4(${e[0]}, ${e[1]}, ${e[2]}, ${e[3]}, ${e[4]}, ${e[5]}, ${e[6]}, ${e[7]}, ${e[8]}, ${e[9]}, ${e[10]}, ${e[11]}, ${e[12]}, ${e[13]}, ${e[14]}, ${e[15]})`}function Gi(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]+e[3]*e[3]+e[4]*e[4]+e[5]*e[5]+e[6]*e[6]+e[7]*e[7]+e[8]*e[8]+e[9]*e[9]+e[10]*e[10]+e[11]*e[11]+e[12]*e[12]+e[13]*e[13]+e[14]*e[14]+e[15]*e[15])}function Zi(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e[3]=t[3]+s[3],e[4]=t[4]+s[4],e[5]=t[5]+s[5],e[6]=t[6]+s[6],e[7]=t[7]+s[7],e[8]=t[8]+s[8],e[9]=t[9]+s[9],e[10]=t[10]+s[10],e[11]=t[11]+s[11],e[12]=t[12]+s[12],e[13]=t[13]+s[13],e[14]=t[14]+s[14],e[15]=t[15]+s[15],e}function ur(e,t,s){return e[0]=t[0]-s[0],e[1]=t[1]-s[1],e[2]=t[2]-s[2],e[3]=t[3]-s[3],e[4]=t[4]-s[4],e[5]=t[5]-s[5],e[6]=t[6]-s[6],e[7]=t[7]-s[7],e[8]=t[8]-s[8],e[9]=t[9]-s[9],e[10]=t[10]-s[10],e[11]=t[11]-s[11],e[12]=t[12]-s[12],e[13]=t[13]-s[13],e[14]=t[14]-s[14],e[15]=t[15]-s[15],e}function ji(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e[3]=t[3]*s,e[4]=t[4]*s,e[5]=t[5]*s,e[6]=t[6]*s,e[7]=t[7]*s,e[8]=t[8]*s,e[9]=t[9]*s,e[10]=t[10]*s,e[11]=t[11]*s,e[12]=t[12]*s,e[13]=t[13]*s,e[14]=t[14]*s,e[15]=t[15]*s,e}function $i(e,t,s,r){return e[0]=t[0]+s[0]*r,e[1]=t[1]+s[1]*r,e[2]=t[2]+s[2]*r,e[3]=t[3]+s[3]*r,e[4]=t[4]+s[4]*r,e[5]=t[5]+s[5]*r,e[6]=t[6]+s[6]*r,e[7]=t[7]+s[7]*r,e[8]=t[8]+s[8]*r,e[9]=t[9]+s[9]*r,e[10]=t[10]+s[10]*r,e[11]=t[11]+s[11]*r,e[12]=t[12]+s[12]*r,e[13]=t[13]+s[13]*r,e[14]=t[14]+s[14]*r,e[15]=t[15]+s[15]*r,e}function Xi(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]}function Qi(e,t){let s=e[0],r=e[1],n=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],l=e[8],d=e[9],u=e[10],m=e[11],x=e[12],g=e[13],p=e[14],_=e[15],E=t[0],M=t[1],T=t[2],S=t[3],y=t[4],O=t[5],w=t[6],C=t[7],R=t[8],I=t[9],v=t[10],z=t[11],A=t[12],j=t[13],mt=t[14],ft=t[15];return Math.abs(s-E)<=1e-6*Math.max(1,Math.abs(s),Math.abs(E))&&Math.abs(r-M)<=1e-6*Math.max(1,Math.abs(r),Math.abs(M))&&Math.abs(n-T)<=1e-6*Math.max(1,Math.abs(n),Math.abs(T))&&Math.abs(i-S)<=1e-6*Math.max(1,Math.abs(i),Math.abs(S))&&Math.abs(o-y)<=1e-6*Math.max(1,Math.abs(o),Math.abs(y))&&Math.abs(a-O)<=1e-6*Math.max(1,Math.abs(a),Math.abs(O))&&Math.abs(c-w)<=1e-6*Math.max(1,Math.abs(c),Math.abs(w))&&Math.abs(h-C)<=1e-6*Math.max(1,Math.abs(h),Math.abs(C))&&Math.abs(l-R)<=1e-6*Math.max(1,Math.abs(l),Math.abs(R))&&Math.abs(d-I)<=1e-6*Math.max(1,Math.abs(d),Math.abs(I))&&Math.abs(u-v)<=1e-6*Math.max(1,Math.abs(u),Math.abs(v))&&Math.abs(m-z)<=1e-6*Math.max(1,Math.abs(m),Math.abs(z))&&Math.abs(x-A)<=1e-6*Math.max(1,Math.abs(x),Math.abs(A))&&Math.abs(g-j)<=1e-6*Math.max(1,Math.abs(g),Math.abs(j))&&Math.abs(p-mt)<=1e-6*Math.max(1,Math.abs(p),Math.abs(mt))&&Math.abs(_-ft)<=1e-6*Math.max(1,Math.abs(_),Math.abs(ft))}var Hi=Bt,Ki=ur;function Ji(){let e=new V(4);return V!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function mr(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e[3]=t[3]+s[3],e}function fr(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e[3]=t[3]*s,e}function pr(e){let t=e[0],s=e[1],r=e[2],n=e[3];return Math.sqrt(t*t+s*s+r*r+n*n)}function xr(e){let t=e[0],s=e[1],r=e[2],n=e[3];return t*t+s*s+r*r+n*n}function gr(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=s*s+r*r+n*n+i*i;return o>0&&(o=1/Math.sqrt(o)),e[0]=s*o,e[1]=r*o,e[2]=n*o,e[3]=i*o,e}function _r(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function Tr(e,t,s,r){let n=t[0],i=t[1],o=t[2],a=t[3];return e[0]=n+r*(s[0]-n),e[1]=i+r*(s[1]-i),e[2]=o+r*(s[2]-o),e[3]=a+r*(s[3]-a),e}function Mr(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3];return e[0]=s[0]*r+s[4]*n+s[8]*i+s[12]*o,e[1]=s[1]*r+s[5]*n+s[9]*i+s[13]*o,e[2]=s[2]*r+s[6]*n+s[10]*i+s[14]*o,e[3]=s[3]*r+s[7]*n+s[11]*i+s[15]*o,e}function yr(e,t,s){let r=t[0],n=t[1],i=t[2],o=s[0],a=s[1],c=s[2],h=s[3],l=h*r+a*i-c*n,d=h*n+c*r-o*i,u=h*i+o*n-a*r,m=-o*r-a*n-c*i;return e[0]=l*h+m*-o+d*-c-u*-a,e[1]=d*h+m*-a+u*-o-l*-c,e[2]=u*h+m*-c+l*-a-d*-o,e[3]=t[3],e}var bc=function(){let e=Ji();return function(t,s,r,n,i,o){let a,c;for(s||(s=4),r||(r=0),n?c=Math.min(n*s+r,t.length):c=t.length,a=r;a<c;a+=s)e[0]=t[a],e[1]=t[a+1],e[2]=t[a+2],e[3]=t[a+3],i(e,e,o),t[a]=e[0],t[a+1]=e[1],t[a+2]=e[2],t[a+3]=e[3];return t}}();var ps;(function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL0ROW3=3]="COL0ROW3",e[e.COL1ROW0=4]="COL1ROW0",e[e.COL1ROW1=5]="COL1ROW1",e[e.COL1ROW2=6]="COL1ROW2",e[e.COL1ROW3=7]="COL1ROW3",e[e.COL2ROW0=8]="COL2ROW0",e[e.COL2ROW1=9]="COL2ROW1",e[e.COL2ROW2=10]="COL2ROW2",e[e.COL2ROW3=11]="COL2ROW3",e[e.COL3ROW0=12]="COL3ROW0",e[e.COL3ROW1=13]="COL3ROW1",e[e.COL3ROW2=14]="COL3ROW2",e[e.COL3ROW3=15]="COL3ROW3"})(ps||(ps={}));var eo=45*Math.PI/180,so=1,ms=.1,fs=500,ro=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),P=class extends bt{static get IDENTITY(){return io()}static get ZERO(){return no()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return ps}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,s,r,n,i,o,a,c,h,l,d,u,m,x,g,p){return this[0]=t,this[1]=s,this[2]=r,this[3]=n,this[4]=i,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=l,this[10]=d,this[11]=u,this[12]=m,this[13]=x,this[14]=g,this[15]=p,this.check()}setRowMajor(t,s,r,n,i,o,a,c,h,l,d,u,m,x,g,p){return this[0]=t,this[1]=i,this[2]=h,this[3]=m,this[4]=s,this[5]=o,this[6]=l,this[7]=x,this[8]=r,this[9]=a,this[10]=d,this[11]=g,this[12]=n,this[13]=c,this[14]=u,this[15]=p,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(ro)}fromObject(t){return this.check()}fromQuaternion(t){return cs(this,t),this.check()}frustum(t){let{left:s,right:r,bottom:n,top:i,near:o=ms,far:a=fs}=t;return a===1/0?oo(this,s,r,n,i,o):hs(this,s,r,n,i,o,a),this.check()}lookAt(t){let{eye:s,center:r=[0,0,0],up:n=[0,1,0]}=t;return us(this,s,r,n),this.check()}ortho(t){let{left:s,right:r,bottom:n,top:i,near:o=ms,far:a=fs}=t;return ds(this,s,r,n,i,o,a),this.check()}orthographic(t){let{fovy:s=eo,aspect:r=so,focalDistance:n=1,near:i=ms,far:o=fs}=t;Sr(s);let a=s/2,c=n*Math.tan(a),h=c*r;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:i,far:o})}perspective(t){let{fovy:s=45*Math.PI/180,aspect:r=1,near:n=.1,far:i=500}=t;return Sr(s),ls(this,s,r,n,i),this.check()}determinant(){return es(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,s){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],s=s||[-0,-0,-0];let r=this.getScale(s),n=1/r[0],i=1/r[1],o=1/r[2];return t[0]=this[0]*n,t[1]=this[1]*i,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*n,t[5]=this[5]*i,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*n,t[9]=this[9]*i,t[10]=this[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,s){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],s=s||[-0,-0,-0];let r=this.getScale(s),n=1/r[0],i=1/r[1],o=1/r[2];return t[0]=this[0]*n,t[1]=this[1]*i,t[2]=this[2]*o,t[3]=this[4]*n,t[4]=this[5]*i,t[5]=this[6]*o,t[6]=this[8]*n,t[7]=this[9]*i,t[8]=this[10]*o,t}transpose(){return Je(this,this),this.check()}invert(){return ts(this,this),this.check()}multiplyLeft(t){return Bt(this,t,this),this.check()}multiplyRight(t){return Bt(this,this,t),this.check()}rotateX(t){return is(this,this,t),this.check()}rotateY(t){return os(this,this,t),this.check()}rotateZ(t){return as(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,s){return ns(this,this,t,s),this.check()}scale(t){return rs(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return ss(this,this,t),this.check()}transform(t,s){return t.length===4?(s=Mr(s||[-0,-0,-0,-0],t,this),lt(s,4),s):this.transformAsPoint(t,s)}transformAsPoint(t,s){let{length:r}=t,n;switch(r){case 2:n=Ws(s||[-0,-0],t,this);break;case 3:n=xt(s||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return lt(n,t.length),n}transformAsVector(t,s){let r;switch(t.length){case 2:r=Ys(s||[-0,-0],t,this);break;case 3:r=re(s||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return lt(r,t.length),r}transformPoint(t,s){return this.transformAsPoint(t,s)}transformVector(t,s){return this.transformAsPoint(t,s)}transformDirection(t,s){return this.transformAsVector(t,s)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,s,r){return this.identity().translate([t,s,r])}},de,ue;function no(){return de||(de=new P([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(de)),de}function io(){return ue||(ue=new P,Object.freeze(ue)),ue}function Sr(e){if(e>Math.PI*2)throw Error("expected radians")}function oo(e,t,s,r,n,i){let o=2*i/(s-t),a=2*i/(n-r),c=(s+t)/(s-t),h=(n+r)/(n-r),l=-1,d=-1,u=-2*i;return e[0]=o,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=a,e[6]=0,e[7]=0,e[8]=c,e[9]=h,e[10]=l,e[11]=d,e[12]=0,e[13]=0,e[14]=u,e[15]=0,e}function Er(){let e=new V(4);return V!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function Rr(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}function xs(e,t,s){s=s*.5;let r=Math.sin(s);return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=Math.cos(s),e}function gs(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=s[0],c=s[1],h=s[2],l=s[3];return e[0]=r*l+o*a+n*h-i*c,e[1]=n*l+o*c+i*a-r*h,e[2]=i*l+o*h+r*c-n*a,e[3]=o*l-r*a-n*c-i*h,e}function wr(e,t,s){s*=.5;let r=t[0],n=t[1],i=t[2],o=t[3],a=Math.sin(s),c=Math.cos(s);return e[0]=r*c+o*a,e[1]=n*c+i*a,e[2]=i*c-n*a,e[3]=o*c-r*a,e}function br(e,t,s){s*=.5;let r=t[0],n=t[1],i=t[2],o=t[3],a=Math.sin(s),c=Math.cos(s);return e[0]=r*c-i*a,e[1]=n*c+o*a,e[2]=i*c+r*a,e[3]=o*c-n*a,e}function Cr(e,t,s){s*=.5;let r=t[0],n=t[1],i=t[2],o=t[3],a=Math.sin(s),c=Math.cos(s);return e[0]=r*c+n*a,e[1]=n*c-r*a,e[2]=i*c+o*a,e[3]=o*c-i*a,e}function Ar(e,t){let s=t[0],r=t[1],n=t[2];return e[0]=s,e[1]=r,e[2]=n,e[3]=Math.sqrt(Math.abs(1-s*s-r*r-n*n)),e}function Wt(e,t,s,r){let n=t[0],i=t[1],o=t[2],a=t[3],c=s[0],h=s[1],l=s[2],d=s[3],u,m,x,g,p;return u=n*c+i*h+o*l+a*d,u<0&&(u=-u,c=-c,h=-h,l=-l,d=-d),1-u>1e-6?(m=Math.acos(u),p=Math.sin(m),x=Math.sin((1-r)*m)/p,g=Math.sin(r*m)/p):(x=1-r,g=r),e[0]=x*n+g*c,e[1]=x*i+g*h,e[2]=x*o+g*l,e[3]=x*a+g*d,e}function Or(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=s*s+r*r+n*n+i*i,a=o?1/o:0;return e[0]=-s*a,e[1]=-r*a,e[2]=-n*a,e[3]=i*a,e}function Pr(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e}function _s(e,t){let s=t[0]+t[4]+t[8],r;if(s>0)r=Math.sqrt(s+1),e[3]=.5*r,r=.5/r,e[0]=(t[5]-t[7])*r,e[1]=(t[6]-t[2])*r,e[2]=(t[1]-t[3])*r;else{let n=0;t[4]>t[0]&&(n=1),t[8]>t[n*3+n]&&(n=2);let i=(n+1)%3,o=(n+2)%3;r=Math.sqrt(t[n*3+n]-t[i*3+i]-t[o*3+o]+1),e[n]=.5*r,r=.5/r,e[3]=(t[i*3+o]-t[o*3+i])*r,e[i]=(t[i*3+n]+t[n*3+i])*r,e[o]=(t[o*3+n]+t[n*3+o])*r}return e}var Nr=mr;var Lr=fr,Ir=_r,vr=Tr,zr=pr;var qr=xr;var Vr=gr;var Dr=function(){let e=ie(),t=oe(1,0,0),s=oe(0,1,0);return function(r,n,i){let o=Dt(n,i);return o<-.999999?(pt(e,t,n),$e(e)<1e-6&&pt(e,s,n),We(e,e),xs(r,e,Math.PI),r):o>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(pt(e,n,i),r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=1+o,Vr(r,r))}}(),Fc=function(){let e=Er(),t=Er();return function(s,r,n,i,o,a){return Wt(e,r,o,a),Wt(t,n,i,a),Wt(s,e,t,2*a*(1-a)),s}}(),Bc=function(){let e=tr();return function(t,s,r,n){return e[0]=r[0],e[3]=r[1],e[6]=r[2],e[1]=n[0],e[4]=n[1],e[7]=n[2],e[2]=-s[0],e[5]=-s[1],e[8]=-s[2],Vr(t,_s(t,e))}}();var ao=[0,0,0,1],dt=class extends ht{constructor(t=0,s=0,r=0,n=1){super(-0,-0,-0,-0),Array.isArray(t)&&arguments.length===1?this.copy(t):this.set(t,s,r,n)}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}set(t,s,r,n){return this[0]=t,this[1]=s,this[2]=r,this[3]=n,this.check()}fromObject(t){return this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this.check()}fromMatrix3(t){return _s(this,t),this.check()}fromAxisRotation(t,s){return xs(this,t,s),this.check()}identity(){return Rr(this),this.check()}setAxisAngle(t,s){return this.fromAxisRotation(t,s)}get ELEMENTS(){return 4}get x(){return this[0]}set x(t){this[0]=N(t)}get y(){return this[1]}set y(t){this[1]=N(t)}get z(){return this[2]}set z(t){this[2]=N(t)}get w(){return this[3]}set w(t){this[3]=N(t)}len(){return zr(this)}lengthSquared(){return qr(this)}dot(t){return Ir(this,t)}rotationTo(t,s){return Dr(this,t,s),this.check()}add(t){return Nr(this,this,t),this.check()}calculateW(){return Ar(this,this),this.check()}conjugate(){return Pr(this,this),this.check()}invert(){return Or(this,this),this.check()}lerp(t,s,r){return r===void 0?this.lerp(this,t,s):(vr(this,t,s,r),this.check())}multiplyRight(t){return gs(this,this,t),this.check()}multiplyLeft(t){return gs(this,t,this),this.check()}normalize(){let t=this.len(),s=t>0?1/t:0;return this[0]=this[0]*s,this[1]=this[1]*s,this[2]=this[2]*s,this[3]=this[3]*s,t===0&&(this[3]=1),this.check()}rotateX(t){return wr(this,this,t),this.check()}rotateY(t){return br(this,this,t),this.check()}rotateZ(t){return Cr(this,this,t),this.check()}scale(t){return Lr(this,this,t),this.check()}slerp(t,s,r){let n,i,o;switch(arguments.length){case 1:({start:n=ao,target:i,ratio:o}=t);break;case 2:n=this,i=t,o=s;break;default:n=t,i=s,o=r}return Wt(this,n,i,o),this.check()}transformVector4(t,s=new wt){return yr(s,t,this),lt(s,4)}lengthSq(){return this.lengthSquared()}setFromAxisAngle(t,s){return this.setAxisAngle(t,s)}premultiply(t){return this.multiplyLeft(t)}multiply(t){return this.multiplyRight(t)}};var it={};qt(it,{EPSILON1:()=>co,EPSILON10:()=>_o,EPSILON11:()=>To,EPSILON12:()=>Mo,EPSILON13:()=>yo,EPSILON14:()=>So,EPSILON15:()=>Eo,EPSILON16:()=>Ro,EPSILON17:()=>wo,EPSILON18:()=>bo,EPSILON19:()=>Co,EPSILON2:()=>ho,EPSILON20:()=>Ao,EPSILON3:()=>lo,EPSILON4:()=>uo,EPSILON5:()=>mo,EPSILON6:()=>fo,EPSILON7:()=>po,EPSILON8:()=>xo,EPSILON9:()=>go,PI_OVER_FOUR:()=>Po,PI_OVER_SIX:()=>No,PI_OVER_TWO:()=>Oo,TWO_PI:()=>Lo});var co=.1,ho=.01,lo=.001,uo=1e-4,mo=1e-5,fo=1e-6,po=1e-7,xo=1e-8,go=1e-9,_o=1e-10,To=1e-11,Mo=1e-12,yo=1e-13,So=1e-14,Eo=1e-15,Ro=1e-16,wo=1e-17,bo=1e-18,Co=1e-19,Ao=1e-20,Oo=Math.PI/2,Po=Math.PI/4,No=Math.PI/6,Lo=Math.PI*2;var ot=6356752314245179e-9,vo={radii:[6378137,6378137,ot],radiiSquared:[6378137*6378137,6378137*6378137,ot*ot],oneOverRadii:[1/6378137,1/6378137,1/ot],oneOverRadiiSquared:[1/(6378137*6378137),1/(6378137*6378137),1/(ot*ot)],maximumRadius:Math.max(6378137,6378137,ot),centerToleranceSquared:.1};function me(e){return e}var xh=new f;function zo(e,t=[],s=me){return"longitude"in e?(t[0]=s(e.longitude),t[1]=s(e.latitude),t[2]=e.height):"x"in e?(t[0]=s(e.x),t[1]=s(e.y),t[2]=e.z):(t[0]=s(e[0]),t[1]=s(e[1]),t[2]=e[2]),t}function Ur(e,t=[]){return zo(e,t,q._cartographicRadians?me:Be)}function qo(e,t,s=me){return"longitude"in t?(t.longitude=s(e[0]),t.latitude=s(e[1]),t.height=e[2]):"x"in t?(t.x=s(e[0]),t.y=s(e[1]),t.z=e[2]):(t[0]=s(e[0]),t[1]=s(e[1]),t[2]=e[2]),t}function Fr(e,t){return qo(e,t,q._cartographicRadians?me:ke)}var Br=1e-14,Vo=new f,kr={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"}},Ts={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Yt={east:new f,north:new f,up:new f,west:new f,south:new f,down:new f},Do=new f,Uo=new f,Fo=new f;function Ms(e,t,s,r,n,i){let o=kr[t]&&kr[t][s];F(o&&(!r||r===o));let a,c,h,l=Vo.copy(n);if(X(l.x,0,Br)&&X(l.y,0,Br)){let u=Math.sign(l.z);a=Do.fromArray(Ts[t]),t!=="east"&&t!=="west"&&a.scale(u),c=Uo.fromArray(Ts[s]),s!=="east"&&s!=="west"&&c.scale(u),h=Fo.fromArray(Ts[r]),r!=="east"&&r!=="west"&&h.scale(u)}else{let{up:u,east:m,north:x}=Yt;m.set(-l.y,l.x,0).normalize(),e.geodeticSurfaceNormal(l,u),x.copy(u).cross(m);let{down:g,west:p,south:_}=Yt;g.copy(u).scale(-1),p.copy(m).scale(-1),_.copy(x).scale(-1),a=Yt[t],c=Yt[s],h=Yt[r]}return i[0]=a.x,i[1]=a.y,i[2]=a.z,i[3]=0,i[4]=c.x,i[5]=c.y,i[6]=c.z,i[7]=0,i[8]=h.x,i[9]=h.y,i[10]=h.z,i[11]=0,i[12]=l.x,i[13]=l.y,i[14]=l.z,i[15]=1,i}var Ct=new f,Bo=new f,ko=new f;function Wr(e,t,s=[]){let{oneOverRadii:r,oneOverRadiiSquared:n,centerToleranceSquared:i}=t;Ct.from(e);let o=Ct.x,a=Ct.y,c=Ct.z,h=r.x,l=r.y,d=r.z,u=o*o*h*h,m=a*a*l*l,x=c*c*d*d,g=u+m+x,p=Math.sqrt(1/g);if(!Number.isFinite(p))return;let _=Bo;if(_.copy(e).scale(p),g<i)return _.to(s);let E=n.x,M=n.y,T=n.z,S=ko;S.set(_.x*E*2,_.y*M*2,_.z*T*2);let y=(1-p)*Ct.len()/(.5*S.len()),O=0,w,C,R,I;do{y-=O,w=1/(1+y*E),C=1/(1+y*M),R=1/(1+y*T);let v=w*w,z=C*C,A=R*R,j=v*w,mt=z*C,ft=A*R;I=u*v+m*z+x*A-1;let Jt=-2*(u*j*E+m*mt*M+x*ft*T);O=I/Jt}while(Math.abs(I)>it.EPSILON12);return Ct.scale([w,C,R]).to(s)}var fe=new f,Yr=new f,Go=new f,H=new f,Zo=new f,pe=new f,b=class{constructor(t=0,s=0,r=0){this.centerToleranceSquared=it.EPSILON1,F(t>=0),F(s>=0),F(r>=0),this.radii=new f(t,s,r),this.radiiSquared=new f(t*t,s*s,r*r),this.radiiToTheFourth=new f(t*t*t*t,s*s*s*s,r*r*r*r),this.oneOverRadii=new f(t===0?0:1/t,s===0?0:1/s,r===0?0:1/r),this.oneOverRadiiSquared=new f(t===0?0:1/(t*t),s===0?0:1/(s*s),r===0?0:1/(r*r)),this.minimumRadius=Math.min(t,s,r),this.maximumRadius=Math.max(t,s,r),this.radiiSquared.z!==0&&(this.squaredXOverSquaredZ=this.radiiSquared.x/this.radiiSquared.z),Object.freeze(this)}equals(t){return this===t||Boolean(t&&this.radii.equals(t.radii))}toString(){return this.radii.toString()}cartographicToCartesian(t,s=[0,0,0]){let r=Yr,n=Go,[,,i]=t;this.geodeticSurfaceNormalCartographic(t,r),n.copy(this.radiiSquared).scale(r);let o=Math.sqrt(r.dot(n));return n.scale(1/o),r.scale(i),n.add(r),n.to(s)}cartesianToCartographic(t,s=[0,0,0]){pe.from(t);let r=this.scaleToGeodeticSurface(pe,H);if(!r)return;let n=this.geodeticSurfaceNormal(r,Yr),i=Zo;i.copy(pe).subtract(r);let o=Math.atan2(n.y,n.x),a=Math.asin(n.z),c=Math.sign(gt.dot(i,pe))*gt.length(i);return Fr([o,a,c],s)}eastNorthUpToFixedFrame(t,s=new P){return Ms(this,"east","north","up",t,s)}localFrameToFixedFrame(t,s,r,n,i=new P){return Ms(this,t,s,r,n,i)}geocentricSurfaceNormal(t,s=[0,0,0]){return fe.from(t).normalize().to(s)}geodeticSurfaceNormalCartographic(t,s=[0,0,0]){let r=Ur(t),n=r[0],i=r[1],o=Math.cos(i);return fe.set(o*Math.cos(n),o*Math.sin(n),Math.sin(i)).normalize(),fe.to(s)}geodeticSurfaceNormal(t,s=[0,0,0]){return fe.from(t).scale(this.oneOverRadiiSquared).normalize().to(s)}scaleToGeodeticSurface(t,s){return Wr(t,this,s)}scaleToGeocentricSurface(t,s=[0,0,0]){H.from(t);let r=H.x,n=H.y,i=H.z,o=this.oneOverRadiiSquared,a=1/Math.sqrt(r*r*o.x+n*n*o.y+i*i*o.z);return H.multiplyScalar(a).to(s)}transformPositionToScaledSpace(t,s=[0,0,0]){return H.from(t).scale(this.oneOverRadii).to(s)}transformPositionFromScaledSpace(t,s=[0,0,0]){return H.from(t).scale(this.radii).to(s)}getSurfaceNormalIntersectionWithZAxis(t,s=0,r=[0,0,0]){F(X(this.radii.x,this.radii.y,it.EPSILON15)),F(this.radii.z>0),H.from(t);let n=H.z*(1-this.squaredXOverSquaredZ);if(!(Math.abs(n)>=this.radii.z-s))return H.set(0,0,n).to(r)}};b.WGS84=new b(6378137,6378137,ot);function Gt(){let e;if(typeof window<"u"&&window.performance)e=window.performance.now();else if(typeof process<"u"&&process.hrtime){let t=process.hrtime();e=t[0]*1e3+t[1]/1e6}else e=Date.now();return e}var _t=class{constructor(t,s){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=t,this.type=s,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(t){return this.sampleSize=t,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(t){return this._count+=t,this._samples++,this._checkSampling(),this}subtractCount(t){return this._count-=t,this._samples++,this._checkSampling(),this}addTime(t){return this._time+=t,this.lastTiming=t,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=Gt(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Gt()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var st=class{constructor(t){this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t,s="count"){return this._getOrCreate({name:t,type:s})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let s of Object.values(this.stats))t(s)}getTable(){let t={};return this.forEach(s=>{t[s.name]={time:s.time||0,count:s.count||0,average:s.getAverageTime()||0,hz:s.getHz()||0}}),t}_initializeStats(t=[]){t.forEach(s=>this._getOrCreate(s))}_getOrCreate(t){let{name:s,type:r}=t,n=this.stats[s];return n||(t instanceof _t?n=t:n=new _t(s,r),this.stats[s]=n),n}};function K(e,t){if(!e)throw new Error(t||"loader assertion failed.")}var jo="Queued Requests",$o="Active Requests",Xo="Cancelled Requests",Qo="Queued Requests Ever",Ho="Active Requests Ever",Ko={id:"request-scheduler",throttleRequests:!0,maxRequests:6,debounceTime:0},at=class{props;stats;activeRequestCount=0;requestQueue=[];requestMap=new Map;updateTimer=null;constructor(t={}){this.props={...Ko,...t},this.stats=new st({id:this.props.id}),this.stats.get(jo),this.stats.get($o),this.stats.get(Xo),this.stats.get(Qo),this.stats.get(Ho)}setProps(t){t.throttleRequests!==void 0&&(this.props.throttleRequests=t.throttleRequests),t.maxRequests!==void 0&&(this.props.maxRequests=t.maxRequests),t.debounceTime!==void 0&&(this.props.debounceTime=t.debounceTime)}scheduleRequest(t,s=()=>0){if(!this.props.throttleRequests)return Promise.resolve({done:()=>{}});if(this.requestMap.has(t))return this.requestMap.get(t);let r={handle:t,priority:0,getPriority:s},n=new Promise(i=>(r.resolve=i,r));return this.requestQueue.push(r),this.requestMap.set(t,n),this._issueNewRequests(),n}_issueRequest(t){let{handle:s,resolve:r}=t,n=!1,i=()=>{n||(n=!0,this.requestMap.delete(s),this.activeRequestCount--,this._issueNewRequests())};return this.activeRequestCount++,r?r({done:i}):Promise.resolve({done:i})}_issueNewRequests(){this.updateTimer!==null&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>this._issueNewRequestsAsync(),this.props.debounceTime)}_issueNewRequestsAsync(){this.updateTimer!==null&&clearTimeout(this.updateTimer),this.updateTimer=null;let t=Math.max(this.props.maxRequests-this.activeRequestCount,0);if(t!==0){this._updateAllRequests();for(let s=0;s<t;++s){let r=this.requestQueue.shift();r&&this._issueRequest(r)}}}_updateAllRequests(){let t=this.requestQueue;for(let s=0;s<t.length;++s){let r=t[s];this._updateRequest(r)||(t.splice(s,1),this.requestMap.delete(r.handle),s--)}t.sort((s,r)=>s.priority-r.priority)}_updateRequest(t){return t.priority=t.getPriority(t.handle),t.priority<0?(t.resolve(null),!1):!0}};var Q={};qt(Q,{dirname:()=>ta,filename:()=>Jo,join:()=>ea,resolve:()=>sa});function Gr(){if(typeof process<"u"&&typeof process.cwd<"u")return process.cwd();let e=window.location?.pathname;return e?.slice(0,e.lastIndexOf("/")+1)||""}function Jo(e){let t=e?e.lastIndexOf("/"):-1;return t>=0?e.substr(t+1):e}function ta(e){let t=e?e.lastIndexOf("/"):-1;return t>=0?e.substr(0,t):""}function ea(...e){let t="/";return e=e.map((s,r)=>(r&&(s=s.replace(new RegExp(`^${t}`),"")),r!==e.length-1&&(s=s.replace(new RegExp(`${t}$`),"")),s)),e.join(t)}function sa(...e){let t=[];for(let i=0;i<e.length;i++)t[i]=e[i];let s="",r=!1,n;for(let i=t.length-1;i>=-1&&!r;i--){let o;i>=0?o=t[i]:(n===void 0&&(n=Gr()),o=n),o.length!==0&&(s=`${o}/${s}`,r=o.charCodeAt(0)===Zt)}return s=ra(s,!r),r?`/${s}`:s.length>0?s:"."}var Zt=47,ys=46;function ra(e,t){let s="",r=-1,n=0,i,o=!1;for(let a=0;a<=e.length;++a){if(a<e.length)i=e.charCodeAt(a);else{if(i===Zt)break;i=Zt}if(i===Zt){if(!(r===a-1||n===1))if(r!==a-1&&n===2){if(s.length<2||!o||s.charCodeAt(s.length-1)!==ys||s.charCodeAt(s.length-2)!==ys){if(s.length>2){let c=s.length-1,h=c;for(;h>=0&&s.charCodeAt(h)!==Zt;--h);if(h!==c){s=h===-1?"":s.slice(0,h),r=a,n=0,o=!1;continue}}else if(s.length===2||s.length===1){s="",r=a,n=0,o=!1;continue}}t&&(s.length>0?s+="/..":s="..",o=!0)}else{let c=e.slice(r+1,a);s.length>0?s+=`/${c}`:s=c,o=!1}r=a,n=0}else i===ys&&n!==-1?++n:n=-1}return s}var At=class{handle;size;bigsize;url;constructor(t){this.handle=t instanceof ArrayBuffer?new Blob([t]):t,this.size=t instanceof ArrayBuffer?t.byteLength:t.size,this.bigsize=BigInt(this.size),this.url=t instanceof File?t.name:""}async close(){}async stat(){return{size:this.handle.size,bigsize:BigInt(this.handle.size),isDirectory:!1}}async read(t,s){return await this.handle.slice(Number(t),Number(t)+Number(s)).arrayBuffer()}};var jt=class{handle;size=0;bigsize=0n;url;constructor(t){this.handle=t,this.url=t}async close(){}async stat(){let t=await fetch(this.handle,{method:"HEAD"});if(!t.ok)throw new Error(`Failed to fetch HEAD ${this.handle}`);let s=parseInt(t.headers.get("Content-Length")||"0");return{size:s,bigsize:BigInt(s),isDirectory:!1}}async read(t=0,s=0){return await(await this.fetchRange(t,s)).arrayBuffer()}async fetchRange(t,s,r){let n=Number(t),i=Number(s),o;r||(o=new AbortController,r=o.signal);let a=this.handle,c=await fetch(a,{signal:r,headers:{Range:`bytes=${n}-${n+i-1}`}});switch(c.status){case 206:break;case 200:let h=c.headers.get("Content-Length");if(!h||Number(h)>s)throw o&&o.abort(),Error("content-length header missing or exceeding request. Server must support HTTP Byte Serving.");case 416:if(t===0){let l=c.headers.get("Content-Range");if(!l||!l.startsWith("bytes *"))throw Error("Missing content-length on 416 response");let d=Number(l.substr(8));c=await fetch(this.url,{signal:r,headers:{Range:`bytes=0-${d-1}`}})}break;default:if(c.status>=300)throw Error(`Bad response code: ${c.status}`)}return c}};var xe=class{item;previous;next;constructor(t,s,r){this.item=t,this.previous=s,this.next=r}};var ge=class{head=null;tail=null;_length=0;get length(){return this._length}add(t){let s=new xe(t,this.tail,null);return this.tail?(this.tail.next=s,this.tail=s):(this.head=s,this.tail=s),++this._length,s}remove(t){t&&(t.previous&&t.next?(t.previous.next=t.next,t.next.previous=t.previous):t.previous?(t.previous.next=null,this.tail=t.previous):t.next?(t.next.previous=null,this.head=t.next):(this.head=null,this.tail=null),t.next=null,t.previous=null,--this._length)}splice(t,s){t!==s&&(this.remove(s),this._insert(t,s))}_insert(t,s){let r=t.next;t.next=s,this.tail===t?this.tail=s:r.previous=s,s.next=r,s.previous=t,++this._length}};var Ot=class{_list;_sentinel;_trimTiles;constructor(){this._list=new ge,this._sentinel=this._list.add("sentinel"),this._trimTiles=!1}reset(){this._list.splice(this._list.tail,this._sentinel)}touch(t){let s=t._cacheNode;s&&this._list.splice(this._sentinel,s)}add(t,s,r){s._cacheNode||(s._cacheNode=this._list.add(s),r&&r(t,s))}unloadTile(t,s,r){let n=s._cacheNode;n&&(this._list.remove(n),s._cacheNode=null,r&&r(t,s))}unloadTiles(t,s){let r=this._trimTiles;this._trimTiles=!1;let n=this._list,i=t.maximumMemoryUsage*1024*1024,o=this._sentinel,a=n.head;for(;a!==o&&(t.gpuMemoryUsageInBytes>i||r);){let c=a.item;a=a.next,this.unloadTile(t,c,s)}}trim(){this._trimTiles=!0}};function _e(e,t){K(e),K(t);let{rtcCenter:s,gltfUpAxis:r}=t,{computedTransform:n,boundingVolume:{center:i}}=e,o=new P(n);switch(s&&o.translate(s),r){case"Z":break;case"Y":let u=new P().rotateX(Math.PI/2);o=o.multiplyRight(u);break;case"X":let m=new P().rotateY(-Math.PI/2);o=o.multiplyRight(m);break;default:break}t.isQuantized&&o.translate(t.quantizedVolumeOffset).scale(t.quantizedVolumeScale);let a=new f(i);t.cartesianModelMatrix=o,t.cartesianOrigin=a;let c=b.WGS84.cartesianToCartographic(a,new f),l=b.WGS84.eastNorthUpToFixedFrame(a).invert();t.cartographicModelMatrix=l.multiplyRight(o),t.cartographicOrigin=c;let d=ia(t);d&&(t.cartesianModelMatrix=new P(o).multiplyRight(d.matrix),t.cartographicModelMatrix.multiplyRight(d.matrix),d.matrix=P.IDENTITY),t.coordinateSystem||(t.modelMatrix=t.cartographicModelMatrix)}var na=1e6**2;function ia(e){let t=e.gltf;if(!t)return null;let s=typeof t.scene=="number"?t.scene:0,n=t.scenes?.[s]?.nodes?.[0];if(!n?.matrix)return null;let i=n.matrix;return i[12]*i[12]+i[13]*i[13]+i[14]*i[14]<=na?null:n}var B={OUTSIDE:-1,INTERSECTING:0,INSIDE:1};var dl=new f,ul=new f;var $t=new f,Zr=new f,G=class{constructor(t=[0,0,0],s=0){this.radius=-0,this.center=new f,this.fromCenterRadius(t,s)}fromCenterRadius(t,s){return this.center.from(t),this.radius=s,this}fromCornerPoints(t,s){return s=$t.from(s),this.center=new f().from(t).add(s).scale(.5),this.radius=this.center.distance(s),this}equals(t){return this===t||Boolean(t)&&this.center.equals(t.center)&&this.radius===t.radius}clone(){return new G(this.center,this.radius)}union(t){let s=this.center,r=this.radius,n=t.center,i=t.radius,o=$t.copy(n).subtract(s),a=o.magnitude();if(r>=a+i)return this.clone();if(i>=a+r)return t.clone();let c=(r+a+i)*.5;return Zr.copy(o).scale((-r+c)/a).add(s),this.center.copy(Zr),this.radius=c,this}expand(t){let r=$t.from(t).subtract(this.center).magnitude();return r>this.radius&&(this.radius=r),this}transform(t){this.center.transform(t);let s=kt.getScaling($t,t);return this.radius=Math.max(s[0],Math.max(s[1],s[2]))*this.radius,this}distanceSquaredTo(t){let s=this.distanceTo(t);return s*s}distanceTo(t){let r=$t.from(t).subtract(this.center);return Math.max(0,r.len()-this.radius)}intersectPlane(t){let s=this.center,r=this.radius,i=t.normal.dot(s)+t.distance;return i<-r?B.OUTSIDE:i<r?B.INTERSECTING:B.INSIDE}};var oa=new f,aa=new f,Te=new f,Me=new f,ye=new f,ca=new f,ha=new f,ct={COLUMN0ROW0:0,COLUMN0ROW1:1,COLUMN0ROW2:2,COLUMN1ROW0:3,COLUMN1ROW1:4,COLUMN1ROW2:5,COLUMN2ROW0:6,COLUMN2ROW1:7,COLUMN2ROW2:8},rt=class{constructor(t=[0,0,0],s=[0,0,0,0,0,0,0,0,0]){this.center=new f().from(t),this.halfAxes=new D(s)}get halfSize(){let t=this.halfAxes.getColumn(0),s=this.halfAxes.getColumn(1),r=this.halfAxes.getColumn(2);return[new f(t).len(),new f(s).len(),new f(r).len()]}get quaternion(){let t=this.halfAxes.getColumn(0),s=this.halfAxes.getColumn(1),r=this.halfAxes.getColumn(2),n=new f(t).normalize(),i=new f(s).normalize(),o=new f(r).normalize();return new dt().fromMatrix3(new D([...n,...i,...o]))}fromCenterHalfSizeQuaternion(t,s,r){let n=new dt(r),i=new D().fromQuaternion(n);return i[0]=i[0]*s[0],i[1]=i[1]*s[0],i[2]=i[2]*s[0],i[3]=i[3]*s[1],i[4]=i[4]*s[1],i[5]=i[5]*s[1],i[6]=i[6]*s[2],i[7]=i[7]*s[2],i[8]=i[8]*s[2],this.center=new f().from(t),this.halfAxes=i,this}clone(){return new rt(this.center,this.halfAxes)}equals(t){return this===t||Boolean(t)&&this.center.equals(t.center)&&this.halfAxes.equals(t.halfAxes)}getBoundingSphere(t=new G){let s=this.halfAxes,r=s.getColumn(0,Te),n=s.getColumn(1,Me),i=s.getColumn(2,ye),o=oa.copy(r).add(n).add(i);return t.center.copy(this.center),t.radius=o.magnitude(),t}intersectPlane(t){let s=this.center,r=t.normal,n=this.halfAxes,i=r.x,o=r.y,a=r.z,c=Math.abs(i*n[ct.COLUMN0ROW0]+o*n[ct.COLUMN0ROW1]+a*n[ct.COLUMN0ROW2])+Math.abs(i*n[ct.COLUMN1ROW0]+o*n[ct.COLUMN1ROW1]+a*n[ct.COLUMN1ROW2])+Math.abs(i*n[ct.COLUMN2ROW0]+o*n[ct.COLUMN2ROW1]+a*n[ct.COLUMN2ROW2]),h=r.dot(s)+t.distance;return h<=-c?B.OUTSIDE:h>=c?B.INSIDE:B.INTERSECTING}distanceTo(t){return Math.sqrt(this.distanceSquaredTo(t))}distanceSquaredTo(t){let s=aa.from(t).subtract(this.center),r=this.halfAxes,n=r.getColumn(0,Te),i=r.getColumn(1,Me),o=r.getColumn(2,ye),a=n.magnitude(),c=i.magnitude(),h=o.magnitude();n.normalize(),i.normalize(),o.normalize();let l=0,d;return d=Math.abs(s.dot(n))-a,d>0&&(l+=d*d),d=Math.abs(s.dot(i))-c,d>0&&(l+=d*d),d=Math.abs(s.dot(o))-h,d>0&&(l+=d*d),l}computePlaneDistances(t,s,r=[-0,-0]){let n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=this.center,a=this.halfAxes,c=a.getColumn(0,Te),h=a.getColumn(1,Me),l=a.getColumn(2,ye),d=ca.copy(c).add(h).add(l).add(o),u=ha.copy(d).subtract(t),m=s.dot(u);return n=Math.min(m,n),i=Math.max(m,i),d.copy(o).add(c).add(h).subtract(l),u.copy(d).subtract(t),m=s.dot(u),n=Math.min(m,n),i=Math.max(m,i),d.copy(o).add(c).subtract(h).add(l),u.copy(d).subtract(t),m=s.dot(u),n=Math.min(m,n),i=Math.max(m,i),d.copy(o).add(c).subtract(h).subtract(l),u.copy(d).subtract(t),m=s.dot(u),n=Math.min(m,n),i=Math.max(m,i),o.copy(d).subtract(c).add(h).add(l),u.copy(d).subtract(t),m=s.dot(u),n=Math.min(m,n),i=Math.max(m,i),o.copy(d).subtract(c).add(h).subtract(l),u.copy(d).subtract(t),m=s.dot(u),n=Math.min(m,n),i=Math.max(m,i),o.copy(d).subtract(c).subtract(h).add(l),u.copy(d).subtract(t),m=s.dot(u),n=Math.min(m,n),i=Math.max(m,i),o.copy(d).subtract(c).subtract(h).subtract(l),u.copy(d).subtract(t),m=s.dot(u),n=Math.min(m,n),i=Math.max(m,i),r[0]=n,r[1]=i,r}transform(t){this.center.transformAsPoint(t);let s=this.halfAxes.getColumn(0,Te);s.transformAsPoint(t);let r=this.halfAxes.getColumn(1,Me);r.transformAsPoint(t);let n=this.halfAxes.getColumn(2,ye);return n.transformAsPoint(t),this.halfAxes=new D([...s,...r,...n]),this}getTransform(){throw new Error("not implemented")}};var jr=new f,$r=new f,k=class{constructor(t=[0,0,1],s=0){this.normal=new f,this.distance=-0,this.fromNormalDistance(t,s)}fromNormalDistance(t,s){return F(Number.isFinite(s)),this.normal.from(t).normalize(),this.distance=s,this}fromPointNormal(t,s){t=jr.from(t),this.normal.from(s).normalize();let r=-this.normal.dot(t);return this.distance=r,this}fromCoefficients(t,s,r,n){return this.normal.set(t,s,r),F(X(this.normal.len(),1)),this.distance=n,this}clone(){return new k(this.normal,this.distance)}equals(t){return X(this.distance,t.distance)&&X(this.normal,t.normal)}getPointDistance(t){return this.normal.dot(t)+this.distance}transform(t){let s=$r.copy(this.normal).transformAsVector(t).normalize(),r=this.normal.scale(-this.distance).transform(t);return this.fromPointNormal(r,s)}projectPointOntoPlane(t,s=[0,0,0]){let r=jr.from(t),n=this.getPointDistance(r),i=$r.copy(this.normal).scale(n);return r.subtract(i).to(s)}};var Xr=[new f([1,0,0]),new f([0,1,0]),new f([0,0,1])],Qr=new f,la=new f,U=class{constructor(t=[]){this.planes=t}fromBoundingSphere(t){this.planes.length=2*Xr.length;let s=t.center,r=t.radius,n=0;for(let i of Xr){let o=this.planes[n],a=this.planes[n+1];o||(o=this.planes[n]=new k),a||(a=this.planes[n+1]=new k);let c=Qr.copy(i).scale(-r).add(s);o.fromPointNormal(c,i);let h=Qr.copy(i).scale(r).add(s),l=la.copy(i).negate();a.fromPointNormal(h,l),n+=2}return this}computeVisibility(t){let s=B.INSIDE;for(let r of this.planes)switch(t.intersectPlane(r)){case B.OUTSIDE:return B.OUTSIDE;case B.INTERSECTING:s=B.INTERSECTING;break;default:}return s}computeVisibilityWithPlaneMask(t,s){if(F(Number.isFinite(s),"parentPlaneMask is required."),s===U.MASK_OUTSIDE||s===U.MASK_INSIDE)return s;let r=U.MASK_INSIDE,n=this.planes;for(let i=0;i<this.planes.length;++i){let o=i<31?1<<i:0;if(i<31&&!(s&o))continue;let a=n[i],c=t.intersectPlane(a);if(c===B.OUTSIDE)return U.MASK_OUTSIDE;c===B.INTERSECTING&&(r|=o)}return r}};U.MASK_OUTSIDE=4294967295;U.MASK_INSIDE=0;U.MASK_INDETERMINATE=2147483647;var Pl=new f,Nl=new f,Ll=new f,Il=new f,vl=new f;var Fl=new f,Bl=new f,kl=new f,Wl=new f,Yl=new f,Gl=new f,Zl=new f,jl=new f,$l=new f,Xl=new f,Ql=new f,Hl=new f;var td=new D,ed=new D,sd=new D,rd=new D,nd=new D;var ld=new f,dd=new f,ud=new f,md=new f,fd=new f,pd=new D,xd={diagonal:new D,unitary:new D};var Hr=new f,Ss=new f,Es=new U([new k,new k,new k,new k,new k,new k]);function Ee(e,t){let{cameraDirection:s,cameraUp:r,height:n}=e,{metersPerUnit:i}=e.distanceScales,o=Se(e,e.center),a=b.WGS84.eastNorthUpToFixedFrame(o),c=e.unprojectPosition(e.cameraPosition),h=b.WGS84.cartographicToCartesian(c,new f),l=new f(a.transformAsVector(new f(s).scale(i))).normalize(),d=new f(a.transformAsVector(new f(r).scale(i))).normalize();fa(e);let u=e.constructor,{longitude:m,latitude:x,width:g,bearing:p,zoom:_}=e,E=new u({longitude:m,latitude:x,height:n,width:g,bearing:p,zoom:_,pitch:0});return{camera:{position:h,direction:l,up:d},viewport:e,topDownViewport:E,height:n,cullingVolume:Es,frameNumber:t,sseDenominator:1.15}}function Jr(e,t,s){if(s===0||e.length<=s)return[e,[]];let r=[],{longitude:n,latitude:i}=t.viewport;for(let[h,l]of e.entries()){let[d,u]=l.header.mbs,m=Math.abs(n-d),x=Math.abs(i-u),g=Math.sqrt(x*x+m*m);r.push([h,g])}let o=r.sort((h,l)=>h[1]-l[1]),a=[];for(let h=0;h<s;h++)a.push(e[o[h][0]]);let c=[];for(let h=s;h<o.length;h++)c.push(e[o[h][0]]);return[a,c]}function fa(e){let t=e.getFrustumPlanes(),s=Kr(t.near,e.cameraPosition),r=Se(e,s),n=Se(e,e.cameraPosition,Ss),i=0;Es.planes[i++].fromPointNormal(r,Hr.copy(r).subtract(n));for(let o in t){if(o==="near")continue;let a=t[o],c=Kr(a,s,Ss),h=Se(e,c,Ss);Es.planes[i++].fromPointNormal(h,Hr.copy(r).subtract(h))}}function Kr(e,t,s=new f){let r=e.normal.dot(t);return s.copy(e.normal).scale(e.distance-r).add(t),s}function Se(e,t,s=new f){let r=e.unprojectPosition(t);return b.WGS84.cartographicToCartesian(r,s)}function Re(e){return Boolean(e&&typeof e=="object"&&"initialize"in e&&"getRootTileset"in e&&"initializeTileHeaders"in e&&"loadTileContent"in e)}var pa={description:"",ellipsoid:b.WGS84,modelMatrix:new P,throttleRequests:!0,maxRequests:64,maximumMemoryUsage:32,memoryCacheOverflow:1,maximumTilesSelected:0,debounceTime:0,onTileLoad:()=>{},onTileUnload:()=>{},onTileError:()=>{},onSourceError:()=>{},onTilesetError:()=>{},onTraversalComplete:e=>e,onUpdate:()=>{},contentLoader:void 0,viewDistanceScale:1,maximumScreenSpaceError:8,memoryAdjustedScreenSpaceError:!1,loadTiles:!0,updateTransforms:!0,viewportTraversersMap:null,loadOptions:{fetch:{}},attributions:[],basePath:"",i3s:{}},Rs="Tiles In Tileset(s)",ws="Tiles In Memory",tn="Tiles In View",en="Tiles To Render",sn="Tiles Loaded",bs="Tiles Loading",rn="Tiles Unloaded",nn="Failed Tile Loads",on="Points/Vertices",Cs="Tile Memory Use",an="Maximum Screen Space Error",we=class{options;loadOptions;source;type;tileset;loader;url;basePath;modelMatrix;ellipsoid;lodMetricType;lodMetricValue;refine;root=null;roots={};asset={};description="";properties;extras=null;attributions={};credits={};stats;contentFormats;cartographicCenter=null;cartesianCenter=null;zoom=1;boundingVolume=null;dynamicScreenSpaceErrorComputedDensity=0;maximumMemoryUsage=32;gpuMemoryUsageInBytes=0;memoryAdjustedScreenSpaceError=0;_cacheBytes=0;_cacheOverflowBytes=0;_frameNumber=0;_tiles={};_pendingCount=0;selectedTiles=[];traverseCounter=0;geometricError=0;lastUpdatedVieports=null;_requestedTiles=[];_emptyTiles=[];frameStateData={};_traverser;_cache=new Ot;_requestScheduler;_heldTiles=new Set;updatePromise=null;tilesetInitializationPromise;constructor(t,s){if(this.options={...pa,...s},this.loadOptions=this.options.loadOptions||{},!Re(t))throw new Error("Tileset3D requires a Tileset3DSource instance");this.source=t,this.tileset=null,this.loader=this.source.loader,this.type=this.source.type,this.url=this.source.url,this.basePath=this.source.basePath,this.modelMatrix=this.options.modelMatrix,this.ellipsoid=this.options.ellipsoid,this.lodMetricType="",this.lodMetricValue=0,this.refine="",this.contentFormats=this.source.contentFormats,this._traverser=this._initializeTraverser(),this._requestScheduler=new at({throttleRequests:this.options.throttleRequests,maxRequests:this.options.maxRequests}),this.memoryAdjustedScreenSpaceError=this.options.maximumScreenSpaceError,this._cacheBytes=this.options.maximumMemoryUsage*1024*1024,this._cacheOverflowBytes=this.options.memoryCacheOverflow*1024*1024,this.stats=new st({id:this.url}),this._initializeStats(),this.tilesetInitializationPromise=this._initializeTileSet()}destroy(){this._destroy()}isLoaded(){return this._pendingCount===0&&this._frameNumber!==0&&this._requestedTiles.length===0}get tiles(){return Object.values(this._tiles)}get frameNumber(){return this._frameNumber}get queryParams(){let t=this.source.getTileUrl(this.url),s=t.indexOf("?");return s>=0?t.slice(s+1):""}setProps(t){this.options={...this.options,...t}}getTileUrl(t){return this.source.getTileUrl(t)}hasExtension(t){return Boolean(this.source.hasExtension?.(t))}update(t=null){this.tilesetInitializationPromise.then(()=>{!t&&this.lastUpdatedVieports?t=this.lastUpdatedVieports:this.lastUpdatedVieports=t,t&&this.doUpdate(t)})}async selectTiles(t=null){return await this.tilesetInitializationPromise,t&&(this.lastUpdatedVieports=t),this.updatePromise||(this.updatePromise=new Promise(s=>{setTimeout(()=>{this.lastUpdatedVieports&&this.doUpdate(this.lastUpdatedVieports),s(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(t){if("loadTiles"in this.options&&!this.options.loadTiles||this.traverseCounter>0)return;let s=t instanceof Array?t:[t];this._cache.reset(),this._frameNumber++,this.traverseCounter=s.length;let r=[];for(let n of s){let i=n.id;this._needTraverse(i)?r.push(i):this.traverseCounter--}for(let n of s){let i=n.id;if(this.roots[i]||(this.roots[i]=this._initializeTileHeaders(this.tileset,null)),!r.includes(i))continue;let o=Ee(n,this._frameNumber);this._traverser.traverse(this.roots[i],o,this.options)}}_needTraverse(t){let s=t;return this.options.viewportTraversersMap&&(s=this.options.viewportTraversersMap[t]),s===t}_onTraversalEnd(t){let s=t.viewport.id;this.frameStateData[s]||(this.frameStateData[s]={selectedTiles:[],_requestedTiles:[],_emptyTiles:[]});let r=this.frameStateData[s],n=Object.values(this._traverser.selectedTiles),[i,o]=Jr(n,t,this.options.maximumTilesSelected);r.selectedTiles=i;for(let a of o)a.unselect();r._requestedTiles=Object.values(this._traverser.requestedTiles),r._emptyTiles=Object.values(this._traverser.emptyTiles),this.traverseCounter--,!(this.traverseCounter>0)&&this._updateTiles()}_updateTiles(){let t=this.selectedTiles;this.selectedTiles=[],this._requestedTiles=[],this._emptyTiles=[];for(let i in this.frameStateData){let o=this.frameStateData[i];this.selectedTiles=this.selectedTiles.concat(o.selectedTiles),this._requestedTiles=this._requestedTiles.concat(o._requestedTiles),this._emptyTiles=this._emptyTiles.concat(o._emptyTiles)}this.selectedTiles=this.options.onTraversalComplete(this.selectedTiles);let s=new Set(this.selectedTiles.map(i=>i.id)),r=this.selectedTiles.some(i=>!i.tileDrawn),n=0;if(r){for(let i of s)this._heldTiles.add(i);for(let i of this._heldTiles){if(s.has(i))continue;let o=this._tiles[i];o&&o.contentAvailable?(o._selectedFrame=this._frameNumber,this.selectedTiles.push(o),n++):this._heldTiles.delete(i)}}else this._heldTiles=s;n>0&&setTimeout(()=>{this.selectTiles()},0);for(let i of this.selectedTiles)this._tiles[i.id]=i;this._loadTiles(),this._unloadTiles(),this._updateStats(),this._tilesChanged(t,this.selectedTiles)&&this.options.onUpdate()}_tilesChanged(t,s){if(t.length!==s.length)return!0;let r=new Set(t.map(o=>o.id)),n=new Set(s.map(o=>o.id)),i=t.some(o=>!n.has(o.id));return i=i||s.some(o=>!r.has(o.id)),i}_loadTiles(){this._requestedTiles.sort((t,s)=>t._priority-s._priority);for(let t of this._requestedTiles)t.contentUnloaded&&this._loadTile(t)}_unloadTiles(){this._cache.unloadTiles(this,(t,s)=>t._unloadTile(s))}_updateStats(){let t=0,s=0;for(let r of this.selectedTiles)r.contentAvailable&&r.content&&(t++,r.content.pointCount?s+=r.content.pointCount:s+=r.content.vertexCount);this.stats.get(tn).count=this.selectedTiles.length,this.stats.get(en).count=t,this.stats.get(on).count=s,this.stats.get(an).count=this.memoryAdjustedScreenSpaceError}async _initializeTileSet(){try{let t=this.source.initialize(),s=this._getSourceMetadata();s&&this._syncSourceState(s),s?.tileset?.root&&typeof s.tileset.root.then!="function"&&(this.root=this._initializeTileHeaders(s.tileset,null),this._applyViewState()),await t;let r=this.source.getMetadata();this._syncSourceState(r),this.root||(this.root=this._initializeTileHeaders(r.tileset,null)),this._applyViewState()}catch(t){let s=t instanceof Error?t:new Error(String(t));throw this._onSourceError(s,this.root),this._onTilesetError(s),s}}_initializeStats(){this.stats.get(Rs),this.stats.get(bs),this.stats.get(ws),this.stats.get(tn),this.stats.get(en),this.stats.get(sn),this.stats.get(rn),this.stats.get(nn),this.stats.get(on),this.stats.get(Cs,"memory"),this.stats.get(an)}_initializeTileHeaders(t,s){return this.source.initializeTileHeaders(this,t,s)}_initializeTraverser(){return this.source.createTraverser({basePath:this.basePath,onTraversalEnd:this._onTraversalEnd.bind(this)})}_destroyTileHeaders(t){this._destroySubtree(t)}async _loadTile(t){let s=null;try{this._onStartTileLoading(),s=await t.loadContent()}catch(r){let n=r instanceof Error?r:new Error("load failed");this._onSourceError(n,t),this._onTileLoadError(t,n)}finally{this._onEndTileLoading(),this._onTileLoad(t,s)}}_onTileLoadError(t,s){this.stats.get(nn).incrementCount();let r=s.message||s.toString(),n=t.url;console.error(`A 3D tile failed to load: ${t.url} ${r}`),this.options.onTileError(t,r,n)}_onSourceError(t,s=null){this.options.onSourceError(t,this.source,s)}_onTilesetError(t){this.options.onTilesetError(t,this)}_onTileLoad(t,s){if(!s?.loaded)return;t.content&&_e(t,t.content),this.source.onTileLoaded?.(this,t,s),this._syncSourceState(this.source.getMetadata());let r=this.source.getTilesTotalCount?.();r&&(this.stats.get(Rs).reset(),this.stats.get(Rs).addCount(r)),this._addTileToCache(t),this.options.onTileLoad(t)}_onStartTileLoading(){this._pendingCount++,this.stats.get(bs).incrementCount()}_onEndTileLoading(){this._pendingCount--,this.stats.get(bs).decrementCount()}_addTileToCache(t){this._cache.add(this,t,s=>s._updateCacheStats(t))}_updateCacheStats(t){this.stats.get(sn).incrementCount(),this.stats.get(ws).incrementCount(),this.gpuMemoryUsageInBytes+=t.gpuMemoryUsageInBytes||0,this.stats.get(Cs).count=this.gpuMemoryUsageInBytes,this.options.memoryAdjustedScreenSpaceError&&this.adjustScreenSpaceError()}_unloadTile(t){this.gpuMemoryUsageInBytes-=t.gpuMemoryUsageInBytes||0,this.stats.get(ws).decrementCount(),this.stats.get(rn).incrementCount(),this.stats.get(Cs).count=this.gpuMemoryUsageInBytes,this.options.onTileUnload(t),t.unloadContent()}_destroy(){let t=[];for(this.root&&t.push(this.root);t.length>0;){let s=t.pop();for(let r of s.children)t.push(r);this._destroyTile(s)}this.root=null}_destroySubtree(t){let s=t,r=[s];for(;r.length>0;){t=r.pop();for(let n of t.children)r.push(n);t!==s&&this._destroyTile(t)}s.children=[]}_destroyTile(t){this._cache.unloadTile(this,t),this._unloadTile(t),t.destroy()}_syncSourceState(t){this.tileset=t.tileset,this.loader=t.loader,this.type=t.type,this.url=t.url,this.basePath=t.basePath,this.lodMetricType=t.lodMetricType,this.lodMetricValue=t.lodMetricValue,this.refine=t.refine,this.contentFormats=this.source.contentFormats,this.asset=this.source.asset||this.asset,this.properties=this.source.properties??this.properties,this.extras=this.source.extras??this.extras,this.options.attributions?.length?this.credits={attributions:this.options.attributions}:this.credits=this.source.credits||this.credits}_applyViewState(){let t=this.source.getViewState(this.root);this.asset=t.asset||this.source.asset||{},this.properties=t.properties??this.source.properties,this.extras=t.extras??this.source.extras??null,this.credits=t.credits||this.source.credits||this.credits||{attributions:this.options.attributions||[]},this.description=t.description||this.options.description||"",this.boundingVolume=t.boundingVolume||this.root?.boundingVolume||null,this.cartographicCenter=t.cartographicCenter||new f,this.cartesianCenter=t.cartesianCenter||null,this.zoom=t.zoom||1,this.geometricError=this.tileset?.geometricError||0}_getSourceMetadata(){try{return this.source.getMetadata()}catch{return null}}};var be=class{sourceUrl;options;archivePromise;constructor(t){this.options=t,this.sourceUrl=xa(t.data,t.fallbackFilename)}async loadRoot(t,s,r){return await this.parseArchiveResource(t,this.options.rootPath,s,r,this.options.rootMode)}async loadResource(t,s,r){let n=this.resolveArchivePath(t,t);return await this.parseArchiveResource(t,n,s,r)}async parseArchiveResource(t,s,r,n,i){let o=this.options.getCoreApi();if(!o)throw new Error(this.options.missingCoreApiMessage);let a=await this.loadFile(s,i),c=this.createArchiveFetch(t);return await o.parse(a,r,{...n,fetch:c},{url:t,fetch:c,_parse:o.parse,loaders:[r],coreApi:o})}createArchiveFetch(t){return async s=>{let r=typeof s=="string"?s:s instanceof URL?s.toString():s.url,n=this.resolveArchivePath(r,t),i=await this.loadFile(n);return new Response(i,{status:200})}}async loadFile(t,s){this.archivePromise||=this.openArchiveReadableFile().then(n=>this.options.parseArchive(n));let r=await this.archivePromise;return await this.options.getFile(r,t,s)}async openArchiveReadableFile(){let{data:t}=this.options;if(typeof t!="string")return new At(t);if(/^https?:\/\//i.test(t))return new jt(t);let s=this.options.getCoreApi();if(!s)throw new Error(this.options.missingCoreApiMessage);let r=await s.fetchFile(t);return new At(await r.arrayBuffer())}resolveArchivePath(t,s){let r=As(t),n=As(this.sourceUrl),i=As(s),o=i===n?n:Q.dirname(i),a=new RegExp(`\\.${this.options.archiveExtension}/(.*)$`,"i"),c=r.match(a);if(c?.[1])return c[1];let h=/^[a-z][a-z0-9+.-]*:/i.test(r)||r.startsWith("/"),l=r.startsWith(n)?r:i===n&&!h?`${n}/${r}`:Q.resolve(o,r);return l===n?"":l.startsWith(`${n}/`)?l.slice(n.length+1):l.replace(/^\/+/,"")}};function xa(e,t){return typeof e=="string"?e:`memory://${"name"in e&&typeof e.name=="string"&&e.name?e.name:t}`}function As(e){let t=e.indexOf("?");return t>=0?e.slice(0,t):e}var W={UNLOADED:0,LOADING:1,PROCESSING:2,READY:3,EXPIRED:4,FAILED:5},Z;(function(e){e[e.ADD=1]="ADD",e[e.REPLACE=2]="REPLACE"})(Z||(Z={}));var Ce;(function(e){e.EMPTY="empty",e.SCENEGRAPH="scenegraph",e.POINTCLOUD="pointcloud",e.MESH="mesh"})(Ce||(Ce={}));var J;(function(e){e.I3S="I3S",e.TILES3D="TILES3D"})(J||(J={}));var Pt;(function(e){e.GEOMETRIC_ERROR="geometricError",e.MAX_SCREEN_THRESHOLD="maxScreenThreshold"})(Pt||(Pt={}));var cn={NOT_COMPUTED:-1,USE_OPTIMIZATION:1,SKIP_OPTIMIZATION:0};function un(e){return e!=null}var Y=new f,Ae=new f,ga=new f,_a=new f,Tt=new f,hn=new f,ln=new f,dn=new f;function Nt(e,t,s){if(K(e,"3D Tile: boundingVolume must be defined"),e.box)return fn(e.box,t,s);if(e.region)return Ma(e.region);if(e.sphere)return Ta(e.sphere,t,s);throw new Error("3D Tile: boundingVolume must contain a sphere, region, or box")}function mn(e,t){if(e.box)return ya(t);if(e.region){let[s,r,n,i,o,a]=e.region;return[[$(s),$(r),o],[$(n),$(i),a]]}if(e.sphere)return Sa(t);throw new Error("Unkown boundingVolume type")}function fn(e,t,s){let r=new f(e[0],e[1],e[2]);t.transform(r,r);let n=[];if(e.length===10){let h=e.slice(3,6),l=new dt;l.fromArray(e,6);let d=new f([1,0,0]),u=new f([0,1,0]),m=new f([0,0,1]);d.transformByQuaternion(l),d.scale(h[0]),u.transformByQuaternion(l),u.scale(h[1]),m.transformByQuaternion(l),m.scale(h[2]),n=[...d.toArray(),...u.toArray(),...m.toArray()]}else n=[...e.slice(3,6),...e.slice(6,9),...e.slice(9,12)];let i=t.transformAsVector(n.slice(0,3)),o=t.transformAsVector(n.slice(3,6)),a=t.transformAsVector(n.slice(6,9)),c=new D([i[0],i[1],i[2],o[0],o[1],o[2],a[0],a[1],a[2]]);return un(s)?(s.center=r,s.halfAxes=c,s):new rt(r,c)}function Ta(e,t,s){let r=new f(e[0],e[1],e[2]);t.transform(r,r);let n=t.getScale(Ae),i=Math.max(Math.max(n[0],n[1]),n[2]),o=e[3]*i;return un(s)?(s.center=r,s.radius=o,s):new G(r,o)}function Ma(e){let[t,s,r,n,i,o]=e,a=b.WGS84.cartographicToCartesian([$(t),$(n),i],ga),c=b.WGS84.cartographicToCartesian([$(r),$(s),o],_a),h=new f().addVectors(a,c).multiplyByScalar(.5);return b.WGS84.cartesianToCartographic(h,Tt),b.WGS84.cartographicToCartesian([$(r),Tt[1],Tt[2]],hn),b.WGS84.cartographicToCartesian([Tt[0],$(n),Tt[2]],ln),b.WGS84.cartographicToCartesian([Tt[0],Tt[1],o],dn),fn([...h,...hn.subtract(h),...ln.subtract(h),...dn.subtract(h)],new P)}function ya(e){let t=pn(),{halfAxes:s}=e,r=new f(s.getColumn(0)),n=new f(s.getColumn(1)),i=new f(s.getColumn(2));for(let o=0;o<2;o++){for(let a=0;a<2;a++){for(let c=0;c<2;c++)Y.copy(e.center),Y.add(r),Y.add(n),Y.add(i),xn(t,Y),i.negate();n.negate()}r.negate()}return t}function Sa(e){let t=pn(),{center:s,radius:r}=e,n=b.WGS84.scaleToGeodeticSurface(s,Y),i;n?i=b.WGS84.geodeticSurfaceNormal(n):i=new f(0,0,1);let o=new f(i[2],-i[1],0);o.len()>0?o.normalize():o=new f(0,1,0);let a=o.clone().cross(i);for(let c of[o,a,i]){Ae.copy(c).scale(r);for(let h=0;h<2;h++)Y.copy(s),Y.add(Ae),xn(t,Y),Ae.negate()}return t}function pn(){return[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]]}function xn(e,t){b.WGS84.cartesianToCartographic(t,Y),e[0][0]=Math.min(e[0][0],Y[0]),e[0][1]=Math.min(e[0][1],Y[1]),e[0][2]=Math.min(e[0][2],Y[2]),e[1][0]=Math.max(e[1][0],Y[0]),e[1][1]=Math.max(e[1][1],Y[1]),e[1][2]=Math.max(e[1][2],Y[2])}var ru=new f,nu=new f,iu=new P,ou=new f,au=new f,cu=new f;function Ea(e,t){let s=e*t;return 1-Math.exp(-(s*s))}function Ra(e,t){if(e.dynamicScreenSpaceError&&e.dynamicScreenSpaceErrorComputedDensity){let s=e.dynamicScreenSpaceErrorComputedDensity,r=e.dynamicScreenSpaceErrorFactor;return Ea(t,s)*r}return 0}function gn(e,t,s){let r=e.tileset,n=e.parent&&e.parent.lodMetricValue||e.lodMetricValue,i=s?n:e.lodMetricValue;if(i===0)return 0;let{viewDistanceScale:o}=r.options,a=o||1,c=wa(i,t,a);if(c!==null)return c;let h=Math.max(e._distanceToCamera,1e-7),{height:l,sseDenominator:d}=t,u=i*l*a/(h*d);return u-=Ra(r,h),u}function wa(e,t,s){let r=t.viewport;if(!r?.orthographic)return null;let n=r.metersPerPixel;return!Number.isFinite(n)||n<=0?null:e*s/n}var Os=new f,_n=new f,ut=new f,Tn=new f,ba=new f,Ps=new P,Mn=new P;function Oe(e,t){if(e.lodMetricValue===0||Number.isNaN(e.lodMetricValue))return"DIG";let s=2*Ns(e,t);return s<2?"OUT":!e.header.children||s<=e.lodMetricValue?"DRAW":e.header.children?"DIG":"OUT"}function Ns(e,t){let{topDownViewport:s}=t,r=e.header.mbs[1],n=e.header.mbs[0],i=e.header.mbs[2],o=e.header.mbs[3],a=[...e.boundingVolume.center],c=s.unprojectPosition(s.cameraPosition);b.WGS84.cartographicToCartesian(c,Os),_n.copy(Os).subtract(a).normalize(),b.WGS84.eastNorthUpToFixedFrame(a,Ps),Mn.copy(Ps).invert(),ut.copy(Os).transform(Mn);let h=Math.sqrt(ut[0]*ut[0]+ut[1]*ut[1]),l=h*h/ut[2];Tn.copy([ut[0],ut[1],l]);let u=Tn.transform(Ps).subtract(a).normalize(),x=_n.cross(u).normalize().scale(o).add(a),g=b.WGS84.cartesianToCartographic(x),p=s.project([n,r,i]),_=s.project(g);return ba.copy(p).subtract(_).magnitude()}var Xt=class{_map=new Map;_array;_length;constructor(t=0){this._array=new Array(t),this._length=t}get length(){return this._length}set length(t){this._length=t,t>this._array.length&&(this._array.length=t)}get values(){return this._array}get(t){return K(t<this._array.length),this._array[t]}set(t,s){K(t>=0),t>=this.length&&(this.length=t+1),this._map.has(this._array[t])&&this._map.delete(this._array[t]),this._array[t]=s,this._map.set(s,t)}delete(t){let s=this._map.get(t);s>=0&&(this._array.splice(s,1),this._map.delete(t),this.length--)}peek(){return this._array[this._length-1]}push(t){if(!this._map.has(t)){let s=this.length++;this._array[s]=t,this._map.set(t,s)}}pop(){let t=this._array[--this.length];return this._map.delete(t),t}reserve(t){K(t>=0),t>this._array.length&&(this._array.length=t)}resize(t){K(t>=0),this.length=t}trim(t){t==null&&(t=this.length),this._array.length=t}reset(){this._array=[],this._map=new Map,this._length=0}find(t){return this._map.has(t)}};var Ca={loadSiblings:!1,skipLevelOfDetail:!1,updateTransforms:!0,onTraversalEnd:()=>{},viewportTraversersMap:{},basePath:""},nt=class{options;root=null;selectedTiles={};requestedTiles={};emptyTiles={};lastUpdate=new Date().getTime();updateDebounceTime=1e3;_traversalStack=new Xt;_emptyTraversalStack=new Xt;_frameNumber=null;traversalFinished(t){return!0}constructor(t){this.options={...Ca,...t}}traverse(t,s,r){this.root=t,this.options={...this.options,...r},this.reset(),this.updateTile(t,s),this._frameNumber=s.frameNumber,this.executeTraversal(t,s)}reset(){this.requestedTiles={},this.selectedTiles={},this.emptyTiles={},this._traversalStack.reset(),this._emptyTraversalStack.reset()}executeTraversal(t,s){let r=this._traversalStack;for(t._selectionDepth=1,r.push(t);r.length>0;){let i=r.pop(),o=!1;this.canTraverse(i,s)&&(this.updateChildTiles(i,s),o=this.updateAndPushChildren(i,s,r,i.hasRenderContent?i._selectionDepth+1:i._selectionDepth));let a=i.parent,c=Boolean(!a||a._shouldRefine),h=!o;i.hasRenderContent?i.refine===Z.ADD?(this.loadTile(i,s),this.selectTile(i,s)):i.refine===Z.REPLACE&&(this.loadTile(i,s),h&&this.selectTile(i,s)):(this.emptyTiles[i.id]=i,this.loadTile(i,s),h&&this.selectTile(i,s)),this.touchTile(i,s),i._shouldRefine=o&&c}let n=new Date().getTime();(this.traversalFinished(s)||n-this.lastUpdate>this.updateDebounceTime)&&(this.lastUpdate=n,this.options.onTraversalEnd(s))}updateChildTiles(t,s){let r=t.children;for(let n of r)this.updateTile(n,s)}updateAndPushChildren(t,s,r,n){let{loadSiblings:i,skipLevelOfDetail:o}=this.options,a=t.children;a.sort(this.compareDistanceToCamera.bind(this));let c=t.refine===Z.REPLACE&&t.hasRenderContent&&!o,h=!1,l=!0;for(let d of a)if(d._selectionDepth=n,d.isVisibleAndInRequestVolume?(r.find(d)&&r.delete(d),r.push(d),h=!0):(c||i)&&(this.loadTile(d,s),this.touchTile(d,s)),c){let u;if(d._inRequestVolume?d.hasRenderContent?u=d.contentAvailable:u=this.executeEmptyTraversal(d,s):u=!1,l=l&&u,!l)return!1}return h||(l=!1),l}updateTile(t,s){this.updateTileVisibility(t,s)}selectTile(t,s){this.shouldSelectTile(t)&&(t._selectedFrame=s.frameNumber,this.selectedTiles[t.id]=t)}loadTile(t,s){this.shouldLoadTile(t)&&(t._requestedFrame=s.frameNumber,t._priority=t._getPriority(),this.requestedTiles[t.id]=t)}touchTile(t,s){t.tileset._cache.touch(t),t._touchedFrame=s.frameNumber}canTraverse(t,s){return t.hasChildren?t.hasTilesetContent?!t.contentExpired:this.shouldRefine(t,s):!1}shouldLoadTile(t){return t.hasUnloadedContent||t.contentExpired}shouldSelectTile(t){return t.contentAvailable&&!this.options.skipLevelOfDetail}shouldRefine(t,s,r=!1){let n=t._screenSpaceError;return r&&(n=t.getScreenSpaceError(s,!0)),n>t.tileset.memoryAdjustedScreenSpaceError}updateTileVisibility(t,s){let r=[];if(this.options.viewportTraversersMap)for(let n in this.options.viewportTraversersMap)this.options.viewportTraversersMap[n]===s.viewport.id&&r.push(n);else r.push(s.viewport.id);t.updateVisibility(s,r)}compareDistanceToCamera(t,s){return t._distanceToCamera-s._distanceToCamera}anyChildrenVisible(t,s){let r=!1;for(let n of t.children)n.updateVisibility(s),r=r||n.isVisibleAndInRequestVolume;return r}executeEmptyTraversal(t,s){let r=!0,n=this._emptyTraversalStack;for(n.push(t);n.length>0;){let i=n.pop(),o=!i.hasRenderContent&&this.canTraverse(i,s),a=!i.hasRenderContent&&i.children.length===0;if(!o&&!i.contentAvailable&&!a&&(r=!1),this.updateTile(i,s),i.isVisibleAndInRequestVolume||(this.loadTile(i,s),this.touchTile(i,s)),o){let c=i.children;for(let h of c)n.push(h)}}return t.hasEmptyContent||r}};var Ls=new f;function Aa(e){return e!=null}var tt=class{tileset;header;id;url;parent;refine;type;contentUrl;lodMetricType="geometricError";lodMetricValue=0;_unscaledLodMetricValue=0;boundingVolume=null;content=null;contentState=W.UNLOADED;gpuMemoryUsageInBytes=0;children=[];depth=0;viewportIds=[];transform=new P;extensions=null;implicitTiling=null;userData={};computedTransform;hasEmptyContent=!1;hasTilesetContent=!1;traverser=new nt({});_cacheNode=null;_frameNumber=null;_expireDate=null;_expiredContent=null;_boundingBox=void 0;_distanceToCamera=0;_screenSpaceError=0;_visibilityPlaneMask;_visible=void 0;_contentBoundingVolume;_viewerRequestVolume;_initialTransform=new P;_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(t,s,r,n=""){this.header=s,this.tileset=t,this.id=n||s.id,this.url=s.url,this.parent=r,this.refine=this._getRefine(s.refine),this.type=s.type,this.contentUrl=s.contentUrl,this._initializeLodMetric(s),this._initializeTransforms(s),this._updateLodMetricScale(),this._initializeBoundingVolumes(s),this._initializeContent(s),this._initializeRenderingState(s),Object.seal(this)}destroy(){this.header=null}isDestroyed(){return this.header===null}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===W.READY||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===W.UNLOADED}get contentExpired(){return this.contentState===W.EXPIRED}get contentFailed(){return this.contentState===W.FAILED}get distanceToCamera(){return this._distanceToCamera}get screenSpaceError(){return this._screenSpaceError}get boundingBox(){return this._boundingBox||(this._boundingBox=mn(this.header.boundingVolume,this.boundingVolume)),this._boundingBox}getScreenSpaceError(t,s){switch(this.tileset.type){case J.I3S:return Ns(this,t);case J.TILES3D:return gn(this,t,s);default:throw new Error("Unsupported tileset type")}}unselect(){this._selectedFrame=0}_getGpuMemoryUsageInBytes(){return this.content.gpuMemoryUsageInBytes||this.content.byteLength||0}_getPriority(){let t=this.tileset._traverser,{skipLevelOfDetail:s}=t.options,r=this.refine===Z.ADD||s;if(r&&!this.isVisible&&this._visible!==void 0||this.tileset._frameNumber-this._touchedFrame>=1||this.contentState===W.UNLOADED)return-1;let n=this.parent,o=n&&(!r||this._screenSpaceError===0||n.hasTilesetContent)?n._screenSpaceError:this._screenSpaceError,a=t.root?t.root._screenSpaceError:0;return Math.max(a-o,0)}async loadContent(){if(this.hasEmptyContent)return{loaded:!1};if(this.content)return{loaded:!0};this.contentExpired&&(this._expireDate=null),this.contentState=W.LOADING;let s=await this.tileset._requestScheduler.scheduleRequest(this.id,this._getPriority.bind(this));if(!s)return this.contentState=W.UNLOADED,{loaded:!1};try{let r=await this.tileset.source.loadTileContent(this);return this.tileset.options.contentLoader&&await this.tileset.options.contentLoader(this),this.contentState=W.READY,this._onContentLoaded(),r}catch(r){throw this.contentState=W.FAILED,r}finally{s.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=W.UNLOADED,this.tileDrawn=!0,!0}updateVisibility(t,s){if(this._frameNumber===t.frameNumber)return;let r=this.parent,n=r?r._visibilityPlaneMask:U.MASK_INDETERMINATE;if(this.tileset._traverser.options.updateTransforms){let i=r?r.computedTransform:this.tileset.modelMatrix;this._updateTransform(i)}this._distanceToCamera=this.distanceToTile(t),this._screenSpaceError=this.getScreenSpaceError(t,!1),this._visibilityPlaneMask=this.visibility(t,n),this._visible=this._visibilityPlaneMask!==U.MASK_OUTSIDE,this._inRequestVolume=this.insideViewerRequestVolume(t),this._frameNumber=t.frameNumber,this.viewportIds=s}visibility(t,s){let{cullingVolume:r}=t,{boundingVolume:n}=this;return r.computeVisibilityWithPlaneMask(n,s)}contentVisibility(){return!0}distanceToTile(t){let s=this.boundingVolume;return Math.sqrt(Math.max(s.distanceSquaredTo(t.camera.position),0))}cameraSpaceZDepth({camera:t}){let s=this.boundingVolume;return Ls.subVectors(s.center,t.position),t.direction.dot(Ls)}insideViewerRequestVolume(t){let s=this._viewerRequestVolume;return!s||s.distanceSquaredTo(t.camera.position)<=0}updateExpiration(){if(Aa(this._expireDate)&&this.contentReady&&!this.hasEmptyContent){let t=Date.now();Date.lessThan(this._expireDate,t)&&(this.contentState=W.EXPIRED,this._expiredContent=this.content)}}get extras(){return this.header.extras}_initializeLodMetric(t){"lodMetricType"in t?this.lodMetricType=t.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 t?this._unscaledLodMetricValue=t.lodMetricValue:(this._unscaledLodMetricValue=this.parent?this.parent._unscaledLodMetricValue:this.tileset.lodMetricValue,console.warn("3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue")),this.lodMetricValue=this._unscaledLodMetricValue}_initializeTransforms(t){this.transform=t.transform?new P(t.transform):new P;let s=this.parent,r=this.tileset,n=s&&s.computedTransform?s.computedTransform.clone():r.modelMatrix.clone();this.computedTransform=new P(n).multiplyRight(this.transform);let i=s&&s._initialTransform?s._initialTransform.clone():new P;this._initialTransform=new P(i).multiplyRight(this.transform)}_updateLodMetricScale(){if(this.lodMetricType!==Pt.GEOMETRIC_ERROR){this.lodMetricValue=this._unscaledLodMetricValue;return}let t=this.computedTransform.getScale(Ls),s=Math.max(t[0],t[1],t[2]);this.lodMetricValue=this._unscaledLodMetricValue*s}_initializeBoundingVolumes(t){this._contentBoundingVolume=null,this._viewerRequestVolume=null,this._updateBoundingVolume(t)}_initializeContent(t){this.content={_tileset:this.tileset,_tile:this},this.hasEmptyContent=!0,this.contentState=W.UNLOADED,this.hasTilesetContent=!1,t.contentUrl&&(this.content=null,this.hasEmptyContent=!1)}_initializeRenderingState(t){this.depth=t.level||(this.parent?this.parent.depth+1:0),this._shouldRefine=!1,this._distanceToCamera=0,this._centerZDepth=0,this._screenSpaceError=0,this._visibilityPlaneMask=U.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(t){return t||this.parent&&this.parent.refine||Z.REPLACE}_isTileset(){return this.contentUrl.indexOf(".json")!==-1}_onContentLoaded(){switch(this.content&&this.content.type){case"vctr":case"geom":this.tileset._traverser.disableSkipLevelOfDetail=!0;break;default:}this._isTileset()?this.hasTilesetContent=!0:this.gpuMemoryUsageInBytes=this._getGpuMemoryUsageInBytes()}_updateBoundingVolume(t){this.boundingVolume=Nt(t.boundingVolume,this.computedTransform,this.boundingVolume);let s=t.content;s&&(s.boundingVolume&&(this._contentBoundingVolume=Nt(s.boundingVolume,this.computedTransform,this._contentBoundingVolume)),t.viewerRequestVolume&&(this._viewerRequestVolume=Nt(t.viewerRequestVolume,this.computedTransform,this._viewerRequestVolume)))}_updateTransform(t=new P){let s=t.clone().multiplyRight(this.transform);s.equals(this.computedTransform)||(this.computedTransform=s,this._updateLodMetricScale(),this._updateBoundingVolume(this.header))}};var Pe=class extends nt{compareDistanceToCamera(t,s){return s._distanceToCamera===0&&t._distanceToCamera===0?s._centerZDepth-t._centerZDepth:s._distanceToCamera-t._distanceToCamera}updateTileVisibility(t,s){if(super.updateTileVisibility(t,s),!t.isVisibleAndInRequestVolume)return;let r=t.children.length>0;if(t.hasTilesetContent&&r){let o=t.children[0];this.updateTileVisibility(o,s),t._visible=o._visible;return}if(this.meetsScreenSpaceErrorEarly(t,s)){t._visible=!1;return}let n=t.refine===Z.REPLACE,i=t._optimChildrenWithinParent===cn.USE_OPTIMIZATION;if(n&&i&&r&&!this.anyChildrenVisible(t,s)){t._visible=!1;return}}meetsScreenSpaceErrorEarly(t,s){let{parent:r}=t;return!r||r.hasTilesetContent||r.refine!==Z.ADD?!1:!this.shouldRefine(t,s,!0)}};var Oa=6378137,Pa=6378137,Is=6356752314245179e-9,Lt=new f;function yn(e,t){if(e instanceof rt){let{halfAxes:s}=e,r=Na(s);return Math.log2(Is/(r+t[2]))}else if(e instanceof G){let{radius:s}=e;return Math.log2(Is/(s+t[2]))}else if(e.width&&e.height){let{width:s,height:r}=e,n=Math.log2(Oa/s),i=Math.log2(Pa/r);return(n+i)/2}return 1}function vs(e,t,s){b.WGS84.cartographicToCartesian([e.xmax,e.ymax,e.zmax],Lt);let r=Math.sqrt(Math.pow(Lt[0]-s[0],2)+Math.pow(Lt[1]-s[1],2)+Math.pow(Lt[2]-s[2],2));return Math.log2(Is/(r+t[2]))}function Sn(e,t,s){let[r,n,i,o]=e;return vs({xmin:r,xmax:i,ymin:n,ymax:o,zmin:0,zmax:0},t,s)}function Na(e){e.getColumn(0,Lt);let t=e.getColumn(1),s=e.getColumn(2);return Lt.add(t).add(s).len()}var La={draco:!1,meshopt:!1,dds:!1,ktx2:!1},Ne=class{type=J.TILES3D;loader;url;basePath;tileset=null;loadOptions;coreApi;contentFormats={...La};asset;properties;extras;credits;metadata;queryParams={};extensionsUsed=[];resolver;rootTileset;constructor(t,s={}){let r=Ia(t);this.rootTileset=En(t)?null:t,this.tileset=this.rootTileset,this.loader=r.loader,this.url=r.url,this.basePath=r.basePath||Q.dirname(r.url),this.resolver=r.resolver,this.coreApi=r.coreApi,this.loadOptions=s}async initialize(){if(!this.rootTileset){let t=this.loadOptions[this.loader.id]||{};this.rootTileset=await this.loadRootData(this.url,{...this.loadOptions,[this.loader.id]:{...t,isTileset:!0}})}if(this.tileset=this.rootTileset,this.rootTileset.queryString){let t=new URLSearchParams(this.rootTileset.queryString);Object.assign(this.queryParams,Object.fromEntries(t.entries()))}if(this.asset=this.rootTileset.asset,!this.asset)throw new Error("Tileset must have an asset property.");if(this.asset.version!=="0.0"&&this.asset.version!=="1.0"&&this.asset.version!=="1.1")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.properties=this.rootTileset.properties,this.extras=this.rootTileset.extras,this.credits={attributions:[]},this.extensionsUsed.splice(0,this.extensionsUsed.length,...this.rootTileset.extensionsUsed||[]),this.metadata={type:this.type,loader:this.loader,url:this.url,basePath:this.basePath,tileset:this.rootTileset,lodMetricType:this.rootTileset.lodMetricType,lodMetricValue:this.rootTileset.lodMetricValue,refine:this.rootTileset.root?.refine}}getMetadata(){if(!this.metadata)throw new Error("Tiles3DSource has not been initialized");return this.metadata}async getRootTileset(){return this.getMetadata().tileset}initializeTileHeaders(t,s,r){let n=new tt(t,s.root,r||void 0);r&&(r.children.push(n),n.depth=r.depth+1);let i=[n];for(;i.length>0;){let o=i.pop();t.stats.get("Tiles In Tileset(s)").incrementCount();let a=o.header.children||[];for(let c of a){let h=new tt(t,c,o);if(h.contentUrl?.includes("?session=")){let d=new URL(h.contentUrl).searchParams.get("session");d&&(this.queryParams.session=d)}o.children.push(h),h.depth=o.depth+1,i.push(h)}}return n}createTraverser(t){return new Pe(t)}async loadTileContent(t){let s=this.getTileUrl(t.contentUrl),r=this.loadOptions[this.loader.id]||{},n={...this.loadOptions,[this.loader.id]:{...r,isTileset:t.type==="json",assetGltfUpAxis:this.asset&&this.asset.gltfUpAxis||"Y"}},i=await this.loadResourceData(s,n);return t.content=i,{loaded:!0,nestedTileset:t.contentUrl.includes(".json")?i:void 0}}getTileUrl(t){if(t.startsWith("data:")||!Object.keys(this.queryParams).length)return t;let[s,r=""]=t.split("?"),n=new URLSearchParams(r);for(let[o,a]of Object.entries(this.queryParams))n.has(o)||n.set(o,a);let i=n.toString();return i?`${s}?${i}`:s}getViewState(t){if(!t)return{asset:this.asset,properties:this.properties,extras:this.extras,credits:this.credits};let{center:s}=t.boundingVolume,r;return s&&(s[0]!==0||s[1]!==0||s[2]!==0)?(r=new f,b.WGS84.cartesianToCartographic(s,r)):r=new f(0,0,-b.WGS84.radii[0]),{asset:this.asset,properties:this.properties,extras:this.extras,credits:this.credits,boundingVolume:t.boundingVolume,cartographicCenter:r,cartesianCenter:s,zoom:yn(t.boundingVolume,r)}}hasExtension(t){return this.extensionsUsed.includes(t)}onTileLoaded(t,s,r){let{extensionsRemoved:n=[]}=s.content?.gltf||{};n.includes("KHR_draco_mesh_compression")&&(this.contentFormats.draco=!0),n.includes("EXT_meshopt_compression")&&(this.contentFormats.meshopt=!0),n.includes("KHR_texture_basisu")&&(this.contentFormats.ktx2=!0),r.nestedTileset&&t._initializeTileHeaders(r.nestedTileset,s)}async loadWithCoreApi(t,s){if(!this.coreApi)throw new Error("Tiles3DSource requires an injected coreApi to load tileset data");return await this.coreApi.load(t,this.loader,s)}async loadRootData(t,s){return this.resolver?await this.resolver.loadRoot(t,this.loader,s):await this.loadWithCoreApi(t,s)}async loadResourceData(t,s){return this.resolver?await this.resolver.loadResource(t,this.loader,s):await this.loadWithCoreApi(t,s)}};function En(e){return Boolean(e&&typeof e=="object"&&"url"in e&&"loader"in e&&!("type"in e))}function Ia(e){return En(e)?{...e,basePath:e.basePath||Q.dirname(e.url)}:{url:e.url,loader:e.loader,basePath:e.basePath||Q.dirname(e.url),resolver:e.resolver,coreApi:e.coreApi}}var Le=class{frameNumberMap=new Map;register(t,s){let r=this.frameNumberMap.get(t)||new Map,n=r.get(s)||0;r.set(s,n+1),this.frameNumberMap.set(t,r)}deregister(t,s){let r=this.frameNumberMap.get(t);if(!r)return;let n=r.get(s)||1;r.set(s,n-1)}isZero(t,s){return(this.frameNumberMap.get(t)?.get(s)||0)===0}};var zs={REQUESTED:"REQUESTED",COMPLETED:"COMPLETED",ERROR:"ERROR"},Ie=class{_statusMap;pendingTilesRegister=new Le;constructor(){this._statusMap={}}add(t,s,r,n){if(!this._statusMap[s]){let{frameNumber:i,viewport:{id:o}}=n;this._statusMap[s]={request:t,callback:r,key:s,frameState:n,status:zs.REQUESTED},this.pendingTilesRegister.register(o,i),t().then(a=>{this._statusMap[s].status=zs.COMPLETED;let{frameNumber:c,viewport:{id:h}}=this._statusMap[s].frameState;this.pendingTilesRegister.deregister(h,c),this._statusMap[s].callback(a,n)}).catch(a=>{this._statusMap[s].status=zs.ERROR;let{frameNumber:c,viewport:{id:h}}=this._statusMap[s].frameState;this.pendingTilesRegister.deregister(h,c),r(a)})}}update(t,s){if(this._statusMap[t]){let{frameNumber:r,viewport:{id:n}}=this._statusMap[t].frameState;this.pendingTilesRegister.deregister(n,r);let{frameNumber:i,viewport:{id:o}}=s;this.pendingTilesRegister.register(o,i),this._statusMap[t].frameState=s}}find(t){return this._statusMap[t]}hasPendingTiles(t,s){return!this.pendingTilesRegister.isZero(t,s)}};var ve=class extends nt{_tileManager;constructor(t){super(t),this._tileManager=new Ie}traversalFinished(t){return!this._tileManager.hasPendingTiles(t.viewport.id,this._frameNumber||0)}shouldRefine(t,s){return t._lodJudge=Oe(t,s),t._lodJudge==="DIG"}updateChildTiles(t,s){let r=t.header.children||[],n=t.children;for(let i of r){let o=`${i.id}-${s.viewport.id}`,a=n&&n.find(c=>c.id===o);if(a)a&&this.updateTile(a,s);else{let c=()=>this._loadTile(t,i.id,s);this._tileManager.find(o)?this._tileManager.update(o,s):this._tileManager.add(c,o,l=>this._onTileLoad(l,t,o),s)}}return!1}async _loadTile(t,s,r){if(!t.tileset.source.loadChildTileHeader)throw new Error("I3S source does not support child tile header loading");return await t.tileset.source.loadChildTileHeader(t,s,r)}_onTileLoad(t,s,r){if(t instanceof Error){s.tileset._onSourceError(t,s);return}let n=new tt(s.tileset,t,s,r);s.children.push(n);let i=this._tileManager.find(n.id).frameState;this.updateTile(n,i),this._frameNumber===i.frameNumber&&(this.traversalFinished(i)||new Date().getTime()-this.lastUpdate>this.updateDebounceTime)&&this.executeTraversal(n,i)}};var va={draco:!1,meshopt:!1,dds:!1,ktx2:!1},ze=class{type=J.I3S;loader;url;basePath;tileset=null;loadOptions;coreApi;contentFormats={...va};asset;properties;extras;credits;metadata;queryParams={};resolver;rootTileset;constructor(t,s={}){let r=za(t);this.rootTileset=Rn(t)?null:t,this.tileset=this.rootTileset,this.loader=r.loader,this.url=r.url,this.basePath=r.basePath||Q.dirname(r.url),this.resolver=r.resolver,this.coreApi=r.coreApi,this.loadOptions=s}async initialize(){this.rootTileset||(this.rootTileset=await this.loadRootData(this.url,this.loadOptions)),this.tileset=this.rootTileset,this.rootTileset.root&&typeof this.rootTileset.root.then=="function"&&(this.rootTileset.root=await this.rootTileset.root);let t=this.loadOptions.i3s;if(t&&typeof t=="object"&&"token"in t){let s=t.token;typeof s=="string"&&(this.queryParams.token=s)}this.metadata={type:this.type,loader:this.loader,url:this.url,basePath:this.basePath,tileset:this.rootTileset,lodMetricType:this.rootTileset.lodMetricType,lodMetricValue:this.rootTileset.lodMetricValue,refine:this.rootTileset.root?.refine}}getMetadata(){if(!this.metadata)throw new Error("I3SSource has not been initialized");return this.metadata}async getRootTileset(){return this.getMetadata().tileset}initializeTileHeaders(t,s,r){let n=new tt(t,s.root,r||void 0);return r&&(r.children.push(n),n.depth=r.depth+1),n}createTraverser(t){return new ve(t)}async loadTileContent(t){let s=this.getTileUrl(t.contentUrl),r=this.loader.id,n=this.loadOptions[r]||{},i=this.getMetadata(),o={...this.loadOptions,[r]:{...n,...t.tileset.options.i3s,_tileOptions:{attributeUrls:t.header.attributeUrls,textureUrl:t.header.textureUrl,textureFormat:t.header.textureFormat,textureLoaderOptions:t.header.textureLoaderOptions,materialDefinition:t.header.materialDefinition,isDracoGeometry:t.header.isDracoGeometry,mbs:t.header.mbs},_tilesetOptions:{store:i.tileset.store,attributeStorageInfo:i.tileset.attributeStorageInfo,fields:i.tileset.fields},isTileHeader:!1}};return t.content=await this.loadResourceData(s,o),{loaded:!0}}async loadChildTileHeader(t,s,r){let n=this.getMetadata();if(n.tileset.nodePages)return await n.tileset.nodePagesTile.formTileFromNodePages(s);let i=this.getTileUrl(`${this.url}/nodes/${s}`),o=this.loadOptions.i3s&&typeof this.loadOptions.i3s=="object"?this.loadOptions.i3s:{},a={...this.loadOptions,i3s:{...o,isTileHeader:!0}};return await this.loadResourceData(i,a)}getTileUrl(t){if(t.startsWith("data:")||!Object.keys(this.queryParams).length)return t;let s=new URLSearchParams(this.queryParams).toString();return`${t}${t.includes("?")?"&":"?"}${s}`}getViewState(t){let s=this.getMetadata(),r=s.tileset.fullExtent;if(r){let{xmin:i,xmax:o,ymin:a,ymax:c,zmin:h,zmax:l}=r,d=new f(i+(o-i)/2,a+(c-a)/2,h+(l-h)/2),u=new f;return b.WGS84.cartographicToCartesian(d,u),{cartographicCenter:d,cartesianCenter:u,zoom:vs(r,d,u)}}let n=s.tileset.store?.extent;if(n){let[i,o,a,c]=n,h=new f(i+(a-i)/2,o+(c-o)/2,0),l=new f;return b.WGS84.cartographicToCartesian(h,l),{cartographicCenter:h,cartesianCenter:l,zoom:Sn(n,h,l)}}return console.warn("Extent is not defined in the tileset header"),{cartographicCenter:new f,zoom:1}}onTileLoaded(t,s){switch(s.header.isDracoGeometry&&(this.contentFormats.draco=!0),s.header.textureFormat){case"dds":this.contentFormats.dds=!0;break;case"ktx2":this.contentFormats.ktx2=!0;break;default:}}getTilesTotalCount(){return this.getMetadata().tileset?.nodePagesTile?.nodesInNodePages||null}async loadWithCoreApi(t,s){if(!this.coreApi)throw new Error("I3SSource requires an injected coreApi to load tileset data");return await this.coreApi.load(t,this.loader,s)}async loadRootData(t,s){return this.resolver?await this.resolver.loadRoot(t,this.loader,s):await this.loadWithCoreApi(t,s)}async loadResourceData(t,s){return this.resolver?await this.resolver.loadResource(t,this.loader,s):await this.loadWithCoreApi(t,s)}};function Rn(e){return Boolean(e&&typeof e=="object"&&"url"in e&&"loader"in e&&!("type"in e))}function za(e){return Rn(e)?{...e,basePath:e.basePath||Q.dirname(e.url)}:{url:e.url,loader:e.loader,basePath:e.basePath||Q.dirname(e.url),resolver:e.resolver,coreApi:e.coreApi}}var Mt=class{index;parent;children;content;error;id;zoom;userData;boundingBox;_abortController;_loader;_loaderId;_isLoaded;_isCancelled;_needsReload;_bbox;constructor(t){this.index=t,this.parent=null,this.children=[],this.content=null,this.error=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(t){this._bbox||(this._bbox=t,"west"in t?this.boundingBox=[[t.west,t.south],[t.east,t.north]]:this.boundingBox=[[t.left,t.top],[t.right,t.bottom]])}get data(){let t=this._loader;return!this._isCancelled&&t!==void 0?t.then(()=>this.data):this.content}get isLoaded(){return this._isLoaded&&!this._needsReload}get isLoading(){return Boolean(this._loader)&&!this._isCancelled}get hasError(){return Boolean(this.error)}get needsReload(){return this._needsReload||this._isCancelled}get byteLength(){let t=this.content?this.content.byteLength:0;return Number.isFinite(t)?t:0}async _loadData({getData:t,requestScheduler:s,onLoad:r,onError:n}){let i=(p,_,E)=>{if(E===this._loaderId){if(this._loader=void 0,this.content=p,this.error=_?qa(_):null,this._isCancelled&&!p){this._isLoaded=!1;return}if(this._isLoaded=!0,this._isCancelled=!1,_){n(_,this);return}r(this)}},{index:o,id:a,bbox:c,userData:h,zoom:l}=this,d=this._loaderId;this._abortController=new AbortController;let{signal:u}=this._abortController,m=await s.scheduleRequest(this,()=>1);if(!m){this._isCancelled=!0;return}if(this._isCancelled){m.done();return}let x=null,g;try{x=await t({index:o,id:a,bbox:c,userData:h,zoom:l,signal:u})}catch(p){g=p||!0}finally{m.done()}i(x,g,d)}loadData(t){return this._isLoaded=!1,this._isCancelled=!1,this._needsReload=!1,this.error=null,this._loaderId++,this._loader=this._loadData(t),this._loader}setNeedsReload(){this.isLoading&&(this.abort(),this._loader=void 0),this._needsReload=!0}abort(){this.isLoaded||(this._isCancelled=!0,this._abortController?.abort())}};function qa(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Tile request failed")}var qs="never",Vs="no-overlap",Qt="best-available",wn={adapter:null,extent:null,tileSize:512,maxZoom:null,minZoom:null,maxCacheSize:100,maxCacheByteSize:null,refinementStrategy:Qt,zRange:null,maxRequests:6,debounceTime:0,zoomOffset:0,onTileLoad:()=>{},onTileUnload:()=>{},onTileError:()=>{},tileSource:null},yt=class{stats;sourceMetadata=null;opts;_requestScheduler;_cache;_dirty;_tiles;_cacheByteSize;_unloadedTileCount;_listeners=new Set;_consumers=new Map;_explicitOptionKeys=new Set;_baseOpts={};_sourceMetadataOverrides={};_maxZoom;_minZoom;_lastTileContext=null;constructor(t){if(this.stats=new st({id:"Tileset2D",stats:[{name:"Tiles In Cache"},{name:"Cache Size"},{name:"Visible Tiles"},{name:"Selected Tiles"},{name:"Loading Tiles"},{name:"Unloaded Tiles"},{name:"Consumers"}]}),this.opts={...wn,...t,getTileData:t.getTileData||(()=>null),tileSource:t.tileSource},this._requestScheduler=new at({throttleRequests:this.opts.maxRequests>0||this.opts.debounceTime>0,maxRequests:this.opts.maxRequests,debounceTime:this.opts.debounceTime}),this._cache=new Map,this._tiles=[],this._dirty=!1,this._cacheByteSize=0,this._unloadedTileCount=0,!this.opts.tileSource&&!t.getTileData)throw new Error("Tileset2D requires either `getTileData` or `tileSource`.");this.setOptions(t),this._updateStats(),this.opts.tileSource&&this._initializeTileSource(this.opts.tileSource).catch(()=>{})}static fromTileSource(t,s={}){return new yt({...s,tileSource:t})}get tiles(){return this._tiles}get cacheByteSize(){return this._cacheByteSize}get selectedTiles(){return Array.from(this._getSelectedTilesUnion())}get visibleTiles(){let t=this._getVisibleTilesUnion();for(let s of this._getSelectedTilesUnion())t.add(s);return Array.from(t)}get loadingTiles(){return Array.from(this._cache.values()).filter(t=>t.isLoading)}get unloadedTiles(){return Array.from(this._cache.values()).filter(t=>!t.isLoaded)}get maxZoom(){return this._maxZoom}get minZoom(){return this._minZoom}get refinementStrategy(){return this.opts.refinementStrategy||Qt}get adapter(){return this.opts.adapter}subscribe(t){return this._listeners.add(t),()=>this._listeners.delete(t)}attachConsumer(t){this._consumers.set(t,{selectedTiles:new Set,visibleTiles:new Set}),this._updateStats()}detachConsumer(t){this._consumers.delete(t),this._pruneRequests(),this._resizeCache(),this._updateStats()}setOptions(t){this._rememberExplicitOptions(t),this._baseOpts={...this._baseOpts,...t};let s=this.opts.maxRequests,r=this.opts.debounceTime;this._applyResolvedOptions(),(s!==this.opts.maxRequests||r!==this.opts.debounceTime)&&(this._requestScheduler=new at({throttleRequests:this.opts.maxRequests>0||this.opts.debounceTime>0,maxRequests:this.opts.maxRequests,debounceTime:this.opts.debounceTime}))}finalize(){for(let t of this._cache.values())t.isLoading&&t.abort();this._cache.clear(),this._tiles=[],this._consumers.clear(),this._cacheByteSize=0,this._unloadedTileCount=0,this._updateStats()}reloadAll(){let t=this._getSelectedTilesUnion();for(let s of this._cache.keys()){let r=this._cache.get(s);r&&!t.has(r)?(this._cache.delete(s),this._handleTileUnload(r),this._dirty=!0):r&&r.setNeedsReload()}this._cacheByteSize=this._getCacheByteSize(),this.prepareTiles(),this._updateStats()}updateConsumer(t,s,r){this._consumers.set(t,{selectedTiles:new Set(s),visibleTiles:new Set(r)}),this._pruneRequests(),this._resizeCache(),this._updateStats()}prepareTiles(){this._dirty&&(this._rebuildTree(),this._syncTiles(),this._dirty=!1)}getTileIndices({viewState:t,maxZoom:s,minZoom:r,zRange:n,modelMatrix:i,modelMatrixInverse:o}){let{adapter:a,tileSize:c,extent:h,zoomOffset:l}=this.opts;if(!a)throw new Error("Tileset2D requires an adapter before tile traversal can be used.");return this._lastTileContext={viewState:t,tileSize:c},a.getTileIndices({viewState:t,maxZoom:s,minZoom:r,zRange:n,tileSize:c,extent:Va(h),modelMatrix:i,modelMatrixInverse:o,zoomOffset:l})}getTileId(t){return`${t.x}-${t.y}-${t.z}`}getTileZoom(t){return t.z}getTileMetadata(t){if(!this._lastTileContext)throw new Error("Tileset2D metadata requested before traversal context was set.");if(!this.opts.adapter)throw new Error("Tileset2D requires an adapter before tile metadata can be derived.");return{bbox:this.opts.adapter.getTileBoundingBox(this._lastTileContext,t)}}getParentIndex(t){return{x:Math.floor(t.x/2),y:Math.floor(t.y/2),z:t.z-1}}getTile(t,s){let r=this.getTileId(t),n=this._cache.get(r),i=!1;return!n&&s?(n=new Mt(t),Object.assign(n,this.getTileMetadata(n.index)),Object.assign(n,{id:r,zoom:this.getTileZoom(n.index)}),i=!0,this._cache.set(r,n),this._dirty=!0,this._updateStats()):n&&n.needsReload&&(i=!0),n&&this._touchTile(r,n),n&&i&&s&&(n.loadData({getData:this.opts.getTileData,requestScheduler:this._requestScheduler,onLoad:this._handleTileLoad.bind(this),onError:this._handleTileError.bind(this)}).catch(()=>{}),this._updateStats()),n}async _initializeTileSource(t){try{this.sourceMetadata=await t.getMetadata(),this._sourceMetadataOverrides=this._getMetadataOverrides(this.sourceMetadata),this._applyResolvedOptions(),this._notifyUpdate()}catch(s){let r=s instanceof Error?s:new Error(`TileSource metadata error: ${String(s)}`);this._notifyError(r)}}_rememberExplicitOptions(t){for(let s of Object.keys(t))this._explicitOptionKeys.add(s)}_applyResolvedOptions(){let t={...wn,...this._sourceMetadataOverrides,...this._baseOpts};if(t.tileSource){let s=t.tileSource;t.getTileData=r=>s.getTileData(r)}this.opts=t,this._maxZoom=typeof this.opts.maxZoom=="number"&&Number.isFinite(this.opts.maxZoom)?Math.floor(this.opts.maxZoom):void 0,this._minZoom=typeof this.opts.minZoom=="number"&&Number.isFinite(this.opts.minZoom)?Math.ceil(this.opts.minZoom):void 0}_getMetadataOverrides(t){if(!t)return{};let s={};return!this._explicitOptionKeys.has("minZoom")&&Number.isFinite(t.minZoom)&&(s.minZoom=t.minZoom),!this._explicitOptionKeys.has("maxZoom")&&Number.isFinite(t.maxZoom)&&(s.maxZoom=t.maxZoom),!this._explicitOptionKeys.has("extent")&&t.boundingBox&&(s.extent=[t.boundingBox[0][0],t.boundingBox[0][1],t.boundingBox[1][0],t.boundingBox[1][1]]),s}_handleTileLoad(t){this.opts.onTileLoad?.(t),this._cacheByteSize=this._getCacheByteSize(),this._resizeCache();for(let s of this._listeners)s.onTileLoad?.(t);this._updateStats()}_handleTileError(t,s){this.opts.onTileError?.(t,s);for(let r of this._listeners)r.onTileError?.(t,s);this._updateStats()}_handleTileUnload(t){this._unloadedTileCount++,this.opts.onTileUnload?.(t);for(let s of this._listeners)s.onTileUnload?.(t);this._updateStats()}_notifyUpdate(){for(let t of this._listeners)t.onUpdate?.()}_notifyError(t){for(let s of this._listeners)s.onError?.(t)}_updateStats(){this._setStatCount("Tiles In Cache",this._cache.size),this._setStatCount("Cache Size",this.cacheByteSize),this._setStatCount("Visible Tiles",this.visibleTiles.length),this._setStatCount("Selected Tiles",this.selectedTiles.length),this._setStatCount("Loading Tiles",this.loadingTiles.length),this._setStatCount("Unloaded Tiles",this._unloadedTileCount),this._setStatCount("Consumers",this._consumers.size);for(let t of this._listeners)t.onStatsChange?.(this.stats)}_setStatCount(t,s){this.stats.get(t).reset().addCount(s)}_getSelectedTilesUnion(){let t=new Set;for(let s of this._consumers.values())for(let r of s.selectedTiles)t.add(r);return t}_getVisibleTilesUnion(){let t=new Set;for(let s of this._consumers.values())for(let r of s.visibleTiles)t.add(r);return t}_touchTile(t,s){this._cache.delete(t),this._cache.set(t,s)}_getCacheByteSize(){let t=0;for(let s of this._cache.values())t+=s.byteLength;return t}_pruneRequests(){let{maxRequests:t=0}=this.opts,s=this._getSelectedTilesUnion(),r=this._getVisibleTilesUnion(),n=[],i=0;for(let o of this._cache.values())o.isLoading&&(i++,!s.has(o)&&!r.has(o)&&n.push(o));for(;t>0&&i>t&&n.length>0;){let o=n.shift();o&&o.abort(),i--}}_rebuildTree(){for(let t of this._cache.values())t.parent=null,t.children&&(t.children.length=0);for(let t of this._cache.values()){let s=this._getNearestAncestor(t);t.parent=s,s?.children&&s.children.push(t)}}_syncTiles(){this._tiles=Array.from(this._cache.values()).sort((t,s)=>t.zoom-s.zoom)}_resizeCache(){let t=this.opts.maxCacheSize??100,s=this.opts.maxCacheByteSize??1/0,r=this._getVisibleTilesUnion(),n=this._getSelectedTilesUnion();if(this._cache.size>t||this._cacheByteSize>s){for(let[o,a]of this._cache)if(!r.has(a)&&!n.has(a)&&(this._cache.delete(o),this._cacheByteSize=this._getCacheByteSize(),this._handleTileUnload(a)),this._cache.size<=t&&this._cacheByteSize<=s)break;this._dirty=!0}this._dirty&&(this._rebuildTree(),this._syncTiles(),this._dirty=!1)}_getNearestAncestor(t){let{_minZoom:s=0}=this,r=t.index;for(;this.getTileZoom(r)>s;){r=this.getParentIndex(r);let n=this.getTile(r);if(n)return n}return null}};function Va(e){return e&&e.length===4?e:void 0}var qe={getMetadata:async()=>({name:"",keywords:[],layers:[]}),getImage:async()=>null,debounceTime:0},It=class{metadata=null;_opts;_listeners=new Set;_currentRequest=null;_lastAcceptedRequestId=-1;_nextRequestId=0;_loadCounter=0;_timeoutId=null;_abortController=null;_finalized=!1;constructor(t){if(this._opts=this._normalizeOptions(t),!this._opts.imageSource&&(!t.getImage||!t.getMetadata))throw new Error("ImageSet requires either `imageSource` or both `getImage` and `getMetadata`.")}static fromImageSource(t,s={}){return new It({...s,imageSource:t})}get isLoaded(){return this._loadCounter===0&&Boolean(this._currentRequest)}get image(){return this._currentRequest?.image||null}get currentRequest(){return this._currentRequest}get imageSource(){return this._opts.imageSource}subscribe(t){return this._listeners.add(t),()=>this._listeners.delete(t)}setOptions(t){let s=this._opts.imageSource,r=this._normalizeOptions({...this._opts,...t}),n=s!==r.imageSource||this._opts.getImage!==r.getImage||this._opts.getMetadata!==r.getMetadata;this._opts=r,n&&(this._cancelScheduledImage(),this.metadata=null,this._currentRequest=null,this._lastAcceptedRequestId=-1,this._nextRequestId=0,this._emitUpdate())}async loadMetadata(){this._startLoading();try{let t=await this._opts.getMetadata();if(this._finalized)return t;this.metadata=t;for(let s of this._listeners)s.onMetadataLoad?.(t);return this._emitUpdate(),t}catch(t){let s=bn(t,"Image metadata request failed");if(!this._finalized)for(let r of this._listeners)r.onMetadataLoadError?.(s);throw s}finally{this._finishLoading()}}requestImage(t,s=this._opts.debounceTime){let r=this._nextRequestId++;return this._cancelScheduledImage(),this._abortActiveRequest(),s>0?this._timeoutId=setTimeout(()=>{this._timeoutId=null,this._loadImage(r,t)},s):this._loadImage(r,t),r}finalize(){this._finalized=!0,this._cancelScheduledImage(),this._abortActiveRequest(),this._listeners.clear()}async _loadImage(t,s){if(!this._finalized){this._startLoading();for(let r of this._listeners)r.onImageLoadStart?.(t,s);try{let r=new AbortController;this._abortController=r;let n=await this._opts.getImage({...s,signal:r.signal});if(this._finalized||t<=this._lastAcceptedRequestId)return;this._lastAcceptedRequestId=t,this._currentRequest={requestId:t,parameters:s,image:n};for(let i of this._listeners)i.onImageLoad?.(this._currentRequest);this._emitUpdate()}catch(r){if(Da(r))return;let n=bn(r,"Image request failed");if(!this._finalized)for(let i of this._listeners)i.onImageLoadError?.(t,n,s)}finally{this._abortController?.signal===s.signal&&(this._abortController=null),this._finishLoading()}}}_normalizeOptions(t){let s=t.imageSource||null;return{...qe,...t,imageSource:s,getMetadata:t.getMetadata||(()=>s?s.getMetadata():qe.getMetadata()),getImage:t.getImage||(r=>s?s.getImage(r):qe.getImage(r)),debounceTime:t.debounceTime??qe.debounceTime}}_emitUpdate(){for(let t of this._listeners)t.onUpdate?.()}_startLoading(){let t=this._loadCounter>0;this._loadCounter++,t||(this._emitLoadingStateChange(!0),this._emitUpdate())}_finishLoading(){let t=this._loadCounter>0;this._loadCounter=Math.max(0,this._loadCounter-1),t&&this._loadCounter===0&&(this._emitLoadingStateChange(!1),this._emitUpdate())}_emitLoadingStateChange(t){for(let s of this._listeners)s.onLoadingStateChange?.(t)}_cancelScheduledImage(){this._timeoutId!==null&&(clearTimeout(this._timeoutId),this._timeoutId=null)}_abortActiveRequest(){this._abortController?.abort(),this._abortController=null}};function Da(e){return e instanceof Error&&e.name==="AbortError"}function bn(e,t){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error(t)}var Ht={getMetadata:async()=>({width:0,height:0,bandCount:0,dtype:"uint8"}),getRaster:async()=>({data:new Uint8Array(0),width:0,height:0,bandCount:0,dtype:"uint8"}),debounceTime:0,shouldRefetch:()=>!0},vt=class{metadata=null;_opts;_listeners=new Set;_currentRequest=null;_lastAcceptedRequestId=-1;_nextRequestId=0;_loadCounter=0;_timeoutId=null;_abortController=null;_finalized=!1;constructor(t){if(this._opts=this._normalizeOptions(t),!this._opts.rasterSource&&(!t.getRaster||!t.getMetadata))throw new Error("RasterSet requires either `rasterSource` or both `getRaster` and `getMetadata`.")}static fromRasterSource(t,s={}){return new vt({...s,rasterSource:t})}get isLoaded(){return this._loadCounter===0&&Boolean(this._currentRequest)}get raster(){return this._currentRequest?.raster||null}get currentRequest(){return this._currentRequest}get rasterSource(){return this._opts.rasterSource}subscribe(t){return this._listeners.add(t),()=>this._listeners.delete(t)}setOptions(t){let s=this._opts.rasterSource,r=this._normalizeOptions({...this._opts,...t}),n=s!==r.rasterSource||this._opts.getRaster!==r.getRaster||this._opts.getMetadata!==r.getMetadata;this._opts=r,n&&(this._cancelScheduledRaster(),this.metadata=null,this._currentRequest=null,this._lastAcceptedRequestId=-1,this._nextRequestId=0,this._emitUpdate())}async loadMetadata(){this._startLoading();try{let t=await this._opts.getMetadata();if(this._finalized)return t;this.metadata=t;for(let s of this._listeners)s.onMetadataLoad?.(t);return this._emitUpdate(),t}catch(t){let s=Cn(t,"Raster metadata request failed");if(!this._finalized)for(let r of this._listeners)r.onMetadataLoadError?.(s);throw s}finally{this._finishLoading()}}requestRaster(t,s=this._opts.debounceTime){if(!this.shouldRefetchRaster(t))return this._currentRequest?.requestId??-1;let r=this._nextRequestId++;return this._cancelScheduledRaster(),s>0?this._timeoutId=setTimeout(()=>{this._timeoutId=null,this._loadRaster(r,t)},s):this._loadRaster(r,t),r}shouldRefetchRaster(t){return this._opts.shouldRefetch({currentRequest:this._currentRequest,metadata:this.metadata,nextParameters:t})}finalize(){this._finalized=!0,this._cancelScheduledRaster(),this._abortActiveRequest(),this._listeners.clear()}async _loadRaster(t,s){if(!this._finalized){this._startLoading();for(let r of this._listeners)r.onRasterLoadStart?.(t,s);try{let r=new AbortController;this._abortController=r;let n=await this._opts.getRaster({...s,signal:r.signal});if(this._finalized||r.signal.aborted||t<=this._lastAcceptedRequestId)return;this._lastAcceptedRequestId=t,this._currentRequest={requestId:t,parameters:s,raster:n};for(let i of this._listeners)i.onRasterLoad?.(this._currentRequest);this._emitUpdate()}catch(r){if(Ua(r))return;let n=Cn(r,"Raster request failed");if(!this._finalized)for(let i of this._listeners)i.onRasterLoadError?.(t,n,s)}finally{this._abortController=null,this._finishLoading()}}}_normalizeOptions(t){let s=t.rasterSource||null;return{...Ht,...t,rasterSource:s,getMetadata:t.getMetadata||(()=>s?s.getMetadata():Ht.getMetadata()),getRaster:t.getRaster||(r=>s?s.getRaster(r):Ht.getRaster(r)),debounceTime:t.debounceTime??Ht.debounceTime,shouldRefetch:t.shouldRefetch||(r=>Ht.shouldRefetch(r))}}_emitUpdate(){for(let t of this._listeners)t.onUpdate?.()}_emitLoadingStateChange(t){for(let s of this._listeners)s.onLoadingStateChange?.(t)}_startLoading(){let t=this._loadCounter>0;this._loadCounter++,t||(this._emitLoadingStateChange(!0),this._emitUpdate())}_finishLoading(){let t=this._loadCounter>0;this._loadCounter=Math.max(0,this._loadCounter-1),t&&this._loadCounter===0&&(this._emitLoadingStateChange(!1),this._emitUpdate())}_cancelScheduledRaster(){this._timeoutId!==null&&(clearTimeout(this._timeoutId),this._timeoutId=null)}_abortActiveRequest(){this._abortController?.abort(),this._abortController=null}};function Cn(e,t){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error(t)}function Ua(e){return e instanceof Error&&e.name==="AbortError"}var zt=class{header;parent;children=[];childrenLoaded=!1;childrenPromise=null;selected=!1;viewportIds=[];content=null;contentAvailable=!1;contentFailed=!1;isContentLoading=!1;constructor(t,s=null){this.header=t,this.parent=s}get id(){return this.header.id}get level(){return this.header.level}get pointCount(){return this.header.pointCount}get geometricError(){return this.header.geometricError}get boundingVolume(){return this.header.boundingVolume}setSelected(t){this.selected=!0,this.viewportIds.includes(t)||this.viewportIds.push(t)}clearSelection(){this.selected=!1,this.viewportIds=[]}};var Fa={debounceTime:0,minimumNodePixelSize:150,maximumScreenSpaceError:1,pointBudget:2e6,maxDepth:Number.POSITIVE_INFINITY,onTileLoad:()=>{},onTileError:()=>{},onTraversalComplete:e=>e,onUpdate:()=>{}},Ve=64,De=class{dataSource;options;root=null;cartographicCenter=null;zoom=1;boundingVolume=null;visibleTilesCount=0;frameNumberValue=0;pendingCount=0;lastUpdatedViewports=null;updatePromise=null;tilesMap=new Map;constructor(t,s={}){this.dataSource=t,this.options={...Fa,...s},this.tilesetInitializationPromise=this.initialize()}tilesetInitializationPromise;get isReady(){return this.dataSource.isReady}get frameNumber(){return this.frameNumberValue}get tiles(){return Array.from(this.tilesMap.values())}isLoaded(){return this.frameNumberValue>0&&this.pendingCount===0&&this.selectedTiles.every(t=>t.contentAvailable||t.contentFailed)}selectedTiles=[];update(t=null){this.selectTiles(t).catch(()=>{})}destroy(){this.selectedTiles=[],this.tilesMap.clear(),this.root=null,this.cartographicCenter=null,this.boundingVolume=null,this.visibleTilesCount=0,this.pendingCount=0,this.lastUpdatedViewports=null,this.updatePromise=null}async initialize(){await this.dataSource.initialize();let t=await this.dataSource.getRootTile();this.root=this.getOrCreateTile(t,null);let s=await this.dataSource.getViewState?.();this.boundingVolume=s?.boundingVolume||this.root.boundingVolume;let r=s?.cartographicCenter||this.root.boundingVolume.center;this.cartographicCenter=new f(r),this.zoom=s?.zoom||this.estimateZoom(this.boundingVolume)}async selectTiles(t=null){return await this.tilesetInitializationPromise,t&&(this.lastUpdatedViewports=t),this.updatePromise||(this.updatePromise=new Promise((s,r)=>{setTimeout(()=>{this.doSelectTiles().then(()=>s(this.frameNumberValue)).catch(r).finally(()=>{this.updatePromise=null})},this.options.debounceTime)})),this.updatePromise}async doSelectTiles(){if(!this.root||!this.lastUpdatedViewports)return;let t=new Set(this.selectedTiles.map(a=>a.id));for(let a of this.tilesMap.values())a.clearSelection();this.frameNumberValue++;let s=Array.isArray(this.lastUpdatedViewports)?this.lastUpdatedViewports:[this.lastUpdatedViewports],r=new Map,n=new Set,i=0;for(let a of s){let c=this.getTraversalContext(a);i=await this.traverseTiles(c,r,i,n)}this.visibleTilesCount=n.size,this.selectedTiles=this.options.onTraversalComplete(Array.from(r.values()));for(let a of this.selectedTiles)this.loadTile(a).catch(()=>{});let o=new Set(this.selectedTiles.map(a=>a.id));this.haveSameIds(t,o)||this.options.onUpdate()}async traverseTiles(t,s,r,n){if(!this.root)return r;let i=r,o=[{tile:this.root,weight:this.estimateScreenRadius(this.root,t.viewport)}];for(;o.length>0;){o.sort((d,u)=>u.weight-d.weight);let a=o.shift();if(!a)break;let{tile:c,weight:h}=a;if(!this.isVisible(c,t))continue;if(n.add(c.id),!s.has(c.id)&&c.pointCount>0){if(i>0&&i+c.pointCount>this.options.pointBudget)break;s.set(c.id,c),i+=c.pointCount}if(s.has(c.id)&&c.setSelected(t.viewport.id),!this.shouldRefine(c,h))continue;let l=await this.getVisibleChildren(c,t);l.length>0&&o.push(...l)}return i}shouldRefine(t,s){return t.level<this.options.maxDepth&&Number.isFinite(s)&&s>=this.options.minimumNodePixelSize}getTraversalContext(t){let s=this.getCullingVolume(t);return{viewport:t,cullingVolume:this.shouldUseCullingVolume(t,s)?s:null}}isVisible(t,s){if(s.cullingVolume){let n=this.getCommonSpaceBoundingSphere(t.boundingVolume,s.viewport);if(n)return this.isBoundingSphereInsideCullingVolume(n,s.cullingVolume)}let r=this.getProjectedFootprint(t.boundingVolume,s.viewport);return r?this.isProjectedFootprintVisible(r,s.viewport):!1}shouldUseCullingVolume(t,s){if(!this.root||!s)return!1;let r=this.getCommonSpaceBoundingSphere(this.root.boundingVolume,t);if(!r)return!1;if(this.isBoundingSphereInsideCullingVolume(r,s))return!0;let n=this.getProjectedFootprint(this.root.boundingVolume,t);return!n||!this.isProjectedFootprintVisible(n,t)}isBoundingSphereInsideCullingVolume(t,s){return s.computeVisibilityWithPlaneMask(t,U.MASK_INDETERMINATE)!==U.MASK_OUTSIDE}isProjectedFootprintVisible(t,s){return!(t.x+t.radius<-Ve||t.x-t.radius>s.width+Ve||t.y+t.radius<-Ve||t.y-t.radius>s.height+Ve)}estimateScreenRadius(t,s){let r=this.getProjectedFootprint(t.boundingVolume,s);return r?r.radius:0}projectBounds(t,s){let r=this.getBoundingVolumeCorners(t),n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;try{for(let c of r){let[h,l]=s.project(c);!Number.isFinite(h)||!Number.isFinite(l)||(n=Math.min(n,h),i=Math.min(i,l),o=Math.max(o,h),a=Math.max(a,l))}}catch{return null}return!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(a)?null:{minX:n,minY:i,maxX:o,maxY:a}}getProjectedFootprint(t,s){let r=Number.NaN,n=Number.NaN;try{[r,n]=s.project(t.center)}catch{return null}if(!Number.isFinite(r)||!Number.isFinite(n))return null;let i=this.getBoundingVolumeCorners(t),o=0;try{for(let a of i){let[c,h]=s.project(a);!Number.isFinite(c)||!Number.isFinite(h)||(o=Math.max(o,Math.hypot(c-r,h-n)))}}catch{return null}if(o===0){let a=this.projectBounds(t,s);a&&(o=Math.max(a.maxX-a.minX,a.maxY-a.minY)/2)}return{x:r,y:n,radius:o}}async getVisibleChildren(t,s){return t.level>=this.options.maxDepth?[]:(await this.getChildren(t)).map(n=>({tile:n,weight:this.estimateScreenRadius(n,s.viewport)})).filter(n=>this.isVisible(n.tile,s))}async getChildren(t){if(t.childrenLoaded)return t.children;if(!t.childrenPromise){let s=this.dataSource.getChildren(t.header).then(r=>r.map(n=>this.getOrCreateTile(n,t))).then(r=>(t.children=r,t.childrenLoaded=!0,r));t.childrenPromise=s.finally(()=>{t.childrenPromise===s&&(t.childrenPromise=null)})}return t.childrenPromise}getOrCreateTile(t,s){let r=this.tilesMap.get(t.id);if(r)return r.header=t,s&&r.parent!==s&&(r.parent=s),r;let n=new zt(t,s);return this.tilesMap.set(t.id,n),s&&!s.children.find(i=>i.id===n.id)&&s.children.push(n),n}async loadTile(t){if(!(t.contentAvailable||t.isContentLoading||t.contentFailed)){t.isContentLoading=!0,this.pendingCount++;try{let s=await this.dataSource.loadTileContent(t.header);t.content=s,t.contentAvailable=!0,s&&this.options.onTileLoad(t)}catch(s){t.contentFailed=!0,this.options.onTileError(t,s)}finally{t.isContentLoading=!1,this.pendingCount--}}}estimateZoom(t){if(!t)return 1;let[s,r]=t.cartographicBounds,n=Math.max(Math.abs(r[0]-s[0]),1e-6);return Math.max(1,Math.round(Math.log2(360/n)))}haveSameIds(t,s){if(t.size!==s.size)return!1;for(let r of t)if(!s.has(r))return!1;return!0}getBoundingVolumeCorners(t){let[s,r]=t.cartographicBounds;return[[s[0],s[1],s[2]||0],[s[0],s[1],r[2]||0],[s[0],r[1],s[2]||0],[s[0],r[1],r[2]||0],[r[0],s[1],s[2]||0],[r[0],s[1],r[2]||0],[r[0],r[1],s[2]||0],[r[0],r[1],r[2]||0]]}getCullingVolume(t){let s=t.getFrustumPlanes?.bind(t);if(!s)return null;let r=s(),n=["left","right","bottom","top","near","far"],i=[];for(let o of n){let a=r[o];if(!a)return null;i.push(new k(a.normal,-a.distance))}return new U(i)}getCommonSpaceBoundingSphere(t,s){let r=s.projectPosition?.bind(s);if(!r)return null;let n=this.getBoundingVolumeCorners(t),i=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;try{for(let d of n){let[u,m,x=0]=r(d);!Number.isFinite(u)||!Number.isFinite(m)||!Number.isFinite(x)||(i=Math.min(i,u),o=Math.min(o,m),a=Math.min(a,x),c=Math.max(c,u),h=Math.max(h,m),l=Math.max(l,x))}}catch{return null}return!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(c)||!Number.isFinite(h)||!Number.isFinite(l)?null:new G().fromCornerPoints([i,o,a],[c,h,l])}};return zn(Kt);})();
|
|
7
|
+
"use strict";var __exports__=(()=>{var Ni=Object.create;var oe=Object.defineProperty;var qi=Object.getOwnPropertyDescriptor;var zi=Object.getOwnPropertyNames;var Di=Object.getPrototypeOf,Bi=Object.prototype.hasOwnProperty;var Vi=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(s){throw t=0,s}},zt=(e,t)=>{for(var s in t)oe(e,s,{get:t[s],enumerable:!0})},ie=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of zi(t))!Bi.call(e,n)&&n!==s&&oe(e,n,{get:()=>t[n],enumerable:!(r=qi(t,n))||r.enumerable});return e},ae=(e,t,s)=>(ie(e,t,"default"),s&&ie(s,t,"default")),Fi=(e,t,s)=>(s=e!=null?Ni(Di(e)):{},ie(t||!e||!e.__esModule?oe(s,"default",{value:e,enumerable:!0}):s,e)),Ui=e=>ie(oe({},"__esModule",{value:!0}),e);var mr=Vi((qh,fr)=>{fr.exports=globalThis.loaders});var re={};zt(re,{I3SSource:()=>Qe,ImageSet:()=>Je,IndexedArchiveTilesetSource:()=>Ue,LOD_METRIC_TYPE:()=>Lt,PointCloudTile:()=>qt,PointCloudTileset:()=>ss,RasterSet:()=>ts,STRATEGY_DEFAULT:()=>ee,STRATEGY_NEVER:()=>ur,STRATEGY_REPLACE:()=>dr,SharedTile2DHeader:()=>Et,TILESET_TYPE:()=>j,TILE_CONTENT_STATE:()=>G,TILE_REFINEMENT:()=>Y,TILE_TYPE:()=>ot,Tile3D:()=>et,Tiles3DSource:()=>He,Tileset2D:()=>te,Tileset3D:()=>Fe,TilesetCache:()=>It,TilesetTraverser:()=>at,calculateTransformProps:()=>Le,createBoundingVolume:()=>Pt,createImplicitSubtreeReference:()=>hr,getFrameState:()=>ze,getLodStatus:()=>We,isTileset3DSource:()=>Ve,materializeImplicitSubtree:()=>Ge,replaceImplicitUrlTemplate:()=>$e});ae(re,Fi(mr(),1));var ki=1/Math.PI*180,Wi=1/180*Math.PI,Yi={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Yi}};var D=globalThis.mathgl.config;function ns(e,{precision:t=D.precision}={}){return e=Gi(e),`${parseFloat(e.toPrecision(t))}`}function nt(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function is(e){return pr(e)}function os(e){return Q(e)}function pr(e,t){return as(e,s=>s*Wi,t)}function Q(e,t){return as(e,s=>s*ki,t)}function Dt(e,t,s){return as(e,r=>Math.max(t,Math.min(s,r)))}function K(e,t,s){let r=D.EPSILON;s&&(D.EPSILON=s);try{if(e===t)return!0;if(nt(e)&&nt(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;++n)if(!K(e[n],t[n]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=D.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{D.EPSILON=r}}function Gi(e){return Math.round(e/D.EPSILON)*D.EPSILON}function $i(e){return e.clone?e.clone():new Array(e.length)}function as(e,t,s){if(nt(e)){let r=e;s=s||$i(r);for(let n=0;n<s.length&&n<r.length;++n){let i=typeof e=="number"?e:e[n];s[n]=t(i,n,s)}return s}return t(e)}var ut=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,s=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=t[r+s];return this.check()}toArray(t=[],s=0){for(let r=0;r<this.ELEMENTS;++r)t[s+r]=this[r];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:nt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(D)}formatString(t){let s="";for(let r=0;r<this.ELEMENTS;++r)s+=(r>0?", ":"")+ns(this[r],t);return`${t.printTypes?this.constructor.name:""}[${s}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let s=0;s<this.ELEMENTS;++s)if(!K(this[s],t[s]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let s=0;s<this.ELEMENTS;++s)if(this[s]!==t[s])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,s,r){if(r===void 0)return this.lerp(this,t,s);for(let n=0;n<this.ELEMENTS;++n){let i=t[n],o=typeof s=="number"?s:s[n];this[n]=i+r*(o-i)}return this.check()}min(t){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(t[s],this[s]);return this.check()}max(t){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.max(t[s],this[s]);return this.check()}clamp(t,s){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t[r]),s[r]);return this.check()}add(...t){for(let s of t)for(let r=0;r<this.ELEMENTS;++r)this[r]+=s[r];return this.check()}subtract(...t){for(let s of t)for(let r=0;r<this.ELEMENTS;++r)this[r]-=s[r];return this.check()}scale(t){if(typeof t=="number")for(let s=0;s<this.ELEMENTS;++s)this[s]*=t;else for(let s=0;s<this.ELEMENTS&&s<t.length;++s)this[s]*=t[s];return this.check()}multiplyByScalar(t){for(let s=0;s<this.ELEMENTS;++s)this[s]*=t;return this.check()}check(){if(D.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let s=0;s<this.ELEMENTS;++s)t=t&&Number.isFinite(this[s]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let s=0;s<this.ELEMENTS;++s)this[s]=t;return this.check()}addScalar(t){for(let s=0;s<this.ELEMENTS;++s)this[s]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let s=0;s<this.ELEMENTS;++s)this[s]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,s){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t),s);return this.check()}get elements(){return this}};function Hi(e,t){if(e.length!==t)return!1;for(let s=0;s<e.length;++s)if(!Number.isFinite(e[s]))return!1;return!0}function I(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function dt(e,t,s=""){if(D.debug&&!Hi(e,t))throw new Error(`math.gl: ${s} some fields set to invalid numbers'`);return e}function F(e,t){if(!e)throw new Error(`math.gl assertion ${t}`)}var bt=class extends ut{get x(){return this[0]}set x(t){this[0]=I(t)}get y(){return this[1]}set y(t){this[1]=I(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let s=0;s<this.ELEMENTS;++s)t+=this[s]*this[s];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let s=0;for(let r=0;r<this.ELEMENTS;++r){let n=this[r]-t[r];s+=n*n}return I(s)}dot(t){let s=0;for(let r=0;r<this.ELEMENTS;++r)s+=this[r]*t[r];return I(s)}normalize(){let t=this.magnitude();if(t!==0)for(let s=0;s<this.ELEMENTS;++s)this[s]/=t;return this.check()}multiply(...t){for(let s of t)for(let r=0;r<this.ELEMENTS;++r)this[r]*=s[r];return this.check()}divide(...t){for(let s of t)for(let r=0;r<this.ELEMENTS;++r)this[r]/=s[r];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return F(t>=0&&t<this.ELEMENTS,"index is out of range"),I(this[t])}setComponent(t,s){return F(t>=0&&t<this.ELEMENTS,"index is out of range"),this[t]=s,this.check()}addVectors(t,s){return this.copy(t).add(s)}subVectors(t,s){return this.copy(t).subtract(s)}multiplyVectors(t,s){return this.copy(t).multiply(s)}addScaledVector(t,s){return this.add(new this.constructor(t).multiplyScalar(s))}};var B=typeof Float32Array<"u"?Float32Array:Array,Bt=Math.random;function Rt(e){return e>=0?Math.round(e):e%.5===0?Math.floor(e):Math.round(e)}var $h=Math.PI/180;function Zi(){let e=new B(2);return B!=Float32Array&&(e[0]=0,e[1]=0),e}function gr(e,t,s){let r=t[0],n=t[1];return e[0]=s[0]*r+s[3]*n+s[6],e[1]=s[1]*r+s[4]*n+s[7],e}function xr(e,t,s){let r=t[0],n=t[1];return e[0]=s[0]*r+s[4]*n+s[12],e[1]=s[1]*r+s[5]*n+s[13],e}var Hh=(function(){let e=Zi();return function(t,s,r,n,i,o){let a,c;for(s||(s=2),r||(r=0),n?c=Math.min(n*s+r,t.length):c=t.length,a=r;a<c;a+=s)e[0]=t[a],e[1]=t[a+1],i(e,e,o),t[a]=e[0],t[a+1]=e[1];return t}})();function yr(e,t,s){let r=t[0],n=t[1],i=s[3]*r+s[7]*n||1;return e[0]=(s[0]*r+s[4]*n)/i,e[1]=(s[1]*r+s[5]*n)/i,e}function ce(e,t,s){let r=t[0],n=t[1],i=t[2],o=s[3]*r+s[7]*n+s[11]*i||1;return e[0]=(s[0]*r+s[4]*n+s[8]*i)/o,e[1]=(s[1]*r+s[5]*n+s[9]*i)/o,e[2]=(s[2]*r+s[6]*n+s[10]*i)/o,e}function Tr(e,t,s){let r=t[0],n=t[1];return e[0]=s[0]*r+s[2]*n,e[1]=s[1]*r+s[3]*n,e[2]=t[2],e}function _r(e,t,s){let r=t[0],n=t[1];return e[0]=s[0]*r+s[2]*n,e[1]=s[1]*r+s[3]*n,e[2]=t[2],e[3]=t[3],e}function he(e,t,s){let r=t[0],n=t[1],i=t[2];return e[0]=s[0]*r+s[3]*n+s[6]*i,e[1]=s[1]*r+s[4]*n+s[7]*i,e[2]=s[2]*r+s[5]*n+s[8]*i,e[3]=t[3],e}var Ct={};zt(Ct,{add:()=>Ji,angle:()=>ds,bezier:()=>fo,ceil:()=>to,clone:()=>Xi,copy:()=>Qi,create:()=>le,cross:()=>yt,dist:()=>So,distance:()=>Rr,div:()=>Mo,divide:()=>br,dot:()=>Vt,equals:()=>yo,exactEquals:()=>xo,floor:()=>eo,forEach:()=>Ro,fromValues:()=>ue,hermite:()=>uo,inverse:()=>co,len:()=>fs,length:()=>Mr,lerp:()=>ho,max:()=>ro,min:()=>so,mul:()=>_o,multiply:()=>Er,negate:()=>ao,normalize:()=>cs,random:()=>mo,rotateX:()=>hs,rotateY:()=>ls,rotateZ:()=>us,round:()=>no,scale:()=>io,scaleAndAdd:()=>oo,set:()=>Ki,slerp:()=>lo,sqrDist:()=>Eo,sqrLen:()=>bo,squaredDistance:()=>wr,squaredLength:()=>Cr,str:()=>go,sub:()=>To,subtract:()=>Sr,transformMat3:()=>Ft,transformMat4:()=>Tt,transformQuat:()=>Ut,zero:()=>po});function le(){let e=new B(3);return B!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Xi(e){let t=new B(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function Mr(e){let t=e[0],s=e[1],r=e[2];return Math.sqrt(t*t+s*s+r*r)}function ue(e,t,s){let r=new B(3);return r[0]=e,r[1]=t,r[2]=s,r}function Qi(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function Ki(e,t,s,r){return e[0]=t,e[1]=s,e[2]=r,e}function Ji(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e}function Sr(e,t,s){return e[0]=t[0]-s[0],e[1]=t[1]-s[1],e[2]=t[2]-s[2],e}function Er(e,t,s){return e[0]=t[0]*s[0],e[1]=t[1]*s[1],e[2]=t[2]*s[2],e}function br(e,t,s){return e[0]=t[0]/s[0],e[1]=t[1]/s[1],e[2]=t[2]/s[2],e}function to(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e}function eo(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e}function so(e,t,s){return e[0]=Math.min(t[0],s[0]),e[1]=Math.min(t[1],s[1]),e[2]=Math.min(t[2],s[2]),e}function ro(e,t,s){return e[0]=Math.max(t[0],s[0]),e[1]=Math.max(t[1],s[1]),e[2]=Math.max(t[2],s[2]),e}function no(e,t){return e[0]=Rt(t[0]),e[1]=Rt(t[1]),e[2]=Rt(t[2]),e}function io(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}function oo(e,t,s,r){return e[0]=t[0]+s[0]*r,e[1]=t[1]+s[1]*r,e[2]=t[2]+s[2]*r,e}function Rr(e,t){let s=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return Math.sqrt(s*s+r*r+n*n)}function wr(e,t){let s=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return s*s+r*r+n*n}function Cr(e){let t=e[0],s=e[1],r=e[2];return t*t+s*s+r*r}function ao(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e}function co(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e}function cs(e,t){let s=t[0],r=t[1],n=t[2],i=s*s+r*r+n*n;return i>0&&(i=1/Math.sqrt(i)),e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e}function Vt(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function yt(e,t,s){let r=t[0],n=t[1],i=t[2],o=s[0],a=s[1],c=s[2];return e[0]=n*c-i*a,e[1]=i*o-r*c,e[2]=r*a-n*o,e}function ho(e,t,s,r){let n=t[0],i=t[1],o=t[2];return e[0]=n+r*(s[0]-n),e[1]=i+r*(s[1]-i),e[2]=o+r*(s[2]-o),e}function lo(e,t,s,r){let n=Math.acos(Math.min(Math.max(Vt(t,s),-1),1)),i=Math.sin(n),o=Math.sin((1-r)*n)/i,a=Math.sin(r*n)/i;return e[0]=o*t[0]+a*s[0],e[1]=o*t[1]+a*s[1],e[2]=o*t[2]+a*s[2],e}function uo(e,t,s,r,n,i){let o=i*i,a=o*(2*i-3)+1,c=o*(i-2)+i,h=o*(i-1),l=o*(3-2*i);return e[0]=t[0]*a+s[0]*c+r[0]*h+n[0]*l,e[1]=t[1]*a+s[1]*c+r[1]*h+n[1]*l,e[2]=t[2]*a+s[2]*c+r[2]*h+n[2]*l,e}function fo(e,t,s,r,n,i){let o=1-i,a=o*o,c=i*i,h=a*o,l=3*i*a,u=3*c*o,d=c*i;return e[0]=t[0]*h+s[0]*l+r[0]*u+n[0]*d,e[1]=t[1]*h+s[1]*l+r[1]*u+n[1]*d,e[2]=t[2]*h+s[2]*l+r[2]*u+n[2]*d,e}function mo(e,t){t=t===void 0?1:t;let s=Bt()*2*Math.PI,r=Bt()*2-1,n=Math.sqrt(1-r*r)*t;return e[0]=Math.cos(s)*n,e[1]=Math.sin(s)*n,e[2]=r*t,e}function Tt(e,t,s){let r=t[0],n=t[1],i=t[2],o=s[3]*r+s[7]*n+s[11]*i+s[15];return o=o||1,e[0]=(s[0]*r+s[4]*n+s[8]*i+s[12])/o,e[1]=(s[1]*r+s[5]*n+s[9]*i+s[13])/o,e[2]=(s[2]*r+s[6]*n+s[10]*i+s[14])/o,e}function Ft(e,t,s){let r=t[0],n=t[1],i=t[2];return e[0]=r*s[0]+n*s[3]+i*s[6],e[1]=r*s[1]+n*s[4]+i*s[7],e[2]=r*s[2]+n*s[5]+i*s[8],e}function Ut(e,t,s){let r=s[0],n=s[1],i=s[2],o=s[3],a=t[0],c=t[1],h=t[2],l=n*h-i*c,u=i*a-r*h,d=r*c-n*a,f=n*d-i*u,g=i*l-r*d,x=r*u-n*l,p=o*2;return l*=p,u*=p,d*=p,f*=2,g*=2,x*=2,e[0]=a+l+f,e[1]=c+u+g,e[2]=h+d+x,e}function hs(e,t,s,r){let n=[],i=[];return n[0]=t[0]-s[0],n[1]=t[1]-s[1],n[2]=t[2]-s[2],i[0]=n[0],i[1]=n[1]*Math.cos(r)-n[2]*Math.sin(r),i[2]=n[1]*Math.sin(r)+n[2]*Math.cos(r),e[0]=i[0]+s[0],e[1]=i[1]+s[1],e[2]=i[2]+s[2],e}function ls(e,t,s,r){let n=[],i=[];return n[0]=t[0]-s[0],n[1]=t[1]-s[1],n[2]=t[2]-s[2],i[0]=n[2]*Math.sin(r)+n[0]*Math.cos(r),i[1]=n[1],i[2]=n[2]*Math.cos(r)-n[0]*Math.sin(r),e[0]=i[0]+s[0],e[1]=i[1]+s[1],e[2]=i[2]+s[2],e}function us(e,t,s,r){let n=[],i=[];return n[0]=t[0]-s[0],n[1]=t[1]-s[1],n[2]=t[2]-s[2],i[0]=n[0]*Math.cos(r)-n[1]*Math.sin(r),i[1]=n[0]*Math.sin(r)+n[1]*Math.cos(r),i[2]=n[2],e[0]=i[0]+s[0],e[1]=i[1]+s[1],e[2]=i[2]+s[2],e}function ds(e,t){let s=e[0],r=e[1],n=e[2],i=t[0],o=t[1],a=t[2],c=Math.sqrt((s*s+r*r+n*n)*(i*i+o*o+a*a)),h=c&&Vt(e,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}function po(e){return e[0]=0,e[1]=0,e[2]=0,e}function go(e){return`vec3(${e[0]}, ${e[1]}, ${e[2]})`}function xo(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function yo(e,t){let s=e[0],r=e[1],n=e[2],i=t[0],o=t[1],a=t[2];return Math.abs(s-i)<=1e-6*Math.max(1,Math.abs(s),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-a)<=1e-6*Math.max(1,Math.abs(n),Math.abs(a))}var To=Sr,_o=Er,Mo=br,So=Rr,Eo=wr,fs=Mr,bo=Cr,Ro=(function(){let e=le();return function(t,s,r,n,i,o){let a,c;for(s||(s=3),r||(r=0),n?c=Math.min(n*s+r,t.length):c=t.length,a=r;a<c;a+=s)e[0]=t[a],e[1]=t[a+1],e[2]=t[a+2],i(e,e,o),t[a]=e[0],t[a+1]=e[1],t[a+2]=e[2];return t}})();var ms=[0,0,0],de,m=class e extends bt{static get ZERO(){return de||(de=new e(0,0,0),Object.freeze(de)),de}constructor(t=0,s=0,r=0){super(-0,-0,-0),arguments.length===1&&nt(t)?this.copy(t):(D.debug&&(I(t),I(s),I(r)),this[0]=t,this[1]=s,this[2]=r)}set(t,s,r){return this[0]=t,this[1]=s,this[2]=r,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return D.debug&&(I(t.x),I(t.y),I(t.z)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this.check()}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t}get ELEMENTS(){return 3}get z(){return this[2]}set z(t){this[2]=I(t)}angle(t){return ds(this,t)}cross(t){return yt(this,this,t),this.check()}rotateX({radians:t,origin:s=ms}){return hs(this,this,s,t),this.check()}rotateY({radians:t,origin:s=ms}){return ls(this,this,s,t),this.check()}rotateZ({radians:t,origin:s=ms}){return us(this,this,s,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return Tt(this,this,t),this.check()}transformAsVector(t){return ce(this,this,t),this.check()}transformByMatrix3(t){return Ft(this,this,t),this.check()}transformByMatrix2(t){return Tr(this,this,t),this.check()}transformByQuaternion(t){return Ut(this,this,t),this.check()}};var fe,me=class e extends bt{static get ZERO(){return fe||(fe=new e(0,0,0,0),Object.freeze(fe)),fe}constructor(t=0,s=0,r=0,n=0){super(-0,-0,-0,-0),nt(t)&&arguments.length===1?this.copy(t):(D.debug&&(I(t),I(s),I(r),I(n)),this[0]=t,this[1]=s,this[2]=r,this[3]=n)}set(t,s,r,n){return this[0]=t,this[1]=s,this[2]=r,this[3]=n,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}fromObject(t){return D.debug&&(I(t.x),I(t.y),I(t.z),I(t.w)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t.w=this[3],t}get ELEMENTS(){return 4}get z(){return this[2]}set z(t){this[2]=I(t)}get w(){return this[3]}set w(t){this[3]=I(t)}transform(t){return Tt(this,this,t),this.check()}transformByMatrix3(t){return he(this,this,t),this.check()}transformByMatrix2(t){return _r(this,this,t),this.check()}transformByQuaternion(t){return Ut(this,this,t),this.check()}applyMatrix4(t){return t.transform(this,this),this}};var Ot=class extends ut{toString(){let t="[";if(D.printRowMajor){t+="row-major:";for(let s=0;s<this.RANK;++s)for(let r=0;r<this.RANK;++r)t+=` ${this[r*this.RANK+s]}`}else{t+="column-major:";for(let s=0;s<this.ELEMENTS;++s)t+=` ${this[s]}`}return t+="]",t}getElementIndex(t,s){return s*this.RANK+t}getElement(t,s){return this[s*this.RANK+t]}setElement(t,s,r){return this[s*this.RANK+t]=I(r),this}getColumn(t,s=new Array(this.RANK).fill(-0)){let r=t*this.RANK;for(let n=0;n<this.RANK;++n)s[n]=this[r+n];return s}setColumn(t,s){let r=t*this.RANK;for(let n=0;n<this.RANK;++n)this[r+n]=s[n];return this}};function Or(){let e=new B(9);return B!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[5]=0,e[6]=0,e[7]=0),e[0]=1,e[4]=1,e[8]=1,e}function Ar(e,t){if(e===t){let s=t[1],r=t[2],n=t[5];e[1]=t[3],e[2]=t[6],e[3]=s,e[5]=t[7],e[6]=r,e[7]=n}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8];return e}function vr(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],u=l*o-a*h,d=-l*i+a*c,f=h*i-o*c,g=s*u+r*d+n*f;return g?(g=1/g,e[0]=u*g,e[1]=(-l*r+n*h)*g,e[2]=(a*r-n*o)*g,e[3]=d*g,e[4]=(l*s-n*c)*g,e[5]=(-a*s+n*i)*g,e[6]=f*g,e[7]=(-h*s+r*c)*g,e[8]=(o*s-r*i)*g,e):null}function Ir(e){let t=e[0],s=e[1],r=e[2],n=e[3],i=e[4],o=e[5],a=e[6],c=e[7],h=e[8];return t*(h*i-o*c)+s*(-h*n+o*a)+r*(c*n-i*a)}function ps(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],u=t[8],d=s[0],f=s[1],g=s[2],x=s[3],p=s[4],y=s[5],E=s[6],_=s[7],T=s[8];return e[0]=d*r+f*o+g*h,e[1]=d*n+f*a+g*l,e[2]=d*i+f*c+g*u,e[3]=x*r+p*o+y*h,e[4]=x*n+p*a+y*l,e[5]=x*i+p*c+y*u,e[6]=E*r+_*o+T*h,e[7]=E*n+_*a+T*l,e[8]=E*i+_*c+T*u,e}function Lr(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],u=t[8],d=s[0],f=s[1];return e[0]=r,e[1]=n,e[2]=i,e[3]=o,e[4]=a,e[5]=c,e[6]=d*r+f*o+h,e[7]=d*n+f*a+l,e[8]=d*i+f*c+u,e}function Pr(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],u=t[8],d=Math.sin(s),f=Math.cos(s);return e[0]=f*r+d*o,e[1]=f*n+d*a,e[2]=f*i+d*c,e[3]=f*o-d*r,e[4]=f*a-d*n,e[5]=f*c-d*i,e[6]=h,e[7]=l,e[8]=u,e}function gs(e,t,s){let r=s[0],n=s[1];return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=n*t[3],e[4]=n*t[4],e[5]=n*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function Nr(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=s+s,a=r+r,c=n+n,h=s*o,l=r*o,u=r*a,d=n*o,f=n*a,g=n*c,x=i*o,p=i*a,y=i*c;return e[0]=1-u-g,e[3]=l-y,e[6]=d+p,e[1]=l+y,e[4]=1-h-g,e[7]=f-x,e[2]=d-p,e[5]=f+x,e[8]=1-h-u,e}var xs;(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"})(xs||(xs={}));var wo=Object.freeze([1,0,0,0,1,0,0,0,1]),V=class extends Ot{static get IDENTITY(){return Oo()}static get ZERO(){return Co()}get ELEMENTS(){return 9}get RANK(){return 3}get INDICES(){return xs}constructor(t,...s){super(-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):s.length>0?this.copy([t,...s]):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this.check()}identity(){return this.copy(wo)}fromObject(t){return this.check()}fromQuaternion(t){return Nr(this,t),this.check()}set(t,s,r,n,i,o,a,c,h){return this[0]=t,this[1]=s,this[2]=r,this[3]=n,this[4]=i,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this.check()}setRowMajor(t,s,r,n,i,o,a,c,h){return this[0]=t,this[1]=n,this[2]=a,this[3]=s,this[4]=i,this[5]=c,this[6]=r,this[7]=o,this[8]=h,this.check()}determinant(){return Ir(this)}transpose(){return Ar(this,this),this.check()}invert(){return vr(this,this),this.check()}multiplyLeft(t){return ps(this,t,this),this.check()}multiplyRight(t){return ps(this,this,t),this.check()}rotate(t){return Pr(this,this,t),this.check()}scale(t){return Array.isArray(t)?gs(this,this,t):gs(this,this,[t,t]),this.check()}translate(t){return Lr(this,this,t),this.check()}transform(t,s){let r;switch(t.length){case 2:r=gr(s||[-0,-0],t,this);break;case 3:r=Ft(s||[-0,-0,-0],t,this);break;case 4:r=he(s||[-0,-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return dt(r,t.length),r}transformVector(t,s){return this.transform(t,s)}transformVector2(t,s){return this.transform(t,s)}transformVector3(t,s){return this.transform(t,s)}},pe,ge=null;function Co(){return pe||(pe=new V([0,0,0,0,0,0,0,0,0]),Object.freeze(pe)),pe}function Oo(){return ge||(ge=new V,Object.freeze(ge)),ge}var xe={};zt(xe,{add:()=>Jo,adjoint:()=>No,clone:()=>vo,copy:()=>Io,create:()=>Ao,decompose:()=>Yo,determinant:()=>_s,equals:()=>ra,exactEquals:()=>sa,frob:()=>Ko,fromQuat:()=>Cs,fromQuat2:()=>Uo,fromRotation:()=>Do,fromRotationTranslation:()=>Dr,fromRotationTranslationScale:()=>Go,fromRotationTranslationScaleOrigin:()=>$o,fromScaling:()=>zo,fromTranslation:()=>qo,fromValues:()=>Lo,fromXRotation:()=>Bo,fromYRotation:()=>Vo,fromZRotation:()=>Fo,frustum:()=>Os,getRotation:()=>Wo,getScaling:()=>Br,getTranslation:()=>ko,identity:()=>zr,invert:()=>Ts,lookAt:()=>Is,mul:()=>na,multiply:()=>kt,multiplyScalar:()=>ta,multiplyScalarAndAdd:()=>ea,ortho:()=>vs,orthoNO:()=>Fr,orthoZO:()=>jo,perspective:()=>As,perspectiveFromFieldOfView:()=>Zo,perspectiveNO:()=>Vr,perspectiveZO:()=>Ho,rotate:()=>Es,rotateX:()=>bs,rotateY:()=>Rs,rotateZ:()=>ws,scale:()=>Ss,set:()=>Po,str:()=>Qo,sub:()=>ia,subtract:()=>Ur,targetTo:()=>Xo,translate:()=>Ms,transpose:()=>ys});function Ao(){let e=new B(16);return B!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function vo(e){let t=new B(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Io(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function Lo(e,t,s,r,n,i,o,a,c,h,l,u,d,f,g,x){let p=new B(16);return p[0]=e,p[1]=t,p[2]=s,p[3]=r,p[4]=n,p[5]=i,p[6]=o,p[7]=a,p[8]=c,p[9]=h,p[10]=l,p[11]=u,p[12]=d,p[13]=f,p[14]=g,p[15]=x,p}function Po(e,t,s,r,n,i,o,a,c,h,l,u,d,f,g,x,p){return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e[4]=i,e[5]=o,e[6]=a,e[7]=c,e[8]=h,e[9]=l,e[10]=u,e[11]=d,e[12]=f,e[13]=g,e[14]=x,e[15]=p,e}function zr(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function ys(e,t){if(e===t){let s=t[1],r=t[2],n=t[3],i=t[6],o=t[7],a=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=s,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=i,e[11]=t[14],e[12]=n,e[13]=o,e[14]=a}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function Ts(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],u=t[9],d=t[10],f=t[11],g=t[12],x=t[13],p=t[14],y=t[15],E=s*a-r*o,_=s*c-n*o,T=s*h-i*o,S=r*c-n*a,M=r*h-i*a,A=n*h-i*c,R=l*x-u*g,C=l*p-d*g,b=l*y-f*g,P=u*p-d*x,q=u*y-f*x,z=d*y-f*p,O=E*z-_*q+T*P+S*b-M*C+A*R;return O?(O=1/O,e[0]=(a*z-c*q+h*P)*O,e[1]=(n*q-r*z-i*P)*O,e[2]=(x*A-p*M+y*S)*O,e[3]=(d*M-u*A-f*S)*O,e[4]=(c*b-o*z-h*C)*O,e[5]=(s*z-n*b+i*C)*O,e[6]=(p*T-g*A-y*_)*O,e[7]=(l*A-d*T+f*_)*O,e[8]=(o*q-a*b+h*R)*O,e[9]=(r*b-s*q-i*R)*O,e[10]=(g*M-x*T+y*E)*O,e[11]=(u*T-l*M-f*E)*O,e[12]=(a*C-o*P-c*R)*O,e[13]=(s*P-r*C+n*R)*O,e[14]=(x*_-g*S-p*E)*O,e[15]=(l*S-u*_+d*E)*O,e):null}function No(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],u=t[9],d=t[10],f=t[11],g=t[12],x=t[13],p=t[14],y=t[15],E=s*a-r*o,_=s*c-n*o,T=s*h-i*o,S=r*c-n*a,M=r*h-i*a,A=n*h-i*c,R=l*x-u*g,C=l*p-d*g,b=l*y-f*g,P=u*p-d*x,q=u*y-f*x,z=d*y-f*p;return e[0]=a*z-c*q+h*P,e[1]=n*q-r*z-i*P,e[2]=x*A-p*M+y*S,e[3]=d*M-u*A-f*S,e[4]=c*b-o*z-h*C,e[5]=s*z-n*b+i*C,e[6]=p*T-g*A-y*_,e[7]=l*A-d*T+f*_,e[8]=o*q-a*b+h*R,e[9]=r*b-s*q-i*R,e[10]=g*M-x*T+y*E,e[11]=u*T-l*M-f*E,e[12]=a*C-o*P-c*R,e[13]=s*P-r*C+n*R,e[14]=x*_-g*S-p*E,e[15]=l*S-u*_+d*E,e}function _s(e){let t=e[0],s=e[1],r=e[2],n=e[3],i=e[4],o=e[5],a=e[6],c=e[7],h=e[8],l=e[9],u=e[10],d=e[11],f=e[12],g=e[13],x=e[14],p=e[15],y=t*o-s*i,E=t*a-r*i,_=s*a-r*o,T=h*g-l*f,S=h*x-u*f,M=l*x-u*g,A=t*M-s*S+r*T,R=i*M-o*S+a*T,C=h*_-l*E+u*y,b=f*_-g*E+x*y;return c*A-n*R+p*C-d*b}function kt(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],u=t[8],d=t[9],f=t[10],g=t[11],x=t[12],p=t[13],y=t[14],E=t[15],_=s[0],T=s[1],S=s[2],M=s[3];return e[0]=_*r+T*a+S*u+M*x,e[1]=_*n+T*c+S*d+M*p,e[2]=_*i+T*h+S*f+M*y,e[3]=_*o+T*l+S*g+M*E,_=s[4],T=s[5],S=s[6],M=s[7],e[4]=_*r+T*a+S*u+M*x,e[5]=_*n+T*c+S*d+M*p,e[6]=_*i+T*h+S*f+M*y,e[7]=_*o+T*l+S*g+M*E,_=s[8],T=s[9],S=s[10],M=s[11],e[8]=_*r+T*a+S*u+M*x,e[9]=_*n+T*c+S*d+M*p,e[10]=_*i+T*h+S*f+M*y,e[11]=_*o+T*l+S*g+M*E,_=s[12],T=s[13],S=s[14],M=s[15],e[12]=_*r+T*a+S*u+M*x,e[13]=_*n+T*c+S*d+M*p,e[14]=_*i+T*h+S*f+M*y,e[15]=_*o+T*l+S*g+M*E,e}function Ms(e,t,s){let r=s[0],n=s[1],i=s[2],o,a,c,h,l,u,d,f,g,x,p,y;return t===e?(e[12]=t[0]*r+t[4]*n+t[8]*i+t[12],e[13]=t[1]*r+t[5]*n+t[9]*i+t[13],e[14]=t[2]*r+t[6]*n+t[10]*i+t[14],e[15]=t[3]*r+t[7]*n+t[11]*i+t[15]):(o=t[0],a=t[1],c=t[2],h=t[3],l=t[4],u=t[5],d=t[6],f=t[7],g=t[8],x=t[9],p=t[10],y=t[11],e[0]=o,e[1]=a,e[2]=c,e[3]=h,e[4]=l,e[5]=u,e[6]=d,e[7]=f,e[8]=g,e[9]=x,e[10]=p,e[11]=y,e[12]=o*r+l*n+g*i+t[12],e[13]=a*r+u*n+x*i+t[13],e[14]=c*r+d*n+p*i+t[14],e[15]=h*r+f*n+y*i+t[15]),e}function Ss(e,t,s){let r=s[0],n=s[1],i=s[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function Es(e,t,s,r){let n=r[0],i=r[1],o=r[2],a=Math.sqrt(n*n+i*i+o*o),c,h,l,u,d,f,g,x,p,y,E,_,T,S,M,A,R,C,b,P,q,z,O,X;return a<1e-6?null:(a=1/a,n*=a,i*=a,o*=a,h=Math.sin(s),c=Math.cos(s),l=1-c,u=t[0],d=t[1],f=t[2],g=t[3],x=t[4],p=t[5],y=t[6],E=t[7],_=t[8],T=t[9],S=t[10],M=t[11],A=n*n*l+c,R=i*n*l+o*h,C=o*n*l-i*h,b=n*i*l-o*h,P=i*i*l+c,q=o*i*l+n*h,z=n*o*l+i*h,O=i*o*l-n*h,X=o*o*l+c,e[0]=u*A+x*R+_*C,e[1]=d*A+p*R+T*C,e[2]=f*A+y*R+S*C,e[3]=g*A+E*R+M*C,e[4]=u*b+x*P+_*q,e[5]=d*b+p*P+T*q,e[6]=f*b+y*P+S*q,e[7]=g*b+E*P+M*q,e[8]=u*z+x*O+_*X,e[9]=d*z+p*O+T*X,e[10]=f*z+y*O+S*X,e[11]=g*z+E*O+M*X,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function bs(e,t,s){let r=Math.sin(s),n=Math.cos(s),i=t[4],o=t[5],a=t[6],c=t[7],h=t[8],l=t[9],u=t[10],d=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*n+h*r,e[5]=o*n+l*r,e[6]=a*n+u*r,e[7]=c*n+d*r,e[8]=h*n-i*r,e[9]=l*n-o*r,e[10]=u*n-a*r,e[11]=d*n-c*r,e}function Rs(e,t,s){let r=Math.sin(s),n=Math.cos(s),i=t[0],o=t[1],a=t[2],c=t[3],h=t[8],l=t[9],u=t[10],d=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*n-h*r,e[1]=o*n-l*r,e[2]=a*n-u*r,e[3]=c*n-d*r,e[8]=i*r+h*n,e[9]=o*r+l*n,e[10]=a*r+u*n,e[11]=c*r+d*n,e}function ws(e,t,s){let r=Math.sin(s),n=Math.cos(s),i=t[0],o=t[1],a=t[2],c=t[3],h=t[4],l=t[5],u=t[6],d=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*n+h*r,e[1]=o*n+l*r,e[2]=a*n+u*r,e[3]=c*n+d*r,e[4]=h*n-i*r,e[5]=l*n-o*r,e[6]=u*n-a*r,e[7]=d*n-c*r,e}function qo(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function zo(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Do(e,t,s){let r=s[0],n=s[1],i=s[2],o=Math.sqrt(r*r+n*n+i*i),a,c,h;return o<1e-6?null:(o=1/o,r*=o,n*=o,i*=o,c=Math.sin(t),a=Math.cos(t),h=1-a,e[0]=r*r*h+a,e[1]=n*r*h+i*c,e[2]=i*r*h-n*c,e[3]=0,e[4]=r*n*h-i*c,e[5]=n*n*h+a,e[6]=i*n*h+r*c,e[7]=0,e[8]=r*i*h+n*c,e[9]=n*i*h-r*c,e[10]=i*i*h+a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)}function Bo(e,t){let s=Math.sin(t),r=Math.cos(t);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=r,e[6]=s,e[7]=0,e[8]=0,e[9]=-s,e[10]=r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Vo(e,t){let s=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=0,e[2]=-s,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=s,e[9]=0,e[10]=r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Fo(e,t){let s=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=s,e[2]=0,e[3]=0,e[4]=-s,e[5]=r,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Dr(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=r+r,c=n+n,h=i+i,l=r*a,u=r*c,d=r*h,f=n*c,g=n*h,x=i*h,p=o*a,y=o*c,E=o*h;return e[0]=1-(f+x),e[1]=u+E,e[2]=d-y,e[3]=0,e[4]=u-E,e[5]=1-(l+x),e[6]=g+p,e[7]=0,e[8]=d+y,e[9]=g-p,e[10]=1-(l+f),e[11]=0,e[12]=s[0],e[13]=s[1],e[14]=s[2],e[15]=1,e}function Uo(e,t){let s=new B(3),r=-t[0],n=-t[1],i=-t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],u=r*r+n*n+i*i+o*o;return u>0?(s[0]=(a*o+l*r+c*i-h*n)*2/u,s[1]=(c*o+l*n+h*r-a*i)*2/u,s[2]=(h*o+l*i+a*n-c*r)*2/u):(s[0]=(a*o+l*r+c*i-h*n)*2,s[1]=(c*o+l*n+h*r-a*i)*2,s[2]=(h*o+l*i+a*n-c*r)*2),Dr(e,t,s),e}function ko(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Br(e,t){let s=t[0],r=t[1],n=t[2],i=t[4],o=t[5],a=t[6],c=t[8],h=t[9],l=t[10];return e[0]=Math.sqrt(s*s+r*r+n*n),e[1]=Math.sqrt(i*i+o*o+a*a),e[2]=Math.sqrt(c*c+h*h+l*l),e}function Wo(e,t){let s=new B(3);Br(s,t);let r=1/s[0],n=1/s[1],i=1/s[2],o=t[0]*r,a=t[1]*n,c=t[2]*i,h=t[4]*r,l=t[5]*n,u=t[6]*i,d=t[8]*r,f=t[9]*n,g=t[10]*i,x=o+l+g,p=0;return x>0?(p=Math.sqrt(x+1)*2,e[3]=.25*p,e[0]=(u-f)/p,e[1]=(d-c)/p,e[2]=(a-h)/p):o>l&&o>g?(p=Math.sqrt(1+o-l-g)*2,e[3]=(u-f)/p,e[0]=.25*p,e[1]=(a+h)/p,e[2]=(d+c)/p):l>g?(p=Math.sqrt(1+l-o-g)*2,e[3]=(d-c)/p,e[0]=(a+h)/p,e[1]=.25*p,e[2]=(u+f)/p):(p=Math.sqrt(1+g-o-l)*2,e[3]=(a-h)/p,e[0]=(d+c)/p,e[1]=(u+f)/p,e[2]=.25*p),e}function Yo(e,t,s,r){t[0]=r[12],t[1]=r[13],t[2]=r[14];let n=r[0],i=r[1],o=r[2],a=r[4],c=r[5],h=r[6],l=r[8],u=r[9],d=r[10];s[0]=Math.sqrt(n*n+i*i+o*o),s[1]=Math.sqrt(a*a+c*c+h*h),s[2]=Math.sqrt(l*l+u*u+d*d);let f=1/s[0],g=1/s[1],x=1/s[2],p=n*f,y=i*g,E=o*x,_=a*f,T=c*g,S=h*x,M=l*f,A=u*g,R=d*x,C=p+T+R,b=0;return C>0?(b=Math.sqrt(C+1)*2,e[3]=.25*b,e[0]=(S-A)/b,e[1]=(M-E)/b,e[2]=(y-_)/b):p>T&&p>R?(b=Math.sqrt(1+p-T-R)*2,e[3]=(S-A)/b,e[0]=.25*b,e[1]=(y+_)/b,e[2]=(M+E)/b):T>R?(b=Math.sqrt(1+T-p-R)*2,e[3]=(M-E)/b,e[0]=(y+_)/b,e[1]=.25*b,e[2]=(S+A)/b):(b=Math.sqrt(1+R-p-T)*2,e[3]=(y-_)/b,e[0]=(M+E)/b,e[1]=(S+A)/b,e[2]=.25*b),e}function Go(e,t,s,r){let n=t[0],i=t[1],o=t[2],a=t[3],c=n+n,h=i+i,l=o+o,u=n*c,d=n*h,f=n*l,g=i*h,x=i*l,p=o*l,y=a*c,E=a*h,_=a*l,T=r[0],S=r[1],M=r[2];return e[0]=(1-(g+p))*T,e[1]=(d+_)*T,e[2]=(f-E)*T,e[3]=0,e[4]=(d-_)*S,e[5]=(1-(u+p))*S,e[6]=(x+y)*S,e[7]=0,e[8]=(f+E)*M,e[9]=(x-y)*M,e[10]=(1-(u+g))*M,e[11]=0,e[12]=s[0],e[13]=s[1],e[14]=s[2],e[15]=1,e}function $o(e,t,s,r,n){let i=t[0],o=t[1],a=t[2],c=t[3],h=i+i,l=o+o,u=a+a,d=i*h,f=i*l,g=i*u,x=o*l,p=o*u,y=a*u,E=c*h,_=c*l,T=c*u,S=r[0],M=r[1],A=r[2],R=n[0],C=n[1],b=n[2],P=(1-(x+y))*S,q=(f+T)*S,z=(g-_)*S,O=(f-T)*M,X=(1-(d+y))*M,gt=(p+E)*M,xt=(g+_)*A,rs=(p-E)*A,ne=(1-(d+x))*A;return e[0]=P,e[1]=q,e[2]=z,e[3]=0,e[4]=O,e[5]=X,e[6]=gt,e[7]=0,e[8]=xt,e[9]=rs,e[10]=ne,e[11]=0,e[12]=s[0]+R-(P*R+O*C+xt*b),e[13]=s[1]+C-(q*R+X*C+rs*b),e[14]=s[2]+b-(z*R+gt*C+ne*b),e[15]=1,e}function Cs(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=s+s,a=r+r,c=n+n,h=s*o,l=r*o,u=r*a,d=n*o,f=n*a,g=n*c,x=i*o,p=i*a,y=i*c;return e[0]=1-u-g,e[1]=l+y,e[2]=d-p,e[3]=0,e[4]=l-y,e[5]=1-h-g,e[6]=f+x,e[7]=0,e[8]=d+p,e[9]=f-x,e[10]=1-h-u,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Os(e,t,s,r,n,i,o){let a=1/(s-t),c=1/(n-r),h=1/(i-o);return e[0]=i*2*a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i*2*c,e[6]=0,e[7]=0,e[8]=(s+t)*a,e[9]=(n+r)*c,e[10]=(o+i)*h,e[11]=-1,e[12]=0,e[13]=0,e[14]=o*i*2*h,e[15]=0,e}function Vr(e,t,s,r,n){let i=1/Math.tan(t/2);if(e[0]=i/s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,n!=null&&n!==1/0){let o=1/(r-n);e[10]=(n+r)*o,e[14]=2*n*r*o}else e[10]=-1,e[14]=-2*r;return e}var As=Vr;function Ho(e,t,s,r,n){let i=1/Math.tan(t/2);if(e[0]=i/s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,n!=null&&n!==1/0){let o=1/(r-n);e[10]=n*o,e[14]=n*r*o}else e[10]=-1,e[14]=-r;return e}function Zo(e,t,s,r){let n=Math.tan(t.upDegrees*Math.PI/180),i=Math.tan(t.downDegrees*Math.PI/180),o=Math.tan(t.leftDegrees*Math.PI/180),a=Math.tan(t.rightDegrees*Math.PI/180),c=2/(o+a),h=2/(n+i);return e[0]=c,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=h,e[6]=0,e[7]=0,e[8]=-((o-a)*c*.5),e[9]=(n-i)*h*.5,e[10]=r/(s-r),e[11]=-1,e[12]=0,e[13]=0,e[14]=r*s/(s-r),e[15]=0,e}function Fr(e,t,s,r,n,i,o){let a=1/(t-s),c=1/(r-n),h=1/(i-o);return e[0]=-2*a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*h,e[11]=0,e[12]=(t+s)*a,e[13]=(n+r)*c,e[14]=(o+i)*h,e[15]=1,e}var vs=Fr;function jo(e,t,s,r,n,i,o){let a=1/(t-s),c=1/(r-n),h=1/(i-o);return e[0]=-2*a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=h,e[11]=0,e[12]=(t+s)*a,e[13]=(n+r)*c,e[14]=i*h,e[15]=1,e}function Is(e,t,s,r){let n,i,o,a,c,h,l,u,d,f,g=t[0],x=t[1],p=t[2],y=r[0],E=r[1],_=r[2],T=s[0],S=s[1],M=s[2];return Math.abs(g-T)<1e-6&&Math.abs(x-S)<1e-6&&Math.abs(p-M)<1e-6?zr(e):(u=g-T,d=x-S,f=p-M,n=1/Math.sqrt(u*u+d*d+f*f),u*=n,d*=n,f*=n,i=E*f-_*d,o=_*u-y*f,a=y*d-E*u,n=Math.sqrt(i*i+o*o+a*a),n?(n=1/n,i*=n,o*=n,a*=n):(i=0,o=0,a=0),c=d*a-f*o,h=f*i-u*a,l=u*o-d*i,n=Math.sqrt(c*c+h*h+l*l),n?(n=1/n,c*=n,h*=n,l*=n):(c=0,h=0,l=0),e[0]=i,e[1]=c,e[2]=u,e[3]=0,e[4]=o,e[5]=h,e[6]=d,e[7]=0,e[8]=a,e[9]=l,e[10]=f,e[11]=0,e[12]=-(i*g+o*x+a*p),e[13]=-(c*g+h*x+l*p),e[14]=-(u*g+d*x+f*p),e[15]=1,e)}function Xo(e,t,s,r){let n=t[0],i=t[1],o=t[2],a=r[0],c=r[1],h=r[2],l=n-s[0],u=i-s[1],d=o-s[2],f=l*l+u*u+d*d;f>0&&(f=1/Math.sqrt(f),l*=f,u*=f,d*=f);let g=c*d-h*u,x=h*l-a*d,p=a*u-c*l;return f=g*g+x*x+p*p,f>0&&(f=1/Math.sqrt(f),g*=f,x*=f,p*=f),e[0]=g,e[1]=x,e[2]=p,e[3]=0,e[4]=u*p-d*x,e[5]=d*g-l*p,e[6]=l*x-u*g,e[7]=0,e[8]=l,e[9]=u,e[10]=d,e[11]=0,e[12]=n,e[13]=i,e[14]=o,e[15]=1,e}function Qo(e){return`mat4(${e[0]}, ${e[1]}, ${e[2]}, ${e[3]}, ${e[4]}, ${e[5]}, ${e[6]}, ${e[7]}, ${e[8]}, ${e[9]}, ${e[10]}, ${e[11]}, ${e[12]}, ${e[13]}, ${e[14]}, ${e[15]})`}function Ko(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]+e[3]*e[3]+e[4]*e[4]+e[5]*e[5]+e[6]*e[6]+e[7]*e[7]+e[8]*e[8]+e[9]*e[9]+e[10]*e[10]+e[11]*e[11]+e[12]*e[12]+e[13]*e[13]+e[14]*e[14]+e[15]*e[15])}function Jo(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e[3]=t[3]+s[3],e[4]=t[4]+s[4],e[5]=t[5]+s[5],e[6]=t[6]+s[6],e[7]=t[7]+s[7],e[8]=t[8]+s[8],e[9]=t[9]+s[9],e[10]=t[10]+s[10],e[11]=t[11]+s[11],e[12]=t[12]+s[12],e[13]=t[13]+s[13],e[14]=t[14]+s[14],e[15]=t[15]+s[15],e}function Ur(e,t,s){return e[0]=t[0]-s[0],e[1]=t[1]-s[1],e[2]=t[2]-s[2],e[3]=t[3]-s[3],e[4]=t[4]-s[4],e[5]=t[5]-s[5],e[6]=t[6]-s[6],e[7]=t[7]-s[7],e[8]=t[8]-s[8],e[9]=t[9]-s[9],e[10]=t[10]-s[10],e[11]=t[11]-s[11],e[12]=t[12]-s[12],e[13]=t[13]-s[13],e[14]=t[14]-s[14],e[15]=t[15]-s[15],e}function ta(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e[3]=t[3]*s,e[4]=t[4]*s,e[5]=t[5]*s,e[6]=t[6]*s,e[7]=t[7]*s,e[8]=t[8]*s,e[9]=t[9]*s,e[10]=t[10]*s,e[11]=t[11]*s,e[12]=t[12]*s,e[13]=t[13]*s,e[14]=t[14]*s,e[15]=t[15]*s,e}function ea(e,t,s,r){return e[0]=t[0]+s[0]*r,e[1]=t[1]+s[1]*r,e[2]=t[2]+s[2]*r,e[3]=t[3]+s[3]*r,e[4]=t[4]+s[4]*r,e[5]=t[5]+s[5]*r,e[6]=t[6]+s[6]*r,e[7]=t[7]+s[7]*r,e[8]=t[8]+s[8]*r,e[9]=t[9]+s[9]*r,e[10]=t[10]+s[10]*r,e[11]=t[11]+s[11]*r,e[12]=t[12]+s[12]*r,e[13]=t[13]+s[13]*r,e[14]=t[14]+s[14]*r,e[15]=t[15]+s[15]*r,e}function sa(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]}function ra(e,t){let s=e[0],r=e[1],n=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],l=e[8],u=e[9],d=e[10],f=e[11],g=e[12],x=e[13],p=e[14],y=e[15],E=t[0],_=t[1],T=t[2],S=t[3],M=t[4],A=t[5],R=t[6],C=t[7],b=t[8],P=t[9],q=t[10],z=t[11],O=t[12],X=t[13],gt=t[14],xt=t[15];return Math.abs(s-E)<=1e-6*Math.max(1,Math.abs(s),Math.abs(E))&&Math.abs(r-_)<=1e-6*Math.max(1,Math.abs(r),Math.abs(_))&&Math.abs(n-T)<=1e-6*Math.max(1,Math.abs(n),Math.abs(T))&&Math.abs(i-S)<=1e-6*Math.max(1,Math.abs(i),Math.abs(S))&&Math.abs(o-M)<=1e-6*Math.max(1,Math.abs(o),Math.abs(M))&&Math.abs(a-A)<=1e-6*Math.max(1,Math.abs(a),Math.abs(A))&&Math.abs(c-R)<=1e-6*Math.max(1,Math.abs(c),Math.abs(R))&&Math.abs(h-C)<=1e-6*Math.max(1,Math.abs(h),Math.abs(C))&&Math.abs(l-b)<=1e-6*Math.max(1,Math.abs(l),Math.abs(b))&&Math.abs(u-P)<=1e-6*Math.max(1,Math.abs(u),Math.abs(P))&&Math.abs(d-q)<=1e-6*Math.max(1,Math.abs(d),Math.abs(q))&&Math.abs(f-z)<=1e-6*Math.max(1,Math.abs(f),Math.abs(z))&&Math.abs(g-O)<=1e-6*Math.max(1,Math.abs(g),Math.abs(O))&&Math.abs(x-X)<=1e-6*Math.max(1,Math.abs(x),Math.abs(X))&&Math.abs(p-gt)<=1e-6*Math.max(1,Math.abs(p),Math.abs(gt))&&Math.abs(y-xt)<=1e-6*Math.max(1,Math.abs(y),Math.abs(xt))}var na=kt,ia=Ur;function oa(){let e=new B(4);return B!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function kr(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e[3]=t[3]+s[3],e}function Wr(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e[3]=t[3]*s,e}function Yr(e){let t=e[0],s=e[1],r=e[2],n=e[3];return Math.sqrt(t*t+s*s+r*r+n*n)}function Gr(e){let t=e[0],s=e[1],r=e[2],n=e[3];return t*t+s*s+r*r+n*n}function $r(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=s*s+r*r+n*n+i*i;return o>0&&(o=1/Math.sqrt(o)),e[0]=s*o,e[1]=r*o,e[2]=n*o,e[3]=i*o,e}function Hr(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function Zr(e,t,s,r){let n=t[0],i=t[1],o=t[2],a=t[3];return e[0]=n+r*(s[0]-n),e[1]=i+r*(s[1]-i),e[2]=o+r*(s[2]-o),e[3]=a+r*(s[3]-a),e}function jr(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3];return e[0]=s[0]*r+s[4]*n+s[8]*i+s[12]*o,e[1]=s[1]*r+s[5]*n+s[9]*i+s[13]*o,e[2]=s[2]*r+s[6]*n+s[10]*i+s[14]*o,e[3]=s[3]*r+s[7]*n+s[11]*i+s[15]*o,e}function Xr(e,t,s){let r=t[0],n=t[1],i=t[2],o=s[0],a=s[1],c=s[2],h=s[3],l=h*r+a*i-c*n,u=h*n+c*r-o*i,d=h*i+o*n-a*r,f=-o*r-a*n-c*i;return e[0]=l*h+f*-o+u*-c-d*-a,e[1]=u*h+f*-a+d*-o-l*-c,e[2]=d*h+f*-c+l*-a-u*-o,e[3]=t[3],e}var yl=(function(){let e=oa();return function(t,s,r,n,i,o){let a,c;for(s||(s=4),r||(r=0),n?c=Math.min(n*s+r,t.length):c=t.length,a=r;a<c;a+=s)e[0]=t[a],e[1]=t[a+1],e[2]=t[a+2],e[3]=t[a+3],i(e,e,o),t[a]=e[0],t[a+1]=e[1],t[a+2]=e[2],t[a+3]=e[3];return t}})();var Ns;(function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL0ROW3=3]="COL0ROW3",e[e.COL1ROW0=4]="COL1ROW0",e[e.COL1ROW1=5]="COL1ROW1",e[e.COL1ROW2=6]="COL1ROW2",e[e.COL1ROW3=7]="COL1ROW3",e[e.COL2ROW0=8]="COL2ROW0",e[e.COL2ROW1=9]="COL2ROW1",e[e.COL2ROW2=10]="COL2ROW2",e[e.COL2ROW3=11]="COL2ROW3",e[e.COL3ROW0=12]="COL3ROW0",e[e.COL3ROW1=13]="COL3ROW1",e[e.COL3ROW2=14]="COL3ROW2",e[e.COL3ROW3=15]="COL3ROW3"})(Ns||(Ns={}));var aa=45*Math.PI/180,ca=1,Ls=.1,Ps=500,ha=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),v=class extends Ot{static get IDENTITY(){return ua()}static get ZERO(){return la()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Ns}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,s,r,n,i,o,a,c,h,l,u,d,f,g,x,p){return this[0]=t,this[1]=s,this[2]=r,this[3]=n,this[4]=i,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=l,this[10]=u,this[11]=d,this[12]=f,this[13]=g,this[14]=x,this[15]=p,this.check()}setRowMajor(t,s,r,n,i,o,a,c,h,l,u,d,f,g,x,p){return this[0]=t,this[1]=i,this[2]=h,this[3]=f,this[4]=s,this[5]=o,this[6]=l,this[7]=g,this[8]=r,this[9]=a,this[10]=u,this[11]=x,this[12]=n,this[13]=c,this[14]=d,this[15]=p,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(ha)}fromObject(t){return this.check()}fromQuaternion(t){return Cs(this,t),this.check()}frustum(t){let{left:s,right:r,bottom:n,top:i,near:o=Ls,far:a=Ps}=t;return a===1/0?da(this,s,r,n,i,o):Os(this,s,r,n,i,o,a),this.check()}lookAt(t){let{eye:s,center:r=[0,0,0],up:n=[0,1,0]}=t;return Is(this,s,r,n),this.check()}ortho(t){let{left:s,right:r,bottom:n,top:i,near:o=Ls,far:a=Ps}=t;return vs(this,s,r,n,i,o,a),this.check()}orthographic(t){let{fovy:s=aa,aspect:r=ca,focalDistance:n=1,near:i=Ls,far:o=Ps}=t;Kr(s);let a=s/2,c=n*Math.tan(a),h=c*r;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:i,far:o})}perspective(t){let{fovy:s=45*Math.PI/180,aspect:r=1,near:n=.1,far:i=500}=t;return Kr(s),As(this,s,r,n,i),this.check()}determinant(){return _s(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,s){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],s=s||[-0,-0,-0];let r=this.getScale(s),n=1/r[0],i=1/r[1],o=1/r[2];return t[0]=this[0]*n,t[1]=this[1]*i,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*n,t[5]=this[5]*i,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*n,t[9]=this[9]*i,t[10]=this[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,s){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],s=s||[-0,-0,-0];let r=this.getScale(s),n=1/r[0],i=1/r[1],o=1/r[2];return t[0]=this[0]*n,t[1]=this[1]*i,t[2]=this[2]*o,t[3]=this[4]*n,t[4]=this[5]*i,t[5]=this[6]*o,t[6]=this[8]*n,t[7]=this[9]*i,t[8]=this[10]*o,t}transpose(){return ys(this,this),this.check()}invert(){return Ts(this,this),this.check()}multiplyLeft(t){return kt(this,t,this),this.check()}multiplyRight(t){return kt(this,this,t),this.check()}rotateX(t){return bs(this,this,t),this.check()}rotateY(t){return Rs(this,this,t),this.check()}rotateZ(t){return ws(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,s){return Es(this,this,t,s),this.check()}scale(t){return Ss(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Ms(this,this,t),this.check()}transform(t,s){return t.length===4?(s=jr(s||[-0,-0,-0,-0],t,this),dt(s,4),s):this.transformAsPoint(t,s)}transformAsPoint(t,s){let{length:r}=t,n;switch(r){case 2:n=xr(s||[-0,-0],t,this);break;case 3:n=Tt(s||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return dt(n,t.length),n}transformAsVector(t,s){let r;switch(t.length){case 2:r=yr(s||[-0,-0],t,this);break;case 3:r=ce(s||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return dt(r,t.length),r}transformPoint(t,s){return this.transformAsPoint(t,s)}transformVector(t,s){return this.transformAsPoint(t,s)}transformDirection(t,s){return this.transformAsVector(t,s)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,s,r){return this.identity().translate([t,s,r])}},ye,Te;function la(){return ye||(ye=new v([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(ye)),ye}function ua(){return Te||(Te=new v,Object.freeze(Te)),Te}function Kr(e){if(e>Math.PI*2)throw Error("expected radians")}function da(e,t,s,r,n,i){let o=2*i/(s-t),a=2*i/(n-r),c=(s+t)/(s-t),h=(n+r)/(n-r),l=-1,u=-1,d=-2*i;return e[0]=o,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=a,e[6]=0,e[7]=0,e[8]=c,e[9]=h,e[10]=l,e[11]=u,e[12]=0,e[13]=0,e[14]=d,e[15]=0,e}function Jr(){let e=new B(4);return B!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function tn(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}function qs(e,t,s){s=s*.5;let r=Math.sin(s);return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=Math.cos(s),e}function zs(e,t,s){let r=t[0],n=t[1],i=t[2],o=t[3],a=s[0],c=s[1],h=s[2],l=s[3];return e[0]=r*l+o*a+n*h-i*c,e[1]=n*l+o*c+i*a-r*h,e[2]=i*l+o*h+r*c-n*a,e[3]=o*l-r*a-n*c-i*h,e}function en(e,t,s){s*=.5;let r=t[0],n=t[1],i=t[2],o=t[3],a=Math.sin(s),c=Math.cos(s);return e[0]=r*c+o*a,e[1]=n*c+i*a,e[2]=i*c-n*a,e[3]=o*c-r*a,e}function sn(e,t,s){s*=.5;let r=t[0],n=t[1],i=t[2],o=t[3],a=Math.sin(s),c=Math.cos(s);return e[0]=r*c-i*a,e[1]=n*c+o*a,e[2]=i*c+r*a,e[3]=o*c-n*a,e}function rn(e,t,s){s*=.5;let r=t[0],n=t[1],i=t[2],o=t[3],a=Math.sin(s),c=Math.cos(s);return e[0]=r*c+n*a,e[1]=n*c-r*a,e[2]=i*c+o*a,e[3]=o*c-i*a,e}function nn(e,t){let s=t[0],r=t[1],n=t[2];return e[0]=s,e[1]=r,e[2]=n,e[3]=Math.sqrt(Math.abs(1-s*s-r*r-n*n)),e}function Wt(e,t,s,r){let n=t[0],i=t[1],o=t[2],a=t[3],c=s[0],h=s[1],l=s[2],u=s[3],d,f,g,x,p;return d=n*c+i*h+o*l+a*u,d<0&&(d=-d,c=-c,h=-h,l=-l,u=-u),1-d>1e-6?(f=Math.acos(d),p=Math.sin(f),g=Math.sin((1-r)*f)/p,x=Math.sin(r*f)/p):(g=1-r,x=r),e[0]=g*n+x*c,e[1]=g*i+x*h,e[2]=g*o+x*l,e[3]=g*a+x*u,e}function on(e,t){let s=t[0],r=t[1],n=t[2],i=t[3],o=s*s+r*r+n*n+i*i,a=o?1/o:0;return e[0]=-s*a,e[1]=-r*a,e[2]=-n*a,e[3]=i*a,e}function an(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e}function Ds(e,t){let s=t[0]+t[4]+t[8],r;if(s>0)r=Math.sqrt(s+1),e[3]=.5*r,r=.5/r,e[0]=(t[5]-t[7])*r,e[1]=(t[6]-t[2])*r,e[2]=(t[1]-t[3])*r;else{let n=0;t[4]>t[0]&&(n=1),t[8]>t[n*3+n]&&(n=2);let i=(n+1)%3,o=(n+2)%3;r=Math.sqrt(t[n*3+n]-t[i*3+i]-t[o*3+o]+1),e[n]=.5*r,r=.5/r,e[3]=(t[i*3+o]-t[o*3+i])*r,e[i]=(t[i*3+n]+t[n*3+i])*r,e[o]=(t[o*3+n]+t[n*3+o])*r}return e}var cn=kr;var hn=Wr,ln=Hr,un=Zr,dn=Yr;var fn=Gr;var mn=$r;var pn=(function(){let e=le(),t=ue(1,0,0),s=ue(0,1,0);return function(r,n,i){let o=Vt(n,i);return o<-.999999?(yt(e,t,n),fs(e)<1e-6&&yt(e,s,n),cs(e,e),qs(r,e,Math.PI),r):o>.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(yt(e,n,i),r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=1+o,mn(r,r))}})(),Ll=(function(){let e=Jr(),t=Jr();return function(s,r,n,i,o,a){return Wt(e,r,o,a),Wt(t,n,i,a),Wt(s,e,t,2*a*(1-a)),s}})(),Pl=(function(){let e=Or();return function(t,s,r,n){return e[0]=r[0],e[3]=r[1],e[6]=r[2],e[1]=n[0],e[4]=n[1],e[7]=n[2],e[2]=-s[0],e[5]=-s[1],e[8]=-s[2],mn(t,Ds(t,e))}})();var ma=[0,0,0,1],it=class extends ut{constructor(t=0,s=0,r=0,n=1){super(-0,-0,-0,-0),Array.isArray(t)&&arguments.length===1?this.copy(t):this.set(t,s,r,n)}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this.check()}set(t,s,r,n){return this[0]=t,this[1]=s,this[2]=r,this[3]=n,this.check()}fromObject(t){return this[0]=t.x,this[1]=t.y,this[2]=t.z,this[3]=t.w,this.check()}fromMatrix3(t){return Ds(this,t),this.check()}fromAxisRotation(t,s){return qs(this,t,s),this.check()}identity(){return tn(this),this.check()}setAxisAngle(t,s){return this.fromAxisRotation(t,s)}get ELEMENTS(){return 4}get x(){return this[0]}set x(t){this[0]=I(t)}get y(){return this[1]}set y(t){this[1]=I(t)}get z(){return this[2]}set z(t){this[2]=I(t)}get w(){return this[3]}set w(t){this[3]=I(t)}len(){return dn(this)}lengthSquared(){return fn(this)}dot(t){return ln(this,t)}rotationTo(t,s){return pn(this,t,s),this.check()}add(t){return cn(this,this,t),this.check()}calculateW(){return nn(this,this),this.check()}conjugate(){return an(this,this),this.check()}invert(){return on(this,this),this.check()}lerp(t,s,r){return r===void 0?this.lerp(this,t,s):(un(this,t,s,r),this.check())}multiplyRight(t){return zs(this,this,t),this.check()}multiplyLeft(t){return zs(this,t,this),this.check()}normalize(){let t=this.len(),s=t>0?1/t:0;return this[0]=this[0]*s,this[1]=this[1]*s,this[2]=this[2]*s,this[3]=this[3]*s,t===0&&(this[3]=1),this.check()}rotateX(t){return en(this,this,t),this.check()}rotateY(t){return sn(this,this,t),this.check()}rotateZ(t){return rn(this,this,t),this.check()}scale(t){return hn(this,this,t),this.check()}slerp(t,s,r){let n,i,o;switch(arguments.length){case 1:({start:n=ma,target:i,ratio:o}=t);break;case 2:n=this,i=t,o=s;break;default:n=t,i=s,o=r}return Wt(this,n,i,o),this.check()}transformVector4(t,s=new me){return Xr(s,t,this),dt(s,4)}lengthSq(){return this.lengthSquared()}setFromAxisAngle(t,s){return this.setAxisAngle(t,s)}premultiply(t){return this.multiplyLeft(t)}multiply(t){return this.multiplyRight(t)}};var ft={};zt(ft,{EPSILON1:()=>pa,EPSILON10:()=>ba,EPSILON11:()=>Ra,EPSILON12:()=>wa,EPSILON13:()=>Ca,EPSILON14:()=>Oa,EPSILON15:()=>Aa,EPSILON16:()=>va,EPSILON17:()=>Ia,EPSILON18:()=>La,EPSILON19:()=>Pa,EPSILON2:()=>ga,EPSILON20:()=>Na,EPSILON3:()=>xa,EPSILON4:()=>ya,EPSILON5:()=>Ta,EPSILON6:()=>_a,EPSILON7:()=>Ma,EPSILON8:()=>Sa,EPSILON9:()=>Ea,PI_OVER_FOUR:()=>za,PI_OVER_SIX:()=>Da,PI_OVER_TWO:()=>qa,TWO_PI:()=>Ba});var pa=.1,ga=.01,xa=.001,ya=1e-4,Ta=1e-5,_a=1e-6,Ma=1e-7,Sa=1e-8,Ea=1e-9,ba=1e-10,Ra=1e-11,wa=1e-12,Ca=1e-13,Oa=1e-14,Aa=1e-15,va=1e-16,Ia=1e-17,La=1e-18,Pa=1e-19,Na=1e-20,qa=Math.PI/2,za=Math.PI/4,Da=Math.PI/6,Ba=Math.PI*2;var ct=6356752314245179e-9,Va={radii:[6378137,6378137,ct],radiiSquared:[6378137*6378137,6378137*6378137,ct*ct],oneOverRadii:[1/6378137,1/6378137,1/ct],oneOverRadiiSquared:[1/(6378137*6378137),1/(6378137*6378137),1/(ct*ct)],maximumRadius:Math.max(6378137,6378137,ct),centerToleranceSquared:.1};function _e(e){return e}var au=new m;function Fa(e,t=[],s=_e){return"longitude"in e?(t[0]=s(e.longitude),t[1]=s(e.latitude),t[2]=e.height):"x"in e?(t[0]=s(e.x),t[1]=s(e.y),t[2]=e.z):(t[0]=s(e[0]),t[1]=s(e[1]),t[2]=e[2]),t}function gn(e,t=[]){return Fa(e,t,D._cartographicRadians?_e:is)}function Ua(e,t,s=_e){return"longitude"in t?(t.longitude=s(e[0]),t.latitude=s(e[1]),t.height=e[2]):"x"in t?(t.x=s(e[0]),t.y=s(e[1]),t.z=e[2]):(t[0]=s(e[0]),t[1]=s(e[1]),t[2]=e[2]),t}function xn(e,t){return Ua(e,t,D._cartographicRadians?_e:os)}var yn=1e-14,ka=new m,Tn={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"}},Bs={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Yt={east:new m,north:new m,up:new m,west:new m,south:new m,down:new m},Wa=new m,Ya=new m,Ga=new m;function Vs(e,t,s,r,n,i){let o=Tn[t]&&Tn[t][s];F(o&&(!r||r===o));let a,c,h,l=ka.copy(n);if(K(l.x,0,yn)&&K(l.y,0,yn)){let d=Math.sign(l.z);a=Wa.fromArray(Bs[t]),t!=="east"&&t!=="west"&&a.scale(d),c=Ya.fromArray(Bs[s]),s!=="east"&&s!=="west"&&c.scale(d),h=Ga.fromArray(Bs[r]),r!=="east"&&r!=="west"&&h.scale(d)}else{let{up:d,east:f,north:g}=Yt;f.set(-l.y,l.x,0).normalize(),e.geodeticSurfaceNormal(l,d),g.copy(d).cross(f);let{down:x,west:p,south:y}=Yt;x.copy(d).scale(-1),p.copy(f).scale(-1),y.copy(g).scale(-1),a=Yt[t],c=Yt[s],h=Yt[r]}return i[0]=a.x,i[1]=a.y,i[2]=a.z,i[3]=0,i[4]=c.x,i[5]=c.y,i[6]=c.z,i[7]=0,i[8]=h.x,i[9]=h.y,i[10]=h.z,i[11]=0,i[12]=l.x,i[13]=l.y,i[14]=l.z,i[15]=1,i}var At=new m,$a=new m,Ha=new m;function _n(e,t,s=[]){let{oneOverRadii:r,oneOverRadiiSquared:n,centerToleranceSquared:i}=t;At.from(e);let o=At.x,a=At.y,c=At.z,h=r.x,l=r.y,u=r.z,d=o*o*h*h,f=a*a*l*l,g=c*c*u*u,x=d+f+g,p=Math.sqrt(1/x);if(!Number.isFinite(p))return;let y=$a;if(y.copy(e).scale(p),x<i)return y.to(s);let E=n.x,_=n.y,T=n.z,S=Ha;S.set(y.x*E*2,y.y*_*2,y.z*T*2);let M=(1-p)*At.len()/(.5*S.len()),A=0,R,C,b,P;do{M-=A,R=1/(1+M*E),C=1/(1+M*_),b=1/(1+M*T);let q=R*R,z=C*C,O=b*b,X=q*R,gt=z*C,xt=O*b;P=d*q+f*z+g*O-1;let ne=-2*(d*X*E+f*gt*_+g*xt*T);A=P/ne}while(Math.abs(P)>ft.EPSILON12);return At.scale([R,C,b]).to(s)}var Me=new m,Mn=new m,Xa=new m,st=new m,Qa=new m,Se=new m,w=class{constructor(t=0,s=0,r=0){this.centerToleranceSquared=ft.EPSILON1,F(t>=0),F(s>=0),F(r>=0),this.radii=new m(t,s,r),this.radiiSquared=new m(t*t,s*s,r*r),this.radiiToTheFourth=new m(t*t*t*t,s*s*s*s,r*r*r*r),this.oneOverRadii=new m(t===0?0:1/t,s===0?0:1/s,r===0?0:1/r),this.oneOverRadiiSquared=new m(t===0?0:1/(t*t),s===0?0:1/(s*s),r===0?0:1/(r*r)),this.minimumRadius=Math.min(t,s,r),this.maximumRadius=Math.max(t,s,r),this.radiiSquared.z!==0&&(this.squaredXOverSquaredZ=this.radiiSquared.x/this.radiiSquared.z),Object.freeze(this)}equals(t){return this===t||!!(t&&this.radii.equals(t.radii))}toString(){return this.radii.toString()}cartographicToCartesian(t,s=[0,0,0]){let r=Mn,n=Xa,[,,i]=t;this.geodeticSurfaceNormalCartographic(t,r),n.copy(this.radiiSquared).scale(r);let o=Math.sqrt(r.dot(n));return n.scale(1/o),r.scale(i),n.add(r),n.to(s)}cartesianToCartographic(t,s=[0,0,0]){Se.from(t);let r=this.scaleToGeodeticSurface(Se,st);if(!r)return;let n=this.geodeticSurfaceNormal(r,Mn),i=Qa;i.copy(Se).subtract(r);let o=Math.atan2(n.y,n.x),a=Math.asin(n.z),c=Math.sign(Ct.dot(i,Se))*Ct.length(i);return xn([o,a,c],s)}eastNorthUpToFixedFrame(t,s=new v){return Vs(this,"east","north","up",t,s)}localFrameToFixedFrame(t,s,r,n,i=new v){return Vs(this,t,s,r,n,i)}geocentricSurfaceNormal(t,s=[0,0,0]){return Me.from(t).normalize().to(s)}geodeticSurfaceNormalCartographic(t,s=[0,0,0]){let r=gn(t),n=r[0],i=r[1],o=Math.cos(i);return Me.set(o*Math.cos(n),o*Math.sin(n),Math.sin(i)).normalize(),Me.to(s)}geodeticSurfaceNormal(t,s=[0,0,0]){return Me.from(t).scale(this.oneOverRadiiSquared).normalize().to(s)}scaleToGeodeticSurface(t,s){return _n(t,this,s)}scaleToGeocentricSurface(t,s=[0,0,0]){st.from(t);let r=st.x,n=st.y,i=st.z,o=this.oneOverRadiiSquared,a=1/Math.sqrt(r*r*o.x+n*n*o.y+i*i*o.z);return st.multiplyScalar(a).to(s)}transformPositionToScaledSpace(t,s=[0,0,0]){return st.from(t).scale(this.oneOverRadii).to(s)}transformPositionFromScaledSpace(t,s=[0,0,0]){return st.from(t).scale(this.radii).to(s)}getSurfaceNormalIntersectionWithZAxis(t,s=0,r=[0,0,0]){F(K(this.radii.x,this.radii.y,ft.EPSILON15)),F(this.radii.z>0),st.from(t);let n=st.z*(1-this.squaredXOverSquaredZ);if(!(Math.abs(n)>=this.radii.z-s))return st.set(0,0,n).to(r)}};w.WGS84=new w(6378137,6378137,ct);function Gt(){let e;if(typeof window<"u"&&window.performance)e=window.performance.now();else if(typeof process<"u"&&process.hrtime){let t=process.hrtime();e=t[0]*1e3+t[1]/1e6}else e=Date.now();return e}var _t=class{constructor(t,s){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=t,this.type=s,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(t){return this.sampleSize=t,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(t){return this._count+=t,this._samples++,this._checkSampling(),this}subtractCount(t){return this._count-=t,this._samples++,this._checkSampling(),this}addTime(t){return this._time+=t,this.lastTiming=t,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=Gt(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Gt()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var tt=class{constructor(t){this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t,s="count"){return this._getOrCreate({name:t,type:s})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let s of Object.values(this.stats))t(s)}getTable(){let t={};return this.forEach(s=>{t[s.name]={time:s.time||0,count:s.count||0,average:s.getAverageTime()||0,hz:s.getHz()||0}}),t}_initializeStats(t=[]){t.forEach(s=>this._getOrCreate(s))}_getOrCreate(t){let{name:s,type:r}=t,n=this.stats[s];return n||(t instanceof _t?n=t:n=new _t(s,r),this.stats[s]=n),n}};function rt(e,t){if(!e)throw new Error(t||"loader assertion failed.")}var Ka="Queued Requests",Ja="Active Requests",tc="Cancelled Requests",ec="Queued Requests Ever",sc="Active Requests Ever",rc={id:"request-scheduler",throttleRequests:!0,maxRequests:6,debounceTime:0},ht=class{props;stats;activeRequestCount=0;requestQueue=[];requestMap=new Map;updateTimer=null;constructor(t={}){this.props={...rc,...t},this.stats=new tt({id:this.props.id}),this.stats.get(Ka),this.stats.get(Ja),this.stats.get(tc),this.stats.get(ec),this.stats.get(sc)}setProps(t){t.throttleRequests!==void 0&&(this.props.throttleRequests=t.throttleRequests),t.maxRequests!==void 0&&(this.props.maxRequests=t.maxRequests),t.debounceTime!==void 0&&(this.props.debounceTime=t.debounceTime)}scheduleRequest(t,s=()=>0){if(!this.props.throttleRequests)return Promise.resolve({done:()=>{}});if(this.requestMap.has(t))return this.requestMap.get(t);let r={handle:t,priority:0,getPriority:s},n=new Promise(i=>(r.resolve=i,r));return this.requestQueue.push(r),this.requestMap.set(t,n),this._issueNewRequests(),n}_issueRequest(t){let{handle:s,resolve:r}=t,n=!1,i=()=>{n||(n=!0,this.requestMap.delete(s),this.activeRequestCount--,this._issueNewRequests())};return this.activeRequestCount++,r?r({done:i}):Promise.resolve({done:i})}_issueNewRequests(){this.updateTimer!==null&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>this._issueNewRequestsAsync(),this.props.debounceTime)}_issueNewRequestsAsync(){this.updateTimer!==null&&clearTimeout(this.updateTimer),this.updateTimer=null;let t=Math.max(this.props.maxRequests-this.activeRequestCount,0);if(t!==0){this._updateAllRequests();for(let s=0;s<t;++s){let r=this.requestQueue.shift();r&&this._issueRequest(r)}}}_updateAllRequests(){let t=this.requestQueue;for(let s=0;s<t.length;++s){let r=t[s];this._updateRequest(r)||(t.splice(s,1),this.requestMap.delete(r.handle),s--)}t.sort((s,r)=>s.priority-r.priority)}_updateRequest(t){return t.priority=t.getPriority(t.handle),t.priority<0?(t.resolve(null),!1):!0}};var N={logicalRanges:"Logical Range Requests",rangeBatches:"Range Request Batches",transportRanges:"Transport Ranges Created",completedTransportRanges:"Range Transport Requests Completed",coalescedRanges:"Coalesced Logical Ranges",requestedBytes:"Logical Range Request Bytes",transportBytes:"Range Transport Bytes Requested",responseBytes:"Range Response Bytes",networkTimeMs:"Range Network Time",overfetchBytes:"Range Overfetch Bytes",failedTransportRanges:"Range Transport Requests Failed",abortedLogicalRanges:"Aborted Logical Range Requests",fullResponseFallbacks:"Full Response Fallbacks"},Fs={batchDelayMs:50,maxGapBytes:65536,rangeExpansionBytes:65536,maxMergedBytes:8388608,stats:bn("range-request-scheduler-default"),onEvent:()=>{}},Ee=class{props;stats;onEvent;pendingRequests=[];flushTimer=null;constructor(t={}){let s=t.rangeExpansionBytes??t.maxGapBytes??Fs.rangeExpansionBytes;this.props={batchDelayMs:t.batchDelayMs??Fs.batchDelayMs,maxGapBytes:t.maxGapBytes??s,rangeExpansionBytes:s,maxMergedBytes:t.maxMergedBytes??Fs.maxMergedBytes},this.stats=t.stats||bn("range-request-scheduler"),this.onEvent=t.onEvent,Rn(this.stats)}scheduleRequest(t){if(t.length<0)return Promise.reject(new Error("Byte range length cannot be negative"));if(t.signal?.aborted)return Promise.reject(En());if(t.length===0)return Promise.resolve(new ArrayBuffer(0));let s=new Promise((r,n)=>{let i={...t,resolve:r,reject:n,settled:!1};t.signal&&(i.abortListener=()=>{this.abortRequest(i),i.onAbort?.()},t.signal.addEventListener("abort",i.abortListener,{once:!0})),this.pendingRequests.push(i)});return this.trackEvent({type:"queued",sourceId:t.sourceId,offset:t.offset,length:t.length,logicalRequestCount:1,logicalBytes:t.length}),this.scheduleFlush(),s}fetch(t){let s=t.fetch||globalThis.fetch;return this.scheduleRequest({sourceId:t.sourceId||t.url,offset:t.offset,length:t.length,signal:t.signal,isolationKey:t.isolationKey??{},fetchRange:(r,n,i)=>ic({url:t.url,offset:r,length:n,signal:i,fetch:s,fetchOptions:t.fetchOptions})})}flush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null);let t=this.pendingRequests;this.pendingRequests=[];let s=t.filter(n=>n.settled||n.signal?.aborted?(this.abortRequest(n),!1):!0),r=this.mergeRequests(s);s.length>0&&this.trackBatch(s,r);for(let n of r)this.fetchMergedRequest(n)}scheduleFlush(){this.flushTimer||(this.flushTimer=setTimeout(()=>this.flush(),this.props.batchDelayMs))}mergeRequests(t){t.sort((r,n)=>r.sourceId!==n.sourceId?r.sourceId<n.sourceId?-1:1:r.offset-n.offset);let s=[];for(let r of t){let n=r.offset+r.length,i=s[s.length-1];i&&oc(i,r,this.props)?(i.endOffset=Math.max(i.endOffset,n),i.requests.push(r)):s.push({sourceId:r.sourceId,isolationKey:r.isolationKey??r.sourceId,offset:r.offset,endOffset:n,fetchRange:r.fetchRange,requests:[r]})}return s}async fetchMergedRequest(t){let{offset:s,endOffset:r,fetchRange:n,requests:i}=t,o=new AbortController,a=$t(),c=()=>{i.every(h=>h.signal?.aborted)&&o.abort()};try{for(let p of i)p.onAbort=c;if(c(),i.every(p=>p.settled))return;let h=Us(i),l=r-s;this.trackEvent({type:"request",sourceId:t.sourceId,offset:s,length:l,logicalRequestCount:i.length,logicalBytes:h,transportBytes:l,overfetchBytes:Math.max(l-h,0)});let u=ac(await n(s,l,o.signal)),{arrayBuffer:d}=u,f=u.fullResponse&&s===0&&d.byteLength<l,g=d.byteLength<l&&Number.isSafeInteger(u.sourceByteLength)&&s+d.byteLength===u.sourceByteLength;if(d.byteLength!==l&&!f&&!g)throw new Error(`Byte-range transport returned ${d.byteLength} bytes; expected ${l}`);let x=u.networkTimeMs??$t()-a;this.trackEvent({type:"response",sourceId:t.sourceId,offset:s,length:l,logicalRequestCount:i.length,logicalBytes:h,transportBytes:l,responseBytes:u.transportBytes??d.byteLength,networkTimeMs:x,overfetchBytes:Math.max(l-h,0),status:u.status,fullResponse:u.fullResponse});for(let p of i){if(p.settled)continue;let y=p.offset-s;p.settled=!0,p.resolve(d.slice(y,y+p.length))}}catch(h){this.trackEvent({type:"error",sourceId:t.sourceId,offset:s,length:r-s,logicalRequestCount:i.length,logicalBytes:Us(i),networkTimeMs:$t()-a,error:h});for(let l of i)l.settled||(l.signal?.aborted?this.abortRequest(l):(l.settled=!0,l.reject(h)))}finally{for(let h of i)h.abortListener&&h.signal?.removeEventListener("abort",h.abortListener),h.onAbort=void 0}}abortRequest(t){t.settled||(t.settled=!0,t.reject(En()),this.trackEvent({type:"abort",sourceId:t.sourceId,offset:t.offset,length:t.length,logicalRequestCount:1,logicalBytes:t.length}))}trackEvent(t){nc(this.stats,t);try{this.onEvent?.(t)}catch{}}trackBatch(t,s){let r=Us(t),n=s.reduce((i,o)=>i+o.endOffset-o.offset,0);this.trackEvent({type:"batch",logicalRequestCount:t.length,transportRequestCount:s.length,logicalBytes:r,transportBytes:n,overfetchBytes:Math.max(n-r,0)})}};function nc(e,t){switch((t.type==="response"||t.type==="error")&&t.networkTimeMs!==void 0&&e.get(N.networkTimeMs,"time").addTime(t.networkTimeMs),t.type){case"queued":e.get(N.logicalRanges,"count").incrementCount(),e.get(N.requestedBytes,"count").addCount(t.logicalBytes||0);break;case"batch":e.get(N.rangeBatches,"count").incrementCount(),e.get("Logical Ranges Batched","count").addCount(t.logicalRequestCount||0),e.get(N.transportRanges,"count").addCount(t.transportRequestCount||0),e.get(N.coalescedRanges,"count").addCount(Math.max((t.logicalRequestCount||0)-(t.transportRequestCount||0),0)),e.get(N.transportBytes,"count").addCount(t.transportBytes||0),e.get(N.overfetchBytes,"count").addCount(t.overfetchBytes||0);break;case"response":e.get(N.completedTransportRanges,"count").incrementCount(),e.get(N.responseBytes,"count").addCount(t.responseBytes||0),t.fullResponse&&e.get(N.fullResponseFallbacks,"count").incrementCount();break;case"error":e.get(N.failedTransportRanges,"count").incrementCount();break;case"abort":e.get(N.abortedLogicalRanges,"count").incrementCount();break;default:}}function bn(e="range-request-scheduler"){let t=new tt({id:e});return Rn(t),t}async function ic(e){let t=uc(e.signal),s=$t();try{let r=!1,n=await e.fetch(e.url,Sn(e.fetchOptions,e.offset,e.length,t.signal));if(n.status===416&&e.offset===0){let c=hc(n.headers.get("Content-Range"));if(!c)throw new Error("Missing content-length on 416 response");n=await e.fetch(e.url,Sn(e.fetchOptions,0,c,t.signal)),r=!0}if(n.status===200)throw t.abort(),await dc(n),new Error("Byte-range request failed: server returned 200 instead of 206");if(n.status!==206&&!n.ok)throw new Error(`Bad response code: ${n.status}`);let i=await n.arrayBuffer(),o=n.headers.get("Content-Range"),a=lc(o);if(o&&!a)throw new Error(`Invalid Content-Range header: ${o}`);if(a){let c=a.endOffset-a.offset+1,h=e.offset+e.length-1;if(a.offset!==e.offset||a.endOffset>h||c!==i.byteLength||a.sourceByteLength!==void 0&&a.endOffset>=a.sourceByteLength)throw new Error(`Content-Range does not match requested range: ${o}`)}return{arrayBuffer:i,status:n.status,sourceByteLength:a?.sourceByteLength,transportBytes:i.byteLength,networkTimeMs:$t()-s,fullResponse:r}}finally{t.removeAbortListener()}}function oc(e,t,s){if(e.sourceId!==t.sourceId||e.isolationKey!==(t.isolationKey??t.sourceId))return!1;let r=t.offset+t.length,n=t.offset-e.endOffset,i=Math.max(e.endOffset,r)-e.offset;return n<=s.rangeExpansionBytes&&i<=s.maxMergedBytes}function Rn(e){e.get(N.logicalRanges,"count"),e.get(N.requestedBytes,"count"),e.get(N.rangeBatches,"count"),e.get("Logical Ranges Batched","count"),e.get(N.transportRanges,"count"),e.get(N.coalescedRanges,"count"),e.get(N.transportBytes,"count"),e.get(N.completedTransportRanges,"count"),e.get(N.responseBytes,"count"),e.get(N.networkTimeMs,"time"),e.get(N.overfetchBytes,"count"),e.get(N.fullResponseFallbacks,"count"),e.get(N.failedTransportRanges,"count"),e.get(N.abortedLogicalRanges,"count")}function Us(e){return e.reduce((t,s)=>t+s.length,0)}function ac(e){return e instanceof ArrayBuffer?{arrayBuffer:e}:e}function Sn(e,t,s,r){return{...e,signal:r,headers:{...cc(e?.headers),Range:`bytes=${t}-${t+s-1}`}}}function cc(e){return e?e instanceof Headers?Object.fromEntries(e.entries()):Array.isArray(e)?Object.fromEntries(e):e:{}}function hc(e){let t=e?.match(/^bytes \*\/(\d+)$/);return t?Number(t[1]):null}function lc(e){let t=e?.match(/^bytes (\d+)-(\d+)\/(\d+|\*)$/);if(!t)return null;let s=Number(t[1]),r=Number(t[2]),n=t[3]==="*"?void 0:Number(t[3]);return!Number.isSafeInteger(s)||!Number.isSafeInteger(r)||s>r||n!==void 0&&!Number.isSafeInteger(n)?null:{offset:s,endOffset:r,sourceByteLength:n}}function uc(e){let t=new AbortController,s=()=>t.abort();return e?.aborted?t.abort():e?.addEventListener("abort",s,{once:!0}),{signal:t.signal,abort:()=>t.abort(),removeAbortListener:()=>e?.removeEventListener("abort",s)}}async function dc(e){await e.body?.cancel().catch(()=>{})}function $t(){return globalThis.performance?.now()??Date.now()}function En(){if(typeof DOMException<"u")return new DOMException("Request aborted","AbortError");let e=new Error("Request aborted");return e.name="AbortError",e}var J={};zt(J,{dirname:()=>mc,filename:()=>fc,join:()=>pc,resolve:()=>gc});function wn(){if(typeof process<"u"&&typeof process.cwd<"u")return process.cwd();let e=window.location?.pathname;return e?.slice(0,e.lastIndexOf("/")+1)||""}function fc(e){let t=e?e.lastIndexOf("/"):-1;return t>=0?e.substr(t+1):e}function mc(e){let t=e?e.lastIndexOf("/"):-1;return t>=0?e.substr(0,t):""}function pc(...e){return e=e.map((s,r)=>(r&&(s=s.replace(new RegExp("^/"),"")),r!==e.length-1&&(s=s.replace(new RegExp("/$"),"")),s)),e.join("/")}function gc(...e){let t=[];for(let i=0;i<e.length;i++)t[i]=e[i];let s="",r=!1,n;for(let i=t.length-1;i>=-1&&!r;i--){let o;i>=0?o=t[i]:(n===void 0&&(n=wn()),o=n),o.length!==0&&(s=`${o}/${s}`,r=o.charCodeAt(0)===Ht)}return s=xc(s,!r),r?`/${s}`:s.length>0?s:"."}var Ht=47,ks=46;function xc(e,t){let s="",r=-1,n=0,i,o=!1;for(let a=0;a<=e.length;++a){if(a<e.length)i=e.charCodeAt(a);else{if(i===Ht)break;i=Ht}if(i===Ht){if(!(r===a-1||n===1))if(r!==a-1&&n===2){if(s.length<2||!o||s.charCodeAt(s.length-1)!==ks||s.charCodeAt(s.length-2)!==ks){if(s.length>2){let c=s.length-1,h=c;for(;h>=0&&s.charCodeAt(h)!==Ht;--h);if(h!==c){s=h===-1?"":s.slice(0,h),r=a,n=0,o=!1;continue}}else if(s.length===2||s.length===1){s="",r=a,n=0,o=!1;continue}}t&&(s.length>0?s+="/..":s="..",o=!0)}else{let c=e.slice(r+1,a);s.length>0?s+=`/${c}`:s=c,o=!1}r=a,n=0}else i===ks&&n!==-1?++n:n=-1}return s}var vt=class{handle;size;bigsize;url;constructor(t){this.handle=t instanceof ArrayBuffer?new Blob([t]):t,this.size=t instanceof ArrayBuffer?t.byteLength:t.size,this.bigsize=BigInt(this.size),this.url=t instanceof File?t.name:""}async close(){}async stat(){return{size:this.handle.size,bigsize:BigInt(this.handle.size),isDirectory:!1}}async read(t,s,r){if(r?.aborted)throw new Error("Request aborted");let n=await this.handle.slice(Number(t),Number(t)+Number(s)).arrayBuffer();if(r?.aborted)throw new Error("Request aborted");return n}};var we=class{url;fetchFunction;fetchOptions;consistency;identityHints;countedFailures=new WeakSet;telemetry={requestedBytes:0,downloadedBytes:0,requestCount:0,networkTimeMs:0,abortCount:0,errorCount:0};constructor(t,s){Ec(s.byteLength),this.url=t,this.fetchFunction=s.fetch||((r,n)=>globalThis.fetch(r,n)),this.fetchOptions=s.fetchOptions?{...s.fetchOptions,headers:new Headers(s.fetchOptions.headers)}:void 0,this.consistency=s.consistency||"best-effort",this.identityHints={byteLength:s.byteLength,etag:Oe(s.etag),lastModified:Oe(s.lastModified)}}getInitialIdentity(){let{byteLength:t,etag:s,lastModified:r}=this.identityHints;return t!==void 0&&(s!==void 0||r!==void 0)?Ce(t,s,r):t===0&&this.consistency==="best-effort"?Ce(0):null}getTelemetry(){return Object.freeze({...this.telemetry})}trackFailure(t){if(typeof t=="object"&&t!==null){if(this.countedFailures.has(t))return;this.countedFailures.add(t)}vn(t)?this.telemetry.abortCount++:this.telemetry.errorCount++}async requestRange(t,s,r,n){let i=be(),o=bc(r,this.fetchOptions?.signal);this.telemetry.requestCount++,this.telemetry.requestedBytes+=s;try{let a=await this.fetchFunction(this.url,yc(this.fetchOptions,t,s,o.signal));if(Tc(a,t,s,n))return await this.readEmptyIdentityProbe(a,i);if(a.status!==206)throw await Re(a),new Error(`HTTP byte-range request expected 206, received ${a.status}`);let c=await _c(a),h=Cn(a,c.byteLength),l=An(n,h,this.identityHints,this.consistency)||Sc(c,t,s);if(l)throw await Re(a),new Error(l);let u=await a.arrayBuffer();if(this.telemetry.downloadedBytes+=u.byteLength,u.byteLength!==s)throw new Error(`HTTP byte-range response contained ${u.byteLength} bytes; expected ${s}`);return{arrayBuffer:u,identity:On(n,h,this.identityHints),status:a.status,transportBytes:u.byteLength,networkTimeMs:be()-i}}catch(a){throw(n===null||!vn(a))&&this.trackFailure(a),a}finally{o.removeAbortListeners(),this.telemetry.networkTimeMs+=be()-i}}async readEmptyIdentityProbe(t,s){let r=Cn(t,0),n=An(null,r,this.identityHints,this.consistency);if(await Re(t),n)throw new Error(n);return{arrayBuffer:new ArrayBuffer(0),identity:On(null,r,this.identityHints),status:t.status,transportBytes:0,networkTimeMs:be()-s}}};function yc(e,t,s,r){let n=new Headers(e?.headers);return n.set("Range",`bytes=${t}-${t+s-1}`),{...e,method:"GET",body:void 0,headers:n,signal:r}}function Tc(e,t,s,r){return e.status===416&&r===null&&t===0&&s===1&&/^bytes \*\/0$/i.test(e.headers.get("Content-Range")||"")}async function _c(e){try{return Mc(e.headers.get("Content-Range"))}catch(t){throw await Re(e),t}}function Mc(e){let t=e?.match(/^bytes (\d+)-(\d+)\/(\d+)$/);if(!t)throw new Error("HTTP byte-range response has an invalid Content-Range header");return{offset:Number(t[1]),endOffset:Number(t[2]),byteLength:Number(t[3])}}function Cn(e,t){return Ce(t,Oe(e.headers.get("ETag")),Oe(e.headers.get("Last-Modified")))}function On(e,t,s){return e||Ce(t.byteLength,t.etag??s.etag,t.lastModified??s.lastModified)}function Sc(e,t,s){return!Number.isSafeInteger(e.offset)||!Number.isSafeInteger(e.endOffset)||!Number.isSafeInteger(e.byteLength)||e.offset<0||e.endOffset<e.offset||e.endOffset>=e.byteLength?"HTTP byte-range response has invalid range bounds":e.offset!==t||e.endOffset!==t+s-1?"HTTP byte-range response does not match the requested range":null}function An(e,t,s,r){let n=e?.byteLength??s.byteLength;if(n!==void 0&&t.byteLength!==n)return"HTTP file length changed while the file was open";let i=e?.etag??s.etag,o=e?.lastModified??s.lastModified;return i?t.etag?i===t.etag?null:"HTTP file ETag changed while the file was open":r==="strict"?"HTTP byte-range response is missing the pinned ETag":o&&t.lastModified&&o!==t.lastModified?"HTTP file Last-Modified value changed while the file was open":null:o?t.lastModified&&o!==t.lastModified?"HTTP file Last-Modified value changed while the file was open":r==="strict"&&!t.lastModified?"HTTP byte-range response is missing the pinned Last-Modified value":null:r==="strict"&&!t.etag&&!t.lastModified?"HTTP byte-range response does not provide an ETag or Last-Modified validator":null}function Ce(e,t,s){return Object.freeze({byteLength:e,etag:t,lastModified:s})}function Ec(e){if(e!==void 0&&(!Number.isSafeInteger(e)||e<0))throw new Error("HttpFile byteLength must be a non-negative safe integer")}async function Re(e){await e.body?.cancel().catch(()=>{})}function Oe(e){return e||void 0}function be(){return globalThis.performance?.now()??Date.now()}function vn(e){return e instanceof Error&&e.name==="AbortError"||e instanceof Error&&/aborted/i.test(e.message)}function bc(...e){let t=new AbortController,s=[...new Set(e.filter(n=>!!n))],r=()=>t.abort();for(let n of s)n.aborted?t.abort():n.addEventListener("abort",r,{once:!0});return{signal:t.signal,removeAbortListeners:()=>{for(let n of s)n.removeEventListener("abort",r)}}}var Zt=class e{handle;url;transport;rangeScheduler;schedulerIsolationKey={};suppliedByteLength;identity;openPromise=null;closed=!1;constructor(t,s={}){this.handle=t,this.url=t,this.transport=new we(t,s),this.rangeScheduler=s.rangeScheduler||new Ee({batchDelayMs:0,...s.rangeSchedulerProps}),this.suppliedByteLength=s.byteLength,this.identity=this.transport.getInitialIdentity()}static async open(t,s={},r){let n=new e(t,s);return await n.open(r),n}async open(t){if(this.assertOpen(),t?.aborted){let s=Ae();throw this.transport.trackFailure(s),s}return await this.getIdentity(t),this}get size(){return this.identity?.byteLength??this.suppliedByteLength??0}get bigsize(){return BigInt(this.size)}getIdentitySnapshot(){return this.identity}getTelemetry(){return this.transport.getTelemetry()}async close(){this.closed=!0}async stat(){this.assertOpen();let t=await this.getIdentity();return{size:t.byteLength,bigsize:BigInt(t.byteLength),isDirectory:!1}}async read(t=0,s=0,r){if(this.assertOpen(),r?.aborted){let o=Ae();throw this.transport.trackFailure(o),o}let n=await this.getIdentity(r),i=In(t);if(wc(i,s,n.byteLength),s===0)return new ArrayBuffer(0);try{return await this.rangeScheduler.scheduleRequest({sourceId:this.url,isolationKey:this.schedulerIsolationKey,offset:i,length:s,signal:r,fetchRange:this.fetchScheduledRange})}catch(o){throw this.transport.trackFailure(o),o}}async fetchRange(t,s,r){let n=In(t),i=await this.read(n,s,r),o=Rc(this.identity,n,s);return new Response(i,{status:206,headers:o})}fetchScheduledRange=async(t,s,r)=>{let n=await this.getIdentity(r),i=await this.transport.requestRange(t,s,r,n);return{arrayBuffer:i.arrayBuffer,status:i.status,transportBytes:i.transportBytes,networkTimeMs:i.networkTimeMs}};getIdentity(t){if(this.identity)return Promise.resolve(this.identity);if(!this.openPromise){let r=this.probeIdentity().catch(n=>{throw this.openPromise===r&&(this.openPromise=null),n});this.openPromise=r}return Cc(this.openPromise,t).catch(s=>{throw this.transport.trackFailure(s),s})}async probeIdentity(){try{let t=await this.transport.requestRange(0,1,void 0,null);return this.identity=t.identity,t.identity}catch(t){throw this.transport.trackFailure(t),t}}assertOpen(){if(this.closed)throw new Error("HttpFile is closed")}};function Rc(e,t,s){let r=new Headers;return s>0&&e&&r.set("Content-Range",`bytes ${t}-${t+s-1}/${e.byteLength}`),e?.etag&&r.set("ETag",e.etag),e?.lastModified&&r.set("Last-Modified",e.lastModified),r}function In(e){let t=Number(e);if(!Number.isSafeInteger(t)||t<0)throw new Error("HTTP byte-range offset must be a non-negative safe integer");return t}function wc(e,t,s){if(!Number.isSafeInteger(t)||t<0)throw new Error("HTTP byte-range length must be a non-negative safe integer");if(e+t>s)throw new Error("HTTP byte range extends beyond the end of the file")}function Ae(){if(typeof DOMException<"u")return new DOMException("Request aborted","AbortError");let e=new Error("Request aborted");return e.name="AbortError",e}function Cc(e,t){return t?t.aborted?Promise.reject(Ae()):new Promise((s,r)=>{let n=()=>{t.removeEventListener("abort",n),r(Ae())};t.addEventListener("abort",n,{once:!0}),e.then(i=>{t.removeEventListener("abort",n),s(i)},i=>{t.removeEventListener("abort",n),r(i)})}):e}var ve=class{item;previous;next;constructor(t,s,r){this.item=t,this.previous=s,this.next=r}};var Ie=class{head=null;tail=null;_length=0;get length(){return this._length}add(t){let s=new ve(t,this.tail,null);return this.tail?(this.tail.next=s,this.tail=s):(this.head=s,this.tail=s),++this._length,s}remove(t){t&&(t.previous&&t.next?(t.previous.next=t.next,t.next.previous=t.previous):t.previous?(t.previous.next=null,this.tail=t.previous):t.next?(t.next.previous=null,this.head=t.next):(this.head=null,this.tail=null),t.next=null,t.previous=null,--this._length)}splice(t,s){t!==s&&(this.remove(s),this._insert(t,s))}_insert(t,s){let r=t.next;t.next=s,this.tail===t?this.tail=s:r.previous=s,s.next=r,s.previous=t,++this._length}};var It=class{_list;_sentinel;_trimTiles;constructor(){this._list=new Ie,this._sentinel=this._list.add("sentinel"),this._trimTiles=!1}reset(){this._list.splice(this._list.tail,this._sentinel)}touch(t){let s=t._cacheNode;s&&this._list.splice(this._sentinel,s)}add(t,s,r){s._cacheNode||(s._cacheNode=this._list.add(s),r&&r(t,s))}unloadTile(t,s,r){let n=s._cacheNode;n&&(this._list.remove(n),s._cacheNode=null,r&&r(t,s))}unloadTiles(t,s){let r=this._trimTiles;this._trimTiles=!1;let n=this._list,i=this._sentinel,o=n.head;for(;o!==i&&(t.gpuMemoryUsageInBytes>t.cacheBytes||r);){let a=o.item;o=o.next,this.unloadTile(t,a,s)}}trim(){this._trimTiles=!0}};function Le(e,t){rt(e),rt(t);let{rtcCenter:s,gltfUpAxis:r}=t,{computedTransform:n,boundingVolume:{center:i}}=e,o=new v(n);switch(s&&o.translate(s),r){case"Z":break;case"Y":let d=new v().rotateX(Math.PI/2);o=o.multiplyRight(d);break;case"X":let f=new v().rotateY(-Math.PI/2);o=o.multiplyRight(f);break;default:break}t.isQuantized&&o.translate(t.quantizedVolumeOffset).scale(t.quantizedVolumeScale);let a=new m(i);t.cartesianModelMatrix=o,t.cartesianOrigin=a;let c=w.WGS84.cartesianToCartographic(a,new m),l=w.WGS84.eastNorthUpToFixedFrame(a).invert();t.cartographicModelMatrix=l.multiplyRight(o),t.cartographicOrigin=c;let u=Ac(t);u&&(t.cartesianModelMatrix=new v(o).multiplyRight(u.matrix),t.cartographicModelMatrix.multiplyRight(u.matrix),u.matrix=v.IDENTITY),t.coordinateSystem||(t.modelMatrix=t.cartographicModelMatrix)}var Oc=1e6**2;function Ac(e){let t=e.gltf;if(!t)return null;let s=typeof t.scene=="number"?t.scene:0,n=t.scenes?.[s]?.nodes?.[0];if(!n?.matrix)return null;let i=n.matrix;return i[12]*i[12]+i[13]*i[13]+i[14]*i[14]<=Oc?null:n}var U={OUTSIDE:-1,INTERSECTING:0,INSIDE:1};var ad=new m,cd=new m;var jt=new m,Ln=new m,Z=class e{constructor(t=[0,0,0],s=0){this.radius=-0,this.center=new m,this.fromCenterRadius(t,s)}fromCenterRadius(t,s){return this.center.from(t),this.radius=s,this}fromCornerPoints(t,s){return s=jt.from(s),this.center=new m().from(t).add(s).scale(.5),this.radius=this.center.distance(s),this}equals(t){return this===t||!!t&&this.center.equals(t.center)&&this.radius===t.radius}clone(){return new e(this.center,this.radius)}union(t){let s=this.center,r=this.radius,n=t.center,i=t.radius,o=jt.copy(n).subtract(s),a=o.magnitude();if(r>=a+i)return this.clone();if(i>=a+r)return t.clone();let c=(r+a+i)*.5;return Ln.copy(o).scale((-r+c)/a).add(s),this.center.copy(Ln),this.radius=c,this}expand(t){let r=jt.from(t).subtract(this.center).magnitude();return r>this.radius&&(this.radius=r),this}transform(t){this.center.transform(t);let s=xe.getScaling(jt,t);return this.radius=Math.max(s[0],Math.max(s[1],s[2]))*this.radius,this}distanceSquaredTo(t){let s=this.distanceTo(t);return s*s}distanceTo(t){let r=jt.from(t).subtract(this.center);return Math.max(0,r.len()-this.radius)}intersectPlane(t){let s=this.center,r=this.radius,i=t.normal.dot(s)+t.distance;return i<-r?U.OUTSIDE:i<r?U.INTERSECTING:U.INSIDE}};var vc=new m,Ic=new m,Pe=new m,Ne=new m,qe=new m,Lc=new m,Pc=new m,lt={COLUMN0ROW0:0,COLUMN0ROW1:1,COLUMN0ROW2:2,COLUMN1ROW0:3,COLUMN1ROW1:4,COLUMN1ROW2:5,COLUMN2ROW0:6,COLUMN2ROW1:7,COLUMN2ROW2:8},mt=class e{constructor(t=[0,0,0],s=[0,0,0,0,0,0,0,0,0]){this.center=new m().from(t),this.halfAxes=new V(s)}get halfSize(){let t=this.halfAxes.getColumn(0),s=this.halfAxes.getColumn(1),r=this.halfAxes.getColumn(2);return[new m(t).len(),new m(s).len(),new m(r).len()]}get quaternion(){let t=this.halfAxes.getColumn(0),s=this.halfAxes.getColumn(1),r=this.halfAxes.getColumn(2),n=new m(t).normalize(),i=new m(s).normalize(),o=new m(r).normalize();return new it().fromMatrix3(new V([...n,...i,...o]))}fromCenterHalfSizeQuaternion(t,s,r){let n=new it(r),i=new V().fromQuaternion(n);return i[0]=i[0]*s[0],i[1]=i[1]*s[0],i[2]=i[2]*s[0],i[3]=i[3]*s[1],i[4]=i[4]*s[1],i[5]=i[5]*s[1],i[6]=i[6]*s[2],i[7]=i[7]*s[2],i[8]=i[8]*s[2],this.center=new m().from(t),this.halfAxes=i,this}clone(){return new e(this.center,this.halfAxes)}equals(t){return this===t||!!t&&this.center.equals(t.center)&&this.halfAxes.equals(t.halfAxes)}getBoundingSphere(t=new Z){let s=this.halfAxes,r=s.getColumn(0,Pe),n=s.getColumn(1,Ne),i=s.getColumn(2,qe),o=vc.copy(r).add(n).add(i);return t.center.copy(this.center),t.radius=o.magnitude(),t}intersectPlane(t){let s=this.center,r=t.normal,n=this.halfAxes,i=r.x,o=r.y,a=r.z,c=Math.abs(i*n[lt.COLUMN0ROW0]+o*n[lt.COLUMN0ROW1]+a*n[lt.COLUMN0ROW2])+Math.abs(i*n[lt.COLUMN1ROW0]+o*n[lt.COLUMN1ROW1]+a*n[lt.COLUMN1ROW2])+Math.abs(i*n[lt.COLUMN2ROW0]+o*n[lt.COLUMN2ROW1]+a*n[lt.COLUMN2ROW2]),h=r.dot(s)+t.distance;return h<=-c?U.OUTSIDE:h>=c?U.INSIDE:U.INTERSECTING}distanceTo(t){return Math.sqrt(this.distanceSquaredTo(t))}distanceSquaredTo(t){let s=Ic.from(t).subtract(this.center),r=this.halfAxes,n=r.getColumn(0,Pe),i=r.getColumn(1,Ne),o=r.getColumn(2,qe),a=n.magnitude(),c=i.magnitude(),h=o.magnitude();n.normalize(),i.normalize(),o.normalize();let l=0,u;return u=Math.abs(s.dot(n))-a,u>0&&(l+=u*u),u=Math.abs(s.dot(i))-c,u>0&&(l+=u*u),u=Math.abs(s.dot(o))-h,u>0&&(l+=u*u),l}computePlaneDistances(t,s,r=[-0,-0]){let n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=this.center,a=this.halfAxes,c=a.getColumn(0,Pe),h=a.getColumn(1,Ne),l=a.getColumn(2,qe),u=Lc.copy(c).add(h).add(l).add(o),d=Pc.copy(u).subtract(t),f=s.dot(d);return n=Math.min(f,n),i=Math.max(f,i),u.copy(o).add(c).add(h).subtract(l),d.copy(u).subtract(t),f=s.dot(d),n=Math.min(f,n),i=Math.max(f,i),u.copy(o).add(c).subtract(h).add(l),d.copy(u).subtract(t),f=s.dot(d),n=Math.min(f,n),i=Math.max(f,i),u.copy(o).add(c).subtract(h).subtract(l),d.copy(u).subtract(t),f=s.dot(d),n=Math.min(f,n),i=Math.max(f,i),o.copy(u).subtract(c).add(h).add(l),d.copy(u).subtract(t),f=s.dot(d),n=Math.min(f,n),i=Math.max(f,i),o.copy(u).subtract(c).add(h).subtract(l),d.copy(u).subtract(t),f=s.dot(d),n=Math.min(f,n),i=Math.max(f,i),o.copy(u).subtract(c).subtract(h).add(l),d.copy(u).subtract(t),f=s.dot(d),n=Math.min(f,n),i=Math.max(f,i),o.copy(u).subtract(c).subtract(h).subtract(l),d.copy(u).subtract(t),f=s.dot(d),n=Math.min(f,n),i=Math.max(f,i),r[0]=n,r[1]=i,r}transform(t){this.center.transformAsPoint(t);let s=this.halfAxes.getColumn(0,Pe);s.transformAsPoint(t);let r=this.halfAxes.getColumn(1,Ne);r.transformAsPoint(t);let n=this.halfAxes.getColumn(2,qe);return n.transformAsPoint(t),this.halfAxes=new V([...s,...r,...n]),this}getTransform(){throw new Error("not implemented")}};var Pn=new m,Nn=new m,W=class e{constructor(t=[0,0,1],s=0){this.normal=new m,this.distance=-0,this.fromNormalDistance(t,s)}fromNormalDistance(t,s){return F(Number.isFinite(s)),this.normal.from(t).normalize(),this.distance=s,this}fromPointNormal(t,s){t=Pn.from(t),this.normal.from(s).normalize();let r=-this.normal.dot(t);return this.distance=r,this}fromCoefficients(t,s,r,n){return this.normal.set(t,s,r),F(K(this.normal.len(),1)),this.distance=n,this}clone(){return new e(this.normal,this.distance)}equals(t){return K(this.distance,t.distance)&&K(this.normal,t.normal)}getPointDistance(t){return this.normal.dot(t)+this.distance}transform(t){let s=Nn.copy(this.normal).transformAsVector(t).normalize(),r=this.normal.scale(-this.distance).transform(t);return this.fromPointNormal(r,s)}projectPointOntoPlane(t,s=[0,0,0]){let r=Pn.from(t),n=this.getPointDistance(r),i=Nn.copy(this.normal).scale(n);return r.subtract(i).to(s)}};var qn=[new m([1,0,0]),new m([0,1,0]),new m([0,0,1])],zn=new m,Nc=new m,k=class e{constructor(t=[]){this.planes=t}fromBoundingSphere(t){this.planes.length=2*qn.length;let s=t.center,r=t.radius,n=0;for(let i of qn){let o=this.planes[n],a=this.planes[n+1];o||(o=this.planes[n]=new W),a||(a=this.planes[n+1]=new W);let c=zn.copy(i).scale(-r).add(s);o.fromPointNormal(c,i);let h=zn.copy(i).scale(r).add(s),l=Nc.copy(i).negate();a.fromPointNormal(h,l),n+=2}return this}computeVisibility(t){let s=U.INSIDE;for(let r of this.planes)switch(t.intersectPlane(r)){case U.OUTSIDE:return U.OUTSIDE;case U.INTERSECTING:s=U.INTERSECTING;break;default:}return s}computeVisibilityWithPlaneMask(t,s){if(F(Number.isFinite(s),"parentPlaneMask is required."),s===e.MASK_OUTSIDE||s===e.MASK_INSIDE)return s;let r=e.MASK_INSIDE,n=this.planes;for(let i=0;i<this.planes.length;++i){let o=i<31?1<<i:0;if(i<31&&(s&o)===0)continue;let a=n[i],c=t.intersectPlane(a);if(c===U.OUTSIDE)return e.MASK_OUTSIDE;c===U.INTERSECTING&&(r|=o)}return r}};k.MASK_OUTSIDE=4294967295;k.MASK_INSIDE=0;k.MASK_INDETERMINATE=2147483647;var wd=new m,Cd=new m,Od=new m,Ad=new m,vd=new m;var zd=new m,Dd=new m,Bd=new m,Vd=new m,Fd=new m,Ud=new m,kd=new m,Wd=new m,Yd=new m,Gd=new m,$d=new m,Hd=new m;var Xd=new V,Qd=new V,Kd=new V,Jd=new V,tf=new V;var af=new m,cf=new m,hf=new m,lf=new m,uf=new m,df=new V,ff={diagonal:new V,unitary:new V};var Dn=new m,Ws=new m,Bc=1e-5,Vc=1e-7,Ys=new k([new W,new W,new W,new W,new W,new W]);function ze(e,t,s={}){let{cameraUp:r,height:n}=e,i=e.cameraDirection,{metersPerUnit:o}=e.distanceScales,a=Xt(e,e.center),c=w.WGS84.eastNorthUpToFixedFrame(a),h=e.unprojectPosition(e.cameraPosition),l=w.WGS84.cartographicToCartesian(h,new m),u;if(i)u=new m(c.transformAsVector(new m(i).scale(o))).normalize();else{let T=e.getFrustumPlanes().near,S=Gs(T,e.cameraPosition),M=Xt(e,S);u=new m(M).subtract(l).normalize()}let d=new m(c.transformAsVector(new m(r).scale(o))).normalize();Fc(e);let f=e.constructor,{longitude:g,latitude:x,width:p,bearing:y,zoom:E}=e,_=new f({longitude:g,latitude:x,height:n,width:p,bearing:y,zoom:E,pitch:0});return{camera:{position:l,direction:u,up:d,cartographicPosition:h,verticalFieldOfView:Number.isFinite(e.fovy)&&Number(e.fovy)>0?Number(e.fovy)*Math.PI/180:Math.PI/3,timeSinceMovement:s.timeSinceCameraMovement??Number.POSITIVE_INFINITY},viewport:e,topDownViewport:_,height:n,cullingVolume:Ys,frameNumber:t,sseDenominator:1.15,dynamicScreenSpaceErrorDensity:0}}function Bn(e,t,s,r){let n=Array.from(t),i=Array.from(s),o=e?n.length!==e.position.length||n.some((h,l)=>Math.abs(h-e.position[l])>Bc):!1,a=e?i.length!==e.direction.length||i.some((h,l)=>Math.abs(h-e.direction[l])>Vc):!1,c=o||a?r:e?.lastMovementTime??Number.NEGATIVE_INFINITY;return{state:{position:n,direction:i,lastMovementTime:c},timeSinceMovement:Math.max((r-c)/1e3,0)}}function Vn(e,t,s){if(s===0||e.length<=s)return[e,[]];let r=[],{longitude:n,latitude:i}=t.viewport;for(let[h,l]of e.entries()){let[u,d]=l.header.mbs,f=Math.abs(n-u),g=Math.abs(i-d),x=Math.sqrt(g*g+f*f);r.push([h,x])}let o=r.sort((h,l)=>h[1]-l[1]),a=[];for(let h=0;h<s;h++)a.push(e[o[h][0]]);let c=[];for(let h=s;h<o.length;h++)c.push(e[o[h][0]]);return[a,c]}function Fc(e){let t=e.getFrustumPlanes(),s=Gs(t.near,e.cameraPosition),r=Xt(e,s),n=Xt(e,e.cameraPosition,Ws),i=0;Ys.planes[i++].fromPointNormal(r,Dn.copy(r).subtract(n));for(let o in t){if(o==="near")continue;let a=t[o],c=Gs(a,s,Ws),h=Xt(e,c,Ws);Ys.planes[i++].fromPointNormal(h,Dn.copy(r).subtract(h))}}function Gs(e,t,s=new m){let r=e.normal.dot(t);return s.copy(e.normal).scale(e.distance-r).add(t),s}function Xt(e,t,s=new m){let r=e.unprojectPosition(t);return w.WGS84.cartographicToCartesian(r,s)}var Yn=new m,Uc=new m,Mt=new m,Fn=new m,Qt=new m,Un=new m,kn=new m,Wn=new m,De=new it,kc=new m(0,0,1);function Gn(e,t){e._updateTransform(t)}function $n(e,t,s){if(!Number.isFinite(s.dynamicScreenSpaceErrorDensity)||s.dynamicScreenSpaceErrorDensity<=0)return 0;let r=$c(e),n=r.region?Hc(r.region,t):Zc(e,r,t);if(!n)return 0;let i=Dt(s.dynamicScreenSpaceErrorHeightFalloff,0,1),o=n.minimumHeight+(n.maximumHeight-n.minimumHeight)*i,a=n.maximumHeight-o,c=a>0?Dt((n.cameraHeight-o)/a,0,1):n.cameraHeight>=n.maximumHeight?1:0,l=(1-Dt(Math.abs(n.cameraDirection.dot(n.upDirection)),0,1))*(1-c);return s.dynamicScreenSpaceErrorDensity*l}function Wc(e,t){let s=e*t;return 1-Math.exp(-(s*s))}function Yc(e,t,s){return t<=0||s<=0||!Number.isFinite(t)||!Number.isFinite(s)?0:Wc(e,t)*s}function Hn(e,t,s,r=1){let n=e.tileset,i=e.parent&&e.parent.lodMetricValue||e.lodMetricValue,o=s?i:e.lodMetricValue;if(o===0)return 0;let{viewDistanceScale:a}=n.options,c=a||1,h=Number.isFinite(r)?Math.max(r,0):1,l=Gc(o,t,c,h);if(l!==null)return l;let u=Math.max(e._distanceToCamera,1e-7),{height:d,sseDenominator:f}=t,g=o*d*h*c/(u*f);return n.options.dynamicScreenSpaceError&&!t.viewport.orthographic&&(g-=Yc(u,t.dynamicScreenSpaceErrorDensity,n.options.dynamicScreenSpaceErrorFactor)),g}function Gc(e,t,s,r){let n=t.viewport;if(!n?.orthographic)return null;let i=n.metersPerPixel;return!Number.isFinite(i)||!i||i<=0?null:e*s*r/i}function $c(e){return e.header.content?.boundingVolume||e.header.boundingVolume}function Hc(e,t){let s=Yn.copy(t.camera.position).normalize(),r=Qt.copy(t.camera.direction).normalize();return{cameraHeight:t.camera.cartographicPosition[2],minimumHeight:e[4],maximumHeight:e[5],cameraDirection:r,upDirection:s}}function Zc(e,t,s){let r=jc(t,Mt);if(r===null)return null;let n=new v(e.computedTransform).invert(),i=e.tileset.ellipsoid;if(Math.hypot(Mt[0],Mt[1],Mt[2])>i.minimumRadius){let a=i.cartesianToCartographic(Mt,Uc),c=Yn.copy(s.camera.position).normalize(),h=Qt.copy(s.camera.direction).normalize();return{cameraHeight:s.camera.cartographicPosition[2],minimumHeight:0,maximumHeight:a[2]*2,cameraDirection:h,upDirection:c}}return n.transformAsPoint(s.camera.position,Fn),n.transformAsVector(s.camera.direction,Qt),Qt.normalize(),{cameraHeight:Fn[2],minimumHeight:Mt[2]-r,maximumHeight:Mt[2]+r,cameraDirection:Qt,upDirection:kc}}function jc(e,t){if(e.box){let s=e.box;return t.set(s[0],s[1],s[2]),Xc(s)}if(e.sphere){let s=e.sphere;return t.set(s[0],s[1],s[2]),s[3]}return null}function Xc(e){return e.length===10?(De.fromArray(e,6),Un.set(e[3],0,0).transformByQuaternion(De),kn.set(0,e[4],0).transformByQuaternion(De),Wn.set(0,0,e[5]).transformByQuaternion(De),Math.abs(Un[2])+Math.abs(kn[2])+Math.abs(Wn[2])):Math.abs(e[5])+Math.abs(e[8])+Math.abs(e[11])}var G={UNLOADED:0,LOADING:1,PROCESSING:2,READY:3,EXPIRED:4,FAILED:5},Y;(function(e){e[e.ADD=1]="ADD",e[e.REPLACE=2]="REPLACE"})(Y||(Y={}));var ot;(function(e){e.EMPTY="empty",e.SCENEGRAPH="scenegraph",e.POINTCLOUD="pointcloud",e.MESH="mesh"})(ot||(ot={}));var j;(function(e){e.I3S="I3S",e.TILES3D="TILES3D"})(j||(j={}));var Lt;(function(e){e.GEOMETRIC_ERROR="geometricError",e.MAX_SCREEN_THRESHOLD="maxScreenThreshold"})(Lt||(Lt={}));var Zn={NOT_COMPUTED:-1,USE_OPTIMIZATION:1,SKIP_OPTIMIZATION:0};var jn=1e4,Qc=1e4,Kc=1e8,Jc=new Z,Xn=new m,Qn=new m,$s=new m,Be=new m;function Hs(e,t,s){return e+(t-e)*s}function Kn(e,t){let s=e instanceof Z?e:e.getBoundingSphere(Jc),{center:r,radius:n}=s;Xn.copy(r).subtract(t.position);let i=Math.max(Xn.dot(t.direction),0);return Qn.copy(t.direction).scale(i).add(t.position),$s.copy(Qn).subtract(r),$s.magnitude()<=n||(Be.copy($s).normalize().scale(n).add(r).subtract(t.position),Be.magnitude()===0)?0:(Be.normalize(),Math.min(Math.max(1-Be.dot(t.direction),0),1))}function Jn(e,t,s,r){return!Number.isFinite(r)||r<=0||r>.5?!1:e>s?!0:t!==void 0&&t>s}function ti(e){let t=Number.isFinite(e.foveatedConeSize)?Math.min(Math.max(e.foveatedConeSize,0),1):1,s=e.refinement===Y.REPLACE;if(s&&!e.skipLevelOfDetail||!e.foveatedScreenSpaceError||t>=1||s&&e.skipLevelOfDetail&&e.priorityProgressiveResolution)return!1;let r=Number.isFinite(e.verticalFieldOfView)&&e.verticalFieldOfView>0?e.verticalFieldOfView:Math.PI/3,n=1-Math.cos(r*.5),i=t*n;if(e.foveatedFactor<=i||n<=i)return!1;let o=Math.min(Math.max((e.foveatedFactor-i)/(n-i),0),1),c=(typeof e.interpolationCallback=="function"?e.interpolationCallback:Hs)(e.minimumScreenSpaceErrorRelaxation,e.maximumScreenSpaceError,o),h=Number.isFinite(c)?Math.min(Math.max(c,0),e.maximumScreenSpaceError):0,l=e.screenSpaceError===0&&e.parentScreenSpaceError!==void 0?e.parentScreenSpaceError*.5:e.screenSpaceError;return e.maximumScreenSpaceError-h<=l}function ei(e,t,s){return e&&Number.isFinite(t)&&Number.isFinite(s)&&s>0&&t<s}function si(e){let t=e.rootScreenSpaceError>0?Math.min(Math.max(e.reverseScreenSpaceError/e.rootScreenSpaceError,0),1):0,s=Math.floor(t*(jn-1)),r=Number.isFinite(e.foveatedFactor)?Math.min(Math.max(e.foveatedFactor,0),1):0,n=Math.floor(r*(jn-1))*Qc;return(e.priorityProgressiveResolution?0:Kc)+n+s}function Ve(e){return!!(e&&typeof e=="object"&&"initialize"in e&&"getRootTileset"in e&&"initializeTileHeaders"in e&&"loadTileContent"in e)}var $=1024*1024,Js=512*$,tr=512*$,th=32*$,eh=$;function Kt(e,t){if(!Number.isFinite(e)||e<0)throw new Error(`${t} must be a finite number greater than or equal to 0`);return e}function ri(e,t){let s=e.cacheBytes??(e.maximumMemoryUsage!==void 0?e.maximumMemoryUsage*$:t);return Kt(s,"cacheBytes")}function ni(e,t){let s=e.maximumCacheOverflowBytes??(e.memoryCacheOverflow!==void 0?e.memoryCacheOverflow*$:t);return Kt(s,"maximumCacheOverflowBytes")}var Zs={description:"",ellipsoid:w.WGS84,modelMatrix:new v,throttleRequests:!0,maxRequests:64,cacheBytes:Js,maximumCacheOverflowBytes:tr,maximumMemoryUsage:Js/$,memoryCacheOverflow:tr/$,maximumTilesSelected:0,debounceTime:0,onTileLoad:()=>{},onTileUnload:()=>{},onTileError:()=>{},onSourceError:()=>{},onTilesetError:()=>{},onTraversalComplete:e=>e,onUpdate:()=>{},contentLoader:void 0,viewDistanceScale:1,progressiveResolutionHeightFraction:.3,foveatedScreenSpaceError:!0,foveatedConeSize:.1,foveatedMinimumScreenSpaceErrorRelaxation:0,foveatedInterpolationCallback:Hs,foveatedTimeDelay:.2,maximumScreenSpaceError:8,dynamicScreenSpaceError:!0,dynamicScreenSpaceErrorDensity:2e-4,dynamicScreenSpaceErrorFactor:24,dynamicScreenSpaceErrorHeightFalloff:.25,memoryAdjustedScreenSpaceError:!0,loadTiles:!0,updateTransforms:!0,viewportTraversersMap:null,loadOptions:{fetch:{}},attributions:[],basePath:"",i3s:{}},js="Tiles In Tileset(s)",Xs="Tiles In Memory",ii="Tiles In View",oi="Tiles To Render",ai="Tiles Loaded",Qs="Tiles Loading",ci="Tiles Unloaded",hi="Failed Tile Loads",li="Points/Vertices",Ks="Tile Memory Use",ui="Maximum Screen Space Error",Fe=class{options;loadOptions;source;type;tileset;loader;url;basePath;modelMatrix;ellipsoid;lodMetricType;lodMetricValue;refine;root=null;roots={};asset={};description="";properties;extras=null;attributions={};credits={};stats;contentFormats;cartographicCenter=null;cartesianCenter=null;zoom=1;boundingVolume=null;dynamicScreenSpaceErrorComputedDensity=0;gpuMemoryUsageInBytes=0;memoryAdjustedScreenSpaceError=0;_cacheBytes=Js;_maximumCacheOverflowBytes=tr;_frameNumber=0;_tiles={};_pendingCount=0;selectedTiles=[];traverseCounter=0;geometricError=0;lastUpdatedVieports=null;_requestedTiles=[];_emptyTiles=[];frameStateData={};_cameraMotionStates={};_deferredTraversalTimeout=null;_traverser;_cache=new It;_requestScheduler;_heldTiles=new Set;updatePromise=null;tilesetInitializationPromise;constructor(t,s){if(!Ve(t))throw new Error("Tileset3D requires a Tileset3DSource instance");let r=s||{},n=t.type===j.TILES3D,i=n?Zs.cacheBytes:th,o=n?Zs.maximumCacheOverflowBytes:eh,a=ri(r,i),c=ni(r,o);this.options={...Zs,...r,cacheBytes:a,maximumCacheOverflowBytes:c,maximumMemoryUsage:a/$,memoryCacheOverflow:c/$,memoryAdjustedScreenSpaceError:r.memoryAdjustedScreenSpaceError??n},this.loadOptions=this.options.loadOptions||{},this.source=t,this.tileset=null,this.loader=this.source.loader,this.type=this.source.type,this.url=this.source.url,this.basePath=this.source.basePath,this.modelMatrix=this.options.modelMatrix,this.ellipsoid=this.options.ellipsoid,this.lodMetricType="",this.lodMetricValue=0,this.refine="",this.contentFormats=this.source.contentFormats,this._traverser=this._initializeTraverser(),this._requestScheduler=new ht({throttleRequests:this.options.throttleRequests,maxRequests:this.options.maxRequests}),this.memoryAdjustedScreenSpaceError=this.options.maximumScreenSpaceError,this._cacheBytes=a,this._maximumCacheOverflowBytes=c,this.stats=new tt({id:this.url}),this._initializeStats(),this.tilesetInitializationPromise=this._initializeTileSet()}destroy(){this._clearDeferredTraversal(),this.source.destroy?.(),this._destroy()}isLoaded(){return this._pendingCount===0&&this._frameNumber!==0&&this._requestedTiles.length===0}get tiles(){return Object.values(this._tiles)}get frameNumber(){return this._frameNumber}get cacheBytes(){return this._cacheBytes}set cacheBytes(t){this._cacheBytes=Kt(t,"cacheBytes"),this.options.cacheBytes=this._cacheBytes,this.options.maximumMemoryUsage=this._cacheBytes/$}get maximumCacheOverflowBytes(){return this._maximumCacheOverflowBytes}set maximumCacheOverflowBytes(t){this._maximumCacheOverflowBytes=Kt(t,"maximumCacheOverflowBytes"),this.options.maximumCacheOverflowBytes=this._maximumCacheOverflowBytes,this.options.memoryCacheOverflow=this._maximumCacheOverflowBytes/$}get maximumMemoryUsage(){return this.cacheBytes/$}set maximumMemoryUsage(t){this.cacheBytes=Kt(t*$,"maximumMemoryUsage")}get queryParams(){let t=this.source.getTileUrl(this.url),s=t.indexOf("?");return s>=0?t.slice(s+1):""}setProps(t){let s=ri(t,this.cacheBytes),r=ni(t,this.maximumCacheOverflowBytes);this.options={...this.options,...t,cacheBytes:s,maximumCacheOverflowBytes:r,maximumMemoryUsage:s/$,memoryCacheOverflow:r/$},this._cacheBytes=s,this._maximumCacheOverflowBytes=r}getTileUrl(t){return this.source.getTileUrl(t)}hasExtension(t){return!!this.source.hasExtension?.(t)}update(t=null){this.tilesetInitializationPromise.then(()=>{!t&&this.lastUpdatedVieports?t=this.lastUpdatedVieports:this.lastUpdatedVieports=t,t&&this.doUpdate(t)})}async selectTiles(t=null){return await this.tilesetInitializationPromise,t&&(this.lastUpdatedVieports=t),this.updatePromise||(this.updatePromise=new Promise(s=>{setTimeout(()=>{this.lastUpdatedVieports&&this.doUpdate(this.lastUpdatedVieports),s(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.maximumCacheOverflowBytes&&(this.memoryAdjustedScreenSpaceError*=1.02)}doUpdate(t){if("loadTiles"in this.options&&!this.options.loadTiles||this.traverseCounter>0)return;let s=t instanceof Array?t:[t];this._cache.reset(),this._frameNumber++,this.traverseCounter=s.length;let r=Date.now(),n=Number.POSITIVE_INFINITY,i=[];for(let o of s){let a=o.id;this._needTraverse(a)?i.push(a):this.traverseCounter--}for(let o of s){let a=o.id;if(this.roots[a]||(this.roots[a]=this._initializeTileHeaders(this.tileset,null)),!i.includes(a))continue;let c=ze(o,this._frameNumber),h=this.roots[a],l=Bn(this._cameraMotionStates[a],c.camera.position,c.camera.direction,r);this._cameraMotionStates[a]=l.state,c.camera.timeSinceMovement=l.timeSinceMovement,Gn(h,this.modelMatrix),c.dynamicScreenSpaceErrorDensity=this.type===j.TILES3D&&this.options.dynamicScreenSpaceError&&!c.viewport.orthographic?$n(h,c,this.options):0,this.dynamicScreenSpaceErrorComputedDensity=c.dynamicScreenSpaceErrorDensity,this._traverser.traverse(h,c,this.options),Object.keys(this._traverser.deferredTiles).length>0&&(n=Math.min(n,Math.max(this.options.foveatedTimeDelay-l.timeSinceMovement,0)))}Number.isFinite(n)?this._scheduleDeferredTraversal(n):this._clearDeferredTraversal()}_scheduleDeferredTraversal(t){this._clearDeferredTraversal(),this._deferredTraversalTimeout=setTimeout(()=>{this._deferredTraversalTimeout=null,this.selectTiles().catch(s=>{let r=s instanceof Error?s:new Error(String(s));this._onTilesetError(r)})},Math.max(t*1e3,0))}_clearDeferredTraversal(){this._deferredTraversalTimeout!==null&&(clearTimeout(this._deferredTraversalTimeout),this._deferredTraversalTimeout=null)}_needTraverse(t){let s=t;return this.options.viewportTraversersMap&&(s=this.options.viewportTraversersMap[t]),s===t}_onTraversalEnd(t){let s=t.viewport.id;this.frameStateData[s]||(this.frameStateData[s]={selectedTiles:[],_requestedTiles:[],_emptyTiles:[]});let r=this.frameStateData[s],n=Object.values(this._traverser.selectedTiles),[i,o]=Vn(n,t,this.options.maximumTilesSelected);r.selectedTiles=i;for(let a of o)a.unselect();r._requestedTiles=Object.values(this._traverser.requestedTiles),r._emptyTiles=Object.values(this._traverser.emptyTiles),this.traverseCounter--,!(this.traverseCounter>0)&&this._updateTiles()}_updateTiles(){let t=this.selectedTiles;this.selectedTiles=[],this._requestedTiles=[],this._emptyTiles=[];for(let i in this.frameStateData){let o=this.frameStateData[i];this.selectedTiles=this.selectedTiles.concat(o.selectedTiles),this._requestedTiles=this._requestedTiles.concat(o._requestedTiles),this._emptyTiles=this._emptyTiles.concat(o._emptyTiles)}this.selectedTiles=this.options.onTraversalComplete(this.selectedTiles);let s=new Set(this.selectedTiles.map(i=>i.id)),r=this.selectedTiles.some(i=>!i.tileDrawn),n=0;if(r){for(let i of s)this._heldTiles.add(i);for(let i of this._heldTiles){if(s.has(i))continue;let o=this._tiles[i];o&&o.contentAvailable?(o._selectedFrame=this._frameNumber,this.selectedTiles.push(o),n++):this._heldTiles.delete(i)}}else this._heldTiles=s;n>0&&setTimeout(()=>{this.selectTiles()},0);for(let i of this.selectedTiles)this._tiles[i.id]=i;this._loadTiles(),this._unloadTiles(),this._updateStats(),this._tilesChanged(t,this.selectedTiles)&&this.options.onUpdate()}_tilesChanged(t,s){if(t.length!==s.length)return!0;let r=new Set(t.map(o=>o.id)),n=new Set(s.map(o=>o.id)),i=t.some(o=>!n.has(o.id));return i=i||s.some(o=>!r.has(o.id)),i}_loadTiles(){this._requestedTiles.sort((t,s)=>t._priority-s._priority);for(let t of this._requestedTiles)t.contentUnloaded&&this._loadTile(t)}_unloadTiles(){this._cache.unloadTiles(this,(t,s)=>t._unloadTile(s)),this.options.memoryAdjustedScreenSpaceError&&this.adjustScreenSpaceError()}_updateStats(){let t=0,s=0;for(let r of this.selectedTiles)r.contentAvailable&&r.content&&(t++,r.content.pointCount?s+=r.content.pointCount:s+=r.content.vertexCount);this.stats.get(ii).count=this.selectedTiles.length,this.stats.get(oi).count=t,this.stats.get(li).count=s,this.stats.get(ui).count=this.memoryAdjustedScreenSpaceError}async _initializeTileSet(){try{let t=this.source.initialize(),s=this._getSourceMetadata();s&&this._syncSourceState(s),s?.tileset?.root&&typeof s.tileset.root.then!="function"&&(this.root=this._initializeTileHeaders(s.tileset,null),this._applyViewState()),await t;let r=this.source.getMetadata();this._syncSourceState(r),this.root||(this.root=this._initializeTileHeaders(r.tileset,null)),this._applyViewState()}catch(t){let s=t instanceof Error?t:new Error(String(t));throw this._onSourceError(s,this.root),this._onTilesetError(s),s}}_initializeStats(){this.stats.get(js),this.stats.get(Qs),this.stats.get(Xs),this.stats.get(ii),this.stats.get(oi),this.stats.get(ai),this.stats.get(ci),this.stats.get(hi),this.stats.get(li),this.stats.get(Ks,"memory"),this.stats.get(ui)}_initializeTileHeaders(t,s){return this.source.initializeTileHeaders(this,t,s)}_initializeTraverser(){return this.source.createTraverser({basePath:this.basePath,onTraversalEnd:this._onTraversalEnd.bind(this)})}_destroyTileHeaders(t){this._destroySubtree(t)}async _loadTile(t){let s=null;try{this._onStartTileLoading(),s=await t.loadContent()}catch(r){let n=r instanceof Error?r:new Error("load failed");this._onSourceError(n,t),this._onTileLoadError(t,n)}finally{this._onEndTileLoading(),this._onTileLoad(t,s)}}async _loadTileChildren(t,s){try{this._onStartTileLoading(),await t.loadChildren(s)}catch(r){let n=r instanceof Error?r:new Error("subtree load failed");this._onSourceError(n,t),this._onTileLoadError(t,n)}finally{this._onEndTileLoading()}}_onTileLoadError(t,s){this.stats.get(hi).incrementCount();let r=s.message||s.toString(),n=t.url;console.error(`A 3D tile failed to load: ${t.url} ${r}`),this.options.onTileError(t,r,n)}_onSourceError(t,s=null){this.options.onSourceError(t,this.source,s)}_onTilesetError(t){this.options.onTilesetError(t,this)}_onTileLoad(t,s){if(!s?.loaded)return;t.content&&Le(t,t.content),this.source.onTileLoaded?.(this,t,s),this._syncSourceState(this.source.getMetadata());let r=this.source.getTilesTotalCount?.();r&&(this.stats.get(js).reset(),this.stats.get(js).addCount(r)),this._addTileToCache(t),this.options.onTileLoad(t)}_onStartTileLoading(){this._pendingCount++,this.stats.get(Qs).incrementCount()}_onEndTileLoading(){this._pendingCount--,this.stats.get(Qs).decrementCount()}_addTileToCache(t){this._cache.add(this,t,s=>s._updateCacheStats(t))}_updateCacheStats(t){this.stats.get(ai).incrementCount(),this.stats.get(Xs).incrementCount(),this.gpuMemoryUsageInBytes+=t.gpuMemoryUsageInBytes||0,this.stats.get(Ks).count=this.gpuMemoryUsageInBytes,this.options.memoryAdjustedScreenSpaceError&&this.adjustScreenSpaceError()}_unloadTile(t){this.gpuMemoryUsageInBytes-=t.gpuMemoryUsageInBytes||0,this.stats.get(Xs).decrementCount(),this.stats.get(ci).incrementCount(),this.stats.get(Ks).count=this.gpuMemoryUsageInBytes,this.options.onTileUnload(t),t.unloadContent()}_destroy(){let t=[];for(this.root&&t.push(this.root);t.length>0;){let s=t.pop();for(let r of s.children)t.push(r);this._destroyTile(s)}this.root=null}_destroySubtree(t){let s=t,r=[s];for(;r.length>0;){t=r.pop();for(let n of t.children)r.push(n);t!==s&&this._destroyTile(t)}s.children=[]}_destroyTile(t){this._cache.unloadTile(this,t),this._unloadTile(t),t.destroy()}_syncSourceState(t){this.tileset=t.tileset,this.loader=t.loader,this.type=t.type,this.url=t.url,this.basePath=t.basePath,this.lodMetricType=t.lodMetricType,this.lodMetricValue=t.lodMetricValue,this.refine=t.refine,this.contentFormats=this.source.contentFormats,this.asset=this.source.asset||this.asset,this.properties=this.source.properties??this.properties,this.extras=this.source.extras??this.extras,this.options.attributions?.length?this.credits={attributions:this.options.attributions}:this.credits=this.source.credits||this.credits}_applyViewState(){let t=this.source.getViewState(this.root);this.asset=t.asset||this.source.asset||{},this.properties=t.properties??this.source.properties,this.extras=t.extras??this.source.extras??null,this.credits=t.credits||this.source.credits||this.credits||{attributions:this.options.attributions||[]},this.description=t.description||this.options.description||"",this.boundingVolume=t.boundingVolume||this.root?.boundingVolume||null,this.cartographicCenter=t.cartographicCenter||new m,this.cartesianCenter=t.cartesianCenter||null,this.zoom=t.zoom||1,this.geometricError=this.tileset?.geometricError||0}_getSourceMetadata(){try{return this.source.getMetadata()}catch{return null}}};var Ue=class{sourceUrl;options;archivePromise;constructor(t){this.options=t,this.sourceUrl=sh(t.data,t.fallbackFilename)}async loadRoot(t,s,r){return await this.parseArchiveResource(t,this.options.rootPath,s,r,this.options.rootMode)}async loadResource(t,s,r){let n=this.resolveArchivePath(t,t);return await this.parseArchiveResource(t,n,s,r)}async parseArchiveResource(t,s,r,n,i){let o=this.options.getCoreApi();if(!o)throw new Error(this.options.missingCoreApiMessage);let a=await this.loadFile(s,i),c=this.createArchiveFetch(t);return await o.parse(a,r,{...n,fetch:c},{url:t,fetch:c,_parse:o.parse,loaders:[r],coreApi:o})}createArchiveFetch(t){return async s=>{let r=typeof s=="string"?s:s instanceof URL?s.toString():s.url,n=this.resolveArchivePath(r,t),i=await this.loadFile(n);return new Response(i,{status:200})}}async loadFile(t,s){this.archivePromise||=this.openArchiveReadableFile().then(n=>this.options.parseArchive(n));let r=await this.archivePromise;return await this.options.getFile(r,t,s)}async openArchiveReadableFile(){let{data:t}=this.options;if(typeof t!="string")return new vt(t);if(/^https?:\/\//i.test(t))return new Zt(t);let s=this.options.getCoreApi();if(!s)throw new Error(this.options.missingCoreApiMessage);let r=await s.fetchFile(t);return new vt(await r.arrayBuffer())}resolveArchivePath(t,s){let r=er(t),n=er(this.sourceUrl),i=er(s),o=i===n?n:J.dirname(i),a=new RegExp(`\\.${this.options.archiveExtension}/(.*)$`,"i"),c=r.match(a);if(c?.[1])return c[1];let h=/^[a-z][a-z0-9+.-]*:/i.test(r)||r.startsWith("/"),l=r.startsWith(n)?r:i===n&&!h?`${n}/${r}`:J.resolve(o,r);return l===n?"":l.startsWith(`${n}/`)?l.slice(n.length+1):l.replace(/^\/+/,"")}};function sh(e,t){return typeof e=="string"?e:`memory://${"name"in e&&typeof e.name=="string"&&e.name?e.name:t}`}function er(e){let t=e.indexOf("?");return t>=0?e.slice(0,t):e}function pi(e){return e!=null}var H=new m,ke=new m,rh=new m,nh=new m,St=new m,di=new m,fi=new m,mi=new m;function Pt(e,t,s){if(rt(e,"3D Tile: boundingVolume must be defined"),e.box)return xi(e.box,t,s);if(e.region)return oh(e.region);if(e.sphere)return ih(e.sphere,t,s);throw new Error("3D Tile: boundingVolume must contain a sphere, region, or box")}function gi(e,t){if(e.box)return ah(t);if(e.region){let[s,r,n,i,o,a]=e.region;return[[Q(s),Q(r),o],[Q(n),Q(i),a]]}if(e.sphere)return ch(t);throw new Error("Unkown boundingVolume type")}function xi(e,t,s){let r=new m(e[0],e[1],e[2]);t.transform(r,r);let n=[];if(e.length===10){let h=e.slice(3,6),l=new it;l.fromArray(e,6);let u=new m([1,0,0]),d=new m([0,1,0]),f=new m([0,0,1]);u.transformByQuaternion(l),u.scale(h[0]),d.transformByQuaternion(l),d.scale(h[1]),f.transformByQuaternion(l),f.scale(h[2]),n=[...u.toArray(),...d.toArray(),...f.toArray()]}else n=[...e.slice(3,6),...e.slice(6,9),...e.slice(9,12)];let i=t.transformAsVector(n.slice(0,3)),o=t.transformAsVector(n.slice(3,6)),a=t.transformAsVector(n.slice(6,9)),c=new V([i[0],i[1],i[2],o[0],o[1],o[2],a[0],a[1],a[2]]);return pi(s)?(s.center=r,s.halfAxes=c,s):new mt(r,c)}function ih(e,t,s){let r=new m(e[0],e[1],e[2]);t.transform(r,r);let n=t.getScale(ke),i=Math.max(Math.max(n[0],n[1]),n[2]),o=e[3]*i;return pi(s)?(s.center=r,s.radius=o,s):new Z(r,o)}function oh(e){let[t,s,r,n,i,o]=e,a=w.WGS84.cartographicToCartesian([Q(t),Q(n),i],rh),c=w.WGS84.cartographicToCartesian([Q(r),Q(s),o],nh),h=new m().addVectors(a,c).multiplyByScalar(.5);return w.WGS84.cartesianToCartographic(h,St),w.WGS84.cartographicToCartesian([Q(r),St[1],St[2]],di),w.WGS84.cartographicToCartesian([St[0],Q(n),St[2]],fi),w.WGS84.cartographicToCartesian([St[0],St[1],o],mi),xi([...h,...di.subtract(h),...fi.subtract(h),...mi.subtract(h)],new v)}function ah(e){let t=yi(),{halfAxes:s}=e,r=new m(s.getColumn(0)),n=new m(s.getColumn(1)),i=new m(s.getColumn(2));for(let o=0;o<2;o++){for(let a=0;a<2;a++){for(let c=0;c<2;c++)H.copy(e.center),H.add(r),H.add(n),H.add(i),Ti(t,H),i.negate();n.negate()}r.negate()}return t}function ch(e){let t=yi(),{center:s,radius:r}=e,n=w.WGS84.scaleToGeodeticSurface(s,H),i;n?i=w.WGS84.geodeticSurfaceNormal(n):i=new m(0,0,1);let o=new m(i[2],-i[1],0);o.len()>0?o.normalize():o=new m(0,1,0);let a=o.clone().cross(i);for(let c of[o,a,i]){ke.copy(c).scale(r);for(let h=0;h<2;h++)H.copy(s),H.add(ke),Ti(t,H),ke.negate()}return t}function yi(){return[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]]}function Ti(e,t){w.WGS84.cartesianToCartographic(t,H),e[0][0]=Math.min(e[0][0],H[0]),e[0][1]=Math.min(e[0][1],H[1]),e[0][2]=Math.min(e[0][2],H[2]),e[1][0]=Math.max(e[1][0],H[0]),e[1][1]=Math.max(e[1][1],H[1]),e[1][2]=Math.max(e[1][2],H[2])}var sr=new m,_i=new m,pt=new m,Mi=new m,hh=new m,rr=new v,Si=new v;function We(e,t){if(e.lodMetricValue===0||Number.isNaN(e.lodMetricValue))return"DIG";let s=2*nr(e,t);return s<2?"OUT":!e.header.children||s<=e.lodMetricValue?"DRAW":e.header.children?"DIG":"OUT"}function nr(e,t){let{topDownViewport:s}=t,r=e.header.mbs[1],n=e.header.mbs[0],i=e.header.mbs[2],o=e.header.mbs[3],a=[...e.boundingVolume.center],c=s.unprojectPosition(s.cameraPosition);w.WGS84.cartographicToCartesian(c,sr),_i.copy(sr).subtract(a).normalize(),w.WGS84.eastNorthUpToFixedFrame(a,rr),Si.copy(rr).invert(),pt.copy(sr).transform(Si);let h=Math.sqrt(pt[0]*pt[0]+pt[1]*pt[1]),l=h*h/pt[2];Mi.copy([pt[0],pt[1],l]);let d=Mi.transform(rr).subtract(a).normalize(),g=_i.cross(d).normalize().scale(o).add(a),x=w.WGS84.cartesianToCartographic(g),p=s.project([n,r,i]),y=s.project(x);return hh.copy(p).subtract(y).magnitude()}var Jt=class{_map=new Map;_array;_length;constructor(t=0){this._array=new Array(t),this._length=t}get length(){return this._length}set length(t){this._length=t,t>this._array.length&&(this._array.length=t)}get values(){return this._array}get(t){return rt(t<this._array.length),this._array[t]}set(t,s){rt(t>=0),t>=this.length&&(this.length=t+1),this._map.has(this._array[t])&&this._map.delete(this._array[t]),this._array[t]=s,this._map.set(s,t)}delete(t){let s=this._map.get(t);s>=0&&(this._array.splice(s,1),this._map.delete(t),this.length--)}peek(){return this._array[this._length-1]}push(t){if(!this._map.has(t)){let s=this.length++;this._array[s]=t,this._map.set(t,s)}}pop(){let t=this._array[--this.length];return this._map.delete(t),t}reserve(t){rt(t>=0),t>this._array.length&&(this._array.length=t)}resize(t){rt(t>=0),this.length=t}trim(t){t==null&&(t=this.length),this._array.length=t}reset(){this._array=[],this._map=new Map,this._length=0}find(t){return this._map.has(t)}};var lh={loadSiblings:!1,skipLevelOfDetail:!1,updateTransforms:!0,onTraversalEnd:()=>{},viewportTraversersMap:{},basePath:""},at=class{options;root=null;selectedTiles={};requestedTiles={};deferredTiles={};emptyTiles={};lastUpdate=new Date().getTime();updateDebounceTime=1e3;_traversalStack=new Jt;_emptyTraversalStack=new Jt;_frameNumber=null;traversalFinished(t){return!0}constructor(t){this.options={...lh,...t}}traverse(t,s,r){this.root=t,this.options={...this.options,...r},this.reset(),this.updateTile(t,s),this._frameNumber=s.frameNumber,this.executeTraversal(t,s)}reset(){this.requestedTiles={},this.deferredTiles={},this.selectedTiles={},this.emptyTiles={},this._traversalStack.reset(),this._emptyTraversalStack.reset()}executeTraversal(t,s){let r=this._traversalStack;for(t._selectionDepth=1,r.push(t);r.length>0;){let i=r.pop(),o=!1;this.canTraverse(i,s)&&(this.updateChildTiles(i,s),o=this.updateAndPushChildren(i,s,r,i.hasRenderContent?i._selectionDepth+1:i._selectionDepth));let a=i.parent,c=!!(!a||a._shouldRefine),h=!o;i.hasRenderContent?i.refine===Y.ADD?(this.loadTile(i,s),this.selectTile(i,s)):i.refine===Y.REPLACE&&(this.loadTile(i,s),h&&this.selectTile(i,s)):(this.emptyTiles[i.id]=i,this.loadTile(i,s),h&&this.selectTile(i,s)),this.touchTile(i,s),i._shouldRefine=o&&c}let n=new Date().getTime();(this.traversalFinished(s)||n-this.lastUpdate>this.updateDebounceTime)&&(this.lastUpdate=n,this.options.onTraversalEnd(s))}updateChildTiles(t,s){let r=t.children;for(let n of r)this.updateTile(n,s)}updateAndPushChildren(t,s,r,n){let{loadSiblings:i,skipLevelOfDetail:o}=this.options,a=t.children;a.sort(this.compareDistanceToCamera.bind(this));let c=t.refine===Y.REPLACE&&t.hasRenderContent&&!o,h=!1,l=!0;for(let u of a)if(u._selectionDepth=n,u.isVisibleAndInRequestVolume?(r.find(u)&&r.delete(u),r.push(u),h=!0):(c||i)&&(this.loadTile(u,s),this.touchTile(u,s)),c){let d;if(u._inRequestVolume?u.hasRenderContent?d=u.contentAvailable:d=this.executeEmptyTraversal(u,s):d=!1,l=l&&d,!l)return!1}return h||(l=!1),l}updateTile(t,s){this.updateTileVisibility(t,s)}selectTile(t,s){this.shouldSelectTile(t)&&(t._selectedFrame=s.frameNumber,this.selectedTiles[t.id]=t)}loadTile(t,s){if(this.shouldLoadTile(t)){if(this.shouldDeferTileRequest(t)){this.deferredTiles[t.id]=t;return}t._requestedFrame=s.frameNumber,t._priority=t._getPriority(),this.requestedTiles[t.id]=t}}shouldDeferTileRequest(t){return t.priorityDeferred}touchTile(t,s){t.tileset._cache.touch(t),t._touchedFrame=s.frameNumber}canTraverse(t,s){return t.hasChildren?t.hasTilesetContent?!t.contentExpired:this.shouldRefine(t,s):!1}shouldLoadTile(t){return t.hasUnloadedContent||t.contentExpired}shouldSelectTile(t){return t.contentAvailable&&!this.options.skipLevelOfDetail}shouldRefine(t,s,r=!1){let n=t._screenSpaceError;return r&&(n=t.getScreenSpaceError(s,!0)),n>t.tileset.memoryAdjustedScreenSpaceError}updateTileVisibility(t,s){let r=[];if(this.options.viewportTraversersMap)for(let n in this.options.viewportTraversersMap)this.options.viewportTraversersMap[n]===s.viewport.id&&r.push(n);else r.push(s.viewport.id);t.updateVisibility(s,r)}compareDistanceToCamera(t,s){return t._distanceToCamera-s._distanceToCamera}anyChildrenVisible(t,s){let r=!1;for(let n of t.children)n.updateVisibility(s),r=r||n.isVisibleAndInRequestVolume;return r}executeEmptyTraversal(t,s){let r=!0,n=!1,i=this._emptyTraversalStack;for(i.push(t);i.length>0;){let o=i.pop(),a=!o.hasRenderContent&&this.canTraverse(o,s),c=!o.hasRenderContent&&o.children.length===0;if(o.header.implicitSubtree&&(n=!0,r=!1),!a&&!o.contentAvailable&&!c&&(r=!1),this.updateTile(o,s),o.isVisibleAndInRequestVolume||(this.loadTile(o,s),this.touchTile(o,s)),a){let h=o.children;for(let l of h)i.push(l)}}return t.hasEmptyContent&&!n||r}};var ir=new m;function uh(e){return e!=null}var et=class{tileset;header;id;url;parent;refine;type;contentUrl;lodMetricType="geometricError";lodMetricValue=0;_unscaledLodMetricValue=0;boundingVolume=null;content=null;contentState=G.UNLOADED;gpuMemoryUsageInBytes=0;children=[];childrenState="ready";depth=0;viewportIds=[];transform=new v;extensions=null;implicitTiling=null;userData={};computedTransform;hasEmptyContent=!1;hasTilesetContent=!1;traverser=new at({});_cacheNode=null;_frameNumber=null;_expireDate=null;_expiredContent=null;_childrenPromise=null;_boundingBox=void 0;_distanceToCamera=0;_screenSpaceError=0;_screenSpaceErrorProgressiveResolution=0;_priorityProgressiveResolution=!1;_foveatedFactor=0;priorityDeferred=!1;_visibilityPlaneMask;_visible=void 0;_contentBoundingVolume;_viewerRequestVolume;_initialTransform=new v;_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(t,s,r,n=""){this.header=s,this.tileset=t,this.id=n||s.id,this.url=s.url,this.parent=r,this.refine=this._getRefine(s.refine),this.type=s.type,this.contentUrl=s.contentUrl,this.childrenState=s.implicitSubtree?"unloaded":"ready",this._initializeLodMetric(s),this._initializeTransforms(s),this._updateLodMetricScale(),this._initializeBoundingVolumes(s),this._initializeContent(s),this._initializeRenderingState(s),Object.seal(this)}destroy(){this.header=null}isDestroyed(){return this.header===null}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||!!(this.header.implicitSubtree&&this.childrenState!=="ready")}get hasUnloadedChildren(){return!!(this.header.implicitSubtree&&(this.childrenState==="unloaded"||this.childrenState==="failed"))}get childrenLoading(){return this.childrenState==="loading"}get contentReady(){return this.contentState===G.READY||this.hasEmptyContent}get contentAvailable(){return!!(this.contentReady&&this.hasRenderContent||this._expiredContent&&!this.contentFailed)}get hasUnloadedContent(){return this.hasRenderContent&&this.contentUnloaded}get contentUnloaded(){return this.contentState===G.UNLOADED}get contentExpired(){return this.contentState===G.EXPIRED}get contentFailed(){return this.contentState===G.FAILED}get distanceToCamera(){return this._distanceToCamera}get screenSpaceError(){return this._screenSpaceError}get boundingBox(){return this._boundingBox||(this._boundingBox=gi(this.header.boundingVolume,this.boundingVolume)),this._boundingBox}getScreenSpaceError(t,s,r=1){switch(this.tileset.type){case j.I3S:return nr(this,t);case j.TILES3D:return Hn(this,t,s,r);default:throw new Error("Unsupported tileset type")}}unselect(){this._selectedFrame=0}_getGpuMemoryUsageInBytes(){return this.content.gpuMemoryUsageInBytes||this.content.byteLength||0}_getPriority(){return this._calculateRequestPriority(!1)}_getChildrenPriority(){return this._calculateRequestPriority(!0)}_calculateRequestPriority(t){let s=this.tileset._traverser,{skipLevelOfDetail:r}=s.options,n=this.refine===Y.ADD||r;if(n&&!this.isVisible&&this._visible!==void 0||this.tileset._frameNumber-this._touchedFrame>=1||this.priorityDeferred||!t&&this.contentState===G.UNLOADED)return-1;let i=this.parent,a=i&&(!n||this._screenSpaceError===0||i.hasTilesetContent)?i._screenSpaceError:this._screenSpaceError,c=s.root?s.root._screenSpaceError:0,h=Math.max(c-a,0);return si({priorityProgressiveResolution:this._priorityProgressiveResolution,foveatedFactor:this._foveatedFactor,reverseScreenSpaceError:h,rootScreenSpaceError:c})}async loadContent(){if(this.hasEmptyContent)return{loaded:!1};if(this.content)return{loaded:!0};this.contentExpired&&(this._expireDate=null),this.contentState=G.LOADING;let s=await this.tileset._requestScheduler.scheduleRequest(this.id,this._getPriority.bind(this));if(!s)return this.contentState=G.UNLOADED,{loaded:!1};try{let r=await this.tileset.source.loadTileContent(this);return this.tileset.options.contentLoader&&await this.tileset.options.contentLoader(this),this.contentState=G.READY,this._onContentLoaded(),r}catch(r){throw this.contentState=G.FAILED,r}finally{s.done()}}async loadChildren(t){if(!this.header.implicitSubtree||this.childrenState==="ready")return{loaded:!1,tileCount:0,childSubtreeCount:0};if(this._childrenPromise)return await this._childrenPromise;if(!this.tileset.source.loadTileChildren)throw new Error("Tileset source does not support lazy tile children");this.childrenState="loading",this._childrenPromise=this._loadChildrenWithScheduler(t);try{return await this._childrenPromise}finally{this._childrenPromise=null}}async _loadChildrenWithScheduler(t){let s=await this.tileset._requestScheduler.scheduleRequest(`${this.id}:implicit-subtree`,this._getChildrenPriority.bind(this));if(!s)return this.childrenState="unloaded",{loaded:!1,tileCount:0,childSubtreeCount:0};try{let r=await this.tileset.source.loadTileChildren(this,t);return this.childrenState=r.loaded?"ready":"unloaded",r}catch(r){throw this.childrenState="failed",r}finally{s.done()}}applyImplicitSubtreeHeader(t){let s=this.header.transform,r=this.header.transformMatrix;this.header={...this.header,...t,transform:s,transformMatrix:r,implicitSubtree:void 0},this.refine=this._getRefine(t.refine),this.type=t.type,this.contentUrl=t.contentUrl,this._initializeLodMetric(t),this._updateLodMetricScale(),this._initializeBoundingVolumes(this.header),this._initializeContent(this.header)}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=G.UNLOADED,this.tileDrawn=!0,!0}updateVisibility(t,s){if(this._frameNumber===t.frameNumber)return;let r=this.parent,n=r?r._visibilityPlaneMask:k.MASK_INDETERMINATE;if(this.tileset._traverser.options.updateTransforms){let i=r?r.computedTransform:this.tileset.modelMatrix;this._updateTransform(i)}this._distanceToCamera=this.distanceToTile(t),this._screenSpaceError=this.getScreenSpaceError(t,!1),this._updateRequestPriorityMetrics(t),this._visibilityPlaneMask=this.visibility(t,n),this._visible=this._visibilityPlaneMask!==k.MASK_OUTSIDE,this._inRequestVolume=this.insideViewerRequestVolume(t),this._frameNumber=t.frameNumber,this.viewportIds=s}_updateRequestPriorityMetrics(t){if(this.tileset.type!==j.TILES3D){this._screenSpaceErrorProgressiveResolution=this._screenSpaceError,this._priorityProgressiveResolution=!1,this._foveatedFactor=0,this.priorityDeferred=!1;return}let s=this.tileset.options,r=s.progressiveResolutionHeightFraction;if(this._screenSpaceErrorProgressiveResolution=this.getScreenSpaceError(t,!1,r),this._priorityProgressiveResolution=Jn(this._screenSpaceErrorProgressiveResolution,this.parent?._screenSpaceErrorProgressiveResolution,this.tileset.memoryAdjustedScreenSpaceError,r),!s.foveatedScreenSpaceError||t.viewport?.orthographic||!t.camera?.position||!t.camera?.direction){this._foveatedFactor=0,this.priorityDeferred=!1;return}this._foveatedFactor=Kn(this.boundingVolume,t.camera);let n=ti({refinement:this.refine,skipLevelOfDetail:this.tileset._traverser.options.skipLevelOfDetail,foveatedScreenSpaceError:s.foveatedScreenSpaceError,foveatedConeSize:s.foveatedConeSize,minimumScreenSpaceErrorRelaxation:s.foveatedMinimumScreenSpaceErrorRelaxation,interpolationCallback:s.foveatedInterpolationCallback,foveatedFactor:this._foveatedFactor,verticalFieldOfView:t.camera.verticalFieldOfView,screenSpaceError:this._screenSpaceError,parentScreenSpaceError:this.parent?._screenSpaceError,maximumScreenSpaceError:this.tileset.memoryAdjustedScreenSpaceError,priorityProgressiveResolution:this._priorityProgressiveResolution});this.priorityDeferred=ei(n,t.camera.timeSinceMovement,s.foveatedTimeDelay)}visibility(t,s){let{cullingVolume:r}=t,{boundingVolume:n}=this;return r.computeVisibilityWithPlaneMask(n,s)}contentVisibility(){return!0}distanceToTile(t){let s=this.boundingVolume;return Math.sqrt(Math.max(s.distanceSquaredTo(t.camera.position),0))}cameraSpaceZDepth({camera:t}){let s=this.boundingVolume;return ir.subVectors(s.center,t.position),t.direction.dot(ir)}insideViewerRequestVolume(t){let s=this._viewerRequestVolume;return!s||s.distanceSquaredTo(t.camera.position)<=0}updateExpiration(){if(uh(this._expireDate)&&this.contentReady&&!this.hasEmptyContent){let t=Date.now();Date.lessThan(this._expireDate,t)&&(this.contentState=G.EXPIRED,this._expiredContent=this.content)}}get extras(){return this.header.extras}_initializeLodMetric(t){"lodMetricType"in t?this.lodMetricType=t.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 t?this._unscaledLodMetricValue=t.lodMetricValue:(this._unscaledLodMetricValue=this.parent?this.parent._unscaledLodMetricValue:this.tileset.lodMetricValue,console.warn("3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue")),this.lodMetricValue=this._unscaledLodMetricValue}_initializeTransforms(t){this.transform=t.transform?new v(t.transform):new v;let s=this.parent,r=this.tileset,n=s&&s.computedTransform?s.computedTransform.clone():r.modelMatrix.clone();this.computedTransform=new v(n).multiplyRight(this.transform);let i=s&&s._initialTransform?s._initialTransform.clone():new v;this._initialTransform=new v(i).multiplyRight(this.transform)}_updateLodMetricScale(){if(this.lodMetricType!==Lt.GEOMETRIC_ERROR){this.lodMetricValue=this._unscaledLodMetricValue;return}let t=this.computedTransform.getScale(ir),s=Math.max(t[0],t[1],t[2]);this.lodMetricValue=this._unscaledLodMetricValue*s}_initializeBoundingVolumes(t){this._contentBoundingVolume=null,this._viewerRequestVolume=null,this._updateBoundingVolume(t)}_initializeContent(t){this.content={_tileset:this.tileset,_tile:this},this.hasEmptyContent=!0,this.contentState=G.UNLOADED,this.hasTilesetContent=!1,t.contentUrl&&(this.content=null,this.hasEmptyContent=!1)}_initializeRenderingState(t){this.depth=t.level||(this.parent?this.parent.depth+1:0),this._shouldRefine=!1,this._distanceToCamera=0,this._centerZDepth=0,this._screenSpaceError=0,this._screenSpaceErrorProgressiveResolution=0,this._priorityProgressiveResolution=!1,this._foveatedFactor=0,this.priorityDeferred=!1,this._visibilityPlaneMask=k.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(t){return t||this.parent&&this.parent.refine||Y.REPLACE}_isTileset(){return this.content?.shape==="tileset3d"}_onContentLoaded(){switch(this.content&&this.content.type){case"vctr":case"geom":this.tileset._traverser.disableSkipLevelOfDetail=!0;break;default:}this._isTileset()?this.hasTilesetContent=!0:this.gpuMemoryUsageInBytes=this._getGpuMemoryUsageInBytes()}_updateBoundingVolume(t){this.boundingVolume=Pt(t.boundingVolume,this.computedTransform,this.boundingVolume),t.viewerRequestVolume&&(this._viewerRequestVolume=Pt(t.viewerRequestVolume,this.computedTransform,this._viewerRequestVolume));let s=t.content;s&&s.boundingVolume&&(this._contentBoundingVolume=Pt(s.boundingVolume,this.computedTransform,this._contentBoundingVolume))}_updateTransform(t=new v){let s=t.clone().multiplyRight(this.transform);s.equals(this.computedTransform)||(this.computedTransform=s,this._updateLodMetricScale(),this._updateBoundingVolume(this.header))}};var Ye=class extends at{pendingImplicitSubtrees=new Map;traversalFinished(t){let s=`${t.viewport.id}:`;for(let[r,n]of this.pendingImplicitSubtrees)if(r.startsWith(s)&&n===t.frameNumber)return!1;return!0}compareDistanceToCamera(t,s){return s._distanceToCamera===0&&t._distanceToCamera===0?s._centerZDepth-t._centerZDepth:s._distanceToCamera-t._distanceToCamera}updateChildTiles(t,s){if(t.hasUnloadedChildren&&t.isVisibleAndInRequestVolume&&this.shouldRefine(t,s)){let r=`${s.viewport.id}:${t.id}`;this.pendingImplicitSubtrees.has(r)||(this.pendingImplicitSubtrees.set(r,s.frameNumber),t.tileset._loadTileChildren(t,s).finally(()=>{this.handleImplicitSubtreeLoad(t,s,r)}))}super.updateChildTiles(t,s)}handleImplicitSubtreeLoad(t,s,r){this.pendingImplicitSubtrees.delete(r),this._frameNumber===s.frameNumber&&(t.childrenState==="ready"?this.executeTraversal(t,s):this.traversalFinished(s)&&this.options.onTraversalEnd(s))}updateTileVisibility(t,s){if(super.updateTileVisibility(t,s),!t.isVisibleAndInRequestVolume)return;let r=t.children.length>0;if(t.hasTilesetContent&&r){let o=t.children[0];this.updateTileVisibility(o,s),t._visible=o._visible;return}if(this.meetsScreenSpaceErrorEarly(t,s)){t._visible=!1;return}let n=t.refine===Y.REPLACE,i=t._optimChildrenWithinParent===Zn.USE_OPTIMIZATION;if(n&&i&&r&&!this.anyChildrenVisible(t,s)){t._visible=!1;return}}meetsScreenSpaceErrorEarly(t,s){let{parent:r}=t;return!r||r.hasTilesetContent||r.refine!==Y.ADD?!1:!this.shouldRefine(t,s,!0)}};var dh=6378137,fh=6378137,or=6356752314245179e-9,Nt=new m;function Ei(e,t){if(e instanceof mt){let{halfAxes:s}=e,r=mh(s);return Math.log2(or/(r+t[2]))}else if(e instanceof Z){let{radius:s}=e;return Math.log2(or/(s+t[2]))}else if(e.width&&e.height){let{width:s,height:r}=e,n=Math.log2(dh/s),i=Math.log2(fh/r);return(n+i)/2}return 1}function ar(e,t,s){w.WGS84.cartographicToCartesian([e.xmax,e.ymax,e.zmax],Nt);let r=Math.sqrt(Math.pow(Nt[0]-s[0],2)+Math.pow(Nt[1]-s[1],2)+Math.pow(Nt[2]-s[2],2));return Math.log2(or/(r+t[2]))}function bi(e,t,s){let[r,n,i,o]=e;return ar({xmin:r,xmax:i,ymin:n,ymax:o,zmin:0,zmax:0},t,s)}function mh(e){e.getColumn(0,Nt);let t=e.getColumn(1),s=e.getColumn(2);return Nt.add(t).add(s).len()}var ph=4,gh=8;function hr(e,t){return{coordinates:t,subtreeUrl:$e(e.subtreesUrlTemplate,t),descriptor:e}}function Ge(e,t){let{descriptor:s}=t;Eh(s);let r={tileCount:0,childSubtreeCount:0},n=wi(e,t,{localLevel:0,mortonIndex:0},t.coordinates,r);if(!n)throw new Error(`Invalid 3D Tiles subtree: root tile is unavailable at ${t.subtreeUrl}`);return{root:n,...r}}function $e(e,t){let s={level:t.level,x:t.x,y:t.y,z:t.z};return e.replace(/{(level|x|y|z)}/gi,(r,n)=>String(s[n.toLowerCase()]))}function wi(e,t,s,r,n){let{descriptor:i}=t,o=Mh(i.subdivisionScheme),a=_h(o,s.localLevel)+s.mortonIndex;if(!cr(e.tileAvailability,a))return null;n.tileCount++;let c=cr(Th(e.contentAvailability),a),h=[];if(r.level<i.maximumLevel)if(s.localLevel+1<i.subtreeLevels)for(let l=0;l<o;l++){let u=Ri(r,l,i.subdivisionScheme),d=wi(e,t,{localLevel:s.localLevel+1,mortonIndex:s.mortonIndex*o+l},u,n);d&&h.push(d)}else for(let l=0;l<o;l++){let u=s.mortonIndex*o+l;if(cr(e.childSubtreeAvailability,u)){let d=Ri(r,l,i.subdivisionScheme);h.push(xh(i,d)),n.childSubtreeCount++}}return yh(i,t,r,c,h)}function xh(e,t){let s=hr(e,t);return{id:Ci(s,t),children:[],implicitSubtree:s,boundingVolume:Oi(e.rootBoundingVolume,t,e.subdivisionScheme),geometricError:e.rootLodMetricValue/2**t.level,lodMetricType:e.lodMetricType,lodMetricValue:e.rootLodMetricValue/2**t.level,refine:e.refine,type:ot.EMPTY}}function yh(e,t,s,r,n){let i=r&&e.contentUrlTemplate?$e(e.contentUrlTemplate,s):void 0,o=e.rootLodMetricValue/2**s.level;return{id:Ci(t,s),children:n,contentUrl:i,content:i?{...e.contentHeader,uri:i}:void 0,refine:e.refine,type:Sh(i),lodMetricType:e.lodMetricType,lodMetricValue:o,geometricError:o,boundingVolume:Oi(e.rootBoundingVolume,s,e.subdivisionScheme)}}function Ci(e,t){return`${e.subtreeUrl}#implicit=${t.level}/${t.x}/${t.y}/${t.z}`}function cr(e,t){if(typeof e?.constant=="number")return!!e.constant;let s=e?.explicitBitstream;if(!s)return!1;let r=Math.floor(t/8),n=t%8;return!!(s[r]>>n&1)}function Th(e){return Array.isArray(e)?e[0]||{constant:0}:e||{constant:0}}function _h(e,t){return(e**t-1)/(e-1)}function Ri(e,t,s){return{level:e.level+1,x:e.x*2+(t&1),y:e.y*2+(t>>1&1),z:s==="OCTREE"?e.z*2+(t>>2&1):0}}function Mh(e){return e==="OCTREE"?gh:ph}function Oi(e,t,s){if(e.region){let[r,n,i,o,a,c]=e.region,h=2**t.level,l=(i-r)/h,u=(o-n)/h,d=r+l*t.x,f=n+u*t.y,g=a,x=c;if(s==="OCTREE"){let p=(c-a)/h;g=a+p*t.z,x=g+p}return{region:[d,f,d+l,f+u,g,x]}}if(e.box){if(e.s2VolumeInfo)return{box:[...e.box],s2VolumeInfo:e.s2VolumeInfo};let r=e.box,n=2**t.level,i=-1+(2*t.x+1)/n,o=-1+(2*t.y+1)/n,a=-1+(2*t.z+1)/n,c=s==="OCTREE";return{box:[...[r[0]+r[3]*i+r[6]*o+(c?r[9]*a:0),r[1]+r[4]*i+r[7]*o+(c?r[10]*a:0),r[2]+r[5]*i+r[8]*o+(c?r[11]*a:0)],r[3]/n,r[4]/n,r[5]/n,r[6]/n,r[7]/n,r[8]/n,c?r[9]/n:r[9],c?r[10]/n:r[10],c?r[11]/n:r[11]]}}throw new Error(`Unsupported implicit 3D Tiles bounding volume: ${JSON.stringify(e)}`)}function Sh(e){if(!e)return ot.EMPTY;let t=e.split("?")[0].split(".").pop()?.toLowerCase();switch(t){case"pnts":return ot.POINTCLOUD;case"i3dm":case"b3dm":case"glb":case"gltf":return ot.SCENEGRAPH;default:return t||ot.EMPTY}}function Eh(e){if(e.subdivisionScheme!=="QUADTREE"&&e.subdivisionScheme!=="OCTREE")throw new Error(`Unsupported implicit subdivision scheme: ${e.subdivisionScheme}`);if(!Number.isInteger(e.subtreeLevels)||e.subtreeLevels<1)throw new Error("Implicit subtreeLevels must be a positive integer");if(!Number.isInteger(e.maximumLevel)||e.maximumLevel<0)throw new Error("Implicit availableLevels must describe at least the root level")}var bh={draco:!1,meshopt:!1,dds:!1,ktx2:!1},Rh=32,He=class{type=j.TILES3D;loader;url;basePath;tileset=null;loadOptions;coreApi;contentFormats={...bh};asset;properties;extras;credits;metadata;queryParams={};tileUrlCache=new Map;implicitSubtreeCache=new Map;pendingImplicitSubtreeUrls=new Set;maximumCachedSubtrees;implicitTilingStats={requestedSubtrees:0,loadedSubtrees:0,cacheHits:0,materializedTiles:0};destroyed=!1;extensionsUsed=[];resolver;rootTileset;constructor(t,s={}){let r=wh(t);this.rootTileset=Ai(t)?null:t,this.tileset=this.rootTileset,this.loader=r.loader,this.url=r.url,this.basePath=r.basePath||J.dirname(r.url),this.resolver=r.resolver,this.coreApi=r.coreApi,this.loadOptions=s;let n=Number(s["3d-tiles"]?.maximumCachedSubtrees);this.maximumCachedSubtrees=Number.isFinite(n)?Math.max(0,Math.floor(n)):Rh}destroy(){this.destroyed=!0,this.tileUrlCache.clear(),this.implicitSubtreeCache.clear(),this.pendingImplicitSubtreeUrls.clear()}async initialize(){if(!this.rootTileset){let t=this.loadOptions[this.loader.id]||{};this.rootTileset=await this.loadRootData(this.url,{...this.loadOptions,[this.loader.id]:{...t,isTileset:!0}})}if(this.tileset=this.rootTileset,this.rootTileset.queryString){let t=new URLSearchParams(this.rootTileset.queryString);for(let[s,r]of t.entries())this.setQueryParameter(s,r)}if(this.asset=this.rootTileset.asset,!this.asset)throw new Error("Tileset must have an asset property.");if(this.asset.version!=="0.0"&&this.asset.version!=="1.0"&&this.asset.version!=="1.1")throw new Error("The tileset must be 3D Tiles version either 0.0 or 1.0 or 1.1.");"tilesetVersion"in this.asset&&this.setQueryParameter("v",this.asset.tilesetVersion),this.properties=this.rootTileset.properties,this.extras=this.rootTileset.extras,this.credits={attributions:[]},this.extensionsUsed.splice(0,this.extensionsUsed.length,...this.rootTileset.extensionsUsed||[]),this.metadata={type:this.type,loader:this.loader,url:this.url,basePath:this.basePath,tileset:this.rootTileset,lodMetricType:this.rootTileset.lodMetricType,lodMetricValue:this.rootTileset.lodMetricValue,refine:this.rootTileset.root?.refine}}getMetadata(){if(!this.metadata)throw new Error("Tiles3DSource has not been initialized");return this.metadata}async getRootTileset(){return this.getMetadata().tileset}initializeTileHeaders(t,s,r){let n=new et(t,s.root,r||void 0);r&&(r.children.push(n),n.depth=r.depth+1);let i=[n];for(;i.length>0;){let o=i.pop();t.stats.get("Tiles In Tileset(s)").incrementCount();let a=o.header.children||[];for(let c of a){let h=new et(t,c,o);if(h.contentUrl?.includes("?session=")){let u=new URL(h.contentUrl).searchParams.get("session");u&&this.setQueryParameter("session",u)}o.children.push(h),h.depth=o.depth+1,i.push(h)}}return n}createTraverser(t){return new Ye(t)}async loadTileContent(t){let s=this.getTileUrl(t.contentUrl),r=this.loadOptions[this.loader.id]||{},n={...this.loadOptions,[this.loader.id]:{...r,isTileset:"auto",assetGltfUpAxis:this.asset&&this.asset.gltfUpAxis||"Y"}},i=await this.loadResourceData(s,n);return t.content=i,{loaded:!0,nestedTileset:i?.shape==="tileset3d"?i:void 0}}async loadTileChildren(t,s){let r=t.header.implicitSubtree;if(!r)return{loaded:!1,tileCount:0,childSubtreeCount:0};let n=this.getTileUrl(r.subtreeUrl),i=await this.loadImplicitSubtreeResource(n);if(this.destroyed||t.isDestroyed())return{loaded:!1,tileCount:0,childSubtreeCount:0};let o=Ge(i,{...r,subtreeUrl:n});t.applyImplicitSubtreeHeader(o.root);let a=this.initializeMaterializedChildren(t.tileset,t,o.root.children);return this.implicitTilingStats.loadedSubtrees++,this.implicitTilingStats.materializedTiles+=a,{loaded:!0,tileCount:o.tileCount,childSubtreeCount:o.childSubtreeCount}}getImplicitTilingStats(){return{...this.implicitTilingStats,cachedSubtrees:this.implicitSubtreeCache.size-this.pendingImplicitSubtreeUrls.size,pendingSubtrees:this.pendingImplicitSubtreeUrls.size}}getTileUrl(t){if(t.startsWith("data:"))return t;let s=this.tileUrlCache.get(t);if(s)return s;if(!Object.keys(this.queryParams).length)return this.tileUrlCache.set(t,t),t;let[r,n=""]=t.split("?"),i=new URLSearchParams(n);for(let[c,h]of Object.entries(this.queryParams))i.has(c)||i.set(c,h);let o=i.toString(),a=o?`${r}?${o}`:r;return this.tileUrlCache.set(t,a),a}setQueryParameter(t,s){this.queryParams[t]!==s&&(this.queryParams[t]=s,this.tileUrlCache.clear())}getViewState(t){if(!t)return{asset:this.asset,properties:this.properties,extras:this.extras,credits:this.credits};let{center:s}=t.boundingVolume,r;return s&&(s[0]!==0||s[1]!==0||s[2]!==0)?(r=new m,w.WGS84.cartesianToCartographic(s,r)):r=new m(0,0,-w.WGS84.radii[0]),{asset:this.asset,properties:this.properties,extras:this.extras,credits:this.credits,boundingVolume:t.boundingVolume,cartographicCenter:r,cartesianCenter:s,zoom:Ei(t.boundingVolume,r)}}hasExtension(t){return this.extensionsUsed.includes(t)}onTileLoaded(t,s,r){let{extensionsRemoved:n=[]}=s.content?.gltf||{};n.includes("KHR_draco_mesh_compression")&&(this.contentFormats.draco=!0),n.includes("EXT_meshopt_compression")&&(this.contentFormats.meshopt=!0),n.includes("KHR_texture_basisu")&&(this.contentFormats.ktx2=!0),r.nestedTileset&&t._initializeTileHeaders(r.nestedTileset,s)}async loadWithCoreApi(t,s,r=this.loader){if(!this.coreApi)throw new Error("Tiles3DSource requires an injected coreApi to load tileset data");return await this.coreApi.load(t,r,s)}async loadRootData(t,s){return this.resolver?await this.resolver.loadRoot(t,this.loader,s):await this.loadWithCoreApi(t,s)}async loadResourceData(t,s,r=this.loader){return this.resolver?await this.resolver.loadResource(t,r,s):await this.loadWithCoreApi(t,s,r)}async loadImplicitSubtreeResource(t){let s=this.implicitSubtreeCache.get(t);if(s)return this.implicitTilingStats.cacheHits++,this.implicitSubtreeCache.delete(t),this.implicitSubtreeCache.set(t,s),await s;this.implicitTilingStats.requestedSubtrees++,this.pendingImplicitSubtreeUrls.add(t);let r=this.loadOptions[this.loader.id]||{},n=this.loadResourceData(t,{...this.loadOptions,[this.loader.id]:{...r,isTileset:!1,isSubtree:!0}});this.implicitSubtreeCache.set(t,n);try{return await n}catch(i){throw this.implicitSubtreeCache.delete(t),i}finally{this.pendingImplicitSubtreeUrls.delete(t),this.trimImplicitSubtreeCache()}}initializeMaterializedChildren(t,s,r){let n=0,i=[{parentTile:s,childHeaders:r}];for(;i.length>0;){let o=i.pop();for(let a of o.childHeaders){let c=new et(t,a,o.parentTile);o.parentTile.children.push(c),c.depth=o.parentTile.depth+1,t.stats.get("Tiles In Tileset(s)").incrementCount(),n++,a.children?.length&&i.push({parentTile:c,childHeaders:a.children})}}return n}trimImplicitSubtreeCache(){if(!(this.implicitSubtreeCache.size<=this.maximumCachedSubtrees)){for(let t of this.implicitSubtreeCache.keys())if(this.pendingImplicitSubtreeUrls.has(t)||this.implicitSubtreeCache.delete(t),this.implicitSubtreeCache.size<=this.maximumCachedSubtrees)break}}};function Ai(e){return!!(e&&typeof e=="object"&&"url"in e&&"loader"in e&&!("type"in e))}function wh(e){return Ai(e)?{...e,basePath:e.basePath||J.dirname(e.url)}:{url:e.url,loader:e.loader,basePath:e.basePath||J.dirname(e.url),resolver:e.resolver,coreApi:e.coreApi}}var Ze=class{frameNumberMap=new Map;register(t,s){let r=this.frameNumberMap.get(t)||new Map,n=r.get(s)||0;r.set(s,n+1),this.frameNumberMap.set(t,r)}deregister(t,s){let r=this.frameNumberMap.get(t);if(!r)return;let n=r.get(s)||1;r.set(s,n-1)}isZero(t,s){return(this.frameNumberMap.get(t)?.get(s)||0)===0}};var lr={REQUESTED:"REQUESTED",COMPLETED:"COMPLETED",ERROR:"ERROR"},je=class{_statusMap;pendingTilesRegister=new Ze;constructor(){this._statusMap={}}add(t,s,r,n){if(!this._statusMap[s]){let{frameNumber:i,viewport:{id:o}}=n;this._statusMap[s]={request:t,callback:r,key:s,frameState:n,status:lr.REQUESTED},this.pendingTilesRegister.register(o,i),t().then(a=>{this._statusMap[s].status=lr.COMPLETED;let{frameNumber:c,viewport:{id:h}}=this._statusMap[s].frameState;this.pendingTilesRegister.deregister(h,c),this._statusMap[s].callback(a,n)}).catch(a=>{this._statusMap[s].status=lr.ERROR;let{frameNumber:c,viewport:{id:h}}=this._statusMap[s].frameState;this.pendingTilesRegister.deregister(h,c),r(a)})}}update(t,s){if(this._statusMap[t]){let{frameNumber:r,viewport:{id:n}}=this._statusMap[t].frameState;this.pendingTilesRegister.deregister(n,r);let{frameNumber:i,viewport:{id:o}}=s;this.pendingTilesRegister.register(o,i),this._statusMap[t].frameState=s}}find(t){return this._statusMap[t]}hasPendingTiles(t,s){return!this.pendingTilesRegister.isZero(t,s)}};var Xe=class extends at{_tileManager;constructor(t){super(t),this._tileManager=new je}traversalFinished(t){return!this._tileManager.hasPendingTiles(t.viewport.id,this._frameNumber||0)}shouldRefine(t,s){return t._lodJudge=We(t,s),t._lodJudge==="DIG"}updateChildTiles(t,s){let r=t.header.children||[],n=t.children;for(let i of r){let o=`${i.id}-${s.viewport.id}`,a=n&&n.find(c=>c.id===o);if(a)a&&this.updateTile(a,s);else{let c=()=>this._loadTile(t,i.id,s);this._tileManager.find(o)?this._tileManager.update(o,s):this._tileManager.add(c,o,l=>this._onTileLoad(l,t,o),s)}}return!1}async _loadTile(t,s,r){if(!t.tileset.source.loadChildTileHeader)throw new Error("I3S source does not support child tile header loading");return await t.tileset.source.loadChildTileHeader(t,s,r)}_onTileLoad(t,s,r){if(t instanceof Error){s.tileset._onSourceError(t,s);return}let n=new et(s.tileset,t,s,r);s.children.push(n);let i=this._tileManager.find(n.id).frameState;this.updateTile(n,i),this._frameNumber===i.frameNumber&&(this.traversalFinished(i)||new Date().getTime()-this.lastUpdate>this.updateDebounceTime)&&this.executeTraversal(n,i)}};var Ch={draco:!1,meshopt:!1,dds:!1,ktx2:!1},Qe=class{type=j.I3S;loader;url;basePath;tileset=null;loadOptions;coreApi;contentFormats={...Ch};asset;properties;extras;credits;metadata;queryParams={};resolver;rootTileset;constructor(t,s={}){let r=Oh(t);this.rootTileset=vi(t)?null:t,this.tileset=this.rootTileset,this.loader=r.loader,this.url=r.url,this.basePath=r.basePath||J.dirname(r.url),this.resolver=r.resolver,this.coreApi=r.coreApi,this.loadOptions=s}async initialize(){this.rootTileset||(this.rootTileset=await this.loadRootData(this.url,this.loadOptions)),this.tileset=this.rootTileset,this.rootTileset.root&&typeof this.rootTileset.root.then=="function"&&(this.rootTileset.root=await this.rootTileset.root);let t=this.loadOptions.i3s;if(t&&typeof t=="object"&&"token"in t){let s=t.token;typeof s=="string"&&(this.queryParams.token=s)}this.metadata={type:this.type,loader:this.loader,url:this.url,basePath:this.basePath,tileset:this.rootTileset,lodMetricType:this.rootTileset.lodMetricType,lodMetricValue:this.rootTileset.lodMetricValue,refine:this.rootTileset.root?.refine}}getMetadata(){if(!this.metadata)throw new Error("I3SSource has not been initialized");return this.metadata}async getRootTileset(){return this.getMetadata().tileset}initializeTileHeaders(t,s,r){let n=new et(t,s.root,r||void 0);return r&&(r.children.push(n),n.depth=r.depth+1),n}createTraverser(t){return new Xe(t)}async loadTileContent(t){let s=this.getTileUrl(t.contentUrl),r=this.loader.id,n=this.loadOptions[r]||{},i=this.getMetadata(),o={...this.loadOptions,[r]:{...n,...t.tileset.options.i3s,_tileOptions:{attributeUrls:t.header.attributeUrls,textureUrl:t.header.textureUrl,textureFormat:t.header.textureFormat,textureLoaderOptions:t.header.textureLoaderOptions,materialDefinition:t.header.materialDefinition,isDracoGeometry:t.header.isDracoGeometry,mbs:t.header.mbs},_tilesetOptions:{store:i.tileset.store,attributeStorageInfo:i.tileset.attributeStorageInfo,fields:i.tileset.fields},isTileHeader:!1}};return t.content=await this.loadResourceData(s,o),{loaded:!0}}async loadChildTileHeader(t,s,r){let n=this.getMetadata();if(n.tileset.nodePages)return await n.tileset.nodePagesTile.formTileFromNodePages(s);let i=this.getTileUrl(`${this.url}/nodes/${s}`),o=this.loadOptions.i3s&&typeof this.loadOptions.i3s=="object"?this.loadOptions.i3s:{},a={...this.loadOptions,i3s:{...o,isTileHeader:!0}};return await this.loadResourceData(i,a)}getTileUrl(t){if(t.startsWith("data:")||!Object.keys(this.queryParams).length)return t;let s=new URLSearchParams(this.queryParams).toString();return`${t}${t.includes("?")?"&":"?"}${s}`}getViewState(t){let s=this.getMetadata(),r=s.tileset.fullExtent;if(r){let{xmin:i,xmax:o,ymin:a,ymax:c,zmin:h,zmax:l}=r,u=new m(i+(o-i)/2,a+(c-a)/2,h+(l-h)/2),d=new m;return w.WGS84.cartographicToCartesian(u,d),{cartographicCenter:u,cartesianCenter:d,zoom:ar(r,u,d)}}let n=s.tileset.store?.extent;if(n){let[i,o,a,c]=n,h=new m(i+(a-i)/2,o+(c-o)/2,0),l=new m;return w.WGS84.cartographicToCartesian(h,l),{cartographicCenter:h,cartesianCenter:l,zoom:bi(n,h,l)}}return console.warn("Extent is not defined in the tileset header"),{cartographicCenter:new m,zoom:1}}onTileLoaded(t,s){switch(s.header.isDracoGeometry&&(this.contentFormats.draco=!0),s.header.textureFormat){case"dds":this.contentFormats.dds=!0;break;case"ktx2":this.contentFormats.ktx2=!0;break;default:}}getTilesTotalCount(){return this.getMetadata().tileset?.nodePagesTile?.nodesInNodePages||null}async loadWithCoreApi(t,s){if(!this.coreApi)throw new Error("I3SSource requires an injected coreApi to load tileset data");return await this.coreApi.load(t,this.loader,s)}async loadRootData(t,s){return this.resolver?await this.resolver.loadRoot(t,this.loader,s):await this.loadWithCoreApi(t,s)}async loadResourceData(t,s){return this.resolver?await this.resolver.loadResource(t,this.loader,s):await this.loadWithCoreApi(t,s)}};function vi(e){return!!(e&&typeof e=="object"&&"url"in e&&"loader"in e&&!("type"in e))}function Oh(e){return vi(e)?{...e,basePath:e.basePath||J.dirname(e.url)}:{url:e.url,loader:e.loader,basePath:e.basePath||J.dirname(e.url),resolver:e.resolver,coreApi:e.coreApi}}var Et=class{index;parent;children;content;error;id;zoom;userData;boundingBox;_abortController;_loader;_loaderId;_isLoaded;_isCancelled;_needsReload;_bbox;constructor(t){this.index=t,this.parent=null,this.children=[],this.content=null,this.error=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(t){this._bbox||(this._bbox=t,"west"in t?this.boundingBox=[[t.west,t.south],[t.east,t.north]]:this.boundingBox=[[t.left,t.top],[t.right,t.bottom]])}get data(){let t=this._loader;return!this._isCancelled&&t!==void 0?t.then(()=>this.data):this.content}get isLoaded(){return this._isLoaded&&!this._needsReload}get isLoading(){return!!this._loader&&!this._isCancelled}get hasError(){return!!this.error}get needsReload(){return this._needsReload||this._isCancelled}get byteLength(){let t=this.content?this.content.byteLength:0;return Number.isFinite(t)?t:0}async _loadData({getData:t,requestScheduler:s,onLoad:r,onError:n}){let i=(p,y,E)=>{if(E===this._loaderId){if(this._loader=void 0,this.content=p,this.error=y?Ah(y):null,this._isCancelled&&!p){this._isLoaded=!1;return}if(this._isLoaded=!0,this._isCancelled=!1,y){n(y,this);return}r(this)}},{index:o,id:a,bbox:c,userData:h,zoom:l}=this,u=this._loaderId;this._abortController=new AbortController;let{signal:d}=this._abortController,f=await s.scheduleRequest(this,()=>1);if(!f){this._isCancelled=!0;return}if(this._isCancelled){f.done();return}let g=null,x;try{g=await t({index:o,id:a,bbox:c,userData:h,zoom:l,signal:d})}catch(p){x=p||!0}finally{f.done()}i(g,x,u)}loadData(t){return this._isLoaded=!1,this._isCancelled=!1,this._needsReload=!1,this.error=null,this._loaderId++,this._loader=this._loadData(t),this._loader}setNeedsReload(){this.isLoading&&(this.abort(),this._loader=void 0),this._needsReload=!0}abort(){this.isLoaded||(this._isCancelled=!0,this._abortController?.abort())}};function Ah(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error("Tile request failed")}var ur="never",dr="no-overlap",ee="best-available",Ii={adapter:null,extent:null,tileSize:512,maxZoom:null,minZoom:null,maxCacheSize:100,maxCacheByteSize:null,refinementStrategy:ee,zRange:null,maxRequests:6,debounceTime:0,zoomOffset:0,onTileLoad:()=>{},onTileUnload:()=>{},onTileError:()=>{},tileSource:null},te=class e{stats;sourceMetadata=null;opts;_requestScheduler;_cache;_dirty;_tiles;_cacheByteSize;_unloadedTileCount;_listeners=new Set;_consumers=new Map;_explicitOptionKeys=new Set;_baseOpts={};_sourceMetadataOverrides={};_maxZoom;_minZoom;_lastTileContext=null;constructor(t){if(this.stats=new tt({id:"Tileset2D",stats:[{name:"Tiles In Cache"},{name:"Cache Size"},{name:"Visible Tiles"},{name:"Selected Tiles"},{name:"Loading Tiles"},{name:"Unloaded Tiles"},{name:"Consumers"}]}),this.opts={...Ii,...t,getTileData:t.getTileData||(()=>null),tileSource:t.tileSource},this._requestScheduler=new ht({throttleRequests:this.opts.maxRequests>0||this.opts.debounceTime>0,maxRequests:this.opts.maxRequests,debounceTime:this.opts.debounceTime}),this._cache=new Map,this._tiles=[],this._dirty=!1,this._cacheByteSize=0,this._unloadedTileCount=0,!this.opts.tileSource&&!t.getTileData)throw new Error("Tileset2D requires either `getTileData` or `tileSource`.");this.setOptions(t),this._updateStats(),this.opts.tileSource&&this._initializeTileSource(this.opts.tileSource).catch(()=>{})}static fromTileSource(t,s={}){return new e({...s,tileSource:t})}get tiles(){return this._tiles}get cacheByteSize(){return this._cacheByteSize}get selectedTiles(){return Array.from(this._getSelectedTilesUnion())}get visibleTiles(){let t=this._getVisibleTilesUnion();for(let s of this._getSelectedTilesUnion())t.add(s);return Array.from(t)}get loadingTiles(){return Array.from(this._cache.values()).filter(t=>t.isLoading)}get unloadedTiles(){return Array.from(this._cache.values()).filter(t=>!t.isLoaded)}get maxZoom(){return this._maxZoom}get minZoom(){return this._minZoom}get refinementStrategy(){return this.opts.refinementStrategy||ee}get adapter(){return this.opts.adapter}subscribe(t){return this._listeners.add(t),()=>this._listeners.delete(t)}attachConsumer(t){this._consumers.set(t,{selectedTiles:new Set,visibleTiles:new Set}),this._updateStats()}detachConsumer(t){this._consumers.delete(t),this._pruneRequests(),this._resizeCache(),this._updateStats()}setOptions(t){this._rememberExplicitOptions(t),this._baseOpts={...this._baseOpts,...t};let s=this.opts.maxRequests,r=this.opts.debounceTime;this._applyResolvedOptions(),(s!==this.opts.maxRequests||r!==this.opts.debounceTime)&&(this._requestScheduler=new ht({throttleRequests:this.opts.maxRequests>0||this.opts.debounceTime>0,maxRequests:this.opts.maxRequests,debounceTime:this.opts.debounceTime}))}finalize(){for(let t of this._cache.values())t.isLoading&&t.abort();this._cache.clear(),this._tiles=[],this._consumers.clear(),this._cacheByteSize=0,this._unloadedTileCount=0,this._updateStats()}reloadAll(){let t=this._getSelectedTilesUnion();for(let s of this._cache.keys()){let r=this._cache.get(s);r&&!t.has(r)?(this._cache.delete(s),this._handleTileUnload(r),this._dirty=!0):r&&r.setNeedsReload()}this._cacheByteSize=this._getCacheByteSize(),this.prepareTiles(),this._updateStats()}updateConsumer(t,s,r){this._consumers.set(t,{selectedTiles:new Set(s),visibleTiles:new Set(r)}),this._pruneRequests(),this._resizeCache(),this._updateStats()}prepareTiles(){this._dirty&&(this._rebuildTree(),this._syncTiles(),this._dirty=!1)}getTileIndices({viewState:t,maxZoom:s,minZoom:r,zRange:n,modelMatrix:i,modelMatrixInverse:o}){let{adapter:a,tileSize:c,extent:h,zoomOffset:l}=this.opts;if(!a)throw new Error("Tileset2D requires an adapter before tile traversal can be used.");return this._lastTileContext={viewState:t,tileSize:c},a.getTileIndices({viewState:t,maxZoom:s,minZoom:r,zRange:n,tileSize:c,extent:vh(h),modelMatrix:i,modelMatrixInverse:o,zoomOffset:l})}getTileId(t){return`${t.x}-${t.y}-${t.z}`}getTileZoom(t){return t.z}getTileMetadata(t){if(!this._lastTileContext)throw new Error("Tileset2D metadata requested before traversal context was set.");if(!this.opts.adapter)throw new Error("Tileset2D requires an adapter before tile metadata can be derived.");return{bbox:this.opts.adapter.getTileBoundingBox(this._lastTileContext,t)}}getParentIndex(t){return{x:Math.floor(t.x/2),y:Math.floor(t.y/2),z:t.z-1}}getTile(t,s){let r=this.getTileId(t),n=this._cache.get(r),i=!1;return!n&&s?(n=new Et(t),Object.assign(n,this.getTileMetadata(n.index)),Object.assign(n,{id:r,zoom:this.getTileZoom(n.index)}),i=!0,this._cache.set(r,n),this._dirty=!0,this._updateStats()):n&&n.needsReload&&(i=!0),n&&this._touchTile(r,n),n&&i&&s&&(n.loadData({getData:this.opts.getTileData,requestScheduler:this._requestScheduler,onLoad:this._handleTileLoad.bind(this),onError:this._handleTileError.bind(this)}).catch(()=>{}),this._updateStats()),n}async _initializeTileSource(t){try{this.sourceMetadata=await t.getMetadata(),this._sourceMetadataOverrides=this._getMetadataOverrides(this.sourceMetadata),this._applyResolvedOptions(),this._notifyUpdate()}catch(s){let r=s instanceof Error?s:new Error(`TileSource metadata error: ${String(s)}`);this._notifyError(r)}}_rememberExplicitOptions(t){for(let s of Object.keys(t))this._explicitOptionKeys.add(s)}_applyResolvedOptions(){let t={...Ii,...this._sourceMetadataOverrides,...this._baseOpts};if(t.tileSource){let s=t.tileSource;t.getTileData=r=>s.getTileData(r)}this.opts=t,this._maxZoom=typeof this.opts.maxZoom=="number"&&Number.isFinite(this.opts.maxZoom)?Math.floor(this.opts.maxZoom):void 0,this._minZoom=typeof this.opts.minZoom=="number"&&Number.isFinite(this.opts.minZoom)?Math.ceil(this.opts.minZoom):void 0}_getMetadataOverrides(t){if(!t)return{};let s={};return!this._explicitOptionKeys.has("minZoom")&&Number.isFinite(t.minZoom)&&(s.minZoom=t.minZoom),!this._explicitOptionKeys.has("maxZoom")&&Number.isFinite(t.maxZoom)&&(s.maxZoom=t.maxZoom),!this._explicitOptionKeys.has("extent")&&t.boundingBox&&(s.extent=[t.boundingBox[0][0],t.boundingBox[0][1],t.boundingBox[1][0],t.boundingBox[1][1]]),s}_handleTileLoad(t){this.opts.onTileLoad?.(t),this._cacheByteSize=this._getCacheByteSize(),this._resizeCache();for(let s of this._listeners)s.onTileLoad?.(t);this._updateStats()}_handleTileError(t,s){this.opts.onTileError?.(t,s);for(let r of this._listeners)r.onTileError?.(t,s);this._updateStats()}_handleTileUnload(t){this._unloadedTileCount++,this.opts.onTileUnload?.(t);for(let s of this._listeners)s.onTileUnload?.(t);this._updateStats()}_notifyUpdate(){for(let t of this._listeners)t.onUpdate?.()}_notifyError(t){for(let s of this._listeners)s.onError?.(t)}_updateStats(){this._setStatCount("Tiles In Cache",this._cache.size),this._setStatCount("Cache Size",this.cacheByteSize),this._setStatCount("Visible Tiles",this.visibleTiles.length),this._setStatCount("Selected Tiles",this.selectedTiles.length),this._setStatCount("Loading Tiles",this.loadingTiles.length),this._setStatCount("Unloaded Tiles",this._unloadedTileCount),this._setStatCount("Consumers",this._consumers.size);for(let t of this._listeners)t.onStatsChange?.(this.stats)}_setStatCount(t,s){this.stats.get(t).reset().addCount(s)}_getSelectedTilesUnion(){let t=new Set;for(let s of this._consumers.values())for(let r of s.selectedTiles)t.add(r);return t}_getVisibleTilesUnion(){let t=new Set;for(let s of this._consumers.values())for(let r of s.visibleTiles)t.add(r);return t}_touchTile(t,s){this._cache.delete(t),this._cache.set(t,s)}_getCacheByteSize(){let t=0;for(let s of this._cache.values())t+=s.byteLength;return t}_pruneRequests(){let{maxRequests:t=0}=this.opts,s=this._getSelectedTilesUnion(),r=this._getVisibleTilesUnion(),n=[],i=0;for(let o of this._cache.values())o.isLoading&&(i++,!s.has(o)&&!r.has(o)&&n.push(o));for(;t>0&&i>t&&n.length>0;){let o=n.shift();o&&o.abort(),i--}}_rebuildTree(){for(let t of this._cache.values())t.parent=null,t.children&&(t.children.length=0);for(let t of this._cache.values()){let s=this._getNearestAncestor(t);t.parent=s,s?.children&&s.children.push(t)}}_syncTiles(){this._tiles=Array.from(this._cache.values()).sort((t,s)=>t.zoom-s.zoom)}_resizeCache(){let t=this.opts.maxCacheSize??100,s=this.opts.maxCacheByteSize??1/0,r=this._getVisibleTilesUnion(),n=this._getSelectedTilesUnion();if(this._cache.size>t||this._cacheByteSize>s){for(let[o,a]of this._cache)if(!r.has(a)&&!n.has(a)&&(this._cache.delete(o),this._cacheByteSize=this._getCacheByteSize(),this._handleTileUnload(a)),this._cache.size<=t&&this._cacheByteSize<=s)break;this._dirty=!0}this._dirty&&(this._rebuildTree(),this._syncTiles(),this._dirty=!1)}_getNearestAncestor(t){let{_minZoom:s=0}=this,r=t.index;for(;this.getTileZoom(r)>s;){r=this.getParentIndex(r);let n=this.getTile(r);if(n)return n}return null}};function vh(e){return e&&e.length===4?e:void 0}var Ke={getMetadata:async()=>({name:"",keywords:[],layers:[]}),getImage:async()=>null,debounceTime:0},Je=class e{metadata=null;_opts;_listeners=new Set;_currentRequest=null;_lastAcceptedRequestId=-1;_nextRequestId=0;_loadCounter=0;_timeoutId=null;_abortController=null;_finalized=!1;constructor(t){if(this._opts=this._normalizeOptions(t),!this._opts.imageSource&&(!t.getImage||!t.getMetadata))throw new Error("ImageSet requires either `imageSource` or both `getImage` and `getMetadata`.")}static fromImageSource(t,s={}){return new e({...s,imageSource:t})}get isLoaded(){return this._loadCounter===0&&!!this._currentRequest}get image(){return this._currentRequest?.image||null}get currentRequest(){return this._currentRequest}get imageSource(){return this._opts.imageSource}subscribe(t){return this._listeners.add(t),()=>this._listeners.delete(t)}setOptions(t){let s=this._opts.imageSource,r=this._normalizeOptions({...this._opts,...t}),n=s!==r.imageSource||this._opts.getImage!==r.getImage||this._opts.getMetadata!==r.getMetadata;this._opts=r,n&&(this._cancelScheduledImage(),this.metadata=null,this._currentRequest=null,this._lastAcceptedRequestId=-1,this._nextRequestId=0,this._emitUpdate())}async loadMetadata(){this._startLoading();try{let t=await this._opts.getMetadata();if(this._finalized)return t;this.metadata=t;for(let s of this._listeners)s.onMetadataLoad?.(t);return this._emitUpdate(),t}catch(t){let s=Li(t,"Image metadata request failed");if(!this._finalized)for(let r of this._listeners)r.onMetadataLoadError?.(s);throw s}finally{this._finishLoading()}}requestImage(t,s=this._opts.debounceTime){let r=this._nextRequestId++;return this._cancelScheduledImage(),this._abortActiveRequest(),s>0?this._timeoutId=setTimeout(()=>{this._timeoutId=null,this._loadImage(r,t)},s):this._loadImage(r,t),r}finalize(){this._finalized=!0,this._cancelScheduledImage(),this._abortActiveRequest(),this._listeners.clear()}async _loadImage(t,s){if(!this._finalized){this._startLoading();for(let r of this._listeners)r.onImageLoadStart?.(t,s);try{let r=new AbortController;this._abortController=r;let n=await this._opts.getImage({...s,signal:r.signal});if(this._finalized||t<=this._lastAcceptedRequestId)return;this._lastAcceptedRequestId=t,this._currentRequest={requestId:t,parameters:s,image:n};for(let i of this._listeners)i.onImageLoad?.(this._currentRequest);this._emitUpdate()}catch(r){if(Ih(r))return;let n=Li(r,"Image request failed");if(!this._finalized)for(let i of this._listeners)i.onImageLoadError?.(t,n,s)}finally{this._abortController?.signal===s.signal&&(this._abortController=null),this._finishLoading()}}}_normalizeOptions(t){let s=t.imageSource||null;return{...Ke,...t,imageSource:s,getMetadata:t.getMetadata||(()=>s?s.getMetadata():Ke.getMetadata()),getImage:t.getImage||(r=>s?s.getImage(r):Ke.getImage(r)),debounceTime:t.debounceTime??Ke.debounceTime}}_emitUpdate(){for(let t of this._listeners)t.onUpdate?.()}_startLoading(){let t=this._loadCounter>0;this._loadCounter++,t||(this._emitLoadingStateChange(!0),this._emitUpdate())}_finishLoading(){let t=this._loadCounter>0;this._loadCounter=Math.max(0,this._loadCounter-1),t&&this._loadCounter===0&&(this._emitLoadingStateChange(!1),this._emitUpdate())}_emitLoadingStateChange(t){for(let s of this._listeners)s.onLoadingStateChange?.(t)}_cancelScheduledImage(){this._timeoutId!==null&&(clearTimeout(this._timeoutId),this._timeoutId=null)}_abortActiveRequest(){this._abortController?.abort(),this._abortController=null}};function Ih(e){return e instanceof Error&&e.name==="AbortError"}function Li(e,t){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error(t)}var se={getMetadata:async()=>({width:0,height:0,bandCount:0,dtype:"uint8"}),getRaster:async()=>({data:new Uint8Array(0),width:0,height:0,bandCount:0,dtype:"uint8"}),debounceTime:0,shouldRefetch:()=>!0},ts=class e{metadata=null;_opts;_listeners=new Set;_currentRequest=null;_lastAcceptedRequestId=-1;_nextRequestId=0;_loadCounter=0;_timeoutId=null;_abortController=null;_finalized=!1;constructor(t){if(this._opts=this._normalizeOptions(t),!this._opts.rasterSource&&(!t.getRaster||!t.getMetadata))throw new Error("RasterSet requires either `rasterSource` or both `getRaster` and `getMetadata`.")}static fromRasterSource(t,s={}){return new e({...s,rasterSource:t})}get isLoaded(){return this._loadCounter===0&&!!this._currentRequest}get raster(){return this._currentRequest?.raster||null}get currentRequest(){return this._currentRequest}get rasterSource(){return this._opts.rasterSource}subscribe(t){return this._listeners.add(t),()=>this._listeners.delete(t)}setOptions(t){let s=this._opts.rasterSource,r=this._normalizeOptions({...this._opts,...t}),n=s!==r.rasterSource||this._opts.getRaster!==r.getRaster||this._opts.getMetadata!==r.getMetadata;this._opts=r,n&&(this._cancelScheduledRaster(),this.metadata=null,this._currentRequest=null,this._lastAcceptedRequestId=-1,this._nextRequestId=0,this._emitUpdate())}async loadMetadata(){this._startLoading();try{let t=await this._opts.getMetadata();if(this._finalized)return t;this.metadata=t;for(let s of this._listeners)s.onMetadataLoad?.(t);return this._emitUpdate(),t}catch(t){let s=Pi(t,"Raster metadata request failed");if(!this._finalized)for(let r of this._listeners)r.onMetadataLoadError?.(s);throw s}finally{this._finishLoading()}}requestRaster(t,s=this._opts.debounceTime){if(!this.shouldRefetchRaster(t))return this._currentRequest?.requestId??-1;let r=this._nextRequestId++;return this._cancelScheduledRaster(),s>0?this._timeoutId=setTimeout(()=>{this._timeoutId=null,this._loadRaster(r,t)},s):this._loadRaster(r,t),r}shouldRefetchRaster(t){return this._opts.shouldRefetch({currentRequest:this._currentRequest,metadata:this.metadata,nextParameters:t})}finalize(){this._finalized=!0,this._cancelScheduledRaster(),this._abortActiveRequest(),this._listeners.clear()}async _loadRaster(t,s){if(!this._finalized){this._startLoading();for(let r of this._listeners)r.onRasterLoadStart?.(t,s);try{let r=new AbortController;this._abortController=r;let n=await this._opts.getRaster({...s,signal:r.signal});if(this._finalized||r.signal.aborted||t<=this._lastAcceptedRequestId)return;this._lastAcceptedRequestId=t,this._currentRequest={requestId:t,parameters:s,raster:n};for(let i of this._listeners)i.onRasterLoad?.(this._currentRequest);this._emitUpdate()}catch(r){if(Lh(r))return;let n=Pi(r,"Raster request failed");if(!this._finalized)for(let i of this._listeners)i.onRasterLoadError?.(t,n,s)}finally{this._abortController=null,this._finishLoading()}}}_normalizeOptions(t){let s=t.rasterSource||null;return{...se,...t,rasterSource:s,getMetadata:t.getMetadata||(()=>s?s.getMetadata():se.getMetadata()),getRaster:t.getRaster||(r=>s?s.getRaster(r):se.getRaster(r)),debounceTime:t.debounceTime??se.debounceTime,shouldRefetch:t.shouldRefetch||(r=>se.shouldRefetch(r))}}_emitUpdate(){for(let t of this._listeners)t.onUpdate?.()}_emitLoadingStateChange(t){for(let s of this._listeners)s.onLoadingStateChange?.(t)}_startLoading(){let t=this._loadCounter>0;this._loadCounter++,t||(this._emitLoadingStateChange(!0),this._emitUpdate())}_finishLoading(){let t=this._loadCounter>0;this._loadCounter=Math.max(0,this._loadCounter-1),t&&this._loadCounter===0&&(this._emitLoadingStateChange(!1),this._emitUpdate())}_cancelScheduledRaster(){this._timeoutId!==null&&(clearTimeout(this._timeoutId),this._timeoutId=null)}_abortActiveRequest(){this._abortController?.abort(),this._abortController=null}};function Pi(e,t){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error(t)}function Lh(e){return e instanceof Error&&e.name==="AbortError"}var qt=class{header;parent;children=[];childrenLoaded=!1;childrenPromise=null;selected=!1;viewportIds=[];content=null;contentAvailable=!1;contentFailed=!1;isContentLoading=!1;constructor(t,s=null){this.header=t,this.parent=s}get id(){return this.header.id}get level(){return this.header.level}get pointCount(){return this.header.pointCount}get geometricError(){return this.header.geometricError}get boundingVolume(){return this.header.boundingVolume}setSelected(t){this.selected=!0,this.viewportIds.includes(t)||this.viewportIds.push(t)}clearSelection(){this.selected=!1,this.viewportIds=[]}};var Ph={debounceTime:0,minimumNodePixelSize:150,maximumScreenSpaceError:1,pointBudget:2e6,maxDepth:Number.POSITIVE_INFINITY,onTileLoad:()=>{},onTileError:()=>{},onTraversalComplete:e=>e,onUpdate:()=>{}},es=64,ss=class{dataSource;options;root=null;cartographicCenter=null;zoom=1;boundingVolume=null;visibleTilesCount=0;frameNumberValue=0;pendingCount=0;lastUpdatedViewports=null;updatePromise=null;tilesMap=new Map;constructor(t,s={}){this.dataSource=t,this.options={...Ph,...s},this.tilesetInitializationPromise=this.initialize()}tilesetInitializationPromise;get isReady(){return this.dataSource.isReady}get frameNumber(){return this.frameNumberValue}get tiles(){return Array.from(this.tilesMap.values())}isLoaded(){return this.frameNumberValue>0&&this.pendingCount===0&&this.selectedTiles.every(t=>t.contentAvailable||t.contentFailed)}selectedTiles=[];update(t=null){this.selectTiles(t).catch(()=>{})}destroy(){this.selectedTiles=[],this.tilesMap.clear(),this.root=null,this.cartographicCenter=null,this.boundingVolume=null,this.visibleTilesCount=0,this.pendingCount=0,this.lastUpdatedViewports=null,this.updatePromise=null}async initialize(){await this.dataSource.initialize();let t=await this.dataSource.getRootTile();this.root=this.getOrCreateTile(t,null);let s=await this.dataSource.getViewState?.();this.boundingVolume=s?.boundingVolume||this.root.boundingVolume;let r=s?.cartographicCenter||this.root.boundingVolume.center;this.cartographicCenter=new m(r),this.zoom=s?.zoom||this.estimateZoom(this.boundingVolume)}async selectTiles(t=null){return await this.tilesetInitializationPromise,t&&(this.lastUpdatedViewports=t),this.updatePromise||(this.updatePromise=new Promise((s,r)=>{setTimeout(()=>{this.doSelectTiles().then(()=>s(this.frameNumberValue)).catch(r).finally(()=>{this.updatePromise=null})},this.options.debounceTime)})),this.updatePromise}async doSelectTiles(){if(!this.root||!this.lastUpdatedViewports)return;let t=new Set(this.selectedTiles.map(a=>a.id));for(let a of this.tilesMap.values())a.clearSelection();this.frameNumberValue++;let s=Array.isArray(this.lastUpdatedViewports)?this.lastUpdatedViewports:[this.lastUpdatedViewports],r=new Map,n=new Set,i=0;for(let a of s){let c=this.getTraversalContext(a);i=await this.traverseTiles(c,r,i,n)}this.visibleTilesCount=n.size,this.selectedTiles=this.options.onTraversalComplete(Array.from(r.values()));for(let a of this.selectedTiles)this.loadTile(a).catch(()=>{});let o=new Set(this.selectedTiles.map(a=>a.id));this.haveSameIds(t,o)||this.options.onUpdate()}async traverseTiles(t,s,r,n){if(!this.root)return r;let i=r,o=[{tile:this.root,weight:this.estimateScreenRadius(this.root,t.viewport)}];for(;o.length>0;){o.sort((u,d)=>d.weight-u.weight);let a=o.shift();if(!a)break;let{tile:c,weight:h}=a;if(!this.isVisible(c,t))continue;if(n.add(c.id),!s.has(c.id)&&c.pointCount>0){if(i>0&&i+c.pointCount>this.options.pointBudget)break;s.set(c.id,c),i+=c.pointCount}if(s.has(c.id)&&c.setSelected(t.viewport.id),!this.shouldRefine(c,h))continue;let l=await this.getVisibleChildren(c,t);l.length>0&&o.push(...l)}return i}shouldRefine(t,s){return t.level<this.options.maxDepth&&Number.isFinite(s)&&s>=this.options.minimumNodePixelSize}getTraversalContext(t){let s=this.getCullingVolume(t);return{viewport:t,cullingVolume:this.shouldUseCullingVolume(t,s)?s:null}}isVisible(t,s){if(s.cullingVolume){let n=this.getCommonSpaceBoundingSphere(t.boundingVolume,s.viewport);if(n)return this.isBoundingSphereInsideCullingVolume(n,s.cullingVolume)}let r=this.getProjectedFootprint(t.boundingVolume,s.viewport);return r?this.isProjectedFootprintVisible(r,s.viewport):!1}shouldUseCullingVolume(t,s){if(!this.root||!s)return!1;let r=this.getCommonSpaceBoundingSphere(this.root.boundingVolume,t);if(!r)return!1;if(this.isBoundingSphereInsideCullingVolume(r,s))return!0;let n=this.getProjectedFootprint(this.root.boundingVolume,t);return!n||!this.isProjectedFootprintVisible(n,t)}isBoundingSphereInsideCullingVolume(t,s){return s.computeVisibilityWithPlaneMask(t,k.MASK_INDETERMINATE)!==k.MASK_OUTSIDE}isProjectedFootprintVisible(t,s){return!(t.x+t.radius<-es||t.x-t.radius>s.width+es||t.y+t.radius<-es||t.y-t.radius>s.height+es)}estimateScreenRadius(t,s){let r=this.getProjectedFootprint(t.boundingVolume,s);return r?r.radius:0}projectBounds(t,s){let r=this.getBoundingVolumeCorners(t),n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;try{for(let c of r){let[h,l]=s.project(c);!Number.isFinite(h)||!Number.isFinite(l)||(n=Math.min(n,h),i=Math.min(i,l),o=Math.max(o,h),a=Math.max(a,l))}}catch{return null}return!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(a)?null:{minX:n,minY:i,maxX:o,maxY:a}}getProjectedFootprint(t,s){let r=Number.NaN,n=Number.NaN;try{[r,n]=s.project(t.center)}catch{return null}if(!Number.isFinite(r)||!Number.isFinite(n))return null;let i=this.getBoundingVolumeCorners(t),o=0;try{for(let a of i){let[c,h]=s.project(a);!Number.isFinite(c)||!Number.isFinite(h)||(o=Math.max(o,Math.hypot(c-r,h-n)))}}catch{return null}if(o===0){let a=this.projectBounds(t,s);a&&(o=Math.max(a.maxX-a.minX,a.maxY-a.minY)/2)}return{x:r,y:n,radius:o}}async getVisibleChildren(t,s){return t.level>=this.options.maxDepth?[]:(await this.getChildren(t)).map(n=>({tile:n,weight:this.estimateScreenRadius(n,s.viewport)})).filter(n=>this.isVisible(n.tile,s))}async getChildren(t){if(t.childrenLoaded)return t.children;if(!t.childrenPromise){let s=this.dataSource.getChildren(t.header).then(r=>r.map(n=>this.getOrCreateTile(n,t))).then(r=>(t.children=r,t.childrenLoaded=!0,r));t.childrenPromise=s.finally(()=>{t.childrenPromise===s&&(t.childrenPromise=null)})}return t.childrenPromise}getOrCreateTile(t,s){let r=this.tilesMap.get(t.id);if(r)return r.header=t,s&&r.parent!==s&&(r.parent=s),r;let n=new qt(t,s);return this.tilesMap.set(t.id,n),s&&!s.children.find(i=>i.id===n.id)&&s.children.push(n),n}async loadTile(t){if(!(t.contentAvailable||t.isContentLoading||t.contentFailed)){t.isContentLoading=!0,this.pendingCount++;try{let s=await this.dataSource.loadTileContent(t.header);t.content=s,t.contentAvailable=!0,s&&this.options.onTileLoad(t)}catch(s){t.contentFailed=!0,this.options.onTileError(t,s)}finally{t.isContentLoading=!1,this.pendingCount--}}}estimateZoom(t){if(!t)return 1;let[s,r]=t.cartographicBounds,n=Math.max(Math.abs(r[0]-s[0]),1e-6);return Math.max(1,Math.round(Math.log2(360/n)))}haveSameIds(t,s){if(t.size!==s.size)return!1;for(let r of t)if(!s.has(r))return!1;return!0}getBoundingVolumeCorners(t){let[s,r]=t.cartographicBounds;return[[s[0],s[1],s[2]||0],[s[0],s[1],r[2]||0],[s[0],r[1],s[2]||0],[s[0],r[1],r[2]||0],[r[0],s[1],s[2]||0],[r[0],s[1],r[2]||0],[r[0],r[1],s[2]||0],[r[0],r[1],r[2]||0]]}getCullingVolume(t){let s=t.getFrustumPlanes?.bind(t);if(!s)return null;let r=s(),n=["left","right","bottom","top","near","far"],i=[];for(let o of n){let a=r[o];if(!a)return null;i.push(new W(a.normal,-a.distance))}return new k(i)}getCommonSpaceBoundingSphere(t,s){let r=s.projectPosition?.bind(s);if(!r)return null;let n=this.getBoundingVolumeCorners(t),i=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;try{for(let u of n){let[d,f,g=0]=r(u);!Number.isFinite(d)||!Number.isFinite(f)||!Number.isFinite(g)||(i=Math.min(i,d),o=Math.min(o,f),a=Math.min(a,g),c=Math.max(c,d),h=Math.max(h,f),l=Math.max(l,g))}}catch{return null}return!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(c)||!Number.isFinite(h)||!Number.isFinite(l)?null:new Z().fromCornerPoints([i,o,a],[c,h,l])}};return Ui(re);})();
|
|
8
8
|
return __exports__;
|
|
9
9
|
});
|