diff --git a/src/objects/input/sk_hand.rs b/src/objects/input/sk_hand.rs index efebb5a..b56a791 100644 --- a/src/objects/input/sk_hand.rs +++ b/src/objects/input/sk_hand.rs @@ -7,6 +7,7 @@ use crate::nodes::{ spatial::Spatial, Node, }; +use crate::objects::{ObjectHandle, SpatialRef}; use color_eyre::eyre::Result; use glam::{Mat4, Quat, Vec3}; use serde::{Deserialize, Serialize}; @@ -16,6 +17,7 @@ use std::sync::Arc; use stereokit_rust::sk::{DisplayMode, MainThreadToken, Sk}; use stereokit_rust::system::{HandJoint, HandSource, Handed, Input, LinePoint, Lines}; use stereokit_rust::util::Color128; +use zbus::Connection; fn convert_joint(joint: HandJoint) -> Joint { Joint { @@ -34,13 +36,23 @@ struct HandDatamap { pub struct SkHand { _node: OwnedNode, + palm_spatial: Arc, + palm_object: ObjectHandle, handed: Handed, input: Arc, capture: Option>, datamap: HandDatamap, } impl SkHand { - pub fn new(handed: Handed) -> Result { + pub fn new(connection: &Connection, handed: Handed) -> Result { + let (palm_spatial, palm_object) = SpatialRef::create( + connection, + &("/org/stardustxr/Hand/".to_string() + + match handed { + Handed::Left => "left", + _ => "right", + } + "/palm"), + ); let _node = Node::generate(&INTERNAL_CLIENT, false).add_to_scenegraph_owned()?; Spatial::add_to(&_node.0, None, Mat4::IDENTITY, false); let hand = InputDataType::Hand(Hand { @@ -53,6 +65,8 @@ impl SkHand { Input::hand_visible(handed, false); Ok(SkHand { _node, + palm_spatial, + palm_object, handed, input, capture: None, @@ -93,6 +107,12 @@ impl SkHand { hand.palm.radius = (sk_hand.fingers[2][0].radius + sk_hand.fingers[2][1].radius) * 0.5; + self.palm_spatial + .set_local_transform(Mat4::from_rotation_translation( + hand.palm.rotation.into(), + hand.palm.position.into(), + )); + hand.wrist.position = Vec3::from(sk_hand.wrist.position).into(); hand.wrist.rotation = Quat::from(sk_hand.wrist.orientation).into(); hand.wrist.radius = diff --git a/src/objects/mod.rs b/src/objects/mod.rs index 77e08d9..b4756c1 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -66,21 +66,26 @@ impl ServerObjects { }); } + tokio::task::spawn({ + let connection = connection.clone(); + async move { + connection + .request_name("org.stardustxr.Controllers") + .await + .unwrap(); + connection + .request_name("org.stardustxr.Hands") + .await + .unwrap(); + } + }); + let inputs = if sk.get_active_display_mode() == DisplayMode::MixedReality { - tokio::task::spawn({ - let connection = connection.clone(); - async move { - connection - .request_name("org.stardustxr.Controllers") - .await - .unwrap(); - } - }); Inputs::XR { controller_left: SkController::new(&connection, Handed::Left).unwrap(), controller_right: SkController::new(&connection, Handed::Right).unwrap(), - hand_left: SkHand::new(Handed::Left).unwrap(), - hand_right: SkHand::new(Handed::Right).unwrap(), + hand_left: SkHand::new(&connection, Handed::Left).unwrap(), + hand_right: SkHand::new(&connection, Handed::Right).unwrap(), eye_pointer: Device::has_eye_gaze() .then(EyePointer::new) .transpose() @@ -130,8 +135,8 @@ impl ServerObjects { // } if Input::key(Key::F8).is_just_inactive() { self.inputs = Inputs::Hands { - left: SkHand::new(Handed::Left).unwrap(), - right: SkHand::new(Handed::Right).unwrap(), + left: SkHand::new(&self.connection, Handed::Left).unwrap(), + right: SkHand::new(&self.connection, Handed::Right).unwrap(), }; } }