Repository: JonahPlusPlus/bevy_atmosphere (language: rust)

Issue:
Support 2+ cameras (including UI)
`bevy_atmosphere` grabs the first camera it finds instead of the main 3D camera. This prevents using the plugin with 2+ cameras, and in particular with a main 3D camera and a UI one, which I'd argue is a rather common case.

The problem is that the camera transform query just picks any `Camera`:
https://github.com/JonahPlusPlus/bevy_atmosphere/blob/f85f3a5414862b077164ef8225f1e02ff578fa6d/src/lib.rs#L104-L110

Instead I believe it should query the active 3D one via `ActiveCameras`:
```rust
fn atmosphere_sky_follow(
    camera_transform_query: Query<
        (&GlobalTransform, Entity),
        (With<Camera>, Without<Handle<AtmosphereMat>>),
    >,
    mut sky_transform_query: Query<&mut GlobalTransform, With<Handle<AtmosphereMat>>>,
    active_cameras: Res<ActiveCameras>,
) {
    if let Some(camera_3d) = active_cameras.get(CameraPlugin::CAMERA_3D) {
        if let Some(camera_3d_entity) = camera_3d.entity {
            for (camera_transform, entity) in camera_transform_query.iter() {
                if entity == camera_3d_entity {
                    if let Some(mut sky_transform) = sky_transform_query.iter_mut().next() {
                        sky_transform.translation = camera_transform.translation;
                    }
                    break;
                }
            }
        }
    }
}
```

I tested the fix above and can render some UI on top of the atmosphere background and 3D scene.


Discussion / hints:
Ah, thank you for this. Would you mind creating a PR so we can test and merge this?

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index c0ea3be..69a64d3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -19,7 +19,7 @@
 //! }
 //! ```
 
-use bevy::render::camera::Camera;
+use bevy::render::camera::{ActiveCameras, Camera, CameraPlugin};
 use bevy::{pbr::NotShadowCaster, prelude::*};
 use std::ops::Deref;
 
@@ -113,10 +113,15 @@ fn atmosphere_add_sky_sphere(
 fn atmosphere_sky_follow(
     camera_transform_query: Query<&GlobalTransform, (With<Camera>, Without<Handle<AtmosphereMat>>)>,
     mut sky_transform_query: Query<&mut GlobalTransform, With<Handle<AtmosphereMat>>>,
+    active_cameras: Res<ActiveCameras>,
 ) {
-    if let Some(camera_transform) = camera_transform_query.iter().next() {
-        if let Some(mut sky_transform) = sky_transform_query.iter_mut().next() {
-            sky_transform.translation = camera_transform.translation;
+    if let Some(camera_3d) = active_cameras.get(CameraPlugin::CAMERA_3D) {
+        if let Some(camera_3d_entity) = camera_3d.entity {
+            if let Ok(camera_transform) = camera_transform_query.get(camera_3d_entity) {
+                if let Some(mut sky_transform) = sky_transform_query.iter_mut().next() {
+                    sky_transform.translation = camera_transform.translation;
+                }
+            }
         }
     }
 }


Test patch: