update to bevy 0.15 rc

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-11-20 10:04:49 +01:00
parent 690b433516
commit 7320ae8dac
34 changed files with 1338 additions and 1079 deletions

View File

@@ -94,11 +94,11 @@ impl<A: Action<ActionType = bool>> ActionState<A> {
}
pub fn just_pressed(&self) -> bool {
self.previous_state == false && self.current_state == true
!self.previous_state && self.current_state
}
pub fn just_released(&self) -> bool {
self.previous_state == true && self.current_state == false
self.previous_state && !self.current_state
}
pub fn press(&mut self) {

View File

@@ -1,3 +1,5 @@
use core::panic;
use bevy::app::{App, Plugin, PostUpdate};
use bevy::core_pipeline::core_3d::graph::Core3d;
use bevy::core_pipeline::core_3d::Camera3d;
@@ -7,7 +9,9 @@ use bevy::ecs::component::Component;
use bevy::ecs::reflect::ReflectComponent;
use bevy::ecs::schedule::IntoSystemConfigs;
use bevy::math::{Mat4, Vec3A};
use bevy::pbr::{build_directional_light_cascades, clear_directional_light_cascades, SimulationLightSystems};
use bevy::pbr::{
build_directional_light_cascades, clear_directional_light_cascades, SimulationLightSystems,
};
use bevy::reflect::std_traits::ReflectDefault;
use bevy::reflect::Reflect;
use bevy::render::camera::{
@@ -68,10 +72,8 @@ impl CameraProjection for XrProjection {
fn update(&mut self, _width: f32, _height: f32) {}
fn far(&self) -> f32 {
let far = self.projection_matrix.to_cols_array()[14]
/ (self.projection_matrix.to_cols_array()[10] + 1.0);
far
self.projection_matrix.to_cols_array()[14]
/ (self.projection_matrix.to_cols_array()[10] + 1.0)
}
// TODO calculate this properly
@@ -99,6 +101,10 @@ impl CameraProjection for XrProjection {
fn get_clip_from_view(&self) -> Mat4 {
self.projection_matrix
}
fn get_clip_from_view_for_sub(&self, _sub_view: &bevy::render::camera::SubCameraView) -> Mat4 {
panic!("sub view not supported for xr camera");
}
}
#[derive(Bundle)]

View File

@@ -1,15 +1,11 @@
use bevy::{
ecs::{component::Component, entity::Entity, world::Command},
hierarchy::BuildWorldChildren,
log::{error, warn},
math::bool,
prelude::{Bundle, Commands, Deref, DerefMut, Resource, SpatialBundle, With, World},
prelude::{BuildChildren, Bundle, Commands, Deref, DerefMut, Resource, Transform, Visibility, With, World},
};
use crate::{
session:: XrTrackingRoot,
spaces::XrSpaceLocationFlags,
};
use crate::{session::XrTrackingRoot, spaces::XrSpaceLocationFlags};
pub const HAND_JOINT_COUNT: usize = 26;
pub fn spawn_hand_bones<T: Bundle>(
@@ -20,7 +16,8 @@ pub fn spawn_hand_bones<T: Bundle>(
for bone in HandBone::get_all_bones().into_iter() {
bones[bone as usize] = cmds
.spawn((
SpatialBundle::default(),
Transform::default(),
Visibility::default(),
bone,
HandBoneRadius(0.0),
XrSpaceLocationFlags::default(),
@@ -205,9 +202,9 @@ impl<B: Bundle> Command for SpawnHandTracker<B> {
HandSide::Right => tracker.insert(LeftHand),
};
let tracker = tracker.id();
world.entity_mut(root).push_children(&[tracker]);
world.entity_mut(root).add_children(&[tracker]);
executor.0(world, tracker, self.side);
if let Some(mut tracker) = world.get_entity_mut(tracker) {
if let Ok(mut tracker) = world.get_entity_mut(tracker) {
tracker.insert(self.side);
tracker.insert(self.tracker_bundle);
}

View File

@@ -121,7 +121,7 @@ impl Plugin for XrSessionPlugin {
.add_systems(
XrFirst,
exits_session_on_app_exit
.run_if(on_event::<AppExit>())
.run_if(on_event::<AppExit>)
.run_if(session_created)
.in_set(XrHandleEvents::ExitEvents),
);
@@ -129,6 +129,8 @@ impl Plugin for XrSessionPlugin {
.resource_mut::<MainScheduleOrder>()
.labels
.insert(0, XrFirst.intern());
app.world_mut()
.spawn((Transform::default(), Visibility::default(), XrTrackingRoot));
if self.auto_handle {
app.add_systems(PreUpdate, auto_handle_session);
@@ -153,7 +155,7 @@ impl Plugin for XrSessionPlugin {
XrFirst,
exits_session_on_app_exit
.before(XrHandleEvents::ExitEvents)
.run_if(on_event::<AppExit>().and_then(session_running)),
.run_if(on_event::<AppExit>.and(session_running)),
);
let render_app = app.sub_app_mut(RenderApp);

View File

@@ -1,26 +1,4 @@
use bevy::{
math::{Quat, Vec3},
reflect::Reflect,
transform::components::Transform,
};
use bevy::math::Isometry3d;
#[derive(Clone, Copy, PartialEq, Reflect, Debug)]
pub struct XrPose {
pub translation: Vec3,
pub rotation: Quat,
}
impl Default for XrPose {
fn default() -> Self {
Self::IDENTITY
}
}
impl XrPose {
pub const IDENTITY: XrPose = XrPose {
translation: Vec3::ZERO,
rotation: Quat::IDENTITY,
};
pub const fn to_transform(self) -> Transform {
Transform::from_translation(self.translation).with_rotation(self.rotation)
}
}
#[deprecated = "Use Isometry3d instead"]
pub type XrPose = Isometry3d;