gizmo_engine/systems/
transform.rs1pub struct TransformSyncSystem;
2
3impl gizmo_core::system::System for TransformSyncSystem {
4 fn access_info(&self) -> gizmo_core::system::AccessInfo {
5 let mut info = gizmo_core::system::AccessInfo::new();
6 info.is_exclusive = true;
9 info
10 }
11
12 fn run(&mut self, world: &gizmo_core::world::World, _dt: f32) {
13 let transforms = world.borrow_mut::<crate::physics::Transform>();
14 for (_, trans) in transforms.iter_mut() {
15 trans.update_local_matrix();
16 }
17 }
18}
19
20pub struct TransformPropagateSystem;
21
22impl gizmo_core::system::System for TransformPropagateSystem {
23 fn access_info(&self) -> gizmo_core::system::AccessInfo {
24 let mut info = gizmo_core::system::AccessInfo::new();
25 info.is_exclusive = true; info
27 }
28
29 fn run(&mut self, world: &gizmo_core::world::World, _dt: f32) {
30 let locals = world.borrow::<crate::physics::Transform>();
31 let mut globals = world.borrow_mut::<crate::physics::GlobalTransform>();
32 let parents = world.borrow::<gizmo_core::component::Parent>();
33 let children_storage = world.borrow::<gizmo_core::component::Children>();
34
35 let mut queue = Vec::new();
36
37 for (id, local) in locals.iter() {
39 if parents.get(id).is_none() {
40 if let Some(global) = globals.get_mut(id) {
41 global.matrix = local.local_matrix;
42
43 if let Some(children) = children_storage.get(id) {
45 for &child_id in &children.0 {
46 queue.push((global.matrix, child_id));
47 }
48 }
49 }
50 }
51 }
52
53 let mut head = 0;
55 while head < queue.len() {
56 let (parent_matrix, current_id) = queue[head];
57 head += 1;
58
59 if let Some(local) = locals.get(current_id) {
60 if let Some(global) = globals.get_mut(current_id) {
61 global.matrix = parent_matrix * local.local_matrix;
62
63 if let Some(children) = children_storage.get(current_id) {
64 for &child_id in &children.0 {
65 queue.push((global.matrix, child_id));
66 }
67 }
68 }
69 }
70 }
71 }
72}