[Bf-blender-cvs] [37da2b60fe1] virtual-array-attributes: progress

Jacques Lucke noreply at git.blender.org
Mon Apr 12 18:27:56 CEST 2021


Commit: 37da2b60fe1e64884872cbc1e2282a5cab7c3ba6
Author: Jacques Lucke
Date:   Mon Apr 12 17:20:26 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rB37da2b60fe1e64884872cbc1e2282a5cab7c3ba6

progress

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

M	source/blender/blenkernel/intern/geometry_component_mesh.cc

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

diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index df451b5db1d..3b3b8b0e588 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -32,7 +32,7 @@
 /* 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);
 
-using blender::bke::ReadAttributePtr;
+using blender::fn::GVArray;
 
 /* -------------------------------------------------------------------- */
 /** \name Geometry Component Implementation
@@ -201,14 +201,14 @@ namespace blender::bke {
 
 template<typename T>
 static void adapt_mesh_domain_corner_to_point_impl(const Mesh &mesh,
-                                                   const TypedReadAttribute<T> &attribute,
+                                                   const VArray<T> &old_values,
                                                    MutableSpan<T> r_values)
 {
   BLI_assert(r_values.size() == mesh.totvert);
   attribute_math::DefaultMixer<T> mixer(r_values);
 
   for (const int loop_index : IndexRange(mesh.totloop)) {
-    const T value = attribute[loop_index];
+    const T value = old_values[loop_index];
     const MLoop &loop = mesh.mloop[loop_index];
     const int point_index = loop.v;
     mixer.mix_in(point_index, value);
@@ -216,43 +216,42 @@ static void adapt_mesh_domain_corner_to_point_impl(const Mesh &mesh,
   mixer.finalize();
 }
 
-static ReadAttributePtr adapt_mesh_domain_corner_to_point(const Mesh &mesh,
-                                                          ReadAttributePtr attribute)
+static std::unique_ptr<GVArray> adapt_mesh_domain_corner_to_point(const Mesh &mesh,
+                                                                  std::unique_ptr<GVArray> varray)
 {
-  ReadAttributePtr new_attribute;
-  const CustomDataType data_type = attribute->custom_data_type();
+  std::unique_ptr<GVArray> new_varray;
+  const CustomDataType data_type = cpp_type_to_custom_data_type(varray->type());
   attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
     using T = decltype(dummy);
     if constexpr (!std::is_void_v<attribute_math::DefaultMixer<T>>) {
       /* We compute all interpolated values at once, because for this interpolation, one has to
        * iterate over all loops anyway. */
       Array<T> values(mesh.totvert);
-      adapt_mesh_domain_corner_to_point_impl<T>(mesh, *attribute, values);
-      new_attribute = std::make_unique<OwnedArrayReadAttribute<T>>(ATTR_DOMAIN_POINT,
-                                                                   std::move(values));
+      adapt_mesh_domain_corner_to_point_impl<T>(mesh, *fn::GVArray_Typed<T>{varray}, values);
+      new_varray = std::make_unique<fn::GVArray_For_ArrayContainer<Array<T>>>(std::move(values));
     }
   });
-  return new_attribute;
+  return new_varray;
 }
 
 template<typename T>
 static void adapt_mesh_domain_point_to_corner_impl(const Mesh &mesh,
-                                                   const TypedReadAttribute<T> &attribute,
+                                                   const VArray<T> &old_values,
                                                    MutableSpan<T> r_values)
 {
   BLI_assert(r_values.size() == mesh.totloop);
 
   for (const int loop_index : IndexRange(mesh.totloop)) {
     const int vertex_index = mesh.mloop[loop_index].v;
-    r_values[loop_index] = attribute[vertex_index];
+    r_values[loop_index] = old_values[vertex_index];
   }
 }
 
-static ReadAttributePtr adapt_mesh_domain_point_to_corner(const Mesh &mesh,
-                                                          ReadAttributePtr attribute)
+static std::unique_ptr<GVArray> adapt_mesh_domain_point_to_corner(const Mesh &mesh,
+                                                                  std::unique_ptr<GVArray> varray)
 {
-  ReadAttributePtr new_attribute;
-  const CustomDataType data_type = attribute->custom_data_type();
+  std::unique_ptr<GVArray> new_varray;
+  const CustomDataType data_type = cpp_type_to_custom_data_type(varray->type());
   attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
     using T = decltype(dummy);
     /* It is not strictly necessary to compute the value for all corners here. Instead one could
@@ -260,11 +259,10 @@ static ReadAttributePtr adapt_mesh_domain_point_to_corner(const Mesh &mesh,
      * when an algorithm only accesses very few of the corner values. However, for the algorithms
      * we currently have, precomputing the array is fine. Also, it is easier to implement. */
     Array<T> values(mesh.totloop);
-    adapt_mesh_domain_point_to_corner_impl<T>(mesh, *attribute, values);
-    new_attribute = std::make_unique<OwnedArrayReadAttribute<T>>(ATTR_DOMAIN_CORNER,
-                                                                 std::move(values));
+    adapt_mesh_domain_point_to_corner_impl<T>(mesh, *fn::GVArray_Typed<T>{varray}, values);
+    new_varray = std::make_unique<fn::GVArray_For_ArrayContainer<Array<T>>>(std::move(values));
   });
-  return new_attribute;
+  return new_varray;
 }
 
 /**
@@ -291,26 +289,25 @@ static void adapt_mesh_domain_corner_to_face_impl(const Mesh &mesh,
   mixer.finalize();
 }
 
-static ReadAttributePtr adapt_mesh_domain_corner_to_face(const Mesh &mesh,
-                                                         ReadAttributePtr attribute)
+static std::unique_ptr<GVArray> adapt_mesh_domain_corner_to_face(const Mesh &mesh,
+                                                                 std::unique_ptr<GVArray> varray)
 {
-  ReadAttributePtr new_attribute;
-  const CustomDataType data_type = attribute->custom_data_type();
+  std::unique_ptr<GVArray> new_varray;
+  const CustomDataType data_type = cpp_type_to_custom_data_type(varray->type());
   attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
     using T = decltype(dummy);
     if constexpr (!std::is_void_v<attribute_math::DefaultMixer<T>>) {
       Array<T> values(mesh.totpoly);
-      adapt_mesh_domain_corner_to_face_impl<T>(mesh, attribute->get_span<T>(), values);
-      new_attribute = std::make_unique<OwnedArrayReadAttribute<T>>(ATTR_DOMAIN_POINT,
-                                                                   std::move(values));
+      adapt_mesh_domain_corner_to_face_impl<T>(mesh, *fn::GVArray_Typed<T>{varray}, values);
+      new_varray = std::make_unique<fn::GVArray_For_ArrayContainer<Array<T>>>(std::move(values));
     }
   });
-  return new_attribute;
+  return new_varray;
 }
 
 template<typename T>
 static void adapt_mesh_domain_corner_to_edge_impl(const Mesh &mesh,
-                                                  Span<T> old_values,
+                                                  const VArray<T> old_values,
                                                   MutableSpan<T> r_values)
 {
   BLI_assert(r_values.size() == mesh.totedge);
@@ -332,21 +329,20 @@ static void adapt_mesh_domain_corner_to_edge_impl(const Mesh &mesh,
   mixer.finalize();
 }
 
-static ReadAttributePtr adapt_mesh_domain_corner_to_edge(const Mesh &mesh,
-                                                         ReadAttributePtr attribute)
+static std::unique_ptr<GVArray> adapt_mesh_domain_corner_to_edge(const Mesh &mesh,
+                                                                 std::unique_ptr<GVArray> varray)
 {
-  ReadAttributePtr new_attribute;
-  const CustomDataType data_type = attribute->custom_data_type();
+  std::unique_ptr<GVArray> new_varray;
+  const CustomDataType data_type = cpp_type_to_custom_data_type(varray->type());
   attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
     using T = decltype(dummy);
     if constexpr (!std::is_void_v<attribute_math::DefaultMixer<T>>) {
       Array<T> values(mesh.totedge);
-      adapt_mesh_domain_corner_to_edge_impl<T>(mesh, attribute->get_span<T>(), values);
-      new_attribute = std::make_unique<OwnedArrayReadAttribute<T>>(ATTR_DOMAIN_POINT,
-                                                                   std::move(values));
+      adapt_mesh_domain_corner_to_edge_impl<T>(mesh, *fn::GVArray_Typed<T>{varray}, values);
+      new_varray = std::make_unique<fn::GVArray_For_ArrayContainer<Array<T>>>(std::move(values));
     }
   });
-  return new_attribute;
+  return new_varray;
 }
 
 template<typename T>
@@ -370,26 +366,25 @@ void adapt_mesh_domain_face_to_point_impl(const Mesh &mesh,
   mixer.finalize();
 }
 
-static ReadAttributePtr adapt_mesh_domain_face_to_point(const Mesh &mesh,
-                                                        ReadAttributePtr attribute)
+static std::unique_ptr<GVArray> adapt_mesh_domain_face_to_point(const Mesh &mesh,
+                                                                std::unique_ptr<GVArray> varray)
 {
-  ReadAttributePtr new_attribute;
-  const CustomDataType data_type = attribute->custom_data_type();
+  std::unique_ptr<GVArray> new_varray;
+  const CustomDataType data_type = cpp_type_to_custom_data_type(varray->type());
   attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
     using T = decltype(dummy);
     if constexpr (!std::is_void_v<attribute_math::DefaultMixer<T>>) {
       Array<T> values(mesh.totvert);
-      adapt_mesh_domain_face_to_point_impl<T>(mesh, attribute->get_span<T>(), values);
-      new_attribute = std::make_unique<OwnedArrayReadAttribute<T>>(ATTR_DOMAIN_POINT,
-                                                                   std::move(values));
+      adapt_mesh_domain_face_to_point_impl<T>(mesh, *fn::GVArray_Typed<T>{varray}, values);
+      new_varray = std::make_unique<fn::GVArray_For_ArrayContainer<Array<T>>>(std::move(values));
     }
   });
-  return new_attribute;
+  return new_varray;
 }
 
 template<typename T>
 void adapt_mesh_domain_face_to_corner_impl(const Mesh &mesh,
-                                           const Span<T> old_values,
+                                           const VArray<T> old_values,
                                            MutableSpan<T> r_values)
 {
   BLI_assert(r_values.size() == mesh.totloop);
@@ -401,26 +396,25 @

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list