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

Allow tool script to alter transform of node 3d editor viewport camera #93503

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Geekotron
Copy link
Contributor

I'd like my plugin/tool script to be able to move the 3d editor's camera. Same as some comments in several issues, e.g.
godotengine/godot-proposals#1302 (comment)
godotengine/godot-proposals#3287 (comment)
godotengine/godot-proposals#3164 (comment)

As others have found, moving/rotating the camera only works temporarily, it springs back to original transform as soon as you pan or navigate.

Cause:
Looking at node_3d_editor_plugin I see it's because camera is updated from a "cursor" and cursor is not exposed to tool script.

Proposed approach:
Rather than expose new methods or properties to script, I thought it would be simplest to have node_3d_editor_plugin look for external changes to the camera transform, and if any occur, to update its cursor to match the manually updated camera position. Seems to work fine.

Before:
problem-demo

After:
working-demo

Repro project:
cam-move-test.zip

@Geekotron Geekotron requested a review from a team as a code owner June 23, 2024 06:41
@Geekotron Geekotron force-pushed the viewport_accept_cam_change_from_tool branch from 6bfa6c5 to 6d85913 Compare June 23, 2024 06:54
@AThousandShips AThousandShips added this to the 4.x milestone Jun 23, 2024
@AThousandShips AThousandShips changed the title allow tool script to alter transform of node 3d editor viewport cam Allow tool script to alter transform of node 3d editor viewport camera Jun 23, 2024
@rossunger
Copy link

This looks awesome! Have the godot devs had a chance to discuss / look at this?

@Download
Copy link

Download commented Sep 9, 2024

I'm also keeping a keen eye on this issue. I am planning a terrain system of sorts that should allow for very large terrain and I would like to create some sort of mini-map tool and allow the user to click on the map to move the camera to the relevant part of the terrain. Not being able to control the camera was a showstopper for that.

It would also be great if the zoom level could be controlled in the same way but if I read the comments correctly that is also included in this PR right? I can't wait for this to land. Also I think there are a few people working on terrain stuff for Godot that would also welcome this! 👍

EDIT:
I glossed over this but it seems to be a very elegant solution. The editor tool just maintains a cursor position and instead of always force-updating the camera it first checks if the camera was updated externally and if so, first applies that update to the cursor before using the cursor to synch the editor camera. Very focused patch that adds only the small bit of code to make this work and should be relatively easy to review.

@akien-mga Or other reviewers, did this maybe fall of your radar? Looks like this could be merged quickly as it does not have conflicts, all tests passing and very humble scope / few changes.

@rossunger
Copy link

rossunger commented Sep 9, 2024 via email

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally (rebased on top of master 9e60984), it works as expected.

Code looks good to me.

Note that #99499 will likely need to integrate into this, so that externally-set transforms make it exit the follow mode automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants