@@ -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
64026433Dictionary Node3DEditor::get_state () const {
@@ -7831,6 +7862,33 @@ void Node3DEditor::update_grid() {
78317862
78327863void 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++) {
0 commit comments