diff options
author | Jacques Lucke <jacques@blender.org> | 2021-09-27 18:35:26 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-09-27 18:35:45 +0300 |
commit | 0559971ab3772e3b5efb0fcad396735ea4ac22fe (patch) | |
tree | e373f64625d71d643e03f28a1383ee7c9b276d42 /source/blender/blenkernel/intern/geometry_set.cc | |
parent | 2189dfd6e25a7bb6b734116619d87bc2d2a535ff (diff) |
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
Diffstat (limited to 'source/blender/blenkernel/intern/geometry_set.cc')
-rw-r--r-- | source/blender/blenkernel/intern/geometry_set.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc index 1ebdde75f46..3abe2fd2213 100644 --- a/source/blender/blenkernel/intern/geometry_set.cc +++ b/source/blender/blenkernel/intern/geometry_set.cc @@ -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); + } + } +} + /** \} */ /* -------------------------------------------------------------------- */ |