Commit: 38e65331a8345054874e81668772dc8c66ad1a1e
Author: Jacques Lucke
Date:   Mon Jul 27 16:26:32 2020 +0200
Branches: master
https://developer.blender.org/rB38e65331a8345054874e81668772dc8c66ad1a1e

Particles: initial support for events and actions

The following nodes work now (although things can still be improved of course):
Particle Birth Event, Praticle Time Step Event, Set Particle Attribute and 
Execute Condition.

Multiple Set Particle Attribute nodes can be chained using the "Execute" 
sockets.
They will be executed from left to right.

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

M       release/scripts/startup/nodeitems_builtins.py
M       source/blender/blenkernel/intern/node.c
M       source/blender/functions/FN_attributes_ref.hh
M       source/blender/functions/FN_cpp_type.hh
M       source/blender/functions/FN_spans.hh
M       source/blender/functions/intern/attributes_ref.cc
M       source/blender/nodes/simulation/nodes/node_sim_set_particle_attribute.cc
M       source/blender/simulation/intern/particle_function.cc
M       source/blender/simulation/intern/particle_function.hh
M       source/blender/simulation/intern/simulation_collect_influences.cc
M       source/blender/simulation/intern/simulation_solver.cc
M       source/blender/simulation/intern/simulation_solver_influences.hh

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

diff --git a/release/scripts/startup/nodeitems_builtins.py 
b/release/scripts/startup/nodeitems_builtins.py
index 8439eadcec3..8ae41a9e19c 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -498,16 +498,16 @@ simulation_node_categories = [
         not_implemented_node("SimulationNodeEmitParticles"),
     ]),
     SimulationNodeCategory("SIM_EVENTS", "Events", items=[
-        not_implemented_node("SimulationNodeParticleBirthEvent"),
-        not_implemented_node("SimulationNodeParticleTimeStepEvent"),
+        NodeItem("SimulationNodeParticleBirthEvent"),
+        NodeItem("SimulationNodeParticleTimeStepEvent"),
         not_implemented_node("SimulationNodeParticleMeshCollisionEvent"),
     ]),
     SimulationNodeCategory("SIM_FORCES", "Forces", items=[
         NodeItem("SimulationNodeForce"),
     ]),
     SimulationNodeCategory("SIM_EXECUTE", "Execute", items=[
-        not_implemented_node("SimulationNodeSetParticleAttribute"),
-        not_implemented_node("SimulationNodeExecuteCondition"),
+        NodeItem("SimulationNodeSetParticleAttribute"),
+        NodeItem("SimulationNodeExecuteCondition"),
         not_implemented_node("SimulationNodeMultiExecute"),
     ]),
     SimulationNodeCategory("SIM_NOISE", "Noise", items=[
diff --git a/source/blender/blenkernel/intern/node.c 
b/source/blender/blenkernel/intern/node.c
index ca1354e9fea..8d7cb90fb71 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -846,12 +846,12 @@ static void socket_id_user_increment(bNodeSocket *sock)
   switch ((eNodeSocketDatatype)sock->type) {
     case SOCK_OBJECT: {
       bNodeSocketValueObject *default_value = sock->default_value;
-      id_us_plus(&default_value->value->id);
+      id_us_plus((ID *)default_value->value);
       break;
     }
     case SOCK_IMAGE: {
       bNodeSocketValueImage *default_value = sock->default_value;
-      id_us_plus(&default_value->value->id);
+      id_us_plus((ID *)default_value->value);
       break;
     }
     case SOCK_FLOAT:
diff --git a/source/blender/functions/FN_attributes_ref.hh 
b/source/blender/functions/FN_attributes_ref.hh
index ed14676731e..c694f11b7a7 100644
--- a/source/blender/functions/FN_attributes_ref.hh
+++ b/source/blender/functions/FN_attributes_ref.hh
@@ -50,12 +50,12 @@ class AttributesInfoBuilder : NonCopyable, NonMovable {
   AttributesInfoBuilder() = default;
   ~AttributesInfoBuilder();
 
-  template<typename T> void add(StringRef name, const T &default_value)
+  template<typename T> bool add(StringRef name, const T &default_value)
   {
-    this->add(name, CPPType::get<T>(), (const void *)&default_value);
+    return this->add(name, CPPType::get<T>(), (const void *)&default_value);
   }
 
-  void add(StringRef name, const CPPType &type, const void *default_value = 
nullptr);
+  bool add(StringRef name, const CPPType &type, const void *default_value = 
nullptr);
 };
 
 /**
diff --git a/source/blender/functions/FN_cpp_type.hh 
b/source/blender/functions/FN_cpp_type.hh
index 594890e353a..531a9073784 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -371,7 +371,7 @@ class CPPType : NonCopyable, NonMovable {
 
   void copy_to_initialized_n(const void *src, void *dst, int64_t n) const
   {
-    BLI_assert(src != dst);
+    BLI_assert(n == 0 || src != dst);
     BLI_assert(n == 0 || this->pointer_can_point_to_instance(src));
     BLI_assert(n == 0 || this->pointer_can_point_to_instance(dst));
 
@@ -380,7 +380,7 @@ class CPPType : NonCopyable, NonMovable {
 
   void copy_to_initialized_indices(const void *src, void *dst, IndexMask mask) 
const
   {
-    BLI_assert(src != dst);
+    BLI_assert(mask.size() == 0 || src != dst);
     BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
     BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
 
@@ -406,7 +406,7 @@ class CPPType : NonCopyable, NonMovable {
 
   void copy_to_uninitialized_n(const void *src, void *dst, int64_t n) const
   {
-    BLI_assert(src != dst);
+    BLI_assert(n == 0 || src != dst);
     BLI_assert(n == 0 || this->pointer_can_point_to_instance(src));
     BLI_assert(n == 0 || this->pointer_can_point_to_instance(dst));
 
@@ -415,7 +415,7 @@ class CPPType : NonCopyable, NonMovable {
 
   void copy_to_uninitialized_indices(const void *src, void *dst, IndexMask 
mask) const
   {
-    BLI_assert(src != dst);
+    BLI_assert(mask.size() == 0 || src != dst);
     BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
     BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
 
@@ -441,7 +441,7 @@ class CPPType : NonCopyable, NonMovable {
 
   void relocate_to_initialized_n(void *src, void *dst, int64_t n) const
   {
-    BLI_assert(src != dst);
+    BLI_assert(n == 0 || src != dst);
     BLI_assert(n == 0 || this->pointer_can_point_to_instance(src));
     BLI_assert(n == 0 || this->pointer_can_point_to_instance(dst));
 
@@ -450,7 +450,7 @@ class CPPType : NonCopyable, NonMovable {
 
   void relocate_to_initialized_indices(void *src, void *dst, IndexMask mask) 
const
   {
-    BLI_assert(src != dst);
+    BLI_assert(mask.size() == 0 || src != dst);
     BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
     BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
 
@@ -476,7 +476,7 @@ class CPPType : NonCopyable, NonMovable {
 
   void relocate_to_uninitialized_n(void *src, void *dst, int64_t n) const
   {
-    BLI_assert(src != dst);
+    BLI_assert(n == 0 || src != dst);
     BLI_assert(n == 0 || this->pointer_can_point_to_instance(src));
     BLI_assert(n == 0 || this->pointer_can_point_to_instance(dst));
 
@@ -485,7 +485,7 @@ class CPPType : NonCopyable, NonMovable {
 
   void relocate_to_uninitialized_indices(void *src, void *dst, IndexMask mask) 
const
   {
-    BLI_assert(src != dst);
+    BLI_assert(mask.size() == 0 || src != dst);
     BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(src));
     BLI_assert(mask.size() == 0 || this->pointer_can_point_to_instance(dst));
 
diff --git a/source/blender/functions/FN_spans.hh 
b/source/blender/functions/FN_spans.hh
index c50c92cd16d..a81f3ea3633 100644
--- a/source/blender/functions/FN_spans.hh
+++ b/source/blender/functions/FN_spans.hh
@@ -209,6 +209,20 @@ template<typename T> struct VSpanBase {
     return false;
   }
 
+  bool is_full_array() const
+  {
+    switch (category_) {
+      case VSpanCategory::Single:
+        return virtual_size_ == 1;
+      case VSpanCategory::FullArray:
+        return true;
+      case VSpanCategory::FullPointerArray:
+        return false;
+    }
+    BLI_assert(false);
+    return false;
+  }
+
   bool is_empty() const
   {
     return this->virtual_size_ == 0;
@@ -285,6 +299,22 @@ template<typename T> class VSpan : public VSpanBase<T> {
     BLI_assert(false);
     return *this->data_.single.data;
   }
+
+  const T &as_single_element() const
+  {
+    BLI_assert(this->is_single_element());
+    return (*this)[0];
+  }
+
+  Span<T> as_full_array() const
+  {
+    BLI_assert(this->is_full_array());
+    if (this->virtual_size_ == 0) {
+      return Span<T>();
+    }
+    const T *data = &(*this)[0];
+    return Span<T>(data, this->virtual_size_);
+  }
 };
 
 /**
@@ -395,6 +425,16 @@ class GVSpan : public VSpanBase<void> {
     return (*this)[0];
   }
 
+  GSpan as_full_array() const
+  {
+    BLI_assert(this->is_full_array());
+    if (this->virtual_size_ == 0) {
+      return GSpan(*this->type_);
+    }
+    const void *data = (*this)[0];
+    return GSpan(*this->type_, data, this->virtual_size_);
+  }
+
   void materialize_to_uninitialized(void *dst) const
   {
     this->materialize_to_uninitialized(IndexRange(virtual_size_), dst);
diff --git a/source/blender/functions/intern/attributes_ref.cc 
b/source/blender/functions/intern/attributes_ref.cc
index 7bfcc69671a..4686e217911 100644
--- a/source/blender/functions/intern/attributes_ref.cc
+++ b/source/blender/functions/intern/attributes_ref.cc
@@ -25,7 +25,7 @@ AttributesInfoBuilder::~AttributesInfoBuilder()
   }
 }
 
-void AttributesInfoBuilder::add(StringRef name, const CPPType &type, const 
void *default_value)
+bool AttributesInfoBuilder::add(StringRef name, const CPPType &type, const 
void *default_value)
 {
   if (names_.add_as(name)) {
     types_.append(&type);
@@ -36,10 +36,15 @@ void AttributesInfoBuilder::add(StringRef name, const 
CPPType &type, const void
     void *dst = allocator_.allocate(type.size(), type.alignment());
     type.copy_to_uninitialized(default_value, dst);
     defaults_.append(dst);
+    return true;
   }
   else {
-    /* The same name can be added more than once as long as the type is always 
the same. */
-    BLI_assert(types_[names_.index_of_as(name)] == &type);
+    const CPPType &stored_type = *types_[names_.index_of_as(name)];
+    if (stored_type != type) {
+      std::cout << "Warning: Tried to add an attribute twice with different 
types (" << name
+                << ": " << stored_type.name() << ", " << type.name() << ").\n";
+    }
+    return false;
   }
 }
 
diff --git 
a/source/blender/nodes/simulation/nodes/node_sim_set_particle_attribute.cc 
b/source/blender/nodes/simulation/nodes/node_sim_set_particle_attribute.cc
index 8696dbe340c..8f5c6818cb4 100644
--- a/source/blender/nodes/simulation/nodes/node_sim_set_particle_attribute.cc
+++ b/source/blender/nodes/simulation/nodes/node_sim_set_particle_attribute.cc
@@ -18,6 +18,7 @@
 #include "node_simulation_util.h"
 
 static bNodeSocketTemplate sim_node_set_particle_attribute_in[] = {
+    {SOCK_CONTROL_FLOW, N_("Execute")},
     {SOCK_STRING, N_("Name")},
     {SOCK_FLOAT, N_("Float"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
     {SOCK_INT, N_("Int"), 0, 0, 0, 0, -10000, 10000},
@@ -38,7 +39,7 @@ static void sim_node_set_particle_attribute_update(bNodeTree 
*UNUSED(ntree), bNo
 {
   int index = 0;
   LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
-    if (index >= 1) {
+    if (index >= 2) {
       nodeSetSocketAvailability(sock, sock->type == node->custom1);
     }
     index++;
diff --git a/source/blender/simul

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to