Skip to content

Commit

Permalink
Expose 3D editor snap settings to EditorInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
gr8alpaca committed Mar 5, 2025
1 parent 1753893 commit 8f46b5b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc/classes/EditorInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@
[b]Warning:[/b] Removing and freeing this node will render a part of the editor useless and may cause a crash.
</description>
</method>
<method name="get_node_3d_rotate_snap" qualifiers="const">
<return type="float" />
<description>
Returns the amount of degrees the 3D editor's rotational snapping is set to.
</description>
</method>
<method name="get_node_3d_scale_snap" qualifiers="const">
<return type="float" />
<description>
Returns the amount of units the 3D editor's scale snapping is set to.
</description>
</method>
<method name="get_node_3d_translate_snap" qualifiers="const">
<return type="float" />
<description>
Returns the amount of units the 3D editor's translation snapping is set to.
</description>
</method>
<method name="get_open_scenes" qualifiers="const">
<return type="PackedStringArray" />
<description>
Expand Down Expand Up @@ -217,6 +235,12 @@
- [member Viewport.gui_embed_subwindows] is [code]false[/code]. This is forced to [code]true[/code] on platforms that don't support multiple windows such as Web, or when the [code]--single-window[/code] [url=$DOCS_URL/tutorials/editor/command_line_tutorial.html]command line argument[/url] is used.
</description>
</method>
<method name="is_node_3d_snap_enabled" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the 3D editor currently has snapping mode enabled, and [code]false[/code] otherwise.
</description>
</method>
<method name="is_playing_scene" qualifiers="const">
<return type="bool" />
<description>
Expand Down
21 changes: 21 additions & 0 deletions editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,22 @@ float EditorInterface::get_editor_scale() const {
return EDSCALE;
}

bool EditorInterface::is_node_3d_snap_enabled() const {
return Node3DEditor::get_singleton()->is_snap_enabled();
}

real_t EditorInterface::get_node_3d_translate_snap() const {
return Node3DEditor::get_singleton()->get_translate_snap();
}

real_t EditorInterface::get_node_3d_rotate_snap() const {
return Node3DEditor::get_singleton()->get_rotate_snap();
}

real_t EditorInterface::get_node_3d_scale_snap() const {
return Node3DEditor::get_singleton()->get_scale_snap();
}

void EditorInterface::popup_dialog(Window *p_dialog, const Rect2i &p_screen_rect) {
p_dialog->popup_exclusive(EditorNode::get_singleton(), p_screen_rect);
}
Expand Down Expand Up @@ -791,6 +807,11 @@ void EditorInterface::_bind_methods() {

ClassDB::bind_method(D_METHOD("get_editor_scale"), &EditorInterface::get_editor_scale);

ClassDB::bind_method(D_METHOD("is_node_3d_snap_enabled"), &EditorInterface::is_node_3d_snap_enabled);
ClassDB::bind_method(D_METHOD("get_node_3d_translate_snap"), &EditorInterface::get_node_3d_translate_snap);
ClassDB::bind_method(D_METHOD("get_node_3d_rotate_snap"), &EditorInterface::get_node_3d_rotate_snap);
ClassDB::bind_method(D_METHOD("get_node_3d_scale_snap"), &EditorInterface::get_node_3d_scale_snap);

ClassDB::bind_method(D_METHOD("popup_dialog", "dialog", "rect"), &EditorInterface::popup_dialog, DEFVAL(Rect2i()));
ClassDB::bind_method(D_METHOD("popup_dialog_centered", "dialog", "minsize"), &EditorInterface::popup_dialog_centered, DEFVAL(Size2i()));
ClassDB::bind_method(D_METHOD("popup_dialog_centered_ratio", "dialog", "ratio"), &EditorInterface::popup_dialog_centered_ratio, DEFVAL(0.8));
Expand Down
5 changes: 5 additions & 0 deletions editor/editor_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class EditorInterface : public Object {

float get_editor_scale() const;

bool is_node_3d_snap_enabled() const;
real_t get_node_3d_translate_snap() const;
real_t get_node_3d_rotate_snap() const;
real_t get_node_3d_scale_snap() const;

void popup_dialog(Window *p_dialog, const Rect2i &p_screen_rect = Rect2i());
void popup_dialog_centered(Window *p_dialog, const Size2i &p_minsize = Size2i());
void popup_dialog_centered_ratio(Window *p_dialog, float p_ratio = 0.8);
Expand Down

0 comments on commit 8f46b5b

Please sign in to comment.