Skip to content

Commit 78fa9b2

Browse files
committed
better hardcoded string
1 parent 95c63b5 commit 78fa9b2

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
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
@@ -6,7 +6,7 @@ use re_tf::TransformInfo;
66
use re_types::ViewClassIdentifier;
77
use re_view::AnnotationSceneContext;
88

9-
pub use transform_tree_context::TransformTreeContext;
9+
pub use transform_tree_context::{TransformTreeContext, UNKNOWN_SPACE_ORIGIN};
1010

1111
// -----------------------------------------------------------------------------
1212

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ use vec1::smallvec_v1::SmallVec1;
1515

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

18+
/// Currently, there is no straightfoward way to retrieve the space origin
19+
/// when registering fallbacks. So, if unknown we set the target frame to a
20+
/// dummy string and rely on the view to supply that information after the
21+
/// first frame.
22+
pub const UNKNOWN_SPACE_ORIGIN: &str = "<unknown space origin>";
23+
1824
/// Provides a transform tree for the view & time it operates on.
1925
///
2026
/// Will do the necessary bulk processing of transform information and make it available
@@ -124,10 +130,10 @@ impl ViewContextSystem for TransformTreeContext {
124130
match target_frame_component {
125131
Ok(target_frame) => {
126132
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 {
133+
if target_frame_str == UNKNOWN_SPACE_ORIGIN {
130134
self.transform_frame_id_for(query.space_origin.hash())
135+
} else {
136+
TransformFrameIdHash::from_str(target_frame.as_str())
131137
}
132138
}
133139
Err(err) => {

crates/viewer/re_view_spatial/src/shared_fallbacks.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,4 @@ 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-
);
145126
}

crates/viewer/re_view_spatial/src/view_3d.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use re_types::{
1111
archetypes::{Background, EyeControls3D, LineGrid3D, SpatialInformation},
1212
components::Eye3DKind,
1313
},
14-
components::{LinearSpeed, Plane3D, Position3D, Vector3D},
14+
components::{LinearSpeed, Plane3D, Position3D, TransformFrameId, Vector3D},
1515
datatypes::Vec3D,
1616
view_coordinates::SignedAxis3,
1717
};
@@ -27,7 +27,7 @@ use re_viewer_context::{
2727
use re_viewport_blueprint::ViewProperty;
2828

2929
use crate::{
30-
contexts::{TransformTreeContext, register_spatial_contexts},
30+
contexts::{TransformTreeContext, UNKNOWN_SPACE_ORIGIN, register_spatial_contexts},
3131
heuristics::default_visualized_entities_for_visualizer_kind,
3232
spatial_topology::{HeuristicHints, SpatialTopology, SubSpaceConnectionFlags},
3333
ui::SpatialViewState,
@@ -251,6 +251,24 @@ impl ViewClass for SpatialView3D {
251251
},
252252
);
253253

254+
system_registry.register_fallback_provider(
255+
SpatialInformation::descriptor_target_frame().component,
256+
|ctx| {
257+
let unknown_space_origin = || TransformFrameId(UNKNOWN_SPACE_ORIGIN.into());
258+
259+
let Ok(state) = ctx.view_state().downcast_ref::<SpatialViewState>() else {
260+
return unknown_space_origin();
261+
};
262+
263+
// Return the computed target frame from the view state
264+
state
265+
.target_frame
266+
.as_ref()
267+
.map(|frame_str| TransformFrameId(frame_str.clone().into()))
268+
.unwrap_or_else(unknown_space_origin)
269+
},
270+
);
271+
254272
shared_fallbacks::register_fallbacks(system_registry);
255273

256274
// Ensure spatial topology is registered.

0 commit comments

Comments
 (0)