finnish everything

This commit is contained in:
Schmarni
2023-11-14 02:32:57 +01:00
parent 74e4e0c3b7
commit e5363acac9
10 changed files with 97 additions and 74 deletions

View File

@@ -23,6 +23,8 @@ use xr_input::hand::HandInputSource;
use xr_input::handtracking::HandTrackingTracker;
use xr_input::OpenXrInput;
use crate::xr_input::oculus_touch::ActionSets;
const VIEW_TYPE: xr::ViewConfigurationType = xr::ViewConfigurationType::PRIMARY_STEREO;
pub const LEFT_XR_TEXTURE_HANDLE: ManualTextureViewHandle = ManualTextureViewHandle(1208214591);
@@ -96,7 +98,7 @@ impl Plugin for OpenXrPlugin {
views,
frame_state,
));
// app.insert_resource(ActionSets(vec![]));
app.insert_resource(ActionSets(vec![]));
app.add_plugins(RenderPlugin {
render_creation: RenderCreation::Manual(
device,
@@ -131,7 +133,7 @@ impl Plugin for OpenXrPlugin {
frame_state,
) = future_renderer_resources.0.lock().unwrap().take().unwrap();
// let action_sets = app.world.resource::<ActionSets>().clone();
let action_sets = app.world.resource::<ActionSets>().clone();
app.insert_resource(xr_instance.clone())
.insert_resource(session.clone())
@@ -143,8 +145,8 @@ impl Plugin for OpenXrPlugin {
.insert_resource(swapchain.clone())
.insert_resource(input.clone())
.insert_resource(views.clone())
.insert_resource(frame_state.clone());
// .insert_resource(action_sets.clone());
.insert_resource(frame_state.clone())
.insert_resource(action_sets.clone());
let hands = xr_instance.exts().ext_hand_tracking.is_some();
let hands = false;
if hands {
@@ -183,8 +185,8 @@ impl Plugin for OpenXrPlugin {
.insert_resource(swapchain)
.insert_resource(input)
.insert_resource(views)
.insert_resource(frame_state);
// .insert_resource(action_sets);
.insert_resource(frame_state)
.insert_resource(action_sets);
render_app.add_systems(
Render,

View File

@@ -4,6 +4,8 @@ use xr::{Action, Binding, Haptic, Posef};
use crate::resources::{XrInstance, XrSession};
use super::oculus_touch::ActionSets;
pub struct OpenXrActionsPlugin;
impl Plugin for OpenXrActionsPlugin {
fn build(&self, app: &mut App) {
@@ -22,103 +24,123 @@ pub fn setup_oxr_actions(world: &mut World) {
let right_path = instance.string_to_path("/user/hand/right").unwrap();
let hands = [left_path, right_path];
let mut action_sets = ActionSets { sets: default() };
let mut action_bindings: HashMap<&'static str, Vec<xr::Path>> = HashMap::new();
let mut oxr_action_sets = Vec::new();
let mut action_sets = XrActionSets { sets: default() };
// let mut action_bindings: HashMap<&'static str, Vec<xr::Path>> = HashMap::new();
let mut a_iter = actions.sets.into_iter();
let mut action_bindings: HashMap<
(&'static str, &'static str),
HashMap<&'static str, Vec<xr::Path>>,
> = HashMap::new();
while let Some((set_name, set)) = a_iter.next() {
let mut actions: HashMap<&'static str, TypedAction> = default();
let oxr_action_set = instance
.create_action_set(set_name, set.pretty_name, set.priority)
.unwrap();
.expect("Unable to create action set");
for (action_name, action) in set.actions.into_iter() {
let typed_action = match action.action_type {
ActionType::F32 => TypedAction::F32(match action.handednes {
ActionHandednes::Single => oxr_action_set
.create_action(action_name, action.pretty_name, &[])
.unwrap(),
.expect(&format!("Unable to create action: {}", action_name)),
ActionHandednes::Double => oxr_action_set
.create_action(action_name, action.pretty_name, &hands)
.unwrap(),
.expect(&format!("Unable to create action: {}", action_name)),
}),
ActionType::Bool => TypedAction::Bool(match action.handednes {
ActionHandednes::Single => oxr_action_set
.create_action(action_name, action.pretty_name, &[])
.expect(action.pretty_name),
.expect(&format!("Unable to create action: {}", action_name)),
ActionHandednes::Double => oxr_action_set
.create_action(action_name, action.pretty_name, &hands)
.unwrap(),
.expect(&format!("Unable to create action: {}", action_name)),
}),
ActionType::PoseF => TypedAction::PoseF(match action.handednes {
ActionHandednes::Single => oxr_action_set
.create_action(action_name, action.pretty_name, &[])
.unwrap(),
.expect(&format!("Unable to create action: {}", action_name)),
ActionHandednes::Double => oxr_action_set
.create_action(action_name, action.pretty_name, &hands)
.unwrap(),
.expect(&format!("Unable to create action: {}", action_name)),
}),
ActionType::Haptic => TypedAction::Haptic(match action.handednes {
ActionHandednes::Single => oxr_action_set
.create_action(action_name, action.pretty_name, &[])
.unwrap(),
.expect(&format!("Unable to create action: {}", action_name)),
ActionHandednes::Double => oxr_action_set
.create_action(action_name, action.pretty_name, &hands)
.unwrap(),
.expect(&format!("Unable to create action: {}", action_name)),
}),
};
actions.insert(action_name, typed_action);
for (device_path, bindings) in action.bindings.into_iter() {
for b in bindings {
info!("binding {} to {}", action_name, b);
action_bindings
.entry((set_name, action_name))
.or_default()
.entry(device_path)
.or_default()
.push(instance.string_to_path(b).unwrap());
}
}
}
oxr_action_sets.push(oxr_action_set);
action_sets.sets.insert(
set_name,
ActionSet {
oxr_action_set,
// oxr_action_set,
actions,
enabled: true,
},
);
}
for (dev, bindings) in action_sets
let mut b_indings: HashMap<&'static str, Vec<Binding>> = HashMap::new();
for (dev, mut bindings) in action_sets
.sets
.iter()
.flat_map(|(_, set)| set.actions.iter().map(|(_, a)| a))
.zip(action_bindings.into_iter())
.map(|(action, (dev, bindings))| {
.flat_map(|(set_name, set)| {
set.actions
.iter()
.map(move |(action_name, a)| (set_name, action_name, a))
})
.zip([&action_bindings].into_iter().cycle())
.flat_map(move |((set_name, action_name, action), bindings)| {
bindings
.get(&(set_name.clone(), action_name.clone()))
.unwrap()
.iter()
.map(move |(dev, bindings)| (action.clone(), dev.clone(), bindings))
})
.map(|(action, dev, bindings)| {
info!("Hi");
(
dev,
bindings
.into_iter()
.map(move |binding| match &action {
TypedAction::F32(a) => Binding::new(a, binding),
TypedAction::Bool(a) => Binding::new(a, binding),
TypedAction::PoseF(a) => Binding::new(a, binding),
TypedAction::Haptic(a) => Binding::new(a, binding),
TypedAction::F32(a) => Binding::new(a, *binding),
TypedAction::Bool(a) => Binding::new(a, *binding),
TypedAction::PoseF(a) => Binding::new(a, *binding),
TypedAction::Haptic(a) => Binding::new(a, *binding),
})
.collect::<Vec<_>>(),
)
})
{
b_indings.entry(dev).or_default().append(&mut bindings);
}
for (dev, bindings) in b_indings.into_iter() {
info!(dev);
instance
.suggest_interaction_profile_bindings(instance.string_to_path(dev).unwrap(), &bindings)
.unwrap();
.expect("Unable to suggest interaction bindings!");
}
session
.attach_action_sets(
&action_sets
.sets
.iter()
.map(|(_, set)| &set.oxr_action_set)
.collect::<Vec<_>>(),
)
.unwrap();
.attach_action_sets(&oxr_action_sets.iter().collect::<Vec<_>>())
.expect("Unable to attach action sets!");
world.insert_resource(ActionSets(oxr_action_sets));
world.insert_resource(action_sets);
}
@@ -224,17 +246,17 @@ impl SetupActionSets {
}
pub struct ActionSet {
oxr_action_set: xr::ActionSet,
// oxr_action_set: xr::ActionSet,
enabled: bool,
actions: HashMap<&'static str, TypedAction>,
}
#[derive(Resource)]
pub struct ActionSets {
pub struct XrActionSets {
sets: HashMap<&'static str, ActionSet>,
}
impl ActionSets {
impl XrActionSets {
pub fn get_action_f32(
&self,
action_set: &'static str,

View File

@@ -14,7 +14,7 @@ use crate::xr_input::{
};
use super::{
actions::ActionSets,
actions::XrActionSets,
handtracking::{HandTrackingRef, HandTrackingTracker},
trackers::{OpenXRLeftController, OpenXRRightController, OpenXRTrackingRoot},
QuatConv,
@@ -56,7 +56,7 @@ pub fn draw_gizmos(
Without<OpenXRTrackingRoot>,
)>,
hand_tracking: Option<Res<HandTrackingTracker>>,
action_sets: Res<ActionSets>,
action_sets: Res<XrActionSets>,
) {
if let Some(hand_tracking) = hand_tracking {
let handtracking_ref = hand_tracking.get_ref(&xr_input, &frame_state);
@@ -96,7 +96,6 @@ pub fn draw_gizmos(
let frame_state = *frame_state.lock().unwrap();
//get controller
let controller = oculus_controller.get_ref(&session, &frame_state, &xr_input, &action_sets);
info!("{}",controller.x_button());
//tracking root?
let mut tracking_transform = &Transform::IDENTITY;
let root = tracking_root_query.get_single();

View File

@@ -14,7 +14,7 @@ use crate::{
};
use super::{
actions::ActionSets,
actions::XrActionSets,
hand_poses::get_simulated_open_hand_transforms,
handtracking::HandTrackingTracker,
oculus_touch::OculusController,
@@ -364,7 +364,7 @@ pub fn update_hand_states(
xr_input: Res<XrInput>,
instance: Res<XrInstance>,
session: Res<XrSession>,
action_sets: Res<ActionSets>,
action_sets: Res<XrActionSets>,
) {
match hand_states_option {
Some(mut hands) => {

View File

@@ -24,7 +24,7 @@ use bevy::render::view::{update_frusta, VisibilitySystems};
use bevy::transform::TransformSystem;
use self::actions::{setup_oxr_actions, OpenXrActionsPlugin};
use self::oculus_touch::post_action_setup_oculus_controller;
use self::oculus_touch::{post_action_setup_oculus_controller, ActionSets};
use self::trackers::{
adopt_open_xr_trackers, update_open_xr_controllers, OpenXRLeftEye, OpenXRRightEye,
OpenXRTrackingRoot,
@@ -61,7 +61,7 @@ impl Plugin for OpenXrInput {
}
//adopt any new trackers
app.add_systems(PreUpdate, adopt_open_xr_trackers);
// app.add_systems(PreUpdate, action_set_system);
app.add_systems(PreUpdate, action_set_system);
app.add_systems(PreUpdate, xr_camera_head_sync.after(xr_begin_frame));
//update controller trackers
app.add_systems(Update, update_open_xr_controllers);
@@ -90,19 +90,19 @@ fn setup_xr_cameras(mut commands: Commands) {
commands.entity(tracking_root).push_children(&[right, left]);
}
// fn action_set_system(action_sets: Res<ActionSets>, session: Res<XrSession>) {
// let mut active_action_sets = vec![];
// for i in &action_sets.0 {
// active_action_sets.push(openxr::ActiveActionSet::new(i));
// }
// //info!("action sets: {:#?}", action_sets.0.len());
// match session.sync_actions(&active_action_sets) {
// Err(err) => {
// warn!("{}", err);
// }
// _ => {}
// }
// }
fn action_set_system(action_sets: Res<ActionSets>, session: Res<XrSession>) {
let mut active_action_sets = vec![];
for i in &action_sets.0 {
active_action_sets.push(openxr::ActiveActionSet::new(i));
}
//info!("action sets: {:#?}", action_sets.0.len());
match session.sync_actions(&active_action_sets) {
Err(err) => {
warn!("{}", err);
}
_ => {}
}
}
pub trait Vec3Conv {
fn to_vec3(&self) -> Vec3;

View File

@@ -11,10 +11,10 @@ use openxr::{
use std::convert::identity;
use std::sync::OnceLock;
use super::actions::{ActionHandednes, ActionSets, ActionType, SetupActionSets, XrBinding};
use super::actions::{ActionHandednes, XrActionSets, ActionType, SetupActionSets, XrBinding};
pub fn post_action_setup_oculus_controller(
action_sets: Res<ActionSets>,
action_sets: Res<XrActionSets>,
mut controller: ResMut<OculusController>,
instance: Res<XrInstance>,
session: Res<XrSession>,
@@ -64,19 +64,19 @@ pub fn post_action_setup_oculus_controller(
pub fn setup_oculus_controller(
mut commands: Commands,
instance: Res<XrInstance>,
mut action_sets: ResMut<SetupActionSets>,
action_sets: ResMut<SetupActionSets>,
) {
let oculus_controller = OculusController::new(action_sets).unwrap();
init_subaction_path(&instance);
commands.insert_resource(oculus_controller);
}
// #[derive(Resource, Clone)]
// pub struct ActionSets(pub Vec<ActionSet>);
#[derive(Resource, Clone)]
pub struct ActionSets(pub Vec<ActionSet>);
pub struct OculusControllerRef<'a> {
oculus_controller: &'a OculusController,
action_sets: &'a ActionSets,
action_sets: &'a XrActionSets,
session: &'a Session<AnyGraphics>,
frame_state: &'a FrameState,
xr_input: &'a XrInput,
@@ -278,7 +278,7 @@ impl OculusController {
session: &'a Session<AnyGraphics>,
frame_state: &'a FrameState,
xr_input: &'a XrInput,
action_sets: &'a ActionSets,
action_sets: &'a XrActionSets,
) -> OculusControllerRef {
OculusControllerRef {
oculus_controller: self,

View File

@@ -11,7 +11,7 @@ use crate::{
};
use super::{
actions::ActionSets, oculus_touch::OculusController, trackers::OpenXRTrackingRoot, Hand,
actions::XrActionSets, oculus_touch::OculusController, trackers::OpenXRTrackingRoot, Hand,
QuatConv, Vec3Conv,
};
@@ -68,7 +68,7 @@ pub fn proto_locomotion(
views: ResMut<XrViews>,
mut gizmos: Gizmos,
config_option: Option<ResMut<PrototypeLocomotionConfig>>,
action_sets: Res<ActionSets>,
action_sets: Res<XrActionSets>,
) {
match config_option {
Some(_) => (),

View File

@@ -8,7 +8,7 @@ use crate::{
resources::{XrFrameState, XrInstance, XrSession},
};
use super::{actions::ActionSets, oculus_touch::OculusController, Hand, QuatConv, Vec3Conv};
use super::{actions::XrActionSets, oculus_touch::OculusController, Hand, QuatConv, Vec3Conv};
#[derive(Component)]
pub struct OpenXRTrackingRoot;
@@ -64,7 +64,7 @@ pub fn update_open_xr_controllers(
frame_state: Res<XrFrameState>,
xr_input: Res<XrInput>,
session: Res<XrSession>,
action_sets: Res<ActionSets>,
action_sets: Res<XrActionSets>,
) {
//lock dat frame?
let frame_state = *frame_state.lock().unwrap();