polyscope_core/pick.rs
1//! Picking and selection system.
2
3use glam::Vec3;
4
5/// Result of a pick/selection operation.
6#[derive(Debug, Clone)]
7pub struct PickResult {
8 /// The type of structure that was picked.
9 pub structure_type: String,
10
11 /// The name of the structure that was picked.
12 pub structure_name: String,
13
14 /// The index of the element that was picked (vertex, face, etc.).
15 pub element_index: usize,
16
17 /// The world position of the pick point.
18 pub world_position: Vec3,
19
20 /// The depth of the pick point.
21 pub depth: f32,
22}
23
24impl PickResult {
25 /// Creates a new pick result.
26 pub fn new(
27 structure_type: impl Into<String>,
28 structure_name: impl Into<String>,
29 element_index: usize,
30 world_position: Vec3,
31 depth: f32,
32 ) -> Self {
33 Self {
34 structure_type: structure_type.into(),
35 structure_name: structure_name.into(),
36 element_index,
37 world_position,
38 depth,
39 }
40 }
41}
42
43/// Trait for objects that support picking/selection.
44pub trait Pickable {
45 /// Encodes this object's pick data into a color.
46 fn encode_pick_color(&self, element_index: usize) -> [u8; 4];
47
48 /// Decodes a pick color back to an element index.
49 fn decode_pick_color(&self, color: [u8; 4]) -> Option<usize>;
50
51 /// Returns the total number of pickable elements.
52 fn num_pickable_elements(&self) -> usize;
53}