Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-09-05 19:56:34 +0300
committerHans Goudey <h.goudey@me.com>2022-09-05 19:56:34 +0300
commit05952aa94d33eeb504fa63618ba35c2bcc8bd19b (patch)
treec9ec37adf20c3c37ccaab44869220dcbe8e987a3 /source/blender/makesdna
parent63cfc8f9f6d623f33b50c5c07976af2b22845713 (diff)
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes where possible. Mutable pointers like `Mesh.mvert` make that difficult by making ownership vague. They also make code more complex by adding redundancy. The simplest solution is just removing them and retrieving layers from `CustomData` as needed. Similar changes have already been applied to curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of the pointers generally makes code more obvious and more reusable. Mesh data is now accessed with a C++ API (`Mesh::edges()` or `Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`). The CoW changes this commit makes possible are described in T95845 and T95842, and started in D14139 and D14140. The change also simplifies the ongoing mesh struct-of-array refactors from T95965. **RNA/Python Access Performance** Theoretically, accessing mesh elements with the RNA API may become slower, since the layer needs to be found on every random access. However, overhead is already high enough that this doesn't make a noticible differenc, and performance is actually improved in some cases. Random access can be up to 10% faster, but other situations might be a bit slower. Generally using `foreach_get/set` are the best way to improve performance. See the differential revision for more discussion about Python performance. Cycles has been updated to use raw pointers and the internal Blender mesh types, mostly because there is no sense in having this overhead when it's already compiled with Blender. In my tests this roughly halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million face grid). Differential Revision: https://developer.blender.org/D15488
Diffstat (limited to 'source/blender/makesdna')
-rw-r--r--source/blender/makesdna/DNA_mesh_types.h122
1 files changed, 66 insertions, 56 deletions
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index 9912ec8ec3b..6b48f1e029f 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -10,8 +10,17 @@
#include "DNA_ID.h"
#include "DNA_customdata_types.h"
#include "DNA_defs.h"
+#include "DNA_meshdata_types.h"
#include "DNA_session_uuid_types.h"
+/** Workaround to forward-declare C++ type in C header. */
+#ifdef __cplusplus
+namespace blender {
+template<typename T> class Span;
+template<typename T> class MutableSpan;
+} // namespace blender
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -23,11 +32,8 @@ struct Key;
struct MCol;
struct MEdge;
struct MFace;
-struct MLoop;
struct MLoopCol;
struct MLoopTri;
-struct MLoopUV;
-struct MPoly;
struct MVert;
struct Material;
struct Mesh;
@@ -166,30 +172,6 @@ typedef struct Mesh {
*/
struct Material **mat;
- /**
- * 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 MVert *mvert;
- /**
- * 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;
- /**
- * 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;
-
/** 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. */
@@ -201,8 +183,6 @@ typedef struct 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.
@@ -218,18 +198,6 @@ typedef struct Mesh {
int attributes_active_index;
/**
- * 2D vector data used for UVs. "UV" data can also be stored as generic attributes in #ldata.
- * \note This pointer is for convenient access to the #CD_MLOOPUV layer in #ldata.
- */
- struct MLoopUV *mloopuv;
- /**
- * The active vertex corner color layer, if it exists. Also called "Vertex Color" in Blender's
- * UI, even though it is stored per face corner.
- * \note This pointer is for convenient access to the #CD_PROP_BYTE_COLOR layer in #ldata.
- */
- struct MLoopCol *mloopcol;
-
- /**
* Runtime storage of the edit mode mesh. If it exists, it generally has the most up-to-date
* information about the mesh.
* \note When the object is available, the preferred access method is #BKE_editmesh_from_object.
@@ -304,29 +272,32 @@ typedef struct Mesh {
char subdivr DNA_DEPRECATED;
char subsurftype DNA_DEPRECATED;
- /**
- * Deprecated. Store of runtime data for tessellation face UVs and texture.
- *
- * \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).
- */
- struct MTFace *mtface;
+ /** Deprecated pointer to mesh polygons, kept for forward compatibility. */
+ struct MPoly *mpoly DNA_DEPRECATED;
+ /** Deprecated pointer to face corners, kept for forward compatibility. */
+ struct MLoop *mloop DNA_DEPRECATED;
+
+ /** Deprecated array of mesh vertices, kept for reading old files, now stored in #CustomData. */
+ struct MVert *mvert DNA_DEPRECATED;
+ /** Deprecated array of mesh edges, kept for reading old files, now stored in #CustomData. */
+ struct MEdge *medge DNA_DEPRECATED;
+ /** Deprecated "Vertex group" data. Kept for reading old files, now stored in #CustomData.*/
+ struct MDeformVert *dvert DNA_DEPRECATED;
+ /** Deprecated runtime data for tessellation face UVs and texture, kept for reading old files. */
+ struct MTFace *mtface DNA_DEPRECATED;
/** Deprecated, use mtface. */
struct TFace *tface DNA_DEPRECATED;
-
- /* Deprecated. Array of colors for the tessellated faces, must be number of tessellated
- * faces * 4 in length. This is stored in #fdata, and deprecated. */
- struct MCol *mcol;
+ /** Deprecated array of colors for the tessellated faces, kept for reading old files. */
+ struct MCol *mcol DNA_DEPRECATED;
+ /** Deprecated face storage (quads & triangles only). Kept for reading old files. */
+ struct MFace *mface DNA_DEPRECATED;
/**
- * Deprecated face storage (quads & triangles only);
- * faces are now pointed to by #Mesh.mpoly and #Mesh.mloop.
+ * Deprecated storage of old faces (only triangles or quads).
*
* \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).
*/
- struct MFace *mface;
- /* Deprecated storage of old faces (only triangles or quads). */
CustomData fdata;
/* Deprecated size of #fdata. */
int totface;
@@ -345,6 +316,45 @@ typedef struct Mesh {
void *_pad2;
Mesh_Runtime runtime;
+#ifdef __cplusplus
+ /**
+ * Array of vertex positions (and various other data). Edges and faces are defined by indices
+ * into this array.
+ */
+ blender::Span<MVert> vertices() const;
+ /** Write access to vertex data. */
+ blender::MutableSpan<MVert> vertices_for_write();
+ /**
+ * 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.
+ */
+ blender::Span<MEdge> edges() const;
+ /** Write access to edge data. */
+ blender::MutableSpan<MEdge> edges_for_write();
+ /**
+ * Face topology storage of the size and offset of each face's section of the face corners.
+ */
+ blender::Span<MPoly> polygons() const;
+ /** Write access to polygon data. */
+ blender::MutableSpan<MPoly> polygons_for_write();
+ /**
+ * Mesh face corners that "loop" around each face, storing the vertex index and the index of the
+ * subsequent edge.
+ */
+ blender::Span<MLoop> loops() const;
+ /** Write access to loop data. */
+ blender::MutableSpan<MLoop> loops_for_write();
+
+ /**
+ * Vertex group data, encoded as an array of indices and weights for every vertex.
+ * \warning: May be empty.
+ */
+ blender::Span<MDeformVert> deform_verts() const;
+ /** Write access to vertex group data. */
+ blender::MutableSpan<MDeformVert> deform_verts_for_write();
+
+#endif
} Mesh;
/* deprecated by MTFace, only here for file reading */