[Bf-blender-cvs] [c23ee6d7b4d] master: Cleanup: Simplify operating on multiple geometry components

Hans Goudey noreply at git.blender.org
Thu Feb 24 20:02:43 CET 2022


Commit: c23ee6d7b4d6665aed4d0440153f0b1e80b77c8b
Author: Hans Goudey
Date:   Thu Feb 24 14:02:32 2022 -0500
Branches: master
https://developer.blender.org/rBc23ee6d7b4d6665aed4d0440153f0b1e80b77c8b

Cleanup: Simplify operating on multiple geometry components

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

M	source/blender/nodes/geometry/nodes/node_geo_attribute_remove.cc
M	source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
M	source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc

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

diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_remove.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_remove.cc
index 6424fccbe04..cb7132d5ea2 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_remove.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_remove.cc
@@ -33,25 +33,18 @@ static void node_geo_exec(GeoNodeExecParams params)
   GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
   Vector<std::string> attribute_names = params.extract_multi_input<std::string>("Attribute");
 
-  if (geometry_set.has<MeshComponent>()) {
-    remove_attribute(
-        geometry_set.get_component_for_write<MeshComponent>(), params, attribute_names);
-  }
-  if (geometry_set.has<PointCloudComponent>()) {
-    remove_attribute(
-        geometry_set.get_component_for_write<PointCloudComponent>(), params, attribute_names);
-  }
-  if (geometry_set.has<CurveComponent>()) {
-    remove_attribute(
-        geometry_set.get_component_for_write<CurveComponent>(), params, attribute_names);
-  }
-  if (geometry_set.has<InstancesComponent>()) {
-    remove_attribute(
-        geometry_set.get_component_for_write<InstancesComponent>(), params, attribute_names);
+  for (const GeometryComponentType type : {GEO_COMPONENT_TYPE_MESH,
+                                           GEO_COMPONENT_TYPE_POINT_CLOUD,
+                                           GEO_COMPONENT_TYPE_CURVE,
+                                           GEO_COMPONENT_TYPE_INSTANCES}) {
+    if (geometry_set.has(type)) {
+      remove_attribute(geometry_set.get_component_for_write(type), params, attribute_names);
+    }
   }
 
   params.set_output("Geometry", geometry_set);
 }
+
 }  // namespace blender::nodes::node_geo_attribute_remove_cc
 
 void register_node_type_geo_attribute_remove()
diff --git a/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc b/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
index df6d10991fb..61f719ade4e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
@@ -195,35 +195,24 @@ static void node_geo_exec(GeoNodeExecParams params)
   geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
     InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
 
+    const Array<GeometryComponentType> types{
+        GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE};
+
     Map<AttributeIDRef, AttributeKind> attributes_to_propagate;
     geometry_set.gather_attributes_for_propagation(
-        {GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE},
-        GEO_COMPONENT_TYPE_INSTANCES,
-        false,
-        attributes_to_propagate);
+        types, GEO_COMPONENT_TYPE_INSTANCES, false, attributes_to_propagate);
     attributes_to_propagate.remove("position");
 
-    if (geometry_set.has<MeshComponent>()) {
-      add_instances_from_component(instances,
-                                   *geometry_set.get_component_for_read<MeshComponent>(),
-                                   instance,
-                                   params,
-                                   attributes_to_propagate);
-    }
-    if (geometry_set.has<PointCloudComponent>()) {
-      add_instances_from_component(instances,
-                                   *geometry_set.get_component_for_read<PointCloudComponent>(),
-                                   instance,
-                                   params,
-                                   attributes_to_propagate);
-    }
-    if (geometry_set.has<CurveComponent>()) {
-      add_instances_from_component(instances,
-                                   *geometry_set.get_component_for_read<CurveComponent>(),
-                                   instance,
-                                   params,
-                                   attributes_to_propagate);
+    for (const GeometryComponentType type : types) {
+      if (geometry_set.has(type)) {
+        add_instances_from_component(instances,
+                                     *geometry_set.get_component_for_read(type),
+                                     instance,
+                                     params,
+                                     attributes_to_propagate);
+      }
     }
+
     geometry_set.keep_only({GEO_COMPONENT_TYPE_INSTANCES});
   });
 
diff --git a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
index 1731ba64b97..c99b51ffd4c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
@@ -198,17 +198,12 @@ static void initialize_volume_component_from_points(GeoNodeExecParams &params,
   Vector<float3> positions;
   Vector<float> radii;
 
-  if (r_geometry_set.has<MeshComponent>()) {
-    gather_point_data_from_component(
-        params, *r_geometry_set.get_component_for_read<MeshComponent>(), positions, radii);
-  }
-  if (r_geometry_set.has<PointCloudComponent>()) {
-    gather_point_data_from_component(
-        params, *r_geometry_set.get_component_for_read<PointCloudComponent>(), positions, radii);
-  }
-  if (r_geometry_set.has<CurveComponent>()) {
-    gather_point_data_from_component(
-        params, *r_geometry_set.get_component_for_read<CurveComponent>(), positions, radii);
+  for (const GeometryComponentType type :
+       {GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE}) {
+    if (r_geometry_set.has(type)) {
+      gather_point_data_from_component(
+          params, *r_geometry_set.get_component_for_read(type), positions, radii);
+    }
   }
 
   const float max_radius = *std::max_element(radii.begin(), radii.end());



More information about the Bf-blender-cvs mailing list