jank socket interactor
This commit is contained in:
@@ -5,8 +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::{
|
||||||
interactions, draw_interaction_gizmos, update_interactable_states, InteractionEvent,
|
draw_interaction_gizmos, draw_socket_gizmos, interactions, update_interactable_states,
|
||||||
XRDirectInteractor, XRInteractable, XRInteractableState, XRInteractorState, XRRayInteractor,
|
InteractionEvent, XRDirectInteractor, XRInteractable, XRInteractableState, XRInteractorState,
|
||||||
|
XRRayInteractor, XRSocketInteractor, socket_interactions,
|
||||||
};
|
};
|
||||||
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};
|
||||||
@@ -33,7 +34,9 @@ fn main() {
|
|||||||
Update,
|
Update,
|
||||||
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, interactions)
|
.add_systems(Update, interactions)
|
||||||
|
.add_systems(Update, socket_interactions)
|
||||||
.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.after(interactions))
|
||||||
.add_systems(Update, update_grabbables.after(update_interactable_states))
|
.add_systems(Update, update_grabbables.after(update_interactable_states))
|
||||||
@@ -60,13 +63,16 @@ fn setup(
|
|||||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
// cube
|
// socket
|
||||||
commands.spawn(PbrBundle {
|
commands.spawn((
|
||||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
SpatialBundle {
|
||||||
material: materials.add(Color::rgb(0.8, 0.0, 0.0).into()),
|
transform: Transform::from_xyz(0.0, 0.5, 1.0),
|
||||||
transform: Transform::from_xyz(0.0, 0.5, 1.0),
|
..default()
|
||||||
..default()
|
},
|
||||||
});
|
XRInteractorState::Selecting,
|
||||||
|
XRSocketInteractor,
|
||||||
|
));
|
||||||
|
|
||||||
// light
|
// light
|
||||||
commands.spawn(PointLightBundle {
|
commands.spawn(PointLightBundle {
|
||||||
point_light: PointLight {
|
point_light: PointLight {
|
||||||
@@ -167,7 +173,11 @@ 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, With<XRDirectInteractor>, Without<Grabbable>)>,
|
interactor_query: Query<(
|
||||||
|
&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() {
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ pub struct XRDirectInteractor;
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct XRRayInteractor;
|
pub struct XRRayInteractor;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct XRSocketInteractor;
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy)]
|
#[derive(Component, Clone, Copy)]
|
||||||
pub enum XRInteractableState {
|
pub enum XRInteractableState {
|
||||||
Idle,
|
Idle,
|
||||||
@@ -40,6 +43,27 @@ impl Default for XRInteractorState {
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct XRInteractable;
|
pub struct XRInteractable;
|
||||||
|
|
||||||
|
//i guess really these should be seperate
|
||||||
|
pub fn draw_socket_gizmos(
|
||||||
|
mut gizmos: Gizmos,
|
||||||
|
interactor_query: Query<(
|
||||||
|
&GlobalTransform,
|
||||||
|
&XRInteractorState,
|
||||||
|
Entity,
|
||||||
|
&XRSocketInteractor,
|
||||||
|
)>,
|
||||||
|
) {
|
||||||
|
for (global, state, _entity, _socket) in interactor_query.iter() {
|
||||||
|
let mut transform = global.compute_transform().clone();
|
||||||
|
transform.scale = Vec3::splat(0.1);
|
||||||
|
let color = match state {
|
||||||
|
XRInteractorState::Idle => Color::BLUE,
|
||||||
|
XRInteractorState::Selecting => Color::PURPLE,
|
||||||
|
};
|
||||||
|
gizmos.cuboid(transform, color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn draw_interaction_gizmos(
|
pub fn draw_interaction_gizmos(
|
||||||
mut gizmos: Gizmos,
|
mut gizmos: Gizmos,
|
||||||
interactable_query: Query<
|
interactable_query: Query<
|
||||||
@@ -118,6 +142,59 @@ pub struct InteractionEvent {
|
|||||||
pub interactable_state: XRInteractableState,
|
pub interactable_state: XRInteractableState,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//yeah these need to be seperate somehow
|
||||||
|
pub fn socket_interactions(
|
||||||
|
mut interactable_query: Query<
|
||||||
|
(&GlobalTransform, &mut XRInteractableState, Entity),
|
||||||
|
(With<XRInteractable>, Without<XRSocketInteractor>),
|
||||||
|
>,
|
||||||
|
interactor_query: Query<
|
||||||
|
(
|
||||||
|
&GlobalTransform,
|
||||||
|
&XRInteractorState,
|
||||||
|
Entity,
|
||||||
|
&XRSocketInteractor,
|
||||||
|
),
|
||||||
|
(Without<XRInteractable>),
|
||||||
|
>,
|
||||||
|
mut writer: EventWriter<InteractionEvent>,
|
||||||
|
) {
|
||||||
|
for interactable in interactable_query.iter() {
|
||||||
|
//for the interactbles
|
||||||
|
for socket in interactor_query.iter() {
|
||||||
|
let interactor_global_transform = socket.0;
|
||||||
|
let xr_interactable_global_transform = interactable.0;
|
||||||
|
let interactor_state = socket.1;
|
||||||
|
//check for sphere overlaps
|
||||||
|
let size = 0.1;
|
||||||
|
if interactor_global_transform
|
||||||
|
.compute_transform()
|
||||||
|
.translation
|
||||||
|
.distance_squared(
|
||||||
|
xr_interactable_global_transform
|
||||||
|
.compute_transform()
|
||||||
|
.translation,
|
||||||
|
)
|
||||||
|
< (size * size) * 2.0
|
||||||
|
{
|
||||||
|
//check for selections first
|
||||||
|
match interactor_state {
|
||||||
|
XRInteractorState::Idle => (), //welp this wont work,
|
||||||
|
XRInteractorState::Selecting => {
|
||||||
|
//welp now I gota actually make things do stuff lol
|
||||||
|
let event = InteractionEvent {
|
||||||
|
interactor: socket.2,
|
||||||
|
interactable: interactable.2,
|
||||||
|
interactable_state: XRInteractableState::Select,
|
||||||
|
};
|
||||||
|
writer.send(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn interactions(
|
pub fn interactions(
|
||||||
mut interactable_query: Query<
|
mut interactable_query: Query<
|
||||||
(&GlobalTransform, &mut XRInteractableState, Entity),
|
(&GlobalTransform, &mut XRInteractableState, Entity),
|
||||||
@@ -235,8 +312,7 @@ pub fn update_interactable_states(
|
|||||||
Ok((_entity, mut entity_state)) => {
|
Ok((_entity, mut entity_state)) => {
|
||||||
*entity_state = event.interactable_state;
|
*entity_state = event.interactable_state;
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user