cleaned up code and made DefaultXrPlugins
This commit is contained in:
@@ -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"] }
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -10,6 +10,8 @@ use crate::resources::{
|
||||
XrSwapchain, XrViews, XrResolution, XrFormat,
|
||||
};
|
||||
|
||||
use openxr as xr;
|
||||
|
||||
pub fn initialize_xr_graphics(
|
||||
window: Option<RawHandleWrapper>,
|
||||
) -> 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
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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::AnyGraphics>) -> xr::Result<Self> {
|
||||
pub fn new(_instance: xr::Instance, session: xr::Session<xr::AnyGraphics>) -> xr::Result<Self> {
|
||||
// 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();
|
||||
|
||||
42
src/lib.rs
42
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::<PipelinedRenderingPlugin>()
|
||||
.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::<Self>();
|
||||
group = group.add(OpenXrPlugin);
|
||||
group
|
||||
DefaultPlugins
|
||||
.build()
|
||||
.disable::<RenderPlugin>()
|
||||
.disable::<PipelinedRenderingPlugin>()
|
||||
.add_before::<RenderPlugin, _>(OpenXrPlugin)
|
||||
.add_after::<OpenXrPlugin, _>(OpenXrInput::new(XrControllerType::OculusTouch))
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,13 +336,11 @@ pub fn locate_views(
|
||||
xr_frame_state: Res<XrFrameState>,
|
||||
) {
|
||||
let _span = info_span!("xr_locate_views").entered();
|
||||
*views.lock().unwrap() = match session
|
||||
.locate_views(
|
||||
*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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user