Removing bounding box calculations from 3D scene drag and drop and collide against physics rather than visual geometry.

This commit is contained in:
SaracenOne 2021-07-21 20:32:55 +01:00
parent fef27e9b5b
commit fbda490d0f

View File

@ -3782,63 +3782,16 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const
Vector3 world_ray = _get_ray(p_pos);
Vector3 world_pos = _get_ray_pos(p_pos);
Vector<ObjectID> instances = RenderingServer::get_singleton()->instances_cull_ray(world_pos, world_ray, get_tree()->get_root()->get_world_3d()->get_scenario());
Set<Ref<EditorNode3DGizmo>> found_gizmos;
float closest_dist = MAX_DISTANCE;
Vector3 point = world_pos + world_ray * MAX_DISTANCE;
Vector3 normal = Vector3(0.0, 0.0, 0.0);
for (int i = 0; i < instances.size(); i++) {
MeshInstance3D *mesh_instance = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(instances[i]));
PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state();
PhysicsDirectSpaceState3D::RayResult result;
if (!mesh_instance) {
continue;
}
Vector<Ref<Node3DGizmo>> gizmos = mesh_instance->get_gizmos();
for (int j = 0; j < gizmos.size(); j++) {
Ref<EditorNode3DGizmo> seg = gizmos[j];
if ((!seg.is_valid()) || found_gizmos.has(seg)) {
continue;
}
found_gizmos.insert(seg);
Vector3 hit_point;
Vector3 hit_normal;
bool inters = seg->intersect_ray(camera, p_pos, hit_point, hit_normal);
if (!inters) {
continue;
}
float dist = world_pos.distance_to(hit_point);
if (dist < 0) {
continue;
}
if (dist < closest_dist) {
closest_dist = dist;
point = hit_point;
normal = hit_normal;
}
}
if (ss->intersect_ray(world_pos, world_pos + world_ray * MAX_DISTANCE, result)) {
point = result.position;
}
Vector3 offset = Vector3();
for (int i = 0; i < 3; i++) {
if (normal[i] > 0.0) {
offset[i] = (preview_bounds->get_size()[i] - (preview_bounds->get_size()[i] + preview_bounds->get_position()[i]));
} else if (normal[i] < 0.0) {
offset[i] = -(preview_bounds->get_size()[i] + preview_bounds->get_position()[i]);
}
}
return point + offset;
return point;
}
AABB Node3DEditorViewport::_calculate_spatial_bounds(const Node3D *p_parent, bool p_exclude_top_level_transform) {