Skip to content

Commit 8a1ba46

Browse files
committed
Do not use bevy Visibility because it doesn't support serde
1 parent 1b32479 commit 8a1ba46

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/debug_render/configuration.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Default for ContactGizmoScale {
133133
}
134134

135135
/// Determines if the visibility of entities with [colliders](Collider) should
136-
/// be overwritten. Setting this to `MeshVisibility::Overwrite(Visibility::Hidden)`,
136+
/// be overwritten. Setting this to `MeshVisibility::AlwaysHide`,
137137
/// will only show the debug renders.
138138
#[derive(Reflect, Clone, Copy, PartialEq, Default)]
139139
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
@@ -143,15 +143,39 @@ pub enum MeshVisibility {
143143
/// Do not change the visibility of the entity's mesh.
144144
#[default]
145145
Ignore,
146-
/// Always overwrite the visibility of the entity's mesh.
147-
Overwrite(Visibility),
146+
/// Always overwrite the visibility of the entity's mesh to use parent visibility.
147+
AlwaysInherit,
148+
/// Always overwrite the visibility of the entity's mesh to hidden.
149+
AlwaysHide,
150+
/// Always overwrite the visibility of the entity's mesh to visible.
151+
AlwaysShow,
152+
}
153+
154+
impl From<Visibility> for MeshVisibility {
155+
fn from(visibility: Visibility) -> Self {
156+
match visibility {
157+
Visibility::Inherited => MeshVisibility::AlwaysInherit,
158+
Visibility::Hidden => MeshVisibility::AlwaysHide,
159+
Visibility::Visible => MeshVisibility::AlwaysShow,
160+
}
161+
}
148162
}
149163

150164
impl MeshVisibility {
151165
/// Returns the first non-ignore visibility.
152166
pub fn or(self, other: Self) -> Self {
153167
if self == Self::Ignore { other } else { self }
154168
}
169+
170+
/// Returns the visibility that should be used to replace the entity's mesh visibility.
171+
pub fn to_visibility(self) -> Option<Visibility> {
172+
match self {
173+
MeshVisibility::Ignore => None,
174+
MeshVisibility::AlwaysInherit => Some(Visibility::Inherited),
175+
MeshVisibility::AlwaysHide => Some(Visibility::Hidden),
176+
MeshVisibility::AlwaysShow => Some(Visibility::Visible),
177+
}
178+
}
155179
}
156180

157181
impl PhysicsGizmos {
@@ -175,7 +199,7 @@ impl PhysicsGizmos {
175199
shapecast_point_color: Some(YELLOW.into()),
176200
shapecast_normal_color: Some(PINK.into()),
177201
island_color: Some(RED.into()),
178-
mesh_visibility: MeshVisibility::Overwrite(Visibility::Hidden),
202+
mesh_visibility: MeshVisibility::from(Visibility::Hidden),
179203
}
180204
}
181205

@@ -477,7 +501,7 @@ impl DebugRender {
477501
aabb_color: Some(Color::srgb(0.8, 0.8, 0.8)),
478502
collider_color: Some(ORANGE.into()),
479503
sleeping_color_multiplier: Some([1.0, 1.0, 0.4, 1.0]),
480-
mesh_visibility: MeshVisibility::Overwrite(Visibility::Hidden),
504+
mesh_visibility: MeshVisibility::from(Visibility::Hidden),
481505
}
482506
}
483507

src/debug_render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ fn change_mesh_visibility(
539539
.unwrap_or_default()
540540
.or(config.1.mesh_visibility);
541541

542-
if let MeshVisibility::Overwrite(value) = mesh_visibility {
542+
if let Some(value) = mesh_visibility.to_visibility() {
543543
*visibility = value;
544544
}
545545
}

0 commit comments

Comments
 (0)