Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix earcut bug - triangulating faces with +4 vertices (#32)
* fix earcut bug - check triangles for correct order corresponding to original face * actually check if it's 2d or 3d before turning everything to 3d * checking the edge orientation using the face instead of faceEdges * second earcut fix - since only the first two coordinates are used in triangulation (even when dim=3), it is important we give it a nondegenerate face.. this commit checks which coordinates have the largest variance and rearranges the dimensions accordingly. this doesn't affect the model in any way * fix for the fix - just try all dimensions combinations until we hate a triangulation * Fix indentation to match coding style; remove unnecessary changes * Correct is2d and needsFlip detection and y/z flipping * Correct is2d detection: 2D only if all vertices are 2D, and treat 0 the same as an absent third coordinate. * Always swap y and z coordinates when importing/exporting FOLD, independent of 2D status, for consistent behavior in all cases. (To get there, `rawFold` also has swapped coordinates.) * To decide `needsFlip`, instead of looking for a face edge in the first triangle, which can fail if the first triangle is a fully interior triangle, look for the first edge of the face in all the triangles. * Revert 2D -> 3D mapping instead of y/z swap. Swapping y/z flips the coordinate system between left- and right-handed, effectively reversing the notions of cw/ccw. This isn't an issue in 2D, because there it would be the same as mapping (x, y, z) → (x, -z, y) (because z=0) which doesn't flip handedness, but it's a problem in 3D. * earcut sometimes returns less triangles than needed to cover the face (because of it using only the first two coordinates, and possible degeneracies there). this update makes sure there are at least enough triangles before breaking * check dimension combination starting from [2,0,1] to [1, 2, 0] to [0, 1, 2] Co-authored-by: Erik Demaine <[email protected]>
- Loading branch information