Skip to content

Commit

Permalink
added warning with error when openxr fails to load and added Vec2Conv…
Browse files Browse the repository at this point in the history
… helper
  • Loading branch information
Schmarni-Dev committed Dec 13, 2023
1 parent 5a4e171 commit 90fe934
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 60 deletions.
123 changes: 63 additions & 60 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,67 +82,70 @@ 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((
device,
queue,
adapter_info,
render_adapter,
instance,
xr_instance,
session,
blend_mode,
resolution,
format,
session_running,
frame_waiter,
swapchain,
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());
app.insert_resource(xr_instance.clone());
app.insert_resource(session.clone());
app.insert_resource(blend_mode.clone());
app.insert_resource(resolution.clone());
app.insert_resource(format.clone());
app.insert_resource(session_running.clone());
app.insert_resource(frame_waiter.clone());
app.insert_resource(swapchain.clone());
app.insert_resource(input.clone());
app.insert_resource(views.clone());
app.insert_resource(frame_state.clone());
let xr_data = XrRenderData {
match graphics::initialize_xr_graphics(primary_window.clone()) {
Ok((
device,
queue,
adapter_info,
render_adapter,
instance,
xr_instance,
xr_session: session,
xr_blend_mode: blend_mode,
xr_resolution: resolution,
xr_format: format,
xr_session_running: session_running,
xr_frame_waiter: frame_waiter,
xr_swapchain: swapchain,
xr_input: input,
xr_views: views,
xr_frame_state: frame_state,
};
app.insert_resource(xr_data);
app.insert_resource(ActionSets(vec![]));
app.add_plugins(RenderPlugin {
render_creation: RenderCreation::Manual(
device,
queue,
adapter_info,
render_adapter,
RenderInstance(Arc::new(instance)),
),
});
app.insert_resource(XrEnableStatus::Enabled);
} else {
app.add_plugins(RenderPlugin::default());
app.insert_resource(XrEnableStatus::Disabled);
session,
blend_mode,
resolution,
format,
session_running,
frame_waiter,
swapchain,
input,
views,
frame_state,
)) => {
// std::thread::sleep(Duration::from_secs(5));
debug!("Configured wgpu adapter Limits: {:#?}", device.limits());
debug!("Configured wgpu adapter Features: {:#?}", device.features());
app.insert_resource(xr_instance.clone());
app.insert_resource(session.clone());
app.insert_resource(blend_mode.clone());
app.insert_resource(resolution.clone());
app.insert_resource(format.clone());
app.insert_resource(session_running.clone());
app.insert_resource(frame_waiter.clone());
app.insert_resource(swapchain.clone());
app.insert_resource(input.clone());
app.insert_resource(views.clone());
app.insert_resource(frame_state.clone());
let xr_data = XrRenderData {
xr_instance,
xr_session: session,
xr_blend_mode: blend_mode,
xr_resolution: resolution,
xr_format: format,
xr_session_running: session_running,
xr_frame_waiter: frame_waiter,
xr_swapchain: swapchain,
xr_input: input,
xr_views: views,
xr_frame_state: frame_state,
};
app.insert_resource(xr_data);
app.insert_resource(ActionSets(vec![]));
app.add_plugins(RenderPlugin {
render_creation: RenderCreation::Manual(
device,
queue,
adapter_info,
render_adapter,
RenderInstance(Arc::new(instance)),
),
});
app.insert_resource(XrEnableStatus::Enabled);
}
Err(err) => {
warn!("OpenXR Failed to initialize: {}", err);
app.add_plugins(RenderPlugin::default());
app.insert_resource(XrEnableStatus::Disabled);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/xr_input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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::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;
Expand Down Expand Up @@ -117,6 +118,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;
}
Expand Down

0 comments on commit 90fe934

Please sign in to comment.