This is an initial patch to avoid converting EditMesh to Mesh.
This patch makes the following changes:
- Mesh data blocks in the modifier stack can be "thin wrapped" edit-mesh data (empty mesh data, with pointers to the `EditMesh` and `EditMeshData`).
- Any users of these meshes that need the full mesh data can ensure this data exists (delaying edit-mesh conversion until it's needed).
- Currently, this means there is no EditMesh to Mesh conversion for edit-mode for many deform modifiers, giving significant performance improvements (about 2x).
In this patch a define is checked for, currently no functional changes unless the developer defines `USE_EDITMESH_THIN_WRAP` (exact details of how this is enabled can be tweaked).
Once this patch is applied, each modifier with a `deformVertsEM` callback which runs `BKE_mesh_from_editmesh_thick_wrap_ensure` needs to be updated to remove this call.
In most cases this can be removed once there is a utility to get vertex weights from both a mesh and edit-mesh vertices.
Performance
-----------
Testing playback of a mesh with ~98k tris and two deform modifiers gives a little over 2x performance improvement here.
{F8413233}
Note that `draw_cache_extract_mesh.c` is accessing normals and coordinates more than I would like. In the current patch this checks for deformed coordinates on each access.
Eventually we should be able to avoid passing vertex coordinates to the GPU so many times to reduce the overhead.
Currently it's not practical to split the code into separate branches for deform/non-deform cases. With different logic for updating the coordinate buffer, we might be able to avoid checking for deformed coords on every access.
Remaining Work
--------------
- Check on the possibility of threading issues (the need for locking). As long as lazy initializing the mesh data happens in modifiers (for the mesh being created by the modifier stack). This isn't needed, however we will most likely want locking for the final `id_eval`, as well as modifiers that depend on other objects geometry.
- Test cycles (render engines that use RNA).
- Checking UV tangents are being correctly calculated before & after this patch is applied.
- Custom normals code depends on Mesh data layer in
and tangent calculation need to be investigated (see `BKE_mesh_foreach_mapped_loop`, when `MESH_FOREACH_USE_NORMAL` is used). Although this is low priority as the function isn't used.
Proposal
--------
- Apply this patch as-is (or with only minor adjustments).
- Incrementally remove `BKE_mesh_from_editmesh_thick_wrap_ensure` for modifiers.
- Ensure there are no regressions (UV mapping, tangents, normal editing... etc).
- Remove pre-processor checks and enable this by default.
Further Work
------------
- Support modifiers passing thin-wrapped meshes between modifiers (`eModifierTypeFlag_AcceptsBMesh`). This shouldn't be such a big task, it's mostly a matter of making sure there are no regressions.
- Support bypassing normal calculation in wire-frame mode //(if we want 2.7x performance)//
- Support statvis display with coordinates deformed by modifiers.