Skip to content

Commit

Permalink
fix(objects/input): multimodal hand input
Browse files Browse the repository at this point in the history
  • Loading branch information
technobaboo committed Jun 7, 2024
1 parent 45b8324 commit 6931112
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
12 changes: 4 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ struct CliArgs {
#[clap(id = "PRIORITY", short = 'o', long = "overlay", action)]
overlay_priority: Option<u32>,

/// Don't create a tip input for controller because SOME RUNTIMES will lie
#[clap(long, action)]
disable_controller: bool,

/// Run a script when ready for clients to connect. If this is not set the script at $HOME/.config/stardust/startup will be ran if it exists.
#[clap(id = "PATH", short = 'e', long = "execute-startup-script", action)]
startup_script: Option<PathBuf>,
Expand Down Expand Up @@ -167,7 +163,7 @@ fn main() {
left.zip(right)
})
.flatten();
let mut controllers = (!cli_args.flatscreen && !cli_args.disable_controller)
let mut controllers = (!cli_args.flatscreen)
.then(|| {
let left = SkController::new(Handed::Left).ok();
let right = SkController::new(Handed::Right).ok();
Expand Down Expand Up @@ -216,7 +212,7 @@ fn main() {
SkClosures::run_app(
sk,
sk_event_loop,
|_sk, token| {
|sk, token| {
let _span = debug_span!("StereoKit step");
let _span = _span.enter();

Expand All @@ -230,8 +226,8 @@ fn main() {
mouse_pointer.update();
}
if let Some((left_hand, right_hand)) = &mut hands {
left_hand.update(!cli_args.disable_controller, token);
right_hand.update(!cli_args.disable_controller, token);
left_hand.update(sk, token);
right_hand.update(sk, token);
}
if let Some((left_controller, right_controller)) = &mut controllers {
left_controller.update(token);
Expand Down
6 changes: 4 additions & 2 deletions src/nodes/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ impl PulseSender {
}

fn handle_drop_receiver(&self, receiver: &PulseReceiver) {
let id = receiver.node.upgrade().unwrap().get_id();
let Some(node) = receiver.node.upgrade() else {
return;
};
self.aliases.remove_aspect(receiver);
self.field_aliases.remove_aspect(receiver.field.as_ref());
let Some(tx_node) = self.node.upgrade() else {
return;
};
let _ = pulse_sender_client::drop_receiver(&tx_node, id);
let _ = pulse_sender_client::drop_receiver(&tx_node, node.get_id());
}
}
impl Aspect for PulseSender {
Expand Down
15 changes: 8 additions & 7 deletions src/objects/input/sk_hand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use serde::{Deserialize, Serialize};
use stardust_xr::values::Datamap;
use std::f32::INFINITY;
use std::sync::Arc;
use stereokit_rust::sk::MainThreadToken;
use stereokit_rust::system::{HandJoint, Handed, Input, LinePoint, Lines};
use stereokit_rust::sk::{DisplayMode, MainThreadToken, Sk};
use stereokit_rust::system::{HandJoint, HandSource, Handed, Input, LinePoint, Lines};
use stereokit_rust::util::Color128;

fn convert_joint(joint: HandJoint) -> Joint {
Expand Down Expand Up @@ -58,14 +58,15 @@ impl SkHand {
datamap: Default::default(),
})
}
pub fn update(&mut self, controller_enabled: bool, token: &MainThreadToken) {
pub fn update(&mut self, sk: &Sk, token: &MainThreadToken) {
let sk_hand = Input::hand(self.handed);
let real_hand = Input::hand_source(self.handed) as u32 == HandSource::Articulated as u32;
if let InputDataType::Hand(hand) = &mut *self.input.data.lock() {
let controller_active =
controller_enabled && Input::controller(self.handed).is_tracked();

let input_node = self.input.spatial.node().unwrap();
input_node.set_enabled(!controller_active && sk_hand.tracked.is_active());
input_node.set_enabled(
(real_hand || sk.get_active_display_mode() == DisplayMode::Flatscreen)
&& sk_hand.tracked.is_active(),
);
if input_node.enabled() {
hand.thumb.tip = convert_joint(sk_hand.fingers[0][4]);
hand.thumb.distal = convert_joint(sk_hand.fingers[0][3]);
Expand Down

0 comments on commit 6931112

Please sign in to comment.