From 8f89196be252cd541a0669c0aed02f4ad457e39d Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 22 Dec 2021 18:15:21 -0600 Subject: [PATCH] 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 --- .../blender/nodes/geometry/nodes/node_geo_set_material.cc | 6 ++++++ 1 file changed, 6 insertions(+) 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];