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 std::{f32::consts::PI, ops::Mul, time::Duration};
use bevy::{ 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, 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 },
render::mesh::Meshable,
time::{Fixed, Time, Timer, TimerMode},
transform::TransformSystem,
}; };
use bevy_oxr::{ use bevy_oxr::{
graphics::{extensions::XrExtensions, XrAppInfo, XrPreferdBlendMode}, graphics::{extensions::XrExtensions, XrAppInfo, XrPreferdBlendMode},

View File

@@ -1,7 +1,11 @@
use bevy::{ use bevy::{
math::primitives::{Cuboid, Plane3d}, prelude::{ math::primitives::{Cuboid, Plane3d},
Assets, Camera3dBundle, Color, Commands, Mesh, PbrBundle, ResMut, StandardMaterial, Transform, Vec3, prelude::{
}, render::mesh::Meshable, utils::default 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_oxr::xr_input::interactions::{Touched, XRInteractable, XRInteractableState};
use bevy_rapier3d::{ use bevy_rapier3d::{

View File

@@ -82,9 +82,7 @@ fn setup(
let radius = 5.0; let radius = 5.0;
commands.spawn(( commands.spawn((
PbrBundle { PbrBundle {
mesh: meshes.add( mesh: meshes.add(Sphere::new(radius)),
Sphere::new(radius)
),
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())),
..default() ..default()

View File

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

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)] #[derive(Debug, ScheduleLabel, Clone, Copy, Hash, PartialEq, Eq)]
pub struct XrPreSetup; pub struct XrPreSetup;

View File

@@ -186,7 +186,12 @@ 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, 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 //button a
let mut a_color = off_color; let mut a_color = off_color;
@@ -200,7 +205,12 @@ 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, 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 //joystick
let joystick_offset_quat = face_quat; let joystick_offset_quat = face_quat;
@@ -212,7 +222,12 @@ fn draw_hand_gizmo(
} }
//base //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 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);
@@ -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(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, 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 //trigger
let trigger_state = controller.trigger(Hand::Left); let trigger_state = controller.trigger(Hand::Left);
@@ -295,7 +315,12 @@ 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, 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 //button a
let mut a_color = off_color; let mut a_color = off_color;
@@ -309,7 +334,12 @@ 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, 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 //joystick time
let joystick_offset_quat = face_quat; let joystick_offset_quat = face_quat;
@@ -321,7 +351,12 @@ fn draw_hand_gizmo(
} }
//base //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 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);
@@ -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(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, 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 //trigger
let trigger_state = controller.trigger(Hand::Right); let trigger_state = controller.trigger(Hand::Right);

View File

@@ -31,7 +31,9 @@ use bevy::utils::HashMap;
use openxr::Binding; use openxr::Binding;
use self::actions::{setup_oxr_actions, XrActionsPlugin}; 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::{ 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,