added ugly exclusive grabbing
This commit is contained in:
@@ -2,10 +2,10 @@ use bevy::{
|
|||||||
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
|
||||||
log::info,
|
log::info,
|
||||||
prelude::{
|
prelude::{
|
||||||
default, shape, App, Assets, Color, Commands, Component, Event, EventReader, EventWriter,
|
default, shape, App, Assets, Color, Commands, Component, Entity, Event, EventReader,
|
||||||
GlobalTransform, IntoSystemConfigs, IntoSystemSetConfigs, Mesh, PbrBundle, PostUpdate,
|
EventWriter, GlobalTransform, IntoSystemConfigs, IntoSystemSetConfigs, Mesh, PbrBundle,
|
||||||
Query, Res, ResMut, Resource, SpatialBundle, StandardMaterial, Startup, Transform, Update,
|
PostUpdate, Query, Res, ResMut, Resource, SpatialBundle, StandardMaterial, Startup,
|
||||||
With, Without,
|
Transform, Update, With, Without,
|
||||||
},
|
},
|
||||||
time::{Time, Timer},
|
time::{Time, Timer},
|
||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
@@ -18,7 +18,7 @@ use bevy_openxr::{
|
|||||||
interactions::{
|
interactions::{
|
||||||
draw_interaction_gizmos, draw_socket_gizmos, interactions, socket_interactions,
|
draw_interaction_gizmos, draw_socket_gizmos, interactions, socket_interactions,
|
||||||
update_interactable_states, InteractionEvent, Touched, XRDirectInteractor,
|
update_interactable_states, InteractionEvent, Touched, XRDirectInteractor,
|
||||||
XRInteractable, XRInteractableState, XRInteractorState, XRRayInteractor,
|
XRInteractable, XRInteractableState, XRInteractorState, XRSelection,
|
||||||
},
|
},
|
||||||
oculus_touch::OculusController,
|
oculus_touch::OculusController,
|
||||||
prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig},
|
prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig},
|
||||||
@@ -79,8 +79,7 @@ fn main() {
|
|||||||
bevy::time::TimerMode::Once,
|
bevy::time::TimerMode::Once,
|
||||||
)))
|
)))
|
||||||
.add_systems(Update, request_cube_spawn)
|
.add_systems(Update, request_cube_spawn)
|
||||||
.add_systems(Update, cube_spawner.after(request_cube_spawn))
|
.add_systems(Update, cube_spawner.after(request_cube_spawn));
|
||||||
;
|
|
||||||
|
|
||||||
//configure rapier sets
|
//configure rapier sets
|
||||||
app.configure_sets(
|
app.configure_sets(
|
||||||
@@ -121,6 +120,7 @@ fn spawn_controllers_example(mut commands: Commands) {
|
|||||||
SpatialBundle::default(),
|
SpatialBundle::default(),
|
||||||
XRDirectInteractor,
|
XRDirectInteractor,
|
||||||
XRInteractorState::default(),
|
XRInteractorState::default(),
|
||||||
|
XRSelection::default(),
|
||||||
));
|
));
|
||||||
//right hand
|
//right hand
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
@@ -130,6 +130,7 @@ fn spawn_controllers_example(mut commands: Commands) {
|
|||||||
SpatialBundle::default(),
|
SpatialBundle::default(),
|
||||||
XRDirectInteractor,
|
XRDirectInteractor,
|
||||||
XRInteractorState::default(),
|
XRInteractorState::default(),
|
||||||
|
XRSelection::default(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,12 +248,18 @@ 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,
|
||||||
&mut Transform,
|
&mut Transform,
|
||||||
With<Grabbable>,
|
With<Grabbable>,
|
||||||
Without<XRDirectInteractor>,
|
Without<XRDirectInteractor>,
|
||||||
Option<&mut RigidBody>,
|
Option<&mut RigidBody>,
|
||||||
)>,
|
)>,
|
||||||
interactor_query: Query<(&GlobalTransform, &XRInteractorState, Without<Grabbable>)>,
|
mut interactor_query: Query<(
|
||||||
|
&GlobalTransform,
|
||||||
|
&XRInteractorState,
|
||||||
|
&mut XRSelection,
|
||||||
|
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() {
|
||||||
@@ -261,24 +268,48 @@ pub fn update_grabbables(
|
|||||||
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_mut(event.interactor) {
|
||||||
Ok(interactor_transform) => {
|
Ok(mut interactor_transform) => {
|
||||||
|
match *interactor_transform.2 {
|
||||||
|
XRSelection::Empty => {
|
||||||
match interactor_transform.1 {
|
match interactor_transform.1 {
|
||||||
XRInteractorState::Idle => match grabbable_transform.3 {
|
XRInteractorState::Idle => match grabbable_transform.4 {
|
||||||
Some(mut thing) => {
|
Some(mut thing) => {
|
||||||
*thing = RigidBody::Dynamic;
|
*thing = RigidBody::Dynamic;
|
||||||
|
*interactor_transform.2 = XRSelection::Empty;
|
||||||
}
|
}
|
||||||
None => (),
|
None => (),
|
||||||
},
|
},
|
||||||
XRInteractorState::Selecting => {
|
XRInteractorState::Selecting => {
|
||||||
// info!("its a direct interactor?");
|
// info!("its a direct interactor?");
|
||||||
match grabbable_transform.3 {
|
match grabbable_transform.4 {
|
||||||
Some(mut thing) => {
|
Some(mut thing) => {
|
||||||
*thing = RigidBody::KinematicPositionBased;
|
*thing = RigidBody::KinematicPositionBased;
|
||||||
|
*interactor_transform.2 =
|
||||||
|
XRSelection::Full(grabbable_transform.0);
|
||||||
}
|
}
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
*grabbable_transform.0 = interactor_transform.0.compute_transform();
|
*grabbable_transform.1 =
|
||||||
|
interactor_transform.0.compute_transform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XRSelection::Full(ent) => {
|
||||||
|
info!("nah bro we holding something");
|
||||||
|
match grabbable_transform.0 == ent {
|
||||||
|
true => {
|
||||||
|
*grabbable_transform.1 =
|
||||||
|
interactor_transform.0.compute_transform();
|
||||||
|
}
|
||||||
|
false => {}
|
||||||
|
}
|
||||||
|
match interactor_transform.1 {
|
||||||
|
XRInteractorState::Idle => {
|
||||||
|
*interactor_transform.2 = XRSelection::Empty
|
||||||
|
}
|
||||||
|
XRInteractorState::Selecting => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,16 @@ impl Default for XRInteractorState {
|
|||||||
XRInteractorState::Idle
|
XRInteractorState::Idle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Component)]
|
||||||
|
pub enum XRSelection {
|
||||||
|
Empty,
|
||||||
|
Full(Entity)
|
||||||
|
}
|
||||||
|
impl Default for XRSelection {
|
||||||
|
fn default() -> Self {
|
||||||
|
XRSelection::Empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct XRInteractable;
|
pub struct XRInteractable;
|
||||||
|
|||||||
Reference in New Issue
Block a user