[Bf-blender-cvs] [c8808542d03] refactor-mesh-position-generic: Remove most uses of CD_MVERT

Hans Goudey noreply at git.blender.org
Mon Sep 12 04:12:00 CEST 2022


Commit: c8808542d0365877e1345a708931320ffe71b098
Author: Hans Goudey
Date:   Sun Sep 11 21:11:52 2022 -0500
Branches: refactor-mesh-position-generic
https://developer.blender.org/rBc8808542d0365877e1345a708931320ffe71b098

Remove most uses of CD_MVERT

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

M	source/blender/blenkernel/intern/DerivedMesh.cc
M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/mesh_boolean_convert.cc
M	source/blender/bmesh/intern/bmesh_mesh_convert.cc
M	source/blender/editors/mesh/mesh_data.cc
M	source/blender/editors/object/object_modifier.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
M	source/blender/geometry/intern/mesh_merge_by_distance.cc
M	source/blender/io/collada/MeshImporter.cpp
M	source/blender/io/stl/importer/stl_import_mesh.cc
M	source/blender/makesdna/DNA_customdata_types.h

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

diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index 72f804dcb4c..dda9ee20e58 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -91,18 +91,19 @@ static void editbmesh_calc_modifier_final_normals_or_defer(
 
 /* -------------------------------------------------------------------- */
 
-static MVert *dm_getVertArray(DerivedMesh *dm)
+static float (*dm_getVertArray(DerivedMesh *dm))[3]
 {
-  MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
+  float(*positions)[3] = (float(*)[3])CustomData_get_layer_named(
+      &dm->vertData, CD_PROP_FLOAT3, "position");
 
-  if (!mvert) {
-    mvert = (MVert *)CustomData_add_layer(
-        &dm->vertData, CD_MVERT, CD_SET_DEFAULT, nullptr, dm->getNumVerts(dm));
-    CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY);
-    dm->copyVertArray(dm, mvert);
+  if (!positions) {
+    positions = (float(*)[3])CustomData_add_layer_named(
+        &dm->vertData, CD_PROP_FLOAT3, CD_SET_DEFAULT, nullptr, dm->getNumVerts(dm), "position");
+    CustomData_set_layer_flag(&dm->vertData, CD_PROP_FLOAT3, CD_FLAG_TEMPORARY);
+    dm->copyVertArray(dm, positions);
   }
 
-  return mvert;
+  return positions;
 }
 
 static MEdge *dm_getEdgeArray(DerivedMesh *dm)
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 93286751f92..ab70596a739 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -38,7 +38,7 @@ typedef struct {
 
   /* these point to data in the DerivedMesh custom data layers,
    * they are only here for efficiency and convenience */
-  MVert *mvert;
+  float (*positions)[3];
   const float (*vert_normals)[3];
   MEdge *medge;
   MFace *mface;
@@ -75,10 +75,10 @@ static int cdDM_getNumPolys(DerivedMesh *dm)
   return dm->numPolyData;
 }
 
-static void cdDM_copyVertArray(DerivedMesh *dm, MVert *r_vert)
+static void cdDM_copyVertArray(DerivedMesh *dm, float (*r_positions)[3])
 {
   CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
-  memcpy(r_vert, cddm->mvert, sizeof(*r_vert) * dm->numVertData);
+  memcpy(r_positions, cddm->positions, sizeof(float[3]) * dm->numVertData);
 }
 
 static void cdDM_copyEdgeArray(DerivedMesh *dm, MEdge *r_edge)
@@ -103,7 +103,7 @@ static void cdDM_getVertCo(DerivedMesh *dm, int index, float r_co[3])
 {
   CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
 
-  copy_v3_v3(r_co, cddm->mvert[index].co);
+  copy_v3_v3(r_co, cddm->positions[index]);
 }
 
 static void cdDM_getVertNo(DerivedMesh *dm, int index, float r_no[3])
@@ -122,7 +122,7 @@ static void cdDM_recalc_looptri(DerivedMesh *dm)
   BLI_assert(totpoly == 0 || cddm->dm.looptris.array_wip != NULL);
 
   BKE_mesh_recalc_looptri(
-      cddm->mloop, cddm->mpoly, cddm->mvert, totloop, totpoly, cddm->dm.looptris.array_wip);
+      cddm->mloop, cddm->mpoly, cddm->positions, totloop, totpoly, cddm->dm.looptris.array_wip);
 
   BLI_assert(cddm->dm.looptris.array == NULL);
   atomic_cas_ptr(
@@ -218,7 +218,7 @@ static DerivedMesh *cdDM_from_mesh_ex(Mesh *mesh,
   CustomData_merge(&mesh->ldata, &dm->loopData, cddata_masks.lmask, alloctype, mesh->totloop);
   CustomData_merge(&mesh->pdata, &dm->polyData, cddata_masks.pmask, alloctype, mesh->totpoly);
 
-  cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT);
+  cddm->positions = CustomData_get_layer_named(&dm->vertData, CD_PROP_FLOAT3, "position");
   /* Though this may be an unnecessary calculation, simply retrieving the layer may return nothing
    * or dirty normals. */
   cddm->vert_normals = BKE_mesh_vertex_normals_ensure(mesh);
@@ -271,10 +271,11 @@ DerivedMesh *CDDM_copy(DerivedMesh *source)
   CustomData_copy_data(&source->edgeData, &dm->edgeData, 0, 0, numEdges);
 
   /* now add mvert/medge/mface layers */
-  cddm->mvert = source->dupVertArray(source);
+  cddm->positions = source->dupVertArray(source);
   cddm->medge = source->dupEdgeArray(source);
 
-  CustomData_add_layer(&dm->vertData, CD_MVERT, CD_ASSIGN, cddm->mvert, numVerts);
+  CustomData_add_layer_named(
+      &dm->vertData, CD_PROP_FLOAT3, CD_ASSIGN, cddm->positions, numVerts, "position");
   CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_ASSIGN, cddm->medge, numEdges);
 
   DM_DupPolys(source, dm);
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 0dd537f28ce..965c8487f9a 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -519,22 +519,6 @@ static int customdata_compare(
       /* At this point `l1` and `l2` have the same name and type, so they should be compared. */
 
       switch (l1->type) {
-
-        case CD_MVERT: {
-          MVert *v1 = (MVert *)l1->data;
-          MVert *v2 = (MVert *)l2->data;
-          int vtot = m1->totvert;
-
-          for (j = 0; j < vtot; j++, v1++, v2++) {
-            for (int k = 0; k < 3; k++) {
-              if (compare_threshold_relative(v1->co[k], v2->co[k], thresh)) {
-                return MESHCMP_VERTCOMISMATCH;
-              }
-            }
-          }
-          break;
-        }
-
         /* We're order-agnostic for edges here. */
         case CD_MEDGE: {
           MEdge *e1 = (MEdge *)l1->data;
@@ -928,7 +912,7 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name)
 /* Custom data layer functions; those assume that totXXX are set correctly. */
 static void mesh_ensure_cdlayers_primary(Mesh *mesh, bool do_tessface)
 {
-  if (!CustomData_get_layer(&mesh->vdata, CD_MVERT)) {
+  if (!CustomData_get_layer_named(&mesh->vdata, CD_PROP_FLOAT3, "position")) {
     CustomData_add_layer_named(
         &mesh->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, mesh->totvert, "position");
   }
diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
index 6ab5c791811..d6361e9f9c0 100644
--- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
@@ -382,9 +382,7 @@ static void copy_vert_attributes(Mesh *dest_mesh,
   const CustomData *source_cd = &orig_me->vdata;
   for (int source_layer_i = 0; source_layer_i < source_cd->totlayer; ++source_layer_i) {
     int ty = source_cd->layers[source_layer_i].type;
-    /* The (first) CD_MVERT layer is the same as dest_mesh->vdata, so we've
-     * already set the coordinate to the right value. */
-    if (ty == CD_MVERT) {
+    if (StringRef(source_cd->layers->name) == "position") {
       continue;
     }
     const char *name = source_cd->layers[source_layer_i].name;
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index 87ba86192ce..ea6b1a70552 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -1012,7 +1012,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
   MutableSpan<MLoop> mloop;
   if (me->totvert > 0) {
     positions = {static_cast<float3 *>(CustomData_add_layer_named(
-                     &me->vdata, CD_MVERT, CD_CONSTRUCT, nullptr, me->totvert, "position")),
+                     &me->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, me->totvert, "position")),
                  me->totvert};
   }
   if (me->totedge > 0) {
@@ -1273,7 +1273,8 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
   me->totloop = bm->totloop;
   me->totpoly = bm->totface;
 
-  CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, bm->totvert);
+  CustomData_add_layer_named(
+      &me->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, bm->totvert, "position");
   CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, bm->totedge);
   CustomData_add_layer(&me->ldata, CD_MLOOP, CD_SET_DEFAULT, nullptr, bm->totloop);
   CustomData_add_layer(&me->pdata, CD_MPOLY, CD_SET_DEFAULT, nullptr, bm->totface);
diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc
index 933f8a75c6c..5144c449889 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -1025,8 +1025,9 @@ static void mesh_add_verts(Mesh *mesh, int len)
   CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH.vmask, CD_SET_DEFAULT, totvert);
   CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert);
 
-  if (!CustomData_has_layer(&vdata, CD_MVERT)) {
-    CustomData_add_layer(&vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, totvert);
+  if (!CustomData_get_layer_named(&vdata, CD_PROP_FLOAT3, "position")) {
+    CustomData_add_layer_named(
+        &vdata, CD_PROP_FLOAT3, CD_SET_DEFAULT, nullptr, totvert, "position");
   }
 
   CustomData_free(&mesh->vdata, mesh->totvert);
diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc
index 55a1a82dfcf..b040e5390bb 100644
--- a/source/blender/editors/object/object_modifier.cc
+++ b/source/blender/editors/object/object_modifier.cc
@@ -591,7 +591,8 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList *UNUSED(reports),
   me->totvert = verts_num;
   me->totedge = edges_num;
 
-  CustomData_add_layer(&me->vdata, CD_MVERT, CD_SET_DEFAULT, nullptr, verts_num);
+  CustomData_add_layer_named(
+      &me->vdata, CD_PROP_FLOAT3, CD_CONSTRUCT, nullptr, verts_num, "position");
   CustomData_add_layer(&me->edata, CD_MEDGE, CD_SET_DEFAULT, nullptr, edges_num);
   CustomData_add_layer(&me->fdata, CD_MFACE, CD_SET_DEFAULT, nullptr, 0);
 
@@ -610,7 +611,7 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList *UNUSED(reports),
     ParticleCacheKey *key = cache[a];
     int kmax = key->segments;
     for (int k = 0; k <= kmax; k++, key++, cvert++, vert_index++) {
-      copy_v3_v3(positions[vert_index], key->co);
+      positions[vert_index] = key->co;
       if (k) {
         medge->v1 = cvert - 1;
         medge->v2 = cvert;
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
index ed631ef4d6b..8e3c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list