[Bf-blender-cvs] [8f89196be25] master: Fix T94232: No selection with set material node empty material list

Hans Goudey noreply at git.blender.org
Thu Dec 23 01:15:53 CET 2021


Commit: 8f89196be252cd541a0669c0aed02f4ad457e39d
Author: Hans Goudey
Date:   Wed Dec 22 18:15:21 2021 -0600
Branches: master
https://developer.blender.org/rB8f89196be252cd541a0669c0aed02f4ad457e39d

Fix T94232: No selection with set material node empty material list

If the input mesh had no materials already, the new material would
become the only material on the mesh, meaning the material was
added to all of the faces, instead of just the selected faces.

The mesh primitive nodes in geometry nodes already add an empty
slot by default, so this only affects outside geometry.

The fix is just adding an empty slot before the new slot, so the
non-selected material indices can still point to an empty slot.

Differential Revision: https://developer.blender.org/D13654

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

M	source/blender/nodes/geometry/nodes/node_geo_set_material.cc

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

diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_material.cc b/source/blender/nodes/geometry/nodes/node_geo_set_material.cc
index 30510c3570c..0e30522296f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_material.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_material.cc
@@ -40,6 +40,12 @@ static void node_declare(NodeDeclarationBuilder &b)
 
 static void assign_material_to_faces(Mesh &mesh, const IndexMask selection, Material *material)
 {
+  if (selection.size() != mesh.totpoly) {
+    /* If the entire mesh isn't selected, and there is no material slot yet, add an empty
+     * slot so that the faces that aren't selected can still refer to the default material. */
+    BKE_id_material_eval_ensure_default_slot(&mesh.id);
+  }
+
   int new_material_index = -1;
   for (const int i : IndexRange(mesh.totcol)) {
     Material *other_material = mesh.mat[i];



More information about the Bf-blender-cvs mailing list