diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-06-19 12:06:23 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-06-19 12:06:23 +0300 |
commit | 0a7715e30862345c8ed4eb681898a178b68bf4fb (patch) | |
tree | 074e58a0261557ae8f5da2f0d3450bb955091cc5 /source | |
parent | 3138c7c5d7912c4b90b13e78263886873e964826 (diff) |
move forces into separate file
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/simulations/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/simulations/bparticles/c_wrapper.cpp | 77 | ||||
-rw-r--r-- | source/blender/simulations/bparticles/emitters.cpp | 12 | ||||
-rw-r--r-- | source/blender/simulations/bparticles/emitters.hpp | 4 | ||||
-rw-r--r-- | source/blender/simulations/bparticles/forces.cpp | 60 | ||||
-rw-r--r-- | source/blender/simulations/bparticles/forces.hpp | 10 |
6 files changed, 88 insertions, 77 deletions
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt index 3ef9df3a6ba..08770db1712 100644 --- a/source/blender/simulations/CMakeLists.txt +++ b/source/blender/simulations/CMakeLists.txt @@ -23,6 +23,8 @@ set(SRC bparticles/playground_solver.cpp bparticles/emitters.hpp bparticles/emitters.cpp + bparticles/forces.hpp + bparticles/forces.cpp bparticles/attributes.hpp bparticles/attributes.cpp bparticles/c_wrapper.cpp diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp index 635e7d51c74..9009f2b05e2 100644 --- a/source/blender/simulations/bparticles/c_wrapper.cpp +++ b/source/blender/simulations/bparticles/c_wrapper.cpp @@ -3,7 +3,8 @@ #include "particles_container.hpp" #include "playground_solver.hpp" #include "emitters.hpp" -#include "BLI_noise.h" +#include "forces.hpp" + #include "BLI_timeit.hpp" #define WRAPPERS(T1, T2) \ @@ -36,81 +37,17 @@ WRAPPERS(BParticles::Description *, BParticlesDescription); WRAPPERS(BParticles::Solver *, BParticlesSolver); WRAPPERS(BParticles::WrappedState *, BParticlesState); -class TestForce : public BParticles::Force { - private: - float m_strength; - - public: - TestForce(float strength) : m_strength(strength) - { - } - - void add_force(AttributeArrays UNUSED(attributes), - ArrayRef<uint> indices_mask, - ArrayRef<float3> dst) override - { - for (uint i = 0; i < indices_mask.size(); i++) { - dst[i].z += m_strength; - } - }; -}; - -class TurbulenceForce : public BParticles::Force { - private: - float m_strength; - - public: - TurbulenceForce(float strength) : m_strength(strength) - { - } - - void add_force(AttributeArrays attributes, - ArrayRef<uint> indices_mask, - ArrayRef<float3> dst) override - { - auto positions = attributes.get_float3("Position"); - for (uint i = 0; i < indices_mask.size(); i++) { - uint pindex = indices_mask[i]; - - float3 pos = positions[pindex]; - float value = BLI_hnoise(0.5f, pos.x, pos.y, pos.z); - dst[i].z += value * m_strength; - } - } -}; - -class TestEmitter : public BParticles::Emitter { - public: - void info(EmitterInfoBuilder &builder) const override - { - builder.inits_attribute("Position", AttributeType::Float3); - builder.inits_attribute("Velocity", AttributeType::Float3); - } - - void emit(EmitterHelper helper) override - { - EmitterTarget &dst = helper.request_raw(); - - auto positions = dst.attributes().get_float3("Position"); - auto velocities = dst.attributes().get_float3("Velocity"); - - for (uint i = 0; i < dst.size(); i++) { - positions[i] = {(float)(rand() % 10000) / 3000.0f, 0, 1}; - velocities[i] = {0, 1, 1}; - } - dst.set_initialized(dst.size()); - } -}; - BParticlesDescription BParticles_playground_description(float control1, float control2, float *emitter_position, struct Mesh *mesh) { - auto emitter1 = BParticles::new_point_emitter(emitter_position); - auto emitter2 = BParticles::new_surface_emitter(mesh); + auto force = BParticles::FORCE_directional({0.0, 0.0, control1}); + + auto emitter1 = BParticles::EMITTER_point(emitter_position); + auto emitter2 = BParticles::EMITTER_mesh_surface(mesh, control2); - Description *description = new Description({new TestForce(control1)}, + Description *description = new Description({force.release()}, {emitter1.release(), emitter2.release()}); return wrap(description); } diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp index 27905ee27e3..6b7292ccbaf 100644 --- a/source/blender/simulations/bparticles/emitters.cpp +++ b/source/blender/simulations/bparticles/emitters.cpp @@ -36,9 +36,11 @@ class PointEmitter : public Emitter { class SurfaceEmitter : public Emitter { private: Mesh *m_mesh; + float m_normal_velocity; public: - SurfaceEmitter(Mesh *mesh) : m_mesh(mesh) + SurfaceEmitter(Mesh *mesh, float normal_velocity) + : m_mesh(mesh), m_normal_velocity(normal_velocity) { } @@ -70,7 +72,7 @@ class SurfaceEmitter : public Emitter { float3 pos = (v1 + v2 + v3) / 3.0f; positions.append(pos); - velocities.append(normal); + velocities.append(normal * m_normal_velocity); } auto target = helper.request(positions.size()); @@ -79,15 +81,15 @@ class SurfaceEmitter : public Emitter { } }; -std::unique_ptr<Emitter> new_point_emitter(float3 point) +std::unique_ptr<Emitter> EMITTER_point(float3 point) { Emitter *emitter = new PointEmitter(point); return std::unique_ptr<Emitter>(emitter); } -std::unique_ptr<Emitter> new_surface_emitter(Mesh *mesh) +std::unique_ptr<Emitter> EMITTER_mesh_surface(Mesh *mesh, float normal_velocity) { - Emitter *emitter = new SurfaceEmitter(mesh); + Emitter *emitter = new SurfaceEmitter(mesh, normal_velocity); return std::unique_ptr<Emitter>(emitter); } diff --git a/source/blender/simulations/bparticles/emitters.hpp b/source/blender/simulations/bparticles/emitters.hpp index b100b43d1e1..c991a2e6eb4 100644 --- a/source/blender/simulations/bparticles/emitters.hpp +++ b/source/blender/simulations/bparticles/emitters.hpp @@ -6,7 +6,7 @@ struct Mesh; namespace BParticles { -std::unique_ptr<Emitter> new_point_emitter(float3 point); -std::unique_ptr<Emitter> new_surface_emitter(struct Mesh *mesh); +std::unique_ptr<Emitter> EMITTER_point(float3 point); +std::unique_ptr<Emitter> EMITTER_mesh_surface(struct Mesh *mesh, float normal_velocity); } // namespace BParticles diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp new file mode 100644 index 00000000000..622d7f8ba3f --- /dev/null +++ b/source/blender/simulations/bparticles/forces.cpp @@ -0,0 +1,60 @@ +#include "BLI_noise.h" + +#include "forces.hpp" + +namespace BParticles { + +class DirectionalForce : public Force { + private: + float3 m_force; + + public: + DirectionalForce(float3 force) : m_force(force) + { + } + + void add_force(AttributeArrays UNUSED(attributes), + ArrayRef<uint> indices_mask, + ArrayRef<float3> dst) override + { + for (uint i = 0; i < indices_mask.size(); i++) { + dst[i] += m_force; + } + }; +}; + +class TurbulenceForce : public BParticles::Force { + private: + float m_strength; + + public: + TurbulenceForce(float strength) : m_strength(strength) + { + } + + void add_force(AttributeArrays attributes, + ArrayRef<uint> indices_mask, + ArrayRef<float3> dst) override + { + auto positions = attributes.get_float3("Position"); + for (uint i = 0; i < indices_mask.size(); i++) { + uint pindex = indices_mask[i]; + + float3 pos = positions[pindex]; + float value = BLI_hnoise(0.5f, pos.x, pos.y, pos.z); + dst[i].z += value * m_strength; + } + } +}; + +std::unique_ptr<Force> FORCE_directional(float3 force) +{ + return std::unique_ptr<Force>(new DirectionalForce(force)); +} + +std::unique_ptr<Force> FORCE_turbulence(float strength) +{ + return std::unique_ptr<Force>(new TurbulenceForce(strength)); +} + +} // namespace BParticles diff --git a/source/blender/simulations/bparticles/forces.hpp b/source/blender/simulations/bparticles/forces.hpp new file mode 100644 index 00000000000..53d014bd9b2 --- /dev/null +++ b/source/blender/simulations/bparticles/forces.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include "core.hpp" + +namespace BParticles { + +std::unique_ptr<Force> FORCE_directional(float3 force); +std::unique_ptr<Force> FORCE_turbulence(float strength); + +} // namespace BParticles |