-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - add a SpatialBundle with visibility and transform components #5344
Changes from 2 commits
141a119
98b9191
ef320d1
f6b3d9f
29d8374
94f8119
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use bevy_ecs::prelude::Bundle; | ||
use bevy_transform::prelude::{GlobalTransform, Transform}; | ||
|
||
use crate::view::{ComputedVisibility, Visibility}; | ||
|
||
/// A [`Bundle`] with the following [`Component`](bevy_ecs::component::Component)s: | ||
/// * [`Visibility`] and [`ComputedVisibility`], which describe the visibility of an entity | ||
/// * [`Transform`] and [`GlobalTransform`], which describe the position of an entity | ||
/// | ||
/// * To show or hide an entity, you should set its [`Visibility`]. | ||
/// * To get the computed visibility of an entity, you should get its [`ComputedVisibility`]. | ||
/// * To place or move an entity, you should set its [`Transform`]. | ||
/// * To get the global position of an entity, you should get its [`GlobalTransform`]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not just global position, but global transform. :) Maybe note that it is only valid for the current frame after transform propagation has been run? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the one hand, this is useful information. On the other hand, idk if we should be duplicating it across every bundle that includes GlobalTransform. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do agree that "global transform" is preferable to "global position". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
/// * For hierarchies to work correctly, you must have all four components. | ||
/// * You may use the [`BaseBundle`] to guarantee this. | ||
mockersf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[derive(Bundle, Debug, Default)] | ||
pub struct BaseBundle { | ||
mockersf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// The visibility of the entity. | ||
pub visibility: Visibility, | ||
/// The computed visibility of the entity. | ||
pub computed: ComputedVisibility, | ||
/// The transform of the entity. | ||
pub transform: Transform, | ||
/// The global transform of the entity. | ||
pub global_transform: GlobalTransform, | ||
} | ||
|
||
impl BaseBundle { | ||
/// Creates a new [`BaseBundle`] from a [`Transform`]. | ||
/// | ||
/// This initializes [`GlobalTransform`] as identity, and visibility as visible | ||
#[inline] | ||
pub const fn from_transform(transform: Transform) -> Self { | ||
BaseBundle { | ||
local: transform, | ||
// Note: `..Default::default()` cannot be used here, because it isn't const | ||
..Self::visible_identity() | ||
} | ||
} | ||
|
||
/// Creates a new identity [`BaseBundle`], with no translation, rotation, and a scale of 1 | ||
/// on all axes. | ||
#[inline] | ||
pub const fn visible_identity() -> Self { | ||
mockersf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BaseBundle { | ||
local: Transform::identity(), | ||
global: GlobalTransform::identity(), | ||
visibility: Visibility::visible(), | ||
computed: ComputedVisibility::visible(), | ||
} | ||
} | ||
} | ||
|
||
impl From<Transform> for BaseBundle { | ||
#[inline] | ||
fn from(transform: Transform) -> Self { | ||
Self::from_transform(transform) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe note that it is only valid after the visibility systems have been run? (check_visibility and visibility_propagate, I think.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the one hand, this is useful information. On the other hand, idk if we should be duplicating it across every bundle that includes ComputedVisibility. ComputedVisibility does have this "label dependency" information encoded in the relevant fields already. But it is probably worth also including that in the main ComputedVisibility docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Not something I think we should block on here though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#5372