[Bf-blender-cvs] [dec218643e5] functions: use particle function in turbulence node

Jacques Lucke noreply at git.blender.org
Wed Jul 24 19:12:04 CEST 2019


Commit: dec218643e57b249808cbba04dc4971ffda5d1a2
Author: Jacques Lucke
Date:   Wed Jul 24 15:54:16 2019 +0200
Branches: functions
https://developer.blender.org/rBdec218643e57b249808cbba04dc4971ffda5d1a2

use particle function in turbulence node

===================================================================

M	source/blender/simulations/bparticles/forces.cpp
M	source/blender/simulations/bparticles/forces.hpp
M	source/blender/simulations/bparticles/inserters.cpp
M	source/blender/simulations/bparticles/particle_function.cpp
M	source/blender/simulations/bparticles/particle_function.hpp

===================================================================

diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp
index 1f9081dbe23..9cc62159138 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -34,15 +34,13 @@ void TurbulenceForce::add_force(ForceInterface &interface)
 
   auto positions = block.attributes().get_float3("Position");
 
-  FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_strength_body, fn_in, fn_out);
-  FN::ExecutionStack stack;
-  FN::ExecutionContext execution_context(stack);
-  m_compute_strength_body->call(fn_in, fn_out, execution_context);
-
-  float3 strength = fn_out.get<float3>(0);
+  auto caller = m_compute_inputs.get_caller(interface);
+  auto strengths = caller.add_output<float3>();
+  caller.call(block.active_range().as_array_ref());
 
   for (uint pindex = 0; pindex < block.active_amount(); pindex++) {
     float3 pos = positions[pindex];
+    float3 strength = strengths[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;
diff --git a/source/blender/simulations/bparticles/forces.hpp b/source/blender/simulations/bparticles/forces.hpp
index 55725e47d92..1a58f44f371 100644
--- a/source/blender/simulations/bparticles/forces.hpp
+++ b/source/blender/simulations/bparticles/forces.hpp
@@ -29,13 +29,11 @@ class GravityForce : public Force {
 
 class TurbulenceForce : public Force {
  private:
-  SharedFunction m_compute_strength_fn;
-  TupleCallBody *m_compute_strength_body;
+  ParticleFunction m_compute_inputs;
 
  public:
-  TurbulenceForce(SharedFunction &compute_strength_fn) : m_compute_strength_fn(compute_strength_fn)
+  TurbulenceForce(ParticleFunction compute_inputs) : m_compute_inputs(std::move(compute_inputs))
   {
-    m_compute_strength_body = m_compute_strength_fn->body<TupleCallBody>();
   }
 
   void add_force(ForceInterface &interface) override;
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 23bc0c54ccb..61e4bb9113d 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -54,22 +54,6 @@ static ValueOrError<SharedFunction> create_function__emitter_inputs(VirtualNode
   return fn;
 }
 
-static ValueOrError<SharedFunction> create_function__force_inputs(VirtualNode *force_vnode,
-                                                                  VTreeDataGraph &data_graph)
-{
-  Vector<DFGraphSocket> sockets_to_compute = find_input_data_sockets(force_vnode, data_graph);
-  auto dependencies = data_graph.find_placeholder_dependencies(sockets_to_compute);
-
-  if (dependencies.size() > 0) {
-    return BLI_ERROR_CREATE("Force inputs cannot have dependencies currently.");
-  }
-
-  FunctionGraph fgraph(data_graph.graph(), {}, sockets_to_compute);
-  SharedFunction fn = fgraph.new_function(force_vnode->name());
-  FN::fgraph_add_TupleCallBody(fn, fgraph);
-  return fn;
-}
-
 static ValueOrError<SharedFunction> create_function__event_inputs(VirtualNode *event_vnode,
                                                                   VTreeDataGraph &data_graph)
 {
@@ -127,6 +111,12 @@ static ValueOrError<SharedFunction> create_function__offset_handler_inputs(
   return create_function__action_inputs(offset_handler_vnode, data_graph);
 }
 
+static ValueOrError<SharedFunction> create_function__force_inputs(VirtualNode *force_vnode,
+                                                                  VTreeDataGraph &data_graph)
+{
+  return create_function__action_inputs(force_vnode, data_graph);
+}
+
 static std::unique_ptr<Action> build_action(BuildContext &ctx,
                                             VirtualSocket *start,
                                             VirtualSocket *trigger);
@@ -263,7 +253,7 @@ static std::unique_ptr<Force> BUILD_FORCE_turbulence(BuildContext &ctx, VirtualN
   }
 
   SharedFunction fn = fn_or_error.extract_value();
-  return std::unique_ptr<Force>(new TurbulenceForce(fn));
+  return std::unique_ptr<Force>(new TurbulenceForce(ParticleFunction(fn)));
 }
 
 static std::unique_ptr<Event> BUILD_EVENT_mesh_collision(BuildContext &ctx, VirtualNode *vnode)
diff --git a/source/blender/simulations/bparticles/particle_function.cpp b/source/blender/simulations/bparticles/particle_function.cpp
index a0d9c3aedce..9656a29cfd6 100644
--- a/source/blender/simulations/bparticles/particle_function.cpp
+++ b/source/blender/simulations/bparticles/particle_function.cpp
@@ -17,6 +17,12 @@ ParticleFunctionCaller ParticleFunction::get_caller(
                           nullptr);
 }
 
+ParticleFunctionCaller ParticleFunction::get_caller(ForceInterface &force_interface)
+{
+  return this->get_caller(
+      force_interface.array_allocator(), force_interface.block().attributes(), nullptr);
+}
+
 ParticleFunctionCaller ParticleFunction::get_caller(ArrayAllocator &array_allocator,
                                                     AttributeArrays attributes,
                                                     ActionContext *action_context)
diff --git a/source/blender/simulations/bparticles/particle_function.hpp b/source/blender/simulations/bparticles/particle_function.hpp
index 4a108b9b491..c40b148887b 100644
--- a/source/blender/simulations/bparticles/particle_function.hpp
+++ b/source/blender/simulations/bparticles/particle_function.hpp
@@ -3,6 +3,7 @@
 #include "FN_tuple_call.hpp"
 #include "attributes.hpp"
 #include "action_interface.hpp"
+#include "force_interface.hpp"
 
 namespace BParticles {
 
@@ -91,6 +92,7 @@ class ParticleFunction {
 
   ParticleFunctionCaller get_caller(ActionInterface &action_interface);
   ParticleFunctionCaller get_caller(OffsetHandlerInterface &offset_handler_interface);
+  ParticleFunctionCaller get_caller(ForceInterface &force_interface);
 
  private:
   ParticleFunctionCaller get_caller(ArrayAllocator &array_allocator,



More information about the Bf-blender-cvs mailing list