[Bf-blender-cvs] [cdc432429ff] functions: Falloff input in Drag Force node
Jacques Lucke
noreply at git.blender.org
Mon Sep 9 17:23:04 CEST 2019
Commit: cdc432429fff8616bc3be45bc78b455e7bfbf3c3
Author: Jacques Lucke
Date: Mon Sep 9 16:23:38 2019 +0200
Branches: functions
https://developer.blender.org/rBcdc432429fff8616bc3be45bc78b455e7bfbf3c3
Falloff input in Drag Force node
===================================================================
M release/scripts/startup/nodes/bparticle_nodes/forces.py
M source/blender/simulations/bparticles/forces.cpp
M source/blender/simulations/bparticles/forces.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
===================================================================
diff --git a/release/scripts/startup/nodes/bparticle_nodes/forces.py b/release/scripts/startup/nodes/bparticle_nodes/forces.py
index 938418c0932..54bc6e497d0 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/forces.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/forces.py
@@ -28,4 +28,5 @@ class DragForceNode(bpy.types.Node, BParticlesNode):
def declaration(self, builder: NodeBuilder):
builder.fixed_input("strength", "Strength", 'Float', default=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 0cf1ad6057e..eb9e0fe9e00 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -48,10 +48,14 @@ void DragForce::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 velocity = velocities[pindex];
float strength = inputs->get<float>("Strength", 0, pindex);
- destination[pindex] -= velocity * strength;
+ float weight = weights[pindex];
+ destination[pindex] -= velocity * strength * weight;
}
}
diff --git a/source/blender/simulations/bparticles/forces.hpp b/source/blender/simulations/bparticles/forces.hpp
index bdae5422cc2..88a04f47470 100644
--- a/source/blender/simulations/bparticles/forces.hpp
+++ b/source/blender/simulations/bparticles/forces.hpp
@@ -45,10 +45,11 @@ class TurbulenceForce : public Force {
class DragForce : public Force {
private:
std::unique_ptr<ParticleFunction> m_compute_inputs;
+ std::unique_ptr<Falloff> m_falloff;
public:
- DragForce(std::unique_ptr<ParticleFunction> compute_inputs)
- : m_compute_inputs(std::move(compute_inputs))
+ DragForce(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 c5abebfbdfd..e3b43a79836 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -440,6 +440,17 @@ static void PARSE_drag_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);
@@ -448,7 +459,7 @@ static void PARSE_drag_force(BehaviorCollector &collector,
}
std::unique_ptr<ParticleFunction> compute_inputs = fn_or_error.extract_value();
- Force *force = new DragForce(std::move(compute_inputs));
+ Force *force = new DragForce(std::move(compute_inputs), falloff.get_unique_copy());
collector.m_forces.add(type_name, force);
}
}
More information about the Bf-blender-cvs
mailing list