[Bf-blender-cvs] [46c0b1942d2] refactor-mesh-remove-pointers: Branch compiles and very basic tests work

Hans Goudey noreply at git.blender.org
Sun Jul 31 20:06:34 CEST 2022


Commit: 46c0b1942d248383a3ed0c60fffd000a4e0e0734
Author: Hans Goudey
Date:   Sun Jul 31 13:06:26 2022 -0500
Branches: refactor-mesh-remove-pointers
https://developer.blender.org/rB46c0b1942d248383a3ed0c60fffd000a4e0e0734

Branch compiles and very basic tests work

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/mesh_legacy_convert.cc
M	source/blender/blenkernel/intern/multires_reshape_apply_base.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/particle_distribute.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/shrinkwrap.c
M	source/blender/blenloader/intern/versioning_legacy.c
M	source/blender/editors/mesh/mesh_data.cc
M	source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/makesrna/intern/rna_mesh.c
M	source/blender/makesrna/intern/rna_mesh_utils.h

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 1265c245039..aa1125e202b 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -151,7 +151,6 @@ void BKE_mesh_copy_parameters_for_eval(struct Mesh *me_dst, const struct Mesh *m
  * when a new mesh is based on an existing mesh.
  */
 void BKE_mesh_copy_parameters(struct Mesh *me_dst, const struct Mesh *me_src);
-void BKE_mesh_update_customdata_pointers(struct Mesh *me, bool do_ensure_tess_cd);
 void BKE_mesh_ensure_skin_customdata(struct Mesh *me);
 
 struct Mesh *BKE_mesh_new_nomain(
@@ -1050,7 +1049,7 @@ BLI_INLINE MEdge *BKE_mesh_edges_for_write(Mesh *mesh)
 
 BLI_INLINE const MPoly *BKE_mesh_polygons(const Mesh *mesh)
 {
-  return (const MPoly *)CustomData_get_layer(&mesh->vdata, CD_MPOLY);
+  return (const MPoly *)CustomData_get_layer(&mesh->pdata, CD_MPOLY);
 }
 BLI_INLINE MPoly *BKE_mesh_polygons_for_write(Mesh *mesh)
 {
@@ -1060,7 +1059,7 @@ BLI_INLINE MPoly *BKE_mesh_polygons_for_write(Mesh *mesh)
 
 BLI_INLINE const MLoop *BKE_mesh_loops(const Mesh *mesh)
 {
-  return (const MLoop *)CustomData_get_layer(&mesh->vdata, CD_MLOOP);
+  return (const MLoop *)CustomData_get_layer(&mesh->ldata, CD_MLOOP);
 }
 BLI_INLINE MLoop *BKE_mesh_loops_for_write(Mesh *mesh)
 {
@@ -1075,7 +1074,7 @@ BLI_INLINE const MDeformVert *BKE_mesh_deform_verts(const Mesh *mesh)
 BLI_INLINE MDeformVert *BKE_mesh_deform_verts_for_write(Mesh *mesh)
 {
   MDeformVert *dvert = (MDeformVert *)CustomData_duplicate_referenced_layer(
-      &mesh->ldata, CD_MDEFORMVERT, mesh->totvert);
+      &mesh->vdata, CD_MDEFORMVERT, mesh->totvert);
   if (dvert) {
     return dvert;
   }
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 32de13b148a..edf16adeb2f 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -737,47 +737,6 @@ const char *BKE_mesh_cmp(Mesh *me1, Mesh *me2, float thresh)
   return nullptr;
 }
 
-static void mesh_ensure_tessellation_customdata(Mesh *me)
-{
-  if (UNLIKELY((me->totface != 0) && (me->totpoly == 0))) {
-    /* Pass, otherwise this function  clears 'mface' before
-     * versioning 'mface -> mpoly' code kicks in T30583.
-     *
-     * Callers could also check but safer to do here - campbell */
-  }
-  else {
-    const int tottex_original = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
-    const int totcol_original = CustomData_number_of_layers(&me->ldata, CD_PROP_BYTE_COLOR);
-
-    const int tottex_tessface = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
-    const int totcol_tessface = CustomData_number_of_layers(&me->fdata, CD_MCOL);
-
-    if (tottex_tessface != tottex_original || totcol_tessface != totcol_original) {
-      BKE_mesh_tessface_clear(me);
-
-      BKE_mesh_add_mface_layers(&me->fdata, &me->ldata, me->totface);
-
-      /* TODO: add some `--debug-mesh` option. */
-      if (G.debug & G_DEBUG) {
-        /* NOTE(campbell): this warning may be un-called for if we are initializing the mesh for
-         * the first time from #BMesh, rather than giving a warning about this we could be smarter
-         * and check if there was any data to begin with, for now just print the warning with
-         * some info to help troubleshoot what's going on. */
-        printf(
-            "%s: warning! Tessellation uvs or vcol data got out of sync, "
-            "had to reset!\n    CD_MTFACE: %d != CD_MLOOPUV: %d || CD_MCOL: %d != "
-            "CD_PROP_BYTE_COLOR: "
-            "%d\n",
-            __func__,
-            tottex_tessface,
-            tottex_original,
-            totcol_tessface,
-            totcol_original);
-      }
-    }
-  }
-}
-
 void BKE_mesh_ensure_skin_customdata(Mesh *me)
 {
   BMesh *bm = me->edit_mesh ? me->edit_mesh->bm : nullptr;
@@ -849,28 +808,6 @@ bool BKE_mesh_clear_facemap_customdata(struct Mesh *me)
   return changed;
 }
 
-/**
- * This ensures grouped custom-data (e.g. #CD_MLOOPUV and #CD_MTFACE, or
- * #CD_PROP_BYTE_COLOR and #CD_MCOL) have the same relative active/render/clone/mask indices.
- *
- * NOTE(@campbellbarton): that for undo mesh data we want to skip 'ensure_tess_cd' call since
- * we don't want to store memory for #MFace data when its only used for older
- * versions of the mesh.
- */
-static void mesh_update_linked_customdata(Mesh *me, const bool do_ensure_tess_cd)
-{
-  if (do_ensure_tess_cd) {
-    mesh_ensure_tessellation_customdata(me);
-  }
-
-  CustomData_bmesh_update_active_layers(&me->fdata, &me->ldata);
-}
-
-void BKE_mesh_update_customdata_pointers(Mesh *me, const bool do_ensure_tess_cd)
-{
-  mesh_update_linked_customdata(me, do_ensure_tess_cd);
-}
-
 bool BKE_mesh_has_custom_loop_normals(Mesh *me)
 {
   if (me->edit_mesh) {
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index 7606c927886..fd54f06ac0b 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -23,6 +23,7 @@
 
 #include "BKE_attribute.hh"
 #include "BKE_customdata.h"
+#include "BKE_global.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_legacy_convert.h"
 #include "BKE_multires.h"
@@ -270,6 +271,47 @@ static void convert_mfaces_to_mpolys(ID *id,
 #undef ME_FGON
 }
 
+static void mesh_ensure_tessellation_customdata(Mesh *me)
+{
+  if (UNLIKELY((me->totface != 0) && (me->totpoly == 0))) {
+    /* Pass, otherwise this function  clears 'mface' before
+     * versioning 'mface -> mpoly' code kicks in T30583.
+     *
+     * Callers could also check but safer to do here - campbell */
+  }
+  else {
+    const int tottex_original = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
+    const int totcol_original = CustomData_number_of_layers(&me->ldata, CD_PROP_BYTE_COLOR);
+
+    const int tottex_tessface = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
+    const int totcol_tessface = CustomData_number_of_layers(&me->fdata, CD_MCOL);
+
+    if (tottex_tessface != tottex_original || totcol_tessface != totcol_original) {
+      BKE_mesh_tessface_clear(me);
+
+      BKE_mesh_add_mface_layers(&me->fdata, &me->ldata, me->totface);
+
+      /* TODO: add some `--debug-mesh` option. */
+      if (G.debug & G_DEBUG) {
+        /* NOTE(campbell): this warning may be un-called for if we are initializing the mesh for
+         * the first time from #BMesh, rather than giving a warning about this we could be smarter
+         * and check if there was any data to begin with, for now just print the warning with
+         * some info to help troubleshoot what's going on. */
+        printf(
+            "%s: warning! Tessellation uvs or vcol data got out of sync, "
+            "had to reset!\n    CD_MTFACE: %d != CD_MLOOPUV: %d || CD_MCOL: %d != "
+            "CD_PROP_BYTE_COLOR: "
+            "%d\n",
+            __func__,
+            tottex_tessface,
+            tottex_original,
+            totcol_tessface,
+            totcol_original);
+      }
+    }
+  }
+}
+
 void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh)
 {
   convert_mfaces_to_mpolys(&mesh->id,
@@ -285,7 +327,7 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh)
                            &mesh->totloop,
                            &mesh->totpoly);
 
-  BKE_mesh_update_customdata_pointers(mesh, true);
+  mesh_ensure_tessellation_customdata(mesh);
 }
 
 /**
@@ -344,7 +386,7 @@ void BKE_mesh_do_versions_convert_mfaces_to_mpolys(Mesh *mesh)
 
   CustomData_bmesh_do_versions_update_active_layers(&mesh->fdata, &mesh->ldata);
 
-  BKE_mesh_update_customdata_pointers(mesh, true);
+  mesh_ensure_tessellation_customdata(mesh);
 }
 
 /** \} */
@@ -779,7 +821,7 @@ void BKE_mesh_tessface_calc(Mesh *mesh)
                                      mesh->totloop,
                                      mesh->totpoly);
 
-  BKE_mesh_update_customdata_pointers(mesh, true);
+  mesh_ensure_tessellation_customdata(mesh);
 }
 
 void BKE_mesh_tessface_ensure(struct Mesh *mesh)
diff --git a/source/blender/blenkernel/intern/multires_reshape_apply_base.c b/source/blender/blenkernel/intern/multires_reshape_apply_base.c
index 69d84cc78d9..22b775e51cb 100644
--- a/source/blender/blenkernel/intern/multires_reshape_apply_base.c
+++ b/source/blender/blenkernel/intern/multires_reshape_apply_base.c
@@ -30,11 +30,11 @@
 void multires_reshape_apply_base_update_mesh_coords(MultiresReshapeContext *reshape_context)
 {
   Mesh *base_mesh = reshape_context->base_mesh;
+  MVert *base_vertices = BKE_mesh_vertices_for_write(base_mesh);
   const MLoop *mloop = reshape_context->base_loops;
-  MVert *mvert = reshape_context->base_vertices;
   for (int loop_index = 0; loop_index < base_mesh->totloop; ++loop_index) {
     const MLoop *loop = &mloop[loop_index];
-    MVert *vert = &mvert[loop->v];
+    MVert *vert = &base_vertices[loop->v];
 
     GridCoord grid_coord;
     grid_coord.grid_index = loop_index;
@@ -66,6 +66,7 @@ static float v3_dist_from_plane(const float v[3], const float center[3], const f
 void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape_context)
 {
   Mesh *base_mesh = reshape_context->base_mesh;
+  MVert *base_vertices = BKE_mesh_vertices_for_write(base_mesh);
 
   MeshElemMap *pmap;
   int *pmap_mem;
@@ -80,7 +81,7 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
   float(*origco)[3] = MEM_calloc_arrayN(
       base_mesh->totvert, sizeof(float[3]), "multires apply base origco");
   for (int i = 0; i < base_mesh->totvert; i++) {
-    copy_v3_v3(origco[i], reshape_context->base_vertices[i].co);
+    copy_v3_v3(origco[i], base_vertices[i].co);
   }
 
   for (int i = 0; i < base_mesh->totvert; i++) {
@@ -143,10 +144,10 @@ void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape
     normalize_v3(avg_no);
 
     /* Push vertex away from the plane. */
-    const float dist = v3_dist_from_plane(reshape_context->base_vertices[i].co, center, avg_no);
+    const float dist = v3_dist_from_plane(base_vertices[i].co, center, avg_no);
     copy_v3_v3(push, avg_no);
     mul_v3_fl(push, dist);
-    add_v3_v3(reshape_co

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list