-
Notifications
You must be signed in to change notification settings - Fork 208
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
reflect polygon winding order in triangle winding order #44
Comments
Alternatively, to avoid the .reverse if not desired, it would be an option to just return the computed winding order of the polygon, in addition to the triangles, and then leave reversing to the consumer, or a wrapper function. However, this requires returning an array or object and would not be compatible. |
That's a valid feature request, thanks! My hunch is that |
Ok. Another option would be to have a (not required) "keep_sense" parameter for the earcut function. By default, it would be false and there would be no reversing. Only if requested (true) ccw polygon triangles would be reversed. This way, there is backward compatibility and transparency. |
x3dom maintainers absorbed earcut with the ccw-winding order patch in place but otherwise unchanged here: The patch will be available in the developer version of x3dom by tomorrow, and likely in the next stable version. Feel free to look the PR above over and voice concerns if there are any. Using array.reverse() on polygons with 50k points did not have a noticeable effect on performance in use cases although I am sure there is some cost. |
@andreasplesch awesome, thanks for letting me know! |
@andreasplesch |
@JamesJungmoonLim |
Currently, earcut will always produce triangles in a clockwise winding order, regardless of the sense of the winding order of the original polygon. In 3d, this can reverse the direction of the normal vector which is used for example for lighting calculations of the generated triangles with respect to the original polygon. So for 3d applications it is often required to reflect the winding order of the original polygon in the winding order of the triangles.
I created a branch with a few, simple modifications to this effect here:
https://github.com/andreasplesch/earcut/tree/ccw-winding
I would gladly submit a pull request if there is a desire to accommodate such a feature. There is a performance cost for ccw polygons since the array of indices needs to be reversed. array.reverse(), however, is a native array function, and hopefully optimized. To avoid this cost, it would be necessary to take into account winding order during construction of the triangle list which is also possible.
The text was updated successfully, but these errors were encountered: