godot icon indicating copy to clipboard operation
godot copied to clipboard

Add viewport override to 2D editor

Open KoBeWi opened this issue 1 year ago • 11 comments

This PR supersedes #61873 with alternative approach. Instead of enabling other viewports and fighting with the editor to make it work properly, I added a button that allows to override the default 2D editor viewport with another one.

https://user-images.githubusercontent.com/2223172/223558255-e3a3c033-6b92-4f7d-b116-c56c1124a6a5.mp4

I have one unresolved problem though - the overriding viewport's size must match the editor's size to display properly. Right now I'm just displaying its content with a TextureRect, but maybe I should use some different approach, idk. I didn't make much progress for some time, so I'm opening a draft.

Closes #20619 Closes #60088 Closes https://github.com/godotengine/godot-proposals/issues/2139 Closes https://github.com/godotengine/godot-proposals/issues/5422

KoBeWi avatar Mar 07 '23 21:03 KoBeWi

Ok this is somewhat finished. I fixed the viewport problems by adding more viewports. So the 2D editor structure is now SubViewportContainer -> SubViewport -> TextureRect -> current viewport.

The current viewport is still displayed inside TextureRect, but screen transform is now different. While using main viewport, the displayed viewports' transform is changed. If the viewport is overriden, the containing viewport (the one under SubViewportContainer) is transformed instead and the overriding viewport is displayed in local space. It works quite well.

https://user-images.githubusercontent.com/2223172/233101084-95d37ee7-1784-4421-80f4-07d409d5992d.mp4

I'm really surprised that selecting nodes works without any problems in this setup.

The only problem are Window nodes. For whatever reason they don't redraw when content changes and don't draw anything while invisible.

https://user-images.githubusercontent.com/2223172/233101280-5c6e959b-1824-4fc5-a0da-530471e6c47b.mp4

(I also remembered that the override button is buggy)

But it's ready to be ready for review I think.

EDIT: Also this is funny with Camera2D

https://user-images.githubusercontent.com/2223172/233103500-007787ee-635a-436e-9c2d-2d27b57205ee.mp4

KoBeWi avatar Apr 19 '23 14:04 KoBeWi

This is amazing, really need that one :)

jordanlis avatar Jul 07 '23 08:07 jordanlis

Indeed It'll Help A LOT

Variable-ind avatar Jul 10 '23 14:07 Variable-ind

@Variable-ind Please don't bump issues without contributing significant new information. Use the :+1: reaction button on the first post instead.

Calinou avatar Jul 10 '23 15:07 Calinou

What's status of this?

Summersay415 avatar Aug 30 '23 02:08 Summersay415

Needs testing and review.

KoBeWi avatar Aug 30 '23 12:08 KoBeWi

Tested locally, works good with some caveats you mentioned. Suggestion: how about not restricting rendering outside of the overridden viewport, as in a normal, not overridden one?

Summersay415 avatar Aug 30 '23 16:08 Summersay415

This is a technical restriction. The main viewport works a bit differently - when you move around, its canvas is transformed and displays a different region. The rendering is still restricted to the viewport's size, but it has the size of the editor, so you don't see that objects outside don't render.

KoBeWi avatar Aug 30 '23 16:08 KoBeWi

Needs rebase, and then going around to poke people on #editor to actually get this reviewed :P

akien-mga avatar Jan 04 '24 16:01 akien-mga

Would this also work for 3D nodes with a 2D Subviewport?

jan-Kulpas avatar Jun 09 '24 08:06 jan-Kulpas

No, this doesn't cover 3D.

KoBeWi avatar Jun 09 '24 10:06 KoBeWi