[Bf-blender-cvs] [42d70c81522] functions: emitter decides at which time individual particles are spawned

Jacques Lucke noreply at git.blender.org
Thu Jun 27 15:50:06 CEST 2019


Commit: 42d70c8152261b6dd36fa57dbdda25ea83ebfe79
Author: Jacques Lucke
Date:   Thu Jun 27 14:29:26 2019 +0200
Branches: functions
https://developer.blender.org/rB42d70c8152261b6dd36fa57dbdda25ea83ebfe79

emitter decides at which time individual particles are spawned

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

M	source/blender/simulations/bparticles/core.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index 590010fd9e8..b9e67a81f85 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -104,9 +104,9 @@ void EmitTarget::set_elements(uint index, void *data)
 
   void *remaining_data = data;
 
-  for (uint i = 0; i < m_ranges.size(); i++) {
-    ParticlesBlock &block = *m_blocks[i];
-    Range<uint> range = m_ranges[i];
+  for (uint part = 0; part < m_ranges.size(); part++) {
+    ParticlesBlock &block = *m_blocks[part];
+    Range<uint> range = m_ranges[part];
 
     AttributeArrays attributes = block.slice(range);
     void *dst = attributes.get_ptr(index);
@@ -117,6 +117,21 @@ void EmitTarget::set_elements(uint index, void *data)
   }
 }
 
+void EmitTarget::fill_elements(uint index, void *value)
+{
+  AttributeType type = m_attributes_info.type_of(index);
+  uint element_size = size_of_attribute_type(type);
+
+  for (uint part = 0; part < m_ranges.size(); part++) {
+    ParticlesBlock &block = *m_blocks[part];
+
+    void *dst = block.slice_all().get_ptr(index);
+    for (uint i : m_ranges[part]) {
+      memcpy(POINTER_OFFSET(dst, element_size * i), value, element_size);
+    }
+  }
+}
+
 void EmitTarget::set_byte(uint index, ArrayRef<uint8_t> data)
 {
   BLI_assert(data.size() == m_size);
@@ -152,4 +167,37 @@ void EmitTarget::set_float3(StringRef name, ArrayRef<float3> data)
   this->set_float3(index, data);
 }
 
+void EmitTarget::fill_byte(uint index, uint8_t value)
+{
+  this->fill_elements(index, (void *)&value);
+}
+
+void EmitTarget::fill_byte(StringRef name, uint8_t value)
+{
+  uint index = m_attributes_info.attribute_index(name);
+  this->fill_byte(index, value);
+}
+
+void EmitTarget::fill_float(uint index, float value)
+{
+  this->fill_elements(index, (void *)&value);
+}
+
+void EmitTarget::fill_float(StringRef name, float value)
+{
+  uint index = m_attributes_info.attribute_index(name);
+  this->fill_float(index, value);
+}
+
+void EmitTarget::fill_float3(uint index, float3 value)
+{
+  this->fill_elements(index, (void *)&value);
+}
+
+void EmitTarget::fill_float3(StringRef name, float3 value)
+{
+  uint index = m_attributes_info.attribute_index(name);
+  this->fill_float3(index, value);
+}
+
 }  // namespace BParticles
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 7ddced9956d..e3071f4547f 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -89,6 +89,13 @@ class EmitTarget {
   void set_float3(uint index, ArrayRef<float3> data);
   void set_float3(StringRef name, ArrayRef<float3> data);
 
+  void fill_byte(uint index, uint8_t value);
+  void fill_byte(StringRef name, uint8_t value);
+  void fill_float(uint index, float value);
+  void fill_float(StringRef name, float value);
+  void fill_float3(uint index, float3 value);
+  void fill_float3(StringRef name, float3 value);
+
   ArrayRef<ParticlesBlock *> blocks()
   {
     return m_blocks;
@@ -116,6 +123,7 @@ class EmitTarget {
 
  private:
   void set_elements(uint index, void *data);
+  void fill_elements(uint index, void *value);
 };
 
 class EmitterInterface {
diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index 73cdafb52b4..34a788be04d 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -25,6 +25,7 @@ class PointEmitter : public Emitter {
     auto attributes = interface.request(0, 1);
     attributes.set_float3("Position", {m_point});
     attributes.set_float3("Velocity", {float3{-1, -1, 0}});
+    attributes.fill_float("Birth Factor", 1.0f);
   }
 };
 
@@ -72,6 +73,7 @@ class SurfaceEmitter : public Emitter {
     auto target = interface.request(m_particle_type_id, positions.size());
     target.set_float3("Position", positions);
     target.set_float3("Velocity", velocities);
+    target.fill_float("Birth Factor", 1.0f);
   }
 };
 
@@ -103,6 +105,7 @@ class PathEmitter : public Emitter {
     auto target = interface.request(0, positions.size());
     target.set_float3("Position", positions);
     target.set_float3("Velocity", SmallVector<float3>(positions.size()));
+    target.fill_float("Birth Factor", 1.0f);
   }
 };
 
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 82e104b6a64..696d9f6b8fc 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -387,12 +387,11 @@ BLI_NOINLINE static void emit_new_particles_from_emitter(StepDescription &descri
       Range<uint> range = target.ranges()[part];
       AttributeArrays attributes = block.slice(range);
 
-      attributes.get_byte("Kill State").fill(0);
-
       auto birth_times = attributes.get_float("Birth Time");
-      for (float &birth_time : birth_times) {
-        float fac = (rand() % 1000) / 1000.0f;
-        birth_time = time_span.interpolate(fac);
+      auto birth_factors = attributes.get_float("Birth Factor");
+
+      for (uint i = 0; i < birth_factors.size(); i++) {
+        birth_times[i] = time_span.interpolate(birth_factors[i]);
       }
 
       SmallVector<float> initial_step_durations;
@@ -439,7 +438,8 @@ BLI_NOINLINE static void ensure_required_containers_exist(
 BLI_NOINLINE static AttributesInfo build_attribute_info_for_type(ParticleType &UNUSED(type),
                                                                  AttributesInfo &UNUSED(last_info))
 {
-  AttributesInfo new_info{{"Kill State"}, {"Birth Time"}, {"Position", "Velocity"}};
+  AttributesInfo new_info{
+      {"Kill State"}, {"Birth Time", "Birth Factor"}, {"Position", "Velocity"}};
   return new_info;
 }



More information about the Bf-blender-cvs mailing list