UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 2.99 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{deg2rad as t}from"../../../../core/mathUtils.js";import{fromScaling as e,mul as r,fromTranslation as o,fromRotation as i}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as a,copy as n,transformMat4 as l}from"../../../../core/libs/gl-matrix-2/math/vec3.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"./ViewshedConfiguration.js";import{getViewshedRotationMatrix as p,rotateBy as u}from"./viewshedToolUtils.js";import{Object3DVisualElement as d}from"../../interactive/visualElements/Object3DVisualElement.js";import{Attribute as w}from"../../webgl-engine/lib/Attribute.js";import{Geometry as v}from"../../webgl-engine/lib/Geometry.js";import{ColorMaterial as b}from"../../webgl-engine/materials/ColorMaterial.js";class D extends d{constructor(t){super(t),this._material=null,this._viewshedComputedData=null,this._material=new b({...f.shapeMaterialParameters,isDecoration:this.isDecoration,writeDepth:!1}),this.applyProperties(t)}get viewshedComputedData(){return this._viewshedComputedData}set viewshedComputedData(t){this._viewshedComputedData=t,this.updateTransform()}updateTransform(){const t=this._viewshedComputedData;if(null==t)return;const i=s(),a=t.farDistanceRenderSpace;e(i,m(a,a,a)),p(t,M),r(i,M,i),o(M,this._viewshedComputedData.observerRenderSpace),r(i,M,i),this.transform=i}createExternalResources(){}destroyExternalResources(){}forEachMaterial(t){t(this._material)}createGeometries(t){const{_material:e,viewshedComputedData:r}=this;if(null==r||null==e||!r.valid)return;g(e,r).forEach(e=>t.addGeometry(e))}}function g(e,r){const{horizontalFieldOfView:o,verticalFieldOfView:s}=r,m=a(C,0,0,1),c=a(_,0,1,0),f=a(x,1,0,0);u(m,m,t(s/2),c),u(m,m,t(o/2),f);const p=t=>Math.ceil(Math.abs(t)/h)+1,d=t(o),b=n(E,f),D=p(d),g=j(-d/(D-1)),R=i(M,g,b),V=t(-s),G=p(V),O=j(V/(G-1)),T=n(_,c),F=i(y,t(o)/2,f);l(T,T,F);const N=y,P=[],S=n(x,m);for(let t=0;t<D;t++){i(N,O,T);for(let e=0;e<G;e++){const r=3*(e*D+t);P[r]=S[0],P[r+1]=S[1],P[r+2]=S[2],l(S,S,N)}l(T,T,R),l(m,m,R),n(S,m)}const U=D*G;P[3*U]=0,P[3*U+1]=0,P[3*U+2]=0;const z=[];for(let t=0;t<D-1;t++)for(let e=0;e<G-1;e++){const r=6*(e*(D-1)+t);z[r]=e*D+t,z[r+1]=(e+1)*D+t,z[r+2]=e*D+t+1,z[r+3]=e*D+t+1,z[r+4]=(e+1)*D+t,z[r+5]=(e+1)*D+t+1}const A=[z];if(360!==o&&0!==s){const t=[],e=[];for(let r=0;r<G-1;r++){const o=3*r;t[o]=U,t[o+1]=(r+1)*D,t[o+2]=r*D,e[o]=U,e[o+1]=r*D+D-1,e[o+2]=(r+1)*D+D-1}A.push(t,e)}if(180!==s&&0!==o){const t=[],e=[];for(let r=0;r<D-1;r++){const o=3*r;t[o]=U,t[o+1]=r,t[o+2]=r+1,e[o]=U,e[o+1]=r+(G-1)*D+1,e[o+2]=r+(G-1)*D}A.push(t,e)}return A.map(t=>{const r=[["position",new w(P,t,3,!0)]];return new v(e,r)})}function j(t){return isNaN(t)?1:t}const C=c(),_=c(),x=c(),E=c(),M=s(),y=s();export{D as ViewshedShapeVisualElement};