Skip to content

Commit a0f8b7a

Browse files
authored
Add option to specify target_frame to SpatialInformation (#12040)
### Related * Closes RR-2876 * Closes RR-2907 * Follow up: RR-3076 ### What This PR adds `target_frame` view property to the `SpatialInformation` archetype. <img width="553" height="285" alt="image" src="https://github.com/user-attachments/assets/2232dbc0-fd77-4e93-ba1f-ae95be578d5b" /> To this this PR open the DNA example and enter `tf#/helix/structure` into the `target_frame` field of the view. Now only the beads should be animated when pressing play.
1 parent 90f5db3 commit a0f8b7a

File tree

63 files changed

+321
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+321
-122
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 coordinate frame used by the space origin entity.
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
@@ -46,8 +46,8 @@ use re_types::components::{
4646
AggregationPolicy, AlbedoFactor, AxisLength, Color, DepthMeter, DrawOrder, FillMode, FillRatio,
4747
GammaCorrection, GraphType, ImagePlaneDistance, LinearSpeed, MagnificationFilter, MarkerSize,
4848
Name, Opacity, Position2D, Position3D, Range1D, Scale3D, SeriesVisible, ShowLabels,
49-
StrokeWidth, Text, Timestamp, TransformRelation, Translation3D, ValueRange, Vector3D,
50-
VideoCodec, Visible,
49+
StrokeWidth, Text, Timestamp, TransformFrameId, TransformRelation, Translation3D, ValueRange,
50+
Vector3D, VideoCodec, Visible,
5151
};
5252
use re_viewer_context::gpu_bridge::colormap_edit_or_view_ui;
5353

@@ -118,6 +118,7 @@ pub fn create_component_ui_registry() -> re_viewer_context::ComponentUiRegistry
118118
registry.add_multiline_edit_or_view::<Text>(edit_multiline_string);
119119
registry.add_singleline_edit_or_view::<Name>(edit_singleline_string);
120120
registry.add_multiline_edit_or_view::<Name>(edit_multiline_string);
121+
registry.add_singleline_edit_or_view::<TransformFrameId>(edit_singleline_string);
121122

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

crates/viewer/re_view/src/view_property_ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub fn view_property_ui_with_redirect<A: Archetype + ArchetypeReflectionMarker>(
4242
viewer_ctx: ctx.viewer_ctx,
4343
view_id: redirect_with_view_id,
4444
view_class_identifier: ctx.view_class_identifier,
45+
space_origin: ctx.space_origin,
4546
view_state: ctx.view_state,
4647
query_result: &re_viewer_context::DataQueryResult::default(),
4748
},

crates/viewer/re_view_bar_chart/src/view_class.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ impl ViewClass for BarChartView {
140140
ctx: &ViewerContext<'_>,
141141
ui: &mut egui::Ui,
142142
state: &mut dyn ViewState,
143-
_space_origin: &EntityPath,
143+
space_origin: &EntityPath,
144144
view_id: ViewId,
145145
) -> Result<(), ViewSystemExecutionError> {
146146
list_item::list_item_scope(ui, "bar_char_selection_ui", |ui| {
147-
let ctx = self.view_context(ctx, view_id, state);
147+
let ctx = self.view_context(ctx, view_id, state, space_origin);
148148
view_property_ui::<PlotBackground>(&ctx, ui);
149149
view_property_ui::<PlotLegend>(&ctx, ui);
150150
});
@@ -173,7 +173,7 @@ impl ViewClass for BarChartView {
173173
.get::<BarChartVisualizerSystem>()?
174174
.charts;
175175

176-
let ctx = self.view_context(ctx, view_id, state);
176+
let ctx = self.view_context(ctx, view_id, state, query.space_origin);
177177
let background = ViewProperty::from_archetype::<PlotBackground>(
178178
blueprint_db,
179179
ctx.blueprint_query(),

crates/viewer/re_view_graph/src/view.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl ViewClass for GraphView {
171171
ctx: &ViewerContext<'_>,
172172
ui: &mut egui::Ui,
173173
state: &mut dyn ViewState,
174-
_space_origin: &EntityPath,
174+
space_origin: &EntityPath,
175175
view_id: ViewId,
176176
) -> Result<(), ViewSystemExecutionError> {
177177
let state = state.downcast_mut::<GraphViewState>()?;
@@ -182,7 +182,7 @@ impl ViewClass for GraphView {
182182
});
183183

184184
re_ui::list_item::list_item_scope(ui, "graph_selection_ui", |ui| {
185-
let ctx = self.view_context(ctx, view_id, state);
185+
let ctx = self.view_context(ctx, view_id, state, space_origin);
186186
view_property_ui::<GraphBackground>(&ctx, ui);
187187
view_property_ui::<VisualBounds2D>(&ctx, ui);
188188
view_property_force_ui::<ForceLink>(&ctx, ui);
@@ -217,7 +217,7 @@ impl ViewClass for GraphView {
217217

218218
let state = state.downcast_mut::<GraphViewState>()?;
219219

220-
let view_ctx = self.view_context(ctx, query.view_id, state);
220+
let view_ctx = self.view_context(ctx, query.view_id, state, query.space_origin);
221221
let params = ForceLayoutParams::get(&view_ctx)?;
222222

223223
let background = ViewProperty::from_archetype::<GraphBackground>(

crates/viewer/re_view_map/src/map_view.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ impl ViewClass for MapView {
170170
ctx: &ViewerContext<'_>,
171171
ui: &mut egui::Ui,
172172
state: &mut dyn ViewState,
173-
_space_origin: &EntityPath,
173+
space_origin: &EntityPath,
174174
view_id: ViewId,
175175
) -> Result<(), ViewSystemExecutionError> {
176176
re_ui::list_item::list_item_scope(ui, "map_selection_ui", |ui| {
177-
let ctx = self.view_context(ctx, view_id, state);
177+
let ctx = self.view_context(ctx, view_id, state, space_origin);
178178
re_view::view_property_ui::<MapZoom>(&ctx, ui);
179179
re_view::view_property_ui::<MapBackground>(&ctx, ui);
180180
});
@@ -212,7 +212,7 @@ impl ViewClass for MapView {
212212
// Map Provider
213213
//
214214

215-
let view_ctx = self.view_context(ctx, query.view_id, state);
215+
let view_ctx = self.view_context(ctx, query.view_id, state, query.space_origin);
216216
let map_provider = map_background
217217
.component_or_fallback(&view_ctx, MapBackground::descriptor_provider().component)?;
218218
if state.selected_provider != map_provider {

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ use re_chunk_store::LatestAtQuery;
55
use re_log_types::{EntityPath, EntityPathHash};
66
use re_tf::{TransformFrameId, TransformFrameIdHash, TreeTransform};
77
use re_types::components::ImagePlaneDistance;
8-
use re_types::{ArchetypeName, archetypes};
8+
use re_types::{ArchetypeName, archetypes, blueprint};
99
use re_view::{
1010
DataResultQuery as _, HybridLatestAtResults, latest_at_with_blueprint_resolved_data,
1111
};
1212
use re_viewer_context::{
1313
IdentifiedViewSystem, TransformDatabaseStoreCache, ViewContext, ViewContextSystem,
1414
ViewContextSystemOncePerFrameResult, typed_fallback_for,
1515
};
16+
use re_viewport_blueprint::ViewProperty;
1617
use vec1::smallvec_v1::SmallVec1;
1718

1819
type FrameIdMapping = IntMap<TransformFrameIdHash, TransformFrameId>;
@@ -209,8 +210,28 @@ impl ViewContextSystem for TransformTreeContext {
209210
self.entity_transform_id_mapping =
210211
EntityTransformIdMapping::new(ctx, &results, query.space_origin);
211212

212-
// Target frame is the coordinate frame of the space origin entity.
213-
self.target_frame = self.transform_frame_id_for(query.space_origin.hash());
213+
// Target frame - check for blueprint override first, otherwise use space origin's coordinate frame.
214+
self.target_frame = {
215+
let spatial_info_prop = ViewProperty::from_archetype::<
216+
blueprint::archetypes::SpatialInformation,
217+
>(
218+
ctx.blueprint_db(), ctx.blueprint_query(), ctx.view_id
219+
);
220+
221+
let target_frame_component = spatial_info_prop
222+
.component_or_fallback::<TransformFrameId>(
223+
ctx,
224+
blueprint::archetypes::SpatialInformation::descriptor_target_frame().component,
225+
);
226+
227+
match target_frame_component {
228+
Ok(target_frame) => TransformFrameIdHash::from_str(target_frame.as_str()),
229+
Err(err) => {
230+
re_log::error_once!("Failed to query target frame: {err}");
231+
self.transform_frame_id_for(query.space_origin.hash())
232+
}
233+
}
234+
};
214235

215236
let latest_at_query = query.latest_at_query();
216237

crates/viewer/re_view_spatial/src/shared_fallbacks.rs

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

@@ -124,4 +124,30 @@ pub fn register_fallbacks(system_registry: &mut re_viewer_context::ViewSystemReg
124124
components::ShowLabels(false.into())
125125
},
126126
);
127+
128+
system_registry.register_fallback_provider(
129+
blueprint::archetypes::SpatialInformation::descriptor_target_frame().component,
130+
|ctx| {
131+
let space_origin = ctx.view_ctx.space_origin;
132+
let query_result = ctx.viewer_ctx().lookup_query_result(ctx.view_ctx.view_id);
133+
134+
if let Some(data_result) = query_result.tree.lookup_result_by_path(space_origin.hash())
135+
{
136+
let results = data_result
137+
.latest_at_with_blueprint_resolved_data::<archetypes::CoordinateFrame>(
138+
ctx.view_ctx,
139+
ctx.query,
140+
);
141+
142+
if let Some(frame_id) = results.get_mono::<components::TransformFrameId>(
143+
archetypes::CoordinateFrame::descriptor_frame().component,
144+
) {
145+
return frame_id;
146+
}
147+
}
148+
149+
// Fallback to entity path if no explicit CoordinateFrame
150+
components::TransformFrameId::from_entity_path(space_origin)
151+
},
152+
);
127153
}

0 commit comments

Comments
 (0)