Skip to content

Commit

Permalink
Support switching display mode with "Z" key
Browse files Browse the repository at this point in the history
  • Loading branch information
imjp94 committed Nov 21, 2021
1 parent bc16b13 commit d813540
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions addons/gd-blender-3d-shortcuts/Utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ static func get_spatial_editor(base_control):
if child.get_class() == "SpatialEditor":
return child

static func get_spatial_editor_viewport_container(spatial_editor):
var children = recursive_get_children(spatial_editor)
for child in children:
if child.get_class() == "SpatialEditorViewportContainer":
return child

static func get_spatial_editor_viewport(spatial_editor_viewport_container):
var children = recursive_get_children(spatial_editor_viewport_container)
for child in children:
if child.get_class() == "Viewport":
return child

static func get_snap_dialog(spatial_editor):
var children = recursive_get_children(spatial_editor)
for child in children:
Expand Down
15 changes: 15 additions & 0 deletions addons/gd-blender-3d-shortcuts/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var scale_snap_line_edit
var local_space_button
var snap_button
var overlay_control
var spatial_editor_viewport

var overlay_label = Label.new()
var axis_ig
Expand Down Expand Up @@ -73,11 +74,18 @@ func _ready():
local_space_button.connect("toggled", self, "_on_local_space_button_toggled")
snap_button = Utils.get_spatial_editor_snap_button(spatial_editor)
snap_button.connect("toggled", self, "_on_snap_button_toggled")
var spatial_editor_viewport_container = Utils.get_spatial_editor_viewport_container(spatial_editor)
if spatial_editor_viewport_container:
spatial_editor_viewport = Utils.get_spatial_editor_viewport(spatial_editor_viewport_container)
sync_settings()

func _input(event):
if event is InputEventKey:
if event.pressed:
match event.scancode:
KEY_Z:
if not (event.control or event.alt or event.shift) and current_session == SESSION.NONE:
switch_display_mode()
# Hacky way to intercept default shortcut behavior when in session
if current_session != SESSION.NONE:
var event_text = event.as_text()
Expand Down Expand Up @@ -534,6 +542,13 @@ func sync_settings():
if snap_button:
is_snapping = snap_button.pressed

func switch_display_mode():
if spatial_editor_viewport:
if spatial_editor_viewport.debug_draw == Viewport.DEBUG_DRAW_WIREFRAME:
spatial_editor_viewport.debug_draw = 0
else:
spatial_editor_viewport.debug_draw += 1

# Repeatedly applying same axis will results in toggling is_global, just like pressing xx, yy or zz in blender
func toggle_constraint_axis(axis):
# Following order as below:
Expand Down

0 comments on commit d813540

Please sign in to comment.