From 0f838074b108f7a949c5fa9b9b5b614de984e269 Mon Sep 17 00:00:00 2001 From: Jay Christy Date: Sun, 12 Nov 2023 00:51:41 -0500 Subject: [PATCH 1/2] git --- examples/demo/src/lib.rs | 89 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 4 deletions(-) diff --git a/examples/demo/src/lib.rs b/examples/demo/src/lib.rs index 196975a3..b4eaeedb 100644 --- a/examples/demo/src/lib.rs +++ b/examples/demo/src/lib.rs @@ -11,7 +11,7 @@ use bevy::{ Schedule, SpatialBundle, StandardMaterial, Startup, Transform, Update, Vec3, Vec3Swizzles, With, Without, World, }, - time::{Fixed, Time, Timer}, + time::{Fixed, Time, Timer, TimerMode}, transform::TransformSystem, }; use bevy_oxr::{ @@ -54,7 +54,7 @@ pub fn main() { .add_plugins(OpenXrDebugRenderer) //rapier goes here .add_plugins(RapierPhysicsPlugin::::default().with_default_system_setup(false)) - // .add_plugins(RapierDebugRenderPlugin::default()) + .add_plugins(RapierDebugRenderPlugin::default()) //lets setup the starting scene .add_systems(Startup, setup_scene) .add_systems(Startup, spawn_controllers_example) //you need to spawn controllers or it crashes TODO:: Fix this @@ -95,7 +95,14 @@ pub fn main() { .add_systems( FixedUpdate, update_physics_hands.before(PhysicsSet::SyncBackend), - ); + ) + .add_event::() + .add_systems(Update, handle_ghost_hand_events.after(update_grabbables)) + .insert_resource(GhostTimers { + left: Timer::from_seconds(0.25, TimerMode::Once), + right: Timer::from_seconds(0.25, TimerMode::Once), + }) + .add_systems(Update, watch_ghost_timers.before(handle_ghost_hand_events)); //configure rapier sets let mut physics_schedule = Schedule::new(PhysicsSchedule); @@ -166,6 +173,7 @@ fn spawn_controllers_example(mut commands: Commands) { XRDirectInteractor, XRInteractorState::default(), XRSelection::default(), + Hand::Left, )); //right hand commands.spawn(( @@ -176,6 +184,7 @@ fn spawn_controllers_example(mut commands: Commands) { XRDirectInteractor, XRInteractorState::default(), XRSelection::default(), + Hand::Right, )); } @@ -609,6 +618,65 @@ fn prototype_interaction_input( } } +//this terribly named event is for transitioning the physics hand in an out of existent so we can drop things better +#[derive(Event)] +pub struct GhostHandEvent { + pub hand: Hand, + pub desired_state: bool, +} +#[derive(Resource)] +pub struct GhostTimers { + pub left: Timer, + pub right: Timer, +} + +pub fn handle_ghost_hand_events( + mut events: EventReader, + mut bones: Query<(&Hand, &mut CollisionGroups, With)>, +) { + for event in events.read() { + info!( + "Ghost hand Event: {:?}, {:?}", + event.hand, event.desired_state + ); + //do work + for mut bone in bones.iter_mut() { + match *bone.0 == event.hand { + true => match event.desired_state { + true => bone.1.filters = Group::NONE, + false => bone.1.filters = Group::from_bits(0b0001).unwrap(), + }, + false => (), + } + } + } +} + +pub fn watch_ghost_timers( + mut timers: ResMut, + mut writer: EventWriter, + time: Res