Skip to content

Commit a6160bd

Browse files
committed
Use in fallbacks
checkpoint
1 parent c838ad3 commit a6160bd

File tree

6 files changed

+31
-50
lines changed

6 files changed

+31
-50
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use re_renderer::DepthOffset;
77
use re_types::ViewClassIdentifier;
88
use re_view::AnnotationSceneContext;
99
use re_viewer_context::{Annotations, ViewClassRegistryError};
10-
pub use transform_tree_context::{TransformInfo, TransformTreeContext, UNKNOWN_SPACE_ORIGIN};
10+
pub use transform_tree_context::{TransformInfo, TransformTreeContext};
1111

1212
/// Context objects for a single entity in a spatial scene.
1313
pub struct SpatialSceneEntityContext<'a> {

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ use vec1::smallvec_v1::SmallVec1;
1616

1717
type FrameIdMapping = IntMap<TransformFrameIdHash, TransformFrameId>;
1818

19-
/// Currently, there is no straightforward way to retrieve the space origin
20-
/// when registering fallbacks. So, if unknown we set the target frame to a
21-
/// dummy string and rely on the view to supply that information after the
22-
/// first frame.
23-
pub const UNKNOWN_SPACE_ORIGIN: &str = "<unknown space origin>";
24-
2519
/// Details on how to transform an entity (!) to the origin of the view's space.
2620
#[derive(Clone, Debug, PartialEq)]
2721
pub struct TransformInfo {
@@ -208,14 +202,7 @@ impl ViewContextSystem for TransformTreeContext {
208202
);
209203

210204
match target_frame_component {
211-
Ok(target_frame) => {
212-
let target_frame_str = target_frame.as_str();
213-
if target_frame_str == UNKNOWN_SPACE_ORIGIN {
214-
self.transform_frame_id_for(query.space_origin.hash())
215-
} else {
216-
TransformFrameIdHash::from_str(target_frame.as_str())
217-
}
218-
}
205+
Ok(target_frame) => TransformFrameIdHash::from_str(target_frame.as_str()),
219206
Err(err) => {
220207
re_log::error_once!("Failed to query target frame: {err}");
221208
self.transform_frame_id_for(query.space_origin.hash())

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+
// Query the actual coordinate frame for the space origin entity.
132+
// This respects explicit CoordinateFrame components rather than just deriving from entity path.
133+
let space_origin = ctx.view_ctx.space_origin;
134+
let query_result = ctx.viewer_ctx().lookup_query_result(ctx.view_ctx.view_id);
135+
136+
if let Some(data_result) = query_result.tree.lookup_result_by_path(space_origin.hash())
137+
{
138+
let results = data_result.latest_at_with_blueprint_resolved_data::<
139+
archetypes::CoordinateFrame,
140+
>(ctx.view_ctx, ctx.query);
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
}

crates/viewer/re_view_spatial/src/ui.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ pub struct SpatialViewState {
6363
pub pinhole_at_origin: Option<Pinhole>,
6464

6565
pub visual_bounds_2d: Option<VisualBounds2D>,
66-
67-
/// The target frame, i.e., the coordinate frame that transforms are resolved to.
68-
/// Computed from the space origin via the transform tree.
69-
pub target_frame: Option<String>,
7066
}
7167

7268
impl ViewState for SpatialViewState {

crates/viewer/re_view_spatial/src/view_2d.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use re_viewer_context::{
1010
ViewSpawnHeuristics, ViewState, ViewStateExt as _, ViewSystemExecutionError, ViewerContext,
1111
};
1212

13-
use crate::contexts::{TransformTreeContext, register_spatial_contexts};
13+
use crate::contexts::register_spatial_contexts;
1414
use crate::heuristics::default_visualized_entities_for_visualizer_kind;
1515
use crate::max_image_dimension_subscriber::{ImageTypes, MaxDimensions};
1616
use crate::shared_fallbacks;
@@ -255,11 +255,6 @@ impl ViewClass for SpatialView2D {
255255
let state = state.downcast_mut::<SpatialViewState>()?;
256256
state.update_frame_statistics(ui, &system_output, SpatialViewKind::TwoD);
257257

258-
// Store the target frame for display in the selection panel
259-
if let Ok(transforms) = system_output.context_systems.get::<TransformTreeContext>() {
260-
state.target_frame = Some(transforms.format_frame(transforms.target_frame()));
261-
}
262-
263258
self.view_2d(ctx, ui, state, query, system_output)
264259
}
265260
}

crates/viewer/re_view_spatial/src/view_3d.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use re_viewer_context::{
2222
};
2323
use re_viewport_blueprint::ViewProperty;
2424

25-
use crate::contexts::{TransformTreeContext, UNKNOWN_SPACE_ORIGIN, register_spatial_contexts};
25+
use crate::contexts::register_spatial_contexts;
2626
use crate::heuristics::default_visualized_entities_for_visualizer_kind;
2727
use crate::shared_fallbacks;
2828
use crate::spatial_topology::{HeuristicHints, SpatialTopology, SubSpaceConnectionFlags};
@@ -244,24 +244,6 @@ impl ViewClass for SpatialView3D {
244244
},
245245
);
246246

247-
system_registry.register_fallback_provider(
248-
SpatialInformation::descriptor_target_frame().component,
249-
|ctx| {
250-
let unknown_space_origin = || TransformFrameId(UNKNOWN_SPACE_ORIGIN.into());
251-
252-
let Ok(state) = ctx.view_state().downcast_ref::<SpatialViewState>() else {
253-
return unknown_space_origin();
254-
};
255-
256-
// Return the computed target frame from the view state
257-
state
258-
.target_frame
259-
.as_ref()
260-
.map(|frame_str| TransformFrameId(frame_str.clone().into()))
261-
.unwrap_or_else(unknown_space_origin)
262-
},
263-
);
264-
265247
shared_fallbacks::register_fallbacks(system_registry);
266248

267249
// Ensure spatial topology is registered.
@@ -549,11 +531,6 @@ impl ViewClass for SpatialView3D {
549531
let state = state.downcast_mut::<SpatialViewState>()?;
550532
state.update_frame_statistics(ui, &system_output, SpatialViewKind::ThreeD);
551533

552-
// Store the target frame for display in the selection panel
553-
if let Ok(transforms) = system_output.context_systems.get::<TransformTreeContext>() {
554-
state.target_frame = Some(transforms.format_frame(transforms.target_frame()));
555-
}
556-
557534
self.view_3d(ctx, ui, state, query, system_output)
558535
}
559536
}

0 commit comments

Comments
 (0)