Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-12-23 03:15:21 +0300
committerHans Goudey <h.goudey@me.com>2021-12-23 03:15:21 +0300
commit8f89196be252cd541a0669c0aed02f4ad457e39d (patch)
treec342b5bed969fbf7254be3e559c3d1e0f787ee75 /source/blender
parent60c59d7d611dfd72652d9f7ffef519f983703349 (diff)
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
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_set_material.cc6
1 files changed, 6 insertions, 0 deletions
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];