[Bf-blender-cvs] [873f483836a] functions: new change direction action

Jacques Lucke noreply at git.blender.org
Fri Jul 5 12:26:55 CEST 2019


Commit: 873f483836af88d05ecac525de2380db0410df39
Author: Jacques Lucke
Date:   Fri Jul 5 11:15:57 2019 +0200
Branches: functions
https://developer.blender.org/rB873f483836af88d05ecac525de2380db0410df39

new change direction action

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

A	release/scripts/startup/nodes/bparticle_nodes/change_direction.py
M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/actions.hpp
M	source/blender/simulations/bparticles/c_wrapper.cpp

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

diff --git a/release/scripts/startup/nodes/bparticle_nodes/change_direction.py b/release/scripts/startup/nodes/bparticle_nodes/change_direction.py
new file mode 100644
index 00000000000..b3487c13ffa
--- /dev/null
+++ b/release/scripts/startup/nodes/bparticle_nodes/change_direction.py
@@ -0,0 +1,13 @@
+import bpy
+from bpy.props import *
+from .. base import BParticlesNode
+from .. socket_builder import SocketBuilder
+
+class ChangeParticleDirectionNode(bpy.types.Node, BParticlesNode):
+    bl_idname = "bp_ChangeParticleDirectionNode"
+    bl_label = "Change Particle Direction"
+
+    def declaration(self, builder : SocketBuilder):
+        builder.control_flow_input("control_in", "(In)")
+        builder.fixed_input("direction", "Direction", "Vector")
+        builder.control_flow_output("control_out", "(Out)")
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 34c878a2aa5..3427a6d2ec1 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -14,6 +14,36 @@ class NoneAction : public Action {
   }
 };
 
+class ChangeDirectionAction : public Action {
+ private:
+  SharedFunction m_compute_direction_fn;
+  TupleCallBody *m_compute_direction_body;
+
+ public:
+  ChangeDirectionAction(SharedFunction &compute_direction_fn)
+      : m_compute_direction_fn(compute_direction_fn)
+  {
+    m_compute_direction_body = m_compute_direction_fn->body<TupleCallBody>();
+  }
+
+  void execute(EventExecuteInterface &interface) override
+  {
+    ParticleSet particles = interface.particles();
+    auto velocities = particles.attributes().get_float3("Velocity");
+
+    FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_direction_body, fn_in, fn_out);
+
+    FN::ExecutionStack stack;
+    FN::ExecutionContext execution_context(stack);
+
+    for (uint pindex : particles.indices()) {
+      m_compute_direction_body->call(fn_in, fn_out, execution_context);
+      float3 direction = fn_out.get<float3>(0);
+      velocities[pindex] = direction;
+    }
+  }
+};
+
 class KillAction : public Action {
   void execute(EventExecuteInterface &interface) override
   {
@@ -122,6 +152,11 @@ Action *ACTION_none()
   return new NoneAction();
 }
 
+Action *ACTION_change_direction(SharedFunction &compute_direction_fn)
+{
+  return new ChangeDirectionAction(compute_direction_fn);
+}
+
 Action *ACTION_kill()
 {
   return new KillAction();
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index 3f14abfe8d8..3af29afe23d 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -1,9 +1,14 @@
 #pragma once
 
+#include "FN_tuple_call.hpp"
+
 #include "core.hpp"
 
 namespace BParticles {
 
+using FN::SharedFunction;
+using FN::TupleCallBody;
+
 class Action {
  public:
   virtual ~Action() = 0;
@@ -12,6 +17,7 @@ class Action {
 };
 
 Action *ACTION_none();
+Action *ACTION_change_direction(SharedFunction &compute_direction_fn);
 Action *ACTION_kill();
 Action *ACTION_move(float3 offset);
 Action *ACTION_spawn();
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 15af0816d56..d19e3f1a49a 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -41,6 +41,7 @@
 
 using namespace BParticles;
 
+using BKE::bSocketList;
 using BKE::IndexedNodeTree;
 using BKE::SocketWithNode;
 using BLI::ArrayRef;
@@ -242,6 +243,16 @@ static Action *build_action(SocketWithNode start,
   if (STREQ(bnode->idname, "bp_KillParticleNode")) {
     return ACTION_kill();
   }
+  else if (STREQ(bnode->idname, "bp_ChangeParticleDirectionNode")) {
+    bNodeSocket *direction_socket = bSocketList(bnode->inputs).get(1);
+
+    FN::DFGraphSocket direction_input = data_graph.lookup_socket(direction_socket);
+    FN::FunctionGraph function_graph(data_graph.graph(), {}, {direction_input});
+    SharedFunction compute_direction_fn = function_graph.new_function("Compute Direction");
+    FN::fgraph_add_TupleCallBody(compute_direction_fn, function_graph);
+
+    return ACTION_change_direction(compute_direction_fn);
+  }
   else {
     return nullptr;
   }



More information about the Bf-blender-cvs mailing list