feat: parse transform vectors
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
name = "stardust-xr-server"
|
name = "stardust-xr-server"
|
||||||
version = "0.9.1"
|
version = "0.10.0"
|
||||||
authors = ["Nova King <technobaboo@proton.me>"]
|
authors = ["Nova King <technobaboo@proton.me>"]
|
||||||
description = "Stardust XR reference display server"
|
description = "Stardust XR reference display server"
|
||||||
license = "GPLv2"
|
license = "GPLv2"
|
||||||
@@ -32,7 +32,7 @@ prisma = "0.1.1"
|
|||||||
slog = "2.7.0"
|
slog = "2.7.0"
|
||||||
slog-stdlog = "4.1.1"
|
slog-stdlog = "4.1.1"
|
||||||
xkbcommon = { version = "0.5.0", default-features = false }
|
xkbcommon = { version = "0.5.0", default-features = false }
|
||||||
stardust-xr = "0.2.0"
|
stardust-xr = "0.3.0"
|
||||||
stardust-xr-schemas = "0.1.0"
|
stardust-xr-schemas = "0.1.0"
|
||||||
stereokit = {default-features = false, features = ["linux-egl"], version = "0.2.0"}
|
stereokit = {default-features = false, features = ["linux-egl"], version = "0.2.0"}
|
||||||
wayland-backend = "=0.1.0-beta.9"
|
wayland-backend = "=0.1.0-beta.9"
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
use super::fields::Field;
|
use super::fields::Field;
|
||||||
use super::spatial::{get_spatial_parent_flex, parse_pose, Spatial};
|
use super::spatial::{get_spatial_parent_flex, parse_transform, Spatial};
|
||||||
use super::{Alias, Node};
|
use super::{Alias, Node};
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::nodelist::LifeLinkedNodeList;
|
use crate::core::nodelist::LifeLinkedNodeList;
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
use anyhow::{anyhow, ensure, Result};
|
use anyhow::{anyhow, ensure, Result};
|
||||||
use glam::{vec3a, Mat4};
|
use glam::vec3a;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use stardust_xr::flex::flexbuffer_from_vector_arguments;
|
use stardust_xr::flex::flexbuffer_from_vector_arguments;
|
||||||
use stardust_xr::{flex_to_quat, flex_to_vec3};
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
static PULSE_SENDER_REGISTRY: Registry<PulseSender> = Registry::new();
|
static PULSE_SENDER_REGISTRY: Registry<PulseSender> = Registry::new();
|
||||||
@@ -249,14 +248,7 @@ pub fn create_pulse_sender_flex(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = Mat4::from_rotation_translation(
|
let transform = parse_transform(flex_vec.index(2)?, true, true, false)?;
|
||||||
flex_to_quat!(flex_vec.idx(3))
|
|
||||||
.ok_or_else(|| anyhow!("Rotation not found"))?
|
|
||||||
.into(),
|
|
||||||
flex_to_vec3!(flex_vec.idx(2))
|
|
||||||
.ok_or_else(|| anyhow!("Position not found"))?
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
let node = node.add_to_scenegraph();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, Some(parent), transform)?;
|
Spatial::add_to(&node, Some(parent), transform)?;
|
||||||
PulseSender::add_to(&node)?;
|
PulseSender::add_to(&node)?;
|
||||||
@@ -287,7 +279,7 @@ pub fn create_pulse_receiver_flex(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = parse_pose(flex_vec.idx(2), flex_vec.idx(3))?;
|
let transform = parse_transform(flex_vec.index(2)?, true, true, false)?;
|
||||||
let field = calling_client
|
let field = calling_client
|
||||||
.scenegraph
|
.scenegraph
|
||||||
.get_node(flex_vec.idx(4).as_str())
|
.get_node(flex_vec.idx(4).as_str())
|
||||||
|
|||||||
@@ -172,8 +172,8 @@ pub fn create(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let resource_id = parse_resource_id(flex_vec.idx(2))?;
|
let transform = parse_transform(flex_vec.index(2)?, true, true, true)?;
|
||||||
let transform = parse_transform(flex_vec.index(3)?, flex_vec.index(4)?, flex_vec.index(5)?)?;
|
let resource_id = parse_resource_id(flex_vec.idx(3))?;
|
||||||
let node = node.add_to_scenegraph();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, Some(parent), transform)?;
|
Spatial::add_to(&node, Some(parent), transform)?;
|
||||||
Model::add_to(&node, resource_id)?;
|
Model::add_to(&node, resource_id)?;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use super::{Field, FieldTrait, Node};
|
use super::{Field, FieldTrait, Node};
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::nodes::spatial::{get_spatial_parent_flex, Spatial};
|
use crate::nodes::spatial::{get_spatial_parent_flex, parse_transform, Spatial};
|
||||||
use anyhow::{anyhow, ensure, Result};
|
use anyhow::{anyhow, ensure, Result};
|
||||||
use glam::{vec3, vec3a, Mat4, Vec3, Vec3A};
|
use glam::{vec3, vec3a, Vec3, Vec3A};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use stardust_xr::{flex_to_quat, flex_to_vec3};
|
use stardust_xr::values::parse_vec3;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct BoxField {
|
pub struct BoxField {
|
||||||
@@ -38,7 +38,7 @@ impl BoxField {
|
|||||||
|
|
||||||
pub fn set_size_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
pub fn set_size_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
let root = flexbuffers::Reader::get_root(data)?;
|
let root = flexbuffers::Reader::get_root(data)?;
|
||||||
let size = flex_to_vec3!(root).ok_or_else(|| anyhow!("Size is invalid"))?;
|
let size = parse_vec3(root).ok_or_else(|| anyhow!("Size is invalid"))?;
|
||||||
if let Field::Box(box_field) = node.field.get().unwrap().as_ref() {
|
if let Field::Box(box_field) = node.field.get().unwrap().as_ref() {
|
||||||
box_field.set_size(size.into());
|
box_field.set_size(size.into());
|
||||||
}
|
}
|
||||||
@@ -64,17 +64,15 @@ impl FieldTrait for BoxField {
|
|||||||
|
|
||||||
pub fn create_box_field_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
pub fn create_box_field_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
|
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
|
||||||
let node = Node::create(&calling_client, "/field", flex_vec.idx(0).get_str()?, true);
|
let node = Node::create(
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
&calling_client,
|
||||||
let transform = Mat4::from_rotation_translation(
|
"/field",
|
||||||
flex_to_quat!(flex_vec.idx(3))
|
flex_vec.index(0)?.get_str()?,
|
||||||
.ok_or_else(|| anyhow!("Rotation not found"))?
|
true,
|
||||||
.into(),
|
|
||||||
flex_to_vec3!(flex_vec.idx(2))
|
|
||||||
.ok_or_else(|| anyhow!("Position not found"))?
|
|
||||||
.into(),
|
|
||||||
);
|
);
|
||||||
let size = flex_to_vec3!(flex_vec.idx(4)).ok_or_else(|| anyhow!("Size invalid"))?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.index(1)?.get_str()?)?;
|
||||||
|
let transform = parse_transform(flex_vec.index(2)?, true, true, false)?;
|
||||||
|
let size = parse_vec3(flex_vec.idx(4)).ok_or_else(|| anyhow!("Size invalid"))?;
|
||||||
let node = node.add_to_scenegraph();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, Some(parent), transform)?;
|
Spatial::add_to(&node, Some(parent), transform)?;
|
||||||
BoxField::add_to(&node, size.into())?;
|
BoxField::add_to(&node, size.into())?;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use super::{Field, FieldTrait, Node};
|
use super::{Field, FieldTrait, Node};
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::nodes::spatial::{get_spatial_parent_flex, Spatial};
|
use crate::nodes::spatial::{get_spatial_parent_flex, parse_transform, Spatial};
|
||||||
use anyhow::{anyhow, ensure, Result};
|
use anyhow::{ensure, Result};
|
||||||
use glam::{swizzles::*, vec2, Mat4, Vec3A};
|
use glam::{swizzles::*, vec2, Vec3A};
|
||||||
use portable_atomic::AtomicF32;
|
use portable_atomic::AtomicF32;
|
||||||
use stardust_xr::{flex_to_quat, flex_to_vec3};
|
use stardust_xr::values::parse_f32;
|
||||||
|
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -72,20 +73,18 @@ pub fn create_cylinder_field_flex(
|
|||||||
data: &[u8],
|
data: &[u8],
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
|
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
|
||||||
let node = Node::create(&calling_client, "/field", flex_vec.idx(0).get_str()?, true);
|
let node = Node::create(
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
&calling_client,
|
||||||
let transform = Mat4::from_rotation_translation(
|
"/field",
|
||||||
flex_to_quat!(flex_vec.idx(3))
|
flex_vec.index(0)?.get_str()?,
|
||||||
.ok_or_else(|| anyhow!("Rotation not found"))?
|
true,
|
||||||
.into(),
|
|
||||||
flex_to_vec3!(flex_vec.idx(2))
|
|
||||||
.ok_or_else(|| anyhow!("Position not found"))?
|
|
||||||
.into(),
|
|
||||||
);
|
);
|
||||||
let length = flex_vec.idx(0).as_f32();
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let radius = flex_vec.idx(1).as_f32();
|
let transform = parse_transform(flex_vec.index(2)?, true, true, false)?;
|
||||||
|
let length = parse_f32(flex_vec.index(3)?).ok_or_else(|| anyhow::anyhow!("Invalid length"))?;
|
||||||
|
let radius = parse_f32(flex_vec.index(4)?).ok_or_else(|| anyhow::anyhow!("Invalid radius"))?;
|
||||||
let node = node.add_to_scenegraph();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, Some(parent), transform)?;
|
Spatial::add_to(&node, Some(parent), transform)?;
|
||||||
CylinderField::add_to(&node, length, radius)?;
|
CylinderField::add_to(&node, dbg!(length), dbg!(radius))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use crate::core::client::Client;
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use glam::{vec2, vec3a, Vec3, Vec3A};
|
use glam::{vec2, vec3a, Vec3, Vec3A};
|
||||||
use stardust_xr::flex::FlexBuffable;
|
use stardust_xr::flex::FlexBuffable;
|
||||||
use stardust_xr::flex_to_vec3;
|
use stardust_xr::values::parse_vec3;
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -78,7 +78,7 @@ fn field_distance_flex(node: &Node, calling_client: Arc<Client>, data: &[u8]) ->
|
|||||||
.get()
|
.get()
|
||||||
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
||||||
.clone();
|
.clone();
|
||||||
let point = flex_to_vec3!(flex_vec.idx(1)).ok_or_else(|| anyhow!("Point is invalid"))?;
|
let point = parse_vec3(flex_vec.idx(1)).ok_or_else(|| anyhow!("Point is invalid"))?;
|
||||||
|
|
||||||
let distance = node
|
let distance = node
|
||||||
.field
|
.field
|
||||||
@@ -97,7 +97,7 @@ fn field_normal_flex(node: &Node, calling_client: Arc<Client>, data: &[u8]) -> R
|
|||||||
.get()
|
.get()
|
||||||
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
||||||
.clone();
|
.clone();
|
||||||
let point = flex_to_vec3!(flex_vec.idx(1)).ok_or_else(|| anyhow!("Point is invalid"))?;
|
let point = parse_vec3(flex_vec.idx(1)).ok_or_else(|| anyhow!("Point is invalid"))?;
|
||||||
|
|
||||||
let normal = node.field.get().as_ref().unwrap().normal(
|
let normal = node.field.get().as_ref().unwrap().normal(
|
||||||
reference_space.as_ref(),
|
reference_space.as_ref(),
|
||||||
@@ -120,7 +120,7 @@ fn field_closest_point_flex(
|
|||||||
.get()
|
.get()
|
||||||
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
.ok_or_else(|| anyhow!("Reference space node does not have a spatial"))?
|
||||||
.clone();
|
.clone();
|
||||||
let point = flex_to_vec3!(flex_vec.idx(1)).ok_or_else(|| anyhow!("Point is invalid"))?;
|
let point = parse_vec3(flex_vec.idx(1)).ok_or_else(|| anyhow!("Point is invalid"))?;
|
||||||
|
|
||||||
let closest_point =
|
let closest_point =
|
||||||
node.field
|
node.field
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::nodes::spatial::{get_spatial_parent_flex, Spatial};
|
|||||||
use anyhow::{anyhow, ensure, Result};
|
use anyhow::{anyhow, ensure, Result};
|
||||||
use glam::{Mat4, Vec3A};
|
use glam::{Mat4, Vec3A};
|
||||||
use portable_atomic::AtomicF32;
|
use portable_atomic::AtomicF32;
|
||||||
use stardust_xr::flex_to_vec3;
|
use stardust_xr::values::parse_vec3;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ pub fn create_sphere_field_flex(
|
|||||||
let node = Node::create(&calling_client, "/field", flex_vec.idx(0).get_str()?, true);
|
let node = Node::create(&calling_client, "/field", flex_vec.idx(0).get_str()?, true);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = Mat4::from_translation(
|
let transform = Mat4::from_translation(
|
||||||
flex_to_vec3!(flex_vec.idx(2))
|
parse_vec3(flex_vec.idx(2))
|
||||||
.ok_or_else(|| anyhow!("Position not found"))?
|
.ok_or_else(|| anyhow!("Position not found"))?
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use self::hand::Hand;
|
|||||||
use self::pointer::Pointer;
|
use self::pointer::Pointer;
|
||||||
|
|
||||||
use super::fields::Field;
|
use super::fields::Field;
|
||||||
use super::spatial::{get_spatial_parent_flex, parse_pose, Spatial};
|
use super::spatial::{get_spatial_parent_flex, parse_transform, Spatial};
|
||||||
use super::Node;
|
use super::Node;
|
||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use crate::core::eventloop::FRAME;
|
use crate::core::eventloop::FRAME;
|
||||||
@@ -218,10 +218,10 @@ pub fn create_input_handler_flex(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = parse_pose(flex_vec.idx(2), flex_vec.idx(3))?;
|
let transform = parse_transform(flex_vec.idx(2), true, true, false)?;
|
||||||
let field = calling_client
|
let field = calling_client
|
||||||
.scenegraph
|
.scenegraph
|
||||||
.get_node(flex_vec.idx(4).as_str())
|
.get_node(flex_vec.idx(3).as_str())
|
||||||
.ok_or_else(|| anyhow!("Field not found"))?
|
.ok_or_else(|| anyhow!("Field not found"))?
|
||||||
.field
|
.field
|
||||||
.get()
|
.get()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ mod environment;
|
|||||||
use self::environment::EnvironmentItem;
|
use self::environment::EnvironmentItem;
|
||||||
|
|
||||||
use super::fields::Field;
|
use super::fields::Field;
|
||||||
use super::spatial::{get_spatial_parent_flex, parse_pose, Spatial};
|
use super::spatial::{get_spatial_parent_flex, parse_transform, Spatial};
|
||||||
use super::{Alias, Node};
|
use super::{Alias, Node};
|
||||||
use crate::core::client::{Client, INTERNAL_CLIENT};
|
use crate::core::client::{Client, INTERNAL_CLIENT};
|
||||||
use crate::core::nodelist::LifeLinkedNodeList;
|
use crate::core::nodelist::LifeLinkedNodeList;
|
||||||
@@ -352,10 +352,10 @@ pub fn create_environment_item_flex(
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let space = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let space = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = parse_pose(flex_vec.idx(2), flex_vec.idx(3))?;
|
let transform = parse_transform(flex_vec.idx(2), true, true, false)?;
|
||||||
let node = node.add_to_scenegraph();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, None, transform * space.global_transform())?;
|
Spatial::add_to(&node, None, transform * space.global_transform())?;
|
||||||
EnvironmentItem::add_to(&node, flex_vec.idx(4).get_str()?.to_string());
|
EnvironmentItem::add_to(&node, flex_vec.idx(3).get_str()?.to_string());
|
||||||
node.item
|
node.item
|
||||||
.get()
|
.get()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -372,10 +372,10 @@ pub fn create_item_acceptor_flex(
|
|||||||
let flex_vec = root.get_vector()?;
|
let flex_vec = root.get_vector()?;
|
||||||
let parent_name = format!("/item/{}/acceptor/", ITEM_TYPE_INFO_ENVIRONMENT.type_name);
|
let parent_name = format!("/item/{}/acceptor/", ITEM_TYPE_INFO_ENVIRONMENT.type_name);
|
||||||
let space = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
let space = get_spatial_parent_flex(&calling_client, flex_vec.idx(1).get_str()?)?;
|
||||||
let transform = parse_pose(flex_vec.idx(2), flex_vec.idx(3))?;
|
let transform = parse_transform(flex_vec.idx(2), true, true, false)?;
|
||||||
let field = calling_client
|
let field = calling_client
|
||||||
.scenegraph
|
.scenegraph
|
||||||
.get_node(flex_vec.idx(4).get_str()?)
|
.get_node(flex_vec.idx(3).get_str()?)
|
||||||
.ok_or_else(|| anyhow!("Field node not found"))?;
|
.ok_or_else(|| anyhow!("Field node not found"))?;
|
||||||
let field = field
|
let field = field
|
||||||
.field
|
.field
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ use super::Node;
|
|||||||
use crate::core::client::Client;
|
use crate::core::client::Client;
|
||||||
use anyhow::{anyhow, ensure, Result};
|
use anyhow::{anyhow, ensure, Result};
|
||||||
use glam::{Mat4, Quat, Vec3};
|
use glam::{Mat4, Quat, Vec3};
|
||||||
|
use mint::Vector3;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use stardust_xr::flex::flexbuffer_from_vector_arguments;
|
use stardust_xr::flex::flexbuffer_from_vector_arguments;
|
||||||
use stardust_xr::push_to_vec;
|
use stardust_xr::push_to_vec;
|
||||||
use stardust_xr::{flex_to_quat, flex_to_vec3};
|
use stardust_xr::values::{parse_quat, parse_vec3};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
@@ -205,9 +206,9 @@ impl Spatial {
|
|||||||
};
|
};
|
||||||
node.spatial.get().unwrap().set_local_transform_components(
|
node.spatial.get().unwrap().set_local_transform_components(
|
||||||
reference_space_transform.as_deref(),
|
reference_space_transform.as_deref(),
|
||||||
flex_to_vec3!(flex_vec.idx(1)).map(|v| v.into()),
|
parse_vec3(flex_vec.idx(1)).map(|v| v.into()),
|
||||||
flex_to_quat!(flex_vec.idx(2)).map(|v| v.into()),
|
parse_quat(flex_vec.idx(2)).map(|v| v.into()),
|
||||||
flex_to_vec3!(flex_vec.idx(3)).map(|v| v.into()),
|
parse_vec3(flex_vec.idx(3)).map(|v| v.into()),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -266,34 +267,30 @@ pub fn get_spatial_parent_flex(
|
|||||||
.ok_or_else(|| anyhow!("Spatial parent node is not a spatial"))?
|
.ok_or_else(|| anyhow!("Spatial parent node is not a spatial"))?
|
||||||
.clone())
|
.clone())
|
||||||
}
|
}
|
||||||
pub fn parse_pose<B: flexbuffers::Buffer>(
|
|
||||||
translation: flexbuffers::Reader<B>,
|
|
||||||
rotation: flexbuffers::Reader<B>,
|
|
||||||
) -> Result<Mat4> {
|
|
||||||
Ok(Mat4::from_rotation_translation(
|
|
||||||
flex_to_quat!(rotation)
|
|
||||||
.ok_or_else(|| anyhow!("Rotation not found"))?
|
|
||||||
.into(),
|
|
||||||
flex_to_vec3!(translation)
|
|
||||||
.ok_or_else(|| anyhow!("Position not found"))?
|
|
||||||
.into(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
pub fn parse_transform<B: flexbuffers::Buffer>(
|
pub fn parse_transform<B: flexbuffers::Buffer>(
|
||||||
translation: flexbuffers::Reader<B>,
|
reader: flexbuffers::Reader<B>,
|
||||||
rotation: flexbuffers::Reader<B>,
|
translation: bool,
|
||||||
scale: flexbuffers::Reader<B>,
|
rotation: bool,
|
||||||
|
scale: bool,
|
||||||
) -> Result<Mat4> {
|
) -> Result<Mat4> {
|
||||||
|
let transform_vec = reader.get_vector()?;
|
||||||
|
let translation = translation
|
||||||
|
.then(|| parse_vec3(transform_vec.idx(0)))
|
||||||
|
.flatten()
|
||||||
|
.unwrap_or(Vector3::from([0.0; 3]));
|
||||||
|
let rotation = rotation
|
||||||
|
.then(|| parse_quat(transform_vec.idx(1)))
|
||||||
|
.flatten()
|
||||||
|
.unwrap_or(Quat::IDENTITY.into());
|
||||||
|
let scale = scale
|
||||||
|
.then(|| parse_vec3(transform_vec.idx(2)))
|
||||||
|
.flatten()
|
||||||
|
.unwrap_or(Vector3::from([1.0; 3]));
|
||||||
|
|
||||||
Ok(Mat4::from_scale_rotation_translation(
|
Ok(Mat4::from_scale_rotation_translation(
|
||||||
flex_to_vec3!(scale)
|
scale.into(),
|
||||||
.ok_or_else(|| anyhow!("Scale not found"))?
|
rotation.into(),
|
||||||
.into(),
|
translation.into(),
|
||||||
flex_to_quat!(rotation)
|
|
||||||
.ok_or_else(|| anyhow!("Rotation not found"))?
|
|
||||||
.into(),
|
|
||||||
flex_to_vec3!(translation)
|
|
||||||
.ok_or_else(|| anyhow!("Position not found"))?
|
|
||||||
.into(),
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +309,7 @@ pub fn create_spatial_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let parent = get_spatial_parent_flex(&calling_client, flex_vec.index(1)?.get_str()?)?;
|
let parent = get_spatial_parent_flex(&calling_client, flex_vec.index(1)?.get_str()?)?;
|
||||||
let transform = parse_transform(flex_vec.index(2)?, flex_vec.index(3)?, flex_vec.index(4)?)?;
|
let transform = parse_transform(flex_vec.index(2)?, true, true, true)?;
|
||||||
let node = node.add_to_scenegraph();
|
let node = node.add_to_scenegraph();
|
||||||
Spatial::add_to(&node, Some(parent), transform)?;
|
Spatial::add_to(&node, Some(parent), transform)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use smithay::{
|
|||||||
};
|
};
|
||||||
use stardust_xr::{
|
use stardust_xr::{
|
||||||
flex::{flexbuffer_from_arguments, flexbuffer_from_vector_arguments},
|
flex::{flexbuffer_from_arguments, flexbuffer_from_vector_arguments},
|
||||||
flex_to_vec2,
|
values::parse_vec2,
|
||||||
};
|
};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use xkbcommon::xkb::{self, ffi::XKB_KEYMAP_FORMAT_TEXT_V1, Keymap};
|
use xkbcommon::xkb::{self, ffi::XKB_KEYMAP_FORMAT_TEXT_V1, Keymap};
|
||||||
@@ -328,11 +328,11 @@ impl PanelItem {
|
|||||||
pointer.axis_stop(0, Axis::VerticalScroll);
|
pointer.axis_stop(0, Axis::VerticalScroll);
|
||||||
} else {
|
} else {
|
||||||
let flex_vec = flex.get_vector()?;
|
let flex_vec = flex.get_vector()?;
|
||||||
let axis_continuous_vec = flex_to_vec2!(flex_vec.idx(0))
|
let axis_continuous_vec = parse_vec2(flex_vec.idx(0))
|
||||||
.ok_or_else(|| anyhow!("No continuous axis vector!"))?;
|
.ok_or_else(|| anyhow!("No continuous axis vector!"))?;
|
||||||
pointer.axis(0, Axis::HorizontalScroll, axis_continuous_vec.x as f64);
|
pointer.axis(0, Axis::HorizontalScroll, axis_continuous_vec.x as f64);
|
||||||
pointer.axis(0, Axis::VerticalScroll, axis_continuous_vec.y as f64);
|
pointer.axis(0, Axis::VerticalScroll, axis_continuous_vec.y as f64);
|
||||||
if let Some(axis_discrete_vec) = flex_to_vec2!(flex_vec.idx(0)) {
|
if let Some(axis_discrete_vec) = parse_vec2(flex_vec.idx(0)) {
|
||||||
pointer.axis_discrete(
|
pointer.axis_discrete(
|
||||||
Axis::HorizontalScroll,
|
Axis::HorizontalScroll,
|
||||||
axis_discrete_vec.x as i32,
|
axis_discrete_vec.x as i32,
|
||||||
|
|||||||
Reference in New Issue
Block a user