[Bf-blender-cvs] [5ca38fd612c] master: Cleanup/Docs: Add comments to Mesh header, rearrange fields

Hans Goudey noreply at git.blender.org
Fri Dec 10 17:42:40 CET 2021


Commit: 5ca38fd612cdde15bf46a66f96993bad6a185706
Author: Hans Goudey
Date:   Fri Dec 10 10:42:28 2021 -0600
Branches: master
https://developer.blender.org/rB5ca38fd612cdde15bf46a66f96993bad6a185706

Cleanup/Docs: Add comments to Mesh header, rearrange fields

Most of the fields in Mesh had no comments, or outdated misleading
comments. For example, "BMESH ONLY" referred to the BMesh project,
not the data structure. Given how much these structs are used, it should
save a lot of time to have proper comments.

I also rearranged the fields in mesh to have a more logical order. Now
the most important fields come first. In the process I was able to
remove 19 bytes of unnecessary padding (31->12). I just had to
change a `short` flag to `char`.

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

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/mesh.cc
M	source/blender/blenkernel/intern/object.cc
M	source/blender/editors/transform/transform_convert_object_texspace.c
M	source/blender/makesdna/DNA_curve_types.h
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/makesdna/DNA_meshdata_types.h
M	source/blender/makesdna/DNA_meta_types.h

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 1e7262248d5..c39583d234a 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -229,7 +229,7 @@ void BKE_mesh_texspace_calc(struct Mesh *me);
 void BKE_mesh_texspace_ensure(struct Mesh *me);
 void BKE_mesh_texspace_get(struct Mesh *me, float r_loc[3], float r_size[3]);
 void BKE_mesh_texspace_get_reference(struct Mesh *me,
-                                     short **r_texflag,
+                                     char **r_texflag,
                                      float **r_loc,
                                      float **r_size);
 void BKE_mesh_texspace_copy_from_object(struct Mesh *me, struct Object *ob);
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 3f4268f2169..882d6f111d8 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -507,7 +507,7 @@ void BKE_object_handle_update_ex(struct Depsgraph *depsgraph,
 void BKE_object_sculpt_data_create(struct Object *ob);
 
 bool BKE_object_obdata_texspace_get(struct Object *ob,
-                                    short **r_texflag,
+                                    char **r_texflag,
                                     float **r_loc,
                                     float **r_size);
 
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 5f8d4ccb734..05aa9111fa3 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -1246,7 +1246,7 @@ void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_size[3])
   }
 }
 
-void BKE_mesh_texspace_get_reference(Mesh *me, short **r_texflag, float **r_loc, float **r_size)
+void BKE_mesh_texspace_get_reference(Mesh *me, char **r_texflag, float **r_loc, float **r_size)
 {
   BKE_mesh_texspace_ensure(me);
 
@@ -1264,7 +1264,7 @@ void BKE_mesh_texspace_get_reference(Mesh *me, short **r_texflag, float **r_loc,
 void BKE_mesh_texspace_copy_from_object(Mesh *me, Object *ob)
 {
   float *texloc, *texsize;
-  short *texflag;
+  char *texflag;
 
   if (BKE_object_obdata_texspace_get(ob, &texflag, &texloc, &texsize)) {
     me->texflag = *texflag;
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 3628b522f76..e74d9d3ee61 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -4454,7 +4454,7 @@ void BKE_object_sculpt_data_create(Object *ob)
   ob->sculpt->mode_type = (eObjectMode)ob->mode;
 }
 
-bool BKE_object_obdata_texspace_get(Object *ob, short **r_texflag, float **r_loc, float **r_size)
+bool BKE_object_obdata_texspace_get(Object *ob, char **r_texflag, float **r_loc, float **r_size)
 {
 
   if (ob->data == nullptr) {
diff --git a/source/blender/editors/transform/transform_convert_object_texspace.c b/source/blender/editors/transform/transform_convert_object_texspace.c
index 98879852326..3e434da66ec 100644
--- a/source/blender/editors/transform/transform_convert_object_texspace.c
+++ b/source/blender/editors/transform/transform_convert_object_texspace.c
@@ -51,7 +51,7 @@ void createTransTexspace(TransInfo *t)
   TransData *td;
   Object *ob;
   ID *id;
-  short *texflag;
+  char *texflag;
 
   ob = OBACT(view_layer);
 
diff --git a/source/blender/makesdna/DNA_curve_types.h b/source/blender/makesdna/DNA_curve_types.h
index 7230ac38f2f..dab43d16cbb 100644
--- a/source/blender/makesdna/DNA_curve_types.h
+++ b/source/blender/makesdna/DNA_curve_types.h
@@ -228,9 +228,8 @@ typedef struct Curve {
   /** Creation-time type of curve datablock. */
   short type;
 
-  /** Keep a short because of BKE_object_obdata_texspace_get(). */
-  short texflag;
-  char _pad0[6];
+  char texflag;
+  char _pad0[7];
   short twist_mode;
   float twist_smooth, smallcaps_scale;
 
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index 3943c063c39..77cb553c7c7 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -74,7 +74,7 @@ struct MLoopTri_Store {
   int len_alloc;
 };
 
-/* not saved in file! */
+/* Runtime data, not saved in files. */
 typedef struct Mesh_Runtime {
   /* Evaluated mesh for objects which do not have effective modifiers.
    * This mesh is used as a result of modifier stack evaluation.
@@ -82,27 +82,33 @@ typedef struct Mesh_Runtime {
   struct Mesh *mesh_eval;
   void *eval_mutex;
 
-  struct EditMeshData *edit_data;
-  void *batch_cache;
+  /** Needed to ensure some thread-safety during render data pre-processing. */
+  void *render_mutex;
 
-  struct SubdivCCG *subdiv_ccg;
-  void *_pad1;
-  int subdiv_ccg_tot_level;
-  char _pad2[4];
+  /** Lazily initialized SoA data from the #edit_mesh field in #Mesh. */
+  struct EditMeshData *edit_data;
 
-  int64_t cd_dirty_vert;
-  int64_t cd_dirty_edge;
-  int64_t cd_dirty_loop;
-  int64_t cd_dirty_poly;
+  /**
+   * Data used to efficiently draw the mesh in the viewport, especially useful when
+   * the same mesh is used in many objects or instances. See `draw_cache_impl_mesh.c`.
+   */
+  void *batch_cache;
 
+  /** Cache for derived triangulation of the mesh. */
   struct MLoopTri_Store looptris;
 
-  /** `BVHCache` defined in 'BKE_bvhutil.c' */
+  /** Cache for BVH trees generated for the mesh. Defined in 'BKE_bvhutil.c' */
   struct BVHCache *bvh_cache;
 
-  /** Non-manifold boundary data for Shrinkwrap Target Project. */
+  /** Cache of non-manifold boundary data for Shrinkwrap Target Project. */
   struct ShrinkwrapBoundaryData *shrinkwrap_data;
 
+  /** Needed in case we need to lazily initialize the mesh. */
+  CustomData_MeshMasks cd_mask_extra;
+
+  struct SubdivCCG *subdiv_ccg;
+  int subdiv_ccg_tot_level;
+
   /** Set by modifier stack if only deformed from original. */
   char deformed_only;
   /**
@@ -122,14 +128,15 @@ typedef struct Mesh_Runtime {
    */
   char wrapper_type_finalize;
 
-  char _pad[4];
-
-  /** Needed in case we need to lazily initialize the mesh. */
-  CustomData_MeshMasks cd_mask_extra;
+  /**
+   * Used to mark when derived data needs to be recalculated for a certain layer.
+   * Currently only normals.
+   */
 
-  /** Needed to ensure some thread-safety during render data pre-processing. */
-  void *render_mutex;
-  void *_pad3;
+  int64_t cd_dirty_vert;
+  int64_t cd_dirty_edge;
+  int64_t cd_dirty_loop;
+  int64_t cd_dirty_poly;
 
 } Mesh_Runtime;
 
@@ -141,101 +148,191 @@ typedef struct Mesh {
   /** Old animation system, deprecated for 2.5. */
   struct Ipo *ipo DNA_DEPRECATED;
   struct Key *key;
-  struct Material **mat;
-  struct MSelect *mselect;
 
-  /* BMESH ONLY */
-  /* New face structures. */
-  struct MPoly *mpoly;
-  struct MLoop *mloop;
-  struct MLoopUV *mloopuv;
-  struct MLoopCol *mloopcol;
-  /* END BMESH ONLY */
+  /**
+   * An array of materials, with length #totcol. These can be overridden by material slots
+   * on #Object. Indices in #MPoly.mat_nr control which material is used for every face.
+   */
+  struct Material **mat;
 
   /**
-   * Legacy face storage (quads & tries only),
-   * faces are now stored in #Mesh.mpoly & #Mesh.mloop arrays.
-   *
-   * \note This would be marked deprecated however the particles still use this at run-time
-   * for placing particles on the mesh (something which should be eventually upgraded).
+   * Array of vertices. Edges and faces are defined by indices into this array.
+   * \note This pointer is for convenient access to the #CD_MVERT layer in #vdata.
    */
-  struct MFace *mface;
-  /** Store tessellation face UV's and texture here. */
-  struct MTFace *mtface;
-  /** Deprecated, use mtface. */
-  struct TFace *tface DNA_DEPRECATED;
-  /** Array of verts. */
   struct MVert *mvert;
-  /** Array of edges. */
+  /**
+   * Array of edges, containing vertex indices. For simple triangle or quad meshes, edges could be
+   * calculated from the #MPoly and #MLoop arrays, however, edges need to be stored explicitly to
+   * edge domain attributes and to support loose edges that aren't connected to faces.
+   * \note This pointer is for convenient access to the #CD_MEDGE layer in #edata.
+   */
   struct MEdge *medge;
-  /** Deform-group vertices. */
-  struct MDeformVert *dvert;
-  /** List of bDeformGroup names and flag only. */
-  ListBase vertex_group_names;
+  /**
+   * Face topology storage of the size and offset of each face's section of the #mloop face corner
+   * array. Also stores various flags and the `material_index` attribute.
+   * \note This pointer is for convenient access to the #CD_MPOLY layer in #pdata.
+   */
+  struct MPoly *mpoly;
+  /**
+   * The vertex and edge index at each face corner.
+   * \note This pointer is for convenient access to the #CD_MLOOP layer in #ldata.
+   */
+  struct MLoop *mloop;
 
-  /* array of colors for the tessellated faces, must be number of tessellated
-   * faces * 4 in length */
-  struct MCol *mcol;
-  struct Mesh *texcomesh;
+  /** The number of vertices (#MVert) in the mesh, and the size of #vdata. */
+  int totvert;
+  /** The number of edges (#MEdge) in the mesh, and the size of #edata. */
+  int totedge;
+  /** The number of polygons/faces (#MPoly) in the mesh, and the size of #pdata. */
+  int totpoly;
+  /** The number of face corners (#MLoop) in the mesh, and the size of #ldata. */
+  int totloop;
 
-  /* When the object is available, the preferred access method is: BKE_editmesh_from_object(ob) */
-  /** Not saved in file. */
-  struct BMEditMesh *edit_mesh;
+  CustomData vdata, edata, pdata, ldata;
+
+  /** "Vertex group" vertices. */
+  struct MDeformVert *dvert;
+  /**
+   * List of vertex group (#bDeformGroup) names and flags only. Actual weights are stored in dvert.
+   * \note This pointer is for convenient access to the #CD_MDEFORMVERT layer in #vdata.
+   */
+  ListBase vertex_group_names;
+  /** The active index in the #vertex_group_names list. */
+  int vertex_group_active_index;
 
-  struct CustomData vdata, edata, fdata;
+  /**
+   * The index of the active attribute in the UI. The attribute list is a combination of the
+  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list