diff options
author | Nils ANDRÉ-CHANG <nils@nilsand.re> | 2019-09-12 21:28:49 +0100 |
---|---|---|
committer | Nils ANDRÉ-CHANG <nils@nilsand.re> | 2019-09-26 20:36:12 +0100 |
commit | 0024dd7bb5a8a5194ed0283fc506edcd8b4a7737 (patch) | |
tree | 86316cccbf4fda58a275a7451e37fda83465bb20 /editor/plugins/spatial_editor_plugin.cpp | |
parent | cafb888361eba08297dd88b18dc71f4d418525c0 (diff) | |
parent | 24e1039eb6fe32115e8d1a62a84965e9be19a2ed (diff) |
Merge branch 'master' into tab_key
Diffstat (limited to 'editor/plugins/spatial_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 348 |
1 files changed, 180 insertions, 168 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index b475eee920..ecc631d045 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -69,19 +69,11 @@ #define FREELOOK_SPEED_MULTIPLIER 1.08 #define MIN_Z 0.01 -#define MAX_Z 10000 +#define MAX_Z 1000000.0 #define MIN_FOV 0.01 #define MAX_FOV 179 -#ifdef TOOLS_ENABLED -#define get_global_gizmo_transform get_global_gizmo_transform -#define get_local_gizmo_transform get_local_gizmo_transform -#else -#define get_global_gizmo_transform get_global_transform -#define get_local_gizmo_transform get_transform -#endif - void SpatialEditorViewport::_update_camera(float p_interp_delta) { bool is_orthogonal = camera->get_projection() == Camera::PROJECTION_ORTHOGONAL; @@ -250,15 +242,7 @@ Vector3 SpatialEditorViewport::_get_ray(const Vector2 &p_pos) const { return camera->project_ray_normal(p_pos / viewport_container->get_stretch_shrink()); } -/* -void SpatialEditorViewport::_clear_id(Spatial *p_node) { - - - editor_selection->remove_node(p_node); - -} -*/ void SpatialEditorViewport::_clear_selected() { editor_selection->clear(); @@ -645,7 +629,7 @@ bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hig Vector3 r; - if (Geometry::segment_intersects_sphere(ray_pos, ray_pos + ray * 10000.0, grabber_pos, grabber_radius, &r)) { + if (Geometry::segment_intersects_sphere(ray_pos, ray_pos + ray * MAX_Z, grabber_pos, grabber_radius, &r)) { float d = r.distance_to(ray_pos); if (d < col_d) { col_d = d; @@ -753,7 +737,7 @@ bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hig Vector3 r; - if (Geometry::segment_intersects_sphere(ray_pos, ray_pos + ray * 10000.0, grabber_pos, grabber_radius, &r)) { + if (Geometry::segment_intersects_sphere(ray_pos, ray_pos + ray * MAX_Z, grabber_pos, grabber_radius, &r)) { float d = r.distance_to(ray_pos); if (d < col_d) { col_d = d; @@ -1291,6 +1275,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 ray_pos = _get_ray_pos(m->get_position()); Vector3 ray = _get_ray(m->get_position()); + float snap = EDITOR_GET("interface/inspector/default_float_step"); + int snap_step_decimals = Math::range_step_decimals(snap); switch (_edit.mode) { @@ -1372,18 +1358,14 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { // Disable local transformation for TRANSFORM_VIEW bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); - float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { - snap = spatial_editor->get_scale_snap() / 100; - - Vector3 motion_snapped = motion; - motion_snapped.snap(Vector3(snap, snap, snap)); - set_message(TTR("Scaling: ") + motion_snapped); - - } else { - set_message(TTR("Scaling: ") + motion); } + Vector3 motion_snapped = motion; + motion_snapped.snap(Vector3(snap, snap, snap)); + // This might not be necessary anymore after issue #288 is solved (in 4.0?). + set_message(TTR("Scaling: ") + "(" + String::num(motion_snapped.x, snap_step_decimals) + ", " + + String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -1502,17 +1484,13 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { // Disable local transformation for TRANSFORM_VIEW bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); - float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { - snap = spatial_editor->get_translate_snap(); - - Vector3 motion_snapped = motion; - motion_snapped.snap(Vector3(snap, snap, snap)); - set_message(TTR("Translating: ") + motion_snapped); - } else { - set_message(TTR("Translating: ") + motion); } + Vector3 motion_snapped = motion; + motion_snapped.snap(Vector3(snap, snap, snap)); + set_message(TTR("Translating: ") + "(" + String::num(motion_snapped.x, snap_step_decimals) + ", " + + String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -1601,20 +1579,12 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { float angle = Math::atan2(x_axis.dot(intersection - _edit.center), y_axis.dot(intersection - _edit.center)); if (_edit.snap || spatial_editor->is_snap_enabled()) { - - float snap = spatial_editor->get_rotate_snap(); - - if (snap) { - angle = Math::rad2deg(angle) + snap * 0.5; //else it won't reach +180 - angle -= Math::fmod(angle, snap); - set_message(vformat(TTR("Rotating %s degrees."), rtos(angle))); - angle = Math::deg2rad(angle); - } else - set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle)))); - - } else { - set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle)))); + snap = spatial_editor->get_rotate_snap(); } + angle = Math::rad2deg(angle) + snap * 0.5; //else it won't reach +180 + angle -= Math::fmod(angle, snap); + set_message(vformat(TTR("Rotating %s degrees."), String::num(angle, snap_step_decimals))); + angle = Math::deg2rad(angle); List<Node *> &selection = editor_selection->get_selected_node_list(); @@ -1835,8 +1805,11 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { _menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL); _update_name(); } - if (ED_IS_SHORTCUT("spatial_editor/align_selection_with_view", p_event)) { - _menu_option(VIEW_ALIGN_SELECTION_WITH_VIEW); + if (ED_IS_SHORTCUT("spatial_editor/align_transform_with_view", p_event)) { + _menu_option(VIEW_ALIGN_TRANSFORM_WITH_VIEW); + } + if (ED_IS_SHORTCUT("spatial_editor/align_rotation_with_view", 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) @@ -2392,16 +2365,22 @@ void SpatialEditorViewport::_draw() { get_stylebox("Focus", "EditorStyles")->draw(surface->get_canvas_item(), r); } - RID ci = surface->get_canvas_item(); - if (cursor.region_select) { + const Rect2 selection_rect = Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin); - VisualServer::get_singleton()->canvas_item_add_rect( - ci, - Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin), - get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375)); + surface->draw_rect( + selection_rect, + get_color("box_selection_fill_color", "Editor")); + + surface->draw_rect( + selection_rect, + get_color("box_selection_stroke_color", "Editor"), + false, + Math::round(EDSCALE)); } + RID ci = surface->get_canvas_item(); + if (message_time > 0) { Ref<Font> font = get_font("font", "Label"); Point2 msgpos = Point2(5, get_size().y - 20); @@ -2562,7 +2541,7 @@ void SpatialEditorViewport::_menu_option(int p_option) { focus_selection(); } break; - case VIEW_ALIGN_SELECTION_WITH_VIEW: { + case VIEW_ALIGN_TRANSFORM_WITH_VIEW: { if (!get_selected_count()) break; @@ -2571,7 +2550,8 @@ void SpatialEditorViewport::_menu_option(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); - undo_redo->create_action(TTR("Align with View")); + undo_redo->create_action(TTR("Align Transform with View")); + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Spatial *sp = Object::cast_to<Spatial>(E->get()); @@ -2595,6 +2575,34 @@ void SpatialEditorViewport::_menu_option(int p_option) { undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_gizmo_transform()); } undo_redo->commit_action(); + focus_selection(); + + } break; + case VIEW_ALIGN_ROTATION_WITH_VIEW: { + + if (!get_selected_count()) + break; + + Transform camera_transform = camera->get_global_transform(); + + List<Node *> &selection = editor_selection->get_selected_node_list(); + + undo_redo->create_action(TTR("Align Rotation with View")); + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + + Spatial *sp = Object::cast_to<Spatial>(E->get()); + if (!sp) + continue; + + SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp); + 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()); + } + undo_redo->commit_action(); + } break; case VIEW_ENVIRONMENT: { @@ -2912,8 +2920,14 @@ void SpatialEditorViewport::update_transform_gizmo_view() { if (dd == 0) dd = 0.0001; - float gsize = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_size"); - gizmo_scale = (gsize / Math::abs(dd)) * MAX(1, EDSCALE) / viewport_container->get_stretch_shrink(); + 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. + // This prevents the gizmo from growing very large and going outside the viewport. + const int viewport_base_height = 400 * MAX(1, EDSCALE); + gizmo_scale = + (gizmo_size / Math::abs(dd)) * MAX(1, EDSCALE) * + MIN(viewport_base_height, viewport_container->get_size().height) / viewport_base_height / + viewport_container->get_stretch_shrink(); Vector3 scale = Vector3(1, 1, 1) * gizmo_scale; xform.basis.scale(scale); @@ -3535,7 +3549,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_half_resolution", TTR("Half Resolution")), VIEW_HALF_RESOLUTION); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER); - view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Doppler Enable")), VIEW_AUDIO_DOPPLER); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Enable Doppler")), VIEW_AUDIO_DOPPLER); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true); view_menu->get_popup()->add_separator(); @@ -3544,7 +3558,8 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/focus_origin"), VIEW_CENTER_TO_ORIGIN); view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/focus_selection"), VIEW_CENTER_TO_SELECTION); - view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/align_selection_with_view"), VIEW_ALIGN_SELECTION_WITH_VIEW); + view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/align_transform_with_view"), VIEW_ALIGN_TRANSFORM_WITH_VIEW); + view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/align_rotation_with_view"), VIEW_ALIGN_ROTATION_WITH_VIEW); view_menu->get_popup()->connect("id_pressed", this, "_menu_option"); view_menu->set_disable_shortcuts(true); @@ -3982,11 +3997,11 @@ void SpatialEditor::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_hl : gizmo_color[i]); - move_plane_gizmo[i]->surface_set_material(0, (i + 6) == p_axis ? gizmo_hl : plane_gizmo_color[i]); - rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_hl : gizmo_color[i]); - scale_gizmo[i]->surface_set_material(0, (i + 9) == p_axis ? gizmo_hl : gizmo_color[i]); - scale_plane_gizmo[i]->surface_set_material(0, (i + 12) == p_axis ? gizmo_hl : plane_gizmo_color[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]); + scale_gizmo[i]->surface_set_material(0, (i + 9) == p_axis ? gizmo_color_hl[i] : gizmo_color[i]); + scale_plane_gizmo[i]->surface_set_material(0, (i + 12) == p_axis ? plane_gizmo_color_hl[i] : plane_gizmo_color[i]); } } @@ -4065,6 +4080,23 @@ Object *SpatialEditor::_get_editor_data(Object *p_what) { return si; } +Color SpatialEditor::_get_axis_color(int axis) { + + switch (axis) { + case 0: + // X axis + return Color(0.96, 0.20, 0.32); + case 1: + // Y axis + return Color(0.53, 0.84, 0.01); + case 2: + // Z axis + return Color(0.16, 0.55, 0.96); + default: + return Color(0, 0, 0); + } +} + void SpatialEditor::_generate_selection_box() { AABB aabb(Vector3(), Vector3(1, 1, 1)); @@ -4078,11 +4110,6 @@ void SpatialEditor::_generate_selection_box() { Vector3 a, b; aabb.get_edge(i, a, b); - /*Vector<Vector3> points; - Vector<Color> colors; - points.push_back(a); - points.push_back(b);*/ - st->add_color(Color(1.0, 1.0, 0.8, 0.8)); st->add_vertex(a); st->add_color(Color(1.0, 1.0, 0.8, 0.4)); @@ -4621,12 +4648,13 @@ void SpatialEditor::_init_indicators() { for (int i = 0; i < 3; i++) { Vector3 axis; axis[i] = 1; + Color origin_color = _get_axis_color(i); grid_enable[i] = false; grid_visible[i] = false; - origin_colors.push_back(Color(axis.x, axis.y, axis.z)); - origin_colors.push_back(Color(axis.x, axis.y, axis.z)); + origin_colors.push_back(origin_color); + origin_colors.push_back(origin_color); origin_points.push_back(axis * 4096); origin_points.push_back(axis * -4096); } @@ -4655,17 +4683,11 @@ void SpatialEditor::_init_indicators() { //move gizmo - float gizmo_alph = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_opacity"); - - gizmo_hl = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - gizmo_hl->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - gizmo_hl->set_on_top_of_alpha(); - gizmo_hl->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - gizmo_hl->set_albedo(Color(1, 1, 1, gizmo_alph + 0.2f)); - gizmo_hl->set_cull_mode(SpatialMaterial::CULL_DISABLED); - for (int i = 0; i < 3; i++) { + Color col = _get_axis_color(i); + col.a = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_opacity"); + move_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); move_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); @@ -4676,13 +4698,13 @@ void SpatialEditor::_init_indicators() { mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); mat->set_on_top_of_alpha(); mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - Color col; - col[i] = 1.0; - col.a = gizmo_alph; mat->set_albedo(col); - gizmo_color[i] = mat; + Ref<SpatialMaterial> mat_hl = mat->duplicate(); + mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); + gizmo_color_hl[i] = mat_hl; + Vector3 ivec; ivec[i] = 1; Vector3 nivec; @@ -4772,13 +4794,14 @@ void SpatialEditor::_init_indicators() { plane_mat->set_on_top_of_alpha(); plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); - Color col2; - col2[i] = 1.0; - col2.a = gizmo_alph; - plane_mat->set_albedo(col2); + plane_mat->set_albedo(col); plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides surftool->set_material(plane_mat); surftool->commit(move_plane_gizmo[i]); + + Ref<SpatialMaterial> plane_mat_hl = plane_mat->duplicate(); + plane_mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); + plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides } // Rotate @@ -4901,13 +4924,14 @@ void SpatialEditor::_init_indicators() { plane_mat->set_on_top_of_alpha(); plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); - Color col2; - col2[i] = 1.0; - col2.a = gizmo_alph; - plane_mat->set_albedo(col2); + plane_mat->set_albedo(col); plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides surftool->set_material(plane_mat); surftool->commit(scale_plane_gizmo[i]); + + Ref<SpatialMaterial> plane_mat_hl = plane_mat->duplicate(); + plane_mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); + plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides } } } @@ -5144,7 +5168,7 @@ void SpatialEditor::snap_selected_nodes_to_floor() { // We add a bit of margin to the from position to avoid it from snapping // when the spatial is already on a floor and there's another floor under // it - from = from + Vector3(0.0, 0.1, 0.0); + from = from + Vector3(0.0, 0.2, 0.0); Dictionary d; @@ -5159,31 +5183,56 @@ void SpatialEditor::snap_selected_nodes_to_floor() { Array keys = snap_data.keys(); - if (keys.size()) { - undo_redo->create_action(TTR("Snap Nodes To Floor")); + // The maximum height an object can travel to be snapped + const float max_snap_height = 20.0; + // Will be set to `true` if at least one node from the selection was sucessfully snapped + bool snapped_to_floor = false; + + if (keys.size()) { + // For snapping to be performed, there must be solid geometry under at least one of the selected nodes. + // We need to check this before snapping to register the undo/redo action only if needed. for (int i = 0; i < keys.size(); i++) { Node *node = keys[i]; Spatial *sp = Object::cast_to<Spatial>(node); - Dictionary d = snap_data[node]; Vector3 from = d["from"]; - Vector3 position_offset = d["position_offset"]; - - Vector3 to = from - Vector3(0.0, 10.0, 0.0); + Vector3 to = from - Vector3(0.0, max_snap_height, 0.0); Set<RID> excluded = _get_physics_bodies_rid(sp); if (ss->intersect_ray(from, to, result, excluded)) { - Transform new_transform = sp->get_global_transform(); - new_transform.origin.y = result.position.y; - new_transform.origin = new_transform.origin - position_offset; - - undo_redo->add_do_method(sp, "set_global_transform", new_transform); - undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_transform()); + snapped_to_floor = true; } } - undo_redo->commit_action(); + if (snapped_to_floor) { + undo_redo->create_action(TTR("Snap Nodes To Floor")); + + // Perform snapping if at least one node can be snapped + for (int i = 0; i < keys.size(); i++) { + Node *node = keys[i]; + Spatial *sp = Object::cast_to<Spatial>(node); + Dictionary d = snap_data[node]; + Vector3 from = d["from"]; + Vector3 to = from - Vector3(0.0, max_snap_height, 0.0); + Set<RID> excluded = _get_physics_bodies_rid(sp); + + if (ss->intersect_ray(from, to, result, excluded)) { + Vector3 position_offset = d["position_offset"]; + Transform new_transform = sp->get_global_transform(); + + new_transform.origin.y = result.position.y; + new_transform.origin = new_transform.origin - position_offset; + + undo_redo->add_do_method(sp, "set_global_transform", new_transform); + undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_transform()); + } + } + + undo_redo->commit_action(); + } else { + EditorNode::get_singleton()->show_warning(TTR("Couldn't find a solid floor to snap the selection to.")); + } } } @@ -5193,42 +5242,6 @@ void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) { return; snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); - - Ref<InputEventKey> k = p_event; - - if (k.is_valid()) { - - // Note: need to check is_echo because first person movement keys might still be held - if (!is_any_freelook_active() && !p_event->is_echo()) { - - if (!k->is_pressed()) - return; - - if (ED_IS_SHORTCUT("spatial_editor/tool_select", p_event)) { - _menu_item_pressed(MENU_TOOL_SELECT); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_move", p_event)) { - _menu_item_pressed(MENU_TOOL_MOVE); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_rotate", p_event)) { - _menu_item_pressed(MENU_TOOL_ROTATE); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event)) { - _menu_item_pressed(MENU_TOOL_SCALE); - } else if (ED_IS_SHORTCUT("spatial_editor/snap_to_floor", p_event)) { - snap_selected_nodes_to_floor(); - } else if (ED_IS_SHORTCUT("spatial_editor/local_coords", p_event)) { - if (are_local_coords_enabled()) { - _menu_item_toggled(false, MENU_TOOL_LOCAL_COORDS); - } else { - _menu_item_toggled(true, MENU_TOOL_LOCAL_COORDS); - } - } else if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) { - if (is_snap_enabled()) { - _menu_item_toggled(false, MENU_TOOL_USE_SNAP); - } else { - _menu_item_toggled(true, MENU_TOOL_USE_SNAP); - } - } - } - } } void SpatialEditor::_notification(int p_what) { @@ -5277,6 +5290,10 @@ void SpatialEditor::_notification(int p_what) { tool_button[SpatialEditor::TOOL_MODE_ROTATE]->set_icon(get_icon("ToolRotate", "EditorIcons")); tool_button[SpatialEditor::TOOL_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons")); tool_button[SpatialEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_icon("ListSelect", "EditorIcons")); + tool_button[SpatialEditor::TOOL_LOCK_SELECTED]->set_icon(get_icon("Lock", "EditorIcons")); + tool_button[SpatialEditor::TOOL_UNLOCK_SELECTED]->set_icon(get_icon("Unlock", "EditorIcons")); + tool_button[SpatialEditor::TOOL_GROUP_SELECTED]->set_icon(get_icon("Group", "EditorIcons")); + tool_button[SpatialEditor::TOOL_UNGROUP_SELECTED]->set_icon(get_icon("Ungroup", "EditorIcons")); tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_icon("Object", "EditorIcons")); tool_option_button[SpatialEditor::TOOL_OPT_USE_SNAP]->set_icon(get_icon("Snap", "EditorIcons")); @@ -5412,6 +5429,7 @@ void SpatialEditor::_register_all_gizmos() { add_gizmo_plugin(Ref<VehicleWheelSpatialGizmoPlugin>(memnew(VehicleWheelSpatialGizmoPlugin))); add_gizmo_plugin(Ref<VisibilityNotifierGizmoPlugin>(memnew(VisibilityNotifierGizmoPlugin))); add_gizmo_plugin(Ref<ParticlesGizmoPlugin>(memnew(ParticlesGizmoPlugin))); + add_gizmo_plugin(Ref<CPUParticlesGizmoPlugin>(memnew(CPUParticlesGizmoPlugin))); add_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin))); add_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin))); add_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin))); @@ -5501,7 +5519,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SELECT]->set_pressed(true); button_binds.write[0] = MENU_TOOL_SELECT; tool_button[TOOL_MODE_SELECT]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_SELECT]->set_tooltip(TTR("Select Mode (Q)") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection")); + tool_button[TOOL_MODE_SELECT]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_select", TTR("Select Mode"), KEY_Q)); + tool_button[TOOL_MODE_SELECT]->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection")); hbc_menu->add_child(memnew(VSeparator)); @@ -5511,7 +5530,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_MOVE]->set_flat(true); button_binds.write[0] = MENU_TOOL_MOVE; tool_button[TOOL_MODE_MOVE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_MOVE]->set_tooltip(TTR("Move Mode (W)")); + tool_button[TOOL_MODE_MOVE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_move", TTR("Move Mode"), KEY_W)); tool_button[TOOL_MODE_ROTATE] = memnew(ToolButton); hbc_menu->add_child(tool_button[TOOL_MODE_ROTATE]); @@ -5519,7 +5538,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_ROTATE]->set_flat(true); button_binds.write[0] = MENU_TOOL_ROTATE; tool_button[TOOL_MODE_ROTATE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_ROTATE]->set_tooltip(TTR("Rotate Mode (E)")); + tool_button[TOOL_MODE_ROTATE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_rotate", TTR("Rotate Mode"), KEY_E)); tool_button[TOOL_MODE_SCALE] = memnew(ToolButton); hbc_menu->add_child(tool_button[TOOL_MODE_SCALE]); @@ -5527,7 +5546,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SCALE]->set_flat(true); button_binds.write[0] = MENU_TOOL_SCALE; tool_button[TOOL_MODE_SCALE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_SCALE]->set_tooltip(TTR("Scale Mode (R)")); + tool_button[TOOL_MODE_SCALE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_scale", TTR("Scale Mode"), KEY_R)); hbc_menu->add_child(memnew(VSeparator)); @@ -5571,9 +5590,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_flat(true); button_binds.write[0] = MENU_TOOL_LOCAL_COORDS; tool_option_button[TOOL_OPT_LOCAL_COORDS]->connect("toggled", this, "_menu_item_toggled", button_binds); - ED_SHORTCUT("spatial_editor/local_coords", TTR("Local Coords"), KEY_T); - sct = ED_GET_SHORTCUT("spatial_editor/local_coords").ptr()->get_as_text(); - tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_tooltip(vformat(TTR("Local Space Mode (%s)"), sct)); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_shortcut(ED_SHORTCUT("spatial_editor/local_coords", TTR("Use Local Space"), KEY_T)); tool_option_button[TOOL_OPT_USE_SNAP] = memnew(ToolButton); hbc_menu->add_child(tool_option_button[TOOL_OPT_USE_SNAP]); @@ -5581,9 +5598,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_option_button[TOOL_OPT_USE_SNAP]->set_flat(true); button_binds.write[0] = MENU_TOOL_USE_SNAP; tool_option_button[TOOL_OPT_USE_SNAP]->connect("toggled", this, "_menu_item_toggled", button_binds); - ED_SHORTCUT("spatial_editor/snap", TTR("Snap"), KEY_Y); - sct = ED_GET_SHORTCUT("spatial_editor/snap").ptr()->get_as_text(); - tool_option_button[TOOL_OPT_USE_SNAP]->set_tooltip(vformat(TTR("Snap Mode (%s)"), sct)); + tool_option_button[TOOL_OPT_USE_SNAP]->set_shortcut(ED_SHORTCUT("spatial_editor/snap", TTR("Use Snap"), KEY_Y)); hbc_menu->add_child(memnew(VSeparator)); @@ -5601,13 +5616,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { ED_SHORTCUT("spatial_editor/insert_anim_key", TTR("Insert Animation Key"), KEY_K); ED_SHORTCUT("spatial_editor/focus_origin", TTR("Focus Origin"), KEY_O); ED_SHORTCUT("spatial_editor/focus_selection", TTR("Focus Selection"), KEY_F); - ED_SHORTCUT("spatial_editor/align_selection_with_view", TTR("Align Selection With View"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_F); - - ED_SHORTCUT("spatial_editor/tool_select", TTR("Tool Select"), KEY_Q); - ED_SHORTCUT("spatial_editor/tool_move", TTR("Tool Move"), KEY_W); - ED_SHORTCUT("spatial_editor/tool_rotate", TTR("Tool Rotate"), KEY_E); - ED_SHORTCUT("spatial_editor/tool_scale", TTR("Tool Scale"), KEY_R); - + ED_SHORTCUT("spatial_editor/align_transform_with_view", TTR("Align Transform with View"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_M); + ED_SHORTCUT("spatial_editor/align_rotation_with_view", TTR("Align Rotation with View"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_F); ED_SHORTCUT("spatial_editor/freelook_toggle", TTR("Toggle Freelook"), KEY_MASK_SHIFT + KEY_F); PopupMenu *p; @@ -5619,10 +5629,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p = transform_menu->get_popup(); p->add_shortcut(ED_SHORTCUT("spatial_editor/snap_to_floor", TTR("Snap Object to Floor"), KEY_PAGEDOWN), MENU_SNAP_TO_FLOOR); - p->add_shortcut(ED_SHORTCUT("spatial_editor/configure_snap", TTR("Configure Snap...")), MENU_TRANSFORM_CONFIGURE_SNAP); - p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/transform_dialog", TTR("Transform Dialog...")), MENU_TRANSFORM_DIALOG); + p->add_separator(); + p->add_shortcut(ED_SHORTCUT("spatial_editor/configure_snap", TTR("Configure Snap...")), MENU_TRANSFORM_CONFIGURE_SNAP); + p->connect("id_pressed", this, "_menu_item_pressed"); view_menu = memnew(MenuButton); @@ -5646,11 +5657,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_submenu_item(TTR("Gizmos"), "GizmosMenu"); p->add_separator(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_origin", TTR("View Origin")), MENU_VIEW_ORIGIN); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid", TTR("View Grid")), MENU_VIEW_GRID); + p->add_separator(); - p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings")), MENU_VIEW_CAMERA_SETTINGS); + p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings...")), MENU_VIEW_CAMERA_SETTINGS); p->set_item_checked(p->get_item_index(MENU_VIEW_ORIGIN), true); p->set_item_checked(p->get_item_index(MENU_VIEW_GRID), true); @@ -5804,7 +5815,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { EDITOR_DEF("editors/3d/manipulator_gizmo_size", 80); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/3d/manipulator_gizmo_size", PROPERTY_HINT_RANGE, "16,1024,1")); - EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.2); + EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.4); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::REAL, "editors/3d/manipulator_gizmo_opacity", PROPERTY_HINT_RANGE, "0,1,0.01")); over_gizmo_handle = -1; } |