diff options
author | Jacques Lucke <jacques@blender.org> | 2020-08-01 22:56:05 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-08-01 22:56:05 +0300 |
commit | 7cd2c1fd2e7a4c82dd5569cf0ee0155c3cca9101 (patch) | |
tree | 3480d391ee85aa4d2af02f2690b07764da08f228 /source/blender/simulation/intern/simulation_solver_influences.hh | |
parent | 6141549feefcdd33ba36cecf7fb97f0b360f3bb4 (diff) |
Particles: support custom particle events in solver
Previously, there were only particle-birth and time-step events.
Now the solver can handle custom events. On the user level
this does not change anything yet. This feature of the solver
will be used by an upcoming Age Reached Event node and
possibly others. When this node exists, I can finally remove
the hardcoded maximum particle age.
Diffstat (limited to 'source/blender/simulation/intern/simulation_solver_influences.hh')
-rw-r--r-- | source/blender/simulation/intern/simulation_solver_influences.hh | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/source/blender/simulation/intern/simulation_solver_influences.hh b/source/blender/simulation/intern/simulation_solver_influences.hh index d3c515bb6a0..f7b8affd88d 100644 --- a/source/blender/simulation/intern/simulation_solver_influences.hh +++ b/source/blender/simulation/intern/simulation_solver_influences.hh @@ -45,6 +45,7 @@ using fn::MutableAttributesRef; struct ParticleEmitterContext; struct ParticleForceContext; struct ParticleActionContext; +struct ParticleEventFilterContext; class ParticleEmitter { public: @@ -64,11 +65,19 @@ class ParticleAction { virtual void execute(ParticleActionContext &context) const = 0; }; +class ParticleEvent { + public: + virtual ~ParticleEvent(); + virtual void filter(ParticleEventFilterContext &context) const = 0; + virtual void execute(ParticleActionContext &context) const = 0; +}; + struct SimulationInfluences { MultiValueMap<std::string, const ParticleForce *> particle_forces; MultiValueMap<std::string, const ParticleAction *> particle_birth_actions; MultiValueMap<std::string, const ParticleAction *> particle_time_step_begin_actions; MultiValueMap<std::string, const ParticleAction *> particle_time_step_end_actions; + MultiValueMap<std::string, const ParticleEvent *> particle_events; Map<std::string, AttributesInfoBuilder *> particle_attributes_builder; Vector<const ParticleEmitter *> particle_emitters; }; @@ -157,9 +166,37 @@ class ParticleAllocators { } }; +struct ParticleChunkIntegrationContext { + MutableSpan<float3> position_diffs; + MutableSpan<float3> velocity_diffs; + MutableSpan<float> durations; + float end_time; +}; + struct ParticleChunkContext { + ParticleSimulationState &state; IndexMask index_mask; MutableAttributesRef attributes; + ParticleChunkIntegrationContext *integration = nullptr; + + void update_diffs_after_velocity_change() + { + if (integration == nullptr) { + return; + } + + Span<float> remaining_durations = integration->durations; + MutableSpan<float3> position_diffs = integration->position_diffs; + Span<float3> velocities = attributes.get<float3>("Velocity"); + + for (int i : index_mask) { + const float duration = remaining_durations[i]; + /* This is certainly not a perfect way to "re-integrate" the velocity, but it should be good + * enough for most use cases. Changing the velocity in an instant is not physically correct + * anyway. */ + position_diffs[i] = velocities[i] * duration; + } + } }; struct ParticleEmitterContext { @@ -189,6 +226,12 @@ struct ParticleActionContext { ParticleChunkContext &particles; }; +struct ParticleEventFilterContext { + SimulationSolveContext &solve_context; + ParticleChunkContext &particles; + MutableSpan<float> factor_dst; +}; + } // namespace blender::sim #endif /* __SIM_SIMULATION_SOLVER_INFLUENCES_HH__ */ |