Commit: 6715600796c1fac720d041b3c099d27c4ab82996
Author: Jacques Lucke
Date:   Sat Jul 6 16:49:12 2019 +0200
Branches: functions
https://developer.blender.org/rB6715600796c1fac720d041b3c099d27c4ab82996

flatten float3 attribute of container

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

M       source/blender/simulations/bparticles/attributes.hpp
M       source/blender/simulations/bparticles/c_wrapper.cpp
M       source/blender/simulations/bparticles/particles_container.cpp
M       source/blender/simulations/bparticles/particles_container.hpp

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

diff --git a/source/blender/simulations/bparticles/attributes.hpp 
b/source/blender/simulations/bparticles/attributes.hpp
index 803818430a7..04fbc931828 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -103,6 +103,15 @@ class AttributesInfo {
     return m_types[index];
   }
 
+  /**
+   * Get the type of an attribute identified by its name.
+   * Asserts when the name does not exist.
+   */
+  AttributeType type_of(StringRef name) const
+  {
+    return this->type_of(this->attribute_index(name));
+  }
+
   /**
    * Get the types of all attributes. The index into the array is the index of 
the corresponding
    * attribute.
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp 
b/source/blender/simulations/bparticles/c_wrapper.cpp
index 6e669fe8abe..79243b9d9b9 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -692,9 +692,12 @@ Mesh *BParticles_test_mesh_from_state(BParticlesState 
state_c)
 {
   SCOPED_TIMER(__func__);
 
-  uint particle_count = BParticles_state_particle_count(state_c);
-  SmallVector<float3> positions(particle_count);
-  BParticles_state_get_positions(state_c, (float(*)[3])positions.begin());
+  ParticlesState &state = *unwrap(state_c);
+
+  SmallVector<float3> positions;
+  for (ParticlesContainer *container : state.particle_containers().values()) {
+    positions.extend(container->flatten_attribute_float3("Position"));
+  }
 
   return distribute_tetrahedons(positions, 0.025f);
 }
diff --git a/source/blender/simulations/bparticles/particles_container.cpp 
b/source/blender/simulations/bparticles/particles_container.cpp
index 54d2d45e70d..318ec66ec43 100644
--- a/source/blender/simulations/bparticles/particles_container.cpp
+++ b/source/blender/simulations/bparticles/particles_container.cpp
@@ -135,6 +135,14 @@ void ParticlesContainer::flatten_attribute_data(StringRef 
attribute_name, void *
   }
 }
 
+SmallVector<float3> ParticlesContainer::flatten_attribute_float3(StringRef 
attribute_name)
+{
+  BLI_assert(m_attributes_info.type_of(attribute_name) == 
AttributeType::Float3);
+  SmallVector<float3> result(this->count_active());
+  this->flatten_attribute_data(attribute_name, (void *)result.begin());
+  return result;
+}
+
 void ParticlesBlock::MoveUntilFull(ParticlesBlock &from, ParticlesBlock &to)
 {
   BLI_assert(&from.container() == &to.container());
diff --git a/source/blender/simulations/bparticles/particles_container.hpp 
b/source/blender/simulations/bparticles/particles_container.hpp
index cb34db0e4c8..a833573e134 100644
--- a/source/blender/simulations/bparticles/particles_container.hpp
+++ b/source/blender/simulations/bparticles/particles_container.hpp
@@ -79,6 +79,11 @@ class ParticlesContainer {
    */
   void flatten_attribute_data(StringRef attribute_name, void *dst);
 
+  /**
+   * Get a vector containing a a float3 attribute value from every particle.
+   */
+  SmallVector<float3> flatten_attribute_float3(StringRef attribute_name);
+
   friend bool operator==(const ParticlesContainer &a, const ParticlesContainer 
&b);
 };

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to