This task goal is to discuss the requirements and design a new mesh representation structure to replace both ##Mesh## and grids in Sculpt Mode, trying to improve performances, memory usage and tool compatibility.
# Requirements
## Tools
### Main topology queries
Almost all tools and functionality in sculpt mode relies on the following topology info:
{F9608160}
**Vertex to connected vertices:** All cloth sculpting, boundary, pose, all smooth algorithms, data slide and flood fill operations rely on looping over neighbor vertices. This is the most performance-critical operation.
**Vertex to faces that use that vertex:** Used for all face set related functionality (mesh visibility state, face set boundaries, automasking, pose brush origin detection...)
On top of this, tools need to always know if a vertex is part of a mesh boundary. Right now, this is cached into a bitmap by looping over polys and edges of ##Mesh##. This info does not change during the sculpting session unless the geometry is modified.
### Normal updates for deformation
Updating the normals is currently done in two loops. First normals are calculated per face and then accumulated into vertices using atomics. Then vertex normals are normalized in a second loop.
{F9608162}
As a proposal, if the neighbors vertex list is stored in radial order, it is possible to approximate the normal in a single loop per vertex, without atomics and with a single square root operation. Storing the list in radial order will also help to simplify and implementing new tools.
### Draw Face Sets / Face Set Gestures
{F9608164}
**Face to vertices that use that face:** This is used in the Draw Face Sets brush to increase the precision of the falloff. As the main iterator loops over vertices, the shown topology queries are used to get the center of the affected faces and apply the brush falloff in that point instead of using the vertex directly. This also allows to paint individual faces with a Face Set
### Expand / Face Set Grow / Shrink
{F9608166}
**Face to neighbor faces by and edge and neighbor faces by a vertex:** This is used to grow/shrink face sets IDs and create different patterns in Expand. It is also used to delete Face sets from the mesh with content-aware filling.
### Face Sets Init
{F9608168}.
Face to neighbor faces with reference to edge: This is used to create Face Sets by UV seams or crease data. The reference to the edge is needed to check different flags and limit the flood fill operation which works using faces and faces neighbors. This is currently implemented using ##BMesh##
### Mesh Fairing
Fairing supports multiple algorithms to calculate vertex and loop weights to achieve different effects. The only one of those algorithms that is currently being used for the sculpt mode tools is Voronoi vertex weights.
{F9608170}
When using ##Mesh##, this algorithm is using a vertex to loop map. From that loop, it needs the next and previous vertex to make a triangle. If neighbors are stored in radial order, this should be possible to implement using only that information.
Even if fairing uses loop weights, both fairing operations that are required for sculpt mode use uniform loop weights (all loops have the weight of 1), so face corner references are not needed.
### Geodesic Distances
Geodesic distances is used for surface falloff and expand. The current geodesic distances algorithm needs two extra maps on top of #Mesh# to implement the following queries:
{F9608172}
**Edge to neighbor vertices connected by a face:** Currently implemented by using and edge to poly map and then looping overt the loops of that poly.
{F9608176}
**Vertex to edges that use that vertex**: Currently implemented with a vertex -> edge map
**Geodesic distances requires references to the geometry edges.**
## Rendering
## BVH building and ray intersections
Both are done using a separate array to store the triangles. In Multires, they use the grids directly.
## Mesh / BMesh conversions
* Sculpting with modifiers enabled require copying the coordinate data from the sculpt geometry to ##Mesh## after each deformation.(I don't think this would be problem).
* Both remeshers require a conversion from the sculpt geometry to ##Mesh## in order to work. Voxel should be expected to work with high poly meshes, and it already contains a ##Mesh## -> ##BMesh## -> ##Mesh## conversion which takes up to 80% of its execution time.
* Trimming tools require a conversion to ##BMesh## in order to use the boolean solver.
* Mesh slicing and extracting require the sculpt geometry with mask and face set datalayers as ##Mesh##
* Face sets form Edit mode selection requires ##Mesh## selection flags. This can be copied on geometry creation as they are not modified by sculpt mode.
* Dyntopo needs to be discussed separately. There should not be a problem to use ##BMesh## for it.