@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 12.5 kB
JavaScript
import has from"../../../../core/has.js";import e from"../../../../core/Logger.js";import{clamp as t}from"../../../../core/mathUtils.js";import{isSome as r}from"../../../../core/maybe.js";import{createRenderScreenPointArray3 as i}from"../../../../core/screenUtils.js";import{c as s}from"../../../../chunks/vec2.js";import{s as a,b as n,e as o,g as l,a as c,c as h,l as u,i as p,m}from"../../../../chunks/vec3.js";import{c as f}from"../../../../chunks/vec3f64.js";import{O as T}from"../../../../chunks/vec4f64.js";import{PlaneIndex as d}from"../../../../geometry/support/frustum.js";import{create as _,distance2 as E,fromPoints as A,closestLineSegmentPoint as v}from"../../../../geometry/support/lineSegment.js";import{create as R,fromPoints as S,signedDistance as I,normal as g}from"../../../../geometry/support/plane.js";import{newLayout as O}from"../../support/buffer/InterleavedLayout.js";import{ShaderOutput as b}from"../core/shaderLibrary/ShaderOutput.js";import L from"../lib/GLMaterial.js";import{Material as P,RenderOccludedFlag as N}from"../lib/Material.js";import{RenderSlot as C}from"../lib/RenderSlot.js";import{isTranslationMatrix as y}from"../lib/Util.js";import{VertexAttribute as j}from"../lib/VertexAttribute.js";import{VisualVariablePassParameters as D}from"./VisualVariablePassParameters.js";import{LineMarkerAnchor as U}from"../shaders/LineMarkerTechniqueConfiguration.js";import{R as F}from"../../../../chunks/RibbonLine.glsl.js";import{vertexAttributeLocations as x,RibbonLineTechnique as w}from"../shaders/RibbonLineTechnique.js";import{RibbonLineTechniqueConfiguration as M,CapType as J}from"../shaders/RibbonLineTechniqueConfiguration.js";var B;!function(e){e[e.LEFT_JOIN_START=-2]="LEFT_JOIN_START",e[e.LEFT_JOIN_END=-1]="LEFT_JOIN_END",e[e.LEFT_CAP_START=-4]="LEFT_CAP_START",e[e.LEFT_CAP_END=-5]="LEFT_CAP_END",e[e.RIGHT_JOIN_START=2]="RIGHT_JOIN_START",e[e.RIGHT_JOIN_END=1]="RIGHT_JOIN_END",e[e.RIGHT_CAP_START=4]="RIGHT_CAP_START",e[e.RIGHT_CAP_END=5]="RIGHT_CAP_END"}(B||(B={}));class z extends P{constructor(e){super(e,new H),this._configuration=new M,this._vertexAttributeLocations=x,this._layout=this.createLayout()}isClosed(e,t){return Z(this.parameters,e,t)}getConfiguration(e,t){this._configuration.output=e,this._configuration.draped=t.slot===C.DRAPED_MATERIAL;const i=r(this.parameters.stipplePattern)&&e!==b.Highlight;return this._configuration.stippleEnabled=i,this._configuration.stippleOffColorEnabled=i&&r(this.parameters.stippleOffColor),this._configuration.stippleScaleWithLineWidth=i&&this.parameters.stippleScaleWithLineWidth,this._configuration.stipplePreferContinuous=i&&this.parameters.stipplePreferContinuous,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.hasOccludees=this.parameters.hasOccludees,this._configuration.roundJoins="round"===this.parameters.join,this._configuration.capType=this.parameters.cap,this._configuration.applyMarkerOffset=!!r(this.parameters.markerParameters)&&q(this.parameters.markerParameters),this._configuration.hasPolygonOffset=this.parameters.hasPolygonOffset,this._configuration.writeDepth=this.parameters.writeDepth,this._configuration.vvColor=this.parameters.vvColorEnabled,this._configuration.vvOpacity=this.parameters.vvOpacityEnabled,this._configuration.vvSize=this.parameters.vvSizeEnabled,this._configuration.innerColorEnabled=this.parameters.innerWidth>0&&r(this.parameters.innerColor),this._configuration.falloffEnabled=this.parameters.falloff>0,this._configuration.occluder=this.parameters.renderOccluded===N.OccludeAndTransparentStencil,this._configuration.transparencyPassType=t.transparencyPassType,this._configuration.hasMultipassTerrain=t.multipassTerrain.enabled,this._configuration.cullAboveGround=t.multipassTerrain.cullAboveGround,this._configuration.wireframe=this.parameters.wireframe,this._configuration}intersectDraped(e,r,i,s,a,n){if(!i.options.selectionMode)return;const o=e.vertexAttributes.get(j.POSITION).data,l=e.vertexAttributes.get(j.SIZE);let c=this.parameters.width;if(this.parameters.vvSizeEnabled){const r=e.vertexAttributes.get(j.SIZEFEATUREATTRIBUTE).data[0];c*=t(this.parameters.vvSizeOffset[0]+r*this.parameters.vvSizeFactor[0],this.parameters.vvSizeMinSize[0],this.parameters.vvSizeMaxSize[0])}else l&&(c*=l.data[0]);const h=s[0],u=s[1],p=(c/2+4)*e.screenToWorldRatio;let m=Number.MAX_VALUE,f=0;for(let T=0;T<o.length-5;T+=3){const e=o[T],r=o[T+1],i=h-e,s=u-r,a=o[T+3]-e,n=o[T+4]-r,l=t((a*i+n*s)/(a*a+n*n),0,1),c=a*l-i,p=n*l-s,d=c*c+p*p;d<m&&(m=d,f=T/3)}m<p*p&&a(n.dist,n.normal,f,!1)}intersect(r,i,m,f,T,_){if(!m.options.selectionMode||!r.visible)return;if(!y(i))return void e.getLogger("esri.views.3d.webgl-engine.materials.RibbonLineMaterial").error("intersection assumes a translation-only matrix");const R=r.vertexAttributes,O=R.get(j.POSITION).data;let b=this.parameters.width;if(this.parameters.vvSizeEnabled){const e=R.get(j.SIZEFEATUREATTRIBUTE).data[0];b*=t(this.parameters.vvSizeOffset[0]+e*this.parameters.vvSizeFactor[0],this.parameters.vvSizeMinSize[0],this.parameters.vvSizeMaxSize[0])}else R.has(j.SIZE)&&(b*=R.get(j.SIZE).data[0]);const L=m.camera,P=$;s(P,m.point);const N=b*L.pixelRatio/2+4*L.pixelRatio;a(ce[0],P[0]-N,P[1]+N,0),a(ce[1],P[0]+N,P[1]+N,0),a(ce[2],P[0]+N,P[1]-N,0),a(ce[3],P[0]-N,P[1]-N,0);for(let e=0;e<4;e++)if(!L.unprojectFromRenderScreen(ce[e],he[e]))return;S(L.eye,he[0],he[1],ue),S(L.eye,he[1],he[2],pe),S(L.eye,he[2],he[3],me),S(L.eye,he[3],he[0],fe);let C=Number.MAX_VALUE,D=0;const U=V(this.parameters,R,r.indices)?O.length-2:O.length-5;for(let e=0;e<U;e+=3){X[0]=O[e]+i[12],X[1]=O[e+1]+i[13],X[2]=O[e+2]+i[14];const t=(e+3)%O.length;if(Y[0]=O[t]+i[12],Y[1]=O[t+1]+i[13],Y[2]=O[t+2]+i[14],I(ue,X)<0&&I(ue,Y)<0||I(pe,X)<0&&I(pe,Y)<0||I(me,X)<0&&I(me,Y)<0||I(fe,X)<0&&I(fe,Y)<0)continue;if(L.projectToRenderScreen(X,ee),L.projectToRenderScreen(Y,te),ee[2]<0&&te[2]>0){n(Q,X,Y);const e=L.frustum,t=-I(e[d.NEAR],X)/o(Q,g(e[d.NEAR]));l(Q,Q,t),c(X,X,Q),L.projectToRenderScreen(X,ee)}else if(ee[2]>0&&te[2]<0){n(Q,Y,X);const e=L.frustum,t=-I(e[d.NEAR],Y)/o(Q,g(e[d.NEAR]));l(Q,Q,t),c(Y,Y,Q),L.projectToRenderScreen(Y,te)}else if(ee[2]<0&&te[2]<0)continue;ee[2]=0,te[2]=0;const r=E(A(ee,te,se),P);r<C&&(C=r,h(re,X),h(ie,Y),D=e/3)}const F=m.rayBegin,x=m.rayEnd;if(C<N*N){let e=Number.MAX_VALUE;if(v(A(re,ie,se),A(F,x,ae),K)){n(K,K,F);const t=u(K);l(K,K,1/t),e=t/p(F,x)}_(e,K,D,!1)}}createLayout(){const e=O().vec3f(j.POSITION).f32(j.SUBDIVISIONFACTOR).vec2f(j.UV0).vec3f(j.AUXPOS1).vec3f(j.AUXPOS2);return this.parameters.vvSizeEnabled?e.f32(j.SIZEFEATUREATTRIBUTE):e.f32(j.SIZE),this.parameters.vvColorEnabled?e.f32(j.COLORFEATUREATTRIBUTE):e.vec4f(j.COLOR),this.parameters.vvOpacityEnabled&&e.f32(j.OPACITYFEATUREATTRIBUTE),has("enable-feature:objectAndLayerId-rendering")&&e.vec4u8(j.OBJECTANDLAYERIDCOLOR),e}createBufferWriter(){return new k(this._layout,this.parameters)}requiresSlot(e,t){if(t===b.Color||t===b.Alpha||t===b.Highlight||t===b.Depth||t===b.ObjectAndLayerIdColor){if(e===C.DRAPED_MATERIAL)return!0;if(this.parameters.renderOccluded===N.OccludeAndTransparentStencil)return e===C.OPAQUE_MATERIAL||e===C.OCCLUDER_MATERIAL||e===C.TRANSPARENT_OCCLUDER_MATERIAL;if(t===b.Color||t===b.Alpha){return e===(this.parameters.writeDepth?C.TRANSPARENT_MATERIAL:C.TRANSPARENT_DEPTH_WRITE_DISABLED_MATERIAL)}return e===C.OPAQUE_MATERIAL}return!1}createGLMaterial(e){return new G(e)}validateParameters(e){"miter"!==e.join&&(e.miterLimit=0),r(e.markerParameters)&&(e.markerScale=e.markerParameters.width/e.width)}}class G extends L{constructor(){super(...arguments),this._stipplePattern=null}dispose(){super.dispose(),this._stippleTextureRepository.release(this._stipplePattern),this._stipplePattern=null}_updateOccludeeState(e){e.hasOccludees!==this._material.parameters.hasOccludees&&this._material.setParameters({hasOccludees:e.hasOccludees})}beginSlot(e){this._output!==b.Color&&this._output!==b.Alpha||this._updateOccludeeState(e);const t=this._material.parameters.stipplePattern;return this._stipplePattern!==t&&(this._material.setParameters(this._stippleTextureRepository.swap(this._stipplePattern,t)),this._stipplePattern=t),this.ensureTechnique(w,e)}}class H extends D{constructor(){super(...arguments),this.width=0,this.color=T,this.join="miter",this.cap=J.BUTT,this.miterLimit=5,this.writeDepth=!0,this.hasPolygonOffset=!1,this.stippleTexture=null,this.stippleScaleWithLineWidth=!1,this.stipplePreferContinuous=!0,this.markerParameters=null,this.markerScale=1,this.hasSlicePlane=!1,this.vvFastUpdate=!1,this.isClosed=!1,this.falloff=0,this.innerWidth=0,this.hasOccludees=!1,this.wireframe=!1}}class k{constructor(e,t){this._parameters=t,this.numJoinSubdivisions=0,this.vertexBufferLayout=e;const r=t.stipplePattern?1:0;switch(this._parameters.join){case"miter":case"bevel":this.numJoinSubdivisions=r;break;case"round":this.numJoinSubdivisions=F+r}}_isClosed(e){return V(this._parameters,e.vertexAttributes,e.indices)}allocate(e){return this.vertexBufferLayout.createBuffer(e)}elementCount(e){const t=2,r=e.indices.get(j.POSITION).length/2+1,i=this._isClosed(e);let s=i?2:2*t;return s+=((i?r:r-1)-(i?0:1))*(2*this.numJoinSubdivisions+4),s+=2,this._parameters.wireframe&&(s=2+4*(s-2)),s}write(e,t,i,s,n){const o=ne,l=oe,c=le,u=i.vertexAttributes.get(j.POSITION).data,f=i.indices&&i.indices.get(j.POSITION),T=i.vertexAttributes.get(j.DISTANCETOSTART)?.data;f&&f.length!==2*(u.length/3-1)&&console.warn("RibbonLineMaterial does not support indices");let d=1,_=0;this._parameters.vvSizeEnabled?_=i.vertexAttributes.get(j.SIZEFEATUREATTRIBUTE).data[0]:i.vertexAttributes.has(j.SIZE)&&(d=i.vertexAttributes.get(j.SIZE).data[0]);let E=[1,1,1,1],A=0;this._parameters.vvColorEnabled?A=i.vertexAttributes.get(j.COLORFEATUREATTRIBUTE).data[0]:i.vertexAttributes.has(j.COLOR)&&(E=i.vertexAttributes.get(j.COLOR).data);const v=has("enable-feature:objectAndLayerId-rendering")?i.objectAndLayerIdColor:null;let R=0;this._parameters.vvOpacityEnabled&&(R=i.vertexAttributes.get(j.OPACITYFEATUREATTRIBUTE).data[0]);const S=u.length/3,I=new Float32Array(s.buffer),g=has("enable-feature:objectAndLayerId-rendering")?new Uint8Array(s.buffer):null,O=this.vertexBufferLayout.stride/4;let b=n*O;const L=b;let P=0;const N=T?(e,t,r)=>P=T[r]:(e,t,r)=>P+=p(e,t),C=has("enable-feature:objectAndLayerId-rendering"),y=(e,t,i,s,a,n,o)=>{if(I[b++]=t[0],I[b++]=t[1],I[b++]=t[2],I[b++]=s,I[b++]=o,I[b++]=a,I[b++]=e[0],I[b++]=e[1],I[b++]=e[2],I[b++]=i[0],I[b++]=i[1],I[b++]=i[2],this._parameters.vvSizeEnabled?I[b++]=_:I[b++]=d,this._parameters.vvColorEnabled)I[b++]=A;else{const e=Math.min(4*n,E.length-4);I[b++]=E[e],I[b++]=E[e+1],I[b++]=E[e+2],I[b++]=E[e+3]}this._parameters.vvOpacityEnabled&&(I[b++]=R),C&&(r(v)&&(g[4*b]=v[0],g[4*b+1]=v[1],g[4*b+2]=v[2],g[4*b+3]=v[3]),b++)};b+=O,a(l,u[0],u[1],u[2]),e&&m(l,l,e);const D=this._isClosed(i);if(D){const t=u.length-3;a(o,u[t],u[t+1],u[t+2]),e&&m(o,o,e)}else a(c,u[3],u[4],u[5]),e&&m(c,c,e),y(l,l,c,1,B.LEFT_CAP_START,0,0),y(l,l,c,1,B.RIGHT_CAP_START,0,0),h(o,l),h(l,c);const U=D?0:1,F=D?S:S-1;for(let r=U;r<F;r++){const t=(r+1)%S*3;a(c,u[t],u[t+1],u[t+2]),e&&m(c,c,e),N(o,l,r),y(o,l,c,0,B.LEFT_JOIN_END,r,P),y(o,l,c,0,B.RIGHT_JOIN_END,r,P);const i=this.numJoinSubdivisions;for(let e=0;e<i;++e){const t=(e+1)/(i+1);y(o,l,c,t,B.LEFT_JOIN_END,r,P),y(o,l,c,t,B.RIGHT_JOIN_END,r,P)}y(o,l,c,1,B.LEFT_JOIN_START,r,P),y(o,l,c,1,B.RIGHT_JOIN_START,r,P),h(o,l),h(l,c)}D?(a(c,u[3],u[4],u[5]),e&&m(c,c,e),P=N(o,l,F),y(o,l,c,0,B.LEFT_JOIN_END,U,P),y(o,l,c,0,B.RIGHT_JOIN_END,U,P)):(P=N(o,l,F),y(o,l,l,0,B.LEFT_CAP_END,F,P),y(o,l,l,0,B.RIGHT_CAP_END,F,P)),W(I,L+O,I,L,O);b=W(I,b-O,I,b,O),this._parameters.wireframe&&this._addWireframeVertices(s,L,b,O)}_addWireframeVertices(e,t,r,i){const s=new Float32Array(e.buffer,r*Float32Array.BYTES_PER_ELEMENT),a=new Float32Array(e.buffer,t*Float32Array.BYTES_PER_ELEMENT,r-t);let n=0;const o=e=>n=W(a,e,s,n,i);for(let l=0;l<a.length-1;l+=2*i)o(l),o(l+2*i),o(l+1*i),o(l+2*i),o(l+1*i),o(l+3*i)}}function W(e,t,r,i,s){for(let a=0;a<s;a++)r[i++]=e[t++];return i}function V(e,t,r){return Z(e,t.get(j.POSITION).data,r?r.get(j.POSITION):null)}function Z(e,t,r){return!!e.isClosed&&(r?r.length>2:t.length>6)}function q(e){return e.anchor===U.Tip&&e.hideOnShortSegments&&"begin-end"===e.placement&&e.worldSpace}const X=f(),Y=f(),Q=f(),K=f(),$=f(),ee=i(),te=i(),re=f(),ie=f(),se=_(),ae=_(),ne=f(),oe=f(),le=f(),ce=[i(),i(),i(),i()],he=[f(),f(),f(),f()],ue=R(),pe=R(),me=R(),fe=R();export{H as Parameters,z as RibbonLineMaterial};