Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of OBJ models in Right Handed mode #207

Merged
merged 2 commits into from
Mar 7, 2022

Conversation

Carifio24
Copy link
Member

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 and indexiesC in the FlipHandedness 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, and partIndex), 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.

@Carifio24
Copy link
Member Author

Just confirming that the ISS model looks identical to me with and without this change.

@pkgw
Copy link
Contributor

pkgw commented Mar 3, 2022

Ah, OK, I see you've changed only the specific issue about the triangle indexing. Should we change the code to load OBJs as right-handed by default, instead of requiring user intervention?

@Carifio24
Copy link
Member Author

Yeah, that's probably the best thing to do. I'll add that to this PR.

@Carifio24
Copy link
Member Author

I've added in this functionality - any newly-loaded .obj files will be loaded with right-handed mode automatically selected. Just as a reference, page B1-6 here states that .obj files use a right-handed coordinate system.

With the change as I've made it, existing WWTL layer files wont be affected by this. When an instance of Object3d is created from a layers file, the path that gets passed into LoadData is a .txt file, so the line that sets flipHandedness = true won't get executed. I think this is the right approach - otherwise, old layer files will get altered, and it would be impossible to save a model from a .obj as left-handed if you wanted to.

@pkgw
Copy link
Contributor

pkgw commented Mar 7, 2022

Sounds good! Nice analysis of the correct place to make the change.

@pkgw pkgw merged commit fcbfd6c into WorldWideTelescope:master Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants