@@ -200,31 +200,33 @@ impl Hub {
200200 }
201201
202202 fn update_graph ( & mut self ) {
203- let mut cursor = self . nodes . cursor_alive ( ) ;
204- while let Some ( mut item) = cursor. next ( ) {
203+ let mut cursor = self . nodes . cursor ( ) ;
204+ // forward pass: derive visibility, scene id, and world transform
205+ // from the parent `Node`
206+ while let Some ( ( left, mut item, _) ) = cursor. next ( ) {
205207 if !item. visible {
206208 item. world_visible = false ;
207209 continue
208210 }
209- let ( visibility, affilation, transform, bounds ) = match item. parent {
211+ let ( visibility, affilation, transform) = match item. parent {
210212 Some ( ref parent_ptr) => {
211- let parent = item . look_back ( parent_ptr) . unwrap ( ) ;
213+ let parent = left . get ( parent_ptr) . unwrap ( ) ;
212214 let transform = parent. world_transform . concat ( & item. transform ) ;
213- let bounds = if parent. world_visible {
214- let bounds = item. bounds . transform ( & transform) ;
215- parent. world_bounds = parent. world_bounds . union ( & bounds) ;
216- bounds
217- } else {
218- item. bounds
219- } ;
220- ( parent. world_visible , parent. scene_id , transform, bounds)
215+ ( parent. world_visible , parent. scene_id , transform)
221216 } ,
222- None => ( true , item. scene_id , item. transform , item . bounds ) ,
217+ None => ( true , item. scene_id , item. transform ) ,
223218 } ;
224219 item. world_visible = visibility;
225220 item. scene_id = affilation;
226221 item. world_transform = transform;
227- item. world_bounds = bounds;
222+ item. world_bounds = item. bounds . transform ( & transform) ;
223+ }
224+ // backwards pass: accumulate bounding boxes of children
225+ while let Some ( ( mut left, item, _) ) = cursor. prev ( ) {
226+ if let ( true , Some ( parent_ptr) ) = ( item. world_visible , item. parent . as_ref ( ) ) {
227+ let bounds = & mut left. get_mut ( parent_ptr) . unwrap ( ) . world_bounds ;
228+ * bounds = item. world_bounds . union ( bounds) ;
229+ }
228230 }
229231 }
230232}
0 commit comments