Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: allow creating 3D space views for pinhole-only 3D scenes #5563

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 50 additions & 28 deletions crates/re_space_view_spatial/src/space_view_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,36 +212,58 @@ impl SpaceViewClass for SpatialSpaceView3D {
recommended_space_views: topo
.iter_subspaces()
.filter_map(|subspace| {
if !subspace.supports_3d_content() || subspace.entities.is_empty() {
None
} else {
// Creates space views at each view coordinates if there's any.
// (yes, we do so even if they're empty at the moment!)
//
// An exception to this rule is not to create a view there if this is already _also_ a subspace root.
// (e.g. this also has a camera or a `disconnect` logged there)
let mut origins = subspace
.heuristic_hints
.iter()
.filter(|(path, hint)| {
hint.contains(HeuristicHints::ViewCoordinates3d)
&& !subspace.child_spaces.contains(path)
})
.map(|(path, _)| path.clone())
.collect::<Vec<_>>();

// If there's no view coordinates or there are still some entities not covered,
// create a view at the subspace origin.
if !origins.iter().contains(&subspace.origin)
&& indicated_entities
.intersection(&subspace.entities)
.any(|e| origins.iter().all(|origin| !e.starts_with(origin)))
{
origins.push(subspace.origin.clone());
}
if !subspace.supports_3d_content() {
return None;
}

let mut pinhole_child_spaces = subspace
.child_spaces
.iter()
.filter(|child| {
topo.subspace_for_subspace_origin(child.hash()).map_or(
false,
|child_space| {
child_space.connection_to_parent.is_connected_pinhole()
},
)
})
.peekable(); // Don't collect the iterator, we're only interested in 'any'-style operations.

// Empty space views are still of interest if any of the child spaces is connected via a pinhole.
if subspace.entities.is_empty() && pinhole_child_spaces.peek().is_none() {
return None;
}

Some(origins.into_iter().map(RecommendedSpaceView::new_subtree))
// Creates space views at each view coordinates if there's any.
// (yes, we do so even if they're empty at the moment!)
//
// An exception to this rule is not to create a view there if this is already _also_ a subspace root.
// (e.g. this also has a camera or a `disconnect` logged there)
let mut origins = subspace
.heuristic_hints
.iter()
.filter(|(path, hint)| {
hint.contains(HeuristicHints::ViewCoordinates3d)
&& !subspace.child_spaces.contains(path)
})
.map(|(path, _)| path.clone())
.collect::<Vec<_>>();

let path_not_covered_yet =
|e: &EntityPath| origins.iter().all(|origin| !e.starts_with(origin));

// If there's no view coordinates or there are still some entities not covered,
// create a view at the subspace origin.
if !origins.iter().contains(&subspace.origin)
&& (indicated_entities
.intersection(&subspace.entities)
.any(path_not_covered_yet)
|| pinhole_child_spaces.any(path_not_covered_yet))
{
origins.push(subspace.origin.clone());
}

Some(origins.into_iter().map(RecommendedSpaceView::new_subtree))
})
.flatten()
.collect(),
Expand Down
Loading