feat: update to bevy 0.17 and use individual bevy crates
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
use std::borrow::Cow;
|
||||
use std::ptr;
|
||||
|
||||
use bevy::ecs::schedule::ScheduleLabel;
|
||||
use bevy::ecs::system::RunSystemOnce;
|
||||
use bevy::platform::collections::HashMap;
|
||||
use bevy::prelude::*;
|
||||
use bevy_mod_xr::session::XrSessionCreatedEvent;
|
||||
use bevy_app::{App, Plugin, Update};
|
||||
use bevy_ecs::message::{Message, MessageReader};
|
||||
use bevy_ecs::schedule::common_conditions::on_message;
|
||||
use bevy_ecs::schedule::{IntoScheduleConfigs as _, Schedule, ScheduleLabel};
|
||||
use bevy_ecs::system::{Res, RunSystemOnce};
|
||||
use bevy_ecs::world::World;
|
||||
use bevy_log::error;
|
||||
use bevy_mod_xr::session::XrSessionCreatedMessage;
|
||||
use bevy_platform::collections::HashMap;
|
||||
use openxr::sys::ActionSuggestedBinding;
|
||||
|
||||
use crate::resources::OxrInstance;
|
||||
@@ -13,10 +17,10 @@ use crate::resources::OxrInstance;
|
||||
impl Plugin for OxrActionBindingPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_schedule(Schedule::new(OxrSendActionBindings));
|
||||
app.add_event::<OxrSuggestActionBinding>();
|
||||
app.add_message::<OxrSuggestActionBinding>();
|
||||
app.add_systems(
|
||||
Update,
|
||||
run_action_binding_sugestion.run_if(on_event::<XrSessionCreatedEvent>),
|
||||
run_action_binding_sugestion.run_if(on_message::<XrSessionCreatedMessage>),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +32,7 @@ pub(crate) fn run_action_binding_sugestion(world: &mut World) {
|
||||
_ = world.run_system_once(bind_actions);
|
||||
}
|
||||
|
||||
fn bind_actions(instance: Res<OxrInstance>, mut actions: EventReader<OxrSuggestActionBinding>) {
|
||||
fn bind_actions(instance: Res<OxrInstance>, mut actions: MessageReader<OxrSuggestActionBinding>) {
|
||||
let mut bindings: HashMap<&str, Vec<ActionSuggestedBinding>> = HashMap::new();
|
||||
for e in actions.read() {
|
||||
bindings.entry(&e.interaction_profile).or_default().extend(
|
||||
@@ -88,7 +92,7 @@ fn bind_actions(instance: Res<OxrInstance>, mut actions: EventReader<OxrSuggestA
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Event, Clone)]
|
||||
#[derive(Message, Clone)]
|
||||
/// Only Send this for Actions that were not attached yet!
|
||||
pub struct OxrSuggestActionBinding {
|
||||
pub action: openxr::sys::Action,
|
||||
@@ -97,6 +101,5 @@ pub struct OxrSuggestActionBinding {
|
||||
}
|
||||
|
||||
pub struct OxrActionBindingPlugin;
|
||||
// Maybe use a SystemSet in an XrStartup Schedule?
|
||||
#[derive(ScheduleLabel, Hash, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct OxrSendActionBindings;
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
use crate::{action_binding::run_action_binding_sugestion, session::OxrSession};
|
||||
use bevy::prelude::*;
|
||||
use bevy_mod_xr::session::XrSessionCreatedEvent;
|
||||
use bevy_app::{App, Plugin, PostUpdate};
|
||||
use bevy_ecs::{message::{Message, MessageReader}, schedule::{IntoScheduleConfigs as _, common_conditions::on_message}, system::Res};
|
||||
use bevy_log::{error, info};
|
||||
use bevy_mod_xr::session::XrSessionCreatedMessage;
|
||||
|
||||
impl Plugin for OxrActionAttachingPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<OxrAttachActionSet>();
|
||||
app.add_message::<OxrAttachActionSet>();
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
attach_sets
|
||||
.run_if(on_event::<XrSessionCreatedEvent>)
|
||||
.run_if(on_message::<XrSessionCreatedMessage>)
|
||||
.after(run_action_binding_sugestion),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn attach_sets(session: Res<OxrSession>, mut events: EventReader<OxrAttachActionSet>) {
|
||||
fn attach_sets(session: Res<OxrSession>, mut events: MessageReader<OxrAttachActionSet>) {
|
||||
let sets = events.read().map(|v| &v.0).collect::<Vec<_>>();
|
||||
if sets.is_empty() {
|
||||
return;
|
||||
@@ -36,7 +38,7 @@ fn attach_sets(session: Res<OxrSession>, mut events: EventReader<OxrAttachAction
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Event, Clone)]
|
||||
#[derive(Message, Clone)]
|
||||
/// Send this event for every ActionSet you want to attach to the [`OxrSession`] once the Session Status changed to Ready. all requests will
|
||||
/// be applied in [`PostUpdate`]
|
||||
pub struct OxrAttachActionSet(pub openxr::ActionSet);
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
use bevy_app::{App, Plugin, PreUpdate};
|
||||
use bevy_ecs::{message::{Message, MessageReader}, schedule::{IntoScheduleConfigs as _, SystemSet}, system::Res};
|
||||
use bevy_log::warn;
|
||||
|
||||
use crate::{openxr_session_running, session::OxrSession};
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
||||
pub struct OxrActionSetSyncSet;
|
||||
|
||||
impl Plugin for OxrActionSyncingPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<OxrSyncActionSet>();
|
||||
app.add_message::<OxrSyncActionSet>();
|
||||
app.add_systems(
|
||||
PreUpdate,
|
||||
sync_sets
|
||||
@@ -16,8 +19,8 @@ impl Plugin for OxrActionSyncingPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_sets(session: Res<OxrSession>, mut events: EventReader<OxrSyncActionSet>) {
|
||||
let sets = events
|
||||
fn sync_sets(session: Res<OxrSession>, mut messages: MessageReader<OxrSyncActionSet>) {
|
||||
let sets = messages
|
||||
.read()
|
||||
.map(|v| &v.0)
|
||||
.map(openxr::ActiveActionSet::new)
|
||||
@@ -31,7 +34,7 @@ fn sync_sets(session: Res<OxrSession>, mut events: EventReader<OxrSyncActionSet>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Event, Clone)]
|
||||
#[derive(Message, Clone)]
|
||||
/// Send this event for every ActionSet you want to attach to the [`OxrSession`] once the Session Status changed to Ready. all requests will
|
||||
pub struct OxrSyncActionSet(pub openxr::ActionSet);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use bevy::{ecs::resource::Resource, render::extract_resource::ExtractResource};
|
||||
use bevy_ecs::resource::Resource;
|
||||
use bevy_render::extract_resource::ExtractResource;
|
||||
use openxr::EnvironmentBlendMode;
|
||||
|
||||
#[derive(Resource, ExtractResource, Clone)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use bevy::prelude::{Deref, DerefMut, Resource};
|
||||
use bevy_derive::{Deref, DerefMut};
|
||||
use bevy_ecs::resource::Resource;
|
||||
use openxr::ExtensionSet;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deref, DerefMut, Resource)]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::Render;
|
||||
use bevy::render::RenderApp;
|
||||
use bevy::render::RenderSet;
|
||||
use bevy_log::error;
|
||||
use bevy_log::info;
|
||||
use bevy_render::Render;
|
||||
use bevy_render::RenderApp;
|
||||
use bevy_render::RenderSystems;
|
||||
use openxr::sys::SystemPassthroughProperties2FB;
|
||||
use openxr::PassthroughCapabilityFlagsFB;
|
||||
|
||||
@@ -105,7 +106,7 @@ pub fn supports_passthrough(instance: &OxrInstance, system: OxrSystemId) -> OxrR
|
||||
system.0,
|
||||
p.as_mut_ptr(),
|
||||
))?;
|
||||
bevy::log::info!(
|
||||
info!(
|
||||
"From supports_passthrough: Passthrough capabilities: {:?}",
|
||||
properties.capabilities
|
||||
);
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_app::{App, Plugin, PreUpdate, Startup};
|
||||
use bevy_derive::{Deref, DerefMut};
|
||||
use bevy_ecs::component::Component;
|
||||
use bevy_ecs::entity::Entity;
|
||||
use bevy_ecs::query::{Or, With};
|
||||
use bevy_ecs::schedule::IntoScheduleConfigs as _;
|
||||
use bevy_ecs::system::{Commands, Query, Res};
|
||||
use bevy_ecs::world::World;
|
||||
use bevy_log::{debug, error, warn};
|
||||
use bevy_mod_xr::hands::{
|
||||
spawn_hand_bones, HandBone, HandSide, SpawnHandTracker, SpawnHandTrackerCommandExecutor,
|
||||
XrHandBoneRadius,
|
||||
@@ -9,6 +17,7 @@ use bevy_mod_xr::spaces::{
|
||||
XrPrimaryReferenceSpace, XrReferenceSpace, XrSpaceLocationFlags, XrSpaceSyncSet,
|
||||
XrSpaceVelocityFlags, XrVelocity,
|
||||
};
|
||||
use bevy_transform::components::Transform;
|
||||
use openxr::{SpaceLocationFlags, SpaceVelocityFlags};
|
||||
|
||||
use crate::helper_traits::ToVec3;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::{mem, ptr};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_app::{App, First, Plugin};
|
||||
use bevy_ecs::{message::{Message, MessageWriter}, resource::Resource, schedule::IntoScheduleConfigs as _, system::{NonSendMut, Res}};
|
||||
use openxr::{sys, Event};
|
||||
|
||||
use crate::{
|
||||
@@ -14,8 +15,8 @@ use crate::{
|
||||
pub struct OxrOverlayPlugin;
|
||||
|
||||
impl Plugin for OxrOverlayPlugin {
|
||||
fn build(&self, app: &mut bevy::prelude::App) {
|
||||
app.add_event::<OxrOverlaySessionEvent>();
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_message::<OxrOverlaySessionMessage>();
|
||||
app.init_resource::<OxrOverlaySettings>();
|
||||
app.add_systems(
|
||||
First,
|
||||
@@ -25,9 +26,9 @@ impl Plugin for OxrOverlayPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_overlay_event(event: OxrEventIn, mut writer: EventWriter<OxrOverlaySessionEvent>) {
|
||||
fn handle_overlay_event(event: OxrEventIn, mut writer: MessageWriter<OxrOverlaySessionMessage>) {
|
||||
if let Event::MainSessionVisibilityChangedEXTX(event) = *event {
|
||||
writer.write(OxrOverlaySessionEvent::MainSessionVisibilityChanged {
|
||||
writer.write(OxrOverlaySessionMessage::MainSessionVisibilityChanged {
|
||||
visible: event.visible(),
|
||||
flags: event.flags(),
|
||||
});
|
||||
@@ -62,8 +63,8 @@ fn add_overlay_info_to_chain(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Event, Clone, Copy, Debug)]
|
||||
pub enum OxrOverlaySessionEvent {
|
||||
#[derive(Message, Clone, Copy, Debug)]
|
||||
pub enum OxrOverlaySessionMessage {
|
||||
MainSessionVisibilityChanged {
|
||||
visible: bool,
|
||||
flags: openxr::OverlayMainSessionFlagsEXTX,
|
||||
|
||||
@@ -5,7 +5,8 @@ pub mod vulkan;
|
||||
|
||||
use std::{any::TypeId, ffi::CStr};
|
||||
|
||||
use bevy::{ecs::resource::Resource, math::UVec2};
|
||||
use bevy_ecs::resource::Resource;
|
||||
use bevy_math::UVec2;
|
||||
use openxr::{FrameStream, FrameWaiter, Session};
|
||||
|
||||
use crate::{
|
||||
|
||||
@@ -2,10 +2,11 @@ use std::ffi::{c_void, CStr, CString};
|
||||
use std::str::FromStr;
|
||||
|
||||
use ash::vk::{self, Handle};
|
||||
use bevy::log::{debug, error};
|
||||
use bevy::math::UVec2;
|
||||
use bevy_log::{debug, error};
|
||||
use bevy_math::UVec2;
|
||||
use openxr::{sys, Version};
|
||||
use wgpu::InstanceFlags;
|
||||
use wgpu::{InstanceFlags, MemoryBudgetThresholds};
|
||||
use wgpu::TextureUses;
|
||||
use wgpu_hal::api::Vulkan;
|
||||
use wgpu_hal::Api;
|
||||
|
||||
@@ -53,7 +54,15 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
) -> Result<wgpu::Texture> {
|
||||
let color_image = vk::Image::from_raw(color_image);
|
||||
let wgpu_hal_texture = unsafe {
|
||||
<wgpu_hal::vulkan::Api as wgpu_hal::Api>::Device::texture_from_raw(
|
||||
let hal_dev =
|
||||
device
|
||||
.as_hal::<wgpu_hal::vulkan::Api>()
|
||||
.ok_or(OxrError::GraphicsBackendMismatch {
|
||||
item: "Wgpu Device",
|
||||
backend: "unknown",
|
||||
expected_backend: "vulkan",
|
||||
})?;
|
||||
hal_dev.texture_from_raw(
|
||||
color_image,
|
||||
&wgpu_hal::TextureDescriptor {
|
||||
label: Some("VR Swapchain"),
|
||||
@@ -66,7 +75,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format,
|
||||
usage: wgpu_hal::TextureUses::COLOR_TARGET | wgpu_hal::TextureUses::COPY_DST,
|
||||
usage: TextureUses::COLOR_TARGET | TextureUses::COPY_DST,
|
||||
memory_flags: wgpu_hal::MemoryFlags::empty(),
|
||||
view_formats: vec![],
|
||||
},
|
||||
@@ -151,7 +160,7 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
vk_physical_device,
|
||||
instance_exts,
|
||||
flags,
|
||||
device_exts.into(),
|
||||
device_exts,
|
||||
|info| unsafe {
|
||||
let vk_device = instance
|
||||
.create_vulkan_device(
|
||||
@@ -262,8 +271,8 @@ unsafe impl GraphicsExt for openxr::Vulkan {
|
||||
vk_physical_device,
|
||||
instance_exts,
|
||||
instance_flags,
|
||||
device_exts.into(),
|
||||
|info| unsafe { Ok(vk_instance.create_device(vk_physical_device, &info, None)?) },
|
||||
device_exts,
|
||||
|info| unsafe { Ok(vk_instance.create_device(vk_physical_device, info, None)?) },
|
||||
)
|
||||
.map(|v| v.0)
|
||||
}
|
||||
@@ -275,7 +284,7 @@ fn get_extensions(
|
||||
) -> Result<(wgpu::InstanceFlags, Vec<&'static CStr>, Vec<&'static CStr>)> {
|
||||
let flags = wgpu::InstanceFlags::default().with_env();
|
||||
let mut instance_exts =
|
||||
<Vulkan as Api>::Instance::desired_extensions(&vk_entry, VK_TARGET_VERSION_ASH, flags)?;
|
||||
<Vulkan as Api>::Instance::desired_extensions(vk_entry, VK_TARGET_VERSION_ASH, flags)?;
|
||||
let mut device_exts = vec![
|
||||
ash::khr::swapchain::NAME,
|
||||
ash::khr::draw_indirect_count::NAME,
|
||||
@@ -370,6 +379,7 @@ fn init_from_instance_and_dev(
|
||||
None,
|
||||
instance_exts,
|
||||
instance_flags,
|
||||
MemoryBudgetThresholds::default(),
|
||||
has_nv_optimus,
|
||||
None,
|
||||
)?
|
||||
@@ -442,8 +452,8 @@ fn init_from_instance_and_dev(
|
||||
required_features: wgpu_features,
|
||||
required_limits: limits,
|
||||
memory_hints: wgpu::MemoryHints::Performance,
|
||||
trace: wgpu::Trace::Off,
|
||||
},
|
||||
None,
|
||||
)
|
||||
}?;
|
||||
Ok((
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use bevy::{math::Vec3A, prelude::*};
|
||||
use bevy_math::{Isometry3d, Quat, Vec2, Vec3, Vec3A};
|
||||
use bevy_transform::components::Transform;
|
||||
|
||||
pub trait ToPosef {
|
||||
fn to_posef(&self) -> openxr::Posef;
|
||||
|
||||
@@ -1,23 +1,45 @@
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::extract_resource::ExtractResourcePlugin;
|
||||
use bevy::render::renderer::RenderAdapter;
|
||||
use bevy::render::renderer::RenderAdapterInfo;
|
||||
use bevy::render::renderer::RenderDevice;
|
||||
use bevy::render::renderer::RenderInstance;
|
||||
use bevy::render::renderer::RenderQueue;
|
||||
use bevy::render::renderer::WgpuWrapper;
|
||||
use bevy::render::settings::RenderCreation;
|
||||
use bevy::render::MainWorld;
|
||||
use bevy::render::Render;
|
||||
use bevy::render::RenderApp;
|
||||
use bevy::render::RenderDebugFlags;
|
||||
use bevy::render::RenderPlugin;
|
||||
use bevy::winit::UpdateMode;
|
||||
use bevy::winit::WinitSettings;
|
||||
use bevy_app::App;
|
||||
use bevy_app::Plugin;
|
||||
use bevy_ecs::message::MessageWriter;
|
||||
use bevy_ecs::message::Messages;
|
||||
use bevy_ecs::resource::Resource;
|
||||
use bevy_ecs::schedule::SystemCondition as _;
|
||||
use bevy_ecs::schedule::common_conditions::on_message;
|
||||
use bevy_ecs::schedule::common_conditions::resource_exists;
|
||||
use bevy_ecs::schedule::IntoScheduleConfigs as _;
|
||||
use bevy_ecs::system::Commands;
|
||||
use bevy_ecs::system::Local;
|
||||
use bevy_ecs::system::Res;
|
||||
use bevy_ecs::system::ResMut;
|
||||
use bevy_ecs::world::World;
|
||||
use bevy_log::debug;
|
||||
use bevy_log::debug_span;
|
||||
use bevy_log::error;
|
||||
use bevy_log::info;
|
||||
use bevy_log::warn;
|
||||
use bevy_math::UVec2;
|
||||
use bevy_mod_xr::session::*;
|
||||
use bevy_render::extract_resource::ExtractResourcePlugin;
|
||||
use bevy_render::renderer::RenderAdapter;
|
||||
use bevy_render::renderer::RenderAdapterInfo;
|
||||
use bevy_render::renderer::RenderDevice;
|
||||
use bevy_render::renderer::RenderInstance;
|
||||
use bevy_render::renderer::RenderQueue;
|
||||
use bevy_render::renderer::WgpuWrapper;
|
||||
use bevy_render::settings::RenderCreation;
|
||||
use bevy_render::ExtractSchedule;
|
||||
use bevy_render::MainWorld;
|
||||
use bevy_render::Render;
|
||||
use bevy_render::RenderApp;
|
||||
use bevy_render::RenderDebugFlags;
|
||||
use bevy_render::RenderPlugin;
|
||||
#[cfg(feature = "window_support")]
|
||||
use bevy_winit::UpdateMode;
|
||||
#[cfg(feature = "window_support")]
|
||||
use bevy_winit::WinitSettings;
|
||||
|
||||
use crate::error::OxrError;
|
||||
use crate::graphics::*;
|
||||
@@ -63,15 +85,15 @@ pub struct OxrInitPlugin {
|
||||
impl Default for OxrInitPlugin {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
app_info: default(),
|
||||
app_info: Default::default(),
|
||||
exts: {
|
||||
let mut exts = OxrExtensions::default();
|
||||
exts.enable_hand_tracking();
|
||||
exts
|
||||
},
|
||||
backends: default(),
|
||||
backends: Default::default(),
|
||||
synchronous_pipeline_compilation: false,
|
||||
render_debug_flags: default(),
|
||||
render_debug_flags: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +132,7 @@ impl Plugin for OxrInitPlugin {
|
||||
(
|
||||
create_xr_session
|
||||
.run_if(state_equals(XrState::Available))
|
||||
.run_if(on_event::<XrCreateSessionEvent>),
|
||||
.run_if(on_message::<XrCreateSessionMessage>),
|
||||
(
|
||||
destroy_xr_session,
|
||||
(|v: Res<XrDestroySessionRender>| {
|
||||
@@ -120,16 +142,16 @@ impl Plugin for OxrInitPlugin {
|
||||
)
|
||||
.chain()
|
||||
.run_if(state_matches!(XrState::Exiting { .. }))
|
||||
.run_if(on_event::<XrDestroySessionEvent>),
|
||||
.run_if(on_message::<XrDestroySessionMessage>),
|
||||
begin_xr_session
|
||||
.run_if(state_equals(XrState::Ready))
|
||||
.run_if(on_event::<XrBeginSessionEvent>),
|
||||
.run_if(on_message::<XrBeginSessionMessage>),
|
||||
end_xr_session
|
||||
.run_if(state_equals(XrState::Stopping))
|
||||
.run_if(on_event::<XrEndSessionEvent>),
|
||||
.run_if(on_message::<XrEndSessionMessage>),
|
||||
request_exit_xr_session
|
||||
.run_if(session_created)
|
||||
.run_if(on_event::<XrRequestExitEvent>),
|
||||
.run_if(on_message::<XrRequestExitMessage>),
|
||||
detect_session_destroyed,
|
||||
)
|
||||
.in_set(XrHandleEvents::SessionStateUpdateEvents),
|
||||
@@ -137,17 +159,20 @@ impl Plugin for OxrInitPlugin {
|
||||
.insert_resource(instance.clone())
|
||||
.insert_resource(system_id)
|
||||
.insert_resource(XrState::Available)
|
||||
.insert_resource(WinitSettings {
|
||||
focused_mode: UpdateMode::Continuous,
|
||||
unfocused_mode: UpdateMode::Continuous,
|
||||
})
|
||||
.insert_resource(OxrSessionStarted(false))
|
||||
.insert_non_send_resource(graphics_info)
|
||||
.init_non_send_resource::<OxrSessionCreateNextChain>();
|
||||
#[cfg(feature = "window_support")]
|
||||
{
|
||||
app.insert_resource(WinitSettings {
|
||||
focused_mode: UpdateMode::Continuous,
|
||||
unfocused_mode: UpdateMode::Continuous,
|
||||
});
|
||||
};
|
||||
|
||||
app.world_mut()
|
||||
.resource_mut::<Events<XrStateChanged>>()
|
||||
.send(XrStateChanged(XrState::Available));
|
||||
.resource_mut::<Messages<XrStateChanged>>()
|
||||
.write(XrStateChanged(XrState::Available));
|
||||
|
||||
let render_app = app.sub_app_mut(RenderApp);
|
||||
|
||||
@@ -213,7 +238,7 @@ impl Plugin for OxrInitPlugin {
|
||||
fn detect_session_destroyed(
|
||||
mut last_state: Local<bool>,
|
||||
state: Res<XrDestroySessionRender>,
|
||||
mut sender: EventWriter<XrSessionDestroyedEvent>,
|
||||
mut sender: MessageWriter<XrSessionDestroyedMessage>,
|
||||
mut cmds: Commands,
|
||||
) {
|
||||
let state = state.0.load(Ordering::Relaxed);
|
||||
@@ -307,7 +332,7 @@ impl OxrInitPlugin {
|
||||
pub fn handle_events(
|
||||
event: OxrEventIn,
|
||||
mut status: ResMut<XrState>,
|
||||
mut changed_event: EventWriter<XrStateChanged>,
|
||||
mut changed_event: MessageWriter<XrStateChanged>,
|
||||
) {
|
||||
use openxr::Event::*;
|
||||
match *event {
|
||||
@@ -511,7 +536,7 @@ pub fn create_xr_session(world: &mut World) {
|
||||
}
|
||||
world.insert_non_send_resource(chain);
|
||||
world.run_schedule(XrSessionCreated);
|
||||
world.send_event(XrSessionCreatedEvent);
|
||||
world.write_message(XrSessionCreatedMessage);
|
||||
}
|
||||
|
||||
pub fn destroy_xr_session(world: &mut World) {
|
||||
@@ -525,9 +550,7 @@ pub fn destroy_xr_session(world: &mut World) {
|
||||
world.insert_resource(XrState::Available);
|
||||
}
|
||||
|
||||
pub fn begin_xr_session(
|
||||
world: &mut World,
|
||||
) {
|
||||
pub fn begin_xr_session(world: &mut World) {
|
||||
let _span = debug_span!("xr_begin_session").entered();
|
||||
world
|
||||
.get_resource::<OxrSession>()
|
||||
@@ -539,9 +562,7 @@ pub fn begin_xr_session(
|
||||
world.run_schedule(XrPostSessionBegin);
|
||||
}
|
||||
|
||||
pub fn end_xr_session(
|
||||
world: &mut World,
|
||||
) {
|
||||
pub fn end_xr_session(world: &mut World) {
|
||||
world.run_schedule(XrPreSessionEnd);
|
||||
let _span = debug_span!("xr_end_session").entered();
|
||||
world
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::mem;
|
||||
|
||||
use bevy::ecs::world::World;
|
||||
use bevy_ecs::world::World;
|
||||
use bevy_mod_xr::spaces::{XrPrimaryReferenceSpace, XrSpace};
|
||||
use openxr::{sys, CompositionLayerFlags, Fovf, Posef, Rect2Di};
|
||||
|
||||
@@ -63,7 +63,7 @@ impl LayerProvider for ProjectionLayer {
|
||||
}
|
||||
|
||||
impl LayerProvider for PassthroughLayer {
|
||||
fn get(&self, world: &World) -> Option<Box<dyn CompositionLayer>> {
|
||||
fn get(&self, world: &World) -> Option<Box<dyn CompositionLayer<'_>>> {
|
||||
Some(Box::new(
|
||||
CompositionLayerPassthrough::new()
|
||||
.layer_handle(world.get_resource::<OxrPassthroughLayer>()?)
|
||||
@@ -171,7 +171,7 @@ impl Default for CompositionLayerProjectionView<'_> {
|
||||
}
|
||||
}
|
||||
/// # Safety
|
||||
/// the header function must return a ref to a valid Composition Layer struct.
|
||||
/// the header function must return a ref to a valid Composition Layer struct.
|
||||
/// it has to use `repr(C)` and it has to follow the shape of a Composition Layer struct from the
|
||||
/// OpenXR specification
|
||||
pub unsafe trait CompositionLayer<'a> {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// use actions::XrActionPlugin;
|
||||
use bevy::{
|
||||
app::{PluginGroup, PluginGroupBuilder},
|
||||
prelude::Res,
|
||||
render::RenderPlugin,
|
||||
utils::default,
|
||||
window::{PresentMode, Window, WindowPlugin},
|
||||
};
|
||||
use bevy_app::{PluginGroup, PluginGroupBuilder};
|
||||
use bevy_ecs::system::Res;
|
||||
use bevy_mod_xr::session::XrSessionPlugin;
|
||||
use bevy_mod_xr::{camera::XrCameraPlugin, session::XrState};
|
||||
use bevy_render::RenderPlugin;
|
||||
#[cfg(feature = "window_support")]
|
||||
use bevy_window::{PresentMode, Window, WindowPlugin};
|
||||
use init::OxrInitPlugin;
|
||||
use poll_events::OxrEventsPlugin;
|
||||
use render::OxrRenderPlugin;
|
||||
@@ -54,7 +52,7 @@ pub fn openxr_session_running(
|
||||
}
|
||||
|
||||
pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||
plugins
|
||||
let plugins = plugins
|
||||
.build()
|
||||
.disable::<RenderPlugin>()
|
||||
.add_before::<RenderPlugin>(XrSessionPlugin { auto_handle: true })
|
||||
@@ -69,15 +67,17 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||
.add(action_set_syncing::OxrActionSyncingPlugin)
|
||||
.add(features::overlay::OxrOverlayPlugin)
|
||||
.add(spaces::OxrSpatialPlugin)
|
||||
.add(spaces::OxrSpacePatchingPlugin)
|
||||
// we should probably handle the exiting ourselfs so that we can correctly end the
|
||||
// session and instance
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
transparent: true,
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
..default()
|
||||
}),
|
||||
.add(spaces::OxrSpacePatchingPlugin);
|
||||
// we should probably handle the exiting ourselfs so that we can correctly end the
|
||||
// session and instance
|
||||
#[cfg(feature = "window_support")]
|
||||
let plugins = plugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
transparent: true,
|
||||
present_mode: PresentMode::AutoNoVsync,
|
||||
..default()
|
||||
})
|
||||
}),
|
||||
..default()
|
||||
});
|
||||
plugins
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use super::{openxr_session_available, resources::OxrInstance};
|
||||
use bevy::{ecs::system::SystemId, prelude::*};
|
||||
use bevy_app::{App, Plugin};
|
||||
use bevy_derive::Deref;
|
||||
use bevy_ecs::{entity::Entity, resource::Resource, schedule::IntoScheduleConfigs as _, system::{IntoSystem, SystemId, SystemInput}, world::World};
|
||||
use bevy_log::{debug_span, error};
|
||||
use bevy_mod_xr::session::{XrFirst, XrHandleEvents};
|
||||
use openxr::{Event, EventDataBuffer};
|
||||
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
render::{extract_resource::ExtractResourcePlugin, RenderApp},
|
||||
use bevy_app::{App, Plugin};
|
||||
use bevy_ecs::{
|
||||
entity::Entity,
|
||||
query::With,
|
||||
resource::Resource,
|
||||
system::{Commands, Query, Res},
|
||||
};
|
||||
use bevy_log::error;
|
||||
use bevy_math::Isometry3d;
|
||||
use bevy_mod_xr::{
|
||||
session::{XrPreDestroySession, XrSessionCreated},
|
||||
spaces::{XrPrimaryReferenceSpace, XrReferenceSpace},
|
||||
};
|
||||
use bevy_render::{RenderApp, extract_resource::ExtractResourcePlugin};
|
||||
|
||||
use crate::session::OxrSession;
|
||||
|
||||
@@ -51,7 +57,7 @@ fn set_primary_ref_space(
|
||||
space_type: Res<OxrDefaultPrimaryReferenceSpaceType>,
|
||||
mut cmds: Commands,
|
||||
) {
|
||||
match session.create_reference_space(space_type.0, Transform::IDENTITY) {
|
||||
match session.create_reference_space(space_type.0, Isometry3d::IDENTITY) {
|
||||
Ok(space) => {
|
||||
cmds.insert_resource(XrPrimaryReferenceSpace(space));
|
||||
}
|
||||
|
||||
@@ -1,25 +1,33 @@
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
render::{
|
||||
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
|
||||
extract_resource::ExtractResourcePlugin,
|
||||
pipelined_rendering::PipelinedRenderingPlugin,
|
||||
view::{ExtractedView, NoFrustumCulling},
|
||||
Render, RenderApp,
|
||||
},
|
||||
transform::TransformSystem,
|
||||
use bevy_app::{App, Plugin, PostUpdate};
|
||||
use bevy_camera::{Camera, ManualTextureViewHandle, Projection, RenderTarget};
|
||||
use bevy_ecs::{
|
||||
change_detection::DetectChanges as _,
|
||||
entity::Entity,
|
||||
schedule::{IntoScheduleConfigs as _, SystemSet},
|
||||
system::{Commands, Query, Res, ResMut},
|
||||
world::World,
|
||||
};
|
||||
use bevy_log::{debug_span, error, info};
|
||||
use bevy_render::{
|
||||
extract_resource::ExtractResourcePlugin,
|
||||
pipelined_rendering::PipelinedRenderingPlugin,
|
||||
texture::{ManualTextureView, ManualTextureViews},
|
||||
view::ExtractedView,
|
||||
Render, RenderApp,
|
||||
};
|
||||
|
||||
use bevy_mod_xr::{
|
||||
camera::{calculate_projection, Fov, XrCamera, XrProjection, XrViewInit},
|
||||
session::{
|
||||
XrFirst, XrHandleEvents, XrPreDestroySession, XrRenderSet, XrRootTransform,
|
||||
XrFirst, XrHandleEvents, XrPreDestroySession, XrRenderSystems, XrRootTransform,
|
||||
XrSessionCreated,
|
||||
},
|
||||
spaces::XrPrimaryReferenceSpace,
|
||||
};
|
||||
use bevy_transform::{components::Transform, TransformSystems};
|
||||
use openxr::ViewStateFlags;
|
||||
|
||||
use crate::{init::should_run_frame_loop, resources::*};
|
||||
use crate::{helper_traits::ToTransform as _, init::should_run_frame_loop, resources::*};
|
||||
use crate::{layer_builder::ProjectionLayer, session::OxrSession};
|
||||
|
||||
use super::environment_blend_mode::OxrEnvironmentBlendModes;
|
||||
@@ -88,9 +96,8 @@ impl Plugin for OxrRenderPlugin {
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(locate_views, update_views)
|
||||
.before(TransformSystem::TransformPropagate)
|
||||
.before(TransformSystems::Propagate)
|
||||
.chain()
|
||||
// .run_if(should_render)
|
||||
.run_if(should_run_frame_loop),
|
||||
)
|
||||
.init_resource::<OxrViews>();
|
||||
@@ -109,7 +116,7 @@ impl Plugin for OxrRenderPlugin {
|
||||
wait_image,
|
||||
)
|
||||
.chain()
|
||||
.in_set(XrRenderSet::PreRender)
|
||||
.in_set(XrRenderSystems::PreRender)
|
||||
.run_if(should_run_frame_loop),
|
||||
)
|
||||
.add_systems(
|
||||
@@ -117,40 +124,12 @@ impl Plugin for OxrRenderPlugin {
|
||||
(release_image, end_frame)
|
||||
.chain()
|
||||
.run_if(should_run_frame_loop)
|
||||
.in_set(XrRenderSet::PostRender),
|
||||
.in_set(XrRenderSystems::PostRender),
|
||||
)
|
||||
.insert_resource(OxrRenderLayers(vec![Box::new(ProjectionLayer)]));
|
||||
}
|
||||
}
|
||||
|
||||
// fn update_rendering(app_world: &mut World, _sub_app: &mut App) {
|
||||
// app_world.resource_scope(|world, main_thread_executor: Mut<MainThreadExecutor>| {
|
||||
// world.resource_scope(|world, mut render_channels: Mut<RenderAppChannels>| {
|
||||
// // we use a scope here to run any main thread tasks that the render world still needs to run
|
||||
// // while we wait for the render world to be received.
|
||||
// let mut render_app = ComputeTaskPool::get()
|
||||
// .scope_with_executor(true, Some(&*main_thread_executor.0), |s| {
|
||||
// s.spawn(async { render_channels.recv().await });
|
||||
// })
|
||||
// .pop()
|
||||
// .unwrap();
|
||||
|
||||
// if matches!(world.resource::<XrState>(), XrState::Stopping) {
|
||||
// world.run_schedule(XrEndSession);
|
||||
// }
|
||||
|
||||
// if matches!(world.resource::<XrState>(), XrState::Exiting { .. }) {
|
||||
// world.run_schedule(XrDestroySession);
|
||||
// render_app.app.world.run_schedule(XrDestroySession);
|
||||
// }
|
||||
|
||||
// render_app.extract(world);
|
||||
|
||||
// render_channels.send_blocking(render_app);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
pub const XR_TEXTURE_INDEX: u32 = 3383858418;
|
||||
|
||||
pub fn clean_views(
|
||||
@@ -185,7 +164,7 @@ pub fn init_views<const SPAWN_CAMERAS: bool>(
|
||||
},
|
||||
XrCamera(index),
|
||||
Projection::custom(XrProjection::default()),
|
||||
NoFrustumCulling,
|
||||
// NoFrustumCulling,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -283,12 +262,7 @@ pub fn update_views(
|
||||
);
|
||||
projection.projection_matrix = projection_matrix;
|
||||
|
||||
let openxr::Quaternionf { x, y, z, w } = view.pose.orientation;
|
||||
let rotation = Quat::from_xyzw(x, y, z, w);
|
||||
transform.rotation = rotation;
|
||||
let openxr::Vector3f { x, y, z } = view.pose.position;
|
||||
let translation = Vec3::new(x, y, z);
|
||||
transform.translation = translation;
|
||||
*transform = view.pose.to_transform();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,14 +275,7 @@ pub fn update_views_render_world(
|
||||
let Some(view) = views.get(camera.0 as usize) else {
|
||||
continue;
|
||||
};
|
||||
let mut transform = Transform::IDENTITY;
|
||||
let openxr::Quaternionf { x, y, z, w } = view.pose.orientation;
|
||||
let rotation = Quat::from_xyzw(x, y, z, w);
|
||||
transform.rotation = rotation;
|
||||
let openxr::Vector3f { x, y, z } = view.pose.position;
|
||||
let translation = Vec3::new(x, y, z);
|
||||
transform.translation = translation;
|
||||
extracted_view.world_from_view = root.0.mul_transform(transform);
|
||||
extracted_view.world_from_view = root.0.mul_transform(view.pose.to_transform());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +312,7 @@ pub fn add_texture_view(
|
||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
||||
array_layer_count: Some(1),
|
||||
base_array_layer: index,
|
||||
..default()
|
||||
..Default::default()
|
||||
});
|
||||
let view = ManualTextureView {
|
||||
texture_view: view.into(),
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::extract_resource::ExtractResource;
|
||||
use bevy_derive::{Deref, DerefMut};
|
||||
use bevy_ecs::resource::Resource;
|
||||
use bevy_math::UVec2;
|
||||
use bevy_render::extract_resource::ExtractResource;
|
||||
use bevy_log::error;
|
||||
|
||||
use crate::error::OxrError;
|
||||
use crate::graphics::*;
|
||||
@@ -351,7 +354,7 @@ impl Default for OxrSessionConfig {
|
||||
Self {
|
||||
blend_mode_preference: vec![openxr::EnvironmentBlendMode::OPAQUE],
|
||||
formats: Some(vec![wgpu::TextureFormat::Rgba8UnormSrgb]),
|
||||
resolutions: default(),
|
||||
resolutions: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ use std::ffi::c_void;
|
||||
use crate::next_chain::{OxrNextChain, OxrNextChainStructBase, OxrNextChainStructProvider};
|
||||
use crate::resources::{OxrPassthrough, OxrPassthroughLayer, OxrSwapchain};
|
||||
use crate::types::{Result, SwapchainCreateInfo};
|
||||
use bevy::prelude::*;
|
||||
use bevy_derive::Deref;
|
||||
use bevy_ecs::resource::Resource;
|
||||
use openxr::AnyGraphics;
|
||||
|
||||
use crate::graphics::{graphics_match, GraphicsExt, GraphicsType, GraphicsWrap};
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
use std::{mem::MaybeUninit, ptr, sync::Mutex};
|
||||
|
||||
use bevy::{platform::collections::hash_set::HashSet, prelude::*};
|
||||
use bevy_app::{App, Plugin, PreUpdate, Startup};
|
||||
use bevy_ecs::{
|
||||
component::Component, message::MessageReader, schedule::IntoScheduleConfigs as _, system::{Query, Res, ResMut}
|
||||
};
|
||||
use bevy_log::{error, info};
|
||||
use bevy_log::warn;
|
||||
use bevy_math::Isometry3d;
|
||||
use bevy_mod_xr::{
|
||||
session::{XrFirst, XrHandleEvents},
|
||||
spaces::{
|
||||
XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrSpaceLocationFlags, XrSpaceSyncSet, XrSpaceVelocityFlags, XrVelocity
|
||||
XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrSpaceLocationFlags,
|
||||
XrSpaceSyncSet, XrSpaceVelocityFlags, XrVelocity,
|
||||
},
|
||||
};
|
||||
use bevy_platform::collections::hash_set::HashSet;
|
||||
use bevy_transform::components::Transform;
|
||||
use openxr::{
|
||||
sys, HandJointLocation, HandJointLocations, HandJointVelocities, HandJointVelocity,
|
||||
ReferenceSpaceType, SpaceLocationFlags, SpaceVelocityFlags, HAND_JOINT_COUNT,
|
||||
};
|
||||
use std::{mem::MaybeUninit, ptr, sync::Mutex};
|
||||
|
||||
use crate::{
|
||||
helper_traits::{ToPosef, ToQuat, ToVec3},
|
||||
@@ -33,7 +41,7 @@ impl Plugin for OxrSpacePatchingPlugin {
|
||||
pub struct OxrSpatialPlugin;
|
||||
impl Plugin for OxrSpatialPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<XrDestroySpace>()
|
||||
app.add_message::<XrDestroySpace>()
|
||||
.add_systems(
|
||||
XrFirst,
|
||||
destroy_space_event
|
||||
@@ -51,7 +59,7 @@ impl Plugin for OxrSpatialPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn destroy_space_event(instance: Res<OxrInstance>, mut events: EventReader<XrDestroySpace>) {
|
||||
fn destroy_space_event(instance: Res<OxrInstance>, mut events: MessageReader<XrDestroySpace>) {
|
||||
for space in events.read() {
|
||||
match instance.destroy_space(space.0) {
|
||||
Ok(_) => (),
|
||||
@@ -231,7 +239,7 @@ impl OxrSession {
|
||||
pub fn create_reference_space(
|
||||
&self,
|
||||
ref_space_type: ReferenceSpaceType,
|
||||
pose_in_ref_space: Transform,
|
||||
pose_in_ref_space: Isometry3d,
|
||||
) -> openxr::Result<XrReferenceSpace> {
|
||||
let info = sys::ReferenceSpaceCreateInfo {
|
||||
ty: sys::ReferenceSpaceCreateInfo::TYPE,
|
||||
@@ -579,6 +587,7 @@ fn cvt(x: sys::Result) -> openxr::Result<sys::Result> {
|
||||
Err(x)
|
||||
}
|
||||
}
|
||||
#[allow(clippy::obfuscated_if_else)]
|
||||
unsafe fn create_view(flags: openxr::ViewStateFlags, raw: &MaybeUninit<sys::View>) -> openxr::View {
|
||||
// Applications *must* not read invalid parts of a poses, i.e. they may be uninitialized
|
||||
let ptr = raw.as_ptr();
|
||||
@@ -596,6 +605,7 @@ unsafe fn create_view(flags: openxr::ViewStateFlags, raw: &MaybeUninit<sys::View
|
||||
fov: *ptr::addr_of!((*ptr).fov),
|
||||
}
|
||||
}
|
||||
#[allow(clippy::obfuscated_if_else)]
|
||||
unsafe fn create_space_location(raw: &MaybeUninit<sys::SpaceLocation>) -> openxr::SpaceLocation {
|
||||
// Applications *must* not read invalid parts of a pose, i.e. they may be uninitialized
|
||||
let ptr = raw.as_ptr();
|
||||
@@ -614,6 +624,7 @@ unsafe fn create_space_location(raw: &MaybeUninit<sys::SpaceLocation>) -> openxr
|
||||
},
|
||||
}
|
||||
}
|
||||
#[allow(clippy::obfuscated_if_else)]
|
||||
unsafe fn create_space_velocity(raw: &MaybeUninit<sys::SpaceVelocity>) -> openxr::SpaceVelocity {
|
||||
// Applications *must* not read invalid velocities, i.e. they may be uninitialized
|
||||
let ptr = raw.as_ptr();
|
||||
|
||||
Reference in New Issue
Block a user