/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{throwIfAborted as t}from"../../../../../core/promiseUtils.js";import{deserializeFlowPaths as s}from"../flowPathsIO.js";import{areStreamlinesCompatible as a,getFlowFloatUniforms as e,getFlowColorUniforms as i}from"../utils.js";import{AFlowResources as r}from"./AFlowResources.js";import{Mesh as o}from"../../webgl/meshing/Mesh.js";import{FlowParticlesShader as p}from"../../webgl/shaderGraph/techniques/shaders/flow/FlowParticlesShader.js";import{getPositions as n}from"../../../../support/flow/utils.js";import{PrimitiveType as m,DataType as h}from"../../../../webgl/enums.js";import{VertexElementDescriptor as l}from"../../../../webgl/VertexElementDescriptor.js";class d{constructor(t){this._params=t,this.supportsContinuation=!1,this.slideoutDuration=0}get animated(){return this._params.flowSpeed>0}isCompatible(t){return t instanceof d&&a(this._params,t._params)}updateResource(t){t.update(this._params)}async load(a,e,i){const{extent:r,size:o}=a;t(i);const p=await this._params.loadImagery(r,o[0],o[1],this._params.timeExtent,i),m={...p,data:p.data.slice(),mask:p.mask?.slice()},h=e&&this._params.simulationSettings.continuous?n(e.flowPaths,e.query,a,this._params.flowSpeed):[],{vertexData:l,indexData:d,pathData:c}=await this._params.createFlowMesh("Particles",this._params.simulationSettings,p,{positions:h},i),_=s(c);return new u(l,d,a,_,m,this._params)}}const c=[new l("xyts0",4,h.FLOAT,0,64),new l("xyts1",4,h.FLOAT,16,64),new l("typeIdFirstTimeLastTime",4,h.FLOAT,32,64),new l("extrudeInfo",4,h.FLOAT,48,64)];class u extends r{static{this._shader=new p}constructor(t,s,a,e,i,r){super(a,e,i),this._vertexData=t,this._indexData=s,this._params=r,this.kind="particles",this.update(r)}attach(t){const{context:s}=t;this.mesh=new o(s,{vertex:{geometry:{data:this._vertexData,layout:c}},index:{indices:{data:this._indexData}},groups:[{index:"indices",primitive:m.TRIANGLES}],parts:[{group:0,start:0,count:this._indexData.length}]}),this._vertexData=null,this._indexData=null}detach(){this.mesh.destroy()}get ready(){return!0}update(t){this._params=t,this._values={color:this._params.color,opacity:this._params.opacity,size:this._params.size}}getProgramSpec(t){return{shader:u._shader,uniforms:{state:{time:t.time,dvsMat3:t.dvsMat3,displayViewMat3:t.displayViewMat3,displayOpacity:t.displayOpacity,startTime:t.startTime,endTime:t.endTime},config:{trailLength:this._params.trailLength,flowSpeed:this._params.flowSpeed,featheringSize:this._params.featheringSize,featheringOffset:this._params.featheringOffset,introFade:this._params.introFade?1:0,fadeToZero:this._params.fadeToZero?1:0,decayRate:this._params.decayRate},color:i(this._values.color),opacity:e(this._values.opacity),size:e(this._values.size)},textures:{},defines:{vvColor:"ramp"===this._values.color.kind,vvOpacity:"ramp"===this._values.opacity.kind,vvSize:"ramp"===this._values.size.kind},optionalAttributes:null}}}export{d as Particles,u as ParticlesResources};
