godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.88k stars 19.45k forks source link

[3.6] get_viewport().get_camera() doesn't work in editor #77661

Open QbieShay opened 1 year ago

QbieShay commented 1 year ago

Godot version

3.6 (custom build)

System information

Fedora, RX 590

Issue description

I am trying to use immediate geometry and force the geometry to draw in a billboard mode.

I am not able to do get_viewport().get_camera() in editor, so i can't preview the billboard mode in editor

Steps to reproduce

print(get_viewport().get_camera()) on a tool script.

Minimal reproduction project

N/A

bitsawer commented 1 year ago

Have you tried to call Camera.make_current()? I rember having to do that when I had to do some off-screen viewport rendering in an editor tool script.

QbieShay commented 1 year ago

The node is running in the 3D view so it should grab the 3D view camera

AThousandShips commented 1 year ago

Don't think it's safe to assume the editor camera to be the camera attached to the viewport of the node

timothyqiu commented 1 year ago

The 3D editor can show up to four viewports at the same time, and each viewport has its own camera, so I don't think this is supposed to work.

TokisanGames commented 1 year ago

There are 4 editor cameras. They exist in a different place in the tree than the rest of your scene, but they do exist. You can either search the tree for Camera3Ds, or you can use the editorplugin route, as demonstrated by EditorFlyCam https://github.com/Schroedi/EditorFlyCam/blob/main/addons/EditorFlyCam/efc_plugin.gd

Several people already demonstrated how to find the editor cameras in 3.x and 4.x. You participated in this thread. https://github.com/godotengine/godot-proposals/issues/1302

The best solution though is to get the core dev team to finally relent and expose the editor cameras, by accepting any of the several PRs that have been provided.

QbieShay commented 1 year ago

This is a slightly different usecase because I think the behaviour in editor should be the same as in-game without any extra plugin or separate calls. I need to get camera information so that I can do rendering. I need the same transform that gets passed to shaders, yet it's somehow unavailable.

I don't need to manipulate the editor camera here, only read from it. Reading is easier than writing because it affects way less existing systems.

Calinou commented 1 year ago

I don't need to manipulate the editor camera here, only read from it. Reading is easier than writing because it affects way less existing systems.

It sounds like there should be a dedicated method for that through EditorInterface, like https://github.com/godotengine/godot/pull/68706 did for the 2D editor.

That said, this is proposal territory as I don't think get_viewport().get_camera()'s behavior should be altered in tool scripts. (If anything, it could print a warning when used as it generally doesn't do what you want.)

QbieShay commented 1 year ago

The 3D editor can show up to four viewports at the same time, and each viewport has its own camera, so I don't think this is supposed to work.

Billboarding works though. I am generating immediate geometry and i need the camera vectors to do that.

timothyqiu commented 1 year ago

The 3D editor can show up to four viewports at the same time, and each viewport has its own camera, so I don't think this is supposed to work.

Billboarding works though. I am generating immediate geometry and i need the camera vectors to do that.

Billboarding is done in the shader IIRC, so the camera vector is different for each viewport. If it's done via immediate geometry, it can only face one camera.

QbieShay commented 1 year ago

I'd still take that over not being able to test it in editor at all