UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.82 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{c as t,a as e}from"../../../../../chunks/vec32.js";import{create as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as o}from"../../../../../geometry/support/aaBoundingBox.js";import{ComponentObjectElevationAgnosticComponentGeometryBVH as s,intersectTriangleRangeForComponent as i}from"./ComponentObjectElevationAgnosticComponentGeometryBVH.js";import{ElevationAgnosticBVH as r}from"./ElevationAgnosticBVH.js";import{getVisibility as a}from"../../lib/ComponentUtils.js";import{computeInvDir as c,intersectAabbInvDir as l,MeshIntersectionOptions as h}from"../../lib/RayIntersections.js";class m{constructor(t,e,o,s,i,a,c,l){this.vertexData=t,this.vertexStride=e,this.indexData=o,this._components=s,this._componentAabbs3D=i,this.geometryMinZ=a,this.planetCenterZ=c,this.localMode=l,this.maxBspNodeDepth=6,this.minElementCountForBVH=10,this.minBspNodeElementCount=3,this._ray0=f,this._ray1=u,this._invDir=n(),this._componentVerticalOffsets=null,this._verticalOffset=null,this._tolerance=0,this._intersectionOptions=D,this._callback=y,this.rayDirectionC=n(),this._componentIndexMap=null,this._bvh=new r(s.count,this),this.componentIntersectionData=new Array(s.count)}get numComponents(){return this._components.count}get minZGlobal(){return this.geometryMinZ-this.planetCenterZ}getAabbs2D(){return this.localMode?this.getAabbs2DLocal():this.getAabbs2DGlobal()}getAabbs2DGlobal(){const{numComponents:t,planetCenterZ:e,minZGlobal:n}=this,o=new Float64Array(4*t),s=this._componentAabbs3D;for(let i=0;i<t;++i){const t=6*i,r=s[t+0],a=s[t+1],c=s[t+2],l=s[t+3],h=s[t+4],m=n/(c-e),p=n/(s[t+5]-e),_=Math.min(r*m,r*p),b=Math.min(a*m,a*p),f=Math.max(l*m,l*p),u=Math.max(h*m,h*p),y=4*i;o[y+0]=_,o[y+1]=b,o[y+2]=f,o[y+3]=u}return o}getAabbs2DLocal(){const{numComponents:t}=this,e=new Float64Array(4*t),n=this._componentAabbs3D;for(let o=0;o<t;++o){const t=6*o,s=n[t+0],i=n[t+1],r=n[t+3],a=n[t+4],c=4*o;e[c+0]=s,e[c+1]=i,e[c+2]=r,e[c+3]=a}return e}intersectRay(t,e,n,o,s,i,r){const{isVerticalRay:a}=r;this._ray0=t,this._ray1=e,this._componentVerticalOffsets=n,this._verticalOffset=o,this._tolerance=i,this._intersectionOptions=r,this._componentIndexMap=this._bvh.elementIndexMap,c(t,e,this._invDir),this._callback=s,this._bvh.intersectRay(t,e,a),this._callback=y}intersectRange(t,e){const n=this._componentIndexMap,o=this._components,s=o.pickability,i=o.visibility;for(let r=t;r<e;++r){const t=n?n[r]:r;a(s,t)&&i.isVisible(t)&&this._intersectComponent(t)}}getComponentTriangleCount(t){const e=this._components.offsets,n=e[t]/3;return e[t+1]/3-n}getComponentAabb3D(t,e){const n=this._componentAabbs3D,o=6*t;return e[0]=n[o],e[1]=n[o+1],e[2]=n[o+2],e[3]=n[o+3],e[4]=n[o+4],e[5]=n[o+5],e}_intersectComponent(n){if(!a(this._components.pickability,n))return;const o=this.getComponentAabb3D(n,p);let r=!1;const{localMode:c,_componentVerticalOffsets:h,_verticalOffset:m,_ray0:f,_ray1:u,_invDir:y,planetCenterZ:D,_tolerance:C,rayDirectionC:v,componentIntersectionData:A}=this,{isVerticalRay:x}=this._intersectionOptions,d=this._components.offsets,M=t(_,f),O=t(b,u),V=h?.[n]??0,Z=V+(m?.offset??0);if(0!==Z&&(c?(M[2]=f[2]-Z,O[2]=u[2]-Z,r=!0):null!=m&&(m.componentOffset=V)),null==m||r||0===Z||m.applyToAabb(o),!l(o,M,y,C))return;e(v,O,M);const j=d[n]/3,R=d[n+1]/3,k=R-j,B=(t,e,o)=>{this._callback(t,e,n,o)},{vertexData:I,vertexStride:w,indexData:G,_intersectionOptions:E}=this,{normalRequired:F}=E;if(k>g){let t=A[n];null==t&&(t=new s(n,I,w,G,j,R,this.geometryMinZ,D,c),A[n]=t),t.intersectRay(M,O,x,r?0:Z,B,F)}else{i(M,v,j,R,G,I,w,r?0:Z,D,F,B)}}}const p=o(),_=n(),b=n(),f=n(),u=n(),y=()=>{},D=new h,g=40;export{m as ComponentObjectElevationAgnosticComponentBVH};