@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.56 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{invert as t,transpose as s}from"../../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as e}from"../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{a as n,o,u as i}from"../../../../../chunks/vec32.js";import{create as a}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as r}from"../../../../../geometry/support/aaBoundingBox.js";import{newFloatArray as h}from"../../../../../geometry/support/FloatArray.js";import{compactIndices as m,getContinuousIndexArray as p}from"../../../../../geometry/support/Indices.js";import{ViewingMode as c}from"../../../../ViewingMode.js";import{ComponentObjectElevationAgnosticComponentBVH as b}from"./ComponentObjectElevationAgnosticComponentBVH.js";class l{constructor(t,s,e){this.viewingMode=t,this.positionData=s,this._components=e,this.verticalOffset=null,this.componentVerticalOffsets=null,this._planetCenter=a(),this._componentBvh=null,this._aabb=r(),this._indices=s.indices?m(s.indices):p(s.positions.length/3),this._positions=s.positions}destroy(){this._positions=null,this._indices=null,this._perComponentAabbs=null,this._componentBvh=null}getComponentAabb(t,s){const e=this._ensureComponentAabbs(),n=6*t;return s[0]=e[n],s[1]=e[n+1],s[2]=e[n+2],s[3]=e[n+3],s[4]=e[n+4],s[5]=e[n+5],s}getComponentAabbs(){return this._ensureComponentAabbs()}_ensureComponentAabbs(){return this._perComponentAabbs||(this._perComponentAabbs=this._computePerComponentAabbs()),this._perComponentAabbs}getComponentPositions(t,s){s.indices=this._indices,s.data=this._positions,s.stride=3,s.startIndex=this._components.offsets[t],s.endIndex=this._components.offsets[t+1]}intersect(e,a,r,h,m,p,b,l){this.verticalOffset=h,this.componentVerticalOffsets=m;const{position:C}=p,M=n(_,e,C),A=n(u,a,C),x=t(f,p.rotationScale);o(M,M,x),o(A,A,x);const v=s(d,x);if(this.viewingMode===c.Global){const t=this._planetCenter;i(t,C),o(t,t,x)}const j=(t,s,e,n)=>{l(e,t,n?o(g,n,v):null,s)};this._intersectComponents(M,A,m,h,j,r,b)}_computePerComponentAabbs(){const t=this._aabb,s=.5*(t[0]+t[3]),e=.5*(t[1]+t[4]),n=.5*(t[2]+t[5]),o=this._components.count,i=h(6*o),a=this._indices,r=this._positions,m=this._components.offsets;let p=0,c=1/0,b=1/0,l=1/0,_=-1/0,u=-1/0,f=-1/0;for(let h=0;h<o;h++){const t=m[h],o=m[h+1];let g=1/0,d=1/0,C=1/0,M=-1/0,A=-1/0,x=-1/0;if(t<o)for(let s=t;s<o;s++){const t=3*a[s],e=r[t],n=r[t+1],o=r[t+2];g=Math.min(g,e),d=Math.min(d,n),C=Math.min(C,o),M=Math.max(M,e),A=Math.max(A,n),x=Math.max(x,o)}else g=s,d=e,C=n,M=s,A=e,x=n;i[p++]=g,i[p++]=d,i[p++]=C,i[p++]=M,i[p++]=A,i[p++]=x,c=Math.min(c,g),b=Math.min(b,d),l=Math.min(l,C),_=Math.max(_,M),u=Math.max(u,A),f=Math.max(f,x)}return this._aabb[0]=c,this._aabb[1]=b,this._aabb[2]=l,this._aabb[3]=_,this._aabb[4]=u,this._aabb[5]=f,i}_intersectComponents(t,s,e,n,o,i,a){let r=this._componentBvh;null==r&&(r=new b(this._positions,3,this._indices,this._components,this._ensureComponentAabbs(),this.geometryMinZ,this.planetCenterZ,this.localMode),this._componentBvh=r),r.intersectRay(t,s,e,n,o,i,a)}get geometryMinZ(){return this._aabb[2]}get planetCenterZ(){return this._planetCenter[2]}get numTriangles(){return this._indices.length/3}get localMode(){return this.viewingMode===c.Local}get positions(){return this._positions}get indices(){return this._indices}get aabb(){return this._ensureComponentAabbs(),this._aabb}}const _=a(),u=a(),f=e(),g=a(),d=e();export{l as IntersectionGeometry};