amandaghassaei / OrigamiSimulator

Realtime WebGL origami simulator
http://origamisimulator.org/
MIT License
1.11k stars 140 forks source link

fix bug where earcut() faces have backwards winding #20

Closed mayakraft closed 4 years ago

mayakraft commented 4 years ago

an example of a FOLD file i was using for testing http://robbykraft.github.io/Origami/files/fold/crane.fold which of course could have errors on their own but to double check winding i've been using jason's FOLD viewer

edemaine commented 4 years ago

I agree that that file is much happier with this patch. I also found the earcut bug that is causing this. But I'm a little unclear whether reversing everything is always the right thing — should we instead preserve the given orientations, as in the patches mentioned in the earcut issue? I'm especially concerned about the 3D case...

I'm also confused why triangulatePolys always gets called with is2d set to true. As a result, earcut gets only the x and y coordinate of each point, with no z coordinate. Actually, if I'm reading things correctly, it gets the x coordinate and zero, because the y coordinate is put in the 3rd position not the 2nd (yuck). Should we actually use the 3D mode of earcut?

edemaine commented 4 years ago

This PR also seems to break the built-in Maze Foldings / origami simulator example (just selected from the Examples menu): it seems to flip the same faces that are incorrect in #21 (so that bug may be related to this earcut issue too). Turning off is2d didn't seem to help...

image

edemaine commented 4 years ago

Replaced by #32.