@@ -203,31 +203,33 @@ impl Hub {
203203 }
204204
205205 fn update_graph ( & mut self ) {
206- let mut cursor = self . nodes . cursor_alive ( ) ;
207- while let Some ( mut item) = cursor. next ( ) {
206+ let mut cursor = self . nodes . cursor ( ) ;
207+ // forward pass: derive visibility, scene id, and world transform
208+ // from the parent `Node`
209+ while let Some ( ( left, mut item, _) ) = cursor. next ( ) {
208210 if !item. visible {
209211 item. world_visible = false ;
210212 continue
211213 }
212- let ( visibility, affilation, transform, bounds ) = match item. parent {
214+ let ( visibility, affilation, transform) = match item. parent {
213215 Some ( ref parent_ptr) => {
214- let parent = item . look_back ( parent_ptr) . unwrap ( ) ;
216+ let parent = left . get ( parent_ptr) . unwrap ( ) ;
215217 let transform = parent. world_transform . concat ( & item. transform ) ;
216- let bounds = if parent. world_visible {
217- let bounds = item. bounds . transform ( & transform) ;
218- parent. world_bounds = parent. world_bounds . union ( & bounds) ;
219- bounds
220- } else {
221- item. bounds
222- } ;
223- ( parent. world_visible , parent. scene_id , transform, bounds)
218+ ( parent. world_visible , parent. scene_id , transform)
224219 } ,
225- None => ( true , item. scene_id , item. transform , item . bounds ) ,
220+ None => ( true , item. scene_id , item. transform ) ,
226221 } ;
227222 item. world_visible = visibility;
228223 item. scene_id = affilation;
229224 item. world_transform = transform;
230- item. world_bounds = bounds;
225+ item. world_bounds = item. bounds . transform ( & transform) ;
226+ }
227+ // backwards pass: accumulate bounding boxes of children
228+ while let Some ( ( mut left, item, _) ) = cursor. prev ( ) {
229+ if let ( true , Some ( parent_ptr) ) = ( item. world_visible , item. parent . as_ref ( ) ) {
230+ let bounds = & mut left. get_mut ( parent_ptr) . unwrap ( ) . world_bounds ;
231+ * bounds = item. world_bounds . union ( bounds) ;
232+ }
231233 }
232234 }
233235}
0 commit comments