diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-07-18 18:34:40 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-07-18 18:34:40 +0300 |
commit | 9a965af52918ef3a19baa1bc282b9243222e651f (patch) | |
tree | 6b91a00904b850d0a26075ace6772e186fcb039d /source/blender/simulations/bparticles | |
parent | 49d2d8b47ec63e4d1e437ef84cdb5d45f571b547 (diff) |
move offset handlers to separate file
Diffstat (limited to 'source/blender/simulations/bparticles')
5 files changed, 61 insertions, 48 deletions
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp index 1d859a3adc4..28d00e9355d 100644 --- a/source/blender/simulations/bparticles/forces.cpp +++ b/source/blender/simulations/bparticles/forces.cpp @@ -44,38 +44,4 @@ void TurbulenceForce::add_force(ParticlesBlock &block, ArrayRef<float3> r_force) } } -void CreateTrailHandler::execute(OffsetHandlerInterface &interface) -{ - if (m_rate <= 0.0f) { - return; - } - - ParticleSet particles = interface.particles(); - auto positions = particles.attributes().get_float3("Position"); - auto position_offsets = interface.offsets().get_float3("Position"); - - float frequency = 1.0f / m_rate; - - SmallVector<float3> new_positions; - SmallVector<float> new_birth_times; - for (uint pindex : particles.pindices()) { - float time_factor = interface.time_factors()[pindex]; - TimeSpan time_span = interface.time_span(pindex); - float current_time = frequency * (std::floor(time_span.start() / frequency) + 1.0f); - - float3 total_offset = position_offsets[pindex] * time_factor; - while (current_time < time_span.end()) { - float factor = time_span.get_factor_safe(current_time); - new_positions.append(positions[pindex] + total_offset * factor); - new_birth_times.append(current_time); - current_time += frequency; - } - } - - auto new_particles = interface.particle_allocator().request(m_particle_type_name, - new_positions.size()); - new_particles.set_float3("Position", new_positions); - new_particles.set_float("Birth Time", new_birth_times); -} - } // namespace BParticles diff --git a/source/blender/simulations/bparticles/forces.hpp b/source/blender/simulations/bparticles/forces.hpp index 6ad7cbbbe2a..fe44ea9cc1a 100644 --- a/source/blender/simulations/bparticles/forces.hpp +++ b/source/blender/simulations/bparticles/forces.hpp @@ -40,18 +40,4 @@ class TurbulenceForce : public Force { void add_force(ParticlesBlock &block, ArrayRef<float3> r_force) override; }; -class CreateTrailHandler : public OffsetHandler { - private: - std::string m_particle_type_name; - float m_rate; - - public: - CreateTrailHandler(StringRef particle_type_name, float rate) - : m_particle_type_name(particle_type_name.to_std_string()), m_rate(rate) - { - } - - void execute(OffsetHandlerInterface &interface) override; -}; - } // namespace BParticles diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp index 239e6d86741..494351fd100 100644 --- a/source/blender/simulations/bparticles/inserters.cpp +++ b/source/blender/simulations/bparticles/inserters.cpp @@ -14,6 +14,7 @@ #include "events.hpp" #include "forces.hpp" #include "integrator.hpp" +#include "offset_handlers.hpp" namespace BParticles { diff --git a/source/blender/simulations/bparticles/offset_handlers.cpp b/source/blender/simulations/bparticles/offset_handlers.cpp new file mode 100644 index 00000000000..2997eb18a7d --- /dev/null +++ b/source/blender/simulations/bparticles/offset_handlers.cpp @@ -0,0 +1,39 @@ +#include "offset_handlers.hpp" + +namespace BParticles { + +void CreateTrailHandler::execute(OffsetHandlerInterface &interface) +{ + if (m_rate <= 0.0f) { + return; + } + + ParticleSet particles = interface.particles(); + auto positions = particles.attributes().get_float3("Position"); + auto position_offsets = interface.offsets().get_float3("Position"); + + float frequency = 1.0f / m_rate; + + SmallVector<float3> new_positions; + SmallVector<float> new_birth_times; + for (uint pindex : particles.pindices()) { + float time_factor = interface.time_factors()[pindex]; + TimeSpan time_span = interface.time_span(pindex); + float current_time = frequency * (std::floor(time_span.start() / frequency) + 1.0f); + + float3 total_offset = position_offsets[pindex] * time_factor; + while (current_time < time_span.end()) { + float factor = time_span.get_factor_safe(current_time); + new_positions.append(positions[pindex] + total_offset * factor); + new_birth_times.append(current_time); + current_time += frequency; + } + } + + auto new_particles = interface.particle_allocator().request(m_particle_type_name, + new_positions.size()); + new_particles.set_float3("Position", new_positions); + new_particles.set_float("Birth Time", new_birth_times); +} + +} // namespace BParticles diff --git a/source/blender/simulations/bparticles/offset_handlers.hpp b/source/blender/simulations/bparticles/offset_handlers.hpp new file mode 100644 index 00000000000..2ec28a65796 --- /dev/null +++ b/source/blender/simulations/bparticles/offset_handlers.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "step_description.hpp" + +namespace BParticles { + +class CreateTrailHandler : public OffsetHandler { + private: + std::string m_particle_type_name; + float m_rate; + + public: + CreateTrailHandler(StringRef particle_type_name, float rate) + : m_particle_type_name(particle_type_name.to_std_string()), m_rate(rate) + { + } + + void execute(OffsetHandlerInterface &interface) override; +}; + +} // namespace BParticles |