/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{set as e}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{exactEquals as r,copy as i}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{fromArray as s}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{Object3DVisualElement as a}from"./Object3DVisualElement.js";import{ElevationContext as l}from"../../layers/graphics/ElevationContext.js";import{geometryToRenderInfo as o}from"../../support/renderInfoUtils/point.js";import{createSphereGeometry as n}from"../../webgl-engine/lib/GeometryUtil.js";import{ShadedColorMaterial as c}from"../../webgl-engine/materials/ShadedColorMaterial.js";class h extends a{constructor(e){super(e),this.view=null,this._renderOccluded=4,this._vertices=null,this._spatialReference=null,this._color=s([1,127/255,0,1]),this._size=11,this._outlineColor=s([0,0,0,.5]),this._outlineSize=1,this._elevationInfo=null,this.applyProperties(e)}get renderOccluded(){return this._renderOccluded}set renderOccluded(e){e!==this._renderOccluded&&(this._renderOccluded=e,this._updateMaterial(),this._updateOutlineMaterial())}get vertices(){return this._vertices}set vertices(e){this._vertices=e,this.recreateGeometry()}get spatialReference(){return this._spatialReference}set spatialReference(e){this._spatialReference=e,this.recreateGeometry()}get color(){return this._color}set color(e){r(e,this._color)||(i(this._color,e),this._updateMaterial())}get size(){return this._size}set size(e){e!==this._size&&(this._size=e,this._updateMaterial())}get outlineColor(){return this._outlineColor}set outlineColor(e){r(e,this._outlineColor)||(i(this._outlineColor,e),this._updateOutlineMaterial())}get outlineSize(){return this._outlineSize}set outlineSize(e){e!==this._outlineSize&&(this._outlineSize=e,this._updateOutlineMaterial())}get elevationInfo(){return this._elevationInfo}set elevationInfo(e){this._elevationInfo=e,this.recreateGeometry()}get _vertexMaterialParameters(){return{color:this._color,screenSizeScale:this.size,renderOccluded:this._renderOccluded,isDecoration:this.isDecoration}}get _vertexOutlineMaterialParameters(){return{color:this._outlineColor,screenSizeScale:this.size+2*this.outlineSize,renderOccluded:this._renderOccluded,isDecoration:this.isDecoration}}_updateMaterial(){this.attached&&this._vertexMaterial.setParameters(this._vertexMaterialParameters)}_updateOutlineMaterial(){this.attached&&this._vertexOutlineMaterial.setParameters(this._vertexOutlineMaterialParameters)}_createRenderGeometries(){const t=this.vertices;if(null==t||0===t.length)return[];const r=.5,i=.5,s=o(t,this.spatialReference,this.view.elevationProvider,this.view.renderCoordsHelper,l.fromElevationInfo(this.elevationInfo)),a=[],n=s.numVertices,c=s.position;for(let l=0;l<n;++l){const t=e(u,c[3*l],c[3*l+1],c[3*l+2]),s=d(this._vertexMaterial,r,t),o=d(this._vertexOutlineMaterial,i,t);a.push({vertexGeometry:s,vertexOutlineGeometry:o})}return a}createGeometries(e){const t=this._createRenderGeometries();for(const{vertexGeometry:r,vertexOutlineGeometry:i}of t)e.addGeometry(r),e.addGeometry(i)}createExternalResources(){this._vertexMaterial=new c({...this._vertexMaterialParameters,writeDepth:!0,cullFace:2,screenSizeEnabled:!0}),this._vertexOutlineMaterial=new c({...this._vertexOutlineMaterialParameters,forceTransparentMode:!0,writeDepth:!0,cullFace:1,screenSizeEnabled:!0,shadingEnabled:!1})}destroyExternalResources(){this._vertexMaterial=null,this._vertexOutlineMaterial=null}forEachMaterial(e){e(this._vertexMaterial),e(this._vertexOutlineMaterial)}}const u=t();function d(e,t,r){return n(e,t,16,16,{offset:r})}export{h as VerticesVisualElement};
