update to bevy release, fix event support and update extension list
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
//! A simple 3D scene with light shining over a cube sitting on a plane.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_mod_openxr::{add_xr_plugins, init::OxrInitPlugin, types::OxrExtensions};
|
||||
use bevy_mod_xr::session::XrState;
|
||||
// use openxr::EnvironmentBlendMode;
|
||||
// use wgpu::TextureFormat;
|
||||
use bevy_mod_openxr::{
|
||||
add_xr_plugins, features::overlay::OxrOverlaySessionEvent, init::OxrInitPlugin,
|
||||
types::OxrExtensions,
|
||||
};
|
||||
use openxr::EnvironmentBlendMode;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
@@ -12,32 +13,32 @@ fn main() {
|
||||
exts: {
|
||||
let mut exts = OxrExtensions::default();
|
||||
exts.enable_hand_tracking();
|
||||
exts.other.push("XR_EXTX_overlay\0".into());
|
||||
exts.extx_overlay = true;
|
||||
exts
|
||||
},
|
||||
// blend_modes: Some({
|
||||
// let mut v = Vec::new();
|
||||
// v.push(EnvironmentBlendMode::ALPHA_BLEND);
|
||||
// v.push(EnvironmentBlendMode::ADDITIVE);
|
||||
// v.push(EnvironmentBlendMode::OPAQUE);
|
||||
// v
|
||||
// }),
|
||||
// formats: Some({
|
||||
// let mut v = Vec::new();
|
||||
// // v.push(TextureFormat::Rgba8Uint);
|
||||
// v.push(TextureFormat::Rgba8Unorm);
|
||||
// v.push(TextureFormat::Rgba8UnormSrgb);
|
||||
// v
|
||||
// }),
|
||||
blend_modes: Some({
|
||||
vec![
|
||||
EnvironmentBlendMode::ALPHA_BLEND,
|
||||
EnvironmentBlendMode::OPAQUE,
|
||||
]
|
||||
}),
|
||||
..OxrInitPlugin::default()
|
||||
}))
|
||||
.insert_resource(ClearColor(Color::NONE))
|
||||
.add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, handle_input)
|
||||
.add_systems(Update, print_main_session_changes)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn print_main_session_changes(mut events: EventReader<OxrOverlaySessionEvent>) {
|
||||
for event in events.read() {
|
||||
let OxrOverlaySessionEvent::MainSessionVisibilityChanged { visible, flags: _ } = event;
|
||||
info!("main session visible: {visible}");
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_input(
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut end: EventWriter<bevy_mod_xr::session::XrEndSessionEvent>,
|
||||
@@ -45,7 +46,6 @@ fn handle_input(
|
||||
mut begin: EventWriter<bevy_mod_xr::session::XrBeginSessionEvent>,
|
||||
mut create: EventWriter<bevy_mod_xr::session::XrCreateSessionEvent>,
|
||||
mut request_exit: EventWriter<bevy_mod_xr::session::XrRequestExitEvent>,
|
||||
state: Res<XrState>,
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::KeyE) {
|
||||
info!("sending end");
|
||||
@@ -67,9 +67,6 @@ fn handle_input(
|
||||
info!("sending request exit");
|
||||
request_exit.send_default();
|
||||
}
|
||||
if keys.just_pressed(KeyCode::KeyI) {
|
||||
info!("current state: {:?}", *state);
|
||||
}
|
||||
}
|
||||
|
||||
/// set up a simple 3D scene
|
||||
@@ -78,12 +75,6 @@ fn setup(
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// circular base
|
||||
// commands.spawn((
|
||||
// Mesh3d(meshes.add(Circle::new(4.0))),
|
||||
// MeshMaterial3d(materials.add(Color::WHITE)),
|
||||
// Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
|
||||
// ));
|
||||
// cube
|
||||
commands.spawn((
|
||||
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
|
||||
@@ -92,11 +83,11 @@ fn setup(
|
||||
));
|
||||
// light
|
||||
commands.spawn((
|
||||
PointLight {
|
||||
PointLight {
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
));
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use bevy::{ecs::system::Resource, prelude::{Deref, DerefMut}};
|
||||
use bevy::{
|
||||
ecs::system::Resource,
|
||||
prelude::{Deref, DerefMut},
|
||||
};
|
||||
use openxr::ExtensionSet;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deref, DerefMut, Resource)]
|
||||
@@ -196,6 +199,8 @@ macro_rules! impl_ext {
|
||||
ext_local_floor,
|
||||
ext_hand_tracking_data_source,
|
||||
ext_plane_detection,
|
||||
ext_future,
|
||||
ext_user_presence,
|
||||
fb_composition_layer_image_layout,
|
||||
fb_composition_layer_alpha_blend,
|
||||
#[cfg(target_os = "android")]
|
||||
@@ -238,6 +243,7 @@ macro_rules! impl_ext {
|
||||
fb_composition_layer_depth_test,
|
||||
fb_spatial_entity_storage_batch,
|
||||
fb_spatial_entity_user,
|
||||
fb_face_tracking2,
|
||||
htc_vive_cosmos_controller_interaction,
|
||||
htc_facial_tracking,
|
||||
htc_vive_focus3_controller_interaction,
|
||||
@@ -245,6 +251,7 @@ macro_rules! impl_ext {
|
||||
htc_vive_wrist_tracker_interaction,
|
||||
htc_passthrough,
|
||||
htc_foveation,
|
||||
htc_anchor,
|
||||
huawei_controller_interaction,
|
||||
#[cfg(target_os = "android")]
|
||||
khr_android_thread_settings,
|
||||
@@ -276,6 +283,8 @@ macro_rules! impl_ext {
|
||||
khr_composition_layer_equirect2,
|
||||
khr_binding_modification,
|
||||
khr_swapchain_usage_input_attachment_bit,
|
||||
khr_locate_spaces,
|
||||
khr_maintenance1,
|
||||
meta_foveation_eye_tracked,
|
||||
meta_local_dimming,
|
||||
meta_passthrough_preferences,
|
||||
@@ -283,11 +292,18 @@ macro_rules! impl_ext {
|
||||
meta_vulkan_swapchain_create_info,
|
||||
meta_performance_metrics,
|
||||
meta_headset_id,
|
||||
meta_recommended_layer_resolution,
|
||||
meta_passthrough_color_lut,
|
||||
meta_spatial_entity_mesh,
|
||||
meta_automatic_layer_filter,
|
||||
meta_touch_controller_plus,
|
||||
meta_environment_depth,
|
||||
ml_ml2_controller_interaction,
|
||||
ml_frame_end_info,
|
||||
ml_global_dimmer,
|
||||
ml_compat,
|
||||
ml_marker_understanding,
|
||||
ml_localization_map,
|
||||
ml_user_calibration,
|
||||
mnd_headless,
|
||||
mnd_swapchain_usage_input_attachment_bit,
|
||||
@@ -319,7 +335,12 @@ macro_rules! impl_ext {
|
||||
varjo_environment_depth_estimation,
|
||||
varjo_marker_tracking,
|
||||
varjo_view_offset,
|
||||
varjo_xr4_controller_interaction,
|
||||
yvr_controller_interaction,
|
||||
extx_overlay,
|
||||
mndx_egl_enable,
|
||||
mndx_force_feedback_curl,
|
||||
htcx_vive_tracker_interaction,
|
||||
}
|
||||
)*
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ fn add_overlay_info_to_chain(
|
||||
exts: Res<OxrEnabledExtensions>,
|
||||
settings: Res<OxrOverlaySettings>,
|
||||
) {
|
||||
if exts.other.contains(&"XR_EXTX_overlay\0".to_string()) {
|
||||
if exts.extx_overlay {
|
||||
chain.push(OxrSessionCreateInfoOverlay::new(
|
||||
settings.flags,
|
||||
settings.session_layer_placement,
|
||||
|
||||
@@ -45,15 +45,16 @@ use super::{openxr_session_available, resources::OxrInstance};
|
||||
pub struct OxrEventHandlers {
|
||||
pub handlers: Vec<OxrEventHandler>,
|
||||
}
|
||||
pub type OxrEventHandler = SystemId<OxrEvent, ()>;
|
||||
pub type OxrEventHandler = SystemId<In<OxrEvent>, ()>;
|
||||
|
||||
pub struct OxrEvent {
|
||||
event: Rc<RefCell<Option<Event<'static>>>>,
|
||||
}
|
||||
|
||||
impl OxrEvent {
|
||||
pub(crate) fn new<'a>(event: Rc<RefCell<Option<Event<'a>>>>) -> Self {
|
||||
pub(crate) fn new(event: Rc<RefCell<Option<Event<'_>>>>) -> Self {
|
||||
Self {
|
||||
#[allow(clippy::missing_transmute_annotations)]
|
||||
event: unsafe { mem::transmute(event) },
|
||||
}
|
||||
}
|
||||
@@ -63,19 +64,19 @@ impl OxrEvent {
|
||||
/// don't Store the [Event] anywhere!!
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
pub unsafe fn get<'a>(&'a self) -> Option<Event<'a>> {
|
||||
self.event.borrow().clone()
|
||||
*self.event.borrow()
|
||||
}
|
||||
}
|
||||
pub trait OxrEventHandlerExt {
|
||||
fn add_oxr_event_handler<M>(
|
||||
&mut self,
|
||||
system: impl IntoSystem<OxrEvent, (), M> + 'static,
|
||||
system: impl IntoSystem<In<OxrEvent>, (), M> + 'static,
|
||||
) -> &mut Self;
|
||||
}
|
||||
impl OxrEventHandlerExt for App {
|
||||
fn add_oxr_event_handler<M>(
|
||||
&mut self,
|
||||
system: impl IntoSystem<OxrEvent, (), M> + 'static,
|
||||
system: impl IntoSystem<In<OxrEvent>, (), M> + 'static,
|
||||
) -> &mut Self {
|
||||
self.init_resource::<OxrEventHandlers>();
|
||||
let id = self.register_system(system);
|
||||
|
||||
Reference in New Issue
Block a user