@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.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{i as e,d as t}from"../../../../../chunks/vec32.js";import{create as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{newDoubleArray as s}from"../../../../../geometry/support/DoubleArray.js";import{ViewingMode as i}from"../../../../ViewingMode.js";import{glLayout as o}from"../../../support/buffer/glUtil.js";import{newLayout as f}from"../../../support/buffer/InterleavedLayout.js";import{vertexAttributeLocations as n}from"./LaserlinePathTechnique.js";import{VertexArrayObject as u}from"../../lib/VertexArrayObject.js";import{VertexAttribute as a}from"../../lib/VertexAttribute.js";import{BufferObject as l}from"../../../../webgl/BufferObject.js";import{PrimitiveType as c,Usage as h}from"../../../../webgl/enums.js";class _{constructor(e){this._renderCoordsHelper=e,this._buffers=null,this._origin=r(),this._dirty=!1,this._count=0,this._vao=null}set vertices(e){const t=s(3*e.length);let r=0;for(const s of e)t[r++]=s[0],t[r++]=s[1],t[r++]=s[2];this.buffers=[t]}set buffers(t){if(this._buffers=t,this._buffers.length>0){const t=this._buffers[0],r=3*Math.floor(t.length/3/2);e(this._origin,t[r],t[r+1],t[r+2])}else e(this._origin,0,0,0);this._dirty=!0}get origin(){return this._origin}draw(e){const t=this._ensureVAO(e);null!=t&&(e.bindVAO(t),e.drawArrays(c.TRIANGLES,0,this._count))}dispose(){null!=this._vao&&this._vao.dispose()}get _layout(){return this._renderCoordsHelper.viewingMode===i.Global?b:g}_ensureVAO(e){return null==this._buffers?null:(this._vao??=this._createVAO(e,this._buffers),this._ensureVertexData(this._vao,this._buffers),this._vao)}_createVAO(e,t){const r=this._createDataBuffer(t);return this._dirty=!1,new u(e,n,new Map([["data",o(this._layout)]]),new Map([["data",l.createVertex(e,h.STATIC_DRAW,r)]]))}_ensureVertexData(e,t){if(!this._dirty)return;const r=this._createDataBuffer(t);e.vertexBuffers.get("data")?.setData(r),this._dirty=!1}_createDataBuffer(r){const s=r.reduce(((e,t)=>e+d(t)),0);this._count=s;const i=this._layout.createBuffer(s),o=this._origin;let f=0,n=0;const u="startUp"in i?this._setUpVectors.bind(this,i):void 0;for(const a of r){for(let r=0;r<a.length;r+=3){const s=e(m,a[r],a[r+1],a[r+2]);0===r?n=this._renderCoordsHelper.getAltitude(s):this._renderCoordsHelper.setAltitude(s,n);const l=f+2*r;u?.(r,l,a,s);const c=t(m,s,o);if(r<a.length-3){for(let e=0;e<6;e++)i.start.setVec(l+e,c);i.extrude.setValues(l,0,-1),i.extrude.setValues(l+1,1,-1),i.extrude.setValues(l+2,1,1),i.extrude.setValues(l+3,0,-1),i.extrude.setValues(l+4,1,1),i.extrude.setValues(l+5,0,1)}if(r>0)for(let e=-6;e<0;e++)i.end.setVec(l+e,c)}f+=d(a)}return i.buffer}_setUpVectors(e,t,r,s,i){const o=this._renderCoordsHelper.worldUpAtPosition(i,p);if(t<s.length-3)for(let f=0;f<6;f++)e.startUp.setVec(r+f,o);if(t>0)for(let f=-6;f<0;f++)e.endUp.setVec(r+f,o)}}function d(e){return 3*(2*(e.length/3-1))}const p=r(),m=r(),b=f().vec3f(a.START).vec3f(a.END).vec2f(a.EXTRUDE).vec3f(a.START_UP).vec3f(a.END_UP),g=f().vec3f(a.START).vec3f(a.END).vec2f(a.EXTRUDE);export{_ as LaserlinePathData};