@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 7.9 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../../core/Accessor.js";import{lerp as s}from"../../../core/mathUtils.js";import{destroyMaybe as i,disposeMaybe as r}from"../../../core/maybe.js";import{watch as o,initial as a}from"../../../core/reactiveUtils.js";import{signal as h}from"../../../core/signal.js";import{property as n,subclass as l}from"../../../core/accessorSupport/decorators.js";import{fromMat4 as c}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{targetTo as u}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{create as d}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{equals as p,copy as m,set as _}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{clone as f,ZEROS as g,zeros as x}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as y}from"../../../core/libs/gl-matrix-2/factories/vec3f32.js";import{zeros as b}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{getReferenceEllipsoid as T}from"../../../geometry/ellipsoidUtils.js";import{C as v,c as S}from"../../../chunks/Clouds.glsl.js";import{cloudPresets as w}from"./CloudsPresets.js";import{CloudsTechnique as C}from"./CloudsTechnique.js";import{CloudsTechniqueConfiguration as P}from"./CloudsTechniqueConfiguration.js";import{NoiseTextureAtlas as j}from"./NoiseTextureAtlas.js";import{TaskPriority as z}from"../../support/Scheduler.js";import{Yield as I}from"../../support/Yield.js";import{ColorAttachment0 as M}from"../../webgl/enums.js";import{FramebufferObject as H}from"../../webgl/FramebufferObject.js";import{TextureDescriptor as q}from"../../webgl/TextureDescriptor.js";let R=class extends e{constructor(t){super(t),this._state=h(0),this._passParameters=new v,this._weatherTileCount=128,this._sliceIndex=0,this._tileIndex=0,this._tilesPerSlice=1,this.coverage=s(w.default.coverage[0],w.default.coverage[1],.5),this.density=s(w.default.density[0],w.default.density[1],.5),this.absorption=s(w.default.absorption[0],w.default.absorption[1],.5),this.cloudSize=s(w.default.cloudSize[0],w.default.cloudSize[1],.5),this.detailSize=s(w.default.detailSize[0],w.default.detailSize[1],.5),this.smoothness=s(w.default.smoothness[0],w.default.smoothness[1],.5),this.cloudHeight=s(w.default.cloudHeight[0],w.default.cloudHeight[1],.5),this.raymarchingSteps=w.default.raymarchingSteps,this._viewMatrix=d(),this._dirty=!0,this.readyToRun=!0,this._configuration=new P}initialize(){const t=T(this.view.spatialReference);this._passParameters.cloudRadius=.5*t.radius;const e=()=>this.setDirty();this.addHandles([this.view.resourceController.scheduler.registerTask(z.CLOUDS_GENERATOR,this),o(()=>this.coverage,e,a),o(()=>this.density,e,a),o(()=>this.absorption,e,a),o(()=>this.cloudSize,e,a),o(()=>this.detailSize,e,a),o(()=>this.smoothness,e,a),o(()=>this.cloudHeight,e,a),o(()=>this.raymarchingSteps,e,a)]);const s=f(this._computeWeatherTile());let i=0;this.addHandles(o(()=>{const t=this._computeWeatherTile();return p(s,t)||(++i,m(s,t)),i},e))}destroy(){this.destroyCubeMap(),this._passParameters.noiseTexture=i(this._passParameters.noiseTexture)}_precompile(){this._configuration.steps=this.raymarchingSteps,this._configuration.writeTextureChannels=0,this.context.techniques.precompile(C,this._configuration),this._configuration.writeTextureChannels=1,this.context.techniques.precompile(C,this._configuration)}_acquireTechnique(){switch(this.raymarchingSteps){case 0:this._tilesPerSlice=1;break;case 1:this._tilesPerSlice=4;break;case 3:case 2:this._tilesPerSlice=8;break;default:this.raymarchingSteps}return this._configuration.writeTextureChannels=1-this.parameters.readChannels,this._configuration.steps=this.raymarchingSteps,this.context.techniques.get(C,this._configuration)}_computeWeatherTile(){const{camera:t,environment:e}=this.view,{latitude:s,longitude:i}=t.position;if(null==s||null==i)return g;_(D,(s+90)/180,(i+180)/360);const r=Math.floor(this._weatherTileCount*Math.abs(2*D[0]-1));D[0]=Math.floor(2*this._weatherTileCount*D[0]),D[1]=Math.floor(4*(this._weatherTileCount-r)*D[1]);let o=0,a=0;if("virtual"!==e?.lighting?.type&&null!=e?.lighting?.date){const t=new Date(e.lighting.date);t.setUTCHours(e.lighting.date.getUTCHours()+(e.lighting.displayUTCOffset??0)),o=31*t.getUTCMonth()+t.getUTCDate(),a=t.getUTCFullYear()}return D[0]=(D[0]+o)%(2*this._weatherTileCount),D[1]=(D[1]+a%100)%(4*this._weatherTileCount),D}get state(){return this._state.value}set state(t){this._state.value=t}get usedMemory(){return(this._fbo?.usedMemory??0)+(this._passParameters.noiseTexture?.textureAtlas?.usedMemory??0)}_ensureNoiseTexture(){return this._passParameters.noiseTexture??=new j({context:this.context}),this._passParameters.noiseTexture}_ensureFrameBufferCube(t){const e=this.context.renderContext.rctx;if(null==this._fbo){const s=new q(t,t/2);s.target=35866,s.depth=6,s.wrapMode=33071,this._fbo=new H(e,s),this.parameters.data=this,this.parameters.absorption=this.absorption,this.parameters.coverage=this.coverage}return e.unbindTexture(this._fbo.colorTexture),this._fbo}get cubeMap(){return this._fbo}get parameters(){return this.context.renderContext.bind.clouds}destroyCubeMap(){this._fbo=r(this._fbo),this.parameters.data=null}applyPreset(t,e){const i=t.median,r=t=>{const r=s(t[0],t[1],i);return e<.5?s(t[0],r,2*e):s(r,t[1],2*(e-.5))};this.coverage=r(t.coverage),this.density=r(t.density),this.absorption=r(t.absorption),this.cloudSize=r(t.cloudSize),this.detailSize=r(t.detailSize),this.smoothness=r(t.smoothness),this.cloudHeight=r(t.cloudHeight),this.raymarchingSteps=t.raymarchingSteps,this._precompile()}setDirty(){this._dirty=this.readyToRun=!0}runTask(t){if(3===this.state)return I;this._dirty&&(this._sliceIndex=this._tileIndex=0,this.state=1,this._passParameters.absorption=this.absorption,this._passParameters.density=this.density,this._passParameters.cloudSize=this.cloudSize,this._passParameters.detailSize=this.detailSize,this._passParameters.smoothness=this.smoothness,this._passParameters.cloudHeight=this.cloudHeight,this._passParameters.coverage=this.coverage,this._ensureNoiseTexture().updateWeatherMap(this._computeWeatherTile()),this._dirty=!1);const e=this._acquireTechnique();if(!this._ensureNoiseTexture().textureAtlas||!e.compiled)return I;const s=U[this._sliceIndex],i=O[this._sliceIndex];u(this._viewMatrix,k,s,i),c(this._passParameters.viewMatrix,this._viewMatrix);const r=this.context.renderContext.rctx,o=r.getViewport(),a=S/this._tilesPerSlice,h=this._tileIndex*a;r.setViewport(0,h,S,a);const n=this._ensureFrameBufferCube(S);r.bindFramebuffer(n),this._passParameters.lastSlice=5===this._sliceIndex,r.bindTechnique(e,this.context.renderContext.bind,this._passParameters);const l=35866;return n.setColorTextureTarget(l,M,this._sliceIndex),r.screen.draw(),r.gl.flush(),r.setViewport(o.x,o.y,o.width,o.height),this.requestRender(),++this._tileIndex,5===this._sliceIndex&&this._tileIndex===this._tilesPerSlice?(this._sliceIndex=this._tileIndex=0,this.state=2,this.readyToRun=!1):this._tileIndex===this._tilesPerSlice&&(++this._sliceIndex,this._tileIndex=0),t.madeProgress(),I}};t([n({constructOnly:!0})],R.prototype,"context",void 0),t([n({constructOnly:!0})],R.prototype,"view",void 0),t([n({constructOnly:!0})],R.prototype,"requestRender",void 0),t([n()],R.prototype,"coverage",void 0),t([n()],R.prototype,"density",void 0),t([n()],R.prototype,"absorption",void 0),t([n()],R.prototype,"cloudSize",void 0),t([n()],R.prototype,"detailSize",void 0),t([n()],R.prototype,"smoothness",void 0),t([n()],R.prototype,"cloudHeight",void 0),t([n()],R.prototype,"raymarchingSteps",void 0),t([n()],R.prototype,"readyToRun",void 0),R=t([l("esri.views.3d.environment.CloudsRenderer")],R);const U=[y(1,0,0),y(-1,0,0),y(0,1,0),y(0,-1,0),y(0,0,1),y(0,0,1)],O=[y(0,0,-1),y(0,0,-1),y(0,0,-1),y(0,0,-1),y(0,1,0),y(0,1,0)],k=b(),D=x();export{R as CloudsRenderer};