/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{create as e}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{project as t}from"../../../../geometry/projectionUtils.js";import{fromExtent as i}from"../../../../geometry/support/aaBoundingRect.js";import{Tiles3DTarget as n}from"../i3s/Intersector.js";import{createTileBVH as r}from"./Tiles3DBVH.js";import{ElevationRange as s}from"../../support/ElevationRange.js";import{IntersectorResult as o}from"../../webgl-engine/lib/IntersectorResult.js";import{MeshIntersectionOptions as l,computeInvDir as a,intersectAabbInvDir as c}from"../../webgl-engine/lib/RayIntersections.js";class d{constructor(e){this.layerView=e,this.type=8,this.slicePlaneEnabled=!1,this.isGround=!0,this.layerViewUid=e.uid;const n=e.view.viewingMode,s=(e.useEsriCrs?e.fullExtentInLocalViewSpatialReference:e.layer.fullExtent?t(e.layer.fullExtent,e.view.renderSpatialReference):void 0)??e.view.extent,o=i(s);this._bvh=r(n,o)}destroy(){this._bvh.destroy()}addTile(e){this._bvh.addTile(e)}removeTile(e){this._bvh.removeTile(e)}intersect(e,t,i,r,s,d){if(e.options.filteredLayerViewUids.includes(this.layerView.uid))return;const{results:m,tolerance:p}=e,h=2===e.options.store,{componentObjectCollection:f}=this.layerView.view.stage.renderView,g=new l(p,d,e.options.normalRequired),w=a(i,r,u),v=(s,l,a)=>{if(l<0)return;if(null!=t&&!t(i,r,l))return;const c=e=>{const t=new n(this.layerView.uid);e.set(this.type,t,l,a)};if(this.isGround&&(null==m.ground.distance||l<m.ground.distance)&&c(m.ground),!e.options.isFiltered&&((null==m.min.distance||l<m.min.distance)&&c(m.min),(null==m.max.distance||l>m.max.distance)&&c(m.max),h)){const t=new o(e.ray);c(t),e.results.all.push(t)}};this._bvh.forEachTileIntersectingRay(i,r,e=>{const{componentObjects:t}=e;for(const n of t)c(n.aabbInWorldCoordinates,i,w,0)&&f.intersect(n,i,r,null,g,v)},d)}getElevationRange(e){return this._bvh.getElevationRangeIntersectingSphere(e)??new s(0,0)}}const u=e();export{d as Tiles3DMeshIntersectionHandler};
