UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 4.37 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../../../chunks/tslib.es6.js";import{lerp as t}from"../../../core/mathUtils.js";import{disposeMaybe as s}from"../../../core/maybe.js";import{watch as r,syncAndInitial as i,sync as o}from"../../../core/reactiveUtils.js";import{secondsFromMilliseconds as a}from"../../../core/time.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import{getReferenceEllipsoid as m}from"../../../geometry/ellipsoidUtils.js";import{InternalRenderCategory as p}from"../webgl.js";import{PrecipitationPassParameters as d,PrecipitationTechnique as h}from"./PrecipitationTechnique.js";import{PrecipitationTechniqueConfiguration as l,PrecipitationType as f}from"./PrecipitationTechniqueConfiguration.js";import{glLayout as u}from"../support/buffer/glUtil.js";import{newLayout as _}from"../support/buffer/InterleavedLayout.js";import{TransparentEnvironment as b}from"../webgl-engine/effects/TransparentEnvironment.js";import{RenderRequestType as y}from"../webgl-engine/lib/basicInterfaces.js";import{VertexArrayObject as g}from"../webgl-engine/lib/VertexArrayObject.js";import{VertexAttribute as j}from"../webgl-engine/lib/VertexAttribute.js";import{BufferObject as w}from"../../webgl/BufferObject.js";import{PrimitiveType as P,Usage as A}from"../../webgl/enums.js";import{bindVertexBufferLayout as I,unbindVertexBufferLayout as v}from"../../webgl/Util.js";let T=class extends b{constructor(e){super(e),this._rainSpeed=.1,this._snowSpeed=.01,this._numParticles=0,this._passParameters=new d,this._configuration=new l;const{view:t,type:s}=e;this._configuration.type="rainy"===s?f.Rain:f.Snow,t.stage.renderView.techniques.precompile(h,this._configuration),this._passParameters.time=0,this._passParameters.radius=m(t.spatialReference).radius,this.addHandles([r((()=>t.environment.weather),(e=>{e.type===s&&this.addHandles(r((()=>e.precipitation),(e=>this._adjustParticles(e)),i))}),i)]),this.addHandles(r((()=>t.stage?.renderer.renderContext.bind.clouds.fadeFactor??1),(e=>{this._passParameters.opacity=e,1===e&&(this.removeHandles("opacity"),this.addHandles(r((()=>t.stage?.renderer.renderContext.bind.clouds.opacity??1),(e=>this._passParameters.opacity=e),i),"opacity"))}),o),"opacity")}initialize(){this.addHandles([r((()=>this.view.environment.atmosphereEnabled),(e=>e?this._enable():this._disable()),i)])}_adjustParticles(e){const s=.35,r=e<.5?t(0,s,2*e):t(s,1,2*(e-.5));this._numParticles=R*r}destroy(){this._numParticles=0,this._vao=s(this._vao),this._instanceIdBuffer=s(this._instanceIdBuffer)}fadeOut(e){this.removeAllHandles(),this.addHandles(r((()=>this.renderContext?.bind.clouds.fadeFactor??1),(t=>{this._passParameters.opacity=1-t,1===t&&(this.removeAllHandles(),e())})),"opacity")}updateAnimation(e){const t=("rainy"===this.type?this._rainSpeed:this._snowSpeed)*a(e.time)%1e5;return this._passParameters.time!==t&&(this._passParameters.time=t,!0)}render(e){const t=this.renderingContext;this._instanceIdBuffer??=this._createInstanceIndices(t);const s=Math.round(this._numParticles*this._passParameters.opacity),r=e.find((({name:e})=>e===p.TRANSPARENT_ENVIRONMENT));if(s<1)return r;const i=this.techniques.get(h,this._configuration);if(!i.compiled)return this.requestRender(y.UPDATE),r;const o=t.bindTechnique(i,this.bindParameters,this._passParameters);return this._vao??=S(t,i.locations),t.bindVAO(this._vao),o.assertCompatibleVertexAttributeLocations(this._vao),I(t,i.locations,this._instanceIdBuffer,E,0),t.drawArraysInstanced(P.TRIANGLES,0,3,s),v(t,i.locations,this._instanceIdBuffer,E),r}_createInstanceIndices(e){const t=[];for(let s=0;s<R;s++)t.push(s);return w.createVertex(e,A.STATIC_DRAW,new Float32Array(t))}};function S(e,t){const s=new Float32Array([-1,0,1,1,0,-1,1,0,1]);return new g(e,t,new Map([["geometry",u(x)]]),new Map([["geometry",w.createVertex(e,A.STATIC_DRAW,s)]]))}e([n({constructOnly:!0})],T.prototype,"type",void 0),T=e([c("esri.views.3d.environment.Precipitation")],T);const R=25e4,x=_().vec3f(j.POSITION),E=u(_().f32(j.INSTANCEFEATUREATTRIBUTE),1);export{T as Precipitation};