feat(objects): add palm
This commit is contained in:
@@ -7,6 +7,7 @@ use crate::nodes::{
|
|||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
Node,
|
Node,
|
||||||
};
|
};
|
||||||
|
use crate::objects::{ObjectHandle, SpatialRef};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use glam::{Mat4, Quat, Vec3};
|
use glam::{Mat4, Quat, Vec3};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -16,6 +17,7 @@ use std::sync::Arc;
|
|||||||
use stereokit_rust::sk::{DisplayMode, MainThreadToken, Sk};
|
use stereokit_rust::sk::{DisplayMode, MainThreadToken, Sk};
|
||||||
use stereokit_rust::system::{HandJoint, HandSource, Handed, Input, LinePoint, Lines};
|
use stereokit_rust::system::{HandJoint, HandSource, Handed, Input, LinePoint, Lines};
|
||||||
use stereokit_rust::util::Color128;
|
use stereokit_rust::util::Color128;
|
||||||
|
use zbus::Connection;
|
||||||
|
|
||||||
fn convert_joint(joint: HandJoint) -> Joint {
|
fn convert_joint(joint: HandJoint) -> Joint {
|
||||||
Joint {
|
Joint {
|
||||||
@@ -34,13 +36,23 @@ struct HandDatamap {
|
|||||||
|
|
||||||
pub struct SkHand {
|
pub struct SkHand {
|
||||||
_node: OwnedNode,
|
_node: OwnedNode,
|
||||||
|
palm_spatial: Arc<Spatial>,
|
||||||
|
palm_object: ObjectHandle<SpatialRef>,
|
||||||
handed: Handed,
|
handed: Handed,
|
||||||
input: Arc<InputMethod>,
|
input: Arc<InputMethod>,
|
||||||
capture: Option<Arc<InputHandler>>,
|
capture: Option<Arc<InputHandler>>,
|
||||||
datamap: HandDatamap,
|
datamap: HandDatamap,
|
||||||
}
|
}
|
||||||
impl SkHand {
|
impl SkHand {
|
||||||
pub fn new(handed: Handed) -> Result<Self> {
|
pub fn new(connection: &Connection, handed: Handed) -> Result<Self> {
|
||||||
|
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()?;
|
let _node = Node::generate(&INTERNAL_CLIENT, false).add_to_scenegraph_owned()?;
|
||||||
Spatial::add_to(&_node.0, None, Mat4::IDENTITY, false);
|
Spatial::add_to(&_node.0, None, Mat4::IDENTITY, false);
|
||||||
let hand = InputDataType::Hand(Hand {
|
let hand = InputDataType::Hand(Hand {
|
||||||
@@ -53,6 +65,8 @@ impl SkHand {
|
|||||||
Input::hand_visible(handed, false);
|
Input::hand_visible(handed, false);
|
||||||
Ok(SkHand {
|
Ok(SkHand {
|
||||||
_node,
|
_node,
|
||||||
|
palm_spatial,
|
||||||
|
palm_object,
|
||||||
handed,
|
handed,
|
||||||
input,
|
input,
|
||||||
capture: None,
|
capture: None,
|
||||||
@@ -93,6 +107,12 @@ impl SkHand {
|
|||||||
hand.palm.radius =
|
hand.palm.radius =
|
||||||
(sk_hand.fingers[2][0].radius + sk_hand.fingers[2][1].radius) * 0.5;
|
(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.position = Vec3::from(sk_hand.wrist.position).into();
|
||||||
hand.wrist.rotation = Quat::from(sk_hand.wrist.orientation).into();
|
hand.wrist.rotation = Quat::from(sk_hand.wrist.orientation).into();
|
||||||
hand.wrist.radius =
|
hand.wrist.radius =
|
||||||
|
|||||||
@@ -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 {
|
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 {
|
Inputs::XR {
|
||||||
controller_left: SkController::new(&connection, Handed::Left).unwrap(),
|
controller_left: SkController::new(&connection, Handed::Left).unwrap(),
|
||||||
controller_right: SkController::new(&connection, Handed::Right).unwrap(),
|
controller_right: SkController::new(&connection, Handed::Right).unwrap(),
|
||||||
hand_left: SkHand::new(Handed::Left).unwrap(),
|
hand_left: SkHand::new(&connection, Handed::Left).unwrap(),
|
||||||
hand_right: SkHand::new(Handed::Right).unwrap(),
|
hand_right: SkHand::new(&connection, Handed::Right).unwrap(),
|
||||||
eye_pointer: Device::has_eye_gaze()
|
eye_pointer: Device::has_eye_gaze()
|
||||||
.then(EyePointer::new)
|
.then(EyePointer::new)
|
||||||
.transpose()
|
.transpose()
|
||||||
@@ -130,8 +135,8 @@ impl ServerObjects {
|
|||||||
// }
|
// }
|
||||||
if Input::key(Key::F8).is_just_inactive() {
|
if Input::key(Key::F8).is_just_inactive() {
|
||||||
self.inputs = Inputs::Hands {
|
self.inputs = Inputs::Hands {
|
||||||
left: SkHand::new(Handed::Left).unwrap(),
|
left: SkHand::new(&self.connection, Handed::Left).unwrap(),
|
||||||
right: SkHand::new(Handed::Right).unwrap(),
|
right: SkHand::new(&self.connection, Handed::Right).unwrap(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user