fix(input): extra hand data
This commit is contained in:
@@ -7,16 +7,21 @@ use std::sync::Arc;
|
||||
|
||||
use super::{DistanceLink, InputSpecialization};
|
||||
|
||||
impl InputSpecialization for HandT {
|
||||
pub struct Hand {
|
||||
pub base: HandT,
|
||||
pub pinch_strength: f32,
|
||||
pub grab_strength: f32,
|
||||
}
|
||||
impl InputSpecialization for Hand {
|
||||
fn distance(&self, space: &Arc<Spatial>, field: &Field) -> f32 {
|
||||
let mut min_distance = f32::MAX;
|
||||
|
||||
for tip in [
|
||||
&self.thumb.tip.position,
|
||||
&self.index.tip.position,
|
||||
&self.middle.tip.position,
|
||||
&self.ring.tip.position,
|
||||
&self.little.tip.position,
|
||||
&self.base.thumb.tip.position,
|
||||
&self.base.index.tip.position,
|
||||
&self.base.middle.tip.position,
|
||||
&self.base.ring.tip.position,
|
||||
&self.base.little.tip.position,
|
||||
] {
|
||||
min_distance = min_distance.min(field.distance(space, vec3a(tip.x, tip.y, tip.z)));
|
||||
}
|
||||
@@ -32,7 +37,7 @@ impl InputSpecialization for HandT {
|
||||
InputDataRaw,
|
||||
flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>,
|
||||
) {
|
||||
let mut hand = self.clone();
|
||||
let mut hand = self.base.clone();
|
||||
let mut joints: Vec<&mut JointT> = Vec::new();
|
||||
|
||||
joints.extend([&mut hand.palm, &mut hand.wrist]);
|
||||
@@ -77,7 +82,9 @@ impl InputSpecialization for HandT {
|
||||
fn serialize_datamap(&self) -> Vec<u8> {
|
||||
let mut fbb = flexbuffers::Builder::default();
|
||||
let mut map = fbb.start_map();
|
||||
map.push("right", self.right);
|
||||
map.push("right", self.base.right);
|
||||
map.push("pinchStrength", self.pinch_strength);
|
||||
map.push("grabStrength", self.grab_strength);
|
||||
map.end_map();
|
||||
fbb.view().to_vec()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod hand;
|
||||
pub mod pointer;
|
||||
|
||||
use self::hand::Hand;
|
||||
use self::pointer::Pointer;
|
||||
|
||||
use super::fields::Field;
|
||||
@@ -14,7 +15,6 @@ use glam::Mat4;
|
||||
use nanoid::nanoid;
|
||||
use parking_lot::Mutex;
|
||||
use stardust_xr_schemas::input::{InputData, InputDataArgs, InputDataRaw};
|
||||
use stardust_xr_schemas::input_hand::HandT;
|
||||
use std::ops::Deref;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::{Arc, Weak};
|
||||
@@ -37,7 +37,7 @@ pub trait InputSpecialization: Send + Sync {
|
||||
}
|
||||
pub enum InputType {
|
||||
Pointer(Pointer),
|
||||
Hand(Box<HandT>),
|
||||
Hand(Box<Hand>),
|
||||
}
|
||||
impl Deref for InputType {
|
||||
type Target = dyn InputSpecialization;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::nodes::{
|
||||
input::{InputMethod, InputType},
|
||||
input::{hand::Hand, InputMethod, InputType},
|
||||
spatial::Spatial,
|
||||
};
|
||||
use glam::Mat4;
|
||||
@@ -29,7 +29,11 @@ impl SkHand {
|
||||
SkHand {
|
||||
hand: InputMethod::new(
|
||||
Spatial::new(Weak::new(), None, Mat4::IDENTITY),
|
||||
InputType::Hand(Box::new(sk_hand)),
|
||||
InputType::Hand(Box::new(Hand {
|
||||
base: sk_hand,
|
||||
pinch_strength: 0.0,
|
||||
grab_strength: 0.0,
|
||||
})),
|
||||
),
|
||||
handed,
|
||||
}
|
||||
@@ -37,36 +41,41 @@ impl SkHand {
|
||||
pub fn update(&mut self, sk: &StereoKit) {
|
||||
if let InputType::Hand(hand) = &mut *self.hand.specialization.lock() {
|
||||
let sk_hand = *sk.input_hand(self.handed);
|
||||
// *self.hand.enabled.lock() = sk_hand.tracked_state.is_active();
|
||||
// if sk_hand.tracked_state.is_active() {
|
||||
hand.thumb.tip = convert_joint(sk_hand.fingers[0][4]);
|
||||
hand.thumb.distal = convert_joint(sk_hand.fingers[0][3]);
|
||||
hand.thumb.proximal = convert_joint(sk_hand.fingers[0][2]);
|
||||
hand.thumb.metacarpal = convert_joint(sk_hand.fingers[0][1]);
|
||||
*self.hand.enabled.lock() = sk_hand.tracked_state.is_active();
|
||||
if sk_hand.tracked_state.is_active() {
|
||||
hand.base.thumb.tip = convert_joint(sk_hand.fingers[0][4]);
|
||||
hand.base.thumb.distal = convert_joint(sk_hand.fingers[0][3]);
|
||||
hand.base.thumb.proximal = convert_joint(sk_hand.fingers[0][2]);
|
||||
hand.base.thumb.metacarpal = convert_joint(sk_hand.fingers[0][1]);
|
||||
|
||||
for (finger, sk_finger) in [
|
||||
(&mut hand.index, sk_hand.fingers[1]),
|
||||
(&mut hand.middle, sk_hand.fingers[2]),
|
||||
(&mut hand.ring, sk_hand.fingers[3]),
|
||||
(&mut hand.little, sk_hand.fingers[4]),
|
||||
] {
|
||||
finger.tip = convert_joint(sk_finger[4]);
|
||||
finger.distal = convert_joint(sk_finger[3]);
|
||||
finger.intermediate = convert_joint(sk_finger[2]);
|
||||
finger.proximal = convert_joint(sk_finger[1]);
|
||||
finger.metacarpal = convert_joint(sk_finger[0]);
|
||||
for (finger, sk_finger) in [
|
||||
(&mut hand.base.index, sk_hand.fingers[1]),
|
||||
(&mut hand.base.middle, sk_hand.fingers[2]),
|
||||
(&mut hand.base.ring, sk_hand.fingers[3]),
|
||||
(&mut hand.base.little, sk_hand.fingers[4]),
|
||||
] {
|
||||
finger.tip = convert_joint(sk_finger[4]);
|
||||
finger.distal = convert_joint(sk_finger[3]);
|
||||
finger.intermediate = convert_joint(sk_finger[2]);
|
||||
finger.proximal = convert_joint(sk_finger[1]);
|
||||
finger.metacarpal = convert_joint(sk_finger[0]);
|
||||
}
|
||||
|
||||
hand.base.palm.position = sk_hand.palm.position.into();
|
||||
hand.base.palm.rotation = sk_hand.palm.orientation.into();
|
||||
hand.base.palm.radius =
|
||||
(sk_hand.fingers[2][0].radius + sk_hand.fingers[2][1].radius) * 0.5;
|
||||
|
||||
hand.base.wrist.position = sk_hand.wrist.position.into();
|
||||
hand.base.wrist.rotation = sk_hand.wrist.orientation.into();
|
||||
hand.base.wrist.radius =
|
||||
(sk_hand.fingers[0][0].radius + sk_hand.fingers[4][0].radius) * 0.5;
|
||||
|
||||
hand.base.elbow = None;
|
||||
|
||||
hand.pinch_strength = sk_hand.pinch_activation;
|
||||
hand.grab_strength = sk_hand.grip_activation;
|
||||
}
|
||||
|
||||
hand.palm.position = sk_hand.palm.position.into();
|
||||
hand.palm.rotation = sk_hand.palm.orientation.into();
|
||||
hand.palm.radius = (sk_hand.fingers[2][0].radius + sk_hand.fingers[2][1].radius) * 0.5;
|
||||
|
||||
hand.wrist.position = sk_hand.wrist.position.into();
|
||||
hand.wrist.rotation = sk_hand.wrist.orientation.into();
|
||||
hand.wrist.radius = (sk_hand.fingers[0][0].radius + sk_hand.fingers[4][0].radius) * 0.5;
|
||||
|
||||
hand.elbow = None;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user