diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-01 20:43:01 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-01 20:45:18 +0300 |
commit | 6ee34319147207abea1dc4d0e78ff3b8fc17b260 (patch) | |
tree | 1e7f39cef3b350d6aedad7826549cc3f57853895 /source/blender/blenkernel/intern/mesh_legacy_convert.cc | |
parent | 08894ac929cbad25219d107f7877b1300135fb60 (diff) |
Fix: Use of deprecated field in legacy MFace conversion
The material indices have been moved out of MPoly since f1c0249f34c4171.
That conversion happens in file reading code currently, so the material
indices have to be accessed the new way everywhere.
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_legacy_convert.cc')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_legacy_convert.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc index 2fc984997b8..58096081ad1 100644 --- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc +++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc @@ -187,6 +187,12 @@ static void convert_mfaces_to_mpolys(ID *id, totpoly = totface_i; mpoly = (MPoly *)MEM_calloc_arrayN((size_t)totpoly, sizeof(MPoly), "mpoly converted"); CustomData_add_layer(pdata, CD_MPOLY, CD_ASSIGN, mpoly, totpoly); + int *material_indices = static_cast<int *>( + CustomData_get_layer_named(pdata, CD_PROP_INT32, "material_index")); + if (material_indices == nullptr) { + material_indices = static_cast<int *>(CustomData_add_layer_named( + pdata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, totpoly, "material_index")); + } numTex = CustomData_number_of_layers(fdata, CD_MTFACE); numCol = CustomData_number_of_layers(fdata, CD_MCOL); @@ -232,7 +238,7 @@ static void convert_mfaces_to_mpolys(ID *id, mp->totloop = mf->v4 ? 4 : 3; - mp->mat_nr = mf->mat_nr; + material_indices[i] = mf->mat_nr; mp->flag = mf->flag; #define ML(v1, v2) \ @@ -564,6 +570,8 @@ static int mesh_tessface_calc(CustomData *fdata, mpoly = (const MPoly *)CustomData_get_layer(pdata, CD_MPOLY); mloop = (const MLoop *)CustomData_get_layer(ldata, CD_MLOOP); + const int *material_indices = static_cast<const int *>( + CustomData_get_layer_named(pdata, CD_PROP_INT32, "material_index")); /* Allocate the length of `totfaces`, avoid many small reallocation's, * if all faces are triangles it will be correct, `quads == 2x` allocations. */ @@ -602,7 +610,7 @@ static int mesh_tessface_calc(CustomData *fdata, lidx[1] = l2; \ lidx[2] = l3; \ lidx[3] = 0; \ - mf->mat_nr = mp->mat_nr; \ + mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \ mf->flag = mp->flag; \ mf->edcode = 0; \ (void)0 @@ -625,7 +633,7 @@ static int mesh_tessface_calc(CustomData *fdata, lidx[1] = l2; \ lidx[2] = l3; \ lidx[3] = l4; \ - mf->mat_nr = mp->mat_nr; \ + mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \ mf->flag = mp->flag; \ mf->edcode = TESSFACE_IS_QUAD; \ (void)0 @@ -711,7 +719,7 @@ static int mesh_tessface_calc(CustomData *fdata, lidx[2] = l3; lidx[3] = 0; - mf->mat_nr = mp->mat_nr; + mf->mat_nr = material_indices ? material_indices[poly_index] : 0; mf->flag = mp->flag; mf->edcode = 0; |