[Bf-blender-cvs] [c4b32f1b291] master: Cleanup: Move mesh legacy conversion to a separate file

Hans Goudey noreply at git.blender.org
Fri Jul 8 05:43:13 CEST 2022


Commit: c4b32f1b291a3c3447879175225a3664aeb0b7ef
Author: Hans Goudey
Date:   Thu Jul 7 22:33:57 2022 -0500
Branches: master
https://developer.blender.org/rBc4b32f1b291a3c3447879175225a3664aeb0b7ef

Cleanup: Move mesh legacy conversion to a separate file

It's helpful to make the separation of legacy data formats explicit,
because it declutters actively changed code and makes it clear which
areas do not follow Blender's current design. In this case I separated
the `MFace`/"tessface" conversion code into a separate blenkernel
.cc file and header. This also makes refactoring to remove these
functions simpler because they're easier to find.

In the future, conversions to the `MLoopUV` type and `MVert`
can be implemented here for the same reasons (see T95965).

Differential Revision: https://developer.blender.org/D15396

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

M	source/blender/blenkernel/BKE_customdata.h
M	source/blender/blenkernel/BKE_mesh.h
A	source/blender/blenkernel/BKE_mesh_legacy_convert.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/customdata.cc
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/mesh_evaluate.cc
A	source/blender/blenkernel/intern/mesh_legacy_convert.cc
M	source/blender/blenkernel/intern/mesh_tessellate.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_distribute.c
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/intern/draw_cache_impl_particles.c
M	source/blender/editors/curves/intern/curves_ops.cc
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/physics/particle_object.c
M	source/blender/io/alembic/exporter/abc_writer_hair.cc
M	source/blender/io/collada/collada_utils.cpp
M	source/blender/makesrna/intern/rna_particle.c
M	source/blender/modifiers/intern/MOD_explode.c
M	source/blender/modifiers/intern/MOD_particlesystem.cc

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

diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index a1101c1df44..010fbb27172 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -550,33 +550,11 @@ void CustomData_validate_layer_name(const struct CustomData *data,
  */
 bool CustomData_verify_versions(struct CustomData *data, int index);
 
-/* BMesh specific custom-data stuff.
- *
- * Needed to convert to/from different face representation (for versioning). */
+/* BMesh specific custom-data stuff. */
 
-void CustomData_to_bmeshpoly(struct CustomData *fdata, struct CustomData *ldata, int totloop);
-void CustomData_from_bmeshpoly(struct CustomData *fdata, struct CustomData *ldata, int total);
 void CustomData_bmesh_update_active_layers(struct CustomData *fdata, struct CustomData *ldata);
-/**
- * Update active indices for active/render/clone/stencil custom data layers
- * based on indices from fdata layers
- * used by do_versions in `readfile.c` when creating pdata and ldata for pre-bmesh
- * meshes and needed to preserve active/render/clone/stencil flags set in pre-bmesh files.
- */
-void CustomData_bmesh_do_versions_update_active_layers(struct CustomData *fdata,
-                                                       struct CustomData *ldata);
 void CustomData_bmesh_init_pool(struct CustomData *data, int totelem, char htype);
 
-#ifndef NDEBUG
-/**
- * Debug check, used to assert when we expect layers to be in/out of sync.
- *
- * \param fallback: Use when there are no layers to handle,
- * since callers may expect success or failure.
- */
-bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *ldata, bool fallback);
-#endif
-
 /**
  * Validate and fix data of \a layer,
  * if possible (needs relevant callback in layer's type to be defined).
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 66e0ff8e81a..ff4f4a8dc9e 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -183,14 +183,6 @@ void BKE_mesh_orco_verts_transform(struct Mesh *me, float (*orco)[3], int totver
  */
 void BKE_mesh_orco_ensure(struct Object *ob, struct Mesh *mesh);
 
-/**
- * Rotates the vertices of a face in case v[2] or v[3] (vertex index) is = 0.
- * this is necessary to make the if #MFace.v4 check for quads work.
- */
-int BKE_mesh_mface_index_validate(struct MFace *mface,
-                                  struct CustomData *mfdata,
-                                  int mfindex,
-                                  int nr);
 struct Mesh *BKE_mesh_from_object(struct Object *ob);
 void BKE_mesh_assign_object(struct Main *bmain, struct Object *ob, struct Mesh *me);
 void BKE_mesh_from_metaball(struct ListBase *lb, struct Mesh *me);
@@ -304,7 +296,6 @@ bool BKE_mesh_minmax(const struct Mesh *me, float r_min[3], float r_max[3]);
 void BKE_mesh_transform(struct Mesh *me, const float mat[4][4], bool do_keys);
 void BKE_mesh_translate(struct Mesh *me, const float offset[3], bool do_keys);
 
-void BKE_mesh_tessface_ensure(struct Mesh *mesh);
 void BKE_mesh_tessface_clear(struct Mesh *mesh);
 
 void BKE_mesh_do_versions_cd_flag_init(struct Mesh *mesh);
@@ -333,15 +324,6 @@ void BKE_mesh_vert_coords_apply(struct Mesh *mesh, const float (*vert_coords)[3]
 
 /* *** mesh_tessellate.c *** */
 
-/**
- * Recreate #MFace Tessellation.
- *
- * \note This doesn't use multi-threading like #BKE_mesh_recalc_looptri since
- * it's not used in many places and #MFace should be phased out.
- */
-
-void BKE_mesh_tessface_calc(struct Mesh *mesh);
-
 /**
  * Calculate tessellation into #MLoopTri which exist only for this purpose.
  */
@@ -789,37 +771,6 @@ void BKE_mesh_calc_volume(const struct MVert *mverts,
                           float *r_volume,
                           float r_center[3]);
 
-/* tessface */
-void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh);
-/**
- * The same as #BKE_mesh_convert_mfaces_to_mpolys
- * but oriented to be used in #do_versions from `readfile.c`
- * the difference is how active/render/clone/stencil indices are handled here.
- *
- * normally they're being set from `pdata` which totally makes sense for meshes which are already
- * converted to #BMesh structures, but when loading older files indices shall be updated in other
- * way around, so newly added `pdata` and `ldata` would have this indices set
- * based on `fdata`  layer.
- *
- * this is normally only needed when reading older files,
- * in all other cases #BKE_mesh_convert_mfaces_to_mpolys shall be always used.
- */
-void BKE_mesh_do_versions_convert_mfaces_to_mpolys(struct Mesh *mesh);
-void BKE_mesh_convert_mfaces_to_mpolys_ex(struct ID *id,
-                                          struct CustomData *fdata,
-                                          struct CustomData *ldata,
-                                          struct CustomData *pdata,
-                                          int totedge_i,
-                                          int totface_i,
-                                          int totloop_i,
-                                          int totpoly_i,
-                                          struct MEdge *medge,
-                                          struct MFace *mface,
-                                          int *r_totloop,
-                                          int *r_totpoly,
-                                          struct MLoop **r_mloop,
-                                          struct MPoly **r_mpoly);
-
 /**
  * Flip a single MLoop's #MDisps structure,
  * low level function to be called from face-flipping code which re-arranged the mdisps themselves.
@@ -1072,18 +1023,6 @@ char *BKE_mesh_debug_info(const struct Mesh *me)
 void BKE_mesh_debug_print(const struct Mesh *me) ATTR_NONNULL(1);
 #endif
 
-/* Inlines */
-
-/* NOTE(@sybren): Instead of -1 that function uses ORIGINDEX_NONE as defined in BKE_customdata.h,
- * but I don't want to force every user of BKE_mesh.h to also include that file. */
-BLI_INLINE int BKE_mesh_origindex_mface_mpoly(const int *index_mf_to_mpoly,
-                                              const int *index_mp_to_orig,
-                                              const int i)
-{
-  const int j = index_mf_to_mpoly[i];
-  return (j != -1) ? (index_mp_to_orig ? index_mp_to_orig[j] : j) : -1;
-}
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/BKE_mesh_legacy_convert.h b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
new file mode 100644
index 00000000000..909fd0e0dea
--- /dev/null
+++ b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
+
+#pragma once
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "BLI_utildefines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct CustomData;
+struct Mesh;
+struct MFace;
+
+/**
+ * Recreate #MFace Tessellation.
+ *
+ * \note This doesn't use multi-threading like #BKE_mesh_recalc_looptri since
+ * it's not used in many places and #MFace should be phased out.
+ */
+
+void BKE_mesh_tessface_calc(struct Mesh *mesh);
+
+void BKE_mesh_tessface_ensure(struct Mesh *mesh);
+
+void BKE_mesh_add_mface_layers(struct CustomData *fdata, struct CustomData *ldata, int total);
+
+/**
+ * Rotates the vertices of a face in case v[2] or v[3] (vertex index) is = 0.
+ * this is necessary to make the if #MFace.v4 check for quads work.
+ */
+int BKE_mesh_mface_index_validate(struct MFace *mface,
+                                  struct CustomData *mfdata,
+                                  int mfindex,
+                                  int nr);
+
+void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh);
+
+/**
+ * The same as #BKE_mesh_convert_mfaces_to_mpolys
+ * but oriented to be used in #do_versions from `readfile.c`
+ * the difference is how active/render/clone/stencil indices are handled here.
+ *
+ * normally they're being set from `pdata` which totally makes sense for meshes which are already
+ * converted to #BMesh structures, but when loading older files indices shall be updated in other
+ * way around, so newly added `pdata` and `ldata` would have this indices set
+ * based on `fdata`  layer.
+ *
+ * this is normally only needed when reading older files,
+ * in all other cases #BKE_mesh_convert_mfaces_to_mpolys shall be always used.
+ */
+void BKE_mesh_do_versions_convert_mfaces_to_mpolys(struct Mesh *mesh);
+
+/* Inlines */
+
+/* NOTE(@sybren): Instead of -1 that function uses ORIGINDEX_NONE as defined in BKE_customdata.h,
+ * but I don't want to force every user of BKE_mesh.h to also include that file. */
+BLI_INLINE int BKE_mesh_origindex_mface_mpoly(const int *index_mf_to_mpoly,
+                                              const int *index_mp_to_orig,
+                                              const int i)
+{
+  const int j = index_mf_to_mpoly[i];
+  return (j != -1) ? (index_mp_to_orig ? index_mp_to_orig[j] : j) : -1;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 50be5b475d4..b2307c0e129 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -199,6 +199,7 @@ set(SRC
   intern/mesh_evaluate.cc
   intern/mesh_fair.cc
   intern/mesh_iterators.c
+  intern/mesh_legacy_convert.cc
   intern/mesh_mapping.c
   intern/mesh_merge.c
   intern/mesh_merge_customdata.cc
@@ -419,6 +420,7 @@ set(SRC
   BKE_mesh_boolean_convert.hh
   BKE_mesh_fair.h
   BKE_mesh_iterators.h
+  BKE_mesh_legacy_convert.h
   BKE_mesh_mapping.h
   BKE_mesh_mirror.h
   BKE_mesh_remap.h
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 74903e72f91..26fbd7d7b54 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -3517,97 +3517,6 @@ void CustomData_set(const CustomData *data, int index, int type, const void *sou
 
 /* BMesh functions */
 
-void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *ldata, int totloop)
-{
-  for (int i = 0; i < fdata->tot

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list