Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double-clicking an entity in the blueprint & time panels focuses the 3D camera on it #4799

Merged
merged 15 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/re_data_ui/src/item_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use egui::Ui;
use re_entity_db::{EntityTree, InstancePath};
use re_log_types::{ComponentPath, EntityPath, TimeInt, Timeline};
use re_viewer_context::{
DataQueryId, HoverHighlight, Item, Selection, SpaceViewId, UiVerbosity, ViewerContext,
DataQueryId, HoverHighlight, Item, Selection, SpaceViewId, SystemCommandSender, UiVerbosity,
ViewerContext,
};

use super::DataUi;
Expand Down Expand Up @@ -339,6 +340,13 @@ pub fn select_hovered_on_click(
selection_state.set_hovered(selection.clone());
}

if response.double_clicked() {
if let Some((item, _)) = selection.first() {
ctx.command_sender
.send_system(re_viewer_context::SystemCommand::SetFocus(item.clone()));
}
}

if response.clicked() {
if response.ctx.input(|i| i.modifiers.command) {
selection_state.toggle_selection(selection);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view/src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub const ROLL_MOUSE_MODIFIER: egui::Modifiers = egui::Modifiers::ALT;
pub const SPEED_UP_3D_MODIFIER: egui::Modifiers = egui::Modifiers::SHIFT;

/// Key to restore the camera.
pub const TRACKED_CAMERA_RESTORE_KEY: egui::Key = egui::Key::Escape;
pub const TRACKED_OBJECT_RESTORE_KEY: egui::Key = egui::Key::Escape;

/// Description text for which action resets a space view.
pub const RESET_VIEW_BUTTON_TEXT: &str = "double click";
Expand Down
1 change: 1 addition & 0 deletions crates/re_space_view_spatial/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod instance_hash_conversions;
mod mesh_cache;
mod mesh_loader;
mod picking;
mod scene_bounding_boxes;
mod space_camera_3d;
mod space_view_2d;
mod space_view_3d;
Expand Down
60 changes: 60 additions & 0 deletions crates/re_space_view_spatial/src/scene_bounding_boxes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use nohash_hasher::IntMap;
use re_log_types::EntityPathHash;
use re_viewer_context::VisualizerCollection;

use crate::visualizers::SpatialViewVisualizerData;

#[derive(Clone)]
pub struct SceneBoundingBoxes {
/// Accumulated bounding box over several frames.
pub accumulated: macaw::BoundingBox,

/// Overall bounding box of the scene for the current query.
pub current: macaw::BoundingBox,

/// Per-entity bounding boxes for the current query.
pub per_entity: IntMap<EntityPathHash, macaw::BoundingBox>,
}

impl Default for SceneBoundingBoxes {
fn default() -> Self {
Self {
accumulated: macaw::BoundingBox::nothing(),
current: macaw::BoundingBox::nothing(),
per_entity: IntMap::default(),
}
}
}

impl SceneBoundingBoxes {
pub fn update(&mut self, visualizers: &VisualizerCollection) {
re_tracing::profile_function!();

self.current = macaw::BoundingBox::nothing();
self.per_entity = IntMap::default();
Wumpf marked this conversation as resolved.
Show resolved Hide resolved

for visualizer in visualizers.iter() {
if let Some(data) = visualizer
.data()
.and_then(|d| d.downcast_ref::<SpatialViewVisualizerData>())
{
for (entity, bbox) in &data.bounding_boxes {
self.per_entity
.entry(*entity)
.and_modify(|bbox_entry| *bbox_entry = bbox_entry.union(*bbox))
.or_insert(*bbox);
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

for bbox in self.per_entity.values() {
self.current = self.current.union(*bbox);
}

if self.accumulated.is_nothing() || !self.accumulated.size().is_finite() {
self.accumulated = self.current;
} else {
self.accumulated = self.accumulated.union(self.current);
}
}
}
13 changes: 6 additions & 7 deletions crates/re_space_view_spatial/src/space_view_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use crate::{
heuristics::{auto_spawn_heuristic, update_object_property_heuristics},
ui::SpatialSpaceViewState,
view_kind::SpatialSpaceViewKind,
visualizers::{
calculate_bounding_box, register_2d_spatial_visualizers, SpatialViewVisualizerData,
},
visualizers::{register_2d_spatial_visualizers, SpatialViewVisualizerData},
};

// TODO(#4388): 2D/3D relationships should be solved via a "SpatialTopology" construct.
Expand Down Expand Up @@ -60,7 +58,7 @@ impl SpaceViewClass for SpatialSpaceView2D {
}

fn preferred_tile_aspect_ratio(&self, state: &Self::State) -> Option<f32> {
let size = state.scene_bbox_accum.size();
let size = state.bounding_boxes.accumulated.size();
Some(size.x / size.y)
}

Expand Down Expand Up @@ -123,7 +121,7 @@ impl SpaceViewClass for SpatialSpaceView2D {
ctx,
ent_paths,
entity_properties,
&state.scene_bbox_accum,
&state.bounding_boxes.accumulated,
SpatialSpaceViewKind::TwoD,
);
}
Expand Down Expand Up @@ -205,8 +203,9 @@ impl SpaceViewClass for SpatialSpaceView2D {
query: &ViewQuery<'_>,
system_output: re_viewer_context::SystemExecutionOutput,
) -> Result<(), SpaceViewSystemExecutionError> {
state.scene_bbox =
calculate_bounding_box(&system_output.view_systems, &mut state.scene_bbox_accum);
re_tracing::profile_function!();

state.bounding_boxes.update(&system_output.view_systems);
state.scene_num_primitives = system_output
.context_systems
.get::<PrimitiveCounter>()?
Expand Down
7 changes: 3 additions & 4 deletions crates/re_space_view_spatial/src/space_view_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
heuristics::{auto_spawn_heuristic, update_object_property_heuristics},
ui::SpatialSpaceViewState,
view_kind::SpatialSpaceViewKind,
visualizers::{calculate_bounding_box, register_3d_spatial_visualizers, CamerasVisualizer},
visualizers::{register_3d_spatial_visualizers, CamerasVisualizer},
};

// TODO(andreas): This context is used to determine whether a 2D entity has a valid transform
Expand Down Expand Up @@ -157,7 +157,7 @@ impl SpaceViewClass for SpatialSpaceView3D {
ctx,
ent_paths,
entity_properties,
&state.scene_bbox_accum,
&state.bounding_boxes.accumulated,
SpatialSpaceViewKind::ThreeD,
);
}
Expand Down Expand Up @@ -185,8 +185,7 @@ impl SpaceViewClass for SpatialSpaceView3D {
) -> Result<(), SpaceViewSystemExecutionError> {
re_tracing::profile_function!();

state.scene_bbox =
calculate_bounding_box(&system_output.view_systems, &mut state.scene_bbox_accum);
state.bounding_boxes.update(&system_output.view_systems);
state.scene_num_primitives = system_output
.context_systems
.get::<PrimitiveCounter>()?
Expand Down
38 changes: 8 additions & 30 deletions crates/re_space_view_spatial/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use re_viewer_context::{

use super::{eye::Eye, ui_2d::View2DState, ui_3d::View3DState};
use crate::heuristics::auto_size_world_heuristic;
use crate::scene_bounding_boxes::SceneBoundingBoxes;
use crate::{
contexts::{AnnotationSceneContext, NonInteractiveEntities},
picking::{PickableUiRect, PickingContext, PickingHitType, PickingResult},
Expand Down Expand Up @@ -48,15 +49,9 @@ impl From<AutoSizeUnit> for WidgetText {
}

/// TODO(andreas): Should turn this "inside out" - [`SpatialSpaceViewState`] should be used by [`View2DState`]/[`View3DState`], not the other way round.
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct SpatialSpaceViewState {
/// Estimated bounding box of all data. Accumulated over every time data is displayed.
///
/// Specify default explicitly, otherwise it will be a box at 0.0 after deserialization.
pub scene_bbox_accum: BoundingBox,

/// Estimated bounding box of all data for the last scene query.
pub scene_bbox: BoundingBox,
pub bounding_boxes: SceneBoundingBoxes,

/// Estimated number of primitives last frame. Used to inform some heuristics.
pub scene_num_primitives: usize,
Expand All @@ -71,23 +66,6 @@ pub struct SpatialSpaceViewState {
auto_size_config: re_renderer::AutoSizeConfig,
}

impl Default for SpatialSpaceViewState {
fn default() -> Self {
Self {
scene_bbox_accum: BoundingBox::nothing(),
scene_bbox: BoundingBox::nothing(),
scene_num_primitives: 0,
state_2d: Default::default(),
state_3d: Default::default(),
auto_size_config: re_renderer::AutoSizeConfig {
point_radius: re_renderer::Size::AUTO, // let re_renderer decide
line_radius: re_renderer::Size::AUTO, // let re_renderer decide
},
previous_picking_result: None,
}
}
}

impl SpaceViewState for SpatialSpaceViewState {
fn as_any(&self) -> &dyn std::any::Any {
self
Expand Down Expand Up @@ -127,7 +105,7 @@ impl SpatialSpaceViewState {

ctx.re_ui.selection_grid(ui, "spatial_settings_ui")
.show(ui, |ui| {
let auto_size_world = auto_size_world_heuristic(&self.scene_bbox_accum, self.scene_num_primitives);
let auto_size_world = auto_size_world_heuristic(&self.bounding_boxes.accumulated, self.scene_num_primitives);

ctx.re_ui.grid_left_hand_label(ui, "Default size");
ui.vertical(|ui| {
Expand Down Expand Up @@ -166,8 +144,8 @@ impl SpatialSpaceViewState {
"Resets camera position & orientation.\nYou can also double-click the 3D view.")
.clicked()
{
self.scene_bbox_accum = self.scene_bbox;
self.state_3d.reset_camera(&self.scene_bbox_accum, &view_coordinates);
self.bounding_boxes.accumulated = self.bounding_boxes.current;
self.state_3d.reset_camera(&self.bounding_boxes.accumulated, &view_coordinates);
}
let mut spin = self.state_3d.spin();
if re_ui.checkbox(ui, &mut spin, "Spin")
Expand Down Expand Up @@ -206,7 +184,7 @@ impl SpatialSpaceViewState {
.on_hover_text("The bounding box encompassing all Entities in the view right now");
ui.vertical(|ui| {
ui.style_mut().wrap = Some(false);
let BoundingBox { min, max } = self.scene_bbox;
let BoundingBox { min, max } = self.bounding_boxes.current;
ui.label(format!(
"x [{} - {}]",
format_f32(min.x),
Expand Down Expand Up @@ -655,7 +633,7 @@ pub fn picking(
SelectedSpaceContext::ThreeD {
space_3d: query.space_origin.clone(),
pos: hovered_point,
tracked_space_camera: state.state_3d.tracked_camera.clone(),
tracked_entity: state.state_3d.tracked_entity.clone(),
point_in_space_cameras: visualizers
.get::<CamerasVisualizer>()?
.space_cameras
Expand Down
5 changes: 3 additions & 2 deletions crates/re_space_view_spatial/src/ui_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ pub fn view_2d(
let available_size = ui.available_size();
let store = ctx.entity_db.store();

let scene_rect_accum = state.bounding_boxes.accumulated;
let scene_rect_accum = egui::Rect::from_min_max(
state.scene_bbox_accum.min.truncate().to_array().into(),
state.scene_bbox_accum.max.truncate().to_array().into(),
scene_rect_accum.min.truncate().to_array().into(),
scene_rect_accum.max.truncate().to_array().into(),
);

// Determine the canvas which determines the extent of the explorable scene coordinates,
Expand Down
Loading
Loading