From 64c8d38c9d78b2d5a5151a57e98d8f57946580a1 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 27 Nov 2024 16:25:57 +0100 Subject: [PATCH] introduce plane offset to the world grid --- .../blueprint/archetypes/line_grid_3d.fbs | 17 +-- .../rerun/blueprint/components.fbs | 1 + .../blueprint/components/plane_offset.fbs | 12 ++ .../src/blueprint/archetypes/line_grid3d.rs | 114 ++++++++++------- .../src/blueprint/components/.gitattributes | 1 + .../re_types/src/blueprint/components/mod.rs | 2 + .../src/blueprint/components/plane_offset.rs | 116 ++++++++++++++++++ crates/viewer/re_component_ui/src/lib.rs | 5 +- .../viewer/re_renderer/shader/world_grid.wgsl | 3 + .../re_renderer/src/renderer/world_grid.rs | 3 + .../viewer/re_space_view_spatial/src/ui_3d.rs | 4 +- .../src/blueprint/validation_gen/mod.rs | 2 + crates/viewer/re_viewer/src/reflection/mod.rs | 19 ++- .../reference/types/views/spatial3d_view.md | 3 +- .../blueprint/archetypes/line_grid3d.cpp | 17 ++- .../blueprint/archetypes/line_grid3d.hpp | 41 ++++--- rerun_cpp/src/rerun/blueprint/components.hpp | 1 + .../rerun/blueprint/components/.gitattributes | 1 + .../blueprint/components/plane_offset.hpp | 74 +++++++++++ .../rerun/blueprint/archetypes/line_grid3d.py | 54 +++++--- .../rerun/blueprint/components/.gitattributes | 1 + .../rerun/blueprint/components/__init__.py | 3 + .../blueprint/components/plane_offset.py | 32 +++++ 23 files changed, 431 insertions(+), 95 deletions(-) create mode 100644 crates/store/re_types/definitions/rerun/blueprint/components/plane_offset.fbs create mode 100644 crates/store/re_types/src/blueprint/components/plane_offset.rs create mode 100644 rerun_cpp/src/rerun/blueprint/components/plane_offset.hpp create mode 100644 rerun_py/rerun_sdk/rerun/blueprint/components/plane_offset.py diff --git a/crates/store/re_types/definitions/rerun/blueprint/archetypes/line_grid_3d.fbs b/crates/store/re_types/definitions/rerun/blueprint/archetypes/line_grid_3d.fbs index 4e2b1770ff555..e5052922c5e0d 100644 --- a/crates/store/re_types/definitions/rerun/blueprint/archetypes/line_grid_3d.fbs +++ b/crates/store/re_types/definitions/rerun/blueprint/archetypes/line_grid_3d.fbs @@ -12,19 +12,22 @@ table LineGrid3D ( /// Space between grid lines spacing of one line to the next in scene units. spacing: rerun.blueprint.components.GridSpacing ("attr.rerun.component_optional", nullable, order: 2000); + /// How the grid is oriented. + /// + /// Defaults to whatever plane is determined as the down plane by view coordinates if present. + orientation: rerun.blueprint.components.PlaneOrientation ("attr.rerun.component_optional", nullable, order: 3000); + + /// Offset of the grid along its normal. + offset: rerun.blueprint.components.PlaneOffset ("attr.rerun.component_optional", nullable, order: 4000); + /// How thick the lines should be in ui units. /// /// Default is 0.5 ui unit. - line_radius: rerun.blueprint.components.UiRadius ("attr.rerun.component_optional", nullable, order: 3000); + line_radius: rerun.blueprint.components.UiRadius ("attr.rerun.component_optional", nullable, order: 5000); /// Color used for the grid. /// /// Transparency via alpha channel is supported. /// Defaults to a slightly transparent light gray. - color: rerun.components.Color ("attr.rerun.component_optional", nullable, order: 4000); - - /// How the grid is oriented. - /// - /// Defaults to whatever plane is determined as the down plane by view coordinates if present. - orientation: rerun.blueprint.components.PlaneOrientation ("attr.rerun.component_optional", nullable, order: 5000); + color: rerun.components.Color ("attr.rerun.component_optional", nullable, order: 6000); } diff --git a/crates/store/re_types/definitions/rerun/blueprint/components.fbs b/crates/store/re_types/definitions/rerun/blueprint/components.fbs index 91ba42ef06013..e2bf2ff711ad9 100644 --- a/crates/store/re_types/definitions/rerun/blueprint/components.fbs +++ b/crates/store/re_types/definitions/rerun/blueprint/components.fbs @@ -19,6 +19,7 @@ include "./components/interactive.fbs"; include "./components/lock_range_during_zoom.fbs"; include "./components/map_provider.fbs"; include "./components/panel_state.fbs"; +include "./components/plane_offset.fbs"; include "./components/plane_orientation.fbs"; include "./components/query_expression.fbs"; include "./components/root_container.fbs"; diff --git a/crates/store/re_types/definitions/rerun/blueprint/components/plane_offset.fbs b/crates/store/re_types/definitions/rerun/blueprint/components/plane_offset.fbs new file mode 100644 index 0000000000000..9a6b3008b8b1f --- /dev/null +++ b/crates/store/re_types/definitions/rerun/blueprint/components/plane_offset.fbs @@ -0,0 +1,12 @@ +namespace rerun.blueprint.components; + +/// Offset of a plane along its normal in scene units. +table PlaneOffset ( + "attr.python.aliases": "float", + "attr.python.array_aliases": "npt.ArrayLike", + "attr.rust.derive": "Default", + "attr.rerun.scope": "blueprint" +) { + /// Offset of a plane along its normal in scene units. + distance: rerun.datatypes.Float32 (order: 100); +} diff --git a/crates/store/re_types/src/blueprint/archetypes/line_grid3d.rs b/crates/store/re_types/src/blueprint/archetypes/line_grid3d.rs index 2e43b993235b3..9bfb3371c86d9 100644 --- a/crates/store/re_types/src/blueprint/archetypes/line_grid3d.rs +++ b/crates/store/re_types/src/blueprint/archetypes/line_grid3d.rs @@ -29,6 +29,14 @@ pub struct LineGrid3D { /// Space between grid lines spacing of one line to the next in scene units. pub spacing: Option, + /// How the grid is oriented. + /// + /// Defaults to whatever plane is determined as the down plane by view coordinates if present. + pub orientation: Option, + + /// Offset of the grid along its normal. + pub offset: Option, + /// How thick the lines should be in ui units. /// /// Default is 0.5 ui unit. @@ -39,11 +47,6 @@ pub struct LineGrid3D { /// Transparency via alpha channel is supported. /// Defaults to a slightly transparent light gray. pub color: Option, - - /// How the grid is oriented. - /// - /// Defaults to whatever plane is determined as the down plane by view coordinates if present. - pub orientation: Option, } impl ::re_types_core::SizeBytes for LineGrid3D { @@ -51,18 +54,20 @@ impl ::re_types_core::SizeBytes for LineGrid3D { fn heap_size_bytes(&self) -> u64 { self.visible.heap_size_bytes() + self.spacing.heap_size_bytes() + + self.orientation.heap_size_bytes() + + self.offset.heap_size_bytes() + self.line_radius.heap_size_bytes() + self.color.heap_size_bytes() - + self.orientation.heap_size_bytes() } #[inline] fn is_pod() -> bool { >::is_pod() && >::is_pod() + && >::is_pod() + && >::is_pod() && >::is_pod() && >::is_pod() - && >::is_pod() } } @@ -72,32 +77,34 @@ static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 0usize]> = static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 1usize]> = once_cell::sync::Lazy::new(|| ["rerun.blueprint.components.LineGrid3DIndicator".into()]); -static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 5usize]> = +static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 6usize]> = once_cell::sync::Lazy::new(|| { [ "rerun.blueprint.components.Visible".into(), "rerun.blueprint.components.GridSpacing".into(), + "rerun.blueprint.components.PlaneOrientation".into(), + "rerun.blueprint.components.PlaneOffset".into(), "rerun.blueprint.components.UiRadius".into(), "rerun.components.Color".into(), - "rerun.blueprint.components.PlaneOrientation".into(), ] }); -static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 6usize]> = +static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 7usize]> = once_cell::sync::Lazy::new(|| { [ "rerun.blueprint.components.LineGrid3DIndicator".into(), "rerun.blueprint.components.Visible".into(), "rerun.blueprint.components.GridSpacing".into(), + "rerun.blueprint.components.PlaneOrientation".into(), + "rerun.blueprint.components.PlaneOffset".into(), "rerun.blueprint.components.UiRadius".into(), "rerun.components.Color".into(), - "rerun.blueprint.components.PlaneOrientation".into(), ] }); impl LineGrid3D { - /// The total number of components in the archetype: 0 required, 1 recommended, 5 optional - pub const NUM_COMPONENTS: usize = 6usize; + /// The total number of components in the archetype: 0 required, 1 recommended, 6 optional + pub const NUM_COMPONENTS: usize = 7usize; } /// Indicator component for the [`LineGrid3D`] [`::re_types_core::Archetype`] @@ -172,6 +179,27 @@ impl ::re_types_core::Archetype for LineGrid3D { } else { None }; + let orientation = if let Some(array) = + arrays_by_name.get("rerun.blueprint.components.PlaneOrientation") + { + ::from_arrow2_opt(&**array) + .with_context("rerun.blueprint.archetypes.LineGrid3D#orientation")? + .into_iter() + .next() + .flatten() + } else { + None + }; + let offset = + if let Some(array) = arrays_by_name.get("rerun.blueprint.components.PlaneOffset") { + ::from_arrow2_opt(&**array) + .with_context("rerun.blueprint.archetypes.LineGrid3D#offset")? + .into_iter() + .next() + .flatten() + } else { + None + }; let line_radius = if let Some(array) = arrays_by_name.get("rerun.blueprint.components.UiRadius") { ::from_arrow2_opt(&**array) @@ -191,23 +219,13 @@ impl ::re_types_core::Archetype for LineGrid3D { } else { None }; - let orientation = if let Some(array) = - arrays_by_name.get("rerun.blueprint.components.PlaneOrientation") - { - ::from_arrow2_opt(&**array) - .with_context("rerun.blueprint.archetypes.LineGrid3D#orientation")? - .into_iter() - .next() - .flatten() - } else { - None - }; Ok(Self { visible, spacing, + orientation, + offset, line_radius, color, - orientation, }) } } @@ -224,13 +242,16 @@ impl ::re_types_core::AsComponents for LineGrid3D { self.spacing .as_ref() .map(|comp| (comp as &dyn ComponentBatch).into()), - self.line_radius + self.orientation .as_ref() .map(|comp| (comp as &dyn ComponentBatch).into()), - self.color + self.offset .as_ref() .map(|comp| (comp as &dyn ComponentBatch).into()), - self.orientation + self.line_radius + .as_ref() + .map(|comp| (comp as &dyn ComponentBatch).into()), + self.color .as_ref() .map(|comp| (comp as &dyn ComponentBatch).into()), ] @@ -249,9 +270,10 @@ impl LineGrid3D { Self { visible: None, spacing: None, + orientation: None, + offset: None, line_radius: None, color: None, - orientation: None, } } @@ -277,6 +299,28 @@ impl LineGrid3D { self } + /// How the grid is oriented. + /// + /// Defaults to whatever plane is determined as the down plane by view coordinates if present. + #[inline] + pub fn with_orientation( + mut self, + orientation: impl Into, + ) -> Self { + self.orientation = Some(orientation.into()); + self + } + + /// Offset of the grid along its normal. + #[inline] + pub fn with_offset( + mut self, + offset: impl Into, + ) -> Self { + self.offset = Some(offset.into()); + self + } + /// How thick the lines should be in ui units. /// /// Default is 0.5 ui unit. @@ -298,16 +342,4 @@ impl LineGrid3D { self.color = Some(color.into()); self } - - /// How the grid is oriented. - /// - /// Defaults to whatever plane is determined as the down plane by view coordinates if present. - #[inline] - pub fn with_orientation( - mut self, - orientation: impl Into, - ) -> Self { - self.orientation = Some(orientation.into()); - self - } } diff --git a/crates/store/re_types/src/blueprint/components/.gitattributes b/crates/store/re_types/src/blueprint/components/.gitattributes index 1abe730df77ba..4ac1300d4535d 100644 --- a/crates/store/re_types/src/blueprint/components/.gitattributes +++ b/crates/store/re_types/src/blueprint/components/.gitattributes @@ -16,6 +16,7 @@ lock_range_during_zoom.rs linguist-generated=true map_provider.rs linguist-generated=true mod.rs linguist-generated=true panel_state.rs linguist-generated=true +plane_offset.rs linguist-generated=true plane_orientation.rs linguist-generated=true query_expression.rs linguist-generated=true row_share.rs linguist-generated=true diff --git a/crates/store/re_types/src/blueprint/components/mod.rs b/crates/store/re_types/src/blueprint/components/mod.rs index 320a46e1001a8..cc8a1bd5c3879 100644 --- a/crates/store/re_types/src/blueprint/components/mod.rs +++ b/crates/store/re_types/src/blueprint/components/mod.rs @@ -21,6 +21,7 @@ mod lock_range_during_zoom; mod map_provider; mod panel_state; mod panel_state_ext; +mod plane_offset; mod plane_orientation; mod query_expression; mod row_share; @@ -58,6 +59,7 @@ pub use self::interactive::Interactive; pub use self::lock_range_during_zoom::LockRangeDuringZoom; pub use self::map_provider::MapProvider; pub use self::panel_state::PanelState; +pub use self::plane_offset::PlaneOffset; pub use self::plane_orientation::PlaneOrientation; pub use self::query_expression::QueryExpression; pub use self::row_share::RowShare; diff --git a/crates/store/re_types/src/blueprint/components/plane_offset.rs b/crates/store/re_types/src/blueprint/components/plane_offset.rs new file mode 100644 index 0000000000000..3a1fd0170e8d3 --- /dev/null +++ b/crates/store/re_types/src/blueprint/components/plane_offset.rs @@ -0,0 +1,116 @@ +// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs +// Based on "crates/store/re_types/definitions/rerun/blueprint/components/plane_offset.fbs". + +#![allow(unused_imports)] +#![allow(unused_parens)] +#![allow(clippy::clone_on_copy)] +#![allow(clippy::cloned_instead_of_copied)] +#![allow(clippy::map_flatten)] +#![allow(clippy::needless_question_mark)] +#![allow(clippy::new_without_default)] +#![allow(clippy::redundant_closure)] +#![allow(clippy::too_many_arguments)] +#![allow(clippy::too_many_lines)] + +use ::re_types_core::external::arrow2; +use ::re_types_core::ComponentName; +use ::re_types_core::SerializationResult; +use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; +use ::re_types_core::{DeserializationError, DeserializationResult}; + +/// **Component**: Offset of a plane along its normal in scene units. +#[derive(Clone, Debug, Default)] +pub struct PlaneOffset( + /// Offset of a plane along its normal in scene units. + pub crate::datatypes::Float32, +); + +impl ::re_types_core::SizeBytes for PlaneOffset { + #[inline] + fn heap_size_bytes(&self) -> u64 { + self.0.heap_size_bytes() + } + + #[inline] + fn is_pod() -> bool { + ::is_pod() + } +} + +impl> From for PlaneOffset { + fn from(v: T) -> Self { + Self(v.into()) + } +} + +impl std::borrow::Borrow for PlaneOffset { + #[inline] + fn borrow(&self) -> &crate::datatypes::Float32 { + &self.0 + } +} + +impl std::ops::Deref for PlaneOffset { + type Target = crate::datatypes::Float32; + + #[inline] + fn deref(&self) -> &crate::datatypes::Float32 { + &self.0 + } +} + +impl std::ops::DerefMut for PlaneOffset { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Float32 { + &mut self.0 + } +} + +::re_types_core::macros::impl_into_cow!(PlaneOffset); + +impl ::re_types_core::Loggable for PlaneOffset { + #[inline] + fn arrow_datatype() -> arrow::datatypes::DataType { + crate::datatypes::Float32::arrow_datatype() + } + + fn to_arrow_opt<'a>( + data: impl IntoIterator>>>, + ) -> SerializationResult + where + Self: Clone + 'a, + { + crate::datatypes::Float32::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) + } + + fn from_arrow2_opt( + arrow_data: &dyn arrow2::array::Array, + ) -> DeserializationResult>> + where + Self: Sized, + { + crate::datatypes::Float32::from_arrow2_opt(arrow_data) + .map(|v| v.into_iter().map(|v| v.map(Self)).collect()) + } + + #[inline] + fn from_arrow2(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> + where + Self: Sized, + { + crate::datatypes::Float32::from_arrow2(arrow_data) + .map(|v| v.into_iter().map(Self).collect()) + } +} + +impl ::re_types_core::Component for PlaneOffset { + #[inline] + fn name() -> ComponentName { + "rerun.blueprint.components.PlaneOffset".into() + } +} diff --git a/crates/viewer/re_component_ui/src/lib.rs b/crates/viewer/re_component_ui/src/lib.rs index 086aad422e9c2..d96d3a4903f79 100644 --- a/crates/viewer/re_component_ui/src/lib.rs +++ b/crates/viewer/re_component_ui/src/lib.rs @@ -34,8 +34,8 @@ use datatype_uis::{ use re_types::{ blueprint::components::{ - BackgroundKind, Corner2D, GridSpacing, LockRangeDuringZoom, MapProvider, PlaneOrientation, - UiRadius, ViewFit, Visible, + BackgroundKind, Corner2D, GridSpacing, LockRangeDuringZoom, MapProvider, PlaneOffset, + PlaneOrientation, UiRadius, ViewFit, Visible, }, components::{ AggregationPolicy, AlbedoFactor, AxisLength, Color, DepthMeter, DrawOrder, FillMode, @@ -82,6 +82,7 @@ pub fn create_component_ui_registry() -> re_viewer_context::ComponentUiRegistry // float min-max components: registry.add_singleline_edit_or_view::(edit_f32_min_to_max_float); + registry.add_singleline_edit_or_view::(edit_f32_min_to_max_float); // float 0-1 components: registry.add_singleline_edit_or_view::(edit_f32_zero_to_one); diff --git a/crates/viewer/re_renderer/shader/world_grid.wgsl b/crates/viewer/re_renderer/shader/world_grid.wgsl index b9276b61b5ea5..960ce177a5c1a 100644 --- a/crates/viewer/re_renderer/shader/world_grid.wgsl +++ b/crates/viewer/re_renderer/shader/world_grid.wgsl @@ -12,6 +12,9 @@ struct WorldGridUniformBuffer { /// How thick the lines are in UI units. thickness_ui: f32, + + /// Offset of the grid along its normal. + normal_offset: f32, } @group(1) @binding(0) diff --git a/crates/viewer/re_renderer/src/renderer/world_grid.rs b/crates/viewer/re_renderer/src/renderer/world_grid.rs index d5c8532a808fd..910ec309ca053 100644 --- a/crates/viewer/re_renderer/src/renderer/world_grid.rs +++ b/crates/viewer/re_renderer/src/renderer/world_grid.rs @@ -28,6 +28,9 @@ pub struct WorldGridConfiguration { /// How thick the lines are in UI units. pub thickness_ui: f32, + + /// Offset of the grid along its normal. + pub normal_offset: f32, } mod gpu_data { 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 1d7b98a33a39c..76ae2912e47a9 100644 --- a/crates/viewer/re_space_view_spatial/src/ui_3d.rs +++ b/crates/viewer/re_space_view_spatial/src/ui_3d.rs @@ -15,7 +15,7 @@ use re_space_view::controls::{ use re_types::{ blueprint::{ archetypes::{Background, LineGrid3D}, - components::{GridSpacing, PlaneOrientation, UiRadius, Visible}, + components::{GridSpacing, PlaneOffset, PlaneOrientation, UiRadius, Visible}, }, components::ViewCoordinates, view_coordinates::SignedAxis3, @@ -740,6 +740,7 @@ impl SpatialSpaceView3D { PlaneOrientation::Yz => re_math::Plane3::YZ, PlaneOrientation::Xz => re_math::Plane3::ZX, }; + let normal_offset = **grid_config.component_or_fallback::(ctx, self, state)?; let Some(render_ctx) = ctx.render_ctx else { return Ok(None); @@ -752,6 +753,7 @@ impl SpatialSpaceView3D { plane, spacing, thickness_ui, + normal_offset, }, ))) } diff --git a/crates/viewer/re_viewer/src/blueprint/validation_gen/mod.rs b/crates/viewer/re_viewer/src/blueprint/validation_gen/mod.rs index 41a555aecfada..fe322613590fa 100644 --- a/crates/viewer/re_viewer/src/blueprint/validation_gen/mod.rs +++ b/crates/viewer/re_viewer/src/blueprint/validation_gen/mod.rs @@ -15,6 +15,7 @@ pub use re_types::blueprint::components::Interactive; pub use re_types::blueprint::components::LockRangeDuringZoom; pub use re_types::blueprint::components::MapProvider; pub use re_types::blueprint::components::PanelState; +pub use re_types::blueprint::components::PlaneOffset; pub use re_types::blueprint::components::PlaneOrientation; pub use re_types::blueprint::components::QueryExpression; pub use re_types::blueprint::components::RowShare; @@ -62,6 +63,7 @@ pub fn is_valid_blueprint(blueprint: &EntityDb) -> bool { && validate_component::(blueprint) && validate_component::(blueprint) && validate_component::(blueprint) + && validate_component::(blueprint) && validate_component::(blueprint) && validate_component::(blueprint) && validate_component::(blueprint) diff --git a/crates/viewer/re_viewer/src/reflection/mod.rs b/crates/viewer/re_viewer/src/reflection/mod.rs index 210b289107e7b..8fff0008c8ca0 100644 --- a/crates/viewer/re_viewer/src/reflection/mod.rs +++ b/crates/viewer/re_viewer/src/reflection/mod.rs @@ -188,6 +188,14 @@ fn generate_component_reflection() -> Result::name(), + ComponentReflection { + docstring_md: "Offset of a plane along its normal in scene units.", + custom_placeholder: Some(PlaneOffset::default().to_arrow2()?), + datatype: PlaneOffset::arrow2_datatype(), + }, + ), ( ::name(), ComponentReflection { @@ -1977,6 +1985,13 @@ fn generate_archetype_reflection() -> ArchetypeReflectionMap { "Spacing", docstring_md : "Space between grid lines spacing of one line to the next in scene units.", is_required : false, }, ArchetypeFieldReflection { component_name : + "rerun.blueprint.components.PlaneOrientation".into(), display_name : + "Orientation", docstring_md : + "How the grid is oriented.\n\nDefaults to whatever plane is determined as the down plane by view coordinates if present.", + is_required : false, }, ArchetypeFieldReflection { component_name : + "rerun.blueprint.components.PlaneOffset".into(), display_name : + "Offset", docstring_md : "Offset of the grid along its normal.", + is_required : false, }, ArchetypeFieldReflection { component_name : "rerun.blueprint.components.UiRadius".into(), display_name : "Line radius", docstring_md : "How thick the lines should be in ui units.\n\nDefault is 0.5 ui unit.", @@ -1984,10 +1999,6 @@ fn generate_archetype_reflection() -> ArchetypeReflectionMap { "rerun.components.Color".into(), display_name : "Color", docstring_md : "Color used for the grid.\n\nTransparency via alpha channel is supported.\nDefaults to a slightly transparent light gray.", - is_required : false, }, ArchetypeFieldReflection { component_name : - "rerun.blueprint.components.PlaneOrientation".into(), display_name : - "Orientation", docstring_md : - "How the grid is oriented.\n\nDefaults to whatever plane is determined as the down plane by view coordinates if present.", is_required : false, }, ], }, diff --git a/docs/content/reference/types/views/spatial3d_view.md b/docs/content/reference/types/views/spatial3d_view.md index 5ff22ffa2e8c3..546e8dc017a69 100644 --- a/docs/content/reference/types/views/spatial3d_view.md +++ b/docs/content/reference/types/views/spatial3d_view.md @@ -17,9 +17,10 @@ Configuration for the 3D line grid. * `visible`: Whether the grid is visible. * `spacing`: Space between grid lines spacing of one line to the next in scene units. +* `orientation`: How the grid is oriented. +* `offset`: Offset of the grid along its normal. * `line_radius`: How thick the lines should be in ui units. * `color`: Color used for the grid. -* `orientation`: How the grid is oriented. ### `time_ranges` Configures which range on each timeline is shown by this view (unless specified differently per entity). diff --git a/rerun_cpp/src/rerun/blueprint/archetypes/line_grid3d.cpp b/rerun_cpp/src/rerun/blueprint/archetypes/line_grid3d.cpp index b7d5e2a8d4574..3a7f27a714850 100644 --- a/rerun_cpp/src/rerun/blueprint/archetypes/line_grid3d.cpp +++ b/rerun_cpp/src/rerun/blueprint/archetypes/line_grid3d.cpp @@ -14,7 +14,7 @@ namespace rerun { ) { using namespace blueprint::archetypes; std::vector cells; - cells.reserve(6); + cells.reserve(7); if (archetype.visible.has_value()) { auto result = ComponentBatch::from_loggable(archetype.visible.value()); @@ -26,6 +26,16 @@ namespace rerun { RR_RETURN_NOT_OK(result.error); cells.push_back(std::move(result.value)); } + if (archetype.orientation.has_value()) { + auto result = ComponentBatch::from_loggable(archetype.orientation.value()); + RR_RETURN_NOT_OK(result.error); + cells.push_back(std::move(result.value)); + } + if (archetype.offset.has_value()) { + auto result = ComponentBatch::from_loggable(archetype.offset.value()); + RR_RETURN_NOT_OK(result.error); + cells.push_back(std::move(result.value)); + } if (archetype.line_radius.has_value()) { auto result = ComponentBatch::from_loggable(archetype.line_radius.value()); RR_RETURN_NOT_OK(result.error); @@ -36,11 +46,6 @@ namespace rerun { RR_RETURN_NOT_OK(result.error); cells.push_back(std::move(result.value)); } - if (archetype.orientation.has_value()) { - auto result = ComponentBatch::from_loggable(archetype.orientation.value()); - RR_RETURN_NOT_OK(result.error); - cells.push_back(std::move(result.value)); - } { auto indicator = LineGrid3D::IndicatorComponent(); auto result = ComponentBatch::from_loggable(indicator); diff --git a/rerun_cpp/src/rerun/blueprint/archetypes/line_grid3d.hpp b/rerun_cpp/src/rerun/blueprint/archetypes/line_grid3d.hpp index 0898bede41ad6..b66da9203486d 100644 --- a/rerun_cpp/src/rerun/blueprint/archetypes/line_grid3d.hpp +++ b/rerun_cpp/src/rerun/blueprint/archetypes/line_grid3d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../../blueprint/components/grid_spacing.hpp" +#include "../../blueprint/components/plane_offset.hpp" #include "../../blueprint/components/plane_orientation.hpp" #include "../../blueprint/components/ui_radius.hpp" #include "../../blueprint/components/visible.hpp" @@ -30,6 +31,14 @@ namespace rerun::blueprint::archetypes { /// Space between grid lines spacing of one line to the next in scene units. std::optional spacing; + /// How the grid is oriented. + /// + /// Defaults to whatever plane is determined as the down plane by view coordinates if present. + std::optional orientation; + + /// Offset of the grid along its normal. + std::optional offset; + /// How thick the lines should be in ui units. /// /// Default is 0.5 ui unit. @@ -41,11 +50,6 @@ namespace rerun::blueprint::archetypes { /// Defaults to a slightly transparent light gray. std::optional color; - /// How the grid is oriented. - /// - /// Defaults to whatever plane is determined as the down plane by view coordinates if present. - std::optional orientation; - public: static constexpr const char IndicatorComponentName[] = "rerun.blueprint.components.LineGrid3DIndicator"; @@ -73,6 +77,23 @@ namespace rerun::blueprint::archetypes { RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } + /// How the grid is oriented. + /// + /// Defaults to whatever plane is determined as the down plane by view coordinates if present. + LineGrid3D with_orientation(rerun::blueprint::components::PlaneOrientation _orientation + ) && { + orientation = std::move(_orientation); + // See: https://github.com/rerun-io/rerun/issues/4027 + RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + + /// Offset of the grid along its normal. + LineGrid3D with_offset(rerun::blueprint::components::PlaneOffset _offset) && { + offset = std::move(_offset); + // See: https://github.com/rerun-io/rerun/issues/4027 + RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + } + /// How thick the lines should be in ui units. /// /// Default is 0.5 ui unit. @@ -91,16 +112,6 @@ namespace rerun::blueprint::archetypes { // See: https://github.com/rerun-io/rerun/issues/4027 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } - - /// How the grid is oriented. - /// - /// Defaults to whatever plane is determined as the down plane by view coordinates if present. - LineGrid3D with_orientation(rerun::blueprint::components::PlaneOrientation _orientation - ) && { - orientation = std::move(_orientation); - // See: https://github.com/rerun-io/rerun/issues/4027 - RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) - } }; } // namespace rerun::blueprint::archetypes diff --git a/rerun_cpp/src/rerun/blueprint/components.hpp b/rerun_cpp/src/rerun/blueprint/components.hpp index e233eb4730fed..1a587448241b4 100644 --- a/rerun_cpp/src/rerun/blueprint/components.hpp +++ b/rerun_cpp/src/rerun/blueprint/components.hpp @@ -21,6 +21,7 @@ #include "blueprint/components/lock_range_during_zoom.hpp" #include "blueprint/components/map_provider.hpp" #include "blueprint/components/panel_state.hpp" +#include "blueprint/components/plane_offset.hpp" #include "blueprint/components/plane_orientation.hpp" #include "blueprint/components/query_expression.hpp" #include "blueprint/components/root_container.hpp" diff --git a/rerun_cpp/src/rerun/blueprint/components/.gitattributes b/rerun_cpp/src/rerun/blueprint/components/.gitattributes index 6e73ffed54f91..9d3407a5233d1 100644 --- a/rerun_cpp/src/rerun/blueprint/components/.gitattributes +++ b/rerun_cpp/src/rerun/blueprint/components/.gitattributes @@ -25,6 +25,7 @@ map_provider.cpp linguist-generated=true map_provider.hpp linguist-generated=true panel_state.cpp linguist-generated=true panel_state.hpp linguist-generated=true +plane_offset.hpp linguist-generated=true plane_orientation.cpp linguist-generated=true plane_orientation.hpp linguist-generated=true query_expression.hpp linguist-generated=true diff --git a/rerun_cpp/src/rerun/blueprint/components/plane_offset.hpp b/rerun_cpp/src/rerun/blueprint/components/plane_offset.hpp new file mode 100644 index 0000000000000..e30aa17157017 --- /dev/null +++ b/rerun_cpp/src/rerun/blueprint/components/plane_offset.hpp @@ -0,0 +1,74 @@ +// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs +// Based on "crates/store/re_types/definitions/rerun/blueprint/components/plane_offset.fbs". + +#pragma once + +#include "../../datatypes/float32.hpp" +#include "../../result.hpp" + +#include +#include + +namespace rerun::blueprint::components { + /// **Component**: Offset of a plane along its normal in scene units. + struct PlaneOffset { + /// Offset of a plane along its normal in scene units. + rerun::datatypes::Float32 distance; + + public: + PlaneOffset() = default; + + PlaneOffset(rerun::datatypes::Float32 distance_) : distance(distance_) {} + + PlaneOffset& operator=(rerun::datatypes::Float32 distance_) { + distance = distance_; + return *this; + } + + PlaneOffset(float value_) : distance(value_) {} + + PlaneOffset& operator=(float value_) { + distance = value_; + return *this; + } + + /// Cast to the underlying Float32 datatype + operator rerun::datatypes::Float32() const { + return distance; + } + }; +} // namespace rerun::blueprint::components + +namespace rerun { + static_assert(sizeof(rerun::datatypes::Float32) == sizeof(blueprint::components::PlaneOffset)); + + /// \private + template <> + struct Loggable { + static constexpr const char Name[] = "rerun.blueprint.components.PlaneOffset"; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype() { + return Loggable::arrow_datatype(); + } + + /// Serializes an array of `rerun::blueprint:: components::PlaneOffset` into an arrow array. + static Result> to_arrow( + const blueprint::components::PlaneOffset* instances, size_t num_instances + ) { + if (num_instances == 0) { + return Loggable::to_arrow(nullptr, 0); + } else if (instances == nullptr) { + return rerun::Error( + ErrorCode::UnexpectedNullArgument, + "Passed array instances is null when num_elements> 0." + ); + } else { + return Loggable::to_arrow( + &instances->distance, + num_instances + ); + } + } + }; +} // namespace rerun diff --git a/rerun_py/rerun_sdk/rerun/blueprint/archetypes/line_grid3d.py b/rerun_py/rerun_sdk/rerun/blueprint/archetypes/line_grid3d.py index b97765275e2b5..e3f0032434451 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/archetypes/line_grid3d.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/archetypes/line_grid3d.py @@ -28,9 +28,10 @@ def __init__( *, visible: datatypes.BoolLike | None = None, spacing: datatypes.Float32Like | None = None, + orientation: blueprint_components.PlaneOrientationLike | None = None, + offset: datatypes.Float32Like | None = None, line_radius: datatypes.Float32Like | None = None, color: datatypes.Rgba32Like | None = None, - orientation: blueprint_components.PlaneOrientationLike | None = None, ): """ Create a new instance of the LineGrid3D archetype. @@ -43,6 +44,12 @@ def __init__( Defaults to true. spacing: Space between grid lines spacing of one line to the next in scene units. + orientation: + How the grid is oriented. + + Defaults to whatever plane is determined as the down plane by view coordinates if present. + offset: + Offset of the grid along its normal. line_radius: How thick the lines should be in ui units. @@ -52,17 +59,18 @@ def __init__( Transparency via alpha channel is supported. Defaults to a slightly transparent light gray. - orientation: - How the grid is oriented. - - Defaults to whatever plane is determined as the down plane by view coordinates if present. """ # You can define your own __init__ function as a member of LineGrid3DExt in line_grid3d_ext.py with catch_and_log_exceptions(context=self.__class__.__name__): self.__attrs_init__( - visible=visible, spacing=spacing, line_radius=line_radius, color=color, orientation=orientation + visible=visible, + spacing=spacing, + orientation=orientation, + offset=offset, + line_radius=line_radius, + color=color, ) return self.__attrs_clear__() @@ -72,9 +80,10 @@ def __attrs_clear__(self) -> None: self.__attrs_init__( visible=None, # type: ignore[arg-type] spacing=None, # type: ignore[arg-type] + orientation=None, # type: ignore[arg-type] + offset=None, # type: ignore[arg-type] line_radius=None, # type: ignore[arg-type] color=None, # type: ignore[arg-type] - orientation=None, # type: ignore[arg-type] ) @classmethod @@ -104,6 +113,26 @@ def _clear(cls) -> LineGrid3D: # # (Docstring intentionally commented out to hide this field from the docs) + orientation: blueprint_components.PlaneOrientationBatch | None = field( + metadata={"component": "optional"}, + default=None, + converter=blueprint_components.PlaneOrientationBatch._optional, # type: ignore[misc] + ) + # How the grid is oriented. + # + # Defaults to whatever plane is determined as the down plane by view coordinates if present. + # + # (Docstring intentionally commented out to hide this field from the docs) + + offset: blueprint_components.PlaneOffsetBatch | None = field( + metadata={"component": "optional"}, + default=None, + converter=blueprint_components.PlaneOffsetBatch._optional, # type: ignore[misc] + ) + # Offset of the grid along its normal. + # + # (Docstring intentionally commented out to hide this field from the docs) + line_radius: blueprint_components.UiRadiusBatch | None = field( metadata={"component": "optional"}, default=None, @@ -127,16 +156,5 @@ def _clear(cls) -> LineGrid3D: # # (Docstring intentionally commented out to hide this field from the docs) - orientation: blueprint_components.PlaneOrientationBatch | None = field( - metadata={"component": "optional"}, - default=None, - converter=blueprint_components.PlaneOrientationBatch._optional, # type: ignore[misc] - ) - # How the grid is oriented. - # - # Defaults to whatever plane is determined as the down plane by view coordinates if present. - # - # (Docstring intentionally commented out to hide this field from the docs) - __str__ = Archetype.__str__ __repr__ = Archetype.__repr__ # type: ignore[assignment] diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/.gitattributes b/rerun_py/rerun_sdk/rerun/blueprint/components/.gitattributes index 7f343a4b77e82..428cd747bbba3 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/.gitattributes +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/.gitattributes @@ -21,6 +21,7 @@ interactive.py linguist-generated=true lock_range_during_zoom.py linguist-generated=true map_provider.py linguist-generated=true panel_state.py linguist-generated=true +plane_offset.py linguist-generated=true plane_orientation.py linguist-generated=true query_expression.py linguist-generated=true root_container.py linguist-generated=true diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py b/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py index 71c95b710309c..78b24718c1b22 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/__init__.py @@ -21,6 +21,7 @@ from .lock_range_during_zoom import LockRangeDuringZoom, LockRangeDuringZoomBatch from .map_provider import MapProvider, MapProviderArrayLike, MapProviderBatch, MapProviderLike from .panel_state import PanelState, PanelStateArrayLike, PanelStateBatch, PanelStateLike +from .plane_offset import PlaneOffset, PlaneOffsetBatch from .plane_orientation import PlaneOrientation, PlaneOrientationArrayLike, PlaneOrientationBatch, PlaneOrientationLike from .query_expression import QueryExpression, QueryExpressionBatch from .root_container import RootContainer, RootContainerBatch @@ -89,6 +90,8 @@ "PanelStateArrayLike", "PanelStateBatch", "PanelStateLike", + "PlaneOffset", + "PlaneOffsetBatch", "PlaneOrientation", "PlaneOrientationArrayLike", "PlaneOrientationBatch", diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/plane_offset.py b/rerun_py/rerun_sdk/rerun/blueprint/components/plane_offset.py new file mode 100644 index 0000000000000..1b89b6a00c2d7 --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/plane_offset.py @@ -0,0 +1,32 @@ +# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs +# Based on "crates/store/re_types/definitions/rerun/blueprint/components/plane_offset.fbs". + +# You can extend this class by creating a "PlaneOffsetExt" class in "plane_offset_ext.py". + +from __future__ import annotations + +from ... import datatypes +from ..._baseclasses import ( + ComponentBatchMixin, + ComponentMixin, +) + +__all__ = ["PlaneOffset", "PlaneOffsetBatch"] + + +class PlaneOffset(datatypes.Float32, ComponentMixin): + """**Component**: Offset of a plane along its normal in scene units.""" + + _BATCH_TYPE = None + # You can define your own __init__ function as a member of PlaneOffsetExt in plane_offset_ext.py + + # Note: there are no fields here because PlaneOffset delegates to datatypes.Float32 + pass + + +class PlaneOffsetBatch(datatypes.Float32Batch, ComponentBatchMixin): + _COMPONENT_NAME: str = "rerun.blueprint.components.PlaneOffset" + + +# This is patched in late to avoid circular dependencies. +PlaneOffset._BATCH_TYPE = PlaneOffsetBatch # type: ignore[assignment]