scene: improve docs and some code cleanup
ci/woodpecker/push/debug Pipeline failed Details

This commit is contained in:
SeanOMik 2024-04-10 23:55:48 -04:00
parent 2daf617ba3
commit 60ec62c558
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
3 changed files with 11 additions and 30 deletions

View File

@ -22,7 +22,7 @@ pub struct SceneNodeFlag;
#[derive(Component)]
pub struct SceneNodeRoot;
/// A SceneGraph is a Graph of nodes that represents the hierarchy of a scene.
/// A Graph of nodes that represents the hierarchy of a Scene.
///
/// 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.

View File

@ -2,9 +2,9 @@ use lyra_ecs::{query::Entities, relation::{ChildOf, RelationOriginComponent}, Bu
use crate::SceneGraph;
/// A node inside of the Scene
#[derive(Clone, PartialEq, Eq)]
pub struct SceneNode {
//world: WorldLock,
parent: Option<Entity>,
entity: Entity
}
@ -54,28 +54,6 @@ impl SceneNode {
pub fn add_node<B: Bundle>(&self, graph: &mut SceneGraph, bundle: B) -> SceneNode {
graph.add_node_under(self, bundle)
}
/* pub fn local_transform(&self, graph: &SceneGraph) -> Transform {
let v = graph.world.view_one::<&Transform>(self.entity);
let t = v.get().expect("Somehow the SceneNode is missing its Transform!");
t.clone()
}
/// Retrieves the world transform of the Node.
///
/// This traverses up the SceneGraph from this node.
pub fn world_transform(&self, graph: &SceneGraph) -> Transform {
match self.parent(graph) {
Some(parent) => {
let pt = parent.world_transform(graph);
pt + self.local_transform(graph)
},
None => {
self.local_transform(graph)
}
}
} */
}
#[cfg(test)]

View File

@ -4,6 +4,13 @@ use lyra_ecs::{query::{filter::{Has, Not}, Entities, View}, relation::{ChildOf,
use lyra_math::Transform;
use crate::lyra_engine;
/// The world transform of an entity.
///
/// A Transform represents the relative position of the entity to its parent entity, while
/// a world transform is the position relative to the World. When wanting to move an entity,
/// you should use its [`Transform`]. You cannot mutate [`WorldTransform`] as its managed completey
/// by the [`system_update_world_transforms`] system. For the WorldTransform to work properly, you
/// must have both a [`Transform`] and [`WorldTransform`] on the entities in the scene.
#[derive(Debug, Copy, Clone, PartialEq, Default, Component)]
pub struct WorldTransform(pub(crate) Transform);
@ -18,14 +25,11 @@ impl Deref for WorldTransform {
/// A system that updates the [`WorldTransform`]'s for entities and their children.
///
/// For entities without parents, this will update world transform to match local transform.
/// For any children entities, their [`GlobalTransform`]s will be updated to reflect the changes
/// For any children entities, their [`WorldTransform`]s will be updated to reflect the changes
/// of its parent entity.
pub fn system_update_world_transforms(world: &World, view: View<(Entities, &mut WorldTransform, &Transform, Not<Has<RelationOriginComponent<ChildOf>>>)>) -> anyhow::Result<()> {
for (en, mut world_tran, tran, _) in view.into_iter() {
world_tran.0 = *tran;
println!("Found entity {:?} at {:?}", en, world_tran.translation);
recurse_update_trans(world, &world_tran, en);
}
@ -47,8 +51,7 @@ fn recurse_update_trans(world: &World, parent_transform: &WorldTransform, entity
next_entities.push((en, world_tran.0.clone()));
}
next_entities.reverse();
while let Some((en, pos)) = next_entities.pop() {
for (en, pos) in next_entities.into_iter() {
recurse_update_trans(world, &WorldTransform(pos), en);
}
}