UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.65 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import t from"../../../../../core/PooledArray.js";import{fromQuat as e,scale as n}from"../../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as r}from"../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{conjugate as o}from"../../../../../core/libs/gl-matrix-2/math/quat.js";import{create as a}from"../../../../../core/libs/gl-matrix-2/factories/quatf64.js";import{e as s,a as i,v as c,i as l,o as f,f as u,m,c as h}from"../../../../../chunks/vec32.js";import{create as b}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{signedDistance as p}from"../../../../../geometry/support/plane.js";import{DepthRange as g}from"../../lib/DepthRange.js";function j(t,e){const n=new g,{eye:r,frustum:o,viewForward:a}=t;e.forAll((t=>{const e=null!=t.offsetObb?t.offsetObb:t.obb,c=s(i(M,e.center,r),a),l=e.projectedRadius(a);if(n.within(c-l)&&n.within(c+l))return;const f=S(e,o);if(-1===f)return;if(0===f)return w.far=c+l,w.near=c-l,void n.union(w);const u=d.pushNew();u.near=c-l,u.far=c+l,u.mask=f,u.object=t}));for(let c=0;c<d.length;c++){const t=d.data[c];if(n.within(t.near)&&n.within(t.far))continue;w.far=t.far,w.near=1/0;const e=z(null!=t.object.offsetObb?t.object.offsetObb:t.object.obb,r,k,(e=>{let n=q;for(let r=0;r<R&&e.length>0;r++){if(!(t.mask&1<<r))continue;y(o[r],e,n);const a=e;e=n,n=a}for(let t=0;t<e.length;t+=3){l(x,e.data[t],e.data[t+1],e.data[t+2]);const n=s(i(x,x,r),a);w.near=Math.min(w.near,n)}}));0===e&&(w.near=0),n.union(w)}return d.length=0,n}const d=new t({allocator:t=>t||{near:1/0,far:-1/0,mask:0,object:null},deallocator:t=>(t.object=null,t)}),w=new g,x=b(),v=b(),k=new t({deallocator:null}),q=new t({deallocator:null});function y(t,e,n){n.length=0;const r=e.length-3;O(x,e,r);const o=p(t,x);o<=0&&(n.push(x[0]),n.push(x[1]),n.push(x[2]));let a=0,s=o;for(;a<r;a+=3){O(v,e,a);const r=p(t,v);if(s*r<0){m(x,v,x,r/(r-s)),A(n,x)}r<=0&&A(n,v),s=r,h(x,v)}if(s*o<0){O(v,e,r);m(x,v,x,o/(o-s)),A(n,x)}}function O(t,e,n){return l(t,e.data[n],e.data[n+1],e.data[n+2])}function A(t,e){t.push(e[0]),t.push(e[1]),t.push(e[2])}function z(t,r,a,s){o(F,t.quaternion),i(M,r,t.center),c(M,M,F);const m=t.halfSize,h=8*((M[0]<-m[0]?-1:M[0]>m[0]?1:0)+3*(M[1]<-m[1]?-1:M[1]>m[1]?1:0)+9*(M[2]<-m[2]?-1:M[2]>m[2]?1:0)+13),b=P[h];if(0===b)return b;e(D,t.quaternion),n(D,D,t.halfSize);const p=(e,n)=>{const r=P[h+n+1];return l(e,((1&r)<<1)-1,(2&r)-1,((4&r)>>1)-1),f(e,e,D),u(e,t.center,e)};return a.length=0,A(a,p(N,0)),A(a,p(B,1)),A(a,p(M,2)),A(a,p(C,3)),s(a),1===b?b:(a.length=0,A(a,N),A(a,C),A(a,p(M,4)),A(a,p(E,5)),s(a),2===b||(a.length=0,A(a,N),A(a,E),A(a,p(M,6)),A(a,B),s(a)),b)}const P=(()=>{const t=new Array(216);let e=0;const n=n=>{for(let r=0;r<n.length;r++)t[e+r]=n[r];e+=8};return n([3,0,6,2,3,1,5,4]),n([2,0,2,3,1,5,4,0]),n([3,1,0,2,3,7,5,4]),n([2,0,1,3,2,6,4,0]),n([1,0,1,3,2,0,0,0]),n([2,1,5,7,3,2,0,0]),n([3,2,0,1,3,7,6,4]),n([2,2,0,1,3,7,6,0]),n([3,3,0,1,5,7,6,2]),n([2,0,1,5,4,6,2,0]),n([1,0,1,5,4,0,0,0]),n([2,1,3,7,5,4,0,0]),n([1,0,2,6,4,0,0,0]),n([0,0,0,0,0,0,0,0]),n([1,1,3,7,5,0,0,0]),n([2,2,3,7,6,4,0,0]),n([1,2,3,7,6,0,0,0]),n([2,3,1,5,7,6,2,0]),n([3,4,0,1,5,7,6,2]),n([2,5,7,6,4,0,1,0]),n([3,5,0,1,3,7,6,4]),n([2,4,5,7,6,2,0,0]),n([1,4,5,7,6,0,0,0]),n([2,5,1,3,7,6,4,0]),n([3,6,0,2,3,7,5,4]),n([2,6,2,3,7,5,4,0]),n([3,7,6,2,3,1,5,4]),t})(),R=4;function S(t,e){let n=0;for(let r=0;r<R;r++){const o=t.intersectPlane(e[r]);if(o>0)return-1;0===o&&(n|=1<<r)}return n}const D=r(),F=a(),M=b(),N=b(),B=b(),C=b(),E=b();export{j as computeDepthRange};