[Bf-blender-cvs] [30fe7038bcc] virtual-array-attributes: progress

Jacques Lucke noreply at git.blender.org
Tue Apr 13 13:25:47 CEST 2021


Commit: 30fe7038bcc3243ad1fd70db6c761438bfa0aba5
Author: Jacques Lucke
Date:   Tue Apr 13 12:53:10 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rB30fe7038bcc3243ad1fd70db6c761438bfa0aba5

progress

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

M	source/blender/blenlib/BLI_virtual_array.hh
M	source/blender/functions/FN_generic_virtual_array.hh
M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc

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

diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index ce474f80fa9..20827bfd030 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -72,6 +72,11 @@ template<typename T> class VArray {
     return size_ == 0;
   }
 
+  IndexRange index_range() const
+  {
+    return IndexRange(size_);
+  }
+
   /* Returns true when the virtual array is stored as a span internally. */
   bool is_span() const
   {
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index e94e6595fc1..afe7f6302b3 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -134,7 +134,7 @@ class GVArray {
     return (const VArray<T> *)this->try_get_internal_varray_impl();
   }
 
-  template<typename T> GVArray_Typed<T> typed()
+  template<typename T> GVArray_Typed<T> typed() const
   {
     return GVArray_Typed<T>(*this);
   }
@@ -539,6 +539,13 @@ class GVArray_Span final : public GVArray_For_GSpan {
   {
     return data_;
   }
+
+  const void *operator[](const int64_t index)
+  {
+    BLI_assert(index >= 0);
+    BLI_assert(index < size_);
+    return POINTER_OFFSET(data_, index * element_size_);
+  }
 };
 
 class GVMutableArray_Span final : public GVMutableArray_For_GMutableSpan {
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index c596927a941..5ba2281b3a7 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -46,6 +46,7 @@ using fn::GPointer;
 using fn::GValueMap;
 using fn::GVArray;
 using fn::GVArray_Typed;
+using fn::GVMutableArray;
 using fn::GVMutableArray_Typed;
 
 class GeoNodeExecParams {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
index 9d8cd3dfa82..8f956e581be 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
@@ -58,10 +58,10 @@ static void geo_node_attribute_mix_layout(uiLayout *layout, bContext *UNUSED(C),
 namespace blender::nodes {
 
 static void do_mix_operation_float(const int blend_mode,
-                                   const FloatReadAttribute &factors,
-                                   const FloatReadAttribute &inputs_a,
-                                   const FloatReadAttribute &inputs_b,
-                                   FloatWriteAttribute results)
+                                   const VArray<float> &factors,
+                                   const VArray<float> &inputs_a,
+                                   const VArray<float> &inputs_b,
+                                   VMutableArray<float> &results)
 {
   const int size = results.size();
   for (const int i : IndexRange(size)) {
@@ -75,10 +75,10 @@ static void do_mix_operation_float(const int blend_mode,
 }
 
 static void do_mix_operation_float3(const int blend_mode,
-                                    const FloatReadAttribute &factors,
-                                    const Float3ReadAttribute &inputs_a,
-                                    const Float3ReadAttribute &inputs_b,
-                                    Float3WriteAttribute results)
+                                    const VArray<float> &factors,
+                                    const VArray<float3> &inputs_a,
+                                    const VArray<float3> &inputs_b,
+                                    VMutableArray<float3> &results)
 {
   const int size = results.size();
   for (const int i : IndexRange(size)) {
@@ -91,10 +91,10 @@ static void do_mix_operation_float3(const int blend_mode,
 }
 
 static void do_mix_operation_color4f(const int blend_mode,
-                                     const FloatReadAttribute &factors,
-                                     const Color4fReadAttribute &inputs_a,
-                                     const Color4fReadAttribute &inputs_b,
-                                     Color4fWriteAttribute results)
+                                     const VArray<float> &factors,
+                                     const VArray<Color4f> &inputs_a,
+                                     const VArray<Color4f> &inputs_b,
+                                     VMutableArray<Color4f> &results)
 {
   const int size = results.size();
   for (const int i : IndexRange(size)) {
@@ -108,22 +108,31 @@ static void do_mix_operation_color4f(const int blend_mode,
 
 static void do_mix_operation(const CustomDataType result_type,
                              int blend_mode,
-                             const FloatReadAttribute &attribute_factor,
-                             const ReadAttribute &attribute_a,
-                             const ReadAttribute &attribute_b,
-                             WriteAttribute &attribute_result)
+                             const VArray<float> &attribute_factor,
+                             const GVArray &attribute_a,
+                             const GVArray &attribute_b,
+                             GVMutableArray &attribute_result)
 {
   if (result_type == CD_PROP_FLOAT) {
-    do_mix_operation_float(
-        blend_mode, attribute_factor, attribute_a, attribute_b, attribute_result);
+    do_mix_operation_float(blend_mode,
+                           attribute_factor,
+                           attribute_a.typed<float>(),
+                           attribute_b.typed<float>(),
+                           attribute_result.typed<float>());
   }
   else if (result_type == CD_PROP_FLOAT3) {
-    do_mix_operation_float3(
-        blend_mode, attribute_factor, attribute_a, attribute_b, attribute_result);
+    do_mix_operation_float3(blend_mode,
+                            attribute_factor,
+                            attribute_a.typed<float3>(),
+                            attribute_b.typed<float3>(),
+                            attribute_result.typed<float3>());
   }
   else if (result_type == CD_PROP_COLOR) {
-    do_mix_operation_color4f(
-        blend_mode, attribute_factor, attribute_a, attribute_b, attribute_result);
+    do_mix_operation_color4f(blend_mode,
+                             attribute_factor,
+                             attribute_a.typed<Color4f>(),
+                             attribute_b.typed<Color4f>(),
+                             attribute_result.typed<Color4f>());
   }
 }
 
@@ -132,9 +141,9 @@ static AttributeDomain get_result_domain(const GeometryComponent &component,
                                          StringRef result_name)
 {
   /* Use the domain of the result attribute if it already exists. */
-  ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_name);
+  ReadAttributeLookup result_attribute = component.attribute_try_get_for_read(result_name);
   if (result_attribute) {
-    return result_attribute->domain();
+    return result_attribute.domain;
   }
 
   /* Otherwise use the highest priority domain from existing input attributes, or the default. */
@@ -158,17 +167,17 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
 
   const AttributeDomain result_domain = get_result_domain(component, params, result_name);
 
-  OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
+  OutputAttribute attribute_result = component.attribute_try_get_for_output(
       result_name, result_domain, result_type);
   if (!attribute_result) {
     return;
   }
 
-  FloatReadAttribute attribute_factor = params.get_input_attribute<float>(
+  GVArray_Typed<float> attribute_factor = params.get_input_attribute<float>(
       "Factor", component, result_domain, 0.5f);
-  ReadAttributePtr attribute_a = params.get_input_attribute(
+  std::unique_ptr<GVArray> attribute_a = params.get_input_attribute(
       "A", component, result_domain, result_type, nullptr);
-  ReadAttributePtr attribute_b = params.get_input_attribute(
+  std::unique_ptr<GVArray> attribute_b = params.get_input_attribute(
       "B", component, result_domain, result_type, nullptr);
 
   do_mix_operation(result_type,
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc
index f09a9bf056e..13b0c7e2053 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc
@@ -62,7 +62,7 @@ namespace blender::nodes {
 
 static void proximity_calc(MutableSpan<float> distance_span,
                            MutableSpan<float3> location_span,
-                           Span<float3> positions,
+                           const VArray<float3> &positions,
                            BVHTreeFromMesh &tree_data_mesh,
                            BVHTreeFromPointCloud &tree_data_pointcloud,
                            const bool bvh_mesh_success,
@@ -169,19 +169,18 @@ static void attribute_calc_proximity(GeometryComponent &component,
   const AttributeDomain result_domain = ATTR_DOMAIN_POINT;
 
   const std::string distance_attribute_name = params.get_input<std::string>("Distance");
-  OutputAttributePtr distance_attribute = component.attribute_try_get_for_output(
-      distance_attribute_name, result_domain, CD_PROP_FLOAT);
+  OutputAttribute_Typed<float> distance_attribute = component.attribute_try_get_for_output<float>(
+      distance_attribute_name, result_domain);
 
   const std::string location_attribute_name = params.get_input<std::string>("Position");
-  OutputAttributePtr location_attribute = component.attribute_try_get_for_output(
-      location_attribute_name, result_domain, CD_PROP_FLOAT3);
-
-  ReadAttributePtr position_attribute = component.attribute_try_get_for_read("position");
-  BLI_assert(position_attribute->custom_data_type() == CD_PROP_FLOAT3);
+  OutputAttribute_Typed<float3> location_attribute =
+      component.attribute_try_get_for_output<float3>(location_attribute_name, result_domain);
 
+  ReadAttributeLookup position_attribute = component.attribute_try_g

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list