Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Surface supported interaction profiles from OpenXR runtime #229

Merged
merged 7 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion webxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ webxr-api = { path = "../webxr-api" }
crossbeam-channel = "0.5"
euclid = "0.22"
log = "0.4.6"
openxr = { version = "0.18", optional = true }
openxr = { version = "0.19", optional = true }
serde = { version = "1.0", optional = true }
sparkle = "0.1"
surfman = { version = "0.9", features = ["chains"] }
Expand Down
80 changes: 48 additions & 32 deletions webxr/openxr/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use euclid::RigidTransform3D;
use log::debug;
use openxr::d3d::D3D11;
use openxr::{
self, Action, ActionSet, Binding, FrameState, Hand as HandEnum, HandJoint, HandTracker,
Expand All @@ -19,6 +20,9 @@ use webxr_api::Viewer;

use super::IDENTITY_POSE;

use crate::ext_string;
use crate::openxr::interaction_profiles::INTERACTION_PROFILES;

/// Number of frames to wait with the menu gesture before
/// opening the menu.
const MENU_GESTURE_SUSTAIN_THRESHOLD: u8 = 60;
Expand Down Expand Up @@ -173,6 +177,7 @@ impl OpenXRInput {
instance: &Instance,
session: &Session<D3D11>,
needs_hands: bool,
supported_interaction_profiles: Vec<&'static str>,
) -> (ActionSet, Self, Self) {
let action_set = instance.create_action_set("hands", "Hands", 0).unwrap();
let right_hand = OpenXRInput::new(
Expand All @@ -190,32 +195,33 @@ impl OpenXRInput {
needs_hands,
);

let mut bindings =
right_hand.get_bindings(instance, "trigger/value", Some("squeeze/click"));
bindings.extend(
left_hand
.get_bindings(instance, "trigger/value", Some("squeeze/click"))
.into_iter(),
);
let path_controller = instance
.string_to_path("/interaction_profiles/microsoft/motion_controller")
.unwrap();
instance
.suggest_interaction_profile_bindings(path_controller, &bindings)
.unwrap();
for profile in INTERACTION_PROFILES {
if let Some(extension_name) = profile.required_extension {
if !supported_interaction_profiles.contains(&ext_string!(extension_name)) {
continue;
}
}
let select = profile.standard_buttons[0];
let squeeze = Option::from(profile.standard_buttons[1]).filter(|&s| !s.is_empty());
let mut bindings = right_hand.get_bindings(instance, select, squeeze);
bindings.extend(
left_hand
.get_bindings(instance, select, squeeze)
.into_iter(),
);
let path_controller = instance
.string_to_path(profile.path)
.expect(format!("Invalid interaction profile path: {}", profile.path).as_str());
if let Err(_) =
instance.suggest_interaction_profile_bindings(path_controller, &bindings)
{
debug!(
"Interaction profile path not available for this runtime: {:?}",
profile.path
);
}
}

let mut bindings = right_hand.get_bindings(instance, "select/click", None);
bindings.extend(
left_hand
.get_bindings(instance, "select/click", None)
.into_iter(),
);
let path_controller = instance
.string_to_path("/interaction_profiles/khr/simple_controller")
.unwrap();
instance
.suggest_interaction_profile_bindings(path_controller, &bindings)
.unwrap();
session.attach_action_sets(&[&action_set]).unwrap();

(action_set, right_hand, left_hand)
Expand All @@ -230,22 +236,34 @@ impl OpenXRInput {
let hand = hand_str(self.handedness);
let path_aim_pose = instance
.string_to_path(&format!("/user/hand/{}/input/aim/pose", hand))
.unwrap();
.expect(&format!(
"Failed to create path for /user/hand/{}/input/aim/pose",
hand
));
let binding_aim_pose = Binding::new(&self.action_aim_pose, path_aim_pose);
let path_grip_pose = instance
.string_to_path(&format!("/user/hand/{}/input/grip/pose", hand))
.unwrap();
.expect(&format!(
"Failed to create path for /user/hand/{}/input/grip/pose",
hand
));
let binding_grip_pose = Binding::new(&self.action_grip_pose, path_grip_pose);
let path_click = instance
.string_to_path(&format!("/user/hand/{}/input/{}", hand, select_name))
.unwrap();
.expect(&format!(
"Failed to create path for /user/hand/{}/input/{}",
hand, select_name
));
let binding_click = Binding::new(&self.action_click, path_click);

let mut ret = vec![binding_aim_pose, binding_grip_pose, binding_click];
if let Some(squeeze_name) = squeeze_name {
let path_squeeze = instance
.string_to_path(&format!("/user/hand/{}/input/{}", hand, squeeze_name))
.unwrap();
.expect(&format!(
"Failed to create path for /user/hand/{}/input/{}",
hand, squeeze_name
));
let binding_squeeze = Binding::new(&self.action_squeeze, path_squeeze);
ret.push(binding_squeeze);
}
Expand Down Expand Up @@ -349,9 +367,7 @@ impl OpenXRInput {
id: self.id,
target_ray_mode: TargetRayMode::TrackedPointer,
supports_grip: true,
// XXXManishearth update with whatever we decide
// in https://github.com/immersive-web/webxr-input-profiles/issues/105
profiles: vec!["generic-hand".into()],
profiles: vec![],
hand_support,
}
}
Expand Down
Loading
Loading