UNPKG

@arcgis/core

Version:

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

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