UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.89 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{set as t,length as e,normalize as r,dot as i,scale as s,add as o}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{i as n,e as h}from"../../../../chunks/vec32.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as c}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{newFloatArray as u}from"../../../../geometry/support/FloatArray.js";import{getZeroIndexArray as b}from"../../../../geometry/support/Indices.js";import{Attribute as v,Vertices as m}from"./Attribute.js";import{compressNormal as p}from"./Normals.js";import{intersectTriangles as x}from"./RayIntersections.js";import{VertexAttribute as A}from"./VertexAttribute.js";class d{constructor(t){this.builder=t}onPathChanged(t){this.builder.onPathChanged()}}class f extends d{constructor(t){super(t),this.vertexAttributeColor=c(255,255,255,255),this.size=new Array,this.vertexAttributePosition=u(3*this.builder.numVerticesTotal),this.vertexAttributeNormal=new Int16Array(2*this.builder.numVerticesTotal)}bakeVertexColors(t){this.vertexAttributeColor[0]=255*t[0],this.vertexAttributeColor[1]=255*t[1],this.vertexAttributeColor[2]=255*t[2],this.vertexAttributeColor[3]=255*(t.length>3?t[3]:1)}bake(a){this.size=a;const{numVerticesTotal:l,pathVertexData:c,path:u,positions:b,profileRightAxes:v,profileUpAxes:m,profileVertexAndNormals:x}=this.builder;for(let A=0;A<l;++A){let l=c[A];const d=0===l||l===u.vertices.length-1;l*=3;const f=V;let g=0,D=0;const N=4*A,j=n(R,v[N],v[N+1],v[N+2]),E=n(w,m[N],m[N+1],m[N+2]),y=t(P,x[N]*a[0],x[N+1]*a[1]);if(d)h(f,E,j),g=v[N+3]*a[0],D=m[N+3];else{const a=I,h=C;t(a,v[N+3],m[N+3]);const l=e(a);r(a,a);const c=i(y,a);if(Math.abs(c)>l){t(h,-a[1],a[0]);const e=i(y,h);s(a,a,l*Math.sign(c)),s(h,h,e),o(y,a,h)}n(f,0,0,0)}const T=n(O,j[0]*y[0]+E[0]*y[1],j[1]*y[0]+E[1]*y[1],j[2]*y[0]+E[2]*y[1]),L=3*A;this.vertexAttributePosition[L]=b[l]+T[0]+f[0]*g,this.vertexAttributePosition[L+1]=b[l+1]+T[1]+f[1]*g,this.vertexAttributePosition[L+2]=b[l+2]+T[2]+f[2]*g;const M=t(P,x[N+2],x[N+3]);p(this.vertexAttributeNormal,A,j[0]*M[0]+E[0]*M[1]+f[0]*D,j[1]*M[0]+E[1]*M[1]+f[1]*D,j[2]*M[0]+E[2]*M[1]+f[2]*D)}}createGeometryData(){const t=this.builder.vertexIndices.length,{normalIndices:e,vertexIndices:r}=this.builder;return[[A.POSITION,new v(this.vertexAttributePosition,r,3,!0)],[A.NORMALCOMPRESSED,new v(this.vertexAttributeNormal,e,2,!0)],[A.COLOR,new v(this.vertexAttributeColor,b(t),4)]]}onPathChanged(t){super.onPathChanged(t),this.bake(this.size)}intersect(t,e,r,i){const s=this.builder.vertexIndices,o=new m(this.vertexAttributePosition,3),a=s.length/3;x(t,e,0,a,s,o,void 0,r,((t,e,r)=>i(t,r,e,!1)))}}class g extends d{constructor(t,e,r,i){super(t),this.sizeAttributeValue=e,this.colorAttributeValue=r,this.opacityAttributeValue=i,this.vvData=null,this.baked=new f(t),this.vvData=u(4*this.builder.path.vertices.length);for(let s=0;s<this.builder.path.vertices.length;++s){this.vvData[4*s]=e,this.vvData[4*s+1]=r,this.vvData[4*s+2]=i;const t=0===s||s===this.builder.path.vertices.length-1;this.vvData[4*s+3]=t?1:0}}createGeometryData(){const{positions:t,profileRightAxes:e,profileUpAxes:r,profileVertexAndNormals:i,pathVertexIndices:s,vertexIndices:o}=this.builder;return[[A.POSITION,new v(t,s,3,!0)],[A.PROFILERIGHT,new v(e,o,4,!0)],[A.PROFILEUP,new v(r,o,4,!0)],[A.PROFILEVERTEXANDNORMAL,new v(i,o,4,!0)],[A.FEATUREVALUE,new v(this.vvData,s,4,!0)]]}onPathChanged(t){super.onPathChanged(t);const e=t.getMutableAttribute(A.POSITION);e&&(e.data=this.builder.positions)}}const P=a(),I=a(),C=a(),O=l(),V=l(),R=l(),w=l();export{g as FastUpdatePathGeometry,d as PathGeometryData,f as StaticPathGeometry};