update to bevy 0.13. TODO: fix view weirdness and do a pass over most of xr_input to turn the modules into plugins

This commit is contained in:
Schmarni
2024-02-20 09:15:21 +01:00
parent a95462b91d
commit df71c7931d
16 changed files with 179 additions and 177 deletions

View File

@@ -17,12 +17,12 @@ members = ["examples/android", "examples/demo"]
[dependencies]
# anyhow = "1.0.75"
ash = "0.37.3"
bevy = "0.12"
bevy = "0.13"
futures-lite = "2.0.1"
mint = "0.5.9"
wgpu = "0.17.1"
wgpu-core = { version = "0.17.1", features = ["vulkan"] }
wgpu-hal = "0.17.1"
wgpu = "0.19"
wgpu-core = { version = "0.19", features = ["vulkan"] }
wgpu-hal = "0.19"
eyre = "0.6.11"
[target.'cfg(windows)'.dependencies]
@@ -46,7 +46,7 @@ ndk-context = "0.1"
jni = "0.20"
[dev-dependencies]
bevy = "0.12"
bevy = "0.13"
bevy_rapier3d = { git = "https://github.com/devil-ira/bevy_rapier", branch = "bevy-0.12" }
color-eyre = "0.6.2"
@@ -58,4 +58,4 @@ path = "examples/xr.rs"
debug = true
[patch.crates-io]
ndk = { git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }
# ndk = { git = "https://github.com/Schmarni-Dev/ndk.git", branch = "070" }

View File

@@ -13,7 +13,7 @@ crate-type = ["rlib", "cdylib"]
[dependencies]
bevy_oxr.path = "../.."
bevy = "0.12"
bevy = "0.13"
openxr = { git = "https://github.com/Ralith/openxrs", rev = "0177d2d", features = ["mint"] }
# [profile.release]

View File

@@ -17,7 +17,7 @@ use bevy_oxr::DefaultXrPlugins;
#[bevy_main]
fn main() {
let mut xr_extensions = XrExtensions::default();
xr_extensions.enable_fb_passthrough();
// xr_extensions.enable_fb_passthrough();
xr_extensions.enable_hand_tracking();
App::new()
.add_plugins(DefaultXrPlugins {
@@ -31,7 +31,7 @@ fn main() {
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
.add_plugins(HandInputDebugRenderer)
.add_plugins(bevy_oxr::passthrough::EnablePassthroughStartup)
// .add_plugins(bevy_oxr::passthrough::EnablePassthroughStartup)
.add_systems(Startup, setup)
.add_systems(
Update,
@@ -57,21 +57,21 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(Plane3d::new(Vec3::Y)),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::rgb(0.8, 0.0, 0.0).into()),
mesh: meshes.add(Mesh::from(Cuboid::from_size(Vec3::splat(0.1)))),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.0, 0.0))),
transform: Transform::from_xyz(0.0, 0.5, 1.0),
..default()
});
@@ -106,7 +106,7 @@ fn spawn_controllers_example(mut commands: Commands) {
// TODO: make this a vr button
fn toggle_passthrough(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
passthrough_state: Res<XrPassthroughState>,
mut resume: EventWriter<ResumePassthrough>,
mut pause: EventWriter<PausePassthrough>,
@@ -114,8 +114,12 @@ fn toggle_passthrough(
if keys.just_pressed(KeyCode::Space) {
match *passthrough_state {
XrPassthroughState::Unsupported => {}
XrPassthroughState::Running => pause.send_default(),
XrPassthroughState::Paused => resume.send_default(),
XrPassthroughState::Running => {
pause.send_default();
}
XrPassthroughState::Paused => {
resume.send_default();
}
}
}
}

View File

@@ -9,9 +9,10 @@ crate-type = ["rlib", "cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.12"
bevy = "0.13"
bevy_oxr.path = "../../"
bevy_rapier3d = { git = "https://github.com/devil-ira/bevy_rapier", branch = "bevy-0.12" }
# bevy_rapier3d = { git = "https://github.com/devil-ira/bevy_rapier", branch = "bevy-0.12" }
bevy_rapier3d = "0.25"
color-eyre = "0.6.2"

View File

@@ -1,19 +1,13 @@
use std::{f32::consts::PI, ops::Mul, time::Duration};
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
ecs::schedule::ScheduleLabel,
input::{keyboard::KeyCode, Input},
log::info,
prelude::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, ecs::schedule::ScheduleLabel, input::{keyboard::KeyCode, ButtonInput}, log::info, math::primitives::{Capsule3d, Cuboid}, prelude::{
bevy_main, default, shape, App, Assets, Color, Commands, Component, Entity, Event,
EventReader, EventWriter, FixedUpdate, Gizmos, GlobalTransform, IntoSystemConfigs,
IntoSystemSetConfigs, Mesh, PbrBundle, PostUpdate, Quat, Query, Res, ResMut, Resource,
Schedule, SpatialBundle, StandardMaterial, Startup, Transform, Update, Vec3, Vec3Swizzles,
With, Without, World,
},
time::{Fixed, Time, Timer, TimerMode},
transform::TransformSystem,
}, render::mesh::Meshable, time::{Fixed, Time, Timer, TimerMode}, transform::TransformSystem
};
use bevy_oxr::{
graphics::{extensions::XrExtensions, XrAppInfo, XrPreferdBlendMode},
@@ -226,12 +220,8 @@ fn spawn_capsule(
) {
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Capsule {
radius: 0.033,
depth: 0.115,
..default()
})),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(Capsule3d::new(0.033, 0.115).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 2.0, 0.0),
..default()
},
@@ -376,7 +366,7 @@ fn update_physics_hands(
&Hand,
&mut Velocity,
)>,
hand_query: Query<(&Transform, &HandBone, &Hand, Without<PhysicsHandBone>)>,
hand_query: Query<(&Transform, &HandBone, &Hand), Without<PhysicsHandBone>>,
time: Res<Time>,
mut gizmos: Gizmos,
) {
@@ -586,8 +576,8 @@ fn cube_spawner(
// cube
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 1.0, 0.0),
..default()
},
@@ -660,7 +650,7 @@ pub struct GhostTimers {
pub fn handle_ghost_hand_events(
mut events: EventReader<GhostHandEvent>,
mut bones: Query<(&Hand, &mut CollisionGroups, With<PhysicsHandBone>)>,
mut bones: Query<(&Hand, &mut CollisionGroups), With<PhysicsHandBone>>,
) {
for event in events.read() {
// info!(
@@ -708,20 +698,19 @@ pub struct Grabbable;
pub fn update_grabbables(
mut events: EventReader<InteractionEvent>,
mut grabbable_query: Query<(
Entity,
&mut Transform,
With<Grabbable>,
Without<XRDirectInteractor>,
Option<&mut RigidBody>,
)>,
mut interactor_query: Query<(
&GlobalTransform,
&XRInteractorState,
&mut XRSelection,
&Hand,
mut grabbable_query: Query<
(Entity, &mut Transform, Option<&mut RigidBody>),
(Without<XRDirectInteractor>, With<Grabbable>),
>,
mut interactor_query: Query<
(
&GlobalTransform,
&XRInteractorState,
&mut XRSelection,
&Hand,
),
Without<Grabbable>,
)>,
>,
mut writer: EventWriter<GhostHandEvent>,
mut timers: ResMut<GhostTimers>,
) {
@@ -737,7 +726,7 @@ pub fn update_grabbables(
match *interactor_transform.2 {
XRSelection::Empty => {
match interactor_transform.1 {
XRInteractorState::Idle => match grabbable_transform.4 {
XRInteractorState::Idle => match grabbable_transform.2 {
Some(mut thing) => {
*thing = RigidBody::Dynamic;
*interactor_transform.2 = XRSelection::Empty;
@@ -746,7 +735,7 @@ pub fn update_grabbables(
},
XRInteractorState::Selecting => {
// info!("its a direct interactor?");
match grabbable_transform.4 {
match grabbable_transform.2 {
Some(mut thing) => {
*thing = RigidBody::KinematicPositionBased;
*interactor_transform.2 =

View File

@@ -1,10 +1,7 @@
use bevy::{
prelude::{
shape, Assets, Camera3dBundle, Color, Commands, Mesh, PbrBundle, PointLight,
PointLightBundle, ResMut, SpatialBundle, StandardMaterial, Transform, Vec3,
},
transform::TransformBundle,
utils::default,
math::primitives::{Cuboid, Plane3d}, prelude::{
Assets, Camera3dBundle, Color, Commands, Mesh, PbrBundle, ResMut, StandardMaterial, Transform, Vec3,
}, render::mesh::Meshable, utils::default
};
use bevy_oxr::xr_input::interactions::{Touched, XRInteractable, XRInteractableState};
use bevy_rapier3d::{
@@ -29,8 +26,8 @@ pub fn setup_scene(
// plane
commands.spawn((
PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(Plane3d::new(Vec3::Y).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
transform: Transform::from_xyz(0.0, ground_height, 0.0),
..default()
},
@@ -41,8 +38,8 @@ pub fn setup_scene(
// cube
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1))),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 1.0, 0.0),
..default()
},

View File

@@ -1,5 +1,6 @@
use bevy::diagnostic::LogDiagnosticsPlugin;
use bevy::prelude::*;
use bevy::render::render_asset::RenderAssetUsages;
use bevy::transform::components::Transform;
use bevy_oxr::graphics::XrAppInfo;
use bevy_oxr::resources::XrViews;
@@ -66,6 +67,7 @@ fn uv_debug_texture() -> Image {
TextureDimension::D2,
&texture_data,
TextureFormat::Rgba8UnormSrgb,
RenderAssetUsages::RENDER_WORLD,
)
}
@@ -81,13 +83,7 @@ fn setup(
commands.spawn((
PbrBundle {
mesh: meshes.add(
shape::UVSphere {
radius,
sectors: 10,
stacks: 10,
}
.try_into()
.unwrap(),
Sphere::new(radius)
),
material: materials.add(StandardMaterial {
base_color_texture: Some(images.add(uv_debug_texture())),
@@ -100,8 +96,8 @@ fn setup(
));
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
@@ -186,7 +182,7 @@ fn pull_to_ground(
root.translation += diff * adjustment_rate;
// Rotate player to be upright on sphere
let angle_diff = Quat::from_rotation_arc(root.up(), up);
let angle_diff = Quat::from_rotation_arc(*root.up(), up);
let point = root.translation + offset;
root.rotate_around(point, Quat::IDENTITY.slerp(angle_diff, adjustment_rate));
}

View File

@@ -6,6 +6,7 @@ use bevy_oxr::graphics::XrAppInfo;
use bevy_oxr::input::XrInput;
use bevy_oxr::resources::{XrFrameState, XrSession};
use bevy_oxr::xr_init::xr_only;
use bevy_oxr::xr_input::actions::XrActionSets;
use bevy_oxr::xr_input::hands::common::HandInputDebugRenderer;
use bevy_oxr::xr_input::interactions::{
@@ -36,21 +37,21 @@ fn main() {
.add_plugins(LogDiagnosticsPlugin::default())
.add_plugins(FrameTimeDiagnosticsPlugin)
.add_systems(Startup, setup)
.add_systems(Update, proto_locomotion)
.add_systems(Update, proto_locomotion.run_if(xr_only()))
.insert_resource(PrototypeLocomotionConfig::default())
.add_systems(Startup, spawn_controllers_example)
.add_plugins(HandInputDebugRenderer)
.add_systems(
Update,
draw_interaction_gizmos.after(update_interactable_states),
draw_interaction_gizmos.after(update_interactable_states).run_if(xr_only()),
)
.add_systems(Update, draw_socket_gizmos.after(update_interactable_states))
.add_systems(Update, interactions.before(update_interactable_states))
.add_systems(Update, draw_socket_gizmos.after(update_interactable_states).run_if(xr_only()))
.add_systems(Update, interactions.before(update_interactable_states).run_if(xr_only()))
.add_systems(
Update,
socket_interactions.before(update_interactable_states),
)
.add_systems(Update, prototype_interaction_input)
.add_systems(Update, prototype_interaction_input.run_if(xr_only()))
.add_systems(Update, update_interactable_states)
.add_systems(Update, update_grabbables.after(update_interactable_states))
.add_event::<InteractionEvent>()
@@ -65,14 +66,14 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(Plane3d::new(Vec3::Y).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
@@ -191,8 +192,8 @@ pub struct Grabbable;
pub fn update_grabbables(
mut events: EventReader<InteractionEvent>,
mut grabbable_query: Query<(&mut Transform, With<Grabbable>, Without<XRDirectInteractor>)>,
interactor_query: Query<(&GlobalTransform, &XRInteractorState, Without<Grabbable>)>,
mut grabbable_query: Query<&mut Transform, (With<Grabbable>, Without<XRDirectInteractor>)>,
interactor_query: Query<(&GlobalTransform, &XRInteractorState), Without<Grabbable>>,
) {
//so basically the idea is to try all the events?
for event in events.read() {
@@ -207,7 +208,7 @@ pub fn update_grabbables(
XRInteractorState::Idle => (),
XRInteractorState::Selecting => {
// info!("its a direct interactor?");
*grabbable_transform.0 = interactor_transform.0.compute_transform();
*grabbable_transform = interactor_transform.0.compute_transform();
}
}
}

View File

@@ -1,6 +1,6 @@
use std::ffi::{c_void, CString};
use std::sync::atomic::AtomicBool;
use std::sync::Mutex;
use std::sync::{Arc, Mutex};
// use anyhow::Context;
use ash::vk::{self, Handle};
@@ -130,9 +130,8 @@ pub fn initialize_xr_instance(
}
let vk_entry = unsafe { ash::Entry::load() }?;
let flags = wgpu_hal::InstanceFlags::empty();
let extensions =
<V as Api>::Instance::required_extensions(&vk_entry, vk_target_version, flags)?;
let flags = wgpu::InstanceFlags::from_build_config();
let extensions = <V as Api>::Instance::desired_extensions(&vk_entry, vk_target_version, flags)?;
let device_extensions = vec![
ash::extensions::khr::Swapchain::name(),
ash::extensions::khr::DrawIndirectCount::name(),
@@ -282,8 +281,8 @@ pub fn initialize_xr_instance(
wgpu_open_device,
&wgpu::DeviceDescriptor {
label: None,
features: wgpu_features,
limits: wgpu::Limits {
required_features: wgpu_features,
required_limits: wgpu::Limits {
max_bind_groups: 8,
max_storage_buffer_binding_size: wgpu_adapter
.limits()
@@ -358,7 +357,7 @@ pub fn start_xr_session(
// SAFETY: Plugins should be set up on the main thread.
let handle = wrapper.get_handle();
wgpu_instance
.create_surface(&handle)
.create_surface(handle)
.expect("Failed to create wgpu surface")
});
let swapchain_format = surface

View File

@@ -94,6 +94,8 @@ impl Plugin for OpenXrPlugin {
render_adapter,
render_instance,
),
// Expose this? if yes we also have to set this in the non xr case
synchronous_pipeline_compilation: true,
});
app.insert_resource(XrStatus::Disabled);
app.world.send_event(StartXrSession);

View File

@@ -1,5 +1,6 @@
use bevy::ecs::schedule::IntoSystemConfigs;
use bevy::log::{debug, info};
use bevy::math::primitives::Direction3d;
use bevy::prelude::{
Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3, With,
Without,
@@ -104,7 +105,7 @@ pub fn draw_gizmos(
y: 0.01,
z: 0.0,
},
Vec3::Y,
Direction3d::Y,
0.2,
Color::RED,
);
@@ -168,7 +169,7 @@ fn draw_hand_gizmo(
//draw face
gizmos.circle(
face_translation_vec3,
face_quat_normal,
Direction3d::new_unchecked(face_quat_normal),
0.04,
Color::YELLOW_GREEN,
);
@@ -185,7 +186,7 @@ fn draw_hand_gizmo(
let b_offset_quat = face_quat;
let b_translation_vec3 =
face_translation_vec3 + b_offset_quat.mul_vec3(Vec3::new(0.025, -0.01, 0.0));
gizmos.circle(b_translation_vec3, face_quat_normal, 0.0075, b_color);
gizmos.circle(b_translation_vec3, Direction3d::new_unchecked(face_quat_normal), 0.0075, b_color);
//button a
let mut a_color = off_color;
@@ -199,7 +200,7 @@ fn draw_hand_gizmo(
let a_offset_quat = face_quat;
let a_translation_vec3 =
face_translation_vec3 + a_offset_quat.mul_vec3(Vec3::new(0.025, 0.01, 0.0));
gizmos.circle(a_translation_vec3, face_quat_normal, 0.0075, a_color);
gizmos.circle(a_translation_vec3, Direction3d::new_unchecked(face_quat_normal), 0.0075, a_color);
//joystick
let joystick_offset_quat = face_quat;
@@ -211,7 +212,7 @@ fn draw_hand_gizmo(
}
//base
gizmos.circle(joystick_base_vec, face_quat_normal, 0.014, joystick_color);
gizmos.circle(joystick_base_vec, Direction3d::new_unchecked(face_quat_normal), 0.014, joystick_color);
let stick = controller.thumbstick(Hand::Left);
let input = Vec3::new(stick.x, -stick.y, 0.0);
@@ -219,7 +220,7 @@ fn draw_hand_gizmo(
+ joystick_offset_quat.mul_vec3(Vec3::new(-0.02, 0.0, -0.01))
+ joystick_offset_quat.mul_vec3(input * 0.01);
//top
gizmos.circle(joystick_top_vec, face_quat_normal, 0.005, joystick_color);
gizmos.circle(joystick_top_vec, Direction3d::new_unchecked(face_quat_normal), 0.005, joystick_color);
//trigger
let trigger_state = controller.trigger(Hand::Left);
@@ -277,7 +278,7 @@ fn draw_hand_gizmo(
//draw face
gizmos.circle(
face_translation_vec3,
face_quat_normal,
Direction3d::new_unchecked(face_quat_normal),
0.04,
Color::YELLOW_GREEN,
);
@@ -294,7 +295,7 @@ fn draw_hand_gizmo(
let b_offset_quat = face_quat;
let b_translation_vec3 =
face_translation_vec3 + b_offset_quat.mul_vec3(Vec3::new(-0.025, -0.01, 0.0));
gizmos.circle(b_translation_vec3, face_quat_normal, 0.0075, b_color);
gizmos.circle(b_translation_vec3, Direction3d::new_unchecked(face_quat_normal), 0.0075, b_color);
//button a
let mut a_color = off_color;
@@ -308,7 +309,7 @@ fn draw_hand_gizmo(
let a_offset_quat = face_quat;
let a_translation_vec3 =
face_translation_vec3 + a_offset_quat.mul_vec3(Vec3::new(-0.025, 0.01, 0.0));
gizmos.circle(a_translation_vec3, face_quat_normal, 0.0075, a_color);
gizmos.circle(a_translation_vec3, Direction3d::new_unchecked(face_quat_normal), 0.0075, a_color);
//joystick time
let joystick_offset_quat = face_quat;
@@ -320,7 +321,7 @@ fn draw_hand_gizmo(
}
//base
gizmos.circle(joystick_base_vec, face_quat_normal, 0.014, joystick_color);
gizmos.circle(joystick_base_vec, Direction3d::new_unchecked(face_quat_normal), 0.014, joystick_color);
let stick = controller.thumbstick(Hand::Right);
let input = Vec3::new(stick.x, -stick.y, 0.0);
@@ -328,7 +329,7 @@ fn draw_hand_gizmo(
+ joystick_offset_quat.mul_vec3(Vec3::new(0.02, 0.0, -0.01))
+ joystick_offset_quat.mul_vec3(input * 0.01);
//top
gizmos.circle(joystick_top_vec, face_quat_normal, 0.005, joystick_color);
gizmos.circle(joystick_top_vec, Direction3d::new_unchecked(face_quat_normal), 0.005, joystick_color);
//trigger
let trigger_state = controller.trigger(Hand::Right);

View File

@@ -1,6 +1,6 @@
use std::f32::consts::PI;
use bevy::log::info;
use bevy::log::{info, warn};
use bevy::prelude::{
Color, Component, Entity, Event, EventReader, EventWriter, Gizmos, GlobalTransform, Quat,
Query, Transform, Vec3, With, Without,
@@ -93,9 +93,12 @@ pub fn draw_interaction_gizmos(
),
Without<XRInteractable>,
>,
tracking_root_query: Query<(&mut Transform, With<OpenXRTrackingRoot>)>,
tracking_root_query: Query<&mut Transform, With<OpenXRTrackingRoot>>,
) {
let root = tracking_root_query.get_single().unwrap().0;
let Ok(root) = tracking_root_query.get_single() else {
warn!("no or more than one tracking root");
return;
};
for (global_transform, interactable_state) in interactable_query.iter() {
let transform = global_transform.compute_transform();
let color = match interactable_state {
@@ -137,7 +140,7 @@ pub fn draw_interaction_gizmos(
};
gizmos.ray(
root.translation + root.rotation.mul_vec3(aim.0.translation),
root.rotation.mul_vec3(aim.0.forward()),
root.rotation.mul_vec3(*aim.0.forward()),
color,
);
}
@@ -229,7 +232,7 @@ pub fn interactions(
),
Without<XRInteractable>,
>,
tracking_root_query: Query<(&mut Transform, With<OpenXRTrackingRoot>)>,
tracking_root_query: Query<&mut Transform, With<OpenXRTrackingRoot>>,
mut writer: EventWriter<InteractionEvent>,
) {
for (xr_interactable_global_transform, interactable_entity) in interactable_query.iter() {
@@ -280,12 +283,12 @@ pub fn interactions(
let center = sphere_transform.translation;
let radius: f32 = 0.1;
//I hate this but the aim pose needs the root for now
let root = tracking_root_query.get_single().unwrap().0;
let root = tracking_root_query.get_single().unwrap();
match aim {
Some(aim) => {
let ray_origin =
root.translation + root.rotation.mul_vec3(aim.0.translation);
let ray_dir = root.rotation.mul_vec3(aim.0.forward());
let ray_dir = root.rotation.mul_vec3(*aim.0.forward());
if ray_sphere_intersection(
center,

View File

@@ -37,7 +37,7 @@ use self::trackers::{
adopt_open_xr_trackers, update_open_xr_controllers, OpenXRLeftEye, OpenXRRightEye,
OpenXRTrackingRoot,
};
use self::xr_camera::{GlobalTransformExtract, TransformExtract, XrCamera};
use self::xr_camera::{/* GlobalTransformExtract, TransformExtract, */ XrCamera};
#[derive(Copy, Clone)]
pub struct OpenXrInput {

View File

@@ -59,11 +59,10 @@ impl Default for PrototypeLocomotionConfig {
pub fn proto_locomotion(
time: Res<Time>,
mut tracking_root_query: Query<(&mut Transform, With<OpenXRTrackingRoot>)>,
mut tracking_root_query: Query<&mut Transform, With<OpenXRTrackingRoot>>,
oculus_controller: Res<OculusController>,
frame_state: Res<XrFrameState>,
xr_input: Res<XrInput>,
instance: Res<XrInstance>,
session: Res<XrSession>,
views: ResMut<XrViews>,
mut gizmos: Gizmos,
@@ -84,7 +83,7 @@ pub fn proto_locomotion(
Ok(mut position) => {
//get the stick input and do some maths
let stick = controller.thumbstick(Hand::Left);
let input = stick.x * position.0.right() + stick.y * position.0.forward();
let input = stick.x * *position.right() + stick.y * *position.forward();
let reference_quat;
match config.locomotion_type {
LocomotionType::Head => {
@@ -102,10 +101,9 @@ pub fn proto_locomotion(
}
}
let (yaw, _pitch, _roll) = reference_quat.to_euler(EulerRot::YXZ);
let reference_quat = Quat::from_axis_angle(position.0.up(), yaw);
let reference_quat = Quat::from_axis_angle(*position.up(), yaw);
let locomotion_vec = reference_quat.mul_vec3(input);
position.0.translation +=
locomotion_vec * config.locomotion_speed * time.delta_seconds();
position.translation += locomotion_vec * config.locomotion_speed * time.delta_seconds();
//now time for rotation
@@ -118,7 +116,7 @@ pub fn proto_locomotion(
return;
}
let smoth_rot = Quat::from_axis_angle(
position.0.up(),
*position.up(),
rot_input * config.smooth_rotation_speed * time.delta_seconds(),
);
//apply rotation
@@ -127,10 +125,10 @@ pub fn proto_locomotion(
Some(view) => {
let mut hmd_translation = view.pose.position.to_vec3();
hmd_translation.y = 0.0;
let local = position.0.translation;
let global = position.0.rotation.mul_vec3(hmd_translation) + local;
gizmos.circle(global, position.0.up(), 0.1, Color::GREEN);
position.0.rotate_around(global, smoth_rot);
let local = position.translation;
let global = position.rotation.mul_vec3(hmd_translation) + local;
gizmos.circle(global, position.up(), 0.1, Color::GREEN);
position.rotate_around(global, smoth_rot);
}
None => return,
}
@@ -151,7 +149,7 @@ pub fn proto_locomotion(
false => -1.0,
};
let smoth_rot =
Quat::from_axis_angle(position.0.up(), config.snap_angle * dir);
Quat::from_axis_angle(*position.up(), config.snap_angle * dir);
//apply rotation
let v = views;
let views = v.first();
@@ -159,10 +157,10 @@ pub fn proto_locomotion(
Some(view) => {
let mut hmd_translation = view.pose.position.to_vec3();
hmd_translation.y = 0.0;
let local = position.0.translation;
let global = position.0.rotation.mul_vec3(hmd_translation) + local;
gizmos.circle(global, position.0.up(), 0.1, Color::GREEN);
position.0.rotate_around(global, smoth_rot);
let local = position.translation;
let global = position.rotation.mul_vec3(hmd_translation) + local;
gizmos.circle(global, position.up(), 0.1, Color::GREEN);
position.rotate_around(global, smoth_rot);
}
None => return,
}

View File

@@ -1,5 +1,6 @@
use bevy::hierarchy::Parent;
use bevy::log::{debug, info};
use bevy::math::Quat;
use bevy::prelude::{
Added, BuildChildren, Commands, Component, Entity, Query, Res, Transform, Vec3, With, Without,
};
@@ -48,20 +49,23 @@ pub fn adopt_open_xr_trackers(
}
}
pub fn verify_quat(mut quat: Quat) -> Quat {
if quat.length() == 0.0 || !quat.is_finite() {
quat = Quat::IDENTITY;
}
quat.normalize()
}
pub fn update_open_xr_controllers(
oculus_controller: Res<OculusController>,
mut left_controller_query: Query<(
&mut Transform,
Option<&mut AimPose>,
With<OpenXRLeftController>,
Without<OpenXRRightController>,
)>,
mut right_controller_query: Query<(
&mut Transform,
Option<&mut AimPose>,
With<OpenXRRightController>,
Without<OpenXRLeftController>,
)>,
mut left_controller_query: Query<
(&mut Transform, Option<&mut AimPose>),
(With<OpenXRLeftController>, Without<OpenXRRightController>),
>,
mut right_controller_query: Query<
(&mut Transform, Option<&mut AimPose>),
(With<OpenXRRightController>, Without<OpenXRLeftController>),
>,
frame_state: Res<XrFrameState>,
xr_input: Res<XrInput>,
session: Res<XrSession>,
@@ -81,7 +85,7 @@ pub fn update_open_xr_controllers(
Some(mut pose) => {
*pose = AimPose(Transform {
translation: left_aim_space.0.pose.position.to_vec3(),
rotation: left_aim_space.0.pose.orientation.to_quat(),
rotation: verify_quat(left_aim_space.0.pose.orientation.to_quat()),
scale: Vec3::splat(1.0),
});
}
@@ -99,7 +103,7 @@ pub fn update_open_xr_controllers(
let left_rotataion = left_controller_query.get_single_mut();
match left_rotataion {
Ok(mut left_entity) => {
left_entity.0.rotation = left_grip_space.0.pose.orientation.to_quat()
left_entity.0.rotation = verify_quat(left_grip_space.0.pose.orientation.to_quat())
}
Err(_) => (),
}
@@ -114,7 +118,7 @@ pub fn update_open_xr_controllers(
Some(mut pose) => {
*pose = AimPose(Transform {
translation: right_aim_space.0.pose.position.to_vec3(),
rotation: right_aim_space.0.pose.orientation.to_quat(),
rotation: verify_quat(right_aim_space.0.pose.orientation.to_quat()),
scale: Vec3::splat(1.0),
});
}
@@ -132,7 +136,7 @@ pub fn update_open_xr_controllers(
let right_rotataion = right_controller_query.get_single_mut();
match right_rotataion {
Ok(mut right_entity) => {
right_entity.0.rotation = right_grip_space.0.pose.orientation.to_quat()
right_entity.0.rotation = verify_quat(right_grip_space.0.pose.orientation.to_quat())
}
Err(_) => (),
}

View File

@@ -1,22 +1,23 @@
use crate::xr_init::{xr_only, XrCleanup, XrSetup};
use crate::xr_input::{QuatConv, Vec3Conv};
use crate::{locate_views, xr_wait_frame, LEFT_XR_TEXTURE_HANDLE, RIGHT_XR_TEXTURE_HANDLE};
use bevy::core_pipeline::core_3d::graph::Core3d;
use bevy::core_pipeline::tonemapping::{DebandDither, Tonemapping};
use bevy::ecs::system::lifetimeless::Read;
use bevy::math::Vec3A;
use bevy::prelude::*;
use bevy::render::camera::{
CameraProjection, CameraProjectionPlugin, CameraRenderGraph, RenderTarget,
CameraMainTextureUsages, CameraProjection, CameraProjectionPlugin, CameraRenderGraph, RenderTarget
};
use bevy::render::extract_component::{ExtractComponent, ExtractComponentPlugin};
use bevy::render::primitives::Frustum;
use bevy::render::view::{
update_frusta, ColorGrading, ExtractedView, VisibilitySystems, VisibleEntities,
update_frusta, ColorGrading, VisibilitySystems, VisibleEntities,
};
use bevy::transform::TransformSystem;
use openxr::Fovf;
use wgpu::TextureUsages;
use super::trackers::{OpenXRLeftEye, OpenXRRightEye, OpenXRTracker, OpenXRTrackingRoot};
use super::trackers::{OpenXRLeftEye, OpenXRRightEye, OpenXRTracker};
pub struct XrCameraPlugin;
@@ -100,40 +101,41 @@ pub struct XrCameraBundle {
pub tonemapping: Tonemapping,
pub dither: DebandDither,
pub color_grading: ColorGrading,
pub main_texture_usages: CameraMainTextureUsages,
pub xr_camera_type: XrCamera,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Component, ExtractComponent)]
pub struct XrCamera(Eye);
#[derive(Component)]
pub(super) struct TransformExtract;
impl ExtractComponent for TransformExtract {
type Query = Read<Transform>;
type Filter = ();
type Out = Transform;
fn extract_component(item: bevy::ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
Some(*item)
}
}
#[derive(Component)]
pub(super) struct GlobalTransformExtract;
impl ExtractComponent for GlobalTransformExtract {
type Query = Read<GlobalTransform>;
type Filter = ();
type Out = GlobalTransform;
fn extract_component(item: bevy::ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
Some(*item)
}
}
// #[derive(Component)]
// pub(super) struct TransformExtract;
//
// impl ExtractComponent for TransformExtract {
// type Query = Read<Transform>;
//
// type Filter = ();
//
// type Out = Transform;
//
// fn extract_component(item: bevy::ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
// Some(*item)
// }
// }
//
// #[derive(Component)]
// pub(super) struct GlobalTransformExtract;
//
// impl ExtractComponent for GlobalTransformExtract {
// type Query = Read<GlobalTransform>;
//
// type Filter = ();
//
// type Out = GlobalTransform;
//
// fn extract_component(item: bevy::ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
// Some(*item)
// }
// }
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum Eye {
@@ -153,7 +155,7 @@ impl XrCameraBundle {
viewport: None,
..default()
},
camera_render_graph: CameraRenderGraph::new(bevy::core_pipeline::core_3d::graph::NAME),
camera_render_graph: CameraRenderGraph::new(Core3d),
xr_projection: Default::default(),
visible_entities: Default::default(),
frustum: Default::default(),
@@ -164,6 +166,11 @@ impl XrCameraBundle {
dither: DebandDither::Enabled,
color_grading: Default::default(),
xr_camera_type: XrCamera(eye),
main_texture_usages: CameraMainTextureUsages(
TextureUsages::RENDER_ATTACHMENT
| TextureUsages::TEXTURE_BINDING
| TextureUsages::COPY_SRC,
),
}
}
}