diff --git a/Cargo.toml b/Cargo.toml index e7323da..ad43a11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,17 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[target.'cfg(windows)'.features] +default = ["linked"] + +[features] +linked = ["openxr/linked", "openxr/static"] + [dependencies] anyhow = "1.0.75" ash = "0.37.3" bevy = { git = "https://github.com/awtterpip/bevy", default-features = false, features = ["bevy_render"] } -openxr = { version = "0.17.1", features = ["mint", "static", "linked"] } +openxr = { version = "0.17.1", features = ["mint"] } mint = "0.5.9" wgpu = "0.16.0" wgpu-core = { version = "0.16.0", features = ["vulkan"] } diff --git a/examples/xr.rs b/examples/xr.rs index 4bd9c58..fc10cd2 100644 --- a/examples/xr.rs +++ b/examples/xr.rs @@ -3,9 +3,8 @@ use bevy::prelude::*; use bevy::transform::components::Transform; use bevy_openxr::input::XrInput; use bevy_openxr::resources::XrFrameState; -use bevy_openxr::xr_input::controllers::XrControllerType; use bevy_openxr::xr_input::oculus_touch::OculusController; -use bevy_openxr::xr_input::{OpenXrInput, QuatConv, Vec3Conv}; +use bevy_openxr::xr_input::{QuatConv, Vec3Conv}; use bevy_openxr::DefaultXrPlugins; fn main() { @@ -14,7 +13,6 @@ fn main() { info!("Running `openxr-6dof` skill"); App::new() .add_plugins(DefaultXrPlugins) - .add_plugins(OpenXrInput::new(XrControllerType::OculusTouch)) .add_plugins(LogDiagnosticsPlugin::default()) .add_plugins(FrameTimeDiagnosticsPlugin) .add_systems(Startup, setup) diff --git a/src/graphics/mod.rs b/src/graphics/mod.rs index 23c5b3e..00cedf4 100644 --- a/src/graphics/mod.rs +++ b/src/graphics/mod.rs @@ -10,6 +10,8 @@ use crate::resources::{ XrSwapchain, XrViews, XrResolution, XrFormat, }; +use openxr as xr; + pub fn initialize_xr_graphics( window: Option, ) -> anyhow::Result<( @@ -32,3 +34,11 @@ pub fn initialize_xr_graphics( )> { vulkan::initialize_xr_graphics(window) } + +pub fn xr_entry() -> xr::Entry { + #[cfg(feature = "linked")] + let entry = xr::Entry::linked(); + #[cfg(not(feature = "linked"))] + let entry = unsafe { xr::Entry::load().unwrap() }; + entry +} \ No newline at end of file diff --git a/src/graphics/vulkan.rs b/src/graphics/vulkan.rs index 794e9dc..e8f4707 100644 --- a/src/graphics/vulkan.rs +++ b/src/graphics/vulkan.rs @@ -9,7 +9,7 @@ use bevy::prelude::*; use bevy::render::renderer::{RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue}; use bevy::window::RawHandleWrapper; use openxr as xr; -use wgpu::{Instance, Texture}; +use wgpu::Instance; use crate::input::XrInput; use crate::resources::{ @@ -40,7 +40,7 @@ pub fn initialize_xr_graphics( )> { use wgpu_hal::{api::Vulkan as V, Api}; - let xr_entry = xr::Entry::linked(); + let xr_entry = super::xr_entry(); let available_extensions = xr_entry.enumerate_extensions()?; assert!(available_extensions.khr_vulkan_enable2); diff --git a/src/input.rs b/src/input.rs index e6e7750..411cfbc 100644 --- a/src/input.rs +++ b/src/input.rs @@ -3,8 +3,6 @@ use std::sync::Arc; use bevy::prelude::*; use openxr as xr; -type XrPose = (Vec3, Quat); - #[derive(Clone, Resource)] pub struct XrInput { //pub action_set: xr::ActionSet, @@ -16,7 +14,7 @@ pub struct XrInput { } impl XrInput { - pub fn new(instance: xr::Instance, session: xr::Session) -> xr::Result { + pub fn new(_instance: xr::Instance, session: xr::Session) -> xr::Result { // let action_set = instance.create_action_set("input", "input pose information", 0)?; // let left_hand_subaction_path = instance.string_to_path("/user/hand/left").unwrap(); // let right_hand_subaction_path = instance.string_to_path("/user/hand/right").unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 06174f3..5b4f9e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,17 +11,16 @@ use bevy::app::PluginGroupBuilder; use bevy::ecs::system::SystemState; use bevy::prelude::*; use bevy::render::camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews}; -use bevy::render::pipelined_rendering::{RenderExtractApp, PipelinedRenderingPlugin}; -use bevy::render::renderer::{ - render_system, RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue, -}; +use bevy::render::pipelined_rendering::PipelinedRenderingPlugin; +use bevy::render::renderer::render_system; use bevy::render::settings::RenderSettings; use bevy::render::{Render, RenderApp, RenderPlugin, RenderSet}; use bevy::window::{PresentMode, PrimaryWindow, RawHandleWrapper}; use input::XrInput; use openxr as xr; use resources::*; -use wgpu::Instance; +use xr_input::controllers::XrControllerType; +use xr_input::OpenXrInput; const VIEW_TYPE: xr::ViewConfigurationType = xr::ViewConfigurationType::PRIMARY_STEREO; @@ -97,7 +96,7 @@ impl Plugin for OpenXrPlugin { frame_state, )); app.insert_resource(ActionSets(vec![])); - app.add_plugins(DefaultPlugins.set(RenderPlugin { + app.add_plugins(RenderPlugin { render_settings: RenderSettings::Manual( device, queue, @@ -105,14 +104,7 @@ impl Plugin for OpenXrPlugin { render_adapter, Mutex::new(instance), ), - }).disable::() - .set(WindowPlugin { - primary_window: Some(Window { - present_mode: PresentMode::AutoNoVsync, - ..default() - }), - ..default() - })); + }); } fn ready(&self, app: &App) -> bool { @@ -202,9 +194,19 @@ pub struct DefaultXrPlugins; impl PluginGroup for DefaultXrPlugins { fn build(self) -> PluginGroupBuilder { - let mut group = PluginGroupBuilder::start::(); - group = group.add(OpenXrPlugin); - group + DefaultPlugins + .build() + .disable::() + .disable::() + .add_before::(OpenXrPlugin) + .add_after::(OpenXrInput::new(XrControllerType::OculusTouch)) + .set(WindowPlugin { + primary_window: Some(Window { + present_mode: PresentMode::AutoNoVsync, + ..default() + }), + ..default() + }) } } @@ -334,18 +336,16 @@ pub fn locate_views( xr_frame_state: Res, ) { let _span = info_span!("xr_locate_views").entered(); - *views.lock().unwrap() = match session - .locate_views( - VIEW_TYPE, - xr_frame_state.lock().unwrap().predicted_display_time, - &input.stage, - ) - { + *views.lock().unwrap() = match session.locate_views( + VIEW_TYPE, + xr_frame_state.lock().unwrap().predicted_display_time, + &input.stage, + ) { Ok(this) => this, Err(err) => { warn!("error: {}", err); return; } } - .1; + .1; } diff --git a/src/xr_input/mod.rs b/src/xr_input/mod.rs index 314336b..e6fe3c5 100644 --- a/src/xr_input/mod.rs +++ b/src/xr_input/mod.rs @@ -7,18 +7,17 @@ use crate::xr_begin_frame; use crate::xr_input::controllers::XrControllerType; use crate::xr_input::oculus_touch::{setup_oculus_controller, ActionSets}; use crate::xr_input::xr_camera::{ - xr_camera_head_sync, Eye, XRProjection, XrCameraBundle, XrCamerasBundle, + xr_camera_head_sync, Eye, XRProjection, XrCameraBundle, }; use bevy::app::{App, PostUpdate, Startup}; -use bevy::log::{info, warn}; +use bevy::log::warn; use bevy::prelude::IntoSystemConfigs; use bevy::prelude::{ - Commands, Component, IntoSystemSetConfigs, Plugin, PreUpdate, Quat, Res, Resource, Vec3, + Commands, Plugin, PreUpdate, Quat, Res, Vec3, }; use bevy::render::camera::CameraProjectionPlugin; use bevy::render::view::{update_frusta, VisibilitySystems}; use bevy::transform::TransformSystem; -use openxr::{Action, ActionSet, ActionTy}; #[derive(Copy, Clone)] pub struct OpenXrInput { diff --git a/src/xr_input/oculus_touch.rs b/src/xr_input/oculus_touch.rs index 8c01817..cb30282 100644 --- a/src/xr_input/oculus_touch.rs +++ b/src/xr_input/oculus_touch.rs @@ -1,9 +1,7 @@ use crate::resources::{XrInstance, XrSession}; use crate::xr_input::controllers::{Handed, Touchable}; -use crate::FutureXrResources; use bevy::prelude::{Commands, Res, Resource}; use openxr::{Action, ActionSet, AnyGraphics, Binding, Haptic, Instance, Posef, Session, Space}; -use std::any::Any; pub fn setup_oculus_controller( mut commands: Commands,