Fix #105162: Array modifier cap material index ignored

The material indices from the caps were only copied if the base mesh had
a material index attribute. Fix that by copying them manually if the cap
has the attribute.
This commit is contained in:
Hans Goudey
2023-02-28 15:39:19 -05:00
parent 15f59470a3
commit 079dbf4d1b

View File

@@ -24,6 +24,7 @@
#include "DNA_screen_types.h"
#include "BKE_anim_path.h"
#include "BKE_attribute.hh"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_displist.h"
@@ -274,6 +275,7 @@ static void mesh_merge_transform(Mesh *result,
int remap_len,
const bool recalc_normals_later)
{
using namespace blender;
int *index_orig;
int i;
MEdge *me;
@@ -328,6 +330,17 @@ static void mesh_merge_transform(Mesh *result,
ml->e += cap_edges_index;
}
const bke::AttributeAccessor cap_attributes = cap_mesh->attributes();
if (const VArray<int> cap_material_indices = cap_attributes.lookup<int>("material_index",
ATTR_DOMAIN_FACE)) {
bke::MutableAttributeAccessor result_attributes = result->attributes_for_write();
bke::SpanAttributeWriter<int> result_material_indices =
result_attributes.lookup_or_add_for_write_span<int>("material_index", ATTR_DOMAIN_FACE);
cap_material_indices.materialize(
result_material_indices.span.slice(cap_polys_index, cap_npolys));
result_material_indices.finish();
}
/* Set #CD_ORIGINDEX. */
index_orig = static_cast<int *>(
CustomData_get_layer_for_write(&result->vdata, CD_ORIGINDEX, result->totvert));