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

Whether a spatial view is 2d or 3d is now reevaluated over time unless picked explicitly #1660

Merged
merged 2 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/auto_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) fn tree_from_space_views(
let aspect_ratio = match space_view.category {
ViewCategory::Spatial => {
let state_spatial = &space_view.view_state.state_spatial;
match state_spatial.nav_mode {
match *state_spatial.nav_mode.get() {
// This is the only thing where the aspect ratio makes complete sense.
super::view_spatial::SpatialNavigationMode::TwoD => {
let size = state_spatial.scene_bbox_accum.size();
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ fn entity_props_ui(
}
ui.end_row();

if view_state.state_spatial.nav_mode == SpatialNavigationMode::ThreeD {
if *view_state.state_spatial.nav_mode.get() == SpatialNavigationMode::ThreeD {
if let Some(entity_path) = entity_path {
pinhole_props_ui(ctx, ui, entity_path, entity_props);
depth_props_ui(ctx, ui, entity_path, entity_props);
Expand Down
37 changes: 21 additions & 16 deletions crates/re_viewer/src/ui/view_spatial/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::{
};

/// Describes how the scene is navigated, determining if it is a 2D or 3D experience.
#[derive(Clone, Copy, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub enum SpatialNavigationMode {
#[default]
TwoD,
Expand Down Expand Up @@ -56,7 +56,7 @@ impl From<AutoSizeUnit> for WidgetText {
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub struct ViewSpatialState {
/// How the scene is navigated.
pub nav_mode: SpatialNavigationMode,
pub nav_mode: EditableAutoValue<SpatialNavigationMode>,

/// Estimated bounding box of all data. Accumulated over every time data is displayed.
///
Expand All @@ -82,7 +82,7 @@ pub struct ViewSpatialState {
impl Default for ViewSpatialState {
fn default() -> Self {
Self {
nav_mode: SpatialNavigationMode::ThreeD,
nav_mode: EditableAutoValue::Auto(SpatialNavigationMode::ThreeD),
scene_bbox_accum: BoundingBox::nothing(),
scene_bbox: BoundingBox::nothing(),
scene_num_primitives: 0,
Expand Down Expand Up @@ -314,25 +314,29 @@ impl ViewSpatialState {
ctx.re_ui.grid_left_hand_label(ui, "Camera")
.on_hover_text("The virtual camera which controls what is shown on screen.");
ui.vertical(|ui| {
egui::ComboBox::from_id_source("nav_mode")
.selected_text(self.nav_mode)
let mut nav_mode = *self.nav_mode.get();
let nav_mode_response = egui::ComboBox::from_id_source("nav_mode")
.selected_text(nav_mode)
.show_ui(ui, |ui| {
ui.style_mut().wrap = Some(false);
ui.set_min_width(64.0);

ui.selectable_value(
&mut self.nav_mode,
&mut nav_mode,
SpatialNavigationMode::TwoD,
SpatialNavigationMode::TwoD,
);
ui.selectable_value(
&mut self.nav_mode,
&mut nav_mode,
SpatialNavigationMode::ThreeD,
SpatialNavigationMode::ThreeD,
);
});
}).response;
if nav_mode_response.changed() {
self.nav_mode = EditableAutoValue::UserEdited(nav_mode);
}

if self.nav_mode == SpatialNavigationMode::ThreeD {
if *self.nav_mode.get() == SpatialNavigationMode::ThreeD {
if ui.button("Reset").on_hover_text(
"Resets camera position & orientation.\nYou can also double-click the 3D view.")
.clicked()
Expand All @@ -345,7 +349,7 @@ impl ViewSpatialState {
});
ui.end_row();

if self.nav_mode == SpatialNavigationMode::ThreeD {
if *self.nav_mode.get() == SpatialNavigationMode::ThreeD {
ctx.re_ui.grid_left_hand_label(ui, "Coordinates")
.on_hover_text("The world coordinate system used for this view.");
ui.vertical(|ui|{
Expand Down Expand Up @@ -376,7 +380,7 @@ impl ViewSpatialState {
format_f32(min.y),
format_f32(max.y),
));
if self.nav_mode == SpatialNavigationMode::ThreeD {
if *self.nav_mode.get() == SpatialNavigationMode::ThreeD {
ui.label(format!(
"z [{} - {}]",
format_f32(min.z),
Expand All @@ -399,17 +403,18 @@ impl ViewSpatialState {
highlights: &SpaceViewHighlights,
) {
self.scene_bbox = scene.primitives.bounding_box();
// If this is the first time the bounding box is set, (re-)determine the nav_mode.
// TODO(andreas): Keep track of user edits
if self.scene_bbox_accum.is_nothing() {
self.scene_bbox_accum = self.scene_bbox;
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
self.nav_mode = scene.preferred_navigation_mode(space);
} else {
self.scene_bbox_accum = self.scene_bbox_accum.union(self.scene_bbox);
}

if self.nav_mode.is_auto() {
self.nav_mode = EditableAutoValue::Auto(scene.preferred_navigation_mode(space));
}
self.scene_num_primitives = scene.primitives.num_primitives();

match self.nav_mode {
match *self.nav_mode.get() {
SpatialNavigationMode::ThreeD => {
let coordinates =
query_view_coordinates(&ctx.log_db.entity_db, space, &ctx.current_query());
Expand All @@ -436,7 +441,7 @@ impl ViewSpatialState {
}

pub fn help_text(&self) -> &str {
match self.nav_mode {
match *self.nav_mode.get() {
SpatialNavigationMode::TwoD => super::ui_2d::HELP_TEXT_2D,
SpatialNavigationMode::ThreeD => super::ui_3d::HELP_TEXT_3D,
}
Expand Down