diff options
author | Hans Goudey <h.goudey@me.com> | 2022-01-03 22:19:04 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-01-03 22:19:04 +0300 |
commit | c6069c439c8fb28d62700b21587f3f66ea3cd239 (patch) | |
tree | a47f6487f9f09b90af2b0f28a3c012bcad820f81 /source | |
parent | a42e972e1b9354911d9403840e137915a6c17b15 (diff) |
Fix T94581: Incorrect geometry delete behavior with instances
Compare the start of the range to zero to figure out whether the
indices for the instances to keep starts at zero. Also rename the
selection argument, since it made it seem like the selected indices
should be removed rather than kept.
Diffstat (limited to 'source')
3 files changed, 13 insertions, 12 deletions
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index 0f9c2c1062b..88e45baad15 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -923,9 +923,10 @@ class InstancesComponent : public GeometryComponent { int references_amount() const; /** - * Remove the indices in the selection mask and remove unused instance references afterwards. + * Remove the indices that are not contained in the mask input, and remove unused instance + * references afterwards. */ - void remove_instances(const blender::IndexMask selection); + void remove_instances(const blender::IndexMask mask); blender::Span<int> almost_unique_ids() const; diff --git a/source/blender/blenkernel/intern/geometry_component_instances.cc b/source/blender/blenkernel/intern/geometry_component_instances.cc index a7e3c5b60dc..b411c793298 100644 --- a/source/blender/blenkernel/intern/geometry_component_instances.cc +++ b/source/blender/blenkernel/intern/geometry_component_instances.cc @@ -148,27 +148,27 @@ static void copy_data_based_on_mask(Span<T> src, MutableSpan<T> dst, IndexMask m }); } -void InstancesComponent::remove_instances(const IndexMask selection) +void InstancesComponent::remove_instances(const IndexMask mask) { using namespace blender; - if (selection.is_range() && selection.index_range().first() == 0) { + if (mask.is_range() && mask.as_range().start() == 0) { /* Deleting from the end of the array can be much faster since no data has to be shifted. */ - this->resize(selection.size()); + this->resize(mask.size()); this->remove_unused_references(); return; } - Vector<int> new_handles(selection.size()); - copy_data_based_on_mask<int>(this->instance_reference_handles(), new_handles, selection); + Vector<int> new_handles(mask.size()); + copy_data_based_on_mask<int>(this->instance_reference_handles(), new_handles, mask); instance_reference_handles_ = std::move(new_handles); - Vector<float4x4> new_transforms(selection.size()); - copy_data_based_on_mask<float4x4>(this->instance_transforms(), new_transforms, selection); + Vector<float4x4> new_transforms(mask.size()); + copy_data_based_on_mask<float4x4>(this->instance_transforms(), new_transforms, mask); instance_transforms_ = std::move(new_transforms); const bke::CustomDataAttributes &src_attributes = attributes_; bke::CustomDataAttributes dst_attributes; - dst_attributes.reallocate(selection.size()); + dst_attributes.reallocate(mask.size()); src_attributes.foreach_attribute( [&](const bke::AttributeIDRef &id, const AttributeMetaData &meta_data) { @@ -182,7 +182,7 @@ void InstancesComponent::remove_instances(const IndexMask selection) attribute_math::convert_to_static_type(src.type(), [&](auto dummy) { using T = decltype(dummy); - copy_data_based_on_mask<T>(src.typed<T>(), dst.typed<T>(), selection); + copy_data_based_on_mask<T>(src.typed<T>(), dst.typed<T>(), mask); }); return true; }, diff --git a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc index 7d41242b8bc..77546f1ea77 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc @@ -545,7 +545,7 @@ static void separate_instance_selection(GeometrySet &geometry_set, Vector<int64_t> indices; const IndexMask mask = index_mask_indices(selection, invert, indices); - if (mask.size() == 0) { + if (mask.is_empty()) { geometry_set.remove<InstancesComponent>(); return; } |