// 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/has ../../../core/mathUtils ../../../core/maybe ../../../core/reactiveUtils ../../../core/accessorSupport/decorators/property ../../../core/Logger ../../../core/RandomLCG ../../../core/accessorSupport/decorators/subclass ../../../chunks/vec32 ../../../core/libs/gl-matrix-2/factories/vec3f64 ../../../geometry/ellipsoidUtils ../../../geometry/support/spatialReferenceUtils ../../ViewingMode ./AtmosphereType ./ChapmanAtmosphere ./CloudsComposition ./CloudsData ./CloudsGenerator ./CloudsParameters ./CloudsPresets ./Fog ./LocalAtmosphere ./MarsAtmosphere ./Precipitation ./Stars ./weather ../webgl-engine/effects/RenderPlugin ../webgl-engine/lib/RenderSlot ../webgl-engine/lib/Update".split(" "), function(d,e,O,m,f,h,g,P,Q,B,n,w,x,u,C,k,D,E,y,F,p,G,z,H,I,J,K,L,v,q,M){d.EnvironmentRenderer=class extends v.SyncRenderPlugin{constructor(a){super(a);this.produces=new Map([[q.RenderSlot.OPAQUE_ENVIRONMENT,()=>!(null===this._atmosphere&&null===this._stars)],[q.RenderSlot.TRANSPARENT_ENVIRONMENT,()=>null!==this._atmosphere]]);this._atmosphere=this._context=null;this._oldWeatherParameters=new r;this._newWeatherParameters=new r;this._fadedWeatherParameters=new r;this._weatherParameters=this._newWeatherParameters}initialize(){this.view._stage.addRenderPlugin(this)}destroy(){this.removeHandles(); this.uninitializeRenderContext();null!=this.view?._stage&&this.view._stage.removeRenderPlugin(this);this._set("view",null)}get atmosphere(){return this._atmosphere}get _atmosphereType(){return null!=this.atmosphere?this.atmosphere.type:k.AtmosphereType.None}consumes(){return this._atmosphereType===k.AtmosphereType.Realistic?v.ConsumesDepth:v.ConsumesNone}updateAnimation(a){return null!=this._precipitation?this._precipitation.update(a):!1}get updating(){return null!=this._stars&&this._stars.updating|| null!=this._clouds&&this._clouds.running}get weatherVisible(){return n.length(this.view.state.camera.eye)-x.getReferenceEllipsoid(this.view.spatialReference).radius<=L.weatherHeightLimit}get usedMemory(){return this._clouds?.usedMemory??0}get _stars(){const a=this.view,b=a.environment?.starsEnabled??!1,c=this._get("_stars");return b&&null!=this._context?null!=c?c:new K.Stars({view:a,requestRender:()=>this._setNeedsRender()}):(f.destroyMaybe(c),null)}get _precipitation(){const a=this._get("_precipitation"); if(!this._precipitationEnabled||null==this._context)return f.destroyMaybe(a),null;const b=this.view,c=this._context;if(null!=a&&a.context===c)return a;f.destroyMaybe(a);return new J.Precipitation({context:c,view:b})}get _clouds(){const a=this._get("_clouds");if(!this.weatherEnabled||null==this._context)return f.destroyMaybe(a),null;if(null!=a)return a;const b=this.view,c=this._context;f.destroyMaybe(a);return new F.CloudsGenerator({context:c,view:b,requestRender:()=>this._setNeedsRender()})}get _cloudsComposition(){const a= this._get("_cloudsComposition");if(!this.weatherEnabled||null==this._context)return f.destroyMaybe(a),null;const b=this.view.state.viewingMode,c=this._context.renderContext.rctx,t=x.getReferenceEllipsoid(this.view.spatialReference).radius;if(null!=a&&a.viewingMode===b&&a.planetRadius===t)return a;f.destroyMaybe(a);return new E.CloudsComposition({rctx:c,viewingMode:b,planetRadius:t,requestRender:()=>this._setNeedsRender()})}get _fog(){const a=this._get("_fog");return this.weatherEnabled&&null!=this._context? null!=a?a:new z.Fog({context:this._context,view:this.view,rctx:this._context.renderContext.rctx,viewingMode:this.view.state.viewingMode}):(f.destroyMaybe(a),null)}get weatherEnabled(){return!!this.view?.environmentManager?.weatherEnabled}get _precipitationEnabled(){return this.weatherEnabled&&("rainy"===this.view.environment.weather.type||"snowy"===this.view.environment.weather.type)}initializeRenderContext(a=null){this._context=a;a=()=>this._setNeedsRender();this.addHandles([h.watch(()=>({viewingMode:this.view.state.viewingMode, enabled:this.view.environment.atmosphereEnabled}),b=>this._updateAtmosphere(b),h.syncAndInitial),h.watch(()=>this._stars,a),h.watch(()=>this._precipitation,a),h.watch(()=>this._clouds,()=>this._updateWeather(),h.initial),h.watch(()=>this._fog,()=>this._updateFogHaze(),h.initial),h.watch(()=>this.view.state.mode,()=>this._setNeedsRender(),h.sync),h.watch(()=>this._weatherUpdateParameters,()=>{this._updateWeather();this._updateFogHaze()},h.syncAndInitial)])}uninitializeRenderContext(){this._context= null;this._atmosphere=f.destroyMaybe(this._atmosphere);this._set("_stars",f.destroyMaybe(this._stars));this._set("_precipitation",f.destroyMaybe(this._precipitation));this._set("_clouds",f.destroyMaybe(this._clouds));this._set("_cloudsComposition",f.destroyMaybe(this._cloudsComposition));this._set("_fog",f.destroyMaybe(this._fog))}prepareRender(a){a.bindParameters.cloudsFade.data=y.isReadyCloudsData(this._clouds)?this._clouds:null;"local"!==this.view.viewingMode&&null!=a.bindParameters.cloudsFade.data?.cubeMap&& (this._updateWeatherFading(a.bindParameters,a.time),a.bindParameters.cloudsFade.renderingStage===y.CloudsRenderingStages.FINISHED&&null!=this._clouds&&0===this._clouds.coverage&&!1===this._clouds.running&&(this._clouds.destroyFrameBufferCube(),a.bindParameters.cloudsFade.data=null))}renderNode(a){switch(a.bindParameters.slot){case q.RenderSlot.OPAQUE_ENVIRONMENT:this._stars?.render(a);null!=this.atmosphere&&(this.atmosphere.render(a,this.view?._stage?.renderer?.fullResolutionAtmosphere),this._cloudsComposition&& null!=a.bindParameters.cloudsFade.data&&(this.weatherVisible&&null!=this._clouds&&this._clouds.updateWeatherTile(),this._cloudsComposition.render(a)),a.bindParameters.cloudsFade.isFading&&this._context&&null!=a.bindParameters.cloudsFade.data?.cubeMap&&this._context.requestRender());break;case q.RenderSlot.TRANSPARENT_ENVIRONMENT:if(null!=this.atmosphere&&(this.atmosphere.renderHaze(a,this._weatherParameters.hazeAmount,this.view?._stage?.renderer?.fullResolutionAtmosphere),0