Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Jan 19, 2025
1 parent 1a1f022 commit cfe35ca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 37 deletions.
30 changes: 14 additions & 16 deletions alvr/client_openxr/src/extra_extensions/multimodal_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,37 @@ static TYPE_SIMULTANEOUS_HANDS_AND_CONTROLLERS_TRACKING_PAUSE_INFO_META: Lazy<xr
Lazy::new(|| xr::StructureType::from_raw(1000532003));

#[repr(C)]
pub struct SystemSymultaneousHandsAndControllersPropertiesMETA {
struct SystemSymultaneousHandsAndControllersPropertiesMETA {
ty: xr::StructureType,
next: *const c_void,
supports_simultaneous_hands_and_controllers: sys::Bool32,
}

#[repr(C)]
pub struct SimultaneousHandsAndControllersTrackingResumeInfoMETA {
struct SimultaneousHandsAndControllersTrackingResumeInfoMETA {
ty: xr::StructureType,
next: *const c_void,
}
#[repr(C)]
pub struct SimultaneousHandsAndControllersTrackingPauseInfoMETA {
struct SimultaneousHandsAndControllersTrackingPauseInfoMETA {
ty: xr::StructureType,
next: *const c_void,
}

pub type ResumeSimultaneousHandsAndControllersTrackingMETA =
unsafe extern "system" fn(
sys::Session,
*const SimultaneousHandsAndControllersTrackingResumeInfoMETA,
) -> sys::Result;
pub type PauseSimultaneousHandsAndControllersTrackingMETA =
unsafe extern "system" fn(
sys::Session,
*const SimultaneousHandsAndControllersTrackingPauseInfoMETA,
) -> sys::Result;
type ResumeSimultaneousHandsAndControllersTrackingMETA = unsafe extern "system" fn(
sys::Session,
*const SimultaneousHandsAndControllersTrackingResumeInfoMETA,
) -> sys::Result;
type PauseSimultaneousHandsAndControllersTrackingMETA = unsafe extern "system" fn(
sys::Session,
*const SimultaneousHandsAndControllersTrackingPauseInfoMETA,
) -> sys::Result;

pub struct MultimodalMeta {
pub session: xr::Session<xr::AnyGraphics>,
pub resume_simultaneous_hands_and_controllers_tracking_meta:
session: xr::Session<xr::AnyGraphics>,
resume_simultaneous_hands_and_controllers_tracking_meta:
ResumeSimultaneousHandsAndControllersTrackingMETA,
pub pause_simultaneous_hands_and_controllers_tracking_meta:
pause_simultaneous_hands_and_controllers_tracking_meta:
PauseSimultaneousHandsAndControllersTrackingMETA,
}

Expand Down
27 changes: 13 additions & 14 deletions alvr/client_openxr/src/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub struct InteractionContext {
pub action_set: xr::ActionSet,
pub button_actions: HashMap<u64, ButtonAction>,
pub hands_interaction: [HandInteraction; 2],
pub multimodal_hands: Option<(MultimodalMeta, bool)>,
multimodal_handle: Option<MultimodalMeta>,
pub multimodal_hands_enabled: bool,
pub face_sources: FaceSources,
pub body_sources: BodySources,
}
Expand Down Expand Up @@ -229,13 +230,13 @@ impl InteractionContext {
"/user/hand/right/output/haptic",
));

let multimodal = create_ext_object("MultimodalMeta", Some(true), || {
MultimodalMeta::new(xr_session.clone(), &extra_extensions, xr_system)
let multimodal_handle = create_ext_object("MultimodalMeta", Some(true), || {
MultimodalMeta::new(xr_session.clone(), extra_extensions, xr_system)
});

let left_detached_controller_pose_action;
let right_detached_controller_pose_action;
if multimodal.is_some() {
if multimodal_handle.is_some() {
// Note: when multimodal input is enabled, both controllers and hands will always be active.
// To be able to detect when controllers are actually held, we have to register detached
// controllers pose; the controller pose will be diverted to the detached controllers when
Expand Down Expand Up @@ -359,7 +360,8 @@ impl InteractionContext {
skeleton_tracker: right_hand_tracker,
},
],
multimodal_hands: multimodal.map(|m| (m, false)),
multimodal_handle,
multimodal_hands_enabled: false,
face_sources: FaceSources {
combined_eyes_source,
eye_tracker_fb: None,
Expand All @@ -375,12 +377,10 @@ impl InteractionContext {

pub fn select_sources(&mut self, config: &InteractionSourcesConfig) {
// First of all, disable/delete all sources. This ensures there are no conflicts
if let Some((handle, enabled)) = &mut self.multimodal_hands {
if *enabled {
handle.pause().ok();
*enabled = false;
}
if let Some(handle) = &mut self.multimodal_handle {
handle.pause().ok();
}
self.multimodal_hands_enabled = false;
self.face_sources.eye_tracker_fb = None;
self.face_sources.face_tracker_fb = None;
self.face_sources.eye_tracker_htc = None;
Expand Down Expand Up @@ -415,10 +415,9 @@ impl InteractionContext {
// Note: We cannot enable multimodal if fb body tracking is active. It would result in a
// ERROR_RUNTIME_FAILURE crash.
if config.body_tracking.is_none() && config.prefers_multimodal_input {
if let Some((handle, enabled)) = &mut self.multimodal_hands {
if !*enabled {
handle.resume().ok();
*enabled = true;
if let Some(handle) = &mut self.multimodal_handle {
if handle.resume().is_ok() {
self.multimodal_hands_enabled = true;
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions alvr/client_openxr/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,17 +510,12 @@ fn stream_input_loop(

// Note: When multimodal input is enabled, we are sure that when free hands are used
// (not holding controllers) the controller data is None.
let multimodal_enabled = int_ctx
.multimodal_hands
.as_ref()
.map(|(_, enabled)| *enabled)
.unwrap_or(false);
if multimodal_enabled || left_hand_skeleton.is_none() {
if int_ctx.multimodal_hands_enabled || left_hand_skeleton.is_none() {
if let Some(motion) = left_hand_motion {
device_motions.push((*HAND_LEFT_ID, motion));
}
}
if multimodal_enabled || right_hand_skeleton.is_none() {
if int_ctx.multimodal_hands_enabled || right_hand_skeleton.is_none() {
if let Some(motion) = right_hand_motion {
device_motions.push((*HAND_RIGHT_ID, motion));
}
Expand Down

0 comments on commit cfe35ca

Please sign in to comment.