Skip to content

Commit

Permalink
gpu picking in the viewer picks up depth now
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Apr 2, 2023
1 parent 9bbe076 commit b81b862
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions crates/re_viewer/src/ui/view_spatial/scene/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,19 @@ pub fn picking(
if state.closest_opaque_pick.instance_path_hash == InstancePathHash::NONE {
if let Some(gpu_picking_result) = gpu_picking_result {
// TODO(andreas): Pick middle pixel for now. But we soon want to snap to the closest object using a bigger picking rect.
let rect = gpu_picking_result.rect;
let picked_id = gpu_picking_result.picking_id_data
[(rect.width() / 2 + (rect.height() / 2) * rect.width()) as usize];
let picking_rect_position = gpu_picking_result.rect.extent / 2;
let picked_id = gpu_picking_result.picked_id(picking_rect_position);
let picked_object = instance_path_hash_from_picking_layer_id(picked_id);

// TODO(andreas): We're lacking depth information!
state.closest_opaque_pick.instance_path_hash = picked_object;
state.closest_opaque_pick.used_gpu_picking = true;
// It is old data, the object might be gone by now!
if picked_object.is_some() {
// TODO(andreas): Once this is the primary path we should not awkwardly reconstruct the ray_t here. It's entirely correct either!
state.closest_opaque_pick.ray_t = gpu_picking_result
.picked_world_position(picking_rect_position)
.distance(context.ray_in_world.origin);
state.closest_opaque_pick.instance_path_hash = picked_object;
state.closest_opaque_pick.used_gpu_picking = true;
}
} else {
// It is possible that some frames we don't get a picking result and the frame after we get several.
// We need to cache the last picking result and use it until we get a new one or the mouse leaves the screen.
Expand Down

0 comments on commit b81b862

Please sign in to comment.