Skip to content

Commit 4d80777

Browse files
committed
Expose 3D editor snap settings to EditorInterface
1 parent 7893202 commit 4d80777

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

doc/classes/EditorInterface.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@
156156
[b]Warning:[/b] Removing and freeing this node will render a part of the editor useless and may cause a crash.
157157
</description>
158158
</method>
159+
<method name="get_node_3d_rotate_snap" qualifiers="const">
160+
<return type="float" />
161+
<description>
162+
Returns the amount of degrees the 3D editor's rotational snapping is set to.
163+
</description>
164+
</method>
165+
<method name="get_node_3d_scale_snap" qualifiers="const">
166+
<return type="float" />
167+
<description>
168+
Returns the amount of units the 3D editor's scale snapping is set to.
169+
</description>
170+
</method>
171+
<method name="get_node_3d_translate_snap" qualifiers="const">
172+
<return type="float" />
173+
<description>
174+
Returns the amount of units the 3D editor's translation snapping is set to.
175+
</description>
176+
</method>
159177
<method name="get_open_scene_roots" qualifiers="const">
160178
<return type="Node[]" />
161179
<description>
@@ -223,6 +241,12 @@
223241
- [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.
224242
</description>
225243
</method>
244+
<method name="is_node_3d_snap_enabled" qualifiers="const">
245+
<return type="bool" />
246+
<description>
247+
Returns [code]true[/code] if the 3D editor currently has snapping mode enabled, and [code]false[/code] otherwise.
248+
</description>
249+
</method>
226250
<method name="is_playing_scene" qualifiers="const">
227251
<return type="bool" />
228252
<description>

editor/editor_interface.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,22 @@ float EditorInterface::get_editor_scale() const {
415415
return EDSCALE;
416416
}
417417

418+
bool EditorInterface::is_node_3d_snap_enabled() const {
419+
return Node3DEditor::get_singleton()->is_snap_enabled();
420+
}
421+
422+
real_t EditorInterface::get_node_3d_translate_snap() const {
423+
return Node3DEditor::get_singleton()->get_translate_snap();
424+
}
425+
426+
real_t EditorInterface::get_node_3d_rotate_snap() const {
427+
return Node3DEditor::get_singleton()->get_rotate_snap();
428+
}
429+
430+
real_t EditorInterface::get_node_3d_scale_snap() const {
431+
return Node3DEditor::get_singleton()->get_scale_snap();
432+
}
433+
418434
void EditorInterface::popup_dialog(Window *p_dialog, const Rect2i &p_screen_rect) {
419435
p_dialog->popup_exclusive(EditorNode::get_singleton(), p_screen_rect);
420436
}
@@ -803,6 +819,11 @@ void EditorInterface::_bind_methods() {
803819

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

822+
ClassDB::bind_method(D_METHOD("is_node_3d_snap_enabled"), &EditorInterface::is_node_3d_snap_enabled);
823+
ClassDB::bind_method(D_METHOD("get_node_3d_translate_snap"), &EditorInterface::get_node_3d_translate_snap);
824+
ClassDB::bind_method(D_METHOD("get_node_3d_rotate_snap"), &EditorInterface::get_node_3d_rotate_snap);
825+
ClassDB::bind_method(D_METHOD("get_node_3d_scale_snap"), &EditorInterface::get_node_3d_scale_snap);
826+
806827
ClassDB::bind_method(D_METHOD("popup_dialog", "dialog", "rect"), &EditorInterface::popup_dialog, DEFVAL(Rect2i()));
807828
ClassDB::bind_method(D_METHOD("popup_dialog_centered", "dialog", "minsize"), &EditorInterface::popup_dialog_centered, DEFVAL(Size2i()));
808829
ClassDB::bind_method(D_METHOD("popup_dialog_centered_ratio", "dialog", "ratio"), &EditorInterface::popup_dialog_centered_ratio, DEFVAL(0.8));

editor/editor_interface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class EditorInterface : public Object {
132132

133133
float get_editor_scale() const;
134134

135+
bool is_node_3d_snap_enabled() const;
136+
real_t get_node_3d_translate_snap() const;
137+
real_t get_node_3d_rotate_snap() const;
138+
real_t get_node_3d_scale_snap() const;
139+
135140
void popup_dialog(Window *p_dialog, const Rect2i &p_screen_rect = Rect2i());
136141
void popup_dialog_centered(Window *p_dialog, const Size2i &p_minsize = Size2i());
137142
void popup_dialog_centered_ratio(Window *p_dialog, float p_ratio = 0.8);

0 commit comments

Comments
 (0)