WIP: Mesh: Refactor vertex normals for determinism #105920

Closed
Hans Goudey wants to merge 6 commits from HooglyBoogly:mesh-normals-calc-changes into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

6 Commits

Author SHA1 Message Date
Hans Goudey 9ceb145914 Mesh: Use topology map when calculating vertex normals
Vertex normals are now deterministic, meaning the result values will
be the same every time they are calculated. This is important for
making renders match exactly when none of the geometry changes.
2023-04-30 18:16:45 -04:00
Hans Goudey c92f9dc137 Mesh: Cache vertex to face topology map
This commit uses the `SharedCache` concept to keep a cached map from
mesh vertices to polygons available on a mesh as necessary. The map
is split into two caches internally, since the same offsets can be
reused for a potential vertex to face corner map in the future
(though that may be a bit preemptive).

Such a cache (or similar) is often used in topology-changing operations,
and in the future it can be updated as necessary. For now it's simply
calculated as necessary though, since it may take time to validate the
choice of cached map. For example, it could make sense to cache
a vertex to corner and a corner to face map instead.
2023-04-30 18:16:45 -04:00
Hans Goudey 5d3baadb35 Mesh: Avoid clearing poly normals after splitting edges
As noted in a comment, the edge split operation doesn't invalidate
face normals.
2023-04-30 18:15:34 -04:00
Hans Goudey f3ddeb055a Mesh: Use shared cache for mesh poly and vert normals
This allows avoiding recalculations of mesh normals even when meshes
are copied, if the positions and topology are unchanged. Face corner
normals aren't affected yet though.

The BKE_mesh_vert_normals_for_write behavior is quite hacky,
it may need a better solution in the future.
2023-04-30 18:15:34 -04:00
Hans Goudey 501b4ad8c0 Mesh: Add API functions to assign vertex normals
A few places already calculated vertex normals with better contextual
information to improve performance. To allow abstracting the storage
of vertex normals more, change some code from "get normals, set values"
to "make array, set values, give to mesh". This makes the API less
awkward too, since previously the "get for write" and "clear dirty"
calls always had to be separated.
2023-04-30 18:14:59 -04:00
Hans Goudey 0a6a887e2e Separate poly and vertex normal calculation 2023-04-30 18:14:59 -04:00