Closed Carifio24 closed 2 years ago
Just confirming that the ISS model looks identical to me with and without this change.
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?
Yeah, that's probably the best thing to do. I'll add that to this PR.
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.
Sounds good! Nice analysis of the correct place to make the change.
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.