@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.13 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{deg2rad as e}from"../../../../core/mathUtils.js";import{fromScaling as t,mul as r,fromTranslation as s,fromRotation as i}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i as a,c as n,t as l}from"../../../../chunks/vec32.js";import{fromValues as m,create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{viewshedVisualizationConfiguration as f,arcAnglePerSegment as h}from"../../analysis/Viewshed/ViewshedConfiguration.js";import{getViewshedRotationMatrix as p,rotateBy as u}from"../../analysis/Viewshed/viewshedToolUtils.js";import{Object3DVisualElement as d}from"./Object3DVisualElement.js";import{Attribute as w}from"../../webgl-engine/lib/Attribute.js";import{Geometry as b}from"../../webgl-engine/lib/Geometry.js";import{VertexAttribute as v}from"../../webgl-engine/lib/VertexAttribute.js";import{ColorMaterial as g}from"../../webgl-engine/materials/ColorMaterial.js";class j extends d{constructor(e){super(e),this._material=null,this._viewshedComputedData=null,this._material=new g({...f.shapeMaterialParameters,isDecoration:this.isDecoration,writeDepth:!1}),this.applyProperties(e)}get viewshedComputedData(){return this._viewshedComputedData}set viewshedComputedData(e){this._viewshedComputedData=e,this.updateTransform()}updateTransform(){const e=this._viewshedComputedData;if(null==e)return;const i=o(),a=e.farDistanceRenderSpace;t(i,m(a,a,a)),p(e,E),r(i,E,i),s(E,this._viewshedComputedData.observerRenderSpace),r(i,E,i),this.transform=i}createExternalResources(){}destroyExternalResources(){}forEachMaterial(e){e(this._material)}createGeometries(e){const{_material:t,viewshedComputedData:r}=this;if(null==r||null==t||!r.valid)return;D(t,r).forEach((t=>e.addGeometry(t)))}}function D(t,r){const{horizontalFieldOfView:s,verticalFieldOfView:o}=r,m=a(_,0,0,1),c=a(x,0,1,0),f=a(V,1,0,0);u(m,m,e(o/2),c),u(m,m,e(s/2),f);const p=e=>Math.ceil(Math.abs(e)/h)+1,d=e(s),g=n(y,f),j=p(d),D=C(-d/(j-1)),O=i(E,D,g),R=e(-o),T=p(R),G=C(R/(T-1)),N=n(x,c),P=i(M,e(s)/2,f);l(N,N,P);const S=M,A=[],F=n(V,m);for(let e=0;e<j;e++){i(S,G,N);for(let t=0;t<T;t++){const r=3*(t*j+e);A[r]=F[0],A[r+1]=F[1],A[r+2]=F[2],l(F,F,S)}l(N,N,O),l(m,m,O),n(F,m)}const I=j*T;A[3*I]=0,A[3*I+1]=0,A[3*I+2]=0;const U=[];for(let e=0;e<j-1;e++)for(let t=0;t<T-1;t++){const r=6*(t*(j-1)+e);U[r]=t*j+e,U[r+1]=(t+1)*j+e,U[r+2]=t*j+e+1,U[r+3]=t*j+e+1,U[r+4]=(t+1)*j+e,U[r+5]=(t+1)*j+e+1}const k=[U];if(360!==s&&0!==o){const e=[],t=[];for(let r=0;r<T-1;r++){const s=3*r;e[s]=I,e[s+1]=(r+1)*j,e[s+2]=r*j,t[s]=I,t[s+1]=r*j+j-1,t[s+2]=(r+1)*j+j-1}k.push(e,t)}if(180!==o&&0!==s){const e=[],t=[];for(let r=0;r<j-1;r++){const s=3*r;e[s]=I,e[s+1]=r,e[s+2]=r+1,t[s]=I,t[s+1]=r+(T-1)*j+1,t[s+2]=r+(T-1)*j}k.push(e,t)}return k.map((e=>{const r=[[v.POSITION,new w(A,e,3,!0)]];return new b(t,r)}))}function C(e){return isNaN(e)?1:e}const _=c(),x=c(),V=c(),y=c(),E=o(),M=o();export{j as ViewshedShapeVisualElement};