From ad245f1970343ed41098ed9611a38b167fd757d4 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 12 Sep 2022 17:17:11 -0500 Subject: Fix T101013: Reordering materials broken with only one assigned When there was only a single material assigned to the mesh, the material index attribute didn't necessarily exist. Changing the oder of the slots wouldn't change the first material index as necessary. --- source/blender/blenkernel/intern/mesh.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 636be0dc032..8616b056d7f 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -1416,19 +1416,15 @@ void BKE_mesh_material_remap(Mesh *me, const uint *remap, uint remap_len) } else { MutableAttributeAccessor attributes = me->attributes_for_write(); - AttributeWriter material_indices = attributes.lookup_for_write("material_index"); + SpanAttributeWriter material_indices = attributes.lookup_or_add_for_write_span( + "material_index", ATTR_DOMAIN_FACE); if (!material_indices) { return; } - if (material_indices.domain != ATTR_DOMAIN_FACE) { - BLI_assert_unreachable(); - return; - } - MutableVArraySpan indices_span(material_indices.varray); - for (const int i : indices_span.index_range()) { - MAT_NR_REMAP(indices_span[i]); + for (const int i : material_indices.span.index_range()) { + MAT_NR_REMAP(material_indices.span[i]); } - indices_span.save(); + material_indices.span.save(); material_indices.finish(); } -- cgit v1.2.3