diff options
author | Hans Goudey <h.goudey@me.com> | 2022-02-24 22:02:32 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-02-24 22:02:32 +0300 |
commit | c23ee6d7b4d6665aed4d0440153f0b1e80b77c8b (patch) | |
tree | e904941e0cb5e1cfb4c57be01d3d76d77725195f /source | |
parent | 5ccbbaed08dbbf9ac07017e8f8f6053ac0e1ed38 (diff) |
Cleanup: Simplify operating on multiple geometry components
Diffstat (limited to 'source')
3 files changed, 27 insertions, 50 deletions
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 ¶ms, 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()); |