Fix T102502: Collada import sets incorrect material indices

The weird code dealing with `MeshPrimitive` didn't increment the
material indices pointer for geometry types besides triangle fans.
Also use a proper accessor to avoid adding a duplicate material
indices attribute, just in case this code is used on existing meshes.
This commit is contained in:
Hans Goudey 2022-11-14 17:52:50 -06:00
parent 970be7e65a
commit db94d030bc
Notes: blender-bot 2023-02-13 23:16:02 +01:00
Referenced by issue #102502, Regression: DAE Imports materials wrong
1 changed files with 4 additions and 2 deletions

View File

@ -621,8 +621,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
MaterialIdPrimitiveArrayMap mat_prim_map;
int *material_indices = (int *)CustomData_add_layer_named(
&me->pdata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, me->totpoly, "material_index");
int *material_indices = BKE_mesh_material_indices_for_write(me);
COLLADAFW::MeshPrimitiveArray &prim_arr = collada_mesh->getMeshPrimitives();
COLLADAFW::MeshVertexData &nor = collada_mesh->getNormals();
@ -775,6 +774,9 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
}
mpoly++;
if (material_indices) {
material_indices++;
}
mloop += vcount;
loop_index += vcount;
start_index += vcount;