@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 12.6 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import t from"../../../../core/Logger.js";import{clamp as e}from"../../../../core/mathUtils.js";import{createRenderScreenPointArray3 as i}from"../../../../core/screenUtils.js";import{secondsFromMilliseconds as r,Seconds as s}from"../../../../core/time.js";import{copy as a}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{set as n,subtract as o,dot as l,scale as h,add as p,copy as m,length as c,distance as u,transformMat4 as f}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as d}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as g}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{ONES as _,create as b}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{makeFloat16Array as S}from"../../../../geometry/support/float16.js";import{distance2 as v,fromPoints as P,closestLineSegmentPoint as w,create as j}from"../../../../geometry/support/lineSegment.js";import{fromPoints as y,signedDistance as E,getNormal as T,create as z}from"../../../../geometry/support/plane.js";import{isHighlightOrOLID as A,isColor as C,isDepth as x,isColorHighlightOLIDOrDepth as L,is2DGeometryOutput as M}from"../core/shaderLibrary/ShaderOutput.js";import{olidEnabled as O}from"../effects/geometry/olidUtils.js";import V from"../lib/GLMaterial.js";import{Material as R}from"../lib/Material.js";import{isTranslationMatrix as F}from"../lib/Util.js";import{isImagePattern as N}from"./lineStippleUtils.js";import{VisualVariablePassParameters as k}from"./VisualVariablePassParameters.js";import{writeDeltaF16Vector as U}from"./internal/bufferWriterUtils.js";import{r as D}from"../../../../chunks/RibbonLine.glsl.js";import{getLayout as B,RibbonLineTechnique as W}from"../shaders/RibbonLineTechnique.js";import{RibbonLineTechniqueConfiguration as J}from"../shaders/RibbonLineTechniqueConfiguration.js";import{alphaCutoff as I}from"../../../../webscene/support/AlphaCutoff.js";class Y extends R{constructor(t,e){super(t,X),this.produces=new Map([[2,t=>A(t)||C(t)&&8===this.parameters.renderOccluded],[3,t=>x(t)],[11,t=>L(t)&&8===this.parameters.renderOccluded],[12,t=>L(t)&&8===this.parameters.renderOccluded],[4,t=>C(t)&&this.parameters.writeDepth&&8!==this.parameters.renderOccluded],[9,t=>C(t)&&!this.parameters.writeDepth&&8!==this.parameters.renderOccluded],[20,t=>M(t)]]),this._configuration=new J(e)}getConfiguration(t,e){super.getConfiguration(t,e,this._configuration);const i=20===e.slot,r=null!=this.parameters.stipplePattern&&null!=this.parameters.stippleTexture&&8!==t,s=r&&i&&this.parameters.isImagePattern();return this._configuration.draped=i,this._configuration.stippleEnabled=r,this._configuration.stippleOffColorEnabled=r&&null!=this.parameters.stippleOffColor,this._configuration.stipplePreferContinuous=r&&this.parameters.stipplePreferContinuous,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.roundJoins="round"===this.parameters.join,this._configuration.capType=this.parameters.cap,this._configuration.applyMarkerOffset=null!=this.parameters.markerParameters&&Q(this.parameters.markerParameters),this._configuration.hasPolygonOffset=this.parameters.hasPolygonOffset,this._configuration.writeDepth=this.parameters.writeDepth,this._configuration.hasVVSize=this.parameters.hasVVSize,this._configuration.hasVVColor=this.parameters.hasVVColor,this._configuration.hasVVOpacity=this.parameters.hasVVOpacity,this._configuration.innerColorEnabled=this.parameters.innerWidth>0&&null!=this.parameters.innerColor,this._configuration.falloffEnabled=this.parameters.falloff>0,this._configuration.hasOccludees=e.hasOccludees,this._configuration.occluder=8===this.parameters.renderOccluded,this._configuration.terrainDepthTest=e.terrainDepthTest&&C(t),this._configuration.cullAboveTerrain=e.cullAboveTerrain,this._configuration.wireframe=this.parameters.wireframe,this._configuration.animation=this.parameters.animation,this._configuration.emissionSource=this.hasEmissions?1:0,this._configuration.hasScreenSizePerspective=!!this.parameters.screenSizePerspective&&!s,this._configuration.worldSizedImagePattern=s,this._configuration}get visible(){return this.parameters.color[3]>=I||null!=this.parameters.stipplePattern&&(this.parameters.stippleOffColor?.[3]??0)>I}setParameters(t,e){t.animation=this.parameters.animation,super.setParameters(t,e)}intersectDraped({attributes:t,screenToWorldRatio:i},r,s,a,n){if(!r.options.selectionMode)return;const o=t.get("size");let l=this.parameters.width;if(this.parameters.vvSize){const i=t.get("sizeFeatureAttribute").data[0];Number.isNaN(i)?l*=this.parameters.vvSize.fallback[0]:l*=e(this.parameters.vvSize.offset[0]+i*this.parameters.vvSize.factor[0],this.parameters.vvSize.minSize[0],this.parameters.vvSize.maxSize[0])}else o&&(l*=o.data[0]);const h=s[0],p=s[1],m=(l/2+4)*i;let c=Number.MAX_VALUE,u=0;const f=t.get("position").data,d=K(this.parameters,t)?f.length-2:f.length-5;for(let g=0;g<d;g+=3){const t=f[g],i=f[g+1],r=(g+3)%f.length,s=h-t,a=p-i,n=f[r]-t,o=f[r+1]-i,l=e((n*s+o*a)/(n*n+o*o),0,1),m=n*l-s,d=o*l-a,_=m*m+d*d;_<c&&(c=_,u=g/3)}c<m*m&&a(n.distance,n.normal,u)}intersect(i,r,s,f,d,g){const{options:_,camera:b,rayBegin:S,rayEnd:j}=s;if(!_.selectionMode||!i.visible||!b)return;if(!F(r))return void t.getLogger("esri.views.3d.webgl-engine.materials.RibbonLineMaterial").error("intersection assumes a translation-only matrix");const z=i.attributes,A=z.get("position").data;let C=this.parameters.width;if(this.parameters.vvSize){const t=z.get("sizeFeatureAttribute").data[0];Number.isNaN(t)||(C*=e(this.parameters.vvSize.offset[0]+t*this.parameters.vvSize.factor[0],this.parameters.vvSize.minSize[0],this.parameters.vvSize.maxSize[0]))}else z.has("size")&&(C*=z.get("size").data[0]);const x=it;a(x,s.point);const L=C*b.pixelRatio/2+4*b.pixelRatio;n(ut[0],x[0]-L,x[1]+L,0),n(ut[1],x[0]+L,x[1]+L,0),n(ut[2],x[0]+L,x[1]-L,0),n(ut[3],x[0]-L,x[1]-L,0);for(let t=0;t<4;t++)if(!b.unprojectFromRenderScreen(ut[t],ft[t]))return;y(b.eye,ft[0],ft[1],dt),y(b.eye,ft[1],ft[2],gt),y(b.eye,ft[2],ft[3],_t),y(b.eye,ft[3],ft[0],bt);let M=Number.MAX_VALUE,O=0;const V=K(this.parameters,z)?A.length-2:A.length-5;for(let t=0;t<V;t+=3){Z[0]=A[t]+r[12],Z[1]=A[t+1]+r[13],Z[2]=A[t+2]+r[14];const e=(t+3)%A.length;if($[0]=A[e]+r[12],$[1]=A[e+1]+r[13],$[2]=A[e+2]+r[14],E(dt,Z)<0&&E(dt,$)<0||E(gt,Z)<0&&E(gt,$)<0||E(_t,Z)<0&&E(_t,$)<0||E(bt,Z)<0&&E(bt,$)<0)continue;const i=b.projectToRenderScreen(Z,rt),s=b.projectToRenderScreen($,st);if(null==i||null==s)continue;if(i[2]<0&&s[2]>0){o(tt,Z,$);const t=b.frustum,e=-E(t[4],Z)/l(tt,T(t[4]));if(h(tt,tt,e),p(Z,Z,tt),!b.projectToRenderScreen(Z,i))continue}else if(i[2]>0&&s[2]<0){o(tt,$,Z);const t=b.frustum,e=-E(t[4],$)/l(tt,T(t[4]));if(h(tt,tt,e),p($,$,tt),!b.projectToRenderScreen($,s))continue}else if(i[2]<0&&s[2]<0)continue;i[2]=0,s[2]=0;const a=v(P(i,s,ot),x);a<M&&(M=a,m(at,Z),m(nt,$),O=t/3)}if(M<L*L){let t=Number.MAX_VALUE;if(w(P(at,nt,ot),P(S,j,lt),et)){o(et,et,S);const e=c(et);h(et,et,1/e),t=e/u(S,j)}g(t,et,O)}}get hasEmissions(){return this.parameters.emissiveStrength>0}createBufferWriter(){return new G(B(this.parameters),this.parameters)}createGLMaterial(t){return new q(t)}validateParameters(t){"miter"!==t.join&&(t.miterLimit=0),null!=t.markerParameters&&(t.markerScale=t.markerParameters.width/t.width)}update(t){return!!this.parameters.hasAnimation&&(this.setParameters({timeElapsed:r(t.time)},!1),0!==t.dt)}}class q extends V{constructor(){super(...arguments),this._stipplePattern=null}dispose(){super.dispose(),this._stippleTextures?.release(this._stipplePattern),this._stipplePattern=null}beginSlot(t){const{stipplePattern:e}=this._material.parameters;return this._stipplePattern!==e&&(this._material.setParameters({stippleTexture:this._stippleTextures.swap(e,this._stipplePattern)}),this._stipplePattern=e),this.getTechnique(W,t)}}class X extends k{constructor(){super(...arguments),this._width=0,this.color=_,this.join="miter",this.cap=0,this.miterLimit=5,this.writeDepth=!0,this.hasPolygonOffset=!1,this.stippleTexture=null,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.wireframe=!1,this.timeElapsed=s(0),this.animation=0,this.animationSpeed=1,this.trailLength=1,this.startTime=s(0),this.endTime=s(1/0),this.emissiveStrength=0}get width(){return this.isImagePattern()?this.stipplePattern.width:this._width}set width(t){this._width=t}get transparent(){return this.color[3]<1||this.hasAnimation||null!=this.stipplePattern&&(this.stippleOffColor?.[3]??0)<1}get hasAnimation(){return 0!==this.animation}isImagePattern(){return N(this.stipplePattern)&&null!=this.stippleTexture}}class G{constructor(t,e){this.layout=t,this._parameters=e;const i=e.stipplePattern?1:0;switch(this._parameters.join){case"miter":case"bevel":this.numJoinSubdivisions=i;break;case"round":this.numJoinSubdivisions=D+i}}_isClosed(t){return K(this._parameters,t)}allocate(t){return this.layout.createBuffer(t)}elementCount(t){const e=2,i=t.get("position").indices.length/2+1,r=this._isClosed(t);let s=r?2:2*e;return s+=((r?i:i-1)-(r?0:1))*(2*this.numJoinSubdivisions+4),s+=2,this._parameters.wireframe&&(s=2+4*(s-2)),s}write(t,e,i,r,s,a){const o=this.layout,l=i.get("position"),h=l.indices,p=l.data.length/3,c=i.get("distanceToStart")?.data;h&&h.length!==2*(p-1)&&console.warn("RibbonLineMaterial does not support indices");const d=o.fields.has("sizeFeatureAttribute");let _=1,b=null;if(d){const t=i.get("sizeFeatureAttribute");1===t.data.length?_=t.data[0]:b=t.data}else _=i.get("size")?.data[0]??1;let v=[1,1,1,1],P=0,w=null;const j=o.fields.has("colorFeatureAttribute");if(j){const t=i.get("colorFeatureAttribute");1===t.data.length?P=t.data[0]:w=t.data}else v=i.get("color")?.data??v;const y=i.get("timeStamps")?.data,E=y&&o.fields.has("timeStamps"),T=o.fields.has("opacityFeatureAttribute");let z=0,A=null;if(T){const t=i.get("opacityFeatureAttribute");1===t.data.length?z=t.data[0]:A=t.data}const C=new Float32Array(s.buffer),x=S(s.buffer),L=new Uint8Array(s.buffer),M=o.stride/4;let V=a*M;const R=V;let F=0;const N=c?(t,e,i)=>F=c[i]:(t,e,i)=>F+=u(t,e),k=C.BYTES_PER_ELEMENT/x.BYTES_PER_ELEMENT,D=4/k,B=O(),W=(t,e,i,s,a,n,o,l)=>{C[V++]=e[0],C[V++]=e[1],C[V++]=e[2],U(t,e,x,V*k),V+=D,U(i,e,x,V*k),V+=D,C[V++]=l;let h=V*k;if(x[h++]=a,x[h++]=n,V=Math.ceil(h/k),j)C[V]=w?.[o]??P;else{const t=Math.min(4*o,v.length-4),e=4*V;L[e]=255*v[t],L[e+1]=255*v[t+1],L[e+2]=255*v[t+2],L[e+3]=255*v[t+3]}if(V++,C[V++]=b?.[o]??_,T&&(C[V++]=A?.[o]??z),B){let t=4*V;r?(L[t++]=r[0],L[t++]=r[1],L[t++]=r[2],L[t++]=r[3]):(L[t++]=0,L[t++]=0,L[t++]=0,L[t++]=0),V=Math.ceil(.25*t)}E&&(h=V*k,x[h++]=s[0],x[h++]=s[1],x[h++]=s[2],x[h++]=s[3],V=Math.ceil(h/k))};V+=M,n(pt,l.data[0],l.data[1],l.data[2]),E&&g(ct,y[0],y[1],y[2],y[3]),t&&f(pt,pt,t);const J=this._isClosed(i);if(J){const e=l.data.length-3;n(ht,l.data[e],l.data[e+1],l.data[e+2]),t&&f(ht,ht,t)}else n(mt,l.data[3],l.data[4],l.data[5]),t&&f(mt,mt,t),W(pt,pt,mt,ct,1,-4,0,0),W(pt,pt,mt,ct,1,4,0,0),m(ht,pt),m(pt,mt),E&&g(ct,y[4],y[5],y[6],y[7]);const I=J?0:1,Y=J?p:p-1;for(let u=I;u<Y;u++){const e=(u+1)%p*3;n(mt,l.data[e],l.data[e+1],l.data[e+2]),t&&f(mt,mt,t),N(ht,pt,u),W(ht,pt,mt,ct,0,-1,u,F),W(ht,pt,mt,ct,0,1,u,F);const i=this.numJoinSubdivisions;for(let t=0;t<i;++t){const e=(t+1)/(i+1);W(ht,pt,mt,ct,e,-1,u,F),W(ht,pt,mt,ct,e,1,u,F)}if(W(ht,pt,mt,ct,1,-2,u,F),W(ht,pt,mt,ct,1,2,u,F),m(ht,pt),m(pt,mt),E){const t=(u+1)%p*4;g(ct,y[t],y[t+1],y[t+2],y[t+3])}}J?(n(mt,l.data[3],l.data[4],l.data[5]),t&&f(mt,mt,t),F=N(ht,pt,Y),W(ht,pt,mt,ct,0,-1,I,F),W(ht,pt,mt,ct,0,1,I,F)):(F=N(ht,pt,Y),W(ht,pt,pt,ct,0,-5,Y,F),W(ht,pt,pt,ct,0,5,Y,F)),H(C,R+M,C,R,M);return V=H(C,V-M,C,V,M),this._parameters.wireframe&&this._addWireframeVertices(s,R,V,M),null}_addWireframeVertices(t,e,i,r){const s=new Float32Array(t.buffer,i*Float32Array.BYTES_PER_ELEMENT),a=new Float32Array(t.buffer,e*Float32Array.BYTES_PER_ELEMENT,i-e);let n=0;const o=t=>n=H(a,t,s,n,r);for(let l=0;l<a.length-1;l+=2*r)o(l),o(l+2*r),o(l+1*r),o(l+2*r),o(l+1*r),o(l+3*r)}}function H(t,e,i,r,s){for(let a=0;a<s;a++)i[r++]=t[e++];return r}function K(t,e){if(!t.isClosed)return!1;return e.get("position").indices.length>2}function Q(t){return 1===t.anchor&&t.hideOnShortSegments&&"begin-end"===t.placement&&t.worldSpace}const Z=d(),$=d(),tt=d(),et=d(),it=d(),rt=i(),st=i(),at=d(),nt=d(),ot=j(),lt=j(),ht=d(),pt=d(),mt=d(),ct=b(),ut=[i(),i(),i(),i()],ft=[d(),d(),d(),d()],dt=z(),gt=z(),_t=z(),bt=z();export{X as Parameters,Y as RibbonLineMaterial};