@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.84 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{copy as t,sub as e}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as o}from"../../../../../geometry/support/aaBoundingBox.js";import{newDoubleArray as s}from"../../../../../geometry/support/DoubleArray.js";import{ComponentObjectElevationAgnosticComponentGeometryBVH as i,intersectTriangleRangeForComponent as a}from"./ComponentObjectElevationAgnosticComponentGeometryBVH.js";import{ElevationAgnosticBVH as r}from"./ElevationAgnosticBVH.js";import{MeshIntersectionOptions as c,computeInvDir as l,intersectAabbInvDir as m}from"../../lib/RayIntersections.js";import{elevationAlignVertexGlobal as h}from"../../lib/triangleIntersectionUtils.js";class p{constructor(t,e,o,s,i,a,c,l){this.vertexData=t,this.vertexStride=e,this.indexData=o,this._componentData=s,this._componentAabbs3D=i,this.geometryMinZ=a,this.planetCenterZ=c,this.localMode=l,this.maxBspNodeDepth=6,this.minElementCountForBVH=10,this.minBspNodeElementCount=3,this._ray0=u,this._ray1=D,this._invDir=n(),this._componentVerticalOffsets=null,this._verticalOffset=null,this._tolerance=0,this._intersectionOptions=y,this._callback=g,this.rayDirectionC=n(),this._componentIndexMap=null,this._bvh=new r(s.count,this),this.componentIntersectionData=new Array(s.count)}get numComponents(){return this._componentData.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=s(4*t),i=this._componentAabbs3D;for(let s=0;s<t;++s){const t=6*s,a=i[t+0],r=i[t+1],c=i[t+2],l=i[t+3],m=i[t+4],h=n/(c-e),p=n/(i[t+5]-e),b=Math.min(a*h,a*p),_=Math.min(r*h,r*p),f=Math.max(l*h,l*p),u=Math.max(m*h,m*p),D=4*s;o[D+0]=b,o[D+1]=_,o[D+2]=f,o[D+3]=u}return o}getAabbs2DLocal(){const{numComponents:t}=this,e=s(4*t),n=this._componentAabbs3D;for(let o=0;o<t;++o){const t=6*o,s=n[t+0],i=n[t+1],a=n[t+3],r=n[t+4],c=4*o;e[c+0]=s,e[c+1]=i,e[c+2]=a,e[c+3]=r}return e}intersectRay(t,e,n,o,s,i){const{isVerticalRay:a}=n;this._ray0=t,this._ray1=e,this._componentVerticalOffsets=s??null,this._verticalOffset=i??null,this._tolerance=n.tolerance,this._intersectionOptions=n,this._componentIndexMap=this._bvh.elementIndexMap,l(t,e,this._invDir),this._callback=o,this._bvh.intersectRay(t,e,a),this._callback=g}intersectRange(t,e){const n=this._componentIndexMap,o=this._componentData;for(let s=t;s<e;++s){const t=n?n[s]:s;o.isPickable(t)&&o.isVisible(t)&&this._intersectComponent(t)}}getComponentTriangleCount(t){const e=this._componentData.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){const o=this.getComponentAabb3D(n,b);let s=!1;const{localMode:r,_componentVerticalOffsets:c,_verticalOffset:l,_ray0:p,_ray1:u,_invDir:D,planetCenterZ:g,_tolerance:y,rayDirectionC:v,componentIntersectionData:x}=this,{isVerticalRay:A}=this._intersectionOptions,d=this._componentData.offsets,M=t(_,p),O=t(f,u),j=c?.[n]??0,V=j+(l?.offset??0);if(0!==V&&(r?(M[2]=p[2]-V,O[2]=u[2]-V,s=!0):(null!=l&&(l.componentOffset=j),A&&(h(M,-V,g,p),h(O,-V,g,u),s=!0))),null==l||s||0===V||l.applyToAabb(o),!m(o,M,D,y))return;e(v,O,M);const Z=d[n]/3,I=d[n+1]/3,R=I-Z,B=(t,e,o)=>{this._callback(t,e,n,o)},{vertexData:k,vertexStride:G,indexData:w,_intersectionOptions:E}=this,{normalRequired:H}=E;if(R>C){let t=x[n];null==t&&(t=new i(n,k,G,w,Z,I,this.geometryMinZ,g,r),x[n]=t),t.intersectRay(M,O,A,s?0:V,B,H)}else{a(M,v,Z,I,w,k,G,s?0:V,g,H,B)}}}const b=o(),_=n(),f=n(),u=n(),D=n(),g=()=>{},y=new c,C=40;export{p as ComponentObjectElevationAgnosticComponentBVH};