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
SVGLoader: Shape generation breaks with large stroke width. #25326
Comments
I had the hope that setting a high value for the number of interpolation points would correct the issue (note the extra Unfortunately it does not solve it. I'm afraid it is not addressable in the algorithm as it is written right now. It would require self-intersection tests. On the other hand it is doable in a completely separated 2D algorithm, let me see if I can put up something in the next days. |
I tried to make a triangularization algorithm which discards overlapping triangles. But it gives false positives and discards too many. It works in tests but not in the SVG from the example. |
Something that came to my mind: Could you utilize the existing Earcut implementation for this use case? https://threejs.org/docs/index.html#api/en/extras/Earcut Meaning you first generate the contour (which is just a sequence of points) an then let Earcut do its job. |
Thanks for noting it. I will take a look. I will also investigate if I can get the holes indices. |
@Mugen87 I've implemented your idea, by holding two contour points arrays (left and right ones) and combining them at the end, giving the full stroke contour. It works mostly correctly in the use case. I hoped it worked in the general case but you can see that the Tiger.svg has some artifacts. It is caused by the contour I generate, which folds over itself on some corners. Earcut does not like that on complex paths. As before, solving this would require checking self-intersections, but now in the linear contour, not in a triangle soup. It is doable, but only would work if the original path doesn't self-intersect. Detail of the contour folding over itself: Tiger.svg: Use case: Use case detail: The algorithm is smaller and cleaner (751 lines down to 495). Performance seems similar as before. The drawback is that the two contour arrays must be allocated. This can be optimized by providing reusable user arrays. As the whole The function It seems I've tried to make a live preview but failed. You can read the modified loader and example here: yomboprime@563aea9 Expecting your feedback to see if this can be useful. |
Just an update: There was some bugs in that branch commit. I'm trying to debug some last issues. |
I appreciate your effort on this! Even without a concrete solution the problem is now better understood than before 👍 . |
Thanks! |
Description
The original issue was reported at the forum: https://discourse.threejs.org/t/glitches-with-svg-loader/46803
SVGs that exceed a certain
stroke-width
are not rendered correctly. As visible in the below screenshot, the resulting shape is rendered with additional triangles on its back side. When decreasing the stroke width (in the below SVG try 200), the issue goes away.I suspect there is a problem in SVGLoader.pointsToStrokeWithBuffers() which generates triangles based on the stroke definition from the SVG.
Reproduction steps
Code
Live example
Screenshots
Version
r148
Device
Desktop, Mobile, Headset
Browser
Chrome, Firefox, Safari, Edge
OS
Windows, MacOS, Linux, Android, iOS
The text was updated successfully, but these errors were encountered: