diff --git a/.vscode/settings.json b/.vscode/settings.json index fc273709cb4c..e4341b2a74ac 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,6 +24,7 @@ "cSpell.words": [ "andreas", "bbox", + "emath", "framebuffer", "hoverable", "Keypoint", diff --git a/crates/re_renderer/shader/point_cloud.wgsl b/crates/re_renderer/shader/point_cloud.wgsl index 85a4f2e085b8..7eae6f162dda 100644 --- a/crates/re_renderer/shader/point_cloud.wgsl +++ b/crates/re_renderer/shader/point_cloud.wgsl @@ -157,7 +157,7 @@ fn fs_main(in: VertexOut) -> @location(0) Vec4 { // Sphere intersection with anti-aliasing as described by Iq here // https://www.shadertoy.com/view/MsSSWV - // (but rearranged and labled to it's easier to understand!) + // (but rearranged and labeled to it's easier to understand!) let d = sphere_distance(ray, in.point_center, in.radius); let smallest_distance_to_sphere = d.x; let closest_ray_dist = d.y; diff --git a/crates/re_viewer/src/ui/view_spatial/mod.rs b/crates/re_viewer/src/ui/view_spatial/mod.rs index eb74729ff5d6..141f6c3f9dd6 100644 --- a/crates/re_viewer/src/ui/view_spatial/mod.rs +++ b/crates/re_viewer/src/ui/view_spatial/mod.rs @@ -7,9 +7,7 @@ mod ui_2d; mod ui_3d; mod ui_renderer_bridge; -pub use self::scene::{ - Image, Label2D, Label2DTarget, Label3D, MeshSource, MeshSourceData, SceneSpatial, -}; +pub use self::scene::{Image, MeshSource, MeshSourceData, SceneSpatial, UiLabel, UiLabelTarget}; pub use self::space_camera_3d::SpaceCamera3D; pub use ui::{SpatialNavigationMode, ViewSpatialState}; pub use ui_2d::view_2d; diff --git a/crates/re_viewer/src/ui/view_spatial/scene/mod.rs b/crates/re_viewer/src/ui/view_spatial/scene/mod.rs index 84376f4994c2..f0a3b0f94155 100644 --- a/crates/re_viewer/src/ui/view_spatial/scene/mod.rs +++ b/crates/re_viewer/src/ui/view_spatial/scene/mod.rs @@ -74,38 +74,32 @@ pub struct Image { pub annotations: Arc, } -pub enum Label2DTarget { +pub enum UiLabelTarget { /// Labels a given rect (in scene coordinates) Rect(egui::Rect), /// Labels a given point (in scene coordinates) - Point(egui::Pos2), + Point2D(egui::Pos2), + + /// A point in space. + Position3D(glam::Vec3), } -// TODO(andreas): Merge Label2D and Label3D -pub struct Label2D { +pub struct UiLabel { pub text: String, pub color: Color32, - /// The shape being labeled. - pub target: Label2DTarget, + /// The shape/position being labeled. + pub target: UiLabelTarget, /// What is hovered if this label is hovered. - pub labled_instance: InstancePathHash, -} - -pub struct Label3D { - pub(crate) text: String, - - /// Origin of the label - pub(crate) origin: glam::Vec3, + pub labeled_instance: InstancePathHash, } /// Data necessary to setup the ui [`SceneSpatial`] but of no interest to `re_renderer`. #[derive(Default)] pub struct SceneSpatialUiData { - pub labels_3d: Vec, - pub labels_2d: Vec, + pub labels: Vec, /// Picking any any of these rects cause the referred instance to be hovered. /// Only use this for 2d overlays! diff --git a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/boxes2d.rs b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/boxes2d.rs index 54c38ea77b08..f5ae78a22527 100644 --- a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/boxes2d.rs +++ b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/boxes2d.rs @@ -12,7 +12,7 @@ use crate::{ ui::{ scene::SceneQuery, view_spatial::{ - scene::scene_part::instance_path_hash_for_picking, Label2D, Label2DTarget, SceneSpatial, + scene::scene_part::instance_path_hash_for_picking, SceneSpatial, UiLabel, UiLabelTarget, }, DefaultColor, }, @@ -71,14 +71,14 @@ impl Boxes2DPart { .user_data(instance_path_hash); if let Some(label) = label { - scene.ui.labels_2d.push(Label2D { + scene.ui.labels.push(UiLabel { text: label, color, - target: Label2DTarget::Rect(egui::Rect::from_min_size( + target: UiLabelTarget::Rect(egui::Rect::from_min_size( rect.top_left_corner().into(), egui::vec2(rect.width(), rect.height()), )), - labled_instance: instance_path_hash, + labeled_instance: instance_path_hash, }); } } diff --git a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/boxes3d.rs b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/boxes3d.rs index 66b15e455eaf..a5435cb53793 100644 --- a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/boxes3d.rs +++ b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/boxes3d.rs @@ -12,7 +12,7 @@ use crate::{ misc::{OptionalSpaceViewEntityHighlight, SpaceViewHighlights, TransformCache, ViewerContext}, ui::{ scene::SceneQuery, - view_spatial::{Label3D, SceneSpatial}, + view_spatial::{SceneSpatial, UiLabel, UiLabelTarget}, DefaultColor, }, }; @@ -82,9 +82,11 @@ impl Boxes3DPart { .user_data(instance_hash); if let Some(label) = annotation_info.label(label.as_ref().map(|s| &s.0)) { - scene.ui.labels_3d.push(Label3D { + scene.ui.labels.push(UiLabel { text: label, - origin: world_from_obj.transform_point3(tran), + target: UiLabelTarget::Position3D(world_from_obj.transform_point3(tran)), + color, + labeled_instance: instance_hash, }); } }; diff --git a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/points2d.rs b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/points2d.rs index e5bef22be8c3..8a81b4cacd17 100644 --- a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/points2d.rs +++ b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/points2d.rs @@ -12,7 +12,7 @@ use crate::{ misc::{OptionalSpaceViewEntityHighlight, SpaceViewHighlights, TransformCache, ViewerContext}, ui::{ scene::SceneQuery, - view_spatial::{scene::Keypoints, Label2D, Label2DTarget, SceneSpatial}, + view_spatial::{scene::Keypoints, SceneSpatial, UiLabel, UiLabelTarget}, DefaultColor, }, }; @@ -101,11 +101,11 @@ impl Points2DPart { if let Some(label) = label { if label_batch.len() < max_num_labels { - label_batch.push(Label2D { + label_batch.push(UiLabel { text: label, color, - target: Label2DTarget::Point(egui::pos2(pos.x, pos.y)), - labled_instance: instance_hash, + target: UiLabelTarget::Point2D(egui::pos2(pos.x, pos.y)), + labeled_instance: instance_hash, }); } } @@ -115,7 +115,7 @@ impl Points2DPart { drop(point_batch); // Drop batch so we have access to the scene again (batches need to be dropped before starting new ones). if label_batch.len() < max_num_labels { - scene.ui.labels_2d.extend(label_batch.into_iter()); + scene.ui.labels.extend(label_batch.into_iter()); } // Generate keypoint connections if any. diff --git a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/points3d.rs b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/points3d.rs index b9fddeb1cff7..2eb72dd2f137 100644 --- a/crates/re_viewer/src/ui/view_spatial/scene/scene_part/points3d.rs +++ b/crates/re_viewer/src/ui/view_spatial/scene/scene_part/points3d.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use ahash::{HashMap, HashMapExt}; use glam::Mat4; -use re_data_store::{EntityPath, EntityProperties}; +use re_data_store::{EntityPath, EntityProperties, InstancePathHash}; use re_log_types::{ component_types::{ClassId, ColorRGBA, InstanceKey, KeypointId, Label, Point3D, Radius}, msg_bundle::Component, @@ -21,7 +21,7 @@ use crate::{ scene::SceneQuery, view_spatial::{ scene::{scene_part::instance_path_hash_for_picking, Keypoints}, - Label3D, SceneSpatial, + SceneSpatial, UiLabel, UiLabelTarget, }, Annotations, DefaultColor, }, @@ -117,24 +117,34 @@ impl Points3DPart { fn process_labels<'a>( entity_view: &'a EntityView, + instance_path_hashes: &'a [InstancePathHash], + colors: &'a [egui::Color32], annotation_infos: &'a [ResolvedAnnotationInfo], world_from_obj: Mat4, - ) -> Result + 'a, QueryError> { + ) -> Result + 'a, QueryError> { let labels = itertools::izip!( annotation_infos.iter(), entity_view.iter_primary()?, - entity_view.iter_component::