@liveroom-tech/react-immersive 6.2.1 → 6.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +23 -0
  2. package/dist/AnimationsTab-IKAAKT3P.mjs +1 -0
  3. package/dist/AnnotationsTab-NEJIXCOM.mjs +1 -0
  4. package/dist/CinematicTab-TIQXCPFE.mjs +1 -0
  5. package/dist/ConfigureTab-NYRMOFW4.mjs +6 -0
  6. package/dist/RulesTab-2U4MFYOZ.mjs +1 -0
  7. package/dist/SequencesTab-JZEE5WAM.mjs +1 -0
  8. package/dist/SequencesTab-O7USMDFP.css +1 -0
  9. package/dist/{StreamingTilesModel-6Z7SIC2J.mjs → StreamingTilesModel-IM2DDWO5.mjs} +1 -1
  10. package/dist/binding-builder.css +1 -1
  11. package/dist/binding-builder.d.mts +3 -3
  12. package/dist/binding-builder.d.ts +3 -3
  13. package/dist/binding-builder.js +45 -45
  14. package/dist/binding-builder.mjs +1 -1
  15. package/dist/chunk-37QOMZW6.mjs +1 -0
  16. package/dist/{chunk-NMRTI3NQ.mjs → chunk-3GA7JFNH.mjs} +1 -1
  17. package/dist/chunk-3I7PPFUV.mjs +1 -0
  18. package/dist/chunk-3PLML3PO.mjs +1 -0
  19. package/dist/chunk-5C4H7SRF.mjs +1 -0
  20. package/dist/chunk-CHMFH4D4.mjs +1 -0
  21. package/dist/chunk-CUDL77ZY.mjs +1 -0
  22. package/dist/{chunk-UTVFRMYW.mjs → chunk-IEKGBS46.mjs} +2 -2
  23. package/dist/chunk-LU3BQ7WG.mjs +69 -0
  24. package/dist/chunk-QZNUWZG7.mjs +50 -0
  25. package/dist/{chunk-3OCHN3CA.mjs → chunk-SOAUR4DL.mjs} +1 -1
  26. package/dist/chunk-SXN3YYD3.mjs +1 -0
  27. package/dist/chunk-TI2YXAHW.mjs +3 -0
  28. package/dist/exportSceneMesh-MSQIMBFF.mjs +1 -0
  29. package/dist/hosted.css +1 -1
  30. package/dist/hosted.d.mts +5 -3
  31. package/dist/hosted.d.ts +5 -3
  32. package/dist/hosted.js +44 -44
  33. package/dist/hosted.mjs +1 -1
  34. package/dist/index.css +1 -1
  35. package/dist/index.d.mts +8 -4
  36. package/dist/index.d.ts +8 -4
  37. package/dist/index.js +42 -42
  38. package/dist/index.mjs +1 -1
  39. package/dist/{modelFileResolver-CVmON8hg.d.mts → modelFileResolver-An1aQ0D3.d.mts} +42 -29
  40. package/dist/{modelFileResolver-CVmON8hg.d.ts → modelFileResolver-An1aQ0D3.d.ts} +42 -29
  41. package/dist/{modelViewerProps-BBnZTFO-.d.ts → modelViewerProps-BnVflYRA.d.mts} +22 -3
  42. package/dist/{modelViewerProps-CIY4nsNY.d.mts → modelViewerProps-H_K454u_.d.ts} +22 -3
  43. package/dist/{publicProps-BARVwXu7.d.ts → publicProps-AdNUI06n.d.ts} +1 -1
  44. package/dist/{publicProps-n0Yvr_Km.d.mts → publicProps-BOQBJBA_.d.mts} +1 -1
  45. package/dist/simple-model-viewer.css +1 -1
  46. package/dist/simple-model-viewer.d.mts +6 -2
  47. package/dist/simple-model-viewer.d.ts +6 -2
  48. package/dist/simple-model-viewer.js +5 -5
  49. package/dist/simple-model-viewer.mjs +1 -1
  50. package/dist/utils.d.mts +4 -4
  51. package/dist/utils.d.ts +4 -4
  52. package/dist/utils.js +15 -15
  53. package/dist/utils.mjs +1 -1
  54. package/package.json +7 -5
  55. package/dist/AnimationsTab-NUJTEMZ5.mjs +0 -1
  56. package/dist/AnnotationsTab-OHRVWRKI.mjs +0 -1
  57. package/dist/CinematicTab-IJAY2BS6.mjs +0 -1
  58. package/dist/ConfigureTab-UQRRATCY.mjs +0 -6
  59. package/dist/RulesTab-YVBZGJZX.mjs +0 -1
  60. package/dist/SequencesTab-IC5LWQ6N.css +0 -1
  61. package/dist/SequencesTab-VZKEKAUG.mjs +0 -1
  62. package/dist/chunk-25WC5KDO.mjs +0 -50
  63. package/dist/chunk-7OVEHDDE.mjs +0 -1
  64. package/dist/chunk-AL6UIGWP.mjs +0 -1
  65. package/dist/chunk-KYXJG3TX.mjs +0 -1
  66. package/dist/chunk-LD7QWHB4.mjs +0 -3
  67. package/dist/chunk-RKDATTUM.mjs +0 -1
  68. package/dist/chunk-UAZ6I25Y.mjs +0 -1
  69. package/dist/chunk-UHRJ2RBF.mjs +0 -1
  70. package/dist/chunk-YKDDNX2D.mjs +0 -69
  71. package/dist/exportSceneMesh-YJFOLFHS.mjs +0 -1
@@ -1,4 +1,4 @@
1
- import{a as fr,c as yr,g as hi,i as Mr,j as ui,k as We,l as Ge}from"./chunk-3OCHN3CA.mjs";import{d as gr,e as li,f as br,g as xr,h as vr,j as _r,k as Tr,l as wr}from"./chunk-RKDATTUM.mjs";import{a as lr,b as ai,e as hr,f as ur,g as cr,m as dr,n as si,r as pr}from"./chunk-UHRJ2RBF.mjs";import{d as yt,e as ni,g as oi,h as mr}from"./chunk-UCD76KQ6.mjs";import{a as ri}from"./chunk-JR557W27.mjs";import{useCallback as xe,useEffect as ve,useMemo as Mo,useRef as z,useState as tr}from"react";import{useFrame as So,useThree as Co}from"@react-three/fiber";import{Box3 as Ur,BoxGeometry as As,Group as Rr,Matrix4 as Br,Mesh as Ls,MeshBasicMaterial as Is,Vector3 as se}from"three";import{Euler as ds,Matrix4 as Me,MeshBasicMaterial as ps,MeshMatcapMaterial as ms,MeshNormalMaterial as gs,MeshStandardMaterial as fs,Quaternion as ys,Vector3 as He}from"three";function Pr(e){let t={};for(let[i,r]of Object.entries(e))t[r.modelObjectId??i]=i;return t}function pi(e){let t=e,i=null;for(;t;){let r=t.userData?.ri_name;if(typeof r=="string"&&r)return r;!i&&t.name&&(i=t.name),t=t.parent}return i}function Ar(e,t){return e||(t?t.modelObjectId??t.id:null)}function mi(e,t){let i=pi(e);if(!i)return null;let r=t.keyByModelObject[i]??i,a=t.objectBindings[r];return a?{key:r,binding:a}:null}function gi(e,t,i){if(!br(e))return null;let r=mi(e,t);return!r||r.binding.visible===!1||(i==="select"?r.binding.selectable:r.binding.hoverable)===!1?null:r}function Lr(e,t,i,r){for(let a of e){if(a.eventObject!==t)continue;let s=gi(a.object,i,r);if(s)return s}return null}var Re=new He,ci=new He,bs=new Me,Sr=new Me,qe=new Me,xs=new Me,bt=new Me,vs=new Me,_s=new Me,Cr=new He,Er=new He,pe=new He,di=new ys,Ts=new ds;function ws(e,t,i,r,a){let s=!!(i?.position||i?.rotation||i?.scale||i?.shear),n=!!(a&&a.factor>0&&a.radius>0);if(!s&&!n){e.matrixAutoUpdate=!0,e.position.copy(t.position),e.rotation.copy(t.rotation),e.scale.copy(t.scale),e.updateMatrix(),e.updateWorldMatrix(!0,!1);return}Sr.compose(t.position,di.setFromEuler(t.rotation),t.scale);let o=i?.rotation;qe.compose(Cr.fromArray(hi(i?.position??[0,0,0],o??[0,0,0],i?.scale??[1,1,1],i?.pivot,"XYZ",i?.shear)),di.setFromEuler(Ts.set(o?.[0]??0,o?.[1]??0,o?.[2]??0)),Er.fromArray(i?.scale??[1,1,1])),i?.shear&&qe.makeRotationFromQuaternion(di).multiply(lr(i.shear)).scale(Er).setPosition(Cr),qe.premultiply(r).multiply(xs.copy(r).invert()),e.parent?.updateWorldMatrix(!0,!1);let l=e.parent?.matrixWorld??bs;if(bt.multiplyMatrices(l,Sr).premultiply(qe),n&&a){let u=e;for(;u.parent&&!u.userData.ri_name;)u=u.parent;let c=u.userData.ri_center;Array.isArray(c)&&c.length===3?pe.fromArray(c).applyMatrix4(r).applyMatrix4(qe):pe.setFromMatrixPosition(bt),pe.sub(a.centre),pe.lengthSq()>1e-8&&(pe.normalize().multiplyScalar(a.factor*a.radius),bt.premultiply(_s.makeTranslation(pe.x,pe.y,pe.z)))}e.matrixAutoUpdate=!1,e.matrix.multiplyMatrices(vs.copy(l).invert(),bt),e.matrixWorldNeedsUpdate=!0,e.updateWorldMatrix(!1,!1)}function xt(e,t){if(!yt(e)&&!e.userData.riLogicalObject)return;let i=mi(e,t);if(!i)return;let r=Ir(e);if(r.rest??(r.rest={position:e.position.clone(),rotation:e.rotation.clone(),scale:e.scale.clone()}),t.suspendTransforms)return;if(t.placementFrame&&!e.userData.riLogicalObject){ws(e,r.rest,i.binding.transform,t.placementFrame,t.explode);return}let a=r.rest,s=i.binding.transform;s?.position?e.position.fromArray(s.position):e.position.copy(a.position),s?.rotation?e.rotation.set(s.rotation[0],s.rotation[1],s.rotation[2],a.rotation.order):e.rotation.copy(a.rotation),s?.scale?e.scale.fromArray(s.scale):e.scale.copy(a.scale),e.position.fromArray(hi(e.position.toArray(),[e.rotation.x,e.rotation.y,e.rotation.z],e.scale.toArray(),s?.pivot,a.rotation.order,s?.shear)),ai(e,s?.shear);let n=t.explode;if(n&&n.factor>0&&n.radius>0){e.updateWorldMatrix(!0,!1),ci.setFromMatrixPosition(e.matrixWorld);let o=e;for(;o.parent&&!o.userData.ri_name;)o=o.parent;let l=o.userData.ri_center;Array.isArray(l)&&l.length===3?Re.fromArray(l).applyMatrix4(e.matrixWorld).sub(n.centre):Re.copy(ci).sub(n.centre),Re.lengthSq()>1e-8&&(Re.normalize().multiplyScalar(n.factor*n.radius).add(ci),e.parent&&e.parent.worldToLocal(Re),e.position.copy(Re))}ai(e,s?.shear),e.updateWorldMatrix(!0,!1)}function Oe(e,t){e.traverse(i=>xt(i,t))}function Ir(e){var t;return(t=e.userData).riVisuals??(t.riVisuals={}),e.userData.riVisuals}function Ms(e,t,i,r){return JSON.stringify([e?.style?.material??null,t??null,i.shadingMode,i.rendererMode,r])}function Ss(e){if(e.textures){for(let t of ni){let i=e.textures[t];i&&si(i,oi(t))}e.textures=void 0}}function Cs(e,t,i){let r=e.textures??{};for(let a of ni){let s=mr(t,a),n=r[a];if(n===s)continue;let o=oi(a);n&&si(n,o),s?(dr(s,o,i),r[a]=s):delete r[a]}e.textures=Object.keys(r).length>0?r:void 0}function Es(e,t){if(t.shadingMode==="normals")return We(e,()=>new gs);if(t.shadingMode==="unlit")return We(e,i=>{let r=new ps;return r.color.copy(i.color),r.map=i.map,r.vertexColors=i.vertexColors,r.alphaMap=i.alphaMap,r.alphaTest=i.alphaTest,r.transparent=i.transparent,r.opacity=i.opacity,r.side=i.side,r});if(t.rendererMode==="matcap"){let i=pr();return We(e,r=>{let a=new ms;return a.matcap=i,a.color.copy(r.color),a.vertexColors=r.vertexColors,a.alphaMap=r.alphaMap,a.alphaTest=r.alphaTest,a.side=r.side,a})}return e}function Ps(e,t){if(!yt(e))return;let r=Ir(e);r.original??(r.original=ui(e));let a=mi(e,t);if(!a){r.original&&(e.material=r.original),e.visible=!0;return}let{key:s,binding:n}=a;e.visible=n.visible!==!1,xt(e,t);let o=t.itemMaterials?.[s]?.hex??t.itemMaterials?.[n.modelObjectId??s]?.hex,l=t.highlightOnHover!==!1&&s===t.hoveredKey,u=Ms(n,o,t,l);if(r.signature===u&&r.display){e.material=r.display;return}let c=n.style?.material;if(Cs(r,c,t.invalidate),!r.physical){let h=r.original??ui(e);if(!h)return;r.physical=We(h,m=>{let d=_r(m),p=Tr(d??new fs);return wr(p),p})}Ge(r.physical,h=>{Mr(h,c,o??c?.baseColor),l&&(h.emissive.add(hr),h.color.lerp(ur,cr)),h.needsUpdate=!0}),r.display&&r.display!==r.physical&&Ge(r.display,h=>h.dispose()),r.display=Es(r.physical,t),r.signature=u,e.material=r.display}function Dr(e,t){e.traverse(i=>Ps(i,t))}function fi(e){e.traverse(t=>{if(!yt(t))return;let i=t.userData.riVisuals;i&&(i.rest&&(t.matrixAutoUpdate=!0,t.position.copy(i.rest.position),t.rotation.copy(i.rest.rotation),t.scale.copy(i.rest.scale),t.updateMatrix()),i.original&&(t.material=i.original),i.display&&i.display!==i.physical&&Ge(i.display,r=>r.dispose()),i.physical&&Ge(i.physical,r=>r.dispose()),Ss(i),delete t.userData.riVisuals)})}var kr=new Br().makeRotationX(Math.PI/2),Or=kr.clone().invert();function Ds(e){let t=new se(e[0],e[1],e[2]),i=new se(Math.abs(e[3])+Math.abs(e[6])+Math.abs(e[9]),Math.abs(e[4])+Math.abs(e[7])+Math.abs(e[10]),Math.abs(e[5])+Math.abs(e[8])+Math.abs(e[11]));return new Ur(t.clone().sub(i),t.clone().add(i))}function Rs(e){let t=e.getCenter(new se),i=e.getSize(new se).multiplyScalar(.5);return[t.x,t.y,t.z,i.x,0,0,0,i.y,0,0,0,i.z]}var vt=class{constructor(){this.group=new Rr;this.objects=new Map;this.geometry=new As(1,1,1);this.material=new Is;this.originalBounds=new WeakMap;this.signature="";this.lastContext=null;this.lastEffective=null;this.lastDragging=!1;this.version=0;this.tileVersions=new WeakMap;this.transforms=new Map}setCatalog(t){this.group.clear(),this.objects.clear();for(let i of t){let r=new Ur(new se(...i.minimum),new se(...i.maximum)).applyMatrix4(Or),a=new Rr;a.name=i.name,a.userData.ri_name=i.name,a.userData.riLogicalObject=!0,a.userData.ri_center=r.getCenter(new se).toArray();let s=new Ls(this.geometry,this.material);s.visible=!1,s.raycast=()=>{},s.position.copy(r.getCenter(new se)),s.scale.copy(r.getSize(new se)),a.add(s),this.group.add(a),this.objects.set(i.name,a)}this.signature="",this.lastContext=null}nodesByBinding(t){let i={};for(let[r,a]of this.objects){let s=t.keyByModelObject[r]??r;t.objectBindings[s]&&(i[s]=a)}return i}sync(t,i,r=!1){if(!r&&!this.lastDragging&&t===this.lastContext&&this.lastEffective)return this.lastEffective;this.lastContext=t,this.lastDragging=r;let a={...t,suspendTransforms:!1},s=i?t.objectBindings[i]:void 0,n=s?this.objects.get(s.modelObjectId??i):void 0;r&&n&&s&&(a={...a,objectBindings:{...t.objectBindings,[i]:{...s,transform:{position:n.position.toArray(),rotation:[n.rotation.x,n.rotation.y,n.rotation.z],scale:n.scale.toArray()}}}});for(let l of this.objects.values())r&&l===n||xt(l,a);this.group.updateWorldMatrix(!0,!0);let o=[...this.objects].map(([l,u])=>`${l}:${u.matrix.elements.join(",")}`).join(";");if(o!==this.signature){this.signature=o,this.version++,this.transforms.clear();for(let[l,u]of this.objects)u.matrix.equals(new Br)||this.transforms.set(l,kr.clone().multiply(u.matrix).multiply(Or))}return this.lastEffective=a,a}updateBounds(t){if(!t)return;let i=r=>{if(this.tileVersions.get(r)!==this.version){if(r.boundingVolume.box&&this.tileVersions.get(r)!==this.version){let a=this.originalBounds.get(r);a||(a={box:[...r.boundingVolume.box],error:r.geometricError},this.originalBounds.set(r,a));let s=Ds(a.box),n=s.clone(),o=1;for(let u of r.extras?.featureIds??[]){let c=this.transforms.get(u);c&&(n.union(s.clone().applyMatrix4(c)),o=Math.max(o,c.getMaxScaleOnAxis()))}let l=Rs(n);r.boundingVolume.box=l,r.geometricError=a.error*o,r.engineData?.boundingVolume?.setObbData(l,r.engineData.transform),this.tileVersions.set(r,this.version)}r.children?.forEach(i)}};i(t)}dispose(){this.group.clear(),this.objects.clear(),this.geometry.dispose(),this.material.dispose()}};var yi=Object.freeze({factor:1,loosened:!1,tooFine:0,raisedAt:-1/0,changedAt:-1/0}),Ye=16,bi=1.25,Os=1.5,Us=1.25,Bs=500,ks=3e3,Fr=5e3,Vr=2e3,Fs=.9;function zr(e){return e.full&&(e.wanting||e.usage>1)}function Nr(e){return e.loosened?ks:Bs}function jr(e){let t=e.factor/Us;return t<=1+1e-6?1:t}function Wr(e,t){return e.factor>1&&!e.loosened&&!t.full&&!t.wanting&&t.usage<Fs&&jr(e)>e.tooFine}function Gr(e,t){let{now:i}=t,r=t.moved&&e.tooFine>0?{...e,tooFine:0}:e;if(zr(t)){if(i-r.changedAt<Nr(r))return r;let a=Math.max(r.tooFine,r.factor);return r.factor>=Ye?r.loosened&&r.tooFine===a?r:{...r,loosened:!0,tooFine:a,changedAt:i}:{factor:Math.min(Ye,r.factor*Os),loosened:!0,tooFine:a,raisedAt:i,changedAt:i}}return r.loosened&&!t.wanting?{...r,loosened:!1,changedAt:i}:Wr(r,t)&&i-r.raisedAt>=Fr&&i-r.changedAt>=Vr?{...r,factor:jr(r),changedAt:i}:r}function qr(e,t){let{now:i}=t;return zr(t)?e.factor>=Ye&&e.loosened?null:Math.max(0,Nr(e)-(i-e.changedAt)):e.loosened&&!t.wanting?0:Wr(e,t)?Math.max(0,Fr-(i-e.raisedAt),Vr-(i-e.changedAt)):null}function Qr(e){try{let t=typeof location<"u"?location.href:void 0;return new URL(e,t).origin}catch{return null}}function xi(e){if(!e)return null;let t=e.length,i=e.indexOf("?"),r=e.indexOf("#");i!==-1&&(t=Math.min(t,i)),r!==-1&&(t=Math.min(t,r));let a=e.lastIndexOf(".",t),s=e.lastIndexOf("/",t),n=e.indexOf("://");return n!==-1&&n+2===s||a===-1||a<s?null:e.substring(a+1,t)||null}var Tt,Xe=(Tt=class{static setXRSession(e){e!==this.session&&(this.flushPending(),this.session=e)}static requestAnimationFrame(e){let{session:t,pending:i}=this,r,a=()=>{i.delete(r),e()};return r=t?t.requestAnimationFrame(a):requestAnimationFrame(a),i.set(r,e),r}static cancelAnimationFrame(e){let{pending:t,session:i}=this;t.delete(e),i?i.cancelAnimationFrame(e):cancelAnimationFrame(e)}static flushPending(){this.pending.forEach((e,t)=>{e(),this.cancelAnimationFrame(t)})}},ri(Tt,"pending",new Map),ri(Tt,"session",null),Tt),Hr=2**30,Ze=class{get unloadPriorityCallback(){return this._unloadPriorityCallback}set unloadPriorityCallback(e){e.length===1?(console.warn('LRUCache: "unloadPriorityCallback" function has been changed to take two arguments.'),this._unloadPriorityCallback=(t,i)=>{let r=e(t),a=e(i);return r<a?-1:+(r>a)}):this._unloadPriorityCallback=e}constructor(){this.minSize=6e3,this.maxSize=8e3,this.minBytesSize=.3*Hr,this.maxBytesSize=.4*Hr,this.unloadPercent=.05,this.autoMarkUnused=!0,this.cachedBytes=0,this.itemSet=new Map,this.itemList=[],this.usedSet=new Set,this.callbacks=new Map,this.unloadingHandle=-1,this.bytesMap=new Map,this.loadedSet=new Set,this._unloadPriorityCallback=null;let e=this.itemSet;this.defaultPriorityCallback=t=>e.get(t)}isFull(){return this.itemSet.size>=this.maxSize||this.cachedBytes>=this.maxBytesSize}getMemoryUsage(e){return this.bytesMap.get(e)||0}setMemoryUsage(e,t){let{bytesMap:i,itemSet:r}=this;r.has(e)&&(this.cachedBytes-=i.get(e)||0,i.set(e,t),this.cachedBytes+=t)}add(e,t){let i=this.itemSet;if(i.has(e)||this.isFull())return!1;let r=this.usedSet,a=this.itemList,s=this.callbacks;return a.push(e),r.add(e),i.set(e,Date.now()),s.set(e,t),!0}has(e){return this.itemSet.has(e)}remove(e){let t=this.usedSet,i=this.itemSet,r=this.itemList,a=this.bytesMap,s=this.callbacks,n=this.loadedSet;if(i.has(e)){this.cachedBytes-=a.get(e)||0,a.delete(e),s.get(e)(e);let o=r.indexOf(e);return r.splice(o,1),t.delete(e),i.delete(e),s.delete(e),n.delete(e),!0}return!1}setLoaded(e,t){let{itemSet:i,loadedSet:r}=this;i.has(e)&&(t===!0?r.add(e):r.delete(e))}markUsed(e){let t=this.itemSet,i=this.usedSet;t.has(e)&&!i.has(e)&&(t.set(e,Date.now()),i.add(e))}markUnused(e){this.usedSet.delete(e)}markAllUnused(){this.usedSet.clear()}isUsed(e){return this.usedSet.has(e)}unloadUnusedContent(){let{unloadPercent:e,minSize:t,maxSize:i,itemList:r,itemSet:a,usedSet:s,loadedSet:n,callbacks:o,bytesMap:l,minBytesSize:u,maxBytesSize:c}=this,h=r.length-s.size,m=r.length-n.size,d=Math.max(Math.min(r.length-t,h),0),p=this.cachedBytes-u,y=this.unloadPriorityCallback||this.defaultPriorityCallback,M=!1,_=d>0&&h>0||m&&r.length>i;if(h&&this.cachedBytes>u||m&&this.cachedBytes>c||_){r.sort((w,U)=>{let O=s.has(w);if(O===s.has(U)){let V=n.has(w);return V===n.has(U)?-y(w,U):V?1:-1}else return O?1:-1});let C=Math.max(t*e,d*e),g=Math.ceil(Math.min(C,h,d)),P=Math.max(e*p,e*u),S=Math.min(P,p),v=0,L=0;for(;this.cachedBytes-L>c||r.length-v>i;){let w=r[v],U=l.get(w)||0;if(s.has(w)&&n.has(w)||this.cachedBytes-L-U<c&&r.length-v<=i)break;L+=U,v++}for(;L<S||v<g;){let w=r[v],U=l.get(w)||0;if(s.has(w)||this.cachedBytes-L-U<u&&v>=g)break;L+=U,v++}r.splice(0,v).forEach(w=>{this.cachedBytes-=l.get(w)||0,o.get(w)(w),l.delete(w),a.delete(w),o.delete(w),n.delete(w),s.delete(w)}),M=v<d||L<p&&v<h,M&&(M=v>0)}M&&(this.unloadingHandle=Xe.requestAnimationFrame(()=>this.scheduleUnload()))}scheduleUnload(){Xe.cancelAnimationFrame(this.unloadingHandle),this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.unloadUnusedContent()}))}},Vs=class extends DOMException{constructor(){super("PriorityQueue: Item removed","AbortError")}},ie=class{get running(){return this.items.length!==0||this.currJobs!==0}constructor(){this.maxJobs=6,this.items=[],this.callbacks=new Map,this.currJobs=0,this.scheduled=!1,this.autoUpdate=!0,this.priorityCallback=null,this._schedulingCallback=e=>{Xe.requestAnimationFrame(e)},this._runjobs=()=>{this.scheduled=!1,this.tryRunJobs()}}sort(){let e=this.priorityCallback,t=this.items;e!==null&&t.sort(e)}has(e){return this.callbacks.has(e)}add(e,t){let i={callback:t,reject:null,resolve:null,promise:null};return i.promise=new Promise((r,a)=>{let s=this.items,n=this.callbacks;i.resolve=r,i.reject=a,s.unshift(e),n.set(e,i),this.autoUpdate&&this.scheduleJobRun()}),i.promise}remove(e){let t=this.items,i=this.callbacks,r=t.indexOf(e);if(r!==-1){let a=i.get(e);a.promise.catch(s=>{if(s.name!=="AbortError")throw s}),a.reject(new Vs),t.splice(r,1),i.delete(e)}}removeByFilter(e){let{items:t}=this;for(let i=0;i<t.length;i++){let r=t[i];e(r)&&(this.remove(r),i--)}}tryRunJobs(){this.sort();let e=this.items,t=this.callbacks,i=this.maxJobs,r=0,a=()=>{this.currJobs--,this.autoUpdate&&this.scheduleJobRun()};for(;i>this.currJobs&&e.length>0&&r<i;){this.currJobs++,r++;let s=e.pop(),{callback:n,resolve:o,reject:l}=t.get(s);t.delete(s);let u;try{u=n(s)}catch(c){l(c),a();continue}u instanceof Promise?u.then(o).catch(l).finally(a):(o(u),a())}}flush(e){let{items:t,callbacks:i}=this,r=t.indexOf(e);if(!i.has(e))return;let{callback:a,resolve:s,reject:n}=i.get(e);i.delete(e),t.splice(r,1);let o;try{o=a(e)}catch(l){n(l);return}return o instanceof Promise?o.then(s).catch(n):s(o),o}scheduleJobRun(){this.scheduled||(this.scheduled=(this._schedulingCallback(this._runjobs),!0))}},Ct=class{get running(){for(let e of this.originQueues.values())if(e.running)return!0;return!1}get maxJobsPerOrigin(){return this._maxJobsPerOrigin}set maxJobsPerOrigin(e){this._maxJobsPerOrigin=e,this.originQueues.forEach(t=>t.maxJobs=e)}get maxJobs(){return this.maxJobsPerOrigin}set maxJobs(e){console.warn('DownloadPriorityQueue: "maxJobs" is no longer valid and limits jobs per server origin. Use "maxJobsPerOrigin", instead.'),this.maxJobsPerOrigin=e}get priorityCallback(){return this._priorityCallback}set priorityCallback(e){this._priorityCallback=e,this.originQueues.forEach(t=>t.priorityCallback=e)}constructor(){this.originQueues=new Map,this._itemQueues=new WeakMap,this._maxJobsPerOrigin=6,this._priorityCallback=null}add(e,t,i,r=null){this.originQueues.forEach((l,u)=>{l.running||this.originQueues.delete(u)});let a=e===null?null:Qr(e),s=this.originQueues.get(a);s||(s=new ie,s.maxJobs=this._maxJobsPerOrigin,s.priorityCallback=this._priorityCallback,this.originQueues.set(a,s));let n=this._itemQueues.get(t);if(n&&n!==s&&n.has(t))throw Error("DownloadPriorityQueue: Item is already queued with a different url origin.");this._itemQueues.set(t,s);let o=s.add(t,i);return r!==null&&(r.aborted?this.remove(t):r.addEventListener("abort",()=>this.remove(t),{once:!0})),o}remove(e){let t=this._itemQueues.get(e);t&&(t.remove(e),this._itemQueues.delete(e))}has(e){let t=this._itemQueues.get(e);return!!(t&&t.has(e))}};var Ee=6378137,zs=1/298.257223563,_i=6356752314245179e-9,_t={inView:!1,error:1/0,distanceFromCamera:1/0};function Et(e){return e===4||e===-1}function ne(e,t){return Pt(e)&&e.traversal.lastFrameVisited===t&&e.traversal.used}function Pt(e){return!!e.traversal}function Je(e){let{children:t}=e,i=t.length===0||Pt(t[t.length-1]),r=!e.internal.hasUnrenderableContent||Et(e.internal.loadingState);return i&&r}function Se(e){return e.traversal.unconditionallyRefine}function Qe(e,t){if(Pt(e)&&(t.ensureChildrenArePreprocessed(e),e.traversal.lastFrameVisited!==t.frameCount&&(e.traversal.wasInFrustum=e.traversal.inFrustum,e.traversal.wasSetActive=e.traversal.active,e.traversal.wasSetVisible=e.traversal.visible,e.traversal.usedLastFrame=e.traversal.used,e.traversal.lastFrameVisited=t.frameCount,e.traversal.used=!1,e.traversal.inFrustum=!1,e.traversal.isLeaf=!1,e.traversal.visible=!1,e.traversal.active=!1,e.traversal.error=1/0,e.traversal.distanceFromCamera=1/0,e.traversal.allChildrenReady=!1,e.traversal.allChildrenLoaded=!1,e.traversal.kicked=!1,e.traversal.allUsedChildrenProcessed=!1,t.calculateTileViewErrorWithPlugin(e,_t),e.traversal.inFrustum=_t.inView,e.traversal.error=_t.error,e.traversal.distanceFromCamera=_t.distanceFromCamera,e.traversal.unconditionallyRefine=e.internal.hasUnrenderableContent,!e.traversal.unconditionallyRefine))){let i=e.parent;for(;i&&i.traversal.unconditionallyRefine;)i=i.parent;i&&i.geometricError<=e.geometricError&&(e.traversal.unconditionallyRefine=!0)}}function vi(e,t,i=!1){if(Qe(e,t),i?t.markTileUsed(e):wt(e),Se(e)&&Je(e)){let r=e.children;for(let a=0,s=r.length;a<s;a++)vi(r[a],t,i)}}function $r(e,t){if(Qe(e,t),e.traversal.usedLastFrame&&(wt(e),e.traversal.wasSetActive&&(e.traversal.active=!0),(!e.traversal.active||Se(e))&&Je(e))){let i=e.children;for(let r=0,a=i.length;r<a;r++)$r(i[r],t)}}function wt(e){e.traversal.used=!0}function Ns(e,t){return!(e.traversal.error<=t.errorTarget&&!Se(e)||t.maxDepth>0&&e.internal.depth+1>=t.maxDepth||!Je(e))}function Zr(e,t){let{frameCount:i}=t,{children:r}=e;for(let a=0,s=r.length;a<s;a++){let n=r[a];ne(n,i)&&(n.traversal.active&&(n.traversal.kicked=!0,n.traversal.active=!1),Zr(n,t))}}function Yr(e){return!Se(e)&&(!e.internal.hasContent||Et(e.internal.loadingState))}function Jr(e,t){if(Qe(e,t),!e.traversal.inFrustum)return;let i=e.parent;if(i&&i.refine==="ADD"&&e.geometricError>0&&e.traversal.error*(i.geometricError/e.geometricError)<=t.errorTarget)return;if(!Ns(e,t)){wt(e);return}let r=!1,a=!1,s=e.children;for(let n=0,o=s.length;n<o;n++){let l=s[n];Jr(l,t),r||(r=ne(l,t.frameCount)),a||(a=l.traversal.inFrustum)}if(e.refine==="REPLACE"&&!a&&s.length!==0){e.traversal.inFrustum=!1,t.markTileUsed(e);for(let n=0,o=s.length;n<o;n++)vi(s[n],t,!0);return}if(wt(e),e.refine==="REPLACE"&&r&&(t.loadSiblings||t.loadAncestors))for(let n=0,o=s.length;n<o;n++)vi(s[n],t)}function Kr(e,t){let i=t.frameCount;if(!ne(e,i))return;let r=e.children,a=!1;for(let n=0,o=r.length;n<o;n++){let l=r[n];a||(a=ne(l,i))}if(!a)e.traversal.isLeaf=!0;else{for(let o=0,l=r.length;o<l;o++)Kr(r[o],t);let n=!0;for(let o=0,l=r.length;o<l;o++){let u=r[o];if(ne(u,i)){let c=!Se(u),h=!u.internal.hasContent||Et(u.internal.loadingState);c&&h||u.traversal.allChildrenLoaded||(n=!1)}}e.traversal.allChildrenLoaded=n}let s=!0;for(let n=0,o=r.length;n<o;n++){let l=r[n];ne(l,t.frameCount)&&!l.traversal.allUsedChildrenProcessed&&(s=!1)}e.traversal.allUsedChildrenProcessed=s&&Je(e)}function ea(e,t){if(!ne(e,t.frameCount))return;let i=e.children;if(e.refine==="REPLACE"&&t.loadAncestors&&!e.traversal.allChildrenLoaded&&!Se(e)&&(e.traversal.isLeaf=!0),e.traversal.isLeaf){if(!Se(e)&&(e.traversal.active=!0,Je(e)&&e.internal.hasContent&&!Et(e.internal.loadingState)))for(let a=0,s=i.length;a<s;a++)$r(i[a],t);return}let r=i.length>0;for(let a=0,s=i.length;a<s;a++){let n=i[a];ea(n,t),ne(n,t.frameCount)&&!(n.traversal.active&&Yr(n))&&!n.traversal.allChildrenReady&&(r=!1)}e.traversal.allChildrenReady=r,e.refine==="REPLACE"&&!r&&e.traversal.wasSetActive&&Yr(e)&&(e.traversal.active=!0,Zr(e,t))}function ta(e,t){Qe(e,t);let i=ne(e,t.frameCount);if(i&&(e.internal.hasUnrenderableContent&&(t.markTileUsed(e),t.queueTileForDownload(e)),e.internal.hasRenderableContent&&e.refine==="ADD"&&(e.traversal.active=!0),(e.traversal.active||e.traversal.kicked)&&e.internal.hasContent&&(t.markTileUsed(e),e.traversal.allUsedChildrenProcessed&&t.queueTileForDownload(e),e.internal.loadingState!==4&&(e.traversal.active=!1)),t.loadAncestors&&e.internal.hasContent&&(t.markTileUsed(e),t.queueTileForDownload(e)),e.internal.virtualChildCount>0&&e.internal.hasContent&&t.markTileUsed(e),e.traversal.visible=e.internal.hasRenderableContent&&e.traversal.active&&e.traversal.inFrustum&&e.internal.loadingState===4,t.stats.used++,e.traversal.inFrustum&&t.stats.inFrustum++),i||Pt(e)&&e.traversal.usedLastFrame){let r=!1,a=!1;i?(r=e.traversal.active,a=t.displayActiveTiles&&e.traversal.active||e.traversal.visible):Qe(e,t),e.internal.hasRenderableContent&&e.internal.loadingState===4?(r&&t.stats.active++,a&&t.stats.visible++,e.traversal.wasSetActive!==r&&t.invokeOnePlugin(n=>n.setTileActive&&n.setTileActive(e,r)),e.traversal.wasSetVisible!==a&&t.invokeOnePlugin(n=>n.setTileVisible&&n.setTileVisible(e,a))):e.internal.hasRenderableContent||(a=e.traversal.isLeaf,e.traversal.wasSetVisible!==a&&t.invokeOnePlugin(n=>n.setEmptyTileVisible&&n.setEmptyTileVisible(e,a))),e.traversal.visible=a,e.traversal.active=r;let s=e.children;for(let n=0,o=s.length;n<o;n++){let l=s[n];ta(l,t)}}}function js(e,t){Jr(e,t),Kr(e,t),ea(e,t),ta(e,t)}function Ws(e){let t=null;return()=>{t===null&&(t=Xe.requestAnimationFrame(()=>{t=null,e()}))}}function Gs(e,t=null,i=null){let r=[];for(r.push(e),r.push(null),r.push(0);r.length>0;){let a=r.pop(),s=r.pop(),n=r.pop();if(t&&t(n,s,a)){i&&i(n,s,a);return}let o=n.children;if(o)for(let l=o.length-1;l>=0;l--)r.push(o[l]),r.push(n),r.push(a+1);i&&i(n,s,a)}}var Xr=Symbol("PLUGIN_REGISTERED"),me={inView:!0,error:0,distance:1/0},qs=(e,t)=>{let i=e.priority||0,r=t.priority||0;return i===r?!e.traversal||!t.traversal?0:e.traversal.used===t.traversal.used?e.traversal.error===t.traversal.error?e.traversal.distanceFromCamera===t.traversal.distanceFromCamera?e.internal.depthFromRenderedParent===t.internal.depthFromRenderedParent?0:e.internal.depthFromRenderedParent>t.internal.depthFromRenderedParent?-1:1:e.traversal.distanceFromCamera>t.traversal.distanceFromCamera?-1:1:e.traversal.error>t.traversal.error?1:-1:e.traversal.used?1:-1:i>r?1:-1},Hs=(e,t)=>e.traversal.used===t.traversal.used?e.traversal.inFrustum===t.traversal.inFrustum?e.internal.hasUnrenderableContent===t.internal.hasUnrenderableContent?e.traversal.distanceFromCamera===t.traversal.distanceFromCamera?e.internal.depthFromRenderedParent===t.internal.depthFromRenderedParent?0:e.internal.depthFromRenderedParent>t.internal.depthFromRenderedParent?-1:1:e.traversal.distanceFromCamera>t.traversal.distanceFromCamera?-1:1:e.internal.hasUnrenderableContent?1:-1:e.traversal.inFrustum?1:-1:e.traversal.used?1:-1,Ys=(e,t)=>e.traversal.lastFrameVisited===t.traversal.lastFrameVisited?e.internal.depthFromRenderedParent===t.internal.depthFromRenderedParent?e.internal.loadingState===t.internal.loadingState?e.internal.hasUnrenderableContent===t.internal.hasUnrenderableContent?e.traversal.error===t.traversal.error?0:e.traversal.error>t.traversal.error?-1:1:e.internal.hasUnrenderableContent?-1:1:e.internal.loadingState>t.internal.loadingState?-1:1:e.internal.depthFromRenderedParent>t.internal.depthFromRenderedParent?1:-1:e.traversal.lastFrameVisited>t.traversal.lastFrameVisited?-1:1,Ue=(e,t)=>{let i=e.priority??1/0,r=t.priority??1/0;if(i!==r)return i>r?1:-1;if(!e.internal||!t.internal)return 0;let a=e.internal.renderer,s=t.internal.renderer,n=!a.loadAncestors,o=!s.loadAncestors;return n&&o?Hs(e,t):qs(e,t)},Ti=new Ze;Ti.unloadPriorityCallback=Ys;var $e=new Ct;$e.maxJobsPerOrigin=25,$e.priorityCallback=Ue;var Mt=new ie;Mt.maxJobs=5,Mt.priorityCallback=Ue;var St=new ie;St.maxJobs=25,St.priorityCallback=(e,t)=>{let i=e.parent,r=t.parent;return i===r?0:i?r?Ue(i,r):-1:1};var wi=class{get root(){let e=this.rootTileset;return e?e.root:null}get loadProgress(){let{stats:e,isLoading:t}=this,i=e.queued+e.downloading+e.parsing,r=e.inCacheSinceLoad+ +!!t;return r===0?1:1-i/r}get downloadQueue(){return this._downloadQueue}set downloadQueue(e){if(e instanceof ie){console.warn('TilesRenderer: "downloadQueue" is no longer valid as a PriorityQueue. Use a DownloadPriorityQueue, instead.');return}this._downloadQueue=e}constructor(e=null){this.rootLoadingState=0,this.rootTileset=null,this.rootURL=e,this.fetchOptions={},this.plugins=[],this.queuedTiles=[],this.cachedSinceLoadComplete=new Set,this.isLoading=!1,this.processedTiles=new WeakSet,this.visibleTiles=new Set,this.activeTiles=new Set,this.usedSet=new Set,this.loadingTiles=new Set,this.lruCache=Ti,this.downloadQueue=$e,this.parseQueue=Mt,this.processNodeQueue=St,this.stats={inCacheSinceLoad:0,inCache:0,queued:0,downloading:0,parsing:0,loaded:0,failed:0,inFrustum:0,used:0,active:0,visible:0,tilesProcessed:0},this.frameCount=0,this._dispatchNeedsUpdateEvent=Ws(()=>{this.dispatchEvent({type:"needs-update"})}),this.errorTarget=16,this.errorFalloff=0,this.errorFalloffDensity=2e-4,this.displayActiveTiles=!1,this.maxDepth=1/0,this.loadSiblings=!0,this.loadAncestors=!0,this.maxTilesProcessed=250}registerPlugin(e){if(e[Xr]===!0)throw Error("TilesRendererBase: A plugin can only be registered to a single tileset");let t=this.plugins,i=e.priority||0,r=t.length;for(let a=0;a<t.length;a++)if((t[a].priority||0)>i){r=a;break}t.splice(r,0,e),e[Xr]=!0,e.init&&e.init(this)}unregisterPlugin(e){let t=this.plugins;if(typeof e=="string"&&(e=this.getPluginByName(e)),t.includes(e)){let i=t.indexOf(e);return t.splice(i,1),e.dispose&&e.dispose(),!0}return!1}getPluginByName(e){return this.plugins.find(t=>t.name===e)||null}invokeOnePlugin(e){let t=[...this.plugins,this];for(let i=0;i<t.length;i++){let r=e(t[i]);if(r)return r}return null}invokeAllPlugins(e){let t=[...this.plugins,this],i=[];for(let r=0;r<t.length;r++){let a=e(t[r]);a&&i.push(a)}return i.length===0?null:Promise.all(i)}traverse(e,t,i=!0){this.root&&Gs(this.root,(r,...a)=>(i&&this.ensureChildrenArePreprocessed(r,!0),e?e(r,...a):!1),t)}getAttributions(e=[]){return this.invokeAllPlugins(t=>t!==this&&t.getAttributions&&t.getAttributions(e)),e}update(){let{lruCache:e,usedSet:t,stats:i,root:r,downloadQueue:a,parseQueue:s,processNodeQueue:n}=this;if(this.rootLoadingState===0&&(this.rootLoadingState=2,this.invokeOnePlugin(u=>u.loadRootTileset&&u.loadRootTileset()).then(u=>{let c=this.rootURL;c!==null&&this.invokeAllPlugins(h=>c=h.preprocessURL?h.preprocessURL(c,null):c),this.rootLoadingState=4,this.rootTileset=u,this.dispatchEvent({type:"needs-update"}),this.dispatchEvent({type:"load-tileset",tileset:u,url:c}),this.dispatchEvent({type:"load-root-tileset",tileset:u,url:c})}).catch(u=>{this.rootLoadingState=-1,console.error(u),this.rootTileset=null,this.dispatchEvent({type:"load-error",tile:null,error:u,url:this.rootURL})})),!r)return;let o=null;if(this.invokeAllPlugins(u=>{if(u.doTilesNeedUpdate){let c=u.doTilesNeedUpdate();o=o===null?c:!!(o||c)}}),o===!1){this.dispatchEvent({type:"update-before"}),this.dispatchEvent({type:"update-after"});return}this.dispatchEvent({type:"update-before"}),i.inFrustum=0,i.used=0,i.active=0,i.visible=0,i.tilesProcessed=0,this.frameCount++,t.forEach(u=>e.markUnused(u)),t.clear(),this.prepareForTraversal(),js(r,this),this.removeUnusedPendingTiles();let l=this.queuedTiles;l.sort(e.unloadPriorityCallback);for(let u=0,c=l.length;u<c&&!e.isFull();u++)this.requestTileContents(l[u]);l.length=0,e.scheduleUnload(),(a.running||s.running||n.running)===!1&&this.isLoading===!0&&(this.cachedSinceLoadComplete.clear(),i.inCacheSinceLoad=0,this.dispatchEvent({type:"tiles-load-end"}),this.isLoading=!1),this.dispatchEvent({type:"update-after"})}resetFailedTiles(){this.rootLoadingState===-1&&(this.rootLoadingState=0);let e=this.stats;e.failed!==0&&(this.traverse(t=>{t.internal.loadingState===-1&&(t.internal.loadingState=0)},null,!1),e.failed=0)}calculateTileViewErrorWithPlugin(e,t){this.calculateTileViewError(e,t);let{errorFalloff:i,errorFalloffDensity:r}=this;if(i>0&&Number.isFinite(t.distanceFromCamera)){let o=t.distanceFromCamera*r;t.error-=i*(1-Math.exp(-o*o))}let a=null,s=0,n=1/0;this.invokeAllPlugins(o=>{o!==this&&o.calculateTileViewError&&(me.inView=!0,me.error=0,me.distance=1/0,o.calculateTileViewError(e,me)&&(a===null&&(a=!0),a&&(a=me.inView),me.inView&&(n=Math.min(n,me.distance),s=Math.max(s,me.error))))}),t.inView&&a!==!1?(t.error=Math.max(t.error,s),t.distanceFromCamera=Math.min(t.distanceFromCamera,n)):a?(t.inView=!0,t.error=s,t.distanceFromCamera=n):t.inView=!1}dispose(){[...this.plugins].forEach(i=>{this.unregisterPlugin(i)});let e=this.lruCache,t=[];this.traverse(i=>(t.push(i),!1),null,!1);for(let i=0,r=t.length;i<r;i++)e.remove(t[i]);this.stats={queued:0,parsing:0,downloading:0,failed:0,inFrustum:0,traversed:0,used:0,active:0,visible:0},this.frameCount=0,this.loadingTiles.clear()}calculateBytesUsed(e,t){return 0}dispatchEvent(e){}addEventListener(e,t){}removeEventListener(e,t){}parseTile(e,t,i){return null}prepareForTraversal(){}disposeTile(e){e.traversal.visible&&(e.internal.hasRenderableContent?this.invokeOnePlugin(i=>i.setTileVisible&&i.setTileVisible(e,!1)):this.invokeOnePlugin(i=>i.setEmptyTileVisible&&i.setEmptyTileVisible(e,!1)),e.traversal.visible=!1),e.traversal.active&&e.internal.hasRenderableContent&&this.invokeOnePlugin(i=>i.setTileActive&&i.setTileActive(e,!1)),e.traversal.active=!1;let{scene:t}=e.engineData;t&&this.dispatchEvent({type:"dispose-model",scene:t,tile:e})}preprocessNode(e,t,i=null){if(this.processedTiles.add(e),this.stats.tilesProcessed++,e.content&&(!("uri"in e.content)&&"url"in e.content&&(e.content.uri=e.content.url,delete e.content.url),e.content.boundingVolume&&!("box"in e.content.boundingVolume||"sphere"in e.content.boundingVolume||"region"in e.content.boundingVolume)&&delete e.content.boundingVolume),e.parent=i,e.children=e.children||[],e.internal={hasContent:!1,hasRenderableContent:!1,hasUnrenderableContent:!1,loadingState:0,basePath:t,depth:-1,depthFromRenderedParent:-1,isVirtual:!1,virtualChildCount:0,renderer:this,...e.internal},e.content?.uri){let r=xi(e.content.uri),a=!!(r&&/json$/.test(r));e.internal.hasContent=!0,e.internal.hasUnrenderableContent=a,e.internal.hasRenderableContent=!a}else e.internal.hasContent=!1,e.internal.hasUnrenderableContent=!1,e.internal.hasRenderableContent=!1;i?(e.internal.depth=i.internal.depth+1,e.internal.depthFromRenderedParent=i.internal.depthFromRenderedParent+ +!!e.internal.hasRenderableContent):(e.internal.depth=0,e.internal.depthFromRenderedParent=+!!e.internal.hasRenderableContent),e.traversal={distanceFromCamera:1/0,error:1/0,inFrustum:!1,wasInFrustum:!1,isLeaf:!1,used:!1,usedLastFrame:!1,visible:!1,wasSetVisible:!1,active:!1,wasSetActive:!1,allChildrenReady:!1,allChildrenLoaded:!1,kicked:!1,allUsedChildrenProcessed:!1,lastFrameVisited:-1},i===null?e.refine=e.refine||"REPLACE":e.refine=e.refine||i.refine,e.engineData={scene:null,metadata:null,boundingVolume:null},Object.defineProperty(e,"cached",{get(){return console.warn('TilesRenderer: "tile.cached" field has been renamed to "tile.engineData".'),this.engineData},enumerable:!1,configurable:!0}),this.invokeAllPlugins(r=>{r!==this&&r.preprocessNode&&r.preprocessNode(e,t,i)})}setTileActive(e,t){t?this.activeTiles.add(e):this.activeTiles.delete(e)}setTileVisible(e,t){t?this.visibleTiles.add(e):this.visibleTiles.delete(e),this.dispatchEvent({type:"tile-visibility-change",scene:e.engineData.scene,tile:e,visible:t})}calculateTileViewError(e,t){}removeUnusedPendingTiles(){let{lruCache:e,loadingTiles:t}=this,i=[];for(let r of t)!e.isUsed(r)&&r.internal.loadingState===1&&i.push(r);for(let r=0;r<i.length;r++)e.remove(i[r])}queueTileForDownload(e){e.internal.loadingState!==0||this.lruCache.isFull()||this.queuedTiles.push(e)}markTileUsed(e){this.usedSet.add(e),this.lruCache.markUsed(e)}fetchData(e,t){return fetch(e,t)}ensureChildrenArePreprocessed(e,t=this.stats.tilesProcessed<this.maxTilesProcessed){let i=e.children;if(i.length===0||i[i.length-1].traversal)return;let r=a=>{for(let s=0,n=a.length;s<n;s++){let o=a[s];o&&!o.traversal&&this.preprocessNode(o,e.internal.basePath,e)}};t?(this.processNodeQueue.remove(e),r(i)):this.processNodeQueue.has(e)||this.processNodeQueue.add(e,a=>{r(a.children),this._dispatchNeedsUpdateEvent()})}getBytesUsed(e){let t=0;return this.invokeAllPlugins(i=>{i.calculateBytesUsed&&(t+=i.calculateBytesUsed(e,e.engineData.scene)||0)}),t}recalculateBytesUsed(e=null){let{lruCache:t,processedTiles:i}=this;e===null?t.itemSet.forEach(r=>{i.has(r)&&t.setMemoryUsage(r,this.getBytesUsed(r))}):t.setMemoryUsage(e,this.getBytesUsed(e))}preprocessTileset(e,t,i=null){let[r,a]=e.asset.version.split(".").map(n=>parseInt(n));console.assert(r<=1,"TilesRenderer: asset.version is expected to be a 1.x or a compatible version."),r===1&&a>0&&console.warn("TilesRenderer: tiles versions at 1.1 or higher have limited support. Some new extensions and features may not be supported.");let s=t.replace(/\/[^/]*$/,"");s=new URL(s,window.location.href).toString(),this.preprocessNode(e.root,s,i)}loadRootTileset(){let e=this.rootURL;return this.invokeAllPlugins(t=>e=t.preprocessURL?t.preprocessURL(e,null):e),this.invokeOnePlugin(t=>t.fetchData&&t.fetchData(e,this.fetchOptions)).then(t=>{if(!(t instanceof Response))return t;if(t.ok)return t.json();throw Error(`TilesRenderer: Failed to load tileset "${e}" with status ${t.status} : ${t.statusText}`)}).then(t=>(this.preprocessTileset(t,e),t))}requestTileContents(e){if(e.internal.loadingState!==0)return;let t=!1,i=null,r=new URL(e.content.uri,e.internal.basePath+"/").toString();this.invokeAllPlugins(m=>r=m.preprocessURL?m.preprocessURL(r,e):r);let a=this.stats,s=this.lruCache,n=this.downloadQueue,o=this.parseQueue,l=this.loadingTiles,u=xi(r),c=new AbortController,h=c.signal;if(s.add(e,m=>{c.abort(),t?m.children.length=0:this.invokeAllPlugins(d=>{d.disposeTile&&d.disposeTile(m)}),a.inCache--,this.cachedSinceLoadComplete.has(e)&&(this.cachedSinceLoadComplete.delete(e),a.inCacheSinceLoad--),m.internal.loadingState===1?a.queued--:m.internal.loadingState===2?a.downloading--:m.internal.loadingState===3?a.parsing--:m.internal.loadingState===4&&a.loaded--,m.internal.loadingState=0,o.remove(m),n.remove(m),l.delete(m)}))return this.isLoading||(this.isLoading=!0,this.dispatchEvent({type:"tiles-load-start"})),s.setMemoryUsage(e,this.getBytesUsed(e)),this.cachedSinceLoadComplete.add(e),a.inCacheSinceLoad++,a.inCache++,a.queued++,e.internal.loadingState=1,l.add(e),n.add(r,e,m=>{if(h.aborted)return Promise.resolve();e.internal.loadingState=2,a.downloading++,a.queued--;let d=this.invokeOnePlugin(p=>p.fetchData&&p.fetchData(r,{...this.fetchOptions,signal:h}));return this.dispatchEvent({type:"tile-download-start",tile:e,url:r,get uri(){return console.warn('tile-download-start event: "uri" has been renamed to "url".'),this.url}}),d}).then(m=>{if(!h.aborted){if(!(m instanceof Response))return m;if(m.ok)return u==="json"?m.json():m.arrayBuffer();throw Error(`Failed to load model with error code ${m.status}`)}}).then(m=>{if(!h.aborted)return a.downloading--,a.parsing++,e.internal.loadingState=3,o.add(e,d=>h.aborted?Promise.resolve():u==="json"&&m.root?(this.preprocessTileset(m,r,e),e.children.push(m.root),i=m,t=!0,Promise.resolve()):this.invokeOnePlugin(p=>p.parseTile&&p.parseTile(m,d,u,r,h)))}).then(()=>{if(h.aborted)return;a.parsing--,a.loaded++,e.internal.loadingState=4,l.delete(e),s.setLoaded(e,!0);let m=this.getBytesUsed(e);if(s.getMemoryUsage(e)===0&&m>0&&s.isFull()){s.remove(e);return}s.setMemoryUsage(e,m),this.dispatchEvent({type:"needs-update"}),t&&this.dispatchEvent({type:"load-tileset",tileset:i,url:r}),e.engineData.scene&&this.dispatchEvent({type:"load-model",scene:e.engineData.scene,tile:e,url:r})}).catch(m=>{h.aborted||(m.name==="AbortError"?s.remove(e):(o.remove(e),n.remove(e),e.internal.loadingState===1?a.queued--:e.internal.loadingState===2?a.downloading--:e.internal.loadingState===3?a.parsing--:e.internal.loadingState===4&&a.loaded--,a.failed++,console.error(`TilesRenderer : Failed to load tile at url "${e.content.uri}".`),console.error(m),e.internal.loadingState=-1,l.delete(e),s.setLoaded(e,!0),this.dispatchEvent({type:"load-error",tile:e,error:m,url:r})))})}};function Ce(e){if(e===null||e.byteLength<4)return"";let t;if(t=e instanceof DataView?e:new DataView(e),String.fromCharCode(t.getUint8(0))==="{")return null;let i="";for(let r=0;r<4;r++)i+=String.fromCharCode(t.getUint8(r));return i}var Xs=new TextDecoder;function ia(e){return Xs.decode(e)}function At(e){return e.replace(/[\\/][^\\/]+$/,"")+"/"}var Be=class{constructor(){this.fetchOptions={},this.workingPath=""}loadAsync(e){return fetch(e,this.fetchOptions).then(t=>{if(!t.ok)throw Error(`Failed to load file "${e}" with status ${t.status} : ${t.statusText}`);return t.arrayBuffer()}).then(t=>(this.workingPath===""&&(this.workingPath=At(e)),this.parse(t)))}resolveExternalURL(e){return new URL(e,this.workingPath).href}parse(e){throw Error("LoaderBase: Parse not implemented.")}};function Mi(e,t,i,r,a,s){let n;switch(r){case"SCALAR":n=1;break;case"VEC2":n=2;break;case"VEC3":n=3;break;case"VEC4":n=4;break;default:throw Error(`FeatureTable : Feature type not provided for "${s}".`)}let o,l=i*n;switch(a){case"BYTE":o=new Int8Array(e,t,l);break;case"UNSIGNED_BYTE":o=new Uint8Array(e,t,l);break;case"SHORT":o=new Int16Array(e,t,l);break;case"UNSIGNED_SHORT":o=new Uint16Array(e,t,l);break;case"INT":o=new Int32Array(e,t,l);break;case"UNSIGNED_INT":o=new Uint32Array(e,t,l);break;case"FLOAT":o=new Float32Array(e,t,l);break;case"DOUBLE":o=new Float64Array(e,t,l);break;default:throw Error(`FeatureTable : Feature component type not provided for "${s}".`)}return o}var Ke=class{constructor(e,t,i,r){this.buffer=e,this.binOffset=t+i,this.binLength=r;let a=null;if(i!==0){let s=new Uint8Array(e,t,i);a=JSON.parse(ia(s))}else a={};this.header=a}getKeys(){return Object.keys(this.header).filter(e=>e!=="extensions")}getData(e,t,i=null,r=null){let a=this.header;if(!(e in a))return null;let s=a[e];if(!(s instanceof Object)||Array.isArray(s))return s;{let{buffer:n,binOffset:o,binLength:l}=this,u=s.byteOffset||0,c=s.type||r,h=s.componentType||i;if("type"in s&&r&&s.type!==r)throw Error("FeatureTable: Specified type does not match expected type.");let m=o+u,d=Mi(n,m,t,c,h,e);if(m+d.byteLength>o+l)throw Error("FeatureTable: Feature data read outside binary body length.");return d}}getBuffer(e,t){let{buffer:i,binOffset:r}=this;return i.slice(r+e,r+e+t)}},Qs=class{constructor(e){this.batchTable=e;let t=e.header.extensions["3DTILES_batch_table_hierarchy"];this.classes=t.classes;for(let r of this.classes){let a=r.instances;for(let s in a)r.instances[s]=this._parseProperty(a[s],r.length,s)}if(this.instancesLength=t.instancesLength,this.classIds=this._parseProperty(t.classIds,this.instancesLength,"classIds"),t.parentCounts?this.parentCounts=this._parseProperty(t.parentCounts,this.instancesLength,"parentCounts"):this.parentCounts=Array(this.instancesLength).fill(1),t.parentIds){let r=this.parentCounts.reduce((a,s)=>a+s,0);this.parentIds=this._parseProperty(t.parentIds,r,"parentIds")}else this.parentIds=null;this.instancesIds=[];let i={};for(let r of this.classIds)i[r]=i[r]??0,this.instancesIds.push(i[r]),i[r]++}_parseProperty(e,t,i){if(Array.isArray(e))return e;{let{buffer:r,binOffset:a}=this.batchTable,s=e.byteOffset,n=e.componentType||"UNSIGNED_SHORT";return Mi(r,a+s,t,"SCALAR",n,i)}}getDataFromId(e,t={}){let i=this.parentCounts[e];if(this.parentIds&&i>0){let o=0;for(let l=0;l<e;l++)o+=this.parentCounts[l];for(let l=0;l<i;l++){let u=this.parentIds[o+l];u!==e&&this.getDataFromId(u,t)}}let r=this.classIds[e],a=this.classes[r].instances,s=this.classes[r].name,n=this.instancesIds[e];for(let o in a)t[s]=t[s]||{},t[s][o]=a[o][n];return t}},Lt=class extends Ke{constructor(e,t,i,r,a){super(e,i,r,a),this.count=t,this.extensions={};let s=this.header.extensions;s&&s["3DTILES_batch_table_hierarchy"]&&(this.extensions["3DTILES_batch_table_hierarchy"]=new Qs(this))}getDataFromId(e,t={}){if(e<0||e>=this.count)throw Error(`BatchTable: id value "${e}" out of bounds for "${this.count}" features number.`);for(let i of this.getKeys())t[i]=super.getData(i,this.count)[e];for(let i in this.extensions){let r=this.extensions[i];r.getDataFromId instanceof Function&&(t[i]=t[i]||{},r.getDataFromId(e,t[i]))}return t}getPropertyArray(e){return super.getData(e,this.count)}},Si=class extends Be{parse(e){let t=new DataView(e),i=Ce(t);console.assert(i==="b3dm");let r=t.getUint32(4,!0);console.assert(r===1);let a=t.getUint32(8,!0);console.assert(a===e.byteLength);let s=t.getUint32(12,!0),n=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),u=new Ke(e.slice(28,28+s+n),0,s,n),c=28+s+n,h=new Lt(e.slice(c,c+o+l),u.getData("BATCH_LENGTH"),0,o,l),m=c+o+l;return{version:r,featureTable:u,batchTable:h,glbBytes:new Uint8Array(e,m,a-m)}}},Ci=class extends Be{parse(e){let t=new DataView(e),i=Ce(t);console.assert(i==="i3dm");let r=t.getUint32(4,!0);console.assert(r===1);let a=t.getUint32(8,!0);console.assert(a===e.byteLength);let s=t.getUint32(12,!0),n=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),u=t.getUint32(28,!0),c=new Ke(e.slice(32,32+s+n),0,s,n),h=32+s+n,m=new Lt(e.slice(h,h+o+l),c.getData("INSTANCES_LENGTH"),0,o,l),d=h+o+l,p=new Uint8Array(e,d,a-d),y=null,M=null,_=null;if(u)y=p,M=Promise.resolve();else{let C=this.resolveExternalURL(ia(p));_=At(C),M=fetch(C,this.fetchOptions).then(g=>{if(!g.ok)throw Error(`I3DMLoaderBase : Failed to load file "${C}" with status ${g.status} : ${g.statusText}`);return g.arrayBuffer()}).then(g=>{y=new Uint8Array(g)})}return M.then(()=>({version:r,featureTable:c,batchTable:m,glbBytes:y,gltfWorkingPath:_}))}},Ei=class extends Be{parse(e){let t=new DataView(e),i=Ce(t);console.assert(i==="pnts");let r=t.getUint32(4,!0);console.assert(r===1);let a=t.getUint32(8,!0);console.assert(a===e.byteLength);let s=t.getUint32(12,!0),n=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),u=new Ke(e.slice(28,28+s+n),0,s,n),c=28+s+n,h=new Lt(e.slice(c,c+o+l),u.getData("BATCH_LENGTH")||u.getData("POINTS_LENGTH"),0,o,l);return Promise.resolve({version:r,featureTable:u,batchTable:h})}},Pi=class extends Be{parse(e){let t=new DataView(e),i=Ce(t);console.assert(i==="cmpt",'CMPTLoader: The magic bytes equal "cmpt".');let r=t.getUint32(4,!0);console.assert(r===1,'CMPTLoader: The version listed in the header is "1".');let a=t.getUint32(8,!0);console.assert(a===e.byteLength,"CMPTLoader: The contents buffer length listed in the header matches the file.");let s=t.getUint32(12,!0),n=[],o=16;for(let l=0;l<s;l++){let u=new DataView(e,o,12),c=Ce(u),h=u.getUint32(4,!0),m=u.getUint32(8,!0),d=new Uint8Array(e,o,m);n.push({type:c,buffer:d,version:h}),o+=m}return{version:r,tiles:n}}};import{Box3 as ba,BufferAttribute as Pe,BufferGeometry as $s,Clock as wl,Color as Zs,DefaultLoadingManager as zt,Euler as Js,EventDispatcher as It,Frustum as Ks,Group as Fi,InstancedMesh as en,LoadingManager as tn,MathUtils as xa,Matrix3 as rn,Matrix4 as k,Mesh as Ml,OrthographicCamera as Sl,PerspectiveCamera as Cl,Plane as an,PlaneGeometry as El,Points as sn,PointsMaterial as nn,Quaternion as va,Ray as Vi,Raycaster as Pl,ShaderMaterial as Al,Sphere as _a,Spherical as on,TextureUtils as ln,Vector2 as zi,Vector3 as E}from"three";import{GLTFLoader as Ni}from"three/addons/loaders/GLTFLoader.js";import{estimateBytesUsed as hn}from"three/addons/utils/BufferGeometryUtils.js";var ji=class extends Si{constructor(e=zt){super(),this.manager=e,this.adjustmentTransform=new k}parse(e){let t=super.parse(e),i=t.glbBytes.slice().buffer;return new Promise((r,a)=>{let s=this.manager,n=this.fetchOptions,o=s.getHandler("path.gltf")||new Ni(s);n.credentials==="include"&&n.mode==="cors"&&o.setCrossOrigin("use-credentials"),"credentials"in n&&o.setWithCredentials(n.credentials==="include"),n.headers&&o.setRequestHeader(n.headers);let l=this.workingPath;!/[\\/]$/.test(l)&&l.length&&(l+="/");let u=this.adjustmentTransform;o.parse(i,l,c=>{let{batchTable:h,featureTable:m}=t,{scene:d}=c,p=m.getData("RTC_CENTER",1,"FLOAT","VEC3");p&&(d.position.x+=p[0],d.position.y+=p[1],d.position.z+=p[2]),c.scene.updateMatrix(),c.scene.matrix.multiply(u),c.scene.matrix.decompose(c.scene.position,c.scene.quaternion,c.scene.scale),c.batchTable=h,c.featureTable=m,d.batchTable=h,d.featureTable=m,r(c)},a)})}};function un(e){let t=e>>11,i=e>>5&63,r=e&31;return[Math.round(t/31*255),Math.round(i/63*255),Math.round(r/31*255)]}var et=new zi;function cn(e,t,i=new E){et.set(e,t).divideScalar(256).multiplyScalar(2).subScalar(1),i.set(et.x,et.y,1-Math.abs(et.x)-Math.abs(et.y));let r=xa.clamp(-i.z,0,1);return i.x>=0?i.setX(i.x-r):i.setX(i.x+r),i.y>=0?i.setY(i.y-r):i.setY(i.y+r),i.normalize(),i}var ra={RGB:"color",POSITION:"position"},Wi=class extends Ei{constructor(e=zt){super(),this.manager=e}parse(e){return super.parse(e).then(async t=>{let{featureTable:i,batchTable:r}=t,a=new nn,s=i.header.extensions,n=new E,o;if(s&&s["3DTILES_draco_point_compression"]){let{byteOffset:c,byteLength:h,properties:m}=s["3DTILES_draco_point_compression"],d=this.manager.getHandler("draco.drc");if(d==null)throw Error("PNTSLoader: dracoLoader not available.");let p={};for(let _ in m)if(_ in ra&&_ in m){let C=ra[_];p[C]=m[_]}let y={attributeIDs:p,attributeTypes:{position:"Float32Array",color:"Uint8Array"},useUniqueIDs:!0},M=i.getBuffer(c,h);o=await d.decodeGeometry(M,y),o.attributes.color&&(a.vertexColors=!0)}else{let c=i.getData("POINTS_LENGTH"),h=i.getData("POSITION",c,"FLOAT","VEC3"),m=i.getData("NORMAL",c,"FLOAT","VEC3"),d=i.getData("NORMAL",c,"UNSIGNED_BYTE","VEC2"),p=i.getData("RGB",c,"UNSIGNED_BYTE","VEC3"),y=i.getData("RGBA",c,"UNSIGNED_BYTE","VEC4"),M=i.getData("RGB565",c,"UNSIGNED_SHORT","SCALAR"),_=i.getData("CONSTANT_RGBA",c,"UNSIGNED_BYTE","VEC4"),C=i.getData("POSITION_QUANTIZED",c,"UNSIGNED_SHORT","VEC3"),g=i.getData("QUANTIZED_VOLUME_SCALE",c,"FLOAT","VEC3"),P=i.getData("QUANTIZED_VOLUME_OFFSET",c,"FLOAT","VEC3");if(o=new $s,C){let S=new Float32Array(c*3);for(let v=0;v<c;v++)for(let L=0;L<3;L++){let w=3*v+L;S[w]=C[w]/65535*g[L]}n.x=P[0],n.y=P[1],n.z=P[2],o.setAttribute("position",new Pe(S,3,!1))}else o.setAttribute("position",new Pe(h,3,!1));if(m!==null)o.setAttribute("normal",new Pe(m,3,!1));else if(d!==null){let S=new Float32Array(c*3),v=new E;for(let L=0;L<c;L++){let w=d[L*2],U=d[L*2+1],O=cn(w,U,v);S[L*3]=O.x,S[L*3+1]=O.y,S[L*3+2]=O.z}o.setAttribute("normal",new Pe(S,3,!1))}if(y!==null)o.setAttribute("color",new Pe(y,4,!0)),a.vertexColors=!0,a.transparent=!0,a.depthWrite=!1;else if(p!==null)o.setAttribute("color",new Pe(p,3,!0)),a.vertexColors=!0;else if(M!==null){let S=new Uint8Array(c*3);for(let v=0;v<c;v++){let L=un(M[v]);for(let w=0;w<3;w++){let U=3*v+w;S[U]=L[w]}}o.setAttribute("color",new Pe(S,3,!0)),a.vertexColors=!0}else if(_!==null){a.color=new Zs(_[0],_[1],_[2]);let S=_[3]/255;S<1&&(a.opacity=S,a.transparent=!0,a.depthWrite=!1)}}let l=new sn(o,a);l.position.copy(n),t.scene=l,t.scene.featureTable=i,t.scene.batchTable=r;let u=i.getData("RTC_CENTER",1,"FLOAT","VEC3");return u&&(t.scene.position.x+=u[0],t.scene.position.y+=u[1],t.scene.position.z+=u[2]),t})}};function dn(e){let{x:t,y:i,z:r}=e;e.x=r,e.y=t,e.z=i}function pn(e){return-e+Math.PI/2}var aa=new on,ge=new E,j=new E,Ai=new E,Z=new k,re=new k,Li=new _a,G=new Js,sa=new E,na=new E,oa=new E,tt=new E,Dt=new Vi,mn=1e-12,gn=.1;var Gi=class{constructor(e=1,t=1,i=1){this.name="",this.radius=new E(e,t,i)}intersectRay(e,t){return Z.makeScale(...this.radius).invert(),Li.center.set(0,0,0),Li.radius=1,Dt.copy(e).applyMatrix4(Z),Dt.intersectSphere(Li,t)?(Z.makeScale(...this.radius),t.applyMatrix4(Z),t):null}getEastNorthUpFrame(e,t,i,r){return i.isMatrix4&&(r=i,i=0,console.warn('Ellipsoid: The signature for "getEastNorthUpFrame" has changed.')),this.getEastNorthUpAxes(e,t,sa,na,oa),this.getCartographicToPosition(e,t,i,tt),r.makeBasis(sa,na,oa).setPosition(tt)}getOrientedEastNorthUpFrame(e,t,i,r,a,s,n){return this.getObjectFrame(e,t,i,r,a,s,n,0)}getObjectFrame(e,t,i,r,a,s,n,o=2){return this.getEastNorthUpFrame(e,t,i,Z),G.set(a,s,-r,"ZXY"),n.makeRotationFromEuler(G).premultiply(Z),o===1?(G.set(Math.PI/2,0,0,"XYZ"),re.makeRotationFromEuler(G),n.multiply(re)):o===2&&(G.set(-Math.PI/2,0,Math.PI,"XYZ"),re.makeRotationFromEuler(G),n.multiply(re)),n}getCartographicFromObjectFrame(e,t,i=2){return i===1?(G.set(-Math.PI/2,0,0,"XYZ"),re.makeRotationFromEuler(G).premultiply(e)):i===2?(G.set(-Math.PI/2,0,Math.PI,"XYZ"),re.makeRotationFromEuler(G).premultiply(e)):re.copy(e),tt.setFromMatrixPosition(re),this.getPositionToCartographic(tt,t),this.getEastNorthUpFrame(t.lat,t.lon,0,Z).invert(),re.premultiply(Z),G.setFromRotationMatrix(re,"ZXY"),t.azimuth=-G.z,t.elevation=G.x,t.roll=G.y,t}getEastNorthUpAxes(e,t,i,r,a,s=tt){this.getCartographicToPosition(e,t,0,s),this.getCartographicToNormal(e,t,a),i.set(-s.y,s.x,0).normalize(),r.crossVectors(a,i).normalize()}getCartographicToPosition(e,t,i,r){this.getCartographicToNormal(e,t,ge);let a=this.radius;j.copy(ge),j.x*=a.x**2,j.y*=a.y**2,j.z*=a.z**2;let s=Math.sqrt(ge.dot(j));return j.divideScalar(s),r.copy(j).addScaledVector(ge,i)}getPositionToCartographic(e,t){this.getPositionToSurfacePoint(e,j),this.getPositionToNormal(j,ge);let i=Ai.subVectors(e,j);return t.lon=Math.atan2(ge.y,ge.x),t.lat=Math.asin(ge.z),t.height=Math.sign(i.dot(e))*i.length(),t}getCartographicToNormal(e,t,i){return aa.set(1,pn(e),t),i.setFromSpherical(aa).normalize(),dn(i),i}getPositionToNormal(e,t){let i=this.radius;return t.copy(e),t.x/=i.x**2,t.y/=i.y**2,t.z/=i.z**2,t.normalize(),t}getPositionToSurfacePoint(e,t){let i=this.radius,r=1/i.x**2,a=1/i.y**2,s=1/i.z**2,n=e.x*e.x*r,o=e.y*e.y*a,l=e.z*e.z*s,u=n+o+l,c=Math.sqrt(1/u),h=j.copy(e).multiplyScalar(c);if(u<gn)return isFinite(c)?t.copy(h):null;let m=Ai.set(h.x*r*2,h.y*a*2,h.z*s*2),d=(1-c)*e.length()/(.5*m.length()),p=0,y,M,_,C,g,P,S,v,L,w,U;do{d-=p,_=1/(1+d*r),C=1/(1+d*a),g=1/(1+d*s),P=_*_,S=C*C,v=g*g,L=P*_,w=S*C,U=v*g,y=n*P+o*S+l*v-1,M=n*L*r+o*w*a+l*U*s;let O=-2*M;p=y/O}while(Math.abs(y)>mn);return t.set(e.x*_,e.y*C,e.z*g)}calculateHorizonDistance(e,t){let i=this.calculateEffectiveRadius(e);return Math.sqrt(2*i*t+t**2)}calculateEffectiveRadius(e){let t=this.radius.x,i=1-this.radius.z**2/t**2,r=e*xa.DEG2RAD,a=Math.sin(r)**2;return t/Math.sqrt(1-i*a)}getPositionElevation(e){this.getPositionToSurfacePoint(e,j);let t=Ai.subVectors(e,j);return Math.sign(t.dot(e))*t.length()}closestPointToRayEstimate(e,t){return this.intersectRay(e,t)?t:(Z.makeScale(...this.radius).invert(),Dt.copy(e).applyMatrix4(Z),j.set(0,0,0),Dt.closestPointToPoint(j,t).normalize(),Z.makeScale(...this.radius),t.applyMatrix4(Z))}copy(e){return this.radius.copy(e.radius),this}clone(){return new this.constructor().copy(this)}},nt=new Gi(Ee,Ee,_i);nt.name="WGS84 Earth";var Rt=new E,ke=new E,Fe=new E,Ii=new E,Ot=new va,Ut=new E,Ve=new k,la=new k,ha=new E,ua=new k,Di=new va,Ri={};function ca(e,t,i,r){if(e=e/i*2-1,t=t/i*2-1,r.x=e,r.y=t,r.z=1-Math.abs(e)-Math.abs(t),r.z<0){let a=r.x;r.x=(1-Math.abs(r.y))*(a>=0?1:-1),r.y=(1-Math.abs(a))*(r.y>=0?1:-1)}return r.normalize(),r}var qi=class extends Ci{constructor(e=zt){super(),this.manager=e,this.adjustmentTransform=new k,this.ellipsoid=nt.clone()}resolveExternalURL(e){return this.manager.resolveURL(super.resolveExternalURL(e))}parse(e){return super.parse(e).then(t=>{let{featureTable:i,batchTable:r}=t,a=t.glbBytes.slice().buffer;return new Promise((s,n)=>{let o=this.fetchOptions,l=this.manager,u=l.getHandler("path.gltf")||new Ni(l);o.credentials==="include"&&o.mode==="cors"&&u.setCrossOrigin("use-credentials"),"credentials"in o&&u.setWithCredentials(o.credentials==="include"),o.headers&&u.setRequestHeader(o.headers);let c=t.gltfWorkingPath??this.workingPath;/[\\/]$/.test(c)||(c+="/");let h=this.adjustmentTransform;u.parse(a,c,m=>{let d=i.getData("INSTANCES_LENGTH"),p=i.getData("POSITION",d,"FLOAT","VEC3"),y=i.getData("POSITION_QUANTIZED",d,"UNSIGNED_SHORT","VEC3"),M=i.getData("QUANTIZED_VOLUME_OFFSET",1,"FLOAT","VEC3"),_=i.getData("QUANTIZED_VOLUME_SCALE",1,"FLOAT","VEC3"),C=i.getData("NORMAL_UP",d,"FLOAT","VEC3"),g=i.getData("NORMAL_RIGHT",d,"FLOAT","VEC3"),P=i.getData("NORMAL_UP_OCT32P",d,"UNSIGNED_SHORT","VEC2"),S=i.getData("NORMAL_RIGHT_OCT32P",d,"UNSIGNED_SHORT","VEC2"),v=i.getData("SCALE_NON_UNIFORM",d,"FLOAT","VEC3"),L=i.getData("SCALE",d,"FLOAT","SCALAR"),w=i.getData("RTC_CENTER",1,"FLOAT","VEC3"),U=i.getData("EAST_NORTH_UP");if(!p&&y){p=new Float32Array(d*3);for(let f=0;f<d;f++)p[f*3+0]=M[0]+y[f*3+0]/65535*_[0],p[f*3+1]=M[1]+y[f*3+1]/65535*_[1],p[f*3+2]=M[2]+y[f*3+2]/65535*_[2]}let O=new E;for(let f=0;f<d;f++)O.x+=p[f*3+0]/d,O.y+=p[f*3+1]/d,O.z+=p[f*3+2]/d;let V=[],ue=[];m.scene.updateMatrixWorld(),m.scene.traverse(f=>{if(f.isMesh){ue.push(f);let{geometry:J,material:Le}=f,Q=new en(J,Le,d);Q.position.copy(O),w&&(Q.position.x+=w[0],Q.position.y+=w[1],Q.position.z+=w[2]),V.push(Q)}});for(let f=0;f<d;f++){Ii.set(p[f*3+0]-O.x,p[f*3+1]-O.y,p[f*3+2]-O.z),Ot.identity(),C&&g?(ke.set(C[f*3+0],C[f*3+1],C[f*3+2]),Fe.set(g[f*3+0],g[f*3+1],g[f*3+2]),Rt.crossVectors(Fe,ke).normalize(),Ve.makeBasis(Fe,ke,Rt),Ot.setFromRotationMatrix(Ve)):P&&S&&(ca(P[f*2+0],P[f*2+1],65535,ke),ca(S[f*2+0],S[f*2+1],65535,Fe),Rt.crossVectors(Fe,ke).normalize(),Ve.makeBasis(Fe,ke,Rt),Ot.setFromRotationMatrix(Ve)),Ut.set(1,1,1),v&&Ut.set(v[f*3+0],v[f*3+1],v[f*3+2]),L&&Ut.multiplyScalar(L[f]);for(let J=0,Le=V.length;J<Le;J++){let Q=V[J];Di.copy(Ot),U&&(Q.updateMatrixWorld(),ha.copy(Ii).applyMatrix4(Q.matrixWorld),this.ellipsoid.getPositionToCartographic(ha,Ri),this.ellipsoid.getEastNorthUpFrame(Ri.lat,Ri.lon,ua),Di.setFromRotationMatrix(ua)),Ve.compose(Ii,Di,Ut).multiply(h);let $=ue[J];la.multiplyMatrices(Ve,$.matrixWorld),Q.setMatrixAt(f,la)}}m.scene.clear(),m.scene.add(...V),m.batchTable=r,m.featureTable=i,m.scene.batchTable=r,m.scene.featureTable=i,s(m)},n)})})}},Ta=class extends Pi{constructor(e=zt){super(),this.manager=e,this.adjustmentTransform=new k,this.ellipsoid=nt.clone()}parse(e){let t=super.parse(e),{manager:i,ellipsoid:r,adjustmentTransform:a}=this,s=[];for(let n in t.tiles){let{type:o,buffer:l}=t.tiles[n];switch(o){case"b3dm":{let u=l.slice(),c=new ji(i);c.workingPath=this.workingPath,c.fetchOptions=this.fetchOptions,c.adjustmentTransform.copy(a);let h=c.parse(u.buffer);s.push(h);break}case"pnts":{let u=l.slice(),c=new Wi(i);c.workingPath=this.workingPath,c.fetchOptions=this.fetchOptions;let h=c.parse(u.buffer);s.push(h);break}case"i3dm":{let u=l.slice(),c=new qi(i);c.workingPath=this.workingPath,c.fetchOptions=this.fetchOptions,c.ellipsoid.copy(r),c.adjustmentTransform.copy(a);let h=c.parse(u.buffer);s.push(h);break}}}return Promise.all(s).then(n=>{let o=new Fi;return n.forEach(l=>{o.add(l.scene)}),{tiles:n,scene:o}})}},it=new k,fn=class extends Fi{constructor(e){super(),this.isTilesGroup=!0,this.name="TilesRenderer.TilesGroup",this.tilesRenderer=e,this.matrixWorldInverse=new k}raycast(e,t){return this.tilesRenderer.raycast(e,t),!1}updateMatrixWorld(e){if(this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldNeedsUpdate||e){this.parent===null?it.copy(this.matrix):it.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1;let t=it.elements,i=this.matrixWorld.elements,r=!1;for(let a=0;a<16;a++){let s=t[a],n=i[a];if(Math.abs(s-n)>2**-52){r=!0;break}}if(r){this.matrixWorld.copy(it),this.matrixWorldInverse.copy(it).invert();let a=this.children;for(let l=0,u=a.length;l<u;l++)a[l].updateMatrixWorld();let{tilesRenderer:s}=this,{activeTiles:n,visibleTiles:o}=s;n.forEach(l=>{o.has(l)||l.engineData.scene.updateMatrixWorld(!0)})}}}updateWorldMatrix(e,t){this.parent&&e&&this.parent.updateWorldMatrix(e,!1),this.updateMatrixWorld(!0)}},yn=new Vi;function bn(e,t,i,r){let{scene:a}=e.engineData;i.invokeOnePlugin(s=>s.raycastTile&&s.raycastTile(e,a,t,r))||t.intersectObject(a,!0,r)}function xn(e){return"traversal"in e}function wa(e,t,i,r,a=null){if(!xn(t))return;let{group:s,activeTiles:n}=e,{boundingVolume:o}=t.engineData;if(a===null&&(a=yn,a.copy(i.ray).applyMatrix4(s.matrixWorldInverse)),!t.traversal.used||!o.intersectsRay(a))return;n.has(t)&&bn(t,i,e,r);let l=t.children;for(let u=0,c=l.length;u<c;u++)wa(e,l[u],i,r,a)}var Bt=new E,kt=new E,q=new E,Ft=new Vi,Bi=class{constructor(e=new ba,t=new k){this.box=e.clone(),this.transform=t.clone(),this.inverseTransform=new k,this.points=Array(8).fill().map(()=>new E),this.planes=[,,,,,,].fill().map(()=>new an)}copy(e){return this.box.copy(e.box),this.transform.copy(e.transform),this.update(),this}clone(){return new this.constructor().copy(this)}clampPoint(e,t){return t.copy(e).applyMatrix4(this.inverseTransform).clamp(this.box.min,this.box.max).applyMatrix4(this.transform)}distanceToPoint(e){return this.clampPoint(e,q).distanceTo(e)}containsPoint(e){return q.copy(e).applyMatrix4(this.inverseTransform),this.box.containsPoint(q)}intersectsRay(e){return Ft.copy(e).applyMatrix4(this.inverseTransform),Ft.intersectsBox(this.box)}intersectRay(e,t){return Ft.copy(e).applyMatrix4(this.inverseTransform),Ft.intersectBox(this.box,t)?(t.applyMatrix4(this.transform),t):null}update(){let{points:e,inverseTransform:t,transform:i,box:r}=this;t.copy(i).invert();let{min:a,max:s}=r,n=0;for(let o=-1;o<=1;o+=2)for(let l=-1;l<=1;l+=2)for(let u=-1;u<=1;u+=2)e[n].set(o<0?a.x:s.x,l<0?a.y:s.y,u<0?a.z:s.z).applyMatrix4(i),n++;this.updatePlanes()}updatePlanes(){Bt.copy(this.box.min).applyMatrix4(this.transform),kt.copy(this.box.max).applyMatrix4(this.transform),q.set(0,0,1).transformDirection(this.transform),this.planes[0].setFromNormalAndCoplanarPoint(q,Bt),this.planes[1].setFromNormalAndCoplanarPoint(q,kt).negate(),q.set(0,1,0).transformDirection(this.transform),this.planes[2].setFromNormalAndCoplanarPoint(q,Bt),this.planes[3].setFromNormalAndCoplanarPoint(q,kt).negate(),q.set(1,0,0).transformDirection(this.transform),this.planes[4].setFromNormalAndCoplanarPoint(q,Bt),this.planes[5].setFromNormalAndCoplanarPoint(q,kt).negate()}intersectsSphere(e){return this.clampPoint(e.center,q),q.distanceToSquared(e.center)<=e.radius*e.radius}intersectsFrustum(e){return this._intersectsPlaneShape(e.planes,e.points)}intersectsOBB(e){return this._intersectsPlaneShape(e.planes,e.points)}_intersectsPlaneShape(e,t){let i=this.points,r=this.planes;for(let a=0;a<6;a++){let s=e[a],n=-1/0;for(let o=0;o<8;o++){let l=i[o],u=s.distanceToPoint(l);n=n<u?u:n}if(n<0)return!1}for(let a=0;a<6;a++){let s=r[a],n=-1/0;for(let o=0;o<8;o++){let l=t[o],u=s.distanceToPoint(l);n=n<u?u:n}if(n<0)return!1}return!0}},st=Math.PI,Oi=st/2,rt=new E,Ae=new E,K=new E,T=new E,W=new k,vn=new ba,da=new k;function fe(e,t){t.radius=Math.max(t.radius,e.distanceToSquared(t.center))}function pa(e){return e.x!==e.y}var Ma=class extends Gi{constructor(e=1,t=1,i=1,r=-Oi,a=Oi,s=0,n=2*st,o=0,l=0){super(e,t,i),this.latStart=r,this.latEnd=a,this.lonStart=s,this.lonEnd=n,this.heightStart=o,this.heightEnd=l}getBoundingBox(e,t){pa(this.radius)&&console.warn("EllipsoidRegion: Triaxial ellipsoids are not supported.");let{latStart:i,latEnd:r,lonStart:a,lonEnd:s,heightStart:n,heightEnd:o}=this,l=(i+r)*.5,u=(a+s)*.5,c=i>0,h=r<0,m;m=c?i:h?r:0;let{min:d,max:p}=e;d.setScalar(1/0),p.setScalar(-1/0),s-a<=st?(this.getCartographicToNormal(l,u,K),Ae.set(0,0,1),rt.crossVectors(Ae,K).normalize(),Ae.crossVectors(K,rt).normalize(),t.makeBasis(rt,Ae,K),W.copy(t).invert(),this.getCartographicToPosition(m,a,o,T).applyMatrix4(W),p.x=Math.abs(T.x),d.x=-p.x,this.getCartographicToPosition(r,a,o,T).applyMatrix4(W),p.y=T.y,this.getCartographicToPosition(r,u,o,T).applyMatrix4(W),p.y=Math.max(T.y,p.y),this.getCartographicToPosition(i,a,o,T).applyMatrix4(W),d.y=T.y,this.getCartographicToPosition(i,u,o,T).applyMatrix4(W),d.y=Math.min(T.y,d.y),this.getCartographicToPosition(l,u,o,T).applyMatrix4(W),p.z=T.z,this.getCartographicToPosition(i,a,n,T).applyMatrix4(W),d.z=T.z,this.getCartographicToPosition(r,a,n,T).applyMatrix4(W),d.z=Math.min(T.z,d.z)):(this.getCartographicToPosition(m,u,o,K),K.z=0,K.length()<1e-10?K.set(1,0,0):K.normalize(),Ae.set(0,0,1),rt.crossVectors(K,Ae).normalize(),t.makeBasis(rt,Ae,K),W.copy(t).invert(),this.getCartographicToPosition(m,u+Oi,o,T).applyMatrix4(W),p.x=Math.abs(T.x),d.x=-p.x,this.getCartographicToPosition(r,0,h?n:o,T).applyMatrix4(W),p.y=T.y,this.getCartographicToPosition(i,0,c?n:o,T).applyMatrix4(W),d.y=T.y,this.getCartographicToPosition(m,u,o,T).applyMatrix4(W),p.z=T.z,this.getCartographicToPosition(m,s,o,T).applyMatrix4(W),d.z=T.z),e.getCenter(T),e.min.sub(T).multiplyScalar(1.0000000000001),e.max.sub(T).multiplyScalar(1.0000000000001),T.applyMatrix4(t),t.setPosition(T)}getBoundingSphere(e){pa(this.radius)&&console.warn("EllipsoidRegion: Triaxial ellipsoids are not supported."),this.getBoundingBox(vn,da),e.center.setFromMatrixPosition(da),e.radius=0;let{latStart:t,latEnd:i,lonStart:r,lonEnd:a,heightStart:s,heightEnd:n}=this,o=(t+i)*.5,l=(r+a)*.5,u=t>0,c=i<0,h;h=u?t:c?i:0,this.getCartographicToPosition(h,r,n,T),fe(T,e),this.getCartographicToPosition(i,r,n,T),fe(T,e),this.getCartographicToPosition(i,l,n,T),fe(T,e),this.getCartographicToPosition(t,r,n,T),fe(T,e),this.getCartographicToPosition(t,l,n,T),fe(T,e),this.getCartographicToPosition(o,l,n,T),fe(T,e),this.getCartographicToPosition(t,r,s,T),fe(T,e),a-r>st&&(this.getCartographicToPosition(h,l+st,n,T),fe(T,e)),e.radius=Math.sqrt(e.radius)*1.0000000000001}},oe=new E,le=new E,he=new E,ma=new E,ga=new E,_n=class{constructor(){this.sphere=null,this.obb=null,this.region=null,this.regionObb=null}intersectsRay(e){let t=this.sphere,i=this.obb||this.regionObb;return!(t&&!e.intersectsSphere(t)||i&&!i.intersectsRay(e))}intersectRay(e,t=null){let i=this.sphere,r=this.obb||this.regionObb,a=-1/0,s=-1/0;i&&e.intersectSphere(i,ma)&&(a=i.containsPoint(e.origin)?0:e.origin.distanceToSquared(ma)),r&&r.intersectRay(e,ga)&&(s=r.containsPoint(e.origin)?0:e.origin.distanceToSquared(ga));let n=Math.max(a,s);return n===-1/0?null:(e.at(Math.sqrt(n),t),t)}distanceToPoint(e){let t=this.sphere,i=this.obb||this.regionObb,r=-1/0,a=-1/0;return t&&(r=Math.max(t.distanceToPoint(e),0)),i&&(a=i.distanceToPoint(e)),r>a?r:a}intersectsFrustum(e){let t=this.obb||this.regionObb,i=this.sphere;return i&&!e.intersectsSphere(i)||t&&!t.intersectsFrustum(e)?!1:!!(i||t)}intersectsSphere(e){let t=this.obb||this.regionObb,i=this.sphere;return i&&!i.intersectsSphere(e)||t&&!t.intersectsSphere(e)?!1:!!(i||t)}intersectsOBB(e){let t=this.obb||this.regionObb,i=this.sphere;return i&&!e.intersectsSphere(i)||t&&!t.intersectsOBB(e)?!1:!!(i||t)}getOBB(e,t){let i=this.obb||this.regionObb;i?(e.copy(i.box),t.copy(i.transform)):(this.getAABB(e),t.identity())}getAABB(e){if(this.sphere)this.sphere.getBoundingBox(e);else{let t=this.obb||this.regionObb;e.copy(t.box).applyMatrix4(t.transform)}}getSphere(e){if(this.sphere)e.copy(this.sphere);else if(this.region)this.region.getBoundingSphere(e);else{let t=this.obb||this.regionObb;t.box.getBoundingSphere(e),e.applyMatrix4(t.transform)}}setObbData(e,t){let i=new Bi;oe.set(e[3],e[4],e[5]),le.set(e[6],e[7],e[8]),he.set(e[9],e[10],e[11]);let r=oe.length(),a=le.length(),s=he.length();oe.normalize(),le.normalize(),he.normalize(),r===0&&oe.crossVectors(le,he),a===0&&le.crossVectors(oe,he),s===0&&he.crossVectors(oe,le),i.transform.set(oe.x,le.x,he.x,e[0],oe.y,le.y,he.y,e[1],oe.z,le.z,he.z,e[2],0,0,0,1).premultiply(t),i.box.min.set(-r,-a,-s),i.box.max.set(r,a,s),i.update(),this.obb=i}setSphereData(e,t,i,r,a){let s=new _a;s.center.set(e,t,i),s.radius=r,s.applyMatrix4(a),this.sphere=s}setRegionData(e,t,i,r,a,s,n){let o=new Ma(...e.radius,i,a,t,r,s,n),l=new Bi;o.getBoundingBox(l.box,l.transform),l.update(),this.region=o,this.regionObb=l}},Tn=new rn;function wn(e,t,i,r){let a=Tn.set(e.normal.x,e.normal.y,e.normal.z,t.normal.x,t.normal.y,t.normal.z,i.normal.x,i.normal.y,i.normal.z);return r.set(-e.constant,-t.constant,-i.constant),r.applyMatrix3(a.invert()),r}var Mn=class extends Ks{constructor(){super(),this.points=Array(8).fill().map(()=>new E)}setFromProjectionMatrix(...e){return super.setFromProjectionMatrix(...e),this.calculateFrustumPoints(),this}calculateFrustumPoints(){let{planes:e,points:t}=this;[[e[0],e[3],e[4]],[e[1],e[3],e[4]],[e[0],e[2],e[4]],[e[1],e[2],e[4]],[e[0],e[3],e[5]],[e[1],e[3],e[5]],[e[0],e[2],e[5]],[e[1],e[2],e[5]]].forEach((i,r)=>{wn(i[0],i[1],i[2],t[r])})}};var ki=0;function fa(e,t,i,r){try{return ln.getByteLength(e,t,i,r)}catch{return ki}}function Sn(e){if(!e)return 0;if(e.isExternalTexture)return e.userData?.byteLength??ki;let{format:t,type:i,image:r,mipmaps:a}=e;if(e.isCompressedTexture&&Array.isArray(a)&&a.length>0){let n=0;for(let o of a)o?.data?.byteLength?n+=o.data.byteLength:n+=fa(o.width,o.height,t,i);return n}if(!r)return ki;let s=fa(r.width,r.height,t,i);return s*=e.generateMipmaps?4/3:1,s}function Cn(e){let t=new Set,i=0;return e.traverse(r=>{if(r.geometry&&!t.has(r.geometry)&&(i+=hn(r.geometry),t.add(r.geometry)),r.material){let a=r.material;for(let s in a){let n=a[s];n&&n.isTexture&&!t.has(n)&&(i+=Sn(n),t.add(n))}}}),i}var Sa=Symbol("INITIAL_FRUSTUM_CULLED"),Vt=new k,at=new E,Ui=new zi,En=new E(1,0,0),Pn=new E(0,1,0),An=()=>null;function ya(e,t){e.traverse(i=>{i.frustumCulled=i[Sa]&&t})}var Hi=class extends wi{get autoDisableRendererCulling(){return this._autoDisableRendererCulling}set autoDisableRendererCulling(e){this._autoDisableRendererCulling!==e&&(super._autoDisableRendererCulling=e,this.forEachLoadedModel(t=>{ya(t,!e)}))}constructor(...e){super(...e),this.accelerateRaycast=!0,this.group=new fn(this),this.ellipsoid=nt.clone(),this.cameras=[],this.cameraMap=new Map,this.cameraInfo=[],this._upRotationMatrix=new k,this._bytesUsed=new WeakMap,this._autoDisableRendererCulling=!0,this.manager=new tn,this._listeners={}}addEventListener(e,t){It.prototype.addEventListener.call(this,e,t)}hasEventListener(e,t){return It.prototype.hasEventListener.call(this,e,t)}removeEventListener(e,t){It.prototype.removeEventListener.call(this,e,t)}dispatchEvent(e){It.prototype.dispatchEvent.call(this,e)}getBoundingBox(e){if(!this.root)return!1;let t=this.root.engineData.boundingVolume;return t?(t.getAABB(e),!0):!1}getOrientedBoundingBox(e,t){if(!this.root)return!1;let i=this.root.engineData.boundingVolume;return i?(i.getOBB(e,t),!0):!1}getBoundingSphere(e){if(!this.root)return!1;let t=this.root.engineData.boundingVolume;return t?(t.getSphere(e),!0):!1}forEachLoadedModel(e){this.traverse(t=>{let i=t.engineData&&t.engineData.scene;i&&e(i,t)},null,!1)}raycast(e,t){if(this.root)if(this.accelerateRaycast)wa(this,this.root,e,t);else{let i=e.firstHitOnly?[]:t;for(let r of this.activeTiles){let{scene:a}=r.engineData;this.invokeOnePlugin(s=>s.raycastTile&&s.raycastTile(r,a,e,i))||e.intersectObject(a,!0,i)}e.firstHitOnly&&i.length>0&&(i.sort((r,a)=>r.distance-a.distance),t.push(i[0]))}}hasCamera(e){return this.cameraMap.has(e)}setCamera(e){let t=this.cameras,i=this.cameraMap;return i.has(e)?!1:(i.set(e,new zi),t.push(e),this.dispatchEvent({type:"add-camera",camera:e}),!0)}setResolution(e,t,i){let r=this.cameraMap;if(!r.has(e))return!1;let a=t.isVector2?t.x:t,s=t.isVector2?t.y:i,n=r.get(e);return(n.width!==a||n.height!==s)&&(n.set(a,s),this.dispatchEvent({type:"camera-resolution-change"})),!0}getResolution(e,t){let i=this.cameraMap.get(e);return i?t.copy(i):null}setResolutionFromRenderer(e,t){return t.getSize(Ui),this.setResolution(e,Ui.x,Ui.y)}deleteCamera(e){let t=this.cameras,i=this.cameraMap;if(i.has(e)){let r=t.indexOf(e);return t.splice(r,1),i.delete(e),this.dispatchEvent({type:"delete-camera",camera:e}),!0}return!1}loadRootTileset(...e){return super.loadRootTileset(...e).then(t=>{let{asset:i,extensions:r={}}=t;switch((i&&i.gltfUpAxis||"y").toLowerCase()){case"x":this._upRotationMatrix.makeRotationAxis(Pn,-Math.PI/2);break;case"y":this._upRotationMatrix.makeRotationAxis(En,Math.PI/2);break}if("3DTILES_ellipsoid"in r){let a=r["3DTILES_ellipsoid"],{ellipsoid:s}=this;s.name=a.body,a.radii?s.radius.set(...a.radii):s.radius.set(1,1,1)}return t})}prepareForTraversal(){let e=this.group,t=this.cameras,i=this.cameraMap,r=this.cameraInfo;for(;r.length>t.length;)r.pop();for(;r.length<t.length;)r.push({frustum:new Mn,isOrthographic:!1,sseDenominator:-1,position:new E,invScale:-1,pixelSize:0});at.setFromMatrixScale(e.matrixWorldInverse),Math.abs(Math.max(at.x-at.y,at.x-at.z))>1e-6&&console.warn("ThreeTilesRenderer : Non uniform scale used for tile which may cause issues when calculating screen space error.");for(let a=0,s=r.length;a<s;a++){let n=t[a],o=r[a],l=o.frustum,u=o.position,c=i.get(n);(c.width===0||c.height===0)&&console.warn("TilesRenderer: resolution for camera error calculation is not set.");let h=n.projectionMatrix.elements;if(o.isOrthographic=h[15]===1,o.isOrthographic){let m=2/h[0],d=2/h[5];o.pixelSize=Math.max(d/c.height,m/c.width)}else o.sseDenominator=2/h[5]/c.height;Vt.copy(e.matrixWorld),Vt.premultiply(n.matrixWorldInverse),Vt.premultiply(n.projectionMatrix),l.setFromProjectionMatrix(Vt,n.coordinateSystem,n.reversedDepth),u.set(0,0,0),u.applyMatrix4(n.matrixWorld),u.applyMatrix4(e.matrixWorldInverse)}}update(){if(super.update(),this.cameras.length===0&&this.root){let e=!1;this.invokeAllPlugins(t=>e||(e=!!(t!==this&&t.calculateTileViewError))),e===!1&&console.warn("TilesRenderer: no cameras defined. Cannot update 3d tiles.")}}preprocessNode(e,t,i=null){super.preprocessNode(e,t,i);let r=new k;if(e.transform){let n=e.transform;for(let o=0;o<16;o++)r.elements[o]=n[o]}i&&r.premultiply(i.engineData.transform);let a=new k().copy(r).invert(),s=new _n;"sphere"in e.boundingVolume&&s.setSphereData(...e.boundingVolume.sphere,r),"box"in e.boundingVolume&&s.setObbData(e.boundingVolume.box,r),"region"in e.boundingVolume&&s.setRegionData(this.ellipsoid,...e.boundingVolume.region),e.engineData.transform=r,e.engineData.transformInverse=a,e.engineData.boundingVolume=s,e.engineData.geometry=null,e.engineData.materials=null,e.engineData.textures=null,e.toJSON=An}async parseTile(e,t,i,r,a){let s=t.engineData,n=At(r),o=this.fetchOptions,l=this.manager,u=null,c=s.transform,h=this._upRotationMatrix,m=(Ce(e)||i).toLowerCase();switch(m){case"b3dm":{let g=new ji(l);g.workingPath=n,g.fetchOptions=o,g.adjustmentTransform.copy(h),u=g.parse(e);break}case"pnts":{let g=new Wi(l);g.workingPath=n,g.fetchOptions=o,u=g.parse(e);break}case"i3dm":{let g=new qi(l);g.workingPath=n,g.fetchOptions=o,g.adjustmentTransform.copy(h),g.ellipsoid.copy(this.ellipsoid),u=g.parse(e);break}case"cmpt":{let g=new Ta(l);g.workingPath=n,g.fetchOptions=o,g.adjustmentTransform.copy(h),g.ellipsoid.copy(this.ellipsoid),u=g.parse(e).then(P=>P.scene);break}case"gltf":case"glb":{let g=l.getHandler("path.gltf")||l.getHandler("path.glb")||new Ni(l);g.setWithCredentials(o.credentials==="include"),g.setRequestHeader(o.headers||{}),o.credentials==="include"&&o.mode==="cors"&&g.setCrossOrigin("use-credentials");let P=g.resourcePath||g.path||n;!/[\\/]$/.test(P)&&P.length&&(P+="/"),u=g.parseAsync(e,P).then(S=>{S.scene=S.scene||new Fi;let{scene:v}=S;return v.updateMatrix(),v.matrix.multiply(h).decompose(v.position,v.quaternion,v.scale),S});break}default:u=this.invokeOnePlugin(g=>g.parseToMesh&&g.parseToMesh(e,t,i,r,a));break}let d=await u;if(d===null)throw Error(`TilesRenderer: Content type "${m}" not supported.`);let p,y;d.isObject3D?(p=d,y=null):(p=d.scene,y=d),p.updateMatrix(),p.matrix.premultiply(c),p.matrix.decompose(p.position,p.quaternion,p.scale),await this.invokeAllPlugins(g=>g.processTileModel&&g.processTileModel(p,t)),p.traverse(g=>{g[Sa]=g.frustumCulled,g.userData.tile=t}),ya(p,!this.autoDisableRendererCulling);let M=[],_=[],C=[];if(p.traverse(g=>{if(g.geometry&&_.push(g.geometry),g.material){let P=g.material;M.push(g.material);for(let S in P){let v=P[S];v&&v.isTexture&&C.push(v)}}}),a.aborted){for(let g=0,P=C.length;g<P;g++){let S=C[g];S.image instanceof ImageBitmap&&S.image.close(),S.dispose()}return}s.materials=M,s.geometry=_,s.textures=C,s.scene=p,s.metadata=y}disposeTile(e){super.disposeTile(e);let t=e.engineData;if(t.scene){let i=t.materials,r=t.geometry,a=t.textures,s=t.scene.parent;t.scene.traverse(n=>{n.userData.meshFeatures&&n.userData.meshFeatures.dispose(),n.userData.structuralMetadata&&n.userData.structuralMetadata.dispose()});for(let n=0,o=r.length;n<o;n++)r[n].dispose();for(let n=0,o=i.length;n<o;n++)i[n].dispose();for(let n=0,o=a.length;n<o;n++){let l=a[n];l.image instanceof ImageBitmap&&l.image.close(),l.dispose()}s&&s.remove(t.scene),t.scene=null,t.materials=null,t.textures=null,t.geometry=null,t.metadata=null}}setTileActive(e,t){super.setTileActive(e,t);let i=e.engineData.scene;i&&(t?(i.parent=this.group,i.updateMatrixWorld(!0)):i.parent=null)}setTileVisible(e,t){let i=e.engineData.scene,{activeTiles:r,group:a}=this;i&&(t?a.add(i):(a.remove(i),r.has(e)&&(i.parent=a))),super.setTileVisible(e,t)}calculateBytesUsed(e,t){let i=this._bytesUsed;return!i.has(e)&&t&&i.set(e,Cn(t)),i.get(e)??null}calculateTileViewError(e,t){let i=e.engineData,r=this.cameras,a=this.cameraInfo,s=i.boundingVolume,n=!1,o=0,l=1/0,u=0,c=1/0;for(let h=0,m=r.length;h<m;h++){let d=a[h],p,y;if(d.isOrthographic){let _=d.pixelSize;p=e.geometricError/_,y=1/0}else{let _=d.sseDenominator;y=s.distanceToPoint(d.position),p=y===0?1/0:e.geometricError/(y*_)}let M=a[h].frustum;s.intersectsFrustum(M)&&(n=!0,o=Math.max(o,p),l=Math.min(l,y)),u=Math.max(u,p),c=Math.min(c,y)}n?(t.inView=!0,t.error=o,t.distanceFromCamera=l):(t.inView=!1,t.error=u,t.distanceFromCamera=c)}dispose(){super.dispose(),this.group.removeFromParent()}};import{BatchedMesh as ph,Box2 as Ln,Box3 as mh,Box3Helper as gh,BoxGeometry as fh,BufferAttribute as Qi,BufferGeometry as yh,CanvasTexture as bh,Color as xh,CustomBlending as In,DataTexture as Dn,DefaultLoadingManager as vh,DoubleSide as _h,EventDispatcher as Th,FileLoader as Rn,FloatType as wh,Frustum as Mh,GreaterDepth as Sh,Group as Ch,LineBasicMaterial as Eh,LineSegments as Ph,LinearFilter as On,LinearMipMapLinearFilter as Ah,MathUtils as $i,Matrix2 as Un,Matrix3 as Bn,Matrix4 as kn,Mesh as Lh,MeshBasicMaterial as Fn,MeshLambertMaterial as Ih,MeshStandardMaterial as Dh,OneFactor as Vn,PlaneGeometry as Rh,Points as Oh,PointsMaterial as Uh,Quaternion as Bh,REVISION as kh,RGFormat as Fh,Ray as Vh,Raycaster as zh,RedFormat as Nh,SRGBColorSpace as jh,ShaderMaterial as zn,Source as Wh,Sphere as Gh,SphereGeometry as qh,Texture as Hh,TextureUtils as Yh,Triangle as Xh,UnsignedByteType as Qh,Vector2 as ee,Vector3 as Na,Vector4 as Nn,WebGLArrayRenderTarget as $h,WebGLRenderTarget as Ca,WebGLRenderer as jn,ZeroFactor as Wn}from"three";import{GLTFLoader as Gn}from"three/addons/loaders/GLTFLoader.js";import{FullScreenQuad as ja}from"three/addons/postprocessing/Pass.js";var Kh=Object.freeze({fill:"#cccccc",stroke:"transparent",strokeWidth:1,radius:2,order:0,visible:!0});var Ea=new ie;Ea.maxJobs=10,Ea.priorityCallback=(e,t)=>{let i=e.tile,r=t.tile,a=i.internal.renderer,s=r.internal.renderer,n=a.visibleTiles.has(i);return n===s.visibleTiles.has(r)?Ue(i,r):n?1:-1};var Pa=new Na;function ot(e,t){if(e.isInterleavedBufferAttribute||e.array instanceof t)return e;let i=t===Int8Array||t===Int16Array||t===Int32Array?-1:0,r=new Qi(new t(e.count*e.itemSize),e.itemSize,!0),a=e.itemSize,s=e.count;for(let n=0;n<s;n++)for(let o=0;o<a;o++){let l=$i.clamp(e.getComponent(n,o),i,1);r.setComponent(n,o,l)}return r}function qn(e,t=Int16Array){let i=e.geometry,r=i.attributes,a=r.position;if(a.isInterleavedBufferAttribute||a.array instanceof t)return a;let s=new Qi(new t(a.count*a.itemSize),a.itemSize,!1),n=a.itemSize,o=a.count;i.computeBoundingBox();let l=i.boundingBox,{min:u,max:c}=l,h=2**(8*t.BYTES_PER_ELEMENT-1)-1,m=-h;for(let d=0;d<o;d++)for(let p=0;p<n;p++){let y=p===0?"x":p===1?"y":"z",M=u[y],_=c[y],C=$i.mapLinear(a.getComponent(d,p),M,_,m,h);s.setComponent(d,p,C)}l.getCenter(Pa).multiply(e.scale).applyQuaternion(e.quaternion),e.position.add(Pa),e.scale.x*=.5*(c.x-u.x)/h,e.scale.y*=.5*(c.y-u.y)/h,e.scale.z*=.5*(c.z-u.z)/h,r.position=s,e.geometry.boundingBox=null,e.geometry.boundingSphere=null,e.updateMatrixWorld()}var Zi=class{constructor(e){this._options={generateNormals:!1,disableMipmaps:!0,compressIndex:!0,compressNormals:!1,compressUvs:!1,compressPosition:!1,uvType:Int8Array,normalType:Int8Array,positionType:Int16Array,...e},this.name="TILES_COMPRESSION_PLUGIN",this.priority=-100}processTileModel(e,t){let{generateNormals:i,disableMipmaps:r,compressIndex:a,compressUvs:s,compressNormals:n,compressPosition:o,uvType:l,normalType:u,positionType:c}=this._options;e.traverse(h=>{if(h.material&&r){let m=h.material;for(let d in m){let p=m[d];p&&p.isTexture&&p.generateMipmaps&&(p.generateMipmaps=!1,p.minFilter=On)}}if(h.geometry){let m=h.geometry,d=m.attributes;if(s){let{uv:p,uv1:y,uv2:M,uv3:_}=d;p&&(d.uv=ot(p,l)),y&&(d.uv1=ot(y,l)),M&&(d.uv2=ot(M,l)),_&&(d.uv3=ot(_,l))}if(i&&!d.normals&&m.computeVertexNormals(),n&&d.normals&&(d.normals=ot(d.normals,u)),o&&qn(h,c),a&&m.index){let p=d.position.count,y=m.index,M=p>65535?Uint32Array:p>255?Uint16Array:Uint8Array;if(!(y.array instanceof M)){let _=new M(m.index.count);_.set(y.array);let C=new Qi(_,1);m.setIndex(C)}}}})}};function F(e,t,i){return e&&t in e?e[t]:i}function Wa(e){return e!=="BOOLEAN"&&e!=="STRING"&&e!=="ENUM"}function Hn(e){return/^FLOAT/.test(e)}function ct(e){return/^VEC/.test(e)}function dt(e){return/^MAT/.test(e)}function Ga(e,t,i,r=null){return dt(i)||ct(i)?r.fromArray(e,t):e[t]}function Yi(e){let{type:t,componentType:i}=e;switch(t){case"SCALAR":return i==="INT64"?0n:0;case"VEC2":return new ee;case"VEC3":return new Na;case"VEC4":return new Nn;case"MAT2":return new Un;case"MAT3":return new Bn;case"MAT4":return new kn;case"BOOLEAN":return!1;case"STRING":return"";case"ENUM":return 0}}function Aa(e,t){if(t==null)return!1;switch(e){case"SCALAR":return typeof t=="number"||typeof t=="bigint";case"VEC2":return t.isVector2;case"VEC3":return t.isVector3;case"VEC4":return t.isVector4;case"MAT2":return t.isMatrix2;case"MAT3":return t.isMatrix3;case"MAT4":return t.isMatrix4;case"BOOLEAN":return typeof t=="boolean";case"STRING":return typeof t=="string";case"ENUM":return typeof t=="number"||typeof t=="bigint"}throw Error("ClassProperty: invalid type.")}function ut(e,t=null){switch(e){case"INT8":return Int8Array;case"INT16":return Int16Array;case"INT32":return Int32Array;case"INT64":return BigInt64Array;case"UINT8":return Uint8Array;case"UINT16":return Uint16Array;case"UINT32":return Uint32Array;case"UINT64":return BigUint64Array;case"FLOAT32":return Float32Array;case"FLOAT64":return Float64Array}switch(t){case"BOOLEAN":return Uint8Array;case"STRING":return Uint8Array}throw Error("ClassProperty: invalid type.")}function Yn(e,t=null){if(e.array){t=t&&Array.isArray(t)?t:[],t.length=e.count;for(let i=0,r=t.length;i<r;i++)t[i]=Nt(e,t[i])}else t=Nt(e,t);return t}function Nt(e,t=null){let i=e.default,r=e.type;if(t||(t=Yi(e)),i===null){switch(r){case"SCALAR":return 0;case"VEC2":return t.set(0,0);case"VEC3":return t.set(0,0,0);case"VEC4":return t.set(0,0,0,0);case"MAT2":return t.identity();case"MAT3":return t.identity();case"MAT4":return t.identity();case"BOOLEAN":return!1;case"STRING":return"";case"ENUM":return""}throw Error("ClassProperty: invalid type.")}else if(dt(r))t.fromArray(i);else if(ct(r))t.fromArray(i);else return i}function Xn(e,t){if(e.noData===null)return t;let i=e.noData,r=e.type;if(Array.isArray(t))for(let n=0,o=t.length;n<o;n++)t[n]=a(t[n]);else t=a(t);return t;function a(n){return s(n)&&(n=Nt(e,n)),n}function s(n){if(dt(r)){let o=n.elements;for(let l=0,u=i.length;l<u;l++)if(i[l]!==o[l])return!1;return!0}else if(ct(r)){for(let o=0,l=i.length;o<l;o++)if(i[o]!==n.getComponent(o))return!1;return!0}else return i===n}}function Qn(e,t){switch(e){case"INT8":return Math.max(t/127,-1);case"INT16":return Math.max(t,32767,-1);case"INT32":return Math.max(t/2147483647,-1);case"INT64":return Math.max(Number(t)/9223372036854776e3,-1);case"UINT8":return t/255;case"UINT16":return t/65535;case"UINT32":return t/4294967295;case"UINT64":return Number(t)/18446744073709552e3}}function $n(e,t){let{type:i,componentType:r,scale:a,offset:s,normalized:n}=e;if(Array.isArray(t))for(let h=0,m=t.length;h<m;h++)t[h]=o(t[h]);else t=o(t);return t;function o(h){return h=dt(i)?u(h):ct(i)?l(h):c(h),h}function l(h){return h.x=c(h.x),h.y=c(h.y),"z"in h&&(h.z=c(h.z)),"w"in h&&(h.w=c(h.w)),h}function u(h){let m=h.elements;for(let d=0,p=m.length;d<p;d++)m[d]=c(m[d]);return h}function c(h){return n&&(h=Qn(r,h)),(n||Hn(r))&&(h=h*a+s),h}}function Ji(e,t,i=null){if(e.array){Array.isArray(t)||(t=Array(e.count||0)),t.length=i===null?e.count:i;for(let r=0,a=t.length;r<a;r++)Aa(e.type,t[r])||(t[r]=Yi(e))}else Aa(e.type,t)||(t=Yi(e));return t}function jt(e,t){for(let i in t)i in e||delete t[i];for(let i in e){let r=e[i];t[i]=Ji(r,t[i])}}function Zn(e){switch(e){case"ENUM":return 1;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":return 4;case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;case"BOOLEAN":return-1;case"STRING":return-1;default:return-1}}var Gt=class{constructor(e,t,i=null){this.name=t.name||null,this.description=t.description||null,this.type=t.type,this.componentType=t.componentType||null,this.enumType=t.enumType||null,this.array=t.array||!1,this.count=t.count||0,this.normalized=t.normalized||!1,this.offset=t.offset||0,this.scale=F(t,"scale",1),this.max=F(t,"max",1/0),this.min=F(t,"min",-1/0),this.required=t.required||!1,this.noData=F(t,"noData",null),this.default=F(t,"default",null),this.semantic=F(t,"semantic",null),this.enumSet=null,this.accessorProperty=i,i&&(this.offset=F(i,"offset",this.offset),this.scale=F(i,"scale",this.scale),this.max=F(i,"max",this.max),this.min=F(i,"min",this.min)),t.type==="ENUM"&&(this.enumSet=e[this.enumType],this.componentType===null&&(this.componentType=F(this.enumSet,"valueType","UINT16")))}shapeToProperty(e,t=null){return Ji(this,e,t)}resolveDefaultElement(e){return Nt(this,e)}resolveDefault(e){return Yn(this,e)}resolveNoData(e){return Xn(this,e)}resolveEnumsToStrings(e){let t=this.enumSet;if(this.type==="ENUM")if(Array.isArray(e))for(let r=0,a=e.length;r<a;r++)e[r]=i(e[r]);else e=i(e);return e;function i(r){let a=t.values.find(s=>s.value===r);return a===null?"":a.name}}adjustValueScaleOffset(e){return Wa(this.type)?$n(this,e):e}},Ki=class{constructor(e,t={},i={},r=null){this.definition=e,this.class=t[e.class],this.className=e.class,this.enums=i,this.data=r,this.name="name"in e?e.name:null,this.properties=null}getPropertyNames(){return Object.keys(this.class.properties)}includesData(e){return!!this.definition.properties[e]}dispose(){}_initProperties(e=Gt){let t={};for(let i in this.class.properties)t[i]=new e(this.enums,this.class.properties[i],this.definition.properties[i]);this.properties=t}},Jn=class extends Gt{constructor(e,t,i=null){super(e,t,i),this.attribute=i?.attribute??null}},Kn=class extends Ki{constructor(...e){super(...e),this.isPropertyAttributeAccessor=!0,this._initProperties(Jn)}getData(e,t,i={}){let r=this.properties;jt(r,i);for(let a in r)i[a]=this.getPropertyValue(a,e,t,i[a]);return i}getPropertyValue(e,t,i,r=null){if(t>=this.count)throw Error("PropertyAttributeAccessor: Requested index is outside the range of the buffer.");let a=this.properties[e],s=a.type;if(!a)throw Error("PropertyAttributeAccessor: Requested class property does not exist.");if(!this.definition.properties[e])return a.resolveDefault(r);r=a.shapeToProperty(r);let n=i.getAttribute(a.attribute.toLowerCase());if(dt(s)){let o=r.elements;for(let l=o.length;0<l;)o[0]=n.getComponent(t,0)}else if(ct(s))r.fromBufferAttribute(n,t);else if(s==="SCALAR"||s==="ENUM")r=n.getX(t);else throw Error("StructuredMetadata.PropertyAttributeAccessor: BOOLEAN and STRING types are not supported by property attributes.");return r=a.adjustValueScaleOffset(r),r=a.resolveEnumsToStrings(r),r=a.resolveNoData(r),r}},eo=class extends Gt{constructor(e,t,i=null){super(e,t,i),this.values=i?.values??null,this.valueLength=Zn(this.type),this.arrayOffsets=F(i,"arrayOffsets",null),this.stringOffsets=F(i,"stringOffsets",null),this.arrayOffsetType=F(i,"arrayOffsetType","UINT32"),this.stringOffsetType=F(i,"stringOffsetType","UINT32")}getArrayLengthFromId(e,t){let i=this.count;if(this.arrayOffsets!==null){let{arrayOffsets:r,arrayOffsetType:a}=this,s=new(ut(a))(e[r]);i=s[t+1]-s[t]}return i}getIndexOffsetFromId(e,t){let i=t;if(this.arrayOffsets){let{arrayOffsets:r,arrayOffsetType:a}=this;i=new(ut(a))(e[r])[i]}else this.array&&(i*=this.count);return i}},to=class extends Ki{constructor(...e){super(...e),this.isPropertyTableAccessor=!0,this.count=this.definition.count,this._initProperties(eo)}getData(e,t={}){let i=this.properties;jt(i,t);for(let r in i)t[r]=this.getPropertyValue(r,e,t[r]);return t}_readValueAtIndex(e,t,i,r=null){let a=this.properties[e],{componentType:s,type:n}=a,o=this.data,l=o[a.values],u=new(ut(s,n))(l),c=a.getIndexOffsetFromId(o,t);if(Wa(n)||n==="ENUM")return Ga(u,(c+i)*a.valueLength,n,r);if(n==="STRING"){let h=c+i,m=0;if(a.stringOffsets!==null){let{stringOffsets:p,stringOffsetType:y}=a,M=new(ut(y))(o[p]);m=M[h+1]-M[h],h=M[h]}let d=new Uint8Array(u.buffer,h,m);r=new TextDecoder().decode(d)}else if(n==="BOOLEAN"){let h=c+i,m=Math.floor(h/8),d=h%8;r=(u[m]>>d&1)==1}return r}getPropertyValue(e,t,i=null){if(t>=this.count)throw Error("PropertyTableAccessor: Requested index is outside the range of the table.");let r=this.properties[e];if(!r)throw Error("PropertyTableAccessor: Requested property does not exist.");if(!this.definition.properties[e])return r.resolveDefault(i);let a=r.array,s=this.data,n=r.getArrayLengthFromId(s,t);if(i=r.shapeToProperty(i,n),a)for(let o=0,l=i.length;o<l;o++)i[o]=this._readValueAtIndex(e,t,o,i[o]);else i=this._readValueAtIndex(e,t,0,i);return i=r.adjustValueScaleOffset(i),i=r.resolveEnumsToStrings(i),i=r.resolveNoData(i),i}},lt=new Ln,La=class{constructor(){this._renderer=new jn,this._target=new Ca(1,1),this._texTarget=new Ca,this._quad=new ja(new zn({blending:In,blendDst:Wn,blendSrc:Vn,uniforms:{map:{value:null},pixel:{value:new ee}},vertexShader:`
1
+ import{a as fr,c as yr,g as hi,i as Mr,j as ui,k as We,l as Ge}from"./chunk-SOAUR4DL.mjs";import{e as gr,g as li,h as br,i as xr,j as vr,l as _r,m as Tr,n as wr}from"./chunk-5C4H7SRF.mjs";import{a as lr,b as ai,e as hr,f as ur,g as cr,m as dr,n as si,r as pr}from"./chunk-37QOMZW6.mjs";import{d as yt,e as ni,g as oi,h as mr}from"./chunk-UCD76KQ6.mjs";import{a as ri}from"./chunk-JR557W27.mjs";import{useCallback as xe,useEffect as ve,useMemo as Mo,useRef as z,useState as tr}from"react";import{useFrame as So,useThree as Co}from"@react-three/fiber";import{Box3 as Ur,BoxGeometry as As,Group as Rr,Matrix4 as Br,Mesh as Ls,MeshBasicMaterial as Is,Vector3 as se}from"three";import{Euler as ds,Matrix4 as Me,MeshBasicMaterial as ps,MeshMatcapMaterial as ms,MeshNormalMaterial as gs,MeshStandardMaterial as fs,Quaternion as ys,Vector3 as He}from"three";function Pr(e){let t={};for(let[i,r]of Object.entries(e))t[r.modelObjectId??i]=i;return t}function pi(e){let t=e,i=null;for(;t;){let r=t.userData?.ri_name;if(typeof r=="string"&&r)return r;!i&&t.name&&(i=t.name),t=t.parent}return i}function Ar(e,t){return e||(t?t.modelObjectId??t.id:null)}function mi(e,t){let i=pi(e);if(!i)return null;let r=t.keyByModelObject[i]??i,a=t.objectBindings[r];return a?{key:r,binding:a}:null}function gi(e,t,i){if(!br(e))return null;let r=mi(e,t);return!r||r.binding.visible===!1||(i==="select"?r.binding.selectable:r.binding.hoverable)===!1?null:r}function Lr(e,t,i,r){for(let a of e){if(a.eventObject!==t)continue;let s=gi(a.object,i,r);if(s)return s}return null}var Re=new He,ci=new He,bs=new Me,Sr=new Me,qe=new Me,xs=new Me,bt=new Me,vs=new Me,_s=new Me,Cr=new He,Er=new He,pe=new He,di=new ys,Ts=new ds;function ws(e,t,i,r,a){let s=!!(i?.position||i?.rotation||i?.scale||i?.shear),n=!!(a&&a.factor>0&&a.radius>0);if(!s&&!n){e.matrixAutoUpdate=!0,e.position.copy(t.position),e.rotation.copy(t.rotation),e.scale.copy(t.scale),e.updateMatrix(),e.updateWorldMatrix(!0,!1);return}Sr.compose(t.position,di.setFromEuler(t.rotation),t.scale);let o=i?.rotation;qe.compose(Cr.fromArray(hi(i?.position??[0,0,0],o??[0,0,0],i?.scale??[1,1,1],i?.pivot,"XYZ",i?.shear)),di.setFromEuler(Ts.set(o?.[0]??0,o?.[1]??0,o?.[2]??0)),Er.fromArray(i?.scale??[1,1,1])),i?.shear&&qe.makeRotationFromQuaternion(di).multiply(lr(i.shear)).scale(Er).setPosition(Cr),qe.premultiply(r).multiply(xs.copy(r).invert()),e.parent?.updateWorldMatrix(!0,!1);let l=e.parent?.matrixWorld??bs;if(bt.multiplyMatrices(l,Sr).premultiply(qe),n&&a){let u=e;for(;u.parent&&!u.userData.ri_name;)u=u.parent;let c=u.userData.ri_center;Array.isArray(c)&&c.length===3?pe.fromArray(c).applyMatrix4(r).applyMatrix4(qe):pe.setFromMatrixPosition(bt),pe.sub(a.centre),pe.lengthSq()>1e-8&&(pe.normalize().multiplyScalar(a.factor*a.radius),bt.premultiply(_s.makeTranslation(pe.x,pe.y,pe.z)))}e.matrixAutoUpdate=!1,e.matrix.multiplyMatrices(vs.copy(l).invert(),bt),e.matrixWorldNeedsUpdate=!0,e.updateWorldMatrix(!1,!1)}function xt(e,t){if(!yt(e)&&!e.userData.riLogicalObject)return;let i=mi(e,t);if(!i)return;let r=Ir(e);if(r.rest??(r.rest={position:e.position.clone(),rotation:e.rotation.clone(),scale:e.scale.clone()}),t.suspendTransforms)return;if(t.placementFrame&&!e.userData.riLogicalObject){ws(e,r.rest,i.binding.transform,t.placementFrame,t.explode);return}let a=r.rest,s=i.binding.transform;s?.position?e.position.fromArray(s.position):e.position.copy(a.position),s?.rotation?e.rotation.set(s.rotation[0],s.rotation[1],s.rotation[2],a.rotation.order):e.rotation.copy(a.rotation),s?.scale?e.scale.fromArray(s.scale):e.scale.copy(a.scale),e.position.fromArray(hi(e.position.toArray(),[e.rotation.x,e.rotation.y,e.rotation.z],e.scale.toArray(),s?.pivot,a.rotation.order,s?.shear)),ai(e,s?.shear);let n=t.explode;if(n&&n.factor>0&&n.radius>0){e.updateWorldMatrix(!0,!1),ci.setFromMatrixPosition(e.matrixWorld);let o=e;for(;o.parent&&!o.userData.ri_name;)o=o.parent;let l=o.userData.ri_center;Array.isArray(l)&&l.length===3?Re.fromArray(l).applyMatrix4(e.matrixWorld).sub(n.centre):Re.copy(ci).sub(n.centre),Re.lengthSq()>1e-8&&(Re.normalize().multiplyScalar(n.factor*n.radius).add(ci),e.parent&&e.parent.worldToLocal(Re),e.position.copy(Re))}ai(e,s?.shear),e.updateWorldMatrix(!0,!1)}function Oe(e,t){e.traverse(i=>xt(i,t))}function Ir(e){var t;return(t=e.userData).riVisuals??(t.riVisuals={}),e.userData.riVisuals}function Ms(e,t,i,r){return JSON.stringify([e?.style?.material??null,t??null,i.shadingMode,i.rendererMode,r])}function Ss(e){if(e.textures){for(let t of ni){let i=e.textures[t];i&&si(i,oi(t))}e.textures=void 0}}function Cs(e,t,i){let r=e.textures??{};for(let a of ni){let s=mr(t,a),n=r[a];if(n===s)continue;let o=oi(a);n&&si(n,o),s?(dr(s,o,i),r[a]=s):delete r[a]}e.textures=Object.keys(r).length>0?r:void 0}function Es(e,t){if(t.shadingMode==="normals")return We(e,()=>new gs);if(t.shadingMode==="unlit")return We(e,i=>{let r=new ps;return r.color.copy(i.color),r.map=i.map,r.vertexColors=i.vertexColors,r.alphaMap=i.alphaMap,r.alphaTest=i.alphaTest,r.transparent=i.transparent,r.opacity=i.opacity,r.side=i.side,r});if(t.rendererMode==="matcap"){let i=pr();return We(e,r=>{let a=new ms;return a.matcap=i,a.color.copy(r.color),a.vertexColors=r.vertexColors,a.alphaMap=r.alphaMap,a.alphaTest=r.alphaTest,a.side=r.side,a})}return e}function Ps(e,t){if(!yt(e))return;let r=Ir(e);r.original??(r.original=ui(e));let a=mi(e,t);if(!a){r.original&&(e.material=r.original),e.visible=!0;return}let{key:s,binding:n}=a;e.visible=n.visible!==!1,xt(e,t);let o=t.itemMaterials?.[s]?.hex??t.itemMaterials?.[n.modelObjectId??s]?.hex,l=t.highlightOnHover!==!1&&s===t.hoveredKey,u=Ms(n,o,t,l);if(r.signature===u&&r.display){e.material=r.display;return}let c=n.style?.material;if(Cs(r,c,t.invalidate),!r.physical){let h=r.original??ui(e);if(!h)return;r.physical=We(h,m=>{let d=_r(m),p=Tr(d??new fs);return wr(p),p})}Ge(r.physical,h=>{Mr(h,c,o??c?.baseColor),l&&(h.emissive.add(hr),h.color.lerp(ur,cr)),h.needsUpdate=!0}),r.display&&r.display!==r.physical&&Ge(r.display,h=>h.dispose()),r.display=Es(r.physical,t),r.signature=u,e.material=r.display}function Dr(e,t){e.traverse(i=>Ps(i,t))}function fi(e){e.traverse(t=>{if(!yt(t))return;let i=t.userData.riVisuals;i&&(i.rest&&(t.matrixAutoUpdate=!0,t.position.copy(i.rest.position),t.rotation.copy(i.rest.rotation),t.scale.copy(i.rest.scale),t.updateMatrix()),i.original&&(t.material=i.original),i.display&&i.display!==i.physical&&Ge(i.display,r=>r.dispose()),i.physical&&Ge(i.physical,r=>r.dispose()),Ss(i),delete t.userData.riVisuals)})}var kr=new Br().makeRotationX(Math.PI/2),Or=kr.clone().invert();function Ds(e){let t=new se(e[0],e[1],e[2]),i=new se(Math.abs(e[3])+Math.abs(e[6])+Math.abs(e[9]),Math.abs(e[4])+Math.abs(e[7])+Math.abs(e[10]),Math.abs(e[5])+Math.abs(e[8])+Math.abs(e[11]));return new Ur(t.clone().sub(i),t.clone().add(i))}function Rs(e){let t=e.getCenter(new se),i=e.getSize(new se).multiplyScalar(.5);return[t.x,t.y,t.z,i.x,0,0,0,i.y,0,0,0,i.z]}var vt=class{constructor(){this.group=new Rr;this.objects=new Map;this.geometry=new As(1,1,1);this.material=new Is;this.originalBounds=new WeakMap;this.signature="";this.lastContext=null;this.lastEffective=null;this.lastDragging=!1;this.version=0;this.tileVersions=new WeakMap;this.transforms=new Map}setCatalog(t){this.group.clear(),this.objects.clear();for(let i of t){let r=new Ur(new se(...i.minimum),new se(...i.maximum)).applyMatrix4(Or),a=new Rr;a.name=i.name,a.userData.ri_name=i.name,a.userData.riLogicalObject=!0,a.userData.ri_center=r.getCenter(new se).toArray();let s=new Ls(this.geometry,this.material);s.visible=!1,s.raycast=()=>{},s.position.copy(r.getCenter(new se)),s.scale.copy(r.getSize(new se)),a.add(s),this.group.add(a),this.objects.set(i.name,a)}this.signature="",this.lastContext=null}nodesByBinding(t){let i={};for(let[r,a]of this.objects){let s=t.keyByModelObject[r]??r;t.objectBindings[s]&&(i[s]=a)}return i}sync(t,i,r=!1){if(!r&&!this.lastDragging&&t===this.lastContext&&this.lastEffective)return this.lastEffective;this.lastContext=t,this.lastDragging=r;let a={...t,suspendTransforms:!1},s=i?t.objectBindings[i]:void 0,n=s?this.objects.get(s.modelObjectId??i):void 0;r&&n&&s&&(a={...a,objectBindings:{...t.objectBindings,[i]:{...s,transform:{position:n.position.toArray(),rotation:[n.rotation.x,n.rotation.y,n.rotation.z],scale:n.scale.toArray()}}}});for(let l of this.objects.values())r&&l===n||xt(l,a);this.group.updateWorldMatrix(!0,!0);let o=[...this.objects].map(([l,u])=>`${l}:${u.matrix.elements.join(",")}`).join(";");if(o!==this.signature){this.signature=o,this.version++,this.transforms.clear();for(let[l,u]of this.objects)u.matrix.equals(new Br)||this.transforms.set(l,kr.clone().multiply(u.matrix).multiply(Or))}return this.lastEffective=a,a}updateBounds(t){if(!t)return;let i=r=>{if(this.tileVersions.get(r)!==this.version){if(r.boundingVolume.box&&this.tileVersions.get(r)!==this.version){let a=this.originalBounds.get(r);a||(a={box:[...r.boundingVolume.box],error:r.geometricError},this.originalBounds.set(r,a));let s=Ds(a.box),n=s.clone(),o=1;for(let u of r.extras?.featureIds??[]){let c=this.transforms.get(u);c&&(n.union(s.clone().applyMatrix4(c)),o=Math.max(o,c.getMaxScaleOnAxis()))}let l=Rs(n);r.boundingVolume.box=l,r.geometricError=a.error*o,r.engineData?.boundingVolume?.setObbData(l,r.engineData.transform),this.tileVersions.set(r,this.version)}r.children?.forEach(i)}};i(t)}dispose(){this.group.clear(),this.objects.clear(),this.geometry.dispose(),this.material.dispose()}};var yi=Object.freeze({factor:1,loosened:!1,tooFine:0,raisedAt:-1/0,changedAt:-1/0}),Ye=16,bi=1.25,Os=1.5,Us=1.25,Bs=500,ks=3e3,Fr=5e3,Vr=2e3,Fs=.9;function zr(e){return e.full&&(e.wanting||e.usage>1)}function Nr(e){return e.loosened?ks:Bs}function jr(e){let t=e.factor/Us;return t<=1+1e-6?1:t}function Wr(e,t){return e.factor>1&&!e.loosened&&!t.full&&!t.wanting&&t.usage<Fs&&jr(e)>e.tooFine}function Gr(e,t){let{now:i}=t,r=t.moved&&e.tooFine>0?{...e,tooFine:0}:e;if(zr(t)){if(i-r.changedAt<Nr(r))return r;let a=Math.max(r.tooFine,r.factor);return r.factor>=Ye?r.loosened&&r.tooFine===a?r:{...r,loosened:!0,tooFine:a,changedAt:i}:{factor:Math.min(Ye,r.factor*Os),loosened:!0,tooFine:a,raisedAt:i,changedAt:i}}return r.loosened&&!t.wanting?{...r,loosened:!1,changedAt:i}:Wr(r,t)&&i-r.raisedAt>=Fr&&i-r.changedAt>=Vr?{...r,factor:jr(r),changedAt:i}:r}function qr(e,t){let{now:i}=t;return zr(t)?e.factor>=Ye&&e.loosened?null:Math.max(0,Nr(e)-(i-e.changedAt)):e.loosened&&!t.wanting?0:Wr(e,t)?Math.max(0,Fr-(i-e.raisedAt),Vr-(i-e.changedAt)):null}function Qr(e){try{let t=typeof location<"u"?location.href:void 0;return new URL(e,t).origin}catch{return null}}function xi(e){if(!e)return null;let t=e.length,i=e.indexOf("?"),r=e.indexOf("#");i!==-1&&(t=Math.min(t,i)),r!==-1&&(t=Math.min(t,r));let a=e.lastIndexOf(".",t),s=e.lastIndexOf("/",t),n=e.indexOf("://");return n!==-1&&n+2===s||a===-1||a<s?null:e.substring(a+1,t)||null}var Tt,Xe=(Tt=class{static setXRSession(e){e!==this.session&&(this.flushPending(),this.session=e)}static requestAnimationFrame(e){let{session:t,pending:i}=this,r,a=()=>{i.delete(r),e()};return r=t?t.requestAnimationFrame(a):requestAnimationFrame(a),i.set(r,e),r}static cancelAnimationFrame(e){let{pending:t,session:i}=this;t.delete(e),i?i.cancelAnimationFrame(e):cancelAnimationFrame(e)}static flushPending(){this.pending.forEach((e,t)=>{e(),this.cancelAnimationFrame(t)})}},ri(Tt,"pending",new Map),ri(Tt,"session",null),Tt),Hr=2**30,Ze=class{get unloadPriorityCallback(){return this._unloadPriorityCallback}set unloadPriorityCallback(e){e.length===1?(console.warn('LRUCache: "unloadPriorityCallback" function has been changed to take two arguments.'),this._unloadPriorityCallback=(t,i)=>{let r=e(t),a=e(i);return r<a?-1:+(r>a)}):this._unloadPriorityCallback=e}constructor(){this.minSize=6e3,this.maxSize=8e3,this.minBytesSize=.3*Hr,this.maxBytesSize=.4*Hr,this.unloadPercent=.05,this.autoMarkUnused=!0,this.cachedBytes=0,this.itemSet=new Map,this.itemList=[],this.usedSet=new Set,this.callbacks=new Map,this.unloadingHandle=-1,this.bytesMap=new Map,this.loadedSet=new Set,this._unloadPriorityCallback=null;let e=this.itemSet;this.defaultPriorityCallback=t=>e.get(t)}isFull(){return this.itemSet.size>=this.maxSize||this.cachedBytes>=this.maxBytesSize}getMemoryUsage(e){return this.bytesMap.get(e)||0}setMemoryUsage(e,t){let{bytesMap:i,itemSet:r}=this;r.has(e)&&(this.cachedBytes-=i.get(e)||0,i.set(e,t),this.cachedBytes+=t)}add(e,t){let i=this.itemSet;if(i.has(e)||this.isFull())return!1;let r=this.usedSet,a=this.itemList,s=this.callbacks;return a.push(e),r.add(e),i.set(e,Date.now()),s.set(e,t),!0}has(e){return this.itemSet.has(e)}remove(e){let t=this.usedSet,i=this.itemSet,r=this.itemList,a=this.bytesMap,s=this.callbacks,n=this.loadedSet;if(i.has(e)){this.cachedBytes-=a.get(e)||0,a.delete(e),s.get(e)(e);let o=r.indexOf(e);return r.splice(o,1),t.delete(e),i.delete(e),s.delete(e),n.delete(e),!0}return!1}setLoaded(e,t){let{itemSet:i,loadedSet:r}=this;i.has(e)&&(t===!0?r.add(e):r.delete(e))}markUsed(e){let t=this.itemSet,i=this.usedSet;t.has(e)&&!i.has(e)&&(t.set(e,Date.now()),i.add(e))}markUnused(e){this.usedSet.delete(e)}markAllUnused(){this.usedSet.clear()}isUsed(e){return this.usedSet.has(e)}unloadUnusedContent(){let{unloadPercent:e,minSize:t,maxSize:i,itemList:r,itemSet:a,usedSet:s,loadedSet:n,callbacks:o,bytesMap:l,minBytesSize:u,maxBytesSize:c}=this,h=r.length-s.size,m=r.length-n.size,d=Math.max(Math.min(r.length-t,h),0),p=this.cachedBytes-u,y=this.unloadPriorityCallback||this.defaultPriorityCallback,M=!1,_=d>0&&h>0||m&&r.length>i;if(h&&this.cachedBytes>u||m&&this.cachedBytes>c||_){r.sort((w,U)=>{let O=s.has(w);if(O===s.has(U)){let V=n.has(w);return V===n.has(U)?-y(w,U):V?1:-1}else return O?1:-1});let C=Math.max(t*e,d*e),g=Math.ceil(Math.min(C,h,d)),P=Math.max(e*p,e*u),S=Math.min(P,p),v=0,L=0;for(;this.cachedBytes-L>c||r.length-v>i;){let w=r[v],U=l.get(w)||0;if(s.has(w)&&n.has(w)||this.cachedBytes-L-U<c&&r.length-v<=i)break;L+=U,v++}for(;L<S||v<g;){let w=r[v],U=l.get(w)||0;if(s.has(w)||this.cachedBytes-L-U<u&&v>=g)break;L+=U,v++}r.splice(0,v).forEach(w=>{this.cachedBytes-=l.get(w)||0,o.get(w)(w),l.delete(w),a.delete(w),o.delete(w),n.delete(w),s.delete(w)}),M=v<d||L<p&&v<h,M&&(M=v>0)}M&&(this.unloadingHandle=Xe.requestAnimationFrame(()=>this.scheduleUnload()))}scheduleUnload(){Xe.cancelAnimationFrame(this.unloadingHandle),this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.unloadUnusedContent()}))}},Vs=class extends DOMException{constructor(){super("PriorityQueue: Item removed","AbortError")}},ie=class{get running(){return this.items.length!==0||this.currJobs!==0}constructor(){this.maxJobs=6,this.items=[],this.callbacks=new Map,this.currJobs=0,this.scheduled=!1,this.autoUpdate=!0,this.priorityCallback=null,this._schedulingCallback=e=>{Xe.requestAnimationFrame(e)},this._runjobs=()=>{this.scheduled=!1,this.tryRunJobs()}}sort(){let e=this.priorityCallback,t=this.items;e!==null&&t.sort(e)}has(e){return this.callbacks.has(e)}add(e,t){let i={callback:t,reject:null,resolve:null,promise:null};return i.promise=new Promise((r,a)=>{let s=this.items,n=this.callbacks;i.resolve=r,i.reject=a,s.unshift(e),n.set(e,i),this.autoUpdate&&this.scheduleJobRun()}),i.promise}remove(e){let t=this.items,i=this.callbacks,r=t.indexOf(e);if(r!==-1){let a=i.get(e);a.promise.catch(s=>{if(s.name!=="AbortError")throw s}),a.reject(new Vs),t.splice(r,1),i.delete(e)}}removeByFilter(e){let{items:t}=this;for(let i=0;i<t.length;i++){let r=t[i];e(r)&&(this.remove(r),i--)}}tryRunJobs(){this.sort();let e=this.items,t=this.callbacks,i=this.maxJobs,r=0,a=()=>{this.currJobs--,this.autoUpdate&&this.scheduleJobRun()};for(;i>this.currJobs&&e.length>0&&r<i;){this.currJobs++,r++;let s=e.pop(),{callback:n,resolve:o,reject:l}=t.get(s);t.delete(s);let u;try{u=n(s)}catch(c){l(c),a();continue}u instanceof Promise?u.then(o).catch(l).finally(a):(o(u),a())}}flush(e){let{items:t,callbacks:i}=this,r=t.indexOf(e);if(!i.has(e))return;let{callback:a,resolve:s,reject:n}=i.get(e);i.delete(e),t.splice(r,1);let o;try{o=a(e)}catch(l){n(l);return}return o instanceof Promise?o.then(s).catch(n):s(o),o}scheduleJobRun(){this.scheduled||(this.scheduled=(this._schedulingCallback(this._runjobs),!0))}},Ct=class{get running(){for(let e of this.originQueues.values())if(e.running)return!0;return!1}get maxJobsPerOrigin(){return this._maxJobsPerOrigin}set maxJobsPerOrigin(e){this._maxJobsPerOrigin=e,this.originQueues.forEach(t=>t.maxJobs=e)}get maxJobs(){return this.maxJobsPerOrigin}set maxJobs(e){console.warn('DownloadPriorityQueue: "maxJobs" is no longer valid and limits jobs per server origin. Use "maxJobsPerOrigin", instead.'),this.maxJobsPerOrigin=e}get priorityCallback(){return this._priorityCallback}set priorityCallback(e){this._priorityCallback=e,this.originQueues.forEach(t=>t.priorityCallback=e)}constructor(){this.originQueues=new Map,this._itemQueues=new WeakMap,this._maxJobsPerOrigin=6,this._priorityCallback=null}add(e,t,i,r=null){this.originQueues.forEach((l,u)=>{l.running||this.originQueues.delete(u)});let a=e===null?null:Qr(e),s=this.originQueues.get(a);s||(s=new ie,s.maxJobs=this._maxJobsPerOrigin,s.priorityCallback=this._priorityCallback,this.originQueues.set(a,s));let n=this._itemQueues.get(t);if(n&&n!==s&&n.has(t))throw Error("DownloadPriorityQueue: Item is already queued with a different url origin.");this._itemQueues.set(t,s);let o=s.add(t,i);return r!==null&&(r.aborted?this.remove(t):r.addEventListener("abort",()=>this.remove(t),{once:!0})),o}remove(e){let t=this._itemQueues.get(e);t&&(t.remove(e),this._itemQueues.delete(e))}has(e){let t=this._itemQueues.get(e);return!!(t&&t.has(e))}};var Ee=6378137,zs=1/298.257223563,_i=6356752314245179e-9,_t={inView:!1,error:1/0,distanceFromCamera:1/0};function Et(e){return e===4||e===-1}function ne(e,t){return Pt(e)&&e.traversal.lastFrameVisited===t&&e.traversal.used}function Pt(e){return!!e.traversal}function Je(e){let{children:t}=e,i=t.length===0||Pt(t[t.length-1]),r=!e.internal.hasUnrenderableContent||Et(e.internal.loadingState);return i&&r}function Se(e){return e.traversal.unconditionallyRefine}function Qe(e,t){if(Pt(e)&&(t.ensureChildrenArePreprocessed(e),e.traversal.lastFrameVisited!==t.frameCount&&(e.traversal.wasInFrustum=e.traversal.inFrustum,e.traversal.wasSetActive=e.traversal.active,e.traversal.wasSetVisible=e.traversal.visible,e.traversal.usedLastFrame=e.traversal.used,e.traversal.lastFrameVisited=t.frameCount,e.traversal.used=!1,e.traversal.inFrustum=!1,e.traversal.isLeaf=!1,e.traversal.visible=!1,e.traversal.active=!1,e.traversal.error=1/0,e.traversal.distanceFromCamera=1/0,e.traversal.allChildrenReady=!1,e.traversal.allChildrenLoaded=!1,e.traversal.kicked=!1,e.traversal.allUsedChildrenProcessed=!1,t.calculateTileViewErrorWithPlugin(e,_t),e.traversal.inFrustum=_t.inView,e.traversal.error=_t.error,e.traversal.distanceFromCamera=_t.distanceFromCamera,e.traversal.unconditionallyRefine=e.internal.hasUnrenderableContent,!e.traversal.unconditionallyRefine))){let i=e.parent;for(;i&&i.traversal.unconditionallyRefine;)i=i.parent;i&&i.geometricError<=e.geometricError&&(e.traversal.unconditionallyRefine=!0)}}function vi(e,t,i=!1){if(Qe(e,t),i?t.markTileUsed(e):wt(e),Se(e)&&Je(e)){let r=e.children;for(let a=0,s=r.length;a<s;a++)vi(r[a],t,i)}}function $r(e,t){if(Qe(e,t),e.traversal.usedLastFrame&&(wt(e),e.traversal.wasSetActive&&(e.traversal.active=!0),(!e.traversal.active||Se(e))&&Je(e))){let i=e.children;for(let r=0,a=i.length;r<a;r++)$r(i[r],t)}}function wt(e){e.traversal.used=!0}function Ns(e,t){return!(e.traversal.error<=t.errorTarget&&!Se(e)||t.maxDepth>0&&e.internal.depth+1>=t.maxDepth||!Je(e))}function Zr(e,t){let{frameCount:i}=t,{children:r}=e;for(let a=0,s=r.length;a<s;a++){let n=r[a];ne(n,i)&&(n.traversal.active&&(n.traversal.kicked=!0,n.traversal.active=!1),Zr(n,t))}}function Yr(e){return!Se(e)&&(!e.internal.hasContent||Et(e.internal.loadingState))}function Jr(e,t){if(Qe(e,t),!e.traversal.inFrustum)return;let i=e.parent;if(i&&i.refine==="ADD"&&e.geometricError>0&&e.traversal.error*(i.geometricError/e.geometricError)<=t.errorTarget)return;if(!Ns(e,t)){wt(e);return}let r=!1,a=!1,s=e.children;for(let n=0,o=s.length;n<o;n++){let l=s[n];Jr(l,t),r||(r=ne(l,t.frameCount)),a||(a=l.traversal.inFrustum)}if(e.refine==="REPLACE"&&!a&&s.length!==0){e.traversal.inFrustum=!1,t.markTileUsed(e);for(let n=0,o=s.length;n<o;n++)vi(s[n],t,!0);return}if(wt(e),e.refine==="REPLACE"&&r&&(t.loadSiblings||t.loadAncestors))for(let n=0,o=s.length;n<o;n++)vi(s[n],t)}function Kr(e,t){let i=t.frameCount;if(!ne(e,i))return;let r=e.children,a=!1;for(let n=0,o=r.length;n<o;n++){let l=r[n];a||(a=ne(l,i))}if(!a)e.traversal.isLeaf=!0;else{for(let o=0,l=r.length;o<l;o++)Kr(r[o],t);let n=!0;for(let o=0,l=r.length;o<l;o++){let u=r[o];if(ne(u,i)){let c=!Se(u),h=!u.internal.hasContent||Et(u.internal.loadingState);c&&h||u.traversal.allChildrenLoaded||(n=!1)}}e.traversal.allChildrenLoaded=n}let s=!0;for(let n=0,o=r.length;n<o;n++){let l=r[n];ne(l,t.frameCount)&&!l.traversal.allUsedChildrenProcessed&&(s=!1)}e.traversal.allUsedChildrenProcessed=s&&Je(e)}function ea(e,t){if(!ne(e,t.frameCount))return;let i=e.children;if(e.refine==="REPLACE"&&t.loadAncestors&&!e.traversal.allChildrenLoaded&&!Se(e)&&(e.traversal.isLeaf=!0),e.traversal.isLeaf){if(!Se(e)&&(e.traversal.active=!0,Je(e)&&e.internal.hasContent&&!Et(e.internal.loadingState)))for(let a=0,s=i.length;a<s;a++)$r(i[a],t);return}let r=i.length>0;for(let a=0,s=i.length;a<s;a++){let n=i[a];ea(n,t),ne(n,t.frameCount)&&!(n.traversal.active&&Yr(n))&&!n.traversal.allChildrenReady&&(r=!1)}e.traversal.allChildrenReady=r,e.refine==="REPLACE"&&!r&&e.traversal.wasSetActive&&Yr(e)&&(e.traversal.active=!0,Zr(e,t))}function ta(e,t){Qe(e,t);let i=ne(e,t.frameCount);if(i&&(e.internal.hasUnrenderableContent&&(t.markTileUsed(e),t.queueTileForDownload(e)),e.internal.hasRenderableContent&&e.refine==="ADD"&&(e.traversal.active=!0),(e.traversal.active||e.traversal.kicked)&&e.internal.hasContent&&(t.markTileUsed(e),e.traversal.allUsedChildrenProcessed&&t.queueTileForDownload(e),e.internal.loadingState!==4&&(e.traversal.active=!1)),t.loadAncestors&&e.internal.hasContent&&(t.markTileUsed(e),t.queueTileForDownload(e)),e.internal.virtualChildCount>0&&e.internal.hasContent&&t.markTileUsed(e),e.traversal.visible=e.internal.hasRenderableContent&&e.traversal.active&&e.traversal.inFrustum&&e.internal.loadingState===4,t.stats.used++,e.traversal.inFrustum&&t.stats.inFrustum++),i||Pt(e)&&e.traversal.usedLastFrame){let r=!1,a=!1;i?(r=e.traversal.active,a=t.displayActiveTiles&&e.traversal.active||e.traversal.visible):Qe(e,t),e.internal.hasRenderableContent&&e.internal.loadingState===4?(r&&t.stats.active++,a&&t.stats.visible++,e.traversal.wasSetActive!==r&&t.invokeOnePlugin(n=>n.setTileActive&&n.setTileActive(e,r)),e.traversal.wasSetVisible!==a&&t.invokeOnePlugin(n=>n.setTileVisible&&n.setTileVisible(e,a))):e.internal.hasRenderableContent||(a=e.traversal.isLeaf,e.traversal.wasSetVisible!==a&&t.invokeOnePlugin(n=>n.setEmptyTileVisible&&n.setEmptyTileVisible(e,a))),e.traversal.visible=a,e.traversal.active=r;let s=e.children;for(let n=0,o=s.length;n<o;n++){let l=s[n];ta(l,t)}}}function js(e,t){Jr(e,t),Kr(e,t),ea(e,t),ta(e,t)}function Ws(e){let t=null;return()=>{t===null&&(t=Xe.requestAnimationFrame(()=>{t=null,e()}))}}function Gs(e,t=null,i=null){let r=[];for(r.push(e),r.push(null),r.push(0);r.length>0;){let a=r.pop(),s=r.pop(),n=r.pop();if(t&&t(n,s,a)){i&&i(n,s,a);return}let o=n.children;if(o)for(let l=o.length-1;l>=0;l--)r.push(o[l]),r.push(n),r.push(a+1);i&&i(n,s,a)}}var Xr=Symbol("PLUGIN_REGISTERED"),me={inView:!0,error:0,distance:1/0},qs=(e,t)=>{let i=e.priority||0,r=t.priority||0;return i===r?!e.traversal||!t.traversal?0:e.traversal.used===t.traversal.used?e.traversal.error===t.traversal.error?e.traversal.distanceFromCamera===t.traversal.distanceFromCamera?e.internal.depthFromRenderedParent===t.internal.depthFromRenderedParent?0:e.internal.depthFromRenderedParent>t.internal.depthFromRenderedParent?-1:1:e.traversal.distanceFromCamera>t.traversal.distanceFromCamera?-1:1:e.traversal.error>t.traversal.error?1:-1:e.traversal.used?1:-1:i>r?1:-1},Hs=(e,t)=>e.traversal.used===t.traversal.used?e.traversal.inFrustum===t.traversal.inFrustum?e.internal.hasUnrenderableContent===t.internal.hasUnrenderableContent?e.traversal.distanceFromCamera===t.traversal.distanceFromCamera?e.internal.depthFromRenderedParent===t.internal.depthFromRenderedParent?0:e.internal.depthFromRenderedParent>t.internal.depthFromRenderedParent?-1:1:e.traversal.distanceFromCamera>t.traversal.distanceFromCamera?-1:1:e.internal.hasUnrenderableContent?1:-1:e.traversal.inFrustum?1:-1:e.traversal.used?1:-1,Ys=(e,t)=>e.traversal.lastFrameVisited===t.traversal.lastFrameVisited?e.internal.depthFromRenderedParent===t.internal.depthFromRenderedParent?e.internal.loadingState===t.internal.loadingState?e.internal.hasUnrenderableContent===t.internal.hasUnrenderableContent?e.traversal.error===t.traversal.error?0:e.traversal.error>t.traversal.error?-1:1:e.internal.hasUnrenderableContent?-1:1:e.internal.loadingState>t.internal.loadingState?-1:1:e.internal.depthFromRenderedParent>t.internal.depthFromRenderedParent?1:-1:e.traversal.lastFrameVisited>t.traversal.lastFrameVisited?-1:1,Ue=(e,t)=>{let i=e.priority??1/0,r=t.priority??1/0;if(i!==r)return i>r?1:-1;if(!e.internal||!t.internal)return 0;let a=e.internal.renderer,s=t.internal.renderer,n=!a.loadAncestors,o=!s.loadAncestors;return n&&o?Hs(e,t):qs(e,t)},Ti=new Ze;Ti.unloadPriorityCallback=Ys;var $e=new Ct;$e.maxJobsPerOrigin=25,$e.priorityCallback=Ue;var Mt=new ie;Mt.maxJobs=5,Mt.priorityCallback=Ue;var St=new ie;St.maxJobs=25,St.priorityCallback=(e,t)=>{let i=e.parent,r=t.parent;return i===r?0:i?r?Ue(i,r):-1:1};var wi=class{get root(){let e=this.rootTileset;return e?e.root:null}get loadProgress(){let{stats:e,isLoading:t}=this,i=e.queued+e.downloading+e.parsing,r=e.inCacheSinceLoad+ +!!t;return r===0?1:1-i/r}get downloadQueue(){return this._downloadQueue}set downloadQueue(e){if(e instanceof ie){console.warn('TilesRenderer: "downloadQueue" is no longer valid as a PriorityQueue. Use a DownloadPriorityQueue, instead.');return}this._downloadQueue=e}constructor(e=null){this.rootLoadingState=0,this.rootTileset=null,this.rootURL=e,this.fetchOptions={},this.plugins=[],this.queuedTiles=[],this.cachedSinceLoadComplete=new Set,this.isLoading=!1,this.processedTiles=new WeakSet,this.visibleTiles=new Set,this.activeTiles=new Set,this.usedSet=new Set,this.loadingTiles=new Set,this.lruCache=Ti,this.downloadQueue=$e,this.parseQueue=Mt,this.processNodeQueue=St,this.stats={inCacheSinceLoad:0,inCache:0,queued:0,downloading:0,parsing:0,loaded:0,failed:0,inFrustum:0,used:0,active:0,visible:0,tilesProcessed:0},this.frameCount=0,this._dispatchNeedsUpdateEvent=Ws(()=>{this.dispatchEvent({type:"needs-update"})}),this.errorTarget=16,this.errorFalloff=0,this.errorFalloffDensity=2e-4,this.displayActiveTiles=!1,this.maxDepth=1/0,this.loadSiblings=!0,this.loadAncestors=!0,this.maxTilesProcessed=250}registerPlugin(e){if(e[Xr]===!0)throw Error("TilesRendererBase: A plugin can only be registered to a single tileset");let t=this.plugins,i=e.priority||0,r=t.length;for(let a=0;a<t.length;a++)if((t[a].priority||0)>i){r=a;break}t.splice(r,0,e),e[Xr]=!0,e.init&&e.init(this)}unregisterPlugin(e){let t=this.plugins;if(typeof e=="string"&&(e=this.getPluginByName(e)),t.includes(e)){let i=t.indexOf(e);return t.splice(i,1),e.dispose&&e.dispose(),!0}return!1}getPluginByName(e){return this.plugins.find(t=>t.name===e)||null}invokeOnePlugin(e){let t=[...this.plugins,this];for(let i=0;i<t.length;i++){let r=e(t[i]);if(r)return r}return null}invokeAllPlugins(e){let t=[...this.plugins,this],i=[];for(let r=0;r<t.length;r++){let a=e(t[r]);a&&i.push(a)}return i.length===0?null:Promise.all(i)}traverse(e,t,i=!0){this.root&&Gs(this.root,(r,...a)=>(i&&this.ensureChildrenArePreprocessed(r,!0),e?e(r,...a):!1),t)}getAttributions(e=[]){return this.invokeAllPlugins(t=>t!==this&&t.getAttributions&&t.getAttributions(e)),e}update(){let{lruCache:e,usedSet:t,stats:i,root:r,downloadQueue:a,parseQueue:s,processNodeQueue:n}=this;if(this.rootLoadingState===0&&(this.rootLoadingState=2,this.invokeOnePlugin(u=>u.loadRootTileset&&u.loadRootTileset()).then(u=>{let c=this.rootURL;c!==null&&this.invokeAllPlugins(h=>c=h.preprocessURL?h.preprocessURL(c,null):c),this.rootLoadingState=4,this.rootTileset=u,this.dispatchEvent({type:"needs-update"}),this.dispatchEvent({type:"load-tileset",tileset:u,url:c}),this.dispatchEvent({type:"load-root-tileset",tileset:u,url:c})}).catch(u=>{this.rootLoadingState=-1,console.error(u),this.rootTileset=null,this.dispatchEvent({type:"load-error",tile:null,error:u,url:this.rootURL})})),!r)return;let o=null;if(this.invokeAllPlugins(u=>{if(u.doTilesNeedUpdate){let c=u.doTilesNeedUpdate();o=o===null?c:!!(o||c)}}),o===!1){this.dispatchEvent({type:"update-before"}),this.dispatchEvent({type:"update-after"});return}this.dispatchEvent({type:"update-before"}),i.inFrustum=0,i.used=0,i.active=0,i.visible=0,i.tilesProcessed=0,this.frameCount++,t.forEach(u=>e.markUnused(u)),t.clear(),this.prepareForTraversal(),js(r,this),this.removeUnusedPendingTiles();let l=this.queuedTiles;l.sort(e.unloadPriorityCallback);for(let u=0,c=l.length;u<c&&!e.isFull();u++)this.requestTileContents(l[u]);l.length=0,e.scheduleUnload(),(a.running||s.running||n.running)===!1&&this.isLoading===!0&&(this.cachedSinceLoadComplete.clear(),i.inCacheSinceLoad=0,this.dispatchEvent({type:"tiles-load-end"}),this.isLoading=!1),this.dispatchEvent({type:"update-after"})}resetFailedTiles(){this.rootLoadingState===-1&&(this.rootLoadingState=0);let e=this.stats;e.failed!==0&&(this.traverse(t=>{t.internal.loadingState===-1&&(t.internal.loadingState=0)},null,!1),e.failed=0)}calculateTileViewErrorWithPlugin(e,t){this.calculateTileViewError(e,t);let{errorFalloff:i,errorFalloffDensity:r}=this;if(i>0&&Number.isFinite(t.distanceFromCamera)){let o=t.distanceFromCamera*r;t.error-=i*(1-Math.exp(-o*o))}let a=null,s=0,n=1/0;this.invokeAllPlugins(o=>{o!==this&&o.calculateTileViewError&&(me.inView=!0,me.error=0,me.distance=1/0,o.calculateTileViewError(e,me)&&(a===null&&(a=!0),a&&(a=me.inView),me.inView&&(n=Math.min(n,me.distance),s=Math.max(s,me.error))))}),t.inView&&a!==!1?(t.error=Math.max(t.error,s),t.distanceFromCamera=Math.min(t.distanceFromCamera,n)):a?(t.inView=!0,t.error=s,t.distanceFromCamera=n):t.inView=!1}dispose(){[...this.plugins].forEach(i=>{this.unregisterPlugin(i)});let e=this.lruCache,t=[];this.traverse(i=>(t.push(i),!1),null,!1);for(let i=0,r=t.length;i<r;i++)e.remove(t[i]);this.stats={queued:0,parsing:0,downloading:0,failed:0,inFrustum:0,traversed:0,used:0,active:0,visible:0},this.frameCount=0,this.loadingTiles.clear()}calculateBytesUsed(e,t){return 0}dispatchEvent(e){}addEventListener(e,t){}removeEventListener(e,t){}parseTile(e,t,i){return null}prepareForTraversal(){}disposeTile(e){e.traversal.visible&&(e.internal.hasRenderableContent?this.invokeOnePlugin(i=>i.setTileVisible&&i.setTileVisible(e,!1)):this.invokeOnePlugin(i=>i.setEmptyTileVisible&&i.setEmptyTileVisible(e,!1)),e.traversal.visible=!1),e.traversal.active&&e.internal.hasRenderableContent&&this.invokeOnePlugin(i=>i.setTileActive&&i.setTileActive(e,!1)),e.traversal.active=!1;let{scene:t}=e.engineData;t&&this.dispatchEvent({type:"dispose-model",scene:t,tile:e})}preprocessNode(e,t,i=null){if(this.processedTiles.add(e),this.stats.tilesProcessed++,e.content&&(!("uri"in e.content)&&"url"in e.content&&(e.content.uri=e.content.url,delete e.content.url),e.content.boundingVolume&&!("box"in e.content.boundingVolume||"sphere"in e.content.boundingVolume||"region"in e.content.boundingVolume)&&delete e.content.boundingVolume),e.parent=i,e.children=e.children||[],e.internal={hasContent:!1,hasRenderableContent:!1,hasUnrenderableContent:!1,loadingState:0,basePath:t,depth:-1,depthFromRenderedParent:-1,isVirtual:!1,virtualChildCount:0,renderer:this,...e.internal},e.content?.uri){let r=xi(e.content.uri),a=!!(r&&/json$/.test(r));e.internal.hasContent=!0,e.internal.hasUnrenderableContent=a,e.internal.hasRenderableContent=!a}else e.internal.hasContent=!1,e.internal.hasUnrenderableContent=!1,e.internal.hasRenderableContent=!1;i?(e.internal.depth=i.internal.depth+1,e.internal.depthFromRenderedParent=i.internal.depthFromRenderedParent+ +!!e.internal.hasRenderableContent):(e.internal.depth=0,e.internal.depthFromRenderedParent=+!!e.internal.hasRenderableContent),e.traversal={distanceFromCamera:1/0,error:1/0,inFrustum:!1,wasInFrustum:!1,isLeaf:!1,used:!1,usedLastFrame:!1,visible:!1,wasSetVisible:!1,active:!1,wasSetActive:!1,allChildrenReady:!1,allChildrenLoaded:!1,kicked:!1,allUsedChildrenProcessed:!1,lastFrameVisited:-1},i===null?e.refine=e.refine||"REPLACE":e.refine=e.refine||i.refine,e.engineData={scene:null,metadata:null,boundingVolume:null},Object.defineProperty(e,"cached",{get(){return console.warn('TilesRenderer: "tile.cached" field has been renamed to "tile.engineData".'),this.engineData},enumerable:!1,configurable:!0}),this.invokeAllPlugins(r=>{r!==this&&r.preprocessNode&&r.preprocessNode(e,t,i)})}setTileActive(e,t){t?this.activeTiles.add(e):this.activeTiles.delete(e)}setTileVisible(e,t){t?this.visibleTiles.add(e):this.visibleTiles.delete(e),this.dispatchEvent({type:"tile-visibility-change",scene:e.engineData.scene,tile:e,visible:t})}calculateTileViewError(e,t){}removeUnusedPendingTiles(){let{lruCache:e,loadingTiles:t}=this,i=[];for(let r of t)!e.isUsed(r)&&r.internal.loadingState===1&&i.push(r);for(let r=0;r<i.length;r++)e.remove(i[r])}queueTileForDownload(e){e.internal.loadingState!==0||this.lruCache.isFull()||this.queuedTiles.push(e)}markTileUsed(e){this.usedSet.add(e),this.lruCache.markUsed(e)}fetchData(e,t){return fetch(e,t)}ensureChildrenArePreprocessed(e,t=this.stats.tilesProcessed<this.maxTilesProcessed){let i=e.children;if(i.length===0||i[i.length-1].traversal)return;let r=a=>{for(let s=0,n=a.length;s<n;s++){let o=a[s];o&&!o.traversal&&this.preprocessNode(o,e.internal.basePath,e)}};t?(this.processNodeQueue.remove(e),r(i)):this.processNodeQueue.has(e)||this.processNodeQueue.add(e,a=>{r(a.children),this._dispatchNeedsUpdateEvent()})}getBytesUsed(e){let t=0;return this.invokeAllPlugins(i=>{i.calculateBytesUsed&&(t+=i.calculateBytesUsed(e,e.engineData.scene)||0)}),t}recalculateBytesUsed(e=null){let{lruCache:t,processedTiles:i}=this;e===null?t.itemSet.forEach(r=>{i.has(r)&&t.setMemoryUsage(r,this.getBytesUsed(r))}):t.setMemoryUsage(e,this.getBytesUsed(e))}preprocessTileset(e,t,i=null){let[r,a]=e.asset.version.split(".").map(n=>parseInt(n));console.assert(r<=1,"TilesRenderer: asset.version is expected to be a 1.x or a compatible version."),r===1&&a>0&&console.warn("TilesRenderer: tiles versions at 1.1 or higher have limited support. Some new extensions and features may not be supported.");let s=t.replace(/\/[^/]*$/,"");s=new URL(s,window.location.href).toString(),this.preprocessNode(e.root,s,i)}loadRootTileset(){let e=this.rootURL;return this.invokeAllPlugins(t=>e=t.preprocessURL?t.preprocessURL(e,null):e),this.invokeOnePlugin(t=>t.fetchData&&t.fetchData(e,this.fetchOptions)).then(t=>{if(!(t instanceof Response))return t;if(t.ok)return t.json();throw Error(`TilesRenderer: Failed to load tileset "${e}" with status ${t.status} : ${t.statusText}`)}).then(t=>(this.preprocessTileset(t,e),t))}requestTileContents(e){if(e.internal.loadingState!==0)return;let t=!1,i=null,r=new URL(e.content.uri,e.internal.basePath+"/").toString();this.invokeAllPlugins(m=>r=m.preprocessURL?m.preprocessURL(r,e):r);let a=this.stats,s=this.lruCache,n=this.downloadQueue,o=this.parseQueue,l=this.loadingTiles,u=xi(r),c=new AbortController,h=c.signal;if(s.add(e,m=>{c.abort(),t?m.children.length=0:this.invokeAllPlugins(d=>{d.disposeTile&&d.disposeTile(m)}),a.inCache--,this.cachedSinceLoadComplete.has(e)&&(this.cachedSinceLoadComplete.delete(e),a.inCacheSinceLoad--),m.internal.loadingState===1?a.queued--:m.internal.loadingState===2?a.downloading--:m.internal.loadingState===3?a.parsing--:m.internal.loadingState===4&&a.loaded--,m.internal.loadingState=0,o.remove(m),n.remove(m),l.delete(m)}))return this.isLoading||(this.isLoading=!0,this.dispatchEvent({type:"tiles-load-start"})),s.setMemoryUsage(e,this.getBytesUsed(e)),this.cachedSinceLoadComplete.add(e),a.inCacheSinceLoad++,a.inCache++,a.queued++,e.internal.loadingState=1,l.add(e),n.add(r,e,m=>{if(h.aborted)return Promise.resolve();e.internal.loadingState=2,a.downloading++,a.queued--;let d=this.invokeOnePlugin(p=>p.fetchData&&p.fetchData(r,{...this.fetchOptions,signal:h}));return this.dispatchEvent({type:"tile-download-start",tile:e,url:r,get uri(){return console.warn('tile-download-start event: "uri" has been renamed to "url".'),this.url}}),d}).then(m=>{if(!h.aborted){if(!(m instanceof Response))return m;if(m.ok)return u==="json"?m.json():m.arrayBuffer();throw Error(`Failed to load model with error code ${m.status}`)}}).then(m=>{if(!h.aborted)return a.downloading--,a.parsing++,e.internal.loadingState=3,o.add(e,d=>h.aborted?Promise.resolve():u==="json"&&m.root?(this.preprocessTileset(m,r,e),e.children.push(m.root),i=m,t=!0,Promise.resolve()):this.invokeOnePlugin(p=>p.parseTile&&p.parseTile(m,d,u,r,h)))}).then(()=>{if(h.aborted)return;a.parsing--,a.loaded++,e.internal.loadingState=4,l.delete(e),s.setLoaded(e,!0);let m=this.getBytesUsed(e);if(s.getMemoryUsage(e)===0&&m>0&&s.isFull()){s.remove(e);return}s.setMemoryUsage(e,m),this.dispatchEvent({type:"needs-update"}),t&&this.dispatchEvent({type:"load-tileset",tileset:i,url:r}),e.engineData.scene&&this.dispatchEvent({type:"load-model",scene:e.engineData.scene,tile:e,url:r})}).catch(m=>{h.aborted||(m.name==="AbortError"?s.remove(e):(o.remove(e),n.remove(e),e.internal.loadingState===1?a.queued--:e.internal.loadingState===2?a.downloading--:e.internal.loadingState===3?a.parsing--:e.internal.loadingState===4&&a.loaded--,a.failed++,console.error(`TilesRenderer : Failed to load tile at url "${e.content.uri}".`),console.error(m),e.internal.loadingState=-1,l.delete(e),s.setLoaded(e,!0),this.dispatchEvent({type:"load-error",tile:e,error:m,url:r})))})}};function Ce(e){if(e===null||e.byteLength<4)return"";let t;if(t=e instanceof DataView?e:new DataView(e),String.fromCharCode(t.getUint8(0))==="{")return null;let i="";for(let r=0;r<4;r++)i+=String.fromCharCode(t.getUint8(r));return i}var Xs=new TextDecoder;function ia(e){return Xs.decode(e)}function At(e){return e.replace(/[\\/][^\\/]+$/,"")+"/"}var Be=class{constructor(){this.fetchOptions={},this.workingPath=""}loadAsync(e){return fetch(e,this.fetchOptions).then(t=>{if(!t.ok)throw Error(`Failed to load file "${e}" with status ${t.status} : ${t.statusText}`);return t.arrayBuffer()}).then(t=>(this.workingPath===""&&(this.workingPath=At(e)),this.parse(t)))}resolveExternalURL(e){return new URL(e,this.workingPath).href}parse(e){throw Error("LoaderBase: Parse not implemented.")}};function Mi(e,t,i,r,a,s){let n;switch(r){case"SCALAR":n=1;break;case"VEC2":n=2;break;case"VEC3":n=3;break;case"VEC4":n=4;break;default:throw Error(`FeatureTable : Feature type not provided for "${s}".`)}let o,l=i*n;switch(a){case"BYTE":o=new Int8Array(e,t,l);break;case"UNSIGNED_BYTE":o=new Uint8Array(e,t,l);break;case"SHORT":o=new Int16Array(e,t,l);break;case"UNSIGNED_SHORT":o=new Uint16Array(e,t,l);break;case"INT":o=new Int32Array(e,t,l);break;case"UNSIGNED_INT":o=new Uint32Array(e,t,l);break;case"FLOAT":o=new Float32Array(e,t,l);break;case"DOUBLE":o=new Float64Array(e,t,l);break;default:throw Error(`FeatureTable : Feature component type not provided for "${s}".`)}return o}var Ke=class{constructor(e,t,i,r){this.buffer=e,this.binOffset=t+i,this.binLength=r;let a=null;if(i!==0){let s=new Uint8Array(e,t,i);a=JSON.parse(ia(s))}else a={};this.header=a}getKeys(){return Object.keys(this.header).filter(e=>e!=="extensions")}getData(e,t,i=null,r=null){let a=this.header;if(!(e in a))return null;let s=a[e];if(!(s instanceof Object)||Array.isArray(s))return s;{let{buffer:n,binOffset:o,binLength:l}=this,u=s.byteOffset||0,c=s.type||r,h=s.componentType||i;if("type"in s&&r&&s.type!==r)throw Error("FeatureTable: Specified type does not match expected type.");let m=o+u,d=Mi(n,m,t,c,h,e);if(m+d.byteLength>o+l)throw Error("FeatureTable: Feature data read outside binary body length.");return d}}getBuffer(e,t){let{buffer:i,binOffset:r}=this;return i.slice(r+e,r+e+t)}},Qs=class{constructor(e){this.batchTable=e;let t=e.header.extensions["3DTILES_batch_table_hierarchy"];this.classes=t.classes;for(let r of this.classes){let a=r.instances;for(let s in a)r.instances[s]=this._parseProperty(a[s],r.length,s)}if(this.instancesLength=t.instancesLength,this.classIds=this._parseProperty(t.classIds,this.instancesLength,"classIds"),t.parentCounts?this.parentCounts=this._parseProperty(t.parentCounts,this.instancesLength,"parentCounts"):this.parentCounts=Array(this.instancesLength).fill(1),t.parentIds){let r=this.parentCounts.reduce((a,s)=>a+s,0);this.parentIds=this._parseProperty(t.parentIds,r,"parentIds")}else this.parentIds=null;this.instancesIds=[];let i={};for(let r of this.classIds)i[r]=i[r]??0,this.instancesIds.push(i[r]),i[r]++}_parseProperty(e,t,i){if(Array.isArray(e))return e;{let{buffer:r,binOffset:a}=this.batchTable,s=e.byteOffset,n=e.componentType||"UNSIGNED_SHORT";return Mi(r,a+s,t,"SCALAR",n,i)}}getDataFromId(e,t={}){let i=this.parentCounts[e];if(this.parentIds&&i>0){let o=0;for(let l=0;l<e;l++)o+=this.parentCounts[l];for(let l=0;l<i;l++){let u=this.parentIds[o+l];u!==e&&this.getDataFromId(u,t)}}let r=this.classIds[e],a=this.classes[r].instances,s=this.classes[r].name,n=this.instancesIds[e];for(let o in a)t[s]=t[s]||{},t[s][o]=a[o][n];return t}},Lt=class extends Ke{constructor(e,t,i,r,a){super(e,i,r,a),this.count=t,this.extensions={};let s=this.header.extensions;s&&s["3DTILES_batch_table_hierarchy"]&&(this.extensions["3DTILES_batch_table_hierarchy"]=new Qs(this))}getDataFromId(e,t={}){if(e<0||e>=this.count)throw Error(`BatchTable: id value "${e}" out of bounds for "${this.count}" features number.`);for(let i of this.getKeys())t[i]=super.getData(i,this.count)[e];for(let i in this.extensions){let r=this.extensions[i];r.getDataFromId instanceof Function&&(t[i]=t[i]||{},r.getDataFromId(e,t[i]))}return t}getPropertyArray(e){return super.getData(e,this.count)}},Si=class extends Be{parse(e){let t=new DataView(e),i=Ce(t);console.assert(i==="b3dm");let r=t.getUint32(4,!0);console.assert(r===1);let a=t.getUint32(8,!0);console.assert(a===e.byteLength);let s=t.getUint32(12,!0),n=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),u=new Ke(e.slice(28,28+s+n),0,s,n),c=28+s+n,h=new Lt(e.slice(c,c+o+l),u.getData("BATCH_LENGTH"),0,o,l),m=c+o+l;return{version:r,featureTable:u,batchTable:h,glbBytes:new Uint8Array(e,m,a-m)}}},Ci=class extends Be{parse(e){let t=new DataView(e),i=Ce(t);console.assert(i==="i3dm");let r=t.getUint32(4,!0);console.assert(r===1);let a=t.getUint32(8,!0);console.assert(a===e.byteLength);let s=t.getUint32(12,!0),n=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),u=t.getUint32(28,!0),c=new Ke(e.slice(32,32+s+n),0,s,n),h=32+s+n,m=new Lt(e.slice(h,h+o+l),c.getData("INSTANCES_LENGTH"),0,o,l),d=h+o+l,p=new Uint8Array(e,d,a-d),y=null,M=null,_=null;if(u)y=p,M=Promise.resolve();else{let C=this.resolveExternalURL(ia(p));_=At(C),M=fetch(C,this.fetchOptions).then(g=>{if(!g.ok)throw Error(`I3DMLoaderBase : Failed to load file "${C}" with status ${g.status} : ${g.statusText}`);return g.arrayBuffer()}).then(g=>{y=new Uint8Array(g)})}return M.then(()=>({version:r,featureTable:c,batchTable:m,glbBytes:y,gltfWorkingPath:_}))}},Ei=class extends Be{parse(e){let t=new DataView(e),i=Ce(t);console.assert(i==="pnts");let r=t.getUint32(4,!0);console.assert(r===1);let a=t.getUint32(8,!0);console.assert(a===e.byteLength);let s=t.getUint32(12,!0),n=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),u=new Ke(e.slice(28,28+s+n),0,s,n),c=28+s+n,h=new Lt(e.slice(c,c+o+l),u.getData("BATCH_LENGTH")||u.getData("POINTS_LENGTH"),0,o,l);return Promise.resolve({version:r,featureTable:u,batchTable:h})}},Pi=class extends Be{parse(e){let t=new DataView(e),i=Ce(t);console.assert(i==="cmpt",'CMPTLoader: The magic bytes equal "cmpt".');let r=t.getUint32(4,!0);console.assert(r===1,'CMPTLoader: The version listed in the header is "1".');let a=t.getUint32(8,!0);console.assert(a===e.byteLength,"CMPTLoader: The contents buffer length listed in the header matches the file.");let s=t.getUint32(12,!0),n=[],o=16;for(let l=0;l<s;l++){let u=new DataView(e,o,12),c=Ce(u),h=u.getUint32(4,!0),m=u.getUint32(8,!0),d=new Uint8Array(e,o,m);n.push({type:c,buffer:d,version:h}),o+=m}return{version:r,tiles:n}}};import{Box3 as ba,BufferAttribute as Pe,BufferGeometry as $s,Clock as wl,Color as Zs,DefaultLoadingManager as zt,Euler as Js,EventDispatcher as It,Frustum as Ks,Group as Fi,InstancedMesh as en,LoadingManager as tn,MathUtils as xa,Matrix3 as rn,Matrix4 as k,Mesh as Ml,OrthographicCamera as Sl,PerspectiveCamera as Cl,Plane as an,PlaneGeometry as El,Points as sn,PointsMaterial as nn,Quaternion as va,Ray as Vi,Raycaster as Pl,ShaderMaterial as Al,Sphere as _a,Spherical as on,TextureUtils as ln,Vector2 as zi,Vector3 as E}from"three";import{GLTFLoader as Ni}from"three/addons/loaders/GLTFLoader.js";import{estimateBytesUsed as hn}from"three/addons/utils/BufferGeometryUtils.js";var ji=class extends Si{constructor(e=zt){super(),this.manager=e,this.adjustmentTransform=new k}parse(e){let t=super.parse(e),i=t.glbBytes.slice().buffer;return new Promise((r,a)=>{let s=this.manager,n=this.fetchOptions,o=s.getHandler("path.gltf")||new Ni(s);n.credentials==="include"&&n.mode==="cors"&&o.setCrossOrigin("use-credentials"),"credentials"in n&&o.setWithCredentials(n.credentials==="include"),n.headers&&o.setRequestHeader(n.headers);let l=this.workingPath;!/[\\/]$/.test(l)&&l.length&&(l+="/");let u=this.adjustmentTransform;o.parse(i,l,c=>{let{batchTable:h,featureTable:m}=t,{scene:d}=c,p=m.getData("RTC_CENTER",1,"FLOAT","VEC3");p&&(d.position.x+=p[0],d.position.y+=p[1],d.position.z+=p[2]),c.scene.updateMatrix(),c.scene.matrix.multiply(u),c.scene.matrix.decompose(c.scene.position,c.scene.quaternion,c.scene.scale),c.batchTable=h,c.featureTable=m,d.batchTable=h,d.featureTable=m,r(c)},a)})}};function un(e){let t=e>>11,i=e>>5&63,r=e&31;return[Math.round(t/31*255),Math.round(i/63*255),Math.round(r/31*255)]}var et=new zi;function cn(e,t,i=new E){et.set(e,t).divideScalar(256).multiplyScalar(2).subScalar(1),i.set(et.x,et.y,1-Math.abs(et.x)-Math.abs(et.y));let r=xa.clamp(-i.z,0,1);return i.x>=0?i.setX(i.x-r):i.setX(i.x+r),i.y>=0?i.setY(i.y-r):i.setY(i.y+r),i.normalize(),i}var ra={RGB:"color",POSITION:"position"},Wi=class extends Ei{constructor(e=zt){super(),this.manager=e}parse(e){return super.parse(e).then(async t=>{let{featureTable:i,batchTable:r}=t,a=new nn,s=i.header.extensions,n=new E,o;if(s&&s["3DTILES_draco_point_compression"]){let{byteOffset:c,byteLength:h,properties:m}=s["3DTILES_draco_point_compression"],d=this.manager.getHandler("draco.drc");if(d==null)throw Error("PNTSLoader: dracoLoader not available.");let p={};for(let _ in m)if(_ in ra&&_ in m){let C=ra[_];p[C]=m[_]}let y={attributeIDs:p,attributeTypes:{position:"Float32Array",color:"Uint8Array"},useUniqueIDs:!0},M=i.getBuffer(c,h);o=await d.decodeGeometry(M,y),o.attributes.color&&(a.vertexColors=!0)}else{let c=i.getData("POINTS_LENGTH"),h=i.getData("POSITION",c,"FLOAT","VEC3"),m=i.getData("NORMAL",c,"FLOAT","VEC3"),d=i.getData("NORMAL",c,"UNSIGNED_BYTE","VEC2"),p=i.getData("RGB",c,"UNSIGNED_BYTE","VEC3"),y=i.getData("RGBA",c,"UNSIGNED_BYTE","VEC4"),M=i.getData("RGB565",c,"UNSIGNED_SHORT","SCALAR"),_=i.getData("CONSTANT_RGBA",c,"UNSIGNED_BYTE","VEC4"),C=i.getData("POSITION_QUANTIZED",c,"UNSIGNED_SHORT","VEC3"),g=i.getData("QUANTIZED_VOLUME_SCALE",c,"FLOAT","VEC3"),P=i.getData("QUANTIZED_VOLUME_OFFSET",c,"FLOAT","VEC3");if(o=new $s,C){let S=new Float32Array(c*3);for(let v=0;v<c;v++)for(let L=0;L<3;L++){let w=3*v+L;S[w]=C[w]/65535*g[L]}n.x=P[0],n.y=P[1],n.z=P[2],o.setAttribute("position",new Pe(S,3,!1))}else o.setAttribute("position",new Pe(h,3,!1));if(m!==null)o.setAttribute("normal",new Pe(m,3,!1));else if(d!==null){let S=new Float32Array(c*3),v=new E;for(let L=0;L<c;L++){let w=d[L*2],U=d[L*2+1],O=cn(w,U,v);S[L*3]=O.x,S[L*3+1]=O.y,S[L*3+2]=O.z}o.setAttribute("normal",new Pe(S,3,!1))}if(y!==null)o.setAttribute("color",new Pe(y,4,!0)),a.vertexColors=!0,a.transparent=!0,a.depthWrite=!1;else if(p!==null)o.setAttribute("color",new Pe(p,3,!0)),a.vertexColors=!0;else if(M!==null){let S=new Uint8Array(c*3);for(let v=0;v<c;v++){let L=un(M[v]);for(let w=0;w<3;w++){let U=3*v+w;S[U]=L[w]}}o.setAttribute("color",new Pe(S,3,!0)),a.vertexColors=!0}else if(_!==null){a.color=new Zs(_[0],_[1],_[2]);let S=_[3]/255;S<1&&(a.opacity=S,a.transparent=!0,a.depthWrite=!1)}}let l=new sn(o,a);l.position.copy(n),t.scene=l,t.scene.featureTable=i,t.scene.batchTable=r;let u=i.getData("RTC_CENTER",1,"FLOAT","VEC3");return u&&(t.scene.position.x+=u[0],t.scene.position.y+=u[1],t.scene.position.z+=u[2]),t})}};function dn(e){let{x:t,y:i,z:r}=e;e.x=r,e.y=t,e.z=i}function pn(e){return-e+Math.PI/2}var aa=new on,ge=new E,j=new E,Ai=new E,Z=new k,re=new k,Li=new _a,G=new Js,sa=new E,na=new E,oa=new E,tt=new E,Dt=new Vi,mn=1e-12,gn=.1;var Gi=class{constructor(e=1,t=1,i=1){this.name="",this.radius=new E(e,t,i)}intersectRay(e,t){return Z.makeScale(...this.radius).invert(),Li.center.set(0,0,0),Li.radius=1,Dt.copy(e).applyMatrix4(Z),Dt.intersectSphere(Li,t)?(Z.makeScale(...this.radius),t.applyMatrix4(Z),t):null}getEastNorthUpFrame(e,t,i,r){return i.isMatrix4&&(r=i,i=0,console.warn('Ellipsoid: The signature for "getEastNorthUpFrame" has changed.')),this.getEastNorthUpAxes(e,t,sa,na,oa),this.getCartographicToPosition(e,t,i,tt),r.makeBasis(sa,na,oa).setPosition(tt)}getOrientedEastNorthUpFrame(e,t,i,r,a,s,n){return this.getObjectFrame(e,t,i,r,a,s,n,0)}getObjectFrame(e,t,i,r,a,s,n,o=2){return this.getEastNorthUpFrame(e,t,i,Z),G.set(a,s,-r,"ZXY"),n.makeRotationFromEuler(G).premultiply(Z),o===1?(G.set(Math.PI/2,0,0,"XYZ"),re.makeRotationFromEuler(G),n.multiply(re)):o===2&&(G.set(-Math.PI/2,0,Math.PI,"XYZ"),re.makeRotationFromEuler(G),n.multiply(re)),n}getCartographicFromObjectFrame(e,t,i=2){return i===1?(G.set(-Math.PI/2,0,0,"XYZ"),re.makeRotationFromEuler(G).premultiply(e)):i===2?(G.set(-Math.PI/2,0,Math.PI,"XYZ"),re.makeRotationFromEuler(G).premultiply(e)):re.copy(e),tt.setFromMatrixPosition(re),this.getPositionToCartographic(tt,t),this.getEastNorthUpFrame(t.lat,t.lon,0,Z).invert(),re.premultiply(Z),G.setFromRotationMatrix(re,"ZXY"),t.azimuth=-G.z,t.elevation=G.x,t.roll=G.y,t}getEastNorthUpAxes(e,t,i,r,a,s=tt){this.getCartographicToPosition(e,t,0,s),this.getCartographicToNormal(e,t,a),i.set(-s.y,s.x,0).normalize(),r.crossVectors(a,i).normalize()}getCartographicToPosition(e,t,i,r){this.getCartographicToNormal(e,t,ge);let a=this.radius;j.copy(ge),j.x*=a.x**2,j.y*=a.y**2,j.z*=a.z**2;let s=Math.sqrt(ge.dot(j));return j.divideScalar(s),r.copy(j).addScaledVector(ge,i)}getPositionToCartographic(e,t){this.getPositionToSurfacePoint(e,j),this.getPositionToNormal(j,ge);let i=Ai.subVectors(e,j);return t.lon=Math.atan2(ge.y,ge.x),t.lat=Math.asin(ge.z),t.height=Math.sign(i.dot(e))*i.length(),t}getCartographicToNormal(e,t,i){return aa.set(1,pn(e),t),i.setFromSpherical(aa).normalize(),dn(i),i}getPositionToNormal(e,t){let i=this.radius;return t.copy(e),t.x/=i.x**2,t.y/=i.y**2,t.z/=i.z**2,t.normalize(),t}getPositionToSurfacePoint(e,t){let i=this.radius,r=1/i.x**2,a=1/i.y**2,s=1/i.z**2,n=e.x*e.x*r,o=e.y*e.y*a,l=e.z*e.z*s,u=n+o+l,c=Math.sqrt(1/u),h=j.copy(e).multiplyScalar(c);if(u<gn)return isFinite(c)?t.copy(h):null;let m=Ai.set(h.x*r*2,h.y*a*2,h.z*s*2),d=(1-c)*e.length()/(.5*m.length()),p=0,y,M,_,C,g,P,S,v,L,w,U;do{d-=p,_=1/(1+d*r),C=1/(1+d*a),g=1/(1+d*s),P=_*_,S=C*C,v=g*g,L=P*_,w=S*C,U=v*g,y=n*P+o*S+l*v-1,M=n*L*r+o*w*a+l*U*s;let O=-2*M;p=y/O}while(Math.abs(y)>mn);return t.set(e.x*_,e.y*C,e.z*g)}calculateHorizonDistance(e,t){let i=this.calculateEffectiveRadius(e);return Math.sqrt(2*i*t+t**2)}calculateEffectiveRadius(e){let t=this.radius.x,i=1-this.radius.z**2/t**2,r=e*xa.DEG2RAD,a=Math.sin(r)**2;return t/Math.sqrt(1-i*a)}getPositionElevation(e){this.getPositionToSurfacePoint(e,j);let t=Ai.subVectors(e,j);return Math.sign(t.dot(e))*t.length()}closestPointToRayEstimate(e,t){return this.intersectRay(e,t)?t:(Z.makeScale(...this.radius).invert(),Dt.copy(e).applyMatrix4(Z),j.set(0,0,0),Dt.closestPointToPoint(j,t).normalize(),Z.makeScale(...this.radius),t.applyMatrix4(Z))}copy(e){return this.radius.copy(e.radius),this}clone(){return new this.constructor().copy(this)}},nt=new Gi(Ee,Ee,_i);nt.name="WGS84 Earth";var Rt=new E,ke=new E,Fe=new E,Ii=new E,Ot=new va,Ut=new E,Ve=new k,la=new k,ha=new E,ua=new k,Di=new va,Ri={};function ca(e,t,i,r){if(e=e/i*2-1,t=t/i*2-1,r.x=e,r.y=t,r.z=1-Math.abs(e)-Math.abs(t),r.z<0){let a=r.x;r.x=(1-Math.abs(r.y))*(a>=0?1:-1),r.y=(1-Math.abs(a))*(r.y>=0?1:-1)}return r.normalize(),r}var qi=class extends Ci{constructor(e=zt){super(),this.manager=e,this.adjustmentTransform=new k,this.ellipsoid=nt.clone()}resolveExternalURL(e){return this.manager.resolveURL(super.resolveExternalURL(e))}parse(e){return super.parse(e).then(t=>{let{featureTable:i,batchTable:r}=t,a=t.glbBytes.slice().buffer;return new Promise((s,n)=>{let o=this.fetchOptions,l=this.manager,u=l.getHandler("path.gltf")||new Ni(l);o.credentials==="include"&&o.mode==="cors"&&u.setCrossOrigin("use-credentials"),"credentials"in o&&u.setWithCredentials(o.credentials==="include"),o.headers&&u.setRequestHeader(o.headers);let c=t.gltfWorkingPath??this.workingPath;/[\\/]$/.test(c)||(c+="/");let h=this.adjustmentTransform;u.parse(a,c,m=>{let d=i.getData("INSTANCES_LENGTH"),p=i.getData("POSITION",d,"FLOAT","VEC3"),y=i.getData("POSITION_QUANTIZED",d,"UNSIGNED_SHORT","VEC3"),M=i.getData("QUANTIZED_VOLUME_OFFSET",1,"FLOAT","VEC3"),_=i.getData("QUANTIZED_VOLUME_SCALE",1,"FLOAT","VEC3"),C=i.getData("NORMAL_UP",d,"FLOAT","VEC3"),g=i.getData("NORMAL_RIGHT",d,"FLOAT","VEC3"),P=i.getData("NORMAL_UP_OCT32P",d,"UNSIGNED_SHORT","VEC2"),S=i.getData("NORMAL_RIGHT_OCT32P",d,"UNSIGNED_SHORT","VEC2"),v=i.getData("SCALE_NON_UNIFORM",d,"FLOAT","VEC3"),L=i.getData("SCALE",d,"FLOAT","SCALAR"),w=i.getData("RTC_CENTER",1,"FLOAT","VEC3"),U=i.getData("EAST_NORTH_UP");if(!p&&y){p=new Float32Array(d*3);for(let f=0;f<d;f++)p[f*3+0]=M[0]+y[f*3+0]/65535*_[0],p[f*3+1]=M[1]+y[f*3+1]/65535*_[1],p[f*3+2]=M[2]+y[f*3+2]/65535*_[2]}let O=new E;for(let f=0;f<d;f++)O.x+=p[f*3+0]/d,O.y+=p[f*3+1]/d,O.z+=p[f*3+2]/d;let V=[],ue=[];m.scene.updateMatrixWorld(),m.scene.traverse(f=>{if(f.isMesh){ue.push(f);let{geometry:J,material:Le}=f,Q=new en(J,Le,d);Q.position.copy(O),w&&(Q.position.x+=w[0],Q.position.y+=w[1],Q.position.z+=w[2]),V.push(Q)}});for(let f=0;f<d;f++){Ii.set(p[f*3+0]-O.x,p[f*3+1]-O.y,p[f*3+2]-O.z),Ot.identity(),C&&g?(ke.set(C[f*3+0],C[f*3+1],C[f*3+2]),Fe.set(g[f*3+0],g[f*3+1],g[f*3+2]),Rt.crossVectors(Fe,ke).normalize(),Ve.makeBasis(Fe,ke,Rt),Ot.setFromRotationMatrix(Ve)):P&&S&&(ca(P[f*2+0],P[f*2+1],65535,ke),ca(S[f*2+0],S[f*2+1],65535,Fe),Rt.crossVectors(Fe,ke).normalize(),Ve.makeBasis(Fe,ke,Rt),Ot.setFromRotationMatrix(Ve)),Ut.set(1,1,1),v&&Ut.set(v[f*3+0],v[f*3+1],v[f*3+2]),L&&Ut.multiplyScalar(L[f]);for(let J=0,Le=V.length;J<Le;J++){let Q=V[J];Di.copy(Ot),U&&(Q.updateMatrixWorld(),ha.copy(Ii).applyMatrix4(Q.matrixWorld),this.ellipsoid.getPositionToCartographic(ha,Ri),this.ellipsoid.getEastNorthUpFrame(Ri.lat,Ri.lon,ua),Di.setFromRotationMatrix(ua)),Ve.compose(Ii,Di,Ut).multiply(h);let $=ue[J];la.multiplyMatrices(Ve,$.matrixWorld),Q.setMatrixAt(f,la)}}m.scene.clear(),m.scene.add(...V),m.batchTable=r,m.featureTable=i,m.scene.batchTable=r,m.scene.featureTable=i,s(m)},n)})})}},Ta=class extends Pi{constructor(e=zt){super(),this.manager=e,this.adjustmentTransform=new k,this.ellipsoid=nt.clone()}parse(e){let t=super.parse(e),{manager:i,ellipsoid:r,adjustmentTransform:a}=this,s=[];for(let n in t.tiles){let{type:o,buffer:l}=t.tiles[n];switch(o){case"b3dm":{let u=l.slice(),c=new ji(i);c.workingPath=this.workingPath,c.fetchOptions=this.fetchOptions,c.adjustmentTransform.copy(a);let h=c.parse(u.buffer);s.push(h);break}case"pnts":{let u=l.slice(),c=new Wi(i);c.workingPath=this.workingPath,c.fetchOptions=this.fetchOptions;let h=c.parse(u.buffer);s.push(h);break}case"i3dm":{let u=l.slice(),c=new qi(i);c.workingPath=this.workingPath,c.fetchOptions=this.fetchOptions,c.ellipsoid.copy(r),c.adjustmentTransform.copy(a);let h=c.parse(u.buffer);s.push(h);break}}}return Promise.all(s).then(n=>{let o=new Fi;return n.forEach(l=>{o.add(l.scene)}),{tiles:n,scene:o}})}},it=new k,fn=class extends Fi{constructor(e){super(),this.isTilesGroup=!0,this.name="TilesRenderer.TilesGroup",this.tilesRenderer=e,this.matrixWorldInverse=new k}raycast(e,t){return this.tilesRenderer.raycast(e,t),!1}updateMatrixWorld(e){if(this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldNeedsUpdate||e){this.parent===null?it.copy(this.matrix):it.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1;let t=it.elements,i=this.matrixWorld.elements,r=!1;for(let a=0;a<16;a++){let s=t[a],n=i[a];if(Math.abs(s-n)>2**-52){r=!0;break}}if(r){this.matrixWorld.copy(it),this.matrixWorldInverse.copy(it).invert();let a=this.children;for(let l=0,u=a.length;l<u;l++)a[l].updateMatrixWorld();let{tilesRenderer:s}=this,{activeTiles:n,visibleTiles:o}=s;n.forEach(l=>{o.has(l)||l.engineData.scene.updateMatrixWorld(!0)})}}}updateWorldMatrix(e,t){this.parent&&e&&this.parent.updateWorldMatrix(e,!1),this.updateMatrixWorld(!0)}},yn=new Vi;function bn(e,t,i,r){let{scene:a}=e.engineData;i.invokeOnePlugin(s=>s.raycastTile&&s.raycastTile(e,a,t,r))||t.intersectObject(a,!0,r)}function xn(e){return"traversal"in e}function wa(e,t,i,r,a=null){if(!xn(t))return;let{group:s,activeTiles:n}=e,{boundingVolume:o}=t.engineData;if(a===null&&(a=yn,a.copy(i.ray).applyMatrix4(s.matrixWorldInverse)),!t.traversal.used||!o.intersectsRay(a))return;n.has(t)&&bn(t,i,e,r);let l=t.children;for(let u=0,c=l.length;u<c;u++)wa(e,l[u],i,r,a)}var Bt=new E,kt=new E,q=new E,Ft=new Vi,Bi=class{constructor(e=new ba,t=new k){this.box=e.clone(),this.transform=t.clone(),this.inverseTransform=new k,this.points=Array(8).fill().map(()=>new E),this.planes=[,,,,,,].fill().map(()=>new an)}copy(e){return this.box.copy(e.box),this.transform.copy(e.transform),this.update(),this}clone(){return new this.constructor().copy(this)}clampPoint(e,t){return t.copy(e).applyMatrix4(this.inverseTransform).clamp(this.box.min,this.box.max).applyMatrix4(this.transform)}distanceToPoint(e){return this.clampPoint(e,q).distanceTo(e)}containsPoint(e){return q.copy(e).applyMatrix4(this.inverseTransform),this.box.containsPoint(q)}intersectsRay(e){return Ft.copy(e).applyMatrix4(this.inverseTransform),Ft.intersectsBox(this.box)}intersectRay(e,t){return Ft.copy(e).applyMatrix4(this.inverseTransform),Ft.intersectBox(this.box,t)?(t.applyMatrix4(this.transform),t):null}update(){let{points:e,inverseTransform:t,transform:i,box:r}=this;t.copy(i).invert();let{min:a,max:s}=r,n=0;for(let o=-1;o<=1;o+=2)for(let l=-1;l<=1;l+=2)for(let u=-1;u<=1;u+=2)e[n].set(o<0?a.x:s.x,l<0?a.y:s.y,u<0?a.z:s.z).applyMatrix4(i),n++;this.updatePlanes()}updatePlanes(){Bt.copy(this.box.min).applyMatrix4(this.transform),kt.copy(this.box.max).applyMatrix4(this.transform),q.set(0,0,1).transformDirection(this.transform),this.planes[0].setFromNormalAndCoplanarPoint(q,Bt),this.planes[1].setFromNormalAndCoplanarPoint(q,kt).negate(),q.set(0,1,0).transformDirection(this.transform),this.planes[2].setFromNormalAndCoplanarPoint(q,Bt),this.planes[3].setFromNormalAndCoplanarPoint(q,kt).negate(),q.set(1,0,0).transformDirection(this.transform),this.planes[4].setFromNormalAndCoplanarPoint(q,Bt),this.planes[5].setFromNormalAndCoplanarPoint(q,kt).negate()}intersectsSphere(e){return this.clampPoint(e.center,q),q.distanceToSquared(e.center)<=e.radius*e.radius}intersectsFrustum(e){return this._intersectsPlaneShape(e.planes,e.points)}intersectsOBB(e){return this._intersectsPlaneShape(e.planes,e.points)}_intersectsPlaneShape(e,t){let i=this.points,r=this.planes;for(let a=0;a<6;a++){let s=e[a],n=-1/0;for(let o=0;o<8;o++){let l=i[o],u=s.distanceToPoint(l);n=n<u?u:n}if(n<0)return!1}for(let a=0;a<6;a++){let s=r[a],n=-1/0;for(let o=0;o<8;o++){let l=t[o],u=s.distanceToPoint(l);n=n<u?u:n}if(n<0)return!1}return!0}},st=Math.PI,Oi=st/2,rt=new E,Ae=new E,K=new E,T=new E,W=new k,vn=new ba,da=new k;function fe(e,t){t.radius=Math.max(t.radius,e.distanceToSquared(t.center))}function pa(e){return e.x!==e.y}var Ma=class extends Gi{constructor(e=1,t=1,i=1,r=-Oi,a=Oi,s=0,n=2*st,o=0,l=0){super(e,t,i),this.latStart=r,this.latEnd=a,this.lonStart=s,this.lonEnd=n,this.heightStart=o,this.heightEnd=l}getBoundingBox(e,t){pa(this.radius)&&console.warn("EllipsoidRegion: Triaxial ellipsoids are not supported.");let{latStart:i,latEnd:r,lonStart:a,lonEnd:s,heightStart:n,heightEnd:o}=this,l=(i+r)*.5,u=(a+s)*.5,c=i>0,h=r<0,m;m=c?i:h?r:0;let{min:d,max:p}=e;d.setScalar(1/0),p.setScalar(-1/0),s-a<=st?(this.getCartographicToNormal(l,u,K),Ae.set(0,0,1),rt.crossVectors(Ae,K).normalize(),Ae.crossVectors(K,rt).normalize(),t.makeBasis(rt,Ae,K),W.copy(t).invert(),this.getCartographicToPosition(m,a,o,T).applyMatrix4(W),p.x=Math.abs(T.x),d.x=-p.x,this.getCartographicToPosition(r,a,o,T).applyMatrix4(W),p.y=T.y,this.getCartographicToPosition(r,u,o,T).applyMatrix4(W),p.y=Math.max(T.y,p.y),this.getCartographicToPosition(i,a,o,T).applyMatrix4(W),d.y=T.y,this.getCartographicToPosition(i,u,o,T).applyMatrix4(W),d.y=Math.min(T.y,d.y),this.getCartographicToPosition(l,u,o,T).applyMatrix4(W),p.z=T.z,this.getCartographicToPosition(i,a,n,T).applyMatrix4(W),d.z=T.z,this.getCartographicToPosition(r,a,n,T).applyMatrix4(W),d.z=Math.min(T.z,d.z)):(this.getCartographicToPosition(m,u,o,K),K.z=0,K.length()<1e-10?K.set(1,0,0):K.normalize(),Ae.set(0,0,1),rt.crossVectors(K,Ae).normalize(),t.makeBasis(rt,Ae,K),W.copy(t).invert(),this.getCartographicToPosition(m,u+Oi,o,T).applyMatrix4(W),p.x=Math.abs(T.x),d.x=-p.x,this.getCartographicToPosition(r,0,h?n:o,T).applyMatrix4(W),p.y=T.y,this.getCartographicToPosition(i,0,c?n:o,T).applyMatrix4(W),d.y=T.y,this.getCartographicToPosition(m,u,o,T).applyMatrix4(W),p.z=T.z,this.getCartographicToPosition(m,s,o,T).applyMatrix4(W),d.z=T.z),e.getCenter(T),e.min.sub(T).multiplyScalar(1.0000000000001),e.max.sub(T).multiplyScalar(1.0000000000001),T.applyMatrix4(t),t.setPosition(T)}getBoundingSphere(e){pa(this.radius)&&console.warn("EllipsoidRegion: Triaxial ellipsoids are not supported."),this.getBoundingBox(vn,da),e.center.setFromMatrixPosition(da),e.radius=0;let{latStart:t,latEnd:i,lonStart:r,lonEnd:a,heightStart:s,heightEnd:n}=this,o=(t+i)*.5,l=(r+a)*.5,u=t>0,c=i<0,h;h=u?t:c?i:0,this.getCartographicToPosition(h,r,n,T),fe(T,e),this.getCartographicToPosition(i,r,n,T),fe(T,e),this.getCartographicToPosition(i,l,n,T),fe(T,e),this.getCartographicToPosition(t,r,n,T),fe(T,e),this.getCartographicToPosition(t,l,n,T),fe(T,e),this.getCartographicToPosition(o,l,n,T),fe(T,e),this.getCartographicToPosition(t,r,s,T),fe(T,e),a-r>st&&(this.getCartographicToPosition(h,l+st,n,T),fe(T,e)),e.radius=Math.sqrt(e.radius)*1.0000000000001}},oe=new E,le=new E,he=new E,ma=new E,ga=new E,_n=class{constructor(){this.sphere=null,this.obb=null,this.region=null,this.regionObb=null}intersectsRay(e){let t=this.sphere,i=this.obb||this.regionObb;return!(t&&!e.intersectsSphere(t)||i&&!i.intersectsRay(e))}intersectRay(e,t=null){let i=this.sphere,r=this.obb||this.regionObb,a=-1/0,s=-1/0;i&&e.intersectSphere(i,ma)&&(a=i.containsPoint(e.origin)?0:e.origin.distanceToSquared(ma)),r&&r.intersectRay(e,ga)&&(s=r.containsPoint(e.origin)?0:e.origin.distanceToSquared(ga));let n=Math.max(a,s);return n===-1/0?null:(e.at(Math.sqrt(n),t),t)}distanceToPoint(e){let t=this.sphere,i=this.obb||this.regionObb,r=-1/0,a=-1/0;return t&&(r=Math.max(t.distanceToPoint(e),0)),i&&(a=i.distanceToPoint(e)),r>a?r:a}intersectsFrustum(e){let t=this.obb||this.regionObb,i=this.sphere;return i&&!e.intersectsSphere(i)||t&&!t.intersectsFrustum(e)?!1:!!(i||t)}intersectsSphere(e){let t=this.obb||this.regionObb,i=this.sphere;return i&&!i.intersectsSphere(e)||t&&!t.intersectsSphere(e)?!1:!!(i||t)}intersectsOBB(e){let t=this.obb||this.regionObb,i=this.sphere;return i&&!e.intersectsSphere(i)||t&&!t.intersectsOBB(e)?!1:!!(i||t)}getOBB(e,t){let i=this.obb||this.regionObb;i?(e.copy(i.box),t.copy(i.transform)):(this.getAABB(e),t.identity())}getAABB(e){if(this.sphere)this.sphere.getBoundingBox(e);else{let t=this.obb||this.regionObb;e.copy(t.box).applyMatrix4(t.transform)}}getSphere(e){if(this.sphere)e.copy(this.sphere);else if(this.region)this.region.getBoundingSphere(e);else{let t=this.obb||this.regionObb;t.box.getBoundingSphere(e),e.applyMatrix4(t.transform)}}setObbData(e,t){let i=new Bi;oe.set(e[3],e[4],e[5]),le.set(e[6],e[7],e[8]),he.set(e[9],e[10],e[11]);let r=oe.length(),a=le.length(),s=he.length();oe.normalize(),le.normalize(),he.normalize(),r===0&&oe.crossVectors(le,he),a===0&&le.crossVectors(oe,he),s===0&&he.crossVectors(oe,le),i.transform.set(oe.x,le.x,he.x,e[0],oe.y,le.y,he.y,e[1],oe.z,le.z,he.z,e[2],0,0,0,1).premultiply(t),i.box.min.set(-r,-a,-s),i.box.max.set(r,a,s),i.update(),this.obb=i}setSphereData(e,t,i,r,a){let s=new _a;s.center.set(e,t,i),s.radius=r,s.applyMatrix4(a),this.sphere=s}setRegionData(e,t,i,r,a,s,n){let o=new Ma(...e.radius,i,a,t,r,s,n),l=new Bi;o.getBoundingBox(l.box,l.transform),l.update(),this.region=o,this.regionObb=l}},Tn=new rn;function wn(e,t,i,r){let a=Tn.set(e.normal.x,e.normal.y,e.normal.z,t.normal.x,t.normal.y,t.normal.z,i.normal.x,i.normal.y,i.normal.z);return r.set(-e.constant,-t.constant,-i.constant),r.applyMatrix3(a.invert()),r}var Mn=class extends Ks{constructor(){super(),this.points=Array(8).fill().map(()=>new E)}setFromProjectionMatrix(...e){return super.setFromProjectionMatrix(...e),this.calculateFrustumPoints(),this}calculateFrustumPoints(){let{planes:e,points:t}=this;[[e[0],e[3],e[4]],[e[1],e[3],e[4]],[e[0],e[2],e[4]],[e[1],e[2],e[4]],[e[0],e[3],e[5]],[e[1],e[3],e[5]],[e[0],e[2],e[5]],[e[1],e[2],e[5]]].forEach((i,r)=>{wn(i[0],i[1],i[2],t[r])})}};var ki=0;function fa(e,t,i,r){try{return ln.getByteLength(e,t,i,r)}catch{return ki}}function Sn(e){if(!e)return 0;if(e.isExternalTexture)return e.userData?.byteLength??ki;let{format:t,type:i,image:r,mipmaps:a}=e;if(e.isCompressedTexture&&Array.isArray(a)&&a.length>0){let n=0;for(let o of a)o?.data?.byteLength?n+=o.data.byteLength:n+=fa(o.width,o.height,t,i);return n}if(!r)return ki;let s=fa(r.width,r.height,t,i);return s*=e.generateMipmaps?4/3:1,s}function Cn(e){let t=new Set,i=0;return e.traverse(r=>{if(r.geometry&&!t.has(r.geometry)&&(i+=hn(r.geometry),t.add(r.geometry)),r.material){let a=r.material;for(let s in a){let n=a[s];n&&n.isTexture&&!t.has(n)&&(i+=Sn(n),t.add(n))}}}),i}var Sa=Symbol("INITIAL_FRUSTUM_CULLED"),Vt=new k,at=new E,Ui=new zi,En=new E(1,0,0),Pn=new E(0,1,0),An=()=>null;function ya(e,t){e.traverse(i=>{i.frustumCulled=i[Sa]&&t})}var Hi=class extends wi{get autoDisableRendererCulling(){return this._autoDisableRendererCulling}set autoDisableRendererCulling(e){this._autoDisableRendererCulling!==e&&(super._autoDisableRendererCulling=e,this.forEachLoadedModel(t=>{ya(t,!e)}))}constructor(...e){super(...e),this.accelerateRaycast=!0,this.group=new fn(this),this.ellipsoid=nt.clone(),this.cameras=[],this.cameraMap=new Map,this.cameraInfo=[],this._upRotationMatrix=new k,this._bytesUsed=new WeakMap,this._autoDisableRendererCulling=!0,this.manager=new tn,this._listeners={}}addEventListener(e,t){It.prototype.addEventListener.call(this,e,t)}hasEventListener(e,t){return It.prototype.hasEventListener.call(this,e,t)}removeEventListener(e,t){It.prototype.removeEventListener.call(this,e,t)}dispatchEvent(e){It.prototype.dispatchEvent.call(this,e)}getBoundingBox(e){if(!this.root)return!1;let t=this.root.engineData.boundingVolume;return t?(t.getAABB(e),!0):!1}getOrientedBoundingBox(e,t){if(!this.root)return!1;let i=this.root.engineData.boundingVolume;return i?(i.getOBB(e,t),!0):!1}getBoundingSphere(e){if(!this.root)return!1;let t=this.root.engineData.boundingVolume;return t?(t.getSphere(e),!0):!1}forEachLoadedModel(e){this.traverse(t=>{let i=t.engineData&&t.engineData.scene;i&&e(i,t)},null,!1)}raycast(e,t){if(this.root)if(this.accelerateRaycast)wa(this,this.root,e,t);else{let i=e.firstHitOnly?[]:t;for(let r of this.activeTiles){let{scene:a}=r.engineData;this.invokeOnePlugin(s=>s.raycastTile&&s.raycastTile(r,a,e,i))||e.intersectObject(a,!0,i)}e.firstHitOnly&&i.length>0&&(i.sort((r,a)=>r.distance-a.distance),t.push(i[0]))}}hasCamera(e){return this.cameraMap.has(e)}setCamera(e){let t=this.cameras,i=this.cameraMap;return i.has(e)?!1:(i.set(e,new zi),t.push(e),this.dispatchEvent({type:"add-camera",camera:e}),!0)}setResolution(e,t,i){let r=this.cameraMap;if(!r.has(e))return!1;let a=t.isVector2?t.x:t,s=t.isVector2?t.y:i,n=r.get(e);return(n.width!==a||n.height!==s)&&(n.set(a,s),this.dispatchEvent({type:"camera-resolution-change"})),!0}getResolution(e,t){let i=this.cameraMap.get(e);return i?t.copy(i):null}setResolutionFromRenderer(e,t){return t.getSize(Ui),this.setResolution(e,Ui.x,Ui.y)}deleteCamera(e){let t=this.cameras,i=this.cameraMap;if(i.has(e)){let r=t.indexOf(e);return t.splice(r,1),i.delete(e),this.dispatchEvent({type:"delete-camera",camera:e}),!0}return!1}loadRootTileset(...e){return super.loadRootTileset(...e).then(t=>{let{asset:i,extensions:r={}}=t;switch((i&&i.gltfUpAxis||"y").toLowerCase()){case"x":this._upRotationMatrix.makeRotationAxis(Pn,-Math.PI/2);break;case"y":this._upRotationMatrix.makeRotationAxis(En,Math.PI/2);break}if("3DTILES_ellipsoid"in r){let a=r["3DTILES_ellipsoid"],{ellipsoid:s}=this;s.name=a.body,a.radii?s.radius.set(...a.radii):s.radius.set(1,1,1)}return t})}prepareForTraversal(){let e=this.group,t=this.cameras,i=this.cameraMap,r=this.cameraInfo;for(;r.length>t.length;)r.pop();for(;r.length<t.length;)r.push({frustum:new Mn,isOrthographic:!1,sseDenominator:-1,position:new E,invScale:-1,pixelSize:0});at.setFromMatrixScale(e.matrixWorldInverse),Math.abs(Math.max(at.x-at.y,at.x-at.z))>1e-6&&console.warn("ThreeTilesRenderer : Non uniform scale used for tile which may cause issues when calculating screen space error.");for(let a=0,s=r.length;a<s;a++){let n=t[a],o=r[a],l=o.frustum,u=o.position,c=i.get(n);(c.width===0||c.height===0)&&console.warn("TilesRenderer: resolution for camera error calculation is not set.");let h=n.projectionMatrix.elements;if(o.isOrthographic=h[15]===1,o.isOrthographic){let m=2/h[0],d=2/h[5];o.pixelSize=Math.max(d/c.height,m/c.width)}else o.sseDenominator=2/h[5]/c.height;Vt.copy(e.matrixWorld),Vt.premultiply(n.matrixWorldInverse),Vt.premultiply(n.projectionMatrix),l.setFromProjectionMatrix(Vt,n.coordinateSystem,n.reversedDepth),u.set(0,0,0),u.applyMatrix4(n.matrixWorld),u.applyMatrix4(e.matrixWorldInverse)}}update(){if(super.update(),this.cameras.length===0&&this.root){let e=!1;this.invokeAllPlugins(t=>e||(e=!!(t!==this&&t.calculateTileViewError))),e===!1&&console.warn("TilesRenderer: no cameras defined. Cannot update 3d tiles.")}}preprocessNode(e,t,i=null){super.preprocessNode(e,t,i);let r=new k;if(e.transform){let n=e.transform;for(let o=0;o<16;o++)r.elements[o]=n[o]}i&&r.premultiply(i.engineData.transform);let a=new k().copy(r).invert(),s=new _n;"sphere"in e.boundingVolume&&s.setSphereData(...e.boundingVolume.sphere,r),"box"in e.boundingVolume&&s.setObbData(e.boundingVolume.box,r),"region"in e.boundingVolume&&s.setRegionData(this.ellipsoid,...e.boundingVolume.region),e.engineData.transform=r,e.engineData.transformInverse=a,e.engineData.boundingVolume=s,e.engineData.geometry=null,e.engineData.materials=null,e.engineData.textures=null,e.toJSON=An}async parseTile(e,t,i,r,a){let s=t.engineData,n=At(r),o=this.fetchOptions,l=this.manager,u=null,c=s.transform,h=this._upRotationMatrix,m=(Ce(e)||i).toLowerCase();switch(m){case"b3dm":{let g=new ji(l);g.workingPath=n,g.fetchOptions=o,g.adjustmentTransform.copy(h),u=g.parse(e);break}case"pnts":{let g=new Wi(l);g.workingPath=n,g.fetchOptions=o,u=g.parse(e);break}case"i3dm":{let g=new qi(l);g.workingPath=n,g.fetchOptions=o,g.adjustmentTransform.copy(h),g.ellipsoid.copy(this.ellipsoid),u=g.parse(e);break}case"cmpt":{let g=new Ta(l);g.workingPath=n,g.fetchOptions=o,g.adjustmentTransform.copy(h),g.ellipsoid.copy(this.ellipsoid),u=g.parse(e).then(P=>P.scene);break}case"gltf":case"glb":{let g=l.getHandler("path.gltf")||l.getHandler("path.glb")||new Ni(l);g.setWithCredentials(o.credentials==="include"),g.setRequestHeader(o.headers||{}),o.credentials==="include"&&o.mode==="cors"&&g.setCrossOrigin("use-credentials");let P=g.resourcePath||g.path||n;!/[\\/]$/.test(P)&&P.length&&(P+="/"),u=g.parseAsync(e,P).then(S=>{S.scene=S.scene||new Fi;let{scene:v}=S;return v.updateMatrix(),v.matrix.multiply(h).decompose(v.position,v.quaternion,v.scale),S});break}default:u=this.invokeOnePlugin(g=>g.parseToMesh&&g.parseToMesh(e,t,i,r,a));break}let d=await u;if(d===null)throw Error(`TilesRenderer: Content type "${m}" not supported.`);let p,y;d.isObject3D?(p=d,y=null):(p=d.scene,y=d),p.updateMatrix(),p.matrix.premultiply(c),p.matrix.decompose(p.position,p.quaternion,p.scale),await this.invokeAllPlugins(g=>g.processTileModel&&g.processTileModel(p,t)),p.traverse(g=>{g[Sa]=g.frustumCulled,g.userData.tile=t}),ya(p,!this.autoDisableRendererCulling);let M=[],_=[],C=[];if(p.traverse(g=>{if(g.geometry&&_.push(g.geometry),g.material){let P=g.material;M.push(g.material);for(let S in P){let v=P[S];v&&v.isTexture&&C.push(v)}}}),a.aborted){for(let g=0,P=C.length;g<P;g++){let S=C[g];S.image instanceof ImageBitmap&&S.image.close(),S.dispose()}return}s.materials=M,s.geometry=_,s.textures=C,s.scene=p,s.metadata=y}disposeTile(e){super.disposeTile(e);let t=e.engineData;if(t.scene){let i=t.materials,r=t.geometry,a=t.textures,s=t.scene.parent;t.scene.traverse(n=>{n.userData.meshFeatures&&n.userData.meshFeatures.dispose(),n.userData.structuralMetadata&&n.userData.structuralMetadata.dispose()});for(let n=0,o=r.length;n<o;n++)r[n].dispose();for(let n=0,o=i.length;n<o;n++)i[n].dispose();for(let n=0,o=a.length;n<o;n++){let l=a[n];l.image instanceof ImageBitmap&&l.image.close(),l.dispose()}s&&s.remove(t.scene),t.scene=null,t.materials=null,t.textures=null,t.geometry=null,t.metadata=null}}setTileActive(e,t){super.setTileActive(e,t);let i=e.engineData.scene;i&&(t?(i.parent=this.group,i.updateMatrixWorld(!0)):i.parent=null)}setTileVisible(e,t){let i=e.engineData.scene,{activeTiles:r,group:a}=this;i&&(t?a.add(i):(a.remove(i),r.has(e)&&(i.parent=a))),super.setTileVisible(e,t)}calculateBytesUsed(e,t){let i=this._bytesUsed;return!i.has(e)&&t&&i.set(e,Cn(t)),i.get(e)??null}calculateTileViewError(e,t){let i=e.engineData,r=this.cameras,a=this.cameraInfo,s=i.boundingVolume,n=!1,o=0,l=1/0,u=0,c=1/0;for(let h=0,m=r.length;h<m;h++){let d=a[h],p,y;if(d.isOrthographic){let _=d.pixelSize;p=e.geometricError/_,y=1/0}else{let _=d.sseDenominator;y=s.distanceToPoint(d.position),p=y===0?1/0:e.geometricError/(y*_)}let M=a[h].frustum;s.intersectsFrustum(M)&&(n=!0,o=Math.max(o,p),l=Math.min(l,y)),u=Math.max(u,p),c=Math.min(c,y)}n?(t.inView=!0,t.error=o,t.distanceFromCamera=l):(t.inView=!1,t.error=u,t.distanceFromCamera=c)}dispose(){super.dispose(),this.group.removeFromParent()}};import{BatchedMesh as ph,Box2 as Ln,Box3 as mh,Box3Helper as gh,BoxGeometry as fh,BufferAttribute as Qi,BufferGeometry as yh,CanvasTexture as bh,Color as xh,CustomBlending as In,DataTexture as Dn,DefaultLoadingManager as vh,DoubleSide as _h,EventDispatcher as Th,FileLoader as Rn,FloatType as wh,Frustum as Mh,GreaterDepth as Sh,Group as Ch,LineBasicMaterial as Eh,LineSegments as Ph,LinearFilter as On,LinearMipMapLinearFilter as Ah,MathUtils as $i,Matrix2 as Un,Matrix3 as Bn,Matrix4 as kn,Mesh as Lh,MeshBasicMaterial as Fn,MeshLambertMaterial as Ih,MeshStandardMaterial as Dh,OneFactor as Vn,PlaneGeometry as Rh,Points as Oh,PointsMaterial as Uh,Quaternion as Bh,REVISION as kh,RGFormat as Fh,Ray as Vh,Raycaster as zh,RedFormat as Nh,SRGBColorSpace as jh,ShaderMaterial as zn,Source as Wh,Sphere as Gh,SphereGeometry as qh,Texture as Hh,TextureUtils as Yh,Triangle as Xh,UnsignedByteType as Qh,Vector2 as ee,Vector3 as Na,Vector4 as Nn,WebGLArrayRenderTarget as $h,WebGLRenderTarget as Ca,WebGLRenderer as jn,ZeroFactor as Wn}from"three";import{GLTFLoader as Gn}from"three/addons/loaders/GLTFLoader.js";import{FullScreenQuad as ja}from"three/addons/postprocessing/Pass.js";var Kh=Object.freeze({fill:"#cccccc",stroke:"transparent",strokeWidth:1,radius:2,order:0,visible:!0});var Ea=new ie;Ea.maxJobs=10,Ea.priorityCallback=(e,t)=>{let i=e.tile,r=t.tile,a=i.internal.renderer,s=r.internal.renderer,n=a.visibleTiles.has(i);return n===s.visibleTiles.has(r)?Ue(i,r):n?1:-1};var Pa=new Na;function ot(e,t){if(e.isInterleavedBufferAttribute||e.array instanceof t)return e;let i=t===Int8Array||t===Int16Array||t===Int32Array?-1:0,r=new Qi(new t(e.count*e.itemSize),e.itemSize,!0),a=e.itemSize,s=e.count;for(let n=0;n<s;n++)for(let o=0;o<a;o++){let l=$i.clamp(e.getComponent(n,o),i,1);r.setComponent(n,o,l)}return r}function qn(e,t=Int16Array){let i=e.geometry,r=i.attributes,a=r.position;if(a.isInterleavedBufferAttribute||a.array instanceof t)return a;let s=new Qi(new t(a.count*a.itemSize),a.itemSize,!1),n=a.itemSize,o=a.count;i.computeBoundingBox();let l=i.boundingBox,{min:u,max:c}=l,h=2**(8*t.BYTES_PER_ELEMENT-1)-1,m=-h;for(let d=0;d<o;d++)for(let p=0;p<n;p++){let y=p===0?"x":p===1?"y":"z",M=u[y],_=c[y],C=$i.mapLinear(a.getComponent(d,p),M,_,m,h);s.setComponent(d,p,C)}l.getCenter(Pa).multiply(e.scale).applyQuaternion(e.quaternion),e.position.add(Pa),e.scale.x*=.5*(c.x-u.x)/h,e.scale.y*=.5*(c.y-u.y)/h,e.scale.z*=.5*(c.z-u.z)/h,r.position=s,e.geometry.boundingBox=null,e.geometry.boundingSphere=null,e.updateMatrixWorld()}var Zi=class{constructor(e){this._options={generateNormals:!1,disableMipmaps:!0,compressIndex:!0,compressNormals:!1,compressUvs:!1,compressPosition:!1,uvType:Int8Array,normalType:Int8Array,positionType:Int16Array,...e},this.name="TILES_COMPRESSION_PLUGIN",this.priority=-100}processTileModel(e,t){let{generateNormals:i,disableMipmaps:r,compressIndex:a,compressUvs:s,compressNormals:n,compressPosition:o,uvType:l,normalType:u,positionType:c}=this._options;e.traverse(h=>{if(h.material&&r){let m=h.material;for(let d in m){let p=m[d];p&&p.isTexture&&p.generateMipmaps&&(p.generateMipmaps=!1,p.minFilter=On)}}if(h.geometry){let m=h.geometry,d=m.attributes;if(s){let{uv:p,uv1:y,uv2:M,uv3:_}=d;p&&(d.uv=ot(p,l)),y&&(d.uv1=ot(y,l)),M&&(d.uv2=ot(M,l)),_&&(d.uv3=ot(_,l))}if(i&&!d.normals&&m.computeVertexNormals(),n&&d.normals&&(d.normals=ot(d.normals,u)),o&&qn(h,c),a&&m.index){let p=d.position.count,y=m.index,M=p>65535?Uint32Array:p>255?Uint16Array:Uint8Array;if(!(y.array instanceof M)){let _=new M(m.index.count);_.set(y.array);let C=new Qi(_,1);m.setIndex(C)}}}})}};function F(e,t,i){return e&&t in e?e[t]:i}function Wa(e){return e!=="BOOLEAN"&&e!=="STRING"&&e!=="ENUM"}function Hn(e){return/^FLOAT/.test(e)}function ct(e){return/^VEC/.test(e)}function dt(e){return/^MAT/.test(e)}function Ga(e,t,i,r=null){return dt(i)||ct(i)?r.fromArray(e,t):e[t]}function Yi(e){let{type:t,componentType:i}=e;switch(t){case"SCALAR":return i==="INT64"?0n:0;case"VEC2":return new ee;case"VEC3":return new Na;case"VEC4":return new Nn;case"MAT2":return new Un;case"MAT3":return new Bn;case"MAT4":return new kn;case"BOOLEAN":return!1;case"STRING":return"";case"ENUM":return 0}}function Aa(e,t){if(t==null)return!1;switch(e){case"SCALAR":return typeof t=="number"||typeof t=="bigint";case"VEC2":return t.isVector2;case"VEC3":return t.isVector3;case"VEC4":return t.isVector4;case"MAT2":return t.isMatrix2;case"MAT3":return t.isMatrix3;case"MAT4":return t.isMatrix4;case"BOOLEAN":return typeof t=="boolean";case"STRING":return typeof t=="string";case"ENUM":return typeof t=="number"||typeof t=="bigint"}throw Error("ClassProperty: invalid type.")}function ut(e,t=null){switch(e){case"INT8":return Int8Array;case"INT16":return Int16Array;case"INT32":return Int32Array;case"INT64":return BigInt64Array;case"UINT8":return Uint8Array;case"UINT16":return Uint16Array;case"UINT32":return Uint32Array;case"UINT64":return BigUint64Array;case"FLOAT32":return Float32Array;case"FLOAT64":return Float64Array}switch(t){case"BOOLEAN":return Uint8Array;case"STRING":return Uint8Array}throw Error("ClassProperty: invalid type.")}function Yn(e,t=null){if(e.array){t=t&&Array.isArray(t)?t:[],t.length=e.count;for(let i=0,r=t.length;i<r;i++)t[i]=Nt(e,t[i])}else t=Nt(e,t);return t}function Nt(e,t=null){let i=e.default,r=e.type;if(t||(t=Yi(e)),i===null){switch(r){case"SCALAR":return 0;case"VEC2":return t.set(0,0);case"VEC3":return t.set(0,0,0);case"VEC4":return t.set(0,0,0,0);case"MAT2":return t.identity();case"MAT3":return t.identity();case"MAT4":return t.identity();case"BOOLEAN":return!1;case"STRING":return"";case"ENUM":return""}throw Error("ClassProperty: invalid type.")}else if(dt(r))t.fromArray(i);else if(ct(r))t.fromArray(i);else return i}function Xn(e,t){if(e.noData===null)return t;let i=e.noData,r=e.type;if(Array.isArray(t))for(let n=0,o=t.length;n<o;n++)t[n]=a(t[n]);else t=a(t);return t;function a(n){return s(n)&&(n=Nt(e,n)),n}function s(n){if(dt(r)){let o=n.elements;for(let l=0,u=i.length;l<u;l++)if(i[l]!==o[l])return!1;return!0}else if(ct(r)){for(let o=0,l=i.length;o<l;o++)if(i[o]!==n.getComponent(o))return!1;return!0}else return i===n}}function Qn(e,t){switch(e){case"INT8":return Math.max(t/127,-1);case"INT16":return Math.max(t,32767,-1);case"INT32":return Math.max(t/2147483647,-1);case"INT64":return Math.max(Number(t)/9223372036854776e3,-1);case"UINT8":return t/255;case"UINT16":return t/65535;case"UINT32":return t/4294967295;case"UINT64":return Number(t)/18446744073709552e3}}function $n(e,t){let{type:i,componentType:r,scale:a,offset:s,normalized:n}=e;if(Array.isArray(t))for(let h=0,m=t.length;h<m;h++)t[h]=o(t[h]);else t=o(t);return t;function o(h){return h=dt(i)?u(h):ct(i)?l(h):c(h),h}function l(h){return h.x=c(h.x),h.y=c(h.y),"z"in h&&(h.z=c(h.z)),"w"in h&&(h.w=c(h.w)),h}function u(h){let m=h.elements;for(let d=0,p=m.length;d<p;d++)m[d]=c(m[d]);return h}function c(h){return n&&(h=Qn(r,h)),(n||Hn(r))&&(h=h*a+s),h}}function Ji(e,t,i=null){if(e.array){Array.isArray(t)||(t=Array(e.count||0)),t.length=i===null?e.count:i;for(let r=0,a=t.length;r<a;r++)Aa(e.type,t[r])||(t[r]=Yi(e))}else Aa(e.type,t)||(t=Yi(e));return t}function jt(e,t){for(let i in t)i in e||delete t[i];for(let i in e){let r=e[i];t[i]=Ji(r,t[i])}}function Zn(e){switch(e){case"ENUM":return 1;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":return 4;case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;case"BOOLEAN":return-1;case"STRING":return-1;default:return-1}}var Gt=class{constructor(e,t,i=null){this.name=t.name||null,this.description=t.description||null,this.type=t.type,this.componentType=t.componentType||null,this.enumType=t.enumType||null,this.array=t.array||!1,this.count=t.count||0,this.normalized=t.normalized||!1,this.offset=t.offset||0,this.scale=F(t,"scale",1),this.max=F(t,"max",1/0),this.min=F(t,"min",-1/0),this.required=t.required||!1,this.noData=F(t,"noData",null),this.default=F(t,"default",null),this.semantic=F(t,"semantic",null),this.enumSet=null,this.accessorProperty=i,i&&(this.offset=F(i,"offset",this.offset),this.scale=F(i,"scale",this.scale),this.max=F(i,"max",this.max),this.min=F(i,"min",this.min)),t.type==="ENUM"&&(this.enumSet=e[this.enumType],this.componentType===null&&(this.componentType=F(this.enumSet,"valueType","UINT16")))}shapeToProperty(e,t=null){return Ji(this,e,t)}resolveDefaultElement(e){return Nt(this,e)}resolveDefault(e){return Yn(this,e)}resolveNoData(e){return Xn(this,e)}resolveEnumsToStrings(e){let t=this.enumSet;if(this.type==="ENUM")if(Array.isArray(e))for(let r=0,a=e.length;r<a;r++)e[r]=i(e[r]);else e=i(e);return e;function i(r){let a=t.values.find(s=>s.value===r);return a===null?"":a.name}}adjustValueScaleOffset(e){return Wa(this.type)?$n(this,e):e}},Ki=class{constructor(e,t={},i={},r=null){this.definition=e,this.class=t[e.class],this.className=e.class,this.enums=i,this.data=r,this.name="name"in e?e.name:null,this.properties=null}getPropertyNames(){return Object.keys(this.class.properties)}includesData(e){return!!this.definition.properties[e]}dispose(){}_initProperties(e=Gt){let t={};for(let i in this.class.properties)t[i]=new e(this.enums,this.class.properties[i],this.definition.properties[i]);this.properties=t}},Jn=class extends Gt{constructor(e,t,i=null){super(e,t,i),this.attribute=i?.attribute??null}},Kn=class extends Ki{constructor(...e){super(...e),this.isPropertyAttributeAccessor=!0,this._initProperties(Jn)}getData(e,t,i={}){let r=this.properties;jt(r,i);for(let a in r)i[a]=this.getPropertyValue(a,e,t,i[a]);return i}getPropertyValue(e,t,i,r=null){if(t>=this.count)throw Error("PropertyAttributeAccessor: Requested index is outside the range of the buffer.");let a=this.properties[e],s=a.type;if(!a)throw Error("PropertyAttributeAccessor: Requested class property does not exist.");if(!this.definition.properties[e])return a.resolveDefault(r);r=a.shapeToProperty(r);let n=i.getAttribute(a.attribute.toLowerCase());if(dt(s)){let o=r.elements;for(let l=o.length;0<l;)o[0]=n.getComponent(t,0)}else if(ct(s))r.fromBufferAttribute(n,t);else if(s==="SCALAR"||s==="ENUM")r=n.getX(t);else throw Error("StructuredMetadata.PropertyAttributeAccessor: BOOLEAN and STRING types are not supported by property attributes.");return r=a.adjustValueScaleOffset(r),r=a.resolveEnumsToStrings(r),r=a.resolveNoData(r),r}},eo=class extends Gt{constructor(e,t,i=null){super(e,t,i),this.values=i?.values??null,this.valueLength=Zn(this.type),this.arrayOffsets=F(i,"arrayOffsets",null),this.stringOffsets=F(i,"stringOffsets",null),this.arrayOffsetType=F(i,"arrayOffsetType","UINT32"),this.stringOffsetType=F(i,"stringOffsetType","UINT32")}getArrayLengthFromId(e,t){let i=this.count;if(this.arrayOffsets!==null){let{arrayOffsets:r,arrayOffsetType:a}=this,s=new(ut(a))(e[r]);i=s[t+1]-s[t]}return i}getIndexOffsetFromId(e,t){let i=t;if(this.arrayOffsets){let{arrayOffsets:r,arrayOffsetType:a}=this;i=new(ut(a))(e[r])[i]}else this.array&&(i*=this.count);return i}},to=class extends Ki{constructor(...e){super(...e),this.isPropertyTableAccessor=!0,this.count=this.definition.count,this._initProperties(eo)}getData(e,t={}){let i=this.properties;jt(i,t);for(let r in i)t[r]=this.getPropertyValue(r,e,t[r]);return t}_readValueAtIndex(e,t,i,r=null){let a=this.properties[e],{componentType:s,type:n}=a,o=this.data,l=o[a.values],u=new(ut(s,n))(l),c=a.getIndexOffsetFromId(o,t);if(Wa(n)||n==="ENUM")return Ga(u,(c+i)*a.valueLength,n,r);if(n==="STRING"){let h=c+i,m=0;if(a.stringOffsets!==null){let{stringOffsets:p,stringOffsetType:y}=a,M=new(ut(y))(o[p]);m=M[h+1]-M[h],h=M[h]}let d=new Uint8Array(u.buffer,h,m);r=new TextDecoder().decode(d)}else if(n==="BOOLEAN"){let h=c+i,m=Math.floor(h/8),d=h%8;r=(u[m]>>d&1)==1}return r}getPropertyValue(e,t,i=null){if(t>=this.count)throw Error("PropertyTableAccessor: Requested index is outside the range of the table.");let r=this.properties[e];if(!r)throw Error("PropertyTableAccessor: Requested property does not exist.");if(!this.definition.properties[e])return r.resolveDefault(i);let a=r.array,s=this.data,n=r.getArrayLengthFromId(s,t);if(i=r.shapeToProperty(i,n),a)for(let o=0,l=i.length;o<l;o++)i[o]=this._readValueAtIndex(e,t,o,i[o]);else i=this._readValueAtIndex(e,t,0,i);return i=r.adjustValueScaleOffset(i),i=r.resolveEnumsToStrings(i),i=r.resolveNoData(i),i}},lt=new Ln,La=class{constructor(){this._renderer=new jn,this._target=new Ca(1,1),this._texTarget=new Ca,this._quad=new ja(new zn({blending:In,blendDst:Wn,blendSrc:Vn,uniforms:{map:{value:null},pixel:{value:new ee}},vertexShader:`
2
2
  void main() {
3
3
 
4
4
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );