@@ -926,16 +926,7 @@ pub(crate) fn assign_lights_to_clusters(
926
926
z_planes. push ( Plane :: new ( normal. extend ( d) ) ) ;
927
927
}
928
928
929
- let mut visible_lights_scratch = Vec :: new ( ) ;
930
-
931
- {
932
- // reuse existing visible lights Vec, if it exists
933
- let visible_lights = if let Some ( visible_lights) = visible_lights. as_mut ( ) {
934
- visible_lights. entities . clear ( ) ;
935
- & mut visible_lights. entities
936
- } else {
937
- & mut visible_lights_scratch
938
- } ;
929
+ let mut update_from_light_intersections = |visible_lights : & mut Vec < Entity > | {
939
930
for light in lights. iter ( ) {
940
931
let light_sphere = Sphere {
941
932
center : Vec3A :: from ( light. translation ) ,
@@ -1088,12 +1079,18 @@ pub(crate) fn assign_lights_to_clusters(
1088
1079
}
1089
1080
}
1090
1081
}
1091
- }
1082
+ } ;
1092
1083
1093
- if visible_lights. is_none ( ) {
1094
- commands. entity ( view_entity) . insert ( VisiblePointLights {
1095
- entities : visible_lights_scratch,
1096
- } ) ;
1084
+ // reuse existing visible lights Vec, if it exists
1085
+ if let Some ( visible_lights) = visible_lights. as_mut ( ) {
1086
+ visible_lights. entities . clear ( ) ;
1087
+ update_from_light_intersections ( & mut visible_lights. entities ) ;
1088
+ } else {
1089
+ let mut entities = Vec :: new ( ) ;
1090
+ update_from_light_intersections ( & mut entities) ;
1091
+ commands
1092
+ . entity ( view_entity)
1093
+ . insert ( VisiblePointLights { entities } ) ;
1097
1094
}
1098
1095
}
1099
1096
}
0 commit comments