From 93c77580aa8fb6b0af2905fef518ccc2c0a72e60 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 28 Apr 2018 11:22:22 -0300 Subject: [PATCH] Fix how snapping is applied to 3D polygon editing, make it more friendly. --- .../collision_polygon_editor_plugin.cpp | 24 ++++++++++++++++--- .../plugins/collision_polygon_editor_plugin.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp index d308cfbbf7d..e837359d0cd 100644 --- a/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_editor_plugin.cpp @@ -33,6 +33,8 @@ #include "canvas_item_editor_plugin.h" #include "editor/editor_settings.h" #include "os/file_access.h" +#include "os/input.h" +#include "os/keyboard.h" #include "scene/3d/camera.h" #include "spatial_editor_plugin.h" @@ -135,7 +137,9 @@ bool Polygon3DEditor::forward_spatial_gui_input(Camera *p_camera, const Refsnap_point(cpoint); + //DO NOT snap here, it's confusing in 3D for adding points. + //Let the snap happen when the point is being moved, instead. + //cpoint = CanvasItemEditor::get_singleton()->snap_point(cpoint); Vector poly = node->call("get_polygon"); @@ -154,6 +158,7 @@ bool Polygon3DEditor::forward_spatial_gui_input(Camera *p_camera, const Refcall("set_polygon", poly); _polygon_draw(); + snap_ignore = true; + return true; } } else { @@ -255,11 +263,14 @@ bool Polygon3DEditor::forward_spatial_gui_input(Camera *p_camera, const Ref mm = p_event; if (mm.is_valid()) { - if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { Vector2 gpoint = mm->get_position(); @@ -332,7 +342,13 @@ bool Polygon3DEditor::forward_spatial_gui_input(Camera *p_camera, const Refsnap_point(cpoint); + if (snap_ignore && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + snap_ignore = false; + } + + if (!snap_ignore) { + cpoint = CanvasItemEditor::get_singleton()->snap_point(cpoint); + } edited_point_pos = cpoint; _polygon_draw(); @@ -552,6 +568,8 @@ Polygon3DEditor::Polygon3DEditor(EditorNode *p_editor) { m.instance(); pointsm->set_mesh(m); pointsm->set_transform(Transform(Basis(), Vector3(0, 0, 0.00001))); + + snap_ignore = false; } Polygon3DEditor::~Polygon3DEditor() { diff --git a/editor/plugins/collision_polygon_editor_plugin.h b/editor/plugins/collision_polygon_editor_plugin.h index 2202dd25f4d..4229808e2f5 100644 --- a/editor/plugins/collision_polygon_editor_plugin.h +++ b/editor/plugins/collision_polygon_editor_plugin.h @@ -78,6 +78,7 @@ class Polygon3DEditor : public HBoxContainer { Vector pre_move_edit; Vector wip; bool wip_active; + bool snap_ignore; float prev_depth;