From f67431d7293ad570e539051ecb90276ec16e093e Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 5 Jul 2019 16:56:40 +0200 Subject: use gravity node in simulation --- source/blender/simulations/bparticles/forces.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'source/blender/simulations/bparticles/forces.cpp') diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp index ea5fc83a79b..4b3215720eb 100644 --- a/source/blender/simulations/bparticles/forces.cpp +++ b/source/blender/simulations/bparticles/forces.cpp @@ -8,19 +8,31 @@ Force::~Force() { } -class DirectionalForce : public Force { +class GravityForce : public Force { private: - float3 m_force; + SharedFunction m_compute_acceleration_fn; + TupleCallBody *m_compute_acceleration_body; public: - DirectionalForce(float3 force) : m_force(force) + GravityForce(SharedFunction &compute_acceleration_fn) + : m_compute_acceleration_fn(compute_acceleration_fn) { + m_compute_acceleration_body = m_compute_acceleration_fn->body(); } void add_force(ParticlesBlock &block, ArrayRef r_force) override { + FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_acceleration_body, fn_in, fn_out); + + FN::ExecutionStack stack; + FN::ExecutionContext execution_context(stack); + + m_compute_acceleration_body->call(fn_in, fn_out, execution_context); + + float3 acceleration = fn_out.get(0); + for (uint i = 0; i < block.active_amount(); i++) { - r_force[i] += m_force; + r_force[i] += acceleration; } }; }; @@ -46,9 +58,9 @@ class TurbulenceForce : public BParticles::Force { } }; -Force *FORCE_directional(float3 force) +Force *FORCE_gravity(SharedFunction &compute_acceleration_fn) { - return new DirectionalForce(force); + return new GravityForce(compute_acceleration_fn); } Force *FORCE_turbulence(float strength) -- cgit v1.2.3