slight cleanup
This commit is contained in:
13
src/lib.rs
13
src/lib.rs
@@ -21,10 +21,10 @@ use bevy::window::{PresentMode, PrimaryWindow, RawHandleWrapper};
|
|||||||
use input::XrInput;
|
use input::XrInput;
|
||||||
use openxr as xr;
|
use openxr as xr;
|
||||||
use resources::*;
|
use resources::*;
|
||||||
|
use xr::FormFactor;
|
||||||
use xr_input::controllers::XrControllerType;
|
use xr_input::controllers::XrControllerType;
|
||||||
use xr_input::hands::emulated::EmulatedHandsPlugin;
|
use xr_input::hands::emulated::EmulatedHandsPlugin;
|
||||||
use xr_input::hands::hand_tracking::{HandTrackingPlugin, HandTrackingData};
|
use xr_input::hands::hand_tracking::{HandTrackingData, HandTrackingPlugin};
|
||||||
use xr_input::handtracking::HandTrackingTracker;
|
|
||||||
use xr_input::OpenXrInput;
|
use xr_input::OpenXrInput;
|
||||||
|
|
||||||
const VIEW_TYPE: xr::ViewConfigurationType = xr::ViewConfigurationType::PRIMARY_STEREO;
|
const VIEW_TYPE: xr::ViewConfigurationType = xr::ViewConfigurationType::PRIMARY_STEREO;
|
||||||
@@ -159,7 +159,14 @@ impl Plugin for OpenXrPlugin {
|
|||||||
.insert_resource(views.clone())
|
.insert_resource(views.clone())
|
||||||
.insert_resource(frame_state.clone())
|
.insert_resource(frame_state.clone())
|
||||||
.insert_resource(action_sets.clone());
|
.insert_resource(action_sets.clone());
|
||||||
let hands = xr_instance.exts().ext_hand_tracking.is_some();
|
let hands = xr_instance.exts().ext_hand_tracking.is_some()
|
||||||
|
&& xr_instance
|
||||||
|
.supports_hand_tracking(
|
||||||
|
xr_instance
|
||||||
|
.system(FormFactor::HEAD_MOUNTED_DISPLAY)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.is_ok_and(|v| v);
|
||||||
if hands {
|
if hands {
|
||||||
app.insert_resource(HandTrackingData::new(&session).unwrap());
|
app.insert_resource(HandTrackingData::new(&session).unwrap());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
info, Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3,
|
Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3, With,
|
||||||
With, Without,
|
Without,
|
||||||
};
|
};
|
||||||
|
use bevy::log::info;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
input::XrInput,
|
input::XrInput,
|
||||||
resources::{XrFrameState, XrInstance, XrSession},
|
resources::{XrFrameState, XrSession},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::xr_input::{
|
use crate::xr_input::{
|
||||||
@@ -15,9 +16,8 @@ use crate::xr_input::{
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
actions::XrActionSets,
|
actions::XrActionSets,
|
||||||
handtracking::{HandTrackingRef, HandTrackingTracker},
|
hands::hand_tracking::HandTrackingData,
|
||||||
trackers::{OpenXRLeftController, OpenXRRightController, OpenXRTrackingRoot},
|
trackers::{OpenXRLeftController, OpenXRRightController, OpenXRTrackingRoot},
|
||||||
QuatConv, hands::hand_tracking::HandTrackingData,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// add debug renderer for controllers
|
/// add debug renderer for controllers
|
||||||
@@ -35,7 +35,6 @@ pub fn draw_gizmos(
|
|||||||
oculus_controller: Res<OculusController>,
|
oculus_controller: Res<OculusController>,
|
||||||
frame_state: Res<XrFrameState>,
|
frame_state: Res<XrFrameState>,
|
||||||
xr_input: Res<XrInput>,
|
xr_input: Res<XrInput>,
|
||||||
instance: Res<XrInstance>,
|
|
||||||
session: Res<XrSession>,
|
session: Res<XrSession>,
|
||||||
tracking_root_query: Query<(
|
tracking_root_query: Query<(
|
||||||
&mut Transform,
|
&mut Transform,
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
|
use bevy::log::info;
|
||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
default, info, Color, Commands, Component, Deref, DerefMut, Entity, Gizmos, GlobalTransform,
|
default, Color, Commands, Component, Deref, DerefMut, Entity, Gizmos, GlobalTransform, Plugin,
|
||||||
Plugin, PostUpdate, PreUpdate, Quat, Query, Res, ResMut, Resource, SpatialBundle, Startup,
|
PostUpdate, Quat, Query, Res, ResMut, Resource, SpatialBundle, Startup, Transform,
|
||||||
Transform, Update, Vec3, With, Without,
|
Vec3, With, Without,
|
||||||
};
|
};
|
||||||
use openxr::{HandJoint, Posef};
|
use openxr::{HandJoint, Posef};
|
||||||
|
|
||||||
@@ -17,10 +18,9 @@ use super::{
|
|||||||
actions::XrActionSets,
|
actions::XrActionSets,
|
||||||
hand_poses::get_simulated_open_hand_transforms,
|
hand_poses::get_simulated_open_hand_transforms,
|
||||||
hands::{BoneTrackingStatus, HandBone},
|
hands::{BoneTrackingStatus, HandBone},
|
||||||
handtracking::HandTrackingTracker,
|
|
||||||
oculus_touch::OculusController,
|
oculus_touch::OculusController,
|
||||||
trackers::{OpenXRLeftController, OpenXRRightController, OpenXRTracker, OpenXRTrackingRoot},
|
trackers::{OpenXRLeftController, OpenXRRightController, OpenXRTracker, OpenXRTrackingRoot},
|
||||||
Hand, QuatConv,
|
Hand,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// add debug renderer for controllers
|
/// add debug renderer for controllers
|
||||||
@@ -967,97 +967,6 @@ fn log_hand(hand_pose: [Posef; 26]) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_hand_skeletons(
|
|
||||||
tracking_root_query: Query<(&Transform, With<OpenXRTrackingRoot>)>,
|
|
||||||
right_controller_query: Query<(&GlobalTransform, With<OpenXRRightController>)>,
|
|
||||||
left_controller_query: Query<(&GlobalTransform, With<OpenXRLeftController>)>,
|
|
||||||
hand_states_option: Option<ResMut<HandStatesResource>>,
|
|
||||||
mut commands: Commands,
|
|
||||||
mut hand_bone_query: Query<(
|
|
||||||
Entity,
|
|
||||||
&mut Transform,
|
|
||||||
&HandBone,
|
|
||||||
&Hand,
|
|
||||||
Option<&mut HandBoneRadius>,
|
|
||||||
Without<OpenXRTrackingRoot>,
|
|
||||||
)>,
|
|
||||||
input_source: Option<Res<HandInputSource>>,
|
|
||||||
hand_tracking: Option<Res<HandTrackingTracker>>,
|
|
||||||
xr_input: Res<XrInput>,
|
|
||||||
xr_frame_state: Res<XrFrameState>,
|
|
||||||
) {
|
|
||||||
match input_source {
|
|
||||||
Some(res) => match *res {
|
|
||||||
HandInputSource::Emulated => {
|
|
||||||
// info!("hand input source is emulated");
|
|
||||||
match hand_states_option {
|
|
||||||
Some(hands) => {
|
|
||||||
let left_hand_transform = left_controller_query
|
|
||||||
.get_single()
|
|
||||||
.unwrap()
|
|
||||||
.0
|
|
||||||
.compute_transform();
|
|
||||||
update_hand_bones_emulated(
|
|
||||||
left_hand_transform,
|
|
||||||
Hand::Left,
|
|
||||||
hands.left,
|
|
||||||
&mut hand_bone_query,
|
|
||||||
);
|
|
||||||
let right_hand_transform = right_controller_query
|
|
||||||
.get_single()
|
|
||||||
.unwrap()
|
|
||||||
.0
|
|
||||||
.compute_transform();
|
|
||||||
update_hand_bones_emulated(
|
|
||||||
right_hand_transform,
|
|
||||||
Hand::Right,
|
|
||||||
hands.right,
|
|
||||||
&mut hand_bone_query,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
None => info!("hand states resource not initialized yet"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HandInputSource::OpenXr => match hand_tracking {
|
|
||||||
Some(tracking) => {
|
|
||||||
let hand_ref = tracking.get_ref(&xr_input, &xr_frame_state);
|
|
||||||
let (root_transform, _) = tracking_root_query.get_single().unwrap();
|
|
||||||
let left_data = hand_ref.get_left_poses();
|
|
||||||
let right_data = hand_ref.get_right_poses();
|
|
||||||
|
|
||||||
for (entity, mut transform, bone, hand, radius, _) in hand_bone_query.iter_mut()
|
|
||||||
{
|
|
||||||
let bone_data = match (hand, left_data, right_data) {
|
|
||||||
(Hand::Left, Some(data), _) => data[bone.get_index_from_bone()],
|
|
||||||
(Hand::Right, _, Some(data)) => data[bone.get_index_from_bone()],
|
|
||||||
_ => continue,
|
|
||||||
};
|
|
||||||
match radius {
|
|
||||||
Some(mut r) => r.0 = bone_data.radius,
|
|
||||||
None => {
|
|
||||||
commands
|
|
||||||
.entity(entity)
|
|
||||||
.insert(HandBoneRadius(bone_data.radius));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*transform = transform
|
|
||||||
.with_translation(
|
|
||||||
root_transform.transform_point(bone_data.pose.position.to_vec3()),
|
|
||||||
)
|
|
||||||
.with_rotation(
|
|
||||||
root_transform.rotation * bone_data.pose.orientation.to_quat(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
info!("hand input source not initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Component, DerefMut, Deref)]
|
#[derive(Debug, Component, DerefMut, Deref)]
|
||||||
pub struct HandBoneRadius(pub f32);
|
pub struct HandBoneRadius(pub f32);
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
use std::mem::MaybeUninit;
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
|
||||||
use openxr::{HandJointLocationEXT, HandTracker, Result};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
input::XrInput,
|
|
||||||
resources::{XrFrameState, XrFrameWaiter, XrSession},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::hands::HandBone;
|
|
||||||
|
|
||||||
#[derive(Resource)]
|
|
||||||
pub struct HandTrackingTracker {
|
|
||||||
left_hand: HandTracker,
|
|
||||||
right_hand: HandTracker,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HandTrackingTracker {
|
|
||||||
pub fn new(session: &XrSession) -> Result<HandTrackingTracker> {
|
|
||||||
let left = session.create_hand_tracker(openxr::HandEXT::LEFT)?;
|
|
||||||
let right = session.create_hand_tracker(openxr::HandEXT::RIGHT)?;
|
|
||||||
Ok(HandTrackingTracker {
|
|
||||||
left_hand: left,
|
|
||||||
right_hand: right,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
pub fn get_ref<'a>(
|
|
||||||
&'a self,
|
|
||||||
input: &'a XrInput,
|
|
||||||
frame_state: &'a XrFrameState,
|
|
||||||
) -> HandTrackingRef<'a> {
|
|
||||||
HandTrackingRef {
|
|
||||||
tracking: self,
|
|
||||||
input,
|
|
||||||
frame_state,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct HandTrackingRef<'a> {
|
|
||||||
tracking: &'a HandTrackingTracker,
|
|
||||||
input: &'a XrInput,
|
|
||||||
frame_state: &'a XrFrameState,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl<'a> HandTrackingRef<'a> {
|
|
||||||
pub fn get_left_poses(&self) -> Option<[HandJointLocationEXT;26]> {
|
|
||||||
self.input
|
|
||||||
.stage
|
|
||||||
.locate_hand_joints(
|
|
||||||
&self.tracking.left_hand,
|
|
||||||
self.frame_state.lock().unwrap().predicted_display_time,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
pub fn get_right_poses(&self) -> Option<[HandJointLocationEXT; 26]> {
|
|
||||||
self.input
|
|
||||||
.stage
|
|
||||||
.locate_hand_joints(
|
|
||||||
&self.tracking.right_hand,
|
|
||||||
self.frame_state.lock().unwrap().predicted_display_time,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ pub mod debug_gizmos;
|
|||||||
pub mod hand;
|
pub mod hand;
|
||||||
pub mod hand_poses;
|
pub mod hand_poses;
|
||||||
pub mod hands;
|
pub mod hands;
|
||||||
pub mod handtracking;
|
|
||||||
pub mod interactions;
|
pub mod interactions;
|
||||||
pub mod oculus_touch;
|
pub mod oculus_touch;
|
||||||
pub mod prototype_locomotion;
|
pub mod prototype_locomotion;
|
||||||
|
|||||||
Reference in New Issue
Block a user