From 833ceb208e1d04f56fd81945317ae95d4dea4836 Mon Sep 17 00:00:00 2001 From: ickk Date: Mon, 17 Oct 2022 02:49:27 +1100 Subject: [PATCH 1/7] Turn the `Visibility` struct into an enum --- crates/bevy_render/src/spatial_bundle.rs | 4 +- crates/bevy_render/src/view/visibility/mod.rs | 48 +++++++++---------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/crates/bevy_render/src/spatial_bundle.rs b/crates/bevy_render/src/spatial_bundle.rs index 6eedd7cbf5992..1acb827e984e0 100644 --- a/crates/bevy_render/src/spatial_bundle.rs +++ b/crates/bevy_render/src/spatial_bundle.rs @@ -39,7 +39,7 @@ impl SpatialBundle { /// A visible [`SpatialBundle`], with no translation, rotation, and a scale of 1 on all axes. pub const VISIBLE_IDENTITY: Self = SpatialBundle { - visibility: Visibility::VISIBLE, + visibility: Visibility::Visible, computed: ComputedVisibility::INVISIBLE, transform: Transform::IDENTITY, global_transform: GlobalTransform::IDENTITY, @@ -47,7 +47,7 @@ impl SpatialBundle { /// An invisible [`SpatialBundle`], with no translation, rotation, and a scale of 1 on all axes. pub const INVISIBLE_IDENTITY: Self = SpatialBundle { - visibility: Visibility::INVISIBLE, + visibility: Visibility::Invisible, ..Self::VISIBLE_IDENTITY }; } diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index d6979ac5e0882..73cce572c5530 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -28,29 +28,34 @@ use crate::{ /// This is done by setting the values of their [`ComputedVisibility`] component. #[derive(Component, Clone, Reflect, Debug)] #[reflect(Component, Default)] -pub struct Visibility { - /// Indicates whether this entity is visible. Hidden values will propagate down the entity hierarchy. - /// If this entity is hidden, all of its descendants will be hidden as well. See [`Children`] and [`Parent`] for - /// hierarchy info. - pub is_visible: bool, +pub enum Visibility { + Visible, + Invisible, } impl Default for Visibility { fn default() -> Self { - Visibility::VISIBLE + Self::Visible } } impl Visibility { - /// A [`Visibility`], set as visible. - pub const VISIBLE: Self = Visibility { is_visible: true }; - - /// A [`Visibility`], set as invisible. - pub const INVISIBLE: Self = Visibility { is_visible: false }; + /// Whether this entity is visible. + #[inline] + pub const fn is_visible(&self) -> bool { + match self { + Self::Visible => true, + Self::Invisible => false, + } + } /// Toggle the visibility. + #[inline] pub fn toggle(&mut self) { - self.is_visible = !self.is_visible; + *self = match self { + Self::Visible => Self::Invisible, + Self::Invisible => Self::Visible, + } } } @@ -271,7 +276,7 @@ fn visibility_propagate_system( children_query: Query<&Children, (With, With, With)>, ) { 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_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; if let Some(children) = children { @@ -304,7 +309,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_visible() && 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 @@ -433,10 +438,7 @@ mod test { let root1 = app .world - .spawn(( - Visibility { is_visible: false }, - ComputedVisibility::default(), - )) + .spawn((Visibility::Invisible, ComputedVisibility::default())) .id(); let root1_child1 = app .world @@ -444,10 +446,7 @@ mod test { .id(); let root1_child2 = app .world - .spawn(( - Visibility { is_visible: false }, - ComputedVisibility::default(), - )) + .spawn((Visibility::Invisible, ComputedVisibility::default())) .id(); let root1_child1_grandchild1 = app .world @@ -478,10 +477,7 @@ mod test { .id(); let root2_child2 = app .world - .spawn(( - Visibility { is_visible: false }, - ComputedVisibility::default(), - )) + .spawn((Visibility::Invisible, ComputedVisibility::default())) .id(); let root2_child1_grandchild1 = app .world From 830c0d9144bf4ca3f61689b61759901f82656c22 Mon Sep 17 00:00:00 2001 From: ickk Date: Tue, 18 Oct 2022 04:00:41 +1100 Subject: [PATCH 2/7] rename `Visibility` variants and related consts to `Shown` & `Hidden` as requested add `Eq`, `PartialEq` derives to `Visibility` --- crates/bevy_gltf/src/loader.rs | 2 +- crates/bevy_render/src/spatial_bundle.rs | 14 +++++----- crates/bevy_render/src/view/visibility/mod.rs | 26 +++++++++---------- examples/2d/mesh2d_manual.rs | 2 +- examples/animation/animated_transform.rs | 2 +- examples/shader/shader_instancing.rs | 2 +- examples/stress_tests/many_foxes.rs | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index ce80600020b1f..91ec72a0d07a0 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -465,7 +465,7 @@ async fn load_gltf<'a, 'b>( let mut entity_to_skin_index_map = HashMap::new(); world - .spawn(SpatialBundle::VISIBLE_IDENTITY) + .spawn(SpatialBundle::SHOWN_IDENTITY) .with_children(|parent| { for node in scene.nodes() { let result = load_node( diff --git a/crates/bevy_render/src/spatial_bundle.rs b/crates/bevy_render/src/spatial_bundle.rs index 1acb827e984e0..e5f0f2dee27f3 100644 --- a/crates/bevy_render/src/spatial_bundle.rs +++ b/crates/bevy_render/src/spatial_bundle.rs @@ -33,22 +33,22 @@ impl SpatialBundle { pub const fn from_transform(transform: Transform) -> Self { SpatialBundle { transform, - ..Self::VISIBLE_IDENTITY + ..Self::SHOWN_IDENTITY } } /// A visible [`SpatialBundle`], with no translation, rotation, and a scale of 1 on all axes. - pub const VISIBLE_IDENTITY: Self = SpatialBundle { - visibility: Visibility::Visible, - computed: ComputedVisibility::INVISIBLE, + pub const SHOWN_IDENTITY: Self = SpatialBundle { + visibility: Visibility::Shown, + computed: ComputedVisibility::HIDDEN, transform: Transform::IDENTITY, global_transform: GlobalTransform::IDENTITY, }; /// An invisible [`SpatialBundle`], with no translation, rotation, and a scale of 1 on all axes. - pub const INVISIBLE_IDENTITY: Self = SpatialBundle { - visibility: Visibility::Invisible, - ..Self::VISIBLE_IDENTITY + pub const HIDDEN_IDENTITY: Self = SpatialBundle { + visibility: Visibility::Hidden, + ..Self::SHOWN_IDENTITY }; } diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index 73cce572c5530..c42fad47ab370 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -26,16 +26,16 @@ use crate::{ /// If an entity is hidden in this way, all [`Children`] (and all of their children and so on) will also be hidden. /// This is done by setting the values of their [`ComputedVisibility`] component. -#[derive(Component, Clone, Reflect, Debug)] +#[derive(Component, Clone, Reflect, Debug, PartialEq, Eq)] #[reflect(Component, Default)] pub enum Visibility { - Visible, - Invisible, + Shown, + Hidden, } impl Default for Visibility { fn default() -> Self { - Self::Visible + Self::Shown } } @@ -44,8 +44,8 @@ impl Visibility { #[inline] pub const fn is_visible(&self) -> bool { match self { - Self::Visible => true, - Self::Invisible => false, + Self::Shown => true, + Self::Hidden => false, } } @@ -53,8 +53,8 @@ impl Visibility { #[inline] pub fn toggle(&mut self) { *self = match self { - Self::Visible => Self::Invisible, - Self::Invisible => Self::Visible, + Self::Shown => Self::Hidden, + Self::Hidden => Self::Shown, } } } @@ -69,13 +69,13 @@ pub struct ComputedVisibility { impl Default for ComputedVisibility { fn default() -> Self { - Self::INVISIBLE + Self::HIDDEN } } impl ComputedVisibility { /// A [`ComputedVisibility`], set as invisible. - pub const INVISIBLE: Self = ComputedVisibility { + pub const HIDDEN: Self = ComputedVisibility { is_visible_in_hierarchy: false, is_visible_in_view: false, }; @@ -438,7 +438,7 @@ mod test { let root1 = app .world - .spawn((Visibility::Invisible, ComputedVisibility::default())) + .spawn((Visibility::Hidden, ComputedVisibility::default())) .id(); let root1_child1 = app .world @@ -446,7 +446,7 @@ mod test { .id(); let root1_child2 = app .world - .spawn((Visibility::Invisible, ComputedVisibility::default())) + .spawn((Visibility::Hidden, ComputedVisibility::default())) .id(); let root1_child1_grandchild1 = app .world @@ -477,7 +477,7 @@ mod test { .id(); let root2_child2 = app .world - .spawn((Visibility::Invisible, ComputedVisibility::default())) + .spawn((Visibility::Hidden, ComputedVisibility::default())) .id(); let root2_child1_grandchild1 = app .world diff --git a/examples/2d/mesh2d_manual.rs b/examples/2d/mesh2d_manual.rs index 5eb72f3a19d88..0eca79eadc357 100644 --- a/examples/2d/mesh2d_manual.rs +++ b/examples/2d/mesh2d_manual.rs @@ -103,7 +103,7 @@ fn star( // The `Handle` 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::VISIBLE_IDENTITY, + SpatialBundle::SHOWN_IDENTITY, )); // Spawn the camera diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index 19f284aa02519..73f1670a6efbf 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -129,7 +129,7 @@ fn setup( .with_children(|p| { // This entity is just used for animation, but doesn't display anything p.spawn(( - SpatialBundle::VISIBLE_IDENTITY, + SpatialBundle::SHOWN_IDENTITY, // Add the Name component orbit_controller, )) diff --git a/examples/shader/shader_instancing.rs b/examples/shader/shader_instancing.rs index 71e68566b40e5..0e0ad62d1a426 100644 --- a/examples/shader/shader_instancing.rs +++ b/examples/shader/shader_instancing.rs @@ -32,7 +32,7 @@ fn main() { fn setup(mut commands: Commands, mut meshes: ResMut>) { commands.spawn(( meshes.add(Mesh::from(shape::Cube { size: 0.5 })), - SpatialBundle::VISIBLE_IDENTITY, + SpatialBundle::SHOWN_IDENTITY, InstanceMaterialData( (1..=10) .flat_map(|x| (1..=10).map(move |y| (x as f32 / 10.0, y as f32 / 10.0))) diff --git a/examples/stress_tests/many_foxes.rs b/examples/stress_tests/many_foxes.rs index d67d05e5b50e0..5d076e10b2b93 100644 --- a/examples/stress_tests/many_foxes.rs +++ b/examples/stress_tests/many_foxes.rs @@ -111,7 +111,7 @@ fn setup( let (base_rotation, ring_direction) = ring_directions[ring_index % 2]; let ring_parent = commands .spawn(( - SpatialBundle::VISIBLE_IDENTITY, + SpatialBundle::SHOWN_IDENTITY, ring_direction, Ring { radius }, )) From b1e0d19cdaf8bc9234d664bb3819c38e34cf20a8 Mon Sep 17 00:00:00 2001 From: ickk Date: Tue, 18 Oct 2022 14:58:01 +1100 Subject: [PATCH 3/7] impl `Not`, `Copy` for `Visibility` accept suggestion to use `matches!` --- crates/bevy_render/src/view/visibility/mod.rs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index c42fad47ab370..45613ff47e227 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -11,6 +11,7 @@ use bevy_reflect::Reflect; use bevy_transform::components::GlobalTransform; use bevy_transform::TransformSystem; use std::cell::Cell; +use std::ops::Not; use thread_local::ThreadLocal; use crate::{ @@ -26,7 +27,7 @@ use crate::{ /// If an entity is hidden in this way, all [`Children`] (and all of their children and so on) will also be hidden. /// This is done by setting the values of their [`ComputedVisibility`] component. -#[derive(Component, Clone, Reflect, Debug, PartialEq, Eq)] +#[derive(Component, Clone, Copy, Reflect, Debug, PartialEq, Eq)] #[reflect(Component, Default)] pub enum Visibility { Shown, @@ -39,23 +40,29 @@ impl Default for Visibility { } } +impl Not for Visibility { + type Output = Visibility; + + #[inline] + fn not(self) -> Visibility { + match self { + Visibility::Shown => Visibility::Hidden, + Visibility::Hidden => Visibility::Shown, + } + } +} + impl Visibility { /// Whether this entity is visible. #[inline] pub const fn is_visible(&self) -> bool { - match self { - Self::Shown => true, - Self::Hidden => false, - } + matches!(self, Self::Shown) } /// Toggle the visibility. #[inline] pub fn toggle(&mut self) { - *self = match self { - Self::Shown => Self::Hidden, - Self::Hidden => Self::Shown, - } + *self = !*self; } } From b70572af67a1e7ba5412dc5902d2c7380d92fca6 Mon Sep 17 00:00:00 2001 From: ickk Date: Thu, 20 Oct 2022 07:56:13 +1100 Subject: [PATCH 4/7] add `set` method to `Visibility` add a test ensuring that `Visibility` is one byte and that null pointer optimisation is doing its thing --- crates/bevy_render/src/view/visibility/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index 45613ff47e227..e240d948fd392 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -64,6 +64,12 @@ impl Visibility { pub fn toggle(&mut self) { *self = !*self; } + + /// Set the visibility using a boolean expression. + #[inline] + pub fn set(&mut self, shown: bool) { + *self = if shown { Self::Shown } else { Self::Hidden } + } } /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering @@ -556,4 +562,12 @@ mod test { "child's invisibility propagates down to grandchild" ); } + + #[test] + fn ensure_visibility_enum_size() { + use std::mem; + assert_eq!(1, mem::size_of::()); + assert_eq!(1, mem::size_of::>()); + assert_eq!(1, mem::size_of::>>()); + } } From 7c024195b0eb14a91f7ca04d5307878b2c985d5f Mon Sep 17 00:00:00 2001 From: ickk Date: Thu, 20 Oct 2022 08:13:31 +1100 Subject: [PATCH 5/7] rename `Visibility::Shown` variant again, this time to `Inherited` --- crates/bevy_gltf/src/loader.rs | 2 +- crates/bevy_render/src/spatial_bundle.rs | 8 ++--- crates/bevy_render/src/view/visibility/mod.rs | 30 +++++++++++-------- examples/2d/mesh2d_manual.rs | 2 +- examples/animation/animated_transform.rs | 2 +- examples/shader/shader_instancing.rs | 2 +- examples/stress_tests/many_foxes.rs | 2 +- 7 files changed, 26 insertions(+), 22 deletions(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 91ec72a0d07a0..cfa4592399611 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -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( diff --git a/crates/bevy_render/src/spatial_bundle.rs b/crates/bevy_render/src/spatial_bundle.rs index e5f0f2dee27f3..b2d50da6097f6 100644 --- a/crates/bevy_render/src/spatial_bundle.rs +++ b/crates/bevy_render/src/spatial_bundle.rs @@ -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, @@ -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 }; } diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index e240d948fd392..8b9c471b8ff88 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -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 } } @@ -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 + } } } @@ -289,7 +293,7 @@ fn visibility_propagate_system( children_query: Query<&Children, (With, With, With)>, ) { 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 { @@ -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 diff --git a/examples/2d/mesh2d_manual.rs b/examples/2d/mesh2d_manual.rs index 0eca79eadc357..602ce568efd32 100644 --- a/examples/2d/mesh2d_manual.rs +++ b/examples/2d/mesh2d_manual.rs @@ -103,7 +103,7 @@ fn star( // The `Handle` 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 diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index 73f1670a6efbf..cf82eb4e72c7e 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -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, )) diff --git a/examples/shader/shader_instancing.rs b/examples/shader/shader_instancing.rs index 0e0ad62d1a426..4012473a5b879 100644 --- a/examples/shader/shader_instancing.rs +++ b/examples/shader/shader_instancing.rs @@ -32,7 +32,7 @@ fn main() { fn setup(mut commands: Commands, mut meshes: ResMut>) { 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))) diff --git a/examples/stress_tests/many_foxes.rs b/examples/stress_tests/many_foxes.rs index 5d076e10b2b93..b9ec2314e7752 100644 --- a/examples/stress_tests/many_foxes.rs +++ b/examples/stress_tests/many_foxes.rs @@ -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 }, )) From bb11759885c162f0544055e7d21f06686e08fd6f Mon Sep 17 00:00:00 2001 From: ickk Date: Thu, 20 Oct 2022 08:49:20 +1100 Subject: [PATCH 6/7] Document the variants --- crates/bevy_render/src/view/visibility/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index 8b9c471b8ff88..56e259f299b95 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -25,12 +25,16 @@ use crate::{ /// User indication of whether an entity is visible. Propagates down the entity hierarchy. -/// If an entity is hidden in this way, all [`Children`] (and all of their children and so on) will also be hidden. +/// If an entity is hidden in this way, all [`Children`] (and all of their children and so on) who are set to +/// `Inherited` will also be hidden. /// This is done by setting the values of their [`ComputedVisibility`] component. #[derive(Component, Clone, Copy, Reflect, Debug, PartialEq, Eq)] #[reflect(Component, Default)] pub enum Visibility { + /// An entity with `Visibility::Inherited` will inherit the Visibility of its [`Parent`]. Inherited, + /// An entity with `Visibility::Hidden` will be unconditionally hidden, and will also cause any + /// of its [`Children`] which are set to `Visibility::Inherited` to also be hidden. Hidden, } From fe3926c9e25172aa65a8313344648157980cc647 Mon Sep 17 00:00:00 2001 From: ickk Date: Thu, 20 Oct 2022 08:55:25 +1100 Subject: [PATCH 7/7] clarify `Visibility::Inherited` behaviour for root-level entities --- crates/bevy_render/src/view/visibility/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index 56e259f299b95..9a274fb256db0 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -25,13 +25,18 @@ use crate::{ /// User indication of whether an entity is visible. Propagates down the entity hierarchy. -/// If an entity is hidden in this way, all [`Children`] (and all of their children and so on) who are set to -/// `Inherited` will also be hidden. +/// If an entity is hidden in this way, all [`Children`] (and all of their children and so on) who +/// are set to `Inherited` will also be hidden. /// This is done by setting the values of their [`ComputedVisibility`] component. +/// +/// A root-level entity that is set to `Inherited` will be visible, and as such will cause any of +/// its [`Children`] entities which are set to `Inherited` to also be visible. #[derive(Component, Clone, Copy, Reflect, Debug, PartialEq, Eq)] #[reflect(Component, Default)] pub enum Visibility { /// An entity with `Visibility::Inherited` will inherit the Visibility of its [`Parent`]. + /// + /// A root-level entity that is set to `Inherited` will be visible. Inherited, /// An entity with `Visibility::Hidden` will be unconditionally hidden, and will also cause any /// of its [`Children`] which are set to `Visibility::Inherited` to also be hidden.