UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 3.17 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/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 h,arcAnglePerSegment as f}from"../../analysis/Viewshed/ViewshedConfiguration.js";import{getViewshedRotationMatrix as u,rotateBy as p}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 g}from"../../webgl-engine/lib/VertexAttribute.js";import{ColorMaterial as j}from"../../webgl-engine/materials/ColorMaterial.js";class v extends d{constructor(e){super(e),this._material=null,this._viewshedComputedData=null,this._material=new j({...h.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)),u(e,E),r(i,E,i),s(E,this._viewshedComputedData.observerRenderSpace),r(i,E,i),this.transform=i}createExternalResources(){}destroyExternalResources(){}forEachExternalMaterial(e){null!=this._material&&e(this._material)}createGeometries(e){const{_material:t,viewshedComputedData:r}=this;if(null==r||null==t||!r.isValid())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),h=a(V,1,0,0);p(m,m,e(o/2),c),p(m,m,e(s/2),h);const u=e=>Math.ceil(Math.abs(e)/f)+1,d=e(s),j=n(y,h),v=u(d),D=C(-d/(v-1)),O=i(E,D,j),R=e(-o),T=u(R),G=C(R/(T-1)),N=n(x,c),P=i(M,e(s)/2,h);l(N,N,P);const S=M,A=[],F=n(V,m);for(let e=0;e<v;e++){i(S,G,N);for(let t=0;t<T;t++){const r=3*(t*v+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=v*T;A[3*I]=0,A[3*I+1]=0,A[3*I+2]=0;const U=[];for(let e=0;e<v-1;e++)for(let t=0;t<T-1;t++){const r=6*(t*(v-1)+e);U[r]=t*v+e,U[r+1]=(t+1)*v+e,U[r+2]=t*v+e+1,U[r+3]=t*v+e+1,U[r+4]=(t+1)*v+e,U[r+5]=(t+1)*v+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)*v,e[s+2]=r*v,t[s]=I,t[s+1]=r*v+v-1,t[s+2]=(r+1)*v+v-1}k.push(e,t)}if(180!==o&&0!==s){const e=[],t=[];for(let r=0;r<v-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)*v+1,t[s+2]=r+(T-1)*v}k.push(e,t)}return k.map((e=>{const r=[[g.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{v as ViewshedShapeVisualElement};