@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.63 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{acosClamped as e,deg2rad as t}from"../../../../../core/mathUtils.js";import o from"../../../../../core/PooledArray.js";import{j as n,i as s,c as a,e as r,d as c,h as l,n as i,E as h}from"../../../../../chunks/vec32.js";import{create as g}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{Edge as u}from"./Edge.js";const d=-1;function p(e,t,o){const c=e.vertices.position,l=e.vertices.componentIndex,i=y.position0,h=y.position1,g=y.faceNormal0,u=y.faceNormal1,{edges:p,normals:v}=w(e),V=p.length/4,j=t.allocate(V);let I=0;const N=V,E=o?.allocate(N);let b=0,D=0,k=0;x.length=0;for(let s=0;s<V;++s){const e=4*s;c.getVec(p.data[e],i),c.getVec(p.data[e+1],h);const t=x.pushNew();t.index=4*s,t.length=n(i,h)}x.sort(((e,t)=>t.length-e.length));const P=new Array,U=new Array;x.forAll((({length:e,index:n})=>{const w=p.data[n],x=p.data[n+1],V=p.data[n+2],N=p.data[n+3],q=N===d;if(c.getVec(w,i),c.getVec(x,h),q){const e=3*V;s(g,v.data[e],v.data[e+1],v.data[e+2]),a(u,g),y.componentIndex=l.get(w),y.cosAngle=r(g,u)}else{let e=3*V;if(s(g,v.data[e],v.data[e+1],v.data[e+2]),e=3*N,s(u,v.data[e],v.data[e+1],v.data[e+2]),y.componentIndex=l.get(w),y.cosAngle=r(g,u),m(y,M))return;y.cosAngle<-.9999&&a(u,g)}D+=e,k++,q||f(y,L)?(t.write(j,I++,y),P.push(e)):A(y,F)&&(E&&o&&o.write(E,b++,y),U.push(e))}));const q=new Float32Array(P.reverse()),z=new Float32Array(U.reverse()),B=E&&o?{instancesData:E.slice(0,b),lodInfo:{lengths:z}}:void 0;return{regular:{instancesData:j.slice(0,I),lodInfo:{lengths:q}},silhouette:B,averageEdgeLength:D/k}}function f(e,t){return e.cosAngle<t}function m(e,t){return e.cosAngle>t}function A(t,o){const n=e(t.cosAngle);h(N,t.position1,t.position0);return n*(r(l(I,t.faceNormal0,t.faceNormal1),N)>0?-1:1)>o}function w(e){const t=e.faces.length/3,o=e.faces,n=e.neighbors,s=e.vertices.position;V.length=j.length=0;for(let a=0;a<t;a++){const e=3*a,t=n[e],r=n[e+1],h=n[e+2],g=o[e],u=o[e+1],p=o[e+2];s.getVec(g,E),s.getVec(u,b),s.getVec(p,D),c(b,b,E),c(D,D,E),l(E,b,D),i(E,E),j.pushArray(E),(t===d||g<u)&&(V.push(g),V.push(u),V.push(a),V.push(t)),(r===d||u<p)&&(V.push(u),V.push(p),V.push(a),V.push(r)),(h===d||p<g)&&(V.push(p),V.push(g),V.push(a),V.push(h))}return{edges:V,normals:j}}class v{constructor(){this.index=0,this.length=0}}const x=new o({allocator:e=>e||new v,deallocator:null}),V=new o({deallocator:null}),j=new o({deallocator:null}),y=new u,I=g(),N=g(),E=g(),b=g(),D=g(),F=t(4),M=Math.cos(F),k=t(35),L=Math.cos(k);export{p as extractEdges};