[Bf-blender-cvs] [202708eeaed] functions: run action on particle birth

Jacques Lucke noreply at git.blender.org
Thu Jul 11 17:15:13 CEST 2019


Commit: 202708eeaed5f3ddaf8eb3b727aaff79f494172e
Author: Jacques Lucke
Date:   Thu Jul 11 11:17:53 2019 +0200
Branches: functions
https://developer.blender.org/rB202708eeaed5f3ddaf8eb3b727aaff79f494172e

run action on particle birth

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

M	release/scripts/startup/nodes/bparticle_nodes/mesh_emitter.py
M	source/blender/simulations/bparticles/attributes.hpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/emitters.hpp
M	source/blender/simulations/bparticles/inserters.cpp

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

diff --git a/release/scripts/startup/nodes/bparticle_nodes/mesh_emitter.py b/release/scripts/startup/nodes/bparticle_nodes/mesh_emitter.py
index d9dcfe3646a..93d659fa1de 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/mesh_emitter.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/mesh_emitter.py
@@ -13,4 +13,5 @@ class MeshEmitterNode(bpy.types.Node, BParticlesNode):
         builder.fixed_input("normal_velocity", "Normal Velocity", "Float", default=1)
         builder.fixed_input("emitter_velocity", "Emitter Velocity", "Float", default=0)
         builder.fixed_input("size", "Size", "Float", default=0.05)
+        builder.control_flow_output("on_birth", "On Birth")
         builder.emitter_output("emitter", "Emitter")
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index 830e2435308..afa24b95544 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -136,7 +136,7 @@ class AttributesInfo {
    * Get the index corresponding to an attribute with the given name and type.
    * Returns -1 when the attribute does not exist.
    */
-  bool attribute_index_try(StringRef name, AttributeType type) const
+  int attribute_index_try(StringRef name, AttributeType type) const
   {
     int index = this->attribute_index_try(name);
     if (index == -1) {
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index a23bb99c94a..6d84e786f2b 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -264,7 +264,7 @@ class ParticleSets {
                AttributesInfo &attributes_info,
                ArrayRef<ParticleSet> sets);
 
-  operator ArrayRef<ParticleSet>();
+  ArrayRef<ParticleSet> sets();
 
   void set_byte(uint index, ArrayRef<uint8_t> data);
   void set_byte(StringRef name, ArrayRef<uint8_t> data);
@@ -631,7 +631,7 @@ inline ArrayRef<ParticlesBlock *> ParticleAllocator::allocated_blocks()
 /* ParticleSets inline functions
  ********************************************/
 
-inline ParticleSets::operator ArrayRef<ParticleSet>()
+inline ArrayRef<ParticleSet> ParticleSets::sets()
 {
   return m_sets;
 }
diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index c416782c4ba..442b1ae7cec 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -44,18 +44,28 @@ class SurfaceEmitter : public Emitter {
   SharedFunction m_compute_inputs_fn;
   TupleCallBody *m_compute_inputs_body;
   WorldState &m_world_state;
+  std::unique_ptr<Action> m_action;
 
  public:
   SurfaceEmitter(StringRef particle_type_name,
                  SharedFunction &compute_inputs,
-                 WorldState &world_state)
+                 WorldState &world_state,
+                 std::unique_ptr<Action> action)
       : m_particle_type_name(particle_type_name.to_std_string()),
         m_compute_inputs_fn(compute_inputs),
-        m_world_state(world_state)
+        m_world_state(world_state),
+        m_action(std::move(action))
   {
     m_compute_inputs_body = m_compute_inputs_fn->body<TupleCallBody>();
   }
 
+  class EmitSurfaceEventInfo : public EventInfo {
+    void *get_info_array(StringRef name)
+    {
+      return nullptr;
+    }
+  };
+
   void emit(EmitterInterface &interface) override
   {
     FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_inputs_body, fn_in, fn_out);
@@ -135,6 +145,25 @@ class SurfaceEmitter : public Emitter {
     target.set_float3("Velocity", velocities);
     target.set_float("Size", sizes);
     target.set_float("Birth Time", birth_times);
+
+    AttributesInfo info;
+    AttributeArraysCore offsets_core(info, {}, 0);
+    AttributeArrays offsets = offsets_core.slice_all();
+
+    EmitSurfaceEventInfo event_info;
+
+    for (ParticleSet particles : target.sets()) {
+      ArrayAllocator::Array<float> durations(interface.array_allocator());
+      ArrayRef<float>(durations).fill_indices(particles.pindices(), 0);
+      ActionInterface action_interface(interface.particle_allocator(),
+                                       interface.array_allocator(),
+                                       particles,
+                                       offsets,
+                                       particles.attributes().get_float("Birth Time"),
+                                       durations,
+                                       event_info);
+      m_action->execute(action_interface);
+    }
   }
 
   float3 random_point_in_triangle(float3 a, float3 b, float3 c)
@@ -159,9 +188,10 @@ Emitter *EMITTER_point(StringRef particle_type_name, float3 point)
 
 Emitter *EMITTER_mesh_surface(StringRef particle_type_name,
                               SharedFunction &compute_inputs_fn,
-                              WorldState &world_state)
+                              WorldState &world_state,
+                              std::unique_ptr<Action> action)
 {
-  return new SurfaceEmitter(particle_type_name, compute_inputs_fn, world_state);
+  return new SurfaceEmitter(particle_type_name, compute_inputs_fn, world_state, std::move(action));
 }
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/emitters.hpp b/source/blender/simulations/bparticles/emitters.hpp
index a99a05b4179..f7f1ffee558 100644
--- a/source/blender/simulations/bparticles/emitters.hpp
+++ b/source/blender/simulations/bparticles/emitters.hpp
@@ -4,6 +4,7 @@
 
 #include "core.hpp"
 #include "world_state.hpp"
+#include "action_interface.hpp"
 
 namespace BParticles {
 
@@ -14,6 +15,7 @@ Emitter *EMITTER_point(StringRef particle_type_name, float3 point);
 
 Emitter *EMITTER_mesh_surface(StringRef particle_type_name,
                               SharedFunction &compute_inputs_fn,
-                              WorldState &world_state);
+                              WorldState &world_state,
+                              std::unique_ptr<Action> action);
 
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 1738b25d841..22de1a4c854 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -208,7 +208,7 @@ static std::unique_ptr<Action> build_action(SocketWithNode start,
 
 static void INSERT_EMITTER_mesh_surface(ProcessNodeInterface &interface)
 {
-  for (SocketWithNode linked : interface.linked_with_output(0)) {
+  for (SocketWithNode linked : interface.linked_with_output(1)) {
     if (!is_particle_type_node(linked.node)) {
       continue;
     }
@@ -220,8 +220,14 @@ static void INSERT_EMITTER_mesh_surface(ProcessNodeInterface &interface)
         {inputs.get(0), inputs.get(1), inputs.get(2), inputs.get(3), inputs.get(4)},
         interface.bnode()->name);
 
+    auto action = build_action({interface.outputs().get(0), interface.bnode()},
+                               interface.indexed_tree(),
+                               interface.data_graph(),
+                               interface.step_description());
+
     bNode *type_node = linked.node;
-    Emitter *emitter = EMITTER_mesh_surface(type_node->name, fn, interface.world_state());
+    Emitter *emitter = EMITTER_mesh_surface(
+        type_node->name, fn, interface.world_state(), std::move(action));
     interface.step_description().m_emitters.append(emitter);
   }
 }



More information about the Bf-blender-cvs mailing list