add XrTracker component that auto parents the entity to the XrTrackingRoot, XrSpace requires XrTracker
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use bevy::{
|
||||
ecs::{component::Component, entity::Entity, world::Command},
|
||||
log::{error, warn},
|
||||
log::warn,
|
||||
math::bool,
|
||||
prelude::{BuildChildren, Bundle, Commands, Deref, DerefMut, Resource, Transform, Visibility, With, World},
|
||||
prelude::{Bundle, Commands, Deref, DerefMut, Resource, Transform, Visibility, World},
|
||||
};
|
||||
|
||||
use crate::{session::XrTrackingRoot, spaces::XrSpaceLocationFlags};
|
||||
use crate::{session::XrTracker, spaces::XrSpaceLocationFlags};
|
||||
pub const HAND_JOINT_COUNT: usize = 26;
|
||||
|
||||
pub fn spawn_hand_bones<T: Bundle>(
|
||||
@@ -14,16 +14,7 @@ pub fn spawn_hand_bones<T: Bundle>(
|
||||
) -> [Entity; HAND_JOINT_COUNT] {
|
||||
let mut bones: [Entity; HAND_JOINT_COUNT] = [Entity::PLACEHOLDER; HAND_JOINT_COUNT];
|
||||
for bone in HandBone::get_all_bones().into_iter() {
|
||||
bones[bone as usize] = cmds
|
||||
.spawn((
|
||||
Transform::default(),
|
||||
Visibility::default(),
|
||||
bone,
|
||||
HandBoneRadius(0.0),
|
||||
XrSpaceLocationFlags::default(),
|
||||
))
|
||||
.insert((get_bundle)(bone))
|
||||
.id();
|
||||
bones[bone as usize] = cmds.spawn((bone, (get_bundle)(bone))).id();
|
||||
}
|
||||
bones
|
||||
}
|
||||
@@ -45,11 +36,18 @@ pub struct RightHand;
|
||||
pub struct XrHandBoneEntities(pub [Entity; HAND_JOINT_COUNT]);
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Component, Debug, DerefMut, Deref)]
|
||||
pub struct HandBoneRadius(pub f32);
|
||||
#[derive(Clone, Copy, Component, Debug, DerefMut, Deref, Default)]
|
||||
pub struct XrHandBoneRadius(pub f32);
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Component, Debug)]
|
||||
#[require(
|
||||
XrSpaceLocationFlags,
|
||||
XrHandBoneRadius,
|
||||
Transform,
|
||||
Visibility,
|
||||
XrTracker
|
||||
)]
|
||||
pub enum HandBone {
|
||||
Palm = 0,
|
||||
Wrist = 1,
|
||||
@@ -189,20 +187,12 @@ impl<B: Bundle> Command for SpawnHandTracker<B> {
|
||||
warn!("no SpawnHandTracker executor defined, skipping handtracker creation");
|
||||
return;
|
||||
};
|
||||
let Ok(root) = world
|
||||
.query_filtered::<Entity, With<XrTrackingRoot>>()
|
||||
.get_single(world)
|
||||
else {
|
||||
error!("unable to get tracking root, skipping handtracker creation");
|
||||
return;
|
||||
};
|
||||
let mut tracker = world.spawn(self.joints);
|
||||
match &self.side {
|
||||
HandSide::Left => tracker.insert(LeftHand),
|
||||
HandSide::Right => tracker.insert(LeftHand),
|
||||
HandSide::Left => tracker.insert((XrTracker, LeftHand)),
|
||||
HandSide::Right => tracker.insert((XrTracker, RightHand)),
|
||||
};
|
||||
let tracker = tracker.id();
|
||||
world.entity_mut(root).add_children(&[tracker]);
|
||||
executor.0(world, tracker, self.side);
|
||||
if let Ok(mut tracker) = world.get_entity_mut(tracker) {
|
||||
tracker.insert(self.side);
|
||||
|
||||
Reference in New Issue
Block a user