Fix display of OBJ models in Right Handed mode #207
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.
Currently, there is a bug when displaying a 3d model from an OBJ file in Right Handed mode that causes the faces to display incorrectly. For an example, see the screenshots in #169. I tried this out with a few other OBJ models and got similar results.
This issue is here, where both parts of the if-else block do the same thing. The fix in this PR is to exchange
indexiesB
andindexiesC
in theFlipHandedness
block. The reason for this is that the three vertices added at a time here define a triangle. These groups of three vertices are then used here to calculate the normal to the triangle via a cross product. Exchanging the two index lists changes the signs of these cross products, which needs to be done when the orientation changes.In case anyone finds the indices confusing, (
1
,partIndex-1
, andpartIndex
), the vertices in an OBJ file are listed in counter-clockwise order. So, if I have vertices indexed as 1, 2, 3, ..., then if X < Y, then the triangles with vertices 1 X Y should all have an outward normal consistent with the face as a whole. Thus, the triangle with vertices 1 Y X will have the opposite orientation, which we want when switching handedness. Basically, I think this part of the algorithm is doing a fan triangulation of the face.