godot
godot copied to clipboard
Fix Camera3D has an incorrect shape before opening the 2D tab
Fixed default shape of frustum of camera3D, which had incorrect shape before opening the 2D tab.
Production edit: Fixes #70362
This is what the behavior of frustum should look like, it seems to me (Godot 3.x):

But while I was testing this PR, I found a more detailed pattern. Frustum doesn't change the first time you switch to a 2D tab, it changes every time you switch to a 2D tab. (But I didn't notice this when I created the issue 😞 )
(recorded with v4.0.beta.custom_build [1ea6a5d38])
https://user-images.githubusercontent.com/7782218/209750377-5f2ea46b-74c9-457c-a55d-0c7ec40ba6da.mp4
Also, the size of the Camera3D gizmo itself in godot 4.x changes as correctly as in godot 3.x

It turns out that this PR does not solve the problem yet.
@DmitriySalnikov so the frustum should be independent on viewport size or the frustum should scale without switching to 2D tab?
I do not know how it worked inside before. But before godot 4, changing the window size parameters always affected Camera3D(gizmo and get_frustum()) on the 3D tab and the size of this area on the 2D tab:
The size of this rectangle was also changed
Current Camera frustum is great for preview mode, but it still only updates when switching to the 2D tab...
By the way, Camera3D inside the SubViewport works correctly, as in godot 3.

@DmitriySalnikov should changing viewport size (in Project setting) affect SubViewport camera frustum ?
@DmitriySalnikov should changing viewport size (in Project setting) affect SubViewport camera frustum ?
No I think not. Even if you look at Camera3D gizmo, you can see that the shape of the camera inside the SubViewport depends only on the size of this subviewport. And a camera without a subviewport changes shape based on the size from ProjectSettings.
https://user-images.githubusercontent.com/7782218/210003476-4d334b30-1967-4db3-85b2-a04c06619fb8.mp4
@DmitriySalnikov i think now it should work like godot 3. :D
This works well, but only as long as the SubViewport has the name SubViewport...
@DmitriySalnikov i am have some trouble solving this. The following code
bool check = false;
Node *temp = this->get_node(this->get_path());
if (temp != NULL) {
if (temp->get_class_name() == "SubViewport") {
check = true;
print_line(temp->get_class_name());
}
else {
check = false;
}
temp = temp->get_parent();
}
is giving the following output for demo project attached in this issue

but the scene tree does not have any subViewport node.
I don't know a best way to find out which SubViewport is the root for the current scene
@DmitriySalnikov finally! i think this should do it. ✌️
@akien-mga godot 4.0 has already been released. Is it possible to merge this PR now?
Not yet, I'm not sure this fix is appropriate. Fetching project settings all the time for such a core method doesn't sound like a good option. The real issue might be deeper and this looks like a workaround.