2024-09-27 17:06:48 +00:00
|
|
|
#![expect(deprecated)]
|
2024-05-31 16:40:36 +00:00
|
|
|
use bevy_ecs::bundle::Bundle;
|
|
|
|
|
|
|
|
use crate::prelude::{GlobalTransform, Transform};
|
|
|
|
|
|
|
|
/// A [`Bundle`] of the [`Transform`] and [`GlobalTransform`]
|
2024-07-11 13:08:31 +00:00
|
|
|
/// [`Component`](bevy_ecs::component::Component)s, which describe the position of an entity.
|
2024-05-31 16:40:36 +00:00
|
|
|
///
|
|
|
|
/// * To place or move an entity, you should set its [`Transform`].
|
|
|
|
/// * To get the global transform of an entity, you should get its [`GlobalTransform`].
|
|
|
|
/// * For transform hierarchies to work correctly, you must have both a [`Transform`] and a [`GlobalTransform`].
|
2024-09-27 19:06:16 +00:00
|
|
|
/// * ~You may use the [`TransformBundle`] to guarantee this.~
|
|
|
|
/// [`TransformBundle`] is now deprecated.
|
|
|
|
/// [`GlobalTransform`] is automatically inserted whenever [`Transform`] is inserted.
|
2024-05-31 16:40:36 +00:00
|
|
|
///
|
|
|
|
/// ## [`Transform`] and [`GlobalTransform`]
|
|
|
|
///
|
|
|
|
/// [`Transform`] is the position of an entity relative to its parent position, or the reference
|
|
|
|
/// frame if it doesn't have a parent.
|
|
|
|
///
|
|
|
|
/// [`GlobalTransform`] is the position of an entity relative to the reference frame.
|
|
|
|
///
|
|
|
|
/// [`GlobalTransform`] is updated from [`Transform`] by systems in the system set
|
2024-07-11 13:08:31 +00:00
|
|
|
/// [`TransformPropagate`](crate::TransformSystem::TransformPropagate).
|
2024-05-31 16:40:36 +00:00
|
|
|
///
|
2024-07-11 13:08:31 +00:00
|
|
|
/// This system runs during [`PostUpdate`](bevy_app::PostUpdate). If you
|
2024-05-31 16:40:36 +00:00
|
|
|
/// update the [`Transform`] of an entity in this schedule or after, you will notice a 1 frame lag
|
|
|
|
/// before the [`GlobalTransform`] is updated.
|
|
|
|
#[derive(Clone, Copy, Debug, Default, Bundle)]
|
2024-09-27 17:06:48 +00:00
|
|
|
#[deprecated(
|
|
|
|
since = "0.15.0",
|
|
|
|
note = "Use the `Transform` component instead. Inserting `Transform` will now also insert a `GlobalTransform` automatically."
|
|
|
|
)]
|
2024-05-31 16:40:36 +00:00
|
|
|
pub struct TransformBundle {
|
|
|
|
/// The transform of the entity.
|
|
|
|
pub local: Transform,
|
|
|
|
/// The global transform of the entity.
|
|
|
|
pub global: GlobalTransform,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TransformBundle {
|
|
|
|
/// An identity [`TransformBundle`] with no translation, rotation, and a scale of 1 on all axes.
|
|
|
|
pub const IDENTITY: Self = TransformBundle {
|
|
|
|
local: Transform::IDENTITY,
|
|
|
|
global: GlobalTransform::IDENTITY,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Creates a new [`TransformBundle`] from a [`Transform`].
|
|
|
|
///
|
|
|
|
/// This initializes [`GlobalTransform`] as identity, to be updated later by the
|
2024-07-11 13:08:31 +00:00
|
|
|
/// [`bevy_app::PostUpdate`] schedule.
|
2024-05-31 16:40:36 +00:00
|
|
|
#[inline]
|
|
|
|
pub const fn from_transform(transform: Transform) -> Self {
|
|
|
|
TransformBundle {
|
|
|
|
local: transform,
|
|
|
|
..Self::IDENTITY
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Transform> for TransformBundle {
|
|
|
|
#[inline]
|
|
|
|
fn from(transform: Transform) -> Self {
|
|
|
|
Self::from_transform(transform)
|
|
|
|
}
|
|
|
|
}
|