@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 12.8 kB
JavaScript
import{isSome as t}from"../../../../core/maybe.js";import{b as n,f as e,n as s,g as o,a as r,e as h,s as l,c as u,m as c}from"../../../../chunks/vec3.js";import{f as a,c as f,b as p}from"../../../../chunks/vec3f32.js";import{c as O}from"../../../../chunks/vec3f64.js";import{create as i,fromPositionAndNormal as I,intersectRay as w}from"../../../../geometry/support/plane.js";import{wrap as M}from"../../../../geometry/support/ray.js";import{Attribute as A}from"./Attribute.js";import{Vec3Compact as g}from"./BufferVectorMath.js";import{ContentObjectType as m}from"./ContentObjectType.js";import{newDoubleArray as N}from"./DoubleArray.js";import{newFloatArray as P,floatArrayFrom as y}from"./FloatArray.js";import{Geometry as S}from"./Geometry.js";import{generateDefaultIndexArray as T}from"./Indices.js";import{assert as L}from"./Util.js";import{VertexAttribute as R}from"./VertexAttribute.js";const b=g,j=[[-.5,-.5,.5],[.5,-.5,.5],[.5,.5,.5],[-.5,.5,.5],[-.5,-.5,-.5],[.5,-.5,-.5],[.5,.5,-.5],[-.5,.5,-.5]],d=[0,0,1,-1,0,0,1,0,0,0,-1,0,0,1,0,0,0,-1],U=[0,0,1,0,1,1,0,1],V=[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],v=new Array(36);for(let gt=0;gt<6;gt++)for(let t=0;t<6;t++)v[6*gt+t]=gt;const x=new Array(36);for(let gt=0;gt<6;gt++)x[6*gt+0]=0,x[6*gt+1]=1,x[6*gt+2]=2,x[6*gt+3]=2,x[6*gt+4]=3,x[6*gt+5]=0;function C(t,n){Array.isArray(n)||(n=[n,n,n]);const e=new Array(24);for(let s=0;s<8;s++)e[3*s]=j[s][0]*n[0],e[3*s+1]=j[s][1]*n[1],e[3*s+2]=j[s][2]*n[2];return new S(t,[[R.POSITION,new A(e,3,!0)],[R.NORMAL,new A(d,3)],[R.UV0,new A(U,2)]],[[R.POSITION,V],[R.NORMAL,v],[R.UV0,x]])}const F=[[-.5,0,-.5],[.5,0,-.5],[.5,0,.5],[-.5,0,.5],[0,-.5,0],[0,.5,0]],G=[0,1,-1,1,1,0,0,1,1,-1,1,0,0,-1,-1,1,-1,0,0,-1,1,-1,-1,0],k=[5,1,0,5,2,1,5,3,2,5,0,3,4,0,1,4,1,2,4,2,3,4,3,0],E=[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 e=new Array(18);for(let s=0;s<6;s++)e[3*s]=F[s][0]*n[0],e[3*s+1]=F[s][1]*n[1],e[3*s+2]=F[s][2]*n[2];return new S(t,[[R.POSITION,new A(e,3,!0)],[R.NORMAL,new A(G,3)]],[[R.POSITION,k],[R.NORMAL,E]])}const X=a(-.5,0,-.5),z=a(.5,0,-.5),B=a(0,0,.5),D=a(0,.5,0),Z=f(),H=f(),J=f(),K=f(),Q=f();n(Z,X,D),n(H,X,z),e(J,Z,H),s(J,J),n(Z,z,D),n(H,z,B),e(K,Z,H),s(K,K),n(Z,B,D),n(H,B,X),e(Q,Z,H),s(Q,Q);const W=[X,z,B,D],Y=[0,-1,0,J[0],J[1],J[2],K[0],K[1],K[2],Q[0],Q[1],Q[2]],$=[0,1,2,3,1,0,3,2,1,3,0,2],_=[0,0,0,1,1,1,2,2,2,3,3,3];function tt(t,n){Array.isArray(n)||(n=[n,n,n]);const e=new Array(12);for(let s=0;s<4;s++)e[3*s]=W[s][0]*n[0],e[3*s+1]=W[s][1]*n[1],e[3*s+2]=W[s][2]*n[2];return new S(t,[[R.POSITION,new A(e,3,!0)],[R.NORMAL,new A(Y,3)]],[[R.POSITION,$],[R.NORMAL,_]])}function nt(t,n,e,s,o={uv:!0}){const r=-Math.PI,h=2*Math.PI,l=-Math.PI/2,u=Math.PI,c=Math.max(3,Math.floor(e)),a=Math.max(2,Math.floor(s)),f=(c+1)*(a+1),p=P(3*f),O=P(3*f),i=P(2*f),I=[];let w=0;for(let A=0;A<=a;A++){const t=[],e=A/a,s=l+e*u,o=Math.cos(s);for(let l=0;l<=c;l++){const u=l/c,a=r+u*h,f=Math.cos(a)*o,I=Math.sin(s),M=-Math.sin(a)*o;p[3*w]=f*n,p[3*w+1]=I*n,p[3*w+2]=M*n,O[3*w]=f,O[3*w+1]=I,O[3*w+2]=M,i[2*w]=u,i[2*w+1]=e,t.push(w),++w}I.push(t)}const M=new Array;for(let A=0;A<a;A++)for(let t=0;t<c;t++){const n=I[A][t],e=I[A][t+1],s=I[A+1][t+1],o=I[A+1][t];0===A?(M.push(n),M.push(s),M.push(o)):A===a-1?(M.push(n),M.push(e),M.push(s)):(M.push(n),M.push(e),M.push(s),M.push(s),M.push(o),M.push(n))}const g=[[R.POSITION,M],[R.NORMAL,M]],m=[[R.POSITION,new A(p,3,!0)],[R.NORMAL,new A(O,3,!0)]];return o.uv&&(m.push([R.UV0,new A(i,2,!0)]),g.push([R.UV0,M])),o.offset&&(g[0][0]=R.OFFSET,m[0][0]=R.OFFSET,g.push([R.POSITION,new Array(M.length).fill(0)]),m.push([R.POSITION,new A(Float64Array.from(o.offset),3,!0)])),new S(t,m,g)}function et(t,n,e,s){const{vertexAttributes:o,indices:r}=st(n,e,s);return new S(t,o,r)}function st(t,n,e){const s=t;let o,r;if(e)o=[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=s*(1+Math.sqrt(5))/2;o=[-s,t,0,s,t,0,-s,-t,0,s,-t,0,0,-s,t,0,s,t,0,-s,-t,0,s,-t,t,0,-s,t,0,s,-t,0,-s,-t,0,s],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<o.length;a+=3)b.scale(o,a,t/b.length(o,a));let h={};function l(n,e){n>e&&([n,e]=[e,n]);const s=n.toString()+"."+e.toString();if(h[s])return h[s];let r=o.length;return o.length+=3,b.add(o,3*n,o,3*e,o,r),b.scale(o,r,t/b.length(o,r)),r/=3,h[s]=r,r}for(let a=0;a<n;a++){const t=r.length,n=new Array(4*t);for(let e=0;e<t;e+=3){const t=r[e],s=r[e+1],o=r[e+2],h=l(t,s),u=l(s,o),c=l(o,t),a=4*e;n[a]=t,n[a+1]=h,n[a+2]=c,n[a+3]=s,n[a+4]=u,n[a+5]=h,n[a+6]=o,n[a+7]=c,n[a+8]=u,n[a+9]=h,n[a+10]=u,n[a+11]=c}r=n,h={}}const u=y(o);for(let a=0;a<u.length;a+=3)b.normalize(u,a);const c=[[R.POSITION,r],[R.NORMAL,r]];return{vertexAttributes:[[R.POSITION,new A(y(o),3,!0)],[R.NORMAL,new A(u,3,!0)]],indices:c}}function ot(n,e,s,o,r,h,l,u,c=null){const a=s?[s[0],s[1],s[2]]:[0,0,0],f=e?[e[0],e[1],e[2]]:[0,0,1];l=l||[0,0];const p=o?[255*o[0],255*o[1],255*o[2],o.length>3?255*o[3]:255]:[255,255,255,255],O=t(r)&&2===r.length?r:[1,1],i=[[R.POSITION,new A(a,3,!0)],[R.NORMAL,new A(f,3,!0)],[R.UV0,new A(l,l.length)],[R.COLOR,new A(p,4,!0)],[R.SIZE,new A(O,2)]];if(null!=h){const t=[h[0],h[1],h[2],h[3]];i.push([R.AUXPOS1,new A(t,4)])}if(null!=u){const t=[u[0],u[1],u[2],u[3]];i.push([R.AUXPOS2,new A(t,4)])}return new S(n,i,null,null,m.Point,c)}const rt=[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]];function ht(t,n=rt){const e=new Array(12);for(let a=0;a<4;a++)for(let t=0;t<3;t++)e[3*a+t]=n[a][t];const s=[0,1,2,2,3,0],o=[0,0,1],r=[0,0,0,0,0,0],h=[0,0,1,0,1,1,0,1],l=[255,255,255,255],u=[[R.POSITION,s],[R.NORMAL,r],[R.UV0,s],[R.COLOR,r]],c=[[R.POSITION,new A(e,3,!0)],[R.NORMAL,new A(o,3,!0)],[R.UV0,new A(h,2,!0)],[R.COLOR,new A(l,4,!0)]];return new S(t,c,u)}function lt(t,n,e,s,o,r=!0,h=!0){let l=0;const u=e,c=n;let f=a(0,l,0),p=a(0,l+c,0),O=a(0,-1,0),i=a(0,1,0);o&&(l=c,p=a(0,0,0),f=a(0,l,0),O=a(0,1,0),i=a(0,-1,0));const I=[p,f],w=[O,i],M=s+2,g=Math.sqrt(c*c+u*u);if(o)for(let A=s-1;A>=0;A--){const t=A*(2*Math.PI/s),n=a(Math.cos(t)*u,l,Math.sin(t)*u);I.push(n);const e=a(c*Math.cos(t)/g,-u/g,c*Math.sin(t)/g);w.push(e)}else for(let A=0;A<s;A++){const t=A*(2*Math.PI/s),n=a(Math.cos(t)*u,l,Math.sin(t)*u);I.push(n);const e=a(c*Math.cos(t)/g,u/g,c*Math.sin(t)/g);w.push(e)}const m=new Array,N=new Array;if(r){for(let t=3;t<I.length;t++)m.push(1),m.push(t-1),m.push(t),N.push(0),N.push(0),N.push(0);m.push(I.length-1),m.push(2),m.push(1),N.push(0),N.push(0),N.push(0)}if(h){for(let t=3;t<I.length;t++)m.push(t),m.push(t-1),m.push(0),N.push(t),N.push(t-1),N.push(1);m.push(0),m.push(2),m.push(I.length-1),N.push(1),N.push(2),N.push(w.length-1)}const y=P(3*M);for(let a=0;a<M;a++)y[3*a]=I[a][0],y[3*a+1]=I[a][1],y[3*a+2]=I[a][2];const T=P(3*M);for(let a=0;a<M;a++)T[3*a]=w[a][0],T[3*a+1]=w[a][1],T[3*a+2]=w[a][2];const L=[[R.POSITION,m],[R.NORMAL,N]],b=[[R.POSITION,new A(y,3,!0)],[R.NORMAL,new A(T,3,!0)]];return new S(t,b,L)}function ut(t,n,u,c,O,i,I){const w=O?p(O):a(1,0,0),M=i?p(i):a(0,0,0);I=I??!0;const g=f();s(g,w);const m=f();o(m,g,Math.abs(n));const N=f();o(N,m,-.5),r(N,N,M);const y=a(0,1,0);Math.abs(1-h(g,y))<.2&&l(y,0,0,1);const T=f();e(T,g,y),s(T,T),e(y,T,g);const L=2*c+(I?2:0),b=c+(I?2:0),j=P(3*L),d=P(3*b),U=P(2*L),V=new Array(3*c*(I?4:2)),v=new Array(3*c*(I?4:2));I&&(j[3*(L-2)+0]=N[0],j[3*(L-2)+1]=N[1],j[3*(L-2)+2]=N[2],U[2*(L-2)]=0,U[2*(L-2)+1]=0,j[3*(L-1)+0]=j[3*(L-2)+0]+m[0],j[3*(L-1)+1]=j[3*(L-2)+1]+m[1],j[3*(L-1)+2]=j[3*(L-2)+2]+m[2],U[2*(L-1)]=1,U[2*(L-1)+1]=1,d[3*(b-2)+0]=-g[0],d[3*(b-2)+1]=-g[1],d[3*(b-2)+2]=-g[2],d[3*(b-1)+0]=g[0],d[3*(b-1)+1]=g[1],d[3*(b-1)+2]=g[2]);const x=(t,n,e)=>{V[t]=n,v[t]=e};let C=0;const F=f(),G=f();for(let e=0;e<c;e++){const t=e*(2*Math.PI/c);o(F,y,Math.sin(t)),o(G,T,Math.cos(t)),r(F,F,G),d[3*e+0]=F[0],d[3*e+1]=F[1],d[3*e+2]=F[2],o(F,F,u),r(F,F,N),j[3*e+0]=F[0],j[3*e+1]=F[1],j[3*e+2]=F[2],U[2*e+0]=e/c,U[2*e+1]=0,j[3*(e+c)+0]=j[3*e+0]+m[0],j[3*(e+c)+1]=j[3*e+1]+m[1],j[3*(e+c)+2]=j[3*e+2]+m[2],U[2*(e+c)+0]=e/c,U[2*e+1]=1;const n=(e+1)%c;x(C++,e,e),x(C++,e+c,e),x(C++,n,n),x(C++,n,n),x(C++,e+c,e),x(C++,n+c,n)}if(I){for(let t=0;t<c;t++){const n=(t+1)%c;x(C++,L-2,b-2),x(C++,t,b-2),x(C++,n,b-2)}for(let t=0;t<c;t++){const n=(t+1)%c;x(C++,t+c,b-1),x(C++,L-1,b-1),x(C++,n+c,b-1)}}const k=[[R.POSITION,V],[R.NORMAL,v],[R.UV0,V]],E=[[R.POSITION,new A(j,3,!0)],[R.NORMAL,new A(d,3,!0)],[R.UV0,new A(U,2,!0)]];return new S(t,E,k)}function ct(t,n,e,s,o,r){s=s||10,o=null==o||o,L(n.length>1);const h=[[0,0,0]],l=[],u=[];for(let c=0;c<s;c++){l.push([0,-c-1,-(c+1)%s-1]);const t=c/s*2*Math.PI;u.push([Math.cos(t)*e,Math.sin(t)*e])}return at(t,u,n,h,l,o,r)}function at(t,h,c,p,g,m,N=a(0,0,0)){const y=h.length,T=P(c.length*y*3+(6*p.length||0)),L=P(c.length*y*3+(p?6:0)),b=new Array,j=new Array;let d=0,U=0;const V=f(),v=f(),x=f(),C=f(),F=f(),G=f(),k=f(),E=O(),q=f(),X=f(),z=f(),B=f(),D=f(),Z=i();l(q,0,1,0),n(v,c[1],c[0]),s(v,v),m?(r(E,c[0],N),s(x,E)):l(x,0,0,1),wt(v,x,q,q,F,x,Mt),u(C,x),u(B,F);for(let n=0;n<p.length;n++)o(G,F,p[n][0]),o(E,x,p[n][2]),r(G,G,E),r(G,G,c[0]),T[d++]=G[0],T[d++]=G[1],T[d++]=G[2];L[U++]=-v[0],L[U++]=-v[1],L[U++]=-v[2];for(let n=0;n<g.length;n++)b.push(g[n][0]>0?g[n][0]:-g[n][0]-1+p.length),b.push(g[n][1]>0?g[n][1]:-g[n][1]-1+p.length),b.push(g[n][2]>0?g[n][2]:-g[n][2]-1+p.length),j.push(0),j.push(0),j.push(0);let H=p.length;const J=p.length-1;for(let l=0;l<c.length;l++){let t=!1;if(l>0){u(V,v),l<c.length-1?(n(v,c[l+1],c[l]),s(v,v)):t=!0,r(X,V,v),s(X,X),r(z,c[l-1],C),I(c[l],X,Z);w(Z,M(z,V),E)?(n(E,E,c[l]),s(x,E),e(F,X,x),s(F,F)):wt(X,C,B,q,F,x,Mt),u(C,x),u(B,F)}m&&(r(E,c[l],N),s(D,E));for(let n=0;n<y;n++)if(o(G,F,h[n][0]),o(E,x,h[n][1]),r(G,G,E),s(k,G),L[U++]=k[0],L[U++]=k[1],L[U++]=k[2],r(G,G,c[l]),T[d++]=G[0],T[d++]=G[1],T[d++]=G[2],!t){const t=(n+1)%y;b.push(H+n),b.push(H+y+n),b.push(H+t),b.push(H+t),b.push(H+y+n),b.push(H+y+t);for(let n=0;n<6;n++){const t=b.length-6;j.push(b[t+n]-J)}}H+=y}const K=c[c.length-1];for(let n=0;n<p.length;n++)o(G,F,p[n][0]),o(E,x,p[n][1]),r(G,G,E),r(G,G,K),T[d++]=G[0],T[d++]=G[1],T[d++]=G[2];const Q=U/3;L[U++]=v[0],L[U++]=v[1],L[U++]=v[2];const W=H-y;for(let n=0;n<g.length;n++)b.push(g[n][0]>=0?H+g[n][0]:-g[n][0]-1+W),b.push(g[n][2]>=0?H+g[n][2]:-g[n][2]-1+W),b.push(g[n][1]>=0?H+g[n][1]:-g[n][1]-1+W),j.push(Q),j.push(Q),j.push(Q);const Y=[[R.POSITION,b],[R.NORMAL,j]],$=[[R.POSITION,new A(T,3,!0)],[R.NORMAL,new A(L,3,!0)]];return new S(t,$,Y)}function ft(t,n,e,s){L(n.length>1,"createPolylineGeometry(): polyline needs at least 2 points"),L(3===n[0].length,"createPolylineGeometry(): malformed vertex"),L(null==e||e.length===n.length,"createPolylineGeometry: need same number of points and normals"),L(null==e||3===e[0].length,"createPolylineGeometry(): malformed normal");const o=N(3*n.length),r=new Array(2*(n.length-1));let h=0,l=0;for(let a=0;a<n.length;a++){for(let t=0;t<3;t++)o[h++]=n[a][t];a>0&&(r[l++]=a-1,r[l++]=a)}const u=[],c=[];if(u.push([R.POSITION,r]),c.push([R.POSITION,new A(o,3,!0)]),e){const t=P(3*e.length);let s=0;for(let o=0;o<n.length;o++)for(let n=0;n<3;n++)t[s++]=e[o][n];u.push([R.NORMAL,r]),c.push([R.NORMAL,new A(t,3,!0)])}return s&&(c.push([R.COLOR,new A(s,4)]),u.push([R.COLOR,T(s.length/4)])),new S(t,c,u,null,m.Line)}function pt(t,n,e,s,o,r=0){const h=new Array(18),l=[[-e,r,o/2],[s,r,o/2],[0,n+r,o/2],[-e,r,-o/2],[s,r,-o/2],[0,n+r,-o/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 c=0;c<6;c++)h[3*c]=l[c][0],h[3*c+1]=l[c][1],h[3*c+2]=l[c][2];return new S(t,[[R.POSITION,new A(h,3,!0)]],[[R.POSITION,u]])}function Ot(t,n){const e=t.getMutableAttribute(R.POSITION).data;for(let s=0;s<e.length;s+=3){const t=e[s],o=e[s+1],r=e[s+2];l(At,t,o,r),c(At,At,n),e[s]=At[0],e[s+1]=At[1],e[s+2]=At[2]}}function it(t,n=t){const e=t.vertexAttributes,s=e.get(R.POSITION).data,o=e.get(R.NORMAL).data;if(o){const t=n.getMutableAttribute(R.NORMAL).data;for(let n=0;n<o.length;n+=3){const e=o[n+1];t[n+1]=-o[n+2],t[n+2]=e}}if(s){const t=n.getMutableAttribute(R.POSITION).data;for(let n=0;n<s.length;n+=3){const e=s[n+1];t[n+1]=-s[n+2],t[n+2]=e}}}function It(t,n,o,r,l){return!(Math.abs(h(n,t))>l)&&(e(o,t,n),s(o,o),e(r,o,t),s(r,r),!0)}function wt(t,n,e,s,o,r,h){return It(t,n,o,r,h)||It(t,e,o,r,h)||It(t,s,o,r,h)}const Mt=.99619469809,At=f();export{it as cgToGIS,C as createBoxGeometry,lt as createConeGeometry,ut as createCylinderGeometry,q as createDiamondGeometry,pt as createExtrudedTriangle,at as createPathExtrusionGeometry,ot as createPointGeometry,st as createPolySphereData,et as createPolySphereGeometry,ft as createPolylineGeometry,nt as createSphereGeometry,ht as createSquareGeometry,tt as createTetrahedronGeometry,ct as createTubeGeometry,wt as makeOrthoBasisDirUpFallback,Ot as transformInPlace};