Skip to content
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

Allow moving all polygon points or center them at the node's origin in polygon editors #266

Open
KoBeWi opened this issue Nov 29, 2019 · 3 comments

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Nov 29, 2019

Describe the project you are working on:
Game with CollisionPolygons2D.

Describe the problem or limitation you are having in your project:
This actually does not apply to this particular project, but my overall experience with CollisionPolygons2D. Their (probably) biggest problem is that when you create a polygon, you are stuck with it. The points are always in the same relative position to origin, unless of course you move them manually one by one by the same offset. Which is most of the time unreasonable thing to do. It's also a shortcoming of not being able to select multiple points, but that's another thing.

Describe how this feature / enhancement will help you overcome this problem or limitation:
So to alleviate that, I suggest that we should be able to change the polygon's "offset" relative to the origin. I mean, drag all the points at once, without changing the polygon's actual position. Also, there should be an option to automatically set the offset to value that makes the polygon's origin point be in the center of the shape.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
SowP01uy0L
(imagine that the gizmo represent's this polygon's position.

Describe implementation detail for your proposal (in code), if possible:
Being able to move the polygon "offset" would be probably a new tool in Polygon2D editor. Also centering the polygon would be done with a button. Other than that it's some simple vector maths.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Well, you can move all the points using a script, but you can't do that using CanvasItem editor without a plugin, which is more complex to do.

Is there a reason why this should be core and not an add-on in the asset library?:
Polygon2Ds just need this built-in.

@Xrayez
Copy link
Contributor

Xrayez commented Dec 2, 2019

Adding another tool for offsetting would be certainly useful.

Honestly it would be nice if all those vertex-based 2D nodes could have an option to construct any shape with Position2D nodes alone (as children of Polygon2D for instance). The vertex order would be inferred from nodes order.

That way, you could simply translate all the points however you want within the editor, and internal points should be updated automatically. Of course that depends on how complex your shape is.

As a bonus, it would be much easier to animate any vertex, as simple as changing offset/rotation/scale of an individual Position2D nodes.

@PLyczkowski
Copy link

How this would work in vector editing apps more or less is that when you are in Edit Points mode
( image )
, you can either click on shape and then click and drag to move it (while it's origin stays in place), or just directly click and drag to move it, or click and drag outside the shape to draw a selection rectangle, select all the points it consists of, and then click and drag to move it. That's in contrast to being in object Select/Move mode (
image
) where you move the shape as well as it's origin.

@hsandt
Copy link

hsandt commented May 19, 2023

EDITED: clean up and give the summary of my findings. Sorry for people who may have read the old message in the email notifications!

Currently, the behavior is like this:

  1. Edit polygon mode cannot be disabled at all, so the behavior depends entirely on the selected sub-mode (Create points, Edit points, Erase points)
  2. In Edit points mode, if you drag-and-drop from right inside the shape (don't click near the edges), you can move the whole shape but also the origin. This is like the usual Node drag-and-drop (e.g. on Sprite2D)
  3. If you deselect the node, then drag-and-drop from anywhere inside the shape (including near edges) without selecting the Node first, then you can exceptionally trigger the classic Node drag-and-drop (move with origin), independently of the last sub-mode selected. After that, Node is selected so you must be careful to use Edit points and drag not near the edges.
  4. Move Mode will always work to move the whole node with origin

If we reuse the blue Edit points sub-mode + drag from right inside the shape (action 2) to batch move all points, it's more logical as I expect the Edit points tool to move actual points relatively to the origin, not the whole Node. However, mind that after that, only action 4 (Move Mode) will reliably move the shape. There is also Action 3 but it is not convenient to do.

So I would also suggest to implement point 1 at some point, so we can disable point editing altogether and move the Node as a normal Node.

That said, if you make batch move all points a brand new sub-mode as suggested in the OP, or you reuse Edit Points but require user to first select all points (with shortcut or drag rectangle select) before moving them, like Inkscape (which doesn't support drag-and-drop all points if you drag from inside the shape), then you can keep the current behavior of 2 which will play the role of classic Node drag with origin.

So I'll wait and see which implementation you choose before posting a suggestion to disable Edit polygon points entirely, as depending on the implementation, Edit points sub-mode may be very close to it already.

GIF example of action 3 followed by action 2: see how the origin moves in both actions

Godot 4 0 2 - drag and drop polygon not selected then selected in Edit Points

@Calinou Calinou changed the title Move all polygon points / center them at origin Allow moving all polygon points or center them at the node's origin in polygon editors May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants