/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{deg2rad as t}from"../../../../core/mathUtils.js";import{fromScaling as e,mul as r,fromTranslation as s,fromRotation as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{h as a,d as n,p 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"./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 D}from"../../webgl-engine/materials/ColorMaterial.js";class b extends d{constructor(t){super(t),this._material=null,this._viewshedComputedData=null,this._material=new D({...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 o=i(),a=t.farDistanceRenderSpace;e(o,m(a,a,a)),p(t,M),r(o,M,o),s(M,this._viewshedComputedData.observerRenderSpace),r(o,M,o),this.transform=o}createExternalResources(){}destroyExternalResources(){}forEachMaterial(t){t(this._material)}createGeometries(t){const{_material:e,viewshedComputedData:r}=this;if(null==r||null==e||!r.valid)return;j(e,r).forEach(e=>t.addGeometry(e))}}function j(e,r){const{horizontalFieldOfView:s,verticalFieldOfView:i}=r,m=a(C,0,0,1),c=a(_,0,1,0),f=a(x,1,0,0);u(m,m,t(i/2),c),u(m,m,t(s/2),f);const p=t=>Math.ceil(Math.abs(t)/h)+1,d=t(s),D=n(E,f),b=p(d),j=g(-d/(b-1)),R=o(M,j,D),V=t(-i),G=p(V),O=g(V/(G-1)),T=n(_,c),F=o(y,t(s)/2,f);l(T,T,F);const N=y,P=[],S=n(x,m);for(let t=0;t<b;t++){o(N,O,T);for(let e=0;e<G;e++){const r=3*(e*b+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=b*G;P[3*U]=0,P[3*U+1]=0,P[3*U+2]=0;const k=[];for(let t=0;t<b-1;t++)for(let e=0;e<G-1;e++){const r=6*(e*(b-1)+t);k[r]=e*b+t,k[r+1]=(e+1)*b+t,k[r+2]=e*b+t+1,k[r+3]=e*b+t+1,k[r+4]=(e+1)*b+t,k[r+5]=(e+1)*b+t+1}const z=[k];if(360!==s&&0!==i){const t=[],e=[];for(let r=0;r<G-1;r++){const s=3*r;t[s]=U,t[s+1]=(r+1)*b,t[s+2]=r*b,e[s]=U,e[s+1]=r*b+b-1,e[s+2]=(r+1)*b+b-1}z.push(t,e)}if(180!==i&&0!==s){const t=[],e=[];for(let r=0;r<b-1;r++){const s=3*r;t[s]=U,t[s+1]=r,t[s+2]=r+1,e[s]=U,e[s+1]=r+(G-1)*b+1,e[s+2]=r+(G-1)*b}z.push(t,e)}return z.map(t=>{const r=[["position",new w(P,t,3,!0)]];return new v(e,r)})}function g(t){return isNaN(t)?1:t}const C=c(),_=c(),x=c(),E=c(),M=i(),y=i();export{b as ViewshedShapeVisualElement};
