bevy_pbr/
bundle.rs

1#![expect(deprecated)]
2
3use crate::{
4    CascadeShadowConfig, Cascades, DirectionalLight, Material, MeshMaterial3d, PointLight,
5    SpotLight, StandardMaterial,
6};
7use bevy_derive::{Deref, DerefMut};
8use bevy_ecs::{
9    bundle::Bundle,
10    component::Component,
11    entity::{Entity, EntityHashMap},
12    reflect::ReflectComponent,
13};
14use bevy_reflect::{std_traits::ReflectDefault, Reflect};
15use bevy_render::sync_world::MainEntity;
16use bevy_render::{
17    mesh::Mesh3d,
18    primitives::{CascadesFrusta, CubemapFrusta, Frustum},
19    sync_world::SyncToRenderWorld,
20    view::{InheritedVisibility, ViewVisibility, Visibility},
21};
22use bevy_transform::components::{GlobalTransform, Transform};
23
24/// A component bundle for PBR entities with a [`Mesh3d`] and a [`MeshMaterial3d<StandardMaterial>`].
25#[deprecated(
26    since = "0.15.0",
27    note = "Use the `Mesh3d` and `MeshMaterial3d` components instead. Inserting them will now also insert the other components required by them automatically."
28)]
29pub type PbrBundle = MaterialMeshBundle<StandardMaterial>;
30
31/// A component bundle for entities with a [`Mesh3d`] and a [`MeshMaterial3d`].
32#[derive(Bundle, Clone)]
33#[deprecated(
34    since = "0.15.0",
35    note = "Use the `Mesh3d` and `MeshMaterial3d` components instead. Inserting them will now also insert the other components required by them automatically."
36)]
37pub struct MaterialMeshBundle<M: Material> {
38    pub mesh: Mesh3d,
39    pub material: MeshMaterial3d<M>,
40    pub transform: Transform,
41    pub global_transform: GlobalTransform,
42    /// User indication of whether an entity is visible
43    pub visibility: Visibility,
44    /// Inherited visibility of an entity.
45    pub inherited_visibility: InheritedVisibility,
46    /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
47    pub view_visibility: ViewVisibility,
48}
49
50impl<M: Material> Default for MaterialMeshBundle<M> {
51    fn default() -> Self {
52        Self {
53            mesh: Default::default(),
54            material: Default::default(),
55            transform: Default::default(),
56            global_transform: Default::default(),
57            visibility: Default::default(),
58            inherited_visibility: Default::default(),
59            view_visibility: Default::default(),
60        }
61    }
62}
63
64/// Collection of mesh entities visible for 3D lighting.
65///
66/// This component contains all mesh entities visible from the current light view.
67/// The collection is updated automatically by [`crate::SimulationLightSystems`].
68#[derive(Component, Clone, Debug, Default, Reflect, Deref, DerefMut)]
69#[reflect(Component, Debug, Default)]
70pub struct VisibleMeshEntities {
71    #[reflect(ignore)]
72    pub entities: Vec<Entity>,
73}
74
75#[derive(Component, Clone, Debug, Default, Reflect, Deref, DerefMut)]
76#[reflect(Component, Debug, Default)]
77pub struct RenderVisibleMeshEntities {
78    #[reflect(ignore)]
79    pub entities: Vec<(Entity, MainEntity)>,
80}
81
82#[derive(Component, Clone, Debug, Default, Reflect)]
83#[reflect(Component, Debug, Default)]
84pub struct CubemapVisibleEntities {
85    #[reflect(ignore)]
86    data: [VisibleMeshEntities; 6],
87}
88
89impl CubemapVisibleEntities {
90    pub fn get(&self, i: usize) -> &VisibleMeshEntities {
91        &self.data[i]
92    }
93
94    pub fn get_mut(&mut self, i: usize) -> &mut VisibleMeshEntities {
95        &mut self.data[i]
96    }
97
98    pub fn iter(&self) -> impl DoubleEndedIterator<Item = &VisibleMeshEntities> {
99        self.data.iter()
100    }
101
102    pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut VisibleMeshEntities> {
103        self.data.iter_mut()
104    }
105}
106
107#[derive(Component, Clone, Debug, Default, Reflect)]
108#[reflect(Component, Debug, Default)]
109pub struct RenderCubemapVisibleEntities {
110    #[reflect(ignore)]
111    pub(crate) data: [RenderVisibleMeshEntities; 6],
112}
113
114impl RenderCubemapVisibleEntities {
115    pub fn get(&self, i: usize) -> &RenderVisibleMeshEntities {
116        &self.data[i]
117    }
118
119    pub fn get_mut(&mut self, i: usize) -> &mut RenderVisibleMeshEntities {
120        &mut self.data[i]
121    }
122
123    pub fn iter(&self) -> impl DoubleEndedIterator<Item = &RenderVisibleMeshEntities> {
124        self.data.iter()
125    }
126
127    pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut RenderVisibleMeshEntities> {
128        self.data.iter_mut()
129    }
130}
131
132#[derive(Component, Clone, Debug, Default, Reflect)]
133#[reflect(Component)]
134pub struct CascadesVisibleEntities {
135    /// Map of view entity to the visible entities for each cascade frustum.
136    #[reflect(ignore)]
137    pub entities: EntityHashMap<Vec<VisibleMeshEntities>>,
138}
139
140#[derive(Component, Clone, Debug, Default, Reflect)]
141#[reflect(Component)]
142pub struct RenderCascadesVisibleEntities {
143    /// Map of view entity to the visible entities for each cascade frustum.
144    #[reflect(ignore)]
145    pub entities: EntityHashMap<Vec<RenderVisibleMeshEntities>>,
146}
147
148/// A component bundle for [`PointLight`] entities.
149#[derive(Debug, Bundle, Default, Clone)]
150#[deprecated(
151    since = "0.15.0",
152    note = "Use the `PointLight` component instead. Inserting it will now also insert the other components required by it automatically."
153)]
154pub struct PointLightBundle {
155    pub point_light: PointLight,
156    pub cubemap_visible_entities: CubemapVisibleEntities,
157    pub cubemap_frusta: CubemapFrusta,
158    pub transform: Transform,
159    pub global_transform: GlobalTransform,
160    /// Enables or disables the light
161    pub visibility: Visibility,
162    /// Inherited visibility of an entity.
163    pub inherited_visibility: InheritedVisibility,
164    /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
165    pub view_visibility: ViewVisibility,
166    /// Marker component that indicates that its entity needs to be synchronized to the render world
167    pub sync: SyncToRenderWorld,
168}
169
170/// A component bundle for spot light entities
171#[derive(Debug, Bundle, Default, Clone)]
172#[deprecated(
173    since = "0.15.0",
174    note = "Use the `SpotLight` component instead. Inserting it will now also insert the other components required by it automatically."
175)]
176pub struct SpotLightBundle {
177    pub spot_light: SpotLight,
178    pub visible_entities: VisibleMeshEntities,
179    pub frustum: Frustum,
180    pub transform: Transform,
181    pub global_transform: GlobalTransform,
182    /// Enables or disables the light
183    pub visibility: Visibility,
184    /// Inherited visibility of an entity.
185    pub inherited_visibility: InheritedVisibility,
186    /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
187    pub view_visibility: ViewVisibility,
188    /// Marker component that indicates that its entity needs to be synchronized to the render world
189    pub sync: SyncToRenderWorld,
190}
191
192/// A component bundle for [`DirectionalLight`] entities.
193#[derive(Debug, Bundle, Default, Clone)]
194#[deprecated(
195    since = "0.15.0",
196    note = "Use the `DirectionalLight` component instead. Inserting it will now also insert the other components required by it automatically."
197)]
198pub struct DirectionalLightBundle {
199    pub directional_light: DirectionalLight,
200    pub frusta: CascadesFrusta,
201    pub cascades: Cascades,
202    pub cascade_shadow_config: CascadeShadowConfig,
203    pub visible_entities: CascadesVisibleEntities,
204    pub transform: Transform,
205    pub global_transform: GlobalTransform,
206    /// Enables or disables the light
207    pub visibility: Visibility,
208    /// Inherited visibility of an entity.
209    pub inherited_visibility: InheritedVisibility,
210    /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
211    pub view_visibility: ViewVisibility,
212    /// Marker component that indicates that its entity needs to be synchronized to the render world
213    pub sync: SyncToRenderWorld,
214}