// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("exports ../../../chunks/tslib.es6 ../../../core/Accessor ../../../core/Cyclical ../../../core/has ../../../core/mathUtils ../../../core/maybe ../../../core/reactiveUtils ../../../core/time ../../../core/accessorSupport/decorators/property ../../../core/Logger ../../../core/RandomLCG ../../../core/accessorSupport/decorators/subclass ../../../core/libs/gl-matrix-2/math/vec2 ../../../chunks/vec32 ../../../core/libs/gl-matrix-2/factories/vec3f64 ../../../chunks/vec42 ../../../core/libs/gl-matrix-2/factories/vec4f64 ../../../geometry/ellipsoidUtils ../../../geometry/projection/projectVectorToVector ../../../geometry/support/aaBoundingRect ../../../geometry/support/ray ../../../chunks/sphere ../../../geometry/support/vector ../../../geometry/support/webMercatorUtils ../state/utils/viewUtils ../support/debugFlags ../support/debugUtils ./interfaces ./OverlayRenderer ../webgl-engine/lib/basicInterfaces ../webgl-engine/lib/Intersector ../webgl-engine/lib/LocalOriginFactory ../webgl-engine/lib/Material ../webgl-engine/lib/SortedRenderGeometryRenderer ../webgl-engine/lib/textureUtils ../webgl-engine/parts/requireUtils ../../support/Scheduler ../../support/Yield".split(" "), function(l,m,P,E,Q,F,R,z,K,p,ma,na,S,T,B,L,G,M,C,N,k,O,H,U,V,W,I,X,q,Y,y,Z,aa,ba,ca,da,ea,J,fa){const ha=[[-.1,-2,3.9,2],[-.1,-3.9,3.9,.1],[-2,-3.9,2,.1],[-3.9,-3.9,.1,.1],[-3.9,-2,.1,2],[-3.9,-.1,.1,3.9],[-2,-.1,2,3.9],[-.1,-.1,3.9,3.9]];let x;l.OverlayManager=class extends P{constructor(a){super(a);this._renderSR=this._spatialReference=null;this._overlaySREqualsRenderSR=!0;this._drapeSources=new Set;this._drapeTargets=new Set;this._drawTexturesAnimateDirty=this._drawTexturesDirty=this._contentUpdated= this._placementDirty=!1;this._longitudeCyclical=null;this._latestOriginId=0;this._maxResolution=Q("esri-mobile")?2048:4096;this._animationTimeLast=0}initialize(){const a=this.view;this.renderer=new Y.OverlayRenderer({view:a,worldToPCSRatio:this._worldToPCSRatio,spatialReference:this._spatialReference});a._stage.renderer.plugins.add(this.renderer);const b=()=>this.setDrawTexturesDirty();this._groundIntersector=Z.newIntersector(this.view.state.viewingMode);this._groundIntersector.options.backfacesTerrain= !0;this._groundIntersector.options.invisibleTerrain=!0;this._groundIntersector.options.hud=!1;this.addHandles([z.watch(()=>this.renderer.hasHighlights,b),this.renderer.events.on("has-water",c=>a._stage?.renderer.setParameters({hasOverlayWater:c})),this.renderer.events.on("content-changed",b),z.watch(()=>a.state.camera.pixelRatio,b),z.watch(()=>a.state.alignPixelEnabled,b),this.renderer.events.on("textures-disposed",()=>this.surface.requestRender()),z.watch(()=>[a.pointsOfInterest?.renderPointOfView, a.pointsOfInterest?.centerOnSurfaceFrequent?.location],()=>this.setPlacementDirty()),z.watch(()=>[a.state?.pixelRatio,a.state?.contentPixelRatio],()=>this.setPlacementDirty(),z.sync),this.surface.on("elevation-change",()=>this.setPlacementDirty()),a.on("resize",()=>this.setPlacementDirty()),a.resourceController.scheduler.registerTask(J.TaskPriority.OVERLAY,this),a._stage.renderView.events.on("force-camera-for-screenshot",c=>{this._updateOverlays(J.noBudget,c.camera,y.RenderRequestType.BACKGROUND); this.renderer.hasOverlays&&this._drawOverlays(y.RenderRequestType.BACKGROUND,c)})]);a._stage.renderer.renderOverlay=c=>this._renderOverlay(c)}destroy(){this.view?._stage&&(this.view._stage.renderer.plugins.remove(this.renderer),this.view._stage.renderer.renderOverlay=()=>{});x&&(x.hide(),x=null);this.renderer=R.destroyMaybe(this.renderer)}get running(){return this._placementDirty&&(0this._updateDrapeSourceExtent(f)),this.surface.updateTileOverlayParams(c);b===u.NONE&&d===u.NONE||this.setDrawTexturesDirty(); this._placementDirty=!1;a.madeProgress()}_computeOverlayResolution(a){const b=this.view.state.contentPixelRatio*this.view.resolutionScale;return Math.min(da.applyTextureResizeModulo(Math.ceil(1.5*Math.max(a.fullWidth/a.pixelRatio*b,a.fullHeight/a.pixelRatio*b))),this._maxResolution)}_updateOverlay(a,b,c,d,e){if(0===this.renderer.overlays.length)return u.NONE;a=this.renderer.overlays[a];const f=a.mapUnitsPerPixel;a.mapUnitsPerPixel=e;a.pixelRatio=d;d=a.extent;const r=I.debugFlags.TESTS_DISABLE_OPTIMIZATIONS? 0:1E-5*Math.max(b[2]-b[0],b[3]-b[1],d[2]-d[0],d[3]-d[1]);if(Math.abs(d[0]-b[0])<=r&&Math.abs(d[1]-b[1])<=r&&Math.abs(d[2]-b[2])<=r&&Math.abs(d[3]-b[3])<=r&&c===a.resolution)return f===e?u.NONE:u.RERENDER_ONLY;k.copy(a.extent,b);a.resolution=c;b=k.center(a.extent);a.renderLocalOrigin=aa.fromValues(b[0],b[1],0,`OV_${this._latestOriginId++}`);return u.EXTENT}setTileParameters(a){const b=a.renderData.overlay;if(0n&&(r=n-(a[2]-a[0]))}c.setScale(b,k.width(a)/ e,k.height(a)/f);c.setOffset(b,(r-d[0])/e,(a[1]-d[1])/f)}}_clearTileOverlayData(a,b){b.setScale(a,-1,-1);b.setOffset(a,-1,-1)}async reloadShaders(){ea.removeLoadedShaderModules();await this.renderer.reloadShaders();this.setDrawTexturesDirty();this.runTask(J.noBudget)}_dispatchAnimationUpdate(a){var b=K.Milliseconds(a-this._animationTimeLast);if(b>=this.surface.view._stage.renderer.animationTimestep||null!=this.view.state.forcedAnimationTime||this._drawTexturesDirty||this._drawTexturesAnimateDirty)b= K.Milliseconds(b/this.surface.view._stage.renderer.animationTimeDilation),b=new ba.UpdateParameters(this.view.state.camera,b,this.view.state.forcedAnimationTime),this.renderer.updateAnimation(b)&&(this._drawTexturesAnimateDirty=!0),this._animationTimeLast=a}setDrawTexturesDirty(){this.renderer.hasOverlays?(this._drawTexturesDirty=this._contentUpdated=!0,this.view._stage.renderView.requestRender()):this.setPlacementDirty()}_intersectGroundFromView(a,b,c,d){c=this.view.sceneIntersectionHelper.getCenterRayWithSubpixelOffset(a, ia,b,c);if(null==c)return!1;b=c.origin;c=B.add(D,c.origin,c.direction);this._groundIntersector.reset(b,c,a);this._groundIntersector.intersect([]);this.view.basemapTerrain.intersect(this._groundIntersector,null,b,c);return this._groundIntersector.results.min.getIntersectionPoint(d)}_findHorizonBasedPointOfInterest(a,b){var c=.5;c=this.view.renderCoordsHelper.getAltitude(a.eye);const d=this.view.pointsOfInterest.centerOnSurfaceFrequent;var e=F.clamp(d.estimatedSurfaceAltitude,a.aboveGround?-Infinity: c+1E-5,a.aboveGround?c-1E-5:Infinity);c=a.aboveGround;if("global"===this.view.viewingMode){var f=D;H.closestPointOnSilhouette(H.fromRadius(H.tmpSphere,C.getReferenceEllipsoid(this.view.spatialReference).radius+e),O.wrap(a.eye,a.viewForward),f);B.subtract(f,f,a.eye);e=E.cyclicalPI.normalize(U.angleAroundAxis(a.viewForward,f,a.viewRight))/a.fovY+.5;f=0>=e||1<=e?.5:.55;c=c?f*e:e+f*(1-e)}else e=M.fromValues(0,Math.tan(.5*Math.PI-Math.acos(-a.viewForward[2])),1,0),e=G.transformMat4(e,e,a.projectionMatrix)[1], e=F.clamp(.5+.5*e,0,1),c=1===e||0===e?.5:c?.55*e:1-.55*(1-e);return this._intersectGroundFromView(a,.5,c,b)?B.sqrDist(b,a.eye)=n&&(f=n,e[1]=0,this._spatialReference.isWebMercator&&(e[0]=0)));v=1;g&&(v=1/Math.max(.2,Math.cos(Math.abs(F.deg2rad(e[1])))),180k.width(d)?k.copy(h,d):Math.PI/2-Math.abs(r-Math.PI/2)<=.25*Math.PI?(h[0]=g[0]-A,h[1]=g[1]-f,h[2]=g[2]+A,h[3]=g[3]+f):(N.projectVectorToVector(a.eye,this._renderSR,D,this._spatialReference),T.subtract(w,e,D),a=-Math.atan2(w[1],w[0])+.125*Math.PI,0>a&&(a+=2*Math.PI),G.scale(w,ha[Math.floor(a/(.25*Math.PI))],2*f),w[0]*=v,w[2]*=v,G.add(h, g,w));this._isSpherical?(h[0]=this._longitudeCyclical.clamp(h[0]),h[2]=this._longitudeCyclical.clamp(h[2]),h[1]=Math.max(h[1],-n),h[3]=Math.min(h[3],n)):(a=k.intersection(g,d,ja),d=k.intersection(h,d,ka),k.contains(a,d)&&(h[2]=h[0],h[3]=h[1]));b=Math.abs(g[2]-g[0])/b;c.mapUnitsPerPixel=Math.max(c.mapUnitsPerPixel,b);c.pixelRatioAdjustment=c.mapUnitsPerPixel/b}_drawOverlays(a,b){if(this.renderer.hasOverlays){if(!this._drawTexturesDirty&&!this._drawTexturesAnimateDirty)return this.renderer;var c=this._drawTexturesDirty; this._drawTexturesDirty=this._drawTexturesAnimateDirty=!1;var d=this.renderer.computeValidity();this.renderer.releaseRenderTargets();this.renderer.drawOverlays(b);b=this.renderer.computeValidity();d!==b&&this.surface.updateTileOverlayParams(y.RenderRequestType.UPDATE);c?(this.surface.requestRender(a),a===y.RenderRequestType.UPDATE&&this.surface.requestUpdate()):this.surface.requestRender(y.RenderRequestType.BACKGROUND);return this.renderer}}_rectanglesOverlap(a,b){return null==a?!1:this._longitudeCyclical? (this._longitudeCyclical.contains(b[0],b[2],a[0])||this._longitudeCyclical.contains(b[0],b[2],a[2])||this._longitudeCyclical.contains(a[0],a[2],b[0]))&&!(a[1]>b[3]||a[3]a[1]&&b[3]= b[1]&&a.y<=b[3];const c=a.x;a=a.y;return c>b[0]&&cb[1]&&ab&&(d=b-a[2]);a[1]<-c?e=a[1]+c:a[3]>c&&(e=c-a[3]);k.offset(a,d,e)}get test(){}};m.__decorate([p.property()],l.OverlayManager.prototype,"_spatialReference",void 0);m.__decorate([p.property({readOnly:!0})],l.OverlayManager.prototype,"running",null);m.__decorate([p.property()],l.OverlayManager.prototype,"_placementDirty",void 0);m.__decorate([p.property()],l.OverlayManager.prototype, "_contentUpdated",void 0);m.__decorate([p.property()],l.OverlayManager.prototype,"_isSpherical",null);m.__decorate([p.property()],l.OverlayManager.prototype,"_worldToPCSRatio",null);m.__decorate([p.property()],l.OverlayManager.prototype,"renderer",void 0);m.__decorate([p.property({constructOnly:!0})],l.OverlayManager.prototype,"view",void 0);m.__decorate([p.property({constructOnly:!0})],l.OverlayManager.prototype,"surface",void 0);m.__decorate([p.property()],l.OverlayManager.prototype,"suspended", null);m.__decorate([p.property()],l.OverlayManager.prototype,"updating",null);m.__decorate([p.property({type:Boolean})],l.OverlayManager.prototype,"rendersOccludedDraped",null);l.OverlayManager=m.__decorate([S.subclass("esri.views.3d.terrain.OverlayManager")],l.OverlayManager);class la{constructor(){this.inner=k.create();this.outer=k.create();this.mapUnitsPerPixel=0;this.pixelRatioAdjustment=1;this.stretch=1.3}}const w=M.create(),D=L.create(),t=new la,ja=k.create(),ka=k.create(),ia=O.create();var u; (function(a){a[a.NONE=0]="NONE";a[a.EXTENT=1]="EXTENT";a[a.RERENDER_ONLY=2]="RERENDER_ONLY"})(u||={});Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});