UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 4.03 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{pt2px as t}from"../../../../../../../core/screenUtils.js";import{GeometryCursor as e}from"../../../../../../../geometry/GeometryCursor.js";import{minMaxZoomPrecisionFactor as s,thinLineHalfWidthThreshold as i}from"../../../definitions.js";import{LineTessellation as r}from"../../../TurboLine.js";import{clipLinesMarshall as o}from"../../../mesh/templates/templateUtils.js";import{packRounded as n,processColorInput as a,getMinMaxZoom as c,processLineCapInput as h,processLineJoinInput as l}from"../fill/meshWriterUtils.js";import{MeshWriter as m}from"../mesh/MeshWriter.js";import{getLineClippingMargin as u}from"../mesh/utils.js";import{DataType as p}from"../../../../../../webgl/enums.js";class d{constructor(){this.extrusionOffsetX=0,this.extrusionOffsetY=0,this.normalX=0,this.normalY=0,this.directionX=0,this.directionY=0,this.distance=0,this.pathLength=0,this.distanceOffset=0,this.lineLength=0}}const f={createComputedParams:t=>t,optionalAttributes:{zoomRange:{type:p.SHORT,count:2,packPrecisionFactor:s,pack:({scaleInfo:t},{tileInfo:e})=>c(t,e)}},attributes:{id:{type:p.UNSIGNED_BYTE,count:3,pack:"id"},pos:{type:p.SHORT,count:2,pack:"position",packPrecisionFactor:10},bitset:{type:p.UNSIGNED_BYTE,count:1},color:{type:p.UNSIGNED_BYTE,count:4,normalized:!0,pack:({color:t})=>a(t)},offset:{type:p.BYTE,count:2,packPrecisionFactor:16,packTessellation:({extrusionOffsetX:t,extrusionOffsetY:e})=>[n(t,16),n(e,16)]},normal:{type:p.BYTE,count:2,packPrecisionFactor:16,packTessellation:({normalX:t,normalY:e})=>[n(t,16),n(e,16)]},halfWidth:{type:p.HALF_FLOAT,count:1,pack:({width:e})=>t(.5*e)},referenceHalfWidth:{type:p.HALF_FLOAT,count:1,pack:({referenceWidth:e})=>t(.5*e)}}};class _{constructor(){this.id=0,this.bitset=0,this.indexCount=0,this.vertexCount=0,this.vertexFrom=0,this.vertexBounds=0,this.pathLength=0,this.distanceOffset=0}}const x=65535;class T extends m{constructor(t,e,s,i){super(t,e,s,i),this.vertexSpec=f,this._currentWrite=new _,this._tessellationOptions={halfWidth:0,pixelCoordRatio:1,offset:0,wrapDistance:x,textured:!1},this._tessParams=new d,this._initializeTessellator()}writeLineVertices(t,e,s){const i=this._getLines(e);null!=i&&this._writeVertices(t,s,i)}_initializeTessellator(){this._lineTessellator=new r(this._writeTesselatedVertex.bind(this),this._writeTriangle.bind(this),!0)}_write(t,s,i){const r=i??e.fromFeatureSetReaderCIM(s);r&&this._writeGeometry(t,s,r)}_writeGeometry(t,e,s,i){t.recordStart(this.instanceId,this.attributeLayout,i),this.writeLineVertices(t,s,e),t.recordEnd()}_getLines(t){return o(t,u(this.evaluatedMeshParams))}_writeVertices(e,s,r){const{_currentWrite:o,_tessellationOptions:n,evaluatedMeshParams:a}=this,{width:c,capType:m,joinType:u,miterLimit:p,hasSizeVV:d}=a,f=t(.5*c);n.halfWidth=f,n.capType=h(m),n.joinType=l(u),n.miterLimit=p;const _=!d;o.out=e,o.id=s.getDisplayId(),o.vertexCount=0,o.indexCount=0,o.vertexFrom=e.vertexCount(),o.vertexBounds=_&&f<i?0:1;for(const{line:t,start:i,pathLength:h}of r)n.initialDistance=i%x,o.pathLength=h,o.distanceOffset=Math.floor(i/x)*x,this._lineTessellator.tessellate(t,n,_)}_writeTesselatedVertex(t,e,s,i,r,o,n,a,c,h,l){const{out:m,id:u,vertexBounds:p,pathLength:d,distanceOffset:f}=this._currentWrite;return this.hasEffects&&m.recordBounds(t,e,p,p),this._tessParams.extrusionOffsetX=n,this._tessParams.extrusionOffsetY=a,this._tessParams.normalX=c,this._tessParams.normalY=h,this._tessParams.directionX=r,this._tessParams.directionY=o,this._tessParams.distance=l,this._tessParams.pathLength=d,this._tessParams.distanceOffset=f,this._writeVertex(m,u,t,e,this._tessParams),this._currentWrite.vertexFrom+this._currentWrite.vertexCount++}_writeTriangle(t,e,s){const{out:i}=this._currentWrite;i.indexEnsureSize(3),i.indexWrite(t),i.indexWrite(e),i.indexWrite(s),this._currentWrite.indexCount+=3}}export{T as LineMeshWriter,d as LineTessellationParams,f as LineVertexSpec};