[Bf-blender-cvs] [74bdbb94e5c] functions: add integer attribute type

Jacques Lucke noreply at git.blender.org
Mon Jul 29 17:57:41 CEST 2019


Commit: 74bdbb94e5c94f332b42ea42e25195485f8504d8
Author: Jacques Lucke
Date:   Mon Jul 29 15:48:59 2019 +0200
Branches: functions
https://developer.blender.org/rB74bdbb94e5c94f332b42ea42e25195485f8504d8

add integer attribute type

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

M	source/blender/simulations/bparticles/attributes.cpp
M	source/blender/simulations/bparticles/attributes.hpp
M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/particle_set.cpp
M	source/blender/simulations/bparticles/particle_set.hpp
M	source/blender/simulations/bparticles/particles_container.cpp
M	source/blender/simulations/bparticles/particles_container.hpp

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

diff --git a/source/blender/simulations/bparticles/attributes.cpp b/source/blender/simulations/bparticles/attributes.cpp
index 76d91b09aa4..dfa8e53f467 100644
--- a/source/blender/simulations/bparticles/attributes.cpp
+++ b/source/blender/simulations/bparticles/attributes.cpp
@@ -9,6 +9,11 @@ void AttributesDeclaration::join(AttributesDeclaration &other)
       m_byte_defaults.append(other.m_byte_defaults[i]);
     }
   }
+  for (uint i = 0; i < other.m_integer_names.size(); i++) {
+    if (m_integer_names.add(other.m_integer_names[i])) {
+      m_integer_defaults.append(other.m_integer_defaults[i]);
+    }
+  }
   for (uint i = 0; i < other.m_float_names.size(); i++) {
     if (m_float_names.add(other.m_float_names[i])) {
       m_float_defaults.append(other.m_float_defaults[i]);
@@ -28,6 +33,11 @@ void AttributesDeclaration::join(AttributesInfo &other)
       m_byte_defaults.append(*(uint8_t *)other.default_value_ptr(i));
     }
   }
+  for (uint i : other.integer_attributes()) {
+    if (m_integer_names.add(other.name_of(i).to_std_string())) {
+      m_integer_defaults.append(*(uint8_t *)other.default_value_ptr(i));
+    }
+  }
   for (uint i : other.float_attributes()) {
     if (m_float_names.add(other.name_of(i).to_std_string())) {
       m_float_defaults.append(*(float *)other.default_value_ptr(i));
@@ -42,41 +52,51 @@ void AttributesDeclaration::join(AttributesInfo &other)
 
 AttributesInfo::AttributesInfo(AttributesDeclaration &builder)
     : AttributesInfo(builder.m_byte_names,
+                     builder.m_integer_names,
                      builder.m_float_names,
                      builder.m_float3_names,
                      builder.m_byte_defaults,
+                     builder.m_integer_defaults,
                      builder.m_float_defaults,
                      builder.m_float3_defaults)
 {
 }
 
 AttributesInfo::AttributesInfo(ArrayRef<std::string> byte_names,
+                               ArrayRef<std::string> integer_names,
                                ArrayRef<std::string> float_names,
                                ArrayRef<std::string> float3_names,
                                ArrayRef<uint8_t> byte_defaults,
+                               ArrayRef<int32_t> integer_defaults,
                                ArrayRef<float> float_defaults,
                                ArrayRef<float3> float3_defaults)
 {
   BLI_assert(byte_names.size() == byte_defaults.size());
+  BLI_assert(integer_names.size() == integer_defaults.size());
   BLI_assert(float_names.size() == float_defaults.size());
   BLI_assert(float3_names.size() == float3_defaults.size());
 
   m_indices = {};
   m_indices.add_multiple_new(byte_names);
+  m_indices.add_multiple_new(integer_names);
   m_indices.add_multiple_new(float_names);
   m_indices.add_multiple_new(float3_names);
-  BLI_assert(m_indices.size() == byte_names.size() + float_names.size() + float3_names.size());
+  BLI_assert(m_indices.size() ==
+             byte_names.size() + integer_names.size() + float_names.size() + float3_names.size());
 
   m_byte_attributes = Range<uint>(0, byte_names.size());
-  m_float_attributes = m_byte_attributes.after(float_names.size());
+  m_integer_attributes = m_byte_attributes.after(integer_names.size());
+  m_float_attributes = m_integer_attributes.after(float_names.size());
   m_float3_attributes = m_float_attributes.after(float3_names.size());
 
   m_types = {};
   m_types.append_n_times(AttributeType::Byte, m_byte_attributes.size());
+  m_types.append_n_times(AttributeType::Integer, m_integer_attributes.size());
   m_types.append_n_times(AttributeType::Float, m_float_attributes.size());
   m_types.append_n_times(AttributeType::Float3, m_float3_attributes.size());
 
   m_byte_defaults = byte_defaults;
+  m_integer_defaults = integer_defaults;
   m_float_defaults = float_defaults;
   m_float3_defaults = float3_defaults;
 }
diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp
index 84ff48aceee..e147d49bf40 100644
--- a/source/blender/simulations/bparticles/attributes.hpp
+++ b/source/blender/simulations/bparticles/attributes.hpp
@@ -29,6 +29,7 @@ using BLI::Vector;
  */
 enum AttributeType {
   Byte,
+  Integer,
   Float,
   Float3,
 };
@@ -43,6 +44,8 @@ inline uint size_of_attribute_type(AttributeType type)
   switch (type) {
     case AttributeType::Byte:
       return sizeof(uint8_t);
+    case AttributeType::Integer:
+      return sizeof(int32_t);
     case AttributeType::Float:
       return sizeof(float);
     case AttributeType::Float3:
@@ -58,9 +61,11 @@ class AttributesInfo;
 class AttributesDeclaration {
  private:
   SetVector<std::string> m_byte_names;
+  SetVector<std::string> m_integer_names;
   SetVector<std::string> m_float_names;
   SetVector<std::string> m_float3_names;
   Vector<uint8_t> m_byte_defaults;
+  Vector<int32_t> m_integer_defaults;
   Vector<float> m_float_defaults;
   Vector<float3> m_float3_defaults;
 
@@ -70,6 +75,7 @@ class AttributesDeclaration {
   AttributesDeclaration() = default;
 
   void add_byte(StringRef name, uint8_t default_value);
+  void add_integer(StringRef name, int32_t default_value);
   void add_float(StringRef name, float default_value);
   void add_float3(StringRef name, float3 default_value);
 
@@ -88,12 +94,14 @@ class AttributesDeclaration {
 class AttributesInfo {
  private:
   Range<uint> m_byte_attributes;
+  Range<uint> m_integer_attributes;
   Range<uint> m_float_attributes;
   Range<uint> m_float3_attributes;
   Vector<AttributeType> m_types;
   SetVector<std::string> m_indices;
 
   Vector<uint8_t> m_byte_defaults;
+  Vector<int32_t> m_integer_defaults;
   Vector<float> m_float_defaults;
   Vector<float3> m_float3_defaults;
 
@@ -101,9 +109,11 @@ class AttributesInfo {
   AttributesInfo() = default;
   AttributesInfo(AttributesDeclaration &builder);
   AttributesInfo(ArrayRef<std::string> byte_names,
+                 ArrayRef<std::string> integer_names,
                  ArrayRef<std::string> float_names,
                  ArrayRef<std::string> float3_names,
                  ArrayRef<uint8_t> byte_defaults,
+                 ArrayRef<int32_t> integer_defaults,
                  ArrayRef<float> float_defaults,
                  ArrayRef<float3> float3_defaults);
 
@@ -206,6 +216,14 @@ class AttributesInfo {
     return m_byte_attributes;
   }
 
+  /**
+   * Get a range with all integer attribute indices.
+   */
+  Range<uint> integer_attributes() const
+  {
+    return m_integer_attributes;
+  }
+
   /**
    * Get a range with all float attribute indices.
    */
@@ -232,6 +250,8 @@ class AttributesInfo {
     switch (type) {
       case AttributeType::Byte:
         return (void *)&m_byte_defaults[index - m_byte_attributes.first()];
+      case AttributeType::Integer:
+        return (void *)&m_integer_defaults[index - m_integer_attributes.first()];
       case AttributeType::Float:
         return (void *)&m_float_defaults[index - m_float_attributes.first()];
       case AttributeType::Float3:
@@ -376,6 +396,8 @@ class AttributeArrays {
    */
   ArrayRef<uint8_t> get_byte(uint index) const;
   ArrayRef<uint8_t> get_byte(StringRef name);
+  ArrayRef<int32_t> get_integer(uint index) const;
+  ArrayRef<int32_t> get_integer(StringRef name);
   ArrayRef<float> get_float(uint index) const;
   ArrayRef<float> get_float(StringRef name);
   ArrayRef<float3> get_float3(uint index) const;
@@ -386,6 +408,7 @@ class AttributeArrays {
    * Does not assert when the attribute does not exist.
    */
   Optional<ArrayRef<uint8_t>> try_get_byte(StringRef name);
+  Optional<ArrayRef<int32_t>> try_get_integer(StringRef name);
   Optional<ArrayRef<float>> try_get_float(StringRef name);
   Optional<ArrayRef<float3>> try_get_float3(StringRef name);
 
@@ -410,6 +433,13 @@ inline void AttributesDeclaration::add_byte(StringRef name, uint8_t default_valu
   }
 }
 
+inline void AttributesDeclaration::add_integer(StringRef name, int32_t default_value)
+{
+  if (m_integer_names.add(name.to_std_string())) {
+    m_integer_defaults.append(default_value);
+  }
+}
+
 inline void AttributesDeclaration::add_float(StringRef name, float default_value)
 {
   if (m_float_names.add(name.to_std_string())) {
@@ -522,6 +552,17 @@ inline ArrayRef<uint8_t> AttributeArrays::get_byte(StringRef name)
   return this->get_byte(this->attribute_index(name));
 }
 
+inline ArrayRef<int32_t> AttributeArrays::get_integer(uint index) const
+{
+  BLI_assert(m_core.get_type(index) == AttributeType::Byte);
+  return ArrayRef<int32_t>((int32_t *)m_core.get_ptr(index) + m_start, m_size);
+}
+
+inline ArrayRef<int32_t> AttributeArrays::get_integer(StringRef name)
+{
+  return this->get_integer(this->attribute_index(name));
+}
+
 inline ArrayRef<float> AttributeArrays::get_float(uint index) const
 {
   BLI_assert(m_core.get_type(index) == AttributeType::Float);
@@ -555,6 +596,17 @@ inline Optional<ArrayRef<uint8_t>> AttributeArrays::try_get_byte(StringRef name)
   }
 }
 
+inline Optional<ArrayRef<int32_t>> AttributeArrays::try_get_integer(StringRef name)
+{
+  int index = this->info().attribute_index_try(name, AttributeType::Integer);
+  if (index == -1) {
+    return {};
+  }
+  else {
+    return this->get_integer((uint)index);
+  }
+}
+
 inline Optional<ArrayRef<float>> AttributeArrays::try_get_float(StringRef name)
 {
   int index = this->info().attribute_index_try(name, AttributeType::Float);
diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index db3c52e0836..ca90d67e644 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -16,6 +16,7 @@ namespace BParticles {
 
 using FN::Types::SharedFloat3List;
 using FN::Types::SharedFloatList;
+using FN::Types::SharedInt32List;
 
 static float random_float()
 {
@@ -140,8 +141,10 @@ void CustomFunctionEmitter::emit(EmitterInterface &interface)
 
   auto &float_list_type = FN::Types::GET_TYPE_float_list();
   auto &float3_list_type = FN::Types::GET_TYPE_float3_list();
+  auto &int32_list_type = FN::Types::GET_TYPE_int32_list();
   auto &float_type = FN::Types::GET_TYPE_float();
   auto &float3_ty

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list