UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.81 kB
import{isSome as t,isNone as o}from"../../../../../core/maybe.js";import{t as s}from"../../../../../chunks/vec3.js";import{c as n}from"../../../../../chunks/vec3f64.js";import{create as e}from"../../../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f as i}from"../../../../../geometry/support/buffer/BufferView.js";import{componentMinimalSizeForIntersectionData as r,ComponentIntersectionData as p}from"./ComponentIntersectionData.js";import{Attribute as m}from"../../lib/Attribute.js";import{getVisibility as a}from"../../lib/ComponentUtils.js";import{generateDefaultIndexArray as c}from"../../lib/Indices.js";import{computeInvDir as h,intersectAabbInvDir as f,intersectTriangles as b}from"../../materials/internal/MaterialUtil.js";class _{constructor(o,s){this._indices=t(o.indices)?o.indices:c(o.positions.length/3),this._positions=new i(o.positions),this._components=s,this._componentIntersectionData=new Array(s.count)}getComponentAabb(o,s){if(t(this._perComponentAabbs)){for(let t=0;t<6;t++)s[t]=this._perComponentAabbs[6*o+t];return s}return this._computePerComponentAabbs(),this.getComponentAabb(o,s)}getComponentPositions(t,o){o.indices=this._indices,o.data=this._positions.typedBuffer,o.stride=this._positions.typedBufferStride,o.startIndex=this._components.offsets[t],o.endIndex=this._components.offsets[t+1]}intersect(n,e,i,c,_,l,A){const C=new m(this._positions.typedBuffer,3,!1,this._positions.typedBufferStride),y=this._indices,g=this._components.offsets,j=h(n,e,d),B=n[2],I=e[2];this._components.visibility.forEachComponent((m=>{if(!a(this._components.pickability,m))return!0;const h=this.getComponentAabb(m,u);if(t(l)){const o=l[m];t(_)?_.componentOffset=o:(n[2]=B-o,e[2]=I-o)}if(t(_)&&_.applyToAabb(h),!f(h,n,j,i))return!0;const d=g[m]/3,x=g[m+1]/3,M=x-d,w=(t,o,n)=>A(m,t,s(o,o,c),n);return o(_)&&M>r?(null==this._componentIntersectionData[m]&&(this._componentIntersectionData[m]=new p(this._indices,d,x,C)),this._componentIntersectionData[m].intersectRay({r0:n,r1:e},w)):b(n,e,d,x,y,C,void 0,_,w),!0}))}_computePerComponentAabbs(){const t=this._components.count;this._perComponentAabbs=new Float32Array(6*t);const o=this._indices,s=this._positions.typedBuffer,n=this._positions.typedBufferStride,e=this._components.offsets;let i=0;for(let r=0;r<t;r++){const t=e[r],p=e[r+1];let m=1/0,a=1/0,c=1/0,h=-1/0,f=-1/0,b=-1/0;for(let e=t;e<p;e++){const t=o[e]*n,i=s[t],r=s[t+1],p=s[t+2];m=Math.min(m,i),a=Math.min(a,r),c=Math.min(c,p),h=Math.max(h,i),f=Math.max(f,r),b=Math.max(b,p)}this._perComponentAabbs[i++]=m,this._perComponentAabbs[i++]=a,this._perComponentAabbs[i++]=c,this._perComponentAabbs[i++]=h,this._perComponentAabbs[i++]=f,this._perComponentAabbs[i++]=b}}get positions(){return this._positions}get indices(){return this._indices}}const d=n(),u=e();export{_ as default};