@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 4.18 kB
JavaScript
import{update as t}from"../../../../../core/arrayUtils.js";import{clamp as n}from"../../../../../core/mathUtils.js";import{isNone as e,isSome as o}from"../../../../../core/maybe.js";import{s as i,f as r,n as s}from"../../../../../chunks/vec3.js";import{c}from"../../../../../chunks/vec3f64.js";import{create as f,setMin as l,setMax as a}from"../../../../../geometry/support/aaBoundingBox.js";import{ContentObjectType as u}from"../../lib/ContentObjectType.js";import{scale as m}from"../../lib/screenSizePerspectiveUtils.js";import{assert as p}from"../../lib/Util.js";import{VertexAttribute as h}from"../../lib/VertexAttribute.js";const b=f();function x(t,n,e,o,i,r){if(t.visible)if(t.boundingInfo){p(t.type===u.Mesh);const s=n.tolerance;g(t.boundingInfo,e,o,s,i,r)}else{const n=t.indices.get(h.POSITION),s=t.vertexAttributes.get(h.POSITION);y(e,o,0,n.length/3,n,s,void 0,i,r)}}const d=c();function g(t,n,i,r,s,c){if(e(t))return;const f=O(n,i,d);if(l(b,t.bbMin),a(b,t.bbMax),o(s)&&s.applyToAabb(b),V(b,n,f,r)){const{primitiveIndices:e,indices:o,position:f}=t,l=e?e.length:o.length/3;if(l>U){const e=t.getChildren();if(void 0!==e){for(const t of e)g(t,n,i,r,s,c);return}}y(n,i,0,l,o,f,e,s,c)}}const M=c();function y(t,n,e,i,r,s,c,f,l){if(c)return j(t,n,e,i,r,s,c,f,l);const{data:a,stride:u}=s,m=t[0],p=t[1],h=t[2],b=n[0]-m,x=n[1]-p,d=n[2]-h;for(let g=e,y=3*e;g<i;++g){let t=u*r[y++],n=a[t++],e=a[t++],i=a[t];t=u*r[y++];let s=a[t++],c=a[t++],j=a[t];t=u*r[y++];let v=a[t++],T=a[t++],O=a[t];o(f)&&([n,e,i]=f.applyToVertex(n,e,i,g),[s,c,j]=f.applyToVertex(s,c,j,g),[v,T,O]=f.applyToVertex(v,T,O,g));const V=s-n,L=c-e,N=j-i,A=v-n,P=T-e,S=O-i,E=x*S-P*d,U=d*A-S*b,W=b*P-A*x,k=V*E+L*U+N*W;if(Math.abs(k)<=Number.EPSILON)continue;const B=m-n,C=p-e,z=h-i,H=B*E+C*U+z*W;if(k>0){if(H<0||H>k)continue}else if(H>0||H<k)continue;const R=C*N-L*z,Y=z*V-N*B,q=B*L-V*C,w=b*R+x*Y+d*q;if(k>0){if(w<0||H+w>k)continue}else if(w>0||H+w<k)continue;const D=(A*R+P*Y+S*q)/k;if(D>=0){l(D,I(V,L,N,A,P,S,M),g,!1)}}}function j(t,n,e,i,r,s,c,f,l){const{data:a,stride:u}=s,m=t[0],p=t[1],h=t[2],b=n[0]-m,x=n[1]-p,d=n[2]-h;for(let g=e;g<i;++g){const t=c[g];let n=3*t,e=u*r[n++],i=a[e++],s=a[e++],y=a[e];e=u*r[n++];let j=a[e++],v=a[e++],T=a[e];e=u*r[n];let O=a[e++],V=a[e++],L=a[e];o(f)&&([i,s,y]=f.applyToVertex(i,s,y,g),[j,v,T]=f.applyToVertex(j,v,T,g),[O,V,L]=f.applyToVertex(O,V,L,g));const N=j-i,A=v-s,P=T-y,S=O-i,E=V-s,U=L-y,W=x*U-E*d,k=d*S-U*b,B=b*E-S*x,C=N*W+A*k+P*B;if(Math.abs(C)<=Number.EPSILON)continue;const z=m-i,H=p-s,R=h-y,Y=z*W+H*k+R*B;if(C>0){if(Y<0||Y>C)continue}else if(Y>0||Y<C)continue;const q=H*P-A*R,w=R*N-P*z,D=z*A-N*H,F=b*q+x*w+d*D;if(C>0){if(F<0||Y+F>C)continue}else if(F>0||Y+F<C)continue;const G=(S*q+E*w+U*D)/C;if(G>=0){l(G,I(N,A,P,S,E,U,M),t,!1)}}}const v=c(),T=c();function I(t,n,e,o,c,f,l){return i(v,t,n,e),i(T,o,c,f),r(l,v,T),s(l,l),l}function O(t,n,e){return i(e,1/(n[0]-t[0]),1/(n[1]-t[1]),1/(n[2]-t[2]))}function V(t,n,e,o){return L(t,n,e,o,1/0)}function L(t,n,e,o,i){const r=(t[0]-o-n[0])*e[0],s=(t[3]+o-n[0])*e[0];let c=Math.min(r,s),f=Math.max(r,s);const l=(t[1]-o-n[1])*e[1],a=(t[4]+o-n[1])*e[1];if(f=Math.min(f,Math.max(l,a)),f<0)return!1;if(c=Math.max(c,Math.min(l,a)),c>f)return!1;const u=(t[2]-o-n[2])*e[2],m=(t[5]+o-n[2])*e[2];return f=Math.min(f,Math.max(u,m)),!(f<0)&&(c=Math.max(c,Math.min(u,m)),!(c>f)&&c<i)}function N(t,e,i,r,s){let c=(i.screenLength||0)*t.pixelRatio;o(s)&&(c=m(c,r,e,s));const f=c*Math.tan(.5*t.fovY)/(.5*t.fullHeight);return n(f*e,i.minWorldLength||0,null!=i.maxWorldLength?i.maxWorldLength:1/0)}function A(t,n){const e=n?A(n):{};for(const o in t){let n=t[o];n&&n.forEach&&(n=S(n)),null==n&&o in e||(e[o]=n)}return e}function P(n,e){let o=!1;for(const i in e){const r=e[i];void 0!==r&&(Array.isArray(r)?null===n[i]?(n[i]=r.slice(),o=!0):t(n[i],r)&&(o=!0):n[i]!==r&&(o=!0,n[i]=r))}return o}function S(t){const n=[];return t.forEach((t=>n.push(t))),n}const E={multiply:1,ignore:2,replace:3,tint:4},U=1e3;export{E as colorMixModes,O as computeInvDir,I as computeNormal,A as copyParameters,V as intersectAabbInvDir,L as intersectAabbInvDirBefore,x as intersectTriangleGeometry,y as intersectTriangles,P as updateParameters,N as verticalOffsetAtDistance};