Page MenuHome

Cleanup: Replace old Mesh edge split implementation
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Dec 9 2022, 9:58 PM.

Details

Summary

Recently a new geometry node for splitting edges was added in D16399.
However, there was already a similar implementation in mesh.cc that was
mainly used to fake auto smooth support in Cycles by splitting sharp
edges and edges around sharp faces.

While there are still possibilities for optimization in the new code,
the implementation is safer and simpler, multi-threaded, and aligns
better with development plans for caching topology on Mesh
and other recent developments with attributes.

This patch removes the old code and moves the node implementation to
the geometry module so it can be used in editors and RNA. The same
"free_loop_normals" argument is kept for backwards compatibility,
though it doesn't make much sense.

The new mesh editors function creates an IndexMask of edges to
split by reusing some of the code from the face corner normal calculation.

This change will help to simplify the changes in D16530 and T102858.

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Dec 9 2022, 9:58 PM
Hans Goudey (HooglyBoogly) created this revision.

Hey @Bastien Montagne (mont29), since you wrote most of the split implementation in mesh.cc I wanted to let you know about this patch.
The big picture is an aim to make some of the topology information and other operations in split normal calculation more generic
and reusable, in line with T93551 as well.

source/blender/makesrna/intern/rna_mesh_api.c
179

This is a bool, no need for != 0.

I had a failing test locally at some point but then I couldn't reproduce it anymore. Even in asan builds I'm not able to cause a crash. Maybe it was an unrelated fluke.

This revision is now accepted and ready to land.Dec 11 2022, 11:38 PM
Bastien Montagne (mont29) requested changes to this revision.Dec 12 2022, 2:37 AM

On quick overview the general changes seem fine, nice to deduplicate logic here. However, the new handling of free_loop_normals in rna_Mesh_split_faces does not looks correct to me.

Did not do detailed code review of the new code in mesh_split_edges.cc though, will trust you guys here.

source/blender/makesrna/intern/rna_mesh_api.c
179–184

This cannot be correct??? Have you checked what original BKE_mesh_split_faces is doing with this flag?

Flag is only here to tell BKE_mesh_split_faces to clear temporary split lnors (aka CD_NORMAL layer of loops) after edge splitting is done!

This revision now requires changes to proceed.Dec 12 2022, 2:37 AM
source/blender/makesrna/intern/rna_mesh_api.c
179–184

As far as I can tell, this does the same thing as before.

  1. Calculate loop normals, assign to CD_NORMAL layer.
  2. Use data from loop normals to split some edges. Do not modify the new loop normals
  3. At the end, free the loop normals if the argument is true

I don't think code relies on the normals being calculated at first though, there are other functions to do that already.
Part of the benefit of the change is that the split_faces function doesn't also need to calculate loop normals.

Or maybe we need to add calc_normals_split() in Cycles before this is called, is that what you're referring to?

Hans Goudey (HooglyBoogly) marked an inline comment as done.Dec 12 2022, 6:42 AM
source/blender/makesrna/intern/rna_mesh_api.c
179–184

I do not understand your answer here. You describe old code behavior, not new one, afaics:

OLD CODE (in BKE_mesh_split_faces):

  1. Compute split normals (aka generate CD_NORMAL temp ldata layer).
  2. Split edges.
  3. if free_loop_normals is true, clear temp CD_NORMAL layer from ldata.

NEW CODE:

  1. If free_loop_normal is set, clear CD_NORMAL layer from ldata, else create/update it (call to BKE_mesh_calc_normals_split).
  2. Split edges.

No clearing of CD_NORMAL ldata here at the end

...

source/blender/makesrna/intern/rna_mesh_api.c
179–184

The end result is the same, because BKE_mesh_split_faces didn't change the face corner normals.
That's true in the new code too. Splitting sharp edges does not change face corner normals.
Whether we do it before or after splitting edges makes no difference.

Am I really getting that wrong? It seems straightforward to me right now.

Resolved the confusion with Bastien in chat. The code to calculate the normals was quite confusing because they weren't actually used and the order of operations was different than before.

That was basically exposing an internal implementation detail as an optimization specifically for Cycles anyway, so we decided to deprecate the argument and require calc_normals_split() instead. I'll document that in the release notes when committing.

Besides note below (always good to document these details in code), LGTM now.

source/blender/makesrna/intern/rna_mesh_api.c
244

Would add a comment here for the future, something along those lines:

/* TODO: This parameter has no effect anymore, since the internal code does not need to compute temporary CD_NORMAL loop data. Should be removed for next major release.  */
This revision is now accepted and ready to land.Dec 14 2022, 1:19 AM
Hans Goudey (HooglyBoogly) marked 3 inline comments as done.Dec 14 2022, 1:40 AM