UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 13.4 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import"../../../core/has.js";import{lerp as s}from"../../../core/mathUtils.js";import{isSome as r,isNone as i,destroyMaybe as a}from"../../../core/maybe.js";import{when as o,syncAndInitial as n,watch as h,initial as p,sync as m}from"../../../core/reactiveUtils.js";import{property as d}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{l as _,c,h as u}from"../../../chunks/vec3.js";import{f as g}from"../../../chunks/vec3f64.js";import{getReferenceEllipsoid as w}from"../../../geometry/ellipsoidUtils.js";import{isMoon as f,isEarth as y}from"../../../geometry/support/spatialReferenceUtils.js";import{ViewingMode as v}from"../../ViewingMode.js";import{AtmosphereType as P}from"./AtmosphereType.js";import{ChapmanAtmosphere as b}from"./ChapmanAtmosphere.js";import{CloudsComposition as R}from"./CloudsComposition.js";import{FadeInStages as x,FadeInOutStages as A}from"./CloudsCompositionParameters.js";import{isReadyCloudsData as W,CloudsRenderingStages as z}from"./CloudsData.js";import{CloudsGenerator as N}from"./CloudsGenerator.js";import{cloudPresets as j}from"./CloudsPresets.js";import{Fog as E,FogParameters as C}from"./Fog.js";import{PanoramicAtmosphere as T}from"./PanoramicAtmosphere.js";import{Precipitation as O}from"./Precipitation.js";import F from"./SimpleAtmosphere.js";import{SimpleHaze as S,HazeParameters as q}from"./SimpleHaze.js";import{Stars as H}from"./Stars.js";import{weatherHeightLimit as I}from"./weather.js";import{updateWeatherFading as M,weatherFadingNeedsRender as L}from"./weatherUtils.js";import{ShaderOutput as U}from"../webgl-engine/core/shaderLibrary/ShaderOutput.js";import{RenderFeature as V}from"../webgl-engine/lib/RenderFeature.js";import{RenderSlot as k}from"../webgl-engine/lib/RenderSlot.js";import{Update as G}from"../webgl-engine/lib/Update.js";var B;const D=[k.POSTPROCESSING_ENVIRONMENT_OPAQUE,k.POSTPROCESSING_ENVIRONMENT_TRANSPARENT];let Q=B=class extends t{constructor(e){super(e),this._context=null,this._atmosphere=null,this._hqAtmosphere=null,this._oldWeatherParameters=new J,this._newWeatherParameters=new J,this._fadedWeatherParameters=new J,this._weatherParameters=this._newWeatherParameters}initialize(){this.view._stage.addRenderPlugin(D,this)}destroy(){this.removeHandles(),null!=this.view?._stage&&this.view._stage.removeRenderPlugin(this),this._set("view",null)}get atmosphere(){return r(this._hqAtmosphere)&&this.view._stage.renderer.isFeatureEnabled(V.RealisticAtmosphere)?this._hqAtmosphere:this._atmosphere}get _atmosphereType(){return r(this.atmosphere)?this.atmosphere.type:P.None}get canRender(){return!!this.view.basemapTerrain?.renderer.canRender||"global"!==this.view.viewingMode}get needsLinearDepth(){return this._atmosphereType===P.Realistic}updateAnimation(e){return!!r(this._precipitation)&&this._precipitation.update(e)}get updating(){return r(this._stars)&&this._stars.updating||r(this._clouds)&&this._clouds.running}get weatherVisible(){return _(this.view.state.camera.eye)-w(this.view.spatialReference).radius<=I}get _stars(){const e=this.view,t=e.environment?.starsEnabled??!1,s=this._get("_stars");return!t||i(this._context)?(a(s),null):r(s)?s:new H({view:e,requestRender:()=>this._setNeedsRender()})}get _precipitation(){const e=this._get("_precipitation");if(!this._precipitationEnabled||i(this._context))return a(e),null;const t=this.view,s=this._context;return r(e)&&e.context===s?e:(a(e),new O({context:s,view:t}))}get _clouds(){const e=this._get("_clouds");if(!this.weatherEnabled||i(this._context))return a(e),null;if(r(e))return e;const t=this.view,s=this._context;return a(e),new N({context:s,view:t,requestRender:()=>this._setNeedsRender()})}get _cloudsComposition(){const e=this._get("_cloudsComposition");if(!this.weatherEnabled||i(this._context))return a(e),null;const t=this.view.state.viewingMode,s=this._context.renderContext.rctx,o=w(this.view.spatialReference).radius;return r(e)&&e.viewingMode===t&&e.planetRadius===o?e:(a(e),new R({rctx:s,viewingMode:t,planetRadius:o,requestRender:()=>this._setNeedsRender()}))}get _fog(){const e=this._get("_fog");if(!this.weatherEnabled||i(this._context))return a(e),null;if(r(e))return e;const t=this.view,s=this._context;return new E({context:s,view:t})}get _simpleHaze(){const e=this._get("_simpleHaze");if(!this.weatherEnabled||i(this._context))return a(e),null;if(r(e))return e;const t=this.view,s=this._context;return new S({context:s,view:t})}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(e=null){this._context=e;const t=()=>this._setNeedsRender();this.addHandles([o((()=>this.view?.basemapTerrain),(()=>this._updateBasemapTerrain()),n),h((()=>({viewingMode:this.view.state.viewingMode,enabled:this.view.environment.atmosphereEnabled,quality:this.view.environment.atmosphere.quality})),(e=>this._updateAtmosphere(e)),n),h((()=>this._stars),t),h((()=>this._precipitation),t),h((()=>this._clouds),(()=>this._updateWeather()),p),h((()=>this._fog),(()=>this._updateFogHaze()),p),h((()=>this._simpleHaze),(()=>this._updateFogHaze()),p),h((()=>this.view.state.mode),(()=>{this._setNeedsRender()}),m),h((()=>this._atmosphereType),(()=>this._updateBasemapTerrain()),n),h((()=>this._weatherUpdateParameters),(()=>{this._updateWeather(),this._updateFogHaze()}),n)])}uninitializeRenderContext(){this._context=null,this._atmosphere=a(this._atmosphere),this._hqAtmosphere=a(this._hqAtmosphere),this._set("_stars",a(this._stars)),this._set("_precipitation",a(this._precipitation)),this._set("_clouds",a(this._clouds)),this._set("_cloudsComposition",a(this._cloudsComposition)),this._set("_fog",a(this._fog)),this._set("_simpleHaze",a(this._simpleHaze))}prepareRender(e){e.bindParameters.cloudsFade.data=W(this._clouds)?this._clouds:null,"local"!==this.view.viewingMode&&(M(e.bindParameters.cloudsFade,e.bindParameters.camera,this.view.state.mode,e.time,this.view.qualitySettings.fadeDuration),this._updateWeatherFading(e.bindParameters),e.bindParameters.cloudsFade.renderingStage===z.FINISHED&&r(this._clouds)&&0===this._clouds.coverage&&!1===this._clouds.running&&(this._clouds.destroyFrameBufferCube(),e.bindParameters.cloudsFade.data=null))}render(e){if(e.output===U.Color)switch(e.bindParameters.slot){case k.POSTPROCESSING_ENVIRONMENT_OPAQUE:r(this._stars)&&this._stars.render(e),r(this.atmosphere)&&(this.atmosphere.render(e),r(this._cloudsComposition)&&r(e.bindParameters.cloudsFade.data)&&(this.weatherVisible&&r(this._clouds)&&this._clouds.updateWeatherTile(),this._cloudsComposition.render(e)),L(e.bindParameters.cloudsFade)&&r(this._context)&&this._context.requestRender());break;case k.POSTPROCESSING_ENVIRONMENT_TRANSPARENT:if(r(this.atmosphere)&&(this.atmosphere.renderHaze(e,this._weatherParameters.haze.amount),this._weatherParameters.haze.amount>0&&this._atmosphereType!==P.Realistic&&r(this._simpleHaze)&&this._simpleHaze.render(e,this._weatherParameters.haze),this._weatherParameters.fog.amount>0&&r(this._fog)&&this._fog.render(e,this._weatherParameters.fog),r(this._precipitation))){const t=this.view.environment.weather;"rainy"!==t.type&&"snowy"!==t.type||this._precipitation.render(e,t.precipitation,t.type)}}}updateLightSources(e,t,s,i){if(r(this._context)){const r=this._context.renderContext;r.bindParameters.oldLighting.copyFrom(r.bindParameters.lighting),r.bindParameters.newLighting.noonFactor=t,r.bindParameters.newLighting.globalFactor=s,r.bindParameters.newLighting.set(e);i===G.Faded||r.bindParameters.weatherFading?r.bindParameters.fadeLighting(0):r.bindParameters.fadeLighting(1),this._context.requestRender()}}get _weatherUpdateParameters(){const e=this.weatherEnabled?this.view.environment.weather:null;return i(e)?null:"rainy"===e.type||"snowy"===e.type?{type:e.type,weatherAdjustment:e.cloudCover,effect:e.precipitation}:{type:e.type,weatherAdjustment:"foggy"===e.type?e.fogStrength:e.cloudCover}}_updateWeatherFading(e){if(!e.weatherFading)return;const t=e.cloudsFade;return t.fadeIn.stage===x.FADE_IN?(e.fadeLighting(t.fadeIn.factor),void this._fadeWeather(t.fadeIn.factor)):t.fadeInOut.stage===A.FADE_IN?(e.fadeLighting(t.fadeInOut.factor),void this._fadeWeather(t.fadeInOut.factor)):t.crossFade.enabled?(e.fadeLighting(t.crossFade.factor),void this._fadeWeather(t.crossFade.factor)):(e.fadeLighting(0),void this._fadeWeather(0))}_fadeWeather(e){const{_newWeatherParameters:t,_oldWeatherParameters:s}=this;e>=1?this._weatherParameters=t:(this._fadedWeatherParameters.lerp(s,t,e),this._weatherParameters=this._fadedWeatherParameters)}_updateWeather(){const e=this._weatherUpdateParameters;i(e)||i(this._clouds)||(this._clouds.applyPreset(j[e.type],e.weatherAdjustment),this._setNeedsRender())}_setNeedsRender(){r(this._context)&&this._context.requestRender()}_updateFogHaze(){const e=this._weatherUpdateParameters;if(i(this._fog)||i(this._simpleHaze)||i(e)||i(this._context))return;const t=this._context.renderContext.bindParameters;switch(this._oldWeatherParameters.copyFrom(this._weatherParameters),e.type){case"foggy":this._newWeatherParameters.fog.strength=s(3e-5,.005,e.weatherAdjustment**3),c(this._newWeatherParameters.fog.color,X),this._newWeatherParameters.fog.amount=1,this._newWeatherParameters.haze.strength=0,this._newWeatherParameters.haze.amount=this._atmosphereType===P.Realistic?1:0,this._setNeedsRender();break;case"rainy":this._newWeatherParameters.fog.strength=s(4e-6,2e-4,(e.effect??0)**3),c(this._newWeatherParameters.fog.color,K),this._newWeatherParameters.fog.amount=1,this._newWeatherParameters.haze.strength=0,this._newWeatherParameters.haze.amount=0,this._setNeedsRender();break;case"snowy":this._newWeatherParameters.fog.strength=s(4e-6,2e-4,(e.effect??0)**3),c(this._newWeatherParameters.fog.color,X),this._newWeatherParameters.fog.amount=1,this._newWeatherParameters.haze.strength=0,this._newWeatherParameters.haze.amount=this._atmosphereType===P.Realistic?1:0,this._setNeedsRender();break;default:this._newWeatherParameters.fog.strength=0,this._newWeatherParameters.fog.amount=0,this._newWeatherParameters.haze.strength=4e-6,this._newWeatherParameters.haze.amount=1,this._setNeedsRender()}t.weatherFading?this._fadeWeather(0):this._fadeWeather(1)}_updateAtmosphere(e){const t=this._selectAtmosphereType(e);if(r(this._atmosphere)?this._atmosphere.type===t:t===P.None)return;this._atmosphere=a(this._atmosphere),this._hqAtmosphere=a(this._hqAtmosphere);const s=this._getAtmosphereClass(t);s&&r(this._context)&&(this._atmosphere=new s(this.view,this._context),t===P.Simple&&(this._hqAtmosphere=new b(this.view,this._context))),this._setNeedsRender(),this._updateBasemapTerrain()}_getAtmosphereClass(e){switch(e){case P.Realistic:return b;case P.Panoramic:return T;case P.Simple:return F;default:case P.None:return null}}_selectAtmosphereType(e){const{enabled:t,quality:s,viewingMode:i}=e;return!t||f(this.view.spatialReference)?P.None:i===v.Local?P.Panoramic:r(this._context)&&"high"===s&&b.isSupported(this._context)&&y(this.view.spatialReference)?P.Realistic:P.Simple}_updateBasemapTerrain(){this.view.basemapTerrain&&(this.view.basemapTerrain.velvetOverground=this._atmosphereType===P.Simple)}get test(){return{atmosphere:this._atmosphere,clouds:this._clouds,selectAtmosphereType:()=>this._selectAtmosphereType({viewingMode:this.view.state.viewingMode,enabled:this.view.environment.atmosphereEnabled,quality:this.view.environment.atmosphere.quality}),stubGetAtmosphereClass:e=>{Y=B.prototype._getAtmosphereClass,B.prototype._getAtmosphereClass=e},restoreGetAtmosphereClass:()=>{B.prototype._getAtmosphereClass=Y}}}};e([d({constructOnly:!0})],Q.prototype,"view",void 0),e([d({readOnly:!0})],Q.prototype,"atmosphere",null),e([d({readOnly:!0})],Q.prototype,"_atmosphereType",null),e([d({type:Boolean,readOnly:!0})],Q.prototype,"updating",null),e([d({readOnly:!0})],Q.prototype,"weatherVisible",null),e([d()],Q.prototype,"_context",void 0),e([d()],Q.prototype,"_atmosphere",void 0),e([d()],Q.prototype,"_hqAtmosphere",void 0),e([d({readOnly:!0})],Q.prototype,"_stars",null),e([d({readOnly:!0})],Q.prototype,"_precipitation",null),e([d({readOnly:!0})],Q.prototype,"_clouds",null),e([d({readOnly:!0})],Q.prototype,"_cloudsComposition",null),e([d({readOnly:!0})],Q.prototype,"_fog",null),e([d({readOnly:!0})],Q.prototype,"_simpleHaze",null),e([d({readOnly:!0})],Q.prototype,"weatherEnabled",null),e([d({readOnly:!0})],Q.prototype,"_precipitationEnabled",null),e([d({readOnly:!0})],Q.prototype,"_weatherUpdateParameters",null),Q=B=e([l("esri.views.3d.environment.EnvironmentRenderer")],Q);class J{constructor(){this.fog=new C,this.haze=new q}copyFrom(e){this.fog.amount=e.fog.amount,this.haze.amount=e.haze.amount,this.fog.strength=e.fog.strength,this.haze.strength=e.haze.strength,c(this.fog.color,e.fog.color)}lerp(e,t,r){this.fog.amount=s(e.fog.amount,t.fog.amount,r),this.haze.amount=s(e.haze.amount,t.haze.amount,r),this.fog.strength=s(e.fog.strength,t.fog.strength,r),this.haze.strength=s(e.haze.strength,t.haze.strength,r),u(this.fog.color,e.fog.color,t.fog.color,r)}}const K=g(.5,.5,.5),X=g(1.5,1.5,1.5);let Y;export{Q as EnvironmentRenderer,J as WeatherParameters};