diff --git a/doc/classes/EditorSpatialGizmoPlugin.xml b/doc/classes/EditorSpatialGizmoPlugin.xml
index 26665f899..4a46ffd3b 100644
--- a/doc/classes/EditorSpatialGizmoPlugin.xml
+++ b/doc/classes/EditorSpatialGizmoPlugin.xml
@@ -49,7 +49,7 @@
Override this method to commit a group of subgizmos being edited (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). This usually means creating an [UndoRedo] action for the change, using the current transforms as "do" and the [code]restore[/code] transforms as "undo".
- If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] transforms should be directly set, without any [UndoRedo] action. Called for this plugin's active gizmos.
+ If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] transforms should be directly set, without any [UndoRedo] action. As with all subgizmo methods, transforms are given in local space respect to the gizmo's Spatial. Called for this plugin's active gizmos.
@@ -127,7 +127,7 @@
All built-in editor gizmos return a priority of [code]-1[/code]. If not overridden, this method will return [code]0[/code], which means custom gizmos will automatically get higher priority than built-in gizmos.
-
+
@@ -135,7 +135,7 @@
- Override this method to return the current transform of a subgizmo. This transform will be requested at the start of an edit and used in the [code]restore[/code] argument in [method _commit_subgizmos]. Called for this plugin's active gizmos.
+ Override this method to return the current transform of a subgizmo. As with all subgizmo methods, the transform should be in local space respect to the gizmo's Node3D. This transform will be requested at the start of an edit and used in the [code]restore[/code] argument in [method _commit_subgizmos]. Called for this plugin's active gizmos.
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 10996ad36..c4272195e 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -1550,15 +1550,15 @@ void SpatialEditorViewport::_sinput(const Ref &p_event) {
//gizmo has priority over everything
- bool can_select_gizmos = true;
+ bool can_select_gizmos = spatial_editor->get_single_selected_node();
{
int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS);
- can_select_gizmos = view_menu->get_popup()->is_item_checked(idx);
+ can_select_gizmos = can_select_gizmos && view_menu->get_popup()->is_item_checked(idx);
}
- if (can_select_gizmos && spatial_editor->get_single_selected_node()) {
- SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data(spatial_editor->get_single_selected_node());
+ // Gizmo handles
+ if (can_select_gizmos) {
Vector[> gizmos = spatial_editor->get_single_selected_node()->get_gizmos();
bool intersected_handle = false;
@@ -1569,6 +1569,40 @@ void SpatialEditorViewport::_sinput(const Ref &p_event) {
continue;
}
+ int gizmo_handle = -1;
+ seg->handles_intersect_ray(camera, _edit.mouse_pos, b->get_shift(), gizmo_handle);
+ if (gizmo_handle != -1) {
+ _edit.gizmo = seg;
+ _edit.gizmo_handle = gizmo_handle;
+ _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle);
+ intersected_handle = true;
+ break;
+ }
+ }
+
+ if (intersected_handle) {
+ break;
+ }
+ }
+
+ // Transform gizmo
+ if (_transform_gizmo_select(_edit.mouse_pos)) {
+ break;
+ }
+
+ // Subgizmos
+ if (can_select_gizmos) {
+ SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data(spatial_editor->get_single_selected_node());
+ Vector][> gizmos = spatial_editor->get_single_selected_node()->get_gizmos();
+
+ bool intersected_subgizmo = false;
+ for (int i = 0; i < gizmos.size(); i++) {
+ Ref seg = gizmos[i];
+
+ if ((!seg.is_valid())) {
+ continue;
+ }
+
int subgizmo_id = seg->subgizmos_intersect_ray(camera, _edit.mouse_pos);
if (subgizmo_id != -1) {
ERR_CONTINUE(!se);
@@ -1590,31 +1624,18 @@ void SpatialEditorViewport::_sinput(const Ref &p_event) {
}
seg->redraw();
- spatial_editor->update_transform_gizmo();
- intersected_handle = true;
- break;
- }
- int gizmo_handle = -1;
- seg->handles_intersect_ray(camera, _edit.mouse_pos, b->get_shift(), gizmo_handle);
- if (gizmo_handle != -1) {
- _edit.gizmo = seg;
- _edit.gizmo_handle = gizmo_handle;
- _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle);
- intersected_handle = true;
+ spatial_editor->update_transform_gizmo();
+ intersected_subgizmo = true;
break;
}
}
- if (intersected_handle) {
+ if (intersected_subgizmo) {
break;
}
}
- if (_transform_gizmo_select(_edit.mouse_pos)) {
- break;
- }
-
clicked = 0;
if ((spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT && b->get_command()) || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE) {
@@ -1933,7 +1954,7 @@ void SpatialEditorViewport::_sinput(const Ref &p_event) {
Transform xform = GE->get();
Transform new_xform = _compute_transform(TRANSFORM_SCALE, se->original * xform, xform, motion, snap, local_coords);
if (!local_coords) {
- new_xform = se->original.inverse() * new_xform;
+ new_xform = se->original.affine_inverse() * new_xform;
}
se->gizmo->set_subgizmo_transform(GE->key(), new_xform);
}
@@ -2031,7 +2052,7 @@ void SpatialEditorViewport::_sinput(const Ref &p_event) {
for (Map::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) {
Transform xform = GE->get();
Transform new_xform = _compute_transform(TRANSFORM_TRANSLATE, se->original * xform, xform, motion, snap, local_coords);
- new_xform = se->original.inverse() * new_xform;
+ new_xform = se->original.affine_inverse() * new_xform;
se->gizmo->set_subgizmo_transform(GE->key(), new_xform);
}
@@ -2120,7 +2141,7 @@ void SpatialEditorViewport::_sinput(const Ref &p_event) {
Transform new_xform = _compute_transform(TRANSFORM_ROTATE, se->original * xform, xform, compute_axis, angle, local_coords);
if (!local_coords) {
- new_xform = se->original.inverse() * new_xform;
+ new_xform = se->original.affine_inverse() * new_xform;
}
se->gizmo->set_subgizmo_transform(GE->key(), new_xform);
}
@@ -7548,7 +7569,6 @@ bool SpatialEditor::is_gizmo_visible() const {
return gizmo.visible;
}
-
void SpatialEditor::snap_cursor_to_plane(const Plane &p_plane) {
//cursor.pos=p_plane.project(cursor.pos);
}
]