diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 3 | ||||
-rw-r--r-- | editor/plugins/polygon_2d_editor_plugin.cpp | 8 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 11 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.h | 2 | ||||
-rw-r--r-- | editor/plugins/texture_region_editor_plugin.cpp | 17 |
5 files changed, 16 insertions, 25 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 2270421eca..70a6954fb5 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3438,7 +3438,6 @@ void CanvasItemEditor::_popup_callback(int p_op) { case ANIM_INSERT_POS_SCALE: case ANIM_INSERT_ROT_SCALE: case ANIM_INSERT_POS_ROT_SCALE: { - static const bool key_toggles[7][3]={ {true,false,false}, {false,true,false}, @@ -3451,12 +3450,10 @@ void CanvasItemEditor::_popup_callback(int p_op) { key_pos=key_toggles[p_op-ANIM_INSERT_POS][0]; key_rot=key_toggles[p_op-ANIM_INSERT_POS][1]; key_scale=key_toggles[p_op-ANIM_INSERT_POS][2]; - for(int i=ANIM_INSERT_POS;i<=ANIM_INSERT_POS_ROT_SCALE;i++) { int idx = animation_menu->get_popup()->get_item_index(i); animation_menu->get_popup()->set_item_checked(idx,i==p_op); } - } break;*/ case ANIM_COPY_POSE: { diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 0e8c13b067..a525983c75 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -437,14 +437,10 @@ void Polygon2DEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_snap_step_y"), &Polygon2DEditor::_set_snap_step_y); } -inline float _snap_scalar(float p_offset, float p_step, float p_target) { - return p_step != 0 ? Math::stepify(p_target - p_offset, p_step) + p_offset : p_target; -} - Vector2 Polygon2DEditor::snap_point(Vector2 p_target) const { if (use_snap) { - p_target.x = _snap_scalar(snap_offset.x * uv_draw_zoom - uv_draw_ofs.x, snap_step.x * uv_draw_zoom, p_target.x); - p_target.y = _snap_scalar(snap_offset.y * uv_draw_zoom - uv_draw_ofs.y, snap_step.y * uv_draw_zoom, p_target.y); + p_target.x = Math::snap_scalar(snap_offset.x * uv_draw_zoom - uv_draw_ofs.x, snap_step.x * uv_draw_zoom, p_target.x); + p_target.y = Math::snap_scalar(snap_offset.y * uv_draw_zoom - uv_draw_ofs.y, snap_step.y * uv_draw_zoom, p_target.y); } return p_target; diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 547679b056..f96cbabde7 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2894,7 +2894,7 @@ bool SpatialEditorViewport::_create_instance(Node *parent, String &path, const P if (parent_spatial) global_transform = parent_spatial->get_global_transform(); - global_transform.origin = _get_instance_position(p_point); + global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point)); editor_data->get_undo_redo().add_do_method(instanced_scene, "set_global_transform", global_transform); @@ -4834,6 +4834,15 @@ void SpatialEditor::snap_cursor_to_plane(const Plane &p_plane) { //cursor.pos=p_plane.project(cursor.pos); } +Vector3 SpatialEditor::snap_point(Vector3 p_target, Vector3 p_start) const { + if (is_snap_enabled()) { + p_target.x = Math::snap_scalar(0.0, get_translate_snap(), p_target.x); + p_target.y = Math::snap_scalar(0.0, get_translate_snap(), p_target.y); + p_target.z = Math::snap_scalar(0.0, get_translate_snap(), p_target.z); + } + return p_target; +} + void SpatialEditorPlugin::_bind_methods() { ClassDB::bind_method("snap_cursor_to_plane", &SpatialEditorPlugin::snap_cursor_to_plane); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index a9dd1f1327..f2a9886f2a 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -548,6 +548,8 @@ public: static SpatialEditor *get_singleton() { return singleton; } void snap_cursor_to_plane(const Plane &p_plane); + Vector3 snap_point(Vector3 p_target, Vector3 p_start = Vector3(0, 0, 0)) const; + float get_znear() const { return settings_znear->get_value(); } float get_zfar() const { return settings_zfar->get_value(); } float get_fov() const { return settings_fov->get_value(); } diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 0a7f3ff8f9..740772e204 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -736,23 +736,10 @@ void TextureRegionEditor::_edit_region() { edit_draw->update(); } -inline float _snap_scalar(float p_offset, float p_step, float separation, float p_target) { - if (p_step != 0) { - float a = Math::stepify(p_target - p_offset, p_step + separation) + p_offset; - float b = a; - if (p_target >= 0) - b -= separation; - else - b += p_step; - return (Math::abs(p_target - a) < Math::abs(p_target - b)) ? a : b; - } - return p_target; -} - Vector2 TextureRegionEditor::snap_point(Vector2 p_target) const { if (snap_mode == SNAP_GRID) { - p_target.x = _snap_scalar(snap_offset.x, snap_step.x, snap_separation.x, p_target.x); - p_target.y = _snap_scalar(snap_offset.y, snap_step.y, snap_separation.y, p_target.y); + p_target.x = Math::snap_scalar_seperation(snap_offset.x, snap_step.x, p_target.x, snap_separation.x); + p_target.y = Math::snap_scalar_seperation(snap_offset.y, snap_step.y, p_target.y, snap_separation.y); } return p_target; |