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
This commit is contained in:
Hans Goudey 2021-12-22 18:15:21 -06:00
parent 60c59d7d61
commit 8f89196be2
Notes: blender-bot 2023-02-14 01:11:05 +01:00
Referenced by issue #94232, Inconsistent Behavior of Set Material Node
1 changed files with 6 additions and 0 deletions

View File

@ -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];