LDrawLoader: Fix a corner case when smoothing normals #23169
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue: #23157 (comment)
Description
This PR fixes a small visual glitch is normal smoothing that has been bugging me for awhile and I finally took a moment to look into it. The way vertices are determined to be close enough to be merged is via vertex hashing which effectively quantizes all vertices into bins which should be expected to have artifacts at points that lie exactly on these quantization boundaries especially when the points being merged may have matrix operations applied to them incurring error. It's much faster than other more robust methods, though. This was happening in this dish element here:
The points on the top strip of the artifact have y set to
1.7
and the points on the bottom strip are set to1.6999...
which get quantized to170
and169
respectively meaning they won't get merged. The inclusion of multiplying the value by1 + 1e-10
thereby adding a small epsilon to1.6999...
to offset the error and pushes it in to the appropriate value to be merged. This effectively moves the boundaries of the quantization by a very small amount meaning the error could still happen but given the nature of the data in the LDraw files it seems much more unlikely.If there are other thoughts on how to address this let me know!