Skip to content

Commit

Permalink
feat(server): ✨ Add only touch option; refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Sep 17, 2023
1 parent 9f9d2e5 commit b923da3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 64 deletions.
45 changes: 24 additions & 21 deletions alvr/server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,28 +700,29 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
.map(|c| c.tracked)
.unwrap_or(false);

let mut tracking_manager_lock = tracking_manager.lock();

let motions;
let left_hand_skeleton;
let right_hand_skeleton;
{
let mut tracking_manager_lock = tracking_manager.lock();
let data_manager_lock = SERVER_DATA_MANAGER.read();
let config = &data_manager_lock.settings().headset;
let headset_config = &data_manager_lock.settings().headset;

motions = tracking_manager_lock.transform_motions(
config,
headset_config,
&tracking.device_motions,
[
tracking.hand_skeletons[0].is_some(),
tracking.hand_skeletons[1].is_some(),
],
);

left_hand_skeleton = tracking.hand_skeletons[0]
.map(|s| tracking::to_openvr_hand_skeleton(config, *LEFT_HAND_ID, s));
right_hand_skeleton = tracking.hand_skeletons[1]
.map(|s| tracking::to_openvr_hand_skeleton(config, *RIGHT_HAND_ID, s));
left_hand_skeleton = tracking.hand_skeletons[0].map(|s| {
tracking::to_openvr_hand_skeleton(headset_config, *LEFT_HAND_ID, s)
});
right_hand_skeleton = tracking.hand_skeletons[1].map(|s| {
tracking::to_openvr_hand_skeleton(headset_config, *RIGHT_HAND_ID, s)
});
}

// Note: using the raw unrecentered head
Expand Down Expand Up @@ -770,17 +771,25 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
.into_iter()
.map(|(id, motion)| tracking::to_ffi_motion(id, motion))
.collect::<Vec<_>>();
let mut ffi_left_hand_skeleton = left_hand_skeleton.map(tracking::to_ffi_skeleton);
let mut ffi_right_hand_skeleton =
right_hand_skeleton.map(tracking::to_ffi_skeleton);

drop(tracking_manager_lock);
let enable_skeleton = controllers_config
.as_ref()
.map(|c| !c.enable_skeleton)
.unwrap_or(false);
let ffi_left_hand_skeleton = enable_skeleton
.then_some(left_hand_skeleton)
.flatten()
.map(tracking::to_ffi_skeleton);
let ffi_right_hand_skeleton = enable_skeleton
.then_some(right_hand_skeleton)
.flatten()
.map(tracking::to_ffi_skeleton);

// Handle hand gestures
if let (Some(gestures_config), Some(gestures_button_mapping_manager)) = (
controllers_config
.as_ref()
.and_then(|c| c.hand_tracking.gestures.as_option()),
.and_then(|c| c.gestures.as_option()),
&mut gestures_button_mapping_manager,
) {
let mut hand_gesture_manager_lock = hand_gesture_manager.lock();
Expand All @@ -794,6 +803,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
gestures_config,
*LEFT_HAND_ID,
),
gestures_config.only_touch,
);
}
if let Some(hand_skeleton) = tracking.hand_skeletons[1] {
Expand All @@ -805,18 +815,11 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
gestures_config,
*RIGHT_HAND_ID,
),
gestures_config.only_touch,
);
}
}

if controllers_config
.map(|c| !c.hand_tracking.enable_skeleton)
.unwrap_or(false)
{
ffi_left_hand_skeleton = None;
ffi_right_hand_skeleton = None;
}

if let Some(stats) = &mut *STATISTICS_MANAGER.lock() {
stats.report_tracking_received(tracking.target_timestamp);

Expand Down
25 changes: 15 additions & 10 deletions alvr/server/src/hand_gestures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,17 @@ pub fn trigger_hand_gesture_actions(
button_mapping_manager: &mut ButtonMappingManager,
device_id: u64,
gestures: &[HandGesture],
only_touch: bool,
) {
for gesture in gestures.iter() {
// Click bind
if let Some(click_bind) = get_click_bind_for_gesture(device_id, gesture.id) {
button_mapping_manager.report_button(
click_bind,
ButtonValue::Binary(gesture.active && gesture.clicked),
);
if !only_touch {
if let Some(click_bind) = get_click_bind_for_gesture(device_id, gesture.id) {
button_mapping_manager.report_button(
click_bind,
ButtonValue::Binary(gesture.active && gesture.clicked),
);
}
}

// Touch bind
Expand All @@ -586,11 +589,13 @@ pub fn trigger_hand_gesture_actions(
}

// Hover bind
if let Some(hover_bind) = get_hover_bind_for_gesture(device_id, gesture.id) {
button_mapping_manager.report_button(
hover_bind,
ButtonValue::Scalar(if gesture.active { gesture.value } else { 0.0 }),
);
if !only_touch {
if let Some(hover_bind) = get_hover_bind_for_gesture(device_id, gesture.id) {
button_mapping_manager.report_button(
hover_bind,
ButtonValue::Scalar(if gesture.active { gesture.value } else { 0.0 }),
);
}
}
}
}
63 changes: 30 additions & 33 deletions alvr/session/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,22 +663,10 @@ pub struct AutomaticButtonMappingConfig {

#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
#[schema(collapsible)]
pub struct HandTrackingConfig {
pub struct HandGestureConfig {
#[schema(flag = "real-time")]
#[schema(strings(
help = "Enabling this allows using hand gestures to emulate controller inputs."
))]
pub gestures: Switch<HandGestureConfig>,
pub only_touch: bool,

#[schema(flag = "real-time")]
#[schema(strings(
help = "Enabling this passes skeletal hand data (finger tracking) to SteamVR."
))]
pub enable_skeleton: bool,
}

#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
pub struct HandGestureConfig {
#[schema(flag = "real-time")]
#[schema(strings(
help = "How close the tips of your fingers need to be to register a pinch click."
Expand Down Expand Up @@ -772,6 +760,12 @@ pub struct ControllersConfig {
#[schema(flag = "real-time")]
pub tracked: bool,

#[schema(flag = "real-time")]
#[schema(strings(
help = "Enabling this passes skeletal hand data (finger tracking) to SteamVR."
))]
pub enable_skeleton: bool,

#[schema(flag = "steamvr-restart")]
pub emulation_mode: ControllersEmulationMode,

Expand All @@ -783,7 +777,11 @@ pub struct ControllersConfig {

pub button_mapping_config: AutomaticButtonMappingConfig,

pub hand_tracking: HandTrackingConfig,
#[schema(flag = "real-time")]
#[schema(strings(
help = "Enabling this allows using hand gestures to emulate controller inputs."
))]
pub gestures: Switch<HandGestureConfig>,

#[schema(strings(
display_name = "Prediction",
Expand Down Expand Up @@ -1343,6 +1341,7 @@ pub fn session_settings_default() -> SettingsDefault {
content: ControllersConfigDefault {
gui_collapsed: false,
tracked: true,
enable_skeleton: true,
emulation_mode: ControllersEmulationModeDefault {
Custom: ControllersEmulationModeCustomDefault {
serial_number: "ALVR Controller".into(),
Expand Down Expand Up @@ -1399,25 +1398,23 @@ pub fn session_settings_default() -> SettingsDefault {
},
force_threshold: 0.8,
},
hand_tracking: HandTrackingConfigDefault {
gui_collapsed: true,
gestures: SwitchDefault {
enabled: true,
content: HandGestureConfigDefault {
pinch_touch_distance: 0.0,
pinch_trigger_distance: 0.25,
curl_touch_distance: 2.0,
curl_trigger_distance: 2.5,
joystick_deadzone: 40.0,
joystick_offset_horizontal: 0.0,
joystick_offset_vertical: 0.0,
joystick_range: 1.0,
repeat_delay: 100,
activation_delay: 50,
deactivation_delay: 100,
},
gestures: SwitchDefault {
enabled: true,
content: HandGestureConfigDefault {
gui_collapsed: true,
only_touch: false,
pinch_touch_distance: 0.0,
pinch_trigger_distance: 0.25,
curl_touch_distance: 2.0,
curl_trigger_distance: 2.5,
joystick_deadzone: 40.0,
joystick_offset_horizontal: 0.0,
joystick_offset_vertical: 0.0,
joystick_range: 1.0,
repeat_delay: 100,
activation_delay: 50,
deactivation_delay: 100,
},
enable_skeleton: true,
},
steamvr_pipeline_frames: 3.0,
linear_velocity_cutoff: 0.05,
Expand Down

0 comments on commit b923da3

Please sign in to comment.