bevy_mod_xr 0.6.0

semi generic Xr Api for Community Driven XR in Bevy
Documentation
use crate::hands::{HandBone, XrHandBoneRadius};
use crate::spaces::XrSpaceLocationFlags;
use bevy_app::{App, Plugin, PostUpdate};
use bevy_color::palettes::css;
use bevy_color::Srgba;
use bevy_ecs::schedule::IntoScheduleConfigs as _;
use bevy_ecs::system::Query;
use bevy_gizmos::gizmos::Gizmos;
use bevy_math::Isometry3d;
use bevy_transform::TransformSystems;
use bevy_transform::components::GlobalTransform;

pub struct HandGizmosPlugin;
impl Plugin for HandGizmosPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(
            PostUpdate,
            draw_hand_gizmos.after(TransformSystems::Propagate),
        );
    }
}
fn draw_hand_gizmos(
    mut gizmos: Gizmos,
    query: Query<(
        &GlobalTransform,
        &HandBone,
        &XrHandBoneRadius,
        &XrSpaceLocationFlags,
    )>,
) {
    for (transform, bone, radius, flags) in &query {
        if (!flags.position_tracked) || (!flags.rotation_tracked) {
            continue;
        }
        let pose = transform.compute_transform();
        let pose = Isometry3d {
            translation: pose.translation.into(),
            rotation: pose.rotation,
        };
        gizmos.sphere(pose, **radius, gizmo_color(bone));
        gizmos.axes(pose, **radius);
    }
}

fn gizmo_color(bone: &HandBone) -> Srgba {
    match bone {
        HandBone::Palm => css::WHITE,
        HandBone::Wrist => css::GRAY,
        b if b.is_thumb() => css::RED,
        b if b.is_index() => css::ORANGE,
        b if b.is_middle() => css::YELLOW,
        b if b.is_ring() => Srgba::rgb(0.0, 1.0, 0.0),
        b if b.is_little() => css::BLUE,
        // should be impossible to hit
        _ => Srgba::rgb(1.0, 0.0, 1.0),
    }
}