From 64cbff7e7db957f45afe870e449abe2340f38510 Mon Sep 17 00:00:00 2001 From: jeffuntildeath Date: Thu, 10 Dec 2020 14:44:09 -0600 Subject: [PATCH] Snap To Floor improperly offsets node fix for issue #44282 AABB for collision geometry was being calculated based on parent nodes transform without consideration for collision geometries translation. Also hopefully clarified logic for selecting starting point for ray cast (cherry picked from commit 4f171afecc283af407e53fb0553028ff99a9d696) --- editor/plugins/spatial_editor_plugin.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 26d75f17a11..2c5df7cf83b 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -5823,17 +5823,20 @@ void SpatialEditor::snap_selected_nodes_to_floor() { // Priorities for snapping to floor are CollisionShapes, VisualInstances and then origin Set vi = _get_child_nodes(sp); Set cs = _get_child_nodes(sp); + bool found_valid_shape = false; if (cs.size()) { AABB aabb; - bool found_valid_shape = false; - if (cs.front()->get()->get_shape().is_valid()) { - aabb = sp->get_global_transform().xform(cs.front()->get()->get_shape()->get_debug_mesh()->get_aabb()); + Set::Element *I = cs.front(); + if (I->get()->get_shape().is_valid()) { + CollisionShape *collision_shape = cs.front()->get(); + aabb = collision_shape->get_global_transform().xform(collision_shape->get_shape()->get_debug_mesh()->get_aabb()); found_valid_shape = true; } - for (Set::Element *I = cs.front(); I; I = I->next()) { - if (I->get()->get_shape().is_valid()) { - aabb.merge_with(sp->get_global_transform().xform(I->get()->get_shape()->get_debug_mesh()->get_aabb())); + for (I = I->next(); I; I = I->next()) { + CollisionShape *col_shape = I->get(); + if (col_shape->get_shape().is_valid()) { + aabb.merge_with(col_shape->get_global_transform().xform(col_shape->get_shape()->get_debug_mesh()->get_aabb())); found_valid_shape = true; } } @@ -5841,10 +5844,9 @@ void SpatialEditor::snap_selected_nodes_to_floor() { Vector3 size = aabb.size * Vector3(0.5, 0.0, 0.5); from = aabb.position + size; position_offset.y = from.y - sp->get_global_transform().origin.y; - } else { - from = sp->get_global_transform().origin; } - } else if (vi.size()) { + } + if (!found_valid_shape && vi.size()) { AABB aabb = vi.front()->get()->get_transformed_aabb(); for (Set::Element *I = vi.front(); I; I = I->next()) { aabb.merge_with(I->get()->get_transformed_aabb()); @@ -5852,7 +5854,7 @@ void SpatialEditor::snap_selected_nodes_to_floor() { Vector3 size = aabb.size * Vector3(0.5, 0.0, 0.5); from = aabb.position + size; position_offset.y = from.y - sp->get_global_transform().origin.y; - } else { + } else if (!found_valid_shape) { from = sp->get_global_transform().origin; }