feat: new stereokit
This commit is contained in:
@@ -14,8 +14,7 @@ use nanoid::nanoid;
|
||||
use serde::Serialize;
|
||||
use stardust_xr::schemas::{flat::Datamap, flex::flexbuffers};
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
use stereokit::input::{ButtonState, Key, StereoKitInput};
|
||||
use stereokit::values::Ray as SkRay;
|
||||
use stereokit::{ray_from_mouse, ButtonState, Key, StereoKitMultiThread};
|
||||
use tracing::instrument;
|
||||
|
||||
const SK_KEYMAP: &str = include_str!("sk.kmp");
|
||||
@@ -58,10 +57,10 @@ impl MousePointer {
|
||||
})
|
||||
}
|
||||
#[instrument(level = "debug", name = "Update Flatscreen Pointer Ray", skip_all)]
|
||||
pub fn update(&self, sk: &impl StereoKitInput) {
|
||||
pub fn update(&self, sk: &impl StereoKitMultiThread) {
|
||||
let mouse = sk.input_mouse();
|
||||
|
||||
let ray = SkRay::from_mouse(&mouse);
|
||||
let ray = ray_from_mouse(mouse.pos).unwrap();
|
||||
self.spatial.set_local_transform(
|
||||
Mat4::look_to_rh(ray.pos.into(), -Vec3::from(ray.dir), vec3(0.0, 1.0, 0.0)).inverse(),
|
||||
);
|
||||
@@ -71,7 +70,7 @@ impl MousePointer {
|
||||
let mut map = fbb.start_map();
|
||||
map.push(
|
||||
"select",
|
||||
if sk.input_key(Key::MouseLeft).contains(ButtonState::Active) {
|
||||
if sk.input_key(Key::MouseLeft).contains(ButtonState::ACTIVE) {
|
||||
1.0f32
|
||||
} else {
|
||||
0.0f32
|
||||
@@ -79,7 +78,7 @@ impl MousePointer {
|
||||
);
|
||||
map.push(
|
||||
"grab",
|
||||
if sk.input_key(Key::MouseRight).contains(ButtonState::Active) {
|
||||
if sk.input_key(Key::MouseRight).contains(ButtonState::ACTIVE) {
|
||||
1.0f32
|
||||
} else {
|
||||
0.0f32
|
||||
@@ -95,7 +94,7 @@ impl MousePointer {
|
||||
self.send_keyboard_input(sk);
|
||||
}
|
||||
|
||||
fn send_keyboard_input(&self, sk: &impl StereoKitInput) {
|
||||
fn send_keyboard_input(&self, sk: &impl StereoKitMultiThread) {
|
||||
let rx = PULSE_RECEIVER_REGISTRY
|
||||
.get_valid_contents()
|
||||
.into_iter()
|
||||
@@ -127,9 +126,9 @@ impl MousePointer {
|
||||
.filter_map(|i| Some((i, Key::try_from(i).ok()?)))
|
||||
.map(|(i, k)| (i - 8, sk.input_key(k)));
|
||||
for (key, state) in keys {
|
||||
if state.contains(ButtonState::JustActive) {
|
||||
if state.contains(ButtonState::JUST_ACTIVE) {
|
||||
keys_down.push(key);
|
||||
} else if state.contains(ButtonState::JustInactive) {
|
||||
} else if state.contains(ButtonState::JUST_INACTIVE) {
|
||||
keys_up.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use stardust_xr::{
|
||||
values::Transform,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use stereokit::input::{ButtonState, Handed, StereoKitInput};
|
||||
use stereokit::{ButtonState, Handed, StereoKitMultiThread};
|
||||
use tracing::instrument;
|
||||
|
||||
pub struct SkController {
|
||||
@@ -35,9 +35,9 @@ impl SkController {
|
||||
})
|
||||
}
|
||||
#[instrument(level = "debug", name = "Update StereoKit Tip Input Method", skip_all)]
|
||||
pub fn update(&mut self, sk: &impl StereoKitInput) {
|
||||
pub fn update(&mut self, sk: &impl StereoKitMultiThread) {
|
||||
let controller = sk.input_controller(self.handed);
|
||||
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::Active);
|
||||
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE);
|
||||
if *self.input.enabled.lock() {
|
||||
self.input.spatial.set_local_transform_components(
|
||||
None,
|
||||
|
||||
@@ -14,16 +14,13 @@ use stardust_xr::schemas::{
|
||||
flex::flexbuffers,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use stereokit::{
|
||||
input::{ButtonState, Handed, Joint as SkJoint, StereoKitInput},
|
||||
lifecycle::StereoKitDraw,
|
||||
};
|
||||
use stereokit::{ButtonState, HandJoint, Handed, StereoKitMultiThread};
|
||||
use tracing::instrument;
|
||||
|
||||
fn convert_joint(joint: SkJoint) -> Joint {
|
||||
fn convert_joint(joint: HandJoint) -> Joint {
|
||||
Joint {
|
||||
position: joint.position,
|
||||
rotation: joint.orientation,
|
||||
position: joint.position.into(),
|
||||
rotation: joint.orientation.into(),
|
||||
radius: joint.radius,
|
||||
}
|
||||
}
|
||||
@@ -51,12 +48,12 @@ impl SkHand {
|
||||
})
|
||||
}
|
||||
#[instrument(level = "debug", name = "Update Hand Input Method", skip_all)]
|
||||
pub fn update(&mut self, sk: &StereoKitDraw) {
|
||||
pub fn update(&mut self, sk: &impl StereoKitMultiThread) {
|
||||
let sk_hand = sk.input_hand(self.handed);
|
||||
if let InputType::Hand(hand) = &mut *self.input.specialization.lock() {
|
||||
let controller = sk.input_controller(self.handed);
|
||||
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::Inactive)
|
||||
&& sk_hand.tracked_state.contains(ButtonState::Active);
|
||||
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE)
|
||||
&& sk_hand.tracked_state.contains(ButtonState::ACTIVE);
|
||||
if *self.input.enabled.lock() {
|
||||
hand.base.thumb.tip = convert_joint(sk_hand.fingers[0][4]);
|
||||
hand.base.thumb.distal = convert_joint(sk_hand.fingers[0][3]);
|
||||
@@ -76,13 +73,13 @@ impl SkHand {
|
||||
finger.metacarpal = convert_joint(sk_finger[0]);
|
||||
}
|
||||
|
||||
hand.base.palm.position = sk_hand.palm.position;
|
||||
hand.base.palm.rotation = sk_hand.palm.orientation;
|
||||
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;
|
||||
hand.base.wrist.rotation = sk_hand.wrist.orientation;
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user