@@ -964,16 +964,7 @@ pub(crate) fn assign_lights_to_clusters(
964
964
. lights
965
965
. resize_with ( clusters. aabbs . len ( ) , VisiblePointLights :: default) ;
966
966
967
- let mut visible_lights_scratch = Vec :: new ( ) ;
968
-
969
- {
970
- // reuse existing visible lights Vec, if it exists
971
- let visible_lights = if let Some ( visible_lights) = visible_lights. as_mut ( ) {
972
- visible_lights. entities . clear ( ) ;
973
- & mut visible_lights. entities
974
- } else {
975
- & mut visible_lights_scratch
976
- } ;
967
+ let mut update_from_light_intersections = |visible_lights : & mut Vec < Entity > | {
977
968
for light in lights. iter ( ) {
978
969
let light_sphere = Sphere {
979
970
center : Vec3A :: from ( light. translation ) ,
@@ -1029,12 +1020,18 @@ pub(crate) fn assign_lights_to_clusters(
1029
1020
}
1030
1021
}
1031
1022
}
1032
- }
1023
+ } ;
1033
1024
1034
- if visible_lights. is_none ( ) {
1035
- commands. entity ( view_entity) . insert ( VisiblePointLights {
1036
- entities : visible_lights_scratch,
1037
- } ) ;
1025
+ // reuse existing visible lights Vec, if it exists
1026
+ if let Some ( visible_lights) = visible_lights. as_mut ( ) {
1027
+ visible_lights. entities . clear ( ) ;
1028
+ update_from_light_intersections ( & mut visible_lights. entities ) ;
1029
+ } else {
1030
+ let mut entities = Vec :: new ( ) ;
1031
+ update_from_light_intersections ( & mut entities) ;
1032
+ commands
1033
+ . entity ( view_entity)
1034
+ . insert ( VisiblePointLights { entities } ) ;
1038
1035
}
1039
1036
}
1040
1037
}
0 commit comments