From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- editor/plugins/node_3d_editor_plugin.cpp | 329 ------------------------------- 1 file changed, 329 deletions(-) (limited to 'editor/plugins/node_3d_editor_plugin.cpp') diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 1614f3f073..fa600ad744 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -77,7 +77,6 @@ #define MAX_FOV 179 void ViewportRotationControl::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { axis_menu_options.clear(); axis_menu_options.push_back(Node3DEditorViewport::VIEW_RIGHT); @@ -255,19 +254,16 @@ void ViewportRotationControl::_bind_methods() { } void Node3DEditorViewport::_update_camera(float p_interp_delta) { - bool is_orthogonal = camera->get_projection() == Camera3D::PROJECTION_ORTHOGONAL; Cursor old_camera_cursor = camera_cursor; camera_cursor = cursor; if (p_interp_delta > 0) { - //------- // Perform smoothing if (is_freelook_active()) { - // Higher inertia should increase "lag" (lerp with factor between 0 and 1) // Inertia of zero should produce instant movement (lerp with factor of 1) in this case it returns a really high value and gets clamped to 1. real_t inertia = EDITOR_GET("editors/3d/freelook/freelook_inertia"); @@ -294,7 +290,6 @@ void Node3DEditorViewport::_update_camera(float p_interp_delta) { camera_cursor.pos = camera_cursor.eye_pos + forward * camera_cursor.distance; } else { - //when not being manipulated, move softly float free_orbit_inertia = EDITOR_GET("editors/3d/navigation_feel/orbit_inertia"); float free_translation_inertia = EDITOR_GET("editors/3d/navigation_feel/translation_inertia"); @@ -348,7 +343,6 @@ void Node3DEditorViewport::_update_camera(float p_interp_delta) { } if (!equal || p_interp_delta == 0 || is_freelook_active() || is_orthogonal != orthogonal) { - camera->set_global_transform(to_camera_transform(camera_cursor)); if (orthogonal) { @@ -379,13 +373,11 @@ Transform Node3DEditorViewport::to_camera_transform(const Cursor &p_cursor) cons } int Node3DEditorViewport::get_selected_count() const { - Map &selection = editor_selection->get_selection(); int count = 0; for (Map::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->key()); if (!sp) continue; @@ -401,55 +393,44 @@ int Node3DEditorViewport::get_selected_count() const { } float Node3DEditorViewport::get_znear() const { - return CLAMP(spatial_editor->get_znear(), MIN_Z, MAX_Z); } float Node3DEditorViewport::get_zfar() const { - return CLAMP(spatial_editor->get_zfar(), MIN_Z, MAX_Z); } float Node3DEditorViewport::get_fov() const { - return CLAMP(spatial_editor->get_fov(), MIN_FOV, MAX_FOV); } Transform Node3DEditorViewport::_get_camera_transform() const { - return camera->get_global_transform(); } Vector3 Node3DEditorViewport::_get_camera_position() const { - return _get_camera_transform().origin; } Point2 Node3DEditorViewport::_point_to_screen(const Vector3 &p_point) { - return camera->unproject_position(p_point) * subviewport_container->get_stretch_shrink(); } Vector3 Node3DEditorViewport::_get_ray_pos(const Vector2 &p_pos) const { - return camera->project_ray_origin(p_pos / subviewport_container->get_stretch_shrink()); } Vector3 Node3DEditorViewport::_get_camera_normal() const { - return -_get_camera_transform().basis.get_axis(2); } Vector3 Node3DEditorViewport::_get_ray(const Vector2 &p_pos) const { - return camera->project_ray_normal(p_pos / subviewport_container->get_stretch_shrink()); } void Node3DEditorViewport::_clear_selected() { - editor_selection->clear(); } void Node3DEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_allow_locked) { - if (clicked.is_null()) return; @@ -475,7 +456,6 @@ void Node3DEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_ } void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { - if (!p_append) { editor_selection->clear(); } @@ -484,7 +464,6 @@ void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { //erase editor_selection->remove_node(p_node); } else { - editor_selection->add_node(p_node); } @@ -495,7 +474,6 @@ void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { } ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle, bool p_alt_select) { - if (r_gizmo_handle) *r_gizmo_handle = -1; @@ -513,7 +491,6 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b int selected_handle = -1; for (int i = 0; i < instances.size(); i++) { - Node3D *spat = Object::cast_to(ObjectDB::get_instance(instances[i])); if (!spat) @@ -541,7 +518,6 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b continue; if (dist < closest_dist) { - item = Object::cast_to(spat); while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) { item = item->get_owner(); @@ -557,7 +533,6 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b return ObjectID(); if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle >= 0)) { - if (r_gizmo_handle) *r_gizmo_handle = selected_handle; } @@ -566,7 +541,6 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b } void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select) { - Vector3 ray = _get_ray(p_pos); Vector3 pos = _get_ray_pos(p_pos); @@ -576,7 +550,6 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu r_includes_current = false; for (int i = 0; i < instances.size(); i++) { - Node3D *spat = Object::cast_to(ObjectDB::get_instance(instances[i])); if (!spat) @@ -622,7 +595,6 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu } Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) { - CameraMatrix cm; if (orthogonal) { cm.set_orthogonal(camera->get_size(), get_size().aspect(), get_znear() + p_vector3.z, get_zfar()); @@ -641,7 +613,6 @@ Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) { } void Node3DEditorViewport::_select_region() { - if (cursor.region_begin == cursor.region_end) return; //nothing really @@ -671,7 +642,6 @@ void Node3DEditorViewport::_select_region() { Vector3 cam_pos = _get_camera_position(); for (int i = 0; i < 4; i++) { - Vector3 a = _get_screen_to_space(box[i]); Vector3 b = _get_screen_to_space(box[(i + 1) % 4]); if (orthogonal) { @@ -695,7 +665,6 @@ void Node3DEditorViewport::_select_region() { Node *edited_scene = get_tree()->get_edited_scene_root(); for (int i = 0; i < instances.size(); i++) { - Node3D *sp = Object::cast_to(ObjectDB::get_instance(instances[i])); if (!sp || _is_node_locked(sp)) continue; @@ -741,7 +710,6 @@ void Node3DEditorViewport::_select_region() { } void Node3DEditorViewport::_update_name() { - String view_mode = orthogonal ? TTR("Orthogonal") : TTR("Perspective"); if (auto_orthogonal) { @@ -757,7 +725,6 @@ void Node3DEditorViewport::_update_name() { } void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { - _edit.click_ray = _get_ray(Vector2(p_point.x, p_point.y)); _edit.click_ray_pos = _get_ray_pos(Vector2(p_point.x, p_point.y)); _edit.plane = TRANSFORM_VIEW; @@ -767,7 +734,6 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -782,9 +748,7 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { } static int _get_key_modifier_setting(const String &p_property) { - switch (EditorSettings::get_singleton()->get(p_property).operator int()) { - case 0: return 0; case 1: @@ -812,7 +776,6 @@ static int _get_key_modifier(Ref e) { } bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only) { - if (!spatial_editor->is_gizmo_visible()) return false; if (get_selected_count() == 0) { @@ -828,12 +791,10 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high float gs = gizmo_scale; if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_MOVE) { - int col_axis = -1; float col_d = 1e20; for (int i = 0; i < 3; i++) { - Vector3 grabber_pos = gt.origin + gt.basis.get_axis(i) * gs * (GIZMO_ARROW_OFFSET + (GIZMO_ARROW_SIZE * 0.5)); float grabber_radius = gs * GIZMO_ARROW_SIZE; @@ -854,7 +815,6 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high col_d = 1e20; for (int i = 0; i < 3; i++) { - Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); @@ -864,10 +824,8 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); if (plane.intersects_ray(ray_pos, ray, &r)) { - float dist = r.distance_to(grabber_pos); if (dist < (gs * GIZMO_PLANE_SIZE)) { - float d = ray_pos.distance_to(r); if (d < col_d) { col_d = d; @@ -881,9 +839,7 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (col_axis != -1) { - if (p_highlight_only) { - spatial_editor->select_gizmo_highlight_axis(col_axis + (is_plane_translate ? 6 : 0)); } else { @@ -897,12 +853,10 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE) { - int col_axis = -1; float col_d = 1e20; for (int i = 0; i < 3; i++) { - Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); Vector3 r; if (!plane.intersects_ray(ray_pos, ray, &r)) @@ -911,7 +865,6 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high float dist = r.distance_to(gt.origin); if (dist > gs * (GIZMO_CIRCLE_SIZE - GIZMO_RING_HALF_WIDTH) && dist < gs * (GIZMO_CIRCLE_SIZE + GIZMO_RING_HALF_WIDTH)) { - float d = ray_pos.distance_to(r); if (d < col_d) { col_d = d; @@ -921,9 +874,7 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (col_axis != -1) { - if (p_highlight_only) { - spatial_editor->select_gizmo_highlight_axis(col_axis + 3); } else { //handle rotate @@ -936,12 +887,10 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SCALE) { - int col_axis = -1; float col_d = 1e20; for (int i = 0; i < 3; i++) { - Vector3 grabber_pos = gt.origin + gt.basis.get_axis(i) * gs * GIZMO_SCALE_OFFSET; float grabber_radius = gs * GIZMO_ARROW_SIZE; @@ -962,7 +911,6 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high col_d = 1e20; for (int i = 0; i < 3; i++) { - Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); @@ -972,10 +920,8 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); if (plane.intersects_ray(ray_pos, ray, &r)) { - float dist = r.distance_to(grabber_pos); if (dist < (gs * GIZMO_PLANE_SIZE)) { - float d = ray_pos.distance_to(r); if (d < col_d) { col_d = d; @@ -989,9 +935,7 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } if (col_axis != -1) { - if (p_highlight_only) { - spatial_editor->select_gizmo_highlight_axis(col_axis + (is_plane_scale ? 12 : 9)); } else { @@ -1011,30 +955,25 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } void Node3DEditorViewport::_surface_mouse_enter() { - if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) surface->grab_focus(); } void Node3DEditorViewport::_surface_mouse_exit() { - _remove_preview(); } void Node3DEditorViewport::_surface_focus_enter() { - view_menu->set_disable_shortcuts(false); } void Node3DEditorViewport::_surface_focus_exit() { - view_menu->set_disable_shortcuts(true); } bool Node3DEditorViewport ::_is_node_locked(const Node *p_node) { return p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_"); } void Node3DEditorViewport::_list_select(Ref b) { - _find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift()); Node *scene = editor->get_edited_scene(); @@ -1051,7 +990,6 @@ void Node3DEditorViewport::_list_select(Ref b) { clicked_wants_append = b->get_shift(); if (selection_results.size() == 1) { - clicked = selection_results[0].item->get_instance_id(); selection_results.clear(); @@ -1061,12 +999,10 @@ void Node3DEditorViewport::_list_select(Ref b) { } } else if (!selection_results.empty()) { - NodePath root_path = get_tree()->get_edited_scene_root()->get_path(); StringName root_name = root_path.get_name(root_path.get_name_count() - 1); for (int i = 0; i < selection_results.size(); i++) { - Node3D *spat = selection_results[i].item; Ref icon = EditorNode::get_singleton()->get_object_icon(spat, "Node"); @@ -1107,7 +1043,6 @@ void Node3DEditorViewport::_list_select(Ref b) { } void Node3DEditorViewport::_sinput(const Ref &p_event) { - if (previewing) return; //do NONE @@ -1137,7 +1072,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { float zoom_factor = 1 + (ZOOM_MULTIPLIER - 1) * b->get_factor(); switch (b->get_button_index()) { - case BUTTON_WHEEL_UP: { if (is_freelook_active()) scale_freelook_speed(zoom_factor); @@ -1153,7 +1087,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } break; case BUTTON_RIGHT: { - NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); if (b->is_pressed() && _edit.gizmo.is_valid()) { @@ -1163,9 +1096,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (_edit.mode == TRANSFORM_NONE && b->is_pressed()) { - if (b->get_alt()) { - if (nav_scheme == NAVIGATION_MAYA) break; @@ -1181,7 +1112,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -1215,32 +1145,25 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } break; case BUTTON_MIDDLE: { - if (b->is_pressed() && _edit.mode != TRANSFORM_NONE) { - switch (_edit.plane) { - case TRANSFORM_VIEW: { - _edit.plane = TRANSFORM_X_AXIS; set_message(TTR("X-Axis Transform."), 2); name = ""; _update_name(); } break; case TRANSFORM_X_AXIS: { - _edit.plane = TRANSFORM_Y_AXIS; set_message(TTR("Y-Axis Transform."), 2); } break; case TRANSFORM_Y_AXIS: { - _edit.plane = TRANSFORM_Z_AXIS; set_message(TTR("Z-Axis Transform."), 2); } break; case TRANSFORM_Z_AXIS: { - _edit.plane = TRANSFORM_VIEW; set_message(TTR("View Plane Transform."), 2); @@ -1253,9 +1176,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } } break; case BUTTON_LEFT: { - if (b->is_pressed()) { - NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); if ((nav_scheme == NAVIGATION_MAYA || nav_scheme == NAVIGATION_MODO) && b->get_alt()) { break; @@ -1280,7 +1201,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (can_select_gizmos && spatial_editor->get_selected()) { - Ref seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { int handle = -1; @@ -1288,7 +1208,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Vector3 normal; bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, b->get_shift()); if (inters && handle != -1) { - _edit.gizmo = seg; _edit.gizmo_handle = handle; _edit.gizmo_initial_value = seg->get_handle_value(handle); @@ -1304,7 +1223,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { clicked_includes_current = false; if ((spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT && b->get_control()) || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE) { - /* HANDLE ROTATION */ if (get_selected_count() == 0) break; //bye @@ -1315,7 +1233,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_MOVE) { - if (get_selected_count() == 0) break; //bye //handle translate @@ -1325,7 +1242,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SCALE) { - if (get_selected_count() == 0) break; //bye //handle scale @@ -1345,7 +1261,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { clicked_wants_append = b->get_shift(); if (clicked.is_null()) { - if (!clicked_wants_append) _clear_selected(); @@ -1356,13 +1271,10 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (clicked.is_valid() && gizmo_handle >= 0) { - Node3D *spa = Object::cast_to(ObjectDB::get_instance(clicked)); if (spa) { - Ref seg = spa->get_gizmo(); if (seg.is_valid()) { - _edit.gizmo = seg; _edit.gizmo_handle = gizmo_handle; _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle); @@ -1373,9 +1285,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { surface->update(); } else { - if (_edit.gizmo.is_valid()) { - _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, false); _edit.gizmo = Ref(); break; @@ -1387,7 +1297,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (cursor.region_select) { - if (!clicked_wants_append) _clear_selected(); @@ -1397,14 +1306,12 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (_edit.mode != TRANSFORM_NONE) { - static const char *_transform_name[4] = { "None", "Rotate", "Translate", "Scale" }; undo_redo->create_action(_transform_name[_edit.mode]); List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -1431,14 +1338,11 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Ref m = p_event; if (m.is_valid()) { - _edit.mouse_pos = m->get_position(); if (spatial_editor->get_selected()) { - Ref seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { - int selected_handle = -1; int handle = -1; @@ -1446,7 +1350,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Vector3 normal; bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, false); if (inters && handle != -1) { - selected_handle = handle; } @@ -1460,7 +1363,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (spatial_editor->get_over_gizmo_handle() == -1 && !(m->get_button_mask() & 1) && !_edit.gizmo.is_valid()) { - _gizmo_select(_edit.mouse_pos, true); } @@ -1468,14 +1370,12 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { NavigationMode nav_mode = NAVIGATION_NONE; if (_edit.gizmo.is_valid()) { - _edit.gizmo->set_handle(_edit.gizmo_handle, camera, m->get_position()); Variant v = _edit.gizmo->get_handle_value(_edit.gizmo_handle); String n = _edit.gizmo->get_handle_name(_edit.gizmo_handle); set_message(n + ": " + String(v)); } else if (m->get_button_mask() & BUTTON_MASK_LEFT) { - if (nav_scheme == NAVIGATION_MAYA && m->get_alt()) { nav_mode = NAVIGATION_ORBIT; } else if (nav_scheme == NAVIGATION_MODO && m->get_alt() && m->get_shift()) { @@ -1486,9 +1386,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { nav_mode = NAVIGATION_ORBIT; } else { if (clicked.is_valid()) { - if (!clicked_includes_current) { - _select_clicked(clicked_wants_append, true); // Processing was deferred. } @@ -1514,9 +1412,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { int snap_step_decimals = Math::range_step_decimals(snap); switch (_edit.mode) { - case TRANSFORM_SCALE: { - Vector3 motion_mask; Plane plane; bool plane_mv = false; @@ -1565,13 +1461,10 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Vector3 motion = intersection - click; if (_edit.plane != TRANSFORM_VIEW) { - if (!plane_mv) { - motion = motion_mask.dot(motion) * motion_mask; } else { - // Alternative planar scaling mode if (_get_key_modifier(m) != KEY_SHIFT) { motion = motion_mask.dot(motion) * motion_mask; @@ -1603,7 +1496,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) { continue; @@ -1625,7 +1517,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Vector3 local_scale; if (local_coords) { - Basis g = original.basis.orthonormalized(); Vector3 local_motion = g.inverse().xform(motion); @@ -1639,13 +1530,11 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Basis check = original_local.basis; check.scale(local_scale); if (check.determinant() != 0) { - // Apply scale sp->set_scale(local_scale); } } else { - if (_edit.snap || spatial_editor->is_snap_enabled()) { motion.snap(Vector3(snap, snap, snap)); } @@ -1664,7 +1553,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } break; case TRANSFORM_TRANSLATE: { - Vector3 motion_mask; Plane plane; bool plane_mv = false; @@ -1728,7 +1616,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) { continue; @@ -1747,7 +1634,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Transform t; if (local_coords) { - if (_edit.snap || spatial_editor->is_snap_enabled()) { Basis g = original.basis.orthonormalized(); Vector3 local_motion = g.inverse().xform(motion); @@ -1757,7 +1643,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } } else { - if (_edit.snap || spatial_editor->is_snap_enabled()) { motion.snap(Vector3(snap, snap, snap)); } @@ -1774,7 +1659,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } break; case TRANSFORM_ROTATE: { - Plane plane; Vector3 axis; @@ -1826,7 +1710,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -1842,7 +1725,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Transform t; if (local_coords) { - Transform original_local = se->original_local; Basis rot = Basis(axis, angle); @@ -1854,7 +1736,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { sp->set_scale(original_local.basis.get_scale()); // re-apply original scale } else { - Transform original = se->original; Transform r; Transform base = Transform(Basis(), _edit.center); @@ -1876,7 +1757,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } } else if ((m->get_button_mask() & BUTTON_MASK_RIGHT) || freelook_active) { - if (nav_scheme == NAVIGATION_MAYA && m->get_alt()) { nav_mode = NAVIGATION_ZOOM; } else if (freelook_active) { @@ -1886,9 +1766,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } } else if (m->get_button_mask() & BUTTON_MASK_MIDDLE) { - if (nav_scheme == NAVIGATION_GODOT) { - const int mod = _get_key_modifier(m); if (mod == _get_key_modifier_setting("editors/3d/navigation/pan_modifier")) { @@ -1949,7 +1827,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Ref magnify_gesture = p_event; if (magnify_gesture.is_valid()) { - if (is_freelook_active()) scale_freelook_speed(magnify_gesture->get_factor()); else @@ -1958,12 +1835,10 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Ref pan_gesture = p_event; if (pan_gesture.is_valid()) { - NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); NavigationMode nav_mode = NAVIGATION_NONE; if (nav_scheme == NAVIGATION_GODOT) { - const int mod = _get_key_modifier(pan_gesture); if (mod == _get_key_modifier_setting("editors/3d/navigation/pan_modifier")) { @@ -2064,7 +1939,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -2096,7 +1970,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } void Node3DEditorViewport::_nav_pan(Ref p_event, const Vector2 &p_relative) { - const NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); real_t pan_speed = 1 / 150.0; @@ -2116,7 +1989,6 @@ void Node3DEditorViewport::_nav_pan(Ref p_event, const } void Node3DEditorViewport::_nav_zoom(Ref p_event, const Vector2 &p_relative) { - const NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); real_t zoom_speed = 1 / 80.0; @@ -2139,7 +2011,6 @@ void Node3DEditorViewport::_nav_zoom(Ref p_event, const } void Node3DEditorViewport::_nav_orbit(Ref p_event, const Vector2 &p_relative) { - if (lock_rotation) { _nav_pan(p_event, p_relative); return; @@ -2168,7 +2039,6 @@ void Node3DEditorViewport::_nav_orbit(Ref p_event, cons } void Node3DEditorViewport::_nav_look(Ref p_event, const Vector2 &p_relative) { - if (orthogonal) { _nav_pan(p_event, p_relative); return; @@ -2208,7 +2078,6 @@ void Node3DEditorViewport::_nav_look(Ref p_event, const } void Node3DEditorViewport::set_freelook_active(bool active_now) { - if (!freelook_active && active_now) { // Sync camera cursor to cursor to "cut" interpolation jumps due to changing referential cursor = camera_cursor; @@ -2240,7 +2109,6 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) { } void Node3DEditorViewport::scale_cursor_distance(real_t scale) { - // Prevents zero distance which would short-circuit any scaling if (cursor.distance < ZOOM_MIN_DISTANCE) cursor.distance = ZOOM_MIN_DISTANCE; @@ -2255,7 +2123,6 @@ void Node3DEditorViewport::scale_cursor_distance(real_t scale) { } void Node3DEditorViewport::scale_freelook_speed(real_t scale) { - // Prevents zero distance which would short-circuit any scaling if (freelook_speed < FREELOOK_MIN_SPEED) freelook_speed = FREELOOK_MIN_SPEED; @@ -2294,7 +2161,6 @@ static bool is_shortcut_pressed(const String &p_path) { } void Node3DEditorViewport::_update_freelook(real_t delta) { - if (!is_freelook_active()) { return; } @@ -2357,7 +2223,6 @@ void Node3DEditorViewport::_update_freelook(real_t delta) { } void Node3DEditorViewport::set_message(String p_message, float p_time) { - message = p_message; message_time = p_time; } @@ -2372,9 +2237,7 @@ void Node3DEditorPlugin::edited_scene_changed() { } void Node3DEditorViewport::_notification(int p_what) { - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - bool visible = is_visible_in_tree(); set_process(visible); @@ -2391,7 +2254,6 @@ void Node3DEditorViewport::_notification(int p_what) { } if (p_what == NOTIFICATION_RESIZED) { - call_deferred("update_transform_gizmo_view"); } @@ -2403,7 +2265,6 @@ void Node3DEditorViewport::_notification(int p_what) { } if (p_what == NOTIFICATION_PROCESS) { - real_t delta = get_process_delta_time(); if (zoom_indicator_delay > 0) { @@ -2438,7 +2299,6 @@ void Node3DEditorViewport::_notification(int p_what) { bool exist = false; for (Map::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->key()); if (!sp) continue; @@ -2475,7 +2335,6 @@ void Node3DEditorViewport::_notification(int p_what) { } if (message_time > 0) { - if (message != last_message) { surface->update(); last_message = message; @@ -2561,7 +2420,6 @@ void Node3DEditorViewport::_notification(int p_what) { cpu_time_history_index = 0; } if (show_fps) { - cpu_time_history[cpu_time_history_index] = RS::get_singleton()->viewport_get_measured_render_time_cpu(viewport->get_viewport_rid()); cpu_time_history_index = (cpu_time_history_index + 1) % FRAME_TIME_HISTORY; float cpu_time = 0.0; @@ -2600,7 +2458,6 @@ void Node3DEditorViewport::_notification(int p_what) { } if (p_what == NOTIFICATION_ENTER_TREE) { - surface->connect("draw", callable_mp(this, &Node3DEditorViewport::_draw)); surface->connect("gui_input", callable_mp(this, &Node3DEditorViewport::_sinput)); surface->connect("mouse_entered", callable_mp(this, &Node3DEditorViewport::_surface_mouse_enter)); @@ -2612,12 +2469,10 @@ void Node3DEditorViewport::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - _finish_gizmo_instances(); } if (p_what == NOTIFICATION_THEME_CHANGED) { - view_menu->set_icon(get_theme_icon("GuiTabMenu", "EditorIcons")); preview_camera->set_icon(get_theme_icon("Camera3D", "EditorIcons")); @@ -2641,7 +2496,6 @@ void Node3DEditorViewport::_notification(int p_what) { } static void draw_indicator_bar(Control &surface, real_t fill, Ref icon) { - // Adjust bar size from control height Vector2 surface_size = surface.get_size(); real_t h = surface_size.y / 2.0; @@ -2662,7 +2516,6 @@ static void draw_indicator_bar(Control &surface, real_t fill, Ref ico } void Node3DEditorViewport::_draw() { - EditorPluginList *over_plugin_list = EditorNode::get_singleton()->get_editor_plugins_over(); if (!over_plugin_list->empty()) { over_plugin_list->forward_spatial_draw_over_viewport(surface); @@ -2704,7 +2557,6 @@ void Node3DEditorViewport::_draw() { } if (_edit.mode == TRANSFORM_ROTATE) { - Point2 center = _point_to_screen(_edit.center); RenderingServer::get_singleton()->canvas_item_add_line( ci, @@ -2714,7 +2566,6 @@ void Node3DEditorViewport::_draw() { Math::round(2 * EDSCALE)); } if (previewing) { - Size2 ss = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height")); float aspect = ss.aspect(); Size2 s = get_size(); @@ -2723,14 +2574,12 @@ void Node3DEditorViewport::_draw() { switch (previewing->get_keep_aspect_mode()) { case Camera3D::KEEP_WIDTH: { - draw_rect.size = Size2(s.width, s.width / aspect); draw_rect.position.x = 0; draw_rect.position.y = (s.height - draw_rect.size.y) * 0.5; } break; case Camera3D::KEEP_HEIGHT: { - draw_rect.size = Size2(s.height * aspect, s.height); draw_rect.position.y = 0; draw_rect.position.x = (s.width - draw_rect.size.x) * 0.5; @@ -2743,9 +2592,7 @@ void Node3DEditorViewport::_draw() { surface->draw_rect(draw_rect, Color(0.6, 0.6, 0.1, 0.5), false, Math::round(2 * EDSCALE)); } else { - if (zoom_indicator_delay > 0.0) { - if (is_freelook_active()) { // Show speed @@ -2787,11 +2634,8 @@ void Node3DEditorViewport::_draw() { } void Node3DEditorViewport::_menu_option(int p_option) { - switch (p_option) { - case VIEW_TOP: { - cursor.y_rot = 0; cursor.x_rot = Math_PI / 2.0; set_message(TTR("Top View."), 2); @@ -2801,7 +2645,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_BOTTOM: { - cursor.y_rot = 0; cursor.x_rot = -Math_PI / 2.0; set_message(TTR("Bottom View."), 2); @@ -2811,7 +2654,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_LEFT: { - cursor.x_rot = 0; cursor.y_rot = Math_PI / 2.0; set_message(TTR("Left View."), 2); @@ -2821,7 +2663,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_RIGHT: { - cursor.x_rot = 0; cursor.y_rot = -Math_PI / 2.0; set_message(TTR("Right View."), 2); @@ -2831,7 +2672,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_FRONT: { - cursor.x_rot = 0; cursor.y_rot = 0; set_message(TTR("Front View."), 2); @@ -2841,7 +2681,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_REAR: { - cursor.x_rot = 0; cursor.y_rot = Math_PI; set_message(TTR("Rear View."), 2); @@ -2851,17 +2690,14 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_CENTER_TO_ORIGIN: { - cursor.pos = Vector3(0, 0, 0); } break; case VIEW_CENTER_TO_SELECTION: { - focus_selection(); } break; case VIEW_ALIGN_TRANSFORM_WITH_VIEW: { - if (!get_selected_count()) break; @@ -2872,7 +2708,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { undo_redo->create_action(TTR("Align Transform with View")); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -2897,7 +2732,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ALIGN_ROTATION_WITH_VIEW: { - if (!get_selected_count()) break; @@ -2907,7 +2741,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { undo_redo->create_action(TTR("Align Rotation with View")); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -2923,15 +2756,12 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ENVIRONMENT: { - int idx = view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; if (current) { - camera->set_environment(RES()); } else { - camera->set_environment(Node3DEditor::get_singleton()->get_viewport_environment()); } @@ -2939,7 +2769,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_PERSPECTIVE: { - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), false); orthogonal = false; @@ -2949,7 +2778,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ORTHOGONAL: { - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), true); orthogonal = true; @@ -2959,7 +2787,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_AUTO_ORTHOGONAL: { - int idx = view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -2970,7 +2797,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } } break; case VIEW_LOCK_ROTATION: { - int idx = view_menu->get_popup()->get_item_index(VIEW_LOCK_ROTATION); bool current = view_menu->get_popup()->is_item_checked(idx); lock_rotation = !current; @@ -2983,7 +2809,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_AUDIO_LISTENER: { - int idx = view_menu->get_popup()->get_item_index(VIEW_AUDIO_LISTENER); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -2992,7 +2817,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_AUDIO_DOPPLER: { - int idx = view_menu->get_popup()->get_item_index(VIEW_AUDIO_DOPPLER); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -3001,7 +2825,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_CINEMATIC_PREVIEW: { - int idx = view_menu->get_popup()->get_item_index(VIEW_CINEMATIC_PREVIEW); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -3017,7 +2840,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { } } break; case VIEW_GIZMOS: { - int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; @@ -3029,21 +2851,18 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_HALF_RESOLUTION: { - int idx = view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; view_menu->get_popup()->set_item_checked(idx, current); } break; case VIEW_INFORMATION: { - int idx = view_menu->get_popup()->get_item_index(VIEW_INFORMATION); bool current = view_menu->get_popup()->is_item_checked(idx); view_menu->get_popup()->set_item_checked(idx, !current); } break; case VIEW_FRAME_TIME: { - int idx = view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME); bool current = view_menu->get_popup()->is_item_checked(idx); view_menu->get_popup()->set_item_checked(idx, !current); @@ -3065,7 +2884,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { case VIEW_DISPLAY_DEBUG_PSSM_SPLITS: case VIEW_DISPLAY_DEBUG_DECAL_ATLAS: case VIEW_DISPLAY_DEBUG_ROUGHNESS_LIMITER: { - static const int display_options[] = { VIEW_DISPLAY_NORMAL, VIEW_DISPLAY_WIREFRAME, @@ -3109,7 +2927,6 @@ void Node3DEditorViewport::_menu_option(int p_option) { int idx = 0; while (display_options[idx] != VIEW_MAX) { - int id = display_options[idx]; int item_idx = view_menu->get_popup()->get_item_index(id); if (item_idx != -1) { @@ -3137,7 +2954,6 @@ void Node3DEditorViewport::_set_auto_orthogonal() { } void Node3DEditorViewport::_preview_exited_scene() { - preview_camera->disconnect("toggled", callable_mp(this, &Node3DEditorViewport::_toggle_camera_preview)); preview_camera->set_pressed(false); _toggle_camera_preview(false); @@ -3146,7 +2962,6 @@ void Node3DEditorViewport::_preview_exited_scene() { } void Node3DEditorViewport::_init_gizmo_instance(int p_idx) { - uint32_t layer = 1 << (GIZMO_BASE_LAYER + p_idx); for (int i = 0; i < 3; i++) { @@ -3188,7 +3003,6 @@ void Node3DEditorViewport::_init_gizmo_instance(int p_idx) { } void Node3DEditorViewport::_finish_gizmo_instances() { - for (int i = 0; i < 3; i++) { RS::get_singleton()->free(move_gizmo_instance[i]); RS::get_singleton()->free(move_plane_gizmo_instance[i]); @@ -3198,14 +3012,12 @@ void Node3DEditorViewport::_finish_gizmo_instances() { } } void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { - ERR_FAIL_COND(p_activate && !preview); ERR_FAIL_COND(!p_activate && !previewing); rotation_control->set_visible(!p_activate); if (!p_activate) { - previewing->disconnect("tree_exiting", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); previewing = nullptr; RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore @@ -3215,7 +3027,6 @@ void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { surface->update(); } else { - previewing = preview; previewing->connect("tree_exiting", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), preview->get_camera()); //replace @@ -3244,7 +3055,6 @@ void Node3DEditorViewport::_toggle_cinema_preview(bool p_activate) { } void Node3DEditorViewport::_selection_result_pressed(int p_result) { - if (selection_results.size() <= p_result) return; @@ -3257,14 +3067,12 @@ void Node3DEditorViewport::_selection_result_pressed(int p_result) { } void Node3DEditorViewport::_selection_menu_hide() { - selection_results.clear(); selection_menu->clear(); selection_menu->set_size(Vector2(0, 0)); } void Node3DEditorViewport::set_can_preview(Camera3D *p_preview) { - preview = p_preview; if (!preview_camera->is_pressed() && !previewing_cinema) @@ -3272,7 +3080,6 @@ void Node3DEditorViewport::set_can_preview(Camera3D *p_preview) { } void Node3DEditorViewport::update_transform_gizmo_view() { - if (!is_visible_in_tree()) return; @@ -3328,7 +3135,6 @@ void Node3DEditorViewport::update_transform_gizmo_view() { } void Node3DEditorViewport::set_state(const Dictionary &p_state) { - if (p_state.has("position")) cursor.pos = p_state["position"]; if (p_state.has("x_rotation")) @@ -3444,7 +3250,6 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { } Dictionary Node3DEditorViewport::get_state() const { - Dictionary d; d["position"] = cursor.pos; d["x_rotation"] = cursor.x_rot; @@ -3479,7 +3284,6 @@ Dictionary Node3DEditorViewport::get_state() const { } void Node3DEditorViewport::_bind_methods() { - ClassDB::bind_method(D_METHOD("update_transform_gizmo_view"), &Node3DEditorViewport::update_transform_gizmo_view); // Used by call_deferred. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &Node3DEditorViewport::can_drop_data_fw); ClassDB::bind_method(D_METHOD("drop_data_fw"), &Node3DEditorViewport::drop_data_fw); @@ -3489,7 +3293,6 @@ void Node3DEditorViewport::_bind_methods() { } void Node3DEditorViewport::reset() { - orthogonal = false; auto_orthogonal = false; lock_rotation = false; @@ -3516,7 +3319,6 @@ void Node3DEditorViewport::focus_selection() { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -3557,7 +3359,6 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const Vector3 normal = Vector3(0.0, 0.0, 0.0); for (int i = 0; i < instances.size(); i++) { - MeshInstance3D *mesh_instance = Object::cast_to(ObjectDB::get_instance(instances[i])); if (!mesh_instance) @@ -3781,7 +3582,6 @@ void Node3DEditorViewport::_perform_drop_data() { } bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - bool can_instance = false; if (!preview_node->is_inside_tree()) { @@ -3878,7 +3678,6 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_ } Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, EditorNode *p_editor, int p_index) { - cpu_time_history_index = 0; gpu_time_history_index = 0; @@ -4132,11 +3931,9 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito ////////////////////////////////////////////////////////////// void Node3DEditorViewportContainer::_gui_input(const Ref &p_event) { - Ref mb = p_event; if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { Vector2 size = get_size(); @@ -4155,25 +3952,21 @@ void Node3DEditorViewportContainer::_gui_input(const Ref &p_event) { switch (view) { case VIEW_USE_1_VIEWPORT: { - dragging_h = false; dragging_v = false; } break; case VIEW_USE_2_VIEWPORTS: { - dragging_h = false; } break; case VIEW_USE_2_VIEWPORTS_ALT: { - dragging_v = false; } break; case VIEW_USE_3_VIEWPORTS: case VIEW_USE_3_VIEWPORTS_ALT: case VIEW_USE_4_VIEWPORTS: { - // Do nothing. } break; @@ -4187,7 +3980,6 @@ void Node3DEditorViewportContainer::_gui_input(const Ref &p_event) { Ref mm = p_event; if (mm.is_valid()) { - if (view == VIEW_USE_3_VIEWPORTS || view == VIEW_USE_3_VIEWPORTS_ALT || view == VIEW_USE_4_VIEWPORTS) { Vector2 size = get_size(); @@ -4225,15 +4017,12 @@ void Node3DEditorViewportContainer::_gui_input(const Ref &p_event) { } void Node3DEditorViewportContainer::_notification(int p_what) { - if (p_what == NOTIFICATION_MOUSE_ENTER || p_what == NOTIFICATION_MOUSE_EXIT) { - mouseover = (p_what == NOTIFICATION_MOUSE_ENTER); update(); } if (p_what == NOTIFICATION_DRAW && mouseover) { - Ref h_grabber = get_theme_icon("grabber", "HSplitContainer"); Ref v_grabber = get_theme_icon("grabber", "VSplitContainer"); @@ -4254,26 +4043,21 @@ void Node3DEditorViewportContainer::_notification(int p_what) { int size_bottom = size.height - mid_h - v_sep / 2; switch (view) { - case VIEW_USE_1_VIEWPORT: { - // Nothing to show. } break; case VIEW_USE_2_VIEWPORTS: { - draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); set_default_cursor_shape(CURSOR_VSPLIT); } break; case VIEW_USE_2_VIEWPORTS_ALT: { - draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); set_default_cursor_shape(CURSOR_HSPLIT); } break; case VIEW_USE_3_VIEWPORTS: { - if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { draw_texture(hdiag_grabber, Vector2(mid_w - hdiag_grabber->get_width() / 2, mid_h - v_grabber->get_height() / 4)); set_default_cursor_shape(CURSOR_DRAG); @@ -4287,7 +4071,6 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_3_VIEWPORTS_ALT: { - if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { draw_texture(vdiag_grabber, Vector2(mid_w - vdiag_grabber->get_width() + v_grabber->get_height() / 4, mid_h - vdiag_grabber->get_height() / 2)); set_default_cursor_shape(CURSOR_DRAG); @@ -4301,7 +4084,6 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_4_VIEWPORTS: { - Vector2 half(mid_w, mid_h); if ((hovering_v && hovering_h && !dragging_v && !dragging_h) || (dragging_v && dragging_h)) { draw_texture(vh_grabber, half - vh_grabber->get_size() / 2.0); @@ -4319,7 +4101,6 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } if (p_what == NOTIFICATION_SORT_CHILDREN) { - Node3DEditorViewport *viewports[4]; int vc = 0; for (int i = 0; i < get_child_count(); i++) { @@ -4353,12 +4134,9 @@ void Node3DEditorViewportContainer::_notification(int p_what) { int size_bottom = size.height - mid_h - v_sep / 2; switch (view) { - case VIEW_USE_1_VIEWPORT: { - viewports[0]->show(); for (int i = 1; i < 4; i++) { - viewports[i]->hide(); } @@ -4366,9 +4144,7 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_2_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - if (i == 1 || i == 3) viewports[i]->hide(); else @@ -4380,9 +4156,7 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_2_VIEWPORTS_ALT: { - for (int i = 0; i < 4; i++) { - if (i == 1 || i == 3) viewports[i]->hide(); else @@ -4393,9 +4167,7 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_3_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - if (i == 1) viewports[i]->hide(); else @@ -4408,9 +4180,7 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_3_VIEWPORTS_ALT: { - for (int i = 0; i < 4; i++) { - if (i == 1) viewports[i]->hide(); else @@ -4423,9 +4193,7 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_4_VIEWPORTS: { - for (int i = 0; i < 4; i++) { - viewports[i]->show(); } @@ -4440,23 +4208,19 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } void Node3DEditorViewportContainer::set_view(View p_view) { - view = p_view; queue_sort(); } Node3DEditorViewportContainer::View Node3DEditorViewportContainer::get_view() { - return view; } void Node3DEditorViewportContainer::_bind_methods() { - ClassDB::bind_method("_gui_input", &Node3DEditorViewportContainer::_gui_input); } Node3DEditorViewportContainer::Node3DEditorViewportContainer() { - set_clip_contents(true); view = VIEW_USE_1_VIEWPORT; mouseover = false; @@ -4473,15 +4237,12 @@ Node3DEditorViewportContainer::Node3DEditorViewportContainer() { Node3DEditor *Node3DEditor::singleton = nullptr; Node3DEditorSelectedItem::~Node3DEditorSelectedItem() { - if (sbox_instance.is_valid()) RenderingServer::get_singleton()->free(sbox_instance); } void Node3DEditor::select_gizmo_highlight_axis(int p_axis) { - for (int i = 0; i < 3; i++) { - move_gizmo[i]->surface_set_material(0, i == p_axis ? gizmo_color_hl[i] : gizmo_color[i]); move_plane_gizmo[i]->surface_set_material(0, (i + 6) == p_axis ? plane_gizmo_color_hl[i] : plane_gizmo_color[i]); rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_color_hl[i] : gizmo_color[i]); @@ -4491,7 +4252,6 @@ void Node3DEditor::select_gizmo_highlight_axis(int p_axis) { } void Node3DEditor::update_transform_gizmo() { - List &selection = editor_selection->get_selected_node_list(); AABB center; bool first = true; @@ -4500,7 +4260,6 @@ void Node3DEditor::update_transform_gizmo() { bool local_gizmo_coords = are_local_coords_enabled(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -4553,7 +4312,6 @@ void Node3DEditor::update_all_gizmos(Node *p_node) { } Object *Node3DEditor::_get_editor_data(Object *p_what) { - Node3D *sp = Object::cast_to(p_what); if (!sp) return nullptr; @@ -4568,7 +4326,6 @@ Object *Node3DEditor::_get_editor_data(Object *p_what) { } void Node3DEditor::_generate_selection_box() { - AABB aabb(Vector3(), Vector3(1, 1, 1)); aabb.grow_by(aabb.get_longest_axis_size() / 20.0); @@ -4576,7 +4333,6 @@ void Node3DEditor::_generate_selection_box() { st->begin(Mesh::PRIMITIVE_LINES); for (int i = 0; i < 12; i++) { - Vector3 a, b; aabb.get_edge(i, a, b); @@ -4602,7 +4358,6 @@ void Node3DEditor::_generate_selection_box() { } Dictionary Node3DEditor::get_state() const { - Dictionary d; d["snap_enabled"] = snap_enabled; @@ -4654,7 +4409,6 @@ Dictionary Node3DEditor::get_state() const { return d; } void Node3DEditor::set_state(const Dictionary &p_state) { - Dictionary d = p_state; if (d.has("snap_enabled")) { @@ -4754,10 +4508,8 @@ void Node3DEditor::set_state(const Dictionary &p_state) { } void Node3DEditor::edit(Node3D *p_spatial) { - if (p_spatial != selected) { if (selected) { - Ref seg = selected->get_gizmo(); if (seg.is_valid()) { seg->set_selected(false); @@ -4769,7 +4521,6 @@ void Node3DEditor::edit(Node3D *p_spatial) { over_gizmo_handle = -1; if (selected) { - Ref seg = selected->get_gizmo(); if (seg.is_valid()) { seg->set_selected(true); @@ -4780,21 +4531,18 @@ void Node3DEditor::edit(Node3D *p_spatial) { } void Node3DEditor::_snap_changed() { - snap_translate_value = snap_translate->get_text().to_double(); snap_rotate_value = snap_rotate->get_text().to_double(); snap_scale_value = snap_scale->get_text().to_double(); } void Node3DEditor::_snap_update() { - snap_translate->set_text(String::num(snap_translate_value)); snap_rotate->set_text(String::num(snap_rotate_value)); snap_scale->set_text(String::num(snap_scale_value)); } void Node3DEditor::_xform_dialog_action() { - Transform t; //translation Vector3 scale; @@ -4816,7 +4564,6 @@ void Node3DEditor::_xform_dialog_action() { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to(E->get()); if (!sp) continue; @@ -4831,7 +4578,6 @@ void Node3DEditor::_xform_dialog_action() { if (post) tr = tr * t; else { - tr.basis = t.basis * tr.basis; tr.origin += t.origin; } @@ -4843,10 +4589,8 @@ void Node3DEditor::_xform_dialog_action() { } void Node3DEditor::_menu_item_toggled(bool pressed, int p_option) { - switch (p_option) { case MENU_TOOL_LOCAL_COORDS: { - tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_pressed(pressed); update_transform_gizmo(); } break; @@ -4861,7 +4605,6 @@ void Node3DEditor::_menu_item_toggled(bool pressed, int p_option) { using Override = EditorDebuggerNode::CameraOverride; if (pressed) { - debugger->set_camera_override((Override)(Override::OVERRIDE_3D_1 + camera_override_viewport_id)); } else { debugger->set_camera_override(Override::OVERRIDE_NONE); @@ -4872,7 +4615,6 @@ void Node3DEditor::_menu_item_toggled(bool pressed, int p_option) { } void Node3DEditor::_menu_gizmo_toggled(int p_option) { - const int idx = gizmos_menu->get_item_index(p_option); gizmos_menu->toggle_item_multistate(idx); @@ -4925,15 +4667,12 @@ void Node3DEditor::_update_camera_override_viewport(Object *p_viewport) { } void Node3DEditor::_menu_item_pressed(int p_option) { - switch (p_option) { - case MENU_TOOL_SELECT: case MENU_TOOL_MOVE: case MENU_TOOL_ROTATE: case MENU_TOOL_SCALE: case MENU_TOOL_LIST_SELECT: { - for (int i = 0; i < TOOL_MAX; i++) tool_button[i]->set_pressed(i == p_option); tool_mode = (ToolMode)p_option; @@ -4941,13 +4680,10 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_TRANSFORM_CONFIGURE_SNAP: { - snap_dialog->popup_centered(Size2(200, 180)); } break; case MENU_TRANSFORM_DIALOG: { - for (int i = 0; i < 3; i++) { - xform_translate[i]->set_text("0"); xform_rotate[i]->set_text("0"); xform_scale[i]->set_text("1"); @@ -4957,7 +4693,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_1_VIEWPORT: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_1_VIEWPORT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), true); @@ -4969,7 +4704,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_2_VIEWPORTS: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_2_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -4981,7 +4715,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_2_VIEWPORTS_ALT: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_2_VIEWPORTS_ALT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -4993,7 +4726,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_3_VIEWPORTS: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_3_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -5005,7 +4737,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_3_VIEWPORTS_ALT: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_3_VIEWPORTS_ALT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -5017,7 +4748,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_4_VIEWPORTS: { - viewport_base->set_view(Node3DEditorViewportContainer::VIEW_USE_4_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); @@ -5029,7 +4759,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_ORIGIN: { - bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); origin_enabled = !is_checked; @@ -5041,7 +4770,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), origin_enabled); } break; case MENU_VIEW_GRID: { - bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); grid_enabled = !is_checked; @@ -5057,7 +4785,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_CAMERA_SETTINGS: { - settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50)); } break; case MENU_SNAP_TO_FLOOR: { @@ -5069,7 +4796,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to(E->get()); if (!spatial || !spatial->is_visible_in_tree()) continue; @@ -5093,7 +4819,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to(E->get()); if (!spatial || !spatial->is_visible_in_tree()) continue; @@ -5117,7 +4842,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to(E->get()); if (!spatial || !spatial->is_visible_in_tree()) continue; @@ -5140,7 +4864,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List &selection = editor_selection->get_selected_node_list(); for (List::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to(E->get()); if (!spatial || !spatial->is_visible_in_tree()) continue; @@ -5162,7 +4885,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } void Node3DEditor::_init_indicators() { - { origin_enabled = true; grid_enabled = true; @@ -5224,11 +4946,9 @@ void Node3DEditor::_init_indicators() { } { - //move gizmo for (int i = 0; i < 3; i++) { - Color col; switch (i) { case 0: @@ -5276,7 +4996,6 @@ void Node3DEditor::_init_indicators() { //translate { - Ref surftool = memnew(SurfaceTool); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); @@ -5293,12 +5012,10 @@ void Node3DEditor::_init_indicators() { int arrow_sides = 16; for (int k = 0; k < arrow_sides; k++) { - Basis ma(ivec, Math_PI * 2 * float(k) / arrow_sides); Basis mb(ivec, Math_PI * 2 * float(k + 1) / arrow_sides); for (int j = 0; j < arrow_points - 1; j++) { - Vector3 points[4] = { ma.xform(arrow[j]), mb.xform(arrow[j]), @@ -5365,7 +5082,6 @@ void Node3DEditor::_init_indicators() { // Rotate { - Ref surftool = memnew(SurfaceTool); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); @@ -5378,12 +5094,10 @@ void Node3DEditor::_init_indicators() { }; for (int k = 0; k < 64; k++) { - Basis ma(ivec, Math_PI * 2 * float(k) / 64); Basis mb(ivec, Math_PI * 2 * float(k + 1) / 64); for (int j = 0; j < 4; j++) { - Vector3 points[4] = { ma.xform(circle[j]), mb.xform(circle[j]), @@ -5423,12 +5137,10 @@ void Node3DEditor::_init_indicators() { int arrow_sides = 4; for (int k = 0; k < 4; k++) { - Basis ma(ivec, Math_PI * 2 * float(k) / arrow_sides); Basis mb(ivec, Math_PI * 2 * float(k + 1) / arrow_sides); for (int j = 0; j < arrow_points - 1; j++) { - Vector3 points[4] = { ma.xform(arrow[j]), mb.xform(arrow[j]), @@ -5499,7 +5211,6 @@ void Node3DEditor::_init_indicators() { } void Node3DEditor::_update_gizmos_menu() { - gizmos_menu->clear(); for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) { @@ -5544,7 +5255,6 @@ void Node3DEditor::_update_gizmos_menu_theme() { } void Node3DEditor::_init_grid() { - Vector grid_colors[3]; Vector grid_points[3]; @@ -5603,7 +5313,6 @@ void Node3DEditor::_init_grid() { } void Node3DEditor::_finish_indicators() { - RenderingServer::get_singleton()->free(origin_instance); RenderingServer::get_singleton()->free(origin); @@ -5626,7 +5335,6 @@ bool Node3DEditor::is_any_freelook_active() const { } void Node3DEditor::_refresh_menu_icons() { - bool all_locked = true; bool all_grouped = true; @@ -5798,16 +5506,13 @@ void Node3DEditor::snap_selected_nodes_to_floor() { } void Node3DEditor::_unhandled_key_input(Ref p_event) { - if (!is_visible_in_tree()) return; snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); } void Node3DEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon("ToolSelect", "EditorIcons")); tool_button[Node3DEditor::TOOL_MODE_MOVE]->set_icon(get_theme_icon("ToolMove", "EditorIcons")); tool_button[Node3DEditor::TOOL_MODE_ROTATE]->set_icon(get_theme_icon("ToolRotate", "EditorIcons")); @@ -5840,14 +5545,12 @@ void Node3DEditor::_notification(int p_what) { editor->connect("stop_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(false)); editor->connect("play_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(true)); } else if (p_what == NOTIFICATION_ENTER_TREE) { - _register_all_gizmos(); _update_gizmos_menu(); _init_indicators(); } else if (p_what == NOTIFICATION_THEME_CHANGED) { _update_gizmos_menu_theme(); } else if (p_what == NOTIFICATION_EXIT_TREE) { - _finish_indicators(); } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon("ToolSelect", "EditorIcons")); @@ -5884,39 +5587,32 @@ void Node3DEditor::_notification(int p_what) { } void Node3DEditor::add_control_to_menu_panel(Control *p_control) { - hbc_menu->add_child(p_control); } void Node3DEditor::remove_control_from_menu_panel(Control *p_control) { - hbc_menu->remove_child(p_control); } void Node3DEditor::set_can_preview(Camera3D *p_preview) { - for (int i = 0; i < 4; i++) { viewports[i]->set_can_preview(p_preview); } } VSplitContainer *Node3DEditor::get_shader_split() { - return shader_split; } HSplitContainer *Node3DEditor::get_palette_split() { - return palette_split; } void Node3DEditor::_request_gizmo(Object *p_obj) { - Node3D *sp = Object::cast_to(p_obj); if (!sp) return; if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) { - Ref seg; for (int i = 0; i < gizmo_plugins_by_priority.size(); ++i) { @@ -5957,7 +5653,6 @@ void Node3DEditor::_toggle_maximize_view(Object *p_viewport) { return; if (!maximized) { - for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { if (i == (uint32_t)index) viewports[i]->set_anchors_and_margins_preset(Control::PRESET_WIDE); @@ -5965,7 +5660,6 @@ void Node3DEditor::_toggle_maximize_view(Object *p_viewport) { viewports[i]->hide(); } } else { - for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) viewports[i]->show(); @@ -5985,7 +5679,6 @@ void Node3DEditor::_toggle_maximize_view(Object *p_viewport) { } void Node3DEditor::_node_removed(Node *p_node) { - if (p_node == selected) selected = nullptr; } @@ -6018,7 +5711,6 @@ void Node3DEditor::_register_all_gizmos() { } void Node3DEditor::_bind_methods() { - ClassDB::bind_method("_unhandled_key_input", &Node3DEditor::_unhandled_key_input); ClassDB::bind_method("_get_editor_data", &Node3DEditor::_get_editor_data); ClassDB::bind_method("_request_gizmo", &Node3DEditor::_request_gizmo); @@ -6029,7 +5721,6 @@ void Node3DEditor::_bind_methods() { } void Node3DEditor::clear() { - settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov", 70.0)); settings_znear->set_value(EDITOR_DEF("editors/3d/default_z_near", 0.05)); settings_zfar->set_value(EDITOR_DEF("editors/3d/default_z_far", 1500.0)); @@ -6048,7 +5739,6 @@ void Node3DEditor::clear() { } for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { - viewports[i]->view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(Node3DEditorViewport::VIEW_AUDIO_LISTENER), i == 0); viewports[i]->viewport->set_as_audio_listener(i == 0); } @@ -6057,7 +5747,6 @@ void Node3DEditor::clear() { } Node3DEditor::Node3DEditor(EditorNode *p_editor) { - gizmo.visible = true; gizmo.scale = 1.0; @@ -6270,7 +5959,6 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { shader_split->add_child(viewport_base); viewport_base->set_v_size_flags(SIZE_EXPAND_FILL); for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { - viewports[i] = memnew(Node3DEditorViewport(this, editor, i)); viewports[i]->connect("toggle_maximize_view", callable_mp(this, &Node3DEditor::_toggle_maximize_view)); viewports[i]->connect("clicked", callable_mp(this, &Node3DEditor::_update_camera_override_viewport)); @@ -6355,7 +6043,6 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { xform_vbc->add_child(xform_hbc); for (int i = 0; i < 3; i++) { - xform_translate[i] = memnew(LineEdit); xform_translate[i]->set_h_size_flags(SIZE_EXPAND_FILL); xform_hbc->add_child(xform_translate[i]); @@ -6420,25 +6107,20 @@ Node3DEditor::~Node3DEditor() { } void Node3DEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { - spatial_editor->show(); spatial_editor->set_process(true); } else { - spatial_editor->hide(); spatial_editor->set_process(false); } } void Node3DEditorPlugin::edit(Object *p_object) { - spatial_editor->edit(Object::cast_to(p_object)); } bool Node3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Node3D"); } @@ -6447,12 +6129,10 @@ Dictionary Node3DEditorPlugin::get_state() const { } void Node3DEditorPlugin::set_state(const Dictionary &p_state) { - spatial_editor->set_state(p_state); } void Node3DEditor::snap_cursor_to_plane(const Plane &p_plane) { - //cursor.pos=p_plane.project(cursor.pos); } @@ -6499,17 +6179,14 @@ float Node3DEditor::get_scale_snap() const { } void Node3DEditorPlugin::_bind_methods() { - ClassDB::bind_method("snap_cursor_to_plane", &Node3DEditorPlugin::snap_cursor_to_plane); } void Node3DEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) { - spatial_editor->snap_cursor_to_plane(p_plane); } struct _GizmoPluginPriorityComparator { - bool operator()(const Ref &p_a, const Ref &p_b) const { if (p_a->get_priority() == p_b->get_priority()) { return p_a->get_name() < p_b->get_name(); @@ -6519,7 +6196,6 @@ struct _GizmoPluginPriorityComparator { }; struct _GizmoPluginNameComparator { - bool operator()(const Ref &p_a, const Ref &p_b) const { return p_a->get_name() < p_b->get_name(); } @@ -6545,7 +6221,6 @@ void Node3DEditor::remove_gizmo_plugin(Ref p_plugin) { } Node3DEditorPlugin::Node3DEditorPlugin(EditorNode *p_node) { - editor = p_node; spatial_editor = memnew(Node3DEditor(p_node)); spatial_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); @@ -6559,7 +6234,6 @@ Node3DEditorPlugin::~Node3DEditorPlugin() { } void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) { - Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6)); Vector> mats; @@ -6601,7 +6275,6 @@ void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color } void EditorNode3DGizmoPlugin::create_icon_material(const String &p_name, const Ref &p_texture, bool p_on_top, const Color &p_albedo) { - Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6)); Vector> icons; @@ -6703,7 +6376,6 @@ int EditorNode3DGizmoPlugin::get_priority() const { } Ref EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("get_gizmo")) { return get_script_instance()->call("get_gizmo", p_spatial); } @@ -6764,7 +6436,6 @@ bool EditorNode3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { } Ref EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("create_gizmo")) { return get_script_instance()->call("create_gizmo", p_spatial); } -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- editor/plugins/node_3d_editor_plugin.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'editor/plugins/node_3d_editor_plugin.cpp') diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index fa600ad744..bfdd148e3f 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -395,9 +395,11 @@ int Node3DEditorViewport::get_selected_count() const { float Node3DEditorViewport::get_znear() const { return CLAMP(spatial_editor->get_znear(), MIN_Z, MAX_Z); } + float Node3DEditorViewport::get_zfar() const { return CLAMP(spatial_editor->get_zfar(), MIN_Z, MAX_Z); } + float Node3DEditorViewport::get_fov() const { return CLAMP(spatial_editor->get_fov(), MIN_FOV, MAX_FOV); } @@ -970,9 +972,11 @@ void Node3DEditorViewport::_surface_focus_enter() { void Node3DEditorViewport::_surface_focus_exit() { view_menu->set_disable_shortcuts(true); } + bool Node3DEditorViewport ::_is_node_locked(const Node *p_node) { return p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_"); } + void Node3DEditorViewport::_list_select(Ref b) { _find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift()); @@ -3011,6 +3015,7 @@ void Node3DEditorViewport::_finish_gizmo_instances() { RS::get_singleton()->free(scale_plane_gizmo_instance[i]); } } + void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { ERR_FAIL_COND(p_activate && !preview); ERR_FAIL_COND(!p_activate && !previewing); @@ -4408,6 +4413,7 @@ Dictionary Node3DEditor::get_state() const { return d; } + void Node3DEditor::set_state(const Dictionary &p_state) { Dictionary d = p_state; @@ -5511,6 +5517,7 @@ void Node3DEditor::_unhandled_key_input(Ref p_event) { snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); } + void Node3DEditor::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon("ToolSelect", "EditorIcons")); @@ -6116,6 +6123,7 @@ void Node3DEditorPlugin::make_visible(bool p_visible) { spatial_editor->set_process(false); } } + void Node3DEditorPlugin::edit(Object *p_object) { spatial_editor->edit(Object::cast_to(p_object)); } -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- editor/plugins/node_3d_editor_plugin.cpp | 583 ++++++++++++++++++++----------- 1 file changed, 377 insertions(+), 206 deletions(-) (limited to 'editor/plugins/node_3d_editor_plugin.cpp') diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index bfdd148e3f..3c12022854 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -364,10 +364,11 @@ Transform Node3DEditorViewport::to_camera_transform(const Cursor &p_cursor) cons camera_transform.basis.rotate(Vector3(1, 0, 0), -p_cursor.x_rot); camera_transform.basis.rotate(Vector3(0, 1, 0), -p_cursor.y_rot); - if (orthogonal) + if (orthogonal) { camera_transform.translate(0, 0, (get_zfar() - get_znear()) / 2.0); - else + } else { camera_transform.translate(0, 0, p_cursor.distance); + } return camera_transform; } @@ -379,12 +380,14 @@ int Node3DEditorViewport::get_selected_count() const { for (Map::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->key()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } count++; } @@ -433,13 +436,15 @@ void Node3DEditorViewport::_clear_selected() { } void Node3DEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_allow_locked) { - if (clicked.is_null()) + if (clicked.is_null()) { return; + } Node *node = Object::cast_to(ObjectDB::get_instance(clicked)); Node3D *selected = Object::cast_to(node); - if (!selected) + if (!selected) { return; + } if (!p_allow_locked) { // Replace the node by the group if grouped @@ -470,14 +475,16 @@ void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { } if (p_single) { - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { editor->call("edit_node", p_node); + } } } ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle, bool p_alt_select) { - if (r_gizmo_handle) + if (r_gizmo_handle) { *r_gizmo_handle = -1; + } Vector3 ray = _get_ray(p_pos); Vector3 pos = _get_ray_pos(p_pos); @@ -495,8 +502,9 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b for (int i = 0; i < instances.size(); i++) { Node3D *spat = Object::cast_to(ObjectDB::get_instance(instances[i])); - if (!spat) + if (!spat) { continue; + } Ref seg = spat->get_gizmo(); @@ -511,13 +519,15 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b int handle = -1; bool inters = seg->intersect_ray(camera, shrinked_pos, point, normal, &handle, p_alt_select); - if (!inters) + if (!inters) { continue; + } float dist = pos.distance_to(point); - if (dist < 0) + if (dist < 0) { continue; + } if (dist < closest_dist) { item = Object::cast_to(spat); @@ -531,12 +541,14 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b } } - if (!item) + if (!item) { return ObjectID(); + } if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle >= 0)) { - if (r_gizmo_handle) + if (r_gizmo_handle) { *r_gizmo_handle = selected_handle; + } } return closest; @@ -554,16 +566,19 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu for (int i = 0; i < instances.size(); i++) { Node3D *spat = Object::cast_to(ObjectDB::get_instance(instances[i])); - if (!spat) + if (!spat) { continue; + } Ref seg = spat->get_gizmo(); - if (!seg.is_valid()) + if (!seg.is_valid()) { continue; + } - if (found_gizmos.has(seg)) + if (found_gizmos.has(seg)) { continue; + } found_gizmos.insert(seg); Vector3 point; @@ -572,16 +587,19 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu int handle = -1; bool inters = seg->intersect_ray(camera, p_pos, point, normal, nullptr, p_alt_select); - if (!inters) + if (!inters) { continue; + } float dist = pos.distance_to(point); - if (dist < 0) + if (dist < 0) { continue; + } - if (editor_selection->is_selected(spat)) + if (editor_selection->is_selected(spat)) { r_includes_current = true; + } _RayResult res; res.item = spat; @@ -590,8 +608,9 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu results.push_back(res); } - if (results.empty()) + if (results.empty()) { return; + } results.sort(); } @@ -615,8 +634,9 @@ Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) { } void Node3DEditorViewport::_select_region() { - if (cursor.region_begin == cursor.region_end) + if (cursor.region_begin == cursor.region_end) { return; //nothing really + } float z_offset = MAX(0.0, 5.0 - get_znear()); @@ -668,8 +688,9 @@ void Node3DEditorViewport::_select_region() { for (int i = 0; i < instances.size(); i++) { Node3D *sp = Object::cast_to(ObjectDB::get_instance(instances[i])); - if (!sp || _is_node_locked(sp)) + if (!sp || _is_node_locked(sp)) { continue; + } Node *item = Object::cast_to(sp); while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) { @@ -689,16 +710,19 @@ void Node3DEditorViewport::_select_region() { item = sel; } - if (selected.find(item) != -1) + if (selected.find(item) != -1) { continue; + } - if (_is_node_locked(item)) + if (_is_node_locked(item)) { continue; + } Ref seg = sp->get_gizmo(); - if (!seg.is_valid()) + if (!seg.is_valid()) { continue; + } if (seg->intersect_frustum(camera, frustum)) { selected.push_back(item); @@ -718,10 +742,11 @@ void Node3DEditorViewport::_update_name() { view_mode += " [auto]"; } - if (name != "") + if (name != "") { view_menu->set_text(name + " " + view_mode); - else + } else { view_menu->set_text(view_mode); + } view_menu->set_size(Vector2(0, 0)); // resets the button size } @@ -737,12 +762,14 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } se->original = se->sp->get_global_gizmo_transform(); se->original_local = se->sp->get_local_gizmo_transform(); @@ -766,23 +793,29 @@ static int _get_key_modifier_setting(const String &p_property) { } static int _get_key_modifier(Ref e) { - if (e->get_shift()) + if (e->get_shift()) { return KEY_SHIFT; - if (e->get_alt()) + } + if (e->get_alt()) { return KEY_ALT; - if (e->get_control()) + } + if (e->get_control()) { return KEY_CONTROL; - if (e->get_metakey()) + } + if (e->get_metakey()) { return KEY_META; + } return 0; } bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only) { - if (!spatial_editor->is_gizmo_visible()) + if (!spatial_editor->is_gizmo_visible()) { return false; + } if (get_selected_count() == 0) { - if (p_highlight_only) + if (p_highlight_only) { spatial_editor->select_gizmo_highlight_axis(-1); + } return false; } @@ -861,8 +894,9 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high for (int i = 0; i < 3; i++) { Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); Vector3 r; - if (!plane.intersects_ray(ray_pos, ray, &r)) + if (!plane.intersects_ray(ray_pos, ray, &r)) { continue; + } float dist = r.distance_to(gt.origin); @@ -950,15 +984,17 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high } } - if (p_highlight_only) + if (p_highlight_only) { spatial_editor->select_gizmo_highlight_axis(-1); + } return false; } void Node3DEditorViewport::_surface_mouse_enter() { - if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) + if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) { surface->grab_focus(); + } } void Node3DEditorViewport::_surface_mouse_exit() { @@ -1047,16 +1083,18 @@ void Node3DEditorViewport::_list_select(Ref b) { } void Node3DEditorViewport::_sinput(const Ref &p_event) { - if (previewing) + if (previewing) { return; //do NONE + } { EditorNode *en = editor; EditorPluginList *force_input_forwarding_list = en->get_editor_plugins_force_input_forwarding(); if (!force_input_forwarding_list->empty()) { bool discard = force_input_forwarding_list->forward_spatial_gui_input(camera, p_event, true); - if (discard) + if (discard) { return; + } } } { @@ -1064,8 +1102,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { EditorPluginList *over_plugin_list = en->get_editor_plugins_over(); if (!over_plugin_list->empty()) { bool discard = over_plugin_list->forward_spatial_gui_input(camera, p_event, false); - if (discard) + if (discard) { return; + } } } @@ -1077,17 +1116,19 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { float zoom_factor = 1 + (ZOOM_MULTIPLIER - 1) * b->get_factor(); switch (b->get_button_index()) { case BUTTON_WHEEL_UP: { - if (is_freelook_active()) + if (is_freelook_active()) { scale_freelook_speed(zoom_factor); - else + } else { scale_cursor_distance(1.0 / zoom_factor); + } } break; case BUTTON_WHEEL_DOWN: { - if (is_freelook_active()) + if (is_freelook_active()) { scale_freelook_speed(1.0 / zoom_factor); - else + } else { scale_cursor_distance(zoom_factor); + } } break; case BUTTON_RIGHT: { @@ -1101,8 +1142,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { if (_edit.mode == TRANSFORM_NONE && b->is_pressed()) { if (b->get_alt()) { - if (nav_scheme == NAVIGATION_MAYA) + if (nav_scheme == NAVIGATION_MAYA) { break; + } _list_select(b); return; @@ -1117,12 +1159,14 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } sp->set_global_transform(se->original); } @@ -1220,16 +1264,18 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } } - if (_gizmo_select(_edit.mouse_pos)) + if (_gizmo_select(_edit.mouse_pos)) { break; + } clicked = ObjectID(); clicked_includes_current = false; if ((spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT && b->get_control()) || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE) { /* HANDLE ROTATION */ - if (get_selected_count() == 0) + if (get_selected_count() == 0) { break; //bye + } //handle rotate _edit.mode = TRANSFORM_ROTATE; _compute_edit(b->get_position()); @@ -1237,8 +1283,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_MOVE) { - if (get_selected_count() == 0) + if (get_selected_count() == 0) { break; //bye + } //handle translate _edit.mode = TRANSFORM_TRANSLATE; _compute_edit(b->get_position()); @@ -1246,8 +1293,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SCALE) { - if (get_selected_count() == 0) + if (get_selected_count() == 0) { break; //bye + } //handle scale _edit.mode = TRANSFORM_SCALE; _compute_edit(b->get_position()); @@ -1265,8 +1313,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { clicked_wants_append = b->get_shift(); if (clicked.is_null()) { - if (!clicked_wants_append) + if (!clicked_wants_append) { _clear_selected(); + } //default to regionselect cursor.region_select = true; @@ -1301,8 +1350,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (cursor.region_select) { - if (!clicked_wants_append) + if (!clicked_wants_append) { _clear_selected(); + } _select_region(); cursor.region_select = false; @@ -1317,12 +1367,14 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } undo_redo->add_do_method(sp, "set_global_transform", sp->get_global_gizmo_transform()); undo_redo->add_undo_method(sp, "set_global_transform", se->original); @@ -1360,8 +1412,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { if (selected_handle != spatial_editor->get_over_gizmo_handle()) { spatial_editor->set_over_gizmo_handle(selected_handle); spatial_editor->get_selected()->update_gizmo(); - if (selected_handle != -1) + if (selected_handle != -1) { spatial_editor->select_gizmo_highlight_axis(-1); + } } } } @@ -1407,8 +1460,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { return; } - if (_edit.mode == TRANSFORM_NONE) + if (_edit.mode == TRANSFORM_NONE) { return; + } Vector3 ray_pos = _get_ray_pos(m->get_position()); Vector3 ray = _get_ray(m->get_position()); @@ -1456,12 +1510,14 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } Vector3 intersection; - if (!plane.intersects_ray(ray_pos, ray, &intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) { break; + } Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) { break; + } Vector3 motion = intersection - click; if (_edit.plane != TRANSFORM_VIEW) { @@ -1478,8 +1534,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } else { float center_click_dist = click.distance_to(_edit.center); float center_inters_dist = intersection.distance_to(_edit.center); - if (center_click_dist == 0) + if (center_click_dist == 0) { break; + } float scale = center_inters_dist - center_click_dist; motion = Vector3(scale, scale, scale); @@ -1592,12 +1649,14 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } Vector3 intersection; - if (!plane.intersects_ray(ray_pos, ray, &intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) { break; + } Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) { break; + } Vector3 motion = intersection - click; if (_edit.plane != TRANSFORM_VIEW) { @@ -1689,12 +1748,14 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } Vector3 intersection; - if (!plane.intersects_ray(ray_pos, ray, &intersection)) + if (!plane.intersects_ray(ray_pos, ray, &intersection)) { break; + } Vector3 click; - if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) + if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) { break; + } Vector3 y_axis = (click - _edit.center).normalized(); Vector3 x_axis = plane.normal.cross(y_axis).normalized(); @@ -1715,12 +1776,14 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } if (sp->has_meta("_edit_lock_")) { continue; @@ -1783,8 +1846,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } } else if (nav_scheme == NAVIGATION_MAYA) { - if (m->get_alt()) + if (m->get_alt()) { nav_mode = NAVIGATION_PAN; + } } } else if (EditorSettings::get_singleton()->get("editors/3d/navigation/emulate_3_button_mouse")) { @@ -1831,10 +1895,11 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Ref magnify_gesture = p_event; if (magnify_gesture.is_valid()) { - if (is_freelook_active()) + if (is_freelook_active()) { scale_freelook_speed(magnify_gesture->get_factor()); - else + } else { scale_cursor_distance(1.0 / magnify_gesture->get_factor()); + } } Ref pan_gesture = p_event; @@ -1855,8 +1920,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } } else if (nav_scheme == NAVIGATION_MAYA) { - if (pan_gesture->get_alt()) + if (pan_gesture->get_alt()) { nav_mode = NAVIGATION_PAN; + } } switch (nav_mode) { @@ -1888,8 +1954,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { Ref k = p_event; if (k.is_valid()) { - if (!k->is_pressed()) + if (!k->is_pressed()) { return; + } if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) { if (_edit.mode != TRANSFORM_NONE) { @@ -1932,8 +1999,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { _menu_option(VIEW_ALIGN_ROTATION_WITH_VIEW); } if (ED_IS_SHORTCUT("spatial_editor/insert_anim_key", p_event)) { - if (!get_selected_count() || _edit.mode != TRANSFORM_NONE) + if (!get_selected_count() || _edit.mode != TRANSFORM_NONE) { return; + } if (!AnimationPlayerEditor::singleton->get_track_editor()->has_keying()) { set_message(TTR("Keying is disabled (no key inserted).")); @@ -1944,8 +2012,9 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } spatial_editor->emit_signal("transform_key_request", sp, "", sp->get_transform()); } @@ -1962,15 +2031,17 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { } if (k->get_keycode() == KEY_SPACE) { - if (!k->is_pressed()) + if (!k->is_pressed()) { emit_signal("toggle_maximize_view", this); + } } } // freelook uses most of the useful shortcuts, like save, so its ok // to consider freelook active as end of the line for future events. - if (freelook_active) + if (freelook_active) { accept_event(); + } } void Node3DEditorViewport::_nav_pan(Ref p_event, const Vector2 &p_relative) { @@ -1978,8 +2049,9 @@ void Node3DEditorViewport::_nav_pan(Ref p_event, const real_t pan_speed = 1 / 150.0; int pan_speed_modifier = 10; - if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) + if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) { pan_speed *= pan_speed_modifier; + } Transform camera_transform; @@ -1997,20 +2069,23 @@ void Node3DEditorViewport::_nav_zoom(Ref p_event, const real_t zoom_speed = 1 / 80.0; int zoom_speed_modifier = 10; - if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) + if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) { zoom_speed *= zoom_speed_modifier; + } NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/navigation/zoom_style").operator int(); if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) { - if (p_relative.x > 0) + if (p_relative.x > 0) { scale_cursor_distance(1 - p_relative.x * zoom_speed); - else if (p_relative.x < 0) + } else if (p_relative.x < 0) { scale_cursor_distance(1.0 / (1 + p_relative.x * zoom_speed)); + } } else { - if (p_relative.y > 0) + if (p_relative.y > 0) { scale_cursor_distance(1 + p_relative.y * zoom_speed); - else if (p_relative.y < 0) + } else if (p_relative.y < 0) { scale_cursor_distance(1.0 / (1 - p_relative.y * zoom_speed)); + } } } @@ -2034,10 +2109,12 @@ void Node3DEditorViewport::_nav_orbit(Ref p_event, cons cursor.x_rot += p_relative.y * radians_per_pixel; } cursor.y_rot += p_relative.x * radians_per_pixel; - if (cursor.x_rot > Math_PI / 2.0) + if (cursor.x_rot > Math_PI / 2.0) { cursor.x_rot = Math_PI / 2.0; - if (cursor.x_rot < -Math_PI / 2.0) + } + if (cursor.x_rot < -Math_PI / 2.0) { cursor.x_rot = -Math_PI / 2.0; + } name = ""; _update_name(); } @@ -2065,10 +2142,12 @@ void Node3DEditorViewport::_nav_look(Ref p_event, const cursor.x_rot += p_relative.y * radians_per_pixel; } cursor.y_rot += p_relative.x * radians_per_pixel; - if (cursor.x_rot > Math_PI / 2.0) + if (cursor.x_rot > Math_PI / 2.0) { cursor.x_rot = Math_PI / 2.0; - if (cursor.x_rot < -Math_PI / 2.0) + } + if (cursor.x_rot < -Math_PI / 2.0) { cursor.x_rot = -Math_PI / 2.0; + } // Look is like the opposite of Orbit: the focus point rotates around the camera Transform camera_transform = to_camera_transform(cursor); @@ -2114,13 +2193,15 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) { void Node3DEditorViewport::scale_cursor_distance(real_t scale) { // Prevents zero distance which would short-circuit any scaling - if (cursor.distance < ZOOM_MIN_DISTANCE) + if (cursor.distance < ZOOM_MIN_DISTANCE) { cursor.distance = ZOOM_MIN_DISTANCE; + } cursor.distance *= scale; - if (cursor.distance < ZOOM_MIN_DISTANCE) + if (cursor.distance < ZOOM_MIN_DISTANCE) { cursor.distance = ZOOM_MIN_DISTANCE; + } zoom_indicator_delay = ZOOM_INDICATOR_DELAY_S; surface->update(); @@ -2128,13 +2209,15 @@ void Node3DEditorViewport::scale_cursor_distance(real_t scale) { void Node3DEditorViewport::scale_freelook_speed(real_t scale) { // Prevents zero distance which would short-circuit any scaling - if (freelook_speed < FREELOOK_MIN_SPEED) + if (freelook_speed < FREELOOK_MIN_SPEED) { freelook_speed = FREELOOK_MIN_SPEED; + } freelook_speed *= scale; - if (freelook_speed < FREELOOK_MIN_SPEED) + if (freelook_speed < FREELOOK_MIN_SPEED) { freelook_speed = FREELOOK_MIN_SPEED; + } zoom_indicator_delay = ZOOM_INDICATOR_DELAY_S; surface->update(); @@ -2304,18 +2387,21 @@ void Node3DEditorViewport::_notification(int p_what) { for (Map::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->key()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } Transform t = sp->get_global_gizmo_transform(); exist = true; - if (se->last_xform == t && !se->last_xform_dirty) + if (se->last_xform == t && !se->last_xform_dirty) { continue; + } changed = true; se->last_xform_dirty = false; se->last_xform = t; @@ -2345,8 +2431,9 @@ void Node3DEditorViewport::_notification(int p_what) { } message_time -= get_physics_process_delta_time(); - if (message_time < 0) + if (message_time < 0) { surface->update(); + } } //update shadow atlas if changed @@ -2609,8 +2696,9 @@ void Node3DEditorViewport::_draw() { // There is no real maximum speed so that factor can become negative, // Let's make it look asymptotic instead (will decrease slower and slower). - if (logscale_t < 0.25) + if (logscale_t < 0.25) { logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0); + } draw_indicator_bar(*surface, 1.0 - logscale_t, get_theme_icon("ViewportSpeed", "EditorIcons")); } @@ -2627,8 +2715,9 @@ void Node3DEditorViewport::_draw() { // There is no real maximum distance so that factor can become negative, // Let's make it look asymptotic instead (will decrease slower and slower). - if (logscale_t < 0.25) + if (logscale_t < 0.25) { logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0); + } draw_indicator_bar(*surface, logscale_t, get_theme_icon("ViewportZoom", "EditorIcons")); } @@ -2702,8 +2791,9 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ALIGN_TRANSFORM_WITH_VIEW: { - if (!get_selected_count()) + if (!get_selected_count()) { break; + } Transform camera_transform = camera->get_global_transform(); @@ -2713,12 +2803,14 @@ void Node3DEditorViewport::_menu_option(int p_option) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } Transform xform; if (orthogonal) { @@ -2736,8 +2828,9 @@ void Node3DEditorViewport::_menu_option(int p_option) { } break; case VIEW_ALIGN_ROTATION_WITH_VIEW: { - if (!get_selected_count()) + if (!get_selected_count()) { break; + } Transform camera_transform = camera->get_global_transform(); @@ -2746,12 +2839,14 @@ void Node3DEditorViewport::_menu_option(int p_option) { undo_redo->create_action(TTR("Align Rotation with View")); for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } undo_redo->add_do_method(sp, "set_rotation", camera_transform.basis.get_rotation()); undo_redo->add_undo_method(sp, "set_rotation", sp->get_rotation()); @@ -2839,18 +2934,20 @@ void Node3DEditorViewport::_menu_option(int p_option) { if (current) { preview_camera->hide(); } else { - if (previewing != nullptr) + if (previewing != nullptr) { preview_camera->show(); + } } } break; case VIEW_GIZMOS: { int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); bool current = view_menu->get_popup()->is_item_checked(idx); current = !current; - if (current) + if (current) { camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER)); - else + } else { camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + index)) | (1 << GIZMO_GRID_LAYER)); + } view_menu->get_popup()->set_item_checked(idx, current); } break; @@ -3026,8 +3123,9 @@ void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { previewing->disconnect("tree_exiting", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); previewing = nullptr; RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore - if (!preview) + if (!preview) { preview_camera->hide(); + } view_menu->set_disabled(false); surface->update(); @@ -3043,8 +3141,9 @@ void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { void Node3DEditorViewport::_toggle_cinema_preview(bool p_activate) { previewing_cinema = p_activate; if (!previewing_cinema) { - if (previewing != nullptr) + if (previewing != nullptr) { previewing->disconnect("tree_exited", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene)); + } previewing = nullptr; RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore @@ -3060,8 +3159,9 @@ void Node3DEditorViewport::_toggle_cinema_preview(bool p_activate) { } void Node3DEditorViewport::_selection_result_pressed(int p_result) { - if (selection_results.size() <= p_result) + if (selection_results.size() <= p_result) { return; + } clicked = selection_results[p_result].item->get_instance_id(); @@ -3080,13 +3180,15 @@ void Node3DEditorViewport::_selection_menu_hide() { void Node3DEditorViewport::set_can_preview(Camera3D *p_preview) { preview = p_preview; - if (!preview_camera->is_pressed() && !previewing_cinema) + if (!preview_camera->is_pressed() && !previewing_cinema) { preview_camera->set_visible(p_preview); + } } void Node3DEditorViewport::update_transform_gizmo_view() { - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } Transform xform = spatial_editor->get_gizmo_transform(); @@ -3110,8 +3212,9 @@ void Node3DEditorViewport::update_transform_gizmo_view() { float d0 = camera->unproject_position(camera_xform.origin + camz * gizmo_d).y; float d1 = camera->unproject_position(camera_xform.origin + camz * gizmo_d + camy).y; float dd = Math::abs(d0 - d1); - if (dd == 0) + if (dd == 0) { dd = 0.0001; + } float gizmo_size = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_size"); // At low viewport heights, multiply the gizmo scale based on the viewport height. @@ -3140,22 +3243,27 @@ void Node3DEditorViewport::update_transform_gizmo_view() { } void Node3DEditorViewport::set_state(const Dictionary &p_state) { - if (p_state.has("position")) + if (p_state.has("position")) { cursor.pos = p_state["position"]; - if (p_state.has("x_rotation")) + } + if (p_state.has("x_rotation")) { cursor.x_rot = p_state["x_rotation"]; - if (p_state.has("y_rotation")) + } + if (p_state.has("y_rotation")) { cursor.y_rot = p_state["y_rotation"]; - if (p_state.has("distance")) + } + if (p_state.has("distance")) { cursor.distance = p_state["distance"]; + } if (p_state.has("use_orthogonal")) { bool orth = p_state["use_orthogonal"]; - if (orth) + if (orth) { _menu_option(VIEW_ORTHOGONAL); - else + } else { _menu_option(VIEW_PERSPECTIVE); + } } if (p_state.has("view_name")) { name = p_state["view_name"]; @@ -3173,8 +3281,9 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { int display = p_state["display_mode"]; int idx = view_menu->get_popup()->get_item_index(display); - if (!view_menu->get_popup()->is_item_checked(idx)) + if (!view_menu->get_popup()->is_item_checked(idx)) { _menu_option(display); + } } if (p_state.has("lock_rotation")) { lock_rotation = p_state["lock_rotation"]; @@ -3185,8 +3294,9 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { if (p_state.has("use_environment")) { bool env = p_state["use_environment"]; - if (env != camera->get_environment().is_valid()) + if (env != camera->get_environment().is_valid()) { _menu_option(VIEW_ENVIRONMENT); + } } if (p_state.has("listener")) { bool listener = p_state["listener"]; @@ -3206,22 +3316,25 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { bool gizmos = p_state["gizmos"]; int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); - if (view_menu->get_popup()->is_item_checked(idx) != gizmos) + if (view_menu->get_popup()->is_item_checked(idx) != gizmos) { _menu_option(VIEW_GIZMOS); + } } if (p_state.has("information")) { bool information = p_state["information"]; int idx = view_menu->get_popup()->get_item_index(VIEW_INFORMATION); - if (view_menu->get_popup()->is_item_checked(idx) != information) + if (view_menu->get_popup()->is_item_checked(idx) != information) { _menu_option(VIEW_INFORMATION); + } } if (p_state.has("frame_time")) { bool fps = p_state["frame_time"]; int idx = view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME); - if (view_menu->get_popup()->is_item_checked(idx) != fps) + if (view_menu->get_popup()->is_item_checked(idx) != fps) { _menu_option(VIEW_FRAME_TIME); + } } if (p_state.has("half_res")) { bool half_res = p_state["half_res"]; @@ -3265,14 +3378,15 @@ Dictionary Node3DEditorViewport::get_state() const { d["view_name"] = name; d["auto_orthogonal"] = auto_orthogonal; d["auto_orthogonal_enabled"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL)); - if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL))) + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL))) { d["display_mode"] = VIEW_DISPLAY_NORMAL; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME))) { d["display_mode"] = VIEW_DISPLAY_WIREFRAME; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW))) { d["display_mode"] = VIEW_DISPLAY_OVERDRAW; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS))) { d["display_mode"] = VIEW_DISPLAY_SHADELESS; + } d["listener"] = viewport->is_audio_listener(); d["doppler"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUDIO_DOPPLER)); d["gizmos"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS)); @@ -3280,10 +3394,12 @@ Dictionary Node3DEditorViewport::get_state() const { d["frame_time"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME)); d["half_res"] = subviewport_container->get_stretch_shrink() > 1; d["cinematic_preview"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_CINEMATIC_PREVIEW)); - if (previewing) + if (previewing) { d["previewing"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing); - if (lock_rotation) + } + if (lock_rotation) { d["lock_rotation"] = lock_rotation; + } return d; } @@ -3315,8 +3431,9 @@ void Node3DEditorViewport::reset() { } void Node3DEditorViewport::focus_selection() { - if (!get_selected_count()) + if (!get_selected_count()) { return; + } Vector3 center; int count = 0; @@ -3325,12 +3442,14 @@ void Node3DEditorViewport::focus_selection() { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } center += sp->get_global_gizmo_transform().origin; count++; @@ -3366,8 +3485,9 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const for (int i = 0; i < instances.size(); i++) { MeshInstance3D *mesh_instance = Object::cast_to(ObjectDB::get_instance(instances[i])); - if (!mesh_instance) + if (!mesh_instance) { continue; + } Ref seg = mesh_instance->get_gizmo(); @@ -3381,13 +3501,15 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const Vector3 hit_normal; bool inters = seg->intersect_ray(camera, p_pos, hit_point, hit_normal, nullptr, false); - if (!inters) + if (!inters) { continue; + } float dist = world_pos.distance_to(hit_point); - if (dist < 0) + if (dist < 0) { continue; + } if (dist < closest_dist) { closest_dist = dist; @@ -3397,10 +3519,11 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const } Vector3 offset = Vector3(); for (int i = 0; i < 3; i++) { - if (normal[i] > 0.0) + if (normal[i] > 0.0) { offset[i] = (preview_bounds->get_size()[i] - (preview_bounds->get_size()[i] + preview_bounds->get_position()[i])); - else if (normal[i] < 0.0) + } else if (normal[i] < 0.0) { offset[i] = -(preview_bounds->get_size()[i] + preview_bounds->get_position()[i]); + } } return point + offset; } @@ -3540,8 +3663,9 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po Transform global_transform; Node3D *parent_spatial = Object::cast_to(parent); - if (parent_spatial) + if (parent_spatial) { global_transform = parent_spatial->get_global_gizmo_transform(); + } global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point)); @@ -3643,8 +3767,9 @@ bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant } void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (!can_drop_data_fw(p_point, p_data, p_from)) + if (!can_drop_data_fw(p_point, p_data, p_from)) { return; + } bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT); @@ -4150,10 +4275,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_2_VIEWPORTS: { for (int i = 0; i < 4; i++) { - if (i == 1 || i == 3) + if (i == 1 || i == 3) { viewports[i]->hide(); - else + } else { viewports[i]->show(); + } } fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); @@ -4162,10 +4288,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_2_VIEWPORTS_ALT: { for (int i = 0; i < 4; i++) { - if (i == 1 || i == 3) + if (i == 1 || i == 3) { viewports[i]->hide(); - else + } else { viewports[i]->show(); + } } fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size.height))); fit_child_in_rect(viewports[2], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); @@ -4173,10 +4300,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_3_VIEWPORTS: { for (int i = 0; i < 4; i++) { - if (i == 1) + if (i == 1) { viewports[i]->hide(); - else + } else { viewports[i]->show(); + } } fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); @@ -4186,10 +4314,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) { } break; case VIEW_USE_3_VIEWPORTS_ALT: { for (int i = 0; i < 4; i++) { - if (i == 1) + if (i == 1) { viewports[i]->hide(); - else + } else { viewports[i]->show(); + } } fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); @@ -4242,8 +4371,9 @@ Node3DEditorViewportContainer::Node3DEditorViewportContainer() { Node3DEditor *Node3DEditor::singleton = nullptr; Node3DEditorSelectedItem::~Node3DEditorSelectedItem() { - if (sbox_instance.is_valid()) + if (sbox_instance.is_valid()) { RenderingServer::get_singleton()->free(sbox_instance); + } } void Node3DEditor::select_gizmo_highlight_axis(int p_axis) { @@ -4266,12 +4396,14 @@ void Node3DEditor::update_transform_gizmo() { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } Transform xf = se->sp->get_global_gizmo_transform(); @@ -4318,8 +4450,9 @@ void Node3DEditor::update_all_gizmos(Node *p_node) { Object *Node3DEditor::_get_editor_data(Object *p_what) { Node3D *sp = Object::cast_to(p_what); - if (!sp) + if (!sp) { return nullptr; + } Node3DEditorSelectedItem *si = memnew(Node3DEditorSelectedItem); @@ -4373,18 +4506,19 @@ Dictionary Node3DEditor::get_state() const { d["local_coords"] = tool_option_button[TOOL_OPT_LOCAL_COORDS]->is_pressed(); int vc = 0; - if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) { vc = 1; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) { vc = 2; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) { vc = 3; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) { vc = 4; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) { vc = 5; - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) { vc = 6; + } d["viewport_mode"] = vc; Array vpdata; @@ -4402,8 +4536,9 @@ Dictionary Node3DEditor::get_state() const { Dictionary gizmos_status; for (int i = 0; i < gizmo_plugins_by_name.size(); i++) { - if (!gizmo_plugins_by_name[i]->can_be_hidden()) + if (!gizmo_plugins_by_name[i]->can_be_hidden()) { continue; + } int state = gizmos_menu->get_item_state(gizmos_menu->get_item_index(i)); String name = gizmo_plugins_by_name[i]->get_name(); gizmos_status[name] = state; @@ -4422,14 +4557,17 @@ void Node3DEditor::set_state(const Dictionary &p_state) { tool_option_button[TOOL_OPT_USE_SNAP]->set_pressed(d["snap_enabled"]); } - if (d.has("translate_snap")) + if (d.has("translate_snap")) { snap_translate_value = d["translate_snap"]; + } - if (d.has("rotate_snap")) + if (d.has("rotate_snap")) { snap_rotate_value = d["rotate_snap"]; + } - if (d.has("scale_snap")) + if (d.has("scale_snap")) { snap_scale_value = d["scale_snap"]; + } _snap_update(); @@ -4441,18 +4579,19 @@ void Node3DEditor::set_state(const Dictionary &p_state) { if (d.has("viewport_mode")) { int vc = d["viewport_mode"]; - if (vc == 1) + if (vc == 1) { _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - else if (vc == 2) + } else if (vc == 2) { _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS); - else if (vc == 3) + } else if (vc == 3) { _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS); - else if (vc == 4) + } else if (vc == 4) { _menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS); - else if (vc == 5) + } else if (vc == 5) { _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS_ALT); - else if (vc == 6) + } else if (vc == 6) { _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS_ALT); + } } if (d.has("viewports")) { @@ -4468,12 +4607,15 @@ void Node3DEditor::set_state(const Dictionary &p_state) { } } - if (d.has("zfar")) + if (d.has("zfar")) { settings_zfar->set_value(float(d["zfar"])); - if (d.has("znear")) + } + if (d.has("znear")) { settings_znear->set_value(float(d["znear"])); - if (d.has("fov")) + } + if (d.has("fov")) { settings_fov->set_value(float(d["fov"])); + } if (d.has("show_grid")) { bool use = d["show_grid"]; @@ -4497,8 +4639,9 @@ void Node3DEditor::set_state(const Dictionary &p_state) { gizmos_status.get_key_list(&keys); for (int j = 0; j < gizmo_plugins_by_name.size(); ++j) { - if (!gizmo_plugins_by_name[j]->can_be_hidden()) + if (!gizmo_plugins_by_name[j]->can_be_hidden()) { continue; + } int state = EditorNode3DGizmoPlugin::VISIBLE; for (int i = 0; i < keys.size(); i++) { if (gizmo_plugins_by_name.write[j]->get_name() == keys[i]) { @@ -4571,19 +4714,21 @@ void Node3DEditor::_xform_dialog_action() { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *sp = Object::cast_to(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data(sp); - if (!se) + if (!se) { continue; + } bool post = xform_type->get_selected() > 0; Transform tr = sp->get_global_gizmo_transform(); - if (post) + if (post) { tr = tr * t; - else { + } else { tr.basis = t.basis * tr.basis; tr.origin += t.origin; } @@ -4659,8 +4804,9 @@ void Node3DEditor::_update_camera_override_button(bool p_game_running) { void Node3DEditor::_update_camera_override_viewport(Object *p_viewport) { Node3DEditorViewport *current_viewport = Object::cast_to(p_viewport); - if (!current_viewport) + if (!current_viewport) { return; + } EditorDebuggerNode *const debugger = EditorDebuggerNode::get_singleton(); @@ -4679,8 +4825,9 @@ void Node3DEditor::_menu_item_pressed(int p_option) { case MENU_TOOL_ROTATE: case MENU_TOOL_SCALE: case MENU_TOOL_LIST_SELECT: { - for (int i = 0; i < TOOL_MAX; i++) + for (int i = 0; i < TOOL_MAX; i++) { tool_button[i]->set_pressed(i == p_option); + } tool_mode = (ToolMode)p_option; update_transform_gizmo(); @@ -4803,11 +4950,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *spatial = Object::cast_to(E->get()); - if (!spatial || !spatial->is_visible_in_tree()) + if (!spatial || !spatial->is_visible_in_tree()) { continue; + } - if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(spatial, "set_meta", "_edit_lock_", true); undo_redo->add_undo_method(spatial, "remove_meta", "_edit_lock_"); @@ -4826,11 +4975,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *spatial = Object::cast_to(E->get()); - if (!spatial || !spatial->is_visible_in_tree()) + if (!spatial || !spatial->is_visible_in_tree()) { continue; + } - if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(spatial, "remove_meta", "_edit_lock_"); undo_redo->add_undo_method(spatial, "set_meta", "_edit_lock_", true); @@ -4849,11 +5000,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *spatial = Object::cast_to(E->get()); - if (!spatial || !spatial->is_visible_in_tree()) + if (!spatial || !spatial->is_visible_in_tree()) { continue; + } - if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(spatial, "set_meta", "_edit_group_", true); undo_redo->add_undo_method(spatial, "remove_meta", "_edit_group_"); @@ -4871,11 +5024,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) { for (List::Element *E = selection.front(); E; E = E->next()) { Node3D *spatial = Object::cast_to(E->get()); - if (!spatial || !spatial->is_visible_in_tree()) + if (!spatial || !spatial->is_visible_in_tree()) { continue; + } - if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) + if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) { continue; + } undo_redo->add_do_method(spatial, "remove_meta", "_edit_group_"); undo_redo->add_undo_method(spatial, "set_meta", "_edit_group_", true); @@ -5220,8 +5375,9 @@ void Node3DEditor::_update_gizmos_menu() { gizmos_menu->clear(); for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) { - if (!gizmo_plugins_by_name[i]->can_be_hidden()) + if (!gizmo_plugins_by_name[i]->can_be_hidden()) { continue; + } String plugin_name = gizmo_plugins_by_name[i]->get_name(); const int plugin_state = gizmo_plugins_by_name[i]->get_state(); gizmos_menu->add_multistate_item(TTR(plugin_name), 3, plugin_state, i); @@ -5242,8 +5398,9 @@ void Node3DEditor::_update_gizmos_menu() { void Node3DEditor::_update_gizmos_menu_theme() { for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) { - if (!gizmo_plugins_by_name[i]->can_be_hidden()) + if (!gizmo_plugins_by_name[i]->can_be_hidden()) { continue; + } const int plugin_state = gizmo_plugins_by_name[i]->get_state(); const int idx = gizmos_menu->get_item_index(i); switch (plugin_state) { @@ -5334,8 +5491,9 @@ void Node3DEditor::_finish_grid() { bool Node3DEditor::is_any_freelook_active() const { for (unsigned int i = 0; i < VIEWPORTS_COUNT; ++i) { - if (viewports[i]->is_freelook_active()) + if (viewports[i]->is_freelook_active()) { return true; + } } return false; } @@ -5512,8 +5670,9 @@ void Node3DEditor::snap_selected_nodes_to_floor() { } void Node3DEditor::_unhandled_key_input(Ref p_event) { - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); } @@ -5617,8 +5776,9 @@ HSplitContainer *Node3DEditor::get_palette_split() { void Node3DEditor::_request_gizmo(Object *p_obj) { Node3D *sp = Object::cast_to(p_obj); - if (!sp) + if (!sp) { return; + } if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) { Ref seg; @@ -5640,54 +5800,62 @@ void Node3DEditor::_request_gizmo(Object *p_obj) { } void Node3DEditor::_toggle_maximize_view(Object *p_viewport) { - if (!p_viewport) + if (!p_viewport) { return; + } Node3DEditorViewport *current_viewport = Object::cast_to(p_viewport); - if (!current_viewport) + if (!current_viewport) { return; + } int index = -1; bool maximized = false; for (int i = 0; i < 4; i++) { if (viewports[i] == current_viewport) { index = i; - if (current_viewport->get_global_rect() == viewport_base->get_global_rect()) + if (current_viewport->get_global_rect() == viewport_base->get_global_rect()) { maximized = true; + } break; } } - if (index == -1) + if (index == -1) { return; + } if (!maximized) { for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { - if (i == (uint32_t)index) + if (i == (uint32_t)index) { viewports[i]->set_anchors_and_margins_preset(Control::PRESET_WIDE); - else + } else { viewports[i]->hide(); + } } } else { - for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) + for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { viewports[i]->show(); + } - if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) + if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) { _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) { _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) { _menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS_ALT); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) { _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) { _menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS_ALT); - else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) + } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) { _menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS); + } } } void Node3DEditor::_node_removed(Node *p_node) { - if (p_node == selected) + if (p_node == selected) { selected = nullptr; + } } void Node3DEditor::_register_all_gizmos() { @@ -6353,8 +6521,9 @@ Ref EditorNode3DGizmoPlugin::get_material(const String &p_na ERR_FAIL_COND_V(!materials.has(p_name), Ref()); ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref()); - if (p_gizmo.is_null() || materials[p_name].size() == 1) + if (p_gizmo.is_null() || materials[p_name].size() == 1) { return materials[p_name][0]; + } int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0); @@ -6390,8 +6559,9 @@ Ref EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { Ref ref = create_gizmo(p_spatial); - if (ref.is_null()) + if (ref.is_null()) { return ref; + } ref->set_plugin(this); ref->set_spatial_node(p_spatial); @@ -6449,8 +6619,9 @@ Ref EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) } Ref ref; - if (has_gizmo(p_spatial)) + if (has_gizmo(p_spatial)) { ref.instance(); + } return ref; } -- cgit v1.2.3