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

The STL loader flips the faces #13317

Merged
merged 3 commits into from
Dec 8, 2022

Conversation

YusakuNo1
Copy link
Contributor

@YusakuNo1 YusakuNo1 commented Dec 6, 2022

The current code loads STL files with faces flipped for the following combinations (RH for useRightHandedSystem, NO_ALTER for DO_NOT_ALTER_FILE_COORDINATES):

  NO_ALTER-true NO_ALTER-false
RH-true good bad
RH-false bad good

The correct combination for whether flip the face indices is like the following table, which means, we should only detect DO_NOT_ALTER_FILE_COORDINATES but not useRightHandedSystem:

  NO_ALTER-true NO_ALTER-false
RH-true flip no-flip
RH-false flip no-flip

… combinations (RH for useRightHandedSystem, NO_ALTER for DO_NOT_ALTER_FILE_COORDINATES):

                  NO_ALTER-true    NO_ALTER-false
RH-true      good                      bad
RH-false     bad                        good

The correct combination for whether flip the face indices is like the following table, which means, we should only detect DO_NOT_ALTER_FILE_COORDINATES but not useRightHandedSystem:
                  NO_ALTER-true    NO_ALTER-false
RH-true     flip                          no-flip
RH-false    flip                          no-flilp
@azure-pipelines
Copy link

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@azure-pipelines
Copy link

@YusakuNo1 YusakuNo1 changed the title The current code loads STL files with faces flipped The STL loader flips the faces Dec 6, 2022
Copy link
Member

@sebavan sebavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand how this will flip the faces in right handed mode after this PR which is needed ?

Not the space I am the most familiar with but I guess rightHanded should be used somewhere ?

@bghgary any thoughts ?

@bghgary
Copy link
Contributor

bghgary commented Dec 6, 2022

I have the same thought. We have to take rightHanded into account somewhere?

@YusakuNo1
Copy link
Contributor Author

+1 I'm wondering as well, the result came from my experiments, but I don't fully understand. Let me dive deeper and update back to this thread.

@sebavan
Copy link
Member

sebavan commented Dec 7, 2022

Moving to draft in the mean time

@sebavan sebavan marked this pull request as draft December 7, 2022 17:27
@YusakuNo1
Copy link
Contributor Author

YusakuNo1 commented Dec 8, 2022

I think I found the issue. First, I don't think we need to update index for right handed system because it's a "runtime" behavior, doesn't need to update data. Instead, it's calculated during runtime, switch back face culling from CCW to CW. For example, one of these "runtime" approaches are: the setter of useRightHandedSystem marks all the materials dirty and then they will be updated later, and the materials will be updated with flag useRightHandedSystem; second (which is obvious) we need to update indexes if Y & Z axis are swapped during loading time for STL file. It's the reason why the PR only need to consider DO_NOT_ALTER_FILE_COORDINATES.

This is the playground demonstrates: when I set the index as CCW for LH, it works for both LH and RH, even though in RH, it's CW.
https://playground.babylonjs.com/#FQ74IH#6

@YusakuNo1 YusakuNo1 marked this pull request as ready for review December 8, 2022 08:45
@sebavan
Copy link
Member

sebavan commented Dec 8, 2022

And this is still OK #12957 Thanks a lot for the fix !!!

Copy link
Contributor

@bghgary bghgary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. The STL loader doesn't need to check useRightHandedSystem because STL uses the default material which already accounts for it. I think we should probably add some tests for these cases, but it doesn't have to be part of this PR.

@sebavan sebavan merged commit 3d4c7ec into BabylonJS:master Dec 8, 2022
@YusakuNo1 YusakuNo1 deleted the yusakuno1/fix-stl-flipped-faces branch December 8, 2022 19:14
RaananW pushed a commit that referenced this pull request Dec 9, 2022
The STL loader flips the faces

Former-commit-id: e56d62846f18d3e571566796964fd8acec685695
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants