add new XrSpace and impl that

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-06-15 15:37:01 +02:00
parent aa2a335074
commit 6003cc7ac6
15 changed files with 860 additions and 52 deletions

View File

@@ -7,7 +7,10 @@ use bevy::{
RenderApp,
},
};
use bevy_xr::session::{XrSessionCreated, XrSessionExiting};
use bevy_xr::{
session::{XrSessionCreated, XrSessionExiting},
spaces::{XrPrimaryReferenceSpace, XrReferenceSpace},
};
use crate::session::OxrSession;
@@ -25,19 +28,19 @@ impl Default for OxrReferenceSpacePlugin {
#[derive(Resource)]
struct OxrDefaultPrimaryReferenceSpaceType(openxr::ReferenceSpaceType);
/// The Default Reference space used for locating things
#[derive(Resource, Deref, ExtractResource, Clone)]
pub struct OxrPrimaryReferenceSpace(pub Arc<openxr::Space>);
// #[derive(Resource, Deref, ExtrctResource, Clone)]
// pub struct OxrPrimaryReferenceSpace(pub Arc<openxr::Space>);
/// The Reference space used for locating spaces on this entity
#[derive(Component)]
pub struct OxrReferenceSpace(pub openxr::Space);
// #[derive(Component)]
// pub struct OxrReferenceSpace(pub openxr::Space);
impl Plugin for OxrReferenceSpacePlugin {
fn build(&self, app: &mut App) {
app.insert_resource(OxrDefaultPrimaryReferenceSpaceType(
self.default_primary_ref_space,
));
app.add_plugins(ExtractResourcePlugin::<OxrPrimaryReferenceSpace>::default());
app.add_plugins(ExtractResourcePlugin::<XrPrimaryReferenceSpace>::default());
app.add_systems(XrSessionCreated, set_primary_ref_space);
app.add_systems(XrSessionExiting, cleanup);
app.sub_app_mut(RenderApp)
@@ -45,10 +48,10 @@ impl Plugin for OxrReferenceSpacePlugin {
}
}
fn cleanup(mut cmds: Commands, query: Query<Entity, With<OxrReferenceSpace>>) {
cmds.remove_resource::<OxrPrimaryReferenceSpace>();
fn cleanup(mut cmds: Commands, query: Query<Entity, With<XrReferenceSpace>>) {
cmds.remove_resource::<XrPrimaryReferenceSpace>();
for e in &query {
cmds.entity(e).remove::<OxrReferenceSpace>();
cmds.entity(e).remove::<XrReferenceSpace>();
}
}
@@ -57,9 +60,9 @@ fn set_primary_ref_space(
space_type: Res<OxrDefaultPrimaryReferenceSpaceType>,
mut cmds: Commands,
) {
match session.create_reference_space(space_type.0, openxr::Posef::IDENTITY) {
match session.create_reference_space(space_type.0, Transform::IDENTITY) {
Ok(space) => {
cmds.insert_resource(OxrPrimaryReferenceSpace(Arc::new(space)));
cmds.insert_resource(XrPrimaryReferenceSpace(space));
}
Err(openxr::sys::Result::ERROR_EXTENSION_NOT_PRESENT) => {
error!("Required Extension for Reference Space not loaded");