[Bf-blender-cvs] [681ae8d03c9] functions: initial explode particle node

Jacques Lucke noreply at git.blender.org
Fri Jul 5 17:38:44 CEST 2019


Commit: 681ae8d03c91e3765bcc64ed45381a0b5e2e56bf
Author: Jacques Lucke
Date:   Fri Jul 5 14:38:35 2019 +0200
Branches: functions
https://developer.blender.org/rB681ae8d03c91e3765bcc64ed45381a0b5e2e56bf

initial explode particle node

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

A	release/scripts/startup/nodes/bparticle_nodes/explode_particle.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/explode_particle.py b/release/scripts/startup/nodes/bparticle_nodes/explode_particle.py
new file mode 100644
index 00000000000..b425b14d8f7
--- /dev/null
+++ b/release/scripts/startup/nodes/bparticle_nodes/explode_particle.py
@@ -0,0 +1,18 @@
+import bpy
+from bpy.props import *
+from .. base import BParticlesNode
+from .. socket_builder import SocketBuilder
+
+class ExplodeParticleNode(bpy.types.Node, BParticlesNode):
+    bl_idname = "bp_ExplodeParticleNode"
+    bl_label = "Explode Particle"
+
+    particle_type_name: StringProperty(maxlen=64)
+
+    def declaration(self, builder : SocketBuilder):
+        builder.control_flow_input("control_in", "(In)")
+        builder.fixed_input("amount", "Amount", "Integer")
+        builder.control_flow_output("control_out", "(Out)")
+
+    def draw(self, layout):
+        layout.prop(self, "particle_type_name", text="Type")
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 05341418435..5d284dc7187 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -18,14 +18,20 @@ class ChangeDirectionAction : public Action {
  private:
   SharedFunction m_compute_direction_fn;
   TupleCallBody *m_compute_direction_body;
+  Action *m_post_action;
 
  public:
-  ChangeDirectionAction(SharedFunction &compute_direction_fn)
-      : m_compute_direction_fn(compute_direction_fn)
+  ChangeDirectionAction(SharedFunction &compute_direction_fn, Action *post_action)
+      : m_compute_direction_fn(compute_direction_fn), m_post_action(post_action)
   {
     m_compute_direction_body = m_compute_direction_fn->body<TupleCallBody>();
   }
 
+  ~ChangeDirectionAction()
+  {
+    delete m_post_action;
+  }
+
   void execute(EventExecuteInterface &interface) override
   {
     ParticleSet particles = interface.particles();
@@ -46,6 +52,8 @@ class ChangeDirectionAction : public Action {
       position_offsets[pindex] = direction * interface.remaining_time_in_step(i);
       velocity_offsets[pindex] = float3(0);
     }
+
+    m_post_action->execute(interface);
   }
 };
 
@@ -115,11 +123,19 @@ static float3 random_direction()
 class ExplodeAction : public Action {
  private:
   std::string m_new_particle_name;
+  SharedFunction m_compute_amount_fn;
+  TupleCallBody *m_compute_amount_body;
+  std::unique_ptr<Action> m_post_action;
 
  public:
-  ExplodeAction(StringRef new_particle_name)
-      : m_new_particle_name(new_particle_name.to_std_string())
+  ExplodeAction(StringRef new_particle_name,
+                SharedFunction &compute_amount_fn,
+                std::unique_ptr<Action> post_action)
+      : m_new_particle_name(new_particle_name.to_std_string()),
+        m_compute_amount_fn(compute_amount_fn),
+        m_post_action(std::move(post_action))
   {
+    m_compute_amount_body = m_compute_amount_fn->body<TupleCallBody>();
   }
 
   void execute(EventExecuteInterface &interface) override
@@ -132,7 +148,13 @@ class ExplodeAction : public Action {
     SmallVector<float3> new_velocities;
     SmallVector<uint> original_indices;
 
-    uint parts_amount = 100;
+    FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_amount_body, fn_in, fn_out);
+
+    FN::ExecutionStack stack;
+    FN::ExecutionContext execution_context(stack);
+    m_compute_amount_body->call(fn_in, fn_out, execution_context);
+
+    uint parts_amount = std::max(0, fn_out.get<int>(0));
     for (uint i : particles.range()) {
       uint pindex = particles.get_particle_index(i);
 
@@ -148,7 +170,7 @@ class ExplodeAction : public Action {
     target.set_float3("Position", new_positions);
     target.set_float3("Velocity", new_velocities);
 
-    interface.kill(particles.indices());
+    m_post_action->execute(interface);
   }
 };
 
@@ -157,9 +179,9 @@ Action *ACTION_none()
   return new NoneAction();
 }
 
-Action *ACTION_change_direction(SharedFunction &compute_direction_fn)
+Action *ACTION_change_direction(SharedFunction &compute_direction_fn, Action *post_action)
 {
-  return new ChangeDirectionAction(compute_direction_fn);
+  return new ChangeDirectionAction(compute_direction_fn, post_action);
 }
 
 Action *ACTION_kill()
@@ -177,9 +199,12 @@ Action *ACTION_spawn()
   return new SpawnAction();
 }
 
-Action *ACTION_explode(StringRef new_particle_name)
+Action *ACTION_explode(StringRef new_particle_name,
+                       SharedFunction &compute_amount_fn,
+                       Action *post_action)
 {
-  return new ExplodeAction(new_particle_name);
+  return new ExplodeAction(
+      new_particle_name, compute_amount_fn, std::unique_ptr<Action>(post_action));
 }
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index 3af29afe23d..2a6725368ee 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -17,10 +17,12 @@ class Action {
 };
 
 Action *ACTION_none();
-Action *ACTION_change_direction(SharedFunction &compute_direction_fn);
+Action *ACTION_change_direction(SharedFunction &compute_direction_fn, Action *post_action);
 Action *ACTION_kill();
 Action *ACTION_move(float3 offset);
 Action *ACTION_spawn();
-Action *ACTION_explode(StringRef new_particle_name);
+Action *ACTION_explode(StringRef new_particle_name,
+                       SharedFunction &compute_amount_fn,
+                       Action *post_action);
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 9cab561c421..a4a20139065 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -290,7 +290,33 @@ static Action *build_action(SocketWithNode start,
     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);
+    return ACTION_change_direction(compute_direction_fn,
+                                   build_action({bSocketList(bnode->outputs).get(0), bnode},
+                                                indexed_tree,
+                                                data_graph,
+                                                step_description));
+  }
+  else if (STREQ(bnode->idname, "bp_ExplodeParticleNode")) {
+    bNodeSocket *amount_socket = bSocketList(bnode->inputs).get(1);
+
+    FN::DFGraphSocket amount_input = data_graph.lookup_socket(amount_socket);
+    FN::FunctionGraph function_graph(data_graph.graph(), {}, {amount_input});
+    SharedFunction compute_amount_fn = function_graph.new_function("Compute Amount");
+    FN::fgraph_add_TupleCallBody(compute_amount_fn, function_graph);
+
+    PointerRNA rna = indexed_tree.get_rna(bnode);
+    char name[65];
+    RNA_string_get(&rna, "particle_type_name", name);
+
+    Action *post_action = build_action(
+        {bSocketList(bnode->outputs).get(0), bnode}, indexed_tree, data_graph, step_description);
+
+    if (step_description.m_types.contains(name)) {
+      return ACTION_explode(name, compute_amount_fn, post_action);
+    }
+    else {
+      return post_action;
+    }
   }
   else {
     return nullptr;



More information about the Bf-blender-cvs mailing list