add space flags to bevy_mod_xr
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -3,7 +3,10 @@ use std::{mem::MaybeUninit, ptr, sync::Mutex};
|
|||||||
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
||||||
use bevy_mod_xr::{
|
use bevy_mod_xr::{
|
||||||
session::{XrFirst, XrHandleEvents},
|
session::{XrFirst, XrHandleEvents},
|
||||||
spaces::{XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrVelocity},
|
spaces::{
|
||||||
|
XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrSpaceLocationFlags,
|
||||||
|
XrSpaceVelocityFlags, XrVelocity,
|
||||||
|
},
|
||||||
types::XrPose,
|
types::XrPose,
|
||||||
};
|
};
|
||||||
use openxr::{
|
use openxr::{
|
||||||
@@ -155,7 +158,9 @@ fn update_space_transforms(
|
|||||||
Option<&mut XrVelocity>,
|
Option<&mut XrVelocity>,
|
||||||
Option<&XrReferenceSpace>,
|
Option<&XrReferenceSpace>,
|
||||||
&mut OxrSpaceLocationFlags,
|
&mut OxrSpaceLocationFlags,
|
||||||
|
&mut XrSpaceLocationFlags,
|
||||||
Option<&mut OxrSpaceVelocityFlags>,
|
Option<&mut OxrSpaceVelocityFlags>,
|
||||||
|
Option<&mut XrSpaceVelocityFlags>,
|
||||||
)>,
|
)>,
|
||||||
) {
|
) {
|
||||||
for (
|
for (
|
||||||
@@ -163,8 +168,10 @@ fn update_space_transforms(
|
|||||||
space,
|
space,
|
||||||
velocity,
|
velocity,
|
||||||
ref_space,
|
ref_space,
|
||||||
mut space_location_flags,
|
mut oxr_space_location_flags,
|
||||||
space_velocity_flags,
|
mut xr_space_location_flags,
|
||||||
|
oxr_space_velocity_flags,
|
||||||
|
xr_space_velocity_flags,
|
||||||
) in &mut query
|
) in &mut query
|
||||||
{
|
{
|
||||||
let ref_space = ref_space.unwrap_or(&default_ref_space);
|
let ref_space = ref_space.unwrap_or(&default_ref_space);
|
||||||
@@ -186,11 +193,17 @@ fn update_space_transforms(
|
|||||||
if flags.linear_valid() {
|
if flags.linear_valid() {
|
||||||
velocity.linear = space_velocity.linear_velocity.to_vec3();
|
velocity.linear = space_velocity.linear_velocity.to_vec3();
|
||||||
}
|
}
|
||||||
let Some(mut vel_flags) = space_velocity_flags else {
|
let Some(mut vel_flags) = oxr_space_velocity_flags else {
|
||||||
error!("XrVelocity without OxrSpaceVelocityFlags");
|
error!("XrVelocity without OxrSpaceVelocityFlags");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
let Some(mut xr_vel_flags) = xr_space_velocity_flags else {
|
||||||
|
error!("XrVelocity without XrSpaceVelocityFlags");
|
||||||
|
return;
|
||||||
|
};
|
||||||
*vel_flags = flags;
|
*vel_flags = flags;
|
||||||
|
xr_vel_flags.linear_valid = vel_flags.linear_valid();
|
||||||
|
xr_vel_flags.angular_valid = vel_flags.angular_valid();
|
||||||
Ok(location)
|
Ok(location)
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
@@ -206,7 +219,9 @@ fn update_space_transforms(
|
|||||||
if flags.rot_valid() {
|
if flags.rot_valid() {
|
||||||
transform.rotation = space_location.pose.orientation.to_quat();
|
transform.rotation = space_location.pose.orientation.to_quat();
|
||||||
}
|
}
|
||||||
*space_location_flags = flags;
|
*oxr_space_location_flags = flags;
|
||||||
|
xr_space_location_flags.position_tracked = flags.pos_valid() && flags.pos_tracked();
|
||||||
|
xr_space_location_flags.rotation_tracked = flags.rot_valid() && flags.rot_tracked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
use bevy::{
|
use bevy::{
|
||||||
|
ecs::component::StorageType,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::{extract_component::ExtractComponent, extract_resource::ExtractResource},
|
render::{extract_component::ExtractComponent, extract_resource::ExtractResource},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Any Spaces will be invalid after the owning session exits
|
/// Any Spaces will be invalid after the owning session exits
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, Component, ExtractComponent)]
|
#[derive(Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, ExtractComponent)]
|
||||||
pub struct XrSpace(u64);
|
pub struct XrSpace(u64);
|
||||||
|
|
||||||
#[derive(Clone, Copy, Reflect, Debug, Component, ExtractComponent, Default)]
|
#[derive(Clone, Copy, Reflect, Debug, ExtractComponent, Default)]
|
||||||
pub struct XrVelocity {
|
pub struct XrVelocity {
|
||||||
/// Velocity of a space relative to it's reference space
|
/// Velocity of a space relative to it's reference space
|
||||||
pub linear: Vec3,
|
pub linear: Vec3,
|
||||||
@@ -42,6 +43,22 @@ pub struct XrReferenceSpace(pub XrSpace);
|
|||||||
)]
|
)]
|
||||||
pub struct XrPrimaryReferenceSpace(pub XrReferenceSpace);
|
pub struct XrPrimaryReferenceSpace(pub XrReferenceSpace);
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, Component, ExtractComponent, Default,
|
||||||
|
)]
|
||||||
|
pub struct XrSpaceLocationFlags {
|
||||||
|
pub position_tracked: bool,
|
||||||
|
pub rotation_tracked: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(
|
||||||
|
Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, Component, ExtractComponent, Default,
|
||||||
|
)]
|
||||||
|
pub struct XrSpaceVelocityFlags {
|
||||||
|
pub linear_valid: bool,
|
||||||
|
pub angular_valid: bool,
|
||||||
|
}
|
||||||
|
|
||||||
impl XrSpace {
|
impl XrSpace {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// only call with known valid handles
|
/// only call with known valid handles
|
||||||
@@ -52,3 +69,28 @@ impl XrSpace {
|
|||||||
self.0
|
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());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user