UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 4.37 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{pt2px as t}from"../../../../../../../core/screenUtils.js";import{GeometryCursor as e}from"../../../../../../../geometry/GeometryCursor.js";import{triangulateF32 as s}from"../../../../../../../geometry/libtess.js";import{LineTessellation as i}from"../../../TurboLine.js";import{clipLinesMarshall as r,triangulateEarcut as n,clipMarshall as o}from"../../../mesh/templates/templateUtils.js";import{AAnimatedMeshWriter as a}from"./AnimatedMeshWriter.js";import{noPatternAngle as h,lineLength as l,noTiming as m,zoomRange as u,segmentDirection as c,normal as d,accumulatedDistance as f,sizing as p,animationPointerAndBaseSizeAndReferenceSize as x,tlbr as _,offset as g,pos as P,bitset as b,id as v,patternAngle as L,noLineLength as y}from"./attributes.js";import{createComputedAnimatedMeshParams as W}from"./ComputedAnimatedParams.js";import{processLineCapInput as w,processLineJoinInput as C}from"../fill/meshWriterUtils.js";import{LineTessellationParams as z}from"../line/LineMeshWriter.js";class j extends a{_write(t,s,i){const r=i??e.fromFeatureSetReaderCIM(s);if(!r)return;const n=this.evaluatedMeshParams.sprite,{textureBinding:o}=n;t.recordStart(this.instanceId,this.attributeLayout,o);const a=s.getDisplayId();this._writePoly(t,a,r.asOptimized()),t.recordEnd()}}class S extends j{constructor(){super(...arguments),this.vertexSpec={createComputedParams:W,attributes:{id:v,bitset:b,pos:P,offset:g.fill,tlbr:_,animationPointerAndBaseSizeAndReferenceSize:x,sizing:p},optionalAttributes:{zoomRange:u,value1Position2Value2:m,lineLength:y,angle:L}}}_writePoly(t,e,i){const r=this._clip(i);if(!r)return;i=r;const o=[],a=t.vertexCount();let h;if(n(o,i)){if(0===o.length)return;h=0;for(const s of o){const r=i.coords[2*s],n=i.coords[2*s+1];this._writeVertex(t,e,r,n),h++}}else{const{coords:r,lengths:n}=i,o=s(r,n);h=o.vertexCount;for(let s=0;s<o.buffer.length/2;s++){const i=o.buffer[2*s],r=o.buffer[2*s+1];this._writeVertex(t,e,i,r)}}if(h>0){t.indexEnsureSize(h);for(let e=0;e<h;e++)t.indexWrite(e+a)}}_clip(t){const e=this.hasEffects;return o(t,e?256:8)}}class T{constructor(){this.id=0,this.bitset=0,this.indexCount=0,this.vertexCount=0,this.vertexFrom=0,this.vertexBounds=0,this.pathLength=0}}const A=65535;class R extends j{constructor(){super(...arguments),this.vertexSpec={createComputedParams:W,attributes:{id:v,bitset:b,pos:P,offset:g.line,tlbr:_,animationPointerAndBaseSizeAndReferenceSize:x,sizing:p,accumulatedDistance:f,normal:d,segmentDirection:c},optionalAttributes:{zoomRange:u,value1Position2Value2:m,lineLength:l,angle:h}},this._tessParams=new z,this._currentWrite=new T,this._tessellationOptions={halfWidth:0,pixelCoordRatio:1,offset:0,wrapDistance:A,textured:!1},this._lineLength=0,this._lineTessellator=new i((t,e,s,i,r,n,o,a,h,l,m)=>this._writeTesselatedVertex(t,e,s,i,r,n,o,a,h,l,m,this._lineLength),this._writeTriangle.bind(this),!1)}_writePoly(s,i,n){const o=64,a=!1,h=r(e.fromOptimized(n,"esriGeometryPolyline"),o);if(null==h)return;const{_currentWrite:l,_tessellationOptions:m}=this,{baseSize:u,capType:c,joinType:d,miterLimit:f}=this.evaluatedMeshParams,p=t(.5*u);m.halfWidth=p,m.capType=w(c||"Round"),m.joinType=C(d||"Round"),m.miterLimit=f||2,l.out=s,l.id=i,l.vertexCount=0,l.indexCount=0,l.vertexFrom=s.vertexCount(),l.vertexBounds=1;for(const{line:t,start:e,pathLength:r}of h){m.initialDistance=e%A,l.pathLength=r,this._lineLength=0;for(let e=1;e<t.length;e++){const s=t[e].x-t[e-1].x,i=t[e].y-t[e-1].y;this._lineLength+=Math.sqrt(s*s+i*i)}this._lineTessellator.tessellate(t,m,a)}}_writeTesselatedVertex(t,e,s,i,r,n,o,a,h,l,m,u){const{out:c,id:d,vertexBounds:f,pathLength:p}=this._currentWrite;return this.hasEffects&&c.recordBounds(t,e,f,f),this._tessParams.extrusionOffsetX=o,this._tessParams.extrusionOffsetY=a,this._tessParams.normalX=h,this._tessParams.normalY=l,this._tessParams.directionX=r,this._tessParams.directionY=n,this._tessParams.distance=m,this._tessParams.pathLength=p,this._tessParams.lineLength=u,this._writeVertex(c,d,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{j as AAnimatedPolyMeshWriter,S as AnimatedFillMeshWriter,R as AnimatedLineMeshWriter};