diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 076e4077957..93628b9ab3c 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -3448,58 +3448,16 @@ Vector3 SpatialEditorViewport::_get_instance_position(const Point2 &p_pos) const Vector3 world_ray = _get_ray(p_pos); Vector3 world_pos = _get_ray_pos(p_pos); - Vector instances = VisualServer::get_singleton()->instances_cull_ray(world_pos, world_ray, get_tree()->get_root()->get_world()->get_scenario()); - Set> 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++) { - MeshInstance *mesh_instance = Object::cast_to(ObjectDB::get_instance(instances[i])); + PhysicsDirectSpaceState *ss = get_tree()->get_root()->get_world()->get_direct_space_state(); + PhysicsDirectSpaceState::RayResult result; - if (!mesh_instance) { - continue; - } - - Ref seg = mesh_instance->get_gizmo(); - - 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, nullptr, false); - - 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 SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, bool p_exclude_toplevel_transform) {