add support for hand tracking and configurable reference spaces

This commit is contained in:
Schmarni
2024-05-07 03:34:10 +02:00
parent 3654b36e76
commit 063aef7fb5
17 changed files with 549 additions and 32 deletions

View File

@@ -0,0 +1,34 @@
use bevy::{prelude::*, transform::TransformSystem};
use bevy_xr::hands::{HandBone, HandBoneRadius};
pub struct HandGizmosPlugin;
impl Plugin for HandGizmosPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
PostUpdate,
draw_hand_gizmos.after(TransformSystem::TransformPropagate),
);
}
}
fn draw_hand_gizmos(
mut gizmos: Gizmos,
query: Query<(&GlobalTransform, &HandBone, &HandBoneRadius)>,
) {
for (transform, bone, radius) in &query {
let pose = transform.compute_transform();
gizmos.sphere(pose.translation, pose.rotation, **radius, gizmo_color(bone));
}
}
fn gizmo_color(bone: &HandBone) -> Color {
match bone {
HandBone::Palm => Color::WHITE,
HandBone::Wrist => Color::GRAY,
b if b.is_thumb() => Color::RED,
b if b.is_index() => Color::ORANGE,
b if b.is_middle() => Color::YELLOW,
b if b.is_ring() => Color::GREEN,
b if b.is_little() => Color::BLUE,
// should be impossible to hit
_ => Color::rgb(1.0, 0.0, 1.0),
}
}

View File

@@ -0,0 +1,3 @@
// use bevy::prelude::*;
pub mod hand_gizmos;