feat: /hmd
This commit is contained in:
@@ -2,6 +2,7 @@ use super::eventloop::EventLoop;
|
||||
use super::scenegraph::Scenegraph;
|
||||
use crate::nodes::data;
|
||||
use crate::nodes::field;
|
||||
use crate::nodes::hmd;
|
||||
use crate::nodes::input;
|
||||
use crate::nodes::item;
|
||||
use crate::nodes::model;
|
||||
@@ -64,6 +65,7 @@ impl Client {
|
||||
});
|
||||
let _ = client.scenegraph.client.set(Arc::downgrade(&client));
|
||||
let _ = client.root.set(Root::create(&client));
|
||||
hmd::make_alias(&client);
|
||||
spatial::create_interface(&client);
|
||||
field::create_interface(&client);
|
||||
model::create_interface(&client);
|
||||
|
||||
@@ -3,6 +3,7 @@ mod nodes;
|
||||
mod wayland;
|
||||
|
||||
use crate::core::destroy_queue;
|
||||
use crate::nodes::hmd;
|
||||
use crate::nodes::model::{MODELS_TO_DROP, MODEL_REGISTRY};
|
||||
use crate::wayland::Wayland;
|
||||
|
||||
@@ -63,6 +64,7 @@ fn main() -> Result<()> {
|
||||
println!("Stardust ready!");
|
||||
stereokit.run(
|
||||
|draw_ctx| {
|
||||
hmd::frame(&stereokit);
|
||||
wayland.frame(&stereokit);
|
||||
destroy_queue::clear();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ pub struct Node {
|
||||
local_methods: DashMap<String, Method, BuildHasherDefault<FxHasher>>,
|
||||
destroyable: AtomicBool,
|
||||
|
||||
alias: OnceCell<Arc<Alias>>,
|
||||
pub alias: OnceCell<Arc<Alias>>,
|
||||
aliases: Registry<Alias>,
|
||||
|
||||
pub spatial: OnceCell<Arc<Spatial>>,
|
||||
@@ -198,7 +198,7 @@ impl Node {
|
||||
#[allow(dead_code)]
|
||||
pub struct Alias {
|
||||
node: Weak<Node>,
|
||||
original: Weak<Node>,
|
||||
pub original: Weak<Node>,
|
||||
|
||||
local_signals: Vec<&'static str>,
|
||||
local_methods: Vec<&'static str>,
|
||||
|
||||
35
src/nodes/hmd.rs
Normal file
35
src/nodes/hmd.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use super::{
|
||||
core::{Alias, Node},
|
||||
spatial::Spatial,
|
||||
};
|
||||
use crate::core::client::{Client, INTERNAL_CLIENT};
|
||||
use glam::{vec3, Mat4};
|
||||
use std::sync::Arc;
|
||||
use stereokit::StereoKit;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref HMD: Arc<Node> = create();
|
||||
}
|
||||
|
||||
fn create() -> Arc<Node> {
|
||||
let node = Arc::new(Node::create(&INTERNAL_CLIENT, "", "hmd", false));
|
||||
Spatial::add_to(&node, None, Mat4::IDENTITY).unwrap();
|
||||
|
||||
node
|
||||
}
|
||||
|
||||
pub fn frame(sk: &StereoKit) {
|
||||
let spatial = HMD.spatial.get().unwrap();
|
||||
let hmd_pose = sk.input_head();
|
||||
*spatial.transform.lock() = 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>) -> Arc<Node> {
|
||||
let node = Node::create(client, "", "hmd", false).add_to_scenegraph();
|
||||
Alias::add_to(&node, &HMD, vec!["getTransform"], vec![], vec![], vec![]);
|
||||
node
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod hmd;
|
||||
pub mod core;
|
||||
pub mod data;
|
||||
pub mod field;
|
||||
|
||||
Reference in New Issue
Block a user