refactor: cleanup for bevy 0.16

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2025-04-26 14:25:54 +02:00
parent ae54de3db9
commit 6284d4bf31
13 changed files with 46 additions and 84 deletions

View File

@@ -21,8 +21,8 @@ fn main() {
.add_systems(Update, handle_flight_input)
// Realtime lighting is expensive, use ambient light instead
.insert_resource(AmbientLight {
color: Default::default(),
brightness: 500.0,
..AmbientLight::default()
})
.run();
}
@@ -48,7 +48,7 @@ fn setup_scene(
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
@@ -132,14 +132,15 @@ fn handle_flight_input(
//hard code speed for now
let speed = 5.0;
let root = oxr_root.get_single_mut();
let root = oxr_root.single_mut();
match root {
Ok(mut root_position) => {
//lets assume HMD based direction for now
let view = views.first();
match view {
Some(v) => {
let reference_quat = root_position.rotation * v.pose.orientation.to_quat();
let reference_quat =
root_position.rotation * v.pose.orientation.to_quat();
let locomotion_vector = reference_quat.mul_vec3(input_vector);
root_position.translation +=

View File

@@ -49,23 +49,23 @@ fn handle_input(
) {
if keys.just_pressed(KeyCode::KeyE) {
info!("sending end");
end.send_default();
end.write_default();
}
if keys.just_pressed(KeyCode::KeyC) {
info!("sending create");
create.send_default();
create.write_default();
}
if keys.just_pressed(KeyCode::KeyD) {
info!("sending destroy");
destroy.send_default();
destroy.write_default();
}
if keys.just_pressed(KeyCode::KeyB) {
info!("sending begin");
begin.send_default();
begin.write_default();
}
if keys.just_pressed(KeyCode::KeyR) {
info!("sending request exit");
request_exit.send_default();
request_exit.write_default();
}
}

View File

@@ -35,7 +35,7 @@ fn main() {
}
fn attach_set(actions: Res<ControllerActions>, mut attach: EventWriter<OxrAttachActionSet>) {
attach.send(OxrAttachActionSet(actions.set.clone()));
attach.write(OxrAttachActionSet(actions.set.clone()));
}
#[derive(Resource)]
@@ -45,7 +45,7 @@ struct ControllerActions {
right: openxr::Action<Posef>,
}
fn sync_actions(actions: Res<ControllerActions>, mut sync: EventWriter<OxrSyncActionSet>) {
sync.send(OxrSyncActionSet(actions.set.clone()));
sync.write(OxrSyncActionSet(actions.set.clone()));
}
/// set up a simple 3D scene
fn setup(
@@ -82,12 +82,12 @@ fn suggest_action_bindings(
actions: Res<ControllerActions>,
mut bindings: EventWriter<OxrSuggestActionBinding>,
) {
bindings.send(OxrSuggestActionBinding {
bindings.write(OxrSuggestActionBinding {
action: actions.left.as_raw(),
interaction_profile: "/interaction_profiles/oculus/touch_controller".into(),
bindings: vec!["/user/hand/left/input/grip/pose".into()],
});
bindings.send(OxrSuggestActionBinding {
bindings.write(OxrSuggestActionBinding {
action: actions.right.as_raw(),
interaction_profile: "/interaction_profiles/oculus/touch_controller".into(),
bindings: vec!["/user/hand/right/input/grip/pose".into()],

View File

@@ -32,23 +32,23 @@ fn handle_input(
) {
if keys.just_pressed(KeyCode::KeyE) {
info!("sending end");
end.send_default();
end.write_default();
}
if keys.just_pressed(KeyCode::KeyC) {
info!("sending create");
create.send_default();
create.write_default();
}
if keys.just_pressed(KeyCode::KeyD) {
info!("sending destroy");
destroy.send_default();
destroy.write_default();
}
if keys.just_pressed(KeyCode::KeyB) {
info!("sending begin");
begin.send_default();
begin.write_default();
}
if keys.just_pressed(KeyCode::KeyR) {
info!("sending request exit");
request_exit.send_default();
request_exit.write_default();
}
if keys.just_pressed(KeyCode::KeyI) {
info!("current state: {:?}", *state);

View File

@@ -28,8 +28,8 @@ fn main() {
send_recenter.after(XRUtilsActionSystemSet::SyncActionStates),
)
.insert_resource(AmbientLight {
color: Default::default(),
brightness: 500.0,
..AmbientLight::default()
})
.run();
}
@@ -161,7 +161,7 @@ fn send_look_at_red_cube_event(
info!("send facing");
let quat = Transform::default()
.looking_at(Transform::from_xyz(4.0, 0.0, 0.0).translation, Vec3::Y); //this is a transform facing the red cube from the center of the scene, you should use the HMD posision but I was lazy.
event_writer.send(SnapToRotation(quat.rotation));
event_writer.write(SnapToRotation(quat.rotation));
}
}
XRUtilsActionState::Float(_) => (),
@@ -185,7 +185,7 @@ fn send_recenter(
if send {
let center = Transform::default().translation;
event_writer.send(SnapToPosition(center));
event_writer.write(SnapToPosition(center));
}
}
XRUtilsActionState::Float(_) => (),

View File

@@ -27,7 +27,7 @@ impl Plugin for OxrOverlayPlugin {
fn handle_overlay_event(event: OxrEventIn, mut writer: EventWriter<OxrOverlaySessionEvent>) {
if let Event::MainSessionVisibilityChangedEXTX(event) = *event {
writer.send(OxrOverlaySessionEvent::MainSessionVisibilityChanged {
writer.write(OxrOverlaySessionEvent::MainSessionVisibilityChanged {
visible: event.visible(),
flags: event.flags(),
});

View File

@@ -9,7 +9,7 @@ use crate::resources::*;
use crate::spaces::OxrSpaceExt as _;
pub trait LayerProvider {
fn get<'a>(&'a self, world: &'a World) -> Option<Box<dyn CompositionLayer + 'a>>;
fn get<'a>(&'a self, world: &'a World) -> Option<Box<dyn CompositionLayer<'a> + 'a>>;
}
pub struct ProjectionLayer;
@@ -117,7 +117,7 @@ impl<'a> SwapchainSubImage<'a> {
}
}
impl<'a> Default for SwapchainSubImage<'a> {
impl Default for SwapchainSubImage<'_> {
fn default() -> Self {
Self::new()
}
@@ -165,11 +165,15 @@ impl<'a> CompositionLayerProjectionView<'a> {
self
}
}
impl<'a> Default for CompositionLayerProjectionView<'a> {
impl Default for CompositionLayerProjectionView<'_> {
fn default() -> Self {
Self::new()
}
}
/// # Safety
/// 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> {
fn swapchain(&self) -> Option<&'a OxrSwapchain>;
fn header(&self) -> &sys::CompositionLayerBaseHeader;
@@ -227,7 +231,7 @@ unsafe impl<'a> CompositionLayer<'a> for CompositionLayerProjection<'a> {
unsafe { mem::transmute(&self.inner) }
}
}
impl<'a> Default for CompositionLayerProjection<'a> {
impl Default for CompositionLayerProjection<'_> {
fn default() -> Self {
Self::new()
}

View File

@@ -20,18 +20,10 @@ impl Default for OxrReferenceSpacePlugin {
}
}
/// Resource specifying what the type should be for [`OxrPrimaryReferenceSpace`]. Set through [`OxrReferenceSpacePlugin`].
/// Resource specifying what the type should used be for the [`XrPrimaryReferenceSpace`]. Set through [`OxrReferenceSpacePlugin`].
#[derive(Resource)]
struct OxrDefaultPrimaryReferenceSpaceType(openxr::ReferenceSpaceType);
/// The Default Reference space used for locating things
// #[derive(Resource, Deref, ExtrctResource, Clone)]
// pub struct OxrPrimaryReferenceSpace(pub Arc<openxr::Space>);
/// The Reference space used for locating spaces on this entity
#[derive(Component)]
pub struct OxrReferenceSpace(pub openxr::Space);
impl Plugin for OxrReferenceSpacePlugin {
fn build(&self, app: &mut App) {
app.add_plugins(ExtractResourcePlugin::<XrPrimaryReferenceSpace>::default())

View File

@@ -1,4 +1,3 @@
use bevy::{
prelude::*,
render::{
@@ -251,7 +250,6 @@ pub fn update_views(
views: ResMut<OxrViews>,
) {
for (mut transform, mut projection, camera) in query.iter_mut() {
println!("we have this query");
let Some(view) = views.get(camera.0 as usize) else {
continue;
};
@@ -271,11 +269,6 @@ pub fn update_views(
);
projection.projection_matrix = projection_matrix;
println!(
"Updateing projectinon matrix to: {:#?}",
projection.projection_matrix
);
let openxr::Quaternionf { x, y, z, w } = view.pose.orientation;
let rotation = Quat::from_xyzw(x, y, z, w);
transform.rotation = rotation;

View File

@@ -288,10 +288,6 @@ impl OxrSwapchain {
#[derive(Debug, Deref, Resource, Clone, Copy, ExtractResource)]
pub struct OxrSwapchainImages(pub &'static [wgpu::Texture]);
/// Thread safe wrapper around [openxr::Space] representing the stage.
// #[derive(Deref, Clone, Resource)]
// pub struct OxrStage(pub Arc<openxr::Space>);
/// Stores the latest generated [OxrViews]
#[derive(Clone, Resource, ExtractResource, Deref, DerefMut, Default)]
pub struct OxrViews(pub Vec<openxr::View>);