-
Notifications
You must be signed in to change notification settings - Fork 145
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 earcut bug - triangulating faces with +4 vertices #32
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
40385f4
fix earcut bug - check triangles for correct order corresponding to o…
eyalperry88 3feb42d
actually check if it's 2d or 3d before turning everything to 3d
eyalperry88 50f689b
removed accidental newline
eyalperry88 6cc39c3
fixed! checking the edge orientation using the face instead of faceEdges
eyalperry88 2bbc16d
second earcut fix - since only the first two coordinates are used in …
eyalperry88 f5b8979
fix for the fix - just try all dimensions combinations until we hate …
eyalperry88 fc84a3d
Fix indentation to match coding style; remove unnecessary changes
edemaine d7fb3d1
Correct is2d and needsFlip detection and y/z flipping
edemaine 68c9a6a
needsFlip bug fix
edemaine ff66566
Revert 2D -> 3D mapping instead of y/z swap
edemaine 940b2e0
earcut sometimes returns less triangles than needed to cover the face…
eyalperry88 18a0313
check dimension combination starting from [2,0,1] to [1, 2, 0] to [0,…
eyalperry88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added this update. I found another problem, here is how to recreate:
On my end, I see exactly two triangles missing (I see this in a previous comment too if you notice)
Here is the FOLD file for reference:
origamisimulator.fold.zip
Debugging it, it seems that again because of earcut using the first two coordinates, for some faces (very few..) we get less triangles than needed to cover the face. In this FOLD, there are two 5 vertices faces that earcut returns only two triangles (one vertex is out of the game).
My fix is checking that the number of triangles is at least the number of vertices on the face - 2. That is always right, right? Using this check, we try giving earcut a different coordinate system and it eventually returns the correct triangulation. I definitely think replacing earcut would be a better option in the future though..
We're getting close... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, assuming no added vertices (which must be the case for earcut, because it has no mechanism to return additional vertices), the number of triangles should be exactly face - 2, so this seems like a good change.
What do you think about also changing the order that we try the dimension pairs to start with x and z, like we do in 2D? It shouldn't matter, but for files that were originally flat and imported, this seems like a better starting point, and kind of nice to try the
is2d
algorithm and then continue? We could just reverse the loop...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. Pushed a commit where I simply reversed the loop and checked with the FOLD and SVG models and it all seems fine