You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-23 15:16:17 +00:00
Allow tool scripts to alter transform of Node3DEditorViewport camera
This commit is contained in:
committed by
Rémi Verschelde
parent
0eadbdb5d0
commit
6ad82aba3b
@@ -590,7 +590,8 @@ void Node3DEditorViewport::_update_camera(real_t p_interp_delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!equal || p_interp_delta == 0 || is_orthogonal != orthogonal) {
|
if (!equal || p_interp_delta == 0 || is_orthogonal != orthogonal) {
|
||||||
camera->set_global_transform(to_camera_transform(camera_cursor));
|
last_camera_transform = to_camera_transform(camera_cursor);
|
||||||
|
camera->set_global_transform(last_camera_transform);
|
||||||
|
|
||||||
if (orthogonal) {
|
if (orthogonal) {
|
||||||
float half_fov = Math::deg_to_rad(get_fov()) / 2.0;
|
float half_fov = Math::deg_to_rad(get_fov()) / 2.0;
|
||||||
@@ -2908,6 +2909,11 @@ void Node3DEditorViewport::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_camera_moved_externally()) {
|
||||||
|
// If camera moved after this plugin last set it, presumably a tool script has moved it, accept the new camera transform as the cursor position.
|
||||||
|
_apply_camera_transform_to_cursor();
|
||||||
|
}
|
||||||
|
|
||||||
_update_camera(delta);
|
_update_camera(delta);
|
||||||
|
|
||||||
const HashMap<Node *, Object *> &selection = editor_selection->get_selection();
|
const HashMap<Node *, Object *> &selection = editor_selection->get_selection();
|
||||||
@@ -3376,6 +3382,19 @@ void Node3DEditorViewport::_draw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Node3DEditorViewport::_camera_moved_externally() {
|
||||||
|
Transform3D t = camera->get_global_transform();
|
||||||
|
return !t.is_equal_approx(last_camera_transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node3DEditorViewport::_apply_camera_transform_to_cursor() {
|
||||||
|
// Effectively the reverse of to_camera_transform, use camera transform to set cursor position and rotation.
|
||||||
|
Transform3D camera_transform = camera->get_camera_transform();
|
||||||
|
cursor.pos = camera_transform.origin;
|
||||||
|
cursor.x_rot = -camera_transform.basis.get_euler().x;
|
||||||
|
cursor.y_rot = -camera_transform.basis.get_euler().y;
|
||||||
|
}
|
||||||
|
|
||||||
void Node3DEditorViewport::_menu_option(int p_option) {
|
void Node3DEditorViewport::_menu_option(int p_option) {
|
||||||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
||||||
switch (p_option) {
|
switch (p_option) {
|
||||||
|
|||||||
@@ -445,6 +445,11 @@ private:
|
|||||||
Transform3D to_camera_transform(const Cursor &p_cursor) const;
|
Transform3D to_camera_transform(const Cursor &p_cursor) const;
|
||||||
void _draw();
|
void _draw();
|
||||||
|
|
||||||
|
// These allow tool scripts to set the 3D cursor location by updating the camera transform.
|
||||||
|
Transform3D last_camera_transform;
|
||||||
|
bool _camera_moved_externally();
|
||||||
|
void _apply_camera_transform_to_cursor();
|
||||||
|
|
||||||
void _surface_mouse_enter();
|
void _surface_mouse_enter();
|
||||||
void _surface_mouse_exit();
|
void _surface_mouse_exit();
|
||||||
void _surface_focus_enter();
|
void _surface_focus_enter();
|
||||||
|
|||||||
Reference in New Issue
Block a user