Add Vec2Conv helper and Display warning with message when openxr fails to load (#58)
* add support for Vec2 Actions, slightly changed the way actions are created but no functionality change and changed the get_action_* return result to a custom error * Whoops * added warning with error when openxr fails to load and added Vec2Conv helper * made it possible for the user to spawn OpenXRTrackingRoot
This commit is contained in:
11
src/lib.rs
11
src/lib.rs
@@ -82,7 +82,8 @@ impl Plugin for OpenXrPlugin {
|
||||
let mut system_state: SystemState<Query<&RawHandleWrapper, With<PrimaryWindow>>> =
|
||||
SystemState::new(&mut app.world);
|
||||
let primary_window = system_state.get(&app.world).get_single().ok().cloned();
|
||||
if let Ok((
|
||||
match graphics::initialize_xr_graphics(primary_window.clone()) {
|
||||
Ok((
|
||||
device,
|
||||
queue,
|
||||
adapter_info,
|
||||
@@ -99,8 +100,7 @@ impl Plugin for OpenXrPlugin {
|
||||
input,
|
||||
views,
|
||||
frame_state,
|
||||
)) = graphics::initialize_xr_graphics(primary_window.clone())
|
||||
{
|
||||
)) => {
|
||||
// std::thread::sleep(Duration::from_secs(5));
|
||||
debug!("Configured wgpu adapter Limits: {:#?}", device.limits());
|
||||
debug!("Configured wgpu adapter Features: {:#?}", device.features());
|
||||
@@ -140,11 +140,14 @@ impl Plugin for OpenXrPlugin {
|
||||
),
|
||||
});
|
||||
app.insert_resource(XrEnableStatus::Enabled);
|
||||
} else {
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("OpenXR Failed to initialize: {}", err);
|
||||
app.add_plugins(RenderPlugin::default());
|
||||
app.insert_resource(XrEnableStatus::Disabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ready(&self, app: &App) -> bool {
|
||||
app.world
|
||||
|
||||
@@ -16,7 +16,11 @@ use crate::xr_input::controllers::XrControllerType;
|
||||
use crate::xr_input::oculus_touch::setup_oculus_controller;
|
||||
use crate::xr_input::xr_camera::{xr_camera_head_sync, Eye, XRProjection, XrCameraBundle};
|
||||
use bevy::app::{App, PostUpdate, Startup};
|
||||
use bevy::ecs::entity::Entity;
|
||||
use bevy::ecs::query::With;
|
||||
use bevy::ecs::system::Query;
|
||||
use bevy::log::{info, warn};
|
||||
use bevy::math::Vec2;
|
||||
use bevy::prelude::{BuildChildren, Component, Deref, DerefMut, IntoSystemConfigs, Resource};
|
||||
use bevy::prelude::{Commands, Plugin, PreUpdate, Quat, Res, SpatialBundle, Update, Vec3};
|
||||
use bevy::render::camera::CameraProjectionPlugin;
|
||||
@@ -60,7 +64,7 @@ impl Plugin for OpenXrInput {
|
||||
}
|
||||
//adopt any new trackers
|
||||
app.add_systems(PreUpdate, adopt_open_xr_trackers.run_if(xr_only()));
|
||||
app.add_systems(PreUpdate, action_set_system);
|
||||
app.add_systems(PreUpdate, action_set_system.run_if(xr_only()));
|
||||
app.add_systems(
|
||||
PreUpdate,
|
||||
xr_camera_head_sync.run_if(xr_only()).after(xr_begin_frame),
|
||||
@@ -88,12 +92,19 @@ fn setup_binding_recommendations(
|
||||
commands.remove_resource::<InteractionProfileBindings>();
|
||||
}
|
||||
|
||||
fn setup_xr_cameras(mut commands: Commands) {
|
||||
fn setup_xr_cameras(
|
||||
mut commands: Commands,
|
||||
tracking_root_query: Query<Entity, With<OpenXRTrackingRoot>>,
|
||||
) {
|
||||
//this needs to do the whole xr tracking volume not just cameras
|
||||
//get the root?
|
||||
let tracking_root = commands
|
||||
|
||||
let tracking_root = match tracking_root_query.get_single() {
|
||||
Ok(e) => e,
|
||||
Err(_) => commands
|
||||
.spawn((SpatialBundle::default(), OpenXRTrackingRoot))
|
||||
.id();
|
||||
.id(),
|
||||
};
|
||||
let right = commands
|
||||
.spawn((XrCameraBundle::new(Eye::Right), OpenXRRightEye))
|
||||
.id();
|
||||
@@ -117,6 +128,15 @@ pub fn action_set_system(action_sets: Res<ActionSets>, session: Res<XrSession>)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Vec2Conv {
|
||||
fn to_vec2(&self) -> Vec2;
|
||||
}
|
||||
|
||||
impl Vec2Conv for openxr::Vector2f {
|
||||
fn to_vec2(&self) -> Vec2 {
|
||||
Vec2::new(self.x, self.y)
|
||||
}
|
||||
}
|
||||
pub trait Vec3Conv {
|
||||
fn to_vec3(&self) -> Vec3;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user