@@ -10,6 +10,7 @@ use crate::{
10
10
ui:: view_spatial:: eye:: Eye ,
11
11
} ;
12
12
13
+ #[ derive( Clone ) ]
13
14
pub enum AdditionalPickingInfo {
14
15
/// No additional picking information.
15
16
None ,
@@ -21,6 +22,7 @@ pub enum AdditionalPickingInfo {
21
22
GuiOverlay ,
22
23
}
23
24
25
+ #[ derive( Clone ) ]
24
26
pub struct PickingRayHit {
25
27
/// What entity or instance got hit by the picking ray.
26
28
///
@@ -34,6 +36,9 @@ pub struct PickingRayHit {
34
36
35
37
/// Any additional information about the picking hit.
36
38
pub info : AdditionalPickingInfo ,
39
+
40
+ /// True if this picking result came from a GPU picking pass.
41
+ pub used_gpu_picking : bool ,
37
42
}
38
43
39
44
impl PickingRayHit {
@@ -43,10 +48,12 @@ impl PickingRayHit {
43
48
ray_t : t,
44
49
info : AdditionalPickingInfo :: None ,
45
50
depth_offset : 0 ,
51
+ used_gpu_picking : false ,
46
52
}
47
53
}
48
54
}
49
55
56
+ #[ derive( Clone ) ]
50
57
pub struct PickingResult {
51
58
/// Picking ray hit for an opaque object (if any).
52
59
pub opaque_hit : Option < PickingRayHit > ,
@@ -131,11 +138,11 @@ impl PickingState {
131
138
}
132
139
}
133
140
134
- // TODO(andreas): This should be temporary. As we switch over (almost) everything over to gpu based picking this should go away.
135
141
#[ allow( clippy:: too_many_arguments) ]
136
142
pub fn picking (
137
143
render_ctx : & re_renderer:: RenderContext ,
138
144
gpu_readback_identifier : re_renderer:: GpuReadbackIdentifier ,
145
+ previous_picking_result : & Option < PickingResult > ,
139
146
pointer_in_ui : glam:: Vec2 ,
140
147
ui_rect : & egui:: Rect ,
141
148
eye : & Eye ,
@@ -160,6 +167,7 @@ pub fn picking(
160
167
ray_t : f32:: INFINITY ,
161
168
info : AdditionalPickingInfo :: None ,
162
169
depth_offset : 0 ,
170
+ used_gpu_picking : false ,
163
171
} ,
164
172
// Combined, sorted (and partially "hidden") by opaque results later.
165
173
transparent_hits : Vec :: new ( ) ,
@@ -206,9 +214,20 @@ pub fn picking(
206
214
207
215
// TODO(andreas): We're lacking depth information!
208
216
state. closest_opaque_pick . instance_path_hash = picked_object;
217
+ state. closest_opaque_pick . used_gpu_picking = true ;
209
218
} else {
210
- // TODO(andreas): It is * possible* that some frames we don't get a picking result and the frame after we get several.
219
+ // It is possible that some frames we don't get a picking result and the frame after we get several.
211
220
// We need to cache the last picking result and use it until we get a new one or the mouse leaves the screen.
221
+ // (Andreas: On my mac this *actually* happens in very simple scenes, I get occasional frames with 0 and then with 2 picking results!)
222
+ if let Some ( PickingResult {
223
+ opaque_hit : Some ( previous_opaque_hit) ,
224
+ ..
225
+ } ) = previous_picking_result
226
+ {
227
+ if previous_opaque_hit. used_gpu_picking {
228
+ state. closest_opaque_pick = previous_opaque_hit. clone ( ) ;
229
+ }
230
+ }
212
231
}
213
232
}
214
233
@@ -368,6 +387,7 @@ fn picking_textured_rects(
368
387
ray_t : t,
369
388
info : AdditionalPickingInfo :: TexturedRect ( glam:: vec2 ( u, v) ) ,
370
389
depth_offset : rect. depth_offset ,
390
+ used_gpu_picking : false ,
371
391
} ;
372
392
state. check_hit ( 0.0 , picking_hit, rect. multiplicative_tint . a ( ) < 1.0 ) ;
373
393
}
@@ -391,6 +411,7 @@ fn picking_ui_rects(
391
411
ray_t : 0.0 ,
392
412
info : AdditionalPickingInfo :: GuiOverlay ,
393
413
depth_offset : 0 ,
414
+ used_gpu_picking : false ,
394
415
} ,
395
416
false ,
396
417
) ;
0 commit comments