feat: upgrade stardust-xr version

This commit is contained in:
Nova
2022-10-14 01:11:54 -04:00
parent edc7eefbbc
commit cdd38da4ee
9 changed files with 70 additions and 109 deletions

View File

@@ -1,13 +1,14 @@
use crate::nodes::fields::Field;
use crate::nodes::spatial::Spatial;
use glam::{vec3a, Mat4};
use stardust_xr::schemas::{common::JointT, input::InputDataRaw, input_hand::HandT};
use stardust_xr::schemas::flat::{Datamap, Hand as FlatHand, InputDataType, Joint};
use std::sync::Arc;
use super::{DistanceLink, InputSpecialization};
#[derive(Debug, Default)]
pub struct Hand {
pub base: HandT,
pub base: FlatHand,
pub pinch_strength: f32,
pub grab_strength: f32,
}
@@ -29,15 +30,11 @@ impl InputSpecialization for Hand {
}
fn serialize(
&self,
fbb: &mut flatbuffers::FlatBufferBuilder,
_distance_link: &DistanceLink,
local_to_handler_matrix: Mat4,
) -> (
InputDataRaw,
flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>,
) {
let mut hand = self.base.clone();
let mut joints: Vec<&mut JointT> = Vec::new();
) -> InputDataType {
let mut hand = self.base;
let mut joints: Vec<&mut Joint> = Vec::new();
joints.extend([&mut hand.palm, &mut hand.wrist]);
if let Some(elbow) = &mut hand.elbow {
@@ -65,26 +62,23 @@ impl InputSpecialization for Hand {
]);
for joint in joints {
let rotation: mint::Quaternion<f32> = joint.rotation.clone().into();
let position: mint::Vector3<f32> = joint.position.clone().into();
let joint_matrix = Mat4::from_rotation_translation(rotation.into(), position.into())
* local_to_handler_matrix;
let joint_matrix =
Mat4::from_rotation_translation(joint.rotation.into(), joint.position.into())
* local_to_handler_matrix;
let (_, rotation, position) = joint_matrix.to_scale_rotation_translation();
let rotation: mint::Quaternion<f32> = rotation.into();
let position: mint::Vector3<f32> = position.into();
joint.position = position.into();
joint.rotation = rotation.into();
}
(InputDataRaw::Hand, hand.pack(fbb).as_union_value())
InputDataType::Hand(Box::new(hand))
}
fn serialize_datamap(&self) -> Vec<u8> {
fn serialize_datamap(&self) -> Datamap {
let mut fbb = flexbuffers::Builder::default();
let mut map = fbb.start_map();
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()
Datamap::new(fbb.view().to_vec()).unwrap()
}
}