You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: lod.rs
    path of file: ./repos/Ambient/crates/renderer/src
    
    the code of the file until where you have to start completion: use ambient_core::{
    bounding::world_bounding_sphere,
    camera::{fovy
    
pub fn lod_system() -> SystemGroup {
    SystemGroup::new(
        "lod",
        vec![
            query((lod_cutoffs(), cpu_lod(), world_bounding_sphere())).to_system(
                |q, world, qs, _| {
                    if let Some(main_camera) =
                        get_active_camera(world, main_scene(), world.resource_opt(local_user_id()))
                    {
                        let camera_pos =
                            world.get(main_camera, translation()).unwrap_or(Vec3::ZERO);
                        let main_camera_fov = match world.get(main_camera, fovy()) {
                            Ok(val) => val,
                            Err(_) => return,
                        };
                        let main_camera_cot_fov_2 = 1. / (main_camera_fov / 2.).tan();

                        // let frame = world.resource(frame_index());
                        // let count = q.query.iter(world, None).count();
                        // let chunk_size = (count / 100).max(1);
                        // let chunks = ((count as f32 / chunk_size as f32).ceil() as usize).max(1);
                        // let start = (frame % chunks) * chunk_size;

                        let mut to_update = Vec::new();
                        for (id, (lod_cutoffs, &current_lod, bounding_sphere)) in q.iter(world, qs)
                        {
                            let dist = (camera_pos - bounding_sphere.center).length();
                            let clip_space_radius =
                                bounding_sphere.radius * main_camera_cot_fov_2 / dist;

                            let l = lod_cutoffs
                                .0
                                .iter()
                                .position(|x| clip_space_radius >= *x)
                                .unwrap_or(lod_cutoffs.0.len());
                            if l != current_lod {
                                to_update.push((id, l, current_lod));
                            }
                        }
                        for (id, l, current_lod) in to_update {
                            world.set(id, cpu_lod(), l).unwrap();
                            if world.has_component(id, cpu_lod_group()) {
                                if let Ok(children) =
                                    world.get_ref(id, children()).map(|x| x.clone())
                                {
                                    if current_lod < children.len() {
                                        set_lod_visible_recursive(
                                            world,
                                            children[current_lod],
                                            false,
                                        )
                                        .unwrap();
                                    }
                                    if l < children.len() {
                                        set_lod_visible_recursive(world, children[l], true)
                                            .unwrap();
                                    }
                                }
                            }
                        }
                    }
                },
            ),
        ],
    )
}