/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{create as t}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{p as e,h as i}from"../../../../chunks/vec32.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as s,empty as a,expandWithVec3 as h,isPoint as r,center as l,offset as o}from"../../../../geometry/support/aaBoundingBox.js";import{evaluateElevationInfoAtPoint as g}from"./elevationAlignmentUtils.js";import{demResolutionForBoundingBox as c}from"./graphicUtils.js";import{Object3DHighlightStateID as d}from"../../webgl-engine/lib/Object3DStateID.js";class m{constructor(t,e,i,n,s){this.graphics3DSymbolLayer=t,this.instanceIndex=e,this.elevationAligner=i,this.elevationContext=n,this._highlightOrderMap=s,this.type="lod-instance",this._highlights=new Set,this.alignedSampledElevation=0,this.isElevationSource=!1,this.needsElevationUpdates=!1,this._highlightName=null}initialize(){}setVisibility(t){const{instanceData:e}=this;t!==e.getVisible(this.instanceIndex)&&e.setVisible(this.instanceIndex,t)}destroy(){null!=this.instanceIndex&&(this.instanceData.removeInstance(this.instanceIndex),this.graphics3DSymbolLayer.notifyDestroyGraphicLayer(this))}get usedMemory(){return this.graphics3DSymbolLayer.usedMemory}alignWithElevation(t,e){if(this.elevationAligner){const i=(i,n)=>g(i,t,this.elevationContext,e,n),n=this.elevationAligner(this,this.elevationContext,t.spatialReference,i,e);null!=n&&(this.alignedSampledElevation=n)}}getCenterObjectSpace(t=n()){return this.instanceData.getCombinedLocalTransform(this.instanceIndex,b),e(t,this._lodRenderer.baseBoundingSphere.center,b)}getBoundingBoxObjectSpace(t=s()){this.instanceData.getCombinedLocalTransform(this.instanceIndex,b);const n=this._lodRenderer.baseBoundingBox;a(t);for(let s=0;s<8;++s)i(u,1&s?n[3]:n[0],2&s?n[4]:n[1],4&s?n[5]:n[2]),e(u,u,b),h(t,u);return t}computeAttachmentOrigin(t){this.instanceData.getGlobalTransform(this.instanceIndex,b),t.render.origin[0]+=b[12],t.render.origin[1]+=b[13],t.render.origin[2]+=b[14],t.render.num++}async getProjectedBoundingBox(t,i,n,s,h){const g=this.getBoundingBoxObjectSpace(h),d=v,m=r(g)?1:d.length;this.instanceData.getGlobalTransform(this.instanceIndex,b);for(let a=0;a<m;a++){const t=d[a];u[0]=g[t[0]],u[1]=g[t[1]],u[2]=g[t[2]],e(u,u,b),p[3*a]=u[0],p[3*a+1]=u[1],p[3*a+2]=u[2]}if(!t(p,0,m))return null;a(g);let _=null;this.calculateRelativeScreenBounds&&(_=this.calculateRelativeScreenBounds());for(let e=0;e<3*m;e+=3){for(let t=0;t<3;t++)g[t]=Math.min(g[t],p[e+t]),g[t+3]=Math.max(g[t+3],p[e+t]);_&&n.push({location:p.slice(e,e+3),screenSpaceBoundingRect:_})}if(i&&(l(g,f),"absolute-height"!==this.elevationContext.mode)){let t;const e=c(g,i.service.spatialReference,i);try{t=await i.service.queryElevation(f[0],f[1],s,e,"ground")}catch(x){}null!=t&&o(g,0,0,-this.alignedSampledElevation+t)}return g}addObjectState(t){0===t.stateType&&this.addObjectHighlightState(t)}addObjectHighlightState(t){const e=new d(t.highlightName);this._addHighlightId(e),t.addExternal(t=>{this._removeHighlightId(t)},e)}removeObjectState(t){this._highlights.forEach(e=>t.remove(e))}updateHighlights(t){this._highlightOrderMap=t,this._updateHighlightOptions()}_calculateHighlightOptions(){let t=-1,e=null;return this._highlights.forEach(({highlightName:i})=>{const n=this._highlightOrderMap.get(i);void 0!==n&&n>t&&(t=n,e=i)}),e}_addHighlightId(t){this._highlights.add(t),this._updateHighlightOptions()}_removeHighlightId(t){this._highlights.delete(t),this._updateHighlightOptions()}_updateHighlightOptions(){const t=this._calculateHighlightOptions();t!==this._highlightName&&(this._highlightName=t,this.instanceData.setHighlight(this.instanceIndex,t))}get _lodRenderer(){return this.graphics3DSymbolLayer.lodRenderer}get instanceData(){return this._lodRenderer.instanceData}}const p=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],u=n(),f=n(),v=[[0,1,2],[3,1,2],[0,4,2],[3,4,2],[0,1,5],[3,1,5],[0,4,5],[3,4,5]],b=t();export{m as Graphics3DLodInstanceGraphicLayer};
