|
@@ -5823,17 +5823,20 @@ void SpatialEditor::snap_selected_nodes_to_floor() {
|
|
// Priorities for snapping to floor are CollisionShapes, VisualInstances and then origin
|
|
// Priorities for snapping to floor are CollisionShapes, VisualInstances and then origin
|
|
Set<VisualInstance *> vi = _get_child_nodes<VisualInstance>(sp);
|
|
Set<VisualInstance *> vi = _get_child_nodes<VisualInstance>(sp);
|
|
Set<CollisionShape *> cs = _get_child_nodes<CollisionShape>(sp);
|
|
Set<CollisionShape *> cs = _get_child_nodes<CollisionShape>(sp);
|
|
|
|
+ bool found_valid_shape = false;
|
|
|
|
|
|
if (cs.size()) {
|
|
if (cs.size()) {
|
|
AABB aabb;
|
|
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<CollisionShape *>::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;
|
|
found_valid_shape = true;
|
|
}
|
|
}
|
|
- for (Set<CollisionShape *>::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;
|
|
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);
|
|
Vector3 size = aabb.size * Vector3(0.5, 0.0, 0.5);
|
|
from = aabb.position + size;
|
|
from = aabb.position + size;
|
|
position_offset.y = from.y - sp->get_global_transform().origin.y;
|
|
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();
|
|
AABB aabb = vi.front()->get()->get_transformed_aabb();
|
|
for (Set<VisualInstance *>::Element *I = vi.front(); I; I = I->next()) {
|
|
for (Set<VisualInstance *>::Element *I = vi.front(); I; I = I->next()) {
|
|
aabb.merge_with(I->get()->get_transformed_aabb());
|
|
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);
|
|
Vector3 size = aabb.size * Vector3(0.5, 0.0, 0.5);
|
|
from = aabb.position + size;
|
|
from = aabb.position + size;
|
|
position_offset.y = from.y - sp->get_global_transform().origin.y;
|
|
position_offset.y = from.y - sp->get_global_transform().origin.y;
|
|
- } else {
|
|
|
|
|
|
+ } else if (!found_valid_shape) {
|
|
from = sp->get_global_transform().origin;
|
|
from = sp->get_global_transform().origin;
|
|
}
|
|
}
|
|
|
|
|