UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 4.2 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import{lerp as i}from"../../../core/mathUtils.js";import{releaseMaybe as r,disposeMaybe as s,isNone as n,isSome as o}from"../../../core/maybe.js";import{secondsFromMilliseconds as a}from"../../../core/time.js";import{property as c}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as h}from"../../../core/accessorSupport/decorators/subclass.js";import{WatchUpdatingTracking as u}from"../../../core/support/WatchUpdatingTracking.js";import{getReferenceEllipsoid as p}from"../../../geometry/ellipsoidUtils.js";import{PrecipitationPassParameters as m,PrecipitationTechnique as d,attributeLocations as _}from"./PrecipitationTechnique.js";import{PrecipitationTechniqueConfiguration as f,PrecipitationType as l}from"./PrecipitationTechniqueConfiguration.js";import{glLayout as T}from"../support/buffer/glUtil.js";import{newLayout as y}from"../support/buffer/InterleavedLayout.js";import{AnimationTimer as g}from"../webgl-engine/lib/AnimationTimer.js";import{VertexArrayObject as w}from"../webgl-engine/lib/VertexArrayObject.js";import{VertexAttribute as b}from"../webgl-engine/lib/VertexAttribute.js";import{BufferObject as j}from"../../webgl/BufferObject.js";import{PrimitiveType as q,Usage as I}from"../../webgl/enums.js";import{bindVertexBufferLayout as A,unbindVertexBufferLayout as v}from"../../webgl/Util.js";let P=class extends t{constructor(e){super(e),this._numParticles=25e4,this._rainSpeed=.1,this._snowSpeed=.01,this._passParameters=new m,this._animation=new g,this._updatingTracking=new u,this._passParameters.time=0,this._passParameters.radius=p(e.view.spatialReference).radius,this._techniqueRepository=e.context.techniqueRepository}destroy(){this._updatingTracking.destroy(),this._numParticles=0,this._snowTechniqueCached=r(this._snowTechniqueCached),this._rainTechniqueCached=r(this._rainTechniqueCached),this._vao=s(this._vao),this._instanceIdBuffer=s(this._instanceIdBuffer)}get updating(){return this._updatingTracking.updating}get _rainTechnique(){if(n(this._rainTechniqueCached)){const e=new f;e.type=l.Rain,this._rainTechniqueCached=this._techniqueRepository.acquire(d,e)}return this._rainTechniqueCached}get _snowTechnique(){if(n(this._snowTechniqueCached)){const e=new f;e.type=l.Snow,this._snowTechniqueCached=this._techniqueRepository.acquire(d,e)}return this._snowTechniqueCached}update(e){return this._animation.advance(e)}render(e,t,r){const s="rainy"===r?this._rainTechnique:this._snowTechnique;if(!s.compiled)return void this.context.requestRender();const c=e.rctx;if(this._ensureResources(c),n(s)||n(this._vao)||n(this._instanceIdBuffer))return;if(o(e.bindParameters.cloudsFade.data)&&(this._passParameters.opacity=1-e.bindParameters.cloudsFade.fadeInOutHeight.factor),this._passParameters.opacity<=0)return;const h=.35;t=t<.5?i(0,h,2*t):i(h,1,2*(t-.5)),this._passParameters.time=("rainy"===r?this._rainSpeed:this._snowSpeed)*a(this._animation.time)%1e5;const u=c.bindTechnique(s,this._passParameters,e.bindParameters);c.bindVAO(this._vao),u.assertCompatibleVertexAttributeLocations(this._vao),A(c,_,this._instanceIdBuffer,R,0),c.capabilities.instancing?.drawArraysInstanced(q.TRIANGLES,0,3,this._numParticles*t),v(c,_,this._instanceIdBuffer,R)}_ensureResources(e){n(this._vao)&&(this._vao=this._createVertexArrayObject(e)),n(this._instanceIdBuffer)&&(this._instanceIdBuffer=this._createInstanceIndices(e))}_createInstanceIndices(e){const t=[];for(let i=0;i<this._numParticles;i++)t.push(i);return j.createVertex(e,I.STATIC_DRAW,new Float32Array(t))}_createVertexArrayObject(e){const t=new Float32Array([-1,0,1,1,0,-1,1,0,1]);return new w(e,_,{geometry:T(C)},{geometry:j.createVertex(e,I.STATIC_DRAW,t)})}};e([c({constructOnly:!0})],P.prototype,"context",void 0),e([c({constructOnly:!0})],P.prototype,"view",void 0),e([c({readOnly:!0})],P.prototype,"updating",null),e([c()],P.prototype,"_updatingTracking",void 0),P=e([h("esri.views.3d.environment.Precipitation")],P);const C=y().vec3f(b.POSITION),R=T(y().f32(b.INSTANCEFEATUREATTRIBUTE),1);export{P as Precipitation};