[Bf-blender-cvs] [dca1a31100c] refactor-mesh-material-index-generic: Fix: Account for null material indices

Hans Goudey noreply at git.blender.org
Sat Aug 27 07:31:11 CEST 2022


Commit: dca1a31100c5c1df014018d02abecb682fb250a1
Author: Hans Goudey
Date:   Sat Aug 27 00:31:03 2022 -0500
Branches: refactor-mesh-material-index-generic
https://developer.blender.org/rBdca1a31100c5c1df014018d02abecb682fb250a1

Fix: Account for null material indices

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

M	source/blender/modifiers/intern/MOD_solidify_extrude.c
M	source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
M	source/blender/nodes/geometry/nodes/node_geo_material_selection.cc
M	source/blender/render/intern/bake.c

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

diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c
index 1c429421829..53c6ee9a1a8 100644
--- a/source/blender/modifiers/intern/MOD_solidify_extrude.c
+++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c
@@ -425,7 +425,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
   } \
   (void)0
 
-  /* TODO: Handle null src indices. */
   int *dst_material_index = BKE_mesh_material_indices_for_write(result);
 
   /* flip normals */
diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
index 6e5ccb15eba..22a8aea03f6 100644
--- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
+++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
@@ -2108,7 +2108,6 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
   }
 #endif
 
-  /* TODO: Handle null src indices. */
   const int *src_material_index = BKE_mesh_material_indices(mesh);
   int *dst_material_index = BKE_mesh_material_indices_for_write(result);
 
@@ -2240,16 +2239,20 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
                 for (EdgeGroup *g3 = g2; g3->valid && k < j; g3++) {
                   if ((do_rim && !g3->is_orig_closed) || (do_shell && g3->split)) {
                     /* Check both far ends in terms of faces of an edge group. */
-                    if (src_material_index[g3->edges[0]->faces[0]->index] == l) {
+                    if ((src_material_index ? src_material_index[g3->edges[0]->faces[0]->index] :
+                                              0) == l) {
                       face = g3->edges[0]->faces[0]->index;
                       count++;
                     }
                     NewEdgeRef *le = g3->edges[g3->edges_len - 1];
-                    if (le->faces[1] && src_material_index[le->faces[1]->index] == l) {
+                    if (le->faces[1] &&
+                        (src_material_index ? src_material_index[le->faces[1]->index] : 0) == l) {
                       face = le->faces[1]->index;
                       count++;
                     }
-                    else if (!le->faces[1] && src_material_index[le->faces[0]->index] == l) {
+                    else if (!le->faces[1] &&
+                             (src_material_index ? src_material_index[le->faces[0]->index] : 0) ==
+                                 l) {
                       face = le->faces[0]->index;
                       count++;
                     }
@@ -2345,7 +2348,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
             &mesh->pdata, &result->pdata, (int)(*new_edges)->faces[0]->index, (int)poly_index, 1);
         mpoly[poly_index].loopstart = (int)loop_index;
         mpoly[poly_index].totloop = 4 - (int)(v1_singularity || v2_singularity);
-        dst_material_index[poly_index] = src_material_index[orig_face_index] + mat_ofs_rim;
+        dst_material_index[poly_index] =
+            (src_material_index ? src_material_index[orig_face_index] : 0) + mat_ofs_rim;
         CLAMP(dst_material_index[poly_index], 0, mat_nr_max);
         mpoly[poly_index].flag = face->flag;
         poly_index++;
@@ -2536,7 +2540,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
           CustomData_copy_data(&mesh->pdata, &result->pdata, (int)(i / 2), (int)poly_index, 1);
           mpoly[poly_index].loopstart = (int)loop_index;
           mpoly[poly_index].totloop = (int)k;
-          dst_material_index[poly_index] = src_material_index[fr->index] +
+          dst_material_index[poly_index] = (src_material_index ? src_material_index[fr->index] :
+                                                                 0) +
                                            (fr->reversed != do_flip ? mat_ofs : 0);
           CLAMP(dst_material_index[poly_index], 0, mat_nr_max);
           mpoly[poly_index].flag = fr->face->flag;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc b/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc
index 2a371b3debd..9bec8cc5640 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_material_selection.cc
@@ -35,10 +35,11 @@ static void select_mesh_by_material(const Mesh &mesh,
   const AttributeAccessor attributes = bke::mesh_attributes(mesh);
   const VArray<int> material_indices = attributes.lookup_or_default<int>(
       "material_index", ATTR_DOMAIN_FACE, 0);
-  /* TODO: What about null materials? */
   if (material_indices.is_single() && material_indices.get_internal_single() == 0) {
-    r_selection.fill_indices(mask, false);
-    return;
+    if (material != nullptr) {
+      r_selection.fill_indices(mask, false);
+      return;
+    }
   }
 
   const VArraySpan<int> material_indices_span(material_indices);
diff --git a/source/blender/render/intern/bake.c b/source/blender/render/intern/bake.c
index 94456003824..a6a62103f23 100644
--- a/source/blender/render/intern/bake.c
+++ b/source/blender/render/intern/bake.c
@@ -749,7 +749,7 @@ void RE_bake_pixels_populate(Mesh *me,
     bd.primitive_id = i;
 
     /* Find images matching this material. */
-    Image *image = targets->material_to_image[material_indices[lt->poly]];
+    Image *image = targets->material_to_image[material_indices ? material_indices[lt->poly] : 0];
     for (int image_id = 0; image_id < targets->images_num; image_id++) {
       BakeImage *bk_image = &targets->images[image_id];
       if (bk_image->image != image) {



More information about the Bf-blender-cvs mailing list