feat(scenegraph): default interface creation

This commit is contained in:
Nova
2022-05-17 16:32:06 -04:00
parent 8242537932
commit 323d1e01fe
3 changed files with 14 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
use super::scenegraph::Scenegraph; use super::scenegraph::Scenegraph;
use crate::nodes::core::{Node, NodeRef};
use libstardustxr::messenger::Messenger; use libstardustxr::messenger::Messenger;
use mio::net::UnixStream; use mio::net::UnixStream;
use std::rc::{Rc, Weak}; use std::rc::{Rc, Weak};
@@ -11,7 +12,7 @@ pub struct Client<'a> {
impl<'a> Client<'a> { impl<'a> Client<'a> {
pub fn from_connection(connection: UnixStream) -> Self { pub fn from_connection(connection: UnixStream) -> Self {
Client { Client {
scenegraph: Scenegraph::new(), scenegraph: Default::default(),
messenger: Rc::new(Messenger::new(connection)), messenger: Rc::new(Messenger::new(connection)),
} }
} }

View File

@@ -1,4 +1,6 @@
use crate::nodes::core::Node; use crate::core::client::Client;
use crate::nodes::core::{Node, NodeRef};
use crate::nodes::spatial::Spatial;
use anyhow::Result; use anyhow::Result;
use libstardustxr::scenegraph; use libstardustxr::scenegraph;
use libstardustxr::scenegraph::ScenegraphError; use libstardustxr::scenegraph::ScenegraphError;
@@ -7,13 +9,11 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc, rc::Weak};
#[derive(Default)] #[derive(Default)]
pub struct Scenegraph<'a> { pub struct Scenegraph<'a> {
nodes: HashMap<String, Rc<RefCell<Node<'a>>>>, nodes: HashMap<String, Rc<RefCell<Node<'a>>>>,
root: NodeRef<'a>,
hmd: NodeRef<'a>,
} }
impl<'a> Scenegraph<'a> { impl<'a> Scenegraph<'a> {
pub fn new() -> Self {
Default::default()
}
pub fn add_node(&mut self, node: Rc<RefCell<Node<'a>>>) { pub fn add_node(&mut self, node: Rc<RefCell<Node<'a>>>) {
let path = node.borrow().get_path().to_string(); let path = node.borrow().get_path().to_string();
self.nodes.insert(path, node); self.nodes.insert(path, node);
@@ -26,6 +26,12 @@ impl<'a> Scenegraph<'a> {
pub fn get_node(&self, path: &str) -> Weak<RefCell<Node<'a>>> { pub fn get_node(&self, path: &str) -> Weak<RefCell<Node<'a>>> {
self.nodes.get(path).map_or(Weak::default(), Rc::downgrade) self.nodes.get(path).map_or(Weak::default(), Rc::downgrade)
} }
pub fn add_interfaces(&mut self, client: &mut Client<'a>) -> Result<()> {
self.root = Spatial::new_node(Some(client), "/", Default::default())?;
self.hmd = Spatial::new_node(Some(client), "/hmd", Default::default())?;
Ok(())
}
} }
impl<'a> scenegraph::Scenegraph for Scenegraph<'a> { impl<'a> scenegraph::Scenegraph for Scenegraph<'a> {

View File

@@ -13,7 +13,7 @@ impl<'a> Spatial {
} }
pub fn new_node( pub fn new_node(
client: Option<&'a mut Client<'a>>, client: Option<&mut Client<'a>>,
path: &str, path: &str,
transform: Mat4<f32>, transform: Mat4<f32>,
) -> Result<NodeRef<'a>> { ) -> Result<NodeRef<'a>> {