[Bf-blender-cvs] [08a8de739d8] master: Fix: Resolve deprecation warning when copying polygon struct

Hans Goudey noreply at git.blender.org
Tue Sep 13 18:43:45 CEST 2022


Commit: 08a8de739d8c7fa60f257ed171d292879edae013
Author: Hans Goudey
Date:   Tue Sep 13 11:43:34 2022 -0500
Branches: master
https://developer.blender.org/rB08a8de739d8c7fa60f257ed171d292879edae013

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

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

M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/mesh_legacy_convert.cc
M	source/blender/makesdna/DNA_meshdata_types.h
M	source/blender/makesdna/intern/dna_rename_defs.h

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

diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 8616b056d7f..6bf25da5ae7 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -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;
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 10fc8ff3195..627c0057a28 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -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();
diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h
index e621343b818..77cb27083ab 100644
--- a/source/blender/makesdna/DNA_meshdata_types.h
+++ b/source/blender/makesdna/DNA_meshdata_types.h
@@ -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;
 
diff --git a/source/blender/makesdna/intern/dna_rename_defs.h b/source/blender/makesdna/intern/dna_rename_defs.h
index f25ff5fbbb8..257e60eae98 100644
--- a/source/blender/makesdna/intern/dna_rename_defs.h
+++ b/source/blender/makesdna/intern/dna_rename_defs.h
@@ -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)



More information about the Bf-blender-cvs mailing list