owned this note
owned this note
Published
Linked with GitHub
# Bundles
## `Camera2dBundle`
```rust
pub struct Camera2dBundle {
pub camera: Camera,
pub camera_render_graph: CameraRenderGraph,
/// Note: default value for `OrthographicProjection.near` is `0.0`
/// which makes objects on the screen plane invisible to 2D camera.
/// `Camera2dBundle::default()` sets `near` to negative value,
/// so be careful when initializing this field manually.
pub projection: OrthographicProjection,
pub visible_entities: VisibleEntities,
pub frustum: Frustum,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub camera_2d: Camera2d,
pub tonemapping: Tonemapping,
pub deband_dither: DebandDither,
pub main_texture_usages: CameraMainTextureUsages,
pub msaa: Msaa,
}
impl Default for Camera2dBundle {
fn default() -> Self {
let projection = OrthographicProjection::default_2d();
let transform = Transform::default();
let frustum = projection.compute_frustum(&GlobalTransform::from(transform));
Self {
camera_render_graph: CameraRenderGraph::new(Core2d),
projection,
visible_entities: VisibleEntities::default(),
frustum,
transform,
global_transform: Default::default(),
camera: Camera::default(),
camera_2d: Camera2d,
tonemapping: Tonemapping::None,
deband_dither: DebandDither::Disabled,
main_texture_usages: Default::default(),
msaa: Default::default(),
}
}
}
```
## `Camera3dBundle`
```rust
pub struct Camera3dBundle {
pub camera: Camera,
pub camera_render_graph: CameraRenderGraph,
pub projection: Projection,
pub visible_entities: VisibleEntities,
pub frustum: Frustum,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub camera_3d: Camera3d,
pub tonemapping: Tonemapping,
pub deband_dither: DebandDither,
pub color_grading: ColorGrading,
pub exposure: Exposure,
pub main_texture_usages: CameraMainTextureUsages,
pub msaa: Msaa,
}
impl Default for Camera3dBundle {
fn default() -> Self {
Self {
camera_render_graph: CameraRenderGraph::new(Core3d),
camera: Default::default(),
projection: Default::default(),
visible_entities: Default::default(),
frustum: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
camera_3d: Default::default(),
tonemapping: Default::default(),
color_grading: Default::default(),
exposure: Default::default(),
main_texture_usages: Default::default(),
deband_dither: DebandDither::Enabled,
msaa: Default::default(),
}
}
}
```
## Combined Proposal 1 (Selected)
```rust
#[derive(Component)]
#[require(VisibleEntities, Frustum, Transform, CameraMainTextureUsages)]
pub struct Camera;
#[derive(Component)]
#[require(
Camera,
Projection,
Frustum,
ColorGrading,
Exposure,
Tonemapping,
CameraRenderGraph(Camera3d::default_render_graph),
DebandDither(Camera3d::default_deband_dither)
)]
pub struct Camera3d;
impl Camera3d {
fn default_render_graph() -> CameraRenderGraph {
CameraRenderGraph::new(Core3d)
}
fn default_deband_dither() -> DebandDither {
DebandDither::Enabled
}
}
#[require(
Camera,
DebandDither,
CameraRenderGraph(Camera2d::default_render_graph),
OrthographicProjection(Camera2d::default_projection),
Frustum(Camera2d::default_frustum),
Tonemapping(Camera2d::default_tonemapping)
)]
pub struct Camera2d;
impl Camera2d {
fn default_render_graph() -> CameraRenderGraph {
CameraRenderGraph::new(Core2d)
}
fn default_projection() -> OrthographicProjection {
OrthographicProjection::default_2d()
}
fn default_frustum() -> Frustum {
Self::default_projection().compute_frustum(&GlobalTransform::from(Transform::default()))
}
fn default_tonemapping() -> Tonemapping {
Tonemapping::None
}
}
```