UNPKG

@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
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{set as t,transformMat4 as n,normalize as o,scale as e,add as s,dot as r,cross as l,subtract as h,copy as u}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{clone as a,fromValues as i,create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f32.js";import{clone as p,create as f,fromValues as w}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{newDoubleArray as g}from"../../../../geometry/support/DoubleArray.js";import{newFloatArray as m,floatArrayFrom as M}from"../../../../geometry/support/FloatArray.js";import{getContinuousIndexArray as A,getZeroIndexArray as y}from"../../../../geometry/support/Indices.js";import{create as b,fromPositionAndNormal as j,intersectRay as d}from"../../../../geometry/support/plane.js";import{wrap as v}from"../../../../geometry/support/ray.js";import{timeStampsToAttribute as I,numTimeStampValuesPerVertex as P}from"../../support/engineContent/line.js";import{Attribute as x}from"./Attribute.js";import{scale as D,length as z,normalize as S,add as q}from"./bufferVectorMath.js";import{Geometry as C}from"./Geometry.js";import{assert as F}from"./Util.js";import{getHUDMaterialBaseInstance as O}from"../materials/HUDMaterialBaseInstance.js";const U=[[-.5,-.5,.5],[.5,-.5,.5],[.5,.5,.5],[-.5,.5,.5],[-.5,-.5,-.5],[.5,-.5,-.5],[.5,.5,-.5],[-.5,.5,-.5]],V=[0,0,1,-1,0,0,1,0,0,0,-1,0,0,1,0,0,0,-1],B=[0,0,1,0,1,1,0,1],G=[0,1,2,2,3,0,4,0,3,3,7,4,1,5,6,6,2,1,1,0,4,4,5,1,3,2,6,6,7,3,5,4,7,7,6,5],H=new Array(36);for(let Pt=0;Pt<6;Pt++)for(let t=0;t<6;t++)H[6*Pt+t]=Pt;const k=new Array(36);for(let Pt=0;Pt<6;Pt++)k[6*Pt]=0,k[6*Pt+1]=1,k[6*Pt+2]=2,k[6*Pt+3]=2,k[6*Pt+4]=3,k[6*Pt+5]=0;function E(t,n){Array.isArray(n)||(n=[n,n,n]);const o=new Array(24);for(let e=0;e<8;e++)o[3*e]=U[e][0]*n[0],o[3*e+1]=U[e][1]*n[1],o[3*e+2]=U[e][2]*n[2];return new C(t,[["position",new x(o,G,3,!0)],["normal",new x(V,H,3)],["uv0",new x(B,k,2)]])}const J=[[-.5,0,-.5],[.5,0,-.5],[.5,0,.5],[-.5,0,.5],[0,-.5,0],[0,.5,0]],K=[0,1,-1,1,1,0,0,1,1,-1,1,0,0,-1,-1,1,-1,0,0,-1,1,-1,-1,0],L=[5,1,0,5,2,1,5,3,2,5,0,3,4,0,1,4,1,2,4,2,3,4,3,0],N=[0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7];function Q(t,n){Array.isArray(n)||(n=[n,n,n]);const o=new Array(18);for(let e=0;e<6;e++)o[3*e]=J[e][0]*n[0],o[3*e+1]=J[e][1]*n[1],o[3*e+2]=J[e][2]*n[2];return new C(t,[["position",new x(o,L,3,!0)],["normal",new x(K,N,3)]])}const R=i(-.5,0,-.5),T=i(.5,0,-.5),W=i(0,0,.5),X=i(0,.5,0),Y=c(),Z=c(),$=c(),_=c(),tt=c();h(Y,R,X),h(Z,R,T),l($,Y,Z),o($,$),h(Y,T,X),h(Z,T,W),l(_,Y,Z),o(_,_),h(Y,W,X),h(Z,W,R),l(tt,Y,Z),o(tt,tt);const nt=[R,T,W,X],ot=[0,-1,0,$[0],$[1],$[2],_[0],_[1],_[2],tt[0],tt[1],tt[2]],et=[0,1,2,3,1,0,3,2,1,3,0,2],st=[0,0,0,1,1,1,2,2,2,3,3,3];function rt(t,n){Array.isArray(n)||(n=[n,n,n]);const o=new Array(12);for(let e=0;e<4;e++)o[3*e]=nt[e][0]*n[0],o[3*e+1]=nt[e][1]*n[1],o[3*e+2]=nt[e][2]*n[2];return new C(t,[["position",new x(o,et,3,!0)],["normal",new x(ot,st,3)]])}function lt(t,n,o,e,s={uv:!0}){const r=-Math.PI,l=2*Math.PI,h=-Math.PI/2,u=Math.PI,a=Math.max(3,Math.floor(o)),i=Math.max(2,Math.floor(e)),c=(a+1)*(i+1),p=m(3*c),f=m(3*c),w=m(2*c),g=[];let M=0;for(let m=0;m<=i;m++){const t=[],o=m/i,e=h+o*u,s=Math.cos(e);for(let h=0;h<=a;h++){const u=h/a,i=r+u*l,c=Math.cos(i)*s,g=Math.sin(e),m=-Math.sin(i)*s;p[3*M]=c*n,p[3*M+1]=g*n,p[3*M+2]=m*n,f[3*M]=c,f[3*M+1]=g,f[3*M+2]=m,w[2*M]=u,w[2*M+1]=o,t.push(M),++M}g.push(t)}const A=new Array;for(let m=0;m<i;m++)for(let t=0;t<a;t++){const n=g[m][t],o=g[m][t+1],e=g[m+1][t+1],s=g[m+1][t];0===m?(A.push(n),A.push(e),A.push(s)):m===i-1?(A.push(n),A.push(o),A.push(e)):(A.push(n),A.push(o),A.push(e),A.push(e),A.push(s),A.push(n))}const b=[["position",new x(p,A,3,!0)],["normal",new x(f,A,3,!0)]];return s.uv&&b.push(["uv0",new x(w,A,2,!0)]),s.offset&&(b[0][0]="offset",b.push(["position",new x(Float64Array.from(s.offset),y(A.length),3,!0)])),new C(t,b)}function ht(t,n,o,e){const s=ut(n,o,e);return new C(t,s)}function ut(t,n,o){const e=t;let s,r;if(o)s=[0,-1,0,1,0,0,0,0,1,-1,0,0,0,0,-1,0,1,0],r=[0,1,2,0,2,3,0,3,4,0,4,1,1,5,2,2,5,3,3,5,4,4,5,1];else{const t=e*(1+Math.sqrt(5))/2;s=[-e,t,0,e,t,0,-e,-t,0,e,-t,0,0,-e,t,0,e,t,0,-e,-t,0,e,-t,t,0,-e,t,0,e,-t,0,-e,-t,0,e],r=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1]}for(let a=0;a<s.length;a+=3)D(s,a,t/z(s,a));let l={};function h(n,o){n>o&&([n,o]=[o,n]);const e=n.toString()+"."+o.toString();if(l[e])return l[e];let r=s.length;return s.length+=3,q(s,3*n,s,3*o,s,r),D(s,r,t/z(s,r)),r/=3,l[e]=r,r}for(let a=0;a<n;a++){const t=r.length,n=new Array(4*t);for(let o=0;o<t;o+=3){const t=r[o],e=r[o+1],s=r[o+2],l=h(t,e),u=h(e,s),a=h(s,t),i=4*o;n[i]=t,n[i+1]=l,n[i+2]=a,n[i+3]=e,n[i+4]=u,n[i+5]=l,n[i+6]=s,n[i+7]=a,n[i+8]=u,n[i+9]=l,n[i+10]=u,n[i+11]=a}r=n,l={}}const u=M(s);for(let a=0;a<u.length;a+=3)S(u,a);return[["position",new x(M(s),r,3,!0)],["normal",new x(u,r,3,!0)]]}function at(t,{normal:n,position:o,color:e,rotation:s,size:r,centerOffsetAndDistance:l,uvi:h,featureAttribute:u,olidColor:a=null}={}){const i=o?p(o):f(),c=n?p(n):w(0,0,1),g=e?[e[0],e[1],e[2],e.length>3?e[3]:255]:[255,255,255,255],m=null!=r&&2===r.length?r:[1,1],M=null!=s?[s]:[0],A=y(1),b=[["position",new x(i,A,3,!0)],["normal",new x(c,A,3,!0)],["color",new x(g,A,4,!0)],["size",new x(m,A,2)],["rotation",new x(M,A,1,!0)]];if(h&&b.push(["uvi",new x(h,A,h.length)]),null!=l){const t=[l[0],l[1],l[2],l[3]];b.push(["centerOffsetAndDistance",new x(t,A,4)])}if(u){const t=[u[0],u[1],u[2],u[3]];b.push(["featureAttribute",new x(t,A,4)])}return new C(t,b,null,1,a,void 0,O())}const it=[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]];function ct(t,n=it){const o=new Array(12);for(let a=0;a<4;a++)for(let t=0;t<3;t++)o[3*a+t]=n[a][t];const e=[0,1,2,2,3,0],s=[0,0,1],r=[0,0,0,0,0,0],l=[0,0,1,0,1,1,0,1],h=[255,255,255,255],u=[["position",new x(o,e,3,!0)],["normal",new x(s,r,3,!0)],["uv0",new x(l,e,2,!0)],["color",new x(h,r,4,!0)]];return new C(t,u)}function pt(t,n,o,e,s=!0,r=!0){let l=0;const h=n,u=t;let a=i(0,l,0),c=i(0,l+u,0),p=i(0,-1,0),f=i(0,1,0);e&&(l=u,c=i(0,0,0),a=i(0,l,0),p=i(0,1,0),f=i(0,-1,0));const w=[c,a],g=[p,f],M=o+2,A=Math.sqrt(u*u+h*h);if(e)for(let m=o-1;m>=0;m--){const t=m*(2*Math.PI/o),n=i(Math.cos(t)*h,l,Math.sin(t)*h);w.push(n);const e=i(u*Math.cos(t)/A,-h/A,u*Math.sin(t)/A);g.push(e)}else for(let m=0;m<o;m++){const t=m*(2*Math.PI/o),n=i(Math.cos(t)*h,l,Math.sin(t)*h);w.push(n);const e=i(u*Math.cos(t)/A,h/A,u*Math.sin(t)/A);g.push(e)}const y=new Array,b=new Array;if(s){for(let t=3;t<w.length;t++)y.push(1),y.push(t-1),y.push(t),b.push(0),b.push(0),b.push(0);y.push(w.length-1),y.push(2),y.push(1),b.push(0),b.push(0),b.push(0)}if(r){for(let t=3;t<w.length;t++)y.push(t),y.push(t-1),y.push(0),b.push(t),b.push(t-1),b.push(1);y.push(0),y.push(2),y.push(w.length-1),b.push(1),b.push(2),b.push(g.length-1)}const j=m(3*M);for(let i=0;i<M;i++)j[3*i]=w[i][0],j[3*i+1]=w[i][1],j[3*i+2]=w[i][2];const d=m(3*M);for(let i=0;i<M;i++)d[3*i]=g[i][0],d[3*i+1]=g[i][1],d[3*i+2]=g[i][2];return[["position",new x(j,y,3,!0)],["normal",new x(d,b,3,!0)]]}function ft(t,n,o,e,s,r=!0,l=!0){return new C(t,pt(n,o,e,s,r,l))}function wt(n,h,u,p,f,w,g){const M=f?a(f):i(1,0,0),A=w?a(w):i(0,0,0);g??=!0;const y=c();o(y,M);const b=c();e(b,y,Math.abs(h));const j=c();e(j,b,-.5),s(j,j,A);const d=i(0,1,0);Math.abs(1-r(y,d))<.2&&t(d,0,0,1);const v=c();l(v,y,d),o(v,v),l(d,v,y);const I=2*p+(g?2:0),P=p+(g?2:0),D=m(3*I),z=m(3*P),S=m(2*I),q=new Array(3*p*(g?4:2)),F=new Array(3*p*(g?4:2));g&&(D[3*(I-2)]=j[0],D[3*(I-2)+1]=j[1],D[3*(I-2)+2]=j[2],S[2*(I-2)]=0,S[2*(I-2)+1]=0,D[3*(I-1)]=D[3*(I-2)]+b[0],D[3*(I-1)+1]=D[3*(I-2)+1]+b[1],D[3*(I-1)+2]=D[3*(I-2)+2]+b[2],S[2*(I-1)]=1,S[2*(I-1)+1]=1,z[3*(P-2)]=-y[0],z[3*(P-2)+1]=-y[1],z[3*(P-2)+2]=-y[2],z[3*(P-1)]=y[0],z[3*(P-1)+1]=y[1],z[3*(P-1)+2]=y[2]);const O=(t,n,o)=>{q[t]=n,F[t]=o};let U=0;const V=c(),B=c();for(let t=0;t<p;t++){const n=t*(2*Math.PI/p);e(V,d,Math.sin(n)),e(B,v,Math.cos(n)),s(V,V,B),z[3*t]=V[0],z[3*t+1]=V[1],z[3*t+2]=V[2],e(V,V,u),s(V,V,j),D[3*t]=V[0],D[3*t+1]=V[1],D[3*t+2]=V[2],S[2*t]=t/p,S[2*t+1]=0,D[3*(t+p)]=D[3*t]+b[0],D[3*(t+p)+1]=D[3*t+1]+b[1],D[3*(t+p)+2]=D[3*t+2]+b[2],S[2*(t+p)]=t/p,S[2*t+1]=1;const o=(t+1)%p;O(U++,t,t),O(U++,t+p,t),O(U++,o,o),O(U++,o,o),O(U++,t+p,t),O(U++,o+p,o)}if(g){for(let t=0;t<p;t++){const n=(t+1)%p;O(U++,I-2,P-2),O(U++,t,P-2),O(U++,n,P-2)}for(let t=0;t<p;t++){const n=(t+1)%p;O(U++,t+p,P-1),O(U++,I-1,P-1),O(U++,n+p,P-1)}}const G=[["position",new x(D,q,3,!0)],["normal",new x(z,F,3,!0)],["uv0",new x(S,q,2,!0)]];return new C(n,G)}function gt(t,n,o,e,s,r){e=e||10,s=null==s||s,F(n.length>1);const l=[[0,0,0]],h=[],u=[];for(let a=0;a<e;a++){h.push([0,-a-1,-(a+1)%e-1]);const t=a/e*2*Math.PI;u.push([Math.cos(t)*o,Math.sin(t)*o])}return mt(t,u,n,l,h,s,r)}function mt(n,r,a,c,p,w,g=i(0,0,0)){const M=r.length,A=m(a.length*M*3+(6*c.length||0)),y=m(a.length*M*3+(c?6:0)),I=new Array,P=new Array;let D=0,z=0;const S=f(),q=f(),F=f(),O=f(),U=f(),V=f(),B=f(),G=f(),H=f(),k=f(),E=f(),J=f(),K=f(),L=b();t(H,0,1,0),h(q,a[1],a[0]),o(q,q),w?(s(G,a[0],g),o(F,G)):t(F,0,0,1),dt(q,F,H,H,U,F,vt),u(O,F),u(J,U);for(let t=0;t<c.length;t++)e(V,U,c[t][0]),e(G,F,c[t][2]),s(V,V,G),s(V,V,a[0]),A[D++]=V[0],A[D++]=V[1],A[D++]=V[2];y[z++]=-q[0],y[z++]=-q[1],y[z++]=-q[2];for(let t=0;t<p.length;t++)I.push(p[t][0]>0?p[t][0]:-p[t][0]-1+c.length),I.push(p[t][1]>0?p[t][1]:-p[t][1]-1+c.length),I.push(p[t][2]>0?p[t][2]:-p[t][2]-1+c.length),P.push(0),P.push(0),P.push(0);let N=c.length;const Q=c.length-1;for(let t=0;t<a.length;t++){let n=!1;if(t>0){u(S,q),t<a.length-1?(h(q,a[t+1],a[t]),o(q,q)):n=!0,s(k,S,q),o(k,k),s(E,a[t-1],O),j(a[t],k,L);d(L,v(E,S),G)?(h(G,G,a[t]),o(F,G),l(U,k,F),o(U,U)):dt(k,O,J,H,U,F,vt),u(O,F),u(J,U)}w&&(s(G,a[t],g),o(K,G));for(let l=0;l<M;l++)if(e(V,U,r[l][0]),e(G,F,r[l][1]),s(V,V,G),o(B,V),y[z++]=B[0],y[z++]=B[1],y[z++]=B[2],s(V,V,a[t]),A[D++]=V[0],A[D++]=V[1],A[D++]=V[2],!n){const t=(l+1)%M;I.push(N+l),I.push(N+M+l),I.push(N+t),I.push(N+t),I.push(N+M+l),I.push(N+M+t);for(let n=0;n<6;n++){const t=I.length-6;P.push(I[t+n]-Q)}}N+=M}const R=a[a.length-1];for(let t=0;t<c.length;t++)e(V,U,c[t][0]),e(G,F,c[t][1]),s(V,V,G),s(V,V,R),A[D++]=V[0],A[D++]=V[1],A[D++]=V[2];const T=z/3;y[z++]=q[0],y[z++]=q[1],y[z++]=q[2];const W=N-M;for(let t=0;t<p.length;t++)I.push(p[t][0]>=0?N+p[t][0]:-p[t][0]-1+W),I.push(p[t][2]>=0?N+p[t][2]:-p[t][2]-1+W),I.push(p[t][1]>=0?N+p[t][1]:-p[t][1]-1+W),P.push(T),P.push(T),P.push(T);const X=[["position",new x(A,I,3,!0)],["normal",new x(y,P,3,!0)]];return new C(n,X)}function Mt(t,n,o,e,s){const r=g(3*n.length),l=new Array(2*(n.length-1));let h=0,u=0;for(let i=0;i<n.length;i++){for(let t=0;t<3;t++)r[h++]=n[i][t];i>0&&(l[u++]=i-1,l[u++]=i)}const a=[["position",new x(r,l,3,!0)]];if(o?.length===n.length&&3===o[0].length){const t=m(3*o.length);let e=0;for(let s=0;s<n.length;s++)for(let n=0;n<3;n++)t[e++]=o[s][n];a.push(["normal",new x(t,l,3,!0)])}if(e&&a.push(["color",new x(e,A(e.length/4),4)]),s?.length===n.length){const t=I(s,1);a.push(["timeStamps",new x(t,l,P,!0)])}return new C(t,a,null,2)}function At(t,n,o,e,s,r=0){const l=new Array(18),h=[[-o,r,s/2],[e,r,s/2],[0,n+r,s/2],[-o,r,-s/2],[e,r,-s/2],[0,n+r,-s/2]],u=[0,1,2,3,0,2,2,5,3,1,4,5,5,2,1,1,0,3,3,4,1,4,3,5];for(let a=0;a<6;a++)l[3*a]=h[a][0],l[3*a+1]=h[a][1],l[3*a+2]=h[a][2];return new C(t,[["position",new x(l,u,3,!0)]])}function yt(o,e){const s=o.getMutableAttribute("position").data;for(let r=0;r<s.length;r+=3){const o=s[r],l=s[r+1],h=s[r+2];t(It,o,l,h),n(It,It,e),s[r]=It[0],s[r+1]=It[1],s[r+2]=It[2]}}function bt(t,n=t){const o=t.attributes,e=o.get("position").data,s=o.get("normal").data;if(s){const t=n.getMutableAttribute("normal").data;for(let n=0;n<s.length;n+=3){const o=s[n+1];t[n+1]=-s[n+2],t[n+2]=o}}if(e){const t=n.getMutableAttribute("position").data;for(let n=0;n<e.length;n+=3){const o=e[n+1];t[n+1]=-e[n+2],t[n+2]=o}}}function jt(t,n,e,s,h){return!(Math.abs(r(n,t))>h)&&(l(e,t,n),o(e,e),l(s,e,t),o(s,s),!0)}function dt(t,n,o,e,s,r,l){return jt(t,n,s,r,l)||jt(t,o,s,r,l)||jt(t,e,s,r,l)}const vt=.99619469809,It=f();export{bt as cgToGIS,E as createBoxGeometry,ft as createConeGeometry,pt as createConeGeometryData,wt as createCylinderGeometry,Q as createDiamondGeometry,At as createExtrudedTriangle,mt as createPathExtrusionGeometry,at as createPointGeometry,ut as createPolySphereData,ht as createPolySphereGeometry,Mt as createPolylineGeometry,lt as createSphereGeometry,ct as createSquareGeometry,rt as createTetrahedronGeometry,gt as createTubeGeometry,dt as makeOrthoBasisDirUpFallback,yt as transformInPlace};