this is a little better

This commit is contained in:
Jay Christy
2023-10-01 00:22:42 -04:00
parent 88838b595b
commit d80506c43c
2 changed files with 79 additions and 46 deletions

View File

@@ -5,9 +5,9 @@ use bevy_openxr::input::XrInput;
use bevy_openxr::resources::{XrFrameState, XrInstance, XrSession}; use bevy_openxr::resources::{XrFrameState, XrInstance, XrSession};
use bevy_openxr::xr_input::debug_gizmos::OpenXrDebugRenderer; use bevy_openxr::xr_input::debug_gizmos::OpenXrDebugRenderer;
use bevy_openxr::xr_input::interactions::{ use bevy_openxr::xr_input::interactions::{
draw_interaction_gizmos, draw_socket_gizmos, interactions, update_interactable_states, draw_interaction_gizmos, draw_socket_gizmos, interactions, socket_interactions,
InteractionEvent, XRDirectInteractor, XRInteractable, XRInteractableState, XRInteractorState, update_interactable_states, InteractionEvent, XRDirectInteractor, XRInteractable,
XRRayInteractor, XRSocketInteractor, socket_interactions, XRInteractableState, XRInteractorState, XRRayInteractor, XRSocketInteractor,
}; };
use bevy_openxr::xr_input::oculus_touch::OculusController; use bevy_openxr::xr_input::oculus_touch::OculusController;
use bevy_openxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig}; use bevy_openxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig};
@@ -35,10 +35,13 @@ fn main() {
draw_interaction_gizmos.after(update_interactable_states), draw_interaction_gizmos.after(update_interactable_states),
) )
.add_systems(Update, draw_socket_gizmos.after(update_interactable_states)) .add_systems(Update, draw_socket_gizmos.after(update_interactable_states))
.add_systems(Update, interactions) .add_systems(Update, interactions.before(update_interactable_states))
.add_systems(Update, socket_interactions) .add_systems(
Update,
socket_interactions.before(update_interactable_states),
)
.add_systems(Update, prototype_interaction_input) .add_systems(Update, prototype_interaction_input)
.add_systems(Update, update_interactable_states.after(interactions)) .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>()
.run(); .run();
@@ -173,37 +176,40 @@ 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<( interactor_query: Query<(&GlobalTransform, &XRInteractorState, Without<Grabbable>)>,
&GlobalTransform,
With<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() {
info!("some event"); // info!("some event");
match grabbable_query.get_mut(event.interactable) { match grabbable_query.get_mut(event.interactable) {
Ok(mut grabbable_transform) => { Ok(mut grabbable_transform) => {
info!("we got a grabbable"); // info!("we got a grabbable");
//now we need the location of our interactor //now we need the location of our interactor
match interactor_query.get(event.interactor) { match interactor_query.get(event.interactor) {
Ok(interactor_transform) => { Ok(interactor_transform) => {
info!("its a direct interactor?"); match interactor_transform.1 {
info!( XRInteractorState::Idle => (),
"before gT: {:?}, iT: {:?}", XRInteractorState::Selecting => {
grabbable_transform, interactor_transform // info!("its a direct interactor?");
); // info!(
// "before gT: {:?}, iT: {:?}",
// grabbable_transform, interactor_transform
// );
*grabbable_transform.0 = interactor_transform.0.compute_transform(); *grabbable_transform.0 = interactor_transform.0.compute_transform();
info!( // info!(
"after gT: {:?}, iT: {:?}", // "after gT: {:?}, iT: {:?}",
grabbable_transform, interactor_transform // grabbable_transform, interactor_transform
); // );
} }
Err(_) => info!("not a direct interactor"),
} }
} }
Err(_) => { Err(_) => {
info!("not a grabbable?") // info!("not a direct interactor")
}
}
}
Err(_) => {
// info!("not a grabbable?")
} }
} }
} }

View File

@@ -16,7 +16,7 @@ pub struct XRRayInteractor;
#[derive(Component)] #[derive(Component)]
pub struct XRSocketInteractor; pub struct XRSocketInteractor;
#[derive(Component, Clone, Copy)] #[derive(Component, Clone, Copy, PartialEq, PartialOrd, Debug)]
pub enum XRInteractableState { pub enum XRInteractableState {
Idle, Idle,
Hover, Hover,
@@ -78,7 +78,7 @@ pub fn draw_interaction_gizmos(
Option<&XRRayInteractor>, Option<&XRRayInteractor>,
Option<&AimPose>, Option<&AimPose>,
), ),
(Without<XRInteractable>), Without<XRInteractable>,
>, >,
tracking_root_query: Query<(&mut Transform, With<OpenXRTrackingRoot>)>, tracking_root_query: Query<(&mut Transform, With<OpenXRTrackingRoot>)>,
) { ) {
@@ -144,7 +144,7 @@ pub struct InteractionEvent {
//yeah these need to be seperate somehow //yeah these need to be seperate somehow
pub fn socket_interactions( pub fn socket_interactions(
mut interactable_query: Query< interactable_query: Query<
(&GlobalTransform, &mut XRInteractableState, Entity), (&GlobalTransform, &mut XRInteractableState, Entity),
(With<XRInteractable>, Without<XRSocketInteractor>), (With<XRInteractable>, Without<XRSocketInteractor>),
>, >,
@@ -155,7 +155,7 @@ pub fn socket_interactions(
Entity, Entity,
&XRSocketInteractor, &XRSocketInteractor,
), ),
(Without<XRInteractable>), Without<XRInteractable>,
>, >,
mut writer: EventWriter<InteractionEvent>, mut writer: EventWriter<InteractionEvent>,
) { ) {
@@ -179,7 +179,15 @@ pub fn socket_interactions(
{ {
//check for selections first //check for selections first
match interactor_state { match interactor_state {
XRInteractorState::Idle => (), //welp this wont work, XRInteractorState::Idle => {
//welp now I gota actually make things do stuff lol
let event = InteractionEvent {
interactor: socket.2,
interactable: interactable.2,
interactable_state: XRInteractableState::Hover,
};
writer.send(event);
}
XRInteractorState::Selecting => { XRInteractorState::Selecting => {
//welp now I gota actually make things do stuff lol //welp now I gota actually make things do stuff lol
let event = InteractionEvent { let event = InteractionEvent {
@@ -196,8 +204,8 @@ pub fn socket_interactions(
} }
pub fn interactions( pub fn interactions(
mut interactable_query: Query< interactable_query: Query<
(&GlobalTransform, &mut XRInteractableState, Entity), (&GlobalTransform, Entity),
(With<XRInteractable>, Without<XRDirectInteractor>), (With<XRInteractable>, Without<XRDirectInteractor>),
>, >,
interactor_query: Query< interactor_query: Query<
@@ -209,15 +217,12 @@ pub fn interactions(
Option<&XRRayInteractor>, Option<&XRRayInteractor>,
Option<&AimPose>, Option<&AimPose>,
), ),
(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, mut state, interactable_entity) in for (xr_interactable_global_transform, interactable_entity) in interactable_query.iter() {
interactable_query.iter_mut()
{
let mut hovered = false;
for (interactor_global_transform, interactor_state, interactor_entity, direct, ray, aim) in for (interactor_global_transform, interactor_state, interactor_entity, direct, ray, aim) in
interactor_query.iter() interactor_query.iter()
{ {
@@ -237,7 +242,15 @@ pub fn interactions(
{ {
//check for selections first //check for selections first
match interactor_state { match interactor_state {
XRInteractorState::Idle => hovered = true, XRInteractorState::Idle => {
//welp now I gota actually make things do stuff lol
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Hover,
};
writer.send(event);
}
XRInteractorState::Selecting => { XRInteractorState::Selecting => {
//welp now I gota actually make things do stuff lol //welp now I gota actually make things do stuff lol
let event = InteractionEvent { let event = InteractionEvent {
@@ -274,7 +287,15 @@ pub fn interactions(
) { ) {
//check for selections first //check for selections first
match interactor_state { match interactor_state {
XRInteractorState::Idle => hovered = true, XRInteractorState::Idle => {
//welp now I gota actually make things do stuff lol
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Hover,
};
writer.send(event);
}
XRInteractorState::Selecting => { XRInteractorState::Selecting => {
//welp now I gota actually make things do stuff lol //welp now I gota actually make things do stuff lol
let event = InteractionEvent { let event = InteractionEvent {
@@ -293,23 +314,29 @@ pub fn interactions(
None => (), None => (),
} }
} }
//still hate this
if hovered {
*state = XRInteractableState::Hover;
} else {
*state = XRInteractableState::Idle;
}
} }
} }
pub fn update_interactable_states( pub fn update_interactable_states(
mut events: EventReader<InteractionEvent>, mut events: EventReader<InteractionEvent>,
mut interactable_query: Query<(Entity, &mut XRInteractableState), (With<XRInteractable>)>, mut interactable_query: Query<(Entity, &mut XRInteractableState), With<XRInteractable>>,
) { ) {
//i legit hate this haha but it works
for (_entity, mut state) in interactable_query.iter_mut() {
*state = XRInteractableState::Idle;
}
for event in events.read() { for event in events.read() {
//lets change the state? //lets change the state?
match interactable_query.get_mut(event.interactable) { match interactable_query.get_mut(event.interactable) {
Ok((_entity, mut entity_state)) => { Ok((_entity, mut entity_state)) => {
if event.interactable_state > *entity_state {
// info!(
// "event.state: {:?}, interactable.state: {:?}",
// event.interactable_state, entity_state
// );
// info!("event has a higher state");
}
*entity_state = event.interactable_state; *entity_state = event.interactable_state;
} }
Err(_) => {} Err(_) => {}