[Bf-blender-cvs] [f169a5eeb78] functions: improve particle function

Jacques Lucke noreply at git.blender.org
Wed Jul 24 19:11:55 CEST 2019


Commit: f169a5eeb78e02da427d1b991f016fbbd2d9086e
Author: Jacques Lucke
Date:   Wed Jul 24 15:06:07 2019 +0200
Branches: functions
https://developer.blender.org/rBf169a5eeb78e02da427d1b991f016fbbd2d9086e

improve particle function

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

M	source/blender/simulations/bparticles/action_interface.hpp
M	source/blender/simulations/bparticles/actions.cpp
M	source/blender/simulations/bparticles/events.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/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp
index d064b4eb3e0..989b2eba555 100644
--- a/source/blender/simulations/bparticles/action_interface.hpp
+++ b/source/blender/simulations/bparticles/action_interface.hpp
@@ -13,7 +13,18 @@ using FN::TupleCallBody;
 
 class ActionContext {
  public:
-  virtual void *get_context_array(StringRef name) = 0;
+  struct ContextArray {
+    void *buffer = nullptr;
+    uint stride = 0;
+
+    ContextArray() = default;
+    template<typename T>
+    ContextArray(ArrayRef<T> array) : buffer((void *)array.begin()), stride(sizeof(T))
+    {
+    }
+  };
+
+  virtual ContextArray get_context_array(StringRef name) = 0;
 };
 
 class ActionInterface {
@@ -82,9 +93,9 @@ inline ActionInterface::ActionInterface(ParticleAllocator &particle_allocator,
 }
 
 class EmptyEventInfo : public ActionContext {
-  void *get_context_array(StringRef UNUSED(name))
+  ContextArray get_context_array(StringRef UNUSED(name))
   {
-    return nullptr;
+    return {};
   }
 };
 
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index ffbbca933f8..fe285915c79 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -15,7 +15,7 @@ void ChangeDirectionAction::execute(ActionInterface &interface)
   auto position_offsets = interface.attribute_offsets().try_get_float3("Position");
   auto velocity_offsets = interface.attribute_offsets().try_get_float3("Velocity");
 
-  auto caller = m_compute_inputs.get_caller(particles.attributes());
+  auto caller = m_compute_inputs.get_caller(interface);
   auto new_directions = caller.add_output<float3>(interface.array_allocator());
   caller.call(particles.pindices());
 
@@ -62,7 +62,7 @@ void ExplodeAction::execute(ActionInterface &interface)
   Vector<float3> new_velocities;
   Vector<float> new_birth_times;
 
-  auto caller = m_compute_inputs.get_caller(particles.attributes());
+  auto caller = m_compute_inputs.get_caller(interface);
   auto parts_amounts = caller.add_output<int>(interface.array_allocator());
   auto speeds = caller.add_output<float>(interface.array_allocator());
   caller.call(particles.pindices());
@@ -93,7 +93,7 @@ void ConditionAction::execute(ActionInterface &interface)
 {
   ParticleSet particles = interface.particles();
 
-  auto caller = m_compute_inputs.get_caller(particles.attributes());
+  auto caller = m_compute_inputs.get_caller(interface);
   auto conditions = caller.add_output<bool>(interface.array_allocator());
   caller.call(particles.pindices());
 
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index c3e3337d0c3..ee824c19dcb 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -48,12 +48,12 @@ class CollisionEventInfo : public ActionContext {
   {
   }
 
-  void *get_context_array(StringRef name) override
+  ContextArray get_context_array(StringRef name) override
   {
     if (name == "Normal") {
-      return (void *)m_normals.begin();
+      return m_normals;
     }
-    return nullptr;
+    return {};
   }
 };
 
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index b4fd2a0d75d..d75872d605a 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -123,7 +123,7 @@ static ValueOrError<SharedFunction> create_function__action_inputs(VirtualNode *
       name_prefix = "Attribute: ";
     }
     else if (STREQ(vnode->idname(), "bp_CollisionInfoNode")) {
-      name_prefix = "Event: ";
+      name_prefix = "Action Context: ";
     }
     else {
       BLI_assert(false);
diff --git a/source/blender/simulations/bparticles/particle_function.cpp b/source/blender/simulations/bparticles/particle_function.cpp
index f67fa8004de..c3c790f6c56 100644
--- a/source/blender/simulations/bparticles/particle_function.cpp
+++ b/source/blender/simulations/bparticles/particle_function.cpp
@@ -2,7 +2,18 @@
 
 namespace BParticles {
 
+ParticleFunctionCaller ParticleFunction::get_caller(ActionInterface &action_interface)
+{
+  return this->get_caller(action_interface.particles().attributes(), &action_interface.context());
+}
+
 ParticleFunctionCaller ParticleFunction::get_caller(AttributeArrays attributes)
+{
+  return this->get_caller(attributes, nullptr);
+}
+
+ParticleFunctionCaller ParticleFunction::get_caller(AttributeArrays attributes,
+                                                    ActionContext *action_context)
 {
   ParticleFunctionCaller caller;
   caller.m_body = m_body;
@@ -18,6 +29,12 @@ ParticleFunctionCaller ParticleFunction::get_caller(AttributeArrays attributes)
       input_buffer = attributes.get_ptr(attribute_index);
       input_stride = attributes.attribute_stride(attribute_index);
     }
+    else if (action_context != nullptr && input_name.startswith("Action Context")) {
+      StringRef context_name = input_name.drop_prefix("Action Context: ");
+      ActionContext::ContextArray array = action_context->get_context_array(context_name);
+      input_buffer = array.buffer;
+      input_stride = array.stride;
+    }
     else {
       BLI_assert(false);
     }
diff --git a/source/blender/simulations/bparticles/particle_function.hpp b/source/blender/simulations/bparticles/particle_function.hpp
index 93147b1a8f3..4a92d090fb1 100644
--- a/source/blender/simulations/bparticles/particle_function.hpp
+++ b/source/blender/simulations/bparticles/particle_function.hpp
@@ -2,6 +2,7 @@
 
 #include "FN_tuple_call.hpp"
 #include "attributes.hpp"
+#include "action_interface.hpp"
 
 namespace BParticles {
 
@@ -87,7 +88,12 @@ class ParticleFunction {
     BLI_assert(m_body != nullptr);
   }
 
+  ParticleFunctionCaller get_caller(ActionInterface &action_interface);
+
   ParticleFunctionCaller get_caller(AttributeArrays attributes);
+
+ private:
+  ParticleFunctionCaller get_caller(AttributeArrays attributes, ActionContext *action_context);
 };
 
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list