diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-09-11 17:05:51 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-09-11 17:05:51 +0300 |
commit | 23de6e69606d8ad3835a453b8ee4088f6aa52532 (patch) | |
tree | d8d03f675bab9eb9f79e2f29aa70918fc9c189b3 | |
parent | f0821153952c7f492081e3b6a08a6a9b6c49b02f (diff) |
new Falloff input for Turbulence Force
4 files changed, 22 insertions, 4 deletions
diff --git a/release/scripts/startup/nodes/bparticle_nodes/forces.py b/release/scripts/startup/nodes/bparticle_nodes/forces.py index 411ee283b5a..452fffb21dd 100644 --- a/release/scripts/startup/nodes/bparticle_nodes/forces.py +++ b/release/scripts/startup/nodes/bparticle_nodes/forces.py @@ -10,6 +10,7 @@ class TurbulenceForceNode(bpy.types.Node, BParticlesNode): def declaration(self, builder: NodeBuilder): builder.fixed_input("strength", "Strength", "Vector", default=(1, 1, 1)) + builder.fixed_input("falloff", "Falloff", "Falloff") builder.particle_effector_output("force", "Force") diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp index 99b9fd84041..5ee4ee6044c 100644 --- a/source/blender/simulations/bparticles/forces.cpp +++ b/source/blender/simulations/bparticles/forces.cpp @@ -31,13 +31,17 @@ void TurbulenceForce::add_force(ForceInterface &interface) auto inputs = m_compute_inputs->compute(interface); + TemporaryArray<float> weights(destination.size()); + m_falloff->compute(interface.attributes(), interface.pindices(), weights); + for (uint pindex : interface.pindices()) { float3 pos = positions[pindex]; float3 strength = inputs->get<float3>("Strength", 0, pindex); + float weight = weights[pindex]; float x = (BLI_gNoise(0.5f, pos.x, pos.y, pos.z + 1000.0f, false, 1) - 0.5f) * strength.x; float y = (BLI_gNoise(0.5f, pos.x, pos.y + 1000.0f, pos.z, false, 1) - 0.5f) * strength.y; float z = (BLI_gNoise(0.5f, pos.x + 1000.0f, pos.y, pos.z, false, 1) - 0.5f) * strength.z; - destination[pindex] += {x, y, z}; + destination[pindex] += float3(x, y, z) * weight; } } diff --git a/source/blender/simulations/bparticles/forces.hpp b/source/blender/simulations/bparticles/forces.hpp index 7fd1f077c61..7b41909edc8 100644 --- a/source/blender/simulations/bparticles/forces.hpp +++ b/source/blender/simulations/bparticles/forces.hpp @@ -39,10 +39,12 @@ class GravityForce : public Force { class TurbulenceForce : public Force { private: std::unique_ptr<ParticleFunction> m_compute_inputs; + std::unique_ptr<Falloff> m_falloff; public: - TurbulenceForce(std::unique_ptr<ParticleFunction> compute_inputs) - : m_compute_inputs(std::move(compute_inputs)) + TurbulenceForce(std::unique_ptr<ParticleFunction> compute_inputs, + std::unique_ptr<Falloff> falloff) + : m_compute_inputs(std::move(compute_inputs)), m_falloff(std::move(falloff)) { } diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp index 5d0b2602dc9..7d63658e089 100644 --- a/source/blender/simulations/bparticles/node_frontend.cpp +++ b/source/blender/simulations/bparticles/node_frontend.cpp @@ -494,6 +494,17 @@ static void PARSE_turbulence_force(BehaviorCollector &collector, WorldTransition &UNUSED(world_transition), VirtualNode *vnode) { + FunctionGraph fgraph( + vtree_data_graph.graph(), {}, {vtree_data_graph.lookup_socket(vnode->input(1, "Falloff"))}); + auto fn = fgraph.new_function("Compute Falloff"); + FN::fgraph_add_TupleCallBody(fn, fgraph); + FN::TupleCallBody &body = fn->body<TupleCallBody>(); + + FN_TUPLE_CALL_ALLOC_TUPLES(body, fn_in, fn_out); + body.call__setup_execution_context(fn_in, fn_out); + + auto falloff = fn_out.relocate_out<FN::Types::FalloffW>(0); + Vector<std::string> type_names = find_connected_particle_type_names(vnode->output(0, "Force")); for (std::string &type_name : type_names) { auto fn_or_error = create_particle_function(vnode, vtree_data_graph); @@ -502,7 +513,7 @@ static void PARSE_turbulence_force(BehaviorCollector &collector, } std::unique_ptr<ParticleFunction> compute_inputs = fn_or_error.extract_value(); - Force *force = new TurbulenceForce(std::move(compute_inputs)); + Force *force = new TurbulenceForce(std::move(compute_inputs), falloff.get_unique_copy()); collector.m_forces.add(type_name, force); } } |