import{b3 as Et,fn as v,a as W,a5 as G,fA as j,g$ as Z,fs as tt,h0 as Rt,E as N,ab as m,h1 as et,fz as K,_ as At,a0 as Nt,l as Ft,t as nt,b5 as Mt,fO as $}from"./index.6c049565.js";import{c as ot,v as xt,b as St,j as jt}from"./Util.7142962a.js";import{s as mt,d as it,_ as w,p as st,T as H,k as F,V as rt,R as S,N as ht}from"./sphere.66d31df4.js";import{q as at}from"./QueryEngineResult.fe74257f.js";import"./plane.80965a04.js";import{m as Bt}from"./edgeProcessing.d8abd144.js";import"./mat3f64.6d32a1d7.js";import"./mat4f64.ff2a477c.js";import"./quatf64.4ae3e6f1.js";import"./quantizationUtils.4f3ed95a.js";import"./WhereClause.39c9a123.js";import"./utils.5216fcae.js";import"./generateRendererUtils.03b1f269.js";import"./projectionSupport.2b4a8796.js";import"./json.879c9adc.js";import"./utils.9592ea84.js";import"./deduplicate.b87c02b8.js";import"./InterleavedLayout.7e8c844d.js";import"./BufferView.f5101c27.js";import"./types.44c7402c.js";import"./VertexAttribute.42396f25.js";import"./enums.2d9e6f64.js";import"./VertexElementDescriptor.1fdca6da.js";function pt(o){return o?{ray:it(o.ray),c0:o.c0,c1:o.c1}:{ray:it(),c0:0,c1:Number.MAX_VALUE}}new mt(()=>pt());function C(o,t){for(let e=0;e=t[3])return!1}return!0}var dt,d;(function(o){o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o[o.BOTTOM=2]="BOTTOM",o[o.TOP=3]="TOP",o[o.NEAR=4]="NEAR",o[o.FAR=5]="FAR"})(dt||(dt={})),function(o){o[o.NEAR_BOTTOM_LEFT=0]="NEAR_BOTTOM_LEFT",o[o.NEAR_BOTTOM_RIGHT=1]="NEAR_BOTTOM_RIGHT",o[o.NEAR_TOP_RIGHT=2]="NEAR_TOP_RIGHT",o[o.NEAR_TOP_LEFT=3]="NEAR_TOP_LEFT",o[o.FAR_BOTTOM_LEFT=4]="FAR_BOTTOM_LEFT",o[o.FAR_BOTTOM_RIGHT=5]="FAR_BOTTOM_RIGHT",o[o.FAR_TOP_RIGHT=6]="FAR_TOP_RIGHT",o[o.FAR_TOP_LEFT=7]="FAR_TOP_LEFT"}(d||(d={}));d.FAR_BOTTOM_RIGHT,d.NEAR_BOTTOM_RIGHT,d.NEAR_BOTTOM_LEFT,d.FAR_BOTTOM_LEFT,d.NEAR_BOTTOM_LEFT,d.NEAR_BOTTOM_RIGHT,d.NEAR_TOP_RIGHT,d.NEAR_TOP_LEFT,d.FAR_BOTTOM_RIGHT,d.FAR_BOTTOM_LEFT,d.FAR_TOP_LEFT,d.FAR_TOP_RIGHT,d.NEAR_BOTTOM_RIGHT,d.FAR_BOTTOM_RIGHT,d.FAR_TOP_RIGHT,d.NEAR_TOP_RIGHT,d.FAR_BOTTOM_LEFT,d.NEAR_BOTTOM_LEFT,d.NEAR_TOP_LEFT,d.FAR_TOP_LEFT,d.FAR_TOP_LEFT,d.NEAR_TOP_LEFT,d.NEAR_TOP_RIGHT,d.FAR_TOP_RIGHT;var X,ct;(function(o){o[o.NUM=6]="NUM"})(X||(X={})),function(o){o[o.NUM=8]="NUM"}(ct||(ct={}));new mt(pt);class B{constructor(t,e){this._objectToBoundingSphere=t,this._maximumObjectsPerNode=10,this._maximumDepth=20,this._degenerateObjects=new Set,this._root=new c,this._objectCount=0,e&&(e.maximumObjectsPerNode!==void 0&&(this._maximumObjectsPerNode=e.maximumObjectsPerNode),e.maximumDepth!==void 0&&(this._maximumDepth=e.maximumDepth))}get bounds(){return this._root.bounds}get halfSize(){return this._root.halfSize}get root(){return this._root.node}get maximumObjectsPerNode(){return this._maximumObjectsPerNode}get maximumDepth(){return this._maximumDepth}get objectCount(){return this._objectCount}destroy(){this._degenerateObjects.clear(),c.clearPool(),J[0]=null,M.prune(),x.prune()}add(t,e=t.length){this._objectCount+=e,this._grow(t,e);const n=c.acquire();for(let i=0;i{if(!this._intersectsNode(i,s))return!1;const h=s.node;return h.terminals.forAll(r=>{this._intersectsObject(i,r)&&n(r)}),h.residents!==null&&h.residents.forAll(r=>{this._intersectsObject(i,r)&&n(r)}),!0})}forEachAlongRayWithVerticalOffset(t,e,n,i){const s=st(t,e);this._forEachNode(this._root,h=>{if(!this._intersectsNodeWithOffset(s,h,i))return!1;const r=h.node;return r.terminals.forAll(a=>{this._intersectsObjectWithOffset(s,a,i)&&n(a)}),r.residents!==null&&r.residents.forAll(a=>{this._intersectsObjectWithOffset(s,a,i)&&n(a)}),!0})}forEach(t){this._forEachNode(this._root,e=>{const n=e.node;return n.terminals.forAll(t),n.residents!==null&&n.residents.forAll(t),!0}),this._degenerateObjects.forEach(t)}forEachDegenerateObject(t){this._degenerateObjects.forEach(t)}findClosest(t,e,n,i=()=>!0,s=1/0){let h=1/0,r=1/0,a=null;const u=q(t,e),_=l=>{if(--s,!i(l))return;const O=this._objectToBoundingSphere(l);if(!C(n,O))return;const E=A(t,e,F(O)),I=E-O[3],f=E+O[3];I{if(s<=0||!C(n,l.bounds)||(G(g,u,l.halfSize),j(g,g,l.bounds),A(t,e,g)>r))return!1;const O=l.node;return O.terminals.forAll(E=>_(E)),O.residents!==null&&O.residents.forAll(E=>_(E)),!0},t,e),a}forEachInDepthRange(t,e,n,i,s,h,r){let a=-1/0,u=1/0;const _={setRange:f=>{n===B.DepthOrder.FRONT_TO_BACK?(a=Math.max(a,f.near),u=Math.min(u,f.far)):(a=Math.max(a,-f.far),u=Math.min(u,-f.near))}};_.setRange(i);const l=A(e,n,t),O=q(e,n),E=q(e,-n),I=f=>{if(!r(f))return;const R=this._objectToBoundingSphere(f),L=F(R),Y=A(e,n,L)-l,gt=Y-R[3],bt=Y+R[3];gt>u||bt{if(!C(h,f.bounds)||(G(g,O,f.halfSize),j(g,g,f.bounds),A(e,n,g)-l>u)||(G(g,E,f.halfSize),j(g,g,f.bounds),A(e,n,g)-lI(L)),R.residents!==null&&R.residents.forAll(L=>I(L)),!0},e,n)}forEachNode(t){this._forEachNode(this._root,e=>t(e.node,e.bounds,e.halfSize))}forEachNeighbor(t,e){const n=H(e),i=F(e),s=a=>{const u=this._objectToBoundingSphere(a),_=H(u),l=n+_;return!(Z(F(u),i)-l*l<=0)||t(a)};let h=!0;const r=a=>{h&&(h=s(a))};this._forEachNode(this._root,a=>{const u=H(a.bounds),_=n+u;if(Z(F(a.bounds),i)-_*_>0)return!1;const l=a.node;return l.terminals.forAll(r),h&&l.residents!==null&&l.residents.forAll(r),h}),h&&this.forEachDegenerateObject(r)}_intersectsNode(t,e){return z(e.bounds,2*-e.halfSize,p),z(e.bounds,2*e.halfSize,T),ot(t.origin,t.direction,p,T)}_intersectsNodeWithOffset(t,e,n){return z(e.bounds,2*-e.halfSize,p),z(e.bounds,2*e.halfSize,T),n.applyToMinMax(p,T),ot(t.origin,t.direction,p,T)}_intersectsObject(t,e){const n=this._objectToBoundingSphere(e);return!(n[3]>0)||rt(n,t)}_intersectsObjectWithOffset(t,e,n){const i=this._objectToBoundingSphere(e);return!(i[3]>0)||rt(n.applyToBoundingSphere(i),t)}_forEachNode(t,e){let n=c.acquire().init(t);const i=[n];for(;i.length!==0;){if(n=i.pop(),e(n)&&!n.isLeaf())for(let s=0;s=0;--r){const a=_t[r];s.node.children[a]&&h.push(c.acquire().init(s).advance(a))}c.release(s)}}_remove(t,e,n){M.clear();const i=n.advanceTo(e,(s,h)=>{M.push(s.node),M.push(h)})?n.node.terminals:n.node.residents;if(i.removeUnordered(t),i.length===0)for(let s=M.length-2;s>=0;s-=2){const h=M.data[s],r=M.data[s+1];if(!this._purge(h,r))break}}_nodeIsEmpty(t){if(t.terminals.length!==0)return!1;if(t.residents!==null)return t.residents.length===0;for(let e=0;e=0&&(t.children[e]=null),!!this._nodeIsEmpty(t)&&(t.residents===null&&(t.residents=new v({shrink:!0})),!0)}_add(t,e){e.advanceTo(this._objectToBoundingSphere(t))?e.node.terminals.push(t):(e.node.residents.push(t),e.node.residents.length>this._maximumObjectsPerNode&&e.depththis._objectToBoundingSphere(n),b),P(b[3])&&!this._fitsInsideTree(b)))if(this._nodeIsEmpty(this._root.node))w(b,this._root.bounds),this._root.halfSize=1.25*b[3];else{const n=this._rootBoundsForRootAsSubNode(b);this._placingRootViolatesMaxDepth(n)?this._rebuildTree(b,n):this._growRootAsSubNode(n),c.release(n)}}_rebuildTree(t,e){tt(k,e.bounds),k[3]=e.halfSize,lt([t,k],2,i=>i,U);const n=c.acquire().init(this._root);this._root.initFrom(null,U,1.25*U[3]),this._forEachNode(n,i=>(this.add(i.node.terminals.data,i.node.terminals.length),i.node.residents!==null&&this.add(i.node.residents.data,i.node.residents.length),!0)),c.release(n)}_placingRootViolatesMaxDepth(t){const e=Math.log(t.halfSize/this._root.halfSize)*Math.LOG2E;let n=0;return this._forEachNode(this._root,i=>(n=Math.max(n,i.depth),n+e<=this._maximumDepth)),n+e>this._maximumDepth}_rootBoundsForRootAsSubNode(t){const e=t[3],n=t;let i=-1/0;const s=this._root.bounds,h=this._root.halfSize;for(let r=0;r<3;r++){const a=s[r]-h-(n[r]-e),u=n[r]+e-(s[r]+h),_=Math.max(0,Math.ceil(a/(2*h))),l=Math.max(0,Math.ceil(u/(2*h)))+1,O=2**Math.ceil(Math.log(_+l)*Math.LOG2E);i=Math.max(i,O),y[r].min=_,y[r].max=l}for(let r=0;r<3;r++){let a=y[r].min,u=y[r].max;const _=(i-(a+u))/2;a+=Math.ceil(_),u+=Math.floor(_);const l=s[r]-h-a*h*2;V[r]=l+(u+a)*h}return V[3]=i*h*Ot,c.acquire().initFrom(null,V,i*h,0)}_growRootAsSubNode(t){const e=this._root.node;tt(b,this._root.bounds),b[3]=this._root.halfSize,this._root.init(t),t.advanceTo(b,null,!0),t.node.children=e.children,t.node.residents=e.residents,t.node.terminals=e.terminals}_shrink(){for(;;){const t=this._findShrinkIndex();if(t===-1)break;this._root.advance(t),this._root.depth=0}}_findShrinkIndex(){if(this._root.node.terminals.length!==0||this._root.isLeaf())return-1;let t=null;const e=this._root.node.children;let n=0,i=0;for(;i=e[0]-n&&t[0]<=e[0]+n&&t[1]>=e[1]-n&&t[1]<=e[1]+n&&t[2]>=e[2]-n&&t[2]<=e[2]+n}}class c{constructor(){this.bounds=S(),this.halfSize=0,this.initFrom(null,null,0,0)}init(t){return this.initFrom(t.node,t.bounds,t.halfSize,t.depth)}initFrom(t,e,n,i=this.depth){return this.node=W(t)?t:c.createEmptyNode(),W(e)&&w(e,this.bounds),this.halfSize=n,this.depth=i,this}advance(t){let e=this.node.children[t];e||(e=c.createEmptyNode(),this.node.children[t]=e),this.node=e,this.halfSize/=2,this.depth++;const n=Tt[t];return this.bounds[0]+=n[0]*this.halfSize,this.bounds[1]+=n[1]*this.halfSize,this.bounds[2]+=n[2]*this.halfSize,this.bounds[3]=this.halfSize*Ot,this}advanceTo(t,e,n=!1){for(;;){if(this.isTerminalFor(t))return e&&e(this,-1),!0;if(this.isLeaf()){if(!n)return e&&e(this,-1),!1;this.node.residents=null}const i=this._childIndex(t);e&&e(this,i),this.advance(i)}}isLeaf(){return this.node.residents!=null}isTerminalFor(t){return t[3]>this.halfSize/2}_childIndex(t){const e=this.bounds;return(e[0]n.distance-i.distance);for(let n=0;n<8;++n)e[n]=x.data[n].index}function q(o,t){let e,n=1/0;for(let i=0;i<8;++i){const s=A(o,t,ut[i]);s0}c._pool=new Et(c),function(o){var t;(t=o.DepthOrder||(o.DepthOrder={}))[t.FRONT_TO_BACK=1]="FRONT_TO_BACK",t[t.BACK_TO_FRONT=-1]="BACK_TO_FRONT"}(B||(B={}));const Tt=[m(-1,-1,-1),m(1,-1,-1),m(-1,1,-1),m(1,1,-1),m(-1,-1,1),m(1,-1,1),m(-1,1,1),m(1,1,1)],ut=[m(-1,-1,-1),m(-1,-1,1),m(-1,1,-1),m(-1,1,1),m(1,-1,-1),m(1,-1,1),m(1,1,-1),m(1,1,1)],Ot=Math.sqrt(3),J=[null];function vt(o){return J[0]=o,J}const V=S(),g=N(),p=N(),T=N(),M=new v,$t=S(),b=S(),k=S(),U=S(),y=[{min:0,max:0},{min:0,max:0},{min:0,max:0}],x=new v,_t=[0,0,0,0,0,0,0,0],ft=B,Ct=1e3;function zt(o,t,e){const n=S(),i=F(n);return et(i,i,o,.5),et(i,i,t,.5),n[3]=K(i,o),j(i,i,e),n}let Q=class{constructor(){this._idToComponent=new Map,this._components=new ft(o=>o.bounds),this._edges=new ft(o=>o.bounds),this._tmpLineSegment=xt(),this._tmpP1=N(),this._tmpP2=N(),this._tmpP3=N(),this.remoteClient=null}async fetchCandidates(o,t){await Promise.resolve(),Ft(t),await this._ensureEdgeLocations(o,t);const e=[];return this._edges.forEachNeighbor(n=>(this._addCandidates(o,n,e),e.length{if(nt(s.info)){const{id:h,uid:r}=s;e.push({id:h,uid:r})}return!0},o.bounds),!e.length)return;const n={components:e},i=await this.remoteClient.invoke("fetchAllEdgeLocations",n,Mt(t,{}));for(const s of i.components)this._setFetchEdgeLocations(s)}async add(o){const t=new D(o.id,o.bounds);return this._idToComponent.set(t.id,t),this._components.add([t]),{result:{}}}async remove(o){const t=this._idToComponent.get(o.id);if(t){const e=[];this._edges.forEachNeighbor(n=>(n.component===t&&e.push(n),!0),t.bounds),this._edges.remove(e),this._components.remove([t]),this._idToComponent.delete(t.id)}return{result:{}}}_setFetchEdgeLocations(o){const t=this._idToComponent.get(o.id);if(nt(t)||o.uid!==t.uid)return;const e=Bt.createView(o.locations),n=new Array(e.count),i=N(),s=N();for(let a=0;a