Merge pull request #37 from ForTehLose/optionalHands
only add hand resource if we support the ext
This commit is contained in:
11
src/lib.rs
11
src/lib.rs
@@ -20,6 +20,7 @@ use input::XrInput;
|
|||||||
use openxr as xr;
|
use openxr as xr;
|
||||||
use resources::*;
|
use resources::*;
|
||||||
use xr_input::controllers::XrControllerType;
|
use xr_input::controllers::XrControllerType;
|
||||||
|
use xr_input::hand::HandInputSource;
|
||||||
use xr_input::handtracking::HandTrackingTracker;
|
use xr_input::handtracking::HandTrackingTracker;
|
||||||
use xr_input::OpenXrInput;
|
use xr_input::OpenXrInput;
|
||||||
|
|
||||||
@@ -144,8 +145,14 @@ impl Plugin for OpenXrPlugin {
|
|||||||
.insert_resource(input.clone())
|
.insert_resource(input.clone())
|
||||||
.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());
|
||||||
.insert_resource(HandTrackingTracker::new(&session).unwrap());
|
let hands = xr_instance.exts().ext_hand_tracking.is_some();
|
||||||
|
if hands {
|
||||||
|
app.insert_resource(HandTrackingTracker::new(&session).unwrap());
|
||||||
|
app.insert_resource(HandInputSource::OpenXr);
|
||||||
|
} else {
|
||||||
|
app.insert_resource(HandInputSource::Emulated);
|
||||||
|
}
|
||||||
|
|
||||||
let (left, right) = swapchain.get_render_views();
|
let (left, right) = swapchain.get_render_views();
|
||||||
let left = ManualTextureView {
|
let left = ManualTextureView {
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ impl Plugin for OpenXrHandInput {
|
|||||||
app.add_systems(Update, update_hand_skeletons)
|
app.add_systems(Update, update_hand_skeletons)
|
||||||
.add_systems(PreUpdate, update_hand_states)
|
.add_systems(PreUpdate, update_hand_states)
|
||||||
.add_systems(Startup, spawn_hand_entities)
|
.add_systems(Startup, spawn_hand_entities)
|
||||||
.insert_resource(HandStatesResource::default())
|
.insert_resource(HandStatesResource::default());
|
||||||
.insert_resource(HandInputSource::default());
|
// .insert_resource(HandInputSource::default());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1068,7 +1068,7 @@ pub fn update_hand_skeletons(
|
|||||||
Without<OpenXRTrackingRoot>,
|
Without<OpenXRTrackingRoot>,
|
||||||
)>,
|
)>,
|
||||||
input_source: Option<Res<HandInputSource>>,
|
input_source: Option<Res<HandInputSource>>,
|
||||||
hand_tracking: Res<HandTrackingTracker>,
|
hand_tracking: Option<Res<HandTrackingTracker>>,
|
||||||
xr_input: Res<XrInput>,
|
xr_input: Res<XrInput>,
|
||||||
xr_frame_state: Res<XrFrameState>,
|
xr_frame_state: Res<XrFrameState>,
|
||||||
) {
|
) {
|
||||||
@@ -1104,35 +1104,39 @@ pub fn update_hand_skeletons(
|
|||||||
None => info!("hand states resource not initialized yet"),
|
None => info!("hand states resource not initialized yet"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HandInputSource::OpenXr => {
|
HandInputSource::OpenXr => match hand_tracking {
|
||||||
let hand_ref = hand_tracking.get_ref(&xr_input, &xr_frame_state);
|
Some(tracking) => {
|
||||||
let (root_transform, _) = tracking_root_query.get_single().unwrap();
|
let hand_ref = tracking.get_ref(&xr_input, &xr_frame_state);
|
||||||
let left_data = hand_ref.get_left_poses();
|
let (root_transform, _) = tracking_root_query.get_single().unwrap();
|
||||||
let right_data = hand_ref.get_right_poses();
|
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() {
|
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()],
|
let bone_data = match (hand, left_data, right_data) {
|
||||||
(Hand::Right, _, Some(data)) => data[bone.get_index_from_bone()],
|
(Hand::Left, Some(data), _) => data[bone.get_index_from_bone()],
|
||||||
_ => continue,
|
(Hand::Right, _, Some(data)) => data[bone.get_index_from_bone()],
|
||||||
};
|
_ => continue,
|
||||||
match radius {
|
};
|
||||||
Some(mut r) => r.0 = bone_data.radius,
|
match radius {
|
||||||
None => {
|
Some(mut r) => r.0 = bone_data.radius,
|
||||||
commands
|
None => {
|
||||||
.entity(entity)
|
commands
|
||||||
.insert(HandBoneRadius(bone_data.radius));
|
.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(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
*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 => {
|
None => {
|
||||||
info!("hand input source not initialized");
|
info!("hand input source not initialized");
|
||||||
|
|||||||
Reference in New Issue
Block a user