@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.79 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
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{sub as n,transformMat3 as i,negate as o}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as a}from"../../../../../geometry/support/aaBoundingBox.js";import{floatArrayFrom as h,floatArrayByteSize as m,newFloatArray as p}from"../../../../../geometry/support/FloatArray.js";import{indexArrayFrom as c,getContinuousIndexArray as l,indexArrayByteSize as _}from"../../../../../geometry/support/Indices.js";import{ComponentObjectElevationAgnosticComponentBVH as b}from"./ComponentObjectElevationAgnosticBVH.js";import{ComponentObjectFixedBVH as u}from"./ComponentObjectFixedBVH.js";class f{constructor(t,s,e,n){this.viewingMode=t,this._components=e,this._needsElevationAlignment=n,this.verticalOffset=null,this.componentVerticalOffsets=null,this._planetCenter=r(),this._componentBvh=null,this._aabb=a();const{indices:i,positions:o}=s,m=o.length/3;this._indices=i?c(i,m):l(m),this._positions=h(o)}get usedMemory(){return m(this._positions)+_(this._indices)}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,r,a,h,m,p,c){this.verticalOffset=a,this.componentVerticalOffsets=h;const{position:l}=m,_=n(d,e,l),b=n(g,r,l),u=t(C,m.rotationScale);i(_,_,u),i(b,b,u);const f=s(A,u);if(1===this.viewingMode){const t=this._planetCenter;o(t,l),i(t,t,u)}const v=(t,s,e,n)=>{c(e,t,n?i(M,n,f):null,s)};this._intersectComponents(_,b,h,a,v,p)}_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=p(6*i),r=this._indices,a=this._positions,h=this._components.offsets;let m=0,c=1/0,l=1/0,_=1/0,b=-1/0,u=-1/0,f=-1/0;for(let p=0;p<i;p++){const t=h[p],i=h[p+1];let d=1/0,g=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*r[s],e=a[t],n=a[t+1],i=a[t+2];d=Math.min(d,e),g=Math.min(g,n),C=Math.min(C,i),M=Math.max(M,e),A=Math.max(A,n),v=Math.max(v,i)}else d=s,g=e,C=n,M=s,A=e,v=n;o[m++]=d,o[m++]=g,o[m++]=C,o[m++]=M,o[m++]=A,o[m++]=v,c=Math.min(c,d),l=Math.min(l,g),_=Math.min(_,C),b=Math.max(b,M),u=Math.max(u,A),f=Math.max(f,v)}return this._aabb[0]=c,this._aabb[1]=l,this._aabb[2]=_,this._aabb[3]=b,this._aabb[4]=u,this._aabb[5]=f,o}_intersectComponents(t,s,e,n,i,o){let r=this._componentBvh;null==r&&(r=this._needsElevationAlignment?new b(this._positions,v,this._indices,this._components,this._ensureComponentAabbs(),this.geometryMinZ,this.planetCenterZ,this.localMode):new u(this._positions,v,this._indices,this.numTriangles,this._components.offsets),this._componentBvh=r),r.intersectRay(t,s,o,i,e??void 0,n??void 0)}get geometryMinZ(){return this._aabb[2]}get planetCenterZ(){return this._planetCenter[2]}get numTriangles(){return this._indices.length/3}get localMode(){return 2===this.viewingMode}get positions(){return this._positions}get indices(){return this._indices}get aabb(){return this._ensureComponentAabbs(),this._aabb}}const d=r(),g=r(),C=e(),M=r(),A=e(),v=3;export{f as IntersectionGeometry};