This commit is contained in:
Schmarni
2024-02-22 10:40:53 +01:00
parent adb8b13675
commit 4f753b68de
8 changed files with 76 additions and 21 deletions

View File

@@ -1,13 +1,21 @@
use std::{f32::consts::PI, ops::Mul, time::Duration};
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, ecs::schedule::ScheduleLabel, input::{keyboard::KeyCode, ButtonInput}, log::info, math::primitives::{Capsule3d, Cuboid}, 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,
}, render::mesh::Meshable, 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},

View File

@@ -1,7 +1,11 @@
use bevy::{
math::primitives::{Cuboid, Plane3d}, prelude::{
Assets, Camera3dBundle, Color, Commands, Mesh, PbrBundle, ResMut, StandardMaterial, Transform, Vec3,
}, render::mesh::Meshable, 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::{

View File

@@ -82,9 +82,7 @@ fn setup(
let radius = 5.0;
commands.spawn((
PbrBundle {
mesh: meshes.add(
Sphere::new(radius)
),
mesh: meshes.add(Sphere::new(radius)),
material: materials.add(StandardMaterial {
base_color_texture: Some(images.add(uv_debug_texture())),
..default()

View File

@@ -1,8 +1,8 @@
use bevy::ecs::schedule::{IntoSystemConfigs, SystemConfigs};
pub use crate::xr_init::schedules::XrSetup;
use crate::xr_init::xr_only;
pub use crate::xr_input::{QuatConv, Vec2Conv, Vec3Conv};
pub use crate::xr_init::schedules::XrSetup;
pub trait XrSystems<Marker> {
fn xr_only(self) -> SystemConfigs;

View File

@@ -94,7 +94,7 @@ impl Plugin for XrInitPlugin {
}
}
#[derive(Resource, Clone, Copy, PartialEq, Eq,Default)]
#[derive(Resource, Clone, Copy, PartialEq, Eq, Default)]
pub enum ExitAppOnSessionExit {
#[default]
/// Restart XrSession when session is lost

View File

@@ -1,4 +1,7 @@
use bevy::{ecs::schedule::{ScheduleLabel, Schedule, ExecutorKind}, app::App};
use bevy::{
app::App,
ecs::schedule::{ExecutorKind, Schedule, ScheduleLabel},
};
#[derive(Debug, ScheduleLabel, Clone, Copy, Hash, PartialEq, Eq)]
pub struct XrPreSetup;

View File

@@ -186,7 +186,12 @@ 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, Direction3d::new_unchecked(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;
@@ -200,7 +205,12 @@ 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, Direction3d::new_unchecked(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;
@@ -212,7 +222,12 @@ fn draw_hand_gizmo(
}
//base
gizmos.circle(joystick_base_vec, Direction3d::new_unchecked(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);
@@ -220,7 +235,12 @@ 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, Direction3d::new_unchecked(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);
@@ -295,7 +315,12 @@ 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, Direction3d::new_unchecked(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;
@@ -309,7 +334,12 @@ 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, Direction3d::new_unchecked(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;
@@ -321,7 +351,12 @@ fn draw_hand_gizmo(
}
//base
gizmos.circle(joystick_base_vec, Direction3d::new_unchecked(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);
@@ -329,7 +364,12 @@ 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, Direction3d::new_unchecked(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

@@ -31,7 +31,9 @@ use bevy::utils::HashMap;
use openxr::Binding;
use self::actions::{setup_oxr_actions, XrActionsPlugin};
use self::oculus_touch::{init_subaction_path, post_action_setup_oculus_controller, ActionSets, OculusController};
use self::oculus_touch::{
init_subaction_path, post_action_setup_oculus_controller, ActionSets, OculusController,
};
use self::trackers::{
adopt_open_xr_trackers, update_open_xr_controllers, OpenXRLeftEye, OpenXRRightEye,
OpenXRTrackingRoot,
@@ -63,7 +65,7 @@ impl Plugin for XrInputPlugin {
}
fn cleanup_oculus_controller(mut commands: Commands) {
commands.remove_resource::<OculusController>();
commands.remove_resource::<OculusController>();
}
fn cleanup_xr_root(