Cleanup: remove is_same method for virtual arrays

This abstraction is rarely used. It could be replaced by some more
general "query" API in the future. For now it's easier to just compare
pointers in the Set Position node where this was used.

This is possible now, because mesh positions are stored as flat `float3`
arrays (previously, they were stored as `MVert` with some other data
interleaved).
This commit is contained in:
2023-01-18 13:24:00 +01:00
parent 6e6ae17335
commit cf50a3eabc
2 changed files with 10 additions and 60 deletions

View File

@@ -29,9 +29,16 @@ static void set_computed_position_and_offset(GeometryComponent &component,
const IndexMask selection)
{
MutableAttributeAccessor attributes = *component.attributes_for_write();
const VArray<float3> positions_read_only = attributes.lookup<float3>("position");
if (in_positions.is_same(positions_read_only)) {
/* Optimize the case when `in_positions` references the original positions array. */
const VArray<float3> positions_read_only = attributes.lookup<float3>("position");
bool positions_are_original = false;
if (positions_read_only.is_span() && in_positions.is_span()) {
positions_are_original = positions_read_only.get_internal_span().data() ==
in_positions.get_internal_span().data();
}
if (positions_are_original) {
if (const std::optional<float3> offset = in_offsets.get_if_single()) {
if (math::is_zero(*offset)) {
return;
@@ -81,7 +88,7 @@ static void set_computed_position_and_offset(GeometryComponent &component,
default: {
AttributeWriter<float3> positions = attributes.lookup_for_write<float3>("position");
MutableVArraySpan<float3> out_positions_span = positions.varray;
if (in_positions.is_same(positions_read_only)) {
if (positions_are_original) {
devirtualize_varray(in_offsets, [&](const auto in_offsets) {
threading::parallel_for(
selection.index_range(), grain_size, [&](const IndexRange range) {