From 05ad91a64f120fa5261527cb5ef7ad01c1c3b957 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sun, 3 Mar 2024 22:15:18 -0500 Subject: [PATCH] scene: some cleanup --- lyra-scene/src/lib.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lyra-scene/src/lib.rs b/lyra-scene/src/lib.rs index 78dd50c..dde3c66 100644 --- a/lyra-scene/src/lib.rs +++ b/lyra-scene/src/lib.rs @@ -51,7 +51,7 @@ impl<'a, T> DerefMut for MutCow<'a, T> { /// This SceneGraph is special in the sense that it is literally just an ECS world with methods /// implemented for it that make it easier to use for a SceneGraph. //#[derive(Default)] -pub struct SceneGraph<'a> { +pub struct SceneGraph<'a> { pub(crate) world: MutCow<'a, World>, root_node: SceneNode, } @@ -162,6 +162,13 @@ impl<'a> SceneGraph<'a> { world_add_child_node(&mut self.world, parent, local_transform, bundle) } + pub fn add_empty_node_under(&mut self, parent: &SceneNode, local_transform: Transform) -> SceneNode { + let e = self.world.spawn((SceneNodeFlag, local_transform)); + self.world.add_relation(e, ChildOf, parent.entity()); + + SceneNode::new(Some(parent.entity()), e) + } + /// Traverses down the SceneGraph, calling `callback` with each SceneNode and its world transform. /// /// The traversal does not include the root scene node. @@ -189,6 +196,10 @@ impl<'a> SceneGraph<'a> { self.traverse_down_from(node, callback); } } + + pub fn root_node(&self) -> SceneNode { + self.root_node.clone() + } } /// Add a node under a parent node. @@ -256,7 +267,7 @@ pub mod tests { }); } - #[test] + /* #[test] fn inserting_and_from_world() { let v2s = vec![Vec3::new(10.0, 10.0, 10.0), Vec3::new(50.0, 50.0, 50.0)]; @@ -301,5 +312,5 @@ pub mod tests { idx += 1; }); - } + } */ } \ No newline at end of file