wde_camera/lib.rs
1//! Camera plugin for WaterDropEngine.
2//!
3//! This plugin provides a camera component and a camera view component, as well as a system to extract the active camera and update the camera uniform each frame.
4//!
5//! # Example
6//! To spawn the default active camera, add a [`ActiveCamera`](crate::camera::ActiveCamera) component.
7//! This will automatically spawn a [`Camera`](crate::camera::Camera) component and a [`CameraView`](crate::view::CameraView) component with default parameters.
8//! For example:
9//! ```rust
10//! commands.spawn((
11//! Transform::from_xyz(0.0, 2.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
12//! ActiveCamera
13//! ));
14//! ```
15//!
16//! If you want to customize the camera view parameters, you can spawn the components separately and add the `ActiveCamera` marker:
17//! ```rust
18//! commands.spawn((
19//! Transform::from_xyz(0.0, 2.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
20//! Camera,
21//! CameraView::default(),
22//! ActiveCamera
23//! ));
24//! ```
25//!
26//! The camera uniform will then be automatically updated each frame with the active camera's transform and view parameters.
27//! To consumes the camera uniform in a shader, you can use the [`CameraRender`](crate::camera::CameraRender) render binding.
28//! It is accessible by the resource `Res<RenderAssets<GpuRenderBinding<CameraRender>>>` in render systems, or `SBindings<CameraRender>` in shader code.
29//! See [`GpuRenderBinding`](wde_renderer::prelude::GpuRenderBinding) for more details on how to use render bindings in shaders.
30use bevy::prelude::*;
31
32use crate::camera::CameraFeature;
33
34#[doc(hidden)]
35pub mod prelude {
36 pub use crate::camera::{ActiveCamera, Camera, CameraBinding};
37 pub use crate::transform::TransformUniform;
38 pub use crate::view::CameraView;
39}
40
41mod camera;
42#[cfg(debug_assertions)]
43mod editor;
44mod transform;
45mod view;
46
47pub struct CameraPlugin;
48impl Plugin for CameraPlugin {
49 fn build(&self, app: &mut App) {
50 app.add_plugins(CameraFeature);
51
52 #[cfg(debug_assertions)]
53 app.add_plugins(editor::CameraPropertiesEditor);
54 }
55}