Fix: Resolve deprecation warning when copying polygon struct

`MPoly` is used and copied in many places. To avoid the need to use a
special function for copying MPoly, or the need to add a copy
constructor, just rename the `mat_nr` field to include "legacy" in the
name. This keeps the original purpose of notifying developers that
the field shouldn't be used without any further complexity.
Apply the same fix to `bweight`.

Differential Revision: https://developer.blender.org/D15841
This commit is contained in:
Hans Goudey 2022-09-13 11:43:34 -05:00
parent eaf416693d
commit 08a8de739d
4 changed files with 17 additions and 14 deletions

View File

@ -1612,14 +1612,14 @@ void BKE_mesh_do_versions_cd_flag_init(Mesh *mesh)
const Span<MEdge> edges = mesh->edges();
for (const MVert &vert : verts) {
if (vert.bweight != 0) {
if (vert.bweight_legacy != 0) {
mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
break;
}
}
for (const MEdge &edge : edges) {
if (edge.bweight != 0) {
if (edge.bweight_legacy != 0) {
mesh->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
if (mesh->cd_flag & ME_CDFLAG_EDGE_CREASE) {
break;

View File

@ -929,13 +929,13 @@ void BKE_mesh_legacy_bevel_weight_from_layers(Mesh *mesh)
CustomData_get_layer(&mesh->vdata, CD_BWEIGHT))) {
mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
for (const int i : verts.index_range()) {
verts[i].bweight = std::clamp(weights[i], 0.0f, 1.0f) * 255.0f;
verts[i].bweight_legacy = std::clamp(weights[i], 0.0f, 1.0f) * 255.0f;
}
}
else {
mesh->cd_flag &= ~ME_CDFLAG_VERT_BWEIGHT;
for (const int i : verts.index_range()) {
verts[i].bweight = 0;
verts[i].bweight_legacy = 0;
}
}
MutableSpan<MEdge> edges = mesh->edges_for_write();
@ -943,13 +943,13 @@ void BKE_mesh_legacy_bevel_weight_from_layers(Mesh *mesh)
CustomData_get_layer(&mesh->edata, CD_BWEIGHT))) {
mesh->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
for (const int i : edges.index_range()) {
edges[i].bweight = std::clamp(weights[i], 0.0f, 1.0f) * 255.0f;
edges[i].bweight_legacy = std::clamp(weights[i], 0.0f, 1.0f) * 255.0f;
}
}
else {
mesh->cd_flag &= ~ME_CDFLAG_EDGE_BWEIGHT;
for (const int i : edges.index_range()) {
edges[i].bweight = 0;
edges[i].bweight_legacy = 0;
}
}
}
@ -962,7 +962,7 @@ void BKE_mesh_legacy_bevel_weight_to_layers(Mesh *mesh)
float *weights = static_cast<float *>(
CustomData_add_layer(&mesh->vdata, CD_BWEIGHT, CD_CONSTRUCT, nullptr, verts.size()));
for (const int i : verts.index_range()) {
weights[i] = verts[i].bweight / 255.0f;
weights[i] = verts[i].bweight_legacy / 255.0f;
}
}
@ -971,7 +971,7 @@ void BKE_mesh_legacy_bevel_weight_to_layers(Mesh *mesh)
float *weights = static_cast<float *>(
CustomData_add_layer(&mesh->edata, CD_BWEIGHT, CD_CONSTRUCT, nullptr, edges.size()));
for (const int i : edges.index_range()) {
weights[i] = edges[i].bweight / 255.0f;
weights[i] = edges[i].bweight_legacy / 255.0f;
}
}
}
@ -1077,7 +1077,7 @@ void BKE_mesh_legacy_convert_material_indices_to_mpoly(Mesh *mesh)
"material_index", ATTR_DOMAIN_FACE, 0);
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
polys[i].mat_nr = material_indices[i];
polys[i].mat_nr_legacy = material_indices[i];
}
});
}
@ -1089,12 +1089,12 @@ void BKE_mesh_legacy_convert_mpoly_to_material_indices(Mesh *mesh)
MutableAttributeAccessor attributes = mesh->attributes_for_write();
const Span<MPoly> polys = mesh->polys();
if (std::any_of(
polys.begin(), polys.end(), [](const MPoly &poly) { return poly.mat_nr != 0; })) {
polys.begin(), polys.end(), [](const MPoly &poly) { return poly.mat_nr_legacy != 0; })) {
SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>(
"material_index", ATTR_DOMAIN_FACE);
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
material_indices.span[i] = polys[i].mat_nr;
material_indices.span[i] = polys[i].mat_nr_legacy;
}
});
material_indices.finish();

View File

@ -29,7 +29,7 @@ typedef struct MVert {
/**
* Deprecated bevel weight storage, now located in #CD_BWEIGHT, except for file read and write.
*/
char bweight DNA_DEPRECATED;
char bweight_legacy;
char _pad[2];
} MVert;
@ -55,7 +55,7 @@ typedef struct MEdge {
/**
* Deprecated bevel weight storage, now located in #CD_BWEIGHT, except for file read and write.
*/
char bweight DNA_DEPRECATED;
char bweight_legacy;
short flag;
} MEdge;
@ -83,7 +83,7 @@ typedef struct MPoly {
/** Keep signed since we need to subtract when getting the previous loop. */
int totloop;
/** Deprecated material index. Now stored in the "material_index" attribute, but kept for IO. */
short mat_nr DNA_DEPRECATED;
short mat_nr_legacy;
char flag, _pad;
} MPoly;

View File

@ -97,6 +97,9 @@ DNA_STRUCT_RENAME_ELEM(Object, dupfacesca, instance_faces_scale)
DNA_STRUCT_RENAME_ELEM(Object, restrictflag, visibility_flag)
DNA_STRUCT_RENAME_ELEM(Object, size, scale)
DNA_STRUCT_RENAME_ELEM(Object_Runtime, crazyspace_num_verts, crazyspace_verts_num)
DNA_STRUCT_RENAME_ELEM(MEdge, bweight, bweight_legacy)
DNA_STRUCT_RENAME_ELEM(MPoly, mat_nr, mat_nr_legacy)
DNA_STRUCT_RENAME_ELEM(MVert, bweight, bweight_legacy)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, child_nbr, child_percent)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, dup_group, instance_collection)
DNA_STRUCT_RENAME_ELEM(ParticleSettings, dup_ob, instance_object)