UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.51 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../../../core/Logger.js";import{clamp as r}from"../../../../core/mathUtils.js";import{createRenderScreenPointArray3 as t}from"../../../../core/screenUtils.js";import{copy as o}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{i as s,d as i,e as a,g as n,f as c,c as m,l,j as f}from"../../../../chunks/vec32.js";import{create as u}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as p}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{PlaneIndex as h}from"../../../../geometry/support/frustum.js";import{distance2 as g,fromPoints as d,create as j,closestLineSegmentPoint as b}from"../../../../geometry/support/lineSegment.js";import{fromPoints as A,create as S,signedDistance as x,getNormal as L}from"../../../../geometry/support/plane.js";import{isColorHighlightOrOID as y}from"../core/shaderLibrary/ShaderOutput.js";import N from"../lib/GLMaterial.js";import{Material as R,MaterialParameters as v}from"../lib/Material.js";import{RenderSlot as E}from"../lib/RenderSlot.js";import{isTranslationMatrix as M}from"../lib/Util.js";import{VertexAttribute as T}from"../lib/VertexAttribute.js";import{DefaultBufferWriter as _}from"./DefaultBufferWriter.js";import{PositionColorLayout as w,PositionLayout as C}from"./DefaultLayouts.js";import{NativeLineTechnique as O}from"../shaders/NativeLineTechnique.js";import{NativeLineTechniqueConfiguration as V}from"../shaders/NativeLineTechniqueConfiguration.js";import{alphaCutoff as P}from"../../../../webscene/support/AlphaCutoff.js";class U extends R{constructor(e){super(e,q),this._configuration=new V,this.produces=new Map([[E.OPAQUE_MATERIAL,e=>y(e)]])}getConfiguration(e,r){return super.getConfiguration(e,r,this._configuration),this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.hasVertexColors=this.parameters.hasVertexColors,this._configuration.transparent=this.parameters.color[3]<1||this.parameters.width<1,this._configuration.hasOccludees=r.hasOccludees,this._configuration}get visible(){return this.parameters.color[3]>=P}intersect(r,t,u,p,j,S){const y=u.camera;if(!u.options.selectionMode||!r.visible||!y)return;if(!M(t))return void e.getLogger("esri.views.3d.webgl-engine.materials.NativeLineMaterial").error("intersection assumes a translation-only matrix");const N=r.attributes.get(T.POSITION).data,R=H;o(R,u.point);const v=2;s(J[0],R[0]-v,R[1]+v,0),s(J[1],R[0]+v,R[1]+v,0),s(J[2],R[0]+v,R[1]-v,0),s(J[3],R[0]-v,R[1]-v,0);for(let e=0;e<4;e++)if(!y.unprojectFromRenderScreen(J[e],K[e]))return;A(y.eye,K[0],K[1],Y),A(y.eye,K[1],K[2],$),A(y.eye,K[2],K[3],ee),A(y.eye,K[3],K[0],re);let E=Number.MAX_VALUE,_=0;for(let e=0;e<N.length-5;e+=3){if(B[0]=N[e]+t[12],B[1]=N[e+1]+t[13],B[2]=N[e+2]+t[14],D[0]=N[e+3]+t[12],D[1]=N[e+4]+t[13],D[2]=N[e+5]+t[14],x(Y,B)<0&&x(Y,D)<0||x($,B)<0&&x($,D)<0||x(ee,B)<0&&x(ee,D)<0||x(re,B)<0&&x(re,D)<0)continue;if(y.projectToRenderScreen(B,G),y.projectToRenderScreen(D,k),G[2]<0&&k[2]>0){i(W,B,D);const e=y.frustum,r=-x(e[h.NEAR],B)/a(W,L(e[h.NEAR]));n(W,W,r),c(B,B,W),y.projectToRenderScreen(B,G)}else if(G[2]>0&&k[2]<0){i(W,D,B);const e=y.frustum,r=-x(e[h.NEAR],D)/a(W,L(e[h.NEAR]));n(W,W,r),c(D,D,W),y.projectToRenderScreen(D,k)}else if(G[2]<0&&k[2]<0)continue;G[2]=0,k[2]=0;const r=g(d(G,k,Z),R);r<E&&(E=r,m(F,B),m(Q,D),_=e/3)}const w=u.rayBegin,C=u.rayEnd;if(E<v*v){let e=Number.MAX_VALUE;if(b(d(F,Q,Z),d(w,C,z),X)){i(X,X,w);const r=l(X);n(X,X,1/r),e=r/f(w,C)}S(e,X,_)}}intersectDraped(e,t,o,s,i){if(!t.options.selectionMode)return;const a=e.attributes.get(T.POSITION).data,n=e.attributes.get(T.SIZE),c=n?n.data[0]:0,m=o[0],l=o[1],f=((c+1)/2+4)*e.screenToWorldRatio;let u=Number.MAX_VALUE,p=0;for(let h=0;h<a.length-5;h+=3){const e=a[h],t=a[h+1],o=m-e,s=l-t,i=a[h+3]-e,n=a[h+4]-t,c=r((i*o+n*s)/(i*i+n*n),0,1),f=i*c-o,g=n*c-s,d=f*f+g*g;d<u&&(u=d,p=h/3)}u<f*f&&s(i.distance,i.normal,p)}createGLMaterial(e){return new I(e)}createBufferWriter(){const e=this.parameters.hasVertexColors?w:C;return new _(e)}}class I extends N{beginSlot(e){return this.getTechnique(O,e)}}class q extends v{constructor(){super(...arguments),this.color=p,this.hasVertexColors=!1,this.hasSlicePlane=!1,this.width=1}}const B=u(),D=u(),W=u(),X=u(),G=t(),k=t(),F=u(),Q=u(),Z=j(),z=j(),H=u(),J=[t(),t(),t(),t()],K=[u(),u(),u(),u()],Y=S(),$=S(),ee=S(),re=S();export{U as NativeLineMaterial,q as Parameters};