[Bf-blender-cvs] [ad245f19703] master: Fix T101013: Reordering materials broken with only one assigned

Hans Goudey noreply at git.blender.org
Tue Sep 13 00:18:11 CEST 2022


Commit: ad245f1970343ed41098ed9611a38b167fd757d4
Author: Hans Goudey
Date:   Mon Sep 12 17:17:11 2022 -0500
Branches: master
https://developer.blender.org/rBad245f1970343ed41098ed9611a38b167fd757d4

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.

===================================================================

M	source/blender/blenkernel/intern/mesh.cc

===================================================================

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<int> material_indices = attributes.lookup_for_write<int>("material_index");
+    SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
+        "material_index", ATTR_DOMAIN_FACE);
     if (!material_indices) {
       return;
     }
-    if (material_indices.domain != ATTR_DOMAIN_FACE) {
-      BLI_assert_unreachable();
-      return;
-    }
-    MutableVArraySpan<int> 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();
   }



More information about the Bf-blender-cvs mailing list