From 0c53396a4cf23b334dd25d64034c8b49c70cbb15 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 27 Nov 2024 15:54:54 +0100 Subject: [PATCH] enable grid in 3d views, some tweaks, make alpha picker always show up --- .../components/plane_orientation.fbs | 4 +- .../blueprint/components/plane_orientation.rs | 2 +- crates/viewer/re_component_ui/src/color.rs | 5 +- .../viewer/re_renderer/shader/world_grid.wgsl | 2 +- .../viewer/re_space_view_spatial/src/ui_3d.rs | 56 ++++++++++++++++++- .../src/view_3d_properties.rs | 2 +- .../src/view_properties.rs | 4 +- 7 files changed, 64 insertions(+), 11 deletions(-) diff --git a/crates/store/re_types/definitions/rerun/blueprint/components/plane_orientation.fbs b/crates/store/re_types/definitions/rerun/blueprint/components/plane_orientation.fbs index 424c3207d03ea..aba3db30ae986 100644 --- a/crates/store/re_types/definitions/rerun/blueprint/components/plane_orientation.fbs +++ b/crates/store/re_types/definitions/rerun/blueprint/components/plane_orientation.fbs @@ -8,9 +8,9 @@ enum PlaneOrientation: ubyte ( Invalid = 0, /// Plane spanned by X and Z axis. - Xz (default), + Xz, /// Plane spanned by Y and Z axis. Yz, /// Plane spanned by X and Y axis. - Xy, + Xy (default), // we default to RFU cameras in the view. } diff --git a/crates/store/re_types/src/blueprint/components/plane_orientation.rs b/crates/store/re_types/src/blueprint/components/plane_orientation.rs index 5795db5aaf56b..970aa3310487f 100644 --- a/crates/store/re_types/src/blueprint/components/plane_orientation.rs +++ b/crates/store/re_types/src/blueprint/components/plane_orientation.rs @@ -24,13 +24,13 @@ use ::re_types_core::{DeserializationError, DeserializationResult}; #[repr(u8)] pub enum PlaneOrientation { /// Plane spanned by X and Z axis. - #[default] Xz = 1, /// Plane spanned by Y and Z axis. Yz = 2, /// Plane spanned by X and Y axis. + #[default] Xy = 3, } diff --git a/crates/viewer/re_component_ui/src/color.rs b/crates/viewer/re_component_ui/src/color.rs index 48392540adf18..09114a1622534 100644 --- a/crates/viewer/re_component_ui/src/color.rs +++ b/crates/viewer/re_component_ui/src/color.rs @@ -19,9 +19,8 @@ fn edit_rgba32_impl(ui: &mut egui::Ui, color: &mut MaybeMutRef<'_, Rgba32>) -> e let response = egui::color_picker::color_edit_button_srgba( ui, &mut edit_color, - // TODO(#1611): No transparency supported right now. - // Once we do we probably need to be more explicit about the component semantics. - egui::color_picker::Alpha::Opaque, + // TODO(#1611): Most of the time this doesn't do anything. Would be great to distinguish that. + egui::color_picker::Alpha::OnlyBlend, ); *color = edit_color.into(); response diff --git a/crates/viewer/re_renderer/shader/world_grid.wgsl b/crates/viewer/re_renderer/shader/world_grid.wgsl index 49f0a0b8fb8b8..b9276b61b5ea5 100644 --- a/crates/viewer/re_renderer/shader/world_grid.wgsl +++ b/crates/viewer/re_renderer/shader/world_grid.wgsl @@ -18,7 +18,7 @@ struct WorldGridUniformBuffer { var config: WorldGridUniformBuffer; struct VertexOutput { - @builtin(position)W + @builtin(position) position: vec4f, @location(0) diff --git a/crates/viewer/re_space_view_spatial/src/ui_3d.rs b/crates/viewer/re_space_view_spatial/src/ui_3d.rs index ca723785eb9c5..1d7b98a33a39c 100644 --- a/crates/viewer/re_space_view_spatial/src/ui_3d.rs +++ b/crates/viewer/re_space_view_spatial/src/ui_3d.rs @@ -13,7 +13,12 @@ use re_space_view::controls::{ ROTATE3D_BUTTON, SPEED_UP_3D_MODIFIER, TRACKED_OBJECT_RESTORE_KEY, }; use re_types::{ - blueprint::archetypes::Background, components::ViewCoordinates, view_coordinates::SignedAxis3, + blueprint::{ + archetypes::{Background, LineGrid3D}, + components::{GridSpacing, PlaneOrientation, UiRadius, Visible}, + }, + components::ViewCoordinates, + view_coordinates::SignedAxis3, }; use re_ui::{ContextExt, ModifiersMarkdown, MouseButtonMarkdown}; use re_viewer_context::{ @@ -667,6 +672,16 @@ impl SpatialSpaceView3D { view_builder.queue_draw(draw_data); } + // Optional 3D line grid. + let grid_config = ViewProperty::from_archetype::( + ctx.blueprint_db(), + ctx.blueprint_query, + query.space_view_id, + ); + if let Some(draw_data) = self.setup_grid_3d(ctx, &grid_config, state)? { + view_builder.queue_draw(draw_data); + } + // Commit ui induced lines. view_builder.queue_draw(line_builder.into_draw_data()?); @@ -701,6 +716,45 @@ impl SpatialSpaceView3D { Ok(()) } + + fn setup_grid_3d( + &self, + ctx: &ViewerContext<'_>, + grid_config: &ViewProperty, + state: &SpatialSpaceViewState, + ) -> Result, SpaceViewSystemExecutionError> + { + if !**grid_config.component_or_fallback::(ctx, self, state)? { + return Ok(None); + } + + let spacing = **grid_config.component_or_fallback::(ctx, self, state)?; + let thickness_ui = + (**grid_config.component_or_fallback::(ctx, self, state)?) * 2.0; + let color = + grid_config.component_or_fallback::(ctx, self, state)?; + let orientation = + grid_config.component_or_fallback::(ctx, self, state)?; + let plane = match orientation { + PlaneOrientation::Xy => re_math::Plane3::XY, + PlaneOrientation::Yz => re_math::Plane3::YZ, + PlaneOrientation::Xz => re_math::Plane3::ZX, + }; + + let Some(render_ctx) = ctx.render_ctx else { + return Ok(None); + }; + + Ok(Some(re_renderer::renderer::WorldGridDrawData::new( + render_ctx, + &re_renderer::renderer::WorldGridConfiguration { + color: color.into(), + plane, + spacing, + thickness_ui, + }, + ))) + } } /// Show center of orbit camera when interacting with camera (it's quite helpful). diff --git a/crates/viewer/re_space_view_spatial/src/view_3d_properties.rs b/crates/viewer/re_space_view_spatial/src/view_3d_properties.rs index a211ee3b64e4a..5c37d70c1a724 100644 --- a/crates/viewer/re_space_view_spatial/src/view_3d_properties.rs +++ b/crates/viewer/re_space_view_spatial/src/view_3d_properties.rs @@ -16,7 +16,7 @@ impl TypedComponentFallbackProvider for SpatialSpaceView3D { if ctx.archetype_name == Some(Background::name()) { Color::WHITE } else if ctx.archetype_name == Some(LineGrid3D::name()) { - Color::from_unmultiplied_rgba(200, 200, 200, 200) + Color::from_unmultiplied_rgba(128, 128, 128, 128) } else { Color::default() } diff --git a/crates/viewer/re_viewport_blueprint/src/view_properties.rs b/crates/viewer/re_viewport_blueprint/src/view_properties.rs index 2216e84555a14..f9d4cfae2204d 100644 --- a/crates/viewer/re_viewport_blueprint/src/view_properties.rs +++ b/crates/viewer/re_viewport_blueprint/src/view_properties.rs @@ -83,7 +83,7 @@ impl ViewProperty { /// Get the value of a specific component or its fallback if the component is not present. // TODO(andreas): Unfortunately we can't use TypedComponentFallbackProvider here because it may not be implemented for all components of interest. // This sadly means that there's a bit of unnecessary back and forth between arrow array and untyped that could be avoided otherwise. - pub fn component_or_fallback( + pub fn component_or_fallback( &self, ctx: &ViewerContext<'_>, fallback_provider: &dyn ComponentFallbackProvider, @@ -96,7 +96,7 @@ impl ViewProperty { } /// Get the component array for a given type or its fallback if the component is not present or empty. - pub fn component_array_or_fallback( + pub fn component_array_or_fallback( &self, ctx: &ViewerContext<'_>, fallback_provider: &dyn ComponentFallbackProvider,