Cleanup: Simplify operating on multiple geometry components

This commit is contained in:
Hans Goudey 2022-02-24 14:02:32 -05:00
parent 5ccbbaed08
commit c23ee6d7b4
3 changed files with 27 additions and 50 deletions

View File

@ -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()

View File

@ -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});
});

View File

@ -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());