diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-19 14:58:49 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-19 14:58:58 +0300 |
commit | 5063820c9b7fdc499c0aa16ca850541101ffda09 (patch) | |
tree | 45541e8148069cabdadfd9ac4dc00558498e73c0 /source/blender/simulation/intern/simulation_solver.hh | |
parent | 8c90910dcc3ac56ecaa3f0d0ed1a43a423ff687f (diff) |
Particles: Emit particles over time
This adds a basic internal emitter for every particle simulation.
The emitter cannot be controlled by the user yet. That will
come next.
Diffstat (limited to 'source/blender/simulation/intern/simulation_solver.hh')
-rw-r--r-- | source/blender/simulation/intern/simulation_solver.hh | 118 |
1 files changed, 116 insertions, 2 deletions
diff --git a/source/blender/simulation/intern/simulation_solver.hh b/source/blender/simulation/intern/simulation_solver.hh index 818bcf067a3..5a45a676ec7 100644 --- a/source/blender/simulation/intern/simulation_solver.hh +++ b/source/blender/simulation/intern/simulation_solver.hh @@ -24,19 +24,133 @@ #include "FN_attributes_ref.hh" +#include "particle_allocator.hh" +#include "time_interval.hh" + struct Depsgraph; namespace blender::sim { +class ParticleEmitterContext; +class ParticleForceContext; + +class ParticleEmitter { + public: + virtual ~ParticleEmitter(); + virtual void emit(ParticleEmitterContext &context) const = 0; +}; + class ParticleForce { public: virtual ~ParticleForce(); - virtual void add_force(fn::AttributesRef attributes, - MutableSpan<float3> r_combined_force) const = 0; + virtual void add_force(ParticleForceContext &context) const = 0; }; struct SimulationInfluences { Map<std::string, Vector<const ParticleForce *>> particle_forces; + Vector<const ParticleEmitter *> particle_emitters; +}; + +class SimulationSolveContext { + private: + Simulation &simulation_; + Depsgraph &depsgraph_; + const SimulationInfluences &influences_; + + public: + SimulationSolveContext(Simulation &simulation, + Depsgraph &depsgraph, + const SimulationInfluences &influences) + : simulation_(simulation), depsgraph_(depsgraph), influences_(influences) + { + } +}; + +class ParticleChunkContext { + private: + IndexMask index_mask_; + fn::MutableAttributesRef attributes_; + + public: + ParticleChunkContext(IndexMask index_mask, fn::MutableAttributesRef attributes) + : index_mask_(index_mask), attributes_(attributes) + { + } + + IndexMask index_mask() const + { + return index_mask_; + } + + fn::MutableAttributesRef attributes() + { + return attributes_; + } + + fn::AttributesRef attributes() const + { + return attributes_; + } +}; + +class ParticleEmitterContext { + private: + SimulationSolveContext &solve_context_; + Map<std::string, std::unique_ptr<ParticleAllocator>> &particle_allocators_; + TimeInterval simulation_time_interval_; + + public: + ParticleEmitterContext(SimulationSolveContext &solve_context, + Map<std::string, std::unique_ptr<ParticleAllocator>> &particle_allocators, + TimeInterval simulation_time_interval) + : solve_context_(solve_context), + particle_allocators_(particle_allocators), + simulation_time_interval_(simulation_time_interval) + { + } + + ParticleAllocator *try_get_particle_allocator(StringRef particle_simulation_name) + { + auto *ptr = particle_allocators_.lookup_ptr_as(particle_simulation_name); + if (ptr != nullptr) { + return ptr->get(); + } + else { + return nullptr; + } + } + + TimeInterval simulation_time_interval() const + { + return simulation_time_interval_; + } +}; + +class ParticleForceContext { + private: + SimulationSolveContext &solve_context_; + const ParticleChunkContext &particle_chunk_context_; + MutableSpan<float3> force_dst_; + + public: + ParticleForceContext(SimulationSolveContext &solve_context, + const ParticleChunkContext &particle_chunk_context, + MutableSpan<float3> force_dst) + : solve_context_(solve_context), + particle_chunk_context_(particle_chunk_context), + force_dst_(force_dst) + { + } + + const ParticleChunkContext &particle_chunk() const + { + return particle_chunk_context_; + } + + MutableSpan<float3> force_dst() + { + return force_dst_; + } }; void initialize_simulation_states(Simulation &simulation, |