Geometry Nodes: add utility to process all instances separately

This adds a new `GeometrySet::modify_geometry_sets` method that can be
used to update each sub-geometry-set separately without making any
instances real.

Differential Revision: https://developer.blender.org/D12650
This commit is contained in:
2021-09-27 17:35:26 +02:00
parent 2189dfd6e2
commit 0559971ab3
5 changed files with 104 additions and 48 deletions

View File

@@ -458,6 +458,28 @@ void GeometrySet::gather_attributes_for_propagation(
delete dummy_component;
}
/**
* Modify every (recursive) instance separately. This is often more efficient than realizing all
* instances just to change the same thing on all of them.
*/
void GeometrySet::modify_geometry_sets(ForeachSubGeometryCallback callback)
{
callback(*this);
if (!this->has_instances()) {
return;
}
/* In the future this can be improved by deduplicating instance references across different
* instances. */
InstancesComponent &instances_component = this->get_component_for_write<InstancesComponent>();
instances_component.ensure_geometry_instances();
for (const int handle : instances_component.references().index_range()) {
if (instances_component.references()[handle].type() == InstanceReference::Type::GeometrySet) {
GeometrySet &instance_geometry = instances_component.geometry_set_from_reference(handle);
instance_geometry.modify_geometry_sets(callback);
}
}
}
/** \} */
/* -------------------------------------------------------------------- */