Geometry Nodes: Add selection and depth options to realize instances #104832

Closed
Angus Stanton wants to merge 15 commits from ab_stanton/blender:add-selection-realize-instances into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 34 additions and 18 deletions
Showing only changes of commit 242dc8a407 - Show all commits

View File

@ -10,7 +10,9 @@ namespace blender::geometry {
* Join all src_components and add the resulting component to result.
*/
template<typename Component>
void GEO_join_component_type(Span<const Component *> src_components, GeometrySet &result);
void GEO_join_component_type(Span<const Component *> src_components,
GeometrySet &result,
const bke::AnonymousAttributePropagationInfo &propagation_info);
/**
* Join InstancesComponents and apply corresponding transforms for each.

View File

@ -26,7 +26,7 @@ static Map<AttributeIDRef, AttributeMetaData> get_final_attribute_info(
for (const GeometryComponent *component : components) {
component->attributes()->for_all(
[&](const bke::AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
if (attribute_id.is_named() && ignored_attributes.contains(attribute_id.name())) {
if (ignored_attributes.contains(attribute_id.name())) {
return true;
}
if (meta_data.data_type == CD_PROP_STRING) {
@ -146,7 +146,9 @@ static void join_components(Span<const VolumeComponent *> /*src_components*/,
}
template<typename Component>
void GEO_join_component_type(Span<const Component *> src_components, GeometrySet &result)
void GEO_join_component_type(Span<const Component *> src_components,
GeometrySet &result,
const bke::AnonymousAttributePropagationInfo &propagation_info)
{
if (src_components.size() == 0) {
return;
@ -176,7 +178,8 @@ void GEO_join_component_type(Span<const Component *> src_components, GeometrySet
{true,
false,
IndexMask(instances->instances_num()),
VArray<int>::ForSingle(-1, instances->instances_num())});
VArray<int>::ForSingle(-1, instances->instances_num()),
propagation_info});
result.add(joined_components.get_component_for_write<Component>());
}
}
@ -195,15 +198,23 @@ void GEO_join_transform_instance_components(Span<const InstancesComponent *> src
}
/** Explicit template instantiation for all GeometryComponent subclasses. */
template void GEO_join_component_type<MeshComponent>(Span<const MeshComponent *>, GeometrySet &);
template void GEO_join_component_type<PointCloudComponent>(Span<const PointCloudComponent *>,
GeometrySet &);
template void GEO_join_component_type<InstancesComponent>(Span<const InstancesComponent *>,
GeometrySet &);
template void GEO_join_component_type<VolumeComponent>(Span<const VolumeComponent *>,
GeometrySet &);
template void GEO_join_component_type<CurveComponent>(Span<const CurveComponent *>, GeometrySet &);
template void GEO_join_component_type<MeshComponent>(
Span<const MeshComponent *>, GeometrySet &, const bke::AnonymousAttributePropagationInfo &);
template void GEO_join_component_type<PointCloudComponent>(
Span<const PointCloudComponent *>,
GeometrySet &,
const bke::AnonymousAttributePropagationInfo &);
template void GEO_join_component_type<InstancesComponent>(
Span<const InstancesComponent *>,
GeometrySet &,
const bke::AnonymousAttributePropagationInfo &);
template void GEO_join_component_type<VolumeComponent>(
Span<const VolumeComponent *>, GeometrySet &, const bke::AnonymousAttributePropagationInfo &);
template void GEO_join_component_type<CurveComponent>(
Span<const CurveComponent *>, GeometrySet &, const bke::AnonymousAttributePropagationInfo &);
template void GEO_join_component_type<GeometryComponentEditData>(
Span<const GeometryComponentEditData *>, GeometrySet &);
Span<const GeometryComponentEditData *>,
GeometrySet &,
const bke::AnonymousAttributePropagationInfo &);
} // namespace blender::geometry

View File

@ -1495,9 +1495,11 @@ static void remove_id_attribute_from_instances(GeometrySet &geometry_set)
/** Propagate instances from the old geometry set to the new geometry set if they are not realized.
*/
static void propagate_instances_to_keep(const GeometrySet &geometry_set,
IndexMask selection,
GeometrySet &new_geometry_set)
static void propagate_instances_to_keep(
const GeometrySet &geometry_set,
IndexMask selection,
GeometrySet &new_geometry_set,
const bke::AnonymousAttributePropagationInfo &propagation_info)
{
const Instances *instances = geometry_set.get_instances_for_read();
ab_stanton marked this conversation as resolved
Review

Add a null check or use a reference here with *

Add a null check or use a reference here with `*`
@ -1513,7 +1515,7 @@ static void propagate_instances_to_keep(const GeometrySet &geometry_set,
new_geometry_set.get_component_for_write<InstancesComponent>();
std::unique_ptr<Instances> new_instances = std::make_unique<Instances>(*instances);
new_instances->remove(inverse_selection);
new_instances->remove(inverse_selection, propagation_info);
new_instances_components.replace(new_instances.release(), GeometryOwnershipType::Owned);
}
@ -1531,7 +1533,8 @@ GeometrySet realize_instances(GeometrySet geometry_set, const RealizeInstancesOp
}
GeometrySet temp_geometry_set;
propagate_instances_to_keep(geometry_set, options.selection, temp_geometry_set);
propagate_instances_to_keep(
geometry_set, options.selection, temp_geometry_set, options.propagation_info);
if (options.keep_original_ids) {
remove_id_attribute_from_instances(geometry_set);