refactor(node): return weak reference and store Rc in scenegraph

This commit is contained in:
Nova
2022-05-17 02:35:44 -04:00
parent a736fb503e
commit 52565cd381
4 changed files with 45 additions and 38 deletions

View File

@@ -1,11 +1,26 @@
use super::core::Node;
use crate::core::client::Client;
use anyhow::Result;
use std::cell::RefCell;
use std::rc::Weak;
use vek::mat::repr_c::row_major::Mat4;
pub struct Spatial<'a> {
node: &'a Node<'a>,
pub struct Spatial {
transform: Mat4<f32>,
}
impl<'a> Spatial<'a> {
pub fn new(node: &'a Node<'a>) -> Self {
Spatial { node }
impl<'a> Spatial {
pub fn new(transform: Mat4<f32>) -> Self {
Spatial { transform }
}
pub fn new_node(
client: Option<&'a Client<'a>>,
path: &str,
transform: Mat4<f32>,
) -> Result<Weak<RefCell<Node<'a>>>> {
let node = Node::from_path(client, path)?;
node.upgrade().unwrap().borrow_mut().spatial = Some(Spatial::new(transform));
Ok(node)
}
}