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:
Schmarni
2024-11-20 11:46:24 +01:00
parent d1cc160cac
commit a04ebb8426
10 changed files with 128 additions and 203 deletions

View File

@@ -1,15 +1,18 @@
use bevy::{
ecs::component::StorageType,
prelude::*,
render::{extract_component::ExtractComponent, extract_resource::ExtractResource},
};
use crate::session::XrTracker;
/// Any Spaces will be invalid after the owning session exits
#[repr(transparent)]
#[derive(Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, ExtractComponent)]
#[derive(Component, Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, ExtractComponent)]
#[require(XrSpaceLocationFlags, Transform, Visibility, XrTracker)]
pub struct XrSpace(u64);
#[derive(Clone, Copy, Reflect, Debug, ExtractComponent, Default)]
#[derive(Component, Clone, Copy, Reflect, Debug, ExtractComponent, Default)]
#[require(XrSpaceVelocityFlags)]
pub struct XrVelocity {
/// Velocity of a space relative to it's reference space
pub linear: Vec3,
@@ -69,28 +72,3 @@ impl XrSpace {
self.0
}
}
impl Component for XrSpace {
const STORAGE_TYPE: StorageType = StorageType::Table;
fn register_component_hooks(hooks: &mut bevy::ecs::component::ComponentHooks) {
hooks.on_add(|mut world, entity, _| {
world
.commands()
.entity(entity)
.insert(XrSpaceLocationFlags::default());
});
}
}
impl Component for XrVelocity {
const STORAGE_TYPE: StorageType = StorageType::Table;
fn register_component_hooks(hooks: &mut bevy::ecs::component::ComponentHooks) {
hooks.on_add(|mut world, entity, _| {
world
.commands()
.entity(entity)
.insert(XrSpaceVelocityFlags::default());
});
}
}