Skip to content

Commit

Permalink
rename Visibility::Shown variant again, this time to Inherited
Browse files Browse the repository at this point in the history
  • Loading branch information
ickk committed Oct 19, 2022
1 parent b70572a commit 7c02419
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ async fn load_gltf<'a, 'b>(
let mut entity_to_skin_index_map = HashMap::new();

world
.spawn(SpatialBundle::SHOWN_IDENTITY)
.spawn(SpatialBundle::INHERITED_IDENTITY)
.with_children(|parent| {
for node in scene.nodes() {
let result = load_node(
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_render/src/spatial_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ impl SpatialBundle {
pub const fn from_transform(transform: Transform) -> Self {
SpatialBundle {
transform,
..Self::SHOWN_IDENTITY
..Self::INHERITED_IDENTITY
}
}

/// A visible [`SpatialBundle`], with no translation, rotation, and a scale of 1 on all axes.
pub const SHOWN_IDENTITY: Self = SpatialBundle {
visibility: Visibility::Shown,
pub const INHERITED_IDENTITY: Self = SpatialBundle {
visibility: Visibility::Inherited,
computed: ComputedVisibility::HIDDEN,
transform: Transform::IDENTITY,
global_transform: GlobalTransform::IDENTITY,
Expand All @@ -48,7 +48,7 @@ impl SpatialBundle {
/// An invisible [`SpatialBundle`], with no translation, rotation, and a scale of 1 on all axes.
pub const HIDDEN_IDENTITY: Self = SpatialBundle {
visibility: Visibility::Hidden,
..Self::SHOWN_IDENTITY
..Self::INHERITED_IDENTITY
};
}

Expand Down
30 changes: 17 additions & 13 deletions crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ use crate::{
#[derive(Component, Clone, Copy, Reflect, Debug, PartialEq, Eq)]
#[reflect(Component, Default)]
pub enum Visibility {
Shown,
Inherited,
Hidden,
}

impl Default for Visibility {
fn default() -> Self {
Self::Shown
Self::Inherited
}
}

Expand All @@ -46,29 +46,33 @@ impl Not for Visibility {
#[inline]
fn not(self) -> Visibility {
match self {
Visibility::Shown => Visibility::Hidden,
Visibility::Hidden => Visibility::Shown,
Visibility::Inherited => Visibility::Hidden,
Visibility::Hidden => Visibility::Inherited,
}
}
}

impl Visibility {
/// Whether this entity is visible.
/// Whether this entity is Inherited.
#[inline]
pub const fn is_visible(&self) -> bool {
matches!(self, Self::Shown)
pub const fn is_inherited(&self) -> bool {
matches!(self, Self::Inherited)
}

/// Toggle the visibility.
/// Toggle the visibility state between Inherited and Hidden.
#[inline]
pub fn toggle(&mut self) {
*self = !*self;
}

/// Set the visibility using a boolean expression.
/// Set the visibility to either Inherited or Hidden using a boolean expression.
#[inline]
pub fn set(&mut self, shown: bool) {
*self = if shown { Self::Shown } else { Self::Hidden }
pub fn set(&mut self, inherited: bool) {
*self = if inherited {
Self::Inherited
} else {
Self::Hidden
}
}
}

Expand Down Expand Up @@ -289,7 +293,7 @@ fn visibility_propagate_system(
children_query: Query<&Children, (With<Parent>, With<Visibility>, With<ComputedVisibility>)>,
) {
for (children, visibility, mut computed_visibility, entity) in root_query.iter_mut() {
computed_visibility.is_visible_in_hierarchy = visibility.is_visible();
computed_visibility.is_visible_in_hierarchy = visibility.is_inherited();
// reset "view" visibility here ... if this entity should be drawn a future system should set this to true
computed_visibility.is_visible_in_view = false;
if let Some(children) = children {
Expand Down Expand Up @@ -322,7 +326,7 @@ fn propagate_recursive(
child_parent.get(), expected_parent,
"Malformed hierarchy. This probably means that your hierarchy has been improperly maintained, or contains a cycle"
);
computed_visibility.is_visible_in_hierarchy = visibility.is_visible() && parent_visible;
computed_visibility.is_visible_in_hierarchy = visibility.is_inherited() && parent_visible;
// reset "view" visibility here ... if this entity should be drawn a future system should set this to true
computed_visibility.is_visible_in_view = false;
computed_visibility.is_visible_in_hierarchy
Expand Down
2 changes: 1 addition & 1 deletion examples/2d/mesh2d_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn star(
// The `Handle<Mesh>` needs to be wrapped in a `Mesh2dHandle` to use 2d rendering instead of 3d
Mesh2dHandle(meshes.add(star)),
// This bundle's components are needed for something to be rendered
SpatialBundle::SHOWN_IDENTITY,
SpatialBundle::INHERITED_IDENTITY,
));

// Spawn the camera
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/animated_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn setup(
.with_children(|p| {
// This entity is just used for animation, but doesn't display anything
p.spawn((
SpatialBundle::SHOWN_IDENTITY,
SpatialBundle::INHERITED_IDENTITY,
// Add the Name component
orbit_controller,
))
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/shader_instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {
fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
commands.spawn((
meshes.add(Mesh::from(shape::Cube { size: 0.5 })),
SpatialBundle::SHOWN_IDENTITY,
SpatialBundle::INHERITED_IDENTITY,
InstanceMaterialData(
(1..=10)
.flat_map(|x| (1..=10).map(move |y| (x as f32 / 10.0, y as f32 / 10.0)))
Expand Down
2 changes: 1 addition & 1 deletion examples/stress_tests/many_foxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn setup(
let (base_rotation, ring_direction) = ring_directions[ring_index % 2];
let ring_parent = commands
.spawn((
SpatialBundle::SHOWN_IDENTITY,
SpatialBundle::INHERITED_IDENTITY,
ring_direction,
Ring { radius },
))
Expand Down

0 comments on commit 7c02419

Please sign in to comment.