Skip to content

Commit 1772fe2

Browse files
committed
Add target_frame to SpatialInformation
1 parent 78b3f45 commit 1772fe2

File tree

14 files changed

+202
-53
lines changed

14 files changed

+202
-53
lines changed

crates/store/re_types/definitions/rerun/blueprint/archetypes/spatial_information.fbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ namespace rerun.blueprint.archetypes;
44
table SpatialInformation (
55
"attr.rerun.scope": "blueprint"
66
) {
7+
/// The target reference frame for all transformations.
8+
///
9+
/// Defaults to the frame derived from the space origin.
10+
target_frame: rerun.components.TransformFrameId ("attr.rerun.component_optional", order: 50);
11+
712
/// Whether axes should be shown at the origin.
813
show_axes: rerun.blueprint.components.Enabled ("attr.rerun.component_optional", nullable, order: 100);
914

crates/store/re_types/src/blueprint/archetypes/spatial_information.rs

Lines changed: 58 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/reflection/mod.rs

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/viewer/re_component_ui/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ use re_types::{
4848
AggregationPolicy, AlbedoFactor, AxisLength, Color, DepthMeter, DrawOrder, FillMode,
4949
FillRatio, GammaCorrection, GraphType, ImagePlaneDistance, LinearSpeed,
5050
MagnificationFilter, MarkerSize, Name, Opacity, Position2D, Position3D, Range1D, Scale3D,
51-
SeriesVisible, ShowLabels, StrokeWidth, Text, Timestamp, TransformRelation, Translation3D,
52-
ValueRange, Vector3D, VideoCodec, Visible,
51+
SeriesVisible, ShowLabels, StrokeWidth, Text, Timestamp, TransformFrameId,
52+
TransformRelation, Translation3D, ValueRange, Vector3D, VideoCodec, Visible,
5353
},
5454
};
5555
use re_viewer_context::gpu_bridge::colormap_edit_or_view_ui;
@@ -121,6 +121,7 @@ pub fn create_component_ui_registry() -> re_viewer_context::ComponentUiRegistry
121121
registry.add_multiline_edit_or_view::<Text>(edit_multiline_string);
122122
registry.add_singleline_edit_or_view::<Name>(edit_singleline_string);
123123
registry.add_multiline_edit_or_view::<Name>(edit_multiline_string);
124+
registry.add_singleline_edit_or_view::<TransformFrameId>(edit_singleline_string);
124125

125126
// Enums:
126127
// TODO(#6974): Enums editors trivial and always the same, provide them automatically!

crates/viewer/re_view_spatial/src/contexts/transform_tree_context.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use nohash_hasher::IntMap;
44
use re_chunk_store::LatestAtQuery;
55
use re_log_types::EntityPathHash;
66
use re_tf::{TransformFrameId, TransformFrameIdHash};
7-
use re_types::{archetypes, components::ImagePlaneDistance};
7+
use re_types::{archetypes, blueprint, components::ImagePlaneDistance};
88
use re_view::{DataResultQuery as _, latest_at_with_blueprint_resolved_data};
99
use re_viewer_context::{
1010
DataResult, IdentifiedViewSystem, ViewContext, ViewContextSystem,
1111
ViewContextSystemOncePerFrameResult, typed_fallback_for,
1212
};
13+
use re_viewport_blueprint::ViewProperty;
1314
use vec1::smallvec_v1::SmallVec1;
1415

1516
use crate::caches::TransformDatabaseStoreCache;
@@ -106,8 +107,35 @@ impl ViewContextSystem for TransformTreeContext {
106107
// Currently, we don't keep it around during the frame, but we may do so in the future.
107108
self.entity_transform_id_mapping = EntityTransformIdMapping::new(ctx, query);
108109

109-
// Target frame is the coordinate frame of the space origin entity.
110-
self.target_frame = self.transform_frame_id_for(query.space_origin.hash());
110+
// Target frame - check for blueprint override first, otherwise use space origin's coordinate frame.
111+
self.target_frame = {
112+
let spatial_info_prop = ViewProperty::from_archetype::<
113+
blueprint::archetypes::SpatialInformation,
114+
>(
115+
ctx.blueprint_db(), ctx.blueprint_query(), ctx.view_id
116+
);
117+
118+
let target_frame_component = spatial_info_prop
119+
.component_or_fallback::<TransformFrameId>(
120+
ctx,
121+
blueprint::archetypes::SpatialInformation::descriptor_target_frame().component,
122+
);
123+
124+
match target_frame_component {
125+
Ok(target_frame) => {
126+
let target_frame_str = target_frame.as_str();
127+
if !target_frame_str.is_empty() {
128+
TransformFrameIdHash::from_str(target_frame.as_str())
129+
} else {
130+
self.transform_frame_id_for(query.space_origin.hash())
131+
}
132+
}
133+
Err(err) => {
134+
re_log::error_once!("Failed to query target frame: {err}");
135+
self.transform_frame_id_for(query.space_origin.hash())
136+
}
137+
}
138+
};
111139

112140
let latest_at_query = query.latest_at_query();
113141

crates/viewer/re_view_spatial/src/shared_fallbacks.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use re_types::{archetypes, components, image::ImageKind};
1+
use re_types::{archetypes, blueprint, components, image::ImageKind};
22
use re_view::DataResultQuery as _;
33
use re_viewer_context::{IdentifiedViewSystem as _, QueryContext, ViewStateExt as _};
44

@@ -123,4 +123,23 @@ pub fn register_fallbacks(system_registry: &mut re_viewer_context::ViewSystemReg
123123
components::ShowLabels(false.into())
124124
},
125125
);
126+
127+
// Target reference frame - fallback to the computed value from view state
128+
//
129+
// An empty string signals that nothing has been set yet.
130+
system_registry.register_fallback_provider(
131+
blueprint::archetypes::SpatialInformation::descriptor_target_frame().component,
132+
|ctx| {
133+
let Ok(state) = ctx.view_state().downcast_ref::<SpatialViewState>() else {
134+
return components::TransformFrameId(String::new().into());
135+
};
136+
137+
// Return the computed target frame from the view state
138+
state
139+
.target_frame
140+
.as_ref()
141+
.map(|frame_str| components::TransformFrameId(frame_str.clone().into()))
142+
.unwrap_or_else(|| components::TransformFrameId(String::new().into()))
143+
},
144+
);
126145
}

crates/viewer/re_view_spatial/src/view_2d.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use re_viewer_context::{
1515
};
1616

1717
use crate::{
18-
contexts::{register_spatial_contexts, TransformTreeContext},
18+
contexts::{TransformTreeContext, register_spatial_contexts},
1919
heuristics::default_visualized_entities_for_visualizer_kind,
2020
max_image_dimension_subscriber::{ImageTypes, MaxDimensions},
2121
shared_fallbacks,
@@ -291,19 +291,6 @@ impl ViewClass for SpatialView2D {
291291
let state = state.downcast_mut::<SpatialViewState>()?;
292292
// TODO(andreas): list_item'ify the rest
293293
ui.selection_grid("spatial_settings_ui").show(ui, |ui| {
294-
if ctx.app_options().experimental_coordinate_frame_display_and_override {
295-
ui.grid_left_hand_label("Target frame")
296-
.on_hover_text("The coordinate frame that transforms are resolved to");
297-
ui.vertical(|ui| {
298-
if let Some(target_frame) = &state.target_frame {
299-
ui.label(target_frame);
300-
} else {
301-
ui.weak("(unknown)");
302-
}
303-
});
304-
ui.end_row();
305-
}
306-
307294
state.bounding_box_ui(ui, SpatialViewKind::TwoD);
308295
});
309296

crates/viewer/re_view_spatial/src/view_3d.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use re_viewer_context::{
2828
use re_viewport_blueprint::ViewProperty;
2929

3030
use crate::{
31-
contexts::{register_spatial_contexts, TransformTreeContext},
31+
contexts::{TransformTreeContext, register_spatial_contexts},
3232
heuristics::default_visualized_entities_for_visualizer_kind,
3333
spatial_topology::{HeuristicHints, SpatialTopology, SubSpaceConnectionFlags},
3434
ui::SpatialViewState,
@@ -575,19 +575,6 @@ impl ViewClass for SpatialView3D {
575575
});
576576
ui.end_row();
577577

578-
if ctx.app_options().experimental_coordinate_frame_display_and_override {
579-
ui.grid_left_hand_label("Target frame")
580-
.on_hover_text("The coordinate frame that transforms are resolved to");
581-
ui.vertical(|ui| {
582-
if let Some(target_frame) = &state.target_frame {
583-
ui.label(target_frame);
584-
} else {
585-
ui.weak("(unknown)");
586-
}
587-
});
588-
ui.end_row();
589-
}
590-
591578
state.bounding_box_ui(ui, SpatialViewKind::ThreeD);
592579

593580
#[cfg(debug_assertions)]
@@ -596,10 +583,10 @@ impl ViewClass for SpatialView3D {
596583

597584
re_ui::list_item::list_item_scope(ui, "spatial_view3d_selection_ui", |ui| {
598585
let view_ctx = self.view_context(ctx, view_id, state);
586+
view_property_ui::<SpatialInformation>(&view_ctx, ui);
599587
view_property_ui::<EyeControls3D>(&view_ctx, ui);
600588
view_property_ui::<Background>(&view_ctx, ui);
601589
view_property_ui_grid3d(&view_ctx, ui);
602-
view_property_ui::<SpatialInformation>(&view_ctx, ui);
603590
});
604591

605592
Ok(())

docs/content/reference/types/views/spatial3d_view.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/snippets/all/views/spatial3d.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
color=[255, 255, 255, 128], # Colors the grid a half-transparent white.
4242
),
4343
spatial_information=rrb.SpatialInformation(
44+
target_frame="tf#/",
4445
show_axes=True,
4546
show_bounding_box=True,
4647
),

0 commit comments

Comments
 (0)