Fix T92652: Joining curves breaks point attribute order

Currently the curve to mesh node relies on the order of attributes being
the same on every spline. This is a worthwhile assumption, because it
will allow removing the attribute name storage duplication on every
spline in the future.

However, the join geometry node broke this order, since it just created
new attributes without any regard to the order. To fix this, I added a
"reorder" step after all the merged attributes have been created, the
types have been joined, etc. It should be possible to change this code
so that the attributes are added with the right order in the first
place, but I would like to do that after refactoring spline attribute
storage, and not for 3.0.

Differential Revision: https://developer.blender.org/D13074
This commit is contained in:
2021-11-02 15:16:52 -05:00
parent 7aa311e539
commit 18392cef17
4 changed files with 64 additions and 0 deletions

View File

@@ -835,6 +835,26 @@ bool CustomDataAttributes::foreach_attribute(const AttributeForeachCallback call
return true;
}
void CustomDataAttributes::reorder(Span<AttributeIDRef> new_order)
{
BLI_assert(new_order.size() == data.totlayer);
Map<AttributeIDRef, int> old_order;
old_order.reserve(data.totlayer);
Array<CustomDataLayer> old_layers(Span(data.layers, data.totlayer));
for (const int i : old_layers.index_range()) {
old_order.add_new(attribute_id_from_custom_data_layer(old_layers[i]), i);
}
MutableSpan layers(data.layers, data.totlayer);
for (const int i : layers.index_range()) {
const int old_index = old_order.lookup(new_order[i]);
layers[i] = old_layers[old_index];
}
CustomData_update_typemap(&data);
}
} // namespace blender::bke
/* -------------------------------------------------------------------- */