-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
create/fix offset_polygon_2d(), an offsetting function for PoolVector2Array by a single vector #777
Comments
Can you move a parent node of the Polygon2D/CollisionPolygon2D instead? |
I am using Geometry.clip_polygons_2d(), which don't accept coordinates of polygons, only poolvector2array. So no |
Perhaps another solution (for me) would be to add an offset vector argument to the clip_polygon_2d() function, but as a general solution, I think an offset function would be more practical. |
I've chosen the For translating polygon's vertices specifically, I've added support in So this is a documentation issue I guess. Adding a note to |
That should do it, though I am surprised at how little performance boost this gave me. Thank you Xrayez. |
There are many places where you could have a performance bottleneck, the polygon clipping is quite an intensive operation in and of itself, so you'll likely want to come up with optimization techniques like splitting polygons into smaller chunks. For translating polygons, see documentation changes in godotengine/godot#38390 which may be merged to 3.2/4.0 built-in docs. |
Also, you might be surprised how this can be little to do with the polygon clipping, but rather the rendering of polygons, which might be quite the case for you (and myself): godotengine/godot#19943, especially with many vertices which might result from this operation (more vertices → more shapes decomposed into convex → the number triangles to draw → slowdown). |
Describe the project you are working on:
an acid node that eats up polygons2d/collisionpolygons2d, or a bomb that does the same.
Describe the problem or limitation you are having in your project:
When creating a new polygon, correct positional placement is key.
creating FOR loops in GDscript that offset the polygons is extremely taxing on performance but wouldn't be in C++. There is no function in polygon2d/collisionpolygon2d nor PoolVector2Array nor Geometry that offsets polygons. The function Geometry.offset_polygon_2d() doesn't offset a polygon by a vector amount, but inflates or deflates them, which is pretty silly.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Either using (Transform2D * PoolVector2DArray) or .translate(), create a function in PoolVector2Array, Polygon2D & CollisionPolygon2D or Geometry that would add an input vector to all vectors in a given PoolVector2Array
I think the function should be called offset_polygon_2d, and the function that already has that name should be changed to inflate_polygon_2d.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
If this enhancement will not be used often, can it be worked around with a few lines of script?:
It will be used often, by most developers that use polygons a lot
Is there a reason why this should be core and not an add-on in the asset library?:
This is a very basic vector function that belongs at the core.
The text was updated successfully, but these errors were encountered: