/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../core/maybe","../../../../chunks/mat4f64","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../geometry/support/aaBoundingBox","./featureExpressionInfoUtils","./graphicUtils","../../webgl-engine/lib/basicInterfaces","../../webgl-engine/lib/Object3DStateID"],(function(e,t,n,i,s,a,o,r,c,l){"use strict";let h=function(){function n(e,t,n,i){this.graphics3DSymbolLayer=e,this.instanceIndex=t,this.elevationAligner=n,this.elevationContext=i,this.type="lod-instance",this._highlights=new Set,this.alignedSampledElevation=0,this.isElevationSource=!1,this.needsElevationUpdates=!1}var h=n.prototype;return h.initialize=function(){},h.setVisibility=function(e){const t=this.lodRenderer.instanceData;e!==t.getVisible(this.instanceIndex)&&t.setVisible(this.instanceIndex,e)},h.destroy=function(){null!=this.instanceIndex&&(this.lodRenderer.instanceData.removeInstance(this.instanceIndex),this.graphics3DSymbolLayer.notifyDestroyGraphicLayer(this))},h.alignWithElevation=function(e,n,i){if(this.elevationAligner){o.setContextFeature(this.elevationContext.featureExpressionInfoContext,i);const s=this.elevationAligner(this,this.elevationContext,e,n);t.isSome(s)&&(this.alignedSampledElevation=s)}},h.getCenterObjectSpace=function(e=s.create()){return this.lodRenderer.instanceData.getCombinedLocalTransform(this.instanceIndex,m),i.transformMat4(e,this.lodRenderer.baseBoundingSphere.center,m)},h.getBoundingBoxObjectSpace=function(e=a.create()){this.lodRenderer.instanceData.getCombinedLocalTransform(this.instanceIndex,m);const t=this.lodRenderer.baseBoundingBox;a.empty(e);for(let n=0;n<8;++n)i.set(g,0==(1&n)?t[0]:t[3],0==(2&n)?t[1]:t[4],0==(4&n)?t[2]:t[5]),i.transformMat4(g,g,m),a.expandWithVec3(e,g);return e},h.computeAttachmentOrigin=function(e){this.lodRenderer.instanceData.getGlobalTransform(this.instanceIndex,m),e.render.origin[0]+=m[12],e.render.origin[1]+=m[13],e.render.origin[2]+=m[14],e.render.num++},h.getProjectedBoundingBox=function(){var n=e._asyncToGenerator((function*(e,n,s,o,c){const l=this.getBoundingBoxObjectSpace(c),h=f,p=a.isPoint(l)?1:h.length;this.lodRenderer.instanceData.getGlobalTransform(this.instanceIndex,m);for(let t=0;t<p;t++){const e=h[t];g[0]=l[e[0]],g[1]=l[e[1]],g[2]=l[e[2]],i.transformMat4(g,g,m),d[3*t+0]=g[0],d[3*t+1]=g[1],d[3*t+2]=g[2]}if(!e(d,0,p))return null;a.empty(l);let b=null;this.calculateRelativeScreenBounds&&(b=this.calculateRelativeScreenBounds());for(let t=0;t<3*p;t+=3){for(let e=0;e<3;e++)l[e]=Math.min(l[e],d[t+e]),l[e+3]=Math.max(l[e+3],d[t+e]);b&&s.push({location:d.slice(t,t+3),screenSpaceBoundingRect:b})}if(n&&(a.center(l,u),"absolute-height"!==this.elevationContext.mode)){let e;const i=r.demResolutionForBoundingBox(l,n);try{e=yield n.service.queryElevation(u[0],u[1],o,i,"ground")}catch(x){}t.isSome(e)&&a.offset(l,0,0,-this.alignedSampledElevation+e)}return l}));function s(e,t,i,s,a){return n.apply(this,arguments)}return s}(),h.addObjectState=function(e,t){if(e===c.Object3DState.Highlight){const n=new l.Object3DStateID(e);this._addHighlightId(n),t.addExternal((e=>{this._removeHighlightId(e)}),n)}},h.removeObjectState=function(e){this._highlights.forEach((t=>e.remove(t)))},h._addHighlightId=function(e){this._highlights.add(e),this.lodRenderer.instanceData.setHighlight(this.instanceIndex,!0)},h._removeHighlightId=function(e){this._highlights.delete(e),this.lodRenderer.instanceData.setHighlight(this.instanceIndex,this._highlights.size>0)},e._createClass(n,[{key:"lodRenderer",get:function(){return this.graphics3DSymbolLayer.lodRenderer}}]),n}();const d=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],g=s.create(),u=s.create(),f=[[0,1,2],[3,1,2],[0,4,2],[3,4,2],[0,1,5],[3,1,5],[0,4,5],[3,4,5]],m=n.create();return h}));
