-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Geometry.clip_polygons_2d sometimes produces polygon that can't be triangulated #53152
Comments
When doing triangulation with Goost after clipping, I get this expected result: ClipPolygonTestGoost.zip (requires Goost to run). So at least we know it's not an issue with clipping, but triangulation. For this, see #52978 and #40911 to get the idea of why errors like this happen.
I think it makes sense, shapes are not perfectly aligned, so this leaves a very small dent after clip, something like this when "zoomed in": |
@Xrayez thank you for the info! So I started using |
Actually, it turns out that checking for duplicate or near-duplicate points is not enough, because there are some triangles being produced that don't have close points but are very thin with little area, and these triangles fail the internal triangulate call (for example, this triangle: |
In that case you can directly draw the triangles via In any case, you can refer to this C++ implementation on how to use |
@Xrayez thank you again for the info! For now I'll stick with the manual clipping approach and draw with func _draw() -> void:
var triangles: Array = []
for clipped_polygon in clipped_polygons:
triangles.append_array(GoostGeometry2D.triangulate_polygon(clipped_polygon))
if triangles.empty():
return
var vertices: Array = []
for triangle in triangles:
vertices.append_array(Array(triangle))
VisualServer.canvas_item_add_triangle_array(get_canvas_item(), range(vertices.size()), vertices, [color]) |
Godot version
v3.3.3.stable.official.b973f997f
System information
Windows 10, OpenGL ES 3.0 Renderer: GeForce GTX 1070/PCIe/SSE2
Issue description
I am attempting to use
Geometry.clip_polygons_2d
in the following way; I have an initial polygon that must be clipped against a series of other polygons. I use the results of a given call toGeometry.clip_polygons_2d
as thepolygon_a
input in the next clip iteration. The resulting polygon after all clip iterations is then drawn on the screen.Occasionally,
Geometry.clip_polygons_2d
used in this manner will produce a polygon that can't be triangulated (and therefore can't be drawn), even though both input polygons are triangulatable. I haven't been able to come up with a simpler contrived example, so I just used actual data taken from the program for the attached reproduction project.Here's the code from the reproduction project:
Here's the text output when it's run:
And here's a screenshot of the two polygons being clipped, scaled up and repositioned to better see the intersection between the them:
The trouble seems to be with that inner concave point on
polygon_a
; bothpolygon_a
andpolygon_b
share a nearly identical point there, and that point seems to be near-duplicated twice in the clipped polygon. Why the point is near-duplicated at all I have no idea.Steps to reproduce
Open the reproduction project and run it.
Minimal reproduction project
ClipPolygonTest.zip
The text was updated successfully, but these errors were encountered: