UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.03 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{floatSubArray as t}from"../../../../geometry/support/FloatArray.js";import{newHalfFloatArray as e}from"../../../../geometry/support/HalfFloatArray.js";import{newIntArray as i,compactIndices as s}from"../../../../geometry/support/Indices.js";import{newShortArray as r}from"../../../../geometry/support/ShortArray.js";import{compressNormal as o}from"./Normals.js";class h{constructor(s,o,h,n,a,p={}){this.path=s,this.profile=o,this.extruder=h,this.startCap=n,this.endCap=a,this.options=p,this._extrusionVertexCount=0;const l=this.path.vertices.length-2;this.numExtrusionProfiles=h.numProfilesPerJoin()*l+2,this.numVerticesTotal=o.vertices.length*this.numExtrusionProfiles,this.startCap.vertexBufferStart=this.numVerticesTotal;const u=this.startCap.numVertices;this.numVerticesTotal+=u,this.endCap.vertexBufferStart=this.numVerticesTotal;const x=this.endCap.numVertices;this.numVerticesTotal+=x,this.pathVertexData=i(1*this.numVerticesTotal),this.profileRightAxes=r(2*this.numVerticesTotal),this.profileUpAxes=r(2*this.numVerticesTotal),this.profileVertexAndNormals=e(4*this.numVerticesTotal),this.profileAuxData=e(3*this.numVerticesTotal),this.positions=t(s.positions,s.offset,3*s.vertices.length),this._rebuildGeometry(),this._buildTopology()}emitVertex(t,e,i,s,r){let h=4*this._extrusionVertexCount;if(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,h=3*this._extrusionVertexCount,r){const e=this.path.vertices[t],i=e.maxStretchDistance;this.profileAuxData[h]=e.rotationRight[0]*i,this.profileAuxData[h+1]=e.rotationRight[1]*i}else this.profileAuxData[h]=this.profileAuxData[h+1]=0;this.profileAuxData[h+2]=0,o(this.profileRightAxes,this._extrusionVertexCount,e.right[0],e.right[1],e.right[2]),o(this.profileUpAxes,this._extrusionVertexCount,e.up[0],e.up[1],e.up[2]),++this._extrusionVertexCount}emitCapVertex(t,e,i,s,r,h){let n=4*this._extrusionVertexCount;this.profileVertexAndNormals[n]=i[0],this.profileVertexAndNormals[n+1]=i[1],this.profileVertexAndNormals[n+2]=s[0],this.profileVertexAndNormals[n+3]=s[1],n=3*this._extrusionVertexCount,this.profileAuxData[n]=r,this.profileAuxData[n+1]=h,this.profileAuxData[n+2]=1,o(this.profileRightAxes,this._extrusionVertexCount,e.right[0],e.right[1],e.right[2]),o(this.profileUpAxes,this._extrusionVertexCount,e.up[0],e.up[1],e.up[2]),this.pathVertexData[this._extrusionVertexCount]=t,++this._extrusionVertexCount}_rebuildGeometry(){this._extrusionVertexCount=0;const{positions:e,offset:i,vertices:s}=this.path;this.positions=t(e,i,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 r=3*(2*(e*i));this.startCap.indexBufferStart=r,this.startCap.firstProfileVertexIndex=0,r+=this.startCap.numIndices,this.endCap.indexBufferStart=r,this.endCap.firstProfileVertexIndex=t*(this.numExtrusionProfiles-1);const o=new Array,h=new Array,n=(t,e,i)=>{o.push(t),o.push(e),o.push(i),h.push(this.pathVertexData[t]),h.push(this.pathVertexData[e]),h.push(this.pathVertexData[i])};for(let s=0;s<e;++s){const e=this.profile.indices[2*s],r=this.profile.indices[2*s+1];for(let s=0;s<i;++s){const i=s*t+e,o=(s+1)*t+r,h=s*t+r;n(i,(s+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=s(o),this.pathVertexIndices=s(h)}onPathChanged(){this._rebuildGeometry()}}export{h as PathBuilder};