Skip to content

Commit

Permalink
enable grid in 3d views, some tweaks, make alpha picker always show up
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Nov 28, 2024
1 parent 49933e1 commit 0c53396
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions crates/viewer/re_component_ui/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_renderer/shader/world_grid.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct WorldGridUniformBuffer {
var<uniform> config: WorldGridUniformBuffer;

struct VertexOutput {
@builtin(position)W
@builtin(position)
position: vec4f,

@location(0)
Expand Down
56 changes: 55 additions & 1 deletion crates/viewer/re_space_view_spatial/src/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -667,6 +672,16 @@ impl SpatialSpaceView3D {
view_builder.queue_draw(draw_data);
}

// Optional 3D line grid.
let grid_config = ViewProperty::from_archetype::<LineGrid3D>(
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()?);

Expand Down Expand Up @@ -701,6 +716,45 @@ impl SpatialSpaceView3D {

Ok(())
}

fn setup_grid_3d(
&self,
ctx: &ViewerContext<'_>,
grid_config: &ViewProperty,
state: &SpatialSpaceViewState,
) -> Result<Option<re_renderer::renderer::WorldGridDrawData>, SpaceViewSystemExecutionError>
{
if !**grid_config.component_or_fallback::<Visible>(ctx, self, state)? {
return Ok(None);
}

let spacing = **grid_config.component_or_fallback::<GridSpacing>(ctx, self, state)?;
let thickness_ui =
(**grid_config.component_or_fallback::<UiRadius>(ctx, self, state)?) * 2.0;
let color =
grid_config.component_or_fallback::<re_types::components::Color>(ctx, self, state)?;
let orientation =
grid_config.component_or_fallback::<PlaneOrientation>(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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl TypedComponentFallbackProvider<Color> 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()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/re_viewport_blueprint/src/view_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: re_types::Component + Default>(
pub fn component_or_fallback<C: re_types::Component>(
&self,
ctx: &ViewerContext<'_>,
fallback_provider: &dyn ComponentFallbackProvider,
Expand All @@ -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<C: re_types::Component + Default>(
pub fn component_array_or_fallback<C: re_types::Component>(
&self,
ctx: &ViewerContext<'_>,
fallback_provider: &dyn ComponentFallbackProvider,
Expand Down

0 comments on commit 0c53396

Please sign in to comment.