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:
12
Cargo.toml
12
Cargo.toml
@@ -17,12 +17,12 @@ members = ["examples/android", "examples/demo"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
# anyhow = "1.0.75"
|
# anyhow = "1.0.75"
|
||||||
ash = "0.37.3"
|
ash = "0.37.3"
|
||||||
bevy = "0.12"
|
bevy = "0.13"
|
||||||
futures-lite = "2.0.1"
|
futures-lite = "2.0.1"
|
||||||
mint = "0.5.9"
|
mint = "0.5.9"
|
||||||
wgpu = "0.17.1"
|
wgpu = "0.19"
|
||||||
wgpu-core = { version = "0.17.1", features = ["vulkan"] }
|
wgpu-core = { version = "0.19", features = ["vulkan"] }
|
||||||
wgpu-hal = "0.17.1"
|
wgpu-hal = "0.19"
|
||||||
eyre = "0.6.11"
|
eyre = "0.6.11"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
@@ -46,7 +46,7 @@ ndk-context = "0.1"
|
|||||||
jni = "0.20"
|
jni = "0.20"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bevy = "0.12"
|
bevy = "0.13"
|
||||||
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" }
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
|
|
||||||
@@ -58,4 +58,4 @@ path = "examples/xr.rs"
|
|||||||
debug = true
|
debug = true
|
||||||
|
|
||||||
[patch.crates-io]
|
[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" }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ crate-type = ["rlib", "cdylib"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy_oxr.path = "../.."
|
bevy_oxr.path = "../.."
|
||||||
bevy = "0.12"
|
bevy = "0.13"
|
||||||
openxr = { git = "https://github.com/Ralith/openxrs", rev = "0177d2d", features = ["mint"] }
|
openxr = { git = "https://github.com/Ralith/openxrs", rev = "0177d2d", features = ["mint"] }
|
||||||
|
|
||||||
# [profile.release]
|
# [profile.release]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use bevy_oxr::DefaultXrPlugins;
|
|||||||
#[bevy_main]
|
#[bevy_main]
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut xr_extensions = XrExtensions::default();
|
let mut xr_extensions = XrExtensions::default();
|
||||||
xr_extensions.enable_fb_passthrough();
|
// xr_extensions.enable_fb_passthrough();
|
||||||
xr_extensions.enable_hand_tracking();
|
xr_extensions.enable_hand_tracking();
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultXrPlugins {
|
.add_plugins(DefaultXrPlugins {
|
||||||
@@ -31,7 +31,7 @@ fn main() {
|
|||||||
.add_plugins(LogDiagnosticsPlugin::default())
|
.add_plugins(LogDiagnosticsPlugin::default())
|
||||||
.add_plugins(FrameTimeDiagnosticsPlugin)
|
.add_plugins(FrameTimeDiagnosticsPlugin)
|
||||||
.add_plugins(HandInputDebugRenderer)
|
.add_plugins(HandInputDebugRenderer)
|
||||||
.add_plugins(bevy_oxr::passthrough::EnablePassthroughStartup)
|
// .add_plugins(bevy_oxr::passthrough::EnablePassthroughStartup)
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
@@ -57,21 +57,21 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
// plane
|
// plane
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
|
mesh: meshes.add(Plane3d::new(Vec3::Y)),
|
||||||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// cube
|
// cube
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
|
||||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// cube
|
// cube
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
mesh: meshes.add(Mesh::from(Cuboid::from_size(Vec3::splat(0.1)))),
|
||||||
material: materials.add(Color::rgb(0.8, 0.0, 0.0).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.0, 0.0))),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 1.0),
|
transform: Transform::from_xyz(0.0, 0.5, 1.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
@@ -106,7 +106,7 @@ fn spawn_controllers_example(mut commands: Commands) {
|
|||||||
|
|
||||||
// TODO: make this a vr button
|
// TODO: make this a vr button
|
||||||
fn toggle_passthrough(
|
fn toggle_passthrough(
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<ButtonInput<KeyCode>>,
|
||||||
passthrough_state: Res<XrPassthroughState>,
|
passthrough_state: Res<XrPassthroughState>,
|
||||||
mut resume: EventWriter<ResumePassthrough>,
|
mut resume: EventWriter<ResumePassthrough>,
|
||||||
mut pause: EventWriter<PausePassthrough>,
|
mut pause: EventWriter<PausePassthrough>,
|
||||||
@@ -114,8 +114,12 @@ fn toggle_passthrough(
|
|||||||
if keys.just_pressed(KeyCode::Space) {
|
if keys.just_pressed(KeyCode::Space) {
|
||||||
match *passthrough_state {
|
match *passthrough_state {
|
||||||
XrPassthroughState::Unsupported => {}
|
XrPassthroughState::Unsupported => {}
|
||||||
XrPassthroughState::Running => pause.send_default(),
|
XrPassthroughState::Running => {
|
||||||
XrPassthroughState::Paused => resume.send_default(),
|
pause.send_default();
|
||||||
|
}
|
||||||
|
XrPassthroughState::Paused => {
|
||||||
|
resume.send_default();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ crate-type = ["rlib", "cdylib"]
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.12"
|
bevy = "0.13"
|
||||||
bevy_oxr.path = "../../"
|
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"
|
color-eyre = "0.6.2"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
use std::{f32::consts::PI, ops::Mul, time::Duration};
|
use std::{f32::consts::PI, ops::Mul, time::Duration};
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, ecs::schedule::ScheduleLabel, input::{keyboard::KeyCode, ButtonInput}, log::info, math::primitives::{Capsule3d, Cuboid}, prelude::{
|
||||||
ecs::schedule::ScheduleLabel,
|
|
||||||
input::{keyboard::KeyCode, Input},
|
|
||||||
log::info,
|
|
||||||
prelude::{
|
|
||||||
bevy_main, default, shape, App, Assets, Color, Commands, Component, Entity, Event,
|
bevy_main, default, shape, App, Assets, Color, Commands, Component, Entity, Event,
|
||||||
EventReader, EventWriter, FixedUpdate, Gizmos, GlobalTransform, IntoSystemConfigs,
|
EventReader, EventWriter, FixedUpdate, Gizmos, GlobalTransform, IntoSystemConfigs,
|
||||||
IntoSystemSetConfigs, Mesh, PbrBundle, PostUpdate, Quat, Query, Res, ResMut, Resource,
|
IntoSystemSetConfigs, Mesh, PbrBundle, PostUpdate, Quat, Query, Res, ResMut, Resource,
|
||||||
Schedule, SpatialBundle, StandardMaterial, Startup, Transform, Update, Vec3, Vec3Swizzles,
|
Schedule, SpatialBundle, StandardMaterial, Startup, Transform, Update, Vec3, Vec3Swizzles,
|
||||||
With, Without, World,
|
With, Without, World,
|
||||||
},
|
}, render::mesh::Meshable, time::{Fixed, Time, Timer, TimerMode}, transform::TransformSystem
|
||||||
time::{Fixed, Time, Timer, TimerMode},
|
|
||||||
transform::TransformSystem,
|
|
||||||
};
|
};
|
||||||
use bevy_oxr::{
|
use bevy_oxr::{
|
||||||
graphics::{extensions::XrExtensions, XrAppInfo, XrPreferdBlendMode},
|
graphics::{extensions::XrExtensions, XrAppInfo, XrPreferdBlendMode},
|
||||||
@@ -226,12 +220,8 @@ fn spawn_capsule(
|
|||||||
) {
|
) {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Capsule {
|
mesh: meshes.add(Capsule3d::new(0.033, 0.115).mesh()),
|
||||||
radius: 0.033,
|
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
|
||||||
depth: 0.115,
|
|
||||||
..default()
|
|
||||||
})),
|
|
||||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
|
||||||
transform: Transform::from_xyz(0.0, 2.0, 0.0),
|
transform: Transform::from_xyz(0.0, 2.0, 0.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
@@ -376,7 +366,7 @@ fn update_physics_hands(
|
|||||||
&Hand,
|
&Hand,
|
||||||
&mut Velocity,
|
&mut Velocity,
|
||||||
)>,
|
)>,
|
||||||
hand_query: Query<(&Transform, &HandBone, &Hand, Without<PhysicsHandBone>)>,
|
hand_query: Query<(&Transform, &HandBone, &Hand), Without<PhysicsHandBone>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut gizmos: Gizmos,
|
mut gizmos: Gizmos,
|
||||||
) {
|
) {
|
||||||
@@ -586,8 +576,8 @@ fn cube_spawner(
|
|||||||
// cube
|
// cube
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
|
||||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
|
||||||
transform: Transform::from_xyz(0.0, 1.0, 0.0),
|
transform: Transform::from_xyz(0.0, 1.0, 0.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
@@ -660,7 +650,7 @@ pub struct GhostTimers {
|
|||||||
|
|
||||||
pub fn handle_ghost_hand_events(
|
pub fn handle_ghost_hand_events(
|
||||||
mut events: EventReader<GhostHandEvent>,
|
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() {
|
for event in events.read() {
|
||||||
// info!(
|
// info!(
|
||||||
@@ -708,20 +698,19 @@ pub struct Grabbable;
|
|||||||
|
|
||||||
pub fn update_grabbables(
|
pub fn update_grabbables(
|
||||||
mut events: EventReader<InteractionEvent>,
|
mut events: EventReader<InteractionEvent>,
|
||||||
mut grabbable_query: Query<(
|
mut grabbable_query: Query<
|
||||||
Entity,
|
(Entity, &mut Transform, Option<&mut RigidBody>),
|
||||||
&mut Transform,
|
(Without<XRDirectInteractor>, With<Grabbable>),
|
||||||
With<Grabbable>,
|
>,
|
||||||
Without<XRDirectInteractor>,
|
mut interactor_query: Query<
|
||||||
Option<&mut RigidBody>,
|
(
|
||||||
)>,
|
|
||||||
mut interactor_query: Query<(
|
|
||||||
&GlobalTransform,
|
&GlobalTransform,
|
||||||
&XRInteractorState,
|
&XRInteractorState,
|
||||||
&mut XRSelection,
|
&mut XRSelection,
|
||||||
&Hand,
|
&Hand,
|
||||||
|
),
|
||||||
Without<Grabbable>,
|
Without<Grabbable>,
|
||||||
)>,
|
>,
|
||||||
mut writer: EventWriter<GhostHandEvent>,
|
mut writer: EventWriter<GhostHandEvent>,
|
||||||
mut timers: ResMut<GhostTimers>,
|
mut timers: ResMut<GhostTimers>,
|
||||||
) {
|
) {
|
||||||
@@ -737,7 +726,7 @@ pub fn update_grabbables(
|
|||||||
match *interactor_transform.2 {
|
match *interactor_transform.2 {
|
||||||
XRSelection::Empty => {
|
XRSelection::Empty => {
|
||||||
match interactor_transform.1 {
|
match interactor_transform.1 {
|
||||||
XRInteractorState::Idle => match grabbable_transform.4 {
|
XRInteractorState::Idle => match grabbable_transform.2 {
|
||||||
Some(mut thing) => {
|
Some(mut thing) => {
|
||||||
*thing = RigidBody::Dynamic;
|
*thing = RigidBody::Dynamic;
|
||||||
*interactor_transform.2 = XRSelection::Empty;
|
*interactor_transform.2 = XRSelection::Empty;
|
||||||
@@ -746,7 +735,7 @@ pub fn update_grabbables(
|
|||||||
},
|
},
|
||||||
XRInteractorState::Selecting => {
|
XRInteractorState::Selecting => {
|
||||||
// info!("its a direct interactor?");
|
// info!("its a direct interactor?");
|
||||||
match grabbable_transform.4 {
|
match grabbable_transform.2 {
|
||||||
Some(mut thing) => {
|
Some(mut thing) => {
|
||||||
*thing = RigidBody::KinematicPositionBased;
|
*thing = RigidBody::KinematicPositionBased;
|
||||||
*interactor_transform.2 =
|
*interactor_transform.2 =
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::{
|
math::primitives::{Cuboid, Plane3d}, prelude::{
|
||||||
shape, Assets, Camera3dBundle, Color, Commands, Mesh, PbrBundle, PointLight,
|
Assets, Camera3dBundle, Color, Commands, Mesh, PbrBundle, ResMut, StandardMaterial, Transform, Vec3,
|
||||||
PointLightBundle, ResMut, SpatialBundle, StandardMaterial, Transform, Vec3,
|
}, render::mesh::Meshable, utils::default
|
||||||
},
|
|
||||||
transform::TransformBundle,
|
|
||||||
utils::default,
|
|
||||||
};
|
};
|
||||||
use bevy_oxr::xr_input::interactions::{Touched, XRInteractable, XRInteractableState};
|
use bevy_oxr::xr_input::interactions::{Touched, XRInteractable, XRInteractableState};
|
||||||
use bevy_rapier3d::{
|
use bevy_rapier3d::{
|
||||||
@@ -29,8 +26,8 @@ pub fn setup_scene(
|
|||||||
// plane
|
// plane
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
|
mesh: meshes.add(Plane3d::new(Vec3::Y).mesh()),
|
||||||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
|
||||||
transform: Transform::from_xyz(0.0, ground_height, 0.0),
|
transform: Transform::from_xyz(0.0, ground_height, 0.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
@@ -41,8 +38,8 @@ pub fn setup_scene(
|
|||||||
// cube
|
// cube
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1))),
|
||||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
|
||||||
transform: Transform::from_xyz(0.0, 1.0, 0.0),
|
transform: Transform::from_xyz(0.0, 1.0, 0.0),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use bevy::diagnostic::LogDiagnosticsPlugin;
|
use bevy::diagnostic::LogDiagnosticsPlugin;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use bevy::render::render_asset::RenderAssetUsages;
|
||||||
use bevy::transform::components::Transform;
|
use bevy::transform::components::Transform;
|
||||||
use bevy_oxr::graphics::XrAppInfo;
|
use bevy_oxr::graphics::XrAppInfo;
|
||||||
use bevy_oxr::resources::XrViews;
|
use bevy_oxr::resources::XrViews;
|
||||||
@@ -66,6 +67,7 @@ fn uv_debug_texture() -> Image {
|
|||||||
TextureDimension::D2,
|
TextureDimension::D2,
|
||||||
&texture_data,
|
&texture_data,
|
||||||
TextureFormat::Rgba8UnormSrgb,
|
TextureFormat::Rgba8UnormSrgb,
|
||||||
|
RenderAssetUsages::RENDER_WORLD,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,13 +83,7 @@ fn setup(
|
|||||||
commands.spawn((
|
commands.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(
|
mesh: meshes.add(
|
||||||
shape::UVSphere {
|
Sphere::new(radius)
|
||||||
radius,
|
|
||||||
sectors: 10,
|
|
||||||
stacks: 10,
|
|
||||||
}
|
|
||||||
.try_into()
|
|
||||||
.unwrap(),
|
|
||||||
),
|
),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color_texture: Some(images.add(uv_debug_texture())),
|
base_color_texture: Some(images.add(uv_debug_texture())),
|
||||||
@@ -100,8 +96,8 @@ fn setup(
|
|||||||
));
|
));
|
||||||
// cube
|
// cube
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
|
||||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
@@ -186,7 +182,7 @@ fn pull_to_ground(
|
|||||||
root.translation += diff * adjustment_rate;
|
root.translation += diff * adjustment_rate;
|
||||||
|
|
||||||
// Rotate player to be upright on sphere
|
// 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;
|
let point = root.translation + offset;
|
||||||
root.rotate_around(point, Quat::IDENTITY.slerp(angle_diff, adjustment_rate));
|
root.rotate_around(point, Quat::IDENTITY.slerp(angle_diff, adjustment_rate));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use bevy_oxr::graphics::XrAppInfo;
|
|||||||
use bevy_oxr::input::XrInput;
|
use bevy_oxr::input::XrInput;
|
||||||
use bevy_oxr::resources::{XrFrameState, XrSession};
|
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::actions::XrActionSets;
|
||||||
use bevy_oxr::xr_input::hands::common::HandInputDebugRenderer;
|
use bevy_oxr::xr_input::hands::common::HandInputDebugRenderer;
|
||||||
use bevy_oxr::xr_input::interactions::{
|
use bevy_oxr::xr_input::interactions::{
|
||||||
@@ -36,21 +37,21 @@ fn main() {
|
|||||||
.add_plugins(LogDiagnosticsPlugin::default())
|
.add_plugins(LogDiagnosticsPlugin::default())
|
||||||
.add_plugins(FrameTimeDiagnosticsPlugin)
|
.add_plugins(FrameTimeDiagnosticsPlugin)
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(Update, proto_locomotion)
|
.add_systems(Update, proto_locomotion.run_if(xr_only()))
|
||||||
.insert_resource(PrototypeLocomotionConfig::default())
|
.insert_resource(PrototypeLocomotionConfig::default())
|
||||||
.add_systems(Startup, spawn_controllers_example)
|
.add_systems(Startup, spawn_controllers_example)
|
||||||
.add_plugins(HandInputDebugRenderer)
|
.add_plugins(HandInputDebugRenderer)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
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, draw_socket_gizmos.after(update_interactable_states).run_if(xr_only()))
|
||||||
.add_systems(Update, interactions.before(update_interactable_states))
|
.add_systems(Update, interactions.before(update_interactable_states).run_if(xr_only()))
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
socket_interactions.before(update_interactable_states),
|
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_interactable_states)
|
||||||
.add_systems(Update, update_grabbables.after(update_interactable_states))
|
.add_systems(Update, update_grabbables.after(update_interactable_states))
|
||||||
.add_event::<InteractionEvent>()
|
.add_event::<InteractionEvent>()
|
||||||
@@ -65,14 +66,14 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
// plane
|
// plane
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
|
mesh: meshes.add(Plane3d::new(Vec3::Y).mesh()),
|
||||||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// cube
|
// cube
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
|
||||||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
|
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
@@ -191,8 +192,8 @@ pub struct Grabbable;
|
|||||||
|
|
||||||
pub fn update_grabbables(
|
pub fn update_grabbables(
|
||||||
mut events: EventReader<InteractionEvent>,
|
mut events: EventReader<InteractionEvent>,
|
||||||
mut grabbable_query: Query<(&mut Transform, With<Grabbable>, Without<XRDirectInteractor>)>,
|
mut grabbable_query: Query<&mut Transform, (With<Grabbable>, Without<XRDirectInteractor>)>,
|
||||||
interactor_query: Query<(&GlobalTransform, &XRInteractorState, Without<Grabbable>)>,
|
interactor_query: Query<(&GlobalTransform, &XRInteractorState), Without<Grabbable>>,
|
||||||
) {
|
) {
|
||||||
//so basically the idea is to try all the events?
|
//so basically the idea is to try all the events?
|
||||||
for event in events.read() {
|
for event in events.read() {
|
||||||
@@ -207,7 +208,7 @@ pub fn update_grabbables(
|
|||||||
XRInteractorState::Idle => (),
|
XRInteractorState::Idle => (),
|
||||||
XRInteractorState::Selecting => {
|
XRInteractorState::Selecting => {
|
||||||
// info!("its a direct interactor?");
|
// info!("its a direct interactor?");
|
||||||
*grabbable_transform.0 = interactor_transform.0.compute_transform();
|
*grabbable_transform = interactor_transform.0.compute_transform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::ffi::{c_void, CString};
|
use std::ffi::{c_void, CString};
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::Mutex;
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
// use anyhow::Context;
|
// use anyhow::Context;
|
||||||
use ash::vk::{self, Handle};
|
use ash::vk::{self, Handle};
|
||||||
@@ -130,9 +130,8 @@ pub fn initialize_xr_instance(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let vk_entry = unsafe { ash::Entry::load() }?;
|
let vk_entry = unsafe { ash::Entry::load() }?;
|
||||||
let flags = wgpu_hal::InstanceFlags::empty();
|
let flags = wgpu::InstanceFlags::from_build_config();
|
||||||
let extensions =
|
let extensions = <V as Api>::Instance::desired_extensions(&vk_entry, vk_target_version, flags)?;
|
||||||
<V as Api>::Instance::required_extensions(&vk_entry, vk_target_version, flags)?;
|
|
||||||
let device_extensions = vec![
|
let device_extensions = vec![
|
||||||
ash::extensions::khr::Swapchain::name(),
|
ash::extensions::khr::Swapchain::name(),
|
||||||
ash::extensions::khr::DrawIndirectCount::name(),
|
ash::extensions::khr::DrawIndirectCount::name(),
|
||||||
@@ -282,8 +281,8 @@ pub fn initialize_xr_instance(
|
|||||||
wgpu_open_device,
|
wgpu_open_device,
|
||||||
&wgpu::DeviceDescriptor {
|
&wgpu::DeviceDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
features: wgpu_features,
|
required_features: wgpu_features,
|
||||||
limits: wgpu::Limits {
|
required_limits: wgpu::Limits {
|
||||||
max_bind_groups: 8,
|
max_bind_groups: 8,
|
||||||
max_storage_buffer_binding_size: wgpu_adapter
|
max_storage_buffer_binding_size: wgpu_adapter
|
||||||
.limits()
|
.limits()
|
||||||
@@ -358,7 +357,7 @@ pub fn start_xr_session(
|
|||||||
// SAFETY: Plugins should be set up on the main thread.
|
// SAFETY: Plugins should be set up on the main thread.
|
||||||
let handle = wrapper.get_handle();
|
let handle = wrapper.get_handle();
|
||||||
wgpu_instance
|
wgpu_instance
|
||||||
.create_surface(&handle)
|
.create_surface(handle)
|
||||||
.expect("Failed to create wgpu surface")
|
.expect("Failed to create wgpu surface")
|
||||||
});
|
});
|
||||||
let swapchain_format = surface
|
let swapchain_format = surface
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ impl Plugin for OpenXrPlugin {
|
|||||||
render_adapter,
|
render_adapter,
|
||||||
render_instance,
|
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.insert_resource(XrStatus::Disabled);
|
||||||
app.world.send_event(StartXrSession);
|
app.world.send_event(StartXrSession);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use bevy::ecs::schedule::IntoSystemConfigs;
|
use bevy::ecs::schedule::IntoSystemConfigs;
|
||||||
use bevy::log::{debug, info};
|
use bevy::log::{debug, info};
|
||||||
|
use bevy::math::primitives::Direction3d;
|
||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3, With,
|
Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3, With,
|
||||||
Without,
|
Without,
|
||||||
@@ -104,7 +105,7 @@ pub fn draw_gizmos(
|
|||||||
y: 0.01,
|
y: 0.01,
|
||||||
z: 0.0,
|
z: 0.0,
|
||||||
},
|
},
|
||||||
Vec3::Y,
|
Direction3d::Y,
|
||||||
0.2,
|
0.2,
|
||||||
Color::RED,
|
Color::RED,
|
||||||
);
|
);
|
||||||
@@ -168,7 +169,7 @@ fn draw_hand_gizmo(
|
|||||||
//draw face
|
//draw face
|
||||||
gizmos.circle(
|
gizmos.circle(
|
||||||
face_translation_vec3,
|
face_translation_vec3,
|
||||||
face_quat_normal,
|
Direction3d::new_unchecked(face_quat_normal),
|
||||||
0.04,
|
0.04,
|
||||||
Color::YELLOW_GREEN,
|
Color::YELLOW_GREEN,
|
||||||
);
|
);
|
||||||
@@ -185,7 +186,7 @@ fn draw_hand_gizmo(
|
|||||||
let b_offset_quat = face_quat;
|
let b_offset_quat = face_quat;
|
||||||
let b_translation_vec3 =
|
let b_translation_vec3 =
|
||||||
face_translation_vec3 + b_offset_quat.mul_vec3(Vec3::new(0.025, -0.01, 0.0));
|
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
|
//button a
|
||||||
let mut a_color = off_color;
|
let mut a_color = off_color;
|
||||||
@@ -199,7 +200,7 @@ fn draw_hand_gizmo(
|
|||||||
let a_offset_quat = face_quat;
|
let a_offset_quat = face_quat;
|
||||||
let a_translation_vec3 =
|
let a_translation_vec3 =
|
||||||
face_translation_vec3 + a_offset_quat.mul_vec3(Vec3::new(0.025, 0.01, 0.0));
|
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
|
//joystick
|
||||||
let joystick_offset_quat = face_quat;
|
let joystick_offset_quat = face_quat;
|
||||||
@@ -211,7 +212,7 @@ fn draw_hand_gizmo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//base
|
//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 stick = controller.thumbstick(Hand::Left);
|
||||||
let input = Vec3::new(stick.x, -stick.y, 0.0);
|
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(Vec3::new(-0.02, 0.0, -0.01))
|
||||||
+ joystick_offset_quat.mul_vec3(input * 0.01);
|
+ joystick_offset_quat.mul_vec3(input * 0.01);
|
||||||
//top
|
//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
|
//trigger
|
||||||
let trigger_state = controller.trigger(Hand::Left);
|
let trigger_state = controller.trigger(Hand::Left);
|
||||||
@@ -277,7 +278,7 @@ fn draw_hand_gizmo(
|
|||||||
//draw face
|
//draw face
|
||||||
gizmos.circle(
|
gizmos.circle(
|
||||||
face_translation_vec3,
|
face_translation_vec3,
|
||||||
face_quat_normal,
|
Direction3d::new_unchecked(face_quat_normal),
|
||||||
0.04,
|
0.04,
|
||||||
Color::YELLOW_GREEN,
|
Color::YELLOW_GREEN,
|
||||||
);
|
);
|
||||||
@@ -294,7 +295,7 @@ fn draw_hand_gizmo(
|
|||||||
let b_offset_quat = face_quat;
|
let b_offset_quat = face_quat;
|
||||||
let b_translation_vec3 =
|
let b_translation_vec3 =
|
||||||
face_translation_vec3 + b_offset_quat.mul_vec3(Vec3::new(-0.025, -0.01, 0.0));
|
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
|
//button a
|
||||||
let mut a_color = off_color;
|
let mut a_color = off_color;
|
||||||
@@ -308,7 +309,7 @@ fn draw_hand_gizmo(
|
|||||||
let a_offset_quat = face_quat;
|
let a_offset_quat = face_quat;
|
||||||
let a_translation_vec3 =
|
let a_translation_vec3 =
|
||||||
face_translation_vec3 + a_offset_quat.mul_vec3(Vec3::new(-0.025, 0.01, 0.0));
|
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
|
//joystick time
|
||||||
let joystick_offset_quat = face_quat;
|
let joystick_offset_quat = face_quat;
|
||||||
@@ -320,7 +321,7 @@ fn draw_hand_gizmo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//base
|
//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 stick = controller.thumbstick(Hand::Right);
|
||||||
let input = Vec3::new(stick.x, -stick.y, 0.0);
|
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(Vec3::new(0.02, 0.0, -0.01))
|
||||||
+ joystick_offset_quat.mul_vec3(input * 0.01);
|
+ joystick_offset_quat.mul_vec3(input * 0.01);
|
||||||
//top
|
//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
|
//trigger
|
||||||
let trigger_state = controller.trigger(Hand::Right);
|
let trigger_state = controller.trigger(Hand::Right);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::log::info;
|
use bevy::log::{info, warn};
|
||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
Color, Component, Entity, Event, EventReader, EventWriter, Gizmos, GlobalTransform, Quat,
|
Color, Component, Entity, Event, EventReader, EventWriter, Gizmos, GlobalTransform, Quat,
|
||||||
Query, Transform, Vec3, With, Without,
|
Query, Transform, Vec3, With, Without,
|
||||||
@@ -93,9 +93,12 @@ pub fn draw_interaction_gizmos(
|
|||||||
),
|
),
|
||||||
Without<XRInteractable>,
|
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() {
|
for (global_transform, interactable_state) in interactable_query.iter() {
|
||||||
let transform = global_transform.compute_transform();
|
let transform = global_transform.compute_transform();
|
||||||
let color = match interactable_state {
|
let color = match interactable_state {
|
||||||
@@ -137,7 +140,7 @@ pub fn draw_interaction_gizmos(
|
|||||||
};
|
};
|
||||||
gizmos.ray(
|
gizmos.ray(
|
||||||
root.translation + root.rotation.mul_vec3(aim.0.translation),
|
root.translation + root.rotation.mul_vec3(aim.0.translation),
|
||||||
root.rotation.mul_vec3(aim.0.forward()),
|
root.rotation.mul_vec3(*aim.0.forward()),
|
||||||
color,
|
color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -229,7 +232,7 @@ pub fn interactions(
|
|||||||
),
|
),
|
||||||
Without<XRInteractable>,
|
Without<XRInteractable>,
|
||||||
>,
|
>,
|
||||||
tracking_root_query: Query<(&mut Transform, With<OpenXRTrackingRoot>)>,
|
tracking_root_query: Query<&mut Transform, With<OpenXRTrackingRoot>>,
|
||||||
mut writer: EventWriter<InteractionEvent>,
|
mut writer: EventWriter<InteractionEvent>,
|
||||||
) {
|
) {
|
||||||
for (xr_interactable_global_transform, interactable_entity) in interactable_query.iter() {
|
for (xr_interactable_global_transform, interactable_entity) in interactable_query.iter() {
|
||||||
@@ -280,12 +283,12 @@ pub fn interactions(
|
|||||||
let center = sphere_transform.translation;
|
let center = sphere_transform.translation;
|
||||||
let radius: f32 = 0.1;
|
let radius: f32 = 0.1;
|
||||||
//I hate this but the aim pose needs the root for now
|
//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 {
|
match aim {
|
||||||
Some(aim) => {
|
Some(aim) => {
|
||||||
let ray_origin =
|
let ray_origin =
|
||||||
root.translation + root.rotation.mul_vec3(aim.0.translation);
|
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(
|
if ray_sphere_intersection(
|
||||||
center,
|
center,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ use self::trackers::{
|
|||||||
adopt_open_xr_trackers, update_open_xr_controllers, OpenXRLeftEye, OpenXRRightEye,
|
adopt_open_xr_trackers, update_open_xr_controllers, OpenXRLeftEye, OpenXRRightEye,
|
||||||
OpenXRTrackingRoot,
|
OpenXRTrackingRoot,
|
||||||
};
|
};
|
||||||
use self::xr_camera::{GlobalTransformExtract, TransformExtract, XrCamera};
|
use self::xr_camera::{/* GlobalTransformExtract, TransformExtract, */ XrCamera};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct OpenXrInput {
|
pub struct OpenXrInput {
|
||||||
|
|||||||
@@ -59,11 +59,10 @@ impl Default for PrototypeLocomotionConfig {
|
|||||||
|
|
||||||
pub fn proto_locomotion(
|
pub fn proto_locomotion(
|
||||||
time: Res<Time>,
|
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>,
|
oculus_controller: Res<OculusController>,
|
||||||
frame_state: Res<XrFrameState>,
|
frame_state: Res<XrFrameState>,
|
||||||
xr_input: Res<XrInput>,
|
xr_input: Res<XrInput>,
|
||||||
instance: Res<XrInstance>,
|
|
||||||
session: Res<XrSession>,
|
session: Res<XrSession>,
|
||||||
views: ResMut<XrViews>,
|
views: ResMut<XrViews>,
|
||||||
mut gizmos: Gizmos,
|
mut gizmos: Gizmos,
|
||||||
@@ -84,7 +83,7 @@ pub fn proto_locomotion(
|
|||||||
Ok(mut position) => {
|
Ok(mut position) => {
|
||||||
//get the stick input and do some maths
|
//get the stick input and do some maths
|
||||||
let stick = controller.thumbstick(Hand::Left);
|
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;
|
let reference_quat;
|
||||||
match config.locomotion_type {
|
match config.locomotion_type {
|
||||||
LocomotionType::Head => {
|
LocomotionType::Head => {
|
||||||
@@ -102,10 +101,9 @@ pub fn proto_locomotion(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let (yaw, _pitch, _roll) = reference_quat.to_euler(EulerRot::YXZ);
|
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);
|
let locomotion_vec = reference_quat.mul_vec3(input);
|
||||||
position.0.translation +=
|
position.translation += locomotion_vec * config.locomotion_speed * time.delta_seconds();
|
||||||
locomotion_vec * config.locomotion_speed * time.delta_seconds();
|
|
||||||
|
|
||||||
//now time for rotation
|
//now time for rotation
|
||||||
|
|
||||||
@@ -118,7 +116,7 @@ pub fn proto_locomotion(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let smoth_rot = Quat::from_axis_angle(
|
let smoth_rot = Quat::from_axis_angle(
|
||||||
position.0.up(),
|
*position.up(),
|
||||||
rot_input * config.smooth_rotation_speed * time.delta_seconds(),
|
rot_input * config.smooth_rotation_speed * time.delta_seconds(),
|
||||||
);
|
);
|
||||||
//apply rotation
|
//apply rotation
|
||||||
@@ -127,10 +125,10 @@ pub fn proto_locomotion(
|
|||||||
Some(view) => {
|
Some(view) => {
|
||||||
let mut hmd_translation = view.pose.position.to_vec3();
|
let mut hmd_translation = view.pose.position.to_vec3();
|
||||||
hmd_translation.y = 0.0;
|
hmd_translation.y = 0.0;
|
||||||
let local = position.0.translation;
|
let local = position.translation;
|
||||||
let global = position.0.rotation.mul_vec3(hmd_translation) + local;
|
let global = position.rotation.mul_vec3(hmd_translation) + local;
|
||||||
gizmos.circle(global, position.0.up(), 0.1, Color::GREEN);
|
gizmos.circle(global, position.up(), 0.1, Color::GREEN);
|
||||||
position.0.rotate_around(global, smoth_rot);
|
position.rotate_around(global, smoth_rot);
|
||||||
}
|
}
|
||||||
None => return,
|
None => return,
|
||||||
}
|
}
|
||||||
@@ -151,7 +149,7 @@ pub fn proto_locomotion(
|
|||||||
false => -1.0,
|
false => -1.0,
|
||||||
};
|
};
|
||||||
let smoth_rot =
|
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
|
//apply rotation
|
||||||
let v = views;
|
let v = views;
|
||||||
let views = v.first();
|
let views = v.first();
|
||||||
@@ -159,10 +157,10 @@ pub fn proto_locomotion(
|
|||||||
Some(view) => {
|
Some(view) => {
|
||||||
let mut hmd_translation = view.pose.position.to_vec3();
|
let mut hmd_translation = view.pose.position.to_vec3();
|
||||||
hmd_translation.y = 0.0;
|
hmd_translation.y = 0.0;
|
||||||
let local = position.0.translation;
|
let local = position.translation;
|
||||||
let global = position.0.rotation.mul_vec3(hmd_translation) + local;
|
let global = position.rotation.mul_vec3(hmd_translation) + local;
|
||||||
gizmos.circle(global, position.0.up(), 0.1, Color::GREEN);
|
gizmos.circle(global, position.up(), 0.1, Color::GREEN);
|
||||||
position.0.rotate_around(global, smoth_rot);
|
position.rotate_around(global, smoth_rot);
|
||||||
}
|
}
|
||||||
None => return,
|
None => return,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use bevy::hierarchy::Parent;
|
use bevy::hierarchy::Parent;
|
||||||
use bevy::log::{debug, info};
|
use bevy::log::{debug, info};
|
||||||
|
use bevy::math::Quat;
|
||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
Added, BuildChildren, Commands, Component, Entity, Query, Res, Transform, Vec3, With, Without,
|
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(
|
pub fn update_open_xr_controllers(
|
||||||
oculus_controller: Res<OculusController>,
|
oculus_controller: Res<OculusController>,
|
||||||
mut left_controller_query: Query<(
|
mut left_controller_query: Query<
|
||||||
&mut Transform,
|
(&mut Transform, Option<&mut AimPose>),
|
||||||
Option<&mut AimPose>,
|
(With<OpenXRLeftController>, Without<OpenXRRightController>),
|
||||||
With<OpenXRLeftController>,
|
>,
|
||||||
Without<OpenXRRightController>,
|
mut right_controller_query: Query<
|
||||||
)>,
|
(&mut Transform, Option<&mut AimPose>),
|
||||||
mut right_controller_query: Query<(
|
(With<OpenXRRightController>, Without<OpenXRLeftController>),
|
||||||
&mut Transform,
|
>,
|
||||||
Option<&mut AimPose>,
|
|
||||||
With<OpenXRRightController>,
|
|
||||||
Without<OpenXRLeftController>,
|
|
||||||
)>,
|
|
||||||
frame_state: Res<XrFrameState>,
|
frame_state: Res<XrFrameState>,
|
||||||
xr_input: Res<XrInput>,
|
xr_input: Res<XrInput>,
|
||||||
session: Res<XrSession>,
|
session: Res<XrSession>,
|
||||||
@@ -81,7 +85,7 @@ pub fn update_open_xr_controllers(
|
|||||||
Some(mut pose) => {
|
Some(mut pose) => {
|
||||||
*pose = AimPose(Transform {
|
*pose = AimPose(Transform {
|
||||||
translation: left_aim_space.0.pose.position.to_vec3(),
|
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),
|
scale: Vec3::splat(1.0),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -99,7 +103,7 @@ pub fn update_open_xr_controllers(
|
|||||||
let left_rotataion = left_controller_query.get_single_mut();
|
let left_rotataion = left_controller_query.get_single_mut();
|
||||||
match left_rotataion {
|
match left_rotataion {
|
||||||
Ok(mut left_entity) => {
|
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(_) => (),
|
Err(_) => (),
|
||||||
}
|
}
|
||||||
@@ -114,7 +118,7 @@ pub fn update_open_xr_controllers(
|
|||||||
Some(mut pose) => {
|
Some(mut pose) => {
|
||||||
*pose = AimPose(Transform {
|
*pose = AimPose(Transform {
|
||||||
translation: right_aim_space.0.pose.position.to_vec3(),
|
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),
|
scale: Vec3::splat(1.0),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -132,7 +136,7 @@ pub fn update_open_xr_controllers(
|
|||||||
let right_rotataion = right_controller_query.get_single_mut();
|
let right_rotataion = right_controller_query.get_single_mut();
|
||||||
match right_rotataion {
|
match right_rotataion {
|
||||||
Ok(mut right_entity) => {
|
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(_) => (),
|
Err(_) => (),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
use crate::xr_init::{xr_only, XrCleanup, XrSetup};
|
use crate::xr_init::{xr_only, XrCleanup, XrSetup};
|
||||||
use crate::xr_input::{QuatConv, Vec3Conv};
|
use crate::xr_input::{QuatConv, Vec3Conv};
|
||||||
use crate::{locate_views, xr_wait_frame, LEFT_XR_TEXTURE_HANDLE, RIGHT_XR_TEXTURE_HANDLE};
|
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::core_pipeline::tonemapping::{DebandDither, Tonemapping};
|
||||||
use bevy::ecs::system::lifetimeless::Read;
|
|
||||||
use bevy::math::Vec3A;
|
use bevy::math::Vec3A;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::render::camera::{
|
use bevy::render::camera::{
|
||||||
CameraProjection, CameraProjectionPlugin, CameraRenderGraph, RenderTarget,
|
CameraMainTextureUsages, CameraProjection, CameraProjectionPlugin, CameraRenderGraph, RenderTarget
|
||||||
};
|
};
|
||||||
use bevy::render::extract_component::{ExtractComponent, ExtractComponentPlugin};
|
use bevy::render::extract_component::{ExtractComponent, ExtractComponentPlugin};
|
||||||
use bevy::render::primitives::Frustum;
|
use bevy::render::primitives::Frustum;
|
||||||
use bevy::render::view::{
|
use bevy::render::view::{
|
||||||
update_frusta, ColorGrading, ExtractedView, VisibilitySystems, VisibleEntities,
|
update_frusta, ColorGrading, VisibilitySystems, VisibleEntities,
|
||||||
};
|
};
|
||||||
use bevy::transform::TransformSystem;
|
use bevy::transform::TransformSystem;
|
||||||
use openxr::Fovf;
|
use openxr::Fovf;
|
||||||
|
use wgpu::TextureUsages;
|
||||||
|
|
||||||
use super::trackers::{OpenXRLeftEye, OpenXRRightEye, OpenXRTracker, OpenXRTrackingRoot};
|
use super::trackers::{OpenXRLeftEye, OpenXRRightEye, OpenXRTracker};
|
||||||
|
|
||||||
pub struct XrCameraPlugin;
|
pub struct XrCameraPlugin;
|
||||||
|
|
||||||
@@ -100,40 +101,41 @@ pub struct XrCameraBundle {
|
|||||||
pub tonemapping: Tonemapping,
|
pub tonemapping: Tonemapping,
|
||||||
pub dither: DebandDither,
|
pub dither: DebandDither,
|
||||||
pub color_grading: ColorGrading,
|
pub color_grading: ColorGrading,
|
||||||
|
pub main_texture_usages: CameraMainTextureUsages,
|
||||||
pub xr_camera_type: XrCamera,
|
pub xr_camera_type: XrCamera,
|
||||||
}
|
}
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Component, ExtractComponent)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Component, ExtractComponent)]
|
||||||
pub struct XrCamera(Eye);
|
pub struct XrCamera(Eye);
|
||||||
|
|
||||||
#[derive(Component)]
|
// #[derive(Component)]
|
||||||
pub(super) struct TransformExtract;
|
// pub(super) struct TransformExtract;
|
||||||
|
//
|
||||||
impl ExtractComponent for TransformExtract {
|
// impl ExtractComponent for TransformExtract {
|
||||||
type Query = Read<Transform>;
|
// type Query = Read<Transform>;
|
||||||
|
//
|
||||||
type Filter = ();
|
// type Filter = ();
|
||||||
|
//
|
||||||
type Out = Transform;
|
// type Out = Transform;
|
||||||
|
//
|
||||||
fn extract_component(item: bevy::ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
|
// fn extract_component(item: bevy::ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
|
||||||
Some(*item)
|
// Some(*item)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
#[derive(Component)]
|
// #[derive(Component)]
|
||||||
pub(super) struct GlobalTransformExtract;
|
// pub(super) struct GlobalTransformExtract;
|
||||||
|
//
|
||||||
impl ExtractComponent for GlobalTransformExtract {
|
// impl ExtractComponent for GlobalTransformExtract {
|
||||||
type Query = Read<GlobalTransform>;
|
// type Query = Read<GlobalTransform>;
|
||||||
|
//
|
||||||
type Filter = ();
|
// type Filter = ();
|
||||||
|
//
|
||||||
type Out = GlobalTransform;
|
// type Out = GlobalTransform;
|
||||||
|
//
|
||||||
fn extract_component(item: bevy::ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
|
// fn extract_component(item: bevy::ecs::query::QueryItem<'_, Self::Query>) -> Option<Self::Out> {
|
||||||
Some(*item)
|
// Some(*item)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||||
pub enum Eye {
|
pub enum Eye {
|
||||||
@@ -153,7 +155,7 @@ impl XrCameraBundle {
|
|||||||
viewport: None,
|
viewport: None,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
camera_render_graph: CameraRenderGraph::new(bevy::core_pipeline::core_3d::graph::NAME),
|
camera_render_graph: CameraRenderGraph::new(Core3d),
|
||||||
xr_projection: Default::default(),
|
xr_projection: Default::default(),
|
||||||
visible_entities: Default::default(),
|
visible_entities: Default::default(),
|
||||||
frustum: Default::default(),
|
frustum: Default::default(),
|
||||||
@@ -164,6 +166,11 @@ impl XrCameraBundle {
|
|||||||
dither: DebandDither::Enabled,
|
dither: DebandDither::Enabled,
|
||||||
color_grading: Default::default(),
|
color_grading: Default::default(),
|
||||||
xr_camera_type: XrCamera(eye),
|
xr_camera_type: XrCamera(eye),
|
||||||
|
main_texture_usages: CameraMainTextureUsages(
|
||||||
|
TextureUsages::RENDER_ATTACHMENT
|
||||||
|
| TextureUsages::TEXTURE_BINDING
|
||||||
|
| TextureUsages::COPY_SRC,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user