Refactor hands (#110)

* cargo fmt and removed the unessecary examples.

* added left and right hand components for each bone as well as the hand tracker.
This commit is contained in:
Malek
2024-05-29 16:55:40 -07:00
committed by GitHub
parent ec16d9a254
commit 35725eaa8b
2 changed files with 21 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
use bevy::prelude::*;
use bevy_xr::hands::{LeftHand, RightHand};
use bevy_xr::{
hands::{HandBone, HandBoneRadius},
session::{session_running, status_changed_to, XrStatus},
@@ -74,10 +75,20 @@ fn spawn_default_hands(
let mut right_bones = [Entity::PLACEHOLDER; 26];
for bone in HandBone::get_all_bones() {
let bone_left = cmds
.spawn((SpatialBundle::default(), bone, HandBoneRadius(0.0)))
.spawn((
SpatialBundle::default(),
bone,
HandBoneRadius(0.0),
LeftHand,
))
.id();
let bone_right = cmds
.spawn((SpatialBundle::default(), bone, HandBoneRadius(0.0)))
.spawn((
SpatialBundle::default(),
bone,
HandBoneRadius(0.0),
RightHand,
))
.id();
cmds.entity(root).push_children(&[bone_left]);
cmds.entity(root).push_children(&[bone_right]);
@@ -88,11 +99,13 @@ fn spawn_default_hands(
DefaultHandTracker,
OxrHandTracker(tracker_left),
OxrHandBoneEntities(left_bones),
LeftHand,
));
cmds.spawn((
DefaultHandTracker,
OxrHandTracker(tracker_right),
OxrHandBoneEntities(right_bones),
RightHand,
));
}

View File

@@ -4,6 +4,12 @@ use bevy::{
prelude::{Deref, DerefMut},
};
#[derive(Clone, Copy, Component, Debug)]
pub struct LeftHand;
#[derive(Clone, Copy, Component, Debug)]
pub struct RightHand;
#[repr(transparent)]
#[derive(Clone, Copy, Component, Debug, DerefMut, Deref)]
pub struct HandBoneRadius(pub f32);