-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Ellipse Hole in a Shape can wreck the Shape. #12921
Comments
A fiddle would be beneficial. See "How to report a bug" in the guidelines. |
It seems this is fixed in r89. It didn't work at first, probably owing to the viewer using a cached r88. Mea culpa. Closing this. |
I did try to set up a fiddle, but didn't get the dev version to load properly. Probably because it was the first time ever I tried to use jsfiddle and I need some more practice. I'll go back to fixing typos. |
|
🙌 |
Description of the problem
If a Hole in the form of one or more absarc/absellipse/arc/ellipse segments forming a full circle or ellipse is added to a 2D Shape and rendered as a ShapeBufferGeometry, this can wreck the Shape, anything from removing two triangles between one vertice in the outer Path and the three vertices around an absarc/absellipse/arc/ellipse start/end, to not rendering the Shape at all, depending on the Shape outer Path geometry. It gives the warning "THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()". This does not happen if the Hole is a single closed bezierCurveTo or any other Curve segments, independent of what Curve segments make up the outer Path of the Shape. It does however give a warning for each Path start/end "THREE.ShapeUtils: Duplicate point".
All vertices are correctly added to the geometry position attribute, but the problem seems to be with vertex indices, which are added oddly, incomplete or not at all, depending on the Shape outer Path. The fact that the glitch always seems to emanate around an absarc/absellipse/arc/ellipse start or end indicates that it may be the wrapping there working incorrectly. The actual reason seems to be that the start and end points at the angles 0 and 2 * Math.PI can become unequal, because Math.sin( 0 ) === 0 but Math.sin( 2 * Math.PI ) === -2.4492935982947064e-16, so the "duplicate" end point is not removed following an equal comparison (ShapeUtils.js line 38-40). In some cases, this still works, because rounding errors compensate for the sin error.
There are several ways to solve this. The probably most correct one, to handle any kind of rounding errors, would be to replace the straightforward function
with a more complex function similar to
or a joined function, keeping (most of) the simplicity and speed in the simple case
(edited function to handle origin position case and add joined function)
Three.js version
Browser
OS
Hardware Requirements (graphics card, VR Device, ...)
The text was updated successfully, but these errors were encountered: