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