From eb927383f2ba6ced34343ee9fcd6173bba8a8147 Mon Sep 17 00:00:00 2001 From: SaracenOne Date: Wed, 6 Apr 2016 07:34:34 +0100 Subject: [PATCH] Fixes errors occurring when switching to a new scene with a spatial editor from a canvas editor. (cherry picked from commit f303e3483d2a160a9841a3b50f21b86a62a7b4ec) --- .../editor/plugins/spatial_editor_plugin.cpp | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 27aff932e4d..12b662bbe4f 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -51,7 +51,31 @@ #define GIZMO_SCALE_DEFAULT 0.15 -//void SpatialEditorViewport::_update_camera(); +void SpatialEditorViewport::_update_camera() { + if (orthogonal) { + Size2 size = get_size(); + Size2 vpsize = Point2(cursor.distance*size.get_aspect(), cursor.distance / size.get_aspect()); + //camera->set_orthogonal(size.width*cursor.distance,get_znear(),get_zfar()); + camera->set_orthogonal(2 * cursor.distance, 0.1, 8192); + } + else + camera->set_perspective(get_fov(), get_znear(), get_zfar()); + + Transform camera_transform; + camera_transform.translate(cursor.pos); + camera_transform.basis.rotate(Vector3(0, 1, 0), cursor.y_rot); + camera_transform.basis.rotate(Vector3(1, 0, 0), cursor.x_rot); + + if (orthogonal) + camera_transform.translate(0, 0, 4096); + else + camera_transform.translate(0, 0, cursor.distance); + + if (camera->get_global_transform() != camera_transform) { + camera->set_global_transform(camera_transform); + update_transform_gizmo_view(); + } +} String SpatialEditorGizmo::get_handle_name(int p_idx) const { @@ -1787,6 +1811,10 @@ void SpatialEditorViewport::_notification(int p_what) { bool visible=is_visible(); set_process(visible); + + if (visible) + _update_camera(); + call_deferred("update_transform_gizmo_view"); } @@ -1808,28 +1836,7 @@ void SpatialEditorViewport::_notification(int p_what) { } */ - if (orthogonal) { - Size2 size=get_size(); - Size2 vpsize = Point2(cursor.distance*size.get_aspect(),cursor.distance/size.get_aspect()); - //camera->set_orthogonal(size.width*cursor.distance,get_znear(),get_zfar()); - camera->set_orthogonal(2*cursor.distance,0.1,8192); - } else - camera->set_perspective(get_fov(),get_znear(),get_zfar()); - - Transform camera_transform; - camera_transform.translate( cursor.pos ); - camera_transform.basis.rotate(Vector3(0,1,0),cursor.y_rot); - camera_transform.basis.rotate(Vector3(1,0,0),cursor.x_rot); - - if (orthogonal) - camera_transform.translate(0,0,4096); - else - camera_transform.translate(0,0,cursor.distance); - - if (camera->get_global_transform()!=camera_transform) { - camera->set_global_transform( camera_transform ); - update_transform_gizmo_view(); - } + _update_camera(); Map &selection = editor_selection->get_selection(); @@ -1932,7 +1939,6 @@ void SpatialEditorViewport::_notification(int p_what) { surface->connect("mouse_enter",this,"_smouseenter"); preview_camera->set_icon(get_icon("Camera","EditorIcons")); _init_gizmo_instance(index); - } if (p_what==NOTIFICATION_EXIT_TREE) {