Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2019-07-18 18:34:40 +0300
committerJacques Lucke <mail@jlucke.com>2019-07-18 18:34:40 +0300
commit9a965af52918ef3a19baa1bc282b9243222e651f (patch)
tree6b91a00904b850d0a26075ace6772e186fcb039d /source
parent49d2d8b47ec63e4d1e437ef84cdb5d45f571b547 (diff)
move offset handlers to separate file
Diffstat (limited to 'source')
-rw-r--r--source/blender/simulations/CMakeLists.txt2
-rw-r--r--source/blender/simulations/bparticles/forces.cpp34
-rw-r--r--source/blender/simulations/bparticles/forces.hpp14
-rw-r--r--source/blender/simulations/bparticles/inserters.cpp1
-rw-r--r--source/blender/simulations/bparticles/offset_handlers.cpp39
-rw-r--r--source/blender/simulations/bparticles/offset_handlers.hpp21
6 files changed, 63 insertions, 48 deletions
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index cae36d8c2f6..44a431cce2b 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -50,6 +50,8 @@ set(SRC
bparticles/particles_state.cpp
bparticles/particle_allocator.hpp
bparticles/particle_allocator.cpp
+ bparticles/offset_handlers.hpp
+ bparticles/offset_handlers.cpp
)
set(LIB
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