godot icon indicating copy to clipboard operation
godot copied to clipboard

Fix Camera3D has an incorrect shape before opening the 2D tab

Open Ayush-singla27 opened this issue 2 years ago • 11 comments
trafficstars

Fixed default shape of frustum of camera3D, which had incorrect shape before opening the 2D tab.

Production edit: Fixes #70362

Ayush-singla27 avatar Dec 27 '22 12:12 Ayush-singla27

This is what the behavior of frustum should look like, it seems to me (Godot 3.x): Godot_v3 5 1-stable_win64_lV18GvEzX3

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 godot windows editor x86_64_JVsBtVWw3p

It turns out that this PR does not solve the problem yet.

DmitriySalnikov avatar Dec 28 '22 03:12 DmitriySalnikov

@DmitriySalnikov so the frustum should be independent on viewport size or the frustum should scale without switching to 2D tab?

Ayush-singla27 avatar Dec 28 '22 08:12 Ayush-singla27

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: image The size of this rectangle was also changed image 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. godot windows editor x86_64_gf31kyEu8O godot windows editor x86_64_IUTdsp39da

DmitriySalnikov avatar Dec 28 '22 09:12 DmitriySalnikov

@DmitriySalnikov should changing viewport size (in Project setting) affect SubViewport camera frustum ?

Ayush-singla27 avatar Dec 29 '22 18:12 Ayush-singla27

@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 avatar Dec 29 '22 19:12 DmitriySalnikov

@DmitriySalnikov i think now it should work like godot 3. :D

Ayush-singla27 avatar Jan 02 '23 18:01 Ayush-singla27

This works well, but only as long as the SubViewport has the name SubViewport...

DmitriySalnikov avatar Jan 02 '23 19:01 DmitriySalnikov

@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

subviewport

but the scene tree does not have any subViewport node.

Ayush-singla27 avatar Jan 05 '23 03:01 Ayush-singla27

I don't know a best way to find out which SubViewport is the root for the current scene

DmitriySalnikov avatar Jan 05 '23 11:01 DmitriySalnikov

@DmitriySalnikov finally! i think this should do it. ✌️

Ayush-singla27 avatar Jan 07 '23 06:01 Ayush-singla27

@akien-mga godot 4.0 has already been released. Is it possible to merge this PR now?

DmitriySalnikov avatar Mar 08 '23 17:03 DmitriySalnikov

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.

akien-mga avatar Mar 08 '23 18:03 akien-mga