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

[pure refactor] Move spatial space view to its own crate #2286

Merged
merged 9 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
58 changes: 53 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ re_renderer = { path = "crates/re_renderer", version = "0.7.0-alpha.0", default-
re_sdk = { path = "crates/re_sdk", version = "0.7.0-alpha.0", default-features = false }
re_sdk_comms = { path = "crates/re_sdk_comms", version = "0.7.0-alpha.0", default-features = false }
re_smart_channel = { path = "crates/re_smart_channel", version = "0.7.0-alpha.0", default-features = false }
re_space_view = { path = "crates/re_space_view", version = "0.7.0-alpha.0", default-features = false }
re_space_view_text = { path = "crates/re_space_view_text", version = "0.7.0-alpha.0", default-features = false }
re_space_view_text_box = { path = "crates/re_space_view_text_box", version = "0.7.0-alpha.0", default-features = false }
re_space_view_spatial = { path = "crates/re_space_view_spatial", version = "0.7.0-alpha.0", default-features = false }
re_string_interner = { path = "crates/re_string_interner", version = "0.7.0-alpha.0", default-features = false }
re_tensor_ops = { path = "crates/re_tensor_ops", version = "0.7.0-alpha.0", default-features = false }
re_time_panel = { path = "crates/re_time_panel", version = "=0.7.0-alpha.0", default-features = false }
Expand Down
31 changes: 31 additions & 0 deletions crates/re_space_view/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
authors.workspace = true
description = "Types & utilities for defining Space View classes and communicating with the Viewport."
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "re_space_view"
publish = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true
include = ["../../LICENSE-APACHE", "../../LICENSE-MIT", "**/*.rs", "Cargo.toml"]

[package.metadata.docs.rs]
all-features = true

[dependencies]
re_data_store.workspace = true
re_log_types.workspace = true
re_renderer.workspace = true
re_tracing.workspace = true
re_viewer_context.workspace = true

ahash.workspace = true
egui.workspace = true
lazy_static.workspace = true
nohash-hasher.workspace = true
serde = "1.0"
slotmap.workspace = true
smallvec.workspace = true
10 changes: 10 additions & 0 deletions crates/re_space_view/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# re_space_view

Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.

[![Latest version](https://img.shields.io/crates/v/re_space_view.svg)](https://crates.io/crates/re_space_view)
[![Documentation](https://docs.rs/re_space_view/badge.svg)](https://docs.rs/re_space_view)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

Types & utilities for defining Space View classes and communicating with the Viewport.
83 changes: 83 additions & 0 deletions crates/re_space_view/src/highlights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use lazy_static::lazy_static;
use nohash_hasher::IntMap;

use re_log_types::{EntityPathHash, InstanceKey};
use re_renderer::OutlineMaskPreference;

use re_viewer_context::InteractionHighlight;

/// Highlights of a specific entity path in a specific space view.
///
/// Using this in bulk on many instances is faster than querying single objects.
#[derive(Default)]
pub struct SpaceViewEntityHighlight {
pub overall: InteractionHighlight,
pub instances: ahash::HashMap<InstanceKey, InteractionHighlight>,
}

#[derive(Copy, Clone)]
pub struct OptionalSpaceViewEntityHighlight<'a>(Option<&'a SpaceViewEntityHighlight>);

impl<'a> OptionalSpaceViewEntityHighlight<'a> {
pub fn index_highlight(&self, instance_key: InstanceKey) -> InteractionHighlight {
match self.0 {
Some(entity_highlight) => entity_highlight
.instances
.get(&instance_key)
.cloned()
.unwrap_or_default()
.max(entity_highlight.overall),
None => InteractionHighlight::default(),
}
}
}

#[derive(Default)]
pub struct SpaceViewOutlineMasks {
pub overall: OutlineMaskPreference,
pub instances: ahash::HashMap<InstanceKey, OutlineMaskPreference>,
pub any_selection_highlight: bool,
}

lazy_static! {
static ref SPACEVIEW_OUTLINE_MASK_NONE: SpaceViewOutlineMasks =
SpaceViewOutlineMasks::default();
}

impl SpaceViewOutlineMasks {
pub fn index_outline_mask(&self, instance_key: InstanceKey) -> OutlineMaskPreference {
self.instances
.get(&instance_key)
.cloned()
.unwrap_or_default()
.with_fallback_to(self.overall)
}
}

/// Highlights in a specific space view.
///
/// Using this in bulk on many objects is faster than querying single objects.
#[derive(Default)]
pub struct SpaceViewHighlights {
pub highlighted_entity_paths: IntMap<EntityPathHash, SpaceViewEntityHighlight>,
pub outlines_masks: IntMap<EntityPathHash, SpaceViewOutlineMasks>,
}

impl SpaceViewHighlights {
pub fn entity_highlight(
&self,
entity_path_hash: EntityPathHash,
) -> OptionalSpaceViewEntityHighlight<'_> {
OptionalSpaceViewEntityHighlight(self.highlighted_entity_paths.get(&entity_path_hash))
}

pub fn entity_outline_mask(&self, entity_path_hash: EntityPathHash) -> &SpaceViewOutlineMasks {
self.outlines_masks
.get(&entity_path_hash)
.unwrap_or(&SPACEVIEW_OUTLINE_MASK_NONE)
}

pub fn any_outlines(&self) -> bool {
!self.outlines_masks.is_empty()
}
}
12 changes: 12 additions & 0 deletions crates/re_space_view/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Rerun Space View utilities
//!
//! Types & utilities for defining Space View classes and communicating with the Viewport.

pub mod controls;
mod data_blueprint;
mod highlights;
mod screenshot;

pub use data_blueprint::{DataBlueprintGroup, DataBlueprintTree};
pub use highlights::{SpaceViewEntityHighlight, SpaceViewHighlights, SpaceViewOutlineMasks};
pub use screenshot::ScreenshotMode;
9 changes: 9 additions & 0 deletions crates/re_space_view/src/screenshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[derive(PartialEq, Eq, Clone, Copy)]
#[allow(dead_code)] // Not used on the web.
pub enum ScreenshotMode {
/// The screenshot will be saved to disc and copied to the clipboard.
SaveAndCopyToClipboard,

/// The screenshot will be copied to the clipboard.
CopyToClipboard,
}
45 changes: 45 additions & 0 deletions crates/re_space_view_spatial/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
authors.workspace = true
description = "Space Views that show entities in a 2D or 3D spatial relationship."
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "re_space_view_spatial"
publish = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true
include = ["../../LICENSE-APACHE", "../../LICENSE-MIT", "**/*.rs", "Cargo.toml"]

[package.metadata.docs.rs]
all-features = true

[dependencies]
re_arrow_store.workspace = true
re_components = { workspace = true, features = ["ecolor", "glam", "image"] }
re_data_store = { workspace = true, features = ["serde"] }
re_data_ui.workspace = true
re_error.workspace = true
re_format.workspace = true
re_log_types.workspace = true
re_log.workspace = true
re_query.workspace = true
re_renderer.workspace = true
re_tracing.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true
re_space_view.workspace = true

ahash.workspace = true
anyhow.workspace = true
bytemuck.workspace = true
egui.workspace = true
eframe.workspace = true
glam.workspace = true
itertools.workspace = true
macaw = { workspace = true, features = ["with_serde"] }
nohash-hasher.workspace = true
serde = "1"
smallvec = { workspace = true, features = ["serde"] }
wgpu.workspace = true
10 changes: 10 additions & 0 deletions crates/re_space_view_spatial/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# re_space_view_spatial

Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.

[![Latest version](https://img.shields.io/crates/v/re_space_view_spatial.svg)](https://crates.io/crates/re_space_view_spatial)
[![Documentation](https://docs.rs/re_space_view_spatial/badge.svg)](https://docs.rs/re_space_view_spatial)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

Space Views that show entities in a 2D or 3D spatial relationship.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use egui::{lerp, NumExt as _, Rect};
use glam::Affine3A;
use macaw::{vec3, IsoTransform, Mat4, Quat, Vec3};

use crate::space_view_controls::{
use re_space_view::controls::{
DRAG_PAN3D_BUTTON, ROLL_MOUSE, ROLL_MOUSE_ALT, ROLL_MOUSE_MODIFIER, ROTATE3D_BUTTON,
SLOW_DOWN_3D_MODIFIER, SPEED_UP_3D_MODIFIER,
};

use super::SpaceCamera3D;
use crate::space_camera_3d::SpaceCamera3D;

/// An eye in a 3D view.
///
Expand Down
21 changes: 21 additions & 0 deletions crates/re_space_view_spatial/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Rerun Spatial Scene Views
//!
//! Space Views that show entities in a 2D or 3D spatial relationship.

mod eye;
mod instance_hash_conversions;
mod mesh_cache;
mod mesh_loader;
mod scene;
mod space_camera_3d;
mod transform_cache;
mod ui;
mod ui_2d;
mod ui_3d;
mod ui_renderer_bridge;

// TODO(andreas) should only make the main type public

pub use scene::SceneSpatial;
pub use transform_cache::{TransformCache, UnreachableTransform};
pub use ui::{SpatialNavigationMode, ViewSpatialState};
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ use re_components::{ClassId, DecodedTensor, DrawOrder, InstanceKey, KeypointId};
use re_data_store::{EntityPath, InstancePathHash};
use re_log_types::EntityPathHash;
use re_renderer::{renderer::TexturedRect, Color32, OutlineMaskPreference, Size};
use re_space_view::SpaceViewHighlights;
use re_viewer_context::{auto_color, AnnotationMap, Annotations, SceneQuery, ViewerContext};

use super::SpatialNavigationMode;
use crate::{
mesh_loader::LoadedMesh, space_view_highlights::SpaceViewHighlights,
transform_cache::TransformCache,
mesh_loader::LoadedMesh, space_camera_3d::SpaceCamera3D, transform_cache::TransformCache,
};

use super::{SpaceCamera3D, SpatialNavigationMode};

mod picking;
mod primitives;
mod scene_part;
Expand Down Expand Up @@ -96,7 +95,7 @@ pub struct SceneSpatial {
num_logged_3d_objects: usize,

/// All space cameras in this scene.
/// TODO(andreas): Does this belong to [`SceneSpatialUiData`]?
/// TODO(andreas): Does this belong to `SceneSpatialUiData`?
pub space_cameras: Vec<SpaceCamera3D>,
}

Expand Down Expand Up @@ -226,7 +225,7 @@ impl SceneSpatial {
}

/// Loads all 3D objects into the scene according to the given query.
pub(crate) fn load(
pub fn load(
&mut self,
ctx: &mut ViewerContext<'_>,
query: &SceneQuery<'_>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use re_log_types::InstanceKey;
use re_renderer::PickingLayerProcessor;

use super::{Image, SceneSpatialPrimitives, SceneSpatialUiData};
use crate::{
instance_hash_conversions::instance_path_hash_from_picking_layer_id, view_spatial::eye::Eye,
};
use crate::{eye::Eye, instance_hash_conversions::instance_path_hash_from_picking_layer_id};

#[derive(Clone, PartialEq, Eq)]
pub enum PickingHitType {
Expand Down
Loading