Skip to content

Commit 27b66ae

Browse files
committed
Add keyboard shortcuts to lock transform axes.
While actively using a transform tool, you can press X/Y/Z to lock the transform to an axis or (shift)+X/Y/Z to constrain the transform to a plane. These keys are only processed if you have a transform tool (translate/rotate/scale) active _and_ the mouse button is held. When we handle a key during a transform, we need to accept/return so it doesn't cascade through. In particular, without this "Y" will toggle snap mode unintentionally. See godotengine/godot-proposals#1215.
1 parent 0fe60f8 commit 27b66ae

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

editor/plugins/spatial_editor_plugin.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,37 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
19781978
if (!k->is_pressed())
19791979
return;
19801980

1981+
if (_edit.mode != TRANSFORM_NONE) {
1982+
// We're actively transforming, handle keys specially
1983+
bool handled = true;
1984+
if (ED_IS_SHORTCUT("spatial_editor/lock_transform_x", p_event)) {
1985+
_edit.plane = TRANSFORM_X_AXIS;
1986+
set_message(TTR("X-Axis Transform."), 2);
1987+
} else if (ED_IS_SHORTCUT("spatial_editor/lock_transform_y", p_event)) {
1988+
_edit.plane = TRANSFORM_Y_AXIS;
1989+
set_message(TTR("Y-Axis Transform."), 2);
1990+
} else if (ED_IS_SHORTCUT("spatial_editor/lock_transform_z", p_event)) {
1991+
_edit.plane = TRANSFORM_Z_AXIS;
1992+
set_message(TTR("Z-Axis Transform."), 2);
1993+
} else if (ED_IS_SHORTCUT("spatial_editor/lock_transform_yz", p_event)) {
1994+
_edit.plane = TRANSFORM_YZ;
1995+
set_message(TTR("YZ-Plane Transform."), 2);
1996+
} else if (ED_IS_SHORTCUT("spatial_editor/lock_transform_xz", p_event)) {
1997+
_edit.plane = TRANSFORM_XZ;
1998+
set_message(TTR("XZ-Plane Transform."), 2);
1999+
} else if (ED_IS_SHORTCUT("spatial_editor/lock_transform_xy", p_event)) {
2000+
_edit.plane = TRANSFORM_XY;
2001+
set_message(TTR("XY-Plane Transform."), 2);
2002+
} else {
2003+
handled = false;
2004+
}
2005+
2006+
if (handled) {
2007+
accept_event();
2008+
return;
2009+
}
2010+
}
2011+
19812012
if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) {
19822013
if (_edit.mode != TRANSFORM_NONE) {
19832014
_edit.snap = !_edit.snap;
@@ -3916,6 +3947,12 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
39163947
ED_SHORTCUT("spatial_editor/freelook_down", TTR("Freelook Down"), KEY_Q);
39173948
ED_SHORTCUT("spatial_editor/freelook_speed_modifier", TTR("Freelook Speed Modifier"), KEY_SHIFT);
39183949
ED_SHORTCUT("spatial_editor/freelook_slow_modifier", TTR("Freelook Slow Modifier"), KEY_ALT);
3950+
ED_SHORTCUT("spatial_editor/lock_transform_x", TTR("Lock Transformation to X axis"), KEY_X);
3951+
ED_SHORTCUT("spatial_editor/lock_transform_y", TTR("Lock Transformation to Y axis"), KEY_Y);
3952+
ED_SHORTCUT("spatial_editor/lock_transform_z", TTR("Lock Transformation to Z axis"), KEY_Z);
3953+
ED_SHORTCUT("spatial_editor/lock_transform_yz", TTR("Lock Transformation to YZ plane"), KEY_MASK_SHIFT | KEY_X);
3954+
ED_SHORTCUT("spatial_editor/lock_transform_xz", TTR("Lock Transformation to XZ plane"), KEY_MASK_SHIFT | KEY_Y);
3955+
ED_SHORTCUT("spatial_editor/lock_transform_xy", TTR("Lock Transformation to XY plane"), KEY_MASK_SHIFT | KEY_Z);
39193956

39203957
preview_camera = memnew(CheckBox);
39213958
preview_camera->set_text(TTR("Preview"));

0 commit comments

Comments
 (0)