Skip to content

Commit 9ef1ec5

Browse files
committed
Merge pull request #103608 from gr8alpaca/expose_node_3d_snapping
Expose 3D editor snap settings to EditorInterface
2 parents 9cb6411 + 4d80777 commit 9ef1ec5

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
@@ -162,6 +162,24 @@
162162
[b]Warning:[/b] Removing and freeing this node will render a part of the editor useless and may cause a crash.
163163
</description>
164164
</method>
165+
<method name="get_node_3d_rotate_snap" qualifiers="const">
166+
<return type="float" />
167+
<description>
168+
Returns the amount of degrees the 3D editor's rotational snapping is set to.
169+
</description>
170+
</method>
171+
<method name="get_node_3d_scale_snap" qualifiers="const">
172+
<return type="float" />
173+
<description>
174+
Returns the amount of units the 3D editor's scale snapping is set to.
175+
</description>
176+
</method>
177+
<method name="get_node_3d_translate_snap" qualifiers="const">
178+
<return type="float" />
179+
<description>
180+
Returns the amount of units the 3D editor's translation snapping is set to.
181+
</description>
182+
</method>
165183
<method name="get_open_scene_roots" qualifiers="const">
166184
<return type="Node[]" />
167185
<description>
@@ -229,6 +247,12 @@
229247
- [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.
230248
</description>
231249
</method>
250+
<method name="is_node_3d_snap_enabled" qualifiers="const">
251+
<return type="bool" />
252+
<description>
253+
Returns [code]true[/code] if the 3D editor currently has snapping mode enabled, and [code]false[/code] otherwise.
254+
</description>
255+
</method>
232256
<method name="is_playing_scene" qualifiers="const">
233257
<return type="bool" />
234258
<description>

editor/editor_interface.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,22 @@ float EditorInterface::get_editor_scale() const {
418418
return EDSCALE;
419419
}
420420

421+
bool EditorInterface::is_node_3d_snap_enabled() const {
422+
return Node3DEditor::get_singleton()->is_snap_enabled();
423+
}
424+
425+
real_t EditorInterface::get_node_3d_translate_snap() const {
426+
return Node3DEditor::get_singleton()->get_translate_snap();
427+
}
428+
429+
real_t EditorInterface::get_node_3d_rotate_snap() const {
430+
return Node3DEditor::get_singleton()->get_rotate_snap();
431+
}
432+
433+
real_t EditorInterface::get_node_3d_scale_snap() const {
434+
return Node3DEditor::get_singleton()->get_scale_snap();
435+
}
436+
421437
void EditorInterface::popup_dialog(Window *p_dialog, const Rect2i &p_screen_rect) {
422438
p_dialog->popup_exclusive(EditorNode::get_singleton(), p_screen_rect);
423439
}
@@ -807,6 +823,11 @@ void EditorInterface::_bind_methods() {
807823

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

826+
ClassDB::bind_method(D_METHOD("is_node_3d_snap_enabled"), &EditorInterface::is_node_3d_snap_enabled);
827+
ClassDB::bind_method(D_METHOD("get_node_3d_translate_snap"), &EditorInterface::get_node_3d_translate_snap);
828+
ClassDB::bind_method(D_METHOD("get_node_3d_rotate_snap"), &EditorInterface::get_node_3d_rotate_snap);
829+
ClassDB::bind_method(D_METHOD("get_node_3d_scale_snap"), &EditorInterface::get_node_3d_scale_snap);
830+
810831
ClassDB::bind_method(D_METHOD("popup_dialog", "dialog", "rect"), &EditorInterface::popup_dialog, DEFVAL(Rect2i()));
811832
ClassDB::bind_method(D_METHOD("popup_dialog_centered", "dialog", "minsize"), &EditorInterface::popup_dialog_centered, DEFVAL(Size2i()));
812833
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)