[Bf-blender-cvs] [d1c39eb90f1] virtual-array-attributes: cleanup

Jacques Lucke noreply at git.blender.org
Tue Apr 13 09:01:51 CEST 2021


Commit: d1c39eb90f156d99d861ecc6f21920f5080a566c
Author: Jacques Lucke
Date:   Tue Apr 13 09:01:42 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rBd1c39eb90f156d99d861ecc6f21920f5080a566c

cleanup

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

M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc

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

diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index 7800f024201..ff823251f14 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -186,6 +186,15 @@ class GeometryComponent {
       const CustomDataType data_type,
       const void *default_value = nullptr);
 
+  template<typename T>
+  blender::bke::OutputAttribute_Typed<T> attribute_try_get_for_output(
+      const blender::StringRef attribute_name, const AttributeDomain domain)
+  {
+    const blender::fn::CPPType &cpp_type = blender::fn::CPPType::get<T>();
+    const CustomDataType data_type = blender::bke::custom_data_type_to_cpp_type(cpp_type);
+    return this->attribute_try_get_for_output(attribute_name, domain, data_type, nullptr);
+  }
+
  private:
   virtual const blender::bke::ComponentAttributeProviders *get_attribute_providers() const;
 };
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index d4a4f4d8028..c596927a941 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -35,6 +35,7 @@ namespace blender::nodes {
 
 using bke::geometry_set_realize_instances;
 using bke::OutputAttribute;
+using bke::OutputAttribute_Typed;
 using bke::PersistentDataHandleMap;
 using bke::PersistentObjectHandle;
 using bke::ReadAttributeLookup;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
index ef8a9b99d18..a412dfe2274 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
@@ -89,7 +89,7 @@ static void align_rotations_auto_pivot(const VArray<float3> &vectors,
     float3 new_rotation;
     mat3_to_eul(new_rotation, new_rotation_matrix);
 
-    rotations[i] = new_rotation;
+    rotations.set(i, new_rotation);
   }
 }
 
@@ -133,7 +133,7 @@ static void align_rotations_fixed_pivot(const VArray<float3> &vectors,
     float3 new_rotation;
     mat3_to_eul(new_rotation, new_rotation_matrix);
 
-    rotations[i] = new_rotation;
+    rotations.set(i, new_rotation);
   }
 }
 
@@ -144,14 +144,12 @@ static void align_rotations_on_component(GeometryComponent &component,
   const NodeGeometryAlignRotationToVector &storage = *(const NodeGeometryAlignRotationToVector *)
                                                           node.storage;
 
-  OutputAttribute rotations_attr = component.attribute_try_get_for_output(
-      "rotation", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
-  if (!rotations_attr) {
+  OutputAttribute_Typed<float3> rotations = component.attribute_try_get_for_output<float3>(
+      "rotation", ATTR_DOMAIN_POINT);
+  if (!rotations) {
     return;
   }
 
-  GVMutableArray_Typed<float3> rotations{*rotations_attr};
-
   GVArray_Typed<float> factors = params.get_input_attribute<float>(
       "Factor", component, ATTR_DOMAIN_POINT, 1.0f);
   GVArray_Typed<float3> vectors = params.get_input_attribute<float3>(
@@ -168,7 +166,7 @@ static void align_rotations_on_component(GeometryComponent &component,
     align_rotations_fixed_pivot(vectors, factors, local_main_axis, local_pivot_axis, *rotations);
   }
 
-  rotations_attr.save_if_necessary();
+  rotations.save_if_necessary();
 }
 
 static void geo_node_align_rotation_to_vector_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc
index acbbf6e93c3..d93c2aa00f3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc
@@ -186,7 +186,7 @@ static void clamp_attribute(GeometryComponent &component, const GeoNodeExecParam
         }
       }
       clamp_attribute<float3>(
-          attribute_input->typed<float3>(), attribute_result->typed<float3>(), min, max);
+          *attribute_input->typed<float3>(), *attribute_result->typed<float3>(), min, max);
       break;
     }
     case CD_PROP_FLOAT: {
@@ -194,11 +194,11 @@ static void clamp_attribute(GeometryComponent &component, const GeoNodeExecParam
       const float max = params.get_input<float>("Max_001");
       if (operation == NODE_CLAMP_RANGE && min > max) {
         clamp_attribute<float>(
-            attribute_input->typed<float>(), attribute_result->typed<float>(), max, min);
+            *attribute_input->typed<float>(), *attribute_result->typed<float>(), max, min);
       }
       else {
         clamp_attribute<float>(
-            attribute_input->typed<float>(), attribute_result->typed<float>(), min, max);
+            *attribute_input->typed<float>(), *attribute_result->typed<float>(), min, max);
       }
       break;
     }
@@ -207,11 +207,11 @@ static void clamp_attribute(GeometryComponent &component, const GeoNodeExecParam
       const int max = params.get_input<int>("Max_002");
       if (operation == NODE_CLAMP_RANGE && min > max) {
         clamp_attribute<int>(
-            attribute_input->typed<int>(), attribute_result->typed<int>(), max, min);
+            *attribute_input->typed<int>(), *attribute_result->typed<int>(), max, min);
       }
       else {
         clamp_attribute<int>(
-            attribute_input->typed<int>(), attribute_result->typed<int>(), min, max);
+            *attribute_input->typed<int>(), *attribute_result->typed<int>(), min, max);
       }
       break;
     }
@@ -233,7 +233,7 @@ static void clamp_attribute(GeometryComponent &component, const GeoNodeExecParam
         }
       }
       clamp_attribute<Color4f>(
-          attribute_input->typed<Color4f>(), attribute_result->typed<Color4f>(), min, max);
+          *attribute_input->typed<Color4f>(), *attribute_result->typed<Color4f>(), min, max);
       break;
     }
     default: {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
index 7d77c18b236..64fb3308149 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
@@ -71,11 +71,10 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
   /* Always output a color attribute for now. We might want to allow users to customize.
    * Using the type of an existing attribute could work, but does not have a real benefit
    * currently. */
-  const CustomDataType result_type = CD_PROP_COLOR;
   const AttributeDomain result_domain = get_result_domain(component, input_name, result_name);
 
-  OutputAttribute attribute_result = component.attribute_try_get_for_output(
-      result_name, result_domain, result_type);
+  OutputAttribute_Typed<Color4f> attribute_result =
+      component.attribute_try_get_for_output<Color4f>(result_name, result_domain);
   if (!attribute_result) {
     return;
   }
@@ -83,8 +82,7 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
   GVArray_Typed<float> attribute_in = component.attribute_get_for_read<float>(
       input_name, result_domain, 0.0f);
 
-  GVMutableArray_Typed<Color4f> results_typed{*attribute_result};
-  VMutableArray_Span<Color4f> results{results_typed};
+  VMutableArray_Span<Color4f> results{*attribute_result};
 
   ColorBand *color_ramp = &node_storage->color_ramp;
   for (const int i : IndexRange(attribute_in.size())) {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc
index 186382cc434..cc1eedce065 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc
@@ -94,8 +94,8 @@ static void combine_attributes(GeometryComponent &component, const GeoNodeExecPa
   }
   const AttributeDomain result_domain = get_result_domain(component, params, result_name);
 
-  OutputAttribute attribute_result = component.attribute_try_get_for_output(
-      result_name, result_domain, CD_PROP_FLOAT3);
+  OutputAttribute_Typed<float3> attribute_result = component.attribute_try_get_for_output<float3>(
+      result_name, result_domain);
   if (!attribute_result) {
     return;
   }
@@ -106,15 +106,12 @@ static void combine_attributes(GeometryComponent &component, const GeoNodeExecPa
   GVArray_Typed<float> attribute_z = params.get_input_attribute<float>(
       "Z", component, result_domain, 0.0f);
 
-  GVMutableArray_Typed<float3> results{*attribute_result};
-
-  for (const int i : IndexRange(results.size())) {
+  for (const int i : IndexRange(attribute_result->size())) {
     const float x = attribute_x[i];
     const float y = attribute_y[i];
     const float z = attribute_z[i];
-    results->set(i, {x, y, z});
+    attribute_result->set(i, {x, y, z});
   }
-  attribute_result.save_if_necessary();
 }
 
 static void geo_node_attribute_combine_xyz_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
index 3854f16050f..f78f19a01a3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
@@ -254,11 +254,10 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx
       node_storage->operation);
   const std::string result_name = params.get_input<std::string>("Result");
 
-  const CustomDataType result_type = CD_PROP_BOOL;
   const AttributeDomain result_domain = get_result_domain(component, params, result_name);
 
-  OutputAttribute attribute_result = component.attribute_try_get_for_output(
-      result_name, result_domain, result_type);
+  OutputAttribute_Typed<bool> attribute_result = component.attribute_try_get_for_output<bool>(
+      result_name, result_domain);
   if (!attribute_result) {
     return;
   }
@@ -275,8 +274,7 @@ static void attribute_compare_calc(GeometryComponent &component, co

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list