UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 5.51 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{copy as t}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as r,IDENTITY as i}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{g as s,t as e,h as a,l as n,c as o,n as h}from"../../../../chunks/vec32.js";import{create as d,UNIT_Z as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as l}from"../../../../chunks/vec42.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{create as m,fromPoints as y,copy as u}from"../../../../geometry/support/ray.js";import{ViewingMode as p}from"../../../ViewingMode.js";import{IntersectorOptions as g,StoreResults as _,IntersectorType as O}from"./IntersectorInterfaces.js";import{HudTarget as L}from"./IntersectorTarget.js";import{isValidIntersectorResult as v}from"./intersectorUtils.js";import{IntersectorTransform as j,getVerticalOffsetObject3D as w}from"./verticalOffsetUtils.js";const E=1e-5;class b{constructor(t){this.options=new g,this._results=new A,this.transform=new j,this.tolerance=E,this.verticalOffset=null,this._ray=m(),this._rayEnd=d(),this._rayBeginTransformed=d(),this._rayEndTransformed=d(),this.viewingMode=t??p.Global}get results(){return this._results}get ray(){return this._ray}get rayBegin(){return this._ray.origin}get rayEnd(){return this._rayEnd}reset(t,r,i){this.resetWithRay(y(t,r,this._ray),i)}resetWithRay(t,r){this.camera=r,t!==this._ray&&u(t,this._ray),0!==this.options.verticalOffset?this.viewingMode===p.Local?this._ray.origin[2]-=this.options.verticalOffset:this.verticalOffset=this.options.verticalOffset:this.verticalOffset=null,s(this._rayEnd,this._ray.origin,this._ray.direction),this._results.init(this._ray)}intersect(t=null,r,i,s,e){this.point=r,this.filterPredicate=s,this.tolerance=i??E;const a=w(this.verticalOffset);if(t&&t.length>0){const r=e?t=>{e(t)&&this.intersectObject(t)}:t=>{this.intersectObject(t)};for(const i of t){const t=i.getSpatialQueryAccelerator?.();null!=t?(null!=a?t.forEachAlongRayWithVerticalOffset(this._ray.origin,this._ray.direction,r,a):t.forEachAlongRay(this._ray.origin,this._ray.direction,r),this.options.selectionMode&&this.options.hud&&t.forEachDegenerateObject(r)):i.objects.forAll((t=>r(t)))}}this.sortResults()}intersectObject(t){const r=t.geometries;if(!r)return;const s=t.effectiveTransformation,a=w(this.verticalOffset);for(const n of r){if(!n.visible)continue;const{material:r,id:o}=n;if(!r.visible)continue;this.transform.setAndInvalidateLazyTransforms(s,n.transformation),e(this._rayBeginTransformed,this.rayBegin,this.transform.inverse),e(this._rayEndTransformed,this.rayEnd,this.transform.inverse);const h=this.transform.transform;null!=a&&(a.objectTransform=this.transform),r.intersect(n,this.transform.transform,this,this._rayBeginTransformed,this._rayEndTransformed,((r,s,e,a,n,d)=>{if(r>=0){if(null!=this.filterPredicate&&!this.filterPredicate(this._ray.origin,this._rayEnd,r))return;const c=a?this._results.hud:this._results,l=a?a=>{const h=new L(t,o,e,d);a.set(O.HUD,h,r,s,i,n)}:i=>i.set(O.OBJECT,{object:t,geometryId:o,triangleNr:e},r,s,h,n);if((null==c.min.drapedLayerOrder||n>=c.min.drapedLayerOrder)&&(null==c.min.dist||r<c.min.dist)&&l(c.min),this.options.store!==_.MIN&&(null==c.max.drapedLayerOrder||n<c.max.drapedLayerOrder)&&(null==c.max.dist||r>c.max.dist)&&l(c.max),this.options.store===_.ALL)if(a){const t=new B(this._ray);l(t),this._results.hud.all.push(t)}else{const t=new I(this._ray);l(t),this._results.all.push(t)}}}))}}sortResults(t=this._results.all){t.sort(((t,r)=>t.dist!==r.dist?(t.dist??0)-(r.dist??0):t.drapedLayerOrder!==r.drapedLayerOrder?x(t.drapedLayerOrder,r.drapedLayerOrder):x(t.drapedLayerGraphicOrder,r.drapedLayerGraphicOrder)))}}function x(t,r){return(r??-Number.MAX_VALUE)-(t??-Number.MAX_VALUE)}function T(t){return new b(t)}class A{constructor(){this.min=new I(m()),this.max=new I(m()),this.hud={min:new B(m()),max:new B(m()),all:new Array},this.ground=new I(m()),this.all=[]}init(t){this.min.init(t),this.max.init(t),this.ground.init(t),this.all.length=0,this.hud.min.init(t),this.hud.max.init(t),this.hud.all.length=0}}class I{get ray(){return this._ray}get distanceInRenderSpace(){return null!=this.dist?(a(G,this.ray.direction,this.dist),n(G)):null}withinDistance(t){return!!v(this)&&this.distanceInRenderSpace<=t}getIntersectionPoint(t){return!!v(this)&&(a(G,this.ray.direction,this.dist),s(t,this.ray.origin,G),!0)}getTransformedNormal(t){return o(M,this.normal),M[3]=0,l(M,M,this.transformation),o(t,M),h(t,t)}constructor(t){this.intersector=O.OBJECT,this.normal=d(),this.transformation=r(),this._ray=m(),this.init(t)}init(t){this.dist=null,this.target=null,this.drapedLayerOrder=null,this.drapedLayerGraphicOrder=null,this.intersector=O.OBJECT,u(t,this._ray)}set(r,s,e,a,n,h,d){this.intersector=r,this.dist=e,o(this.normal,a??c),t(this.transformation,n??i),this.target=s,this.drapedLayerOrder=h,this.drapedLayerGraphicOrder=d}copy(r){u(r.ray,this._ray),this.intersector=r.intersector,this.dist=r.dist,this.target=r.target,this.drapedLayerOrder=r.drapedLayerOrder,this.drapedLayerGraphicOrder=r.drapedLayerGraphicOrder,o(this.normal,r.normal),t(this.transformation,r.transformation)}}class B extends I{constructor(){super(...arguments),this.intersector=O.HUD}}function R(t){return new I(t)}const G=d(),M=f();export{E as defaultTolerance,T as newIntersector,R as newIntersectorResult};