From 8d4937c1b54abb609f3b215d3eb0452277a17197 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 14 Aug 2024 12:14:17 +0200 Subject: [PATCH 1/3] Fix 2D objects in 3D affecting bounding box and thus causing flickering of automatic pinhole plane distance --- .../src/scene_bounding_boxes.rs | 20 +++++++++++++++++-- crates/viewer/re_space_view_spatial/src/ui.rs | 4 +++- .../re_space_view_spatial/src/view_2d.rs | 2 +- .../re_space_view_spatial/src/view_3d.rs | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs b/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs index 632aacbdde71..fb6e914fac98 100644 --- a/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs +++ b/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs @@ -3,7 +3,7 @@ use nohash_hasher::IntMap; use re_log_types::EntityPathHash; use re_viewer_context::VisualizerCollection; -use crate::visualizers::SpatialViewVisualizerData; +use crate::{view_kind::SpatialSpaceViewKind, visualizers::SpatialViewVisualizerData}; #[derive(Clone)] pub struct SceneBoundingBoxes { @@ -30,7 +30,12 @@ impl Default for SceneBoundingBoxes { } impl SceneBoundingBoxes { - pub fn update(&mut self, ui: &egui::Ui, visualizers: &VisualizerCollection) { + pub fn update( + &mut self, + ui: &egui::Ui, + visualizers: &VisualizerCollection, + space_kind: SpatialSpaceViewKind, + ) { re_tracing::profile_function!(); let previous = self.current; @@ -42,6 +47,17 @@ impl SceneBoundingBoxes { .data() .and_then(|d| d.downcast_ref::()) { + // If we're in a 3D space, but the visualizer is distintivly 2D, don't count it towards the bounding box. + // These visualizers show up when we're on a pinhole camera plane which itself is heuristically fed by the + // bounding box, creating a feedback loop if we were to add it here. + if space_kind == SpatialSpaceViewKind::ThreeD + && data + .preferred_view_kind + .map_or(true, |kind| kind != space_kind) + { + continue; + } + for (entity, bbox) in &data.bounding_boxes { self.per_entity .entry(*entity) diff --git a/crates/viewer/re_space_view_spatial/src/ui.rs b/crates/viewer/re_space_view_spatial/src/ui.rs index 04aeed9263bb..640921166bf0 100644 --- a/crates/viewer/re_space_view_spatial/src/ui.rs +++ b/crates/viewer/re_space_view_spatial/src/ui.rs @@ -97,10 +97,12 @@ impl SpatialSpaceViewState { &mut self, ui: &egui::Ui, system_output: &re_viewer_context::SystemExecutionOutput, + space_kind: SpatialSpaceViewKind, ) -> Result<(), SpaceViewSystemExecutionError> { re_tracing::profile_function!(); - self.bounding_boxes.update(ui, &system_output.view_systems); + self.bounding_boxes + .update(ui, &system_output.view_systems, space_kind); let view_systems = &system_output.view_systems; diff --git a/crates/viewer/re_space_view_spatial/src/view_2d.rs b/crates/viewer/re_space_view_spatial/src/view_2d.rs index e4e3997234d0..c3117d3ec4a8 100644 --- a/crates/viewer/re_space_view_spatial/src/view_2d.rs +++ b/crates/viewer/re_space_view_spatial/src/view_2d.rs @@ -264,7 +264,7 @@ impl SpaceViewClass for SpatialSpaceView2D { re_tracing::profile_function!(); let state = state.downcast_mut::()?; - state.update_frame_statistics(ui, &system_output)?; + state.update_frame_statistics(ui, &system_output, SpatialSpaceViewKind::TwoD)?; self.view_2d(ctx, ui, state, query, system_output) } diff --git a/crates/viewer/re_space_view_spatial/src/view_3d.rs b/crates/viewer/re_space_view_spatial/src/view_3d.rs index dac14cff9e9e..699b81714367 100644 --- a/crates/viewer/re_space_view_spatial/src/view_3d.rs +++ b/crates/viewer/re_space_view_spatial/src/view_3d.rs @@ -437,7 +437,7 @@ impl SpaceViewClass for SpatialSpaceView3D { re_tracing::profile_function!(); let state = state.downcast_mut::()?; - state.update_frame_statistics(ui, &system_output)?; + state.update_frame_statistics(ui, &system_output, SpatialSpaceViewKind::ThreeD)?; self.view_3d(ctx, ui, state, query, system_output) } From 117bf268f88db7f0b2a706572979708ba20998ef Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 14 Aug 2024 12:41:27 +0200 Subject: [PATCH 2/3] count "undecided" objects like cameras into the bounding box --- crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs b/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs index fb6e914fac98..979274391335 100644 --- a/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs +++ b/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs @@ -53,7 +53,7 @@ impl SceneBoundingBoxes { if space_kind == SpatialSpaceViewKind::ThreeD && data .preferred_view_kind - .map_or(true, |kind| kind != space_kind) + .map_or(false, |kind| kind != space_kind) { continue; } From cdce612c142afdc9a493141184c4da8827ca73c8 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 14 Aug 2024 13:34:40 +0200 Subject: [PATCH 3/3] nicer codesmithing --- .../re_space_view_spatial/src/scene_bounding_boxes.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs b/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs index 979274391335..b13cf85fa59d 100644 --- a/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs +++ b/crates/viewer/re_space_view_spatial/src/scene_bounding_boxes.rs @@ -50,11 +50,10 @@ impl SceneBoundingBoxes { // If we're in a 3D space, but the visualizer is distintivly 2D, don't count it towards the bounding box. // These visualizers show up when we're on a pinhole camera plane which itself is heuristically fed by the // bounding box, creating a feedback loop if we were to add it here. - if space_kind == SpatialSpaceViewKind::ThreeD - && data - .preferred_view_kind - .map_or(false, |kind| kind != space_kind) - { + let data_is_only_2d = data + .preferred_view_kind + .map_or(false, |kind| kind == SpatialSpaceViewKind::TwoD); + if space_kind == SpatialSpaceViewKind::ThreeD && data_is_only_2d { continue; }