Skip to content

Commit 37fed77

Browse files
committed
Merge pull request #102176 from ryevdokimov/fix-local-space-gizmo-basis
Add "active" state to one of the multiple selected Node3Ds to determine basis in Local mode
2 parents 69529ff + 5878b88 commit 37fed77

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

doc/classes/EditorSettings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@
292292
<member name="editors/2d/zoom_speed_factor" type="float" setter="" getter="">
293293
The factor to use when zooming in or out in the 2D editor. For example, [code]1.1[/code] will zoom in by 10% with every step. If set to [code]2.0[/code], zooming will only cycle through powers of two.
294294
</member>
295+
<member name="editors/3d/active_selection_box_color" type="Color" setter="" getter="">
296+
The color to use for the active selection box that surrounds selected nodes in the 3D editor viewport. The color's alpha channel influences the selection box's opacity.
297+
[b]Note:[/b] The term "active" indicates that this object is the primary selection used as the basis for certain operations. This is the last selected [Node3D], which can be reordered with [kbd]Shift + Left mouse button[/kbd].
298+
</member>
295299
<member name="editors/3d/default_fov" type="float" setter="" getter="">
296300
The default camera vertical field of view to use in the 3D editor (in degrees). The camera field of view can be adjusted on a per-scene basis using the [b]View[/b] menu at the top of the 3D editor. If a scene had its camera field of view adjusted using the [b]View[/b] menu, this setting is ignored in the scene in question. This setting is also ignored while a [Camera3D] node is being previewed in the editor.
297301
[b]Note:[/b] The editor camera always uses the [b]Keep Height[/b] aspect mode.

editor/editor_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
789789

790790
// Use a similar color to the 2D editor selection.
791791
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/selection_box_color", Color(1.0, 0.5, 0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
792+
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d/active_selection_box_color", Color(1.5, 0.75, 0, 1.0), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
792793
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
793794
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
794795
EDITOR_SETTING_USAGE(Variant::COLOR, PROPERTY_HINT_NONE, "editors/3d_gizmos/gizmo_colors/aabb", Color(0.28, 0.8, 0.82), "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)

editor/plugins/node_3d_editor_plugin.cpp

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,12 @@ void Node3DEditorViewport::_select_clicked(bool p_allow_locked) {
791791

792792
if (p_allow_locked || (selected != nullptr && !_is_node_locked(selected))) {
793793
if (clicked_wants_append) {
794+
Node *active_node = editor_selection->get_selected_node_list().is_empty() ? nullptr : editor_selection->get_selected_node_list().back()->get();
794795
if (editor_selection->is_selected(selected)) {
795796
editor_selection->remove_node(selected);
797+
if (selected != active_node) {
798+
editor_selection->add_node(selected);
799+
}
796800
} else {
797801
editor_selection->add_node(selected);
798802
}
@@ -6242,7 +6246,7 @@ void Node3DEditor::update_transform_gizmo() {
62426246
for (const KeyValue<int, Transform3D> &E : se->subgizmos) {
62436247
Transform3D xf = se->sp->get_global_transform() * se->gizmo->get_subgizmo_transform(E.key);
62446248
gizmo_center += xf.origin;
6245-
if (count == 0 && local_gizmo_coords) {
6249+
if ((unsigned int)count == se->subgizmos.size() - 1 && local_gizmo_coords) {
62466250
gizmo_basis = xf.basis;
62476251
}
62486252
count++;
@@ -6266,7 +6270,7 @@ void Node3DEditor::update_transform_gizmo() {
62666270

62676271
Transform3D xf = sel_item->sp->get_global_transform();
62686272
gizmo_center += xf.origin;
6269-
if (count == 0 && local_gizmo_coords) {
6273+
if (count == selection.size() - 1 && local_gizmo_coords) {
62706274
gizmo_basis = xf.basis;
62716275
}
62726276
count++;
@@ -6275,7 +6279,7 @@ void Node3DEditor::update_transform_gizmo() {
62756279

62766280
gizmo.visible = count > 0;
62776281
gizmo.transform.origin = (count > 0) ? gizmo_center / count : Vector3();
6278-
gizmo.transform.basis = (count == 1) ? gizmo_basis : Basis();
6282+
gizmo.transform.basis = gizmo_basis;
62796283

62806284
for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) {
62816285
viewports[i]->update_transform_gizmo_view();
@@ -6367,23 +6371,33 @@ void Node3DEditor::_generate_selection_boxes() {
63676371
// This lets the user see where the selection is while still having a sense of depth.
63686372
Ref<SurfaceTool> st = memnew(SurfaceTool);
63696373
Ref<SurfaceTool> st_xray = memnew(SurfaceTool);
6374+
Ref<SurfaceTool> active_st = memnew(SurfaceTool);
6375+
Ref<SurfaceTool> active_st_xray = memnew(SurfaceTool);
63706376

63716377
st->begin(Mesh::PRIMITIVE_LINES);
63726378
st_xray->begin(Mesh::PRIMITIVE_LINES);
6379+
active_st->begin(Mesh::PRIMITIVE_LINES);
6380+
active_st_xray->begin(Mesh::PRIMITIVE_LINES);
63736381
for (int i = 0; i < 12; i++) {
63746382
Vector3 a, b;
63756383
aabb.get_edge(i, a, b);
63766384

63776385
st->add_vertex(a);
63786386
st->add_vertex(b);
6387+
active_st->add_vertex(a);
6388+
active_st->add_vertex(b);
63796389
st_xray->add_vertex(a);
63806390
st_xray->add_vertex(b);
6391+
active_st_xray->add_vertex(a);
6392+
active_st_xray->add_vertex(b);
63816393
}
63826394

6395+
const Color selection_box_color = EDITOR_GET("editors/3d/selection_box_color");
6396+
const Color active_selection_box_color = EDITOR_GET("editors/3d/active_selection_box_color");
6397+
63836398
Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D);
63846399
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
63856400
mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6386-
const Color selection_box_color = EDITOR_GET("editors/3d/selection_box_color");
63876401
mat->set_albedo(selection_box_color);
63886402
mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
63896403
st->set_material(mat);
@@ -6397,6 +6411,23 @@ void Node3DEditor::_generate_selection_boxes() {
63976411
mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
63986412
st_xray->set_material(mat_xray);
63996413
selection_box_xray = st_xray->commit();
6414+
6415+
Ref<StandardMaterial3D> active_mat = memnew(StandardMaterial3D);
6416+
active_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6417+
active_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6418+
active_mat->set_albedo(active_selection_box_color);
6419+
active_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6420+
active_st->set_material(active_mat);
6421+
active_selection_box = active_st->commit();
6422+
6423+
Ref<StandardMaterial3D> active_mat_xray = memnew(StandardMaterial3D);
6424+
active_mat_xray->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
6425+
active_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
6426+
active_mat_xray->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true);
6427+
active_mat_xray->set_albedo(active_selection_box_color * Color(1, 1, 1, 0.15));
6428+
active_mat_xray->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
6429+
active_st_xray->set_material(active_mat_xray);
6430+
active_selection_box_xray = active_st_xray->commit();
64006431
}
64016432

64026433
Dictionary Node3DEditor::get_state() const {
@@ -7831,6 +7862,33 @@ void Node3DEditor::update_grid() {
78317862

78327863
void Node3DEditor::_selection_changed() {
78337864
_refresh_menu_icons();
7865+
7866+
const HashMap<Node *, Object *> &selection = editor_selection->get_selection();
7867+
7868+
for (const KeyValue<Node *, Object *> &E : selection) {
7869+
Node3D *sp = Object::cast_to<Node3D>(E.key);
7870+
if (!sp) {
7871+
continue;
7872+
}
7873+
7874+
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
7875+
if (!se) {
7876+
continue;
7877+
}
7878+
7879+
if (sp == editor_selection->get_selected_node_list().back()->get()) {
7880+
RenderingServer::get_singleton()->instance_set_base(se->sbox_instance, active_selection_box->get_rid());
7881+
RenderingServer::get_singleton()->instance_set_base(se->sbox_instance_xray, active_selection_box_xray->get_rid());
7882+
RenderingServer::get_singleton()->instance_set_base(se->sbox_instance_offset, active_selection_box->get_rid());
7883+
RenderingServer::get_singleton()->instance_set_base(se->sbox_instance_xray_offset, active_selection_box_xray->get_rid());
7884+
} else {
7885+
RenderingServer::get_singleton()->instance_set_base(se->sbox_instance, selection_box->get_rid());
7886+
RenderingServer::get_singleton()->instance_set_base(se->sbox_instance_xray, selection_box_xray->get_rid());
7887+
RenderingServer::get_singleton()->instance_set_base(se->sbox_instance_offset, selection_box->get_rid());
7888+
RenderingServer::get_singleton()->instance_set_base(se->sbox_instance_xray_offset, selection_box_xray->get_rid());
7889+
}
7890+
}
7891+
78347892
if (selected && editor_selection->get_selected_node_list().size() != 1) {
78357893
Vector<Ref<Node3DGizmo>> gizmos = selected->get_gizmos();
78367894
for (int i = 0; i < gizmos.size(); i++) {

editor/plugins/node_3d_editor_plugin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,11 @@ class Node3DEditor : public VBoxContainer {
693693
real_t snap_rotate_value;
694694
real_t snap_scale_value;
695695

696+
Ref<ArrayMesh> active_selection_box_xray;
697+
Ref<ArrayMesh> active_selection_box;
696698
Ref<ArrayMesh> selection_box_xray;
697699
Ref<ArrayMesh> selection_box;
700+
698701
RID indicators;
699702
RID indicators_instance;
700703
RID cursor_mesh;

0 commit comments

Comments
 (0)