diff options
Diffstat (limited to 'editor/plugins/node_3d_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/node_3d_editor_plugin.cpp | 920 |
1 files changed, 385 insertions, 535 deletions
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 1614f3f073..3c12022854 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) { @@ -370,29 +364,30 @@ 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; } int Node3DEditorViewport::get_selected_count() const { - Map<Node *, Object *> &selection = editor_selection->get_selection(); int count = 0; for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->key()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } count++; } @@ -401,62 +396,55 @@ 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 { +float Node3DEditorViewport::get_zfar() const { return CLAMP(spatial_editor->get_zfar(), MIN_Z, MAX_Z); } -float Node3DEditorViewport::get_fov() const { +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()) + if (clicked.is_null()) { return; + } Node *node = Object::cast_to<Node>(ObjectDB::get_instance(clicked)); Node3D *selected = Object::cast_to<Node3D>(node); - if (!selected) + if (!selected) { return; + } if (!p_allow_locked) { // Replace the node by the group if grouped @@ -475,7 +463,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,20 +471,20 @@ 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); } 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); @@ -513,11 +500,11 @@ 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<Node3D>(ObjectDB::get_instance(instances[i])); - if (!spat) + if (!spat) { continue; + } Ref<EditorNode3DGizmo> seg = spat->get_gizmo(); @@ -532,16 +519,17 @@ 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<Node>(spat); while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) { item = item->get_owner(); @@ -553,20 +541,20 @@ 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; } 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,19 +564,21 @@ 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<Node3D>(ObjectDB::get_instance(instances[i])); - if (!spat) + if (!spat) { continue; + } Ref<EditorNode3DGizmo> 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; @@ -597,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; @@ -615,14 +608,14 @@ 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(); } 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,9 +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()); @@ -671,7 +664,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,10 +687,10 @@ 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<Node3D>(ObjectDB::get_instance(instances[i])); - if (!sp || _is_node_locked(sp)) + if (!sp || _is_node_locked(sp)) { continue; + } Node *item = Object::cast_to<Node>(sp); while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) { @@ -718,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<EditorNode3DGizmo> seg = sp->get_gizmo(); - if (!seg.is_valid()) + if (!seg.is_valid()) { continue; + } if (seg->intersect_frustum(camera, frustum)) { selected.push_back(item); @@ -741,23 +736,22 @@ void Node3DEditorViewport::_select_region() { } void Node3DEditorViewport::_update_name() { - String view_mode = orthogonal ? TTR("Orthogonal") : TTR("Perspective"); if (auto_orthogonal) { 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 } 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,14 +761,15 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } se->original = se->sp->get_global_gizmo_transform(); se->original_local = se->sp->get_local_gizmo_transform(); @@ -782,9 +777,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: @@ -800,24 +793,29 @@ static int _get_key_modifier_setting(const String &p_property) { } static int _get_key_modifier(Ref<InputEventWithModifiers> 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; } @@ -828,12 +826,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 +850,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 +859,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 +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 + (is_plane_translate ? 6 : 0)); } else { @@ -897,21 +888,19 @@ 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)) + if (!plane.intersects_ray(ray_pos, ray, &r)) { continue; + } 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 +910,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 +923,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 +947,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 +956,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 +971,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 { @@ -1004,37 +984,36 @@ 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() { - _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<InputEventMouseButton> b) { +void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { _find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift()); Node *scene = editor->get_edited_scene(); @@ -1051,7 +1030,6 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> 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 +1039,10 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> 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<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(spat, "Node"); @@ -1107,17 +1083,18 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { } void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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; + } } } { @@ -1125,8 +1102,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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; + } } } @@ -1137,23 +1115,23 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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: { - NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); if (b->is_pressed() && _edit.gizmo.is_valid()) { @@ -1163,11 +1141,10 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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; @@ -1181,14 +1158,15 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } sp->set_global_transform(se->original); } @@ -1215,32 +1193,25 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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 +1224,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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 +1249,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (can_select_gizmos && spatial_editor->get_selected()) { - Ref<EditorNode3DGizmo> seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { int handle = -1; @@ -1288,7 +1256,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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); @@ -1297,17 +1264,18 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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()); @@ -1315,9 +1283,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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()); @@ -1325,9 +1293,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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()); @@ -1345,9 +1313,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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; @@ -1356,13 +1324,10 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (clicked.is_valid() && gizmo_handle >= 0) { - Node3D *spa = Object::cast_to<Node3D>(ObjectDB::get_instance(clicked)); if (spa) { - Ref<EditorNode3DGizmo> 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 +1338,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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<EditorNode3DGizmo>(); break; @@ -1387,9 +1350,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } if (cursor.region_select) { - - if (!clicked_wants_append) + if (!clicked_wants_append) { _clear_selected(); + } _select_region(); cursor.region_select = false; @@ -1397,21 +1360,21 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(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); @@ -1431,14 +1394,11 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> m = p_event; if (m.is_valid()) { - _edit.mouse_pos = m->get_position(); if (spatial_editor->get_selected()) { - Ref<EditorNode3DGizmo> seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { - int selected_handle = -1; int handle = -1; @@ -1446,21 +1406,20 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 normal; bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, false); if (inters && handle != -1) { - selected_handle = handle; } 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); + } } } } 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 +1427,12 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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 +1443,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { nav_mode = NAVIGATION_ORBIT; } else { if (clicked.is_valid()) { - if (!clicked_includes_current) { - _select_clicked(clicked_wants_append, true); // Processing was deferred. } @@ -1505,8 +1460,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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()); @@ -1514,9 +1470,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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; @@ -1556,22 +1510,21 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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) { - 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; @@ -1581,8 +1534,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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); @@ -1603,7 +1557,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { 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()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); if (!sp) { continue; @@ -1625,7 +1578,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 local_scale; if (local_coords) { - Basis g = original.basis.orthonormalized(); Vector3 local_motion = g.inverse().xform(motion); @@ -1639,13 +1591,11 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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 +1614,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } break; case TRANSFORM_TRANSLATE: { - Vector3 motion_mask; Plane plane; bool plane_mv = false; @@ -1700,12 +1649,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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) { @@ -1728,7 +1679,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { 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()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); if (!sp) { continue; @@ -1747,7 +1697,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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 +1706,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } else { - if (_edit.snap || spatial_editor->is_snap_enabled()) { motion.snap(Vector3(snap, snap, snap)); } @@ -1774,7 +1722,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } break; case TRANSFORM_ROTATE: { - Plane plane; Vector3 axis; @@ -1801,12 +1748,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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(); @@ -1826,14 +1775,15 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } if (sp->has_meta("_edit_lock_")) { continue; @@ -1842,7 +1792,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Transform t; if (local_coords) { - Transform original_local = se->original_local; Basis rot = Basis(axis, angle); @@ -1854,7 +1803,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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 +1824,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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 +1833,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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")) { @@ -1901,8 +1846,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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")) { @@ -1949,21 +1895,19 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Ref<InputEventMagnifyGesture> 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<InputEventPanGesture> 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")) { @@ -1976,8 +1920,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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) { @@ -2009,8 +1954,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Ref<InputEventKey> 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) { @@ -2053,8 +1999,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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).")); @@ -2064,10 +2011,10 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } spatial_editor->emit_signal("transform_key_request", sp, "", sp->get_transform()); } @@ -2084,25 +2031,27 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &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<InputEventWithModifiers> 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; 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; @@ -2116,30 +2065,31 @@ void Node3DEditorViewport::_nav_pan(Ref<InputEventWithModifiers> p_event, const } void Node3DEditorViewport::_nav_zoom(Ref<InputEventWithModifiers> 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; 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)); + } } } void Node3DEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { - if (lock_rotation) { _nav_pan(p_event, p_relative); return; @@ -2159,16 +2109,17 @@ void Node3DEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> 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(); } void Node3DEditorViewport::_nav_look(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) { - if (orthogonal) { _nav_pan(p_event, p_relative); return; @@ -2191,10 +2142,12 @@ void Node3DEditorViewport::_nav_look(Ref<InputEventWithModifiers> 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); @@ -2208,7 +2161,6 @@ void Node3DEditorViewport::_nav_look(Ref<InputEventWithModifiers> 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,30 +2192,32 @@ 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(); } 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(); @@ -2294,7 +2248,6 @@ static bool is_shortcut_pressed(const String &p_path) { } void Node3DEditorViewport::_update_freelook(real_t delta) { - if (!is_freelook_active()) { return; } @@ -2357,7 +2310,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 +2324,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 +2341,6 @@ void Node3DEditorViewport::_notification(int p_what) { } if (p_what == NOTIFICATION_RESIZED) { - call_deferred("update_transform_gizmo_view"); } @@ -2403,7 +2352,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,20 +2386,22 @@ void Node3DEditorViewport::_notification(int p_what) { bool exist = false; for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->key()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(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; @@ -2475,15 +2425,15 @@ void Node3DEditorViewport::_notification(int p_what) { } if (message_time > 0) { - if (message != last_message) { surface->update(); last_message = message; } message_time -= get_physics_process_delta_time(); - if (message_time < 0) + if (message_time < 0) { surface->update(); + } } //update shadow atlas if changed @@ -2561,7 +2511,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 +2549,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 +2560,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 +2587,6 @@ void Node3DEditorViewport::_notification(int p_what) { } static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture2D> icon) { - // Adjust bar size from control height Vector2 surface_size = surface.get_size(); real_t h = surface_size.y / 2.0; @@ -2662,7 +2607,6 @@ static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture2D> 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 +2648,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 +2657,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 +2665,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 +2683,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 @@ -2758,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")); } @@ -2776,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")); } @@ -2787,11 +2727,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 +2738,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 +2747,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 +2756,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 +2765,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 +2774,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,19 +2783,17 @@ 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()) + if (!get_selected_count()) { break; + } Transform camera_transform = camera->get_global_transform(); @@ -2872,14 +2802,15 @@ void Node3DEditorViewport::_menu_option(int p_option) { undo_redo->create_action(TTR("Align Transform with View")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } Transform xform; if (orthogonal) { @@ -2897,9 +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(); @@ -2907,14 +2838,15 @@ void Node3DEditorViewport::_menu_option(int p_option) { undo_redo->create_action(TTR("Align Rotation with View")); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(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()); @@ -2923,15 +2855,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 +2868,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 +2877,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 +2886,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 +2896,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 +2908,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 +2916,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 +2924,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; @@ -3012,38 +2934,36 @@ 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; 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 +2985,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 +3028,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 +3055,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 +3063,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 +3104,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]); @@ -3197,25 +3112,24 @@ void Node3DEditorViewport::_finish_gizmo_instances() { RS::get_singleton()->free(scale_plane_gizmo_instance[i]); } } -void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) { +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 - if (!preview) + if (!preview) { preview_camera->hide(); + } view_menu->set_disabled(false); 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 @@ -3227,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 @@ -3244,9 +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(); @@ -3257,24 +3172,23 @@ 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) + 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(); @@ -3298,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. @@ -3328,23 +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"]; @@ -3362,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"]; @@ -3374,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"]; @@ -3395,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"]; @@ -3444,7 +3368,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; @@ -3455,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)); @@ -3470,16 +3394,17 @@ 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; } 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 +3414,6 @@ void Node3DEditorViewport::_bind_methods() { } void Node3DEditorViewport::reset() { - orthogonal = false; auto_orthogonal = false; lock_rotation = false; @@ -3507,8 +3431,9 @@ void Node3DEditorViewport::reset() { } void Node3DEditorViewport::focus_selection() { - if (!get_selected_count()) + if (!get_selected_count()) { return; + } Vector3 center; int count = 0; @@ -3516,14 +3441,15 @@ void Node3DEditorViewport::focus_selection() { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } center += sp->get_global_gizmo_transform().origin; count++; @@ -3557,11 +3483,11 @@ 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<MeshInstance3D>(ObjectDB::get_instance(instances[i])); - if (!mesh_instance) + if (!mesh_instance) { continue; + } Ref<EditorNode3DGizmo> seg = mesh_instance->get_gizmo(); @@ -3575,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; @@ -3591,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; } @@ -3734,8 +3663,9 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po Transform global_transform; Node3D *parent_spatial = Object::cast_to<Node3D>(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)); @@ -3781,7 +3711,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()) { @@ -3838,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); @@ -3878,7 +3808,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 +4061,9 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito ////////////////////////////////////////////////////////////// void Node3DEditorViewportContainer::_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) { - if (mb->is_pressed()) { Vector2 size = get_size(); @@ -4155,25 +4082,21 @@ void Node3DEditorViewportContainer::_gui_input(const Ref<InputEvent> &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 +4110,6 @@ void Node3DEditorViewportContainer::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> 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 +4147,12 @@ void Node3DEditorViewportContainer::_gui_input(const Ref<InputEvent> &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<Texture2D> h_grabber = get_theme_icon("grabber", "HSplitContainer"); Ref<Texture2D> v_grabber = get_theme_icon("grabber", "VSplitContainer"); @@ -4254,26 +4173,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 +4201,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 +4214,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 +4231,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 +4264,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,13 +4274,12 @@ 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))); @@ -4380,26 +4287,24 @@ 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))); } 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))); @@ -4408,13 +4313,12 @@ 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))); @@ -4423,9 +4327,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 +4342,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 +4371,13 @@ 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) { - 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 +4387,6 @@ void Node3DEditor::select_gizmo_highlight_axis(int p_axis) { } void Node3DEditor::update_transform_gizmo() { - List<Node *> &selection = editor_selection->get_selected_node_list(); AABB center; bool first = true; @@ -4500,14 +4395,15 @@ void Node3DEditor::update_transform_gizmo() { bool local_gizmo_coords = are_local_coords_enabled(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) + if (!se) { continue; + } Transform xf = se->sp->get_global_gizmo_transform(); @@ -4553,10 +4449,10 @@ void Node3DEditor::update_all_gizmos(Node *p_node) { } Object *Node3DEditor::_get_editor_data(Object *p_what) { - Node3D *sp = Object::cast_to<Node3D>(p_what); - if (!sp) + if (!sp) { return nullptr; + } Node3DEditorSelectedItem *si = memnew(Node3DEditorSelectedItem); @@ -4568,7 +4464,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 +4471,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 +4496,6 @@ void Node3DEditor::_generate_selection_box() { } Dictionary Node3DEditor::get_state() const { - Dictionary d; d["snap_enabled"] = snap_enabled; @@ -4613,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; @@ -4642,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; @@ -4653,8 +4548,8 @@ Dictionary Node3DEditor::get_state() const { return d; } -void Node3DEditor::set_state(const Dictionary &p_state) { +void Node3DEditor::set_state(const Dictionary &p_state) { Dictionary d = p_state; if (d.has("snap_enabled")) { @@ -4662,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(); @@ -4681,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")) { @@ -4708,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"]; @@ -4737,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]) { @@ -4754,10 +4657,8 @@ void Node3DEditor::set_state(const Dictionary &p_state) { } void Node3DEditor::edit(Node3D *p_spatial) { - if (p_spatial != selected) { if (selected) { - Ref<EditorNode3DGizmo> seg = selected->get_gizmo(); if (seg.is_valid()) { seg->set_selected(false); @@ -4769,7 +4670,6 @@ void Node3DEditor::edit(Node3D *p_spatial) { over_gizmo_handle = -1; if (selected) { - Ref<EditorNode3DGizmo> seg = selected->get_gizmo(); if (seg.is_valid()) { seg->set_selected(true); @@ -4780,21 +4680,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,22 +4713,22 @@ void Node3DEditor::_xform_dialog_action() { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) + if (!sp) { continue; + } Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(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; } @@ -4843,10 +4740,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 +4756,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 +4766,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); @@ -4911,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<Node3DEditorViewport>(p_viewport); - if (!current_viewport) + if (!current_viewport) { return; + } EditorDebuggerNode *const debugger = EditorDebuggerNode::get_singleton(); @@ -4925,29 +4819,24 @@ 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++) + for (int i = 0; i < TOOL_MAX; i++) { tool_button[i]->set_pressed(i == p_option); + } tool_mode = (ToolMode)p_option; update_transform_gizmo(); } 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 +4846,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 +4857,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 +4868,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 +4879,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 +4890,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 +4901,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 +4912,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 +4923,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 +4938,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,13 +4949,14 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(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_"); @@ -5093,13 +4974,14 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(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); @@ -5117,13 +4999,14 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(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_"); @@ -5140,13 +5023,14 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(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); @@ -5162,7 +5046,6 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } void Node3DEditor::_init_indicators() { - { origin_enabled = true; grid_enabled = true; @@ -5224,11 +5107,9 @@ void Node3DEditor::_init_indicators() { } { - //move gizmo for (int i = 0; i < 3; i++) { - Color col; switch (i) { case 0: @@ -5276,7 +5157,6 @@ void Node3DEditor::_init_indicators() { //translate { - Ref<SurfaceTool> surftool = memnew(SurfaceTool); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); @@ -5293,12 +5173,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 +5243,6 @@ void Node3DEditor::_init_indicators() { // Rotate { - Ref<SurfaceTool> surftool = memnew(SurfaceTool); surftool->begin(Mesh::PRIMITIVE_TRIANGLES); @@ -5378,12 +5255,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 +5298,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,12 +5372,12 @@ void Node3DEditor::_init_indicators() { } 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); @@ -5525,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) { @@ -5544,7 +5418,6 @@ void Node3DEditor::_update_gizmos_menu_theme() { } void Node3DEditor::_init_grid() { - Vector<Color> grid_colors[3]; Vector<Vector3> grid_points[3]; @@ -5603,7 +5476,6 @@ void Node3DEditor::_init_grid() { } void Node3DEditor::_finish_indicators() { - RenderingServer::get_singleton()->free(origin_instance); RenderingServer::get_singleton()->free(origin); @@ -5619,14 +5491,14 @@ 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; } void Node3DEditor::_refresh_menu_icons() { - bool all_locked = true; bool all_grouped = true; @@ -5798,16 +5670,15 @@ void Node3DEditor::snap_selected_nodes_to_floor() { } void Node3DEditor::_unhandled_key_input(Ref<InputEvent> p_event) { - - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); } -void Node3DEditor::_notification(int p_what) { +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 +5711,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 +5753,33 @@ 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<Node3D>(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<EditorNode3DGizmo> seg; for (int i = 0; i < gizmo_plugins_by_priority.size(); ++i) { @@ -5937,57 +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<Node3DEditorViewport>(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() { @@ -6018,7 +5886,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 +5896,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 +5914,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 +5922,6 @@ void Node3DEditor::clear() { } Node3DEditor::Node3DEditor(EditorNode *p_editor) { - gizmo.visible = true; gizmo.scale = 1.0; @@ -6270,7 +6134,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 +6218,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 +6282,21 @@ 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) { +void Node3DEditorPlugin::edit(Object *p_object) { spatial_editor->edit(Object::cast_to<Node3D>(p_object)); } bool Node3DEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("Node3D"); } @@ -6447,12 +6305,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 +6355,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<EditorNode3DGizmoPlugin> &p_a, const Ref<EditorNode3DGizmoPlugin> &p_b) const { if (p_a->get_priority() == p_b->get_priority()) { return p_a->get_name() < p_b->get_name(); @@ -6519,7 +6372,6 @@ struct _GizmoPluginPriorityComparator { }; struct _GizmoPluginNameComparator { - bool operator()(const Ref<EditorNode3DGizmoPlugin> &p_a, const Ref<EditorNode3DGizmoPlugin> &p_b) const { return p_a->get_name() < p_b->get_name(); } @@ -6545,7 +6397,6 @@ void Node3DEditor::remove_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> 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 +6410,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<Ref<StandardMaterial3D>> mats; @@ -6601,7 +6451,6 @@ void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color } void EditorNode3DGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture2D> &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<Ref<StandardMaterial3D>> icons; @@ -6672,8 +6521,9 @@ Ref<StandardMaterial3D> EditorNode3DGizmoPlugin::get_material(const String &p_na ERR_FAIL_COND_V(!materials.has(p_name), Ref<StandardMaterial3D>()); ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<StandardMaterial3D>()); - 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); @@ -6703,15 +6553,15 @@ int EditorNode3DGizmoPlugin::get_priority() const { } Ref<EditorNode3DGizmo> 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); } Ref<EditorNode3DGizmo> 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); @@ -6764,14 +6614,14 @@ bool EditorNode3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { } Ref<EditorNode3DGizmo> 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); } Ref<EditorNode3DGizmo> ref; - if (has_gizmo(p_spatial)) + if (has_gizmo(p_spatial)) { ref.instance(); + } return ref; } |