[Bf-blender-cvs] [d25ab68cf4b] master: Cleanup: Complete earlier geometry component refactor

Hans Goudey noreply at git.blender.org
Mon Mar 8 22:32:02 CET 2021


Commit: d25ab68cf4b28c01281dd689a3926887fa7d32a4
Author: Hans Goudey
Date:   Mon Mar 8 16:31:51 2021 -0500
Branches: master
https://developer.blender.org/rBd25ab68cf4b28c01281dd689a3926887fa7d32a4

Cleanup: Complete earlier geometry component refactor

This was meant to be part of rB9ce950daabbf, but the change dropped from
the set at some point in the process of updating and committing.
Sorry for the noise.

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

M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/geometry_set.cc

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index c954d0670f0..310ac6c4903 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -131,6 +131,10 @@ set(SRC
   intern/fmodifier.c
   intern/font.c
   intern/freestyle.c
+  intern/geometry_component_instances.cc
+  intern/geometry_component_mesh.cc
+  intern/geometry_component_pointcloud.cc
+  intern/geometry_component_volume.cc
   intern/geometry_set.cc
   intern/geometry_set_instances.cc
   intern/gpencil.c
@@ -430,6 +434,7 @@ set(SRC
   nla_private.h
   particle_private.h
   tracking_private.h
+  intern/attribute_access_intern.hh
   intern/CCGSubSurf.h
   intern/CCGSubSurf_inline.h
   intern/CCGSubSurf_intern.h
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index b04af5327ca..01a1333c3ce 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -37,6 +37,8 @@
 
 #include "NOD_node_tree_multi_function.hh"
 
+#include "attribute_access_intern.hh"
+
 static CLG_LogRef LOG = {"bke.attribute_access"};
 
 using blender::float3;
@@ -47,9 +49,6 @@ using blender::bke::ReadAttributePtr;
 using blender::bke::WriteAttributePtr;
 using blender::fn::GMutableSpan;
 
-/* Can't include BKE_object_deform.h right now, due to an enum forward declaration.  */
-extern "C" MDeformVert *BKE_object_defgroup_data_create(ID *id);
-
 namespace blender::bke {
 
 /* -------------------------------------------------------------------- */
@@ -159,101 +158,6 @@ void WriteAttribute::apply_span_if_necessary()
   }
 }
 
-class VertexWeightWriteAttribute final : public WriteAttribute {
- private:
-  MDeformVert *dverts_;
-  const int dvert_index_;
-
- public:
-  VertexWeightWriteAttribute(MDeformVert *dverts, const int totvert, const int dvert_index)
-      : WriteAttribute(ATTR_DOMAIN_POINT, CPPType::get<float>(), totvert),
-        dverts_(dverts),
-        dvert_index_(dvert_index)
-  {
-  }
-
-  void get_internal(const int64_t index, void *r_value) const override
-  {
-    get_internal(dverts_, dvert_index_, index, r_value);
-  }
-
-  void set_internal(const int64_t index, const void *value) override
-  {
-    MDeformWeight *weight = BKE_defvert_ensure_index(&dverts_[index], dvert_index_);
-    weight->weight = *reinterpret_cast<const float *>(value);
-  }
-
-  static void get_internal(const MDeformVert *dverts,
-                           const int dvert_index,
-                           const int64_t index,
-                           void *r_value)
-  {
-    if (dverts == nullptr) {
-      *(float *)r_value = 0.0f;
-      return;
-    }
-    const MDeformVert &dvert = dverts[index];
-    for (const MDeformWeight &weight : Span(dvert.dw, dvert.totweight)) {
-      if (weight.def_nr == dvert_index) {
-        *(float *)r_value = weight.weight;
-        return;
-      }
-    }
-    *(float *)r_value = 0.0f;
-  }
-};
-
-class VertexWeightReadAttribute final : public ReadAttribute {
- private:
-  const MDeformVert *dverts_;
-  const int dvert_index_;
-
- public:
-  VertexWeightReadAttribute(const MDeformVert *dverts, const int totvert, const int dvert_index)
-      : ReadAttribute(ATTR_DOMAIN_POINT, CPPType::get<float>(), totvert),
-        dverts_(dverts),
-        dvert_index_(dvert_index)
-  {
-  }
-
-  void get_internal(const int64_t index, void *r_value) const override
-  {
-    VertexWeightWriteAttribute::get_internal(dverts_, dvert_index_, index, r_value);
-  }
-};
-
-template<typename T> class ArrayWriteAttribute final : public WriteAttribute {
- private:
-  MutableSpan<T> data_;
-
- public:
-  ArrayWriteAttribute(AttributeDomain domain, MutableSpan<T> data)
-      : WriteAttribute(domain, CPPType::get<T>(), data.size()), data_(data)
-  {
-  }
-
-  void get_internal(const int64_t index, void *r_value) const override
-  {
-    new (r_value) T(data_[index]);
-  }
-
-  void set_internal(const int64_t index, const void *value) override
-  {
-    data_[index] = *reinterpret_cast<const T *>(value);
-  }
-
-  void initialize_span(const bool UNUSED(write_only)) override
-  {
-    array_buffer_ = data_.data();
-    array_is_temporary_ = false;
-  }
-
-  void apply_span_if_necessary() override
-  {
-    /* Do nothing, because the span contains the attribute itself already. */
-  }
-};
-
 /* This is used by the #OutputAttributePtr class. */
 class TemporaryWriteAttribute final : public WriteAttribute {
  public:
@@ -302,135 +206,6 @@ class TemporaryWriteAttribute final : public WriteAttribute {
   }
 };
 
-template<typename T> class ArrayReadAttribute final : public ReadAttribute {
- private:
-  Span<T> data_;
-
- public:
-  ArrayReadAttribute(AttributeDomain domain, Span<T> data)
-      : ReadAttribute(domain, CPPType::get<T>(), data.size()), data_(data)
-  {
-  }
-
-  void get_internal(const int64_t index, void *r_value) const override
-  {
-    new (r_value) T(data_[index]);
-  }
-
-  void initialize_span() const override
-  {
-    /* The data will not be modified, so this const_cast is fine. */
-    array_buffer_ = const_cast<T *>(data_.data());
-    array_is_temporary_ = false;
-  }
-};
-
-template<typename T> class OwnedArrayReadAttribute final : public ReadAttribute {
- private:
-  Array<T> data_;
-
- public:
-  OwnedArrayReadAttribute(AttributeDomain domain, Array<T> data)
-      : ReadAttribute(domain, CPPType::get<T>(), data.size()), data_(std::move(data))
-  {
-  }
-
-  void get_internal(const int64_t index, void *r_value) const override
-  {
-    new (r_value) T(data_[index]);
-  }
-
-  void initialize_span() const override
-  {
-    /* The data will not be modified, so this const_cast is fine. */
-    array_buffer_ = const_cast<T *>(data_.data());
-    array_is_temporary_ = false;
-  }
-};
-
-template<typename StructT,
-         typename ElemT,
-         ElemT (*GetFunc)(const StructT &),
-         void (*SetFunc)(StructT &, const ElemT &)>
-class DerivedArrayWriteAttribute final : public WriteAttribute {
- private:
-  MutableSpan<StructT> data_;
-
- public:
-  DerivedArrayWriteAttribute(AttributeDomain domain, MutableSpan<StructT> data)
-      : WriteAttribute(domain, CPPType::get<ElemT>(), data.size()), data_(data)
-  {
-  }
-
-  void get_internal(const int64_t index, void *r_value) const override
-  {
-    const StructT &struct_value = data_[index];
-    const ElemT value = GetFunc(struct_value);
-    new (r_value) ElemT(value);
-  }
-
-  void set_internal(const int64_t index, const void *value) override
-  {
-    StructT &struct_value = data_[index];
-    const ElemT &typed_value = *reinterpret_cast<const ElemT *>(value);
-    SetFunc(struct_value, typed_value);
-  }
-};
-
-template<typename StructT, typename ElemT, ElemT (*GetFunc)(const StructT &)>
-class DerivedArrayReadAttribute final : public ReadAttribute {
- private:
-  Span<StructT> data_;
-
- public:
-  DerivedArrayReadAttribute(AttributeDomain domain, Span<StructT> data)
-      : ReadAttribute(domain, CPPType::get<ElemT>(), data.size()), data_(data)
-  {
-  }
-
-  void get_internal(const int64_t index, void *r_value) const override
-  {
-    const StructT &struct_value = data_[index];
-    const ElemT value = GetFunc(struct_value);
-    new (r_value) ElemT(value);
-  }
-};
-
-class ConstantReadAttribute final : public ReadAttribute {
- private:
-  void *value_;
-
- public:
-  ConstantReadAttribute(AttributeDomain domain,
-                        const int64_t size,
-                        const CPPType &type,
-                        const void *value)
-      : ReadAttribute(domain, type, size)
-  {
-    value_ = MEM_mallocN_aligned(type.size(), type.alignment(), __func__);
-    type.copy_to_uninitialized(value, value_);
-  }
-
-  ~ConstantReadAttribute() override
-  {
-    this->cpp_type_.destruct(value_);
-    MEM_freeN(value_);
-  }
-
-  void get_internal(const int64_t UNUSED(index), void *r_value) const override
-  {
-    this->cpp_type_.copy_to_uninitialized(value_, r_value);
-  }
-
-  void initialize_span() const override
-  {
-    const int element_size = cpp_type_.size();
-    array_buffer_ = MEM_mallocN_aligned(size_ * element_size, cpp_type_.alignment(), __func__);
-    array_is_temporary_ = true;
-    cpp_type_.fill_uninitialized(value_, array_buffer_, size_);
-  }
-};
-
 class ConvertedReadAttribute final : public ReadAttribute {
  private:
   const CPPType &from_type_;
@@ -499,1120 +274,414 @@ CustomDataType cpp_type_to_custom_data_type(const blender::fn::CPPType &type)
   if (type.is<bool>()) {
     return CD_PROP_BOOL;
   }
-  return static_cast<CustomDataType>(-1);
-}
-
-static int attribute_data_type_complexity(const CustomDataType data_type)
-{
-  switch (data_type) {
-    case CD_PROP_BOOL:
-      return 0;
-    case CD_PROP_INT32:
-      return 1;
-    case CD_PROP_FLOAT:
-      return 2;
-    case CD_PROP_FLOAT2:
-      return 3;
-    case CD_PROP_FLOAT3:
-      return 4;
-    case CD_PROP_COLOR:
-      return 5;
-#if 0 /* These attribute types are not supported yet. */
-    case CD_MLOOPCOL:
-      return 3;
-    case CD_PROP_STRING:
-      return 6;
-#endif
-    default:
-      /* Only accept "generic" custom data types used by the attribute system. */
-      BLI_assert(false);
-      return 0;
-  }
-}
-
-CustomDataType attribute_data_type_highest_complexity(Span<CustomDataType> data_types)
-{
-  int highest_complexity = INT_MIN;
-  CustomDataType most_complex_type = CD_PROP_COLOR;
-
-  for (const CustomDataType data_type : data_types) {
-    const int complexity = attribute_data_type_complexity(data_type);
-    if (complexity > highest_complexity) {
-      highest_complexity = complexity;
-      most_complex_type = data_type;
-    }
-  }
-
-  return most_complex_type;
-}
-
-/**
- * \note Generally the order should mirror the order of the domains
- * established in each component's ComponentAttributeProviders.
- */
-static int attribute_domain_priority(const AttributeDomain domain)
-{
-  switch (domain) {
-#if 0
-    case ATTR_DOMAIN_CURVE:
-      return 0;
-#endif
-    case ATTR_DOMAIN_POLYGON:
-      return 1;
-    case ATTR_DOMAIN_EDGE:
-      return 2;
-    case ATTR_DOMAIN_POINT:
-    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list