Skip to content

Add "Use Local Space" option to the 2D editor#107264

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
DevPoodle:local_space_2d
Nov 14, 2025
Merged

Add "Use Local Space" option to the 2D editor#107264
Repiteo merged 1 commit into
godotengine:masterfrom
DevPoodle:local_space_2d

Conversation

@DevPoodle
Copy link
Copy Markdown
Contributor

@DevPoodle DevPoodle commented Jun 7, 2025

Closes godotengine/godot-proposals#6799.

This adds in a "Use Local Space" button to the 2D editor like the 3D editor currently has. By default, Godot uses local space in the 2D editor anyway, so the actual functionality of this PR comes from turning it off, which allows you to do global space transformations. For global translations, this works exactly as you'd expect. For global scale, I made it so that when you scale along the x-axis, it attempts to preserve the height of the object, and when you scale along the y-axis, it attempts to preserve the width of the object. I personally find it intuitive, but there might be a more obvious way that I'm missing, so I'd really appreciate feedback on this.

Keep in mind that by default, "Use Local Space" is on, so there shouldn't be any immediate difference.

@DevPoodle DevPoodle force-pushed the local_space_2d branch 3 times, most recently from f732d33 to 03acb70 Compare June 8, 2025 21:08
@DevPoodle
Copy link
Copy Markdown
Contributor Author

I think I've found another decent way to handle scale. There are 2 main options:
Option 1:

option_1.mp4

Option 2:

option_2.mp4

Option 1 was my initial approach. It scales along the given axis while attempting to preserve the the length of the object along the other axis. It only scales along the desired axis which is good, but it also distorts the object a lot.
Option 2 is what I'm currently doing. It scales along the given axis, while also scaling the other axis to try to keep the object as undistorted as possible.

I like both, but I think option 2 will be a little more intuitive for most users. I definitely would appreciate input on this though.

@DevPoodle DevPoodle marked this pull request as ready for review June 8, 2025 21:23
@aaronfranke aaronfranke added this to the 4.x milestone Jun 9, 2025
@aaronfranke
Copy link
Copy Markdown
Member

aaronfranke commented Jun 9, 2025

@DevPoodle The correct behavior is for the 2D scale gizmo to behave just like the 3D scale gizmo. So it's neither your Option 1 or Option 2.

I can understand why other modes would be desired, like uniform scale, but that's not what the user expects when clicking on one scale handle. In the future, we could implement a Keep Mode dropdown like in Godot 4D which would allow the user to choose what level of "undistorted" they want the transform to be, but for now we don't have that, so the level of distorted should be keep orthogonal, just what can be decomposed into TRS, like in 3D.

@AThousandShips AThousandShips requested a review from a team June 9, 2025 15:29
@DevPoodle
Copy link
Copy Markdown
Contributor Author

DevPoodle commented Jun 9, 2025

Alright, I think it works the same as the 3D editor now. I based the math off of Basis::scaled_orthogonal. I wasn't able to find an equivalent function for 2D, so I redid some of it.

@DevPoodle DevPoodle force-pushed the local_space_2d branch 2 times, most recently from add0053 to 207d317 Compare June 9, 2025 15:47
@aaronfranke
Copy link
Copy Markdown
Member

Tested, it doesn't work correctly. If I drag the global 2D scale handles, it just explodes to a huge size.

scale_2d_doesnt_work.mp4

@DevPoodle
Copy link
Copy Markdown
Contributor Author

I forgot to take into account scaling at places other than the origin, should be fixed now🤞

@aaronfranke
Copy link
Copy Markdown
Member

@DevPoodle Thanks for working on this! It does seem to match 3D now. However, and I did not realize this before... the behavior in 3D is actually not correct either.

In master, when you scale a global axis in 3D, it will expand or collapse depending on which direction the other axes are pointing. This doesn't really make any sense, and isn't good behavior. This PR currently does the same in 2D. I've recorded a video demonstrating this (whenever I shake the mouse side to side that's wrong). Also, I included an example of my 4D module (with "Keep Orthogonal" enabled), which behaves correctly: no matter which way the other axes are pointing, doing a global scale does not collapse the object.

global_scale_not_correct.mp4

@DevPoodle
Copy link
Copy Markdown
Contributor Author

The main thing I'm unsure about is whether global scale should also rotate/skew the object. If we don't allow it to rotate or skew, then the "Option 2" I was previously using is the best option, because it scales the object as much as possible in the given direction without ever collapsing it. If we do allow rotation or skewing, then we would get a more mathematically accurate global scale like the one you demonstrated in your video.

I honestly could go either way on this. I had assumed I shouldn't mess with rotation or skew because I personally wouldn't want the scale tool to affect those, but if it makes it significantly more intuitive for most users then its probably the right option.

@DevPoodle DevPoodle force-pushed the local_space_2d branch 2 times, most recently from af160ef to 4371588 Compare July 3, 2025 00:39
@DevPoodle
Copy link
Copy Markdown
Contributor Author

Alright, I just updated it so that global space scale affects skew and rotation. It should now match the behavior in the video you posted. After using it for a bit, it very clearly is better than the methods I was using before and made the code a little simpler as well.

Comment thread editor/plugins/canvas_item_editor_plugin.cpp Outdated
Comment thread editor/plugins/canvas_item_editor_plugin.cpp Outdated
Comment thread editor/plugins/canvas_item_editor_plugin.cpp Outdated
Comment thread editor/plugins/canvas_item_editor_plugin.cpp Outdated
@DevPoodle DevPoodle requested a review from a team as a code owner July 4, 2025 22:07
@KoBeWi KoBeWi modified the milestones: 4.x, 4.6 Jul 5, 2025
Copy link
Copy Markdown
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, this works correctly.

@Repiteo Repiteo merged commit 527cb41 into godotengine:master Nov 14, 2025
20 checks passed
@Repiteo
Copy link
Copy Markdown
Contributor

Repiteo commented Nov 14, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow moving 2D nodes in local space in the 2D editor (similar to the existing toggle in the 3D editor)

4 participants