RE: Problems with handling sharp edges
2023-04-14, 20:16 (This post was last modified: 2023-04-14, 20:21 by Max Murtazin.)
2023-04-14, 20:16 (This post was last modified: 2023-04-14, 20:21 by Max Murtazin.)
(2023-04-14, 14:39)Jonathan N Wrote: What techniques have you tried? The simple case is to smooth all normals by averaging the normal at each vertex by summing up the normals of adjacent faces and normalizing the result. Normals are interpolated between vertices when rendering, so you may need to index the vertices differently depending on the normals you calculate.
One approach I've seen is using conditional lines to average normals. I've found that averaging on conditional lines or at least edges that aren't marked sharp produces some artifacts when working with triangulated meshes. Applying the averaging before triangulating should give slightly better results. This seems to be the approach used by some older applications.
Another approach is to just average the normals using an angle threshold. For each vertex in each face, add the normal for any adjacent face that differs by at most some threshold. This is common in hard surface modeling and tends to work well for most parts. There's some example code online like the one here: https://gist.github.com/Ni55aN/90c017faf...8ab6566cfa.
In my Blender importer, I split the sharp edges as well as using an angle threshold. This seems to give better results. I'm still working on recreating this code to work outside of Blender.
At this moment, I've already managed to do that
The way I'm doing it is taking edge lines (type 2) and using them to determine should I merge vertices or not (edge line - not merge, no edgeline - merge)
Gives fine results in most cases, tho it's not perfect. I was thinking to switch instead to using conditional lines instead, but it has it's downside of not being an option of models processed through Bricklink Part Designer - something I do want to factor in. Probably, best will be to use mix of both and also angle threshold - if edge is sharp enough, check for condline and smooth if there's none, and if it's nor sharp enough instead check for an edgeline
By the way, angle threshold is very easy to do - you just need to calculate angle between face normals of two faces you are thinking to smooth
Here's a render to show how current approach performs. Aside from chest, all artifacts are either due to rounding or Eyesight render doing some odd stuff: