bevy_render/
spatial_bundle.rs

1#![expect(deprecated)]
2use bevy_ecs::prelude::Bundle;
3use bevy_transform::prelude::{GlobalTransform, Transform};
4
5use crate::view::{InheritedVisibility, ViewVisibility, Visibility};
6
7/// A [`Bundle`] that allows the correct positional rendering of an entity.
8///
9/// It consists of transform components,
10/// controlling position, rotation and scale of the entity,
11/// but also visibility components,
12/// which determine whether the entity is visible or not.
13///
14/// Parent-child hierarchies of entities must contain
15/// all the [`Component`]s in this `Bundle`
16/// to be rendered correctly.
17///
18/// [`Component`]: bevy_ecs::component::Component
19#[derive(Bundle, Clone, Debug, Default)]
20#[deprecated(
21    since = "0.15.0",
22    note = "Use the `Transform` and `Visibility` components instead.
23        Inserting `Transform` will now also insert a `GlobalTransform` automatically.
24        Inserting 'Visibility' will now also insert `InheritedVisibility` and `ViewVisibility` automatically."
25)]
26pub struct SpatialBundle {
27    /// The visibility of the entity.
28    pub visibility: Visibility,
29    /// The inherited visibility of the entity.
30    pub inherited_visibility: InheritedVisibility,
31    /// The view visibility of the entity.
32    pub view_visibility: ViewVisibility,
33    /// The transform of the entity.
34    pub transform: Transform,
35    /// The global transform of the entity.
36    pub global_transform: GlobalTransform,
37}
38
39impl SpatialBundle {
40    /// Creates a new [`SpatialBundle`] from a [`Transform`].
41    ///
42    /// This initializes [`GlobalTransform`] as identity, and visibility as visible
43    #[inline]
44    pub const fn from_transform(transform: Transform) -> Self {
45        SpatialBundle {
46            transform,
47            ..Self::INHERITED_IDENTITY
48        }
49    }
50
51    /// A [`SpatialBundle`] with inherited visibility and identity transform.
52    pub const INHERITED_IDENTITY: Self = SpatialBundle {
53        visibility: Visibility::Inherited,
54        inherited_visibility: InheritedVisibility::HIDDEN,
55        view_visibility: ViewVisibility::HIDDEN,
56        transform: Transform::IDENTITY,
57        global_transform: GlobalTransform::IDENTITY,
58    };
59
60    /// An invisible [`SpatialBundle`] with identity transform.
61    pub const HIDDEN_IDENTITY: Self = SpatialBundle {
62        visibility: Visibility::Hidden,
63        ..Self::INHERITED_IDENTITY
64    };
65}
66
67impl From<Transform> for SpatialBundle {
68    #[inline]
69    fn from(transform: Transform) -> Self {
70        Self::from_transform(transform)
71    }
72}