@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.18 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{estimateNumberArrayMemory as t}from"../../../../core/memoryEstimations.js";import{newFloatArray as e,floatSubArray as i}from"../../../../geometry/support/FloatArray.js";import{newIntArray as s,compactIndices as r}from"../../../../geometry/support/Indices.js";class o{constructor(t,r,o,h,p,n={}){this.path=t,this.profile=r,this.extruder=o,this.startCap=h,this.endCap=p,this.options=n,this._extrusionVertexCount=0;const l=this.path.vertices.length-2;this.numExtrusionProfiles=o.numProfilesPerJoin()*l+2,this.numVerticesTotal=r.vertices.length*this.numExtrusionProfiles,this.startCap.vertexBufferStart=this.numVerticesTotal;const a=this.startCap.numVertices;this.numVerticesTotal+=a,this.endCap.vertexBufferStart=this.numVerticesTotal;const u=this.endCap.numVertices;this.numVerticesTotal+=u,this.pathVertexData=s(1*this.numVerticesTotal),this.profileRightAxes=e(4*this.numVerticesTotal),this.profileUpAxes=e(4*this.numVerticesTotal),this.profileVertexAndNormals=e(4*this.numVerticesTotal),this.positions=i(t.positions,t.offset,3*t.vertices.length),this._rebuildGeometry(),this.buildTopology()}get usedMemory(){return t(this.pathVertexData,this.profileRightAxes,this.profileUpAxes,this.profileVertexAndNormals)+this.path.usedMemory+this.profile.usedMemory}emitVertex(t,e,i,s,r){const o=4*this._extrusionVertexCount;if(this.profileRightAxes[o]=e.right[0],this.profileRightAxes[o+1]=e.right[1],this.profileRightAxes[o+2]=e.right[2],this.profileUpAxes[o]=e.up[0],this.profileUpAxes[o+1]=e.up[1],this.profileUpAxes[o+2]=e.up[2],this.profileVertexAndNormals[o]=i[0],this.profileVertexAndNormals[o+1]=i[1],this.profileVertexAndNormals[o+2]=s[0],this.profileVertexAndNormals[o+3]=s[1],this.pathVertexData[this._extrusionVertexCount]=t,r){const e=this.path.vertices[t],i=e.maxStretchDistance;this.profileRightAxes[o+3]=e.rotationRight[0]*i,this.profileUpAxes[o+3]=e.rotationRight[1]*i}else this.profileRightAxes[o+3]=0,this.profileUpAxes[o+3]=0;++this._extrusionVertexCount}emitCapVertex(t,e,i,s,r,o){const h=4*this._extrusionVertexCount;this.profileRightAxes[h]=e.right[0],this.profileRightAxes[h+1]=e.right[1],this.profileRightAxes[h+2]=e.right[2],this.profileRightAxes[h+3]=r,this.profileUpAxes[h]=e.up[0],this.profileUpAxes[h+1]=e.up[1],this.profileUpAxes[h+2]=e.up[2],this.profileUpAxes[h+3]=o,this.profileVertexAndNormals[h]=i[0],this.profileVertexAndNormals[h+1]=i[1],this.profileVertexAndNormals[h+2]=s[0],this.profileVertexAndNormals[h+3]=s[1],this.pathVertexData[this._extrusionVertexCount]=t,++this._extrusionVertexCount}_rebuildGeometry(){this._extrusionVertexCount=0;const{positions:t,offset:e,vertices:s}=this.path;this.positions=i(t,e,3*s.length);let r=0;const o=(t,e,i,s,o)=>this.emitCapVertex(r,t,e,i,s,o),h=(t,e,i,s)=>this.emitVertex(r,t,e,i,s);for(this.startCap.rebuildConnectingProfileGeometry(s[r],this.profile,o),r=1;r<s.length-1;++r)this.extruder.extrude(s[r],this.profile,h);this.endCap.rebuildConnectingProfileGeometry(s[r],this.profile,o),r=0,this.startCap.rebuildCapGeometry(s[r],o),r=s.length-1,this.endCap.rebuildCapGeometry(s[r],o)}buildTopology(){const t=this.profile.vertices.length,e=this.profile.numSegments,i=this.numExtrusionProfiles-1;let s=3*(2*(e*i));this.startCap.indexBufferStart=s,this.startCap.firstProfileVertexIndex=0,s+=this.startCap.numIndices,this.endCap.indexBufferStart=s,this.endCap.firstProfileVertexIndex=t*(this.numExtrusionProfiles-1);const o=new Array,h=new Array,p=new Array,n=(t,e,i)=>{o.push(t),o.push(e),o.push(i),h.push(t),h.push(e),h.push(i),p.push(this.pathVertexData[t]),p.push(this.pathVertexData[e]),p.push(this.pathVertexData[i])};for(let r=0;r<e;++r){const e=this.profile.indices[2*r],s=this.profile.indices[2*r+1];for(let r=0;r<i;++r){const i=r*t+e,o=(r+1)*t+s,h=r*t+s;n(i,(r+1)*t+e,o),n(i,o,h)}}this.startCap.buildTopology(this.path.vertices[0],n),this.endCap.buildTopology(this.path.vertices[this.path.vertices.length-1],n),this.vertexIndices=r(o),this.normalIndices=r(h),this.pathVertexIndices=r(p)}onPathChanged(){this._rebuildGeometry()}}export{o as PathBuilder};