feat: use dbus for hmd
This commit is contained in:
@@ -6,7 +6,7 @@ use super::{
|
||||
use crate::{
|
||||
core::{registry::OwnedRegistry, task},
|
||||
nodes::{
|
||||
audio, data, drawable, fields, hmd, input, items,
|
||||
audio, data, drawable, fields, input, items,
|
||||
root::{ClientState, Root},
|
||||
spatial, Node,
|
||||
},
|
||||
@@ -108,7 +108,6 @@ impl Client {
|
||||
});
|
||||
let _ = client.scenegraph.client.set(Arc::downgrade(&client));
|
||||
let _ = client.root.set(Root::create(&client, state.root)?);
|
||||
hmd::make_alias(&client)?;
|
||||
spatial::create_interface(&client)?;
|
||||
fields::create_interface(&client)?;
|
||||
drawable::create_interface(&client)?;
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@@ -8,12 +8,14 @@ mod wayland;
|
||||
|
||||
use crate::core::destroy_queue;
|
||||
use crate::nodes::items::camera;
|
||||
use crate::nodes::{audio, drawable, hmd, input};
|
||||
use crate::nodes::{audio, drawable, input};
|
||||
|
||||
use clap::Parser;
|
||||
use core::client::Client;
|
||||
use core::task;
|
||||
use directories::ProjectDirs;
|
||||
use nodes::spatial::Spatial;
|
||||
use objects::hmd::HMD;
|
||||
use objects::ServerObjects;
|
||||
use once_cell::sync::OnceCell;
|
||||
use session::{launch_start, save_session};
|
||||
@@ -33,6 +35,7 @@ use tokio::sync::Notify;
|
||||
use tracing::metadata::LevelFilter;
|
||||
use tracing::{debug_span, error, info};
|
||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||
use zbus::Connection;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
@@ -107,6 +110,13 @@ async fn main() {
|
||||
error!("Unable to get Stardust project directories, default skybox and startup script will not work.");
|
||||
}
|
||||
|
||||
let dbus_connection = Connection::session().await.unwrap();
|
||||
let hmd = HMD::create(&dbus_connection).await;
|
||||
dbus_connection
|
||||
.request_name("org.stardustxr.HMD")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let sk_ready_notifier = Arc::new(Notify::new());
|
||||
let stereokit_loop = tokio::task::spawn_blocking({
|
||||
let sk_ready_notifier = sk_ready_notifier.clone();
|
||||
@@ -119,6 +129,7 @@ async fn main() {
|
||||
project_dirs,
|
||||
flatscreen,
|
||||
overlay_priority,
|
||||
hmd,
|
||||
)
|
||||
}
|
||||
});
|
||||
@@ -148,6 +159,7 @@ fn stereokit_loop(
|
||||
project_dirs: Option<ProjectDirs>,
|
||||
intentional_flatscreen: bool,
|
||||
overlay_priority: Option<u32>,
|
||||
hmd: Arc<Spatial>,
|
||||
) {
|
||||
let sk = SkSettings::default()
|
||||
.app_name("Stardust XR")
|
||||
@@ -206,7 +218,7 @@ fn stereokit_loop(
|
||||
sk_ready_notifier.notify_waiters();
|
||||
info!("Stardust ready!");
|
||||
|
||||
let mut objects = ServerObjects::new(intentional_flatscreen, &sk);
|
||||
let mut objects = ServerObjects::new(intentional_flatscreen, &sk, hmd);
|
||||
|
||||
let mut last_frame_delta = Duration::ZERO;
|
||||
let mut sleep_duration = Duration::ZERO;
|
||||
@@ -215,7 +227,6 @@ fn stereokit_loop(
|
||||
let _span = debug_span!("StereoKit step");
|
||||
let _span = _span.enter();
|
||||
|
||||
hmd::frame();
|
||||
camera::update(token);
|
||||
#[cfg(feature = "wayland")]
|
||||
wayland.frame_event();
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
use super::{
|
||||
alias::Alias,
|
||||
spatial::{Spatial, SPATIAL_ASPECT_ALIAS_INFO},
|
||||
Node,
|
||||
};
|
||||
use crate::core::client::{Client, INTERNAL_CLIENT};
|
||||
use color_eyre::eyre::Result;
|
||||
use glam::{vec3, Mat4};
|
||||
use std::sync::Arc;
|
||||
use stereokit_rust::system::Input;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref HMD: Arc<Node> = create();
|
||||
}
|
||||
|
||||
fn create() -> Arc<Node> {
|
||||
let node = Arc::new(Node::generate(&INTERNAL_CLIENT, false));
|
||||
Spatial::add_to(&node, None, Mat4::IDENTITY, false);
|
||||
node
|
||||
}
|
||||
|
||||
pub fn frame() {
|
||||
let spatial = HMD.get_aspect::<Spatial>().unwrap();
|
||||
let hmd_pose = Input::get_head();
|
||||
spatial.set_local_transform(Mat4::from_scale_rotation_translation(
|
||||
vec3(1.0, 1.0, 1.0),
|
||||
hmd_pose.orientation.into(),
|
||||
hmd_pose.position.into(),
|
||||
));
|
||||
}
|
||||
|
||||
pub fn make_alias(client: &Arc<Client>) -> Result<Arc<Node>> {
|
||||
Alias::create(&HMD, client, SPATIAL_ASPECT_ALIAS_INFO.clone(), None)
|
||||
}
|
||||
@@ -3,7 +3,6 @@ pub mod audio;
|
||||
pub mod data;
|
||||
pub mod drawable;
|
||||
pub mod fields;
|
||||
pub mod hmd;
|
||||
pub mod input;
|
||||
pub mod items;
|
||||
pub mod root;
|
||||
|
||||
28
src/objects/hmd.rs
Normal file
28
src/objects/hmd.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use crate::{
|
||||
core::client::INTERNAL_CLIENT,
|
||||
nodes::{
|
||||
spatial::{Spatial, EXPORTED_SPATIALS},
|
||||
Node,
|
||||
},
|
||||
};
|
||||
use glam::Mat4;
|
||||
use std::sync::Arc;
|
||||
use zbus::{interface, Connection};
|
||||
|
||||
pub struct HMD;
|
||||
impl HMD {
|
||||
pub async fn create(connection: &Connection) -> Arc<Spatial> {
|
||||
let node = Arc::new(Node::generate(&INTERNAL_CLIENT, false));
|
||||
let spatial = Spatial::add_to(&node, None, Mat4::IDENTITY, false);
|
||||
EXPORTED_SPATIALS.lock().insert(0, node);
|
||||
connection.object_server().at("/hmd", Self).await.unwrap();
|
||||
spatial
|
||||
}
|
||||
}
|
||||
#[interface(name = "org.stardustxr.SpatialRef")]
|
||||
impl HMD {
|
||||
#[zbus(property)]
|
||||
pub fn uid(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,23 @@
|
||||
use crate::nodes::spatial::Spatial;
|
||||
use glam::{vec3, Mat4};
|
||||
use input::{
|
||||
eye_pointer::EyePointer, mouse_pointer::MousePointer, sk_controller::SkController,
|
||||
sk_hand::SkHand,
|
||||
};
|
||||
use play_space::PlaySpace;
|
||||
use std::sync::Arc;
|
||||
use stereokit_rust::{
|
||||
sk::{DisplayMode, MainThreadToken, Sk},
|
||||
system::{Handed, World},
|
||||
system::{Handed, Input, World},
|
||||
util::Device,
|
||||
};
|
||||
|
||||
pub mod hmd;
|
||||
pub mod input;
|
||||
pub mod play_space;
|
||||
|
||||
pub struct ServerObjects {
|
||||
hmd: Arc<Spatial>,
|
||||
mouse_pointer: Option<MousePointer>,
|
||||
hands: Option<(SkHand, SkHand)>,
|
||||
controllers: Option<(SkController, SkController)>,
|
||||
@@ -20,8 +25,9 @@ pub struct ServerObjects {
|
||||
play_space: Option<PlaySpace>,
|
||||
}
|
||||
impl ServerObjects {
|
||||
pub fn new(intentional_flatscreen: bool, sk: &Sk) -> ServerObjects {
|
||||
pub fn new(intentional_flatscreen: bool, sk: &Sk, hmd: Arc<Spatial>) -> ServerObjects {
|
||||
ServerObjects {
|
||||
hmd,
|
||||
mouse_pointer: intentional_flatscreen
|
||||
.then(MousePointer::new)
|
||||
.transpose()
|
||||
@@ -50,6 +56,14 @@ impl ServerObjects {
|
||||
}
|
||||
|
||||
pub fn update(&mut self, sk: &Sk, token: &MainThreadToken) {
|
||||
let hmd_pose = Input::get_head();
|
||||
self.hmd
|
||||
.set_local_transform(Mat4::from_scale_rotation_translation(
|
||||
vec3(1.0, 1.0, 1.0),
|
||||
hmd_pose.orientation.into(),
|
||||
hmd_pose.position.into(),
|
||||
));
|
||||
|
||||
if let Some(mouse_pointer) = self.mouse_pointer.as_mut() {
|
||||
mouse_pointer.update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user