/*
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/vec3","../../../../chunks/vec3f64","../../../../geometry/support/aaBoundingBox","../../../../geometry/support/aaBoundingRect","./graphicUtils","../../webgl-engine/lib/basicInterfaces","../../webgl-engine/lib/ModelDirtyTypes"],(function(e,t,i,r,n,o,s,d,a){"use strict";let c=function(){function o(e,t,i,r){this.graphics3DSymbolLayer=e,this.renderGeometries=t,this.boundingBox=i,this._drapeSourceRenderer=r,this.type="draped",this.stage=null,this._visible=!1,this._addedToStage=!1,this.isElevationSource=!1}var c=o.prototype;return c.initialize=function(e){this.stage=e},c.setVisibility=function(e){if(null!=this.stage&&this._visible!==e){if(this._visible=e,e&&!this._addedToStage)return this._addedToStage=!0,void this._drapeSourceRenderer.addGeometries(this.renderGeometries,a.ModelDirty.Geometry.ADD);if(e||this._addedToStage){for(const e of this.renderGeometries)e.instanceParameters.visible=this._visible;this._drapeSourceRenderer.modifyGeometries(this.renderGeometries,a.ModelDirty.State.VISIBILITIES)}}},c.destroy=function(){this.stage&&this._addedToStage&&this._drapeSourceRenderer.removeGeometries(this.renderGeometries,a.ModelDirty.Geometry.REMOVE),this._addedToStage=!1,this._visible=!1,this.stage=null},c.getCenterObjectSpace=function(e=r.create()){return i.set(e,0,0,0)},c.getBoundingBoxObjectSpace=function(e=n.create()){return n.empty(e)},c.addObjectState=function(e,t){e===d.Object3DState.Highlight&&(this.renderGeometries.forEach((e=>{const i=e.addHighlight();t.addRenderGeometry(e,i,this)})),this._addedToStage&&this._drapeSourceRenderer.modifyGeometries(this.renderGeometries,a.ModelDirty.State.HIGHLIGHTS))},c.removeObjectState=function(e){this.renderGeometries.forEach((t=>{e.removeRenderGeometry(t)}))},c.removeRenderGeometryObjectState=function(e,t){e.removeHighlight(t),this._addedToStage&&this._drapeSourceRenderer.modifyGeometries(this.renderGeometries,a.ModelDirty.State.HIGHLIGHTS)},c.computeAttachmentOrigin=function(e){for(const t of this.renderGeometries)t.computeAttachmentOrigin(g)&&(e.draped.origin[0]+=g[0],e.draped.origin[1]+=g[1],e.draped.num++)},c.getProjectedBoundingBox=function(){var i=e._asyncToGenerator((function*(e,i,r,o,d){n.empty(d);for(let t=0;t<this.renderGeometries.length;t++){const i=this.renderGeometries[t];this._getRenderGeometryProjectedBoundingRect(i,e,h,r),n.expandWithRect(d,h)}if(i){let e;n.center(d,g);const r=s.demResolutionForBoundingBox(d,i);try{e=yield i.service.queryElevation(g[0],g[1],o,r,"ground")}catch(a){}t.isSome(e)&&(d[2]=Math.min(d[2],e),d[5]=Math.max(d[5],e))}return d}));function r(e,t,r,n,o){return i.apply(this,arguments)}return r}(),c._getRenderGeometryProjectedBoundingRect=function(e,t,i,r){if(this.boundingBox)n.set(u,this.boundingBox);else{const t=e.boundingSphere,i=t[3];u[0]=t[0]-i,u[1]=t[1]-i,u[2]=t[2]-i,u[3]=t[0]+i,u[4]=t[1]+i,u[5]=t[2]+i}return t(u,0,2),this.calculateRelativeScreenBounds&&r.push({location:n.center(u),screenSpaceBoundingRect:this.calculateRelativeScreenBounds()}),n.toRect(u,i)},o}();const h=o.create(),u=n.create(),g=r.create();return c}));
