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

Use GPU picking for line(like) primitives, fix interactive flags #1829

Merged
merged 16 commits into from
Apr 13, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
warning fixes
Wumpf committed Apr 12, 2023
commit e110091e2efd86b1a1af8b6911ae6d2d7895e943
5 changes: 3 additions & 2 deletions crates/re_renderer/src/line_strip_builder.rs
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ impl<'a> LineBatchBuilder<'a> {
/// Sets the picking object id for every element in the batch.
pub fn picking_object_id(mut self, picking_object_id: PickingLayerObjectId) -> Self {
//self.batch_mut().picking_object_id = picking_object_id;
todo!("");
//todo!("");
self
}

@@ -401,7 +401,8 @@ impl<'a> LineStripBuilder<'a> {
}

pub fn picking_instance_id(self, instance_id: PickingLayerInstanceId) -> Self {
todo!()
//todo!()
self
}

/// Sets an individual outline mask ids.
33 changes: 2 additions & 31 deletions crates/re_viewer/src/ui/view_spatial/scene/picking.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
//! Handles picking in 2D & 3D spaces.

use itertools::Itertools as _;

use re_data_store::InstancePathHash;
use re_renderer::PickingLayerProcessor;

use super::{SceneSpatialPrimitives, SceneSpatialUiData};
use crate::{
math::{line_segment_distance_sq_to_point_2d, ray_closest_t_line_segment},
misc::instance_hash_conversions::instance_path_hash_from_picking_layer_id,
ui::view_spatial::eye::Eye,
};
@@ -44,15 +41,6 @@ pub struct PickingRayHit {
}

impl PickingRayHit {
fn from_instance_and_t(instance_path_hash: InstancePathHash, t: f32) -> Self {
Self {
instance_path_hash,
ray_t: t,
info: AdditionalPickingInfo::None,
depth_offset: 0,
}
}

pub fn space_position(&self, ray_in_world: &macaw::Ray3) -> glam::Vec3 {
ray_in_world.origin + ray_in_world.dir * self.ray_t
}
@@ -151,9 +139,6 @@ pub struct PickingContext {
/// The picking ray used. Given in the coordinates of the space the picking is performed in.
pub ray_in_world: macaw::Ray3,

/// Transformation from ui coordinates to world coordinates.
ui_from_world: glam::Mat4,

/// Multiply with this to convert to pixels from points.
pixels_from_points: f32,
}
@@ -180,7 +165,6 @@ impl PickingContext {
pointer_in_space2d,
pointer_in_pixel: glam::vec2(pointer_in_pixel.x, pointer_in_pixel.y),
pointer_in_ui: glam::vec2(pointer_in_ui.x, pointer_in_ui.y),
ui_from_world: eye.ui_from_world(*space2d_from_ui.to()),
ray_in_world: eye.picking_ray(*space2d_from_ui.to(), pointer_in_space2d),
pixels_from_points,
}
@@ -211,31 +195,18 @@ impl PickingContext {
transparent_hits: Vec::new(),
};

let SceneSpatialPrimitives {
bounding_box: _,
textured_rectangles,
textured_rectangles_ids,
line_strips,
points: _,
meshes: _,
depth_clouds: _, // no picking for depth clouds yet
any_outlines: _,
} = primitives;

// GPU based picking.
picking_gpu(
render_ctx,
gpu_readback_identifier,
&mut state,
self,
previous_picking_result,
);

picking_textured_rects(
self,
&mut state,
textured_rectangles,
textured_rectangles_ids,
&primitives.textured_rectangles,
&primitives.textured_rectangles_ids,
);
picking_ui_rects(self, &mut state, ui_data);

5 changes: 1 addition & 4 deletions crates/re_viewer/src/ui/view_spatial/scene/primitives.rs
Original file line number Diff line number Diff line change
@@ -5,10 +5,7 @@ use re_renderer::{
LineStripSeriesBuilder, PointCloudBuilder,
};

use crate::{
misc::instance_hash_conversions::picking_layer_id_from_instance_path_hash,
ui::view_spatial::scene::scene_part::instance_path_hash_for_picking,
};
use crate::misc::instance_hash_conversions::picking_layer_id_from_instance_path_hash;

use super::MeshSource;

Original file line number Diff line number Diff line change
@@ -8,14 +8,11 @@ use re_query::{query_primary_with_history, EntityView, QueryError};
use re_renderer::Size;

use crate::{
misc::{
instance_hash_conversions::picking_layer_id_from_instance_path_hash, SpaceViewHighlights,
TransformCache, ViewerContext,
},
misc::{SpaceViewHighlights, TransformCache, ViewerContext},
ui::{scene::SceneQuery, view_spatial::SceneSpatial, DefaultColor},
};

use super::{instance_key_to_picking_id, instance_path_hash_for_picking, ScenePart};
use super::{instance_key_to_picking_id, ScenePart};

pub struct Arrows3DPart;

@@ -65,7 +62,7 @@ impl Arrows3DPart {
let radius = radius.map_or(Size::AUTO, |r| Size(r.0));
let end = origin + vector;

let mut segment = line_batch
let segment = line_batch
.add_segment(origin, end)
.radius(radius)
.color(color)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use glam::Mat4;
use re_data_store::{EntityPath, EntityProperties, InstancePathHash};
use re_data_store::{EntityPath, EntityProperties};
use re_log_types::{
component_types::{ClassId, ColorRGBA, InstanceKey, Label, Radius, Rect2D},
Component,
@@ -8,7 +8,7 @@ use re_query::{query_primary_with_history, EntityView, QueryError};
use re_renderer::Size;

use crate::{
misc::{SpaceViewHighlights, SpaceViewOutlineMasks, TransformCache, ViewerContext},
misc::{SpaceViewHighlights, TransformCache, ViewerContext},
ui::{
scene::SceneQuery,
view_spatial::{
@@ -27,7 +27,7 @@ impl Boxes2DPart {
fn process_entity_view(
scene: &mut SceneSpatial,
_query: &SceneQuery<'_>,
properties: &EntityProperties,
_properties: &EntityProperties,
entity_view: &EntityView<Rect2D>,
ent_path: &EntityPath,
world_from_obj: Mat4,
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ impl Boxes3DPart {
let tran = position.map_or(glam::Vec3::ZERO, glam::Vec3::from);
let transform = glam::Affine3A::from_scale_rotation_translation(scale, rot, tran);

let mut box_lines = line_batch
let box_lines = line_batch
.add_box_outline(transform)
.radius(radius)
.color(color)
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ use crate::{
ui::{scene::SceneQuery, view_spatial::SceneSpatial, DefaultColor},
};

use super::{instance_key_to_picking_id, instance_path_hash_for_picking, ScenePart};
use super::{instance_key_to_picking_id, ScenePart};

pub struct Lines2DPart;

@@ -22,7 +22,7 @@ impl Lines2DPart {
fn process_entity_view(
scene: &mut SceneSpatial,
_query: &SceneQuery<'_>,
properties: &EntityProperties,
_properties: &EntityProperties,
entity_view: &EntityView<LineStrip2D>,
ent_path: &EntityPath,
world_from_obj: Mat4,
@@ -51,7 +51,7 @@ impl Lines2DPart {
let color =
annotation_info.color(color.map(move |c| c.to_array()).as_ref(), default_color);

let mut lines = line_batch
let lines = line_batch
.add_strip_2d(strip.0.into_iter().map(|v| v.into()))
.color(color)
.radius(radius)
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ use crate::{
ui::{scene::SceneQuery, view_spatial::SceneSpatial, DefaultColor},
};

use super::{instance_key_to_picking_id, instance_path_hash_for_picking, ScenePart};
use super::{instance_key_to_picking_id, ScenePart};

pub struct Lines3DPart;

@@ -22,7 +22,7 @@ impl Lines3DPart {
fn process_entity_view(
scene: &mut SceneSpatial,
_query: &SceneQuery<'_>,
properties: &EntityProperties,
_properties: &EntityProperties,
entity_view: &EntityView<LineStrip3D>,
ent_path: &EntityPath,
world_from_obj: Mat4,
@@ -51,7 +51,7 @@ impl Lines3DPart {
let color =
annotation_info.color(color.map(move |c| c.to_array()).as_ref(), default_color);

let mut lines = line_batch
let lines = line_batch
.add_strip(strip.0.into_iter().map(|v| v.into()))
.radius(radius)
.color(color)
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ use crate::{
Annotations, DefaultColor,
},
};
use re_data_store::{EntityPath, EntityProperties, InstancePathHash};
use re_data_store::{EntityPath, InstancePathHash};

pub trait ScenePart {
fn load(
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ impl Points2DPart {
&self,
scene: &mut SceneSpatial,
query: &SceneQuery<'_>,
properties: &EntityProperties,
_properties: &EntityProperties,
entity_view: &EntityView<Point2D>,
ent_path: &EntityPath,
world_from_obj: Mat4,
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ impl Points3DPart {
&self,
scene: &mut SceneSpatial,
query: &SceneQuery<'_>,
properties: &EntityProperties,
_properties: &EntityProperties,
entity_view: &EntityView<Point3D>,
ent_path: &EntityPath,
world_from_obj: Mat4,
3 changes: 1 addition & 2 deletions crates/re_viewer/src/ui/view_spatial/ui_2d.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use eframe::emath::RectTransform;
use egui::{pos2, vec2, Align2, Color32, NumExt as _, Pos2, Rect, ScrollArea, Shape, Vec2};
use macaw::IsoTransform;
use re_data_store::{entity_properties, EntityPath, EntityPropertyMap};
use re_data_store::{EntityPath, EntityPropertyMap};
use re_renderer::view_builder::{TargetConfiguration, ViewBuilder};

use super::{
@@ -12,7 +12,6 @@ use super::{
use crate::{
misc::{HoveredSpace, SpaceViewHighlights},
ui::{
data_blueprint::DataBlueprintTree,
view_spatial::{
ui::outline_config,
ui_renderer_bridge::{
1 change: 0 additions & 1 deletion crates/re_viewer/src/ui/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ use re_renderer::{
use crate::{
misc::{HoveredSpace, Item, SpaceViewHighlights},
ui::{
data_blueprint::DataBlueprintTree,
view_spatial::{
ui::{create_labels, outline_config, picking, screenshot_context_menu},
ui_renderer_bridge::{