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

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

Open
QbieShay opened this issue May 30, 2023 · 10 comments
Open

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

QbieShay opened this issue May 30, 2023 · 10 comments

Comments

@QbieShay
Copy link
Contributor

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
Copy link
Member

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
Copy link
Contributor Author

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

@AThousandShips
Copy link
Member

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

@timothyqiu
Copy link
Member

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
Copy link
Contributor

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.
godotengine/godot-proposals#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
Copy link
Contributor Author

QbieShay commented Jun 6, 2023

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
Copy link
Member

Calinou commented Jun 6, 2023

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 #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
Copy link
Contributor Author

QbieShay commented Jun 6, 2023

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
Copy link
Member

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
Copy link
Contributor Author

QbieShay commented Jun 7, 2023

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

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

6 participants